blob: 4633915cb51b273396cd007699bef90f538c3379 [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __DRM_CRTC_H__
26#define __DRM_CRTC_H__
27
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/fb.h>
Vandana Kannan985e5dc2013-12-19 15:34:07 +053033#include <linux/hdmi.h>
Boris Brezillonb5571e92014-07-22 12:09:10 +020034#include <linux/media-bus-format.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020035#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
Rob Clark51fd3712013-11-19 12:10:12 -050037#include <drm/drm_modeset_lock.h>
Ville Syrjäläd7da8242016-07-26 19:06:57 +030038#include <drm/drm_rect.h>
Daniel Vetter949619f2016-08-29 10:27:51 +020039#include <drm/drm_mode_object.h>
Daniel Vetter7520a272016-08-15 16:07:02 +020040#include <drm/drm_framebuffer.h>
41#include <drm/drm_modes.h>
Daniel Vetter52217192016-08-12 22:48:50 +020042#include <drm/drm_connector.h>
Daniel Vetter321a95a2016-08-29 10:27:49 +020043#include <drm/drm_encoder.h>
Daniel Vetter59e71ee2016-08-29 10:27:55 +020044#include <drm/drm_property.h>
Daniel Vetter199e4e92016-08-31 18:09:05 +020045#include <drm/drm_bridge.h>
Daniel Vettercdc3d092016-08-31 18:09:06 +020046#include <drm/drm_edid.h>
Daniel Vetter43968d72016-09-21 10:59:24 +020047#include <drm/drm_plane.h>
Daniel Vetter18733802016-09-21 10:59:26 +020048#include <drm/drm_blend.h>
Daniel Vetterf1e2f662016-09-21 10:59:28 +020049#include <drm/drm_color_mgmt.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080050
Dave Airlief453ba02008-11-07 14:05:41 -080051struct drm_device;
52struct drm_mode_set;
Thierry Reding595887e2012-11-21 15:00:47 +010053struct drm_file;
54struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010055struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010056struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020057struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080058
Rob Clarkebc44cf2012-09-12 22:22:31 -050059static inline int64_t U642I64(uint64_t val)
60{
61 return (int64_t)*((int64_t *)&val);
62}
63static inline uint64_t I642U64(int64_t val)
64{
65 return (uint64_t)*((uint64_t *)&val);
66}
67
Dave Airlie138f9eb2014-10-20 16:17:17 +100068/* data corresponds to displayid vend/prod/serial */
69struct drm_tile_group {
70 struct kref refcount;
71 struct drm_device *dev;
72 int id;
73 u8 group_data[8];
74};
75
Dave Airlief453ba02008-11-07 14:05:41 -080076struct drm_crtc;
Dave Airlief453ba02008-11-07 14:05:41 -080077struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -050078struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -080079struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -040080struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +010081struct drm_atomic_state;
82
Daniel Vetter4490d4c2015-12-04 09:45:45 +010083struct drm_crtc_helper_funcs;
84struct drm_encoder_helper_funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +010085struct drm_plane_helper_funcs;
86
Daniel Vetter144ecb92014-10-27 20:28:44 +010087/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +020088 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +010089 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +010090 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +010091 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +020092 * @planes_changed: planes on this crtc are updated
93 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
94 * @active_changed: crtc_state->active has been toggled.
95 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +020096 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +000097 * @color_mgmt_changed: color management properties have changed (degamma or
98 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -050099 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100100 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100101 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200102 * @last_vblank_count: for helpers and drivers to capture the vblank of the
103 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100104 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100105 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200106 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000107 * @degamma_lut: Lookup table for converting framebuffer pixel data
108 * before apply the conversion matrix
109 * @ctm: Transformation matrix
110 * @gamma_lut: Lookup table for converting pixel data after the
111 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100112 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100113 *
114 * Note that the distinction between @enable and @active is rather subtile:
115 * Flipping @active while @enable is set without changing anything else may
116 * never return in a failure from the ->atomic_check callback. Userspace assumes
117 * that a DPMS On will always succeed. In other words: @enable controls resource
118 * assignment, @active controls the actual hardware state.
Brian Starkeyd807ed12016-10-13 10:47:08 +0100119 *
120 * The three booleans active_changed, connectors_changed and mode_changed are
121 * intended to indicate whether a full modeset is needed, rather than strictly
122 * describing what has changed in a commit.
123 * See also: drm_atomic_crtc_needs_modeset()
Daniel Vetter144ecb92014-10-27 20:28:44 +0100124 */
125struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100126 struct drm_crtc *crtc;
127
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200128 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100129 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100130
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100131 /* computed state bits used by helpers and drivers */
132 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200133 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100134 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200135 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200136 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000137 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200138
Rob Clark6ddd3882014-11-21 15:28:31 -0500139 /* attached planes bitmask:
140 * WARNING: transitional helpers do not maintain plane_mask so
141 * drivers not converted over to atomic helpers should not rely
142 * on plane_mask being accurate!
143 */
144 u32 plane_mask;
145
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100146 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100147 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100148
Daniel Vetter623369e2014-09-16 17:50:47 +0200149 /* last_vblank_count: for vblank waits before cleanup */
150 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100151
Daniel Vetter2f324b42014-10-29 11:13:47 +0100152 /* adjusted_mode: for use by helpers and drivers */
153 struct drm_display_mode adjusted_mode;
154
Daniel Vetter144ecb92014-10-27 20:28:44 +0100155 struct drm_display_mode mode;
156
Daniel Stone99cf4a22015-05-25 19:11:51 +0100157 /* blob property to expose current mode to atomic userspace */
158 struct drm_property_blob *mode_blob;
159
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000160 /* blob property to expose color management to userspace */
161 struct drm_property_blob *degamma_lut;
162 struct drm_property_blob *ctm;
163 struct drm_property_blob *gamma_lut;
164
Daniel Vetter61802132016-09-30 12:04:56 +0200165 /**
166 * @event:
167 *
168 * Optional pointer to a DRM event to signal upon completion of the
169 * state update. The driver must send out the event when the atomic
170 * commit operation completes. There are two cases:
171 *
172 * - The event is for a CRTC which is being disabled through this
173 * atomic commit. In that case the event can be send out any time
174 * after the hardware has stopped scanning out the current
175 * framebuffers. It should contain the timestamp and counter for the
176 * last vblank before the display pipeline was shut off.
177 *
178 * - For a CRTC which is enabled at the end of the commit (even when it
179 * undergoes an full modeset) the vblank timestamp and counter must
180 * be for the vblank right before the first frame that scans out the
181 * new set of buffers. Again the event can only be sent out after the
182 * hardware has stopped scanning out the old buffers.
183 *
184 * - Events for disabled CRTCs are not allowed, and drivers can ignore
185 * that case.
186 *
187 * This can be handled by the drm_crtc_send_vblank_event() function,
188 * which the driver should call on the provided event upon completion of
189 * the atomic commit. Note that if the driver supports vblank signalling
190 * and timestamping the vblank counters and timestamps must agree with
191 * the ones returned from page flip events. With the current vblank
192 * helper infrastructure this can be achieved by holding a vblank
193 * reference while the page flip is pending, acquired through
194 * drm_crtc_vblank_get() and released with drm_crtc_vblank_put().
195 * Drivers are free to implement their own vblank counter and timestamp
196 * tracking though, e.g. if they have accurate timestamp registers in
197 * hardware.
198 *
199 * For hardware which supports some means to synchronize vblank
200 * interrupt delivery with committing display state there's also
201 * drm_crtc_arm_vblank_event(). See the documentation of that function
202 * for a detailed discussion of the constraints it needs to be used
203 * safely.
204 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100205 struct drm_pending_vblank_event *event;
206
207 struct drm_atomic_state *state;
208};
Dave Airlief453ba02008-11-07 14:05:41 -0800209
210/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100211 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800212 *
213 * The drm_crtc_funcs structure is the central CRTC management structure
214 * in the DRM. Each CRTC controls one or more connectors (note that the name
215 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
216 * connectors, not just CRTs).
217 *
218 * Each driver is responsible for filling out this structure at startup time,
219 * in addition to providing other modesetting features, like i2c and DDC
220 * bus accessors.
221 */
222struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100223 /**
224 * @reset:
225 *
226 * Reset CRTC hardware and software state to off. This function isn't
227 * called by the core directly, only through drm_mode_config_reset().
228 * It's not a helper hook only for historical reasons.
229 *
230 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
231 * atomic state using this hook.
232 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000233 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800234
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100235 /**
236 * @cursor_set:
237 *
238 * Update the cursor image. The cursor position is relative to the CRTC
239 * and can be partially or fully outside of the visible area.
240 *
241 * Note that contrary to all other KMS functions the legacy cursor entry
242 * points don't take a framebuffer object, but instead take directly a
243 * raw buffer object id from the driver's buffer manager (which is
244 * either GEM or TTM for current drivers).
245 *
246 * This entry point is deprecated, drivers should instead implement
247 * universal plane support and register a proper cursor plane using
248 * drm_crtc_init_with_planes().
249 *
250 * This callback is optional
251 *
252 * RETURNS:
253 *
254 * 0 on success or a negative error code on failure.
255 */
Dave Airlief453ba02008-11-07 14:05:41 -0800256 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
257 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100258
259 /**
260 * @cursor_set2:
261 *
262 * Update the cursor image, including hotspot information. The hotspot
263 * must not affect the cursor position in CRTC coordinates, but is only
264 * meant as a hint for virtualized display hardware to coordinate the
265 * guests and hosts cursor position. The cursor hotspot is relative to
266 * the cursor image. Otherwise this works exactly like @cursor_set.
267 *
268 * This entry point is deprecated, drivers should instead implement
269 * universal plane support and register a proper cursor plane using
270 * drm_crtc_init_with_planes().
271 *
272 * This callback is optional.
273 *
274 * RETURNS:
275 *
276 * 0 on success or a negative error code on failure.
277 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000278 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
279 uint32_t handle, uint32_t width, uint32_t height,
280 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100281
282 /**
283 * @cursor_move:
284 *
285 * Update the cursor position. The cursor does not need to be visible
286 * when this hook is called.
287 *
288 * This entry point is deprecated, drivers should instead implement
289 * universal plane support and register a proper cursor plane using
290 * drm_crtc_init_with_planes().
291 *
292 * This callback is optional.
293 *
294 * RETURNS:
295 *
296 * 0 on success or a negative error code on failure.
297 */
Dave Airlief453ba02008-11-07 14:05:41 -0800298 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
299
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100300 /**
301 * @gamma_set:
302 *
303 * Set gamma on the CRTC.
304 *
305 * This callback is optional.
306 *
307 * NOTE:
308 *
309 * Drivers that support gamma tables and also fbdev emulation through
310 * the provided helper library need to take care to fill out the gamma
311 * hooks for both. Currently there's a bit an unfortunate duplication
312 * going on, which should eventually be unified to just one set of
313 * hooks.
314 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200315 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
316 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100317
318 /**
319 * @destroy:
320 *
321 * Clean up plane resources. This is only called at driver unload time
322 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
323 * in DRM.
324 */
Dave Airlief453ba02008-11-07 14:05:41 -0800325 void (*destroy)(struct drm_crtc *crtc);
326
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100327 /**
328 * @set_config:
329 *
330 * This is the main legacy entry point to change the modeset state on a
331 * CRTC. All the details of the desired configuration are passed in a
332 * struct &drm_mode_set - see there for details.
333 *
334 * Drivers implementing atomic modeset should use
335 * drm_atomic_helper_set_config() to implement this hook.
336 *
337 * RETURNS:
338 *
339 * 0 on success or a negative error code on failure.
340 */
Dave Airlief453ba02008-11-07 14:05:41 -0800341 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500342
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100343 /**
344 * @page_flip:
345 *
346 * Legacy entry point to schedule a flip to the given framebuffer.
347 *
348 * Page flipping is a synchronization mechanism that replaces the frame
349 * buffer being scanned out by the CRTC with a new frame buffer during
350 * vertical blanking, avoiding tearing (except when requested otherwise
351 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
352 * requests a page flip the DRM core verifies that the new frame buffer
353 * is large enough to be scanned out by the CRTC in the currently
354 * configured mode and then calls the CRTC ->page_flip() operation with a
355 * pointer to the new frame buffer.
356 *
357 * The driver must wait for any pending rendering to the new framebuffer
358 * to complete before executing the flip. It should also wait for any
359 * pending rendering from other drivers if the underlying buffer is a
360 * shared dma-buf.
361 *
362 * An application can request to be notified when the page flip has
363 * completed. The drm core will supply a struct &drm_event in the event
364 * parameter in this case. This can be handled by the
365 * drm_crtc_send_vblank_event() function, which the driver should call on
366 * the provided event upon completion of the flip. Note that if
367 * the driver supports vblank signalling and timestamping the vblank
368 * counters and timestamps must agree with the ones returned from page
369 * flip events. With the current vblank helper infrastructure this can
370 * be achieved by holding a vblank reference while the page flip is
371 * pending, acquired through drm_crtc_vblank_get() and released with
372 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
373 * counter and timestamp tracking though, e.g. if they have accurate
374 * timestamp registers in hardware.
375 *
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100376 * This callback is optional.
377 *
378 * NOTE:
379 *
380 * Very early versions of the KMS ABI mandated that the driver must
381 * block (but not reject) any rendering to the old framebuffer until the
382 * flip operation has completed and the old framebuffer is no longer
383 * visible. This requirement has been lifted, and userspace is instead
384 * expected to request delivery of an event and wait with recycling old
385 * buffers until such has been received.
386 *
387 * RETURNS:
388 *
389 * 0 on success or a negative error code on failure. Note that if a
390 * ->page_flip() operation is already pending the callback should return
391 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
392 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100393 * "ACTIVE" state) should result in an -EINVAL error code. Note that
394 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500395 */
396 int (*page_flip)(struct drm_crtc *crtc,
397 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700398 struct drm_pending_vblank_event *event,
399 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300400
Daniel Vetter88548632015-12-04 09:45:48 +0100401 /**
Michel Dänzerc229bfb2016-08-08 16:23:03 +0900402 * @page_flip_target:
403 *
404 * Same as @page_flip but with an additional parameter specifying the
405 * absolute target vertical blank period (as reported by
406 * drm_crtc_vblank_count()) when the flip should take effect.
407 *
408 * Note that the core code calls drm_crtc_vblank_get before this entry
409 * point, and will call drm_crtc_vblank_put if this entry point returns
410 * any non-0 error code. It's the driver's responsibility to call
411 * drm_crtc_vblank_put after this entry point returns 0, typically when
412 * the flip completes.
413 */
414 int (*page_flip_target)(struct drm_crtc *crtc,
415 struct drm_framebuffer *fb,
416 struct drm_pending_vblank_event *event,
417 uint32_t flags, uint32_t target);
418
419 /**
Daniel Vetter88548632015-12-04 09:45:48 +0100420 * @set_property:
421 *
422 * This is the legacy entry point to update a property attached to the
423 * CRTC.
424 *
425 * Drivers implementing atomic modeset should use
426 * drm_atomic_helper_crtc_set_property() to implement this hook.
427 *
428 * This callback is optional if the driver does not support any legacy
429 * driver-private properties.
430 *
431 * RETURNS:
432 *
433 * 0 on success or a negative error code on failure.
434 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300435 int (*set_property)(struct drm_crtc *crtc,
436 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100437
Daniel Vetter88548632015-12-04 09:45:48 +0100438 /**
439 * @atomic_duplicate_state:
440 *
441 * Duplicate the current atomic state for this CRTC and return it.
442 * The core and helpers gurantee that any atomic state duplicated with
443 * this hook and still owned by the caller (i.e. not transferred to the
444 * driver by calling ->atomic_commit() from struct
445 * &drm_mode_config_funcs) will be cleaned up by calling the
446 * @atomic_destroy_state hook in this structure.
447 *
448 * Atomic drivers which don't subclass struct &drm_crtc should use
449 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
450 * state structure to extend it with driver-private state should use
451 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
452 * duplicated in a consistent fashion across drivers.
453 *
454 * It is an error to call this hook before crtc->state has been
455 * initialized correctly.
456 *
457 * NOTE:
458 *
459 * If the duplicate state references refcounted resources this hook must
460 * acquire a reference for each of them. The driver must release these
461 * references again in @atomic_destroy_state.
462 *
463 * RETURNS:
464 *
465 * Duplicated atomic state or NULL when the allocation failed.
466 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100467 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100468
469 /**
470 * @atomic_destroy_state:
471 *
472 * Destroy a state duplicated with @atomic_duplicate_state and release
473 * or unreference all resources it references
474 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100475 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200476 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100477
478 /**
479 * @atomic_set_property:
480 *
481 * Decode a driver-private property value and store the decoded value
482 * into the passed-in state structure. Since the atomic core decodes all
483 * standardized properties (even for extensions beyond the core set of
484 * properties which might not be implemented by all drivers) this
485 * requires drivers to subclass the state structure.
486 *
487 * Such driver-private properties should really only be implemented for
488 * truly hardware/vendor specific state. Instead it is preferred to
489 * standardize atomic extension and decode the properties used to expose
490 * such an extension in the core.
491 *
492 * Do not call this function directly, use
493 * drm_atomic_crtc_set_property() instead.
494 *
495 * This callback is optional if the driver does not support any
496 * driver-private atomic properties.
497 *
498 * NOTE:
499 *
500 * This function is called in the state assembly phase of atomic
501 * modesets, which can be aborted for any reason (including on
502 * userspace's request to just check whether a configuration would be
503 * possible). Drivers MUST NOT touch any persistent state (hardware or
504 * software) or data structures except the passed in @state parameter.
505 *
506 * Also since userspace controls in which order properties are set this
507 * function must not do any input validation (since the state update is
508 * incomplete and hence likely inconsistent). Instead any such input
509 * validation must be done in the various atomic_check callbacks.
510 *
511 * RETURNS:
512 *
513 * 0 if the property has been found, -EINVAL if the property isn't
514 * implemented by the driver (which should never happen, the core only
515 * asks for properties attached to this CRTC). No other validation is
516 * allowed by the driver. The core already checks that the property
517 * value is within the range (integer, valid enum value, ...) the driver
518 * set when registering the property.
519 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100520 int (*atomic_set_property)(struct drm_crtc *crtc,
521 struct drm_crtc_state *state,
522 struct drm_property *property,
523 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100524 /**
525 * @atomic_get_property:
526 *
527 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100528 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100529 *
530 * Do not call this function directly, use
531 * drm_atomic_crtc_get_property() instead.
532 *
533 * This callback is optional if the driver does not support any
534 * driver-private atomic properties.
535 *
536 * RETURNS:
537 *
538 * 0 on success, -EINVAL if the property isn't implemented by the
539 * driver (which should never happen, the core only asks for
540 * properties attached to this CRTC).
541 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500542 int (*atomic_get_property)(struct drm_crtc *crtc,
543 const struct drm_crtc_state *state,
544 struct drm_property *property,
545 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200546
547 /**
548 * @late_register:
549 *
550 * This optional hook can be used to register additional userspace
551 * interfaces attached to the crtc like debugfs interfaces.
552 * It is called late in the driver load sequence from drm_dev_register().
553 * Everything added from this callback should be unregistered in
554 * the early_unregister callback.
555 *
556 * Returns:
557 *
558 * 0 on success, or a negative error code on failure.
559 */
560 int (*late_register)(struct drm_crtc *crtc);
561
562 /**
563 * @early_unregister:
564 *
565 * This optional hook should be used to unregister the additional
566 * userspace interfaces attached to the crtc from
567 * late_unregister(). It is called from drm_dev_unregister(),
568 * early in the driver unload sequence to disable userspace access
569 * before data structures are torndown.
570 */
571 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800572};
573
574/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100575 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800576 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100577 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800578 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200579 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500580 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800581 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700582 * @primary: primary plane for this CRTC
583 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100584 * @cursor_x: current x position of the cursor, used for universal cursor planes
585 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800586 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800587 * @mode: current mode timings
588 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800589 * @x: x position on screen
590 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800591 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800592 * @gamma_size: size of gamma ramp
593 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800594 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300595 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800596 *
597 * Each CRTC may have one or more connectors associated with it. This structure
598 * allows the CRTC to be controlled.
599 */
600struct drm_crtc {
601 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100602 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800603 struct list_head head;
604
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200605 char *name;
606
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200607 /**
608 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100609 *
610 * This provides a read lock for the overall crtc state (mode, dpms
611 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200612 * without a full modeset (fb, cursor data, crtc properties ...). Full
613 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100614 */
Rob Clark51fd3712013-11-19 12:10:12 -0500615 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100616
Dave Airlief453ba02008-11-07 14:05:41 -0800617 struct drm_mode_object base;
618
Matt Ropere13161a2014-04-01 15:22:38 -0700619 /* primary and cursor planes for CRTC */
620 struct drm_plane *primary;
621 struct drm_plane *cursor;
622
Daniel Vetter96094082016-07-15 21:47:59 +0200623 /**
624 * @index: Position inside the mode_config.list, can be used as an array
625 * index. It is invariant over the lifetime of the CRTC.
626 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100627 unsigned index;
628
Matt Roper161d0dc2014-06-10 08:28:10 -0700629 /* position of cursor plane on crtc */
630 int cursor_x;
631 int cursor_y;
632
Dave Airlief453ba02008-11-07 14:05:41 -0800633 bool enabled;
634
Mario Kleiner27641c32010-10-23 04:20:23 +0200635 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800636 struct drm_display_mode mode;
637
Mario Kleiner27641c32010-10-23 04:20:23 +0200638 /* Programmed mode in hw, after adjustments for encoders,
639 * crtc, panel scaling etc. Needed for timestamping etc.
640 */
641 struct drm_display_mode hwmode;
642
Dave Airlief453ba02008-11-07 14:05:41 -0800643 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800644 const struct drm_crtc_funcs *funcs;
645
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000646 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800647 uint32_t gamma_size;
648 uint16_t *gamma_store;
649
650 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100651 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300652
653 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200654
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200655 /**
656 * @state:
657 *
658 * Current atomic state for this CRTC.
659 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100660 struct drm_crtc_state *state;
661
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200662 /**
663 * @commit_list:
664 *
665 * List of &drm_crtc_commit structures tracking pending commits.
666 * Protected by @commit_lock. This list doesn't hold its own full
667 * reference, but burrows it from the ongoing commit. Commit entries
668 * must be removed from this list once the commit is fully completed,
669 * but before it's correspoding &drm_atomic_state gets destroyed.
670 */
671 struct list_head commit_list;
672
673 /**
674 * @commit_lock:
675 *
676 * Spinlock to protect @commit_list.
677 */
678 spinlock_t commit_lock;
679
680 /**
681 * @acquire_ctx:
682 *
683 * Per-CRTC implicit acquire context used by atomic drivers for legacy
684 * IOCTLs, so that atomic drivers can get at the locking acquire
685 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200686 */
687 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800688};
689
Daniel Vetter144ecb92014-10-27 20:28:44 +0100690/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100691 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -0800692 * @fb: framebuffer to use for new config
693 * @crtc: CRTC whose configuration we're about to change
694 * @mode: mode timings to use
695 * @x: position of this CRTC relative to @fb
696 * @y: position of this CRTC relative to @fb
697 * @connectors: array of connectors to drive with this CRTC if possible
698 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -0800699 *
700 * Represents a single crtc the connectors that it drives with what mode
701 * and from which framebuffer it scans out from.
702 *
703 * This is used to set modes.
704 */
705struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -0800706 struct drm_framebuffer *fb;
707 struct drm_crtc *crtc;
708 struct drm_display_mode *mode;
709
710 uint32_t x;
711 uint32_t y;
712
713 struct drm_connector **connectors;
714 size_t num_connectors;
715};
716
717/**
Jesse Barnes550cebc2011-11-07 12:03:20 -0800718 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -0800719 *
720 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
721 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -0800722 */
723struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +0100724 /**
725 * @fb_create:
726 *
727 * Create a new framebuffer object. The core does basic checks on the
728 * requested metadata, but most of that is left to the driver. See
729 * struct &drm_mode_fb_cmd2 for details.
730 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100731 * If the parameters are deemed valid and the backing storage objects in
732 * the underlying memory manager all exist, then the driver allocates
733 * a new &drm_framebuffer structure, subclassed to contain
734 * driver-specific information (like the internal native buffer object
735 * references). It also needs to fill out all relevant metadata, which
736 * should be done by calling drm_helper_mode_fill_fb_struct().
737 *
738 * The initialization is finalized by calling drm_framebuffer_init(),
739 * which registers the framebuffer and makes it accessible to other
740 * threads.
741 *
Daniel Vetter9953f412015-12-04 09:46:02 +0100742 * RETURNS:
743 *
744 * A new framebuffer with an initial reference count of 1 or a negative
745 * error code encoded with ERR_PTR().
746 */
Jesse Barnes550cebc2011-11-07 12:03:20 -0800747 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
748 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +0200749 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +0100750
751 /**
752 * @output_poll_changed:
753 *
754 * Callback used by helpers to inform the driver of output configuration
755 * changes.
756 *
757 * Drivers implementing fbdev emulation with the helpers can call
758 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
759 * helper of output changes.
760 *
761 * FIXME:
762 *
763 * Except that there's no vtable for device-level helper callbacks
764 * there's no reason this is a core function.
765 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000766 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200767
Daniel Vetter9953f412015-12-04 09:46:02 +0100768 /**
769 * @atomic_check:
770 *
771 * This is the only hook to validate an atomic modeset update. This
772 * function must reject any modeset and state changes which the hardware
773 * or driver doesn't support. This includes but is of course not limited
774 * to:
775 *
776 * - Checking that the modes, framebuffers, scaling and placement
777 * requirements and so on are within the limits of the hardware.
778 *
779 * - Checking that any hidden shared resources are not oversubscribed.
780 * This can be shared PLLs, shared lanes, overall memory bandwidth,
781 * display fifo space (where shared between planes or maybe even
782 * CRTCs).
783 *
784 * - Checking that virtualized resources exported to userspace are not
785 * oversubscribed. For various reasons it can make sense to expose
786 * more planes, crtcs or encoders than which are physically there. One
787 * example is dual-pipe operations (which generally should be hidden
788 * from userspace if when lockstepped in hardware, exposed otherwise),
789 * where a plane might need 1 hardware plane (if it's just on one
790 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
791 * shared a hardware plane with a 2nd plane (if there's a compatible
792 * plane requested on the area handled by the other pipe).
793 *
794 * - Check that any transitional state is possible and that if
795 * requested, the update can indeed be done in the vblank period
796 * without temporarily disabling some functions.
797 *
798 * - Check any other constraints the driver or hardware might have.
799 *
800 * - This callback also needs to correctly fill out the &drm_crtc_state
801 * in this update to make sure that drm_atomic_crtc_needs_modeset()
802 * reflects the nature of the possible update and returns true if and
803 * only if the update cannot be applied without tearing within one
804 * vblank on that CRTC. The core uses that information to reject
805 * updates which require a full modeset (i.e. blanking the screen, or
806 * at least pausing updates for a substantial amount of time) if
807 * userspace has disallowed that in its request.
808 *
809 * - The driver also does not need to repeat basic input validation
810 * like done for the corresponding legacy entry points. The core does
811 * that before calling this hook.
812 *
813 * See the documentation of @atomic_commit for an exhaustive list of
814 * error conditions which don't have to be checked at the
815 * ->atomic_check() stage?
816 *
817 * See the documentation for struct &drm_atomic_state for how exactly
818 * an atomic modeset update is described.
819 *
820 * Drivers using the atomic helpers can implement this hook using
821 * drm_atomic_helper_check(), or one of the exported sub-functions of
822 * it.
823 *
824 * RETURNS:
825 *
826 * 0 on success or one of the below negative error codes:
827 *
828 * - -EINVAL, if any of the above constraints are violated.
829 *
830 * - -EDEADLK, when returned from an attempt to acquire an additional
831 * &drm_modeset_lock through drm_modeset_lock().
832 *
833 * - -ENOMEM, if allocating additional state sub-structures failed due
834 * to lack of memory.
835 *
836 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
837 * This can either be due to a pending signal, or because the driver
838 * needs to completely bail out to recover from an exceptional
839 * situation like a GPU hang. From a userspace point all errors are
840 * treated equally.
841 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200842 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +0100843 struct drm_atomic_state *state);
844
845 /**
846 * @atomic_commit:
847 *
848 * This is the only hook to commit an atomic modeset update. The core
849 * guarantees that @atomic_check has been called successfully before
850 * calling this function, and that nothing has been changed in the
851 * interim.
852 *
853 * See the documentation for struct &drm_atomic_state for how exactly
854 * an atomic modeset update is described.
855 *
856 * Drivers using the atomic helpers can implement this hook using
857 * drm_atomic_helper_commit(), or one of the exported sub-functions of
858 * it.
859 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200860 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +0100861 * do any preparatory work which might result in an unsuccessful commit
862 * in the context of this callback. The only exceptions are hardware
863 * errors resulting in -EIO. But even in that case the driver must
864 * ensure that the display pipe is at least running, to avoid
865 * compositors crashing when pageflips don't work. Anything else,
866 * specifically committing the update to the hardware, should be done
867 * without blocking the caller. For updates which do not require a
868 * modeset this must be guaranteed.
869 *
870 * The driver must wait for any pending rendering to the new
871 * framebuffers to complete before executing the flip. It should also
872 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200873 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +0100874 * rendering in the context of this callback.
875 *
876 * An application can request to be notified when the atomic commit has
877 * completed. These events are per-CRTC and can be distinguished by the
878 * CRTC index supplied in &drm_event to userspace.
879 *
880 * The drm core will supply a struct &drm_event in the event
Daniel Vetter61802132016-09-30 12:04:56 +0200881 * member of each CRTC's &drm_crtc_state structure. See the
882 * documentation for &drm_crtc_state for more details about the precise
883 * semantics of this event.
Daniel Vetter9953f412015-12-04 09:46:02 +0100884 *
885 * NOTE:
886 *
887 * Drivers are not allowed to shut down any display pipe successfully
888 * enabled through an atomic commit on their own. Doing so can result in
889 * compositors crashing if a page flip is suddenly rejected because the
890 * pipe is off.
891 *
892 * RETURNS:
893 *
894 * 0 on success or one of the below negative error codes:
895 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200896 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +0100897 * an earlier updated pending. Drivers are allowed to support a queue
898 * of outstanding updates, but currently no driver supports that.
899 * Note that drivers must wait for preceding updates to complete if a
900 * synchronous update is requested, they are not allowed to fail the
901 * commit in that case.
902 *
903 * - -ENOMEM, if the driver failed to allocate memory. Specifically
904 * this can happen when trying to pin framebuffers, which must only
905 * be done when committing the state.
906 *
907 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
908 * that the driver has run out of vram, iommu space or similar GPU
909 * address space needed for framebuffer.
910 *
911 * - -EIO, if the hardware completely died.
912 *
913 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
914 * This can either be due to a pending signal, or because the driver
915 * needs to completely bail out to recover from an exceptional
916 * situation like a GPU hang. From a userspace point of view all errors are
917 * treated equally.
918 *
919 * This list is exhaustive. Specifically this hook is not allowed to
920 * return -EINVAL (any invalid requests should be caught in
921 * @atomic_check) or -EDEADLK (this function must not acquire
922 * additional modeset locks).
923 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200924 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +0100925 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200926 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +0100927
928 /**
929 * @atomic_state_alloc:
930 *
931 * This optional hook can be used by drivers that want to subclass struct
932 * &drm_atomic_state to be able to track their own driver-private global
933 * state easily. If this hook is implemented, drivers must also
934 * implement @atomic_state_clear and @atomic_state_free.
935 *
936 * RETURNS:
937 *
938 * A new &drm_atomic_state on success or NULL on failure.
939 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +0200940 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +0100941
942 /**
943 * @atomic_state_clear:
944 *
945 * This hook must clear any driver private state duplicated into the
946 * passed-in &drm_atomic_state. This hook is called when the caller
947 * encountered a &drm_modeset_lock deadlock and needs to drop all
948 * already acquired locks as part of the deadlock avoidance dance
949 * implemented in drm_modeset_lock_backoff().
950 *
951 * Any duplicated state must be invalidated since a concurrent atomic
952 * update might change it, and the drm atomic interfaces always apply
953 * updates as relative changes to the current state.
954 *
955 * Drivers that implement this must call drm_atomic_state_default_clear()
956 * to clear common state.
957 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +0200958 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +0100959
960 /**
961 * @atomic_state_free:
962 *
963 * This hook needs driver private resources and the &drm_atomic_state
964 * itself. Note that the core first calls drm_atomic_state_clear() to
965 * avoid code duplicate between the clear and free hooks.
966 *
967 * Drivers that implement this must call drm_atomic_state_default_free()
968 * to release common resources.
969 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +0200970 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -0800971};
972
Jesse Barnesc1aaca22011-11-07 12:03:21 -0800973/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100974 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800975 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100976 * @connection_mutex: ww mutex protecting connector state and routing
977 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100978 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100979 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800980 * @num_fb: number of fbs available
981 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800982 * @num_encoder: number of encoders on this device
983 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100984 * @num_overlay_plane: number of overlay planes on this device
985 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
986 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800987 * @num_crtc: number of CRTCs on this device
988 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100989 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800990 * @min_width: minimum pixel width on this device
991 * @min_height: minimum pixel height on this device
992 * @max_width: maximum pixel width on this device
993 * @max_height: maximum pixel height on this device
994 * @funcs: core driver provided mode setting functions
995 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100996 * @poll_enabled: track polling support for this device
997 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200998 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800999 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001000 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001001 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001002 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001003 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1004 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001005 * @cursor_width: hint to userspace for max cursor width
1006 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001007 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -08001008 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001009 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1010 * enumerated by the driver are added here, as are global properties. Some
1011 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08001012 */
1013struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10001014 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05001015 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1016 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001017
1018 /**
1019 * @idr_mutex:
1020 *
1021 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1022 * and @tile_idr.
1023 */
1024 struct mutex idr_mutex;
1025
1026 /**
1027 * @crtc_idr:
1028 *
1029 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1030 * connector, modes - just makes life easier to have only one.
1031 */
1032 struct idr crtc_idr;
1033
1034 /**
1035 * @tile_idr:
1036 *
1037 * Use this idr for allocating new IDs for tiled sinks like use in some
1038 * high-res DP MST screens.
1039 */
1040 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001041
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001042 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08001043 int num_fb;
1044 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001045
Daniel Vetter96094082016-07-15 21:47:59 +02001046 /**
1047 * @num_connector: Number of connectors on this device.
1048 */
Dave Airlief453ba02008-11-07 14:05:41 -08001049 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02001050 /**
1051 * @connector_ida: ID allocator for connector indices.
1052 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001053 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02001054 /**
1055 * @connector_list: List of connector objects.
1056 */
Dave Airlief453ba02008-11-07 14:05:41 -08001057 struct list_head connector_list;
1058 int num_encoder;
1059 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07001060
1061 /*
1062 * Track # of overlay planes separately from # of total planes. By
1063 * default we only advertise overlay planes to userspace; if userspace
1064 * sets the "universal plane" capability bit, we'll go ahead and
1065 * expose all planes.
1066 */
1067 int num_overlay_plane;
1068 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001069 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08001070
1071 int num_crtc;
1072 struct list_head crtc_list;
1073
1074 struct list_head property_list;
1075
Dave Airlief453ba02008-11-07 14:05:41 -08001076 int min_width, min_height;
1077 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02001078 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11001079 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08001080
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001081 /* output poll support */
1082 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00001083 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01001084 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02001085 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001086
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001087 struct mutex blob_lock;
1088
Dave Airlief453ba02008-11-07 14:05:41 -08001089 /* pointers to standard properties */
1090 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001091 /**
1092 * @edid_property: Default connector property to hold the EDID of the
1093 * currently connected sink, if any.
1094 */
Dave Airlief453ba02008-11-07 14:05:41 -08001095 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001096 /**
1097 * @dpms_property: Default connector property to control the
1098 * connector's DPMS state.
1099 */
Dave Airlief453ba02008-11-07 14:05:41 -08001100 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001101 /**
1102 * @path_property: Default connector property to hold the DP MST path
1103 * for the port.
1104 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001105 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001106 /**
1107 * @tile_property: Default connector property to store the tile
1108 * position of a tiled screen, for sinks which need to be driven with
1109 * multiple CRTCs.
1110 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001111 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001112 /**
1113 * @plane_type_property: Default plane property to differentiate
1114 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1115 */
Rob Clark9922ab52014-04-01 20:16:57 -04001116 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001117 /**
1118 * @rotation_property: Optional property for planes or CRTCs to specifiy
1119 * rotation.
1120 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05301121 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001122 /**
1123 * @prop_src_x: Default atomic plane property for the plane source
1124 * position in the connected &drm_framebuffer.
1125 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001126 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001127 /**
1128 * @prop_src_y: Default atomic plane property for the plane source
1129 * position in the connected &drm_framebuffer.
1130 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001131 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001132 /**
1133 * @prop_src_w: Default atomic plane property for the plane source
1134 * position in the connected &drm_framebuffer.
1135 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001136 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001137 /**
1138 * @prop_src_h: Default atomic plane property for the plane source
1139 * position in the connected &drm_framebuffer.
1140 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001141 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001142 /**
1143 * @prop_crtc_x: Default atomic plane property for the plane destination
1144 * position in the &drm_crtc is is being shown on.
1145 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001146 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001147 /**
1148 * @prop_crtc_y: Default atomic plane property for the plane destination
1149 * position in the &drm_crtc is is being shown on.
1150 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001151 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001152 /**
1153 * @prop_crtc_w: Default atomic plane property for the plane destination
1154 * position in the &drm_crtc is is being shown on.
1155 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001156 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001157 /**
1158 * @prop_crtc_h: Default atomic plane property for the plane destination
1159 * position in the &drm_crtc is is being shown on.
1160 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001161 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001162 /**
1163 * @prop_fb_id: Default atomic plane property to specify the
1164 * &drm_framebuffer.
1165 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001166 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001167 /**
1168 * @prop_crtc_id: Default atomic plane property to specify the
1169 * &drm_crtc.
1170 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001171 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001172 /**
1173 * @prop_active: Default atomic CRTC property to control the active
1174 * state, which is the simplified implementation for DPMS in atomic
1175 * drivers.
1176 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01001177 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001178 /**
1179 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1180 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1181 * connectors must be of and active must be set to disabled, too.
1182 */
Daniel Stone955f3c32015-05-25 19:11:52 +01001183 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001184
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001185 /**
1186 * @dvi_i_subconnector_property: Optional DVI-I property to
1187 * differentiate between analog or digital mode.
1188 */
Dave Airlief453ba02008-11-07 14:05:41 -08001189 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001190 /**
1191 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1192 * select between analog or digital mode.
1193 */
Dave Airlief453ba02008-11-07 14:05:41 -08001194 struct drm_property *dvi_i_select_subconnector_property;
1195
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001196 /**
1197 * @tv_subconnector_property: Optional TV property to differentiate
1198 * between different TV connector types.
1199 */
Dave Airlief453ba02008-11-07 14:05:41 -08001200 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001201 /**
1202 * @tv_select_subconnector_property: Optional TV property to select
1203 * between different TV connector types.
1204 */
Dave Airlief453ba02008-11-07 14:05:41 -08001205 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001206 /**
1207 * @tv_mode_property: Optional TV property to select
1208 * the output TV mode.
1209 */
Dave Airlief453ba02008-11-07 14:05:41 -08001210 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001211 /**
1212 * @tv_left_margin_property: Optional TV property to set the left
1213 * margin.
1214 */
Dave Airlief453ba02008-11-07 14:05:41 -08001215 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001216 /**
1217 * @tv_right_margin_property: Optional TV property to set the right
1218 * margin.
1219 */
Dave Airlief453ba02008-11-07 14:05:41 -08001220 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001221 /**
1222 * @tv_top_margin_property: Optional TV property to set the right
1223 * margin.
1224 */
Dave Airlief453ba02008-11-07 14:05:41 -08001225 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001226 /**
1227 * @tv_bottom_margin_property: Optional TV property to set the right
1228 * margin.
1229 */
Dave Airlief453ba02008-11-07 14:05:41 -08001230 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001231 /**
1232 * @tv_brightness_property: Optional TV property to set the
1233 * brightness.
1234 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001235 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001236 /**
1237 * @tv_contrast_property: Optional TV property to set the
1238 * contrast.
1239 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001240 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001241 /**
1242 * @tv_flicker_reduction_property: Optional TV property to control the
1243 * flicker reduction mode.
1244 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001245 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001246 /**
1247 * @tv_overscan_property: Optional TV property to control the overscan
1248 * setting.
1249 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001250 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001251 /**
1252 * @tv_saturation_property: Optional TV property to set the
1253 * saturation.
1254 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001255 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001256 /**
1257 * @tv_hue_property: Optional TV property to set the hue.
1258 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001259 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08001260
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001261 /**
1262 * @scaling_mode_property: Optional connector property to control the
1263 * upscaling, mostly used for built-in panels.
1264 */
Dave Airlief453ba02008-11-07 14:05:41 -08001265 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001266 /**
1267 * @aspect_ratio_property: Optional connector property to control the
1268 * HDMI infoframe aspect ratio setting.
1269 */
Vandana Kannanff587e42014-06-11 10:46:48 +05301270 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001271 /**
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001272 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1273 * convert the framebuffer's colors to linear gamma.
1274 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001275 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001276 /**
1277 * @degamma_lut_size_property: Optional CRTC property for the size of
1278 * the degamma LUT as supported by the driver (read-only).
1279 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001280 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001281 /**
1282 * @ctm_property: Optional CRTC property to set the
1283 * matrix used to convert colors after the lookup in the
1284 * degamma LUT.
1285 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001286 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001287 /**
1288 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1289 * convert the colors, after the CTM matrix, to the gamma space of the
1290 * connected screen.
1291 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001292 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001293 /**
1294 * @gamma_lut_size_property: Optional CRTC property for the size of the
1295 * gamma LUT as supported by the driver (read-only).
1296 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001297 struct drm_property *gamma_lut_size_property;
1298
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001299 /**
1300 * @suggested_x_property: Optional connector property with a hint for
1301 * the position of the output on the host's screen.
1302 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001303 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001304 /**
1305 * @suggested_y_property: Optional connector property with a hint for
1306 * the position of the output on the host's screen.
1307 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001308 struct drm_property *suggested_y_property;
1309
Dave Airlie019d96c2011-09-29 16:20:42 +01001310 /* dumb ioctl parameters */
1311 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07001312
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001313 /**
1314 * @async_page_flip: Does this device support async flips on the primary
1315 * plane?
1316 */
Keith Packard62f21042013-07-22 18:50:00 -07001317 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05001318
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001319 /**
1320 * @allow_fb_modifiers:
1321 *
1322 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1323 */
Rob Clarke3eb3252015-02-05 14:41:52 +00001324 bool allow_fb_modifiers;
1325
Alex Deucher8716ed42014-02-12 12:48:23 -05001326 /* cursor size */
1327 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001328
1329 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001330};
1331
1332#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
Dave Airlief453ba02008-11-07 14:05:41 -08001333
Ville Syrjäläf9882872015-12-09 16:19:31 +02001334extern __printf(6, 7)
1335int drm_crtc_init_with_planes(struct drm_device *dev,
1336 struct drm_crtc *crtc,
1337 struct drm_plane *primary,
1338 struct drm_plane *cursor,
1339 const struct drm_crtc_funcs *funcs,
1340 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08001341extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01001342
1343/**
1344 * drm_crtc_index - find the index of a registered CRTC
1345 * @crtc: CRTC to find index for
1346 *
1347 * Given a registered CRTC, return the index of that CRTC within a DRM
1348 * device's list of CRTCs.
1349 */
Jani Nikulaa5bd4512016-10-10 18:26:10 +03001350static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)
Chris Wilson490d3d12016-05-27 20:05:00 +01001351{
1352 return crtc->index;
1353}
Russell Kingdb5f7a62014-01-02 21:27:33 +00001354
1355/**
1356 * drm_crtc_mask - find the mask of a registered CRTC
1357 * @crtc: CRTC to find mask for
1358 *
1359 * Given a registered CRTC, return the mask bit of that CRTC for an
1360 * encoder's possible_crtcs field.
1361 */
Maarten Lankhorst1dfdb0ed2016-10-13 10:38:11 +02001362static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc)
Russell Kingdb5f7a62014-01-02 21:27:33 +00001363{
1364 return 1 << drm_crtc_index(crtc);
1365}
Dave Airlief453ba02008-11-07 14:05:41 -08001366
Gustavo Padovanecb7e162014-12-01 15:40:09 -08001367extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1368 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02001369extern int drm_crtc_force_disable(struct drm_crtc *crtc);
1370extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001371
Dave Airlief453ba02008-11-07 14:05:41 -08001372extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00001373extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001374extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001375
Daniel Vetter2d13b672012-12-11 13:47:23 +01001376extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02001377
Dave Airlie138f9eb2014-10-20 16:17:17 +10001378extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1379 char topology[8]);
1380extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1381 char topology[8]);
1382extern void drm_mode_put_tile_group(struct drm_device *dev,
1383 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10001384
Russell King96f60e32012-08-15 13:59:49 +01001385/* Helpers */
1386static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1387 uint32_t id)
1388{
1389 struct drm_mode_object *mo;
1390 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1391 return mo ? obj_to_crtc(mo) : NULL;
1392}
1393
Daniel Vetter6295d602015-07-09 23:44:25 +02001394#define drm_for_each_crtc(crtc, dev) \
1395 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1396
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02001397static inline void
1398assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1399{
Daniel Vettercff20ba2015-07-09 23:44:33 +02001400 /*
1401 * The connector hotadd/remove code currently grabs both locks when
1402 * updating lists. Hence readers need only hold either of them to be
1403 * safe and the check amounts to
1404 *
1405 * WARN_ON(not_holding(A) && not_holding(B)).
1406 */
1407 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
1408 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02001409}
1410
Dave Airlief453ba02008-11-07 14:05:41 -08001411#endif /* __DRM_CRTC_H__ */