aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2016-06-23 21:01:17 -0400
committerDave Airlie <airlied@redhat.com>2016-06-23 21:01:17 -0400
commit9253d0590ef17b4ef2167a66ad500c51b2d61610 (patch)
treeedb4a088e8df95c9da2f7ea0679fb978e22dcaa0
parent4b01ec97808bd897fc91dfbaac63747528d74680 (diff)
parentf510f34c12f65105146ace5561969e5003f6c007 (diff)
Merge tag 'topic/drm-misc-2016-06-22-updated' of git://anongit.freedesktop.org/drm-intel into drm-next
Again a pile of things all over - Conversion to rst from docbook from Jani. Looks real pretty, and the source is now actually readable (compared to horrible, horrible docbook xml)! https://01.org/linuxgraphics/gfx-docs/drm/ - device register/unregister rework from Chris, with follow-up work from Benjamin. Allows more drivers to demidlayer load/unload and others to remove a bit of boilerplate. - master/auth related cleanup, with docs - some dma-buf polish, merged by Sumit - small stuff all over (like build fixes from Arnd) Group maintainership seems to slowly take off, with both Thierry and Sumit pushing a few things. No hiccups thus far. * tag 'topic/drm-misc-2016-06-22-updated' of git://anongit.freedesktop.org/drm-intel: (68 commits) drm/vc4: Remove unused connector drm/fb-helper: Reduce READ_ONCE(master) to lockless_dereference drm/sun4i: Remove open-coded drm_connector_register_all() drm/vc4: Remove open-coded drm_connector_register_all() drm/atmel-hlcdc: Remove redundant call to drm_connector_unregister_all() drm: document drm_auth.c drm: Clear up master tracking booleans drm: Extract drm_is_current_master drm: Refactor drop/set master code a bit drm: Lobotomize set_busid nonsense for !pci drivers drm: Nuke SET_UNIQUE ioctl drm: Don't call drm_dev_set_unique from platform drivers drm/vgem: Stop calling drm_drv_set_unique drm: Use dev->name as fallback for dev->unique drm: Clean up drm_crtc.h drm: Move master pointer from drm_minor to drm_device drm: sti: rework init sequence drm: sti: use late_register and early_unregister callbacks drm/amdkfd: Clean up inline handling drm: Add callbacks for late registering ...
-rw-r--r--Documentation/DocBook/Makefile2
-rw-r--r--Documentation/DocBook/gpu.tmpl3528
-rw-r--r--Documentation/gpu/drm-internals.rst378
-rw-r--r--Documentation/gpu/drm-kms-helpers.rst260
-rw-r--r--Documentation/gpu/drm-kms.rst656
-rw-r--r--Documentation/gpu/drm-mm.rst454
-rw-r--r--Documentation/gpu/drm-uapi.rst111
-rw-r--r--Documentation/gpu/i915.rst347
-rw-r--r--Documentation/gpu/index.rst14
-rw-r--r--Documentation/gpu/introduction.rst51
-rw-r--r--Documentation/gpu/kms-properties.csv128
-rw-r--r--Documentation/gpu/vga-switcheroo.rst102
-rw-r--r--Documentation/index.rst1
-rw-r--r--MAINTAINERS3
-rw-r--r--drivers/dma-buf/dma-buf.c44
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h4
-rw-r--r--drivers/gpu/drm/amd/amdkfd/kfd_priv.h3
-rw-r--r--drivers/gpu/drm/arc/arcpgu_drv.c8
-rw-r--r--drivers/gpu/drm/armada/armada_drv.c1
-rw-r--r--drivers/gpu/drm/armada/armada_overlay.c1
-rw-r--r--drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c15
-rw-r--r--drivers/gpu/drm/drm_auth.c285
-rw-r--r--drivers/gpu/drm/drm_bufs.c8
-rw-r--r--drivers/gpu/drm/drm_crtc.c164
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c3
-rw-r--r--drivers/gpu/drm/drm_crtc_internal.h88
-rw-r--r--drivers/gpu/drm/drm_debugfs.c3
-rw-r--r--drivers/gpu/drm/drm_dp_helper.c56
-rw-r--r--drivers/gpu/drm/drm_drv.c239
-rw-r--r--drivers/gpu/drm/drm_fb_helper.c2
-rw-r--r--drivers/gpu/drm/drm_fops.c125
-rw-r--r--drivers/gpu/drm/drm_info.c117
-rw-r--r--drivers/gpu/drm/drm_internal.h21
-rw-r--r--drivers/gpu/drm/drm_ioctl.c124
-rw-r--r--drivers/gpu/drm/drm_irq.c4
-rw-r--r--drivers/gpu/drm/drm_legacy.h8
-rw-r--r--drivers/gpu/drm/drm_lock.c240
-rw-r--r--drivers/gpu/drm/drm_pci.c51
-rw-r--r--drivers/gpu/drm/drm_plane_helper.c28
-rw-r--r--drivers/gpu/drm/drm_platform.c18
-rw-r--r--drivers/gpu/drm/drm_simple_kms_helper.c1
-rw-r--r--drivers/gpu/drm/drm_vm.c54
-rw-r--r--drivers/gpu/drm/etnaviv/etnaviv_drv.c1
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.c1
-rw-r--r--drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c13
-rw-r--r--drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c9
-rw-r--r--drivers/gpu/drm/i915/i915_drv.h3
-rw-r--r--drivers/gpu/drm/i915/i915_gem_execbuffer.c4
-rw-r--r--drivers/gpu/drm/i915/intel_crt.c2
-rw-r--r--drivers/gpu/drm/i915/intel_display.c15
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c22
-rw-r--r--drivers/gpu/drm/i915/intel_dp_mst.c4
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h17
-rw-r--r--drivers/gpu/drm/i915/intel_dsi.c2
-rw-r--r--drivers/gpu/drm/i915/intel_dvo.c2
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c2
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c2
-rw-r--r--drivers/gpu/drm/i915/intel_panel.c13
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c26
-rw-r--r--drivers/gpu/drm/i915/intel_tv.c2
-rw-r--r--drivers/gpu/drm/imx/imx-drm-core.c1
-rw-r--r--drivers/gpu/drm/mediatek/Kconfig1
-rw-r--r--drivers/gpu/drm/mediatek/mtk_drm_drv.c9
-rw-r--r--drivers/gpu/drm/mediatek/mtk_drm_plane.c1
-rw-r--r--drivers/gpu/drm/msm/msm_drv.c9
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drm.c1
-rw-r--r--drivers/gpu/drm/omapdrm/omap_drv.c1
-rw-r--r--drivers/gpu/drm/omapdrm/omap_fbdev.c3
-rw-r--r--drivers/gpu/drm/rcar-du/rcar_du_drv.c7
-rw-r--r--drivers/gpu/drm/rockchip/Kconfig1
-rw-r--r--drivers/gpu/drm/rockchip/rockchip_drm_drv.c21
-rw-r--r--drivers/gpu/drm/rockchip/rockchip_drm_vop.c1
-rw-r--r--drivers/gpu/drm/shmobile/shmob_drm_drv.c1
-rw-r--r--drivers/gpu/drm/sis/sis_mm.c2
-rw-r--r--drivers/gpu/drm/sti/sti_compositor.c20
-rw-r--r--drivers/gpu/drm/sti/sti_compositor.h3
-rw-r--r--drivers/gpu/drm/sti/sti_crtc.c12
-rw-r--r--drivers/gpu/drm/sti/sti_cursor.c32
-rw-r--r--drivers/gpu/drm/sti/sti_drv.c138
-rw-r--r--drivers/gpu/drm/sti/sti_drv.h1
-rw-r--r--drivers/gpu/drm/sti/sti_dvo.c25
-rw-r--r--drivers/gpu/drm/sti/sti_gdp.c32
-rw-r--r--drivers/gpu/drm/sti/sti_hda.c26
-rw-r--r--drivers/gpu/drm/sti/sti_hdmi.c40
-rw-r--r--drivers/gpu/drm/sti/sti_hqvdp.c32
-rw-r--r--drivers/gpu/drm/sti/sti_mixer.c5
-rw-r--r--drivers/gpu/drm/sti/sti_mixer.h2
-rw-r--r--drivers/gpu/drm/sti/sti_plane.c24
-rw-r--r--drivers/gpu/drm/sti/sti_plane.h7
-rw-r--r--drivers/gpu/drm/sti/sti_tvout.c36
-rw-r--r--drivers/gpu/drm/sti/sti_vid.c5
-rw-r--r--drivers/gpu/drm/sti/sti_vid.h2
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_drv.c38
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_drv.c1
-rw-r--r--drivers/gpu/drm/vc4/vc4_drv.c13
-rw-r--r--drivers/gpu/drm/vgem/vgem_drv.c2
-rw-r--r--drivers/gpu/drm/via/via_mm.c2
-rw-r--r--drivers/gpu/drm/virtio/virtgpu_drm_bus.c10
-rw-r--r--drivers/gpu/drm/virtio/virtgpu_drv.c1
-rw-r--r--drivers/gpu/drm/virtio/virtgpu_drv.h1
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c5
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h1
-rw-r--r--include/drm/drmP.h56
-rw-r--r--include/drm/drm_auth.h59
-rw-r--r--include/drm/drm_crtc.h294
-rw-r--r--include/drm/drm_dp_helper.h1
-rw-r--r--include/drm/drm_legacy.h2
-rw-r--r--include/drm/drm_plane_helper.h1
-rw-r--r--include/linux/dma-buf.h2
109 files changed, 4018 insertions, 4862 deletions
diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index e0c7e1e0590b..f4482f9b221f 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -14,7 +14,7 @@ DOCBOOKS := z8530book.xml device-drivers.xml \
14 genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \ 14 genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \
15 80211.xml debugobjects.xml sh.xml regulator.xml \ 15 80211.xml debugobjects.xml sh.xml regulator.xml \
16 alsa-driver-api.xml writing-an-alsa-driver.xml \ 16 alsa-driver-api.xml writing-an-alsa-driver.xml \
17 tracepoint.xml gpu.xml media_api.xml w1.xml \ 17 tracepoint.xml media_api.xml w1.xml \
18 writing_musb_glue_layer.xml crypto-API.xml iio.xml 18 writing_musb_glue_layer.xml crypto-API.xml iio.xml
19 19
20include Documentation/DocBook/media/Makefile 20include Documentation/DocBook/media/Makefile
diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
deleted file mode 100644
index d09536c91717..000000000000
--- a/Documentation/DocBook/gpu.tmpl
+++ /dev/null
@@ -1,3528 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
4
5<book id="gpuDevelopersGuide">
6 <bookinfo>
7 <title>Linux GPU Driver Developer's Guide</title>
8
9 <authorgroup>
10 <author>
11 <firstname>Jesse</firstname>
12 <surname>Barnes</surname>
13 <contrib>Initial version</contrib>
14 <affiliation>
15 <orgname>Intel Corporation</orgname>
16 <address>
17 <email>jesse.barnes@intel.com</email>
18 </address>
19 </affiliation>
20 </author>
21 <author>
22 <firstname>Laurent</firstname>
23 <surname>Pinchart</surname>
24 <contrib>Driver internals</contrib>
25 <affiliation>
26 <orgname>Ideas on board SPRL</orgname>
27 <address>
28 <email>laurent.pinchart@ideasonboard.com</email>
29 </address>
30 </affiliation>
31 </author>
32 <author>
33 <firstname>Daniel</firstname>
34 <surname>Vetter</surname>
35 <contrib>Contributions all over the place</contrib>
36 <affiliation>
37 <orgname>Intel Corporation</orgname>
38 <address>
39 <email>daniel.vetter@ffwll.ch</email>
40 </address>
41 </affiliation>
42 </author>
43 <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>
53 </authorgroup>
54
55 <copyright>
56 <year>2008-2009</year>
57 <year>2013-2014</year>
58 <holder>Intel Corporation</holder>
59 </copyright>
60 <copyright>
61 <year>2012</year>
62 <holder>Laurent Pinchart</holder>
63 </copyright>
64 <copyright>
65 <year>2015</year>
66 <holder>Lukas Wunner</holder>
67 </copyright>
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>
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>
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>
93 </revhistory>
94 </bookinfo>
95
96<toc></toc>
97
98<part id="drmCore">
99 <title>DRM Core</title>
100 <partintro>
101 <para>
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.
105 </para>
106 </partintro>
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
114 drivers in the kernel may make use of DRM functions to make
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 <sect1>
128 <title>Style Guidelines</title>
129 <para>
130 For consistency this documentation uses American English. Abbreviations
131 are written as all-uppercase, for example: DRM, KMS, IOCTL, CRTC, and so
132 on. To aid in reading, documentations make full use of the markup
133 characters kerneldoc provides: @parameter for function parameters, @member
134 for structure members, &amp;structure to reference structures and
135 function() for functions. These all get automatically hyperlinked if
136 kerneldoc for the referenced objects exists. When referencing entries in
137 function vtables please use -&gt;vfunc(). Note that kerneldoc does
138 not support referencing struct members directly, so please add a reference
139 to the vtable struct somewhere in the same paragraph or at least section.
140 </para>
141 <para>
142 Except in special situations (to separate locked from unlocked variants)
143 locking requirements for functions aren't documented in the kerneldoc.
144 Instead locking should be check at runtime using e.g.
145 <code>WARN_ON(!mutex_is_locked(...));</code>. Since it's much easier to
146 ignore documentation than runtime noise this provides more value. And on
147 top of that runtime checks do need to be updated when the locking rules
148 change, increasing the chances that they're correct. Within the
149 documentation the locking rules should be explained in the relevant
150 structures: Either in the comment for the lock explaining what it
151 protects, or data fields need a note about which lock protects them, or
152 both.
153 </para>
154 <para>
155 Functions which have a non-<code>void</code> return value should have a
156 section called "Returns" explaining the expected return values in
157 different cases and their meanings. Currently there's no consensus whether
158 that section name should be all upper-case or not, and whether it should
159 end in a colon or not. Go with the file-local style. Other common section
160 names are "Notes" with information for dangerous or tricky corner cases,
161 and "FIXME" where the interface could be cleaned up.
162 </para>
163 </sect1>
164 </chapter>
165
166 <!-- Internals -->
167
168 <chapter id="drmInternals">
169 <title>DRM Internals</title>
170 <para>
171 This chapter documents DRM internals relevant to driver authors
172 and developers working to add support for the latest features to
173 existing drivers.
174 </para>
175 <para>
176 First, we go over some typical driver initialization
177 requirements, like setting up command buffers, creating an
178 initial output configuration, and initializing core services.
179 Subsequent sections cover core internals in more detail,
180 providing implementation notes and examples.
181 </para>
182 <para>
183 The DRM layer provides several services to graphics drivers,
184 many of them driven by the application interfaces it provides
185 through libdrm, the library that wraps most of the DRM ioctls.
186 These include vblank event handling, memory
187 management, output management, framebuffer management, command
188 submission &amp; fencing, suspend/resume support, and DMA
189 services.
190 </para>
191
192 <!-- Internals: driver init -->
193
194 <sect1>
195 <title>Driver Initialization</title>
196 <para>
197 At the core of every DRM driver is a <structname>drm_driver</structname>
198 structure. Drivers typically statically initialize a drm_driver structure,
199 and then pass it to <function>drm_dev_alloc()</function> to allocate a
200 device instance. After the device instance is fully initialized it can be
201 registered (which makes it accessible from userspace) using
202 <function>drm_dev_register()</function>.
203 </para>
204 <para>
205 The <structname>drm_driver</structname> structure contains static
206 information that describes the driver and features it supports, and
207 pointers to methods that the DRM core will call to implement the DRM API.
208 We will first go through the <structname>drm_driver</structname> static
209 information fields, and will then describe individual operations in
210 details as they get used in later sections.
211 </para>
212 <sect2>
213 <title>Driver Information</title>
214 <sect3>
215 <title>Driver Features</title>
216 <para>
217 Drivers inform the DRM core about their requirements and supported
218 features by setting appropriate flags in the
219 <structfield>driver_features</structfield> field. Since those flags
220 influence the DRM core behaviour since registration time, most of them
221 must be set to registering the <structname>drm_driver</structname>
222 instance.
223 </para>
224 <synopsis>u32 driver_features;</synopsis>
225 <variablelist>
226 <title>Driver Feature Flags</title>
227 <varlistentry>
228 <term>DRIVER_USE_AGP</term>
229 <listitem><para>
230 Driver uses AGP interface, the DRM core will manage AGP resources.
231 </para></listitem>
232 </varlistentry>
233 <varlistentry>
234 <term>DRIVER_REQUIRE_AGP</term>
235 <listitem><para>
236 Driver needs AGP interface to function. AGP initialization failure
237 will become a fatal error.
238 </para></listitem>
239 </varlistentry>
240 <varlistentry>
241 <term>DRIVER_PCI_DMA</term>
242 <listitem><para>
243 Driver is capable of PCI DMA, mapping of PCI DMA buffers to
244 userspace will be enabled. Deprecated.
245 </para></listitem>
246 </varlistentry>
247 <varlistentry>
248 <term>DRIVER_SG</term>
249 <listitem><para>
250 Driver can perform scatter/gather DMA, allocation and mapping of
251 scatter/gather buffers will be enabled. Deprecated.
252 </para></listitem>
253 </varlistentry>
254 <varlistentry>
255 <term>DRIVER_HAVE_DMA</term>
256 <listitem><para>
257 Driver supports DMA, the userspace DMA API will be supported.
258 Deprecated.
259 </para></listitem>
260 </varlistentry>
261 <varlistentry>
262 <term>DRIVER_HAVE_IRQ</term><term>DRIVER_IRQ_SHARED</term>
263 <listitem><para>
264 DRIVER_HAVE_IRQ indicates whether the driver has an IRQ handler
265 managed by the DRM Core. The core will support simple IRQ handler
266 installation when the flag is set. The installation process is
267 described in <xref linkend="drm-irq-registration"/>.</para>
268 <para>DRIVER_IRQ_SHARED indicates whether the device &amp; handler
269 support shared IRQs (note that this is required of PCI drivers).
270 </para></listitem>
271 </varlistentry>
272 <varlistentry>
273 <term>DRIVER_GEM</term>
274 <listitem><para>
275 Driver use the GEM memory manager.
276 </para></listitem>
277 </varlistentry>
278 <varlistentry>
279 <term>DRIVER_MODESET</term>
280 <listitem><para>
281 Driver supports mode setting interfaces (KMS).
282 </para></listitem>
283 </varlistentry>
284 <varlistentry>
285 <term>DRIVER_PRIME</term>
286 <listitem><para>
287 Driver implements DRM PRIME buffer sharing.
288 </para></listitem>
289 </varlistentry>
290 <varlistentry>
291 <term>DRIVER_RENDER</term>
292 <listitem><para>
293 Driver supports dedicated render nodes.
294 </para></listitem>
295 </varlistentry>
296 <varlistentry>
297 <term>DRIVER_ATOMIC</term>
298 <listitem><para>
299 Driver supports atomic properties. In this case the driver
300 must implement appropriate obj->atomic_get_property() vfuncs
301 for any modeset objects with driver specific properties.
302 </para></listitem>
303 </varlistentry>
304 </variablelist>
305 </sect3>
306 <sect3>
307 <title>Major, Minor and Patchlevel</title>
308 <synopsis>int major;
309int minor;
310int patchlevel;</synopsis>
311 <para>
312 The DRM core identifies driver versions by a major, minor and patch
313 level triplet. The information is printed to the kernel log at
314 initialization time and passed to userspace through the
315 DRM_IOCTL_VERSION ioctl.
316 </para>
317 <para>
318 The major and minor numbers are also used to verify the requested driver
319 API version passed to DRM_IOCTL_SET_VERSION. When the driver API changes
320 between minor versions, applications can call DRM_IOCTL_SET_VERSION to
321 select a specific version of the API. If the requested major isn't equal
322 to the driver major, or the requested minor is larger than the driver
323 minor, the DRM_IOCTL_SET_VERSION call will return an error. Otherwise
324 the driver's set_version() method will be called with the requested
325 version.
326 </para>
327 </sect3>
328 <sect3>
329 <title>Name, Description and Date</title>
330 <synopsis>char *name;
331char *desc;
332char *date;</synopsis>
333 <para>
334 The driver name is printed to the kernel log at initialization time,
335 used for IRQ registration and passed to userspace through
336 DRM_IOCTL_VERSION.
337 </para>
338 <para>
339 The driver description is a purely informative string passed to
340 userspace through the DRM_IOCTL_VERSION ioctl and otherwise unused by
341 the kernel.
342 </para>
343 <para>
344 The driver date, formatted as YYYYMMDD, is meant to identify the date of
345 the latest modification to the driver. However, as most drivers fail to
346 update it, its value is mostly useless. The DRM core prints it to the
347 kernel log at initialization time and passes it to userspace through the
348 DRM_IOCTL_VERSION ioctl.
349 </para>
350 </sect3>
351 </sect2>
352 <sect2>
353 <title>Device Instance and Driver Handling</title>
354!Pdrivers/gpu/drm/drm_drv.c driver instance overview
355!Edrivers/gpu/drm/drm_drv.c
356 </sect2>
357 <sect2>
358 <title>Driver Load</title>
359 <sect3 id="drm-irq-registration">
360 <title>IRQ Registration</title>
361 <para>
362 The DRM core tries to facilitate IRQ handler registration and
363 unregistration by providing <function>drm_irq_install</function> and
364 <function>drm_irq_uninstall</function> functions. Those functions only
365 support a single interrupt per device, devices that use more than one
366 IRQs need to be handled manually.
367 </para>
368 <sect4>
369 <title>Managed IRQ Registration</title>
370 <para>
371 <function>drm_irq_install</function> starts by calling the
372 <methodname>irq_preinstall</methodname> driver operation. The operation
373 is optional and must make sure that the interrupt will not get fired by
374 clearing all pending interrupt flags or disabling the interrupt.
375 </para>
376 <para>
377 The passed-in IRQ will then be requested by a call to
378 <function>request_irq</function>. If the DRIVER_IRQ_SHARED driver
379 feature flag is set, a shared (IRQF_SHARED) IRQ handler will be
380 requested.
381 </para>
382 <para>
383 The IRQ handler function must be provided as the mandatory irq_handler
384 driver operation. It will get passed directly to
385 <function>request_irq</function> and thus has the same prototype as all
386 IRQ handlers. It will get called with a pointer to the DRM device as the
387 second argument.
388 </para>
389 <para>
390 Finally the function calls the optional
391 <methodname>irq_postinstall</methodname> driver operation. The operation
392 usually enables interrupts (excluding the vblank interrupt, which is
393 enabled separately), but drivers may choose to enable/disable interrupts
394 at a different time.
395 </para>
396 <para>
397 <function>drm_irq_uninstall</function> is similarly used to uninstall an
398 IRQ handler. It starts by waking up all processes waiting on a vblank
399 interrupt to make sure they don't hang, and then calls the optional
400 <methodname>irq_uninstall</methodname> driver operation. The operation
401 must disable all hardware interrupts. Finally the function frees the IRQ
402 by calling <function>free_irq</function>.
403 </para>
404 </sect4>
405 <sect4>
406 <title>Manual IRQ Registration</title>
407 <para>
408 Drivers that require multiple interrupt handlers can't use the managed
409 IRQ registration functions. In that case IRQs must be registered and
410 unregistered manually (usually with the <function>request_irq</function>
411 and <function>free_irq</function> functions, or their devm_* equivalent).
412 </para>
413 <para>
414 When manually registering IRQs, drivers must not set the DRIVER_HAVE_IRQ
415 driver feature flag, and must not provide the
416 <methodname>irq_handler</methodname> driver operation. They must set the
417 <structname>drm_device</structname> <structfield>irq_enabled</structfield>
418 field to 1 upon registration of the IRQs, and clear it to 0 after
419 unregistering the IRQs.
420 </para>
421 </sect4>
422 </sect3>
423 <sect3>
424 <title>Memory Manager Initialization</title>
425 <para>
426 Every DRM driver requires a memory manager which must be initialized at
427 load time. DRM currently contains two memory managers, the Translation
428 Table Manager (TTM) and the Graphics Execution Manager (GEM).
429 This document describes the use of the GEM memory manager only. See
430 <xref linkend="drm-memory-management"/> for details.
431 </para>
432 </sect3>
433 <sect3>
434 <title>Miscellaneous Device Configuration</title>
435 <para>
436 Another task that may be necessary for PCI devices during configuration
437 is mapping the video BIOS. On many devices, the VBIOS describes device
438 configuration, LCD panel timings (if any), and contains flags indicating
439 device state. Mapping the BIOS can be done using the pci_map_rom() call,
440 a convenience function that takes care of mapping the actual ROM,
441 whether it has been shadowed into memory (typically at address 0xc0000)
442 or exists on the PCI device in the ROM BAR. Note that after the ROM has
443 been mapped and any necessary information has been extracted, it should
444 be unmapped; on many devices, the ROM address decoder is shared with
445 other BARs, so leaving it mapped could cause undesired behaviour like
446 hangs or memory corruption.
447 <!--!Fdrivers/pci/rom.c pci_map_rom-->
448 </para>
449 </sect3>
450 </sect2>
451 <sect2>
452 <title>Bus-specific Device Registration and PCI Support</title>
453 <para>
454 A number of functions are provided to help with device registration.
455 The functions deal with PCI and platform devices respectively and are
456 only provided for historical reasons. These are all deprecated and
457 shouldn't be used in new drivers. Besides that there's a few
458 helpers for pci drivers.
459 </para>
460!Edrivers/gpu/drm/drm_pci.c
461!Edrivers/gpu/drm/drm_platform.c
462 </sect2>
463 </sect1>
464
465 <!-- Internals: memory management -->
466
467 <sect1 id="drm-memory-management">
468 <title>Memory management</title>
469 <para>
470 Modern Linux systems require large amount of graphics memory to store
471 frame buffers, textures, vertices and other graphics-related data. Given
472 the very dynamic nature of many of that data, managing graphics memory
473 efficiently is thus crucial for the graphics stack and plays a central
474 role in the DRM infrastructure.
475 </para>
476 <para>
477 The DRM core includes two memory managers, namely Translation Table Maps
478 (TTM) and Graphics Execution Manager (GEM). TTM was the first DRM memory
479 manager to be developed and tried to be a one-size-fits-them all
480 solution. It provides a single userspace API to accommodate the need of
481 all hardware, supporting both Unified Memory Architecture (UMA) devices
482 and devices with dedicated video RAM (i.e. most discrete video cards).
483 This resulted in a large, complex piece of code that turned out to be
484 hard to use for driver development.
485 </para>
486 <para>
487 GEM started as an Intel-sponsored project in reaction to TTM's
488 complexity. Its design philosophy is completely different: instead of
489 providing a solution to every graphics memory-related problems, GEM
490 identified common code between drivers and created a support library to
491 share it. GEM has simpler initialization and execution requirements than
492 TTM, but has no video RAM management capabilities and is thus limited to
493 UMA devices.
494 </para>
495 <sect2>
496 <title>The Translation Table Manager (TTM)</title>
497 <para>
498 TTM design background and information belongs here.
499 </para>
500 <sect3>
501 <title>TTM initialization</title>
502 <warning><para>This section is outdated.</para></warning>
503 <para>
504 Drivers wishing to support TTM must fill out a drm_bo_driver
505 structure. The structure contains several fields with function
506 pointers for initializing the TTM, allocating and freeing memory,
507 waiting for command completion and fence synchronization, and memory
508 migration. See the radeon_ttm.c file for an example of usage.
509 </para>
510 <para>
511 The ttm_global_reference structure is made up of several fields:
512 </para>
513 <programlisting>
514 struct ttm_global_reference {
515 enum ttm_global_types global_type;
516 size_t size;
517 void *object;
518 int (*init) (struct ttm_global_reference *);
519 void (*release) (struct ttm_global_reference *);
520 };
521 </programlisting>
522 <para>
523 There should be one global reference structure for your memory
524 manager as a whole, and there will be others for each object
525 created by the memory manager at runtime. Your global TTM should
526 have a type of TTM_GLOBAL_TTM_MEM. The size field for the global
527 object should be sizeof(struct ttm_mem_global), and the init and
528 release hooks should point at your driver-specific init and
529 release routines, which probably eventually call
530 ttm_mem_global_init and ttm_mem_global_release, respectively.
531 </para>
532 <para>
533 Once your global TTM accounting structure is set up and initialized
534 by calling ttm_global_item_ref() on it,
535 you need to create a buffer object TTM to
536 provide a pool for buffer object allocation by clients and the
537 kernel itself. The type of this object should be TTM_GLOBAL_TTM_BO,
538 and its size should be sizeof(struct ttm_bo_global). Again,
539 driver-specific init and release functions may be provided,
540 likely eventually calling ttm_bo_global_init() and
541 ttm_bo_global_release(), respectively. Also, like the previous
542 object, ttm_global_item_ref() is used to create an initial reference
543 count for the TTM, which will call your initialization function.
544 </para>
545 </sect3>
546 </sect2>
547 <sect2 id="drm-gem">
548 <title>The Graphics Execution Manager (GEM)</title>
549 <para>
550 The GEM design approach has resulted in a memory manager that doesn't
551 provide full coverage of all (or even all common) use cases in its
552 userspace or kernel API. GEM exposes a set of standard memory-related
553 operations to userspace and a set of helper functions to drivers, and let
554 drivers implement hardware-specific operations with their own private API.
555 </para>
556 <para>
557 The GEM userspace API is described in the
558 <ulink url="http://lwn.net/Articles/283798/"><citetitle>GEM - the Graphics
559 Execution Manager</citetitle></ulink> article on LWN. While slightly
560 outdated, the document provides a good overview of the GEM API principles.
561 Buffer allocation and read and write operations, described as part of the
562 common GEM API, are currently implemented using driver-specific ioctls.
563 </para>
564 <para>
565 GEM is data-agnostic. It manages abstract buffer objects without knowing
566 what individual buffers contain. APIs that require knowledge of buffer
567 contents or purpose, such as buffer allocation or synchronization
568 primitives, are thus outside of the scope of GEM and must be implemented
569 using driver-specific ioctls.
570 </para>
571 <para>
572 On a fundamental level, GEM involves several operations:
573 <itemizedlist>
574 <listitem>Memory allocation and freeing</listitem>
575 <listitem>Command execution</listitem>
576 <listitem>Aperture management at command execution time</listitem>
577 </itemizedlist>
578 Buffer object allocation is relatively straightforward and largely
579 provided by Linux's shmem layer, which provides memory to back each
580 object.
581 </para>
582 <para>
583 Device-specific operations, such as command execution, pinning, buffer
584 read &amp; write, mapping, and domain ownership transfers are left to
585 driver-specific ioctls.
586 </para>
587 <sect3>
588 <title>GEM Initialization</title>
589 <para>
590 Drivers that use GEM must set the DRIVER_GEM bit in the struct
591 <structname>drm_driver</structname>
592 <structfield>driver_features</structfield> field. The DRM core will
593 then automatically initialize the GEM core before calling the
594 <methodname>load</methodname> operation. Behind the scene, this will
595 create a DRM Memory Manager object which provides an address space
596 pool for object allocation.
597 </para>
598 <para>
599 In a KMS configuration, drivers need to allocate and initialize a
600 command ring buffer following core GEM initialization if required by
601 the hardware. UMA devices usually have what is called a "stolen"
602 memory region, which provides space for the initial framebuffer and
603 large, contiguous memory regions required by the device. This space is
604 typically not managed by GEM, and must be initialized separately into
605 its own DRM MM object.
606 </para>
607 </sect3>
608 <sect3>
609 <title>GEM Objects Creation</title>
610 <para>
611 GEM splits creation of GEM objects and allocation of the memory that
612 backs them in two distinct operations.
613 </para>
614 <para>
615 GEM objects are represented by an instance of struct
616 <structname>drm_gem_object</structname>. Drivers usually need to extend
617 GEM objects with private information and thus create a driver-specific
618 GEM object structure type that embeds an instance of struct
619 <structname>drm_gem_object</structname>.
620 </para>
621 <para>
622 To create a GEM object, a driver allocates memory for an instance of its
623 specific GEM object type and initializes the embedded struct
624 <structname>drm_gem_object</structname> with a call to
625 <function>drm_gem_object_init</function>. The function takes a pointer to
626 the DRM device, a pointer to the GEM object and the buffer object size
627 in bytes.
628 </para>
629 <para>
630 GEM uses shmem to allocate anonymous pageable memory.
631 <function>drm_gem_object_init</function> will create an shmfs file of
632 the requested size and store it into the struct
633 <structname>drm_gem_object</structname> <structfield>filp</structfield>
634 field. The memory is used as either main storage for the object when the
635 graphics hardware uses system memory directly or as a backing store
636 otherwise.
637 </para>
638 <para>
639 Drivers are responsible for the actual physical pages allocation by
640 calling <function>shmem_read_mapping_page_gfp</function> for each page.
641 Note that they can decide to allocate pages when initializing the GEM
642 object, or to delay allocation until the memory is needed (for instance
643 when a page fault occurs as a result of a userspace memory access or
644 when the driver needs to start a DMA transfer involving the memory).
645 </para>
646 <para>
647 Anonymous pageable memory allocation is not always desired, for instance
648 when the hardware requires physically contiguous system memory as is
649 often the case in embedded devices. Drivers can create GEM objects with
650 no shmfs backing (called private GEM objects) by initializing them with
651 a call to <function>drm_gem_private_object_init</function> instead of
652 <function>drm_gem_object_init</function>. Storage for private GEM
653 objects must be managed by drivers.
654 </para>
655 </sect3>
656 <sect3>
657 <title>GEM Objects Lifetime</title>
658 <para>
659 All GEM objects are reference-counted by the GEM core. References can be
660 acquired and release by <function>calling drm_gem_object_reference</function>
661 and <function>drm_gem_object_unreference</function> respectively. The
662 caller must hold the <structname>drm_device</structname>
663 <structfield>struct_mutex</structfield> lock when calling
664 <function>drm_gem_object_reference</function>. As a convenience, GEM
665 provides <function>drm_gem_object_unreference_unlocked</function>
666 functions that can be called without holding the lock.
667 </para>
668 <para>
669 When the last reference to a GEM object is released the GEM core calls
670 the <structname>drm_driver</structname>
671 <methodname>gem_free_object</methodname> operation. That operation is
672 mandatory for GEM-enabled drivers and must free the GEM object and all
673 associated resources.
674 </para>
675 <para>
676 <synopsis>void (*gem_free_object) (struct drm_gem_object *obj);</synopsis>
677 Drivers are responsible for freeing all GEM object resources. This includes
678 the resources created by the GEM core, which need to be released with
679 <function>drm_gem_object_release</function>.
680 </para>
681 </sect3>
682 <sect3>
683 <title>GEM Objects Naming</title>
684 <para>
685 Communication between userspace and the kernel refers to GEM objects
686 using local handles, global names or, more recently, file descriptors.
687 All of those are 32-bit integer values; the usual Linux kernel limits
688 apply to the file descriptors.
689 </para>
690 <para>
691 GEM handles are local to a DRM file. Applications get a handle to a GEM
692 object through a driver-specific ioctl, and can use that handle to refer
693 to the GEM object in other standard or driver-specific ioctls. Closing a
694 DRM file handle frees all its GEM handles and dereferences the
695 associated GEM objects.
696 </para>
697 <para>
698 To create a handle for a GEM object drivers call
699 <function>drm_gem_handle_create</function>. The function takes a pointer
700 to the DRM file and the GEM object and returns a locally unique handle.
701 When the handle is no longer needed drivers delete it with a call to
702 <function>drm_gem_handle_delete</function>. Finally the GEM object
703 associated with a handle can be retrieved by a call to
704 <function>drm_gem_object_lookup</function>.
705 </para>
706 <para>
707 Handles don't take ownership of GEM objects, they only take a reference
708 to the object that will be dropped when the handle is destroyed. To
709 avoid leaking GEM objects, drivers must make sure they drop the
710 reference(s) they own (such as the initial reference taken at object
711 creation time) as appropriate, without any special consideration for the
712 handle. For example, in the particular case of combined GEM object and
713 handle creation in the implementation of the
714 <methodname>dumb_create</methodname> operation, drivers must drop the
715 initial reference to the GEM object before returning the handle.
716 </para>
717 <para>
718 GEM names are similar in purpose to handles but are not local to DRM
719 files. They can be passed between processes to reference a GEM object
720 globally. Names can't be used directly to refer to objects in the DRM
721 API, applications must convert handles to names and names to handles
722 using the DRM_IOCTL_GEM_FLINK and DRM_IOCTL_GEM_OPEN ioctls
723 respectively. The conversion is handled by the DRM core without any
724 driver-specific support.
725 </para>
726 <para>
727 GEM also supports buffer sharing with dma-buf file descriptors through
728 PRIME. GEM-based drivers must use the provided helpers functions to
729 implement the exporting and importing correctly. See <xref linkend="drm-prime-support" />.
730 Since sharing file descriptors is inherently more secure than the
731 easily guessable and global GEM names it is the preferred buffer
732 sharing mechanism. Sharing buffers through GEM names is only supported
733 for legacy userspace. Furthermore PRIME also allows cross-device
734 buffer sharing since it is based on dma-bufs.
735 </para>
736 </sect3>
737 <sect3 id="drm-gem-objects-mapping">
738 <title>GEM Objects Mapping</title>
739 <para>
740 Because mapping operations are fairly heavyweight GEM favours
741 read/write-like access to buffers, implemented through driver-specific
742 ioctls, over mapping buffers to userspace. However, when random access
743 to the buffer is needed (to perform software rendering for instance),
744 direct access to the object can be more efficient.
745 </para>
746 <para>
747 The mmap system call can't be used directly to map GEM objects, as they
748 don't have their own file handle. Two alternative methods currently
749 co-exist to map GEM objects to userspace. The first method uses a
750 driver-specific ioctl to perform the mapping operation, calling
751 <function>do_mmap</function> under the hood. This is often considered
752 dubious, seems to be discouraged for new GEM-enabled drivers, and will
753 thus not be described here.
754 </para>
755 <para>
756 The second method uses the mmap system call on the DRM file handle.
757 <synopsis>void *mmap(void *addr, size_t length, int prot, int flags, int fd,
758 off_t offset);</synopsis>
759 DRM identifies the GEM object to be mapped by a fake offset passed
760 through the mmap offset argument. Prior to being mapped, a GEM object
761 must thus be associated with a fake offset. To do so, drivers must call
762 <function>drm_gem_create_mmap_offset</function> on the object.
763 </para>
764 <para>
765 Once allocated, the fake offset value
766 must be passed to the application in a driver-specific way and can then
767 be used as the mmap offset argument.
768 </para>
769 <para>
770 The GEM core provides a helper method <function>drm_gem_mmap</function>
771 to handle object mapping. The method can be set directly as the mmap
772 file operation handler. It will look up the GEM object based on the
773 offset value and set the VMA operations to the
774 <structname>drm_driver</structname> <structfield>gem_vm_ops</structfield>
775 field. Note that <function>drm_gem_mmap</function> doesn't map memory to
776 userspace, but relies on the driver-provided fault handler to map pages
777 individually.
778 </para>
779 <para>
780 To use <function>drm_gem_mmap</function>, drivers must fill the struct
781 <structname>drm_driver</structname> <structfield>gem_vm_ops</structfield>
782 field with a pointer to VM operations.
783 </para>
784 <para>
785 <synopsis>struct vm_operations_struct *gem_vm_ops
786
787 struct vm_operations_struct {
788 void (*open)(struct vm_area_struct * area);
789 void (*close)(struct vm_area_struct * area);
790 int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf);
791 };</synopsis>
792 </para>
793 <para>
794 The <methodname>open</methodname> and <methodname>close</methodname>
795 operations must update the GEM object reference count. Drivers can use
796 the <function>drm_gem_vm_open</function> and
797 <function>drm_gem_vm_close</function> helper functions directly as open
798 and close handlers.
799 </para>
800 <para>
801 The fault operation handler is responsible for mapping individual pages
802 to userspace when a page fault occurs. Depending on the memory
803 allocation scheme, drivers can allocate pages at fault time, or can
804 decide to allocate memory for the GEM object at the time the object is
805 created.
806 </para>
807 <para>
808 Drivers that want to map the GEM object upfront instead of handling page
809 faults can implement their own mmap file operation handler.
810 </para>
811 </sect3>
812 <sect3>
813 <title>Memory Coherency</title>
814 <para>
815 When mapped to the device or used in a command buffer, backing pages
816 for an object are flushed to memory and marked write combined so as to
817 be coherent with the GPU. Likewise, if the CPU accesses an object
818 after the GPU has finished rendering to the object, then the object
819 must be made coherent with the CPU's view of memory, usually involving
820 GPU cache flushing of various kinds. This core CPU&lt;-&gt;GPU
821 coherency management is provided by a device-specific ioctl, which
822 evaluates an object's current domain and performs any necessary
823 flushing or synchronization to put the object into the desired
824 coherency domain (note that the object may be busy, i.e. an active
825 render target; in that case, setting the domain blocks the client and
826 waits for rendering to complete before performing any necessary
827 flushing operations).
828 </para>
829 </sect3>
830 <sect3>
831 <title>Command Execution</title>
832 <para>
833 Perhaps the most important GEM function for GPU devices is providing a
834 command execution interface to clients. Client programs construct
835 command buffers containing references to previously allocated memory
836 objects, and then submit them to GEM. At that point, GEM takes care to
837 bind all the objects into the GTT, execute the buffer, and provide
838 necessary synchronization between clients accessing the same buffers.
839 This often involves evicting some objects from the GTT and re-binding
840 others (a fairly expensive operation), and providing relocation
841 support which hides fixed GTT offsets from clients. Clients must take
842 care not to submit command buffers that reference more objects than
843 can fit in the GTT; otherwise, GEM will reject them and no rendering
844 will occur. Similarly, if several objects in the buffer require fence
845 registers to be allocated for correct rendering (e.g. 2D blits on
846 pre-965 chips), care must be taken not to require more fence registers
847 than are available to the client. Such resource management should be
848 abstracted from the client in libdrm.
849 </para>
850 </sect3>
851 </sect2>
852 <sect2>
853 <title>GEM Function Reference</title>
854!Edrivers/gpu/drm/drm_gem.c
855!Iinclude/drm/drm_gem.h
856 </sect2>
857 <sect2>
858 <title>VMA Offset Manager</title>
859!Pdrivers/gpu/drm/drm_vma_manager.c vma offset manager
860!Edrivers/gpu/drm/drm_vma_manager.c
861!Iinclude/drm/drm_vma_manager.h
862 </sect2>
863 <sect2 id="drm-prime-support">
864 <title>PRIME Buffer Sharing</title>
865 <para>
866 PRIME is the cross device buffer sharing framework in drm, originally
867 created for the OPTIMUS range of multi-gpu platforms. To userspace
868 PRIME buffers are dma-buf based file descriptors.
869 </para>
870 <sect3>
871 <title>Overview and Driver Interface</title>
872 <para>
873 Similar to GEM global names, PRIME file descriptors are
874 also used to share buffer objects across processes. They offer
875 additional security: as file descriptors must be explicitly sent over
876 UNIX domain sockets to be shared between applications, they can't be
877 guessed like the globally unique GEM names.
878 </para>
879 <para>
880 Drivers that support the PRIME
881 API must set the DRIVER_PRIME bit in the struct
882 <structname>drm_driver</structname>
883 <structfield>driver_features</structfield> field, and implement the
884 <methodname>prime_handle_to_fd</methodname> and
885 <methodname>prime_fd_to_handle</methodname> operations.
886 </para>
887 <para>
888 <synopsis>int (*prime_handle_to_fd)(struct drm_device *dev,
889 struct drm_file *file_priv, uint32_t handle,
890 uint32_t flags, int *prime_fd);
891int (*prime_fd_to_handle)(struct drm_device *dev,
892 struct drm_file *file_priv, int prime_fd,
893 uint32_t *handle);</synopsis>
894 Those two operations convert a handle to a PRIME file descriptor and
895 vice versa. Drivers must use the kernel dma-buf buffer sharing framework
896 to manage the PRIME file descriptors. Similar to the mode setting
897 API PRIME is agnostic to the underlying buffer object manager, as
898 long as handles are 32bit unsigned integers.
899 </para>
900 <para>
901 While non-GEM drivers must implement the operations themselves, GEM
902 drivers must use the <function>drm_gem_prime_handle_to_fd</function>
903 and <function>drm_gem_prime_fd_to_handle</function> helper functions.
904 Those helpers rely on the driver
905 <methodname>gem_prime_export</methodname> and
906 <methodname>gem_prime_import</methodname> operations to create a dma-buf
907 instance from a GEM object (dma-buf exporter role) and to create a GEM
908 object from a dma-buf instance (dma-buf importer role).
909 </para>
910 <para>
911 <synopsis>struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
912 struct drm_gem_object *obj,
913 int flags);
914struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
915 struct dma_buf *dma_buf);</synopsis>
916 These two operations are mandatory for GEM drivers that support
917 PRIME.
918 </para>
919 </sect3>
920 <sect3>
921 <title>PRIME Helper Functions</title>
922!Pdrivers/gpu/drm/drm_prime.c PRIME Helpers
923 </sect3>
924 </sect2>
925 <sect2>
926 <title>PRIME Function References</title>
927!Edrivers/gpu/drm/drm_prime.c
928 </sect2>
929 <sect2>
930 <title>DRM MM Range Allocator</title>
931 <sect3>
932 <title>Overview</title>
933!Pdrivers/gpu/drm/drm_mm.c Overview
934 </sect3>
935 <sect3>
936 <title>LRU Scan/Eviction Support</title>
937!Pdrivers/gpu/drm/drm_mm.c lru scan roaster
938 </sect3>
939 </sect2>
940 <sect2>
941 <title>DRM MM Range Allocator Function References</title>
942!Edrivers/gpu/drm/drm_mm.c
943!Iinclude/drm/drm_mm.h
944 </sect2>
945 <sect2>
946 <title>CMA Helper Functions Reference</title>
947!Pdrivers/gpu/drm/drm_gem_cma_helper.c cma helpers
948!Edrivers/gpu/drm/drm_gem_cma_helper.c
949!Iinclude/drm/drm_gem_cma_helper.h
950 </sect2>
951 </sect1>
952
953 <!-- Internals: mode setting -->
954
955 <sect1 id="drm-mode-setting">
956 <title>Mode Setting</title>
957 <para>
958 Drivers must initialize the mode setting core by calling
959 <function>drm_mode_config_init</function> on the DRM device. The function
960 initializes the <structname>drm_device</structname>
961 <structfield>mode_config</structfield> field and never fails. Once done,
962 mode configuration must be setup by initializing the following fields.
963 </para>
964 <itemizedlist>
965 <listitem>
966 <synopsis>int min_width, min_height;
967int max_width, max_height;</synopsis>
968 <para>
969 Minimum and maximum width and height of the frame buffers in pixel
970 units.
971 </para>
972 </listitem>
973 <listitem>
974 <synopsis>struct drm_mode_config_funcs *funcs;</synopsis>
975 <para>Mode setting functions.</para>
976 </listitem>
977 </itemizedlist>
978 <sect2>
979 <title>Display Modes Function Reference</title>
980!Iinclude/drm/drm_modes.h
981!Edrivers/gpu/drm/drm_modes.c
982 </sect2>
983 <sect2>
984 <title>Atomic Mode Setting Function Reference</title>
985!Edrivers/gpu/drm/drm_atomic.c
986!Idrivers/gpu/drm/drm_atomic.c
987 </sect2>
988 <sect2>
989 <title>Frame Buffer Abstraction</title>
990 <para>
991 Frame buffers are abstract memory objects that provide a source of
992 pixels to scanout to a CRTC. Applications explicitly request the
993 creation of frame buffers through the DRM_IOCTL_MODE_ADDFB(2) ioctls and
994 receive an opaque handle that can be passed to the KMS CRTC control,
995 plane configuration and page flip functions.
996 </para>
997 <para>
998 Frame buffers rely on the underneath memory manager for low-level memory
999 operations. When creating a frame buffer applications pass a memory
1000 handle (or a list of memory handles for multi-planar formats) through
1001 the <parameter>drm_mode_fb_cmd2</parameter> argument. For drivers using
1002 GEM as their userspace buffer management interface this would be a GEM
1003 handle. Drivers are however free to use their own backing storage object
1004 handles, e.g. vmwgfx directly exposes special TTM handles to userspace
1005 and so expects TTM handles in the create ioctl and not GEM handles.
1006 </para>
1007 <para>
1008 The lifetime of a drm framebuffer is controlled with a reference count,
1009 drivers can grab additional references with
1010 <function>drm_framebuffer_reference</function>and drop them
1011 again with <function>drm_framebuffer_unreference</function>. For
1012 driver-private framebuffers for which the last reference is never
1013 dropped (e.g. for the fbdev framebuffer when the struct
1014 <structname>drm_framebuffer</structname> is embedded into the fbdev
1015 helper struct) drivers can manually clean up a framebuffer at module
1016 unload time with
1017 <function>drm_framebuffer_unregister_private</function>.
1018 </para>
1019 </sect2>
1020 <sect2>
1021 <title>DRM Format Handling</title>
1022!Iinclude/drm/drm_fourcc.h
1023!Edrivers/gpu/drm/drm_fourcc.c
1024 </sect2>
1025 <sect2>
1026 <title>Dumb Buffer Objects</title>
1027 <para>
1028 The KMS API doesn't standardize backing storage object creation and
1029 leaves it to driver-specific ioctls. Furthermore actually creating a
1030 buffer object even for GEM-based drivers is done through a
1031 driver-specific ioctl - GEM only has a common userspace interface for
1032 sharing and destroying objects. While not an issue for full-fledged
1033 graphics stacks that include device-specific userspace components (in
1034 libdrm for instance), this limit makes DRM-based early boot graphics
1035 unnecessarily complex.
1036 </para>
1037 <para>
1038 Dumb objects partly alleviate the problem by providing a standard
1039 API to create dumb buffers suitable for scanout, which can then be used
1040 to create KMS frame buffers.
1041 </para>
1042 <para>
1043 To support dumb objects drivers must implement the
1044 <methodname>dumb_create</methodname>,
1045 <methodname>dumb_destroy</methodname> and
1046 <methodname>dumb_map_offset</methodname> operations.
1047 </para>
1048 <itemizedlist>
1049 <listitem>
1050 <synopsis>int (*dumb_create)(struct drm_file *file_priv, struct drm_device *dev,
1051 struct drm_mode_create_dumb *args);</synopsis>
1052 <para>
1053 The <methodname>dumb_create</methodname> operation creates a driver
1054 object (GEM or TTM handle) suitable for scanout based on the
1055 width, height and depth from the struct
1056 <structname>drm_mode_create_dumb</structname> argument. It fills the
1057 argument's <structfield>handle</structfield>,
1058 <structfield>pitch</structfield> and <structfield>size</structfield>
1059 fields with a handle for the newly created object and its line
1060 pitch and size in bytes.
1061 </para>
1062 </listitem>
1063 <listitem>
1064 <synopsis>int (*dumb_destroy)(struct drm_file *file_priv, struct drm_device *dev,
1065 uint32_t handle);</synopsis>
1066 <para>
1067 The <methodname>dumb_destroy</methodname> operation destroys a dumb
1068 object created by <methodname>dumb_create</methodname>.
1069 </para>
1070 </listitem>
1071 <listitem>
1072 <synopsis>int (*dumb_map_offset)(struct drm_file *file_priv, struct drm_device *dev,
1073 uint32_t handle, uint64_t *offset);</synopsis>
1074 <para>
1075 The <methodname>dumb_map_offset</methodname> operation associates an
1076 mmap fake offset with the object given by the handle and returns
1077 it. Drivers must use the
1078 <function>drm_gem_create_mmap_offset</function> function to
1079 associate the fake offset as described in
1080 <xref linkend="drm-gem-objects-mapping"/>.
1081 </para>
1082 </listitem>
1083 </itemizedlist>
1084 <para>
1085 Note that dumb objects may not be used for gpu acceleration, as has been
1086 attempted on some ARM embedded platforms. Such drivers really must have
1087 a hardware-specific ioctl to allocate suitable buffer objects.
1088 </para>
1089 </sect2>
1090 <sect2>
1091 <title>Output Polling</title>
1092 <synopsis>void (*output_poll_changed)(struct drm_device *dev);</synopsis>
1093 <para>
1094 This operation notifies the driver that the status of one or more
1095 connectors has changed. Drivers that use the fb helper can just call the
1096 <function>drm_fb_helper_hotplug_event</function> function to handle this
1097 operation.
1098 </para>
1099 </sect2>
1100 </sect1>
1101
1102 <!-- Internals: kms initialization and cleanup -->
1103
1104 <sect1 id="drm-kms-init">
1105 <title>KMS Initialization and Cleanup</title>
1106 <para>
1107 A KMS device is abstracted and exposed as a set of planes, CRTCs, encoders
1108 and connectors. KMS drivers must thus create and initialize all those
1109 objects at load time after initializing mode setting.
1110 </para>
1111 <sect2>
1112 <title>CRTCs (struct <structname>drm_crtc</structname>)</title>
1113 <para>
1114 A CRTC is an abstraction representing a part of the chip that contains a
1115 pointer to a scanout buffer. Therefore, the number of CRTCs available
1116 determines how many independent scanout buffers can be active at any
1117 given time. The CRTC structure contains several fields to support this:
1118 a pointer to some video memory (abstracted as a frame buffer object), a
1119 display mode, and an (x, y) offset into the video memory to support
1120 panning or configurations where one piece of video memory spans multiple
1121 CRTCs.
1122 </para>
1123 <sect3>
1124 <title>CRTC Initialization</title>
1125 <para>
1126 A KMS device must create and register at least one struct
1127 <structname>drm_crtc</structname> instance. The instance is allocated
1128 and zeroed by the driver, possibly as part of a larger structure, and
1129 registered with a call to <function>drm_crtc_init</function> with a
1130 pointer to CRTC functions.
1131 </para>
1132 </sect3>
1133 </sect2>
1134 <sect2>
1135 <title>Planes (struct <structname>drm_plane</structname>)</title>
1136 <para>
1137 A plane represents an image source that can be blended with or overlayed
1138 on top of a CRTC during the scanout process. Planes are associated with
1139 a frame buffer to crop a portion of the image memory (source) and
1140 optionally scale it to a destination size. The result is then blended
1141 with or overlayed on top of a CRTC.
1142 </para>
1143 <para>
1144 The DRM core recognizes three types of planes:
1145 <itemizedlist>
1146 <listitem>
1147 DRM_PLANE_TYPE_PRIMARY represents a "main" plane for a CRTC. Primary
1148 planes are the planes operated upon by CRTC modesetting and flipping
1149 operations described in the page_flip hook in <structname>drm_crtc_funcs</structname>.
1150 </listitem>
1151 <listitem>
1152 DRM_PLANE_TYPE_CURSOR represents a "cursor" plane for a CRTC. Cursor
1153 planes are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and
1154 DRM_IOCTL_MODE_CURSOR2 ioctls.
1155 </listitem>
1156 <listitem>
1157 DRM_PLANE_TYPE_OVERLAY represents all non-primary, non-cursor planes.
1158 Some drivers refer to these types of planes as "sprites" internally.
1159 </listitem>
1160 </itemizedlist>
1161 For compatibility with legacy userspace, only overlay planes are made
1162 available to userspace by default. Userspace clients may set the
1163 DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that
1164 they wish to receive a universal plane list containing all plane types.
1165 </para>
1166 <sect3>
1167 <title>Plane Initialization</title>
1168 <para>
1169 To create a plane, a KMS drivers allocates and
1170 zeroes an instances of struct <structname>drm_plane</structname>
1171 (possibly as part of a larger structure) and registers it with a call
1172 to <function>drm_universal_plane_init</function>. The function takes a bitmask
1173 of the CRTCs that can be associated with the plane, a pointer to the
1174 plane functions, a list of format supported formats, and the type of
1175 plane (primary, cursor, or overlay) being initialized.
1176 </para>
1177 <para>
1178 Cursor and overlay planes are optional. All drivers should provide
1179 one primary plane per CRTC (although this requirement may change in
1180 the future); drivers that do not wish to provide special handling for
1181 primary planes may make use of the helper functions described in
1182 <xref linkend="drm-kms-planehelpers"/> to create and register a
1183 primary plane with standard capabilities.
1184 </para>
1185 </sect3>
1186 </sect2>
1187 <sect2>
1188 <title>Encoders (struct <structname>drm_encoder</structname>)</title>
1189 <para>
1190 An encoder takes pixel data from a CRTC and converts it to a format
1191 suitable for any attached connectors. On some devices, it may be
1192 possible to have a CRTC send data to more than one encoder. In that
1193 case, both encoders would receive data from the same scanout buffer,
1194 resulting in a "cloned" display configuration across the connectors
1195 attached to each encoder.
1196 </para>
1197 <sect3>
1198 <title>Encoder Initialization</title>
1199 <para>
1200 As for CRTCs, a KMS driver must create, initialize and register at
1201 least one struct <structname>drm_encoder</structname> instance. The
1202 instance is allocated and zeroed by the driver, possibly as part of a
1203 larger structure.
1204 </para>
1205 <para>
1206 Drivers must initialize the struct <structname>drm_encoder</structname>
1207 <structfield>possible_crtcs</structfield> and
1208 <structfield>possible_clones</structfield> fields before registering the
1209 encoder. Both fields are bitmasks of respectively the CRTCs that the
1210 encoder can be connected to, and sibling encoders candidate for cloning.
1211 </para>
1212 <para>
1213 After being initialized, the encoder must be registered with a call to
1214 <function>drm_encoder_init</function>. The function takes a pointer to
1215 the encoder functions and an encoder type. Supported types are
1216 <itemizedlist>
1217 <listitem>
1218 DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A
1219 </listitem>
1220 <listitem>
1221 DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort
1222 </listitem>
1223 <listitem>
1224 DRM_MODE_ENCODER_LVDS for display panels
1225 </listitem>
1226 <listitem>
1227 DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video, Component,
1228 SCART)
1229 </listitem>
1230 <listitem>
1231 DRM_MODE_ENCODER_VIRTUAL for virtual machine displays
1232 </listitem>
1233 </itemizedlist>
1234 </para>
1235 <para>
1236 Encoders must be attached to a CRTC to be used. DRM drivers leave
1237 encoders unattached at initialization time. Applications (or the fbdev
1238 compatibility layer when implemented) are responsible for attaching the
1239 encoders they want to use to a CRTC.
1240 </para>
1241 </sect3>
1242 </sect2>
1243 <sect2>
1244 <title>Connectors (struct <structname>drm_connector</structname>)</title>
1245 <para>
1246 A connector is the final destination for pixel data on a device, and
1247 usually connects directly to an external display device like a monitor
1248 or laptop panel. A connector can only be attached to one encoder at a
1249 time. The connector is also the structure where information about the
1250 attached display is kept, so it contains fields for display data, EDID
1251 data, DPMS &amp; connection status, and information about modes
1252 supported on the attached displays.
1253 </para>
1254 <sect3>
1255 <title>Connector Initialization</title>
1256 <para>
1257 Finally a KMS driver must create, initialize, register and attach at
1258 least one struct <structname>drm_connector</structname> instance. The
1259 instance is created as other KMS objects and initialized by setting the
1260 following fields.
1261 </para>
1262 <variablelist>
1263 <varlistentry>
1264 <term><structfield>interlace_allowed</structfield></term>
1265 <listitem><para>
1266 Whether the connector can handle interlaced modes.
1267 </para></listitem>
1268 </varlistentry>
1269 <varlistentry>
1270 <term><structfield>doublescan_allowed</structfield></term>
1271 <listitem><para>
1272 Whether the connector can handle doublescan.
1273 </para></listitem>
1274 </varlistentry>
1275 <varlistentry>
1276 <term><structfield>display_info
1277 </structfield></term>
1278 <listitem><para>
1279 Display information is filled from EDID information when a display
1280 is detected. For non hot-pluggable displays such as flat panels in
1281 embedded systems, the driver should initialize the
1282 <structfield>display_info</structfield>.<structfield>width_mm</structfield>
1283 and
1284 <structfield>display_info</structfield>.<structfield>height_mm</structfield>
1285 fields with the physical size of the display.
1286 </para></listitem>
1287 </varlistentry>
1288 <varlistentry>
1289 <term id="drm-kms-connector-polled"><structfield>polled</structfield></term>
1290 <listitem><para>
1291 Connector polling mode, a combination of
1292 <variablelist>
1293 <varlistentry>
1294 <term>DRM_CONNECTOR_POLL_HPD</term>
1295 <listitem><para>
1296 The connector generates hotplug events and doesn't need to be
1297 periodically polled. The CONNECT and DISCONNECT flags must not
1298 be set together with the HPD flag.
1299 </para></listitem>
1300 </varlistentry>
1301 <varlistentry>
1302 <term>DRM_CONNECTOR_POLL_CONNECT</term>
1303 <listitem><para>
1304 Periodically poll the connector for connection.
1305 </para></listitem>
1306 </varlistentry>
1307 <varlistentry>
1308 <term>DRM_CONNECTOR_POLL_DISCONNECT</term>
1309 <listitem><para>
1310 Periodically poll the connector for disconnection.
1311 </para></listitem>
1312 </varlistentry>
1313 </variablelist>
1314 Set to 0 for connectors that don't support connection status
1315 discovery.
1316 </para></listitem>
1317 </varlistentry>
1318 </variablelist>
1319 <para>
1320 The connector is then registered with a call to
1321 <function>drm_connector_init</function> with a pointer to the connector
1322 functions and a connector type, and exposed through sysfs with a call to
1323 <function>drm_connector_register</function>.
1324 </para>
1325 <para>
1326 Supported connector types are
1327 <itemizedlist>
1328 <listitem>DRM_MODE_CONNECTOR_VGA</listitem>
1329 <listitem>DRM_MODE_CONNECTOR_DVII</listitem>
1330 <listitem>DRM_MODE_CONNECTOR_DVID</listitem>
1331 <listitem>DRM_MODE_CONNECTOR_DVIA</listitem>
1332 <listitem>DRM_MODE_CONNECTOR_Composite</listitem>
1333 <listitem>DRM_MODE_CONNECTOR_SVIDEO</listitem>
1334 <listitem>DRM_MODE_CONNECTOR_LVDS</listitem>
1335 <listitem>DRM_MODE_CONNECTOR_Component</listitem>
1336 <listitem>DRM_MODE_CONNECTOR_9PinDIN</listitem>
1337 <listitem>DRM_MODE_CONNECTOR_DisplayPort</listitem>
1338 <listitem>DRM_MODE_CONNECTOR_HDMIA</listitem>
1339 <listitem>DRM_MODE_CONNECTOR_HDMIB</listitem>
1340 <listitem>DRM_MODE_CONNECTOR_TV</listitem>
1341 <listitem>DRM_MODE_CONNECTOR_eDP</listitem>
1342 <listitem>DRM_MODE_CONNECTOR_VIRTUAL</listitem>
1343 </itemizedlist>
1344 </para>
1345 <para>
1346 Connectors must be attached to an encoder to be used. For devices that
1347 map connectors to encoders 1:1, the connector should be attached at
1348 initialization time with a call to
1349 <function>drm_mode_connector_attach_encoder</function>. The driver must
1350 also set the <structname>drm_connector</structname>
1351 <structfield>encoder</structfield> field to point to the attached
1352 encoder.
1353 </para>
1354 <para>
1355 Finally, drivers must initialize the connectors state change detection
1356 with a call to <function>drm_kms_helper_poll_init</function>. If at
1357 least one connector is pollable but can't generate hotplug interrupts
1358 (indicated by the DRM_CONNECTOR_POLL_CONNECT and
1359 DRM_CONNECTOR_POLL_DISCONNECT connector flags), a delayed work will
1360 automatically be queued to periodically poll for changes. Connectors
1361 that can generate hotplug interrupts must be marked with the
1362 DRM_CONNECTOR_POLL_HPD flag instead, and their interrupt handler must
1363 call <function>drm_helper_hpd_irq_event</function>. The function will
1364 queue a delayed work to check the state of all connectors, but no
1365 periodic polling will be done.
1366 </para>
1367 </sect3>
1368 <sect3>
1369 <title>Connector Operations</title>
1370 <note><para>
1371 Unless otherwise state, all operations are mandatory.
1372 </para></note>
1373 <sect4>
1374 <title>DPMS</title>
1375 <synopsis>void (*dpms)(struct drm_connector *connector, int mode);</synopsis>
1376 <para>
1377 The DPMS operation sets the power state of a connector. The mode
1378 argument is one of
1379 <itemizedlist>
1380 <listitem><para>DRM_MODE_DPMS_ON</para></listitem>
1381 <listitem><para>DRM_MODE_DPMS_STANDBY</para></listitem>
1382 <listitem><para>DRM_MODE_DPMS_SUSPEND</para></listitem>
1383 <listitem><para>DRM_MODE_DPMS_OFF</para></listitem>
1384 </itemizedlist>
1385 </para>
1386 <para>
1387 In all but DPMS_ON mode the encoder to which the connector is attached
1388 should put the display in low-power mode by driving its signals
1389 appropriately. If more than one connector is attached to the encoder
1390 care should be taken not to change the power state of other displays as
1391 a side effect. Low-power mode should be propagated to the encoders and
1392 CRTCs when all related connectors are put in low-power mode.
1393 </para>
1394 </sect4>
1395 <sect4>
1396 <title>Modes</title>
1397 <synopsis>int (*fill_modes)(struct drm_connector *connector, uint32_t max_width,
1398 uint32_t max_height);</synopsis>
1399 <para>
1400 Fill the mode list with all supported modes for the connector. If the
1401 <parameter>max_width</parameter> and <parameter>max_height</parameter>
1402 arguments are non-zero, the implementation must ignore all modes wider
1403 than <parameter>max_width</parameter> or higher than
1404 <parameter>max_height</parameter>.
1405 </para>
1406 <para>
1407 The connector must also fill in this operation its
1408 <structfield>display_info</structfield>
1409 <structfield>width_mm</structfield> and
1410 <structfield>height_mm</structfield> fields with the connected display
1411 physical size in millimeters. The fields should be set to 0 if the value
1412 isn't known or is not applicable (for instance for projector devices).
1413 </para>
1414 </sect4>
1415 <sect4>
1416 <title>Connection Status</title>
1417 <para>
1418 The connection status is updated through polling or hotplug events when
1419 supported (see <xref linkend="drm-kms-connector-polled"/>). The status
1420 value is reported to userspace through ioctls and must not be used
1421 inside the driver, as it only gets initialized by a call to
1422 <function>drm_mode_getconnector</function> from userspace.
1423 </para>
1424 <synopsis>enum drm_connector_status (*detect)(struct drm_connector *connector,
1425 bool force);</synopsis>
1426 <para>
1427 Check to see if anything is attached to the connector. The
1428 <parameter>force</parameter> parameter is set to false whilst polling or
1429 to true when checking the connector due to user request.
1430 <parameter>force</parameter> can be used by the driver to avoid
1431 expensive, destructive operations during automated probing.
1432 </para>
1433 <para>
1434 Return connector_status_connected if something is connected to the
1435 connector, connector_status_disconnected if nothing is connected and
1436 connector_status_unknown if the connection state isn't known.
1437 </para>
1438 <para>
1439 Drivers should only return connector_status_connected if the connection
1440 status has really been probed as connected. Connectors that can't detect
1441 the connection status, or failed connection status probes, should return
1442 connector_status_unknown.
1443 </para>
1444 </sect4>
1445 </sect3>
1446 </sect2>
1447 <sect2>
1448 <title>Cleanup</title>
1449 <para>
1450 The DRM core manages its objects' lifetime. When an object is not needed
1451 anymore the core calls its destroy function, which must clean up and
1452 free every resource allocated for the object. Every
1453 <function>drm_*_init</function> call must be matched with a
1454 corresponding <function>drm_*_cleanup</function> call to cleanup CRTCs
1455 (<function>drm_crtc_cleanup</function>), planes
1456 (<function>drm_plane_cleanup</function>), encoders
1457 (<function>drm_encoder_cleanup</function>) and connectors
1458 (<function>drm_connector_cleanup</function>). Furthermore, connectors
1459 that have been added to sysfs must be removed by a call to
1460 <function>drm_connector_unregister</function> before calling
1461 <function>drm_connector_cleanup</function>.
1462 </para>
1463 <para>
1464 Connectors state change detection must be cleanup up with a call to
1465 <function>drm_kms_helper_poll_fini</function>.
1466 </para>
1467 </sect2>
1468 <sect2>
1469 <title>Output discovery and initialization example</title>
1470 <programlisting><![CDATA[
1471void intel_crt_init(struct drm_device *dev)
1472{
1473 struct drm_connector *connector;
1474 struct intel_output *intel_output;
1475
1476 intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
1477 if (!intel_output)
1478 return;
1479
1480 connector = &intel_output->base;
1481 drm_connector_init(dev, &intel_output->base,
1482 &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
1483
1484 drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs,
1485 DRM_MODE_ENCODER_DAC);
1486
1487 drm_mode_connector_attach_encoder(&intel_output->base,
1488 &intel_output->enc);
1489
1490 /* Set up the DDC bus. */
1491 intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A");
1492 if (!intel_output->ddc_bus) {
1493 dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
1494 "failed.\n");
1495 return;
1496 }
1497
1498 intel_output->type = INTEL_OUTPUT_ANALOG;
1499 connector->interlace_allowed = 0;
1500 connector->doublescan_allowed = 0;
1501
1502 drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs);
1503 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
1504
1505 drm_connector_register(connector);
1506}]]></programlisting>
1507 <para>
1508 In the example above (taken from the i915 driver), a CRTC, connector and
1509 encoder combination is created. A device-specific i2c bus is also
1510 created for fetching EDID data and performing monitor detection. Once
1511 the process is complete, the new connector is registered with sysfs to
1512 make its properties available to applications.
1513 </para>
1514 </sect2>
1515 <sect2>
1516 <title>KMS API Functions</title>
1517!Edrivers/gpu/drm/drm_crtc.c
1518 </sect2>
1519 <sect2>
1520 <title>KMS Data Structures</title>
1521!Iinclude/drm/drm_crtc.h
1522 </sect2>
1523 <sect2>
1524 <title>KMS Locking</title>
1525!Pdrivers/gpu/drm/drm_modeset_lock.c kms locking
1526!Iinclude/drm/drm_modeset_lock.h
1527!Edrivers/gpu/drm/drm_modeset_lock.c
1528 </sect2>
1529 </sect1>
1530
1531 <!-- Internals: kms helper functions -->
1532
1533 <sect1>
1534 <title>Mode Setting Helper Functions</title>
1535 <para>
1536 The plane, CRTC, encoder and connector functions provided by the drivers
1537 implement the DRM API. They're called by the DRM core and ioctl handlers
1538 to handle device state changes and configuration request. As implementing
1539 those functions often requires logic not specific to drivers, mid-layer
1540 helper functions are available to avoid duplicating boilerplate code.
1541 </para>
1542 <para>
1543 The DRM core contains one mid-layer implementation. The mid-layer provides
1544 implementations of several plane, CRTC, encoder and connector functions
1545 (called from the top of the mid-layer) that pre-process requests and call
1546 lower-level functions provided by the driver (at the bottom of the
1547 mid-layer). For instance, the
1548 <function>drm_crtc_helper_set_config</function> function can be used to
1549 fill the struct <structname>drm_crtc_funcs</structname>
1550 <structfield>set_config</structfield> field. When called, it will split
1551 the <methodname>set_config</methodname> operation in smaller, simpler
1552 operations and call the driver to handle them.
1553 </para>
1554 <para>
1555 To use the mid-layer, drivers call <function>drm_crtc_helper_add</function>,
1556 <function>drm_encoder_helper_add</function> and
1557 <function>drm_connector_helper_add</function> functions to install their
1558 mid-layer bottom operations handlers, and fill the
1559 <structname>drm_crtc_funcs</structname>,
1560 <structname>drm_encoder_funcs</structname> and
1561 <structname>drm_connector_funcs</structname> structures with pointers to
1562 the mid-layer top API functions. Installing the mid-layer bottom operation
1563 handlers is best done right after registering the corresponding KMS object.
1564 </para>
1565 <para>
1566 The mid-layer is not split between CRTC, encoder and connector operations.
1567 To use it, a driver must provide bottom functions for all of the three KMS
1568 entities.
1569 </para>
1570 <sect2>
1571 <title>Atomic Modeset Helper Functions Reference</title>
1572 <sect3>
1573 <title>Overview</title>
1574!Pdrivers/gpu/drm/drm_atomic_helper.c overview
1575 </sect3>
1576 <sect3>
1577 <title>Implementing Asynchronous Atomic Commit</title>
1578!Pdrivers/gpu/drm/drm_atomic_helper.c implementing nonblocking commit
1579 </sect3>
1580 <sect3>
1581 <title>Atomic State Reset and Initialization</title>
1582!Pdrivers/gpu/drm/drm_atomic_helper.c atomic state reset and initialization
1583 </sect3>
1584!Iinclude/drm/drm_atomic_helper.h
1585!Edrivers/gpu/drm/drm_atomic_helper.c
1586 </sect2>
1587 <sect2>
1588 <title>Modeset Helper Reference for Common Vtables</title>
1589!Iinclude/drm/drm_modeset_helper_vtables.h
1590!Pinclude/drm/drm_modeset_helper_vtables.h overview
1591 </sect2>
1592 <sect2>
1593 <title>Legacy CRTC/Modeset Helper Functions Reference</title>
1594!Edrivers/gpu/drm/drm_crtc_helper.c
1595!Pdrivers/gpu/drm/drm_crtc_helper.c overview
1596 </sect2>
1597 <sect2>
1598 <title>Output Probing Helper Functions Reference</title>
1599!Pdrivers/gpu/drm/drm_probe_helper.c output probing helper overview
1600!Edrivers/gpu/drm/drm_probe_helper.c
1601 </sect2>
1602 <sect2>
1603 <title>fbdev Helper Functions Reference</title>
1604!Pdrivers/gpu/drm/drm_fb_helper.c fbdev helpers
1605!Edrivers/gpu/drm/drm_fb_helper.c
1606!Iinclude/drm/drm_fb_helper.h
1607 </sect2>
1608 <sect2>
1609 <title>Framebuffer CMA Helper Functions Reference</title>
1610!Pdrivers/gpu/drm/drm_fb_cma_helper.c framebuffer cma helper functions
1611!Edrivers/gpu/drm/drm_fb_cma_helper.c
1612 </sect2>
1613 <sect2>
1614 <title>Display Port Helper Functions Reference</title>
1615!Pdrivers/gpu/drm/drm_dp_helper.c dp helpers
1616!Iinclude/drm/drm_dp_helper.h
1617!Edrivers/gpu/drm/drm_dp_helper.c
1618 </sect2>
1619 <sect2>
1620 <title>Display Port Dual Mode Adaptor Helper Functions Reference</title>
1621!Pdrivers/gpu/drm/drm_dp_dual_mode_helper.c dp dual mode helpers
1622!Iinclude/drm/drm_dp_dual_mode_helper.h
1623!Edrivers/gpu/drm/drm_dp_dual_mode_helper.c
1624 </sect2>
1625 <sect2>
1626 <title>Display Port MST Helper Functions Reference</title>
1627!Pdrivers/gpu/drm/drm_dp_mst_topology.c dp mst helper
1628!Iinclude/drm/drm_dp_mst_helper.h
1629!Edrivers/gpu/drm/drm_dp_mst_topology.c
1630 </sect2>
1631 <sect2>
1632 <title>MIPI DSI Helper Functions Reference</title>
1633!Pdrivers/gpu/drm/drm_mipi_dsi.c dsi helpers
1634!Iinclude/drm/drm_mipi_dsi.h
1635!Edrivers/gpu/drm/drm_mipi_dsi.c
1636 </sect2>
1637 <sect2>
1638 <title>EDID Helper Functions Reference</title>
1639!Edrivers/gpu/drm/drm_edid.c
1640 </sect2>
1641 <sect2>
1642 <title>Rectangle Utilities Reference</title>
1643!Pinclude/drm/drm_rect.h rect utils
1644!Iinclude/drm/drm_rect.h
1645!Edrivers/gpu/drm/drm_rect.c
1646 </sect2>
1647 <sect2>
1648 <title>Flip-work Helper Reference</title>
1649!Pinclude/drm/drm_flip_work.h flip utils
1650!Iinclude/drm/drm_flip_work.h
1651!Edrivers/gpu/drm/drm_flip_work.c
1652 </sect2>
1653 <sect2>
1654 <title>HDMI Infoframes Helper Reference</title>
1655 <para>
1656 Strictly speaking this is not a DRM helper library but generally useable
1657 by any driver interfacing with HDMI outputs like v4l or alsa drivers.
1658 But it nicely fits into the overall topic of mode setting helper
1659 libraries and hence is also included here.
1660 </para>
1661!Iinclude/linux/hdmi.h
1662!Edrivers/video/hdmi.c
1663 </sect2>
1664 <sect2>
1665 <title id="drm-kms-planehelpers">Plane Helper Reference</title>
1666!Edrivers/gpu/drm/drm_plane_helper.c
1667!Pdrivers/gpu/drm/drm_plane_helper.c overview
1668 </sect2>
1669 <sect2>
1670 <title>Tile group</title>
1671!Pdrivers/gpu/drm/drm_crtc.c Tile group
1672 </sect2>
1673 <sect2>
1674 <title>Bridges</title>
1675 <sect3>
1676 <title>Overview</title>
1677!Pdrivers/gpu/drm/drm_bridge.c overview
1678 </sect3>
1679 <sect3>
1680 <title>Default bridge callback sequence</title>
1681!Pdrivers/gpu/drm/drm_bridge.c bridge callbacks
1682 </sect3>
1683!Edrivers/gpu/drm/drm_bridge.c
1684 </sect2>
1685 <sect2>
1686 <title>Panel Helper Reference</title>
1687!Iinclude/drm/drm_panel.h
1688!Edrivers/gpu/drm/drm_panel.c
1689!Pdrivers/gpu/drm/drm_panel.c drm panel
1690 </sect2>
1691 <sect2>
1692 <title>Simple KMS Helper Reference</title>
1693!Iinclude/drm/drm_simple_kms_helper.h
1694!Edrivers/gpu/drm/drm_simple_kms_helper.c
1695!Pdrivers/gpu/drm/drm_simple_kms_helper.c overview
1696 </sect2>
1697 </sect1>
1698
1699 <!-- Internals: kms properties -->
1700
1701 <sect1 id="drm-kms-properties">
1702 <title>KMS Properties</title>
1703 <para>
1704 Drivers may need to expose additional parameters to applications than
1705 those described in the previous sections. KMS supports attaching
1706 properties to CRTCs, connectors and planes and offers a userspace API to
1707 list, get and set the property values.
1708 </para>
1709 <para>
1710 Properties are identified by a name that uniquely defines the property
1711 purpose, and store an associated value. For all property types except blob
1712 properties the value is a 64-bit unsigned integer.
1713 </para>
1714 <para>
1715 KMS differentiates between properties and property instances. Drivers
1716 first create properties and then create and associate individual instances
1717 of those properties to objects. A property can be instantiated multiple
1718 times and associated with different objects. Values are stored in property
1719 instances, and all other property information are stored in the property
1720 and shared between all instances of the property.
1721 </para>
1722 <para>
1723 Every property is created with a type that influences how the KMS core
1724 handles the property. Supported property types are
1725 <variablelist>
1726 <varlistentry>
1727 <term>DRM_MODE_PROP_RANGE</term>
1728 <listitem><para>Range properties report their minimum and maximum
1729 admissible values. The KMS core verifies that values set by
1730 application fit in that range.</para></listitem>
1731 </varlistentry>
1732 <varlistentry>
1733 <term>DRM_MODE_PROP_ENUM</term>
1734 <listitem><para>Enumerated properties take a numerical value that
1735 ranges from 0 to the number of enumerated values defined by the
1736 property minus one, and associate a free-formed string name to each
1737 value. Applications can retrieve the list of defined value-name pairs
1738 and use the numerical value to get and set property instance values.
1739 </para></listitem>
1740 </varlistentry>
1741 <varlistentry>
1742 <term>DRM_MODE_PROP_BITMASK</term>
1743 <listitem><para>Bitmask properties are enumeration properties that
1744 additionally restrict all enumerated values to the 0..63 range.
1745 Bitmask property instance values combine one or more of the
1746 enumerated bits defined by the property.</para></listitem>
1747 </varlistentry>
1748 <varlistentry>
1749 <term>DRM_MODE_PROP_BLOB</term>
1750 <listitem><para>Blob properties store a binary blob without any format
1751 restriction. The binary blobs are created as KMS standalone objects,
1752 and blob property instance values store the ID of their associated
1753 blob object.</para>
1754 <para>Blob properties are only used for the connector EDID property
1755 and cannot be created by drivers.</para></listitem>
1756 </varlistentry>
1757 </variablelist>
1758 </para>
1759 <para>
1760 To create a property drivers call one of the following functions depending
1761 on the property type. All property creation functions take property flags
1762 and name, as well as type-specific arguments.
1763 <itemizedlist>
1764 <listitem>
1765 <synopsis>struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
1766 const char *name,
1767 uint64_t min, uint64_t max);</synopsis>
1768 <para>Create a range property with the given minimum and maximum
1769 values.</para>
1770 </listitem>
1771 <listitem>
1772 <synopsis>struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
1773 const char *name,
1774 const struct drm_prop_enum_list *props,
1775 int num_values);</synopsis>
1776 <para>Create an enumerated property. The <parameter>props</parameter>
1777 argument points to an array of <parameter>num_values</parameter>
1778 value-name pairs.</para>
1779 </listitem>
1780 <listitem>
1781 <synopsis>struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
1782 int flags, const char *name,
1783 const struct drm_prop_enum_list *props,
1784 int num_values);</synopsis>
1785 <para>Create a bitmask property. The <parameter>props</parameter>
1786 argument points to an array of <parameter>num_values</parameter>
1787 value-name pairs.</para>
1788 </listitem>
1789 </itemizedlist>
1790 </para>
1791 <para>
1792 Properties can additionally be created as immutable, in which case they
1793 will be read-only for applications but can be modified by the driver. To
1794 create an immutable property drivers must set the DRM_MODE_PROP_IMMUTABLE
1795 flag at property creation time.
1796 </para>
1797 <para>
1798 When no array of value-name pairs is readily available at property
1799 creation time for enumerated or range properties, drivers can create
1800 the property using the <function>drm_property_create</function> function
1801 and manually add enumeration value-name pairs by calling the
1802 <function>drm_property_add_enum</function> function. Care must be taken to
1803 properly specify the property type through the <parameter>flags</parameter>
1804 argument.
1805 </para>
1806 <para>
1807 After creating properties drivers can attach property instances to CRTC,
1808 connector and plane objects by calling the
1809 <function>drm_object_attach_property</function>. The function takes a
1810 pointer to the target object, a pointer to the previously created property
1811 and an initial instance value.
1812 </para>
1813 <sect2>
1814 <title>Existing KMS Properties</title>
1815 <para>
1816 The following table gives description of drm properties exposed by various
1817 modules/drivers.
1818 </para>
1819 <table border="1" cellpadding="0" cellspacing="0">
1820 <tbody>
1821 <tr style="font-weight: bold;">
1822 <td valign="top" >Owner Module/Drivers</td>
1823 <td valign="top" >Group</td>
1824 <td valign="top" >Property Name</td>
1825 <td valign="top" >Type</td>
1826 <td valign="top" >Property Values</td>
1827 <td valign="top" >Object attached</td>
1828 <td valign="top" >Description/Restrictions</td>
1829 </tr>
1830 <tr>
1831 <td rowspan="42" valign="top" >DRM</td>
1832 <td rowspan="2" valign="top" >Generic</td>
1833 <td valign="top" >“rotation”</td>
1834 <td valign="top" >BITMASK</td>
1835 <td valign="top" >{ 0, "rotate-0" },
1836 { 1, "rotate-90" },
1837 { 2, "rotate-180" },
1838 { 3, "rotate-270" },
1839 { 4, "reflect-x" },
1840 { 5, "reflect-y" }</td>
1841 <td valign="top" >CRTC, Plane</td>
1842 <td valign="top" >rotate-(degrees) rotates the image by the specified amount in degrees
1843 in counter clockwise direction. reflect-x and reflect-y reflects the
1844 image along the specified axis prior to rotation</td>
1845 </tr>
1846 <tr>
1847 <td valign="top" >“scaling mode”</td>
1848 <td valign="top" >ENUM</td>
1849 <td valign="top" >{ "None", "Full", "Center", "Full aspect" }</td>
1850 <td valign="top" >Connector</td>
1851 <td valign="top" >Supported by: amdgpu, gma500, i915, nouveau and radeon.</td>
1852 </tr>
1853 <tr>
1854 <td rowspan="5" valign="top" >Connector</td>
1855 <td valign="top" >“EDID”</td>
1856 <td valign="top" >BLOB | IMMUTABLE</td>
1857 <td valign="top" >0</td>
1858 <td valign="top" >Connector</td>
1859 <td valign="top" >Contains id of edid blob ptr object.</td>
1860 </tr>
1861 <tr>
1862 <td valign="top" >“DPMS”</td>
1863 <td valign="top" >ENUM</td>
1864 <td valign="top" >{ “On”, “Standby”, “Suspend”, “Off” }</td>
1865 <td valign="top" >Connector</td>
1866 <td valign="top" >Contains DPMS operation mode value.</td>
1867 </tr>
1868 <tr>
1869 <td valign="top" >“PATH”</td>
1870 <td valign="top" >BLOB | IMMUTABLE</td>
1871 <td valign="top" >0</td>
1872 <td valign="top" >Connector</td>
1873 <td valign="top" >Contains topology path to a connector.</td>
1874 </tr>
1875 <tr>
1876 <td valign="top" >“TILE”</td>
1877 <td valign="top" >BLOB | IMMUTABLE</td>
1878 <td valign="top" >0</td>
1879 <td valign="top" >Connector</td>
1880 <td valign="top" >Contains tiling information for a connector.</td>
1881 </tr>
1882 <tr>
1883 <td valign="top" >“CRTC_ID”</td>
1884 <td valign="top" >OBJECT</td>
1885 <td valign="top" >DRM_MODE_OBJECT_CRTC</td>
1886 <td valign="top" >Connector</td>
1887 <td valign="top" >CRTC that connector is attached to (atomic)</td>
1888 </tr>
1889 <tr>
1890 <td rowspan="11" valign="top" >Plane</td>
1891 <td valign="top" >“type”</td>
1892 <td valign="top" >ENUM | IMMUTABLE</td>
1893 <td valign="top" >{ "Overlay", "Primary", "Cursor" }</td>
1894 <td valign="top" >Plane</td>
1895 <td valign="top" >Plane type</td>
1896 </tr>
1897 <tr>
1898 <td valign="top" >“SRC_X”</td>
1899 <td valign="top" >RANGE</td>
1900 <td valign="top" >Min=0, Max=UINT_MAX</td>
1901 <td valign="top" >Plane</td>
1902 <td valign="top" >Scanout source x coordinate in 16.16 fixed point (atomic)</td>
1903 </tr>
1904 <tr>
1905 <td valign="top" >“SRC_Y”</td>
1906 <td valign="top" >RANGE</td>
1907 <td valign="top" >Min=0, Max=UINT_MAX</td>
1908 <td valign="top" >Plane</td>
1909 <td valign="top" >Scanout source y coordinate in 16.16 fixed point (atomic)</td>
1910 </tr>
1911 <tr>
1912 <td valign="top" >“SRC_W”</td>
1913 <td valign="top" >RANGE</td>
1914 <td valign="top" >Min=0, Max=UINT_MAX</td>
1915 <td valign="top" >Plane</td>
1916 <td valign="top" >Scanout source width in 16.16 fixed point (atomic)</td>
1917 </tr>
1918 <tr>
1919 <td valign="top" >“SRC_H”</td>
1920 <td valign="top" >RANGE</td>
1921 <td valign="top" >Min=0, Max=UINT_MAX</td>
1922 <td valign="top" >Plane</td>
1923 <td valign="top" >Scanout source height in 16.16 fixed point (atomic)</td>
1924 </tr>
1925 <tr>
1926 <td valign="top" >“CRTC_X”</td>
1927 <td valign="top" >SIGNED_RANGE</td>
1928 <td valign="top" >Min=INT_MIN, Max=INT_MAX</td>
1929 <td valign="top" >Plane</td>
1930 <td valign="top" >Scanout CRTC (destination) x coordinate (atomic)</td>
1931 </tr>
1932 <tr>
1933 <td valign="top" >“CRTC_Y”</td>
1934 <td valign="top" >SIGNED_RANGE</td>
1935 <td valign="top" >Min=INT_MIN, Max=INT_MAX</td>
1936 <td valign="top" >Plane</td>
1937 <td valign="top" >Scanout CRTC (destination) y coordinate (atomic)</td>
1938 </tr>
1939 <tr>
1940 <td valign="top" >“CRTC_W”</td>
1941 <td valign="top" >RANGE</td>
1942 <td valign="top" >Min=0, Max=UINT_MAX</td>
1943 <td valign="top" >Plane</td>
1944 <td valign="top" >Scanout CRTC (destination) width (atomic)</td>
1945 </tr>
1946 <tr>
1947 <td valign="top" >“CRTC_H”</td>
1948 <td valign="top" >RANGE</td>
1949 <td valign="top" >Min=0, Max=UINT_MAX</td>
1950 <td valign="top" >Plane</td>
1951 <td valign="top" >Scanout CRTC (destination) height (atomic)</td>
1952 </tr>
1953 <tr>
1954 <td valign="top" >“FB_ID”</td>
1955 <td valign="top" >OBJECT</td>
1956 <td valign="top" >DRM_MODE_OBJECT_FB</td>
1957 <td valign="top" >Plane</td>
1958 <td valign="top" >Scanout framebuffer (atomic)</td>
1959 </tr>
1960 <tr>
1961 <td valign="top" >“CRTC_ID”</td>
1962 <td valign="top" >OBJECT</td>
1963 <td valign="top" >DRM_MODE_OBJECT_CRTC</td>
1964 <td valign="top" >Plane</td>
1965 <td valign="top" >CRTC that plane is attached to (atomic)</td>
1966 </tr>
1967 <tr>
1968 <td rowspan="2" valign="top" >DVI-I</td>
1969 <td valign="top" >“subconnector”</td>
1970 <td valign="top" >ENUM</td>
1971 <td valign="top" >{ “Unknown”, “DVI-D”, “DVI-A” }</td>
1972 <td valign="top" >Connector</td>
1973 <td valign="top" >TBD</td>
1974 </tr>
1975 <tr>
1976 <td valign="top" >“select subconnector”</td>
1977 <td valign="top" >ENUM</td>
1978 <td valign="top" >{ “Automatic”, “DVI-D”, “DVI-A” }</td>
1979 <td valign="top" >Connector</td>
1980 <td valign="top" >TBD</td>
1981 </tr>
1982 <tr>
1983 <td rowspan="13" valign="top" >TV</td>
1984 <td valign="top" >“subconnector”</td>
1985 <td valign="top" >ENUM</td>
1986 <td valign="top" >{ "Unknown", "Composite", "SVIDEO", "Component", "SCART" }</td>
1987 <td valign="top" >Connector</td>
1988 <td valign="top" >TBD</td>
1989 </tr>
1990 <tr>
1991 <td valign="top" >“select subconnector”</td>
1992 <td valign="top" >ENUM</td>
1993 <td valign="top" >{ "Automatic", "Composite", "SVIDEO", "Component", "SCART" }</td>
1994 <td valign="top" >Connector</td>
1995 <td valign="top" >TBD</td>
1996 </tr>
1997 <tr>
1998 <td valign="top" >“mode”</td>
1999 <td valign="top" >ENUM</td>
2000 <td valign="top" >{ "NTSC_M", "NTSC_J", "NTSC_443", "PAL_B" } etc.</td>
2001 <td valign="top" >Connector</td>
2002 <td valign="top" >TBD</td>
2003 </tr>
2004 <tr>
2005 <td valign="top" >“left margin”</td>
2006 <td valign="top" >RANGE</td>
2007 <td valign="top" >Min=0, Max=100</td>
2008 <td valign="top" >Connector</td>
2009 <td valign="top" >TBD</td>
2010 </tr>
2011 <tr>
2012 <td valign="top" >“right margin”</td>
2013 <td valign="top" >RANGE</td>
2014 <td valign="top" >Min=0, Max=100</td>
2015 <td valign="top" >Connector</td>
2016 <td valign="top" >TBD</td>
2017 </tr>
2018 <tr>
2019 <td valign="top" >“top margin”</td>
2020 <td valign="top" >RANGE</td>
2021 <td valign="top" >Min=0, Max=100</td>
2022 <td valign="top" >Connector</td>
2023 <td valign="top" >TBD</td>
2024 </tr>
2025 <tr>
2026 <td valign="top" >“bottom margin”</td>
2027 <td valign="top" >RANGE</td>
2028 <td valign="top" >Min=0, Max=100</td>
2029 <td valign="top" >Connector</td>
2030 <td valign="top" >TBD</td>
2031 </tr>
2032 <tr>
2033 <td valign="top" >“brightness”</td>
2034 <td valign="top" >RANGE</td>
2035 <td valign="top" >Min=0, Max=100</td>
2036 <td valign="top" >Connector</td>
2037 <td valign="top" >TBD</td>
2038 </tr>
2039 <tr>
2040 <td valign="top" >“contrast”</td>
2041 <td valign="top" >RANGE</td>
2042 <td valign="top" >Min=0, Max=100</td>
2043 <td valign="top" >Connector</td>
2044 <td valign="top" >TBD</td>
2045 </tr>
2046 <tr>
2047 <td valign="top" >“flicker reduction”</td>
2048 <td valign="top" >RANGE</td>
2049 <td valign="top" >Min=0, Max=100</td>
2050 <td valign="top" >Connector</td>
2051 <td valign="top" >TBD</td>
2052 </tr>
2053 <tr>
2054 <td valign="top" >“overscan”</td>
2055 <td valign="top" >RANGE</td>
2056 <td valign="top" >Min=0, Max=100</td>
2057 <td valign="top" >Connector</td>
2058 <td valign="top" >TBD</td>
2059 </tr>
2060 <tr>
2061 <td valign="top" >“saturation”</td>
2062 <td valign="top" >RANGE</td>
2063 <td valign="top" >Min=0, Max=100</td>
2064 <td valign="top" >Connector</td>
2065 <td valign="top" >TBD</td>
2066 </tr>
2067 <tr>
2068 <td valign="top" >“hue”</td>
2069 <td valign="top" >RANGE</td>
2070 <td valign="top" >Min=0, Max=100</td>
2071 <td valign="top" >Connector</td>
2072 <td valign="top" >TBD</td>
2073 </tr>
2074 <tr>
2075 <td rowspan="2" valign="top" >Virtual GPU</td>
2076 <td valign="top" >“suggested X”</td>
2077 <td valign="top" >RANGE</td>
2078 <td valign="top" >Min=0, Max=0xffffffff</td>
2079 <td valign="top" >Connector</td>
2080 <td valign="top" >property to suggest an X offset for a connector</td>
2081 </tr>
2082 <tr>
2083 <td valign="top" >“suggested Y”</td>
2084 <td valign="top" >RANGE</td>
2085 <td valign="top" >Min=0, Max=0xffffffff</td>
2086 <td valign="top" >Connector</td>
2087 <td valign="top" >property to suggest an Y offset for a connector</td>
2088 </tr>
2089 <tr>
2090 <td rowspan="7" valign="top" >Optional</td>
2091 <td valign="top" >"aspect ratio"</td>
2092 <td valign="top" >ENUM</td>
2093 <td valign="top" >{ "None", "4:3", "16:9" }</td>
2094 <td valign="top" >Connector</td>
2095 <td valign="top" >TDB</td>
2096 </tr>
2097 <tr>
2098 <td valign="top" >“dirty”</td>
2099 <td valign="top" >ENUM | IMMUTABLE</td>
2100 <td valign="top" >{ "Off", "On", "Annotate" }</td>
2101 <td valign="top" >Connector</td>
2102 <td valign="top" >TBD</td>
2103 </tr>
2104 <tr>
2105 <td valign="top" >“DEGAMMA_LUT”</td>
2106 <td valign="top" >BLOB</td>
2107 <td valign="top" >0</td>
2108 <td valign="top" >CRTC</td>
2109 <td valign="top" >DRM property to set the degamma lookup table
2110 (LUT) mapping pixel data from the framebuffer before it is
2111 given to the transformation matrix. The data is an interpreted
2112 as an array of struct drm_color_lut elements. Hardware might
2113 choose not to use the full precision of the LUT elements nor
2114 use all the elements of the LUT (for example the hardware
2115 might choose to interpolate between LUT[0] and LUT[4]). </td>
2116 </tr>
2117 <tr>
2118 <td valign="top" >“DEGAMMA_LUT_SIZE”</td>
2119 <td valign="top" >RANGE | IMMUTABLE</td>
2120 <td valign="top" >Min=0, Max=UINT_MAX</td>
2121 <td valign="top" >CRTC</td>
2122 <td valign="top" >DRM property to gives the size of the lookup
2123 table to be set on the DEGAMMA_LUT property (the size depends
2124 on the underlying hardware).</td>
2125 </tr>
2126 <tr>
2127 <td valign="top" >“CTM”</td>
2128 <td valign="top" >BLOB</td>
2129 <td valign="top" >0</td>
2130 <td valign="top" >CRTC</td>
2131 <td valign="top" >DRM property to set the current
2132 transformation matrix (CTM) apply to pixel data after the
2133 lookup through the degamma LUT and before the lookup through
2134 the gamma LUT. The data is an interpreted as a struct
2135 drm_color_ctm.</td>
2136 </tr>
2137 <tr>
2138 <td valign="top" >“GAMMA_LUT”</td>
2139 <td valign="top" >BLOB</td>
2140 <td valign="top" >0</td>
2141 <td valign="top" >CRTC</td>
2142 <td valign="top" >DRM property to set the gamma lookup table
2143 (LUT) mapping pixel data after to the transformation matrix to
2144 data sent to the connector. The data is an interpreted as an
2145 array of struct drm_color_lut elements. Hardware might choose
2146 not to use the full precision of the LUT elements nor use all
2147 the elements of the LUT (for example the hardware might choose
2148 to interpolate between LUT[0] and LUT[4]).</td>
2149 </tr>
2150 <tr>
2151 <td valign="top" >“GAMMA_LUT_SIZE”</td>
2152 <td valign="top" >RANGE | IMMUTABLE</td>
2153 <td valign="top" >Min=0, Max=UINT_MAX</td>
2154 <td valign="top" >CRTC</td>
2155 <td valign="top" >DRM property to gives the size of the lookup
2156 table to be set on the GAMMA_LUT property (the size depends on
2157 the underlying hardware).</td>
2158 </tr>
2159 <tr>
2160 <td rowspan="20" valign="top" >i915</td>
2161 <td rowspan="2" valign="top" >Generic</td>
2162 <td valign="top" >"Broadcast RGB"</td>
2163 <td valign="top" >ENUM</td>
2164 <td valign="top" >{ "Automatic", "Full", "Limited 16:235" }</td>
2165 <td valign="top" >Connector</td>
2166 <td valign="top" >When this property is set to Limited 16:235
2167 and CTM is set, the hardware will be programmed with the
2168 result of the multiplication of CTM by the limited range
2169 matrix to ensure the pixels normaly in the range 0..1.0 are
2170 remapped to the range 16/255..235/255.</td>
2171 </tr>
2172 <tr>
2173 <td valign="top" >“audio”</td>
2174 <td valign="top" >ENUM</td>
2175 <td valign="top" >{ "force-dvi", "off", "auto", "on" }</td>
2176 <td valign="top" >Connector</td>
2177 <td valign="top" >TBD</td>
2178 </tr>
2179 <tr>
2180 <td rowspan="17" valign="top" >SDVO-TV</td>
2181 <td valign="top" >“mode”</td>
2182 <td valign="top" >ENUM</td>
2183 <td valign="top" >{ "NTSC_M", "NTSC_J", "NTSC_443", "PAL_B" } etc.</td>
2184 <td valign="top" >Connector</td>
2185 <td valign="top" >TBD</td>
2186 </tr>
2187 <tr>
2188 <td valign="top" >"left_margin"</td>
2189 <td valign="top" >RANGE</td>
2190 <td valign="top" >Min=0, Max= SDVO dependent</td>
2191 <td valign="top" >Connector</td>
2192 <td valign="top" >TBD</td>
2193 </tr>
2194 <tr>
2195 <td valign="top" >"right_margin"</td>
2196 <td valign="top" >RANGE</td>
2197 <td valign="top" >Min=0, Max= SDVO dependent</td>
2198 <td valign="top" >Connector</td>
2199 <td valign="top" >TBD</td>
2200 </tr>
2201 <tr>
2202 <td valign="top" >"top_margin"</td>
2203 <td valign="top" >RANGE</td>
2204 <td valign="top" >Min=0, Max= SDVO dependent</td>
2205 <td valign="top" >Connector</td>
2206 <td valign="top" >TBD</td>
2207 </tr>
2208 <tr>
2209 <td valign="top" >"bottom_margin"</td>
2210 <td valign="top" >RANGE</td>
2211 <td valign="top" >Min=0, Max= SDVO dependent</td>
2212 <td valign="top" >Connector</td>
2213 <td valign="top" >TBD</td>
2214 </tr>
2215 <tr>
2216 <td valign="top" >“hpos”</td>
2217 <td valign="top" >RANGE</td>
2218 <td valign="top" >Min=0, Max= SDVO dependent</td>
2219 <td valign="top" >Connector</td>
2220 <td valign="top" >TBD</td>
2221 </tr>
2222 <tr>
2223 <td valign="top" >“vpos”</td>
2224 <td valign="top" >RANGE</td>
2225 <td valign="top" >Min=0, Max= SDVO dependent</td>
2226 <td valign="top" >Connector</td>
2227 <td valign="top" >TBD</td>
2228 </tr>
2229 <tr>
2230 <td valign="top" >“contrast”</td>
2231 <td valign="top" >RANGE</td>
2232 <td valign="top" >Min=0, Max= SDVO dependent</td>
2233 <td valign="top" >Connector</td>
2234 <td valign="top" >TBD</td>
2235 </tr>
2236 <tr>
2237 <td valign="top" >“saturation”</td>
2238 <td valign="top" >RANGE</td>
2239 <td valign="top" >Min=0, Max= SDVO dependent</td>
2240 <td valign="top" >Connector</td>
2241 <td valign="top" >TBD</td>
2242 </tr>
2243 <tr>
2244 <td valign="top" >“hue”</td>
2245 <td valign="top" >RANGE</td>
2246 <td valign="top" >Min=0, Max= SDVO dependent</td>
2247 <td valign="top" >Connector</td>
2248 <td valign="top" >TBD</td>
2249 </tr>
2250 <tr>
2251 <td valign="top" >“sharpness”</td>
2252 <td valign="top" >RANGE</td>
2253 <td valign="top" >Min=0, Max= SDVO dependent</td>
2254 <td valign="top" >Connector</td>
2255 <td valign="top" >TBD</td>
2256 </tr>
2257 <tr>
2258 <td valign="top" >“flicker_filter”</td>
2259 <td valign="top" >RANGE</td>
2260 <td valign="top" >Min=0, Max= SDVO dependent</td>
2261 <td valign="top" >Connector</td>
2262 <td valign="top" >TBD</td>
2263 </tr>
2264 <tr>
2265 <td valign="top" >“flicker_filter_adaptive”</td>
2266 <td valign="top" >RANGE</td>
2267 <td valign="top" >Min=0, Max= SDVO dependent</td>
2268 <td valign="top" >Connector</td>
2269 <td valign="top" >TBD</td>
2270 </tr>
2271 <tr>
2272 <td valign="top" >“flicker_filter_2d”</td>
2273 <td valign="top" >RANGE</td>
2274 <td valign="top" >Min=0, Max= SDVO dependent</td>
2275 <td valign="top" >Connector</td>
2276 <td valign="top" >TBD</td>
2277 </tr>
2278 <tr>
2279 <td valign="top" >“tv_chroma_filter”</td>
2280 <td valign="top" >RANGE</td>
2281 <td valign="top" >Min=0, Max= SDVO dependent</td>
2282 <td valign="top" >Connector</td>
2283 <td valign="top" >TBD</td>
2284 </tr>
2285 <tr>
2286 <td valign="top" >“tv_luma_filter”</td>
2287 <td valign="top" >RANGE</td>
2288 <td valign="top" >Min=0, Max= SDVO dependent</td>
2289 <td valign="top" >Connector</td>
2290 <td valign="top" >TBD</td>
2291 </tr>
2292 <tr>
2293 <td valign="top" >“dot_crawl”</td>
2294 <td valign="top" >RANGE</td>
2295 <td valign="top" >Min=0, Max=1</td>
2296 <td valign="top" >Connector</td>
2297 <td valign="top" >TBD</td>
2298 </tr>
2299 <tr>
2300 <td valign="top" >SDVO-TV/LVDS</td>
2301 <td valign="top" >“brightness”</td>
2302 <td valign="top" >RANGE</td>
2303 <td valign="top" >Min=0, Max= SDVO dependent</td>
2304 <td valign="top" >Connector</td>
2305 <td valign="top" >TBD</td>
2306 </tr>
2307 <tr>
2308 <td rowspan="2" valign="top" >CDV gma-500</td>
2309 <td rowspan="2" valign="top" >Generic</td>
2310 <td valign="top" >"Broadcast RGB"</td>
2311 <td valign="top" >ENUM</td>
2312 <td valign="top" >{ “Full”, “Limited 16:235” }</td>
2313 <td valign="top" >Connector</td>
2314 <td valign="top" >TBD</td>
2315 </tr>
2316 <tr>
2317 <td valign="top" >"Broadcast RGB"</td>
2318 <td valign="top" >ENUM</td>
2319 <td valign="top" >{ “off”, “auto”, “on” }</td>
2320 <td valign="top" >Connector</td>
2321 <td valign="top" >TBD</td>
2322 </tr>
2323 <tr>
2324 <td rowspan="19" valign="top" >Poulsbo</td>
2325 <td rowspan="1" valign="top" >Generic</td>
2326 <td valign="top" >“backlight”</td>
2327 <td valign="top" >RANGE</td>
2328 <td valign="top" >Min=0, Max=100</td>
2329 <td valign="top" >Connector</td>
2330 <td valign="top" >TBD</td>
2331 </tr>
2332 <tr>
2333 <td rowspan="17" valign="top" >SDVO-TV</td>
2334 <td valign="top" >“mode”</td>
2335 <td valign="top" >ENUM</td>
2336 <td valign="top" >{ "NTSC_M", "NTSC_J", "NTSC_443", "PAL_B" } etc.</td>
2337 <td valign="top" >Connector</td>
2338 <td valign="top" >TBD</td>
2339 </tr>
2340 <tr>
2341 <td valign="top" >"left_margin"</td>
2342 <td valign="top" >RANGE</td>
2343 <td valign="top" >Min=0, Max= SDVO dependent</td>
2344 <td valign="top" >Connector</td>
2345 <td valign="top" >TBD</td>
2346 </tr>
2347 <tr>
2348 <td valign="top" >"right_margin"</td>
2349 <td valign="top" >RANGE</td>
2350 <td valign="top" >Min=0, Max= SDVO dependent</td>
2351 <td valign="top" >Connector</td>
2352 <td valign="top" >TBD</td>
2353 </tr>
2354 <tr>
2355 <td valign="top" >"top_margin"</td>
2356 <td valign="top" >RANGE</td>
2357 <td valign="top" >Min=0, Max= SDVO dependent</td>
2358 <td valign="top" >Connector</td>
2359 <td valign="top" >TBD</td>
2360 </tr>
2361 <tr>
2362 <td valign="top" >"bottom_margin"</td>
2363 <td valign="top" >RANGE</td>
2364 <td valign="top" >Min=0, Max= SDVO dependent</td>
2365 <td valign="top" >Connector</td>
2366 <td valign="top" >TBD</td>
2367 </tr>
2368 <tr>
2369 <td valign="top" >“hpos”</td>
2370 <td valign="top" >RANGE</td>
2371 <td valign="top" >Min=0, Max= SDVO dependent</td>
2372 <td valign="top" >Connector</td>
2373 <td valign="top" >TBD</td>
2374 </tr>
2375 <tr>
2376 <td valign="top" >“vpos”</td>
2377 <td valign="top" >RANGE</td>
2378 <td valign="top" >Min=0, Max= SDVO dependent</td>
2379 <td valign="top" >Connector</td>
2380 <td valign="top" >TBD</td>
2381 </tr>
2382 <tr>
2383 <td valign="top" >“contrast”</td>
2384 <td valign="top" >RANGE</td>
2385 <td valign="top" >Min=0, Max= SDVO dependent</td>
2386 <td valign="top" >Connector</td>
2387 <td valign="top" >TBD</td>
2388 </tr>
2389 <tr>
2390 <td valign="top" >“saturation”</td>
2391 <td valign="top" >RANGE</td>
2392 <td valign="top" >Min=0, Max= SDVO dependent</td>
2393 <td valign="top" >Connector</td>
2394 <td valign="top" >TBD</td>
2395 </tr>
2396 <tr>
2397 <td valign="top" >“hue”</td>
2398 <td valign="top" >RANGE</td>
2399 <td valign="top" >Min=0, Max= SDVO dependent</td>
2400 <td valign="top" >Connector</td>
2401 <td valign="top" >TBD</td>
2402 </tr>
2403 <tr>
2404 <td valign="top" >“sharpness”</td>
2405 <td valign="top" >RANGE</td>
2406 <td valign="top" >Min=0, Max= SDVO dependent</td>
2407 <td valign="top" >Connector</td>
2408 <td valign="top" >TBD</td>
2409 </tr>
2410 <tr>
2411 <td valign="top" >“flicker_filter”</td>
2412 <td valign="top" >RANGE</td>
2413 <td valign="top" >Min=0, Max= SDVO dependent</td>
2414 <td valign="top" >Connector</td>
2415 <td valign="top" >TBD</td>
2416 </tr>
2417 <tr>
2418 <td valign="top" >“flicker_filter_adaptive”</td>
2419 <td valign="top" >RANGE</td>
2420 <td valign="top" >Min=0, Max= SDVO dependent</td>
2421 <td valign="top" >Connector</td>
2422 <td valign="top" >TBD</td>
2423 </tr>
2424 <tr>
2425 <td valign="top" >“flicker_filter_2d”</td>
2426 <td valign="top" >RANGE</td>
2427 <td valign="top" >Min=0, Max= SDVO dependent</td>
2428 <td valign="top" >Connector</td>
2429 <td valign="top" >TBD</td>
2430 </tr>
2431 <tr>
2432 <td valign="top" >“tv_chroma_filter”</td>
2433 <td valign="top" >RANGE</td>
2434 <td valign="top" >Min=0, Max= SDVO dependent</td>
2435 <td valign="top" >Connector</td>
2436 <td valign="top" >TBD</td>
2437 </tr>
2438 <tr>
2439 <td valign="top" >“tv_luma_filter”</td>
2440 <td valign="top" >RANGE</td>
2441 <td valign="top" >Min=0, Max= SDVO dependent</td>
2442 <td valign="top" >Connector</td>
2443 <td valign="top" >TBD</td>
2444 </tr>
2445 <tr>
2446 <td valign="top" >“dot_crawl”</td>
2447 <td valign="top" >RANGE</td>
2448 <td valign="top" >Min=0, Max=1</td>
2449 <td valign="top" >Connector</td>
2450 <td valign="top" >TBD</td>
2451 </tr>
2452 <tr>
2453 <td valign="top" >SDVO-TV/LVDS</td>
2454 <td valign="top" >“brightness”</td>
2455 <td valign="top" >RANGE</td>
2456 <td valign="top" >Min=0, Max= SDVO dependent</td>
2457 <td valign="top" >Connector</td>
2458 <td valign="top" >TBD</td>
2459 </tr>
2460 <tr>
2461 <td rowspan="11" valign="top" >armada</td>
2462 <td rowspan="2" valign="top" >CRTC</td>
2463 <td valign="top" >"CSC_YUV"</td>
2464 <td valign="top" >ENUM</td>
2465 <td valign="top" >{ "Auto" , "CCIR601", "CCIR709" }</td>
2466 <td valign="top" >CRTC</td>
2467 <td valign="top" >TBD</td>
2468 </tr>
2469 <tr>
2470 <td valign="top" >"CSC_RGB"</td>
2471 <td valign="top" >ENUM</td>
2472 <td valign="top" >{ "Auto", "Computer system", "Studio" }</td>
2473 <td valign="top" >CRTC</td>
2474 <td valign="top" >TBD</td>
2475 </tr>
2476 <tr>
2477 <td rowspan="9" valign="top" >Overlay</td>
2478 <td valign="top" >"colorkey"</td>
2479 <td valign="top" >RANGE</td>
2480 <td valign="top" >Min=0, Max=0xffffff</td>
2481 <td valign="top" >Plane</td>
2482 <td valign="top" >TBD</td>
2483 </tr>
2484 <tr>
2485 <td valign="top" >"colorkey_min"</td>
2486 <td valign="top" >RANGE</td>
2487 <td valign="top" >Min=0, Max=0xffffff</td>
2488 <td valign="top" >Plane</td>
2489 <td valign="top" >TBD</td>
2490 </tr>
2491 <tr>
2492 <td valign="top" >"colorkey_max"</td>
2493 <td valign="top" >RANGE</td>
2494 <td valign="top" >Min=0, Max=0xffffff</td>
2495 <td valign="top" >Plane</td>
2496 <td valign="top" >TBD</td>
2497 </tr>
2498 <tr>
2499 <td valign="top" >"colorkey_val"</td>
2500 <td valign="top" >RANGE</td>
2501 <td valign="top" >Min=0, Max=0xffffff</td>
2502 <td valign="top" >Plane</td>
2503 <td valign="top" >TBD</td>
2504 </tr>
2505 <tr>
2506 <td valign="top" >"colorkey_alpha"</td>
2507 <td valign="top" >RANGE</td>
2508 <td valign="top" >Min=0, Max=0xffffff</td>
2509 <td valign="top" >Plane</td>
2510 <td valign="top" >TBD</td>
2511 </tr>
2512 <tr>
2513 <td valign="top" >"colorkey_mode"</td>
2514 <td valign="top" >ENUM</td>
2515 <td valign="top" >{ "disabled", "Y component", "U component"
2516 , "V component", "RGB", “R component", "G component", "B component" }</td>
2517 <td valign="top" >Plane</td>
2518 <td valign="top" >TBD</td>
2519 </tr>
2520 <tr>
2521 <td valign="top" >"brightness"</td>
2522 <td valign="top" >RANGE</td>
2523 <td valign="top" >Min=0, Max=256 + 255</td>
2524 <td valign="top" >Plane</td>
2525 <td valign="top" >TBD</td>
2526 </tr>
2527 <tr>
2528 <td valign="top" >"contrast"</td>
2529 <td valign="top" >RANGE</td>
2530 <td valign="top" >Min=0, Max=0x7fff</td>
2531 <td valign="top" >Plane</td>
2532 <td valign="top" >TBD</td>
2533 </tr>
2534 <tr>
2535 <td valign="top" >"saturation"</td>
2536 <td valign="top" >RANGE</td>
2537 <td valign="top" >Min=0, Max=0x7fff</td>
2538 <td valign="top" >Plane</td>
2539 <td valign="top" >TBD</td>
2540 </tr>
2541 <tr>
2542 <td rowspan="2" valign="top" >exynos</td>
2543 <td valign="top" >CRTC</td>
2544 <td valign="top" >“mode”</td>
2545 <td valign="top" >ENUM</td>
2546 <td valign="top" >{ "normal", "blank" }</td>
2547 <td valign="top" >CRTC</td>
2548 <td valign="top" >TBD</td>
2549 </tr>
2550 <tr>
2551 <td valign="top" >Overlay</td>
2552 <td valign="top" >“zpos”</td>
2553 <td valign="top" >RANGE</td>
2554 <td valign="top" >Min=0, Max=MAX_PLANE-1</td>
2555 <td valign="top" >Plane</td>
2556 <td valign="top" >TBD</td>
2557 </tr>
2558 <tr>
2559 <td rowspan="2" valign="top" >i2c/ch7006_drv</td>
2560 <td valign="top" >Generic</td>
2561 <td valign="top" >“scale”</td>
2562 <td valign="top" >RANGE</td>
2563 <td valign="top" >Min=0, Max=2</td>
2564 <td valign="top" >Connector</td>
2565 <td valign="top" >TBD</td>
2566 </tr>
2567 <tr>
2568 <td rowspan="1" valign="top" >TV</td>
2569 <td valign="top" >“mode”</td>
2570 <td valign="top" >ENUM</td>
2571 <td valign="top" >{ "PAL", "PAL-M","PAL-N"}, ”PAL-Nc"
2572 , "PAL-60", "NTSC-M", "NTSC-J" }</td>
2573 <td valign="top" >Connector</td>
2574 <td valign="top" >TBD</td>
2575 </tr>
2576 <tr>
2577 <td rowspan="15" valign="top" >nouveau</td>
2578 <td rowspan="6" valign="top" >NV10 Overlay</td>
2579 <td valign="top" >"colorkey"</td>
2580 <td valign="top" >RANGE</td>
2581 <td valign="top" >Min=0, Max=0x01ffffff</td>
2582 <td valign="top" >Plane</td>
2583 <td valign="top" >TBD</td>
2584 </tr>
2585 <tr>
2586 <td valign="top" >“contrast”</td>
2587 <td valign="top" >RANGE</td>
2588 <td valign="top" >Min=0, Max=8192-1</td>
2589 <td valign="top" >Plane</td>
2590 <td valign="top" >TBD</td>
2591 </tr>
2592 <tr>
2593 <td valign="top" >“brightness”</td>
2594 <td valign="top" >RANGE</td>
2595 <td valign="top" >Min=0, Max=1024</td>
2596 <td valign="top" >Plane</td>
2597 <td valign="top" >TBD</td>
2598 </tr>
2599 <tr>
2600 <td valign="top" >“hue”</td>
2601 <td valign="top" >RANGE</td>
2602 <td valign="top" >Min=0, Max=359</td>
2603 <td valign="top" >Plane</td>
2604 <td valign="top" >TBD</td>
2605 </tr>
2606 <tr>
2607 <td valign="top" >“saturation”</td>
2608 <td valign="top" >RANGE</td>
2609 <td valign="top" >Min=0, Max=8192-1</td>
2610 <td valign="top" >Plane</td>
2611 <td valign="top" >TBD</td>
2612 </tr>
2613 <tr>
2614 <td valign="top" >“iturbt_709”</td>
2615 <td valign="top" >RANGE</td>
2616 <td valign="top" >Min=0, Max=1</td>
2617 <td valign="top" >Plane</td>
2618 <td valign="top" >TBD</td>
2619 </tr>
2620 <tr>
2621 <td rowspan="2" valign="top" >Nv04 Overlay</td>
2622 <td valign="top" >“colorkey”</td>
2623 <td valign="top" >RANGE</td>
2624 <td valign="top" >Min=0, Max=0x01ffffff</td>
2625 <td valign="top" >Plane</td>
2626 <td valign="top" >TBD</td>
2627 </tr>
2628 <tr>
2629 <td valign="top" >“brightness”</td>
2630 <td valign="top" >RANGE</td>
2631 <td valign="top" >Min=0, Max=1024</td>
2632 <td valign="top" >Plane</td>
2633 <td valign="top" >TBD</td>
2634 </tr>
2635 <tr>
2636 <td rowspan="7" valign="top" >Display</td>
2637 <td valign="top" >“dithering mode”</td>
2638 <td valign="top" >ENUM</td>
2639 <td valign="top" >{ "auto", "off", "on" }</td>
2640 <td valign="top" >Connector</td>
2641 <td valign="top" >TBD</td>
2642 </tr>
2643 <tr>
2644 <td valign="top" >“dithering depth”</td>
2645 <td valign="top" >ENUM</td>
2646 <td valign="top" >{ "auto", "off", "on", "static 2x2", "dynamic 2x2", "temporal" }</td>
2647 <td valign="top" >Connector</td>
2648 <td valign="top" >TBD</td>
2649 </tr>
2650 <tr>
2651 <td valign="top" >“underscan”</td>
2652 <td valign="top" >ENUM</td>
2653 <td valign="top" >{ "auto", "6 bpc", "8 bpc" }</td>
2654 <td valign="top" >Connector</td>
2655 <td valign="top" >TBD</td>
2656 </tr>
2657 <tr>
2658 <td valign="top" >“underscan hborder”</td>
2659 <td valign="top" >RANGE</td>
2660 <td valign="top" >Min=0, Max=128</td>
2661 <td valign="top" >Connector</td>
2662 <td valign="top" >TBD</td>
2663 </tr>
2664 <tr>
2665 <td valign="top" >“underscan vborder”</td>
2666 <td valign="top" >RANGE</td>
2667 <td valign="top" >Min=0, Max=128</td>
2668 <td valign="top" >Connector</td>
2669 <td valign="top" >TBD</td>
2670 </tr>
2671 <tr>
2672 <td valign="top" >“vibrant hue”</td>
2673 <td valign="top" >RANGE</td>
2674 <td valign="top" >Min=0, Max=180</td>
2675 <td valign="top" >Connector</td>
2676 <td valign="top" >TBD</td>
2677 </tr>
2678 <tr>
2679 <td valign="top" >“color vibrance”</td>
2680 <td valign="top" >RANGE</td>
2681 <td valign="top" >Min=0, Max=200</td>
2682 <td valign="top" >Connector</td>
2683 <td valign="top" >TBD</td>
2684 </tr>
2685 <tr>
2686 <td valign="top" >omap</td>
2687 <td valign="top" >Generic</td>
2688 <td valign="top" >“zorder”</td>
2689 <td valign="top" >RANGE</td>
2690 <td valign="top" >Min=0, Max=3</td>
2691 <td valign="top" >CRTC, Plane</td>
2692 <td valign="top" >TBD</td>
2693 </tr>
2694 <tr>
2695 <td valign="top" >qxl</td>
2696 <td valign="top" >Generic</td>
2697 <td valign="top" >“hotplug_mode_update"</td>
2698 <td valign="top" >RANGE</td>
2699 <td valign="top" >Min=0, Max=1</td>
2700 <td valign="top" >Connector</td>
2701 <td valign="top" >TBD</td>
2702 </tr>
2703 <tr>
2704 <td rowspan="9" valign="top" >radeon</td>
2705 <td valign="top" >DVI-I</td>
2706 <td valign="top" >“coherent”</td>
2707 <td valign="top" >RANGE</td>
2708 <td valign="top" >Min=0, Max=1</td>
2709 <td valign="top" >Connector</td>
2710 <td valign="top" >TBD</td>
2711 </tr>
2712 <tr>
2713 <td valign="top" >DAC enable load detect</td>
2714 <td valign="top" >“load detection”</td>
2715 <td valign="top" >RANGE</td>
2716 <td valign="top" >Min=0, Max=1</td>
2717 <td valign="top" >Connector</td>
2718 <td valign="top" >TBD</td>
2719 </tr>
2720 <tr>
2721 <td valign="top" >TV Standard</td>
2722 <td valign="top" >"tv standard"</td>
2723 <td valign="top" >ENUM</td>
2724 <td valign="top" >{ "ntsc", "pal", "pal-m", "pal-60", "ntsc-j"
2725 , "scart-pal", "pal-cn", "secam" }</td>
2726 <td valign="top" >Connector</td>
2727 <td valign="top" >TBD</td>
2728 </tr>
2729 <tr>
2730 <td valign="top" >legacy TMDS PLL detect</td>
2731 <td valign="top" >"tmds_pll"</td>
2732 <td valign="top" >ENUM</td>
2733 <td valign="top" >{ "driver", "bios" }</td>
2734 <td valign="top" >-</td>
2735 <td valign="top" >TBD</td>
2736 </tr>
2737 <tr>
2738 <td rowspan="3" valign="top" >Underscan</td>
2739 <td valign="top" >"underscan"</td>
2740 <td valign="top" >ENUM</td>
2741 <td valign="top" >{ "off", "on", "auto" }</td>
2742 <td valign="top" >Connector</td>
2743 <td valign="top" >TBD</td>
2744 </tr>
2745 <tr>
2746 <td valign="top" >"underscan hborder"</td>
2747 <td valign="top" >RANGE</td>
2748 <td valign="top" >Min=0, Max=128</td>
2749 <td valign="top" >Connector</td>
2750 <td valign="top" >TBD</td>
2751 </tr>
2752 <tr>
2753 <td valign="top" >"underscan vborder"</td>
2754 <td valign="top" >RANGE</td>
2755 <td valign="top" >Min=0, Max=128</td>
2756 <td valign="top" >Connector</td>
2757 <td valign="top" >TBD</td>
2758 </tr>
2759 <tr>
2760 <td valign="top" >Audio</td>
2761 <td valign="top" >“audio”</td>
2762 <td valign="top" >ENUM</td>
2763 <td valign="top" >{ "off", "on", "auto" }</td>
2764 <td valign="top" >Connector</td>
2765 <td valign="top" >TBD</td>
2766 </tr>
2767 <tr>
2768 <td valign="top" >FMT Dithering</td>
2769 <td valign="top" >“dither”</td>
2770 <td valign="top" >ENUM</td>
2771 <td valign="top" >{ "off", "on" }</td>
2772 <td valign="top" >Connector</td>
2773 <td valign="top" >TBD</td>
2774 </tr>
2775 <tr>
2776 <td rowspan="3" valign="top" >rcar-du</td>
2777 <td rowspan="3" valign="top" >Generic</td>
2778 <td valign="top" >"alpha"</td>
2779 <td valign="top" >RANGE</td>
2780 <td valign="top" >Min=0, Max=255</td>
2781 <td valign="top" >Plane</td>
2782 <td valign="top" >TBD</td>
2783 </tr>
2784 <tr>
2785 <td valign="top" >"colorkey"</td>
2786 <td valign="top" >RANGE</td>
2787 <td valign="top" >Min=0, Max=0x01ffffff</td>
2788 <td valign="top" >Plane</td>
2789 <td valign="top" >TBD</td>
2790 </tr>
2791 <tr>
2792 <td valign="top" >"zpos"</td>
2793 <td valign="top" >RANGE</td>
2794 <td valign="top" >Min=1, Max=7</td>
2795 <td valign="top" >Plane</td>
2796 <td valign="top" >TBD</td>
2797 </tr>
2798 </tbody>
2799 </table>
2800 </sect2>
2801 </sect1>
2802
2803 <!-- Internals: vertical blanking -->
2804
2805 <sect1 id="drm-vertical-blank">
2806 <title>Vertical Blanking</title>
2807 <para>
2808 Vertical blanking plays a major role in graphics rendering. To achieve
2809 tear-free display, users must synchronize page flips and/or rendering to
2810 vertical blanking. The DRM API offers ioctls to perform page flips
2811 synchronized to vertical blanking and wait for vertical blanking.
2812 </para>
2813 <para>
2814 The DRM core handles most of the vertical blanking management logic, which
2815 involves filtering out spurious interrupts, keeping race-free blanking
2816 counters, coping with counter wrap-around and resets and keeping use
2817 counts. It relies on the driver to generate vertical blanking interrupts
2818 and optionally provide a hardware vertical blanking counter. Drivers must
2819 implement the following operations.
2820 </para>
2821 <itemizedlist>
2822 <listitem>
2823 <synopsis>int (*enable_vblank) (struct drm_device *dev, int crtc);
2824void (*disable_vblank) (struct drm_device *dev, int crtc);</synopsis>
2825 <para>
2826 Enable or disable vertical blanking interrupts for the given CRTC.
2827 </para>
2828 </listitem>
2829 <listitem>
2830 <synopsis>u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);</synopsis>
2831 <para>
2832 Retrieve the value of the vertical blanking counter for the given
2833 CRTC. If the hardware maintains a vertical blanking counter its value
2834 should be returned. Otherwise drivers can use the
2835 <function>drm_vblank_count</function> helper function to handle this
2836 operation.
2837 </para>
2838 </listitem>
2839 </itemizedlist>
2840 <para>
2841 Drivers must initialize the vertical blanking handling core with a call to
2842 <function>drm_vblank_init</function> in their
2843 <methodname>load</methodname> operation.
2844 </para>
2845 <para>
2846 Vertical blanking interrupts can be enabled by the DRM core or by drivers
2847 themselves (for instance to handle page flipping operations). The DRM core
2848 maintains a vertical blanking use count to ensure that the interrupts are
2849 not disabled while a user still needs them. To increment the use count,
2850 drivers call <function>drm_vblank_get</function>. Upon return vertical
2851 blanking interrupts are guaranteed to be enabled.
2852 </para>
2853 <para>
2854 To decrement the use count drivers call
2855 <function>drm_vblank_put</function>. Only when the use count drops to zero
2856 will the DRM core disable the vertical blanking interrupts after a delay
2857 by scheduling a timer. The delay is accessible through the vblankoffdelay
2858 module parameter or the <varname>drm_vblank_offdelay</varname> global
2859 variable and expressed in milliseconds. Its default value is 5000 ms.
2860 Zero means never disable, and a negative value means disable immediately.
2861 Drivers may override the behaviour by setting the
2862 <structname>drm_device</structname>
2863 <structfield>vblank_disable_immediate</structfield> flag, which when set
2864 causes vblank interrupts to be disabled immediately regardless of the
2865 drm_vblank_offdelay value. The flag should only be set if there's a
2866 properly working hardware vblank counter present.
2867 </para>
2868 <para>
2869 When a vertical blanking interrupt occurs drivers only need to call the
2870 <function>drm_handle_vblank</function> function to account for the
2871 interrupt.
2872 </para>
2873 <para>
2874 Resources allocated by <function>drm_vblank_init</function> must be freed
2875 with a call to <function>drm_vblank_cleanup</function> in the driver
2876 <methodname>unload</methodname> operation handler.
2877 </para>
2878 <sect2>
2879 <title>Vertical Blanking and Interrupt Handling Functions Reference</title>
2880!Edrivers/gpu/drm/drm_irq.c
2881!Finclude/drm/drmP.h drm_crtc_vblank_waitqueue
2882 </sect2>
2883 </sect1>
2884
2885 <!-- Internals: open/close, file operations and ioctls -->
2886
2887 <sect1>
2888 <title>Open/Close, File Operations and IOCTLs</title>
2889 <sect2>
2890 <title>Open and Close</title>
2891 <synopsis>int (*firstopen) (struct drm_device *);
2892void (*lastclose) (struct drm_device *);
2893int (*open) (struct drm_device *, struct drm_file *);
2894void (*preclose) (struct drm_device *, struct drm_file *);
2895void (*postclose) (struct drm_device *, struct drm_file *);</synopsis>
2896 <abstract>Open and close handlers. None of those methods are mandatory.
2897 </abstract>
2898 <para>
2899 The <methodname>firstopen</methodname> method is called by the DRM core
2900 for legacy UMS (User Mode Setting) drivers only when an application
2901 opens a device that has no other opened file handle. UMS drivers can
2902 implement it to acquire device resources. KMS drivers can't use the
2903 method and must acquire resources in the <methodname>load</methodname>
2904 method instead.
2905 </para>
2906 <para>
2907 Similarly the <methodname>lastclose</methodname> method is called when
2908 the last application holding a file handle opened on the device closes
2909 it, for both UMS and KMS drivers. Additionally, the method is also
2910 called at module unload time or, for hot-pluggable devices, when the
2911 device is unplugged. The <methodname>firstopen</methodname> and
2912 <methodname>lastclose</methodname> calls can thus be unbalanced.
2913 </para>
2914 <para>
2915 The <methodname>open</methodname> method is called every time the device
2916 is opened by an application. Drivers can allocate per-file private data
2917 in this method and store them in the struct
2918 <structname>drm_file</structname> <structfield>driver_priv</structfield>
2919 field. Note that the <methodname>open</methodname> method is called
2920 before <methodname>firstopen</methodname>.
2921 </para>
2922 <para>
2923 The close operation is split into <methodname>preclose</methodname> and
2924 <methodname>postclose</methodname> methods. Drivers must stop and
2925 cleanup all per-file operations in the <methodname>preclose</methodname>
2926 method. For instance pending vertical blanking and page flip events must
2927 be cancelled. No per-file operation is allowed on the file handle after
2928 returning from the <methodname>preclose</methodname> method.
2929 </para>
2930 <para>
2931 Finally the <methodname>postclose</methodname> method is called as the
2932 last step of the close operation, right before calling the
2933 <methodname>lastclose</methodname> method if no other open file handle
2934 exists for the device. Drivers that have allocated per-file private data
2935 in the <methodname>open</methodname> method should free it here.
2936 </para>
2937 <para>
2938 The <methodname>lastclose</methodname> method should restore CRTC and
2939 plane properties to default value, so that a subsequent open of the
2940 device will not inherit state from the previous user. It can also be
2941 used to execute delayed power switching state changes, e.g. in
2942 conjunction with the vga_switcheroo infrastructure (see
2943 <xref linkend="vga_switcheroo"/>). Beyond that KMS drivers should not
2944 do any further cleanup. Only legacy UMS drivers might need to clean up
2945 device state so that the vga console or an independent fbdev driver
2946 could take over.
2947 </para>
2948 </sect2>
2949 <sect2>
2950 <title>File Operations</title>
2951!Pdrivers/gpu/drm/drm_fops.c file operations
2952!Edrivers/gpu/drm/drm_fops.c
2953 </sect2>
2954 <sect2>
2955 <title>IOCTLs</title>
2956 <synopsis>struct drm_ioctl_desc *ioctls;
2957int num_ioctls;</synopsis>
2958 <abstract>Driver-specific ioctls descriptors table.</abstract>
2959 <para>
2960 Driver-specific ioctls numbers start at DRM_COMMAND_BASE. The ioctls
2961 descriptors table is indexed by the ioctl number offset from the base
2962 value. Drivers can use the DRM_IOCTL_DEF_DRV() macro to initialize the
2963 table entries.
2964 </para>
2965 <para>
2966 <programlisting>DRM_IOCTL_DEF_DRV(ioctl, func, flags)</programlisting>
2967 <para>
2968 <parameter>ioctl</parameter> is the ioctl name. Drivers must define
2969 the DRM_##ioctl and DRM_IOCTL_##ioctl macros to the ioctl number
2970 offset from DRM_COMMAND_BASE and the ioctl number respectively. The
2971 first macro is private to the device while the second must be exposed
2972 to userspace in a public header.
2973 </para>
2974 <para>
2975 <parameter>func</parameter> is a pointer to the ioctl handler function
2976 compatible with the <type>drm_ioctl_t</type> type.
2977 <programlisting>typedef int drm_ioctl_t(struct drm_device *dev, void *data,
2978 struct drm_file *file_priv);</programlisting>
2979 </para>
2980 <para>
2981 <parameter>flags</parameter> is a bitmask combination of the following
2982 values. It restricts how the ioctl is allowed to be called.
2983 <itemizedlist>
2984 <listitem><para>
2985 DRM_AUTH - Only authenticated callers allowed
2986 </para></listitem>
2987 <listitem><para>
2988 DRM_MASTER - The ioctl can only be called on the master file
2989 handle
2990 </para></listitem>
2991 <listitem><para>
2992 DRM_ROOT_ONLY - Only callers with the SYSADMIN capability allowed
2993 </para></listitem>
2994 <listitem><para>
2995 DRM_CONTROL_ALLOW - The ioctl can only be called on a control
2996 device
2997 </para></listitem>
2998 <listitem><para>
2999 DRM_UNLOCKED - The ioctl handler will be called without locking
3000 the DRM global mutex. This is the enforced default for kms drivers
3001 (i.e. using the DRIVER_MODESET flag) and hence shouldn't be used
3002 any more for new drivers.
3003 </para></listitem>
3004 </itemizedlist>
3005 </para>
3006 </para>
3007!Edrivers/gpu/drm/drm_ioctl.c
3008 </sect2>
3009 </sect1>
3010 <sect1>
3011 <title>Legacy Support Code</title>
3012 <para>
3013 The section very briefly covers some of the old legacy support code which
3014 is only used by old DRM drivers which have done a so-called shadow-attach
3015 to the underlying device instead of registering as a real driver. This
3016 also includes some of the old generic buffer management and command
3017 submission code. Do not use any of this in new and modern drivers.
3018 </para>
3019
3020 <sect2>
3021 <title>Legacy Suspend/Resume</title>
3022 <para>
3023 The DRM core provides some suspend/resume code, but drivers wanting full
3024 suspend/resume support should provide save() and restore() functions.
3025 These are called at suspend, hibernate, or resume time, and should perform
3026 any state save or restore required by your device across suspend or
3027 hibernate states.
3028 </para>
3029 <synopsis>int (*suspend) (struct drm_device *, pm_message_t state);
3030 int (*resume) (struct drm_device *);</synopsis>
3031 <para>
3032 Those are legacy suspend and resume methods which
3033 <emphasis>only</emphasis> work with the legacy shadow-attach driver
3034 registration functions. New driver should use the power management
3035 interface provided by their bus type (usually through
3036 the struct <structname>device_driver</structname> dev_pm_ops) and set
3037 these methods to NULL.
3038 </para>
3039 </sect2>
3040
3041 <sect2>
3042 <title>Legacy DMA Services</title>
3043 <para>
3044 This should cover how DMA mapping etc. is supported by the core.
3045 These functions are deprecated and should not be used.
3046 </para>
3047 </sect2>
3048 </sect1>
3049 </chapter>
3050
3051<!-- TODO
3052
3053- Add a glossary
3054- Document the struct_mutex catch-all lock
3055- Document connector properties
3056
3057- Why is the load method optional?
3058- What are drivers supposed to set the initial display state to, and how?
3059 Connector's DPMS states are not initialized and are thus equal to
3060 DRM_MODE_DPMS_ON. The fbcon compatibility layer calls
3061 drm_helper_disable_unused_functions(), which disables unused encoders and
3062 CRTCs, but doesn't touch the connectors' DPMS state, and
3063 drm_helper_connector_dpms() in reaction to fbdev blanking events. Do drivers
3064 that don't implement (or just don't use) fbcon compatibility need to call
3065 those functions themselves?
3066- KMS drivers must call drm_vblank_pre_modeset() and drm_vblank_post_modeset()
3067 around mode setting. Should this be done in the DRM core?
3068- vblank_disable_allowed is set to 1 in the first drm_vblank_post_modeset()
3069 call and never set back to 0. It seems to be safe to permanently set it to 1
3070 in drm_vblank_init() for KMS driver, and it might be safe for UMS drivers as
3071 well. This should be investigated.
3072- crtc and connector .save and .restore operations are only used internally in
3073 drivers, should they be removed from the core?
3074- encoder mid-layer .save and .restore operations are only used internally in
3075 drivers, should they be removed from the core?
3076- encoder mid-layer .detect operation is only used internally in drivers,
3077 should it be removed from the core?
3078-->
3079
3080 <!-- External interfaces -->
3081
3082 <chapter id="drmExternals">
3083 <title>Userland interfaces</title>
3084 <para>
3085 The DRM core exports several interfaces to applications,
3086 generally intended to be used through corresponding libdrm
3087 wrapper functions. In addition, drivers export device-specific
3088 interfaces for use by userspace drivers &amp; device-aware
3089 applications through ioctls and sysfs files.
3090 </para>
3091 <para>
3092 External interfaces include: memory mapping, context management,
3093 DMA operations, AGP management, vblank control, fence
3094 management, memory management, and output management.
3095 </para>
3096 <para>
3097 Cover generic ioctls and sysfs layout here. We only need high-level
3098 info, since man pages should cover the rest.
3099 </para>
3100
3101 <!-- External: render nodes -->
3102
3103 <sect1>
3104 <title>Render nodes</title>
3105 <para>
3106 DRM core provides multiple character-devices for user-space to use.
3107 Depending on which device is opened, user-space can perform a different
3108 set of operations (mainly ioctls). The primary node is always created
3109 and called card&lt;num&gt;. Additionally, a currently
3110 unused control node, called controlD&lt;num&gt; is also
3111 created. The primary node provides all legacy operations and
3112 historically was the only interface used by userspace. With KMS, the
3113 control node was introduced. However, the planned KMS control interface
3114 has never been written and so the control node stays unused to date.
3115 </para>
3116 <para>
3117 With the increased use of offscreen renderers and GPGPU applications,
3118 clients no longer require running compositors or graphics servers to
3119 make use of a GPU. But the DRM API required unprivileged clients to
3120 authenticate to a DRM-Master prior to getting GPU access. To avoid this
3121 step and to grant clients GPU access without authenticating, render
3122 nodes were introduced. Render nodes solely serve render clients, that
3123 is, no modesetting or privileged ioctls can be issued on render nodes.
3124 Only non-global rendering commands are allowed. If a driver supports
3125 render nodes, it must advertise it via the DRIVER_RENDER
3126 DRM driver capability. If not supported, the primary node must be used
3127 for render clients together with the legacy drmAuth authentication
3128 procedure.
3129 </para>
3130 <para>
3131 If a driver advertises render node support, DRM core will create a
3132 separate render node called renderD&lt;num&gt;. There will
3133 be one render node per device. No ioctls except PRIME-related ioctls
3134 will be allowed on this node. Especially GEM_OPEN will be
3135 explicitly prohibited. Render nodes are designed to avoid the
3136 buffer-leaks, which occur if clients guess the flink names or mmap
3137 offsets on the legacy interface. Additionally to this basic interface,
3138 drivers must mark their driver-dependent render-only ioctls as
3139 DRM_RENDER_ALLOW so render clients can use them. Driver
3140 authors must be careful not to allow any privileged ioctls on render
3141 nodes.
3142 </para>
3143 <para>
3144 With render nodes, user-space can now control access to the render node
3145 via basic file-system access-modes. A running graphics server which
3146 authenticates clients on the privileged primary/legacy node is no longer
3147 required. Instead, a client can open the render node and is immediately
3148 granted GPU access. Communication between clients (or servers) is done
3149 via PRIME. FLINK from render node to legacy node is not supported. New
3150 clients must not use the insecure FLINK interface.
3151 </para>
3152 <para>
3153 Besides dropping all modeset/global ioctls, render nodes also drop the
3154 DRM-Master concept. There is no reason to associate render clients with
3155 a DRM-Master as they are independent of any graphics server. Besides,
3156 they must work without any running master, anyway.
3157 Drivers must be able to run without a master object if they support
3158 render nodes. If, on the other hand, a driver requires shared state
3159 between clients which is visible to user-space and accessible beyond
3160 open-file boundaries, they cannot support render nodes.
3161 </para>
3162 </sect1>
3163
3164 <!-- External: vblank handling -->
3165
3166 <sect1>
3167 <title>VBlank event handling</title>
3168 <para>
3169 The DRM core exposes two vertical blank related ioctls:
3170 <variablelist>
3171 <varlistentry>
3172 <term>DRM_IOCTL_WAIT_VBLANK</term>
3173 <listitem>
3174 <para>
3175 This takes a struct drm_wait_vblank structure as its argument,
3176 and it is used to block or request a signal when a specified
3177 vblank event occurs.
3178 </para>
3179 </listitem>
3180 </varlistentry>
3181 <varlistentry>
3182 <term>DRM_IOCTL_MODESET_CTL</term>
3183 <listitem>
3184 <para>
3185 This was only used for user-mode-settind drivers around
3186 modesetting changes to allow the kernel to update the vblank
3187 interrupt after mode setting, since on many devices the vertical
3188 blank counter is reset to 0 at some point during modeset. Modern
3189 drivers should not call this any more since with kernel mode
3190 setting it is a no-op.
3191 </para>
3192 </listitem>
3193 </varlistentry>
3194 </variablelist>
3195 </para>
3196 </sect1>
3197
3198 </chapter>
3199</part>
3200<part id="drmDrivers">
3201 <title>DRM Drivers</title>
3202
3203 <partintro>
3204 <para>
3205 This second part of the GPU Driver Developer's Guide documents driver
3206 code, implementation details and also all the driver-specific userspace
3207 interfaces. Especially since all hardware-acceleration interfaces to
3208 userspace are driver specific for efficiency and other reasons these
3209 interfaces can be rather substantial. Hence every driver has its own
3210 chapter.
3211 </para>
3212 </partintro>
3213
3214 <chapter id="drmI915">
3215 <title>drm/i915 Intel GFX Driver</title>
3216 <para>
3217 The drm/i915 driver supports all (with the exception of some very early
3218 models) integrated GFX chipsets with both Intel display and rendering
3219 blocks. This excludes a set of SoC platforms with an SGX rendering unit,
3220 those have basic support through the gma500 drm driver.
3221 </para>
3222 <sect1>
3223 <title>Core Driver Infrastructure</title>
3224 <para>
3225 This section covers core driver infrastructure used by both the display
3226 and the GEM parts of the driver.
3227 </para>
3228 <sect2>
3229 <title>Runtime Power Management</title>
3230!Pdrivers/gpu/drm/i915/intel_runtime_pm.c runtime pm
3231!Idrivers/gpu/drm/i915/intel_runtime_pm.c
3232!Idrivers/gpu/drm/i915/intel_uncore.c
3233 </sect2>
3234 <sect2>
3235 <title>Interrupt Handling</title>
3236!Pdrivers/gpu/drm/i915/i915_irq.c interrupt handling
3237!Fdrivers/gpu/drm/i915/i915_irq.c intel_irq_init intel_irq_init_hw intel_hpd_init
3238!Fdrivers/gpu/drm/i915/i915_irq.c intel_runtime_pm_disable_interrupts
3239!Fdrivers/gpu/drm/i915/i915_irq.c intel_runtime_pm_enable_interrupts
3240 </sect2>
3241 <sect2>
3242 <title>Intel GVT-g Guest Support(vGPU)</title>
3243!Pdrivers/gpu/drm/i915/i915_vgpu.c Intel GVT-g guest support
3244!Idrivers/gpu/drm/i915/i915_vgpu.c
3245 </sect2>
3246 </sect1>
3247 <sect1>
3248 <title>Display Hardware Handling</title>
3249 <para>
3250 This section covers everything related to the display hardware including
3251 the mode setting infrastructure, plane, sprite and cursor handling and
3252 display, output probing and related topics.
3253 </para>
3254 <sect2>
3255 <title>Mode Setting Infrastructure</title>
3256 <para>
3257 The i915 driver is thus far the only DRM driver which doesn't use the
3258 common DRM helper code to implement mode setting sequences. Thus it
3259 has its own tailor-made infrastructure for executing a display
3260 configuration change.
3261 </para>
3262 </sect2>
3263 <sect2>
3264 <title>Frontbuffer Tracking</title>
3265!Pdrivers/gpu/drm/i915/intel_frontbuffer.c frontbuffer tracking
3266!Idrivers/gpu/drm/i915/intel_frontbuffer.c
3267!Fdrivers/gpu/drm/i915/i915_gem.c i915_gem_track_fb
3268 </sect2>
3269 <sect2>
3270 <title>Display FIFO Underrun Reporting</title>
3271!Pdrivers/gpu/drm/i915/intel_fifo_underrun.c fifo underrun handling
3272!Idrivers/gpu/drm/i915/intel_fifo_underrun.c
3273 </sect2>
3274 <sect2>
3275 <title>Plane Configuration</title>
3276 <para>
3277 This section covers plane configuration and composition with the
3278 primary plane, sprites, cursors and overlays. This includes the
3279 infrastructure to do atomic vsync'ed updates of all this state and
3280 also tightly coupled topics like watermark setup and computation,
3281 framebuffer compression and panel self refresh.
3282 </para>
3283 </sect2>
3284 <sect2>
3285 <title>Atomic Plane Helpers</title>
3286!Pdrivers/gpu/drm/i915/intel_atomic_plane.c atomic plane helpers
3287!Idrivers/gpu/drm/i915/intel_atomic_plane.c
3288 </sect2>
3289 <sect2>
3290 <title>Output Probing</title>
3291 <para>
3292 This section covers output probing and related infrastructure like the
3293 hotplug interrupt storm detection and mitigation code. Note that the
3294 i915 driver still uses most of the common DRM helper code for output
3295 probing, so those sections fully apply.
3296 </para>
3297 </sect2>
3298 <sect2>
3299 <title>Hotplug</title>
3300!Pdrivers/gpu/drm/i915/intel_hotplug.c Hotplug
3301!Idrivers/gpu/drm/i915/intel_hotplug.c
3302 </sect2>
3303 <sect2>
3304 <title>High Definition Audio</title>
3305!Pdrivers/gpu/drm/i915/intel_audio.c High Definition Audio over HDMI and Display Port
3306!Idrivers/gpu/drm/i915/intel_audio.c
3307!Iinclude/drm/i915_component.h
3308 </sect2>
3309 <sect2>
3310 <title>Panel Self Refresh PSR (PSR/SRD)</title>
3311!Pdrivers/gpu/drm/i915/intel_psr.c Panel Self Refresh (PSR/SRD)
3312!Idrivers/gpu/drm/i915/intel_psr.c
3313 </sect2>
3314 <sect2>
3315 <title>Frame Buffer Compression (FBC)</title>
3316!Pdrivers/gpu/drm/i915/intel_fbc.c Frame Buffer Compression (FBC)
3317!Idrivers/gpu/drm/i915/intel_fbc.c
3318 </sect2>
3319 <sect2>
3320 <title>Display Refresh Rate Switching (DRRS)</title>
3321!Pdrivers/gpu/drm/i915/intel_dp.c Display Refresh Rate Switching (DRRS)
3322!Fdrivers/gpu/drm/i915/intel_dp.c intel_dp_set_drrs_state
3323!Fdrivers/gpu/drm/i915/intel_dp.c intel_edp_drrs_enable
3324!Fdrivers/gpu/drm/i915/intel_dp.c intel_edp_drrs_disable
3325!Fdrivers/gpu/drm/i915/intel_dp.c intel_edp_drrs_invalidate
3326!Fdrivers/gpu/drm/i915/intel_dp.c intel_edp_drrs_flush
3327!Fdrivers/gpu/drm/i915/intel_dp.c intel_dp_drrs_init
3328
3329 </sect2>
3330 <sect2>
3331 <title>DPIO</title>
3332!Pdrivers/gpu/drm/i915/i915_reg.h DPIO
3333 </sect2>
3334
3335 <sect2>
3336 <title>CSR firmware support for DMC</title>
3337!Pdrivers/gpu/drm/i915/intel_csr.c csr support for dmc
3338!Idrivers/gpu/drm/i915/intel_csr.c
3339 </sect2>
3340 <sect2>
3341 <title>Video BIOS Table (VBT)</title>
3342!Pdrivers/gpu/drm/i915/intel_bios.c Video BIOS Table (VBT)
3343!Idrivers/gpu/drm/i915/intel_bios.c
3344!Idrivers/gpu/drm/i915/intel_vbt_defs.h
3345 </sect2>
3346 </sect1>
3347
3348 <sect1>
3349 <title>Memory Management and Command Submission</title>
3350 <para>
3351 This sections covers all things related to the GEM implementation in the
3352 i915 driver.
3353 </para>
3354 <sect2>
3355 <title>Batchbuffer Parsing</title>
3356!Pdrivers/gpu/drm/i915/i915_cmd_parser.c batch buffer command parser
3357!Idrivers/gpu/drm/i915/i915_cmd_parser.c
3358 </sect2>
3359 <sect2>
3360 <title>Batchbuffer Pools</title>
3361!Pdrivers/gpu/drm/i915/i915_gem_batch_pool.c batch pool
3362!Idrivers/gpu/drm/i915/i915_gem_batch_pool.c
3363 </sect2>
3364 <sect2>
3365 <title>Logical Rings, Logical Ring Contexts and Execlists</title>
3366!Pdrivers/gpu/drm/i915/intel_lrc.c Logical Rings, Logical Ring Contexts and Execlists
3367!Idrivers/gpu/drm/i915/intel_lrc.c
3368 </sect2>
3369 <sect2>
3370 <title>Global GTT views</title>
3371!Pdrivers/gpu/drm/i915/i915_gem_gtt.c Global GTT views
3372!Idrivers/gpu/drm/i915/i915_gem_gtt.c
3373 </sect2>
3374 <sect2>
3375 <title>GTT Fences and Swizzling</title>
3376!Idrivers/gpu/drm/i915/i915_gem_fence.c
3377 <sect3>
3378 <title>Global GTT Fence Handling</title>
3379!Pdrivers/gpu/drm/i915/i915_gem_fence.c fence register handling
3380 </sect3>
3381 <sect3>
3382 <title>Hardware Tiling and Swizzling Details</title>
3383!Pdrivers/gpu/drm/i915/i915_gem_fence.c tiling swizzling details
3384 </sect3>
3385 </sect2>
3386 <sect2>
3387 <title>Object Tiling IOCTLs</title>
3388!Idrivers/gpu/drm/i915/i915_gem_tiling.c
3389!Pdrivers/gpu/drm/i915/i915_gem_tiling.c buffer object tiling
3390 </sect2>
3391 <sect2>
3392 <title>Buffer Object Eviction</title>
3393 <para>
3394 This section documents the interface functions for evicting buffer
3395 objects to make space available in the virtual gpu address spaces.
3396 Note that this is mostly orthogonal to shrinking buffer objects
3397 caches, which has the goal to make main memory (shared with the gpu
3398 through the unified memory architecture) available.
3399 </para>
3400!Idrivers/gpu/drm/i915/i915_gem_evict.c
3401 </sect2>
3402 <sect2>
3403 <title>Buffer Object Memory Shrinking</title>
3404 <para>
3405 This section documents the interface function for shrinking memory
3406 usage of buffer object caches. Shrinking is used to make main memory
3407 available. Note that this is mostly orthogonal to evicting buffer
3408 objects, which has the goal to make space in gpu virtual address
3409 spaces.
3410 </para>
3411!Idrivers/gpu/drm/i915/i915_gem_shrinker.c
3412 </sect2>
3413 </sect1>
3414 <sect1>
3415 <title>GuC</title>
3416 <sect2>
3417 <title>GuC-specific firmware loader</title>
3418!Pdrivers/gpu/drm/i915/intel_guc_loader.c GuC-specific firmware loader
3419!Idrivers/gpu/drm/i915/intel_guc_loader.c
3420 </sect2>
3421 <sect2>
3422 <title>GuC-based command submission</title>
3423!Pdrivers/gpu/drm/i915/i915_guc_submission.c GuC-based command submission
3424!Idrivers/gpu/drm/i915/i915_guc_submission.c
3425 </sect2>
3426 <sect2>
3427 <title>GuC Firmware Layout</title>
3428!Pdrivers/gpu/drm/i915/intel_guc_fwif.h GuC Firmware Layout
3429 </sect2>
3430 </sect1>
3431
3432 <sect1>
3433 <title> Tracing </title>
3434 <para>
3435 This sections covers all things related to the tracepoints implemented in
3436 the i915 driver.
3437 </para>
3438 <sect2>
3439 <title> i915_ppgtt_create and i915_ppgtt_release </title>
3440!Pdrivers/gpu/drm/i915/i915_trace.h i915_ppgtt_create and i915_ppgtt_release tracepoints
3441 </sect2>
3442 <sect2>
3443 <title> i915_context_create and i915_context_free </title>
3444!Pdrivers/gpu/drm/i915/i915_trace.h i915_context_create and i915_context_free tracepoints
3445 </sect2>
3446 <sect2>
3447 <title> switch_mm </title>
3448!Pdrivers/gpu/drm/i915/i915_trace.h switch_mm tracepoint
3449 </sect2>
3450 </sect1>
3451
3452 </chapter>
3453!Cdrivers/gpu/drm/i915/i915_irq.c
3454</part>
3455
3456<part id="vga_switcheroo">
3457 <title>vga_switcheroo</title>
3458 <partintro>
3459!Pdrivers/gpu/vga/vga_switcheroo.c Overview
3460 </partintro>
3461
3462 <chapter id="modes_of_use">
3463 <title>Modes of Use</title>
3464 <sect1>
3465 <title>Manual switching and manual power control</title>
3466!Pdrivers/gpu/vga/vga_switcheroo.c Manual switching and manual power control
3467 </sect1>
3468 <sect1>
3469 <title>Driver power control</title>
3470!Pdrivers/gpu/vga/vga_switcheroo.c Driver power control
3471 </sect1>
3472 </chapter>
3473
3474 <chapter id="api">
3475 <title>API</title>
3476 <sect1>
3477 <title>Public functions</title>
3478!Edrivers/gpu/vga/vga_switcheroo.c
3479 </sect1>
3480 <sect1>
3481 <title>Public structures</title>
3482!Finclude/linux/vga_switcheroo.h vga_switcheroo_handler
3483!Finclude/linux/vga_switcheroo.h vga_switcheroo_client_ops
3484 </sect1>
3485 <sect1>
3486 <title>Public constants</title>
3487!Finclude/linux/vga_switcheroo.h vga_switcheroo_handler_flags_t
3488!Finclude/linux/vga_switcheroo.h vga_switcheroo_client_id
3489!Finclude/linux/vga_switcheroo.h vga_switcheroo_state
3490 </sect1>
3491 <sect1>
3492 <title>Private structures</title>
3493!Fdrivers/gpu/vga/vga_switcheroo.c vgasr_priv
3494!Fdrivers/gpu/vga/vga_switcheroo.c vga_switcheroo_client
3495 </sect1>
3496 </chapter>
3497
3498 <chapter id="handlers">
3499 <title>Handlers</title>
3500 <sect1>
3501 <title>apple-gmux Handler</title>
3502!Pdrivers/platform/x86/apple-gmux.c Overview
3503!Pdrivers/platform/x86/apple-gmux.c Interrupt
3504 <sect2>
3505 <title>Graphics mux</title>
3506!Pdrivers/platform/x86/apple-gmux.c Graphics mux
3507 </sect2>
3508 <sect2>
3509 <title>Power control</title>
3510!Pdrivers/platform/x86/apple-gmux.c Power control
3511 </sect2>
3512 <sect2>
3513 <title>Backlight control</title>
3514!Pdrivers/platform/x86/apple-gmux.c Backlight control
3515 </sect2>
3516 <sect2>
3517 <title>Public functions</title>
3518!Iinclude/linux/apple-gmux.h
3519 </sect2>
3520 </sect1>
3521 </chapter>
3522
3523!Cdrivers/gpu/vga/vga_switcheroo.c
3524!Cinclude/linux/vga_switcheroo.h
3525!Cdrivers/platform/x86/apple-gmux.c
3526</part>
3527
3528</book>
diff --git a/Documentation/gpu/drm-internals.rst b/Documentation/gpu/drm-internals.rst
new file mode 100644
index 000000000000..4f7176576feb
--- /dev/null
+++ b/Documentation/gpu/drm-internals.rst
@@ -0,0 +1,378 @@
1=============
2DRM Internals
3=============
4
5This chapter documents DRM internals relevant to driver authors and
6developers working to add support for the latest features to existing
7drivers.
8
9First, we go over some typical driver initialization requirements, like
10setting up command buffers, creating an initial output configuration,
11and initializing core services. Subsequent sections cover core internals
12in more detail, providing implementation notes and examples.
13
14The DRM layer provides several services to graphics drivers, many of
15them driven by the application interfaces it provides through libdrm,
16the library that wraps most of the DRM ioctls. These include vblank
17event handling, memory management, output management, framebuffer
18management, command submission & fencing, suspend/resume support, and
19DMA services.
20
21Driver Initialization
22=====================
23
24At the core of every DRM driver is a :c:type:`struct drm_driver
25<drm_driver>` structure. Drivers typically statically initialize
26a drm_driver structure, and then pass it to
27:c:func:`drm_dev_alloc()` to allocate a device instance. After the
28device instance is fully initialized it can be registered (which makes
29it accessible from userspace) using :c:func:`drm_dev_register()`.
30
31The :c:type:`struct drm_driver <drm_driver>` structure
32contains static information that describes the driver and features it
33supports, and pointers to methods that the DRM core will call to
34implement the DRM API. We will first go through the :c:type:`struct
35drm_driver <drm_driver>` static information fields, and will
36then describe individual operations in details as they get used in later
37sections.
38
39Driver Information
40------------------
41
42Driver Features
43~~~~~~~~~~~~~~~
44
45Drivers inform the DRM core about their requirements and supported
46features by setting appropriate flags in the driver_features field.
47Since those flags influence the DRM core behaviour since registration
48time, most of them must be set to registering the :c:type:`struct
49drm_driver <drm_driver>` instance.
50
51u32 driver_features;
52
53DRIVER_USE_AGP
54 Driver uses AGP interface, the DRM core will manage AGP resources.
55
56DRIVER_REQUIRE_AGP
57 Driver needs AGP interface to function. AGP initialization failure
58 will become a fatal error.
59
60DRIVER_PCI_DMA
61 Driver is capable of PCI DMA, mapping of PCI DMA buffers to
62 userspace will be enabled. Deprecated.
63
64DRIVER_SG
65 Driver can perform scatter/gather DMA, allocation and mapping of
66 scatter/gather buffers will be enabled. Deprecated.
67
68DRIVER_HAVE_DMA
69 Driver supports DMA, the userspace DMA API will be supported.
70 Deprecated.
71
72DRIVER_HAVE_IRQ; DRIVER_IRQ_SHARED
73 DRIVER_HAVE_IRQ indicates whether the driver has an IRQ handler
74 managed by the DRM Core. The core will support simple IRQ handler
75 installation when the flag is set. The installation process is
76 described in ?.
77
78 DRIVER_IRQ_SHARED indicates whether the device & handler support
79 shared IRQs (note that this is required of PCI drivers).
80
81DRIVER_GEM
82 Driver use the GEM memory manager.
83
84DRIVER_MODESET
85 Driver supports mode setting interfaces (KMS).
86
87DRIVER_PRIME
88 Driver implements DRM PRIME buffer sharing.
89
90DRIVER_RENDER
91 Driver supports dedicated render nodes.
92
93DRIVER_ATOMIC
94 Driver supports atomic properties. In this case the driver must
95 implement appropriate obj->atomic_get_property() vfuncs for any
96 modeset objects with driver specific properties.
97
98Major, Minor and Patchlevel
99~~~~~~~~~~~~~~~~~~~~~~~~~~~
100
101int major; int minor; int patchlevel;
102The DRM core identifies driver versions by a major, minor and patch
103level triplet. The information is printed to the kernel log at
104initialization time and passed to userspace through the
105DRM_IOCTL_VERSION ioctl.
106
107The major and minor numbers are also used to verify the requested driver
108API version passed to DRM_IOCTL_SET_VERSION. When the driver API
109changes between minor versions, applications can call
110DRM_IOCTL_SET_VERSION to select a specific version of the API. If the
111requested major isn't equal to the driver major, or the requested minor
112is larger than the driver minor, the DRM_IOCTL_SET_VERSION call will
113return an error. Otherwise the driver's set_version() method will be
114called with the requested version.
115
116Name, Description and Date
117~~~~~~~~~~~~~~~~~~~~~~~~~~
118
119char \*name; char \*desc; char \*date;
120The driver name is printed to the kernel log at initialization time,
121used for IRQ registration and passed to userspace through
122DRM_IOCTL_VERSION.
123
124The driver description is a purely informative string passed to
125userspace through the DRM_IOCTL_VERSION ioctl and otherwise unused by
126the kernel.
127
128The driver date, formatted as YYYYMMDD, is meant to identify the date of
129the latest modification to the driver. However, as most drivers fail to
130update it, its value is mostly useless. The DRM core prints it to the
131kernel log at initialization time and passes it to userspace through the
132DRM_IOCTL_VERSION ioctl.
133
134Device Instance and Driver Handling
135-----------------------------------
136
137.. kernel-doc:: drivers/gpu/drm/drm_drv.c
138 :doc: driver instance overview
139
140.. kernel-doc:: drivers/gpu/drm/drm_drv.c
141 :export:
142
143Driver Load
144-----------
145
146IRQ Registration
147~~~~~~~~~~~~~~~~
148
149The DRM core tries to facilitate IRQ handler registration and
150unregistration by providing :c:func:`drm_irq_install()` and
151:c:func:`drm_irq_uninstall()` functions. Those functions only
152support a single interrupt per device, devices that use more than one
153IRQs need to be handled manually.
154
155Managed IRQ Registration
156''''''''''''''''''''''''
157
158:c:func:`drm_irq_install()` starts by calling the irq_preinstall
159driver operation. The operation is optional and must make sure that the
160interrupt will not get fired by clearing all pending interrupt flags or
161disabling the interrupt.
162
163The passed-in IRQ will then be requested by a call to
164:c:func:`request_irq()`. If the DRIVER_IRQ_SHARED driver feature
165flag is set, a shared (IRQF_SHARED) IRQ handler will be requested.
166
167The IRQ handler function must be provided as the mandatory irq_handler
168driver operation. It will get passed directly to
169:c:func:`request_irq()` and thus has the same prototype as all IRQ
170handlers. It will get called with a pointer to the DRM device as the
171second argument.
172
173Finally the function calls the optional irq_postinstall driver
174operation. The operation usually enables interrupts (excluding the
175vblank interrupt, which is enabled separately), but drivers may choose
176to enable/disable interrupts at a different time.
177
178:c:func:`drm_irq_uninstall()` is similarly used to uninstall an
179IRQ handler. It starts by waking up all processes waiting on a vblank
180interrupt to make sure they don't hang, and then calls the optional
181irq_uninstall driver operation. The operation must disable all hardware
182interrupts. Finally the function frees the IRQ by calling
183:c:func:`free_irq()`.
184
185Manual IRQ Registration
186'''''''''''''''''''''''
187
188Drivers that require multiple interrupt handlers can't use the managed
189IRQ registration functions. In that case IRQs must be registered and
190unregistered manually (usually with the :c:func:`request_irq()` and
191:c:func:`free_irq()` functions, or their devm_\* equivalent).
192
193When manually registering IRQs, drivers must not set the
194DRIVER_HAVE_IRQ driver feature flag, and must not provide the
195irq_handler driver operation. They must set the :c:type:`struct
196drm_device <drm_device>` irq_enabled field to 1 upon
197registration of the IRQs, and clear it to 0 after unregistering the
198IRQs.
199
200Memory Manager Initialization
201~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
202
203Every DRM driver requires a memory manager which must be initialized at
204load time. DRM currently contains two memory managers, the Translation
205Table Manager (TTM) and the Graphics Execution Manager (GEM). This
206document describes the use of the GEM memory manager only. See ? for
207details.
208
209Miscellaneous Device Configuration
210~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211
212Another task that may be necessary for PCI devices during configuration
213is mapping the video BIOS. On many devices, the VBIOS describes device
214configuration, LCD panel timings (if any), and contains flags indicating
215device state. Mapping the BIOS can be done using the pci_map_rom()
216call, a convenience function that takes care of mapping the actual ROM,
217whether it has been shadowed into memory (typically at address 0xc0000)
218or exists on the PCI device in the ROM BAR. Note that after the ROM has
219been mapped and any necessary information has been extracted, it should
220be unmapped; on many devices, the ROM address decoder is shared with
221other BARs, so leaving it mapped could cause undesired behaviour like
222hangs or memory corruption.
223
224Bus-specific Device Registration and PCI Support
225------------------------------------------------
226
227A number of functions are provided to help with device registration. The
228functions deal with PCI and platform devices respectively and are only
229provided for historical reasons. These are all deprecated and shouldn't
230be used in new drivers. Besides that there's a few helpers for pci
231drivers.
232
233.. kernel-doc:: drivers/gpu/drm/drm_pci.c
234 :export:
235
236.. kernel-doc:: drivers/gpu/drm/drm_platform.c
237 :export:
238
239Open/Close, File Operations and IOCTLs
240======================================
241
242Open and Close
243--------------
244
245int (\*firstopen) (struct drm_device \*); void (\*lastclose) (struct
246drm_device \*); int (\*open) (struct drm_device \*, struct drm_file
247\*); void (\*preclose) (struct drm_device \*, struct drm_file \*);
248void (\*postclose) (struct drm_device \*, struct drm_file \*);
249 Open and close handlers. None of those methods are mandatory.
250
251The firstopen method is called by the DRM core for legacy UMS (User Mode
252Setting) drivers only when an application opens a device that has no
253other opened file handle. UMS drivers can implement it to acquire device
254resources. KMS drivers can't use the method and must acquire resources
255in the load method instead.
256
257Similarly the lastclose method is called when the last application
258holding a file handle opened on the device closes it, for both UMS and
259KMS drivers. Additionally, the method is also called at module unload
260time or, for hot-pluggable devices, when the device is unplugged. The
261firstopen and lastclose calls can thus be unbalanced.
262
263The open method is called every time the device is opened by an
264application. Drivers can allocate per-file private data in this method
265and store them in the struct :c:type:`struct drm_file
266<drm_file>` driver_priv field. Note that the open method is
267called before firstopen.
268
269The close operation is split into preclose and postclose methods.
270Drivers must stop and cleanup all per-file operations in the preclose
271method. For instance pending vertical blanking and page flip events must
272be cancelled. No per-file operation is allowed on the file handle after
273returning from the preclose method.
274
275Finally the postclose method is called as the last step of the close
276operation, right before calling the lastclose method if no other open
277file handle exists for the device. Drivers that have allocated per-file
278private data in the open method should free it here.
279
280The lastclose method should restore CRTC and plane properties to default
281value, so that a subsequent open of the device will not inherit state
282from the previous user. It can also be used to execute delayed power
283switching state changes, e.g. in conjunction with the vga_switcheroo
284infrastructure (see ?). Beyond that KMS drivers should not do any
285further cleanup. Only legacy UMS drivers might need to clean up device
286state so that the vga console or an independent fbdev driver could take
287over.
288
289File Operations
290---------------
291
292.. kernel-doc:: drivers/gpu/drm/drm_fops.c
293 :doc: file operations
294
295.. kernel-doc:: drivers/gpu/drm/drm_fops.c
296 :export:
297
298IOCTLs
299------
300
301struct drm_ioctl_desc \*ioctls; int num_ioctls;
302 Driver-specific ioctls descriptors table.
303
304Driver-specific ioctls numbers start at DRM_COMMAND_BASE. The ioctls
305descriptors table is indexed by the ioctl number offset from the base
306value. Drivers can use the DRM_IOCTL_DEF_DRV() macro to initialize
307the table entries.
308
309::
310
311 DRM_IOCTL_DEF_DRV(ioctl, func, flags)
312
313``ioctl`` is the ioctl name. Drivers must define the DRM_##ioctl and
314DRM_IOCTL_##ioctl macros to the ioctl number offset from
315DRM_COMMAND_BASE and the ioctl number respectively. The first macro is
316private to the device while the second must be exposed to userspace in a
317public header.
318
319``func`` is a pointer to the ioctl handler function compatible with the
320``drm_ioctl_t`` type.
321
322::
323
324 typedef int drm_ioctl_t(struct drm_device *dev, void *data,
325 struct drm_file *file_priv);
326
327``flags`` is a bitmask combination of the following values. It restricts
328how the ioctl is allowed to be called.
329
330- DRM_AUTH - Only authenticated callers allowed
331
332- DRM_MASTER - The ioctl can only be called on the master file handle
333
334- DRM_ROOT_ONLY - Only callers with the SYSADMIN capability allowed
335
336- DRM_CONTROL_ALLOW - The ioctl can only be called on a control
337 device
338
339- DRM_UNLOCKED - The ioctl handler will be called without locking the
340 DRM global mutex. This is the enforced default for kms drivers (i.e.
341 using the DRIVER_MODESET flag) and hence shouldn't be used any more
342 for new drivers.
343
344.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
345 :export:
346
347Legacy Support Code
348===================
349
350The section very briefly covers some of the old legacy support code
351which is only used by old DRM drivers which have done a so-called
352shadow-attach to the underlying device instead of registering as a real
353driver. This also includes some of the old generic buffer management and
354command submission code. Do not use any of this in new and modern
355drivers.
356
357Legacy Suspend/Resume
358---------------------
359
360The DRM core provides some suspend/resume code, but drivers wanting full
361suspend/resume support should provide save() and restore() functions.
362These are called at suspend, hibernate, or resume time, and should
363perform any state save or restore required by your device across suspend
364or hibernate states.
365
366int (\*suspend) (struct drm_device \*, pm_message_t state); int
367(\*resume) (struct drm_device \*);
368Those are legacy suspend and resume methods which *only* work with the
369legacy shadow-attach driver registration functions. New driver should
370use the power management interface provided by their bus type (usually
371through the :c:type:`struct device_driver <device_driver>`
372dev_pm_ops) and set these methods to NULL.
373
374Legacy DMA Services
375-------------------
376
377This should cover how DMA mapping etc. is supported by the core. These
378functions are deprecated and should not be used.
diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst
new file mode 100644
index 000000000000..0b302fedf1af
--- /dev/null
+++ b/Documentation/gpu/drm-kms-helpers.rst
@@ -0,0 +1,260 @@
1=============================
2Mode Setting Helper Functions
3=============================
4
5The plane, CRTC, encoder and connector functions provided by the drivers
6implement the DRM API. They're called by the DRM core and ioctl handlers
7to handle device state changes and configuration request. As
8implementing those functions often requires logic not specific to
9drivers, mid-layer helper functions are available to avoid duplicating
10boilerplate code.
11
12The DRM core contains one mid-layer implementation. The mid-layer
13provides implementations of several plane, CRTC, encoder and connector
14functions (called from the top of the mid-layer) that pre-process
15requests and call lower-level functions provided by the driver (at the
16bottom of the mid-layer). For instance, the
17:c:func:`drm_crtc_helper_set_config()` function can be used to
18fill the :c:type:`struct drm_crtc_funcs <drm_crtc_funcs>`
19set_config field. When called, it will split the set_config operation
20in smaller, simpler operations and call the driver to handle them.
21
22To use the mid-layer, drivers call
23:c:func:`drm_crtc_helper_add()`,
24:c:func:`drm_encoder_helper_add()` and
25:c:func:`drm_connector_helper_add()` functions to install their
26mid-layer bottom operations handlers, and fill the :c:type:`struct
27drm_crtc_funcs <drm_crtc_funcs>`, :c:type:`struct
28drm_encoder_funcs <drm_encoder_funcs>` and :c:type:`struct
29drm_connector_funcs <drm_connector_funcs>` structures with
30pointers to the mid-layer top API functions. Installing the mid-layer
31bottom operation handlers is best done right after registering the
32corresponding KMS object.
33
34The mid-layer is not split between CRTC, encoder and connector
35operations. To use it, a driver must provide bottom functions for all of
36the three KMS entities.
37
38Atomic Modeset Helper Functions Reference
39=========================================
40
41Overview
42--------
43
44.. kernel-doc:: drivers/gpu/drm/drm_atomic_helper.c
45 :doc: overview
46
47Implementing Asynchronous Atomic Commit
48---------------------------------------
49
50.. kernel-doc:: drivers/gpu/drm/drm_atomic_helper.c
51 :doc: implementing nonblocking commit
52
53Atomic State Reset and Initialization
54-------------------------------------
55
56.. kernel-doc:: drivers/gpu/drm/drm_atomic_helper.c
57 :doc: atomic state reset and initialization
58
59.. kernel-doc:: include/drm/drm_atomic_helper.h
60 :internal:
61
62.. kernel-doc:: drivers/gpu/drm/drm_atomic_helper.c
63 :export:
64
65Modeset Helper Reference for Common Vtables
66===========================================
67
68.. kernel-doc:: include/drm/drm_modeset_helper_vtables.h
69 :internal:
70
71.. kernel-doc:: include/drm/drm_modeset_helper_vtables.h
72 :doc: overview
73
74Legacy CRTC/Modeset Helper Functions Reference
75==============================================
76
77.. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
78 :export:
79
80.. kernel-doc:: drivers/gpu/drm/drm_crtc_helper.c
81 :doc: overview
82
83Output Probing Helper Functions Reference
84=========================================
85
86.. kernel-doc:: drivers/gpu/drm/drm_probe_helper.c
87 :doc: output probing helper overview
88
89.. kernel-doc:: drivers/gpu/drm/drm_probe_helper.c
90 :export:
91
92fbdev Helper Functions Reference
93================================
94
95.. kernel-doc:: drivers/gpu/drm/drm_fb_helper.c
96 :doc: fbdev helpers
97
98.. kernel-doc:: drivers/gpu/drm/drm_fb_helper.c
99 :export:
100
101.. kernel-doc:: include/drm/drm_fb_helper.h
102 :internal:
103
104Framebuffer CMA Helper Functions Reference
105==========================================
106
107.. kernel-doc:: drivers/gpu/drm/drm_fb_cma_helper.c
108 :doc: framebuffer cma helper functions
109
110.. kernel-doc:: drivers/gpu/drm/drm_fb_cma_helper.c
111 :export:
112
113Display Port Helper Functions Reference
114=======================================
115
116.. kernel-doc:: drivers/gpu/drm/drm_dp_helper.c
117 :doc: dp helpers
118
119.. kernel-doc:: include/drm/drm_dp_helper.h
120 :internal:
121
122.. kernel-doc:: drivers/gpu/drm/drm_dp_helper.c
123 :export:
124
125Display Port Dual Mode Adaptor Helper Functions Reference
126=========================================================
127
128.. kernel-doc:: drivers/gpu/drm/drm_dp_dual_mode_helper.c
129 :doc: dp dual mode helpers
130
131.. kernel-doc:: include/drm/drm_dp_dual_mode_helper.h
132 :internal:
133
134.. kernel-doc:: drivers/gpu/drm/drm_dp_dual_mode_helper.c
135 :export:
136
137Display Port MST Helper Functions Reference
138===========================================
139
140.. kernel-doc:: drivers/gpu/drm/drm_dp_mst_topology.c
141 :doc: dp mst helper
142
143.. kernel-doc:: include/drm/drm_dp_mst_helper.h
144 :internal:
145
146.. kernel-doc:: drivers/gpu/drm/drm_dp_mst_topology.c
147 :export:
148
149MIPI DSI Helper Functions Reference
150===================================
151
152.. kernel-doc:: drivers/gpu/drm/drm_mipi_dsi.c
153 :doc: dsi helpers
154
155.. kernel-doc:: include/drm/drm_mipi_dsi.h
156 :internal:
157
158.. kernel-doc:: drivers/gpu/drm/drm_mipi_dsi.c
159 :export:
160
161EDID Helper Functions Reference
162===============================
163
164.. kernel-doc:: drivers/gpu/drm/drm_edid.c
165 :export:
166
167Rectangle Utilities Reference
168=============================
169
170.. kernel-doc:: include/drm/drm_rect.h
171 :doc: rect utils
172
173.. kernel-doc:: include/drm/drm_rect.h
174 :internal:
175
176.. kernel-doc:: drivers/gpu/drm/drm_rect.c
177 :export:
178
179Flip-work Helper Reference
180==========================
181
182.. kernel-doc:: include/drm/drm_flip_work.h
183 :doc: flip utils
184
185.. kernel-doc:: include/drm/drm_flip_work.h
186 :internal:
187
188.. kernel-doc:: drivers/gpu/drm/drm_flip_work.c
189 :export:
190
191HDMI Infoframes Helper Reference
192================================
193
194Strictly speaking this is not a DRM helper library but generally useable
195by any driver interfacing with HDMI outputs like v4l or alsa drivers.
196But it nicely fits into the overall topic of mode setting helper
197libraries and hence is also included here.
198
199.. kernel-doc:: include/linux/hdmi.h
200 :internal:
201
202.. kernel-doc:: drivers/video/hdmi.c
203 :export:
204
205Plane Helper Reference
206======================
207
208.. kernel-doc:: drivers/gpu/drm/drm_plane_helper.c
209 :export:
210
211.. kernel-doc:: drivers/gpu/drm/drm_plane_helper.c
212 :doc: overview
213
214Tile group
215----------
216
217.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
218 :doc: Tile group
219
220Bridges
221=======
222
223Overview
224--------
225
226.. kernel-doc:: drivers/gpu/drm/drm_bridge.c
227 :doc: overview
228
229Default bridge callback sequence
230--------------------------------
231
232.. kernel-doc:: drivers/gpu/drm/drm_bridge.c
233 :doc: bridge callbacks
234
235.. kernel-doc:: drivers/gpu/drm/drm_bridge.c
236 :export:
237
238Panel Helper Reference
239======================
240
241.. kernel-doc:: include/drm/drm_panel.h
242 :internal:
243
244.. kernel-doc:: drivers/gpu/drm/drm_panel.c
245 :export:
246
247.. kernel-doc:: drivers/gpu/drm/drm_panel.c
248 :doc: drm panel
249
250Simple KMS Helper Reference
251===========================
252
253.. kernel-doc:: include/drm/drm_simple_kms_helper.h
254 :internal:
255
256.. kernel-doc:: drivers/gpu/drm/drm_simple_kms_helper.c
257 :export:
258
259.. kernel-doc:: drivers/gpu/drm/drm_simple_kms_helper.c
260 :doc: overview
diff --git a/Documentation/gpu/drm-kms.rst b/Documentation/gpu/drm-kms.rst
new file mode 100644
index 000000000000..0e1c80436c1d
--- /dev/null
+++ b/Documentation/gpu/drm-kms.rst
@@ -0,0 +1,656 @@
1=========================
2Kernel Mode Setting (KMS)
3=========================
4
5Mode Setting
6============
7
8Drivers must initialize the mode setting core by calling
9:c:func:`drm_mode_config_init()` on the DRM device. The function
10initializes the :c:type:`struct drm_device <drm_device>`
11mode_config field and never fails. Once done, mode configuration must
12be setup by initializing the following fields.
13
14- int min_width, min_height; int max_width, max_height;
15 Minimum and maximum width and height of the frame buffers in pixel
16 units.
17
18- struct drm_mode_config_funcs \*funcs;
19 Mode setting functions.
20
21Display Modes Function Reference
22--------------------------------
23
24.. kernel-doc:: include/drm/drm_modes.h
25 :internal:
26
27.. kernel-doc:: drivers/gpu/drm/drm_modes.c
28 :export:
29
30Atomic Mode Setting Function Reference
31--------------------------------------
32
33.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
34 :export:
35
36.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
37 :internal:
38
39Frame Buffer Abstraction
40------------------------
41
42Frame buffers are abstract memory objects that provide a source of
43pixels to scanout to a CRTC. Applications explicitly request the
44creation of frame buffers through the DRM_IOCTL_MODE_ADDFB(2) ioctls
45and receive an opaque handle that can be passed to the KMS CRTC control,
46plane configuration and page flip functions.
47
48Frame buffers rely on the underneath memory manager for low-level memory
49operations. When creating a frame buffer applications pass a memory
50handle (or a list of memory handles for multi-planar formats) through
51the ``drm_mode_fb_cmd2`` argument. For drivers using GEM as their
52userspace buffer management interface this would be a GEM handle.
53Drivers are however free to use their own backing storage object
54handles, e.g. vmwgfx directly exposes special TTM handles to userspace
55and so expects TTM handles in the create ioctl and not GEM handles.
56
57The lifetime of a drm framebuffer is controlled with a reference count,
58drivers can grab additional references with
59:c:func:`drm_framebuffer_reference()`and drop them again with
60:c:func:`drm_framebuffer_unreference()`. For driver-private
61framebuffers for which the last reference is never dropped (e.g. for the
62fbdev framebuffer when the struct :c:type:`struct drm_framebuffer
63<drm_framebuffer>` is embedded into the fbdev helper struct)
64drivers can manually clean up a framebuffer at module unload time with
65:c:func:`drm_framebuffer_unregister_private()`.
66
67DRM Format Handling
68-------------------
69
70.. kernel-doc:: include/drm/drm_fourcc.h
71 :internal:
72
73.. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
74 :export:
75
76Dumb Buffer Objects
77-------------------
78
79The KMS API doesn't standardize backing storage object creation and
80leaves it to driver-specific ioctls. Furthermore actually creating a
81buffer object even for GEM-based drivers is done through a
82driver-specific ioctl - GEM only has a common userspace interface for
83sharing and destroying objects. While not an issue for full-fledged
84graphics stacks that include device-specific userspace components (in
85libdrm for instance), this limit makes DRM-based early boot graphics
86unnecessarily complex.
87
88Dumb objects partly alleviate the problem by providing a standard API to
89create dumb buffers suitable for scanout, which can then be used to
90create KMS frame buffers.
91
92To support dumb objects drivers must implement the dumb_create,
93dumb_destroy and dumb_map_offset operations.
94
95- int (\*dumb_create)(struct drm_file \*file_priv, struct
96 drm_device \*dev, struct drm_mode_create_dumb \*args);
97 The dumb_create operation creates a driver object (GEM or TTM
98 handle) suitable for scanout based on the width, height and depth
99 from the struct :c:type:`struct drm_mode_create_dumb
100 <drm_mode_create_dumb>` argument. It fills the argument's
101 handle, pitch and size fields with a handle for the newly created
102 object and its line pitch and size in bytes.
103
104- int (\*dumb_destroy)(struct drm_file \*file_priv, struct
105 drm_device \*dev, uint32_t handle);
106 The dumb_destroy operation destroys a dumb object created by
107 dumb_create.
108
109- int (\*dumb_map_offset)(struct drm_file \*file_priv, struct
110 drm_device \*dev, uint32_t handle, uint64_t \*offset);
111 The dumb_map_offset operation associates an mmap fake offset with
112 the object given by the handle and returns it. Drivers must use the
113 :c:func:`drm_gem_create_mmap_offset()` function to associate
114 the fake offset as described in ?.
115
116Note that dumb objects may not be used for gpu acceleration, as has been
117attempted on some ARM embedded platforms. Such drivers really must have
118a hardware-specific ioctl to allocate suitable buffer objects.
119
120Output Polling
121--------------
122
123void (\*output_poll_changed)(struct drm_device \*dev);
124This operation notifies the driver that the status of one or more
125connectors has changed. Drivers that use the fb helper can just call the
126:c:func:`drm_fb_helper_hotplug_event()` function to handle this
127operation.
128
129KMS Initialization and Cleanup
130==============================
131
132A KMS device is abstracted and exposed as a set of planes, CRTCs,
133encoders and connectors. KMS drivers must thus create and initialize all
134those objects at load time after initializing mode setting.
135
136CRTCs (:c:type:`struct drm_crtc <drm_crtc>`)
137--------------------------------------------
138
139A CRTC is an abstraction representing a part of the chip that contains a
140pointer to a scanout buffer. Therefore, the number of CRTCs available
141determines how many independent scanout buffers can be active at any
142given time. The CRTC structure contains several fields to support this:
143a pointer to some video memory (abstracted as a frame buffer object), a
144display mode, and an (x, y) offset into the video memory to support
145panning or configurations where one piece of video memory spans multiple
146CRTCs.
147
148CRTC Initialization
149~~~~~~~~~~~~~~~~~~~
150
151A KMS device must create and register at least one struct
152:c:type:`struct drm_crtc <drm_crtc>` instance. The instance is
153allocated and zeroed by the driver, possibly as part of a larger
154structure, and registered with a call to :c:func:`drm_crtc_init()`
155with a pointer to CRTC functions.
156
157Planes (:c:type:`struct drm_plane <drm_plane>`)
158-----------------------------------------------
159
160A plane represents an image source that can be blended with or overlayed
161on top of a CRTC during the scanout process. Planes are associated with
162a frame buffer to crop a portion of the image memory (source) and
163optionally scale it to a destination size. The result is then blended
164with or overlayed on top of a CRTC.
165
166The DRM core recognizes three types of planes:
167
168- DRM_PLANE_TYPE_PRIMARY represents a "main" plane for a CRTC.
169 Primary planes are the planes operated upon by CRTC modesetting and
170 flipping operations described in the page_flip hook in
171 :c:type:`struct drm_crtc_funcs <drm_crtc_funcs>`.
172- DRM_PLANE_TYPE_CURSOR represents a "cursor" plane for a CRTC.
173 Cursor planes are the planes operated upon by the
174 DRM_IOCTL_MODE_CURSOR and DRM_IOCTL_MODE_CURSOR2 ioctls.
175- DRM_PLANE_TYPE_OVERLAY represents all non-primary, non-cursor
176 planes. Some drivers refer to these types of planes as "sprites"
177 internally.
178
179For compatibility with legacy userspace, only overlay planes are made
180available to userspace by default. Userspace clients may set the
181DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate
182that they wish to receive a universal plane list containing all plane
183types.
184
185Plane Initialization
186~~~~~~~~~~~~~~~~~~~~
187
188To create a plane, a KMS drivers allocates and zeroes an instances of
189:c:type:`struct drm_plane <drm_plane>` (possibly as part of a
190larger structure) and registers it with a call to
191:c:func:`drm_universal_plane_init()`. The function takes a
192bitmask of the CRTCs that can be associated with the plane, a pointer to
193the plane functions, a list of format supported formats, and the type of
194plane (primary, cursor, or overlay) being initialized.
195
196Cursor and overlay planes are optional. All drivers should provide one
197primary plane per CRTC (although this requirement may change in the
198future); drivers that do not wish to provide special handling for
199primary planes may make use of the helper functions described in ? to
200create and register a primary plane with standard capabilities.
201
202Encoders (:c:type:`struct drm_encoder <drm_encoder>`)
203-----------------------------------------------------
204
205An encoder takes pixel data from a CRTC and converts it to a format
206suitable for any attached connectors. On some devices, it may be
207possible to have a CRTC send data to more than one encoder. In that
208case, both encoders would receive data from the same scanout buffer,
209resulting in a "cloned" display configuration across the connectors
210attached to each encoder.
211
212Encoder Initialization
213~~~~~~~~~~~~~~~~~~~~~~
214
215As for CRTCs, a KMS driver must create, initialize and register at least
216one :c:type:`struct drm_encoder <drm_encoder>` instance. The
217instance is allocated and zeroed by the driver, possibly as part of a
218larger structure.
219
220Drivers must initialize the :c:type:`struct drm_encoder
221<drm_encoder>` possible_crtcs and possible_clones fields before
222registering the encoder. Both fields are bitmasks of respectively the
223CRTCs that the encoder can be connected to, and sibling encoders
224candidate for cloning.
225
226After being initialized, the encoder must be registered with a call to
227:c:func:`drm_encoder_init()`. The function takes a pointer to the
228encoder functions and an encoder type. Supported types are
229
230- DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A
231- DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort
232- DRM_MODE_ENCODER_LVDS for display panels
233- DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video,
234 Component, SCART)
235- DRM_MODE_ENCODER_VIRTUAL for virtual machine displays
236
237Encoders must be attached to a CRTC to be used. DRM drivers leave
238encoders unattached at initialization time. Applications (or the fbdev
239compatibility layer when implemented) are responsible for attaching the
240encoders they want to use to a CRTC.
241
242Connectors (:c:type:`struct drm_connector <drm_connector>`)
243-----------------------------------------------------------
244
245A connector is the final destination for pixel data on a device, and
246usually connects directly to an external display device like a monitor
247or laptop panel. A connector can only be attached to one encoder at a
248time. The connector is also the structure where information about the
249attached display is kept, so it contains fields for display data, EDID
250data, DPMS & connection status, and information about modes supported on
251the attached displays.
252
253Connector Initialization
254~~~~~~~~~~~~~~~~~~~~~~~~
255
256Finally a KMS driver must create, initialize, register and attach at
257least one :c:type:`struct drm_connector <drm_connector>`
258instance. The instance is created as other KMS objects and initialized
259by setting the following fields.
260
261interlace_allowed
262 Whether the connector can handle interlaced modes.
263
264doublescan_allowed
265 Whether the connector can handle doublescan.
266
267display_info
268 Display information is filled from EDID information when a display
269 is detected. For non hot-pluggable displays such as flat panels in
270 embedded systems, the driver should initialize the
271 display_info.width_mm and display_info.height_mm fields with the
272 physical size of the display.
273
274polled
275 Connector polling mode, a combination of
276
277 DRM_CONNECTOR_POLL_HPD
278 The connector generates hotplug events and doesn't need to be
279 periodically polled. The CONNECT and DISCONNECT flags must not
280 be set together with the HPD flag.
281
282 DRM_CONNECTOR_POLL_CONNECT
283 Periodically poll the connector for connection.
284
285 DRM_CONNECTOR_POLL_DISCONNECT
286 Periodically poll the connector for disconnection.
287
288 Set to 0 for connectors that don't support connection status
289 discovery.
290
291The connector is then registered with a call to
292:c:func:`drm_connector_init()` with a pointer to the connector
293functions and a connector type, and exposed through sysfs with a call to
294:c:func:`drm_connector_register()`.
295
296Supported connector types are
297
298- DRM_MODE_CONNECTOR_VGA
299- DRM_MODE_CONNECTOR_DVII
300- DRM_MODE_CONNECTOR_DVID
301- DRM_MODE_CONNECTOR_DVIA
302- DRM_MODE_CONNECTOR_Composite
303- DRM_MODE_CONNECTOR_SVIDEO
304- DRM_MODE_CONNECTOR_LVDS
305- DRM_MODE_CONNECTOR_Component
306- DRM_MODE_CONNECTOR_9PinDIN
307- DRM_MODE_CONNECTOR_DisplayPort
308- DRM_MODE_CONNECTOR_HDMIA
309- DRM_MODE_CONNECTOR_HDMIB
310- DRM_MODE_CONNECTOR_TV
311- DRM_MODE_CONNECTOR_eDP
312- DRM_MODE_CONNECTOR_VIRTUAL
313
314Connectors must be attached to an encoder to be used. For devices that
315map connectors to encoders 1:1, the connector should be attached at
316initialization time with a call to
317:c:func:`drm_mode_connector_attach_encoder()`. The driver must
318also set the :c:type:`struct drm_connector <drm_connector>`
319encoder field to point to the attached encoder.
320
321Finally, drivers must initialize the connectors state change detection
322with a call to :c:func:`drm_kms_helper_poll_init()`. If at least
323one connector is pollable but can't generate hotplug interrupts
324(indicated by the DRM_CONNECTOR_POLL_CONNECT and
325DRM_CONNECTOR_POLL_DISCONNECT connector flags), a delayed work will
326automatically be queued to periodically poll for changes. Connectors
327that can generate hotplug interrupts must be marked with the
328DRM_CONNECTOR_POLL_HPD flag instead, and their interrupt handler must
329call :c:func:`drm_helper_hpd_irq_event()`. The function will
330queue a delayed work to check the state of all connectors, but no
331periodic polling will be done.
332
333Connector Operations
334~~~~~~~~~~~~~~~~~~~~
335
336 **Note**
337
338 Unless otherwise state, all operations are mandatory.
339
340DPMS
341''''
342
343void (\*dpms)(struct drm_connector \*connector, int mode);
344The DPMS operation sets the power state of a connector. The mode
345argument is one of
346
347- DRM_MODE_DPMS_ON
348
349- DRM_MODE_DPMS_STANDBY
350
351- DRM_MODE_DPMS_SUSPEND
352
353- DRM_MODE_DPMS_OFF
354
355In all but DPMS_ON mode the encoder to which the connector is attached
356should put the display in low-power mode by driving its signals
357appropriately. If more than one connector is attached to the encoder
358care should be taken not to change the power state of other displays as
359a side effect. Low-power mode should be propagated to the encoders and
360CRTCs when all related connectors are put in low-power mode.
361
362Modes
363'''''
364
365int (\*fill_modes)(struct drm_connector \*connector, uint32_t
366max_width, uint32_t max_height);
367Fill the mode list with all supported modes for the connector. If the
368``max_width`` and ``max_height`` arguments are non-zero, the
369implementation must ignore all modes wider than ``max_width`` or higher
370than ``max_height``.
371
372The connector must also fill in this operation its display_info
373width_mm and height_mm fields with the connected display physical size
374in millimeters. The fields should be set to 0 if the value isn't known
375or is not applicable (for instance for projector devices).
376
377Connection Status
378'''''''''''''''''
379
380The connection status is updated through polling or hotplug events when
381supported (see ?). The status value is reported to userspace through
382ioctls and must not be used inside the driver, as it only gets
383initialized by a call to :c:func:`drm_mode_getconnector()` from
384userspace.
385
386enum drm_connector_status (\*detect)(struct drm_connector
387\*connector, bool force);
388Check to see if anything is attached to the connector. The ``force``
389parameter is set to false whilst polling or to true when checking the
390connector due to user request. ``force`` can be used by the driver to
391avoid expensive, destructive operations during automated probing.
392
393Return connector_status_connected if something is connected to the
394connector, connector_status_disconnected if nothing is connected and
395connector_status_unknown if the connection state isn't known.
396
397Drivers should only return connector_status_connected if the
398connection status has really been probed as connected. Connectors that
399can't detect the connection status, or failed connection status probes,
400should return connector_status_unknown.
401
402Cleanup
403-------
404
405The DRM core manages its objects' lifetime. When an object is not needed
406anymore the core calls its destroy function, which must clean up and
407free every resource allocated for the object. Every
408:c:func:`drm_\*_init()` call must be matched with a corresponding
409:c:func:`drm_\*_cleanup()` call to cleanup CRTCs
410(:c:func:`drm_crtc_cleanup()`), planes
411(:c:func:`drm_plane_cleanup()`), encoders
412(:c:func:`drm_encoder_cleanup()`) and connectors
413(:c:func:`drm_connector_cleanup()`). Furthermore, connectors that
414have been added to sysfs must be removed by a call to
415:c:func:`drm_connector_unregister()` before calling
416:c:func:`drm_connector_cleanup()`.
417
418Connectors state change detection must be cleanup up with a call to
419:c:func:`drm_kms_helper_poll_fini()`.
420
421Output discovery and initialization example
422-------------------------------------------
423
424::
425
426 void intel_crt_init(struct drm_device *dev)
427 {
428 struct drm_connector *connector;
429 struct intel_output *intel_output;
430
431 intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
432 if (!intel_output)
433 return;
434
435 connector = &intel_output->base;
436 drm_connector_init(dev, &intel_output->base,
437 &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
438
439 drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs,
440 DRM_MODE_ENCODER_DAC);
441
442 drm_mode_connector_attach_encoder(&intel_output->base,
443 &intel_output->enc);
444
445 /* Set up the DDC bus. */
446 intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A");
447 if (!intel_output->ddc_bus) {
448 dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
449 "failed.\n");
450 return;
451 }
452
453 intel_output->type = INTEL_OUTPUT_ANALOG;
454 connector->interlace_allowed = 0;
455 connector->doublescan_allowed = 0;
456
457 drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs);
458 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
459
460 drm_connector_register(connector);
461 }
462
463In the example above (taken from the i915 driver), a CRTC, connector and
464encoder combination is created. A device-specific i2c bus is also
465created for fetching EDID data and performing monitor detection. Once
466the process is complete, the new connector is registered with sysfs to
467make its properties available to applications.
468
469KMS API Functions
470-----------------
471
472.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
473 :export:
474
475KMS Data Structures
476-------------------
477
478.. kernel-doc:: include/drm/drm_crtc.h
479 :internal:
480
481KMS Locking
482-----------
483
484.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
485 :doc: kms locking
486
487.. kernel-doc:: include/drm/drm_modeset_lock.h
488 :internal:
489
490.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
491 :export:
492
493KMS Properties
494==============
495
496Drivers may need to expose additional parameters to applications than
497those described in the previous sections. KMS supports attaching
498properties to CRTCs, connectors and planes and offers a userspace API to
499list, get and set the property values.
500
501Properties are identified by a name that uniquely defines the property
502purpose, and store an associated value. For all property types except
503blob properties the value is a 64-bit unsigned integer.
504
505KMS differentiates between properties and property instances. Drivers
506first create properties and then create and associate individual
507instances of those properties to objects. A property can be instantiated
508multiple times and associated with different objects. Values are stored
509in property instances, and all other property information are stored in
510the property and shared between all instances of the property.
511
512Every property is created with a type that influences how the KMS core
513handles the property. Supported property types are
514
515DRM_MODE_PROP_RANGE
516 Range properties report their minimum and maximum admissible values.
517 The KMS core verifies that values set by application fit in that
518 range.
519
520DRM_MODE_PROP_ENUM
521 Enumerated properties take a numerical value that ranges from 0 to
522 the number of enumerated values defined by the property minus one,
523 and associate a free-formed string name to each value. Applications
524 can retrieve the list of defined value-name pairs and use the
525 numerical value to get and set property instance values.
526
527DRM_MODE_PROP_BITMASK
528 Bitmask properties are enumeration properties that additionally
529 restrict all enumerated values to the 0..63 range. Bitmask property
530 instance values combine one or more of the enumerated bits defined
531 by the property.
532
533DRM_MODE_PROP_BLOB
534 Blob properties store a binary blob without any format restriction.
535 The binary blobs are created as KMS standalone objects, and blob
536 property instance values store the ID of their associated blob
537 object.
538
539 Blob properties are only used for the connector EDID property and
540 cannot be created by drivers.
541
542To create a property drivers call one of the following functions
543depending on the property type. All property creation functions take
544property flags and name, as well as type-specific arguments.
545
546- struct drm_property \*drm_property_create_range(struct
547 drm_device \*dev, int flags, const char \*name, uint64_t min,
548 uint64_t max);
549 Create a range property with the given minimum and maximum values.
550
551- struct drm_property \*drm_property_create_enum(struct drm_device
552 \*dev, int flags, const char \*name, const struct
553 drm_prop_enum_list \*props, int num_values);
554 Create an enumerated property. The ``props`` argument points to an
555 array of ``num_values`` value-name pairs.
556
557- struct drm_property \*drm_property_create_bitmask(struct
558 drm_device \*dev, int flags, const char \*name, const struct
559 drm_prop_enum_list \*props, int num_values);
560 Create a bitmask property. The ``props`` argument points to an array
561 of ``num_values`` value-name pairs.
562
563Properties can additionally be created as immutable, in which case they
564will be read-only for applications but can be modified by the driver. To
565create an immutable property drivers must set the
566DRM_MODE_PROP_IMMUTABLE flag at property creation time.
567
568When no array of value-name pairs is readily available at property
569creation time for enumerated or range properties, drivers can create the
570property using the :c:func:`drm_property_create()` function and
571manually add enumeration value-name pairs by calling the
572:c:func:`drm_property_add_enum()` function. Care must be taken to
573properly specify the property type through the ``flags`` argument.
574
575After creating properties drivers can attach property instances to CRTC,
576connector and plane objects by calling the
577:c:func:`drm_object_attach_property()`. The function takes a
578pointer to the target object, a pointer to the previously created
579property and an initial instance value.
580
581Existing KMS Properties
582-----------------------
583
584The following table gives description of drm properties exposed by
585various modules/drivers.
586
587.. csv-table::
588 :header-rows: 1
589 :file: kms-properties.csv
590
591Vertical Blanking
592=================
593
594Vertical blanking plays a major role in graphics rendering. To achieve
595tear-free display, users must synchronize page flips and/or rendering to
596vertical blanking. The DRM API offers ioctls to perform page flips
597synchronized to vertical blanking and wait for vertical blanking.
598
599The DRM core handles most of the vertical blanking management logic,
600which involves filtering out spurious interrupts, keeping race-free
601blanking counters, coping with counter wrap-around and resets and
602keeping use counts. It relies on the driver to generate vertical
603blanking interrupts and optionally provide a hardware vertical blanking
604counter. Drivers must implement the following operations.
605
606- int (\*enable_vblank) (struct drm_device \*dev, int crtc); void
607 (\*disable_vblank) (struct drm_device \*dev, int crtc);
608 Enable or disable vertical blanking interrupts for the given CRTC.
609
610- u32 (\*get_vblank_counter) (struct drm_device \*dev, int crtc);
611 Retrieve the value of the vertical blanking counter for the given
612 CRTC. If the hardware maintains a vertical blanking counter its value
613 should be returned. Otherwise drivers can use the
614 :c:func:`drm_vblank_count()` helper function to handle this
615 operation.
616
617Drivers must initialize the vertical blanking handling core with a call
618to :c:func:`drm_vblank_init()` in their load operation.
619
620Vertical blanking interrupts can be enabled by the DRM core or by
621drivers themselves (for instance to handle page flipping operations).
622The DRM core maintains a vertical blanking use count to ensure that the
623interrupts are not disabled while a user still needs them. To increment
624the use count, drivers call :c:func:`drm_vblank_get()`. Upon
625return vertical blanking interrupts are guaranteed to be enabled.
626
627To decrement the use count drivers call
628:c:func:`drm_vblank_put()`. Only when the use count drops to zero
629will the DRM core disable the vertical blanking interrupts after a delay
630by scheduling a timer. The delay is accessible through the
631vblankoffdelay module parameter or the ``drm_vblank_offdelay`` global
632variable and expressed in milliseconds. Its default value is 5000 ms.
633Zero means never disable, and a negative value means disable
634immediately. Drivers may override the behaviour by setting the
635:c:type:`struct drm_device <drm_device>`
636vblank_disable_immediate flag, which when set causes vblank interrupts
637to be disabled immediately regardless of the drm_vblank_offdelay
638value. The flag should only be set if there's a properly working
639hardware vblank counter present.
640
641When a vertical blanking interrupt occurs drivers only need to call the
642:c:func:`drm_handle_vblank()` function to account for the
643interrupt.
644
645Resources allocated by :c:func:`drm_vblank_init()` must be freed
646with a call to :c:func:`drm_vblank_cleanup()` in the driver unload
647operation handler.
648
649Vertical Blanking and Interrupt Handling Functions Reference
650------------------------------------------------------------
651
652.. kernel-doc:: drivers/gpu/drm/drm_irq.c
653 :export:
654
655.. kernel-doc:: include/drm/drmP.h
656 :functions: drm_crtc_vblank_waitqueue
diff --git a/Documentation/gpu/drm-mm.rst b/Documentation/gpu/drm-mm.rst
new file mode 100644
index 000000000000..59f9822fecd0
--- /dev/null
+++ b/Documentation/gpu/drm-mm.rst
@@ -0,0 +1,454 @@
1=====================
2DRM Memory Management
3=====================
4
5Modern Linux systems require large amount of graphics memory to store
6frame buffers, textures, vertices and other graphics-related data. Given
7the very dynamic nature of many of that data, managing graphics memory
8efficiently is thus crucial for the graphics stack and plays a central
9role in the DRM infrastructure.
10
11The DRM core includes two memory managers, namely Translation Table Maps
12(TTM) and Graphics Execution Manager (GEM). TTM was the first DRM memory
13manager to be developed and tried to be a one-size-fits-them all
14solution. It provides a single userspace API to accommodate the need of
15all hardware, supporting both Unified Memory Architecture (UMA) devices
16and devices with dedicated video RAM (i.e. most discrete video cards).
17This resulted in a large, complex piece of code that turned out to be
18hard to use for driver development.
19
20GEM started as an Intel-sponsored project in reaction to TTM's
21complexity. Its design philosophy is completely different: instead of
22providing a solution to every graphics memory-related problems, GEM
23identified common code between drivers and created a support library to
24share it. GEM has simpler initialization and execution requirements than
25TTM, but has no video RAM management capabilities and is thus limited to
26UMA devices.
27
28The Translation Table Manager (TTM)
29-----------------------------------
30
31TTM design background and information belongs here.
32
33TTM initialization
34~~~~~~~~~~~~~~~~~~
35
36 **Warning**
37
38 This section is outdated.
39
40Drivers wishing to support TTM must fill out a drm_bo_driver
41structure. The structure contains several fields with function pointers
42for initializing the TTM, allocating and freeing memory, waiting for
43command completion and fence synchronization, and memory migration. See
44the radeon_ttm.c file for an example of usage.
45
46The ttm_global_reference structure is made up of several fields:
47
48::
49
50 struct ttm_global_reference {
51 enum ttm_global_types global_type;
52 size_t size;
53 void *object;
54 int (*init) (struct ttm_global_reference *);
55 void (*release) (struct ttm_global_reference *);
56 };
57
58
59There should be one global reference structure for your memory manager
60as a whole, and there will be others for each object created by the
61memory manager at runtime. Your global TTM should have a type of
62TTM_GLOBAL_TTM_MEM. The size field for the global object should be
63sizeof(struct ttm_mem_global), and the init and release hooks should
64point at your driver-specific init and release routines, which probably
65eventually call ttm_mem_global_init and ttm_mem_global_release,
66respectively.
67
68Once your global TTM accounting structure is set up and initialized by
69calling ttm_global_item_ref() on it, you need to create a buffer
70object TTM to provide a pool for buffer object allocation by clients and
71the kernel itself. The type of this object should be
72TTM_GLOBAL_TTM_BO, and its size should be sizeof(struct
73ttm_bo_global). Again, driver-specific init and release functions may
74be provided, likely eventually calling ttm_bo_global_init() and
75ttm_bo_global_release(), respectively. Also, like the previous
76object, ttm_global_item_ref() is used to create an initial reference
77count for the TTM, which will call your initialization function.
78
79The Graphics Execution Manager (GEM)
80------------------------------------
81
82The GEM design approach has resulted in a memory manager that doesn't
83provide full coverage of all (or even all common) use cases in its
84userspace or kernel API. GEM exposes a set of standard memory-related
85operations to userspace and a set of helper functions to drivers, and
86let drivers implement hardware-specific operations with their own
87private API.
88
89The GEM userspace API is described in the `GEM - the Graphics Execution
90Manager <http://lwn.net/Articles/283798/>`__ article on LWN. While
91slightly outdated, the document provides a good overview of the GEM API
92principles. Buffer allocation and read and write operations, described
93as part of the common GEM API, are currently implemented using
94driver-specific ioctls.
95
96GEM is data-agnostic. It manages abstract buffer objects without knowing
97what individual buffers contain. APIs that require knowledge of buffer
98contents or purpose, such as buffer allocation or synchronization
99primitives, are thus outside of the scope of GEM and must be implemented
100using driver-specific ioctls.
101
102On a fundamental level, GEM involves several operations:
103
104- Memory allocation and freeing
105- Command execution
106- Aperture management at command execution time
107
108Buffer object allocation is relatively straightforward and largely
109provided by Linux's shmem layer, which provides memory to back each
110object.
111
112Device-specific operations, such as command execution, pinning, buffer
113read & write, mapping, and domain ownership transfers are left to
114driver-specific ioctls.
115
116GEM Initialization
117~~~~~~~~~~~~~~~~~~
118
119Drivers that use GEM must set the DRIVER_GEM bit in the struct
120:c:type:`struct drm_driver <drm_driver>` driver_features
121field. The DRM core will then automatically initialize the GEM core
122before calling the load operation. Behind the scene, this will create a
123DRM Memory Manager object which provides an address space pool for
124object allocation.
125
126In a KMS configuration, drivers need to allocate and initialize a
127command ring buffer following core GEM initialization if required by the
128hardware. UMA devices usually have what is called a "stolen" memory
129region, which provides space for the initial framebuffer and large,
130contiguous memory regions required by the device. This space is
131typically not managed by GEM, and must be initialized separately into
132its own DRM MM object.
133
134GEM Objects Creation
135~~~~~~~~~~~~~~~~~~~~
136
137GEM splits creation of GEM objects and allocation of the memory that
138backs them in two distinct operations.
139
140GEM objects are represented by an instance of struct :c:type:`struct
141drm_gem_object <drm_gem_object>`. Drivers usually need to
142extend GEM objects with private information and thus create a
143driver-specific GEM object structure type that embeds an instance of
144struct :c:type:`struct drm_gem_object <drm_gem_object>`.
145
146To create a GEM object, a driver allocates memory for an instance of its
147specific GEM object type and initializes the embedded struct
148:c:type:`struct drm_gem_object <drm_gem_object>` with a call
149to :c:func:`drm_gem_object_init()`. The function takes a pointer
150to the DRM device, a pointer to the GEM object and the buffer object
151size in bytes.
152
153GEM uses shmem to allocate anonymous pageable memory.
154:c:func:`drm_gem_object_init()` will create an shmfs file of the
155requested size and store it into the struct :c:type:`struct
156drm_gem_object <drm_gem_object>` filp field. The memory is
157used as either main storage for the object when the graphics hardware
158uses system memory directly or as a backing store otherwise.
159
160Drivers are responsible for the actual physical pages allocation by
161calling :c:func:`shmem_read_mapping_page_gfp()` for each page.
162Note that they can decide to allocate pages when initializing the GEM
163object, or to delay allocation until the memory is needed (for instance
164when a page fault occurs as a result of a userspace memory access or
165when the driver needs to start a DMA transfer involving the memory).
166
167Anonymous pageable memory allocation is not always desired, for instance
168when the hardware requires physically contiguous system memory as is
169often the case in embedded devices. Drivers can create GEM objects with
170no shmfs backing (called private GEM objects) by initializing them with
171a call to :c:func:`drm_gem_private_object_init()` instead of
172:c:func:`drm_gem_object_init()`. Storage for private GEM objects
173must be managed by drivers.
174
175GEM Objects Lifetime
176~~~~~~~~~~~~~~~~~~~~
177
178All GEM objects are reference-counted by the GEM core. References can be
179acquired and release by :c:func:`calling
180drm_gem_object_reference()` and
181:c:func:`drm_gem_object_unreference()` respectively. The caller
182must hold the :c:type:`struct drm_device <drm_device>`
183struct_mutex lock when calling
184:c:func:`drm_gem_object_reference()`. As a convenience, GEM
185provides :c:func:`drm_gem_object_unreference_unlocked()`
186functions that can be called without holding the lock.
187
188When the last reference to a GEM object is released the GEM core calls
189the :c:type:`struct drm_driver <drm_driver>` gem_free_object
190operation. That operation is mandatory for GEM-enabled drivers and must
191free the GEM object and all associated resources.
192
193void (\*gem_free_object) (struct drm_gem_object \*obj); Drivers are
194responsible for freeing all GEM object resources. This includes the
195resources created by the GEM core, which need to be released with
196:c:func:`drm_gem_object_release()`.
197
198GEM Objects Naming
199~~~~~~~~~~~~~~~~~~
200
201Communication between userspace and the kernel refers to GEM objects
202using local handles, global names or, more recently, file descriptors.
203All of those are 32-bit integer values; the usual Linux kernel limits
204apply to the file descriptors.
205
206GEM handles are local to a DRM file. Applications get a handle to a GEM
207object through a driver-specific ioctl, and can use that handle to refer
208to the GEM object in other standard or driver-specific ioctls. Closing a
209DRM file handle frees all its GEM handles and dereferences the
210associated GEM objects.
211
212To create a handle for a GEM object drivers call
213:c:func:`drm_gem_handle_create()`. The function takes a pointer
214to the DRM file and the GEM object and returns a locally unique handle.
215When the handle is no longer needed drivers delete it with a call to
216:c:func:`drm_gem_handle_delete()`. Finally the GEM object
217associated with a handle can be retrieved by a call to
218:c:func:`drm_gem_object_lookup()`.
219
220Handles don't take ownership of GEM objects, they only take a reference
221to the object that will be dropped when the handle is destroyed. To
222avoid leaking GEM objects, drivers must make sure they drop the
223reference(s) they own (such as the initial reference taken at object
224creation time) as appropriate, without any special consideration for the
225handle. For example, in the particular case of combined GEM object and
226handle creation in the implementation of the dumb_create operation,
227drivers must drop the initial reference to the GEM object before
228returning the handle.
229
230GEM names are similar in purpose to handles but are not local to DRM
231files. They can be passed between processes to reference a GEM object
232globally. Names can't be used directly to refer to objects in the DRM
233API, applications must convert handles to names and names to handles
234using the DRM_IOCTL_GEM_FLINK and DRM_IOCTL_GEM_OPEN ioctls
235respectively. The conversion is handled by the DRM core without any
236driver-specific support.
237
238GEM also supports buffer sharing with dma-buf file descriptors through
239PRIME. GEM-based drivers must use the provided helpers functions to
240implement the exporting and importing correctly. See ?. Since sharing
241file descriptors is inherently more secure than the easily guessable and
242global GEM names it is the preferred buffer sharing mechanism. Sharing
243buffers through GEM names is only supported for legacy userspace.
244Furthermore PRIME also allows cross-device buffer sharing since it is
245based on dma-bufs.
246
247GEM Objects Mapping
248~~~~~~~~~~~~~~~~~~~
249
250Because mapping operations are fairly heavyweight GEM favours
251read/write-like access to buffers, implemented through driver-specific
252ioctls, over mapping buffers to userspace. However, when random access
253to the buffer is needed (to perform software rendering for instance),
254direct access to the object can be more efficient.
255
256The mmap system call can't be used directly to map GEM objects, as they
257don't have their own file handle. Two alternative methods currently
258co-exist to map GEM objects to userspace. The first method uses a
259driver-specific ioctl to perform the mapping operation, calling
260:c:func:`do_mmap()` under the hood. This is often considered
261dubious, seems to be discouraged for new GEM-enabled drivers, and will
262thus not be described here.
263
264The second method uses the mmap system call on the DRM file handle. void
265\*mmap(void \*addr, size_t length, int prot, int flags, int fd, off_t
266offset); DRM identifies the GEM object to be mapped by a fake offset
267passed through the mmap offset argument. Prior to being mapped, a GEM
268object must thus be associated with a fake offset. To do so, drivers
269must call :c:func:`drm_gem_create_mmap_offset()` on the object.
270
271Once allocated, the fake offset value must be passed to the application
272in a driver-specific way and can then be used as the mmap offset
273argument.
274
275The GEM core provides a helper method :c:func:`drm_gem_mmap()` to
276handle object mapping. The method can be set directly as the mmap file
277operation handler. It will look up the GEM object based on the offset
278value and set the VMA operations to the :c:type:`struct drm_driver
279<drm_driver>` gem_vm_ops field. Note that
280:c:func:`drm_gem_mmap()` doesn't map memory to userspace, but
281relies on the driver-provided fault handler to map pages individually.
282
283To use :c:func:`drm_gem_mmap()`, drivers must fill the struct
284:c:type:`struct drm_driver <drm_driver>` gem_vm_ops field
285with a pointer to VM operations.
286
287struct vm_operations_struct \*gem_vm_ops struct
288vm_operations_struct { void (\*open)(struct vm_area_struct \* area);
289void (\*close)(struct vm_area_struct \* area); int (\*fault)(struct
290vm_area_struct \*vma, struct vm_fault \*vmf); };
291
292The open and close operations must update the GEM object reference
293count. Drivers can use the :c:func:`drm_gem_vm_open()` and
294:c:func:`drm_gem_vm_close()` helper functions directly as open
295and close handlers.
296
297The fault operation handler is responsible for mapping individual pages
298to userspace when a page fault occurs. Depending on the memory
299allocation scheme, drivers can allocate pages at fault time, or can
300decide to allocate memory for the GEM object at the time the object is
301created.
302
303Drivers that want to map the GEM object upfront instead of handling page
304faults can implement their own mmap file operation handler.
305
306Memory Coherency
307~~~~~~~~~~~~~~~~
308
309When mapped to the device or used in a command buffer, backing pages for
310an object are flushed to memory and marked write combined so as to be
311coherent with the GPU. Likewise, if the CPU accesses an object after the
312GPU has finished rendering to the object, then the object must be made
313coherent with the CPU's view of memory, usually involving GPU cache
314flushing of various kinds. This core CPU<->GPU coherency management is
315provided by a device-specific ioctl, which evaluates an object's current
316domain and performs any necessary flushing or synchronization to put the
317object into the desired coherency domain (note that the object may be
318busy, i.e. an active render target; in that case, setting the domain
319blocks the client and waits for rendering to complete before performing
320any necessary flushing operations).
321
322Command Execution
323~~~~~~~~~~~~~~~~~
324
325Perhaps the most important GEM function for GPU devices is providing a
326command execution interface to clients. Client programs construct
327command buffers containing references to previously allocated memory
328objects, and then submit them to GEM. At that point, GEM takes care to
329bind all the objects into the GTT, execute the buffer, and provide
330necessary synchronization between clients accessing the same buffers.
331This often involves evicting some objects from the GTT and re-binding
332others (a fairly expensive operation), and providing relocation support
333which hides fixed GTT offsets from clients. Clients must take care not
334to submit command buffers that reference more objects than can fit in
335the GTT; otherwise, GEM will reject them and no rendering will occur.
336Similarly, if several objects in the buffer require fence registers to
337be allocated for correct rendering (e.g. 2D blits on pre-965 chips),
338care must be taken not to require more fence registers than are
339available to the client. Such resource management should be abstracted
340from the client in libdrm.
341
342GEM Function Reference
343----------------------
344
345.. kernel-doc:: drivers/gpu/drm/drm_gem.c
346 :export:
347
348.. kernel-doc:: include/drm/drm_gem.h
349 :internal:
350
351VMA Offset Manager
352------------------
353
354.. kernel-doc:: drivers/gpu/drm/drm_vma_manager.c
355 :doc: vma offset manager
356
357.. kernel-doc:: drivers/gpu/drm/drm_vma_manager.c
358 :export:
359
360.. kernel-doc:: include/drm/drm_vma_manager.h
361 :internal:
362
363PRIME Buffer Sharing
364--------------------
365
366PRIME is the cross device buffer sharing framework in drm, originally
367created for the OPTIMUS range of multi-gpu platforms. To userspace PRIME
368buffers are dma-buf based file descriptors.
369
370Overview and Driver Interface
371~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
372
373Similar to GEM global names, PRIME file descriptors are also used to
374share buffer objects across processes. They offer additional security:
375as file descriptors must be explicitly sent over UNIX domain sockets to
376be shared between applications, they can't be guessed like the globally
377unique GEM names.
378
379Drivers that support the PRIME API must set the DRIVER_PRIME bit in the
380struct :c:type:`struct drm_driver <drm_driver>`
381driver_features field, and implement the prime_handle_to_fd and
382prime_fd_to_handle operations.
383
384int (\*prime_handle_to_fd)(struct drm_device \*dev, struct drm_file
385\*file_priv, uint32_t handle, uint32_t flags, int \*prime_fd); int
386(\*prime_fd_to_handle)(struct drm_device \*dev, struct drm_file
387\*file_priv, int prime_fd, uint32_t \*handle); Those two operations
388convert a handle to a PRIME file descriptor and vice versa. Drivers must
389use the kernel dma-buf buffer sharing framework to manage the PRIME file
390descriptors. Similar to the mode setting API PRIME is agnostic to the
391underlying buffer object manager, as long as handles are 32bit unsigned
392integers.
393
394While non-GEM drivers must implement the operations themselves, GEM
395drivers must use the :c:func:`drm_gem_prime_handle_to_fd()` and
396:c:func:`drm_gem_prime_fd_to_handle()` helper functions. Those
397helpers rely on the driver gem_prime_export and gem_prime_import
398operations to create a dma-buf instance from a GEM object (dma-buf
399exporter role) and to create a GEM object from a dma-buf instance
400(dma-buf importer role).
401
402struct dma_buf \* (\*gem_prime_export)(struct drm_device \*dev,
403struct drm_gem_object \*obj, int flags); struct drm_gem_object \*
404(\*gem_prime_import)(struct drm_device \*dev, struct dma_buf
405\*dma_buf); These two operations are mandatory for GEM drivers that
406support PRIME.
407
408PRIME Helper Functions
409~~~~~~~~~~~~~~~~~~~~~~
410
411.. kernel-doc:: drivers/gpu/drm/drm_prime.c
412 :doc: PRIME Helpers
413
414PRIME Function References
415-------------------------
416
417.. kernel-doc:: drivers/gpu/drm/drm_prime.c
418 :export:
419
420DRM MM Range Allocator
421----------------------
422
423Overview
424~~~~~~~~
425
426.. kernel-doc:: drivers/gpu/drm/drm_mm.c
427 :doc: Overview
428
429LRU Scan/Eviction Support
430~~~~~~~~~~~~~~~~~~~~~~~~~
431
432.. kernel-doc:: drivers/gpu/drm/drm_mm.c
433 :doc: lru scan roaster
434
435DRM MM Range Allocator Function References
436------------------------------------------
437
438.. kernel-doc:: drivers/gpu/drm/drm_mm.c
439 :export:
440
441.. kernel-doc:: include/drm/drm_mm.h
442 :internal:
443
444CMA Helper Functions Reference
445------------------------------
446
447.. kernel-doc:: drivers/gpu/drm/drm_gem_cma_helper.c
448 :doc: cma helpers
449
450.. kernel-doc:: drivers/gpu/drm/drm_gem_cma_helper.c
451 :export:
452
453.. kernel-doc:: include/drm/drm_gem_cma_helper.h
454 :internal:
diff --git a/Documentation/gpu/drm-uapi.rst b/Documentation/gpu/drm-uapi.rst
new file mode 100644
index 000000000000..536bf3eaadd4
--- /dev/null
+++ b/Documentation/gpu/drm-uapi.rst
@@ -0,0 +1,111 @@
1===================
2Userland interfaces
3===================
4
5The DRM core exports several interfaces to applications, generally
6intended to be used through corresponding libdrm wrapper functions. In
7addition, drivers export device-specific interfaces for use by userspace
8drivers & device-aware applications through ioctls and sysfs files.
9
10External interfaces include: memory mapping, context management, DMA
11operations, AGP management, vblank control, fence management, memory
12management, and output management.
13
14Cover generic ioctls and sysfs layout here. We only need high-level
15info, since man pages should cover the rest.
16
17libdrm Device Lookup
18====================
19
20.. kernel-doc:: drivers/gpu/drm/drm_ioctl.c
21 :doc: getunique and setversion story
22
23
24Primary Nodes, DRM Master and Authentication
25============================================
26
27.. kernel-doc:: drivers/gpu/drm/drm_auth.c
28 :doc: master and authentication
29
30.. kernel-doc:: drivers/gpu/drm/drm_auth.c
31 :export:
32
33.. kernel-doc:: include/drm/drm_auth.h
34 :internal:
35
36Render nodes
37============
38
39DRM core provides multiple character-devices for user-space to use.
40Depending on which device is opened, user-space can perform a different
41set of operations (mainly ioctls). The primary node is always created
42and called card<num>. Additionally, a currently unused control node,
43called controlD<num> is also created. The primary node provides all
44legacy operations and historically was the only interface used by
45userspace. With KMS, the control node was introduced. However, the
46planned KMS control interface has never been written and so the control
47node stays unused to date.
48
49With the increased use of offscreen renderers and GPGPU applications,
50clients no longer require running compositors or graphics servers to
51make use of a GPU. But the DRM API required unprivileged clients to
52authenticate to a DRM-Master prior to getting GPU access. To avoid this
53step and to grant clients GPU access without authenticating, render
54nodes were introduced. Render nodes solely serve render clients, that
55is, no modesetting or privileged ioctls can be issued on render nodes.
56Only non-global rendering commands are allowed. If a driver supports
57render nodes, it must advertise it via the DRIVER_RENDER DRM driver
58capability. If not supported, the primary node must be used for render
59clients together with the legacy drmAuth authentication procedure.
60
61If a driver advertises render node support, DRM core will create a
62separate render node called renderD<num>. There will be one render node
63per device. No ioctls except PRIME-related ioctls will be allowed on
64this node. Especially GEM_OPEN will be explicitly prohibited. Render
65nodes are designed to avoid the buffer-leaks, which occur if clients
66guess the flink names or mmap offsets on the legacy interface.
67Additionally to this basic interface, drivers must mark their
68driver-dependent render-only ioctls as DRM_RENDER_ALLOW so render
69clients can use them. Driver authors must be careful not to allow any
70privileged ioctls on render nodes.
71
72With render nodes, user-space can now control access to the render node
73via basic file-system access-modes. A running graphics server which
74authenticates clients on the privileged primary/legacy node is no longer
75required. Instead, a client can open the render node and is immediately
76granted GPU access. Communication between clients (or servers) is done
77via PRIME. FLINK from render node to legacy node is not supported. New
78clients must not use the insecure FLINK interface.
79
80Besides dropping all modeset/global ioctls, render nodes also drop the
81DRM-Master concept. There is no reason to associate render clients with
82a DRM-Master as they are independent of any graphics server. Besides,
83they must work without any running master, anyway. Drivers must be able
84to run without a master object if they support render nodes. If, on the
85other hand, a driver requires shared state between clients which is
86visible to user-space and accessible beyond open-file boundaries, they
87cannot support render nodes.
88
89VBlank event handling
90=====================
91
92The DRM core exposes two vertical blank related ioctls:
93
94DRM_IOCTL_WAIT_VBLANK
95 This takes a struct drm_wait_vblank structure as its argument, and
96 it is used to block or request a signal when a specified vblank
97 event occurs.
98
99DRM_IOCTL_MODESET_CTL
100 This was only used for user-mode-settind drivers around modesetting
101 changes to allow the kernel to update the vblank interrupt after
102 mode setting, since on many devices the vertical blank counter is
103 reset to 0 at some point during modeset. Modern drivers should not
104 call this any more since with kernel mode setting it is a no-op.
105
106This second part of the GPU Driver Developer's Guide documents driver
107code, implementation details and also all the driver-specific userspace
108interfaces. Especially since all hardware-acceleration interfaces to
109userspace are driver specific for efficiency and other reasons these
110interfaces can be rather substantial. Hence every driver has its own
111chapter.
diff --git a/Documentation/gpu/i915.rst b/Documentation/gpu/i915.rst
new file mode 100644
index 000000000000..2fe5952e90f1
--- /dev/null
+++ b/Documentation/gpu/i915.rst
@@ -0,0 +1,347 @@
1===========================
2 drm/i915 Intel GFX Driver
3===========================
4
5The drm/i915 driver supports all (with the exception of some very early
6models) integrated GFX chipsets with both Intel display and rendering
7blocks. This excludes a set of SoC platforms with an SGX rendering unit,
8those have basic support through the gma500 drm driver.
9
10Core Driver Infrastructure
11==========================
12
13This section covers core driver infrastructure used by both the display
14and the GEM parts of the driver.
15
16Runtime Power Management
17------------------------
18
19.. kernel-doc:: drivers/gpu/drm/i915/intel_runtime_pm.c
20 :doc: runtime pm
21
22.. kernel-doc:: drivers/gpu/drm/i915/intel_runtime_pm.c
23 :internal:
24
25.. kernel-doc:: drivers/gpu/drm/i915/intel_uncore.c
26 :internal:
27
28Interrupt Handling
29------------------
30
31.. kernel-doc:: drivers/gpu/drm/i915/i915_irq.c
32 :doc: interrupt handling
33
34.. kernel-doc:: drivers/gpu/drm/i915/i915_irq.c
35 :functions: intel_irq_init intel_irq_init_hw intel_hpd_init
36
37.. kernel-doc:: drivers/gpu/drm/i915/i915_irq.c
38 :functions: intel_runtime_pm_disable_interrupts
39
40.. kernel-doc:: drivers/gpu/drm/i915/i915_irq.c
41 :functions: intel_runtime_pm_enable_interrupts
42
43Intel GVT-g Guest Support(vGPU)
44-------------------------------
45
46.. kernel-doc:: drivers/gpu/drm/i915/i915_vgpu.c
47 :doc: Intel GVT-g guest support
48
49.. kernel-doc:: drivers/gpu/drm/i915/i915_vgpu.c
50 :internal:
51
52Display Hardware Handling
53=========================
54
55This section covers everything related to the display hardware including
56the mode setting infrastructure, plane, sprite and cursor handling and
57display, output probing and related topics.
58
59Mode Setting Infrastructure
60---------------------------
61
62The i915 driver is thus far the only DRM driver which doesn't use the
63common DRM helper code to implement mode setting sequences. Thus it has
64its own tailor-made infrastructure for executing a display configuration
65change.
66
67Frontbuffer Tracking
68--------------------
69
70.. kernel-doc:: drivers/gpu/drm/i915/intel_frontbuffer.c
71 :doc: frontbuffer tracking
72
73.. kernel-doc:: drivers/gpu/drm/i915/intel_frontbuffer.c
74 :internal:
75
76.. kernel-doc:: drivers/gpu/drm/i915/i915_gem.c
77 :functions: i915_gem_track_fb
78
79Display FIFO Underrun Reporting
80-------------------------------
81
82.. kernel-doc:: drivers/gpu/drm/i915/intel_fifo_underrun.c
83 :doc: fifo underrun handling
84
85.. kernel-doc:: drivers/gpu/drm/i915/intel_fifo_underrun.c
86 :internal:
87
88Plane Configuration
89-------------------
90
91This section covers plane configuration and composition with the primary
92plane, sprites, cursors and overlays. This includes the infrastructure
93to do atomic vsync'ed updates of all this state and also tightly coupled
94topics like watermark setup and computation, framebuffer compression and
95panel self refresh.
96
97Atomic Plane Helpers
98--------------------
99
100.. kernel-doc:: drivers/gpu/drm/i915/intel_atomic_plane.c
101 :doc: atomic plane helpers
102
103.. kernel-doc:: drivers/gpu/drm/i915/intel_atomic_plane.c
104 :internal:
105
106Output Probing
107--------------
108
109This section covers output probing and related infrastructure like the
110hotplug interrupt storm detection and mitigation code. Note that the
111i915 driver still uses most of the common DRM helper code for output
112probing, so those sections fully apply.
113
114Hotplug
115-------
116
117.. kernel-doc:: drivers/gpu/drm/i915/intel_hotplug.c
118 :doc: Hotplug
119
120.. kernel-doc:: drivers/gpu/drm/i915/intel_hotplug.c
121 :internal:
122
123High Definition Audio
124---------------------
125
126.. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c
127 :doc: High Definition Audio over HDMI and Display Port
128
129.. kernel-doc:: drivers/gpu/drm/i915/intel_audio.c
130 :internal:
131
132.. kernel-doc:: include/drm/i915_component.h
133 :internal:
134
135Panel Self Refresh PSR (PSR/SRD)
136--------------------------------
137
138.. kernel-doc:: drivers/gpu/drm/i915/intel_psr.c
139 :doc: Panel Self Refresh (PSR/SRD)
140
141.. kernel-doc:: drivers/gpu/drm/i915/intel_psr.c
142 :internal:
143
144Frame Buffer Compression (FBC)
145------------------------------
146
147.. kernel-doc:: drivers/gpu/drm/i915/intel_fbc.c
148 :doc: Frame Buffer Compression (FBC)
149
150.. kernel-doc:: drivers/gpu/drm/i915/intel_fbc.c
151 :internal:
152
153Display Refresh Rate Switching (DRRS)
154-------------------------------------
155
156.. kernel-doc:: drivers/gpu/drm/i915/intel_dp.c
157 :doc: Display Refresh Rate Switching (DRRS)
158
159.. kernel-doc:: drivers/gpu/drm/i915/intel_dp.c
160 :functions: intel_dp_set_drrs_state
161
162.. kernel-doc:: drivers/gpu/drm/i915/intel_dp.c
163 :functions: intel_edp_drrs_enable
164
165.. kernel-doc:: drivers/gpu/drm/i915/intel_dp.c
166 :functions: intel_edp_drrs_disable
167
168.. kernel-doc:: drivers/gpu/drm/i915/intel_dp.c
169 :functions: intel_edp_drrs_invalidate
170
171.. kernel-doc:: drivers/gpu/drm/i915/intel_dp.c
172 :functions: intel_edp_drrs_flush
173
174.. kernel-doc:: drivers/gpu/drm/i915/intel_dp.c
175 :functions: intel_dp_drrs_init
176
177DPIO
178----
179
180.. kernel-doc:: drivers/gpu/drm/i915/i915_reg.h
181 :doc: DPIO
182
183CSR firmware support for DMC
184----------------------------
185
186.. kernel-doc:: drivers/gpu/drm/i915/intel_csr.c
187 :doc: csr support for dmc
188
189.. kernel-doc:: drivers/gpu/drm/i915/intel_csr.c
190 :internal:
191
192Video BIOS Table (VBT)
193----------------------
194
195.. kernel-doc:: drivers/gpu/drm/i915/intel_bios.c
196 :doc: Video BIOS Table (VBT)
197
198.. kernel-doc:: drivers/gpu/drm/i915/intel_bios.c
199 :internal:
200
201.. kernel-doc:: drivers/gpu/drm/i915/intel_vbt_defs.h
202 :internal:
203
204Memory Management and Command Submission
205========================================
206
207This sections covers all things related to the GEM implementation in the
208i915 driver.
209
210Batchbuffer Parsing
211-------------------
212
213.. kernel-doc:: drivers/gpu/drm/i915/i915_cmd_parser.c
214 :doc: batch buffer command parser
215
216.. kernel-doc:: drivers/gpu/drm/i915/i915_cmd_parser.c
217 :internal:
218
219Batchbuffer Pools
220-----------------
221
222.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_batch_pool.c
223 :doc: batch pool
224
225.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_batch_pool.c
226 :internal:
227
228Logical Rings, Logical Ring Contexts and Execlists
229--------------------------------------------------
230
231.. kernel-doc:: drivers/gpu/drm/i915/intel_lrc.c
232 :doc: Logical Rings, Logical Ring Contexts and Execlists
233
234.. kernel-doc:: drivers/gpu/drm/i915/intel_lrc.c
235 :internal:
236
237Global GTT views
238----------------
239
240.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_gtt.c
241 :doc: Global GTT views
242
243.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_gtt.c
244 :internal:
245
246GTT Fences and Swizzling
247------------------------
248
249.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_fence.c
250 :internal:
251
252Global GTT Fence Handling
253~~~~~~~~~~~~~~~~~~~~~~~~~
254
255.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_fence.c
256 :doc: fence register handling
257
258Hardware Tiling and Swizzling Details
259~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
260
261.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_fence.c
262 :doc: tiling swizzling details
263
264Object Tiling IOCTLs
265--------------------
266
267.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_tiling.c
268 :internal:
269
270.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_tiling.c
271 :doc: buffer object tiling
272
273Buffer Object Eviction
274----------------------
275
276This section documents the interface functions for evicting buffer
277objects to make space available in the virtual gpu address spaces. Note
278that this is mostly orthogonal to shrinking buffer objects caches, which
279has the goal to make main memory (shared with the gpu through the
280unified memory architecture) available.
281
282.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_evict.c
283 :internal:
284
285Buffer Object Memory Shrinking
286------------------------------
287
288This section documents the interface function for shrinking memory usage
289of buffer object caches. Shrinking is used to make main memory
290available. Note that this is mostly orthogonal to evicting buffer
291objects, which has the goal to make space in gpu virtual address spaces.
292
293.. kernel-doc:: drivers/gpu/drm/i915/i915_gem_shrinker.c
294 :internal:
295
296GuC
297===
298
299GuC-specific firmware loader
300----------------------------
301
302.. kernel-doc:: drivers/gpu/drm/i915/intel_guc_loader.c
303 :doc: GuC-specific firmware loader
304
305.. kernel-doc:: drivers/gpu/drm/i915/intel_guc_loader.c
306 :internal:
307
308GuC-based command submission
309----------------------------
310
311.. kernel-doc:: drivers/gpu/drm/i915/i915_guc_submission.c
312 :doc: GuC-based command submission
313
314.. kernel-doc:: drivers/gpu/drm/i915/i915_guc_submission.c
315 :internal:
316
317GuC Firmware Layout
318-------------------
319
320.. kernel-doc:: drivers/gpu/drm/i915/intel_guc_fwif.h
321 :doc: GuC Firmware Layout
322
323Tracing
324=======
325
326This sections covers all things related to the tracepoints implemented
327in the i915 driver.
328
329i915_ppgtt_create and i915_ppgtt_release
330----------------------------------------
331
332.. kernel-doc:: drivers/gpu/drm/i915/i915_trace.h
333 :doc: i915_ppgtt_create and i915_ppgtt_release tracepoints
334
335i915_context_create and i915_context_free
336-----------------------------------------
337
338.. kernel-doc:: drivers/gpu/drm/i915/i915_trace.h
339 :doc: i915_context_create and i915_context_free tracepoints
340
341switch_mm
342---------
343
344.. kernel-doc:: drivers/gpu/drm/i915/i915_trace.h
345 :doc: switch_mm tracepoint
346
347.. WARNING: DOCPROC directive not supported: !Cdrivers/gpu/drm/i915/i915_irq.c
diff --git a/Documentation/gpu/index.rst b/Documentation/gpu/index.rst
new file mode 100644
index 000000000000..fcac0fa72056
--- /dev/null
+++ b/Documentation/gpu/index.rst
@@ -0,0 +1,14 @@
1==================================
2Linux GPU Driver Developer's Guide
3==================================
4
5.. toctree::
6
7 introduction
8 drm-internals
9 drm-mm
10 drm-kms
11 drm-kms-helpers
12 drm-uapi
13 i915
14 vga-switcheroo
diff --git a/Documentation/gpu/introduction.rst b/Documentation/gpu/introduction.rst
new file mode 100644
index 000000000000..1903595b5310
--- /dev/null
+++ b/Documentation/gpu/introduction.rst
@@ -0,0 +1,51 @@
1============
2Introduction
3============
4
5The Linux DRM layer contains code intended to support the needs of
6complex graphics devices, usually containing programmable pipelines well
7suited to 3D graphics acceleration. Graphics drivers in the kernel may
8make use of DRM functions to make tasks like memory management,
9interrupt handling and DMA easier, and provide a uniform interface to
10applications.
11
12A note on versions: this guide covers features found in the DRM tree,
13including the TTM memory manager, output configuration and mode setting,
14and the new vblank internals, in addition to all the regular features
15found in current kernels.
16
17[Insert diagram of typical DRM stack here]
18
19Style Guidelines
20================
21
22For consistency this documentation uses American English. Abbreviations
23are written as all-uppercase, for example: DRM, KMS, IOCTL, CRTC, and so
24on. To aid in reading, documentations make full use of the markup
25characters kerneldoc provides: @parameter for function parameters,
26@member for structure members, &structure to reference structures and
27function() for functions. These all get automatically hyperlinked if
28kerneldoc for the referenced objects exists. When referencing entries in
29function vtables please use ->vfunc(). Note that kerneldoc does not
30support referencing struct members directly, so please add a reference
31to the vtable struct somewhere in the same paragraph or at least
32section.
33
34Except in special situations (to separate locked from unlocked variants)
35locking requirements for functions aren't documented in the kerneldoc.
36Instead locking should be check at runtime using e.g.
37``WARN_ON(!mutex_is_locked(...));``. Since it's much easier to ignore
38documentation than runtime noise this provides more value. And on top of
39that runtime checks do need to be updated when the locking rules change,
40increasing the chances that they're correct. Within the documentation
41the locking rules should be explained in the relevant structures: Either
42in the comment for the lock explaining what it protects, or data fields
43need a note about which lock protects them, or both.
44
45Functions which have a non-\ ``void`` return value should have a section
46called "Returns" explaining the expected return values in different
47cases and their meanings. Currently there's no consensus whether that
48section name should be all upper-case or not, and whether it should end
49in a colon or not. Go with the file-local style. Other common section
50names are "Notes" with information for dangerous or tricky corner cases,
51and "FIXME" where the interface could be cleaned up.
diff --git a/Documentation/gpu/kms-properties.csv b/Documentation/gpu/kms-properties.csv
new file mode 100644
index 000000000000..b6fcaf639c04
--- /dev/null
+++ b/Documentation/gpu/kms-properties.csv
@@ -0,0 +1,128 @@
1Owner Module/Drivers,Group,Property Name,Type,Property Values,Object attached,Description/Restrictions
2DRM,Generic,“rotation”,BITMASK,"{ 0, ""rotate-0"" }, { 1, ""rotate-90"" }, { 2, ""rotate-180"" }, { 3, ""rotate-270"" }, { 4, ""reflect-x"" }, { 5, ""reflect-y"" }","CRTC, Plane",rotate-(degrees) rotates the image by the specified amount in degrees in counter clockwise direction. reflect-x and reflect-y reflects the image along the specified axis prior to rotation
3,,“scaling mode”,ENUM,"{ ""None"", ""Full"", ""Center"", ""Full aspect"" }",Connector,"Supported by: amdgpu, gma500, i915, nouveau and radeon."
4,Connector,“EDID”,BLOB | IMMUTABLE,0,Connector,Contains id of edid blob ptr object.
5,,“DPMS”,ENUM,"{ “On”, “Standby”, “Suspend”, “Off” }",Connector,Contains DPMS operation mode value.
6,,“PATH”,BLOB | IMMUTABLE,0,Connector,Contains topology path to a connector.
7,,“TILE”,BLOB | IMMUTABLE,0,Connector,Contains tiling information for a connector.
8,,“CRTC_ID”,OBJECT,DRM_MODE_OBJECT_CRTC,Connector,CRTC that connector is attached to (atomic)
9,Plane,“type”,ENUM | IMMUTABLE,"{ ""Overlay"", ""Primary"", ""Cursor"" }",Plane,Plane type
10,,“SRC_X”,RANGE,"Min=0, Max=UINT_MAX",Plane,Scanout source x coordinate in 16.16 fixed point (atomic)
11,,“SRC_Y”,RANGE,"Min=0, Max=UINT_MAX",Plane,Scanout source y coordinate in 16.16 fixed point (atomic)
12,,“SRC_W”,RANGE,"Min=0, Max=UINT_MAX",Plane,Scanout source width in 16.16 fixed point (atomic)
13,,“SRC_H”,RANGE,"Min=0, Max=UINT_MAX",Plane,Scanout source height in 16.16 fixed point (atomic)
14,,“CRTC_X”,SIGNED_RANGE,"Min=INT_MIN, Max=INT_MAX",Plane,Scanout CRTC (destination) x coordinate (atomic)
15,,“CRTC_Y”,SIGNED_RANGE,"Min=INT_MIN, Max=INT_MAX",Plane,Scanout CRTC (destination) y coordinate (atomic)
16,,“CRTC_W”,RANGE,"Min=0, Max=UINT_MAX",Plane,Scanout CRTC (destination) width (atomic)
17,,“CRTC_H”,RANGE,"Min=0, Max=UINT_MAX",Plane,Scanout CRTC (destination) height (atomic)
18,,“FB_ID”,OBJECT,DRM_MODE_OBJECT_FB,Plane,Scanout framebuffer (atomic)
19,,“CRTC_ID”,OBJECT,DRM_MODE_OBJECT_CRTC,Plane,CRTC that plane is attached to (atomic)
20,DVI-I,“subconnector”,ENUM,"{ “Unknown”, “DVI-D”, “DVI-A” }",Connector,TBD
21,,“select subconnector”,ENUM,"{ “Automatic”, “DVI-D”, “DVI-A” }",Connector,TBD
22,TV,“subconnector”,ENUM,"{ ""Unknown"", ""Composite"", ""SVIDEO"", ""Component"", ""SCART"" }",Connector,TBD
23,,“select subconnector”,ENUM,"{ ""Automatic"", ""Composite"", ""SVIDEO"", ""Component"", ""SCART"" }",Connector,TBD
24,,“mode”,ENUM,"{ ""NTSC_M"", ""NTSC_J"", ""NTSC_443"", ""PAL_B"" } etc.",Connector,TBD
25,,“left margin”,RANGE,"Min=0, Max=100",Connector,TBD
26,,“right margin”,RANGE,"Min=0, Max=100",Connector,TBD
27,,“top margin”,RANGE,"Min=0, Max=100",Connector,TBD
28,,“bottom margin”,RANGE,"Min=0, Max=100",Connector,TBD
29,,“brightness”,RANGE,"Min=0, Max=100",Connector,TBD
30,,“contrast”,RANGE,"Min=0, Max=100",Connector,TBD
31,,“flicker reduction”,RANGE,"Min=0, Max=100",Connector,TBD
32,,“overscan”,RANGE,"Min=0, Max=100",Connector,TBD
33,,“saturation”,RANGE,"Min=0, Max=100",Connector,TBD
34,,“hue”,RANGE,"Min=0, Max=100",Connector,TBD
35,Virtual GPU,“suggested X”,RANGE,"Min=0, Max=0xffffffff",Connector,property to suggest an X offset for a connector
36,,“suggested Y”,RANGE,"Min=0, Max=0xffffffff",Connector,property to suggest an Y offset for a connector
37,Optional,"""aspect ratio""",ENUM,"{ ""None"", ""4:3"", ""16:9"" }",Connector,TDB
38,,“dirty”,ENUM | IMMUTABLE,"{ ""Off"", ""On"", ""Annotate"" }",Connector,TBD
39,,“DEGAMMA_LUT”,BLOB,0,CRTC,DRM property to set the degamma lookup table (LUT) mapping pixel data from the framebuffer before it is given to the transformation matrix. The data is an interpreted as an array of struct drm_color_lut elements. Hardware might choose not to use the full precision of the LUT elements nor use all the elements of the LUT (for example the hardware might choose to interpolate between LUT[0] and LUT[4]).
40,,“DEGAMMA_LUT_SIZE”,RANGE | IMMUTABLE,"Min=0, Max=UINT_MAX",CRTC,DRM property to gives the size of the lookup table to be set on the DEGAMMA_LUT property (the size depends on the underlying hardware).
41,,“CTM”,BLOB,0,CRTC,DRM property to set the current transformation matrix (CTM) apply to pixel data after the lookup through the degamma LUT and before the lookup through the gamma LUT. The data is an interpreted as a struct drm_color_ctm.
42,,“GAMMA_LUT”,BLOB,0,CRTC,DRM property to set the gamma lookup table (LUT) mapping pixel data after to the transformation matrix to data sent to the connector. The data is an interpreted as an array of struct drm_color_lut elements. Hardware might choose not to use the full precision of the LUT elements nor use all the elements of the LUT (for example the hardware might choose to interpolate between LUT[0] and LUT[4]).
43,,“GAMMA_LUT_SIZE”,RANGE | IMMUTABLE,"Min=0, Max=UINT_MAX",CRTC,DRM property to gives the size of the lookup table to be set on the GAMMA_LUT property (the size depends on the underlying hardware).
44i915,Generic,"""Broadcast RGB""",ENUM,"{ ""Automatic"", ""Full"", ""Limited 16:235"" }",Connector,"When this property is set to Limited 16:235 and CTM is set, the hardware will be programmed with the result of the multiplication of CTM by the limited range matrix to ensure the pixels normaly in the range 0..1.0 are remapped to the range 16/255..235/255."
45,,“audio”,ENUM,"{ ""force-dvi"", ""off"", ""auto"", ""on"" }",Connector,TBD
46,SDVO-TV,“mode”,ENUM,"{ ""NTSC_M"", ""NTSC_J"", ""NTSC_443"", ""PAL_B"" } etc.",Connector,TBD
47,,"""left_margin""",RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
48,,"""right_margin""",RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
49,,"""top_margin""",RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
50,,"""bottom_margin""",RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
51,,“hpos”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
52,,“vpos”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
53,,“contrast”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
54,,“saturation”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
55,,“hue”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
56,,“sharpness”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
57,,“flicker_filter”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
58,,“flicker_filter_adaptive”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
59,,“flicker_filter_2d”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
60,,“tv_chroma_filter”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
61,,“tv_luma_filter”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
62,,“dot_crawl”,RANGE,"Min=0, Max=1",Connector,TBD
63,SDVO-TV/LVDS,“brightness”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
64CDV gma-500,Generic,"""Broadcast RGB""",ENUM,"{ “Full”, “Limited 16:235” }",Connector,TBD
65,,"""Broadcast RGB""",ENUM,"{ “off”, “auto”, “on” }",Connector,TBD
66Poulsbo,Generic,“backlight”,RANGE,"Min=0, Max=100",Connector,TBD
67,SDVO-TV,“mode”,ENUM,"{ ""NTSC_M"", ""NTSC_J"", ""NTSC_443"", ""PAL_B"" } etc.",Connector,TBD
68,,"""left_margin""",RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
69,,"""right_margin""",RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
70,,"""top_margin""",RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
71,,"""bottom_margin""",RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
72,,“hpos”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
73,,“vpos”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
74,,“contrast”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
75,,“saturation”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
76,,“hue”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
77,,“sharpness”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
78,,“flicker_filter”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
79,,“flicker_filter_adaptive”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
80,,“flicker_filter_2d”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
81,,“tv_chroma_filter”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
82,,“tv_luma_filter”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
83,,“dot_crawl”,RANGE,"Min=0, Max=1",Connector,TBD
84,SDVO-TV/LVDS,“brightness”,RANGE,"Min=0, Max= SDVO dependent",Connector,TBD
85armada,CRTC,"""CSC_YUV""",ENUM,"{ ""Auto"" , ""CCIR601"", ""CCIR709"" }",CRTC,TBD
86,,"""CSC_RGB""",ENUM,"{ ""Auto"", ""Computer system"", ""Studio"" }",CRTC,TBD
87,Overlay,"""colorkey""",RANGE,"Min=0, Max=0xffffff",Plane,TBD
88,,"""colorkey_min""",RANGE,"Min=0, Max=0xffffff",Plane,TBD
89,,"""colorkey_max""",RANGE,"Min=0, Max=0xffffff",Plane,TBD
90,,"""colorkey_val""",RANGE,"Min=0, Max=0xffffff",Plane,TBD
91,,"""colorkey_alpha""",RANGE,"Min=0, Max=0xffffff",Plane,TBD
92,,"""colorkey_mode""",ENUM,"{ ""disabled"", ""Y component"", ""U component"" , ""V component"", ""RGB"", “R component"", ""G component"", ""B component"" }",Plane,TBD
93,,"""brightness""",RANGE,"Min=0, Max=256 + 255",Plane,TBD
94,,"""contrast""",RANGE,"Min=0, Max=0x7fff",Plane,TBD
95,,"""saturation""",RANGE,"Min=0, Max=0x7fff",Plane,TBD
96exynos,CRTC,“mode”,ENUM,"{ ""normal"", ""blank"" }",CRTC,TBD
97,Overlay,“zpos”,RANGE,"Min=0, Max=MAX_PLANE-1",Plane,TBD
98i2c/ch7006_drv,Generic,“scale”,RANGE,"Min=0, Max=2",Connector,TBD
99,TV,“mode”,ENUM,"{ ""PAL"", ""PAL-M"",""PAL-N""}, ”PAL-Nc"" , ""PAL-60"", ""NTSC-M"", ""NTSC-J"" }",Connector,TBD
100nouveau,NV10 Overlay,"""colorkey""",RANGE,"Min=0, Max=0x01ffffff",Plane,TBD
101,,“contrast”,RANGE,"Min=0, Max=8192-1",Plane,TBD
102,,“brightness”,RANGE,"Min=0, Max=1024",Plane,TBD
103,,“hue”,RANGE,"Min=0, Max=359",Plane,TBD
104,,“saturation”,RANGE,"Min=0, Max=8192-1",Plane,TBD
105,,“iturbt_709”,RANGE,"Min=0, Max=1",Plane,TBD
106,Nv04 Overlay,“colorkey”,RANGE,"Min=0, Max=0x01ffffff",Plane,TBD
107,,“brightness”,RANGE,"Min=0, Max=1024",Plane,TBD
108,Display,“dithering mode”,ENUM,"{ ""auto"", ""off"", ""on"" }",Connector,TBD
109,,“dithering depth”,ENUM,"{ ""auto"", ""off"", ""on"", ""static 2x2"", ""dynamic 2x2"", ""temporal"" }",Connector,TBD
110,,“underscan”,ENUM,"{ ""auto"", ""6 bpc"", ""8 bpc"" }",Connector,TBD
111,,“underscan hborder”,RANGE,"Min=0, Max=128",Connector,TBD
112,,“underscan vborder”,RANGE,"Min=0, Max=128",Connector,TBD
113,,“vibrant hue”,RANGE,"Min=0, Max=180",Connector,TBD
114,,“color vibrance”,RANGE,"Min=0, Max=200",Connector,TBD
115omap,Generic,“zorder”,RANGE,"Min=0, Max=3","CRTC, Plane",TBD
116qxl,Generic,"“hotplug_mode_update""",RANGE,"Min=0, Max=1",Connector,TBD
117radeon,DVI-I,“coherent”,RANGE,"Min=0, Max=1",Connector,TBD
118,DAC enable load detect,“load detection”,RANGE,"Min=0, Max=1",Connector,TBD
119,TV Standard,"""tv standard""",ENUM,"{ ""ntsc"", ""pal"", ""pal-m"", ""pal-60"", ""ntsc-j"" , ""scart-pal"", ""pal-cn"", ""secam"" }",Connector,TBD
120,legacy TMDS PLL detect,"""tmds_pll""",ENUM,"{ ""driver"", ""bios"" }",-,TBD
121,Underscan,"""underscan""",ENUM,"{ ""off"", ""on"", ""auto"" }",Connector,TBD
122,,"""underscan hborder""",RANGE,"Min=0, Max=128",Connector,TBD
123,,"""underscan vborder""",RANGE,"Min=0, Max=128",Connector,TBD
124,Audio,“audio”,ENUM,"{ ""off"", ""on"", ""auto"" }",Connector,TBD
125,FMT Dithering,“dither”,ENUM,"{ ""off"", ""on"" }",Connector,TBD
126rcar-du,Generic,"""alpha""",RANGE,"Min=0, Max=255",Plane,TBD
127,,"""colorkey""",RANGE,"Min=0, Max=0x01ffffff",Plane,TBD
128,,"""zpos""",RANGE,"Min=1, Max=7",Plane,TBD
diff --git a/Documentation/gpu/vga-switcheroo.rst b/Documentation/gpu/vga-switcheroo.rst
new file mode 100644
index 000000000000..327d930a2229
--- /dev/null
+++ b/Documentation/gpu/vga-switcheroo.rst
@@ -0,0 +1,102 @@
1==============
2VGA Switcheroo
3==============
4
5.. kernel-doc:: drivers/gpu/vga/vga_switcheroo.c
6 :doc: Overview
7
8Modes of Use
9============
10
11Manual switching and manual power control
12-----------------------------------------
13
14.. kernel-doc:: drivers/gpu/vga/vga_switcheroo.c
15 :doc: Manual switching and manual power control
16
17Driver power control
18--------------------
19
20.. kernel-doc:: drivers/gpu/vga/vga_switcheroo.c
21 :doc: Driver power control
22
23API
24===
25
26Public functions
27----------------
28
29.. kernel-doc:: drivers/gpu/vga/vga_switcheroo.c
30 :export:
31
32Public structures
33-----------------
34
35.. kernel-doc:: include/linux/vga_switcheroo.h
36 :functions: vga_switcheroo_handler
37
38.. kernel-doc:: include/linux/vga_switcheroo.h
39 :functions: vga_switcheroo_client_ops
40
41Public constants
42----------------
43
44.. kernel-doc:: include/linux/vga_switcheroo.h
45 :functions: vga_switcheroo_handler_flags_t
46
47.. kernel-doc:: include/linux/vga_switcheroo.h
48 :functions: vga_switcheroo_client_id
49
50.. kernel-doc:: include/linux/vga_switcheroo.h
51 :functions: vga_switcheroo_state
52
53Private structures
54------------------
55
56.. kernel-doc:: drivers/gpu/vga/vga_switcheroo.c
57 :functions: vgasr_priv
58
59.. kernel-doc:: drivers/gpu/vga/vga_switcheroo.c
60 :functions: vga_switcheroo_client
61
62Handlers
63========
64
65apple-gmux Handler
66------------------
67
68.. kernel-doc:: drivers/platform/x86/apple-gmux.c
69 :doc: Overview
70
71.. kernel-doc:: drivers/platform/x86/apple-gmux.c
72 :doc: Interrupt
73
74Graphics mux
75~~~~~~~~~~~~
76
77.. kernel-doc:: drivers/platform/x86/apple-gmux.c
78 :doc: Graphics mux
79
80Power control
81~~~~~~~~~~~~~
82
83.. kernel-doc:: drivers/platform/x86/apple-gmux.c
84 :doc: Power control
85
86Backlight control
87~~~~~~~~~~~~~~~~~
88
89.. kernel-doc:: drivers/platform/x86/apple-gmux.c
90 :doc: Backlight control
91
92Public functions
93~~~~~~~~~~~~~~~~
94
95.. kernel-doc:: include/linux/apple-gmux.h
96 :internal:
97
98.. WARNING: DOCPROC directive not supported: !Cdrivers/gpu/vga/vga_switcheroo.c
99
100.. WARNING: DOCPROC directive not supported: !Cinclude/linux/vga_switcheroo.h
101
102.. WARNING: DOCPROC directive not supported: !Cdrivers/platform/x86/apple-gmux.c
diff --git a/Documentation/index.rst b/Documentation/index.rst
index 71a276f34c7f..dacc77b43c29 100644
--- a/Documentation/index.rst
+++ b/Documentation/index.rst
@@ -13,6 +13,7 @@ Contents:
13.. toctree:: 13.. toctree::
14 :maxdepth: 2 14 :maxdepth: 2
15 15
16 gpu/index
16 17
17Indices and tables 18Indices and tables
18================== 19==================
diff --git a/MAINTAINERS b/MAINTAINERS
index 5b362eb7e9df..512185c9b768 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3865,7 +3865,7 @@ F: drivers/gpu/vga/
3865F: Documentation/devicetree/bindings/display/ 3865F: Documentation/devicetree/bindings/display/
3866F: Documentation/devicetree/bindings/gpu/ 3866F: Documentation/devicetree/bindings/gpu/
3867F: Documentation/devicetree/bindings/video/ 3867F: Documentation/devicetree/bindings/video/
3868F: Documentation/DocBook/gpu.* 3868F: Documentation/gpu/
3869F: include/drm/ 3869F: include/drm/
3870F: include/uapi/drm/ 3870F: include/uapi/drm/
3871 3871
@@ -3917,6 +3917,7 @@ S: Supported
3917F: drivers/gpu/drm/i915/ 3917F: drivers/gpu/drm/i915/
3918F: include/drm/i915* 3918F: include/drm/i915*
3919F: include/uapi/drm/i915_drm.h 3919F: include/uapi/drm/i915_drm.h
3920F: Documentation/gpu/i915.rst
3920 3921
3921DRM DRIVERS FOR ATMEL HLCDC 3922DRM DRIVERS FOR ATMEL HLCDC
3922M: Boris Brezillon <boris.brezillon@free-electrons.com> 3923M: Boris Brezillon <boris.brezillon@free-electrons.com>
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 6355ab38d630..20ce0687b111 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -824,7 +824,7 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, void *vaddr)
824EXPORT_SYMBOL_GPL(dma_buf_vunmap); 824EXPORT_SYMBOL_GPL(dma_buf_vunmap);
825 825
826#ifdef CONFIG_DEBUG_FS 826#ifdef CONFIG_DEBUG_FS
827static int dma_buf_describe(struct seq_file *s) 827static int dma_buf_debug_show(struct seq_file *s, void *unused)
828{ 828{
829 int ret; 829 int ret;
830 struct dma_buf *buf_obj; 830 struct dma_buf *buf_obj;
@@ -879,17 +879,9 @@ static int dma_buf_describe(struct seq_file *s)
879 return 0; 879 return 0;
880} 880}
881 881
882static int dma_buf_show(struct seq_file *s, void *unused)
883{
884 void (*func)(struct seq_file *) = s->private;
885
886 func(s);
887 return 0;
888}
889
890static int dma_buf_debug_open(struct inode *inode, struct file *file) 882static int dma_buf_debug_open(struct inode *inode, struct file *file)
891{ 883{
892 return single_open(file, dma_buf_show, inode->i_private); 884 return single_open(file, dma_buf_debug_show, NULL);
893} 885}
894 886
895static const struct file_operations dma_buf_debug_fops = { 887static const struct file_operations dma_buf_debug_fops = {
@@ -903,20 +895,23 @@ static struct dentry *dma_buf_debugfs_dir;
903 895
904static int dma_buf_init_debugfs(void) 896static int dma_buf_init_debugfs(void)
905{ 897{
898 struct dentry *d;
906 int err = 0; 899 int err = 0;
907 900
908 dma_buf_debugfs_dir = debugfs_create_dir("dma_buf", NULL); 901 d = debugfs_create_dir("dma_buf", NULL);
909 902 if (IS_ERR(d))
910 if (IS_ERR(dma_buf_debugfs_dir)) { 903 return PTR_ERR(d);
911 err = PTR_ERR(dma_buf_debugfs_dir);
912 dma_buf_debugfs_dir = NULL;
913 return err;
914 }
915 904
916 err = dma_buf_debugfs_create_file("bufinfo", dma_buf_describe); 905 dma_buf_debugfs_dir = d;
917 906
918 if (err) 907 d = debugfs_create_file("bufinfo", S_IRUGO, dma_buf_debugfs_dir,
908 NULL, &dma_buf_debug_fops);
909 if (IS_ERR(d)) {
919 pr_debug("dma_buf: debugfs: failed to create node bufinfo\n"); 910 pr_debug("dma_buf: debugfs: failed to create node bufinfo\n");
911 debugfs_remove_recursive(dma_buf_debugfs_dir);
912 dma_buf_debugfs_dir = NULL;
913 err = PTR_ERR(d);
914 }
920 915
921 return err; 916 return err;
922} 917}
@@ -926,17 +921,6 @@ static void dma_buf_uninit_debugfs(void)
926 if (dma_buf_debugfs_dir) 921 if (dma_buf_debugfs_dir)
927 debugfs_remove_recursive(dma_buf_debugfs_dir); 922 debugfs_remove_recursive(dma_buf_debugfs_dir);
928} 923}
929
930int dma_buf_debugfs_create_file(const char *name,
931 int (*write)(struct seq_file *))
932{
933 struct dentry *d;
934
935 d = debugfs_create_file(name, S_IRUGO, dma_buf_debugfs_dir,
936 write, &dma_buf_debug_fops);
937
938 return PTR_ERR_OR_ZERO(d);
939}
940#else 924#else
941static inline int dma_buf_init_debugfs(void) 925static inline int dma_buf_init_debugfs(void)
942{ 926{
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
index ec4036a09f3e..a625b9137da2 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
@@ -187,12 +187,12 @@ int init_pipelines(struct device_queue_manager *dqm,
187unsigned int get_first_pipe(struct device_queue_manager *dqm); 187unsigned int get_first_pipe(struct device_queue_manager *dqm);
188unsigned int get_pipes_num(struct device_queue_manager *dqm); 188unsigned int get_pipes_num(struct device_queue_manager *dqm);
189 189
190extern inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd) 190static inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
191{ 191{
192 return (pdd->lds_base >> 16) & 0xFF; 192 return (pdd->lds_base >> 16) & 0xFF;
193} 193}
194 194
195extern inline unsigned int 195static inline unsigned int
196get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd) 196get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
197{ 197{
198 return (pdd->lds_base >> 60) & 0x0E; 198 return (pdd->lds_base >> 60) & 0x0E;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index d0d5f4baf72d..80113c335966 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -617,10 +617,7 @@ int kgd2kfd_resume(struct kfd_dev *kfd);
617int kfd_init_apertures(struct kfd_process *process); 617int kfd_init_apertures(struct kfd_process *process);
618 618
619/* Queue Context Management */ 619/* Queue Context Management */
620inline uint32_t lower_32(uint64_t x);
621inline uint32_t upper_32(uint64_t x);
622struct cik_sdma_rlc_registers *get_sdma_mqd(void *mqd); 620struct cik_sdma_rlc_registers *get_sdma_mqd(void *mqd);
623inline uint32_t get_sdma_base_addr(struct cik_sdma_rlc_registers *m);
624 621
625int init_queue(struct queue **q, struct queue_properties properties); 622int init_queue(struct queue **q, struct queue_properties properties);
626void uninit_queue(struct queue *q); 623void uninit_queue(struct queue *q);
diff --git a/drivers/gpu/drm/arc/arcpgu_drv.c b/drivers/gpu/drm/arc/arcpgu_drv.c
index 381c5fcbf903..ccbdadb108dc 100644
--- a/drivers/gpu/drm/arc/arcpgu_drv.c
+++ b/drivers/gpu/drm/arc/arcpgu_drv.c
@@ -211,15 +211,8 @@ static int arcpgu_probe(struct platform_device *pdev)
211 if (ret) 211 if (ret)
212 goto err_unload; 212 goto err_unload;
213 213
214 ret = drm_connector_register_all(drm);
215 if (ret)
216 goto err_unregister;
217
218 return 0; 214 return 0;
219 215
220err_unregister:
221 drm_dev_unregister(drm);
222
223err_unload: 216err_unload:
224 arcpgu_unload(drm); 217 arcpgu_unload(drm);
225 218
@@ -233,7 +226,6 @@ static int arcpgu_remove(struct platform_device *pdev)
233{ 226{
234 struct drm_device *drm = platform_get_drvdata(pdev); 227 struct drm_device *drm = platform_get_drvdata(pdev);
235 228
236 drm_connector_unregister_all(drm);
237 drm_dev_unregister(drm); 229 drm_dev_unregister(drm);
238 arcpgu_unload(drm); 230 arcpgu_unload(drm);
239 drm_dev_unref(drm); 231 drm_dev_unref(drm);
diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c
index cb21c0b6374a..f5ebdd681445 100644
--- a/drivers/gpu/drm/armada/armada_drv.c
+++ b/drivers/gpu/drm/armada/armada_drv.c
@@ -189,7 +189,6 @@ static struct drm_driver armada_drm_driver = {
189 .load = armada_drm_load, 189 .load = armada_drm_load,
190 .lastclose = armada_drm_lastclose, 190 .lastclose = armada_drm_lastclose,
191 .unload = armada_drm_unload, 191 .unload = armada_drm_unload,
192 .set_busid = drm_platform_set_busid,
193 .get_vblank_counter = drm_vblank_no_hw_counter, 192 .get_vblank_counter = drm_vblank_no_hw_counter,
194 .enable_vblank = armada_drm_enable_vblank, 193 .enable_vblank = armada_drm_enable_vblank,
195 .disable_vblank = armada_drm_disable_vblank, 194 .disable_vblank = armada_drm_disable_vblank,
diff --git a/drivers/gpu/drm/armada/armada_overlay.c b/drivers/gpu/drm/armada/armada_overlay.c
index 148e8a42b2c6..1ee707ef6b8d 100644
--- a/drivers/gpu/drm/armada/armada_overlay.c
+++ b/drivers/gpu/drm/armada/armada_overlay.c
@@ -121,6 +121,7 @@ armada_ovl_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
121 int ret; 121 int ret;
122 122
123 ret = drm_plane_helper_check_update(plane, crtc, fb, &src, &dest, &clip, 123 ret = drm_plane_helper_check_update(plane, crtc, fb, &src, &dest, &clip,
124 BIT(DRM_ROTATE_0),
124 0, INT_MAX, true, false, &visible); 125 0, INT_MAX, true, false, &visible);
125 if (ret) 126 if (ret)
126 return ret; 127 return ret;
diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
index 9ecf16c7911d..d4a3d61b7b06 100644
--- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
+++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
@@ -691,13 +691,6 @@ static void atmel_hlcdc_dc_unload(struct drm_device *dev)
691 destroy_workqueue(dc->wq); 691 destroy_workqueue(dc->wq);
692} 692}
693 693
694static void atmel_hlcdc_dc_connector_unplug_all(struct drm_device *dev)
695{
696 mutex_lock(&dev->mode_config.mutex);
697 drm_connector_unregister_all(dev);
698 mutex_unlock(&dev->mode_config.mutex);
699}
700
701static void atmel_hlcdc_dc_lastclose(struct drm_device *dev) 694static void atmel_hlcdc_dc_lastclose(struct drm_device *dev)
702{ 695{
703 struct atmel_hlcdc_dc *dc = dev->dev_private; 696 struct atmel_hlcdc_dc *dc = dev->dev_private;
@@ -815,15 +808,8 @@ static int atmel_hlcdc_dc_drm_probe(struct platform_device *pdev)
815 if (ret) 808 if (ret)
816 goto err_unload; 809 goto err_unload;
817 810
818 ret = drm_connector_register_all(ddev);
819 if (ret)
820 goto err_unregister;
821
822 return 0; 811 return 0;
823 812
824err_unregister:
825 drm_dev_unregister(ddev);
826
827err_unload: 813err_unload:
828 atmel_hlcdc_dc_unload(ddev); 814 atmel_hlcdc_dc_unload(ddev);
829 815
@@ -837,7 +823,6 @@ static int atmel_hlcdc_dc_drm_remove(struct platform_device *pdev)
837{ 823{
838 struct drm_device *ddev = platform_get_drvdata(pdev); 824 struct drm_device *ddev = platform_get_drvdata(pdev);
839 825
840 atmel_hlcdc_dc_connector_unplug_all(ddev);
841 drm_dev_unregister(ddev); 826 drm_dev_unregister(ddev);
842 atmel_hlcdc_dc_unload(ddev); 827 atmel_hlcdc_dc_unload(ddev);
843 drm_dev_unref(ddev); 828 drm_dev_unref(ddev);
diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c
index 50d0baa06db0..4153e8a193af 100644
--- a/drivers/gpu/drm/drm_auth.c
+++ b/drivers/gpu/drm/drm_auth.c
@@ -30,25 +30,36 @@
30 30
31#include <drm/drmP.h> 31#include <drm/drmP.h>
32#include "drm_internal.h" 32#include "drm_internal.h"
33#include "drm_legacy.h"
33 34
34/** 35/**
35 * drm_getmagic - Get unique magic of a client 36 * DOC: master and authentication
36 * @dev: DRM device to operate on
37 * @data: ioctl data containing the drm_auth object
38 * @file_priv: DRM file that performs the operation
39 * 37 *
40 * This looks up the unique magic of the passed client and returns it. If the 38 * struct &drm_master is used to track groups of clients with open
41 * client did not have a magic assigned, yet, a new one is registered. The magic 39 * primary/legacy device nodes. For every struct &drm_file which has had at
42 * is stored in the passed drm_auth object. 40 * least once successfully became the device master (either through the
41 * SET_MASTER IOCTL, or implicitly through opening the primary device node when
42 * no one else is the current master that time) there exists one &drm_master.
43 * This is noted in the is_master member of &drm_file. All other clients have
44 * just a pointer to the &drm_master they are associated with.
43 * 45 *
44 * Returns: 0 on success, negative error code on failure. 46 * In addition only one &drm_master can be the current master for a &drm_device.
47 * It can be switched through the DROP_MASTER and SET_MASTER IOCTL, or
48 * implicitly through closing/openeing the primary device node. See also
49 * drm_is_current_master().
50 *
51 * Clients can authenticate against the current master (if it matches their own)
52 * using the GETMAGIC and AUTHMAGIC IOCTLs. Together with exchanging masters,
53 * this allows controlled access to the device for an entire group of mutually
54 * trusted clients.
45 */ 55 */
56
46int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv) 57int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
47{ 58{
48 struct drm_auth *auth = data; 59 struct drm_auth *auth = data;
49 int ret = 0; 60 int ret = 0;
50 61
51 mutex_lock(&dev->struct_mutex); 62 mutex_lock(&dev->master_mutex);
52 if (!file_priv->magic) { 63 if (!file_priv->magic) {
53 ret = idr_alloc(&file_priv->master->magic_map, file_priv, 64 ret = idr_alloc(&file_priv->master->magic_map, file_priv,
54 1, 0, GFP_KERNEL); 65 1, 0, GFP_KERNEL);
@@ -56,23 +67,13 @@ int drm_getmagic(struct drm_device *dev, void *data, struct drm_file *file_priv)
56 file_priv->magic = ret; 67 file_priv->magic = ret;
57 } 68 }
58 auth->magic = file_priv->magic; 69 auth->magic = file_priv->magic;
59 mutex_unlock(&dev->struct_mutex); 70 mutex_unlock(&dev->master_mutex);
60 71
61 DRM_DEBUG("%u\n", auth->magic); 72 DRM_DEBUG("%u\n", auth->magic);
62 73
63 return ret < 0 ? ret : 0; 74 return ret < 0 ? ret : 0;
64} 75}
65 76
66/**
67 * drm_authmagic - Authenticate client with a magic
68 * @dev: DRM device to operate on
69 * @data: ioctl data containing the drm_auth object
70 * @file_priv: DRM file that performs the operation
71 *
72 * This looks up a DRM client by the passed magic and authenticates it.
73 *
74 * Returns: 0 on success, negative error code on failure.
75 */
76int drm_authmagic(struct drm_device *dev, void *data, 77int drm_authmagic(struct drm_device *dev, void *data,
77 struct drm_file *file_priv) 78 struct drm_file *file_priv)
78{ 79{
@@ -81,13 +82,253 @@ int drm_authmagic(struct drm_device *dev, void *data,
81 82
82 DRM_DEBUG("%u\n", auth->magic); 83 DRM_DEBUG("%u\n", auth->magic);
83 84
84 mutex_lock(&dev->struct_mutex); 85 mutex_lock(&dev->master_mutex);
85 file = idr_find(&file_priv->master->magic_map, auth->magic); 86 file = idr_find(&file_priv->master->magic_map, auth->magic);
86 if (file) { 87 if (file) {
87 file->authenticated = 1; 88 file->authenticated = 1;
88 idr_replace(&file_priv->master->magic_map, NULL, auth->magic); 89 idr_replace(&file_priv->master->magic_map, NULL, auth->magic);
89 } 90 }
90 mutex_unlock(&dev->struct_mutex); 91 mutex_unlock(&dev->master_mutex);
91 92
92 return file ? 0 : -EINVAL; 93 return file ? 0 : -EINVAL;
93} 94}
95
96static struct drm_master *drm_master_create(struct drm_device *dev)
97{
98 struct drm_master *master;
99
100 master = kzalloc(sizeof(*master), GFP_KERNEL);
101 if (!master)
102 return NULL;
103
104 kref_init(&master->refcount);
105 spin_lock_init(&master->lock.spinlock);
106 init_waitqueue_head(&master->lock.lock_queue);
107 idr_init(&master->magic_map);
108 master->dev = dev;
109
110 return master;
111}
112
113static int drm_set_master(struct drm_device *dev, struct drm_file *fpriv,
114 bool new_master)
115{
116 int ret = 0;
117
118 dev->master = drm_master_get(fpriv->master);
119 if (dev->driver->master_set) {
120 ret = dev->driver->master_set(dev, fpriv, new_master);
121 if (unlikely(ret != 0)) {
122 drm_master_put(&dev->master);
123 }
124 }
125
126 return ret;
127}
128
129static int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv)
130{
131 struct drm_master *old_master;
132 int ret;
133
134 lockdep_assert_held_once(&dev->master_mutex);
135
136 old_master = fpriv->master;
137 fpriv->master = drm_master_create(dev);
138 if (!fpriv->master) {
139 fpriv->master = old_master;
140 return -ENOMEM;
141 }
142
143 if (dev->driver->master_create) {
144 ret = dev->driver->master_create(dev, fpriv->master);
145 if (ret)
146 goto out_err;
147 }
148 fpriv->is_master = 1;
149 fpriv->authenticated = 1;
150
151 ret = drm_set_master(dev, fpriv, true);
152 if (ret)
153 goto out_err;
154
155 if (old_master)
156 drm_master_put(&old_master);
157
158 return 0;
159
160out_err:
161 /* drop references and restore old master on failure */
162 drm_master_put(&fpriv->master);
163 fpriv->master = old_master;
164
165 return ret;
166}
167
168int drm_setmaster_ioctl(struct drm_device *dev, void *data,
169 struct drm_file *file_priv)
170{
171 int ret = 0;
172
173 mutex_lock(&dev->master_mutex);
174 if (drm_is_current_master(file_priv))
175 goto out_unlock;
176
177 if (dev->master) {
178 ret = -EINVAL;
179 goto out_unlock;
180 }
181
182 if (!file_priv->master) {
183 ret = -EINVAL;
184 goto out_unlock;
185 }
186
187 if (!file_priv->is_master) {
188 ret = drm_new_set_master(dev, file_priv);
189 goto out_unlock;
190 }
191
192 ret = drm_set_master(dev, file_priv, false);
193out_unlock:
194 mutex_unlock(&dev->master_mutex);
195 return ret;
196}
197
198static void drm_drop_master(struct drm_device *dev,
199 struct drm_file *fpriv)
200{
201 if (dev->driver->master_drop)
202 dev->driver->master_drop(dev, fpriv);
203 drm_master_put(&dev->master);
204}
205
206int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
207 struct drm_file *file_priv)
208{
209 int ret = -EINVAL;
210
211 mutex_lock(&dev->master_mutex);
212 if (!drm_is_current_master(file_priv))
213 goto out_unlock;
214
215 if (!dev->master)
216 goto out_unlock;
217
218 ret = 0;
219 drm_drop_master(dev, file_priv);
220out_unlock:
221 mutex_unlock(&dev->master_mutex);
222 return ret;
223}
224
225int drm_master_open(struct drm_file *file_priv)
226{
227 struct drm_device *dev = file_priv->minor->dev;
228 int ret = 0;
229
230 /* if there is no current master make this fd it, but do not create
231 * any master object for render clients */
232 mutex_lock(&dev->master_mutex);
233 if (!dev->master)
234 ret = drm_new_set_master(dev, file_priv);
235 else
236 file_priv->master = drm_master_get(dev->master);
237 mutex_unlock(&dev->master_mutex);
238
239 return ret;
240}
241
242void drm_master_release(struct drm_file *file_priv)
243{
244 struct drm_device *dev = file_priv->minor->dev;
245 struct drm_master *master = file_priv->master;
246
247 mutex_lock(&dev->master_mutex);
248 if (file_priv->magic)
249 idr_remove(&file_priv->master->magic_map, file_priv->magic);
250
251 if (!drm_is_current_master(file_priv))
252 goto out;
253
254 if (!drm_core_check_feature(dev, DRIVER_MODESET)) {
255 /*
256 * Since the master is disappearing, so is the
257 * possibility to lock.
258 */
259 mutex_lock(&dev->struct_mutex);
260 if (master->lock.hw_lock) {
261 if (dev->sigdata.lock == master->lock.hw_lock)
262 dev->sigdata.lock = NULL;
263 master->lock.hw_lock = NULL;
264 master->lock.file_priv = NULL;
265 wake_up_interruptible_all(&master->lock.lock_queue);
266 }
267 mutex_unlock(&dev->struct_mutex);
268 }
269
270 if (dev->master == file_priv->master)
271 drm_drop_master(dev, file_priv);
272out:
273 /* drop the master reference held by the file priv */
274 if (file_priv->master)
275 drm_master_put(&file_priv->master);
276 mutex_unlock(&dev->master_mutex);
277}
278
279/**
280 * drm_is_current_master - checks whether @priv is the current master
281 * @fpriv: DRM file private
282 *
283 * Checks whether @fpriv is current master on its device. This decides whether a
284 * client is allowed to run DRM_MASTER IOCTLs.
285 *
286 * Most of the modern IOCTL which require DRM_MASTER are for kernel modesetting
287 * - the current master is assumed to own the non-shareable display hardware.
288 */
289bool drm_is_current_master(struct drm_file *fpriv)
290{
291 return fpriv->is_master && fpriv->master == fpriv->minor->dev->master;
292}
293EXPORT_SYMBOL(drm_is_current_master);
294
295/**
296 * drm_master_get - reference a master pointer
297 * @master: struct &drm_master
298 *
299 * Increments the reference count of @master and returns a pointer to @master.
300 */
301struct drm_master *drm_master_get(struct drm_master *master)
302{
303 kref_get(&master->refcount);
304 return master;
305}
306EXPORT_SYMBOL(drm_master_get);
307
308static void drm_master_destroy(struct kref *kref)
309{
310 struct drm_master *master = container_of(kref, struct drm_master, refcount);
311 struct drm_device *dev = master->dev;
312
313 if (dev->driver->master_destroy)
314 dev->driver->master_destroy(dev, master);
315
316 drm_legacy_master_rmmaps(dev, master);
317
318 idr_destroy(&master->magic_map);
319 kfree(master->unique);
320 kfree(master);
321}
322
323/**
324 * drm_master_put - unreference and clear a master pointer
325 * @master: pointer to a pointer of struct &drm_master
326 *
327 * This decrements the &drm_master behind @master and sets it to NULL.
328 */
329void drm_master_put(struct drm_master **master)
330{
331 kref_put(&(*master)->refcount, drm_master_destroy);
332 *master = NULL;
333}
334EXPORT_SYMBOL(drm_master_put);
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index 9b34158c0f77..c3a12cd8bd0d 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -51,7 +51,7 @@ static struct drm_map_list *drm_find_matching_map(struct drm_device *dev,
51 */ 51 */
52 if (!entry->map || 52 if (!entry->map ||
53 map->type != entry->map->type || 53 map->type != entry->map->type ||
54 entry->master != dev->primary->master) 54 entry->master != dev->master)
55 continue; 55 continue;
56 switch (map->type) { 56 switch (map->type) {
57 case _DRM_SHM: 57 case _DRM_SHM:
@@ -245,12 +245,12 @@ static int drm_addmap_core(struct drm_device * dev, resource_size_t offset,
245 map->offset = (unsigned long)map->handle; 245 map->offset = (unsigned long)map->handle;
246 if (map->flags & _DRM_CONTAINS_LOCK) { 246 if (map->flags & _DRM_CONTAINS_LOCK) {
247 /* Prevent a 2nd X Server from creating a 2nd lock */ 247 /* Prevent a 2nd X Server from creating a 2nd lock */
248 if (dev->primary->master->lock.hw_lock != NULL) { 248 if (dev->master->lock.hw_lock != NULL) {
249 vfree(map->handle); 249 vfree(map->handle);
250 kfree(map); 250 kfree(map);
251 return -EBUSY; 251 return -EBUSY;
252 } 252 }
253 dev->sigdata.lock = dev->primary->master->lock.hw_lock = map->handle; /* Pointer to lock */ 253 dev->sigdata.lock = dev->master->lock.hw_lock = map->handle; /* Pointer to lock */
254 } 254 }
255 break; 255 break;
256 case _DRM_AGP: { 256 case _DRM_AGP: {
@@ -356,7 +356,7 @@ static int drm_addmap_core(struct drm_device * dev, resource_size_t offset,
356 mutex_unlock(&dev->struct_mutex); 356 mutex_unlock(&dev->struct_mutex);
357 357
358 if (!(map->flags & _DRM_DRIVER)) 358 if (!(map->flags & _DRM_DRIVER))
359 list->master = dev->primary->master; 359 list->master = dev->master;
360 *maplist = list; 360 *maplist = list;
361 return 0; 361 return 0;
362} 362}
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 4ec35f9e6de5..fd93e9c79d28 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -39,6 +39,7 @@
39#include <drm/drm_fourcc.h> 39#include <drm/drm_fourcc.h>
40#include <drm/drm_modeset_lock.h> 40#include <drm/drm_modeset_lock.h>
41#include <drm/drm_atomic.h> 41#include <drm/drm_atomic.h>
42#include <drm/drm_auth.h>
42 43
43#include "drm_crtc_internal.h" 44#include "drm_crtc_internal.h"
44#include "drm_internal.h" 45#include "drm_internal.h"
@@ -608,6 +609,31 @@ static unsigned int drm_num_crtcs(struct drm_device *dev)
608 return num; 609 return num;
609} 610}
610 611
612static int drm_crtc_register_all(struct drm_device *dev)
613{
614 struct drm_crtc *crtc;
615 int ret = 0;
616
617 drm_for_each_crtc(crtc, dev) {
618 if (crtc->funcs->late_register)
619 ret = crtc->funcs->late_register(crtc);
620 if (ret)
621 return ret;
622 }
623
624 return 0;
625}
626
627static void drm_crtc_unregister_all(struct drm_device *dev)
628{
629 struct drm_crtc *crtc;
630
631 drm_for_each_crtc(crtc, dev) {
632 if (crtc->funcs->early_unregister)
633 crtc->funcs->early_unregister(crtc);
634 }
635}
636
611/** 637/**
612 * drm_crtc_init_with_planes - Initialise a new CRTC object with 638 * drm_crtc_init_with_planes - Initialise a new CRTC object with
613 * specified primary and cursor planes. 639 * specified primary and cursor planes.
@@ -938,6 +964,12 @@ void drm_connector_cleanup(struct drm_connector *connector)
938 struct drm_device *dev = connector->dev; 964 struct drm_device *dev = connector->dev;
939 struct drm_display_mode *mode, *t; 965 struct drm_display_mode *mode, *t;
940 966
967 /* The connector should have been removed from userspace long before
968 * it is finally destroyed.
969 */
970 if (WARN_ON(connector->registered))
971 drm_connector_unregister(connector);
972
941 if (connector->tile_group) { 973 if (connector->tile_group) {
942 drm_mode_put_tile_group(dev, connector->tile_group); 974 drm_mode_put_tile_group(dev, connector->tile_group);
943 connector->tile_group = NULL; 975 connector->tile_group = NULL;
@@ -984,19 +1016,34 @@ int drm_connector_register(struct drm_connector *connector)
984{ 1016{
985 int ret; 1017 int ret;
986 1018
1019 if (connector->registered)
1020 return 0;
1021
987 ret = drm_sysfs_connector_add(connector); 1022 ret = drm_sysfs_connector_add(connector);
988 if (ret) 1023 if (ret)
989 return ret; 1024 return ret;
990 1025
991 ret = drm_debugfs_connector_add(connector); 1026 ret = drm_debugfs_connector_add(connector);
992 if (ret) { 1027 if (ret) {
993 drm_sysfs_connector_remove(connector); 1028 goto err_sysfs;
994 return ret; 1029 }
1030
1031 if (connector->funcs->late_register) {
1032 ret = connector->funcs->late_register(connector);
1033 if (ret)
1034 goto err_debugfs;
995 } 1035 }
996 1036
997 drm_mode_object_register(connector->dev, &connector->base); 1037 drm_mode_object_register(connector->dev, &connector->base);
998 1038
1039 connector->registered = true;
999 return 0; 1040 return 0;
1041
1042err_debugfs:
1043 drm_debugfs_connector_remove(connector);
1044err_sysfs:
1045 drm_sysfs_connector_remove(connector);
1046 return ret;
1000} 1047}
1001EXPORT_SYMBOL(drm_connector_register); 1048EXPORT_SYMBOL(drm_connector_register);
1002 1049
@@ -1008,8 +1055,16 @@ EXPORT_SYMBOL(drm_connector_register);
1008 */ 1055 */
1009void drm_connector_unregister(struct drm_connector *connector) 1056void drm_connector_unregister(struct drm_connector *connector)
1010{ 1057{
1058 if (!connector->registered)
1059 return;
1060
1061 if (connector->funcs->early_unregister)
1062 connector->funcs->early_unregister(connector);
1063
1011 drm_sysfs_connector_remove(connector); 1064 drm_sysfs_connector_remove(connector);
1012 drm_debugfs_connector_remove(connector); 1065 drm_debugfs_connector_remove(connector);
1066
1067 connector->registered = false;
1013} 1068}
1014EXPORT_SYMBOL(drm_connector_unregister); 1069EXPORT_SYMBOL(drm_connector_unregister);
1015 1070
@@ -1018,9 +1073,9 @@ EXPORT_SYMBOL(drm_connector_unregister);
1018 * @dev: drm device 1073 * @dev: drm device
1019 * 1074 *
1020 * This function registers all connectors in sysfs and other places so that 1075 * This function registers all connectors in sysfs and other places so that
1021 * userspace can start to access them. Drivers can call it after calling 1076 * userspace can start to access them. drm_connector_register_all() is called
1022 * drm_dev_register() to complete the device registration, if they don't call 1077 * automatically from drm_dev_register() to complete the device registration,
1023 * drm_connector_register() on each connector individually. 1078 * if they don't call drm_connector_register() on each connector individually.
1024 * 1079 *
1025 * When a device is unplugged and should be removed from userspace access, 1080 * When a device is unplugged and should be removed from userspace access,
1026 * call drm_connector_unregister_all(), which is the inverse of this 1081 * call drm_connector_unregister_all(), which is the inverse of this
@@ -1073,6 +1128,31 @@ void drm_connector_unregister_all(struct drm_device *dev)
1073} 1128}
1074EXPORT_SYMBOL(drm_connector_unregister_all); 1129EXPORT_SYMBOL(drm_connector_unregister_all);
1075 1130
1131static int drm_encoder_register_all(struct drm_device *dev)
1132{
1133 struct drm_encoder *encoder;
1134 int ret = 0;
1135
1136 drm_for_each_encoder(encoder, dev) {
1137 if (encoder->funcs->late_register)
1138 ret = encoder->funcs->late_register(encoder);
1139 if (ret)
1140 return ret;
1141 }
1142
1143 return 0;
1144}
1145
1146static void drm_encoder_unregister_all(struct drm_device *dev)
1147{
1148 struct drm_encoder *encoder;
1149
1150 drm_for_each_encoder(encoder, dev) {
1151 if (encoder->funcs->early_unregister)
1152 encoder->funcs->early_unregister(encoder);
1153 }
1154}
1155
1076/** 1156/**
1077 * drm_encoder_init - Init a preallocated encoder 1157 * drm_encoder_init - Init a preallocated encoder
1078 * @dev: drm device 1158 * @dev: drm device
@@ -1261,6 +1341,31 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
1261} 1341}
1262EXPORT_SYMBOL(drm_universal_plane_init); 1342EXPORT_SYMBOL(drm_universal_plane_init);
1263 1343
1344static int drm_plane_register_all(struct drm_device *dev)
1345{
1346 struct drm_plane *plane;
1347 int ret = 0;
1348
1349 drm_for_each_plane(plane, dev) {
1350 if (plane->funcs->late_register)
1351 ret = plane->funcs->late_register(plane);
1352 if (ret)
1353 return ret;
1354 }
1355
1356 return 0;
1357}
1358
1359static void drm_plane_unregister_all(struct drm_device *dev)
1360{
1361 struct drm_plane *plane;
1362
1363 drm_for_each_plane(plane, dev) {
1364 if (plane->funcs->early_unregister)
1365 plane->funcs->early_unregister(plane);
1366 }
1367}
1368
1264/** 1369/**
1265 * drm_plane_init - Initialize a legacy plane 1370 * drm_plane_init - Initialize a legacy plane
1266 * @dev: DRM device 1371 * @dev: DRM device
@@ -1383,6 +1488,46 @@ void drm_plane_force_disable(struct drm_plane *plane)
1383} 1488}
1384EXPORT_SYMBOL(drm_plane_force_disable); 1489EXPORT_SYMBOL(drm_plane_force_disable);
1385 1490
1491int drm_modeset_register_all(struct drm_device *dev)
1492{
1493 int ret;
1494
1495 ret = drm_plane_register_all(dev);
1496 if (ret)
1497 goto err_plane;
1498
1499 ret = drm_crtc_register_all(dev);
1500 if (ret)
1501 goto err_crtc;
1502
1503 ret = drm_encoder_register_all(dev);
1504 if (ret)
1505 goto err_encoder;
1506
1507 ret = drm_connector_register_all(dev);
1508 if (ret)
1509 goto err_connector;
1510
1511 return 0;
1512
1513err_connector:
1514 drm_encoder_unregister_all(dev);
1515err_encoder:
1516 drm_crtc_unregister_all(dev);
1517err_crtc:
1518 drm_plane_unregister_all(dev);
1519err_plane:
1520 return ret;
1521}
1522
1523void drm_modeset_unregister_all(struct drm_device *dev)
1524{
1525 drm_connector_unregister_all(dev);
1526 drm_encoder_unregister_all(dev);
1527 drm_crtc_unregister_all(dev);
1528 drm_plane_unregister_all(dev);
1529}
1530
1386static int drm_mode_create_standard_properties(struct drm_device *dev) 1531static int drm_mode_create_standard_properties(struct drm_device *dev)
1387{ 1532{
1388 struct drm_property *prop; 1533 struct drm_property *prop;
@@ -3499,7 +3644,7 @@ int drm_mode_getfb(struct drm_device *dev,
3499 r->bpp = fb->bits_per_pixel; 3644 r->bpp = fb->bits_per_pixel;
3500 r->pitch = fb->pitches[0]; 3645 r->pitch = fb->pitches[0];
3501 if (fb->funcs->create_handle) { 3646 if (fb->funcs->create_handle) {
3502 if (file_priv->is_master || capable(CAP_SYS_ADMIN) || 3647 if (drm_is_current_master(file_priv) || capable(CAP_SYS_ADMIN) ||
3503 drm_is_control_client(file_priv)) { 3648 drm_is_control_client(file_priv)) {
3504 ret = fb->funcs->create_handle(fb, file_priv, 3649 ret = fb->funcs->create_handle(fb, file_priv,
3505 &r->handle); 3650 &r->handle);
@@ -3656,6 +3801,13 @@ void drm_fb_release(struct drm_file *priv)
3656 } 3801 }
3657} 3802}
3658 3803
3804static bool drm_property_type_valid(struct drm_property *property)
3805{
3806 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
3807 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
3808 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
3809}
3810
3659/** 3811/**
3660 * drm_property_create - create a new property type 3812 * drm_property_create - create a new property type
3661 * @dev: drm device 3813 * @dev: drm device
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index bf10d7046aa6..d61591274ff6 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -232,6 +232,9 @@ static void __drm_helper_disable_unused_functions(struct drm_device *dev)
232 */ 232 */
233void drm_helper_disable_unused_functions(struct drm_device *dev) 233void drm_helper_disable_unused_functions(struct drm_device *dev)
234{ 234{
235 if (drm_core_check_feature(dev, DRIVER_ATOMIC))
236 DRM_ERROR("Called for atomic driver, this is not what you want.\n");
237
235 drm_modeset_lock_all(dev); 238 drm_modeset_lock_all(dev);
236 __drm_helper_disable_unused_functions(dev); 239 __drm_helper_disable_unused_functions(dev);
237 drm_modeset_unlock_all(dev); 240 drm_modeset_unlock_all(dev);
diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
index a78c138282ea..47a500b90fd7 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -31,14 +31,100 @@
31 * and are not exported to drivers. 31 * and are not exported to drivers.
32 */ 32 */
33 33
34
35/* drm_crtc.c */
36void drm_connector_ida_init(void);
37void drm_connector_ida_destroy(void);
34int drm_mode_object_get(struct drm_device *dev, 38int drm_mode_object_get(struct drm_device *dev,
35 struct drm_mode_object *obj, uint32_t obj_type); 39 struct drm_mode_object *obj, uint32_t obj_type);
36void drm_mode_object_unregister(struct drm_device *dev, 40void drm_mode_object_unregister(struct drm_device *dev,
37 struct drm_mode_object *object); 41 struct drm_mode_object *object);
42bool drm_property_change_valid_get(struct drm_property *property,
43 uint64_t value,
44 struct drm_mode_object **ref);
45void drm_property_change_valid_put(struct drm_property *property,
46 struct drm_mode_object *ref);
47
48int drm_plane_check_pixel_format(const struct drm_plane *plane,
49 u32 format);
50int drm_crtc_check_viewport(const struct drm_crtc *crtc,
51 int x, int y,
52 const struct drm_display_mode *mode,
53 const struct drm_framebuffer *fb);
54
55void drm_fb_release(struct drm_file *file_priv);
56void drm_property_destroy_user_blobs(struct drm_device *dev,
57 struct drm_file *file_priv);
58
59/* dumb buffer support IOCTLs */
60int drm_mode_create_dumb_ioctl(struct drm_device *dev,
61 void *data, struct drm_file *file_priv);
62int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
63 void *data, struct drm_file *file_priv);
64int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
65 void *data, struct drm_file *file_priv);
66
67/* framebuffer IOCTLs */
68extern int drm_mode_addfb(struct drm_device *dev,
69 void *data, struct drm_file *file_priv);
70extern int drm_mode_addfb2(struct drm_device *dev,
71 void *data, struct drm_file *file_priv);
72int drm_mode_rmfb(struct drm_device *dev,
73 void *data, struct drm_file *file_priv);
74int drm_mode_getfb(struct drm_device *dev,
75 void *data, struct drm_file *file_priv);
76int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
77 void *data, struct drm_file *file_priv);
78
79/* IOCTLs */
80int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
81 struct drm_file *file_priv);
82int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
83 struct drm_file *file_priv);
84
85int drm_mode_getresources(struct drm_device *dev,
86 void *data, struct drm_file *file_priv);
87int drm_mode_getplane_res(struct drm_device *dev, void *data,
88 struct drm_file *file_priv);
89int drm_mode_getcrtc(struct drm_device *dev,
90 void *data, struct drm_file *file_priv);
91int drm_mode_getconnector(struct drm_device *dev,
92 void *data, struct drm_file *file_priv);
93int drm_mode_setcrtc(struct drm_device *dev,
94 void *data, struct drm_file *file_priv);
95int drm_mode_getplane(struct drm_device *dev,
96 void *data, struct drm_file *file_priv);
97int drm_mode_setplane(struct drm_device *dev,
98 void *data, struct drm_file *file_priv);
99int drm_mode_cursor_ioctl(struct drm_device *dev,
100 void *data, struct drm_file *file_priv);
101int drm_mode_cursor2_ioctl(struct drm_device *dev,
102 void *data, struct drm_file *file_priv);
103int drm_mode_getproperty_ioctl(struct drm_device *dev,
104 void *data, struct drm_file *file_priv);
105int drm_mode_getblob_ioctl(struct drm_device *dev,
106 void *data, struct drm_file *file_priv);
107int drm_mode_createblob_ioctl(struct drm_device *dev,
108 void *data, struct drm_file *file_priv);
109int drm_mode_destroyblob_ioctl(struct drm_device *dev,
110 void *data, struct drm_file *file_priv);
111int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
112 void *data, struct drm_file *file_priv);
113int drm_mode_getencoder(struct drm_device *dev,
114 void *data, struct drm_file *file_priv);
115int drm_mode_gamma_get_ioctl(struct drm_device *dev,
116 void *data, struct drm_file *file_priv);
117int drm_mode_gamma_set_ioctl(struct drm_device *dev,
118 void *data, struct drm_file *file_priv);
119
120int drm_mode_page_flip_ioctl(struct drm_device *dev,
121 void *data, struct drm_file *file_priv);
38 122
39/* drm_atomic.c */ 123/* drm_atomic.c */
40int drm_atomic_get_property(struct drm_mode_object *obj, 124int drm_atomic_get_property(struct drm_mode_object *obj,
41 struct drm_property *property, uint64_t *val); 125 struct drm_property *property, uint64_t *val);
42int drm_mode_atomic_ioctl(struct drm_device *dev, 126int drm_mode_atomic_ioctl(struct drm_device *dev,
43 void *data, struct drm_file *file_priv); 127 void *data, struct drm_file *file_priv);
44 128
129int drm_modeset_register_all(struct drm_device *dev);
130void drm_modeset_unregister_all(struct drm_device *dev);
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index 3bcf8e6a85b3..fa10cef2ba37 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -46,11 +46,8 @@
46 46
47static const struct drm_info_list drm_debugfs_list[] = { 47static const struct drm_info_list drm_debugfs_list[] = {
48 {"name", drm_name_info, 0}, 48 {"name", drm_name_info, 0},
49 {"vm", drm_vm_info, 0},
50 {"clients", drm_clients_info, 0}, 49 {"clients", drm_clients_info, 0},
51 {"bufs", drm_bufs_info, 0},
52 {"gem_names", drm_gem_name_info, DRIVER_GEM}, 50 {"gem_names", drm_gem_name_info, DRIVER_GEM},
53 {"vma", drm_vma_info, 0},
54}; 51};
55#define DRM_DEBUGFS_ENTRIES ARRAY_SIZE(drm_debugfs_list) 52#define DRM_DEBUGFS_ENTRIES ARRAY_SIZE(drm_debugfs_list)
56 53
diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c
index eeaf5a7c3aa7..091053e995e5 100644
--- a/drivers/gpu/drm/drm_dp_helper.c
+++ b/drivers/gpu/drm/drm_dp_helper.c
@@ -708,8 +708,6 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
708 708
709 memset(&msg, 0, sizeof(msg)); 709 memset(&msg, 0, sizeof(msg));
710 710
711 mutex_lock(&aux->hw_mutex);
712
713 for (i = 0; i < num; i++) { 711 for (i = 0; i < num; i++) {
714 msg.address = msgs[i].addr; 712 msg.address = msgs[i].addr;
715 drm_dp_i2c_msg_set_request(&msg, &msgs[i]); 713 drm_dp_i2c_msg_set_request(&msg, &msgs[i]);
@@ -764,8 +762,6 @@ static int drm_dp_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs,
764 msg.size = 0; 762 msg.size = 0;
765 (void)drm_dp_i2c_do_msg(aux, &msg); 763 (void)drm_dp_i2c_do_msg(aux, &msg);
766 764
767 mutex_unlock(&aux->hw_mutex);
768
769 return err; 765 return err;
770} 766}
771 767
@@ -774,22 +770,64 @@ static const struct i2c_algorithm drm_dp_i2c_algo = {
774 .master_xfer = drm_dp_i2c_xfer, 770 .master_xfer = drm_dp_i2c_xfer,
775}; 771};
776 772
773static struct drm_dp_aux *i2c_to_aux(struct i2c_adapter *i2c)
774{
775 return container_of(i2c, struct drm_dp_aux, ddc);
776}
777
778static void lock_bus(struct i2c_adapter *i2c, unsigned int flags)
779{
780 mutex_lock(&i2c_to_aux(i2c)->hw_mutex);
781}
782
783static int trylock_bus(struct i2c_adapter *i2c, unsigned int flags)
784{
785 return mutex_trylock(&i2c_to_aux(i2c)->hw_mutex);
786}
787
788static void unlock_bus(struct i2c_adapter *i2c, unsigned int flags)
789{
790 mutex_unlock(&i2c_to_aux(i2c)->hw_mutex);
791}
792
777/** 793/**
778 * drm_dp_aux_register() - initialise and register aux channel 794 * drm_dp_aux_init() - minimally initialise an aux channel
779 * @aux: DisplayPort AUX channel 795 * @aux: DisplayPort AUX channel
780 * 796 *
781 * Returns 0 on success or a negative error code on failure. 797 * If you need to use the drm_dp_aux's i2c adapter prior to registering it
798 * with the outside world, call drm_dp_aux_init() first. You must still
799 * call drm_dp_aux_register() once the connector has been registered to
800 * allow userspace access to the auxiliary DP channel.
782 */ 801 */
783int drm_dp_aux_register(struct drm_dp_aux *aux) 802void drm_dp_aux_init(struct drm_dp_aux *aux)
784{ 803{
785 int ret;
786
787 mutex_init(&aux->hw_mutex); 804 mutex_init(&aux->hw_mutex);
788 805
789 aux->ddc.algo = &drm_dp_i2c_algo; 806 aux->ddc.algo = &drm_dp_i2c_algo;
790 aux->ddc.algo_data = aux; 807 aux->ddc.algo_data = aux;
791 aux->ddc.retries = 3; 808 aux->ddc.retries = 3;
792 809
810 aux->ddc.lock_bus = lock_bus;
811 aux->ddc.trylock_bus = trylock_bus;
812 aux->ddc.unlock_bus = unlock_bus;
813}
814EXPORT_SYMBOL(drm_dp_aux_init);
815
816/**
817 * drm_dp_aux_register() - initialise and register aux channel
818 * @aux: DisplayPort AUX channel
819 *
820 * Automatically calls drm_dp_aux_init() if this hasn't been done yet.
821 *
822 * Returns 0 on success or a negative error code on failure.
823 */
824int drm_dp_aux_register(struct drm_dp_aux *aux)
825{
826 int ret;
827
828 if (!aux->ddc.algo)
829 drm_dp_aux_init(aux);
830
793 aux->ddc.class = I2C_CLASS_DDC; 831 aux->ddc.class = I2C_CLASS_DDC;
794 aux->ddc.owner = THIS_MODULE; 832 aux->ddc.owner = THIS_MODULE;
795 aux->ddc.dev.parent = aux->dev; 833 aux->ddc.dev.parent = aux->dev;
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 8b2582aeaab6..aead9ffcbe29 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -34,8 +34,10 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <drm/drmP.h> 35#include <drm/drmP.h>
36#include <drm/drm_core.h> 36#include <drm/drm_core.h>
37#include "drm_crtc_internal.h"
37#include "drm_legacy.h" 38#include "drm_legacy.h"
38#include "drm_internal.h" 39#include "drm_internal.h"
40#include "drm_crtc_internal.h"
39 41
40/* 42/*
41 * drm_debug: Enable debug output. 43 * drm_debug: Enable debug output.
@@ -93,114 +95,6 @@ void drm_ut_debug_printk(const char *function_name, const char *format, ...)
93} 95}
94EXPORT_SYMBOL(drm_ut_debug_printk); 96EXPORT_SYMBOL(drm_ut_debug_printk);
95 97
96struct drm_master *drm_master_create(struct drm_minor *minor)
97{
98 struct drm_master *master;
99
100 master = kzalloc(sizeof(*master), GFP_KERNEL);
101 if (!master)
102 return NULL;
103
104 kref_init(&master->refcount);
105 spin_lock_init(&master->lock.spinlock);
106 init_waitqueue_head(&master->lock.lock_queue);
107 idr_init(&master->magic_map);
108 master->minor = minor;
109
110 return master;
111}
112
113struct drm_master *drm_master_get(struct drm_master *master)
114{
115 kref_get(&master->refcount);
116 return master;
117}
118EXPORT_SYMBOL(drm_master_get);
119
120static void drm_master_destroy(struct kref *kref)
121{
122 struct drm_master *master = container_of(kref, struct drm_master, refcount);
123 struct drm_device *dev = master->minor->dev;
124
125 if (dev->driver->master_destroy)
126 dev->driver->master_destroy(dev, master);
127
128 drm_legacy_master_rmmaps(dev, master);
129
130 idr_destroy(&master->magic_map);
131 kfree(master->unique);
132 kfree(master);
133}
134
135void drm_master_put(struct drm_master **master)
136{
137 kref_put(&(*master)->refcount, drm_master_destroy);
138 *master = NULL;
139}
140EXPORT_SYMBOL(drm_master_put);
141
142int drm_setmaster_ioctl(struct drm_device *dev, void *data,
143 struct drm_file *file_priv)
144{
145 int ret = 0;
146
147 mutex_lock(&dev->master_mutex);
148 if (file_priv->is_master)
149 goto out_unlock;
150
151 if (file_priv->minor->master) {
152 ret = -EINVAL;
153 goto out_unlock;
154 }
155
156 if (!file_priv->master) {
157 ret = -EINVAL;
158 goto out_unlock;
159 }
160
161 if (!file_priv->allowed_master) {
162 ret = drm_new_set_master(dev, file_priv);
163 goto out_unlock;
164 }
165
166 file_priv->minor->master = drm_master_get(file_priv->master);
167 file_priv->is_master = 1;
168 if (dev->driver->master_set) {
169 ret = dev->driver->master_set(dev, file_priv, false);
170 if (unlikely(ret != 0)) {
171 file_priv->is_master = 0;
172 drm_master_put(&file_priv->minor->master);
173 }
174 }
175
176out_unlock:
177 mutex_unlock(&dev->master_mutex);
178 return ret;
179}
180
181int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
182 struct drm_file *file_priv)
183{
184 int ret = -EINVAL;
185
186 mutex_lock(&dev->master_mutex);
187 if (!file_priv->is_master)
188 goto out_unlock;
189
190 if (!file_priv->minor->master)
191 goto out_unlock;
192
193 ret = 0;
194 if (dev->driver->master_drop)
195 dev->driver->master_drop(dev, file_priv, false);
196 drm_master_put(&file_priv->minor->master);
197 file_priv->is_master = 0;
198
199out_unlock:
200 mutex_unlock(&dev->master_mutex);
201 return ret;
202}
203
204/* 98/*
205 * DRM Minors 99 * DRM Minors
206 * A DRM device can provide several char-dev interfaces on the DRM-Major. Each 100 * A DRM device can provide several char-dev interfaces on the DRM-Major. Each
@@ -405,10 +299,9 @@ void drm_minor_release(struct drm_minor *minor)
405 * callbacks implemented by the driver. The driver then needs to initialize all 299 * callbacks implemented by the driver. The driver then needs to initialize all
406 * the various subsystems for the drm device like memory management, vblank 300 * the various subsystems for the drm device like memory management, vblank
407 * handling, modesetting support and intial output configuration plus obviously 301 * handling, modesetting support and intial output configuration plus obviously
408 * initialize all the corresponding hardware bits. An important part of this is 302 * initialize all the corresponding hardware bits. Finally when everything is up
409 * also calling drm_dev_set_unique() to set the userspace-visible unique name of 303 * and running and ready for userspace the device instance can be published
410 * this device instance. Finally when everything is up and running and ready for 304 * using drm_dev_register().
411 * userspace the device instance can be published using drm_dev_register().
412 * 305 *
413 * There is also deprecated support for initalizing device instances using 306 * There is also deprecated support for initalizing device instances using
414 * bus-specific helpers and the ->load() callback. But due to 307 * bus-specific helpers and the ->load() callback. But due to
@@ -430,6 +323,14 @@ void drm_minor_release(struct drm_minor *minor)
430 * dev_priv field of &drm_device. 323 * dev_priv field of &drm_device.
431 */ 324 */
432 325
326static int drm_dev_set_unique(struct drm_device *dev, const char *name)
327{
328 kfree(dev->unique);
329 dev->unique = kstrdup(name, GFP_KERNEL);
330
331 return dev->unique ? 0 : -ENOMEM;
332}
333
433/** 334/**
434 * drm_put_dev - Unregister and release a DRM device 335 * drm_put_dev - Unregister and release a DRM device
435 * @dev: DRM device 336 * @dev: DRM device
@@ -549,11 +450,12 @@ static void drm_fs_inode_free(struct inode *inode)
549} 450}
550 451
551/** 452/**
552 * drm_dev_alloc - Allocate new DRM device 453 * drm_dev_init - Initialise new DRM device
553 * @driver: DRM driver to allocate device for 454 * @dev: DRM device
455 * @driver: DRM driver
554 * @parent: Parent device object 456 * @parent: Parent device object
555 * 457 *
556 * Allocate and initialize a new DRM device. No device registration is done. 458 * Initialize a new DRM device. No device registration is done.
557 * Call drm_dev_register() to advertice the device to user space and register it 459 * Call drm_dev_register() to advertice the device to user space and register it
558 * with other core subsystems. This should be done last in the device 460 * with other core subsystems. This should be done last in the device
559 * initialization sequence to make sure userspace can't access an inconsistent 461 * initialization sequence to make sure userspace can't access an inconsistent
@@ -564,19 +466,18 @@ static void drm_fs_inode_free(struct inode *inode)
564 * 466 *
565 * Note that for purely virtual devices @parent can be NULL. 467 * Note that for purely virtual devices @parent can be NULL.
566 * 468 *
469 * Drivers that do not want to allocate their own device struct
470 * embedding struct &drm_device can call drm_dev_alloc() instead.
471 *
567 * RETURNS: 472 * RETURNS:
568 * Pointer to new DRM device, or NULL if out of memory. 473 * 0 on success, or error code on failure.
569 */ 474 */
570struct drm_device *drm_dev_alloc(struct drm_driver *driver, 475int drm_dev_init(struct drm_device *dev,
571 struct device *parent) 476 struct drm_driver *driver,
477 struct device *parent)
572{ 478{
573 struct drm_device *dev;
574 int ret; 479 int ret;
575 480
576 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
577 if (!dev)
578 return NULL;
579
580 kref_init(&dev->ref); 481 kref_init(&dev->ref);
581 dev->dev = parent; 482 dev->dev = parent;
582 dev->driver = driver; 483 dev->driver = driver;
@@ -617,7 +518,8 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
617 if (ret) 518 if (ret)
618 goto err_minors; 519 goto err_minors;
619 520
620 if (drm_ht_create(&dev->map_hash, 12)) 521 ret = drm_ht_create(&dev->map_hash, 12);
522 if (ret)
621 goto err_minors; 523 goto err_minors;
622 524
623 drm_legacy_ctxbitmap_init(dev); 525 drm_legacy_ctxbitmap_init(dev);
@@ -630,13 +532,13 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
630 } 532 }
631 } 533 }
632 534
633 if (parent) { 535 /* Use the parent device name as DRM device unique identifier, but fall
634 ret = drm_dev_set_unique(dev, dev_name(parent)); 536 * back to the driver name for virtual devices like vgem. */
635 if (ret) 537 ret = drm_dev_set_unique(dev, parent ? dev_name(parent) : driver->name);
636 goto err_setunique; 538 if (ret)
637 } 539 goto err_setunique;
638 540
639 return dev; 541 return 0;
640 542
641err_setunique: 543err_setunique:
642 if (drm_core_check_feature(dev, DRIVER_GEM)) 544 if (drm_core_check_feature(dev, DRIVER_GEM))
@@ -651,8 +553,49 @@ err_minors:
651 drm_fs_inode_free(dev->anon_inode); 553 drm_fs_inode_free(dev->anon_inode);
652err_free: 554err_free:
653 mutex_destroy(&dev->master_mutex); 555 mutex_destroy(&dev->master_mutex);
654 kfree(dev); 556 return ret;
655 return NULL; 557}
558EXPORT_SYMBOL(drm_dev_init);
559
560/**
561 * drm_dev_alloc - Allocate new DRM device
562 * @driver: DRM driver to allocate device for
563 * @parent: Parent device object
564 *
565 * Allocate and initialize a new DRM device. No device registration is done.
566 * Call drm_dev_register() to advertice the device to user space and register it
567 * with other core subsystems. This should be done last in the device
568 * initialization sequence to make sure userspace can't access an inconsistent
569 * state.
570 *
571 * The initial ref-count of the object is 1. Use drm_dev_ref() and
572 * drm_dev_unref() to take and drop further ref-counts.
573 *
574 * Note that for purely virtual devices @parent can be NULL.
575 *
576 * Drivers that wish to subclass or embed struct &drm_device into their
577 * own struct should look at using drm_dev_init() instead.
578 *
579 * RETURNS:
580 * Pointer to new DRM device, or NULL if out of memory.
581 */
582struct drm_device *drm_dev_alloc(struct drm_driver *driver,
583 struct device *parent)
584{
585 struct drm_device *dev;
586 int ret;
587
588 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
589 if (!dev)
590 return NULL;
591
592 ret = drm_dev_init(dev, driver, parent);
593 if (ret) {
594 kfree(dev);
595 return NULL;
596 }
597
598 return dev;
656} 599}
657EXPORT_SYMBOL(drm_dev_alloc); 600EXPORT_SYMBOL(drm_dev_alloc);
658 601
@@ -716,11 +659,7 @@ EXPORT_SYMBOL(drm_dev_unref);
716 * 659 *
717 * Register the DRM device @dev with the system, advertise device to user-space 660 * Register the DRM device @dev with the system, advertise device to user-space
718 * and start normal device operation. @dev must be allocated via drm_dev_alloc() 661 * and start normal device operation. @dev must be allocated via drm_dev_alloc()
719 * previously. Right after drm_dev_register() the driver should call 662 * previously.
720 * drm_connector_register_all() to register all connectors in sysfs. This is
721 * a separate call for backward compatibility with drivers still using
722 * the deprecated ->load() callback, where connectors are registered from within
723 * the ->load() callback.
724 * 663 *
725 * Never call this twice on any device! 664 * Never call this twice on any device!
726 * 665 *
@@ -757,6 +696,9 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags)
757 goto err_minors; 696 goto err_minors;
758 } 697 }
759 698
699 if (drm_core_check_feature(dev, DRIVER_MODESET))
700 drm_modeset_register_all(dev);
701
760 ret = 0; 702 ret = 0;
761 goto out_unlock; 703 goto out_unlock;
762 704
@@ -787,6 +729,9 @@ void drm_dev_unregister(struct drm_device *dev)
787 729
788 drm_lastclose(dev); 730 drm_lastclose(dev);
789 731
732 if (drm_core_check_feature(dev, DRIVER_MODESET))
733 drm_modeset_unregister_all(dev);
734
790 if (dev->driver->unload) 735 if (dev->driver->unload)
791 dev->driver->unload(dev); 736 dev->driver->unload(dev);
792 737
@@ -804,26 +749,6 @@ void drm_dev_unregister(struct drm_device *dev)
804} 749}
805EXPORT_SYMBOL(drm_dev_unregister); 750EXPORT_SYMBOL(drm_dev_unregister);
806 751
807/**
808 * drm_dev_set_unique - Set the unique name of a DRM device
809 * @dev: device of which to set the unique name
810 * @name: unique name
811 *
812 * Sets the unique name of a DRM device using the specified string. Drivers
813 * can use this at driver probe time if the unique name of the devices they
814 * drive is static.
815 *
816 * Return: 0 on success or a negative error code on failure.
817 */
818int drm_dev_set_unique(struct drm_device *dev, const char *name)
819{
820 kfree(dev->unique);
821 dev->unique = kstrdup(name, GFP_KERNEL);
822
823 return dev->unique ? 0 : -ENOMEM;
824}
825EXPORT_SYMBOL(drm_dev_set_unique);
826
827/* 752/*
828 * DRM Core 753 * DRM Core
829 * The DRM core module initializes all global DRM objects and makes them 754 * The DRM core module initializes all global DRM objects and makes them
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 0bac5246e5a7..ce54e985d91b 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -464,7 +464,7 @@ static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
464 464
465 /* Sometimes user space wants everything disabled, so don't steal the 465 /* Sometimes user space wants everything disabled, so don't steal the
466 * display if there's a master. */ 466 * display if there's a master. */
467 if (dev->primary->master) 467 if (lockless_dereference(dev->master))
468 return false; 468 return false;
469 469
470 drm_for_each_crtc(crtc, dev) { 470 drm_for_each_crtc(crtc, dev) {
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index a27bc7cda975..323c238fcac7 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -40,6 +40,7 @@
40#include <linux/module.h> 40#include <linux/module.h>
41#include "drm_legacy.h" 41#include "drm_legacy.h"
42#include "drm_internal.h" 42#include "drm_internal.h"
43#include "drm_crtc_internal.h"
43 44
44/* from BKL pushdown */ 45/* from BKL pushdown */
45DEFINE_MUTEX(drm_global_mutex); 46DEFINE_MUTEX(drm_global_mutex);
@@ -168,60 +169,6 @@ static int drm_cpu_valid(void)
168} 169}
169 170
170/* 171/*
171 * drm_new_set_master - Allocate a new master object and become master for the
172 * associated master realm.
173 *
174 * @dev: The associated device.
175 * @fpriv: File private identifying the client.
176 *
177 * This function must be called with dev::struct_mutex held.
178 * Returns negative error code on failure. Zero on success.
179 */
180int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv)
181{
182 struct drm_master *old_master;
183 int ret;
184
185 lockdep_assert_held_once(&dev->master_mutex);
186
187 /* create a new master */
188 fpriv->minor->master = drm_master_create(fpriv->minor);
189 if (!fpriv->minor->master)
190 return -ENOMEM;
191
192 /* take another reference for the copy in the local file priv */
193 old_master = fpriv->master;
194 fpriv->master = drm_master_get(fpriv->minor->master);
195
196 if (dev->driver->master_create) {
197 ret = dev->driver->master_create(dev, fpriv->master);
198 if (ret)
199 goto out_err;
200 }
201 if (dev->driver->master_set) {
202 ret = dev->driver->master_set(dev, fpriv, true);
203 if (ret)
204 goto out_err;
205 }
206
207 fpriv->is_master = 1;
208 fpriv->allowed_master = 1;
209 fpriv->authenticated = 1;
210 if (old_master)
211 drm_master_put(&old_master);
212
213 return 0;
214
215out_err:
216 /* drop both references and restore old master on failure */
217 drm_master_put(&fpriv->minor->master);
218 drm_master_put(&fpriv->master);
219 fpriv->master = old_master;
220
221 return ret;
222}
223
224/*
225 * Called whenever a process opens /dev/drm. 172 * Called whenever a process opens /dev/drm.
226 * 173 *
227 * \param filp file pointer. 174 * \param filp file pointer.
@@ -283,19 +230,11 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor)
283 goto out_prime_destroy; 230 goto out_prime_destroy;
284 } 231 }
285 232
286 /* if there is no current master make this fd it, but do not create 233 if (drm_is_primary_client(priv)) {
287 * any master object for render clients */ 234 ret = drm_master_open(priv);
288 mutex_lock(&dev->master_mutex);
289 if (drm_is_primary_client(priv) && !priv->minor->master) {
290 /* create a new master */
291 ret = drm_new_set_master(dev, priv);
292 if (ret) 235 if (ret)
293 goto out_close; 236 goto out_close;
294 } else if (drm_is_primary_client(priv)) {
295 /* get a reference to the master */
296 priv->master = drm_master_get(priv->minor->master);
297 } 237 }
298 mutex_unlock(&dev->master_mutex);
299 238
300 mutex_lock(&dev->filelist_mutex); 239 mutex_lock(&dev->filelist_mutex);
301 list_add(&priv->lhead, &dev->filelist); 240 list_add(&priv->lhead, &dev->filelist);
@@ -324,7 +263,6 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor)
324 return 0; 263 return 0;
325 264
326out_close: 265out_close:
327 mutex_unlock(&dev->master_mutex);
328 if (dev->driver->postclose) 266 if (dev->driver->postclose)
329 dev->driver->postclose(dev, priv); 267 dev->driver->postclose(dev, priv);
330out_prime_destroy: 268out_prime_destroy:
@@ -338,18 +276,6 @@ out_prime_destroy:
338 return ret; 276 return ret;
339} 277}
340 278
341static void drm_master_release(struct drm_device *dev, struct file *filp)
342{
343 struct drm_file *file_priv = filp->private_data;
344
345 if (drm_legacy_i_have_hw_lock(dev, file_priv)) {
346 DRM_DEBUG("File %p released, freeing lock for context %d\n",
347 filp, _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
348 drm_legacy_lock_free(&file_priv->master->lock,
349 _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
350 }
351}
352
353static void drm_events_release(struct drm_file *file_priv) 279static void drm_events_release(struct drm_file *file_priv)
354{ 280{
355 struct drm_device *dev = file_priv->minor->dev; 281 struct drm_device *dev = file_priv->minor->dev;
@@ -451,11 +377,6 @@ int drm_release(struct inode *inode, struct file *filp)
451 list_del(&file_priv->lhead); 377 list_del(&file_priv->lhead);
452 mutex_unlock(&dev->filelist_mutex); 378 mutex_unlock(&dev->filelist_mutex);
453 379
454 mutex_lock(&dev->struct_mutex);
455 if (file_priv->magic)
456 idr_remove(&file_priv->master->magic_map, file_priv->magic);
457 mutex_unlock(&dev->struct_mutex);
458
459 if (dev->driver->preclose) 380 if (dev->driver->preclose)
460 dev->driver->preclose(dev, file_priv); 381 dev->driver->preclose(dev, file_priv);
461 382
@@ -468,9 +389,8 @@ int drm_release(struct inode *inode, struct file *filp)
468 (long)old_encode_dev(file_priv->minor->kdev->devt), 389 (long)old_encode_dev(file_priv->minor->kdev->devt),
469 dev->open_count); 390 dev->open_count);
470 391
471 /* if the master has gone away we can't do anything with the lock */ 392 if (!drm_core_check_feature(dev, DRIVER_MODESET))
472 if (file_priv->minor->master) 393 drm_legacy_lock_release(dev, filp);
473 drm_master_release(dev, filp);
474 394
475 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) 395 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
476 drm_legacy_reclaim_buffers(dev, file_priv); 396 drm_legacy_reclaim_buffers(dev, file_priv);
@@ -487,43 +407,12 @@ int drm_release(struct inode *inode, struct file *filp)
487 407
488 drm_legacy_ctxbitmap_flush(dev, file_priv); 408 drm_legacy_ctxbitmap_flush(dev, file_priv);
489 409
490 mutex_lock(&dev->master_mutex); 410 if (drm_is_primary_client(file_priv))
491 411 drm_master_release(file_priv);
492 if (file_priv->is_master) {
493 struct drm_master *master = file_priv->master;
494
495 /*
496 * Since the master is disappearing, so is the
497 * possibility to lock.
498 */
499 mutex_lock(&dev->struct_mutex);
500 if (master->lock.hw_lock) {
501 if (dev->sigdata.lock == master->lock.hw_lock)
502 dev->sigdata.lock = NULL;
503 master->lock.hw_lock = NULL;
504 master->lock.file_priv = NULL;
505 wake_up_interruptible_all(&master->lock.lock_queue);
506 }
507 mutex_unlock(&dev->struct_mutex);
508
509 if (file_priv->minor->master == file_priv->master) {
510 /* drop the reference held my the minor */
511 if (dev->driver->master_drop)
512 dev->driver->master_drop(dev, file_priv, true);
513 drm_master_put(&file_priv->minor->master);
514 }
515 }
516
517 /* drop the master reference held by the file priv */
518 if (file_priv->master)
519 drm_master_put(&file_priv->master);
520 file_priv->is_master = 0;
521 mutex_unlock(&dev->master_mutex);
522 412
523 if (dev->driver->postclose) 413 if (dev->driver->postclose)
524 dev->driver->postclose(dev, file_priv); 414 dev->driver->postclose(dev, file_priv);
525 415
526
527 if (drm_core_check_feature(dev, DRIVER_PRIME)) 416 if (drm_core_check_feature(dev, DRIVER_PRIME))
528 drm_prime_destroy_file_private(&file_priv->prime); 417 drm_prime_destroy_file_private(&file_priv->prime);
529 418
diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
index 5d469b2f26f4..9ae353f4dd06 100644
--- a/drivers/gpu/drm/drm_info.c
+++ b/drivers/gpu/drm/drm_info.c
@@ -50,106 +50,24 @@ int drm_name_info(struct seq_file *m, void *data)
50 struct drm_info_node *node = (struct drm_info_node *) m->private; 50 struct drm_info_node *node = (struct drm_info_node *) m->private;
51 struct drm_minor *minor = node->minor; 51 struct drm_minor *minor = node->minor;
52 struct drm_device *dev = minor->dev; 52 struct drm_device *dev = minor->dev;
53 struct drm_master *master = minor->master; 53 struct drm_master *master;
54 if (!master)
55 return 0;
56
57 if (master->unique) {
58 seq_printf(m, "%s %s %s\n",
59 dev->driver->name,
60 dev_name(dev->dev), master->unique);
61 } else {
62 seq_printf(m, "%s %s\n",
63 dev->driver->name, dev_name(dev->dev));
64 }
65 return 0;
66}
67
68/**
69 * Called when "/proc/dri/.../vm" is read.
70 *
71 * Prints information about all mappings in drm_device::maplist.
72 */
73int drm_vm_info(struct seq_file *m, void *data)
74{
75 struct drm_info_node *node = (struct drm_info_node *) m->private;
76 struct drm_device *dev = node->minor->dev;
77 struct drm_local_map *map;
78 struct drm_map_list *r_list;
79
80 /* Hardcoded from _DRM_FRAME_BUFFER,
81 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
82 _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
83 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
84 const char *type;
85 int i;
86
87 mutex_lock(&dev->struct_mutex);
88 seq_printf(m, "slot offset size type flags address mtrr\n\n");
89 i = 0;
90 list_for_each_entry(r_list, &dev->maplist, head) {
91 map = r_list->map;
92 if (!map)
93 continue;
94 if (map->type < 0 || map->type > 5)
95 type = "??";
96 else
97 type = types[map->type];
98
99 seq_printf(m, "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%08lx ",
100 i,
101 (unsigned long long)map->offset,
102 map->size, type, map->flags,
103 (unsigned long) r_list->user_token);
104 if (map->mtrr < 0)
105 seq_printf(m, "none\n");
106 else
107 seq_printf(m, "%4d\n", map->mtrr);
108 i++;
109 }
110 mutex_unlock(&dev->struct_mutex);
111 return 0;
112}
113 54
114/** 55 mutex_lock(&dev->master_mutex);
115 * Called when "/proc/dri/.../bufs" is read. 56 master = dev->master;
116 */ 57 if (!master)
117int drm_bufs_info(struct seq_file *m, void *data) 58 goto out_unlock;
118{ 59
119 struct drm_info_node *node = (struct drm_info_node *) m->private; 60 seq_printf(m, "%s", dev->driver->name);
120 struct drm_device *dev = node->minor->dev; 61 if (dev->dev)
121 struct drm_device_dma *dma; 62 seq_printf(m, " dev=%s", dev_name(dev->dev));
122 int i, seg_pages; 63 if (master && master->unique)
123 64 seq_printf(m, " master=%s", master->unique);
124 mutex_lock(&dev->struct_mutex); 65 if (dev->unique)
125 dma = dev->dma; 66 seq_printf(m, " unique=%s", dev->unique);
126 if (!dma) {
127 mutex_unlock(&dev->struct_mutex);
128 return 0;
129 }
130
131 seq_printf(m, " o size count free segs pages kB\n\n");
132 for (i = 0; i <= DRM_MAX_ORDER; i++) {
133 if (dma->bufs[i].buf_count) {
134 seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order);
135 seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n",
136 i,
137 dma->bufs[i].buf_size,
138 dma->bufs[i].buf_count,
139 0,
140 dma->bufs[i].seg_count,
141 seg_pages,
142 seg_pages * PAGE_SIZE / 1024);
143 }
144 }
145 seq_printf(m, "\n");
146 for (i = 0; i < dma->buf_count; i++) {
147 if (i && !(i % 32))
148 seq_printf(m, "\n");
149 seq_printf(m, " %d", dma->buflist[i]->list);
150 }
151 seq_printf(m, "\n"); 67 seq_printf(m, "\n");
152 mutex_unlock(&dev->struct_mutex); 68out_unlock:
69 mutex_unlock(&dev->master_mutex);
70
153 return 0; 71 return 0;
154} 72}
155 73
@@ -184,7 +102,7 @@ int drm_clients_info(struct seq_file *m, void *data)
184 task ? task->comm : "<unknown>", 102 task ? task->comm : "<unknown>",
185 pid_vnr(priv->pid), 103 pid_vnr(priv->pid),
186 priv->minor->index, 104 priv->minor->index,
187 priv->is_master ? 'y' : 'n', 105 drm_is_current_master(priv) ? 'y' : 'n',
188 priv->authenticated ? 'y' : 'n', 106 priv->authenticated ? 'y' : 'n',
189 from_kuid_munged(seq_user_ns(m), priv->uid), 107 from_kuid_munged(seq_user_ns(m), priv->uid),
190 priv->magic); 108 priv->magic);
@@ -194,7 +112,6 @@ int drm_clients_info(struct seq_file *m, void *data)
194 return 0; 112 return 0;
195} 113}
196 114
197
198static int drm_gem_one_name_info(int id, void *ptr, void *data) 115static int drm_gem_one_name_info(int id, void *ptr, void *data)
199{ 116{
200 struct drm_gem_object *obj = ptr; 117 struct drm_gem_object *obj = ptr;
diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index 902cf6a15212..b86dc9b921a5 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -29,15 +29,9 @@ extern struct mutex drm_global_mutex;
29void drm_lastclose(struct drm_device *dev); 29void drm_lastclose(struct drm_device *dev);
30 30
31/* drm_pci.c */ 31/* drm_pci.c */
32int drm_pci_set_unique(struct drm_device *dev,
33 struct drm_master *master,
34 struct drm_unique *u);
35int drm_irq_by_busid(struct drm_device *dev, void *data, 32int drm_irq_by_busid(struct drm_device *dev, void *data,
36 struct drm_file *file_priv); 33 struct drm_file *file_priv);
37 34
38/* drm_vm.c */
39int drm_vma_info(struct seq_file *m, void *data);
40
41/* drm_prime.c */ 35/* drm_prime.c */
42int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data, 36int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
43 struct drm_file *file_priv); 37 struct drm_file *file_priv);
@@ -51,8 +45,6 @@ void drm_prime_remove_buf_handle_locked(struct drm_prime_file_private *prime_fpr
51 45
52/* drm_info.c */ 46/* drm_info.c */
53int drm_name_info(struct seq_file *m, void *data); 47int drm_name_info(struct seq_file *m, void *data);
54int drm_vm_info(struct seq_file *m, void *data);
55int drm_bufs_info(struct seq_file *m, void *data);
56int drm_clients_info(struct seq_file *m, void* data); 48int drm_clients_info(struct seq_file *m, void* data);
57int drm_gem_name_info(struct seq_file *m, void *data); 49int drm_gem_name_info(struct seq_file *m, void *data);
58 50
@@ -67,6 +59,12 @@ int drm_getmagic(struct drm_device *dev, void *data,
67 struct drm_file *file_priv); 59 struct drm_file *file_priv);
68int drm_authmagic(struct drm_device *dev, void *data, 60int drm_authmagic(struct drm_device *dev, void *data,
69 struct drm_file *file_priv); 61 struct drm_file *file_priv);
62int drm_setmaster_ioctl(struct drm_device *dev, void *data,
63 struct drm_file *file_priv);
64int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
65 struct drm_file *file_priv);
66int drm_master_open(struct drm_file *file_priv);
67void drm_master_release(struct drm_file *file_priv);
70 68
71/* drm_sysfs.c */ 69/* drm_sysfs.c */
72extern struct class *drm_class; 70extern struct class *drm_class;
@@ -92,13 +90,6 @@ int drm_gem_open_ioctl(struct drm_device *dev, void *data,
92void drm_gem_open(struct drm_device *dev, struct drm_file *file_private); 90void drm_gem_open(struct drm_device *dev, struct drm_file *file_private);
93void drm_gem_release(struct drm_device *dev, struct drm_file *file_private); 91void drm_gem_release(struct drm_device *dev, struct drm_file *file_private);
94 92
95/* drm_drv.c */
96int drm_setmaster_ioctl(struct drm_device *dev, void *data,
97 struct drm_file *file_priv);
98int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
99 struct drm_file *file_priv);
100struct drm_master *drm_master_create(struct drm_minor *minor);
101
102/* drm_debugfs.c */ 93/* drm_debugfs.c */
103#if defined(CONFIG_DEBUG_FS) 94#if defined(CONFIG_DEBUG_FS)
104int drm_debugfs_init(struct drm_minor *minor, int minor_id, 95int drm_debugfs_init(struct drm_minor *minor, int minor_id,
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index b7a39771c152..1f84ff5f1bf8 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -30,6 +30,7 @@
30 30
31#include <drm/drmP.h> 31#include <drm/drmP.h>
32#include <drm/drm_core.h> 32#include <drm/drm_core.h>
33#include <drm/drm_auth.h>
33#include "drm_legacy.h" 34#include "drm_legacy.h"
34#include "drm_internal.h" 35#include "drm_internal.h"
35#include "drm_crtc_internal.h" 36#include "drm_crtc_internal.h"
@@ -37,6 +38,64 @@
37#include <linux/pci.h> 38#include <linux/pci.h>
38#include <linux/export.h> 39#include <linux/export.h>
39 40
41/**
42 * DOC: getunique and setversion story
43 *
44 * BEWARE THE DRAGONS! MIND THE TRAPDOORS!
45 *
46 * In an attempt to warn anyone else who's trying to figure out what's going
47 * on here, I'll try to summarize the story. First things first, let's clear up
48 * the names, because the kernel internals, libdrm and the ioctls are all named
49 * differently:
50 *
51 * - GET_UNIQUE ioctl, implemented by drm_getunique is wrapped up in libdrm
52 * through the drmGetBusid function.
53 * - The libdrm drmSetBusid function is backed by the SET_UNIQUE ioctl. All
54 * that code is nerved in the kernel with drm_invalid_op().
55 * - The internal set_busid kernel functions and driver callbacks are
56 * exclusively use by the SET_VERSION ioctl, because only drm 1.0 (which is
57 * nerved) allowed userspace to set the busid through the above ioctl.
58 * - Other ioctls and functions involved are named consistently.
59 *
60 * For anyone wondering what's the difference between drm 1.1 and 1.4: Correctly
61 * handling pci domains in the busid on ppc. Doing this correctly was only
62 * implemented in libdrm in 2010, hence can't be nerved yet. No one knows what's
63 * special with drm 1.2 and 1.3.
64 *
65 * Now the actual horror story of how device lookup in drm works. At large,
66 * there's 2 different ways, either by busid, or by device driver name.
67 *
68 * Opening by busid is fairly simple:
69 *
70 * 1. First call SET_VERSION to make sure pci domains are handled properly. As a
71 * side-effect this fills out the unique name in the master structure.
72 * 2. Call GET_UNIQUE to read out the unique name from the master structure,
73 * which matches the busid thanks to step 1. If it doesn't, proceed to try
74 * the next device node.
75 *
76 * Opening by name is slightly different:
77 *
78 * 1. Directly call VERSION to get the version and to match against the driver
79 * name returned by that ioctl. Note that SET_VERSION is not called, which
80 * means the the unique name for the master node just opening is _not_ filled
81 * out. This despite that with current drm device nodes are always bound to
82 * one device, and can't be runtime assigned like with drm 1.0.
83 * 2. Match driver name. If it mismatches, proceed to the next device node.
84 * 3. Call GET_UNIQUE, and check whether the unique name has length zero (by
85 * checking that the first byte in the string is 0). If that's not the case
86 * libdrm skips and proceeds to the next device node. Probably this is just
87 * copypasta from drm 1.0 times where a set unique name meant that the driver
88 * was in use already, but that's just conjecture.
89 *
90 * Long story short: To keep the open by name logic working, GET_UNIQUE must
91 * _not_ return a unique string when SET_VERSION hasn't been called yet,
92 * otherwise libdrm breaks. Even when that unique string can't ever change, and
93 * is totally irrelevant for actually opening the device because runtime
94 * assignable device instances were only support in drm 1.0, which is long dead.
95 * But the libdrm code in drmOpenByName somehow survived, hence this can't be
96 * broken.
97 */
98
40static int drm_version(struct drm_device *dev, void *data, 99static int drm_version(struct drm_device *dev, void *data,
41 struct drm_file *file_priv); 100 struct drm_file *file_priv);
42 101
@@ -75,51 +134,6 @@ drm_unset_busid(struct drm_device *dev,
75 master->unique_len = 0; 134 master->unique_len = 0;
76} 135}
77 136
78/*
79 * Set the bus id.
80 *
81 * \param inode device inode.
82 * \param file_priv DRM file private.
83 * \param cmd command.
84 * \param arg user argument, pointing to a drm_unique structure.
85 * \return zero on success or a negative number on failure.
86 *
87 * Copies the bus id from userspace into drm_device::unique, and verifies that
88 * it matches the device this DRM is attached to (EINVAL otherwise). Deprecated
89 * in interface version 1.1 and will return EBUSY when setversion has requested
90 * version 1.1 or greater. Also note that KMS is all version 1.1 and later and
91 * UMS was only ever supported on pci devices.
92 */
93static int drm_setunique(struct drm_device *dev, void *data,
94 struct drm_file *file_priv)
95{
96 struct drm_unique *u = data;
97 struct drm_master *master = file_priv->master;
98 int ret;
99
100 if (master->unique_len || master->unique)
101 return -EBUSY;
102
103 if (!u->unique_len || u->unique_len > 1024)
104 return -EINVAL;
105
106 if (drm_core_check_feature(dev, DRIVER_MODESET))
107 return 0;
108
109 if (WARN_ON(!dev->pdev))
110 return -EINVAL;
111
112 ret = drm_pci_set_unique(dev, master, u);
113 if (ret)
114 goto err;
115
116 return 0;
117
118err:
119 drm_unset_busid(dev, master);
120 return ret;
121}
122
123static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv) 137static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)
124{ 138{
125 struct drm_master *master = file_priv->master; 139 struct drm_master *master = file_priv->master;
@@ -135,12 +149,7 @@ static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)
135 return ret; 149 return ret;
136 } 150 }
137 } else { 151 } else {
138 if (WARN(dev->unique == NULL, 152 WARN_ON(!dev->unique);
139 "No drm_driver.set_busid() implementation provided by "
140 "%ps. Use drm_dev_set_unique() to set the unique "
141 "name explicitly.", dev->driver))
142 return -EINVAL;
143
144 master->unique = kstrdup(dev->unique, GFP_KERNEL); 153 master->unique = kstrdup(dev->unique, GFP_KERNEL);
145 if (master->unique) 154 if (master->unique)
146 master->unique_len = strlen(dev->unique); 155 master->unique_len = strlen(dev->unique);
@@ -473,7 +482,8 @@ int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)
473 return -EACCES; 482 return -EACCES;
474 483
475 /* MASTER is only for master or control clients */ 484 /* MASTER is only for master or control clients */
476 if (unlikely((flags & DRM_MASTER) && !file_priv->is_master && 485 if (unlikely((flags & DRM_MASTER) &&
486 !drm_is_current_master(file_priv) &&
477 !drm_is_control_client(file_priv))) 487 !drm_is_control_client(file_priv)))
478 return -EACCES; 488 return -EACCES;
479 489
@@ -504,7 +514,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
504 DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, 514 DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version,
505 DRM_UNLOCKED|DRM_RENDER_ALLOW|DRM_CONTROL_ALLOW), 515 DRM_UNLOCKED|DRM_RENDER_ALLOW|DRM_CONTROL_ALLOW),
506 DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0), 516 DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
507 DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0), 517 DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, DRM_UNLOCKED),
508 DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY), 518 DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
509 DRM_IOCTL_DEF(DRM_IOCTL_GET_MAP, drm_legacy_getmap_ioctl, DRM_UNLOCKED), 519 DRM_IOCTL_DEF(DRM_IOCTL_GET_MAP, drm_legacy_getmap_ioctl, DRM_UNLOCKED),
510 DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT, drm_getclient, DRM_UNLOCKED), 520 DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT, drm_getclient, DRM_UNLOCKED),
@@ -513,10 +523,10 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
513 DRM_IOCTL_DEF(DRM_IOCTL_SET_CLIENT_CAP, drm_setclientcap, 0), 523 DRM_IOCTL_DEF(DRM_IOCTL_SET_CLIENT_CAP, drm_setclientcap, 0),
514 DRM_IOCTL_DEF(DRM_IOCTL_SET_VERSION, drm_setversion, DRM_MASTER), 524 DRM_IOCTL_DEF(DRM_IOCTL_SET_VERSION, drm_setversion, DRM_MASTER),
515 525
516 DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE, drm_setunique, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 526 DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
517 DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 527 DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
518 DRM_IOCTL_DEF(DRM_IOCTL_UNBLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 528 DRM_IOCTL_DEF(DRM_IOCTL_UNBLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
519 DRM_IOCTL_DEF(DRM_IOCTL_AUTH_MAGIC, drm_authmagic, DRM_AUTH|DRM_MASTER), 529 DRM_IOCTL_DEF(DRM_IOCTL_AUTH_MAGIC, drm_authmagic, DRM_AUTH|DRM_UNLOCKED|DRM_MASTER),
520 530
521 DRM_IOCTL_DEF(DRM_IOCTL_ADD_MAP, drm_legacy_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 531 DRM_IOCTL_DEF(DRM_IOCTL_ADD_MAP, drm_legacy_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
522 DRM_IOCTL_DEF(DRM_IOCTL_RM_MAP, drm_legacy_rmmap_ioctl, DRM_AUTH), 532 DRM_IOCTL_DEF(DRM_IOCTL_RM_MAP, drm_legacy_rmmap_ioctl, DRM_AUTH),
@@ -524,8 +534,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
524 DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_legacy_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 534 DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_legacy_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
525 DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_legacy_getsareactx, DRM_AUTH), 535 DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_legacy_getsareactx, DRM_AUTH),
526 536
527 DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, DRM_ROOT_ONLY), 537 DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, DRM_UNLOCKED|DRM_ROOT_ONLY),
528 DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, DRM_ROOT_ONLY), 538 DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, DRM_UNLOCKED|DRM_ROOT_ONLY),
529 539
530 DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_legacy_addctx, DRM_AUTH|DRM_ROOT_ONLY), 540 DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_legacy_addctx, DRM_AUTH|DRM_ROOT_ONLY),
531 DRM_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_legacy_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 541 DRM_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_legacy_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 76e39c50c90c..8ca3d2bf2bda 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -994,10 +994,10 @@ static void send_vblank_event(struct drm_device *dev,
994 e->event.tv_sec = now->tv_sec; 994 e->event.tv_sec = now->tv_sec;
995 e->event.tv_usec = now->tv_usec; 995 e->event.tv_usec = now->tv_usec;
996 996
997 drm_send_event_locked(dev, &e->base);
998
999 trace_drm_vblank_event_delivered(e->base.pid, e->pipe, 997 trace_drm_vblank_event_delivered(e->base.pid, e->pipe,
1000 e->event.sequence); 998 e->event.sequence);
999
1000 drm_send_event_locked(dev, &e->base);
1001} 1001}
1002 1002
1003/** 1003/**
diff --git a/drivers/gpu/drm/drm_legacy.h b/drivers/gpu/drm/drm_legacy.h
index d3b6ee357a2b..c6f422e879dd 100644
--- a/drivers/gpu/drm/drm_legacy.h
+++ b/drivers/gpu/drm/drm_legacy.h
@@ -88,14 +88,10 @@ struct drm_agp_mem {
88 struct list_head head; 88 struct list_head head;
89}; 89};
90 90
91/* 91/* drm_lock.c */
92 * Generic Userspace Locking-API
93 */
94
95int drm_legacy_i_have_hw_lock(struct drm_device *d, struct drm_file *f);
96int drm_legacy_lock(struct drm_device *d, void *v, struct drm_file *f); 92int drm_legacy_lock(struct drm_device *d, void *v, struct drm_file *f);
97int drm_legacy_unlock(struct drm_device *d, void *v, struct drm_file *f); 93int drm_legacy_unlock(struct drm_device *d, void *v, struct drm_file *f);
98int drm_legacy_lock_free(struct drm_lock_data *lock, unsigned int ctx); 94void drm_legacy_lock_release(struct drm_device *dev, struct file *filp);
99 95
100/* DMA support */ 96/* DMA support */
101int drm_legacy_dma_setup(struct drm_device *dev); 97int drm_legacy_dma_setup(struct drm_device *dev);
diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
index daa2ff12101b..48ac0ebbd663 100644
--- a/drivers/gpu/drm/drm_lock.c
+++ b/drivers/gpu/drm/drm_lock.c
@@ -41,6 +41,110 @@
41static int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context); 41static int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
42 42
43/** 43/**
44 * Take the heavyweight lock.
45 *
46 * \param lock lock pointer.
47 * \param context locking context.
48 * \return one if the lock is held, or zero otherwise.
49 *
50 * Attempt to mark the lock as held by the given context, via the \p cmpxchg instruction.
51 */
52static
53int drm_lock_take(struct drm_lock_data *lock_data,
54 unsigned int context)
55{
56 unsigned int old, new, prev;
57 volatile unsigned int *lock = &lock_data->hw_lock->lock;
58
59 spin_lock_bh(&lock_data->spinlock);
60 do {
61 old = *lock;
62 if (old & _DRM_LOCK_HELD)
63 new = old | _DRM_LOCK_CONT;
64 else {
65 new = context | _DRM_LOCK_HELD |
66 ((lock_data->user_waiters + lock_data->kernel_waiters > 1) ?
67 _DRM_LOCK_CONT : 0);
68 }
69 prev = cmpxchg(lock, old, new);
70 } while (prev != old);
71 spin_unlock_bh(&lock_data->spinlock);
72
73 if (_DRM_LOCKING_CONTEXT(old) == context) {
74 if (old & _DRM_LOCK_HELD) {
75 if (context != DRM_KERNEL_CONTEXT) {
76 DRM_ERROR("%d holds heavyweight lock\n",
77 context);
78 }
79 return 0;
80 }
81 }
82
83 if ((_DRM_LOCKING_CONTEXT(new)) == context && (new & _DRM_LOCK_HELD)) {
84 /* Have lock */
85 return 1;
86 }
87 return 0;
88}
89
90/**
91 * This takes a lock forcibly and hands it to context. Should ONLY be used
92 * inside *_unlock to give lock to kernel before calling *_dma_schedule.
93 *
94 * \param dev DRM device.
95 * \param lock lock pointer.
96 * \param context locking context.
97 * \return always one.
98 *
99 * Resets the lock file pointer.
100 * Marks the lock as held by the given context, via the \p cmpxchg instruction.
101 */
102static int drm_lock_transfer(struct drm_lock_data *lock_data,
103 unsigned int context)
104{
105 unsigned int old, new, prev;
106 volatile unsigned int *lock = &lock_data->hw_lock->lock;
107
108 lock_data->file_priv = NULL;
109 do {
110 old = *lock;
111 new = context | _DRM_LOCK_HELD;
112 prev = cmpxchg(lock, old, new);
113 } while (prev != old);
114 return 1;
115}
116
117static int drm_legacy_lock_free(struct drm_lock_data *lock_data,
118 unsigned int context)
119{
120 unsigned int old, new, prev;
121 volatile unsigned int *lock = &lock_data->hw_lock->lock;
122
123 spin_lock_bh(&lock_data->spinlock);
124 if (lock_data->kernel_waiters != 0) {
125 drm_lock_transfer(lock_data, 0);
126 lock_data->idle_has_lock = 1;
127 spin_unlock_bh(&lock_data->spinlock);
128 return 1;
129 }
130 spin_unlock_bh(&lock_data->spinlock);
131
132 do {
133 old = *lock;
134 new = _DRM_LOCKING_CONTEXT(old);
135 prev = cmpxchg(lock, old, new);
136 } while (prev != old);
137
138 if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
139 DRM_ERROR("%d freed heavyweight lock held by %d\n",
140 context, _DRM_LOCKING_CONTEXT(old));
141 return 1;
142 }
143 wake_up_interruptible(&lock_data->lock_queue);
144 return 0;
145}
146
147/**
44 * Lock ioctl. 148 * Lock ioctl.
45 * 149 *
46 * \param inode device inode. 150 * \param inode device inode.
@@ -115,7 +219,7 @@ int drm_legacy_lock(struct drm_device *dev, void *data,
115 /* don't set the block all signals on the master process for now 219 /* don't set the block all signals on the master process for now
116 * really probably not the correct answer but lets us debug xkb 220 * really probably not the correct answer but lets us debug xkb
117 * xserver for now */ 221 * xserver for now */
118 if (!file_priv->is_master) { 222 if (!drm_is_current_master(file_priv)) {
119 dev->sigdata.context = lock->context; 223 dev->sigdata.context = lock->context;
120 dev->sigdata.lock = master->lock.hw_lock; 224 dev->sigdata.lock = master->lock.hw_lock;
121 } 225 }
@@ -165,120 +269,6 @@ int drm_legacy_unlock(struct drm_device *dev, void *data, struct drm_file *file_
165} 269}
166 270
167/** 271/**
168 * Take the heavyweight lock.
169 *
170 * \param lock lock pointer.
171 * \param context locking context.
172 * \return one if the lock is held, or zero otherwise.
173 *
174 * Attempt to mark the lock as held by the given context, via the \p cmpxchg instruction.
175 */
176static
177int drm_lock_take(struct drm_lock_data *lock_data,
178 unsigned int context)
179{
180 unsigned int old, new, prev;
181 volatile unsigned int *lock = &lock_data->hw_lock->lock;
182
183 spin_lock_bh(&lock_data->spinlock);
184 do {
185 old = *lock;
186 if (old & _DRM_LOCK_HELD)
187 new = old | _DRM_LOCK_CONT;
188 else {
189 new = context | _DRM_LOCK_HELD |
190 ((lock_data->user_waiters + lock_data->kernel_waiters > 1) ?
191 _DRM_LOCK_CONT : 0);
192 }
193 prev = cmpxchg(lock, old, new);
194 } while (prev != old);
195 spin_unlock_bh(&lock_data->spinlock);
196
197 if (_DRM_LOCKING_CONTEXT(old) == context) {
198 if (old & _DRM_LOCK_HELD) {
199 if (context != DRM_KERNEL_CONTEXT) {
200 DRM_ERROR("%d holds heavyweight lock\n",
201 context);
202 }
203 return 0;
204 }
205 }
206
207 if ((_DRM_LOCKING_CONTEXT(new)) == context && (new & _DRM_LOCK_HELD)) {
208 /* Have lock */
209 return 1;
210 }
211 return 0;
212}
213
214/**
215 * This takes a lock forcibly and hands it to context. Should ONLY be used
216 * inside *_unlock to give lock to kernel before calling *_dma_schedule.
217 *
218 * \param dev DRM device.
219 * \param lock lock pointer.
220 * \param context locking context.
221 * \return always one.
222 *
223 * Resets the lock file pointer.
224 * Marks the lock as held by the given context, via the \p cmpxchg instruction.
225 */
226static int drm_lock_transfer(struct drm_lock_data *lock_data,
227 unsigned int context)
228{
229 unsigned int old, new, prev;
230 volatile unsigned int *lock = &lock_data->hw_lock->lock;
231
232 lock_data->file_priv = NULL;
233 do {
234 old = *lock;
235 new = context | _DRM_LOCK_HELD;
236 prev = cmpxchg(lock, old, new);
237 } while (prev != old);
238 return 1;
239}
240
241/**
242 * Free lock.
243 *
244 * \param dev DRM device.
245 * \param lock lock.
246 * \param context context.
247 *
248 * Resets the lock file pointer.
249 * Marks the lock as not held, via the \p cmpxchg instruction. Wakes any task
250 * waiting on the lock queue.
251 */
252int drm_legacy_lock_free(struct drm_lock_data *lock_data, unsigned int context)
253{
254 unsigned int old, new, prev;
255 volatile unsigned int *lock = &lock_data->hw_lock->lock;
256
257 spin_lock_bh(&lock_data->spinlock);
258 if (lock_data->kernel_waiters != 0) {
259 drm_lock_transfer(lock_data, 0);
260 lock_data->idle_has_lock = 1;
261 spin_unlock_bh(&lock_data->spinlock);
262 return 1;
263 }
264 spin_unlock_bh(&lock_data->spinlock);
265
266 do {
267 old = *lock;
268 new = _DRM_LOCKING_CONTEXT(old);
269 prev = cmpxchg(lock, old, new);
270 } while (prev != old);
271
272 if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
273 DRM_ERROR("%d freed heavyweight lock held by %d\n",
274 context, _DRM_LOCKING_CONTEXT(old));
275 return 1;
276 }
277 wake_up_interruptible(&lock_data->lock_queue);
278 return 0;
279}
280
281/**
282 * This function returns immediately and takes the hw lock 272 * This function returns immediately and takes the hw lock
283 * with the kernel context if it is free, otherwise it gets the highest priority when and if 273 * with the kernel context if it is free, otherwise it gets the highest priority when and if
284 * it is eventually released. 274 * it is eventually released.
@@ -330,11 +320,27 @@ void drm_legacy_idlelock_release(struct drm_lock_data *lock_data)
330} 320}
331EXPORT_SYMBOL(drm_legacy_idlelock_release); 321EXPORT_SYMBOL(drm_legacy_idlelock_release);
332 322
333int drm_legacy_i_have_hw_lock(struct drm_device *dev, 323static int drm_legacy_i_have_hw_lock(struct drm_device *dev,
334 struct drm_file *file_priv) 324 struct drm_file *file_priv)
335{ 325{
336 struct drm_master *master = file_priv->master; 326 struct drm_master *master = file_priv->master;
337 return (file_priv->lock_count && master->lock.hw_lock && 327 return (file_priv->lock_count && master->lock.hw_lock &&
338 _DRM_LOCK_IS_HELD(master->lock.hw_lock->lock) && 328 _DRM_LOCK_IS_HELD(master->lock.hw_lock->lock) &&
339 master->lock.file_priv == file_priv); 329 master->lock.file_priv == file_priv);
340} 330}
331
332void drm_legacy_lock_release(struct drm_device *dev, struct file *filp)
333{
334 struct drm_file *file_priv = filp->private_data;
335
336 /* if the master has gone away we can't do anything with the lock */
337 if (!dev->master)
338 return;
339
340 if (drm_legacy_i_have_hw_lock(dev, file_priv)) {
341 DRM_DEBUG("File %p released, freeing lock for context %d\n",
342 filp, _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
343 drm_legacy_lock_free(&file_priv->master->lock,
344 _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
345 }
346}
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index 29d5a548d07a..b2f8f1062d5f 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -144,50 +144,6 @@ int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master)
144} 144}
145EXPORT_SYMBOL(drm_pci_set_busid); 145EXPORT_SYMBOL(drm_pci_set_busid);
146 146
147int drm_pci_set_unique(struct drm_device *dev,
148 struct drm_master *master,
149 struct drm_unique *u)
150{
151 int domain, bus, slot, func, ret;
152
153 master->unique_len = u->unique_len;
154 master->unique = kmalloc(master->unique_len + 1, GFP_KERNEL);
155 if (!master->unique) {
156 ret = -ENOMEM;
157 goto err;
158 }
159
160 if (copy_from_user(master->unique, u->unique, master->unique_len)) {
161 ret = -EFAULT;
162 goto err;
163 }
164
165 master->unique[master->unique_len] = '\0';
166
167 /* Return error if the busid submitted doesn't match the device's actual
168 * busid.
169 */
170 ret = sscanf(master->unique, "PCI:%d:%d:%d", &bus, &slot, &func);
171 if (ret != 3) {
172 ret = -EINVAL;
173 goto err;
174 }
175
176 domain = bus >> 8;
177 bus &= 0xff;
178
179 if ((domain != drm_get_pci_domain(dev)) ||
180 (bus != dev->pdev->bus->number) ||
181 (slot != PCI_SLOT(dev->pdev->devfn)) ||
182 (func != PCI_FUNC(dev->pdev->devfn))) {
183 ret = -EINVAL;
184 goto err;
185 }
186 return 0;
187err:
188 return ret;
189}
190
191static int drm_pci_irq_by_busid(struct drm_device *dev, struct drm_irq_busid *p) 147static int drm_pci_irq_by_busid(struct drm_device *dev, struct drm_irq_busid *p)
192{ 148{
193 if ((p->busnum >> 8) != drm_get_pci_domain(dev) || 149 if ((p->busnum >> 8) != drm_get_pci_domain(dev) ||
@@ -444,13 +400,6 @@ int drm_irq_by_busid(struct drm_device *dev, void *data,
444{ 400{
445 return -EINVAL; 401 return -EINVAL;
446} 402}
447
448int drm_pci_set_unique(struct drm_device *dev,
449 struct drm_master *master,
450 struct drm_unique *u)
451{
452 return -EINVAL;
453}
454#endif 403#endif
455 404
456EXPORT_SYMBOL(drm_pci_init); 405EXPORT_SYMBOL(drm_pci_init);
diff --git a/drivers/gpu/drm/drm_plane_helper.c b/drivers/gpu/drm/drm_plane_helper.c
index fc51306fe365..16c4a7bd7465 100644
--- a/drivers/gpu/drm/drm_plane_helper.c
+++ b/drivers/gpu/drm/drm_plane_helper.c
@@ -115,6 +115,7 @@ static int get_connectors_for_crtc(struct drm_crtc *crtc,
115 * @src: source coordinates in 16.16 fixed point 115 * @src: source coordinates in 16.16 fixed point
116 * @dest: integer destination coordinates 116 * @dest: integer destination coordinates
117 * @clip: integer clipping coordinates 117 * @clip: integer clipping coordinates
118 * @rotation: plane rotation
118 * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point 119 * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point
119 * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point 120 * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point
120 * @can_position: is it legal to position the plane such that it 121 * @can_position: is it legal to position the plane such that it
@@ -134,16 +135,17 @@ static int get_connectors_for_crtc(struct drm_crtc *crtc,
134 * Zero if update appears valid, error code on failure 135 * Zero if update appears valid, error code on failure
135 */ 136 */
136int drm_plane_helper_check_update(struct drm_plane *plane, 137int drm_plane_helper_check_update(struct drm_plane *plane,
137 struct drm_crtc *crtc, 138 struct drm_crtc *crtc,
138 struct drm_framebuffer *fb, 139 struct drm_framebuffer *fb,
139 struct drm_rect *src, 140 struct drm_rect *src,
140 struct drm_rect *dest, 141 struct drm_rect *dest,
141 const struct drm_rect *clip, 142 const struct drm_rect *clip,
142 int min_scale, 143 unsigned int rotation,
143 int max_scale, 144 int min_scale,
144 bool can_position, 145 int max_scale,
145 bool can_update_disabled, 146 bool can_position,
146 bool *visible) 147 bool can_update_disabled,
148 bool *visible)
147{ 149{
148 int hscale, vscale; 150 int hscale, vscale;
149 151
@@ -163,6 +165,8 @@ int drm_plane_helper_check_update(struct drm_plane *plane,
163 return -EINVAL; 165 return -EINVAL;
164 } 166 }
165 167
168 drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation);
169
166 /* Check scaling */ 170 /* Check scaling */
167 hscale = drm_rect_calc_hscale(src, dest, min_scale, max_scale); 171 hscale = drm_rect_calc_hscale(src, dest, min_scale, max_scale);
168 vscale = drm_rect_calc_vscale(src, dest, min_scale, max_scale); 172 vscale = drm_rect_calc_vscale(src, dest, min_scale, max_scale);
@@ -174,6 +178,9 @@ int drm_plane_helper_check_update(struct drm_plane *plane,
174 } 178 }
175 179
176 *visible = drm_rect_clip_scaled(src, dest, clip, hscale, vscale); 180 *visible = drm_rect_clip_scaled(src, dest, clip, hscale, vscale);
181
182 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation);
183
177 if (!*visible) 184 if (!*visible)
178 /* 185 /*
179 * Plane isn't visible; some drivers can handle this 186 * Plane isn't visible; some drivers can handle this
@@ -267,6 +274,7 @@ int drm_primary_helper_update(struct drm_plane *plane, struct drm_crtc *crtc,
267 274
268 ret = drm_plane_helper_check_update(plane, crtc, fb, 275 ret = drm_plane_helper_check_update(plane, crtc, fb,
269 &src, &dest, &clip, 276 &src, &dest, &clip,
277 BIT(DRM_ROTATE_0),
270 DRM_PLANE_HELPER_NO_SCALING, 278 DRM_PLANE_HELPER_NO_SCALING,
271 DRM_PLANE_HELPER_NO_SCALING, 279 DRM_PLANE_HELPER_NO_SCALING,
272 false, false, &visible); 280 false, false, &visible);
diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_platform.c
index 644169e1a029..2c819ef90090 100644
--- a/drivers/gpu/drm/drm_platform.c
+++ b/drivers/gpu/drm/drm_platform.c
@@ -68,24 +68,6 @@ err_free:
68 return ret; 68 return ret;
69} 69}
70 70
71int drm_platform_set_busid(struct drm_device *dev, struct drm_master *master)
72{
73 int id;
74
75 id = dev->platformdev->id;
76 if (id < 0)
77 id = 0;
78
79 master->unique = kasprintf(GFP_KERNEL, "platform:%s:%02d",
80 dev->platformdev->name, id);
81 if (!master->unique)
82 return -ENOMEM;
83
84 master->unique_len = strlen(master->unique);
85 return 0;
86}
87EXPORT_SYMBOL(drm_platform_set_busid);
88
89/** 71/**
90 * drm_platform_init - Register a platform device with the DRM subsystem 72 * drm_platform_init - Register a platform device with the DRM subsystem
91 * @driver: DRM device driver 73 * @driver: DRM device driver
diff --git a/drivers/gpu/drm/drm_simple_kms_helper.c b/drivers/gpu/drm/drm_simple_kms_helper.c
index b2071d495ada..0db36d27e90b 100644
--- a/drivers/gpu/drm/drm_simple_kms_helper.c
+++ b/drivers/gpu/drm/drm_simple_kms_helper.c
@@ -105,6 +105,7 @@ static int drm_simple_kms_plane_atomic_check(struct drm_plane *plane,
105 ret = drm_plane_helper_check_update(plane, &pipe->crtc, 105 ret = drm_plane_helper_check_update(plane, &pipe->crtc,
106 plane_state->fb, 106 plane_state->fb,
107 &src, &dest, &clip, 107 &src, &dest, &clip,
108 plane_state->rotation,
108 DRM_PLANE_HELPER_NO_SCALING, 109 DRM_PLANE_HELPER_NO_SCALING,
109 DRM_PLANE_HELPER_NO_SCALING, 110 DRM_PLANE_HELPER_NO_SCALING,
110 false, true, &visible); 111 false, true, &visible);
diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c
index ac9f4b3ec615..43ff44a2b8e7 100644
--- a/drivers/gpu/drm/drm_vm.c
+++ b/drivers/gpu/drm/drm_vm.c
@@ -670,57 +670,3 @@ void drm_legacy_vma_flush(struct drm_device *dev)
670 kfree(vma); 670 kfree(vma);
671 } 671 }
672} 672}
673
674int drm_vma_info(struct seq_file *m, void *data)
675{
676 struct drm_info_node *node = (struct drm_info_node *) m->private;
677 struct drm_device *dev = node->minor->dev;
678 struct drm_vma_entry *pt;
679 struct vm_area_struct *vma;
680 unsigned long vma_count = 0;
681#if defined(__i386__)
682 unsigned int pgprot;
683#endif
684
685 mutex_lock(&dev->struct_mutex);
686 list_for_each_entry(pt, &dev->vmalist, head)
687 vma_count++;
688
689 seq_printf(m, "vma use count: %lu, high_memory = %pK, 0x%pK\n",
690 vma_count, high_memory,
691 (void *)(unsigned long)virt_to_phys(high_memory));
692
693 list_for_each_entry(pt, &dev->vmalist, head) {
694 vma = pt->vma;
695 if (!vma)
696 continue;
697 seq_printf(m,
698 "\n%5d 0x%pK-0x%pK %c%c%c%c%c%c 0x%08lx000",
699 pt->pid,
700 (void *)vma->vm_start, (void *)vma->vm_end,
701 vma->vm_flags & VM_READ ? 'r' : '-',
702 vma->vm_flags & VM_WRITE ? 'w' : '-',
703 vma->vm_flags & VM_EXEC ? 'x' : '-',
704 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
705 vma->vm_flags & VM_LOCKED ? 'l' : '-',
706 vma->vm_flags & VM_IO ? 'i' : '-',
707 vma->vm_pgoff);
708
709#if defined(__i386__)
710 pgprot = pgprot_val(vma->vm_page_prot);
711 seq_printf(m, " %c%c%c%c%c%c%c%c%c",
712 pgprot & _PAGE_PRESENT ? 'p' : '-',
713 pgprot & _PAGE_RW ? 'w' : 'r',
714 pgprot & _PAGE_USER ? 'u' : 's',
715 pgprot & _PAGE_PWT ? 't' : 'b',
716 pgprot & _PAGE_PCD ? 'u' : 'c',
717 pgprot & _PAGE_ACCESSED ? 'a' : '-',
718 pgprot & _PAGE_DIRTY ? 'd' : '-',
719 pgprot & _PAGE_PSE ? 'm' : 'k',
720 pgprot & _PAGE_GLOBAL ? 'g' : 'l');
721#endif
722 seq_printf(m, "\n");
723 }
724 mutex_unlock(&dev->struct_mutex);
725 return 0;
726}
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
index 3d4f56df8359..340d390306d8 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
@@ -496,7 +496,6 @@ static struct drm_driver etnaviv_drm_driver = {
496 DRIVER_RENDER, 496 DRIVER_RENDER,
497 .open = etnaviv_open, 497 .open = etnaviv_open,
498 .preclose = etnaviv_preclose, 498 .preclose = etnaviv_preclose,
499 .set_busid = drm_platform_set_busid,
500 .gem_free_object_unlocked = etnaviv_gem_free_object, 499 .gem_free_object_unlocked = etnaviv_gem_free_object,
501 .gem_vm_ops = &vm_ops, 500 .gem_vm_ops = &vm_ops,
502 .prime_handle_to_fd = drm_gem_prime_handle_to_fd, 501 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index 4a679fb9bb02..13d28d4229e2 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -407,7 +407,6 @@ static struct drm_driver exynos_drm_driver = {
407 .preclose = exynos_drm_preclose, 407 .preclose = exynos_drm_preclose,
408 .lastclose = exynos_drm_lastclose, 408 .lastclose = exynos_drm_lastclose,
409 .postclose = exynos_drm_postclose, 409 .postclose = exynos_drm_postclose,
410 .set_busid = drm_platform_set_busid,
411 .get_vblank_counter = drm_vblank_no_hw_counter, 410 .get_vblank_counter = drm_vblank_no_hw_counter,
412 .enable_vblank = exynos_drm_crtc_enable_vblank, 411 .enable_vblank = exynos_drm_crtc_enable_vblank,
413 .disable_vblank = exynos_drm_crtc_disable_vblank, 412 .disable_vblank = exynos_drm_crtc_disable_vblank,
diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c
index c564ec612b59..a6e4cd591960 100644
--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c
+++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_kms.c
@@ -37,23 +37,22 @@ int fsl_dcu_drm_modeset_init(struct fsl_dcu_drm_device *fsl_dev)
37 37
38 ret = fsl_dcu_drm_crtc_create(fsl_dev); 38 ret = fsl_dcu_drm_crtc_create(fsl_dev);
39 if (ret) 39 if (ret)
40 return ret; 40 goto err;
41 41
42 ret = fsl_dcu_drm_encoder_create(fsl_dev, &fsl_dev->crtc); 42 ret = fsl_dcu_drm_encoder_create(fsl_dev, &fsl_dev->crtc);
43 if (ret) 43 if (ret)
44 goto fail_encoder; 44 goto err;
45 45
46 ret = fsl_dcu_drm_connector_create(fsl_dev, &fsl_dev->encoder); 46 ret = fsl_dcu_drm_connector_create(fsl_dev, &fsl_dev->encoder);
47 if (ret) 47 if (ret)
48 goto fail_connector; 48 goto err;
49 49
50 drm_mode_config_reset(fsl_dev->drm); 50 drm_mode_config_reset(fsl_dev->drm);
51 drm_kms_helper_poll_init(fsl_dev->drm); 51 drm_kms_helper_poll_init(fsl_dev->drm);
52 52
53 return 0; 53 return 0;
54fail_encoder: 54
55 fsl_dev->crtc.funcs->destroy(&fsl_dev->crtc); 55err:
56fail_connector: 56 drm_mode_config_cleanup(fsl_dev->drm);
57 fsl_dev->encoder.funcs->destroy(&fsl_dev->encoder);
58 return ret; 57 return ret;
59} 58}
diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
index 193657259ee9..1edd9bc80294 100644
--- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
@@ -171,7 +171,6 @@ static struct drm_driver kirin_drm_driver = {
171 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | 171 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
172 DRIVER_ATOMIC | DRIVER_HAVE_IRQ, 172 DRIVER_ATOMIC | DRIVER_HAVE_IRQ,
173 .fops = &kirin_drm_fops, 173 .fops = &kirin_drm_fops,
174 .set_busid = drm_platform_set_busid,
175 174
176 .gem_free_object_unlocked = drm_gem_cma_free_object, 175 .gem_free_object_unlocked = drm_gem_cma_free_object,
177 .gem_vm_ops = &drm_gem_cma_vm_ops, 176 .gem_vm_ops = &drm_gem_cma_vm_ops,
@@ -221,19 +220,12 @@ static int kirin_drm_bind(struct device *dev)
221 if (ret) 220 if (ret)
222 goto err_kms_cleanup; 221 goto err_kms_cleanup;
223 222
224 /* connectors should be registered after drm device register */
225 ret = drm_connector_register_all(drm_dev);
226 if (ret)
227 goto err_drm_dev_unregister;
228
229 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", 223 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
230 driver->name, driver->major, driver->minor, driver->patchlevel, 224 driver->name, driver->major, driver->minor, driver->patchlevel,
231 driver->date, drm_dev->primary->index); 225 driver->date, drm_dev->primary->index);
232 226
233 return 0; 227 return 0;
234 228
235err_drm_dev_unregister:
236 drm_dev_unregister(drm_dev);
237err_kms_cleanup: 229err_kms_cleanup:
238 kirin_drm_kms_cleanup(drm_dev); 230 kirin_drm_kms_cleanup(drm_dev);
239err_drm_dev_unref: 231err_drm_dev_unref:
@@ -246,7 +238,6 @@ static void kirin_drm_unbind(struct device *dev)
246{ 238{
247 struct drm_device *drm_dev = dev_get_drvdata(dev); 239 struct drm_device *drm_dev = dev_get_drvdata(dev);
248 240
249 drm_connector_unregister_all(drm_dev);
250 drm_dev_unregister(drm_dev); 241 drm_dev_unregister(drm_dev);
251 kirin_drm_kms_cleanup(drm_dev); 242 kirin_drm_kms_cleanup(drm_dev);
252 drm_dev_unref(drm_dev); 243 drm_dev_unref(drm_dev);
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 0113207967d9..ee338655f782 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -47,6 +47,7 @@
47#include <drm/intel-gtt.h> 47#include <drm/intel-gtt.h>
48#include <drm/drm_legacy.h> /* for struct drm_dma_handle */ 48#include <drm/drm_legacy.h> /* for struct drm_dma_handle */
49#include <drm/drm_gem.h> 49#include <drm/drm_gem.h>
50#include <drm/drm_auth.h>
50 51
51#include "i915_params.h" 52#include "i915_params.h"
52#include "i915_reg.h" 53#include "i915_reg.h"
@@ -3673,7 +3674,7 @@ extern void intel_modeset_init_hw(struct drm_device *dev);
3673extern void intel_modeset_init(struct drm_device *dev); 3674extern void intel_modeset_init(struct drm_device *dev);
3674extern void intel_modeset_gem_init(struct drm_device *dev); 3675extern void intel_modeset_gem_init(struct drm_device *dev);
3675extern void intel_modeset_cleanup(struct drm_device *dev); 3676extern void intel_modeset_cleanup(struct drm_device *dev);
3676extern void intel_connector_unregister(struct intel_connector *); 3677extern void intel_connector_unregister(struct drm_connector *);
3677extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state); 3678extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state);
3678extern void intel_display_resume(struct drm_device *dev); 3679extern void intel_display_resume(struct drm_device *dev);
3679extern void i915_redisable_vga(struct drm_device *dev); 3680extern void i915_redisable_vga(struct drm_device *dev);
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 8097698b9622..7941f1fe9cd2 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -1446,7 +1446,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
1446 1446
1447 dispatch_flags = 0; 1447 dispatch_flags = 0;
1448 if (args->flags & I915_EXEC_SECURE) { 1448 if (args->flags & I915_EXEC_SECURE) {
1449 if (!file->is_master || !capable(CAP_SYS_ADMIN)) 1449 if (!drm_is_current_master(file) || !capable(CAP_SYS_ADMIN))
1450 return -EPERM; 1450 return -EPERM;
1451 1451
1452 dispatch_flags |= I915_DISPATCH_SECURE; 1452 dispatch_flags |= I915_DISPATCH_SECURE;
@@ -1553,7 +1553,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data,
1553 batch_obj, 1553 batch_obj,
1554 args->batch_start_offset, 1554 args->batch_start_offset,
1555 args->batch_len, 1555 args->batch_len,
1556 file->is_master); 1556 drm_is_current_master(file));
1557 if (IS_ERR(parsed_batch_obj)) { 1557 if (IS_ERR(parsed_batch_obj)) {
1558 ret = PTR_ERR(parsed_batch_obj); 1558 ret = PTR_ERR(parsed_batch_obj);
1559 goto err; 1559 goto err;
diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
index 9465de4135aa..e115bcc6766f 100644
--- a/drivers/gpu/drm/i915/intel_crt.c
+++ b/drivers/gpu/drm/i915/intel_crt.c
@@ -743,6 +743,7 @@ static const struct drm_connector_funcs intel_crt_connector_funcs = {
743 .dpms = drm_atomic_helper_connector_dpms, 743 .dpms = drm_atomic_helper_connector_dpms,
744 .detect = intel_crt_detect, 744 .detect = intel_crt_detect,
745 .fill_modes = drm_helper_probe_single_connector_modes, 745 .fill_modes = drm_helper_probe_single_connector_modes,
746 .early_unregister = intel_connector_unregister,
746 .destroy = intel_crt_destroy, 747 .destroy = intel_crt_destroy,
747 .set_property = intel_crt_set_property, 748 .set_property = intel_crt_set_property,
748 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 749 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
@@ -875,7 +876,6 @@ void intel_crt_init(struct drm_device *dev)
875 crt->base.get_hw_state = intel_crt_get_hw_state; 876 crt->base.get_hw_state = intel_crt_get_hw_state;
876 } 877 }
877 intel_connector->get_hw_state = intel_connector_get_hw_state; 878 intel_connector->get_hw_state = intel_connector_get_hw_state;
878 intel_connector->unregister = intel_connector_unregister;
879 879
880 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs); 880 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
881 881
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 49322f6cfa2b..b12085a8bfa6 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -14102,6 +14102,7 @@ intel_check_primary_plane(struct drm_plane *plane,
14102 14102
14103 return drm_plane_helper_check_update(plane, crtc, fb, &state->src, 14103 return drm_plane_helper_check_update(plane, crtc, fb, &state->src,
14104 &state->dst, &state->clip, 14104 &state->dst, &state->clip,
14105 state->base.rotation,
14105 min_scale, max_scale, 14106 min_scale, max_scale,
14106 can_position, true, 14107 can_position, true,
14107 &state->visible); 14108 &state->visible);
@@ -14293,6 +14294,7 @@ intel_check_cursor_plane(struct drm_plane *plane,
14293 14294
14294 ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, 14295 ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src,
14295 &state->dst, &state->clip, 14296 &state->dst, &state->clip,
14297 state->base.rotation,
14296 DRM_PLANE_HELPER_NO_SCALING, 14298 DRM_PLANE_HELPER_NO_SCALING,
14297 DRM_PLANE_HELPER_NO_SCALING, 14299 DRM_PLANE_HELPER_NO_SCALING,
14298 true, true, &state->visible); 14300 true, true, &state->visible);
@@ -16217,23 +16219,20 @@ void intel_modeset_gem_init(struct drm_device *dev)
16217 intel_backlight_register(dev); 16219 intel_backlight_register(dev);
16218} 16220}
16219 16221
16220void intel_connector_unregister(struct intel_connector *intel_connector) 16222void intel_connector_unregister(struct drm_connector *connector)
16221{ 16223{
16222 struct drm_connector *connector = &intel_connector->base; 16224 struct intel_connector *intel_connector = to_intel_connector(connector);
16223 16225
16226 intel_backlight_device_unregister(intel_connector);
16224 intel_panel_destroy_backlight(connector); 16227 intel_panel_destroy_backlight(connector);
16225 drm_connector_unregister(connector);
16226} 16228}
16227 16229
16228void intel_modeset_cleanup(struct drm_device *dev) 16230void intel_modeset_cleanup(struct drm_device *dev)
16229{ 16231{
16230 struct drm_i915_private *dev_priv = dev->dev_private; 16232 struct drm_i915_private *dev_priv = dev->dev_private;
16231 struct intel_connector *connector;
16232 16233
16233 intel_disable_gt_powersave(dev_priv); 16234 intel_disable_gt_powersave(dev_priv);
16234 16235
16235 intel_backlight_unregister(dev);
16236
16237 /* 16236 /*
16238 * Interrupts and polling as the first thing to avoid creating havoc. 16237 * Interrupts and polling as the first thing to avoid creating havoc.
16239 * Too much stuff here (turning of connectors, ...) would 16238 * Too much stuff here (turning of connectors, ...) would
@@ -16254,9 +16253,7 @@ void intel_modeset_cleanup(struct drm_device *dev)
16254 /* flush any delayed tasks or pending work */ 16253 /* flush any delayed tasks or pending work */
16255 flush_scheduled_work(); 16254 flush_scheduled_work();
16256 16255
16257 /* destroy the backlight and sysfs files before encoders/connectors */ 16256 drm_connector_unregister_all(dev);
16258 for_each_intel_connector(dev, connector)
16259 connector->unregister(connector);
16260 16257
16261 drm_mode_config_cleanup(dev); 16258 drm_mode_config_cleanup(dev);
16262 16259
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index be083519dac9..0b84f8e5df50 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1177,7 +1177,6 @@ static void intel_aux_reg_init(struct intel_dp *intel_dp)
1177static void 1177static void
1178intel_dp_aux_fini(struct intel_dp *intel_dp) 1178intel_dp_aux_fini(struct intel_dp *intel_dp)
1179{ 1179{
1180 drm_dp_aux_unregister(&intel_dp->aux);
1181 kfree(intel_dp->aux.name); 1180 kfree(intel_dp->aux.name);
1182} 1181}
1183 1182
@@ -1212,15 +1211,6 @@ intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
1212 return 0; 1211 return 0;
1213} 1212}
1214 1213
1215static void
1216intel_dp_connector_unregister(struct intel_connector *intel_connector)
1217{
1218 struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base);
1219
1220 intel_dp_aux_fini(intel_dp);
1221 intel_connector_unregister(intel_connector);
1222}
1223
1224static int 1214static int
1225intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates) 1215intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
1226{ 1216{
@@ -4457,6 +4447,13 @@ done:
4457} 4447}
4458 4448
4459static void 4449static void
4450intel_dp_connector_unregister(struct drm_connector *connector)
4451{
4452 drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
4453 intel_connector_unregister(connector);
4454}
4455
4456static void
4460intel_dp_connector_destroy(struct drm_connector *connector) 4457intel_dp_connector_destroy(struct drm_connector *connector)
4461{ 4458{
4462 struct intel_connector *intel_connector = to_intel_connector(connector); 4459 struct intel_connector *intel_connector = to_intel_connector(connector);
@@ -4496,6 +4493,9 @@ void intel_dp_encoder_destroy(struct drm_encoder *encoder)
4496 intel_dp->edp_notifier.notifier_call = NULL; 4493 intel_dp->edp_notifier.notifier_call = NULL;
4497 } 4494 }
4498 } 4495 }
4496
4497 intel_dp_aux_fini(intel_dp);
4498
4499 drm_encoder_cleanup(encoder); 4499 drm_encoder_cleanup(encoder);
4500 kfree(intel_dig_port); 4500 kfree(intel_dig_port);
4501} 4501}
@@ -4572,6 +4572,7 @@ static const struct drm_connector_funcs intel_dp_connector_funcs = {
4572 .fill_modes = drm_helper_probe_single_connector_modes, 4572 .fill_modes = drm_helper_probe_single_connector_modes,
4573 .set_property = intel_dp_set_property, 4573 .set_property = intel_dp_set_property,
4574 .atomic_get_property = intel_connector_atomic_get_property, 4574 .atomic_get_property = intel_connector_atomic_get_property,
4575 .early_unregister = intel_dp_connector_unregister,
4575 .destroy = intel_dp_connector_destroy, 4576 .destroy = intel_dp_connector_destroy,
4576 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 4577 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
4577 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 4578 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
@@ -5487,7 +5488,6 @@ intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
5487 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; 5488 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
5488 else 5489 else
5489 intel_connector->get_hw_state = intel_connector_get_hw_state; 5490 intel_connector->get_hw_state = intel_connector_get_hw_state;
5490 intel_connector->unregister = intel_dp_connector_unregister;
5491 5491
5492 /* Set up the hotplug pin. */ 5492 /* Set up the hotplug pin. */
5493 switch (port) { 5493 switch (port) {
diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c
index f62ca9a126b3..9646816604be 100644
--- a/drivers/gpu/drm/i915/intel_dp_mst.c
+++ b/drivers/gpu/drm/i915/intel_dp_mst.c
@@ -336,6 +336,7 @@ static const struct drm_connector_funcs intel_dp_mst_connector_funcs = {
336 .fill_modes = drm_helper_probe_single_connector_modes, 336 .fill_modes = drm_helper_probe_single_connector_modes,
337 .set_property = intel_dp_mst_set_property, 337 .set_property = intel_dp_mst_set_property,
338 .atomic_get_property = intel_connector_atomic_get_property, 338 .atomic_get_property = intel_connector_atomic_get_property,
339 .early_unregister = intel_connector_unregister,
339 .destroy = intel_dp_mst_connector_destroy, 340 .destroy = intel_dp_mst_connector_destroy,
340 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 341 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
341 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 342 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
@@ -455,7 +456,6 @@ static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topolo
455 drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort); 456 drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, DRM_MODE_CONNECTOR_DisplayPort);
456 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs); 457 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs);
457 458
458 intel_connector->unregister = intel_connector_unregister;
459 intel_connector->get_hw_state = intel_dp_mst_get_hw_state; 459 intel_connector->get_hw_state = intel_dp_mst_get_hw_state;
460 intel_connector->mst_port = intel_dp; 460 intel_connector->mst_port = intel_dp;
461 intel_connector->port = port; 461 intel_connector->port = port;
@@ -489,7 +489,7 @@ static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
489 struct intel_connector *intel_connector = to_intel_connector(connector); 489 struct intel_connector *intel_connector = to_intel_connector(connector);
490 struct drm_device *dev = connector->dev; 490 struct drm_device *dev = connector->dev;
491 491
492 intel_connector->unregister(intel_connector); 492 drm_connector_unregister(connector);
493 493
494 /* need to nuke the connector */ 494 /* need to nuke the connector */
495 drm_modeset_lock_all(dev); 495 drm_modeset_lock_all(dev);
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 270da8de0acf..65e60ff3b553 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -242,14 +242,6 @@ struct intel_connector {
242 * and active (i.e. dpms ON state). */ 242 * and active (i.e. dpms ON state). */
243 bool (*get_hw_state)(struct intel_connector *); 243 bool (*get_hw_state)(struct intel_connector *);
244 244
245 /*
246 * Removes all interfaces through which the connector is accessible
247 * - like sysfs, debugfs entries -, so that no new operations can be
248 * started on the connector. Also makes sure all currently pending
249 * operations finish before returing.
250 */
251 void (*unregister)(struct intel_connector *);
252
253 /* Panel info for eDP and LVDS */ 245 /* Panel info for eDP and LVDS */
254 struct intel_panel panel; 246 struct intel_panel panel;
255 247
@@ -1496,7 +1488,14 @@ extern struct drm_display_mode *intel_find_panel_downclock(
1496 struct drm_display_mode *fixed_mode, 1488 struct drm_display_mode *fixed_mode,
1497 struct drm_connector *connector); 1489 struct drm_connector *connector);
1498void intel_backlight_register(struct drm_device *dev); 1490void intel_backlight_register(struct drm_device *dev);
1499void intel_backlight_unregister(struct drm_device *dev); 1491
1492#if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
1493void intel_backlight_device_unregister(struct intel_connector *connector);
1494#else /* CONFIG_BACKLIGHT_CLASS_DEVICE */
1495static inline void intel_backlight_device_unregister(struct intel_connector *connector)
1496{
1497}
1498#endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */
1500 1499
1501 1500
1502/* intel_psr.c */ 1501/* intel_psr.c */
diff --git a/drivers/gpu/drm/i915/intel_dsi.c b/drivers/gpu/drm/i915/intel_dsi.c
index a2ead5eac336..e9eda691e8be 100644
--- a/drivers/gpu/drm/i915/intel_dsi.c
+++ b/drivers/gpu/drm/i915/intel_dsi.c
@@ -1384,6 +1384,7 @@ static const struct drm_connector_helper_funcs intel_dsi_connector_helper_funcs
1384static const struct drm_connector_funcs intel_dsi_connector_funcs = { 1384static const struct drm_connector_funcs intel_dsi_connector_funcs = {
1385 .dpms = drm_atomic_helper_connector_dpms, 1385 .dpms = drm_atomic_helper_connector_dpms,
1386 .detect = intel_dsi_detect, 1386 .detect = intel_dsi_detect,
1387 .early_unregister = intel_connector_unregister,
1387 .destroy = intel_dsi_connector_destroy, 1388 .destroy = intel_dsi_connector_destroy,
1388 .fill_modes = drm_helper_probe_single_connector_modes, 1389 .fill_modes = drm_helper_probe_single_connector_modes,
1389 .set_property = intel_dsi_set_property, 1390 .set_property = intel_dsi_set_property,
@@ -1460,7 +1461,6 @@ void intel_dsi_init(struct drm_device *dev)
1460 intel_encoder->get_config = intel_dsi_get_config; 1461 intel_encoder->get_config = intel_dsi_get_config;
1461 1462
1462 intel_connector->get_hw_state = intel_connector_get_hw_state; 1463 intel_connector->get_hw_state = intel_connector_get_hw_state;
1463 intel_connector->unregister = intel_connector_unregister;
1464 1464
1465 /* 1465 /*
1466 * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI 1466 * On BYT/CHV, pipe A maps to MIPI DSI port A, pipe B maps to MIPI DSI
diff --git a/drivers/gpu/drm/i915/intel_dvo.c b/drivers/gpu/drm/i915/intel_dvo.c
index c86f88ed92fd..60e4ddf2ec6d 100644
--- a/drivers/gpu/drm/i915/intel_dvo.c
+++ b/drivers/gpu/drm/i915/intel_dvo.c
@@ -341,6 +341,7 @@ static void intel_dvo_destroy(struct drm_connector *connector)
341static const struct drm_connector_funcs intel_dvo_connector_funcs = { 341static const struct drm_connector_funcs intel_dvo_connector_funcs = {
342 .dpms = drm_atomic_helper_connector_dpms, 342 .dpms = drm_atomic_helper_connector_dpms,
343 .detect = intel_dvo_detect, 343 .detect = intel_dvo_detect,
344 .early_unregister = intel_connector_unregister,
344 .destroy = intel_dvo_destroy, 345 .destroy = intel_dvo_destroy,
345 .fill_modes = drm_helper_probe_single_connector_modes, 346 .fill_modes = drm_helper_probe_single_connector_modes,
346 .atomic_get_property = intel_connector_atomic_get_property, 347 .atomic_get_property = intel_connector_atomic_get_property,
@@ -447,7 +448,6 @@ void intel_dvo_init(struct drm_device *dev)
447 intel_encoder->compute_config = intel_dvo_compute_config; 448 intel_encoder->compute_config = intel_dvo_compute_config;
448 intel_encoder->pre_enable = intel_dvo_pre_enable; 449 intel_encoder->pre_enable = intel_dvo_pre_enable;
449 intel_connector->get_hw_state = intel_dvo_connector_get_hw_state; 450 intel_connector->get_hw_state = intel_dvo_connector_get_hw_state;
450 intel_connector->unregister = intel_connector_unregister;
451 451
452 /* Now, try to find a controller */ 452 /* Now, try to find a controller */
453 for (i = 0; i < ARRAY_SIZE(intel_dvo_devices); i++) { 453 for (i = 0; i < ARRAY_SIZE(intel_dvo_devices); i++) {
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 6b29da9bba38..d4fc3d436d52 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -1774,6 +1774,7 @@ static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
1774 .fill_modes = drm_helper_probe_single_connector_modes, 1774 .fill_modes = drm_helper_probe_single_connector_modes,
1775 .set_property = intel_hdmi_set_property, 1775 .set_property = intel_hdmi_set_property,
1776 .atomic_get_property = intel_connector_atomic_get_property, 1776 .atomic_get_property = intel_connector_atomic_get_property,
1777 .early_unregister = intel_connector_unregister,
1777 .destroy = intel_hdmi_destroy, 1778 .destroy = intel_hdmi_destroy,
1778 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 1779 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1779 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 1780 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
@@ -1906,7 +1907,6 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
1906 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state; 1907 intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
1907 else 1908 else
1908 intel_connector->get_hw_state = intel_connector_get_hw_state; 1909 intel_connector->get_hw_state = intel_connector_get_hw_state;
1909 intel_connector->unregister = intel_connector_unregister;
1910 1910
1911 intel_hdmi_add_properties(intel_hdmi, connector); 1911 intel_hdmi_add_properties(intel_hdmi, connector);
1912 1912
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index e06b9036bebc..e9082185a375 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -555,6 +555,7 @@ static const struct drm_connector_funcs intel_lvds_connector_funcs = {
555 .fill_modes = drm_helper_probe_single_connector_modes, 555 .fill_modes = drm_helper_probe_single_connector_modes,
556 .set_property = intel_lvds_set_property, 556 .set_property = intel_lvds_set_property,
557 .atomic_get_property = intel_connector_atomic_get_property, 557 .atomic_get_property = intel_connector_atomic_get_property,
558 .early_unregister = intel_connector_unregister,
558 .destroy = intel_lvds_destroy, 559 .destroy = intel_lvds_destroy,
559 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 560 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
560 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 561 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
@@ -991,7 +992,6 @@ void intel_lvds_init(struct drm_device *dev)
991 intel_encoder->get_hw_state = intel_lvds_get_hw_state; 992 intel_encoder->get_hw_state = intel_lvds_get_hw_state;
992 intel_encoder->get_config = intel_lvds_get_config; 993 intel_encoder->get_config = intel_lvds_get_config;
993 intel_connector->get_hw_state = intel_connector_get_hw_state; 994 intel_connector->get_hw_state = intel_connector_get_hw_state;
994 intel_connector->unregister = intel_connector_unregister;
995 995
996 intel_connector_attach_encoder(intel_connector, intel_encoder); 996 intel_connector_attach_encoder(intel_connector, intel_encoder);
997 intel_encoder->type = INTEL_OUTPUT_LVDS; 997 intel_encoder->type = INTEL_OUTPUT_LVDS;
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index f0b1602c3258..bf721781c259 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -1216,7 +1216,7 @@ static int intel_backlight_device_register(struct intel_connector *connector)
1216 return 0; 1216 return 0;
1217} 1217}
1218 1218
1219static void intel_backlight_device_unregister(struct intel_connector *connector) 1219void intel_backlight_device_unregister(struct intel_connector *connector)
1220{ 1220{
1221 struct intel_panel *panel = &connector->panel; 1221 struct intel_panel *panel = &connector->panel;
1222 1222
@@ -1230,9 +1230,6 @@ static int intel_backlight_device_register(struct intel_connector *connector)
1230{ 1230{
1231 return 0; 1231 return 0;
1232} 1232}
1233static void intel_backlight_device_unregister(struct intel_connector *connector)
1234{
1235}
1236#endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */ 1233#endif /* CONFIG_BACKLIGHT_CLASS_DEVICE */
1237 1234
1238/* 1235/*
@@ -1820,11 +1817,3 @@ void intel_backlight_register(struct drm_device *dev)
1820 for_each_intel_connector(dev, connector) 1817 for_each_intel_connector(dev, connector)
1821 intel_backlight_device_register(connector); 1818 intel_backlight_device_register(connector);
1822} 1819}
1823
1824void intel_backlight_unregister(struct drm_device *dev)
1825{
1826 struct intel_connector *connector;
1827
1828 for_each_intel_connector(dev, connector)
1829 intel_backlight_device_unregister(connector);
1830}
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index ab2d0658abe6..02b4a6695528 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -2177,12 +2177,23 @@ done:
2177#undef CHECK_PROPERTY 2177#undef CHECK_PROPERTY
2178} 2178}
2179 2179
2180static void
2181intel_sdvo_connector_unregister(struct drm_connector *connector)
2182{
2183 struct intel_sdvo *sdvo = intel_attached_sdvo(connector);
2184
2185 sysfs_remove_link(&connector->kdev->kobj,
2186 sdvo->ddc.dev.kobj.name);
2187 intel_connector_unregister(connector);
2188}
2189
2180static const struct drm_connector_funcs intel_sdvo_connector_funcs = { 2190static const struct drm_connector_funcs intel_sdvo_connector_funcs = {
2181 .dpms = drm_atomic_helper_connector_dpms, 2191 .dpms = drm_atomic_helper_connector_dpms,
2182 .detect = intel_sdvo_detect, 2192 .detect = intel_sdvo_detect,
2183 .fill_modes = drm_helper_probe_single_connector_modes, 2193 .fill_modes = drm_helper_probe_single_connector_modes,
2184 .set_property = intel_sdvo_set_property, 2194 .set_property = intel_sdvo_set_property,
2185 .atomic_get_property = intel_connector_atomic_get_property, 2195 .atomic_get_property = intel_connector_atomic_get_property,
2196 .early_unregister = intel_sdvo_connector_unregister,
2186 .destroy = intel_sdvo_destroy, 2197 .destroy = intel_sdvo_destroy,
2187 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 2198 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
2188 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 2199 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
@@ -2345,20 +2356,6 @@ intel_sdvo_get_slave_addr(struct drm_device *dev, struct intel_sdvo *sdvo)
2345 return 0x72; 2356 return 0x72;
2346} 2357}
2347 2358
2348static void
2349intel_sdvo_connector_unregister(struct intel_connector *intel_connector)
2350{
2351 struct drm_connector *drm_connector;
2352 struct intel_sdvo *sdvo_encoder;
2353
2354 drm_connector = &intel_connector->base;
2355 sdvo_encoder = intel_attached_sdvo(&intel_connector->base);
2356
2357 sysfs_remove_link(&drm_connector->kdev->kobj,
2358 sdvo_encoder->ddc.dev.kobj.name);
2359 intel_connector_unregister(intel_connector);
2360}
2361
2362static int 2359static int
2363intel_sdvo_connector_init(struct intel_sdvo_connector *connector, 2360intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
2364 struct intel_sdvo *encoder) 2361 struct intel_sdvo *encoder)
@@ -2381,7 +2378,6 @@ intel_sdvo_connector_init(struct intel_sdvo_connector *connector,
2381 connector->base.base.doublescan_allowed = 0; 2378 connector->base.base.doublescan_allowed = 0;
2382 connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB; 2379 connector->base.base.display_info.subpixel_order = SubPixelHorizontalRGB;
2383 connector->base.get_hw_state = intel_sdvo_connector_get_hw_state; 2380 connector->base.get_hw_state = intel_sdvo_connector_get_hw_state;
2384 connector->base.unregister = intel_sdvo_connector_unregister;
2385 2381
2386 intel_connector_attach_encoder(&connector->base, &encoder->base); 2382 intel_connector_attach_encoder(&connector->base, &encoder->base);
2387 ret = drm_connector_register(drm_connector); 2383 ret = drm_connector_register(drm_connector);
diff --git a/drivers/gpu/drm/i915/intel_tv.c b/drivers/gpu/drm/i915/intel_tv.c
index 7ac9e9b0e2c3..4ce70a9f9df2 100644
--- a/drivers/gpu/drm/i915/intel_tv.c
+++ b/drivers/gpu/drm/i915/intel_tv.c
@@ -1501,6 +1501,7 @@ out:
1501static const struct drm_connector_funcs intel_tv_connector_funcs = { 1501static const struct drm_connector_funcs intel_tv_connector_funcs = {
1502 .dpms = drm_atomic_helper_connector_dpms, 1502 .dpms = drm_atomic_helper_connector_dpms,
1503 .detect = intel_tv_detect, 1503 .detect = intel_tv_detect,
1504 .early_unregister = intel_connector_unregister,
1504 .destroy = intel_tv_destroy, 1505 .destroy = intel_tv_destroy,
1505 .set_property = intel_tv_set_property, 1506 .set_property = intel_tv_set_property,
1506 .atomic_get_property = intel_connector_atomic_get_property, 1507 .atomic_get_property = intel_connector_atomic_get_property,
@@ -1599,7 +1600,6 @@ intel_tv_init(struct drm_device *dev)
1599 intel_encoder->disable = intel_disable_tv; 1600 intel_encoder->disable = intel_disable_tv;
1600 intel_encoder->get_hw_state = intel_tv_get_hw_state; 1601 intel_encoder->get_hw_state = intel_tv_get_hw_state;
1601 intel_connector->get_hw_state = intel_connector_get_hw_state; 1602 intel_connector->get_hw_state = intel_connector_get_hw_state;
1602 intel_connector->unregister = intel_connector_unregister;
1603 1603
1604 intel_connector_attach_encoder(intel_connector, intel_encoder); 1604 intel_connector_attach_encoder(intel_connector, intel_encoder);
1605 intel_encoder->type = INTEL_OUTPUT_TVOUT; 1605 intel_encoder->type = INTEL_OUTPUT_TVOUT;
diff --git a/drivers/gpu/drm/imx/imx-drm-core.c b/drivers/gpu/drm/imx/imx-drm-core.c
index 82656654fb21..7746418a4c08 100644
--- a/drivers/gpu/drm/imx/imx-drm-core.c
+++ b/drivers/gpu/drm/imx/imx-drm-core.c
@@ -407,7 +407,6 @@ static struct drm_driver imx_drm_driver = {
407 .load = imx_drm_driver_load, 407 .load = imx_drm_driver_load,
408 .unload = imx_drm_driver_unload, 408 .unload = imx_drm_driver_unload,
409 .lastclose = imx_drm_driver_lastclose, 409 .lastclose = imx_drm_driver_lastclose,
410 .set_busid = drm_platform_set_busid,
411 .gem_free_object_unlocked = drm_gem_cma_free_object, 410 .gem_free_object_unlocked = drm_gem_cma_free_object,
412 .gem_vm_ops = &drm_gem_cma_vm_ops, 411 .gem_vm_ops = &drm_gem_cma_vm_ops,
413 .dumb_create = drm_gem_cma_dumb_create, 412 .dumb_create = drm_gem_cma_dumb_create,
diff --git a/drivers/gpu/drm/mediatek/Kconfig b/drivers/gpu/drm/mediatek/Kconfig
index eeefc971801a..9eefecedc3da 100644
--- a/drivers/gpu/drm/mediatek/Kconfig
+++ b/drivers/gpu/drm/mediatek/Kconfig
@@ -6,7 +6,6 @@ config DRM_MEDIATEK
6 select DRM_KMS_HELPER 6 select DRM_KMS_HELPER
7 select DRM_MIPI_DSI 7 select DRM_MIPI_DSI
8 select DRM_PANEL 8 select DRM_PANEL
9 select IOMMU_DMA
10 select MEMORY 9 select MEMORY
11 select MTK_SMI 10 select MTK_SMI
12 help 11 help
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index c33bf98c5d5e..eebb7d881c2b 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -280,8 +280,6 @@ static int mtk_drm_bind(struct device *dev)
280 if (!drm) 280 if (!drm)
281 return -ENOMEM; 281 return -ENOMEM;
282 282
283 drm_dev_set_unique(drm, dev_name(dev));
284
285 drm->dev_private = private; 283 drm->dev_private = private;
286 private->drm = drm; 284 private->drm = drm;
287 285
@@ -293,14 +291,8 @@ static int mtk_drm_bind(struct device *dev)
293 if (ret < 0) 291 if (ret < 0)
294 goto err_deinit; 292 goto err_deinit;
295 293
296 ret = drm_connector_register_all(drm);
297 if (ret < 0)
298 goto err_unregister;
299
300 return 0; 294 return 0;
301 295
302err_unregister:
303 drm_dev_unregister(drm);
304err_deinit: 296err_deinit:
305 mtk_drm_kms_deinit(drm); 297 mtk_drm_kms_deinit(drm);
306err_free: 298err_free:
@@ -455,7 +447,6 @@ static int mtk_drm_remove(struct platform_device *pdev)
455 struct drm_device *drm = private->drm; 447 struct drm_device *drm = private->drm;
456 int i; 448 int i;
457 449
458 drm_connector_unregister_all(drm);
459 drm_dev_unregister(drm); 450 drm_dev_unregister(drm);
460 mtk_drm_kms_deinit(drm); 451 mtk_drm_kms_deinit(drm);
461 drm_dev_unref(drm); 452 drm_dev_unref(drm);
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_plane.c b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
index 51bc8988fc26..3995765a90dc 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_plane.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_plane.c
@@ -170,6 +170,7 @@ static int mtk_plane_atomic_check(struct drm_plane *plane,
170 170
171 return drm_plane_helper_check_update(plane, state->crtc, fb, 171 return drm_plane_helper_check_update(plane, state->crtc, fb,
172 &src, &dest, &clip, 172 &src, &dest, &clip,
173 state->rotation,
173 DRM_PLANE_HELPER_NO_SCALING, 174 DRM_PLANE_HELPER_NO_SCALING,
174 DRM_PLANE_HELPER_NO_SCALING, 175 DRM_PLANE_HELPER_NO_SCALING,
175 true, true, &visible); 176 true, true, &visible);
diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 9c654092ef78..a02dc2b27739 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -197,8 +197,6 @@ static int msm_drm_uninit(struct device *dev)
197 197
198 drm_kms_helper_poll_fini(ddev); 198 drm_kms_helper_poll_fini(ddev);
199 199
200 drm_connector_unregister_all(ddev);
201
202 drm_dev_unregister(ddev); 200 drm_dev_unregister(ddev);
203 201
204#ifdef CONFIG_DRM_FBDEV_EMULATION 202#ifdef CONFIG_DRM_FBDEV_EMULATION
@@ -431,12 +429,6 @@ static int msm_drm_init(struct device *dev, struct drm_driver *drv)
431 if (ret) 429 if (ret)
432 goto fail; 430 goto fail;
433 431
434 ret = drm_connector_register_all(ddev);
435 if (ret) {
436 dev_err(dev, "failed to register connectors\n");
437 goto fail;
438 }
439
440 drm_mode_config_reset(ddev); 432 drm_mode_config_reset(ddev);
441 433
442#ifdef CONFIG_DRM_FBDEV_EMULATION 434#ifdef CONFIG_DRM_FBDEV_EMULATION
@@ -730,7 +722,6 @@ static struct drm_driver msm_driver = {
730 .open = msm_open, 722 .open = msm_open,
731 .preclose = msm_preclose, 723 .preclose = msm_preclose,
732 .lastclose = msm_lastclose, 724 .lastclose = msm_lastclose,
733 .set_busid = drm_platform_set_busid,
734 .irq_handler = msm_irq, 725 .irq_handler = msm_irq,
735 .irq_preinstall = msm_irq_preinstall, 726 .irq_preinstall = msm_irq_preinstall,
736 .irq_postinstall = msm_irq_postinstall, 727 .irq_postinstall = msm_irq_postinstall,
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
index c00ff6e786a3..295e7621cc68 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -1070,7 +1070,6 @@ nouveau_drm_init(void)
1070 driver_pci = driver_stub; 1070 driver_pci = driver_stub;
1071 driver_pci.set_busid = drm_pci_set_busid; 1071 driver_pci.set_busid = drm_pci_set_busid;
1072 driver_platform = driver_stub; 1072 driver_platform = driver_stub;
1073 driver_platform.set_busid = drm_platform_set_busid;
1074 1073
1075 nouveau_display_options(); 1074 nouveau_display_options();
1076 1075
diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c
index 6b97011154bf..26c6134eb744 100644
--- a/drivers/gpu/drm/omapdrm/omap_drv.c
+++ b/drivers/gpu/drm/omapdrm/omap_drv.c
@@ -801,7 +801,6 @@ static struct drm_driver omap_drm_driver = {
801 .unload = dev_unload, 801 .unload = dev_unload,
802 .open = dev_open, 802 .open = dev_open,
803 .lastclose = dev_lastclose, 803 .lastclose = dev_lastclose,
804 .set_busid = drm_platform_set_busid,
805 .get_vblank_counter = drm_vblank_no_hw_counter, 804 .get_vblank_counter = drm_vblank_no_hw_counter,
806 .enable_vblank = omap_irq_enable_vblank, 805 .enable_vblank = omap_irq_enable_vblank,
807 .disable_vblank = omap_irq_disable_vblank, 806 .disable_vblank = omap_irq_disable_vblank,
diff --git a/drivers/gpu/drm/omapdrm/omap_fbdev.c b/drivers/gpu/drm/omapdrm/omap_fbdev.c
index 31dfa0893416..adb10fbe918d 100644
--- a/drivers/gpu/drm/omapdrm/omap_fbdev.c
+++ b/drivers/gpu/drm/omapdrm/omap_fbdev.c
@@ -279,9 +279,6 @@ struct drm_fb_helper *omap_fbdev_init(struct drm_device *dev)
279 if (ret) 279 if (ret)
280 goto fini; 280 goto fini;
281 281
282 /* disable all the possible outputs/crtcs before entering KMS mode */
283 drm_helper_disable_unused_functions(dev);
284
285 ret = drm_fb_helper_initial_config(helper, 32); 282 ret = drm_fb_helper_initial_config(helper, 32);
286 if (ret) 283 if (ret)
287 goto fini; 284 goto fini;
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
index 48ec4b6e8b26..d1c0512e4a9e 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
@@ -278,7 +278,6 @@ static int rcar_du_remove(struct platform_device *pdev)
278 struct rcar_du_device *rcdu = platform_get_drvdata(pdev); 278 struct rcar_du_device *rcdu = platform_get_drvdata(pdev);
279 struct drm_device *ddev = rcdu->ddev; 279 struct drm_device *ddev = rcdu->ddev;
280 280
281 drm_connector_unregister_all(ddev);
282 drm_dev_unregister(ddev); 281 drm_dev_unregister(ddev);
283 282
284 if (rcdu->fbdev) 283 if (rcdu->fbdev)
@@ -320,8 +319,6 @@ static int rcar_du_probe(struct platform_device *pdev)
320 if (!ddev) 319 if (!ddev)
321 return -ENOMEM; 320 return -ENOMEM;
322 321
323 drm_dev_set_unique(ddev, dev_name(&pdev->dev));
324
325 rcdu->ddev = ddev; 322 rcdu->ddev = ddev;
326 ddev->dev_private = rcdu; 323 ddev->dev_private = rcdu;
327 324
@@ -360,10 +357,6 @@ static int rcar_du_probe(struct platform_device *pdev)
360 if (ret) 357 if (ret)
361 goto error; 358 goto error;
362 359
363 ret = drm_connector_register_all(ddev);
364 if (ret < 0)
365 goto error;
366
367 DRM_INFO("Device %s probed\n", dev_name(&pdev->dev)); 360 DRM_INFO("Device %s probed\n", dev_name(&pdev->dev));
368 361
369 return 0; 362 return 0;
diff --git a/drivers/gpu/drm/rockchip/Kconfig b/drivers/gpu/drm/rockchip/Kconfig
index d30bdc38a760..e48611e83c03 100644
--- a/drivers/gpu/drm/rockchip/Kconfig
+++ b/drivers/gpu/drm/rockchip/Kconfig
@@ -2,6 +2,7 @@ config DRM_ROCKCHIP
2 tristate "DRM Support for Rockchip" 2 tristate "DRM Support for Rockchip"
3 depends on DRM && ROCKCHIP_IOMMU 3 depends on DRM && ROCKCHIP_IOMMU
4 depends on RESET_CONTROLLER 4 depends on RESET_CONTROLLER
5 select DRM_GEM_CMA_HELPER
5 select DRM_KMS_HELPER 6 select DRM_KMS_HELPER
6 select DRM_KMS_FB_HELPER 7 select DRM_KMS_FB_HELPER
7 select DRM_PANEL 8 select DRM_PANEL
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
index c2bcc5ea1abe..d665fb04d264 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
@@ -146,16 +146,12 @@ static int rockchip_drm_bind(struct device *dev)
146 if (!drm_dev) 146 if (!drm_dev)
147 return -ENOMEM; 147 return -ENOMEM;
148 148
149 ret = drm_dev_register(drm_dev, 0);
150 if (ret)
151 goto err_free;
152
153 dev_set_drvdata(dev, drm_dev); 149 dev_set_drvdata(dev, drm_dev);
154 150
155 private = devm_kzalloc(drm_dev->dev, sizeof(*private), GFP_KERNEL); 151 private = devm_kzalloc(drm_dev->dev, sizeof(*private), GFP_KERNEL);
156 if (!private) { 152 if (!private) {
157 ret = -ENOMEM; 153 ret = -ENOMEM;
158 goto err_unregister; 154 goto err_free;
159 } 155 }
160 156
161 drm_dev->dev_private = private; 157 drm_dev->dev_private = private;
@@ -197,12 +193,6 @@ static int rockchip_drm_bind(struct device *dev)
197 if (ret) 193 if (ret)
198 goto err_detach_device; 194 goto err_detach_device;
199 195
200 ret = drm_connector_register_all(drm_dev);
201 if (ret) {
202 dev_err(dev, "failed to register connectors\n");
203 goto err_unbind;
204 }
205
206 /* init kms poll for handling hpd */ 196 /* init kms poll for handling hpd */
207 drm_kms_helper_poll_init(drm_dev); 197 drm_kms_helper_poll_init(drm_dev);
208 198
@@ -222,14 +212,19 @@ static int rockchip_drm_bind(struct device *dev)
222 if (ret) 212 if (ret)
223 goto err_vblank_cleanup; 213 goto err_vblank_cleanup;
224 214
215 ret = drm_dev_register(drm_dev, 0);
216 if (ret)
217 goto err_fbdev_fini;
218
225 if (is_support_iommu) 219 if (is_support_iommu)
226 arm_iommu_release_mapping(mapping); 220 arm_iommu_release_mapping(mapping);
227 return 0; 221 return 0;
222err_fbdev_fini:
223 rockchip_drm_fbdev_fini(drm_dev);
228err_vblank_cleanup: 224err_vblank_cleanup:
229 drm_vblank_cleanup(drm_dev); 225 drm_vblank_cleanup(drm_dev);
230err_kms_helper_poll_fini: 226err_kms_helper_poll_fini:
231 drm_kms_helper_poll_fini(drm_dev); 227 drm_kms_helper_poll_fini(drm_dev);
232err_unbind:
233 component_unbind_all(dev, drm_dev); 228 component_unbind_all(dev, drm_dev);
234err_detach_device: 229err_detach_device:
235 if (is_support_iommu) 230 if (is_support_iommu)
@@ -240,8 +235,6 @@ err_release_mapping:
240err_config_cleanup: 235err_config_cleanup:
241 drm_mode_config_cleanup(drm_dev); 236 drm_mode_config_cleanup(drm_dev);
242 drm_dev->dev_private = NULL; 237 drm_dev->dev_private = NULL;
243err_unregister:
244 drm_dev_unregister(drm_dev);
245err_free: 238err_free:
246 drm_dev_unref(drm_dev); 239 drm_dev_unref(drm_dev);
247 return ret; 240 return ret;
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index 8cd840f602b7..6255e5bcd954 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -626,6 +626,7 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
626 626
627 ret = drm_plane_helper_check_update(plane, crtc, state->fb, 627 ret = drm_plane_helper_check_update(plane, crtc, state->fb,
628 src, dest, &clip, 628 src, dest, &clip,
629 state->rotation,
629 min_scale, 630 min_scale,
630 max_scale, 631 max_scale,
631 true, true, &visible); 632 true, true, &visible);
diff --git a/drivers/gpu/drm/shmobile/shmob_drm_drv.c b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
index ee79264b5b6a..f0492603ea88 100644
--- a/drivers/gpu/drm/shmobile/shmob_drm_drv.c
+++ b/drivers/gpu/drm/shmobile/shmob_drm_drv.c
@@ -259,7 +259,6 @@ static struct drm_driver shmob_drm_driver = {
259 | DRIVER_PRIME, 259 | DRIVER_PRIME,
260 .load = shmob_drm_load, 260 .load = shmob_drm_load,
261 .unload = shmob_drm_unload, 261 .unload = shmob_drm_unload,
262 .set_busid = drm_platform_set_busid,
263 .irq_handler = shmob_drm_irq, 262 .irq_handler = shmob_drm_irq,
264 .get_vblank_counter = drm_vblank_no_hw_counter, 263 .get_vblank_counter = drm_vblank_no_hw_counter,
265 .enable_vblank = shmob_drm_enable_vblank, 264 .enable_vblank = shmob_drm_enable_vblank,
diff --git a/drivers/gpu/drm/sis/sis_mm.c b/drivers/gpu/drm/sis/sis_mm.c
index 93ad8a5704d1..03defda77766 100644
--- a/drivers/gpu/drm/sis/sis_mm.c
+++ b/drivers/gpu/drm/sis/sis_mm.c
@@ -316,7 +316,7 @@ void sis_reclaim_buffers_locked(struct drm_device *dev,
316 struct sis_file_private *file_priv = file->driver_priv; 316 struct sis_file_private *file_priv = file->driver_priv;
317 struct sis_memblock *entry, *next; 317 struct sis_memblock *entry, *next;
318 318
319 if (!(file->minor->master && file->master->lock.hw_lock)) 319 if (!(dev->master && file->master->lock.hw_lock))
320 return; 320 return;
321 321
322 drm_legacy_idlelock_take(&file->master->lock); 322 drm_legacy_idlelock_take(&file->master->lock);
diff --git a/drivers/gpu/drm/sti/sti_compositor.c b/drivers/gpu/drm/sti/sti_compositor.c
index 3d2fa3ab33df..794148ff0e57 100644
--- a/drivers/gpu/drm/sti/sti_compositor.c
+++ b/drivers/gpu/drm/sti/sti_compositor.c
@@ -55,6 +55,26 @@ struct sti_compositor_data stih416_compositor_data = {
55 }, 55 },
56}; 56};
57 57
58int sti_compositor_debufs_init(struct sti_compositor *compo,
59 struct drm_minor *minor)
60{
61 int ret = 0, i;
62
63 for (i = 0; compo->vid[i]; i++) {
64 ret = vid_debugfs_init(compo->vid[i], minor);
65 if (ret)
66 return ret;
67 }
68
69 for (i = 0; compo->mixer[i]; i++) {
70 ret = sti_mixer_debugfs_init(compo->mixer[i], minor);
71 if (ret)
72 return ret;
73 }
74
75 return 0;
76}
77
58static int sti_compositor_bind(struct device *dev, 78static int sti_compositor_bind(struct device *dev,
59 struct device *master, 79 struct device *master,
60 void *data) 80 void *data)
diff --git a/drivers/gpu/drm/sti/sti_compositor.h b/drivers/gpu/drm/sti/sti_compositor.h
index 1a4a73dab11e..24444ef42a98 100644
--- a/drivers/gpu/drm/sti/sti_compositor.h
+++ b/drivers/gpu/drm/sti/sti_compositor.h
@@ -81,4 +81,7 @@ struct sti_compositor {
81 struct notifier_block vtg_vblank_nb; 81 struct notifier_block vtg_vblank_nb;
82}; 82};
83 83
84int sti_compositor_debufs_init(struct sti_compositor *compo,
85 struct drm_minor *minor);
86
84#endif 87#endif
diff --git a/drivers/gpu/drm/sti/sti_crtc.c b/drivers/gpu/drm/sti/sti_crtc.c
index e04deedabd4a..7fab3af7473b 100644
--- a/drivers/gpu/drm/sti/sti_crtc.c
+++ b/drivers/gpu/drm/sti/sti_crtc.c
@@ -331,6 +331,17 @@ void sti_crtc_disable_vblank(struct drm_device *drm_dev, unsigned int pipe)
331 } 331 }
332} 332}
333 333
334static int sti_crtc_late_register(struct drm_crtc *crtc)
335{
336 struct sti_mixer *mixer = to_sti_mixer(crtc);
337 struct sti_compositor *compo = dev_get_drvdata(mixer->dev);
338
339 if (drm_crtc_index(crtc) == 0)
340 return sti_compositor_debufs_init(compo, crtc->dev->primary);
341
342 return 0;
343}
344
334static const struct drm_crtc_funcs sti_crtc_funcs = { 345static const struct drm_crtc_funcs sti_crtc_funcs = {
335 .set_config = drm_atomic_helper_set_config, 346 .set_config = drm_atomic_helper_set_config,
336 .page_flip = drm_atomic_helper_page_flip, 347 .page_flip = drm_atomic_helper_page_flip,
@@ -339,6 +350,7 @@ static const struct drm_crtc_funcs sti_crtc_funcs = {
339 .reset = drm_atomic_helper_crtc_reset, 350 .reset = drm_atomic_helper_crtc_reset,
340 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, 351 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
341 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, 352 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
353 .late_register = sti_crtc_late_register,
342}; 354};
343 355
344bool sti_crtc_is_main(struct drm_crtc *crtc) 356bool sti_crtc_is_main(struct drm_crtc *crtc)
diff --git a/drivers/gpu/drm/sti/sti_cursor.c b/drivers/gpu/drm/sti/sti_cursor.c
index 53aa0029295b..a263bbba4119 100644
--- a/drivers/gpu/drm/sti/sti_cursor.c
+++ b/drivers/gpu/drm/sti/sti_cursor.c
@@ -329,6 +329,33 @@ static const struct drm_plane_helper_funcs sti_cursor_helpers_funcs = {
329 .atomic_disable = sti_cursor_atomic_disable, 329 .atomic_disable = sti_cursor_atomic_disable,
330}; 330};
331 331
332static void sti_cursor_destroy(struct drm_plane *drm_plane)
333{
334 DRM_DEBUG_DRIVER("\n");
335
336 drm_plane_helper_disable(drm_plane);
337 drm_plane_cleanup(drm_plane);
338}
339
340static int sti_cursor_late_register(struct drm_plane *drm_plane)
341{
342 struct sti_plane *plane = to_sti_plane(drm_plane);
343 struct sti_cursor *cursor = to_sti_cursor(plane);
344
345 return cursor_debugfs_init(cursor, drm_plane->dev->primary);
346}
347
348struct drm_plane_funcs sti_cursor_plane_helpers_funcs = {
349 .update_plane = drm_atomic_helper_update_plane,
350 .disable_plane = drm_atomic_helper_disable_plane,
351 .destroy = sti_cursor_destroy,
352 .set_property = sti_plane_set_property,
353 .reset = drm_atomic_helper_plane_reset,
354 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
355 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
356 .late_register = sti_cursor_late_register,
357};
358
332struct drm_plane *sti_cursor_create(struct drm_device *drm_dev, 359struct drm_plane *sti_cursor_create(struct drm_device *drm_dev,
333 struct device *dev, int desc, 360 struct device *dev, int desc,
334 void __iomem *baseaddr, 361 void __iomem *baseaddr,
@@ -363,7 +390,7 @@ struct drm_plane *sti_cursor_create(struct drm_device *drm_dev,
363 390
364 res = drm_universal_plane_init(drm_dev, &cursor->plane.drm_plane, 391 res = drm_universal_plane_init(drm_dev, &cursor->plane.drm_plane,
365 possible_crtcs, 392 possible_crtcs,
366 &sti_plane_helpers_funcs, 393 &sti_cursor_plane_helpers_funcs,
367 cursor_supported_formats, 394 cursor_supported_formats,
368 ARRAY_SIZE(cursor_supported_formats), 395 ARRAY_SIZE(cursor_supported_formats),
369 DRM_PLANE_TYPE_CURSOR, NULL); 396 DRM_PLANE_TYPE_CURSOR, NULL);
@@ -377,9 +404,6 @@ struct drm_plane *sti_cursor_create(struct drm_device *drm_dev,
377 404
378 sti_plane_init_property(&cursor->plane, DRM_PLANE_TYPE_CURSOR); 405 sti_plane_init_property(&cursor->plane, DRM_PLANE_TYPE_CURSOR);
379 406
380 if (cursor_debugfs_init(cursor, drm_dev->primary))
381 DRM_ERROR("CURSOR debugfs setup failed\n");
382
383 return &cursor->plane.drm_plane; 407 return &cursor->plane.drm_plane;
384 408
385err_plane: 409err_plane:
diff --git a/drivers/gpu/drm/sti/sti_drv.c b/drivers/gpu/drm/sti/sti_drv.c
index dd2c400c4a46..96bd3d08b2d4 100644
--- a/drivers/gpu/drm/sti/sti_drv.c
+++ b/drivers/gpu/drm/sti/sti_drv.c
@@ -226,8 +226,28 @@ static int sti_atomic_commit(struct drm_device *drm,
226 return 0; 226 return 0;
227} 227}
228 228
229static void sti_output_poll_changed(struct drm_device *ddev)
230{
231 struct sti_private *private = ddev->dev_private;
232
233 if (!ddev->mode_config.num_connector)
234 return;
235
236 if (private->fbdev) {
237 drm_fbdev_cma_hotplug_event(private->fbdev);
238 return;
239 }
240
241 private->fbdev = drm_fbdev_cma_init(ddev, 32,
242 ddev->mode_config.num_crtc,
243 ddev->mode_config.num_connector);
244 if (IS_ERR(private->fbdev))
245 private->fbdev = NULL;
246}
247
229static const struct drm_mode_config_funcs sti_mode_config_funcs = { 248static const struct drm_mode_config_funcs sti_mode_config_funcs = {
230 .fb_create = drm_fb_cma_create, 249 .fb_create = drm_fb_cma_create,
250 .output_poll_changed = sti_output_poll_changed,
231 .atomic_check = drm_atomic_helper_check, 251 .atomic_check = drm_atomic_helper_check,
232 .atomic_commit = sti_atomic_commit, 252 .atomic_commit = sti_atomic_commit,
233}; 253};
@@ -248,45 +268,6 @@ static void sti_mode_config_init(struct drm_device *dev)
248 dev->mode_config.funcs = &sti_mode_config_funcs; 268 dev->mode_config.funcs = &sti_mode_config_funcs;
249} 269}
250 270
251static int sti_load(struct drm_device *dev, unsigned long flags)
252{
253 struct sti_private *private;
254 int ret;
255
256 private = kzalloc(sizeof(*private), GFP_KERNEL);
257 if (!private) {
258 DRM_ERROR("Failed to allocate private\n");
259 return -ENOMEM;
260 }
261 dev->dev_private = (void *)private;
262 private->drm_dev = dev;
263
264 mutex_init(&private->commit.lock);
265 INIT_WORK(&private->commit.work, sti_atomic_work);
266
267 drm_mode_config_init(dev);
268 drm_kms_helper_poll_init(dev);
269
270 sti_mode_config_init(dev);
271
272 ret = component_bind_all(dev->dev, dev);
273 if (ret) {
274 drm_kms_helper_poll_fini(dev);
275 drm_mode_config_cleanup(dev);
276 kfree(private);
277 return ret;
278 }
279
280 drm_mode_config_reset(dev);
281
282 drm_helper_disable_unused_functions(dev);
283 drm_fbdev_cma_init(dev, 32,
284 dev->mode_config.num_crtc,
285 dev->mode_config.num_connector);
286
287 return 0;
288}
289
290static const struct file_operations sti_driver_fops = { 271static const struct file_operations sti_driver_fops = {
291 .owner = THIS_MODULE, 272 .owner = THIS_MODULE,
292 .open = drm_open, 273 .open = drm_open,
@@ -303,7 +284,6 @@ static const struct file_operations sti_driver_fops = {
303static struct drm_driver sti_driver = { 284static struct drm_driver sti_driver = {
304 .driver_features = DRIVER_HAVE_IRQ | DRIVER_MODESET | 285 .driver_features = DRIVER_HAVE_IRQ | DRIVER_MODESET |
305 DRIVER_GEM | DRIVER_PRIME | DRIVER_ATOMIC, 286 DRIVER_GEM | DRIVER_PRIME | DRIVER_ATOMIC,
306 .load = sti_load,
307 .gem_free_object_unlocked = drm_gem_cma_free_object, 287 .gem_free_object_unlocked = drm_gem_cma_free_object,
308 .gem_vm_ops = &drm_gem_cma_vm_ops, 288 .gem_vm_ops = &drm_gem_cma_vm_ops,
309 .dumb_create = drm_gem_cma_dumb_create, 289 .dumb_create = drm_gem_cma_dumb_create,
@@ -340,14 +320,88 @@ static int compare_of(struct device *dev, void *data)
340 return dev->of_node == data; 320 return dev->of_node == data;
341} 321}
342 322
323static int sti_init(struct drm_device *ddev)
324{
325 struct sti_private *private;
326
327 private = kzalloc(sizeof(*private), GFP_KERNEL);
328 if (!private)
329 return -ENOMEM;
330
331 ddev->dev_private = (void *)private;
332 dev_set_drvdata(ddev->dev, ddev);
333 private->drm_dev = ddev;
334
335 mutex_init(&private->commit.lock);
336 INIT_WORK(&private->commit.work, sti_atomic_work);
337
338 drm_mode_config_init(ddev);
339
340 sti_mode_config_init(ddev);
341
342 drm_kms_helper_poll_init(ddev);
343
344 return 0;
345}
346
347static void sti_cleanup(struct drm_device *ddev)
348{
349 struct sti_private *private = ddev->dev_private;
350
351 if (private->fbdev) {
352 drm_fbdev_cma_fini(private->fbdev);
353 private->fbdev = NULL;
354 }
355
356 drm_kms_helper_poll_fini(ddev);
357 drm_vblank_cleanup(ddev);
358 kfree(private);
359 ddev->dev_private = NULL;
360}
361
343static int sti_bind(struct device *dev) 362static int sti_bind(struct device *dev)
344{ 363{
345 return drm_platform_init(&sti_driver, to_platform_device(dev)); 364 struct drm_device *ddev;
365 int ret;
366
367 ddev = drm_dev_alloc(&sti_driver, dev);
368 if (!ddev)
369 return -ENOMEM;
370
371 ddev->platformdev = to_platform_device(dev);
372
373 ret = sti_init(ddev);
374 if (ret)
375 goto err_drm_dev_unref;
376
377 ret = component_bind_all(ddev->dev, ddev);
378 if (ret)
379 goto err_cleanup;
380
381 ret = drm_dev_register(ddev, 0);
382 if (ret)
383 goto err_register;
384
385 drm_mode_config_reset(ddev);
386
387 return 0;
388
389err_register:
390 drm_mode_config_cleanup(ddev);
391err_cleanup:
392 sti_cleanup(ddev);
393err_drm_dev_unref:
394 drm_dev_unref(ddev);
395 return ret;
346} 396}
347 397
348static void sti_unbind(struct device *dev) 398static void sti_unbind(struct device *dev)
349{ 399{
350 drm_put_dev(dev_get_drvdata(dev)); 400 struct drm_device *ddev = dev_get_drvdata(dev);
401
402 drm_dev_unregister(ddev);
403 sti_cleanup(ddev);
404 drm_dev_unref(ddev);
351} 405}
352 406
353static const struct component_master_ops sti_ops = { 407static const struct component_master_ops sti_ops = {
diff --git a/drivers/gpu/drm/sti/sti_drv.h b/drivers/gpu/drm/sti/sti_drv.h
index 30ddc20841c3..78ebe5e30f53 100644
--- a/drivers/gpu/drm/sti/sti_drv.h
+++ b/drivers/gpu/drm/sti/sti_drv.h
@@ -24,6 +24,7 @@ struct sti_private {
24 struct sti_compositor *compo; 24 struct sti_compositor *compo;
25 struct drm_property *plane_zorder_property; 25 struct drm_property *plane_zorder_property;
26 struct drm_device *drm_dev; 26 struct drm_device *drm_dev;
27 struct drm_fbdev_cma *fbdev;
27 28
28 struct { 29 struct {
29 struct drm_atomic_state *state; 30 struct drm_atomic_state *state;
diff --git a/drivers/gpu/drm/sti/sti_dvo.c b/drivers/gpu/drm/sti/sti_dvo.c
index e2901667eceb..ec3108074350 100644
--- a/drivers/gpu/drm/sti/sti_dvo.c
+++ b/drivers/gpu/drm/sti/sti_dvo.c
@@ -404,24 +404,29 @@ sti_dvo_connector_detect(struct drm_connector *connector, bool force)
404 return connector_status_disconnected; 404 return connector_status_disconnected;
405} 405}
406 406
407static void sti_dvo_connector_destroy(struct drm_connector *connector) 407static int sti_dvo_late_register(struct drm_connector *connector)
408{ 408{
409 struct sti_dvo_connector *dvo_connector 409 struct sti_dvo_connector *dvo_connector
410 = to_sti_dvo_connector(connector); 410 = to_sti_dvo_connector(connector);
411 struct sti_dvo *dvo = dvo_connector->dvo;
412
413 if (dvo_debugfs_init(dvo, dvo->drm_dev->primary)) {
414 DRM_ERROR("DVO debugfs setup failed\n");
415 return -EINVAL;
416 }
411 417
412 drm_connector_unregister(connector); 418 return 0;
413 drm_connector_cleanup(connector);
414 kfree(dvo_connector);
415} 419}
416 420
417static const struct drm_connector_funcs sti_dvo_connector_funcs = { 421static const struct drm_connector_funcs sti_dvo_connector_funcs = {
418 .dpms = drm_atomic_helper_connector_dpms, 422 .dpms = drm_atomic_helper_connector_dpms,
419 .fill_modes = drm_helper_probe_single_connector_modes, 423 .fill_modes = drm_helper_probe_single_connector_modes,
420 .detect = sti_dvo_connector_detect, 424 .detect = sti_dvo_connector_detect,
421 .destroy = sti_dvo_connector_destroy, 425 .destroy = drm_connector_cleanup,
422 .reset = drm_atomic_helper_connector_reset, 426 .reset = drm_atomic_helper_connector_reset,
423 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 427 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
424 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 428 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
429 .late_register = sti_dvo_late_register,
425}; 430};
426 431
427static struct drm_encoder *sti_dvo_find_encoder(struct drm_device *dev) 432static struct drm_encoder *sti_dvo_find_encoder(struct drm_device *dev)
@@ -492,26 +497,16 @@ static int sti_dvo_bind(struct device *dev, struct device *master, void *data)
492 drm_connector_helper_add(drm_connector, 497 drm_connector_helper_add(drm_connector,
493 &sti_dvo_connector_helper_funcs); 498 &sti_dvo_connector_helper_funcs);
494 499
495 err = drm_connector_register(drm_connector);
496 if (err)
497 goto err_connector;
498
499 err = drm_mode_connector_attach_encoder(drm_connector, encoder); 500 err = drm_mode_connector_attach_encoder(drm_connector, encoder);
500 if (err) { 501 if (err) {
501 DRM_ERROR("Failed to attach a connector to a encoder\n"); 502 DRM_ERROR("Failed to attach a connector to a encoder\n");
502 goto err_sysfs; 503 goto err_sysfs;
503 } 504 }
504 505
505 if (dvo_debugfs_init(dvo, drm_dev->primary))
506 DRM_ERROR("DVO debugfs setup failed\n");
507
508 return 0; 506 return 0;
509 507
510err_sysfs: 508err_sysfs:
511 drm_connector_unregister(drm_connector);
512err_connector:
513 drm_bridge_remove(bridge); 509 drm_bridge_remove(bridge);
514 drm_connector_cleanup(drm_connector);
515 return -EINVAL; 510 return -EINVAL;
516} 511}
517 512
diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c
index fdf69b5a041b..bf63086a3dc8 100644
--- a/drivers/gpu/drm/sti/sti_gdp.c
+++ b/drivers/gpu/drm/sti/sti_gdp.c
@@ -866,6 +866,33 @@ static const struct drm_plane_helper_funcs sti_gdp_helpers_funcs = {
866 .atomic_disable = sti_gdp_atomic_disable, 866 .atomic_disable = sti_gdp_atomic_disable,
867}; 867};
868 868
869static void sti_gdp_destroy(struct drm_plane *drm_plane)
870{
871 DRM_DEBUG_DRIVER("\n");
872
873 drm_plane_helper_disable(drm_plane);
874 drm_plane_cleanup(drm_plane);
875}
876
877static int sti_gdp_late_register(struct drm_plane *drm_plane)
878{
879 struct sti_plane *plane = to_sti_plane(drm_plane);
880 struct sti_gdp *gdp = to_sti_gdp(plane);
881
882 return gdp_debugfs_init(gdp, drm_plane->dev->primary);
883}
884
885struct drm_plane_funcs sti_gdp_plane_helpers_funcs = {
886 .update_plane = drm_atomic_helper_update_plane,
887 .disable_plane = drm_atomic_helper_disable_plane,
888 .destroy = sti_gdp_destroy,
889 .set_property = sti_plane_set_property,
890 .reset = drm_atomic_helper_plane_reset,
891 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
892 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
893 .late_register = sti_gdp_late_register,
894};
895
869struct drm_plane *sti_gdp_create(struct drm_device *drm_dev, 896struct drm_plane *sti_gdp_create(struct drm_device *drm_dev,
870 struct device *dev, int desc, 897 struct device *dev, int desc,
871 void __iomem *baseaddr, 898 void __iomem *baseaddr,
@@ -892,7 +919,7 @@ struct drm_plane *sti_gdp_create(struct drm_device *drm_dev,
892 919
893 res = drm_universal_plane_init(drm_dev, &gdp->plane.drm_plane, 920 res = drm_universal_plane_init(drm_dev, &gdp->plane.drm_plane,
894 possible_crtcs, 921 possible_crtcs,
895 &sti_plane_helpers_funcs, 922 &sti_gdp_plane_helpers_funcs,
896 gdp_supported_formats, 923 gdp_supported_formats,
897 ARRAY_SIZE(gdp_supported_formats), 924 ARRAY_SIZE(gdp_supported_formats),
898 type, NULL); 925 type, NULL);
@@ -905,9 +932,6 @@ struct drm_plane *sti_gdp_create(struct drm_device *drm_dev,
905 932
906 sti_plane_init_property(&gdp->plane, type); 933 sti_plane_init_property(&gdp->plane, type);
907 934
908 if (gdp_debugfs_init(gdp, drm_dev->primary))
909 DRM_ERROR("GDP debugfs setup failed\n");
910
911 return &gdp->plane.drm_plane; 935 return &gdp->plane.drm_plane;
912 936
913err: 937err:
diff --git a/drivers/gpu/drm/sti/sti_hda.c b/drivers/gpu/drm/sti/sti_hda.c
index dcec5a8eda59..8505569f75de 100644
--- a/drivers/gpu/drm/sti/sti_hda.c
+++ b/drivers/gpu/drm/sti/sti_hda.c
@@ -681,24 +681,29 @@ sti_hda_connector_detect(struct drm_connector *connector, bool force)
681 return connector_status_connected; 681 return connector_status_connected;
682} 682}
683 683
684static void sti_hda_connector_destroy(struct drm_connector *connector) 684static int sti_hda_late_register(struct drm_connector *connector)
685{ 685{
686 struct sti_hda_connector *hda_connector 686 struct sti_hda_connector *hda_connector
687 = to_sti_hda_connector(connector); 687 = to_sti_hda_connector(connector);
688 struct sti_hda *hda = hda_connector->hda;
689
690 if (hda_debugfs_init(hda, hda->drm_dev->primary)) {
691 DRM_ERROR("HDA debugfs setup failed\n");
692 return -EINVAL;
693 }
688 694
689 drm_connector_unregister(connector); 695 return 0;
690 drm_connector_cleanup(connector);
691 kfree(hda_connector);
692} 696}
693 697
694static const struct drm_connector_funcs sti_hda_connector_funcs = { 698static const struct drm_connector_funcs sti_hda_connector_funcs = {
695 .dpms = drm_atomic_helper_connector_dpms, 699 .dpms = drm_atomic_helper_connector_dpms,
696 .fill_modes = drm_helper_probe_single_connector_modes, 700 .fill_modes = drm_helper_probe_single_connector_modes,
697 .detect = sti_hda_connector_detect, 701 .detect = sti_hda_connector_detect,
698 .destroy = sti_hda_connector_destroy, 702 .destroy = drm_connector_cleanup,
699 .reset = drm_atomic_helper_connector_reset, 703 .reset = drm_atomic_helper_connector_reset,
700 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 704 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
701 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 705 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
706 .late_register = sti_hda_late_register,
702}; 707};
703 708
704static struct drm_encoder *sti_hda_find_encoder(struct drm_device *dev) 709static struct drm_encoder *sti_hda_find_encoder(struct drm_device *dev)
@@ -756,10 +761,6 @@ static int sti_hda_bind(struct device *dev, struct device *master, void *data)
756 drm_connector_helper_add(drm_connector, 761 drm_connector_helper_add(drm_connector,
757 &sti_hda_connector_helper_funcs); 762 &sti_hda_connector_helper_funcs);
758 763
759 err = drm_connector_register(drm_connector);
760 if (err)
761 goto err_connector;
762
763 err = drm_mode_connector_attach_encoder(drm_connector, encoder); 764 err = drm_mode_connector_attach_encoder(drm_connector, encoder);
764 if (err) { 765 if (err) {
765 DRM_ERROR("Failed to attach a connector to a encoder\n"); 766 DRM_ERROR("Failed to attach a connector to a encoder\n");
@@ -769,15 +770,10 @@ static int sti_hda_bind(struct device *dev, struct device *master, void *data)
769 /* force to disable hd dacs at startup */ 770 /* force to disable hd dacs at startup */
770 hda_enable_hd_dacs(hda, false); 771 hda_enable_hd_dacs(hda, false);
771 772
772 if (hda_debugfs_init(hda, drm_dev->primary))
773 DRM_ERROR("HDA debugfs setup failed\n");
774
775 return 0; 773 return 0;
776 774
777err_sysfs: 775err_sysfs:
778 drm_connector_unregister(drm_connector); 776 drm_bridge_remove(bridge);
779err_connector:
780 drm_connector_cleanup(drm_connector);
781 return -EINVAL; 777 return -EINVAL;
782} 778}
783 779
diff --git a/drivers/gpu/drm/sti/sti_hdmi.c b/drivers/gpu/drm/sti/sti_hdmi.c
index 36d9d6635784..8d1402b245bf 100644
--- a/drivers/gpu/drm/sti/sti_hdmi.c
+++ b/drivers/gpu/drm/sti/sti_hdmi.c
@@ -915,16 +915,6 @@ sti_hdmi_connector_detect(struct drm_connector *connector, bool force)
915 return connector_status_disconnected; 915 return connector_status_disconnected;
916} 916}
917 917
918static void sti_hdmi_connector_destroy(struct drm_connector *connector)
919{
920 struct sti_hdmi_connector *hdmi_connector
921 = to_sti_hdmi_connector(connector);
922
923 drm_connector_unregister(connector);
924 drm_connector_cleanup(connector);
925 kfree(hdmi_connector);
926}
927
928static void sti_hdmi_connector_init_property(struct drm_device *drm_dev, 918static void sti_hdmi_connector_init_property(struct drm_device *drm_dev,
929 struct drm_connector *connector) 919 struct drm_connector *connector)
930{ 920{
@@ -1007,17 +997,31 @@ sti_hdmi_connector_get_property(struct drm_connector *connector,
1007 return -EINVAL; 997 return -EINVAL;
1008} 998}
1009 999
1000static int sti_hdmi_late_register(struct drm_connector *connector)
1001{
1002 struct sti_hdmi_connector *hdmi_connector
1003 = to_sti_hdmi_connector(connector);
1004 struct sti_hdmi *hdmi = hdmi_connector->hdmi;
1005
1006 if (hdmi_debugfs_init(hdmi, hdmi->drm_dev->primary)) {
1007 DRM_ERROR("HDMI debugfs setup failed\n");
1008 return -EINVAL;
1009 }
1010
1011 return 0;
1012}
1013
1010static const struct drm_connector_funcs sti_hdmi_connector_funcs = { 1014static const struct drm_connector_funcs sti_hdmi_connector_funcs = {
1011 .dpms = drm_atomic_helper_connector_dpms,
1012 .fill_modes = drm_helper_probe_single_connector_modes, 1015 .fill_modes = drm_helper_probe_single_connector_modes,
1013 .detect = sti_hdmi_connector_detect, 1016 .detect = sti_hdmi_connector_detect,
1014 .destroy = sti_hdmi_connector_destroy, 1017 .destroy = drm_connector_cleanup,
1015 .reset = drm_atomic_helper_connector_reset, 1018 .reset = drm_atomic_helper_connector_reset,
1016 .set_property = drm_atomic_helper_connector_set_property, 1019 .set_property = drm_atomic_helper_connector_set_property,
1017 .atomic_set_property = sti_hdmi_connector_set_property, 1020 .atomic_set_property = sti_hdmi_connector_set_property,
1018 .atomic_get_property = sti_hdmi_connector_get_property, 1021 .atomic_get_property = sti_hdmi_connector_get_property,
1019 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 1022 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
1020 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 1023 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1024 .late_register = sti_hdmi_late_register,
1021}; 1025};
1022 1026
1023static struct drm_encoder *sti_hdmi_find_encoder(struct drm_device *dev) 1027static struct drm_encoder *sti_hdmi_find_encoder(struct drm_device *dev)
@@ -1078,10 +1082,6 @@ static int sti_hdmi_bind(struct device *dev, struct device *master, void *data)
1078 /* initialise property */ 1082 /* initialise property */
1079 sti_hdmi_connector_init_property(drm_dev, drm_connector); 1083 sti_hdmi_connector_init_property(drm_dev, drm_connector);
1080 1084
1081 err = drm_connector_register(drm_connector);
1082 if (err)
1083 goto err_connector;
1084
1085 err = drm_mode_connector_attach_encoder(drm_connector, encoder); 1085 err = drm_mode_connector_attach_encoder(drm_connector, encoder);
1086 if (err) { 1086 if (err) {
1087 DRM_ERROR("Failed to attach a connector to a encoder\n"); 1087 DRM_ERROR("Failed to attach a connector to a encoder\n");
@@ -1091,16 +1091,10 @@ static int sti_hdmi_bind(struct device *dev, struct device *master, void *data)
1091 /* Enable default interrupts */ 1091 /* Enable default interrupts */
1092 hdmi_write(hdmi, HDMI_DEFAULT_INT, HDMI_INT_EN); 1092 hdmi_write(hdmi, HDMI_DEFAULT_INT, HDMI_INT_EN);
1093 1093
1094 if (hdmi_debugfs_init(hdmi, drm_dev->primary))
1095 DRM_ERROR("HDMI debugfs setup failed\n");
1096
1097 return 0; 1094 return 0;
1098 1095
1099err_sysfs: 1096err_sysfs:
1100 drm_connector_unregister(drm_connector); 1097 drm_bridge_remove(bridge);
1101err_connector:
1102 drm_connector_cleanup(drm_connector);
1103
1104 return -EINVAL; 1098 return -EINVAL;
1105} 1099}
1106 1100
diff --git a/drivers/gpu/drm/sti/sti_hqvdp.c b/drivers/gpu/drm/sti/sti_hqvdp.c
index 1c06a50fddca..33d2f42550cc 100644
--- a/drivers/gpu/drm/sti/sti_hqvdp.c
+++ b/drivers/gpu/drm/sti/sti_hqvdp.c
@@ -1234,6 +1234,33 @@ static const struct drm_plane_helper_funcs sti_hqvdp_helpers_funcs = {
1234 .atomic_disable = sti_hqvdp_atomic_disable, 1234 .atomic_disable = sti_hqvdp_atomic_disable,
1235}; 1235};
1236 1236
1237static void sti_hqvdp_destroy(struct drm_plane *drm_plane)
1238{
1239 DRM_DEBUG_DRIVER("\n");
1240
1241 drm_plane_helper_disable(drm_plane);
1242 drm_plane_cleanup(drm_plane);
1243}
1244
1245static int sti_hqvdp_late_register(struct drm_plane *drm_plane)
1246{
1247 struct sti_plane *plane = to_sti_plane(drm_plane);
1248 struct sti_hqvdp *hqvdp = to_sti_hqvdp(plane);
1249
1250 return hqvdp_debugfs_init(hqvdp, drm_plane->dev->primary);
1251}
1252
1253struct drm_plane_funcs sti_hqvdp_plane_helpers_funcs = {
1254 .update_plane = drm_atomic_helper_update_plane,
1255 .disable_plane = drm_atomic_helper_disable_plane,
1256 .destroy = sti_hqvdp_destroy,
1257 .set_property = sti_plane_set_property,
1258 .reset = drm_atomic_helper_plane_reset,
1259 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
1260 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
1261 .late_register = sti_hqvdp_late_register,
1262};
1263
1237static struct drm_plane *sti_hqvdp_create(struct drm_device *drm_dev, 1264static struct drm_plane *sti_hqvdp_create(struct drm_device *drm_dev,
1238 struct device *dev, int desc) 1265 struct device *dev, int desc)
1239{ 1266{
@@ -1246,7 +1273,7 @@ static struct drm_plane *sti_hqvdp_create(struct drm_device *drm_dev,
1246 sti_hqvdp_init(hqvdp); 1273 sti_hqvdp_init(hqvdp);
1247 1274
1248 res = drm_universal_plane_init(drm_dev, &hqvdp->plane.drm_plane, 1, 1275 res = drm_universal_plane_init(drm_dev, &hqvdp->plane.drm_plane, 1,
1249 &sti_plane_helpers_funcs, 1276 &sti_hqvdp_plane_helpers_funcs,
1250 hqvdp_supported_formats, 1277 hqvdp_supported_formats,
1251 ARRAY_SIZE(hqvdp_supported_formats), 1278 ARRAY_SIZE(hqvdp_supported_formats),
1252 DRM_PLANE_TYPE_OVERLAY, NULL); 1279 DRM_PLANE_TYPE_OVERLAY, NULL);
@@ -1259,9 +1286,6 @@ static struct drm_plane *sti_hqvdp_create(struct drm_device *drm_dev,
1259 1286
1260 sti_plane_init_property(&hqvdp->plane, DRM_PLANE_TYPE_OVERLAY); 1287 sti_plane_init_property(&hqvdp->plane, DRM_PLANE_TYPE_OVERLAY);
1261 1288
1262 if (hqvdp_debugfs_init(hqvdp, drm_dev->primary))
1263 DRM_ERROR("HQVDP debugfs setup failed\n");
1264
1265 return &hqvdp->plane.drm_plane; 1289 return &hqvdp->plane.drm_plane;
1266} 1290}
1267 1291
diff --git a/drivers/gpu/drm/sti/sti_mixer.c b/drivers/gpu/drm/sti/sti_mixer.c
index 6f86f2b2b6a5..1885c7ab5a8b 100644
--- a/drivers/gpu/drm/sti/sti_mixer.c
+++ b/drivers/gpu/drm/sti/sti_mixer.c
@@ -181,7 +181,7 @@ static struct drm_info_list mixer1_debugfs_files[] = {
181 { "mixer_aux", mixer_dbg_show, 0, NULL }, 181 { "mixer_aux", mixer_dbg_show, 0, NULL },
182}; 182};
183 183
184static int mixer_debugfs_init(struct sti_mixer *mixer, struct drm_minor *minor) 184int sti_mixer_debugfs_init(struct sti_mixer *mixer, struct drm_minor *minor)
185{ 185{
186 unsigned int i; 186 unsigned int i;
187 struct drm_info_list *mixer_debugfs_files; 187 struct drm_info_list *mixer_debugfs_files;
@@ -393,8 +393,5 @@ struct sti_mixer *sti_mixer_create(struct device *dev,
393 DRM_DEBUG_DRIVER("%s created. Regs=%p\n", 393 DRM_DEBUG_DRIVER("%s created. Regs=%p\n",
394 sti_mixer_to_str(mixer), mixer->regs); 394 sti_mixer_to_str(mixer), mixer->regs);
395 395
396 if (mixer_debugfs_init(mixer, drm_dev->primary))
397 DRM_ERROR("MIXER debugfs setup failed\n");
398
399 return mixer; 396 return mixer;
400} 397}
diff --git a/drivers/gpu/drm/sti/sti_mixer.h b/drivers/gpu/drm/sti/sti_mixer.h
index 6f35fc086873..830a3c42d886 100644
--- a/drivers/gpu/drm/sti/sti_mixer.h
+++ b/drivers/gpu/drm/sti/sti_mixer.h
@@ -55,6 +55,8 @@ int sti_mixer_active_video_area(struct sti_mixer *mixer,
55 55
56void sti_mixer_set_background_status(struct sti_mixer *mixer, bool enable); 56void sti_mixer_set_background_status(struct sti_mixer *mixer, bool enable);
57 57
58int sti_mixer_debugfs_init(struct sti_mixer *mixer, struct drm_minor *minor);
59
58/* depth in Cross-bar control = z order */ 60/* depth in Cross-bar control = z order */
59#define GAM_MIXER_NB_DEPTH_LEVEL 6 61#define GAM_MIXER_NB_DEPTH_LEVEL 6
60 62
diff --git a/drivers/gpu/drm/sti/sti_plane.c b/drivers/gpu/drm/sti/sti_plane.c
index f10c98d3f012..85cee9098439 100644
--- a/drivers/gpu/drm/sti/sti_plane.c
+++ b/drivers/gpu/drm/sti/sti_plane.c
@@ -106,17 +106,9 @@ void sti_plane_update_fps(struct sti_plane *plane,
106 plane->fps_info.fips_str); 106 plane->fps_info.fips_str);
107} 107}
108 108
109static void sti_plane_destroy(struct drm_plane *drm_plane) 109int sti_plane_set_property(struct drm_plane *drm_plane,
110{ 110 struct drm_property *property,
111 DRM_DEBUG_DRIVER("\n"); 111 uint64_t val)
112
113 drm_plane_helper_disable(drm_plane);
114 drm_plane_cleanup(drm_plane);
115}
116
117static int sti_plane_set_property(struct drm_plane *drm_plane,
118 struct drm_property *property,
119 uint64_t val)
120{ 112{
121 struct drm_device *dev = drm_plane->dev; 113 struct drm_device *dev = drm_plane->dev;
122 struct sti_private *private = dev->dev_private; 114 struct sti_private *private = dev->dev_private;
@@ -170,13 +162,3 @@ void sti_plane_init_property(struct sti_plane *plane,
170 plane->drm_plane.base.id, 162 plane->drm_plane.base.id,
171 sti_plane_to_str(plane), plane->zorder); 163 sti_plane_to_str(plane), plane->zorder);
172} 164}
173
174struct drm_plane_funcs sti_plane_helpers_funcs = {
175 .update_plane = drm_atomic_helper_update_plane,
176 .disable_plane = drm_atomic_helper_disable_plane,
177 .destroy = sti_plane_destroy,
178 .set_property = sti_plane_set_property,
179 .reset = drm_atomic_helper_plane_reset,
180 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
181 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
182};
diff --git a/drivers/gpu/drm/sti/sti_plane.h b/drivers/gpu/drm/sti/sti_plane.h
index c50a3b9f5d37..39d39f5b7dd9 100644
--- a/drivers/gpu/drm/sti/sti_plane.h
+++ b/drivers/gpu/drm/sti/sti_plane.h
@@ -11,8 +11,6 @@
11#include <drm/drm_atomic_helper.h> 11#include <drm/drm_atomic_helper.h>
12#include <drm/drm_plane_helper.h> 12#include <drm/drm_plane_helper.h>
13 13
14extern struct drm_plane_funcs sti_plane_helpers_funcs;
15
16#define to_sti_plane(x) container_of(x, struct sti_plane, drm_plane) 14#define to_sti_plane(x) container_of(x, struct sti_plane, drm_plane)
17 15
18#define STI_PLANE_TYPE_SHIFT 8 16#define STI_PLANE_TYPE_SHIFT 8
@@ -83,6 +81,11 @@ const char *sti_plane_to_str(struct sti_plane *plane);
83void sti_plane_update_fps(struct sti_plane *plane, 81void sti_plane_update_fps(struct sti_plane *plane,
84 bool new_frame, 82 bool new_frame,
85 bool new_field); 83 bool new_field);
84
85int sti_plane_set_property(struct drm_plane *drm_plane,
86 struct drm_property *property,
87 uint64_t val);
88
86void sti_plane_init_property(struct sti_plane *plane, 89void sti_plane_init_property(struct sti_plane *plane,
87 enum drm_plane_type type); 90 enum drm_plane_type type);
88#endif 91#endif
diff --git a/drivers/gpu/drm/sti/sti_tvout.c b/drivers/gpu/drm/sti/sti_tvout.c
index 60fe0afa5644..e25995b35715 100644
--- a/drivers/gpu/drm/sti/sti_tvout.c
+++ b/drivers/gpu/drm/sti/sti_tvout.c
@@ -112,6 +112,7 @@ struct sti_tvout {
112 struct drm_encoder *hdmi; 112 struct drm_encoder *hdmi;
113 struct drm_encoder *hda; 113 struct drm_encoder *hda;
114 struct drm_encoder *dvo; 114 struct drm_encoder *dvo;
115 bool debugfs_registered;
115}; 116};
116 117
117struct sti_tvout_encoder { 118struct sti_tvout_encoder {
@@ -625,8 +626,37 @@ static void sti_tvout_encoder_destroy(struct drm_encoder *encoder)
625 kfree(sti_encoder); 626 kfree(sti_encoder);
626} 627}
627 628
629static int sti_tvout_late_register(struct drm_encoder *encoder)
630{
631 struct sti_tvout *tvout = to_sti_tvout(encoder);
632 int ret;
633
634 if (tvout->debugfs_registered)
635 return 0;
636
637 ret = tvout_debugfs_init(tvout, encoder->dev->primary);
638 if (ret)
639 return ret;
640
641 tvout->debugfs_registered = true;
642 return 0;
643}
644
645static void sti_tvout_early_unregister(struct drm_encoder *encoder)
646{
647 struct sti_tvout *tvout = to_sti_tvout(encoder);
648
649 if (!tvout->debugfs_registered)
650 return;
651
652 tvout_debugfs_exit(tvout, encoder->dev->primary);
653 tvout->debugfs_registered = false;
654}
655
628static const struct drm_encoder_funcs sti_tvout_encoder_funcs = { 656static const struct drm_encoder_funcs sti_tvout_encoder_funcs = {
629 .destroy = sti_tvout_encoder_destroy, 657 .destroy = sti_tvout_encoder_destroy,
658 .late_register = sti_tvout_late_register,
659 .early_unregister = sti_tvout_early_unregister,
630}; 660};
631 661
632static void sti_dvo_encoder_enable(struct drm_encoder *encoder) 662static void sti_dvo_encoder_enable(struct drm_encoder *encoder)
@@ -813,9 +843,6 @@ static int sti_tvout_bind(struct device *dev, struct device *master, void *data)
813 843
814 sti_tvout_create_encoders(drm_dev, tvout); 844 sti_tvout_create_encoders(drm_dev, tvout);
815 845
816 if (tvout_debugfs_init(tvout, drm_dev->primary))
817 DRM_ERROR("TVOUT debugfs setup failed\n");
818
819 return 0; 846 return 0;
820} 847}
821 848
@@ -823,11 +850,8 @@ static void sti_tvout_unbind(struct device *dev, struct device *master,
823 void *data) 850 void *data)
824{ 851{
825 struct sti_tvout *tvout = dev_get_drvdata(dev); 852 struct sti_tvout *tvout = dev_get_drvdata(dev);
826 struct drm_device *drm_dev = data;
827 853
828 sti_tvout_destroy_encoders(tvout); 854 sti_tvout_destroy_encoders(tvout);
829
830 tvout_debugfs_exit(tvout, drm_dev->primary);
831} 855}
832 856
833static const struct component_ops sti_tvout_ops = { 857static const struct component_ops sti_tvout_ops = {
diff --git a/drivers/gpu/drm/sti/sti_vid.c b/drivers/gpu/drm/sti/sti_vid.c
index 0132aaebe598..47634a0251fc 100644
--- a/drivers/gpu/drm/sti/sti_vid.c
+++ b/drivers/gpu/drm/sti/sti_vid.c
@@ -123,7 +123,7 @@ static struct drm_info_list vid_debugfs_files[] = {
123 { "vid", vid_dbg_show, 0, NULL }, 123 { "vid", vid_dbg_show, 0, NULL },
124}; 124};
125 125
126static int vid_debugfs_init(struct sti_vid *vid, struct drm_minor *minor) 126int vid_debugfs_init(struct sti_vid *vid, struct drm_minor *minor)
127{ 127{
128 unsigned int i; 128 unsigned int i;
129 129
@@ -220,8 +220,5 @@ struct sti_vid *sti_vid_create(struct device *dev, struct drm_device *drm_dev,
220 220
221 sti_vid_init(vid); 221 sti_vid_init(vid);
222 222
223 if (vid_debugfs_init(vid, drm_dev->primary))
224 DRM_ERROR("VID debugfs setup failed\n");
225
226 return vid; 223 return vid;
227} 224}
diff --git a/drivers/gpu/drm/sti/sti_vid.h b/drivers/gpu/drm/sti/sti_vid.h
index 6c842344f3d8..fdc90f922a05 100644
--- a/drivers/gpu/drm/sti/sti_vid.h
+++ b/drivers/gpu/drm/sti/sti_vid.h
@@ -26,4 +26,6 @@ void sti_vid_disable(struct sti_vid *vid);
26struct sti_vid *sti_vid_create(struct device *dev, struct drm_device *drm_dev, 26struct sti_vid *sti_vid_create(struct device *dev, struct drm_device *drm_dev,
27 int id, void __iomem *baseaddr); 27 int id, void __iomem *baseaddr);
28 28
29int vid_debugfs_init(struct sti_vid *vid, struct drm_minor *minor);
30
29#endif 31#endif
diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c
index 68e9d85085fb..9a67f927a53e 100644
--- a/drivers/gpu/drm/sun4i/sun4i_drv.c
+++ b/drivers/gpu/drm/sun4i/sun4i_drv.c
@@ -24,34 +24,6 @@
24#include "sun4i_layer.h" 24#include "sun4i_layer.h"
25#include "sun4i_tcon.h" 25#include "sun4i_tcon.h"
26 26
27static int sun4i_drv_connector_plug_all(struct drm_device *drm)
28{
29 struct drm_connector *connector, *failed;
30 int ret;
31
32 mutex_lock(&drm->mode_config.mutex);
33 list_for_each_entry(connector, &drm->mode_config.connector_list, head) {
34 ret = drm_connector_register(connector);
35 if (ret) {
36 failed = connector;
37 goto err;
38 }
39 }
40 mutex_unlock(&drm->mode_config.mutex);
41 return 0;
42
43err:
44 list_for_each_entry(connector, &drm->mode_config.connector_list, head) {
45 if (failed == connector)
46 break;
47
48 drm_connector_unregister(connector);
49 }
50 mutex_unlock(&drm->mode_config.mutex);
51
52 return ret;
53}
54
55static int sun4i_drv_enable_vblank(struct drm_device *drm, unsigned int pipe) 27static int sun4i_drv_enable_vblank(struct drm_device *drm, unsigned int pipe)
56{ 28{
57 struct sun4i_drv *drv = drm->dev_private; 29 struct sun4i_drv *drv = drm->dev_private;
@@ -135,10 +107,6 @@ static int sun4i_drv_bind(struct device *dev)
135 if (!drm) 107 if (!drm)
136 return -ENOMEM; 108 return -ENOMEM;
137 109
138 ret = drm_dev_set_unique(drm, dev_name(drm->dev));
139 if (ret)
140 goto free_drm;
141
142 drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); 110 drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL);
143 if (!drv) { 111 if (!drv) {
144 ret = -ENOMEM; 112 ret = -ENOMEM;
@@ -187,14 +155,8 @@ static int sun4i_drv_bind(struct device *dev)
187 if (ret) 155 if (ret)
188 goto free_drm; 156 goto free_drm;
189 157
190 ret = sun4i_drv_connector_plug_all(drm);
191 if (ret)
192 goto unregister_drm;
193
194 return 0; 158 return 0;
195 159
196unregister_drm:
197 drm_dev_unregister(drm);
198free_drm: 160free_drm:
199 drm_dev_unref(drm); 161 drm_dev_unref(drm);
200 return ret; 162 return ret;
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
index 308e197908fc..d27809372d54 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c
@@ -541,7 +541,6 @@ static struct drm_driver tilcdc_driver = {
541 .load = tilcdc_load, 541 .load = tilcdc_load,
542 .unload = tilcdc_unload, 542 .unload = tilcdc_unload,
543 .lastclose = tilcdc_lastclose, 543 .lastclose = tilcdc_lastclose,
544 .set_busid = drm_platform_set_busid,
545 .irq_handler = tilcdc_irq, 544 .irq_handler = tilcdc_irq,
546 .irq_preinstall = tilcdc_irq_preinstall, 545 .irq_preinstall = tilcdc_irq_preinstall,
547 .irq_postinstall = tilcdc_irq_postinstall, 546 .irq_postinstall = tilcdc_irq_postinstall,
diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
index 58b8fc036332..9e88231b8906 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -176,7 +176,6 @@ static int vc4_drm_bind(struct device *dev)
176{ 176{
177 struct platform_device *pdev = to_platform_device(dev); 177 struct platform_device *pdev = to_platform_device(dev);
178 struct drm_device *drm; 178 struct drm_device *drm;
179 struct drm_connector *connector;
180 struct vc4_dev *vc4; 179 struct vc4_dev *vc4;
181 int ret = 0; 180 int ret = 0;
182 181
@@ -211,22 +210,10 @@ static int vc4_drm_bind(struct device *dev)
211 if (ret < 0) 210 if (ret < 0)
212 goto unbind_all; 211 goto unbind_all;
213 212
214 /* Connector registration has to occur after DRM device
215 * registration, because it creates sysfs entries based on the
216 * DRM device.
217 */
218 list_for_each_entry(connector, &drm->mode_config.connector_list, head) {
219 ret = drm_connector_register(connector);
220 if (ret)
221 goto unregister;
222 }
223
224 vc4_kms_load(drm); 213 vc4_kms_load(drm);
225 214
226 return 0; 215 return 0;
227 216
228unregister:
229 drm_dev_unregister(drm);
230unbind_all: 217unbind_all:
231 component_unbind_all(dev, drm); 218 component_unbind_all(dev, drm);
232gem_destroy: 219gem_destroy:
diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
index 1b4cc8b27080..35ea5d02a827 100644
--- a/drivers/gpu/drm/vgem/vgem_drv.c
+++ b/drivers/gpu/drm/vgem/vgem_drv.c
@@ -260,8 +260,6 @@ static int __init vgem_init(void)
260 goto out; 260 goto out;
261 } 261 }
262 262
263 drm_dev_set_unique(vgem_device, "vgem");
264
265 ret = drm_dev_register(vgem_device, 0); 263 ret = drm_dev_register(vgem_device, 0);
266 264
267 if (ret) 265 if (ret)
diff --git a/drivers/gpu/drm/via/via_mm.c b/drivers/gpu/drm/via/via_mm.c
index 4f20742e7788..a04ef1c992d9 100644
--- a/drivers/gpu/drm/via/via_mm.c
+++ b/drivers/gpu/drm/via/via_mm.c
@@ -208,7 +208,7 @@ void via_reclaim_buffers_locked(struct drm_device *dev,
208 struct via_file_private *file_priv = file->driver_priv; 208 struct via_file_private *file_priv = file->driver_priv;
209 struct via_memblock *entry, *next; 209 struct via_memblock *entry, *next;
210 210
211 if (!(file->minor->master && file->master->lock.hw_lock)) 211 if (!(dev->master && file->master->lock.hw_lock))
212 return; 212 return;
213 213
214 drm_legacy_idlelock_take(&file->master->lock); 214 drm_legacy_idlelock_take(&file->master->lock);
diff --git a/drivers/gpu/drm/virtio/virtgpu_drm_bus.c b/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
index 88a39165edd5..7f0e93f87a55 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
@@ -27,16 +27,6 @@
27 27
28#include "virtgpu_drv.h" 28#include "virtgpu_drv.h"
29 29
30int drm_virtio_set_busid(struct drm_device *dev, struct drm_master *master)
31{
32 struct pci_dev *pdev = dev->pdev;
33
34 if (pdev) {
35 return drm_pci_set_busid(dev, master);
36 }
37 return 0;
38}
39
40static void virtio_pci_kick_out_firmware_fb(struct pci_dev *pci_dev) 30static void virtio_pci_kick_out_firmware_fb(struct pci_dev *pci_dev)
41{ 31{
42 struct apertures_struct *ap; 32 struct apertures_struct *ap;
diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.c b/drivers/gpu/drm/virtio/virtgpu_drv.c
index 5820b7020ae5..c13f70cfc461 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.c
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.c
@@ -117,7 +117,6 @@ static const struct file_operations virtio_gpu_driver_fops = {
117 117
118static struct drm_driver driver = { 118static struct drm_driver driver = {
119 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | DRIVER_RENDER | DRIVER_ATOMIC, 119 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | DRIVER_RENDER | DRIVER_ATOMIC,
120 .set_busid = drm_virtio_set_busid,
121 .load = virtio_gpu_driver_load, 120 .load = virtio_gpu_driver_load,
122 .unload = virtio_gpu_driver_unload, 121 .unload = virtio_gpu_driver_unload,
123 .open = virtio_gpu_driver_open, 122 .open = virtio_gpu_driver_open,
diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h
index acf556a35cb2..b18ef3111f0c 100644
--- a/drivers/gpu/drm/virtio/virtgpu_drv.h
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.h
@@ -49,7 +49,6 @@
49#define DRIVER_PATCHLEVEL 1 49#define DRIVER_PATCHLEVEL 1
50 50
51/* virtgpu_drm_bus.c */ 51/* virtgpu_drm_bus.c */
52int drm_virtio_set_busid(struct drm_device *dev, struct drm_master *master);
53int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev); 52int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev);
54 53
55struct virtio_gpu_object { 54struct virtio_gpu_object {
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 9fcd8200d485..60646644bef3 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -1049,7 +1049,7 @@ static struct vmw_master *vmw_master_check(struct drm_device *dev,
1049 if (unlikely(ret != 0)) 1049 if (unlikely(ret != 0))
1050 return ERR_PTR(-ERESTARTSYS); 1050 return ERR_PTR(-ERESTARTSYS);
1051 1051
1052 if (file_priv->is_master) { 1052 if (drm_is_current_master(file_priv)) {
1053 mutex_unlock(&dev->master_mutex); 1053 mutex_unlock(&dev->master_mutex);
1054 return NULL; 1054 return NULL;
1055 } 1055 }
@@ -1228,8 +1228,7 @@ static int vmw_master_set(struct drm_device *dev,
1228} 1228}
1229 1229
1230static void vmw_master_drop(struct drm_device *dev, 1230static void vmw_master_drop(struct drm_device *dev,
1231 struct drm_file *file_priv, 1231 struct drm_file *file_priv)
1232 bool from_release)
1233{ 1232{
1234 struct vmw_private *dev_priv = vmw_priv(dev); 1233 struct vmw_private *dev_priv = vmw_priv(dev);
1235 struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv); 1234 struct vmw_fpriv *vmw_fp = vmw_fpriv(file_priv);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 1980e2a28265..9a90f824814e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -32,6 +32,7 @@
32#include <drm/drmP.h> 32#include <drm/drmP.h>
33#include <drm/vmwgfx_drm.h> 33#include <drm/vmwgfx_drm.h>
34#include <drm/drm_hashtab.h> 34#include <drm/drm_hashtab.h>
35#include <drm/drm_auth.h>
35#include <linux/suspend.h> 36#include <linux/suspend.h>
36#include <drm/ttm/ttm_bo_driver.h> 37#include <drm/ttm/ttm_bo_driver.h>
37#include <drm/ttm/ttm_object.h> 38#include <drm/ttm/ttm_object.h>
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 04310cb08111..cf918e3e6afb 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -86,6 +86,7 @@ struct drm_local_map;
86struct drm_device_dma; 86struct drm_device_dma;
87struct drm_dma_handle; 87struct drm_dma_handle;
88struct drm_gem_object; 88struct drm_gem_object;
89struct drm_master;
89 90
90struct device_node; 91struct device_node;
91struct videomode; 92struct videomode;
@@ -303,8 +304,6 @@ struct drm_prime_file_private {
303/** File private data */ 304/** File private data */
304struct drm_file { 305struct drm_file {
305 unsigned authenticated :1; 306 unsigned authenticated :1;
306 /* Whether we're master for a minor. Protected by master_mutex */
307 unsigned is_master :1;
308 /* true when the client has asked us to expose stereo 3D mode flags */ 307 /* true when the client has asked us to expose stereo 3D mode flags */
309 unsigned stereo_allowed :1; 308 unsigned stereo_allowed :1;
310 /* 309 /*
@@ -315,10 +314,10 @@ struct drm_file {
315 /* true if client understands atomic properties */ 314 /* true if client understands atomic properties */
316 unsigned atomic:1; 315 unsigned atomic:1;
317 /* 316 /*
318 * This client is allowed to gain master privileges for @master. 317 * This client is the creator of @master.
319 * Protected by struct drm_device::master_mutex. 318 * Protected by struct drm_device::master_mutex.
320 */ 319 */
321 unsigned allowed_master:1; 320 unsigned is_master:1;
322 321
323 struct pid *pid; 322 struct pid *pid;
324 kuid_t uid; 323 kuid_t uid;
@@ -336,7 +335,7 @@ struct drm_file {
336 void *driver_priv; 335 void *driver_priv;
337 336
338 struct drm_master *master; /* master this node is currently associated with 337 struct drm_master *master; /* master this node is currently associated with
339 N.B. not always minor->master */ 338 N.B. not always dev->master */
340 /** 339 /**
341 * fbs - List of framebuffers associated with this file. 340 * fbs - List of framebuffers associated with this file.
342 * 341 *
@@ -375,27 +374,6 @@ struct drm_lock_data {
375 int idle_has_lock; 374 int idle_has_lock;
376}; 375};
377 376
378/**
379 * struct drm_master - drm master structure
380 *
381 * @refcount: Refcount for this master object.
382 * @minor: Link back to minor char device we are master for. Immutable.
383 * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
384 * @unique_len: Length of unique field. Protected by drm_global_mutex.
385 * @magic_map: Map of used authentication tokens. Protected by struct_mutex.
386 * @lock: DRI lock information.
387 * @driver_priv: Pointer to driver-private information.
388 */
389struct drm_master {
390 struct kref refcount;
391 struct drm_minor *minor;
392 char *unique;
393 int unique_len;
394 struct idr magic_map;
395 struct drm_lock_data lock;
396 void *driver_priv;
397};
398
399/* Flags and return codes for get_vblank_timestamp() driver function. */ 377/* Flags and return codes for get_vblank_timestamp() driver function. */
400#define DRM_CALLED_FROM_VBLIRQ 1 378#define DRM_CALLED_FROM_VBLIRQ 1
401#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0) 379#define DRM_VBLANKTIME_SCANOUTPOS_METHOD (1 << 0)
@@ -570,8 +548,7 @@ struct drm_driver {
570 548
571 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv, 549 int (*master_set)(struct drm_device *dev, struct drm_file *file_priv,
572 bool from_open); 550 bool from_open);
573 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv, 551 void (*master_drop)(struct drm_device *dev, struct drm_file *file_priv);
574 bool from_release);
575 552
576 int (*debugfs_init)(struct drm_minor *minor); 553 int (*debugfs_init)(struct drm_minor *minor);
577 void (*debugfs_cleanup)(struct drm_minor *minor); 554 void (*debugfs_cleanup)(struct drm_minor *minor);
@@ -705,9 +682,6 @@ struct drm_minor {
705 682
706 struct list_head debugfs_list; 683 struct list_head debugfs_list;
707 struct mutex debugfs_lock; /* Protects debugfs_list. */ 684 struct mutex debugfs_lock; /* Protects debugfs_list. */
708
709 /* currently active master for this node. Protected by master_mutex */
710 struct drm_master *master;
711}; 685};
712 686
713 687
@@ -756,6 +730,10 @@ struct drm_device {
756 struct drm_minor *control; /**< Control node */ 730 struct drm_minor *control; /**< Control node */
757 struct drm_minor *primary; /**< Primary node */ 731 struct drm_minor *primary; /**< Primary node */
758 struct drm_minor *render; /**< Render node */ 732 struct drm_minor *render; /**< Render node */
733
734 /* currently active master for this device. Protected by master_mutex */
735 struct drm_master *master;
736
759 atomic_t unplugged; /**< Flag whether dev is dead */ 737 atomic_t unplugged; /**< Flag whether dev is dead */
760 struct inode *anon_inode; /**< inode for private address-space */ 738 struct inode *anon_inode; /**< inode for private address-space */
761 char *unique; /**< unique name of the device */ 739 char *unique; /**< unique name of the device */
@@ -925,7 +903,6 @@ int drm_open(struct inode *inode, struct file *filp);
925ssize_t drm_read(struct file *filp, char __user *buffer, 903ssize_t drm_read(struct file *filp, char __user *buffer,
926 size_t count, loff_t *offset); 904 size_t count, loff_t *offset);
927int drm_release(struct inode *inode, struct file *filp); 905int drm_release(struct inode *inode, struct file *filp);
928int drm_new_set_master(struct drm_device *dev, struct drm_file *fpriv);
929unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait); 906unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait);
930int drm_event_reserve_init_locked(struct drm_device *dev, 907int drm_event_reserve_init_locked(struct drm_device *dev,
931 struct drm_file *file_priv, 908 struct drm_file *file_priv,
@@ -1012,14 +989,10 @@ static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc
1012extern void drm_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe); 989extern void drm_vblank_pre_modeset(struct drm_device *dev, unsigned int pipe);
1013extern void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe); 990extern void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe);
1014 991
1015 /* Stub support (drm_stub.h) */ 992/* drm_drv.c */
1016extern struct drm_master *drm_master_get(struct drm_master *master); 993void drm_put_dev(struct drm_device *dev);
1017extern void drm_master_put(struct drm_master **master); 994void drm_unplug_dev(struct drm_device *dev);
1018
1019extern void drm_put_dev(struct drm_device *dev);
1020extern void drm_unplug_dev(struct drm_device *dev);
1021extern unsigned int drm_debug; 995extern unsigned int drm_debug;
1022extern bool drm_atomic;
1023 996
1024 /* Debugfs support */ 997 /* Debugfs support */
1025#if defined(CONFIG_DEBUG_FS) 998#if defined(CONFIG_DEBUG_FS)
@@ -1070,11 +1043,13 @@ extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1070 1043
1071struct drm_device *drm_dev_alloc(struct drm_driver *driver, 1044struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1072 struct device *parent); 1045 struct device *parent);
1046int drm_dev_init(struct drm_device *dev,
1047 struct drm_driver *driver,
1048 struct device *parent);
1073void drm_dev_ref(struct drm_device *dev); 1049void drm_dev_ref(struct drm_device *dev);
1074void drm_dev_unref(struct drm_device *dev); 1050void drm_dev_unref(struct drm_device *dev);
1075int drm_dev_register(struct drm_device *dev, unsigned long flags); 1051int drm_dev_register(struct drm_device *dev, unsigned long flags);
1076void drm_dev_unregister(struct drm_device *dev); 1052void drm_dev_unregister(struct drm_device *dev);
1077int drm_dev_set_unique(struct drm_device *dev, const char *name);
1078 1053
1079struct drm_minor *drm_minor_acquire(unsigned int minor_id); 1054struct drm_minor *drm_minor_acquire(unsigned int minor_id);
1080void drm_minor_release(struct drm_minor *minor); 1055void drm_minor_release(struct drm_minor *minor);
@@ -1127,7 +1102,6 @@ extern int drm_pcie_get_max_link_width(struct drm_device *dev, u32 *mlw);
1127 1102
1128/* platform section */ 1103/* platform section */
1129extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device); 1104extern int drm_platform_init(struct drm_driver *driver, struct platform_device *platform_device);
1130extern int drm_platform_set_busid(struct drm_device *d, struct drm_master *m);
1131 1105
1132/* returns true if currently okay to sleep */ 1106/* returns true if currently okay to sleep */
1133static __inline__ bool drm_can_sleep(void) 1107static __inline__ bool drm_can_sleep(void)
diff --git a/include/drm/drm_auth.h b/include/drm/drm_auth.h
new file mode 100644
index 000000000000..610223b0481b
--- /dev/null
+++ b/include/drm/drm_auth.h
@@ -0,0 +1,59 @@
1/*
2 * Internal Header for the Direct Rendering Manager
3 *
4 * Copyright 2016 Intel Corporation
5 *
6 * Author: Daniel Vetter <daniel.vetter@ffwll.ch>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#ifndef _DRM_AUTH_H_
29#define _DRM_AUTH_H_
30
31/**
32 * struct drm_master - drm master structure
33 *
34 * @refcount: Refcount for this master object.
35 * @dev: Link back to the DRM device
36 * @unique: Unique identifier: e.g. busid. Protected by drm_global_mutex.
37 * @unique_len: Length of unique field. Protected by drm_global_mutex.
38 * @magic_map: Map of used authentication tokens. Protected by struct_mutex.
39 * @lock: DRI lock information.
40 * @driver_priv: Pointer to driver-private information.
41 *
42 * Note that master structures are only relevant for the legacy/primary device
43 * nodes, hence there can only be one per device, not one per drm_minor.
44 */
45struct drm_master {
46 struct kref refcount;
47 struct drm_device *dev;
48 char *unique;
49 int unique_len;
50 struct idr magic_map;
51 struct drm_lock_data lock;
52 void *driver_priv;
53};
54
55struct drm_master *drm_master_get(struct drm_master *master);
56void drm_master_put(struct drm_master **master);
57bool drm_is_current_master(struct drm_file *fpriv);
58
59#endif
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 914baa8c161d..f5469d3a46dd 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -44,6 +44,7 @@ struct drm_file;
44struct drm_clip_rect; 44struct drm_clip_rect;
45struct device_node; 45struct device_node;
46struct fence; 46struct fence;
47struct edid;
47 48
48struct drm_mode_object { 49struct drm_mode_object {
49 uint32_t id; 50 uint32_t id;
@@ -704,6 +705,32 @@ struct drm_crtc_funcs {
704 const struct drm_crtc_state *state, 705 const struct drm_crtc_state *state,
705 struct drm_property *property, 706 struct drm_property *property,
706 uint64_t *val); 707 uint64_t *val);
708
709 /**
710 * @late_register:
711 *
712 * This optional hook can be used to register additional userspace
713 * interfaces attached to the crtc like debugfs interfaces.
714 * It is called late in the driver load sequence from drm_dev_register().
715 * Everything added from this callback should be unregistered in
716 * the early_unregister callback.
717 *
718 * Returns:
719 *
720 * 0 on success, or a negative error code on failure.
721 */
722 int (*late_register)(struct drm_crtc *crtc);
723
724 /**
725 * @early_unregister:
726 *
727 * This optional hook should be used to unregister the additional
728 * userspace interfaces attached to the crtc from
729 * late_unregister(). It is called from drm_dev_unregister(),
730 * early in the driver unload sequence to disable userspace access
731 * before data structures are torndown.
732 */
733 void (*early_unregister)(struct drm_crtc *crtc);
707}; 734};
708 735
709/** 736/**
@@ -957,6 +984,33 @@ struct drm_connector_funcs {
957 uint64_t val); 984 uint64_t val);
958 985
959 /** 986 /**
987 * @late_register:
988 *
989 * This optional hook can be used to register additional userspace
990 * interfaces attached to the connector, light backlight control, i2c,
991 * DP aux or similar interfaces. It is called late in the driver load
992 * sequence from drm_connector_register() when registering all the
993 * core drm connector interfaces. Everything added from this callback
994 * should be unregistered in the early_unregister callback.
995 *
996 * Returns:
997 *
998 * 0 on success, or a negative error code on failure.
999 */
1000 int (*late_register)(struct drm_connector *connector);
1001
1002 /**
1003 * @early_unregister:
1004 *
1005 * This optional hook should be used to unregister the additional
1006 * userspace interfaces attached to the connector from
1007 * late_unregister(). It is called from drm_connector_unregister(),
1008 * early in the driver unload sequence to disable userspace access
1009 * before data structures are torndown.
1010 */
1011 void (*early_unregister)(struct drm_connector *connector);
1012
1013 /**
960 * @destroy: 1014 * @destroy:
961 * 1015 *
962 * Clean up connector resources. This is called at driver unload time 1016 * Clean up connector resources. This is called at driver unload time
@@ -1100,6 +1154,32 @@ struct drm_encoder_funcs {
1100 * hotplugged in DRM. 1154 * hotplugged in DRM.
1101 */ 1155 */
1102 void (*destroy)(struct drm_encoder *encoder); 1156 void (*destroy)(struct drm_encoder *encoder);
1157
1158 /**
1159 * @late_register:
1160 *
1161 * This optional hook can be used to register additional userspace
1162 * interfaces attached to the encoder like debugfs interfaces.
1163 * It is called late in the driver load sequence from drm_dev_register().
1164 * Everything added from this callback should be unregistered in
1165 * the early_unregister callback.
1166 *
1167 * Returns:
1168 *
1169 * 0 on success, or a negative error code on failure.
1170 */
1171 int (*late_register)(struct drm_encoder *encoder);
1172
1173 /**
1174 * @early_unregister:
1175 *
1176 * This optional hook should be used to unregister the additional
1177 * userspace interfaces attached to the encoder from
1178 * late_unregister(). It is called from drm_dev_unregister(),
1179 * early in the driver unload sequence to disable userspace access
1180 * before data structures are torndown.
1181 */
1182 void (*early_unregister)(struct drm_encoder *encoder);
1103}; 1183};
1104 1184
1105#define DRM_CONNECTOR_MAX_ENCODER 3 1185#define DRM_CONNECTOR_MAX_ENCODER 3
@@ -1166,6 +1246,7 @@ struct drm_encoder {
1166 * @interlace_allowed: can this connector handle interlaced modes? 1246 * @interlace_allowed: can this connector handle interlaced modes?
1167 * @doublescan_allowed: can this connector handle doublescan? 1247 * @doublescan_allowed: can this connector handle doublescan?
1168 * @stereo_allowed: can this connector handle stereo modes? 1248 * @stereo_allowed: can this connector handle stereo modes?
1249 * @registered: is this connector exposed (registered) with userspace?
1169 * @modes: modes available on this connector (from fill_modes() + user) 1250 * @modes: modes available on this connector (from fill_modes() + user)
1170 * @status: one of the drm_connector_status enums (connected, not, or unknown) 1251 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1171 * @probed_modes: list of modes derived directly from the display 1252 * @probed_modes: list of modes derived directly from the display
@@ -1222,6 +1303,7 @@ struct drm_connector {
1222 bool interlace_allowed; 1303 bool interlace_allowed;
1223 bool doublescan_allowed; 1304 bool doublescan_allowed;
1224 bool stereo_allowed; 1305 bool stereo_allowed;
1306 bool registered;
1225 struct list_head modes; /* list of modes on this connector */ 1307 struct list_head modes; /* list of modes on this connector */
1226 1308
1227 enum drm_connector_status status; 1309 enum drm_connector_status status;
@@ -1541,6 +1623,31 @@ struct drm_plane_funcs {
1541 const struct drm_plane_state *state, 1623 const struct drm_plane_state *state,
1542 struct drm_property *property, 1624 struct drm_property *property,
1543 uint64_t *val); 1625 uint64_t *val);
1626 /**
1627 * @late_register:
1628 *
1629 * This optional hook can be used to register additional userspace
1630 * interfaces attached to the plane like debugfs interfaces.
1631 * It is called late in the driver load sequence from drm_dev_register().
1632 * Everything added from this callback should be unregistered in
1633 * the early_unregister callback.
1634 *
1635 * Returns:
1636 *
1637 * 0 on success, or a negative error code on failure.
1638 */
1639 int (*late_register)(struct drm_plane *plane);
1640
1641 /**
1642 * @early_unregister:
1643 *
1644 * This optional hook should be used to unregister the additional
1645 * userspace interfaces attached to the plane from
1646 * late_unregister(). It is called from drm_dev_unregister(),
1647 * early in the driver unload sequence to disable userspace access
1648 * before data structures are torndown.
1649 */
1650 void (*early_unregister)(struct drm_plane *plane);
1544}; 1651};
1545 1652
1546enum drm_plane_type { 1653enum drm_plane_type {
@@ -2467,12 +2574,10 @@ static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2467 return 1 << drm_crtc_index(crtc); 2574 return 1 << drm_crtc_index(crtc);
2468} 2575}
2469 2576
2470extern void drm_connector_ida_init(void); 2577int drm_connector_init(struct drm_device *dev,
2471extern void drm_connector_ida_destroy(void); 2578 struct drm_connector *connector,
2472extern int drm_connector_init(struct drm_device *dev, 2579 const struct drm_connector_funcs *funcs,
2473 struct drm_connector *connector, 2580 int connector_type);
2474 const struct drm_connector_funcs *funcs,
2475 int connector_type);
2476int drm_connector_register(struct drm_connector *connector); 2581int drm_connector_register(struct drm_connector *connector);
2477void drm_connector_unregister(struct drm_connector *connector); 2582void drm_connector_unregister(struct drm_connector *connector);
2478 2583
@@ -2486,22 +2591,6 @@ static inline unsigned drm_connector_index(struct drm_connector *connector)
2486extern int drm_connector_register_all(struct drm_device *dev); 2591extern int drm_connector_register_all(struct drm_device *dev);
2487extern void drm_connector_unregister_all(struct drm_device *dev); 2592extern void drm_connector_unregister_all(struct drm_device *dev);
2488 2593
2489extern int drm_bridge_add(struct drm_bridge *bridge);
2490extern void drm_bridge_remove(struct drm_bridge *bridge);
2491extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2492extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
2493
2494bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2495 const struct drm_display_mode *mode,
2496 struct drm_display_mode *adjusted_mode);
2497void drm_bridge_disable(struct drm_bridge *bridge);
2498void drm_bridge_post_disable(struct drm_bridge *bridge);
2499void drm_bridge_mode_set(struct drm_bridge *bridge,
2500 struct drm_display_mode *mode,
2501 struct drm_display_mode *adjusted_mode);
2502void drm_bridge_pre_enable(struct drm_bridge *bridge);
2503void drm_bridge_enable(struct drm_bridge *bridge);
2504
2505extern __printf(5, 6) 2594extern __printf(5, 6)
2506int drm_encoder_init(struct drm_device *dev, 2595int drm_encoder_init(struct drm_device *dev,
2507 struct drm_encoder *encoder, 2596 struct drm_encoder *encoder,
@@ -2563,14 +2652,8 @@ static inline unsigned int drm_plane_index(struct drm_plane *plane)
2563} 2652}
2564extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx); 2653extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
2565extern void drm_plane_force_disable(struct drm_plane *plane); 2654extern void drm_plane_force_disable(struct drm_plane *plane);
2566extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2567 u32 format);
2568extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, 2655extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2569 int *hdisplay, int *vdisplay); 2656 int *hdisplay, int *vdisplay);
2570extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2571 int x, int y,
2572 const struct drm_display_mode *mode,
2573 const struct drm_framebuffer *fb);
2574 2657
2575extern void drm_encoder_cleanup(struct drm_encoder *encoder); 2658extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2576 2659
@@ -2581,16 +2664,6 @@ extern const char *drm_get_dvi_i_subconnector_name(int val);
2581extern const char *drm_get_dvi_i_select_name(int val); 2664extern const char *drm_get_dvi_i_select_name(int val);
2582extern const char *drm_get_tv_subconnector_name(int val); 2665extern const char *drm_get_tv_subconnector_name(int val);
2583extern const char *drm_get_tv_select_name(int val); 2666extern const char *drm_get_tv_select_name(int val);
2584extern void drm_fb_release(struct drm_file *file_priv);
2585extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2586 struct drm_file *file_priv);
2587extern bool drm_probe_ddc(struct i2c_adapter *adapter);
2588extern struct edid *drm_get_edid(struct drm_connector *connector,
2589 struct i2c_adapter *adapter);
2590extern struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2591 struct i2c_adapter *adapter);
2592extern struct edid *drm_edid_duplicate(const struct edid *edid);
2593extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2594extern void drm_mode_config_init(struct drm_device *dev); 2667extern void drm_mode_config_init(struct drm_device *dev);
2595extern void drm_mode_config_reset(struct drm_device *dev); 2668extern void drm_mode_config_reset(struct drm_device *dev);
2596extern void drm_mode_config_cleanup(struct drm_device *dev); 2669extern void drm_mode_config_cleanup(struct drm_device *dev);
@@ -2614,13 +2687,6 @@ static inline bool drm_property_type_is(struct drm_property *property,
2614 return property->flags & type; 2687 return property->flags & type;
2615} 2688}
2616 2689
2617static inline bool drm_property_type_valid(struct drm_property *property)
2618{
2619 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2620 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2621 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2622}
2623
2624extern int drm_object_property_set_value(struct drm_mode_object *obj, 2690extern int drm_object_property_set_value(struct drm_mode_object *obj,
2625 struct drm_property *property, 2691 struct drm_property *property,
2626 uint64_t val); 2692 uint64_t val);
@@ -2678,86 +2744,15 @@ extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
2678extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev); 2744extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
2679extern int drm_mode_create_dirty_info_property(struct drm_device *dev); 2745extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
2680extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev); 2746extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
2681extern bool drm_property_change_valid_get(struct drm_property *property,
2682 uint64_t value, struct drm_mode_object **ref);
2683extern void drm_property_change_valid_put(struct drm_property *property,
2684 struct drm_mode_object *ref);
2685 2747
2686extern int drm_mode_connector_attach_encoder(struct drm_connector *connector, 2748extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2687 struct drm_encoder *encoder); 2749 struct drm_encoder *encoder);
2688extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, 2750extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
2689 int gamma_size); 2751 int gamma_size);
2690extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2691 uint32_t id, uint32_t type);
2692void drm_mode_object_reference(struct drm_mode_object *obj);
2693void drm_mode_object_unreference(struct drm_mode_object *obj);
2694 2752
2695/* IOCTLs */
2696extern int drm_mode_getresources(struct drm_device *dev,
2697 void *data, struct drm_file *file_priv);
2698extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2699 struct drm_file *file_priv);
2700extern int drm_mode_getcrtc(struct drm_device *dev,
2701 void *data, struct drm_file *file_priv);
2702extern int drm_mode_getconnector(struct drm_device *dev,
2703 void *data, struct drm_file *file_priv);
2704extern int drm_mode_set_config_internal(struct drm_mode_set *set); 2753extern int drm_mode_set_config_internal(struct drm_mode_set *set);
2705extern int drm_mode_setcrtc(struct drm_device *dev, 2754
2706 void *data, struct drm_file *file_priv);
2707extern int drm_mode_getplane(struct drm_device *dev,
2708 void *data, struct drm_file *file_priv);
2709extern int drm_mode_setplane(struct drm_device *dev,
2710 void *data, struct drm_file *file_priv);
2711extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2712 void *data, struct drm_file *file_priv);
2713extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2714 void *data, struct drm_file *file_priv);
2715extern int drm_mode_addfb(struct drm_device *dev,
2716 void *data, struct drm_file *file_priv);
2717extern int drm_mode_addfb2(struct drm_device *dev,
2718 void *data, struct drm_file *file_priv);
2719extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); 2755extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
2720extern int drm_mode_rmfb(struct drm_device *dev,
2721 void *data, struct drm_file *file_priv);
2722extern int drm_mode_getfb(struct drm_device *dev,
2723 void *data, struct drm_file *file_priv);
2724extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2725 void *data, struct drm_file *file_priv);
2726
2727extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2728 void *data, struct drm_file *file_priv);
2729extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2730 void *data, struct drm_file *file_priv);
2731extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2732 void *data, struct drm_file *file_priv);
2733extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2734 void *data, struct drm_file *file_priv);
2735extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2736 void *data, struct drm_file *file_priv);
2737extern int drm_mode_getencoder(struct drm_device *dev,
2738 void *data, struct drm_file *file_priv);
2739extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2740 void *data, struct drm_file *file_priv);
2741extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2742 void *data, struct drm_file *file_priv);
2743extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2744extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2745extern bool drm_detect_hdmi_monitor(struct edid *edid);
2746extern bool drm_detect_monitor_audio(struct edid *edid);
2747extern bool drm_rgb_quant_range_selectable(struct edid *edid);
2748extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2749 void *data, struct drm_file *file_priv);
2750extern int drm_add_modes_noedid(struct drm_connector *connector,
2751 int hdisplay, int vdisplay);
2752extern void drm_set_preferred_mode(struct drm_connector *connector,
2753 int hpref, int vpref);
2754
2755extern int drm_edid_header_is_valid(const u8 *raw_edid);
2756extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2757 bool *edid_corrupt);
2758extern bool drm_edid_is_valid(struct edid *edid);
2759extern void drm_edid_get_monitor_name(struct edid *edid, char *name,
2760 int buflen);
2761 2756
2762extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 2757extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2763 char topology[8]); 2758 char topology[8]);
@@ -2765,25 +2760,10 @@ extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2765 char topology[8]); 2760 char topology[8]);
2766extern void drm_mode_put_tile_group(struct drm_device *dev, 2761extern void drm_mode_put_tile_group(struct drm_device *dev,
2767 struct drm_tile_group *tg); 2762 struct drm_tile_group *tg);
2768struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2769 int hsize, int vsize, int fresh,
2770 bool rb);
2771 2763
2772extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2773 void *data, struct drm_file *file_priv);
2774extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2775 void *data, struct drm_file *file_priv);
2776extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2777 void *data, struct drm_file *file_priv);
2778extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2779 struct drm_file *file_priv);
2780extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2781 struct drm_file *file_priv);
2782extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane, 2764extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2783 struct drm_property *property, 2765 struct drm_property *property,
2784 uint64_t value); 2766 uint64_t value);
2785extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2786 void *data, struct drm_file *file_priv);
2787 2767
2788extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, 2768extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2789 unsigned int supported_rotations); 2769 unsigned int supported_rotations);
@@ -2794,6 +2774,10 @@ extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2794 bool has_ctm, 2774 bool has_ctm,
2795 uint gamma_lut_size); 2775 uint gamma_lut_size);
2796/* Helpers */ 2776/* Helpers */
2777struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2778 uint32_t id, uint32_t type);
2779void drm_mode_object_reference(struct drm_mode_object *obj);
2780void drm_mode_object_unreference(struct drm_mode_object *obj);
2797 2781
2798static inline struct drm_plane *drm_plane_find(struct drm_device *dev, 2782static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2799 uint32_t id) 2783 uint32_t id)
@@ -2959,4 +2943,50 @@ assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2959 &fb->head != (&(dev)->mode_config.fb_list); \ 2943 &fb->head != (&(dev)->mode_config.fb_list); \
2960 fb = list_next_entry(fb, head)) 2944 fb = list_next_entry(fb, head))
2961 2945
2946/* drm_edid.c */
2947bool drm_probe_ddc(struct i2c_adapter *adapter);
2948struct edid *drm_get_edid(struct drm_connector *connector,
2949 struct i2c_adapter *adapter);
2950struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2951 struct i2c_adapter *adapter);
2952struct edid *drm_edid_duplicate(const struct edid *edid);
2953int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2954
2955u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2956enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2957bool drm_detect_hdmi_monitor(struct edid *edid);
2958bool drm_detect_monitor_audio(struct edid *edid);
2959bool drm_rgb_quant_range_selectable(struct edid *edid);
2960int drm_add_modes_noedid(struct drm_connector *connector,
2961 int hdisplay, int vdisplay);
2962void drm_set_preferred_mode(struct drm_connector *connector,
2963 int hpref, int vpref);
2964
2965int drm_edid_header_is_valid(const u8 *raw_edid);
2966bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2967 bool *edid_corrupt);
2968bool drm_edid_is_valid(struct edid *edid);
2969void drm_edid_get_monitor_name(struct edid *edid, char *name,
2970 int buflen);
2971struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2972 int hsize, int vsize, int fresh,
2973 bool rb);
2974
2975/* drm_bridge.c */
2976extern int drm_bridge_add(struct drm_bridge *bridge);
2977extern void drm_bridge_remove(struct drm_bridge *bridge);
2978extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2979extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
2980
2981bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2982 const struct drm_display_mode *mode,
2983 struct drm_display_mode *adjusted_mode);
2984void drm_bridge_disable(struct drm_bridge *bridge);
2985void drm_bridge_post_disable(struct drm_bridge *bridge);
2986void drm_bridge_mode_set(struct drm_bridge *bridge,
2987 struct drm_display_mode *mode,
2988 struct drm_display_mode *adjusted_mode);
2989void drm_bridge_pre_enable(struct drm_bridge *bridge);
2990void drm_bridge_enable(struct drm_bridge *bridge);
2991
2962#endif /* __DRM_CRTC_H__ */ 2992#endif /* __DRM_CRTC_H__ */
diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
index 5a848e734422..4d85cf2874af 100644
--- a/include/drm/drm_dp_helper.h
+++ b/include/drm/drm_dp_helper.h
@@ -805,6 +805,7 @@ int drm_dp_link_power_up(struct drm_dp_aux *aux, struct drm_dp_link *link);
805int drm_dp_link_power_down(struct drm_dp_aux *aux, struct drm_dp_link *link); 805int drm_dp_link_power_down(struct drm_dp_aux *aux, struct drm_dp_link *link);
806int drm_dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link); 806int drm_dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link);
807 807
808void drm_dp_aux_init(struct drm_dp_aux *aux);
808int drm_dp_aux_register(struct drm_dp_aux *aux); 809int drm_dp_aux_register(struct drm_dp_aux *aux);
809void drm_dp_aux_unregister(struct drm_dp_aux *aux); 810void drm_dp_aux_unregister(struct drm_dp_aux *aux);
810 811
diff --git a/include/drm/drm_legacy.h b/include/drm/drm_legacy.h
index a5ef2c7e40f8..cf0e7d89bcdf 100644
--- a/include/drm/drm_legacy.h
+++ b/include/drm/drm_legacy.h
@@ -1,6 +1,8 @@
1#ifndef __DRM_DRM_LEGACY_H__ 1#ifndef __DRM_DRM_LEGACY_H__
2#define __DRM_DRM_LEGACY_H__ 2#define __DRM_DRM_LEGACY_H__
3 3
4#include <drm/drm_auth.h>
5
4/* 6/*
5 * Legacy driver interfaces for the Direct Rendering Manager 7 * Legacy driver interfaces for the Direct Rendering Manager
6 * 8 *
diff --git a/include/drm/drm_plane_helper.h b/include/drm/drm_plane_helper.h
index 4421f3f4ca8d..0e0c3573cce0 100644
--- a/include/drm/drm_plane_helper.h
+++ b/include/drm/drm_plane_helper.h
@@ -46,6 +46,7 @@ int drm_plane_helper_check_update(struct drm_plane *plane,
46 struct drm_rect *src, 46 struct drm_rect *src,
47 struct drm_rect *dest, 47 struct drm_rect *dest,
48 const struct drm_rect *clip, 48 const struct drm_rect *clip,
49 unsigned int rotation,
49 int min_scale, 50 int min_scale,
50 int max_scale, 51 int max_scale,
51 bool can_position, 52 bool can_position,
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index 4551c6f2a6c4..e0b0741ae671 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -242,6 +242,4 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct *,
242 unsigned long); 242 unsigned long);
243void *dma_buf_vmap(struct dma_buf *); 243void *dma_buf_vmap(struct dma_buf *);
244void dma_buf_vunmap(struct dma_buf *, void *vaddr); 244void dma_buf_vunmap(struct dma_buf *, void *vaddr);
245int dma_buf_debugfs_create_file(const char *name,
246 int (*write)(struct seq_file *));
247#endif /* __DMA_BUF_H__ */ 245#endif /* __DMA_BUF_H__ */