]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/drm/drm_crtc.h
Merge remote-tracking branch 'airlied/drm-next' into topic/drm-misc
[mirror_ubuntu-bionic-kernel.git] / include / drm / drm_crtc.h
CommitLineData
f453ba04
DA
1/*
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>
f453ba04 32#include <linux/fb.h>
985e5dc2 33#include <linux/hdmi.h>
b5571e9d 34#include <linux/media-bus-format.h>
d7d2c48e
DH
35#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
51fd371b 37#include <drm/drm_modeset_lock.h>
d7da824d 38#include <drm/drm_rect.h>
949619f3 39#include <drm/drm_mode_object.h>
7520a277
DV
40#include <drm/drm_framebuffer.h>
41#include <drm/drm_modes.h>
52217195 42#include <drm/drm_connector.h>
321a95ae 43#include <drm/drm_encoder.h>
59e71ee7 44#include <drm/drm_property.h>
199e4e96 45#include <drm/drm_bridge.h>
cdc3d09f 46#include <drm/drm_edid.h>
43968d7b 47#include <drm/drm_plane.h>
18733802 48#include <drm/drm_blend.h>
f1e2f66c 49#include <drm/drm_color_mgmt.h>
9edbf1fa 50#include <drm/drm_debugfs_crc.h>
308e5bcb 51
f453ba04
DA
52struct drm_device;
53struct drm_mode_set;
595887eb
TR
54struct drm_file;
55struct drm_clip_rect;
7e435aad 56struct device_node;
e2330f07 57struct fence;
81065548 58struct edid;
f453ba04 59
ebc44cf3
RC
60static inline int64_t U642I64(uint64_t val)
61{
62 return (int64_t)*((int64_t *)&val);
63}
64static inline uint64_t I642U64(int64_t val)
65{
66 return (uint64_t)*((uint64_t *)&val);
67}
68
138f9ebb
DA
69/* data corresponds to displayid vend/prod/serial */
70struct drm_tile_group {
71 struct kref refcount;
72 struct drm_device *dev;
73 int id;
74 u8 group_data[8];
75};
76
f453ba04 77struct drm_crtc;
f453ba04 78struct drm_encoder;
d91d8a3f 79struct drm_pending_vblank_event;
8cf5c917 80struct drm_plane;
3b336ec4 81struct drm_bridge;
144ecb97
DV
82struct drm_atomic_state;
83
4490d4c7
DV
84struct drm_crtc_helper_funcs;
85struct drm_encoder_helper_funcs;
4490d4c7
DV
86struct drm_plane_helper_funcs;
87
144ecb97 88/**
cc4ceb48 89 * struct drm_crtc_state - mutable CRTC state
07cc0ef6 90 * @crtc: backpointer to the CRTC
144ecb97 91 * @enable: whether the CRTC should be enabled, gates all other state
d9b13620 92 * @active: whether the CRTC is actively displaying (used for DPMS)
fc596660
ML
93 * @planes_changed: planes on this crtc are updated
94 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
95 * @active_changed: crtc_state->active has been toggled.
96 * @connectors_changed: connectors to this crtc have been updated
44d1240d 97 * @zpos_changed: zpos values of planes on this crtc have been updated
5488dc16
LL
98 * @color_mgmt_changed: color management properties have changed (degamma or
99 * gamma LUT or CSC matrix)
6ddd388a 100 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
4cd9fa52 101 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
e87a52b3 102 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
623369e5
DV
103 * @last_vblank_count: for helpers and drivers to capture the vblank of the
104 * update to ensure framebuffer cleanup isn't done too early
2f324b42 105 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
144ecb97 106 * @mode: current mode timings
ac3ba4a5 107 * @mode_blob: &drm_property_blob for @mode
5488dc16
LL
108 * @degamma_lut: Lookup table for converting framebuffer pixel data
109 * before apply the conversion matrix
110 * @ctm: Transformation matrix
111 * @gamma_lut: Lookup table for converting pixel data after the
112 * conversion matrix
144ecb97 113 * @state: backpointer to global drm_atomic_state
d9b13620
DV
114 *
115 * Note that the distinction between @enable and @active is rather subtile:
116 * Flipping @active while @enable is set without changing anything else may
117 * never return in a failure from the ->atomic_check callback. Userspace assumes
118 * that a DPMS On will always succeed. In other words: @enable controls resource
119 * assignment, @active controls the actual hardware state.
d807ed1c
BS
120 *
121 * The three booleans active_changed, connectors_changed and mode_changed are
122 * intended to indicate whether a full modeset is needed, rather than strictly
123 * describing what has changed in a commit.
124 * See also: drm_atomic_crtc_needs_modeset()
144ecb97
DV
125 */
126struct drm_crtc_state {
07cc0ef6
DV
127 struct drm_crtc *crtc;
128
cc4ceb48 129 bool enable;
d9b13620 130 bool active;
144ecb97 131
c2fcd274
DV
132 /* computed state bits used by helpers and drivers */
133 bool planes_changed : 1;
623369e5 134 bool mode_changed : 1;
eab3bbef 135 bool active_changed : 1;
fc596660 136 bool connectors_changed : 1;
44d1240d 137 bool zpos_changed : 1;
5488dc16 138 bool color_mgmt_changed : 1;
623369e5 139
6ddd388a
RC
140 /* attached planes bitmask:
141 * WARNING: transitional helpers do not maintain plane_mask so
142 * drivers not converted over to atomic helpers should not rely
143 * on plane_mask being accurate!
144 */
145 u32 plane_mask;
146
4cd9fa52 147 u32 connector_mask;
e87a52b3 148 u32 encoder_mask;
4cd9fa52 149
623369e5
DV
150 /* last_vblank_count: for vblank waits before cleanup */
151 u32 last_vblank_count;
c2fcd274 152
2f324b42
DV
153 /* adjusted_mode: for use by helpers and drivers */
154 struct drm_display_mode adjusted_mode;
155
144ecb97
DV
156 struct drm_display_mode mode;
157
99cf4a29
DS
158 /* blob property to expose current mode to atomic userspace */
159 struct drm_property_blob *mode_blob;
160
5488dc16
LL
161 /* blob property to expose color management to userspace */
162 struct drm_property_blob *degamma_lut;
163 struct drm_property_blob *ctm;
164 struct drm_property_blob *gamma_lut;
165
61802130
DV
166 /**
167 * @event:
168 *
169 * Optional pointer to a DRM event to signal upon completion of the
170 * state update. The driver must send out the event when the atomic
171 * commit operation completes. There are two cases:
172 *
173 * - The event is for a CRTC which is being disabled through this
174 * atomic commit. In that case the event can be send out any time
175 * after the hardware has stopped scanning out the current
176 * framebuffers. It should contain the timestamp and counter for the
177 * last vblank before the display pipeline was shut off.
178 *
179 * - For a CRTC which is enabled at the end of the commit (even when it
180 * undergoes an full modeset) the vblank timestamp and counter must
181 * be for the vblank right before the first frame that scans out the
182 * new set of buffers. Again the event can only be sent out after the
183 * hardware has stopped scanning out the old buffers.
184 *
185 * - Events for disabled CRTCs are not allowed, and drivers can ignore
186 * that case.
187 *
188 * This can be handled by the drm_crtc_send_vblank_event() function,
189 * which the driver should call on the provided event upon completion of
190 * the atomic commit. Note that if the driver supports vblank signalling
191 * and timestamping the vblank counters and timestamps must agree with
192 * the ones returned from page flip events. With the current vblank
193 * helper infrastructure this can be achieved by holding a vblank
194 * reference while the page flip is pending, acquired through
195 * drm_crtc_vblank_get() and released with drm_crtc_vblank_put().
196 * Drivers are free to implement their own vblank counter and timestamp
197 * tracking though, e.g. if they have accurate timestamp registers in
198 * hardware.
199 *
200 * For hardware which supports some means to synchronize vblank
201 * interrupt delivery with committing display state there's also
202 * drm_crtc_arm_vblank_event(). See the documentation of that function
203 * for a detailed discussion of the constraints it needs to be used
204 * safely.
205 */
144ecb97
DV
206 struct drm_pending_vblank_event *event;
207
208 struct drm_atomic_state *state;
209};
f453ba04
DA
210
211/**
3bf0401c 212 * struct drm_crtc_funcs - control CRTCs for a given device
f453ba04
DA
213 *
214 * The drm_crtc_funcs structure is the central CRTC management structure
215 * in the DRM. Each CRTC controls one or more connectors (note that the name
216 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
217 * connectors, not just CRTs).
218 *
219 * Each driver is responsible for filling out this structure at startup time,
220 * in addition to providing other modesetting features, like i2c and DDC
221 * bus accessors.
222 */
223struct drm_crtc_funcs {
88548636
DV
224 /**
225 * @reset:
226 *
227 * Reset CRTC hardware and software state to off. This function isn't
228 * called by the core directly, only through drm_mode_config_reset().
229 * It's not a helper hook only for historical reasons.
230 *
231 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
232 * atomic state using this hook.
233 */
eb033556 234 void (*reset)(struct drm_crtc *crtc);
f453ba04 235
f6da8c6e
DV
236 /**
237 * @cursor_set:
238 *
239 * Update the cursor image. The cursor position is relative to the CRTC
240 * and can be partially or fully outside of the visible area.
241 *
242 * Note that contrary to all other KMS functions the legacy cursor entry
243 * points don't take a framebuffer object, but instead take directly a
244 * raw buffer object id from the driver's buffer manager (which is
245 * either GEM or TTM for current drivers).
246 *
247 * This entry point is deprecated, drivers should instead implement
248 * universal plane support and register a proper cursor plane using
249 * drm_crtc_init_with_planes().
250 *
251 * This callback is optional
252 *
253 * RETURNS:
254 *
255 * 0 on success or a negative error code on failure.
256 */
f453ba04
DA
257 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
258 uint32_t handle, uint32_t width, uint32_t height);
f6da8c6e
DV
259
260 /**
261 * @cursor_set2:
262 *
263 * Update the cursor image, including hotspot information. The hotspot
264 * must not affect the cursor position in CRTC coordinates, but is only
265 * meant as a hint for virtualized display hardware to coordinate the
266 * guests and hosts cursor position. The cursor hotspot is relative to
267 * the cursor image. Otherwise this works exactly like @cursor_set.
268 *
269 * This entry point is deprecated, drivers should instead implement
270 * universal plane support and register a proper cursor plane using
271 * drm_crtc_init_with_planes().
272 *
273 * This callback is optional.
274 *
275 * RETURNS:
276 *
277 * 0 on success or a negative error code on failure.
278 */
4c813d4d
DA
279 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
280 uint32_t handle, uint32_t width, uint32_t height,
281 int32_t hot_x, int32_t hot_y);
f6da8c6e
DV
282
283 /**
284 * @cursor_move:
285 *
286 * Update the cursor position. The cursor does not need to be visible
287 * when this hook is called.
288 *
289 * This entry point is deprecated, drivers should instead implement
290 * universal plane support and register a proper cursor plane using
291 * drm_crtc_init_with_planes().
292 *
293 * This callback is optional.
294 *
295 * RETURNS:
296 *
297 * 0 on success or a negative error code on failure.
298 */
f453ba04
DA
299 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
300
f6da8c6e
DV
301 /**
302 * @gamma_set:
303 *
304 * Set gamma on the CRTC.
305 *
306 * This callback is optional.
307 *
308 * NOTE:
309 *
310 * Drivers that support gamma tables and also fbdev emulation through
311 * the provided helper library need to take care to fill out the gamma
312 * hooks for both. Currently there's a bit an unfortunate duplication
313 * going on, which should eventually be unified to just one set of
314 * hooks.
315 */
7ea77283
ML
316 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
317 uint32_t size);
88548636
DV
318
319 /**
320 * @destroy:
321 *
322 * Clean up plane resources. This is only called at driver unload time
323 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
324 * in DRM.
325 */
f453ba04
DA
326 void (*destroy)(struct drm_crtc *crtc);
327
f6da8c6e
DV
328 /**
329 * @set_config:
330 *
331 * This is the main legacy entry point to change the modeset state on a
332 * CRTC. All the details of the desired configuration are passed in a
333 * struct &drm_mode_set - see there for details.
334 *
335 * Drivers implementing atomic modeset should use
336 * drm_atomic_helper_set_config() to implement this hook.
337 *
338 * RETURNS:
339 *
340 * 0 on success or a negative error code on failure.
341 */
f453ba04 342 int (*set_config)(struct drm_mode_set *set);
d91d8a3f 343
f6da8c6e
DV
344 /**
345 * @page_flip:
346 *
347 * Legacy entry point to schedule a flip to the given framebuffer.
348 *
349 * Page flipping is a synchronization mechanism that replaces the frame
350 * buffer being scanned out by the CRTC with a new frame buffer during
351 * vertical blanking, avoiding tearing (except when requested otherwise
352 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
353 * requests a page flip the DRM core verifies that the new frame buffer
354 * is large enough to be scanned out by the CRTC in the currently
355 * configured mode and then calls the CRTC ->page_flip() operation with a
356 * pointer to the new frame buffer.
357 *
358 * The driver must wait for any pending rendering to the new framebuffer
359 * to complete before executing the flip. It should also wait for any
360 * pending rendering from other drivers if the underlying buffer is a
361 * shared dma-buf.
362 *
363 * An application can request to be notified when the page flip has
364 * completed. The drm core will supply a struct &drm_event in the event
365 * parameter in this case. This can be handled by the
366 * drm_crtc_send_vblank_event() function, which the driver should call on
367 * the provided event upon completion of the flip. Note that if
368 * the driver supports vblank signalling and timestamping the vblank
369 * counters and timestamps must agree with the ones returned from page
370 * flip events. With the current vblank helper infrastructure this can
371 * be achieved by holding a vblank reference while the page flip is
372 * pending, acquired through drm_crtc_vblank_get() and released with
373 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
374 * counter and timestamp tracking though, e.g. if they have accurate
375 * timestamp registers in hardware.
376 *
f6da8c6e
DV
377 * This callback is optional.
378 *
379 * NOTE:
380 *
381 * Very early versions of the KMS ABI mandated that the driver must
382 * block (but not reject) any rendering to the old framebuffer until the
383 * flip operation has completed and the old framebuffer is no longer
384 * visible. This requirement has been lifted, and userspace is instead
385 * expected to request delivery of an event and wait with recycling old
386 * buffers until such has been received.
387 *
388 * RETURNS:
389 *
390 * 0 on success or a negative error code on failure. Note that if a
391 * ->page_flip() operation is already pending the callback should return
392 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
393 * or just runtime disabled through DPMS respectively the new atomic
4cba6850
DV
394 * "ACTIVE" state) should result in an -EINVAL error code. Note that
395 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
d91d8a3f
KH
396 */
397 int (*page_flip)(struct drm_crtc *crtc,
398 struct drm_framebuffer *fb,
ed8d1975
KP
399 struct drm_pending_vblank_event *event,
400 uint32_t flags);
bffd9de0 401
c229bfbb
MD
402 /**
403 * @page_flip_target:
404 *
405 * Same as @page_flip but with an additional parameter specifying the
406 * absolute target vertical blank period (as reported by
407 * drm_crtc_vblank_count()) when the flip should take effect.
408 *
409 * Note that the core code calls drm_crtc_vblank_get before this entry
410 * point, and will call drm_crtc_vblank_put if this entry point returns
411 * any non-0 error code. It's the driver's responsibility to call
412 * drm_crtc_vblank_put after this entry point returns 0, typically when
413 * the flip completes.
414 */
415 int (*page_flip_target)(struct drm_crtc *crtc,
416 struct drm_framebuffer *fb,
417 struct drm_pending_vblank_event *event,
418 uint32_t flags, uint32_t target);
419
88548636
DV
420 /**
421 * @set_property:
422 *
423 * This is the legacy entry point to update a property attached to the
424 * CRTC.
425 *
426 * Drivers implementing atomic modeset should use
427 * drm_atomic_helper_crtc_set_property() to implement this hook.
428 *
429 * This callback is optional if the driver does not support any legacy
430 * driver-private properties.
431 *
432 * RETURNS:
433 *
434 * 0 on success or a negative error code on failure.
435 */
bffd9de0
PZ
436 int (*set_property)(struct drm_crtc *crtc,
437 struct drm_property *property, uint64_t val);
144ecb97 438
88548636
DV
439 /**
440 * @atomic_duplicate_state:
441 *
442 * Duplicate the current atomic state for this CRTC and return it.
443 * The core and helpers gurantee that any atomic state duplicated with
444 * this hook and still owned by the caller (i.e. not transferred to the
445 * driver by calling ->atomic_commit() from struct
446 * &drm_mode_config_funcs) will be cleaned up by calling the
447 * @atomic_destroy_state hook in this structure.
448 *
449 * Atomic drivers which don't subclass struct &drm_crtc should use
450 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
451 * state structure to extend it with driver-private state should use
452 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
453 * duplicated in a consistent fashion across drivers.
454 *
455 * It is an error to call this hook before crtc->state has been
456 * initialized correctly.
457 *
458 * NOTE:
459 *
460 * If the duplicate state references refcounted resources this hook must
461 * acquire a reference for each of them. The driver must release these
462 * references again in @atomic_destroy_state.
463 *
464 * RETURNS:
465 *
466 * Duplicated atomic state or NULL when the allocation failed.
467 */
144ecb97 468 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
88548636
DV
469
470 /**
471 * @atomic_destroy_state:
472 *
473 * Destroy a state duplicated with @atomic_duplicate_state and release
474 * or unreference all resources it references
475 */
144ecb97 476 void (*atomic_destroy_state)(struct drm_crtc *crtc,
cc4ceb48 477 struct drm_crtc_state *state);
88548636
DV
478
479 /**
480 * @atomic_set_property:
481 *
482 * Decode a driver-private property value and store the decoded value
483 * into the passed-in state structure. Since the atomic core decodes all
484 * standardized properties (even for extensions beyond the core set of
485 * properties which might not be implemented by all drivers) this
486 * requires drivers to subclass the state structure.
487 *
488 * Such driver-private properties should really only be implemented for
489 * truly hardware/vendor specific state. Instead it is preferred to
490 * standardize atomic extension and decode the properties used to expose
491 * such an extension in the core.
492 *
493 * Do not call this function directly, use
494 * drm_atomic_crtc_set_property() instead.
495 *
496 * This callback is optional if the driver does not support any
497 * driver-private atomic properties.
498 *
499 * NOTE:
500 *
501 * This function is called in the state assembly phase of atomic
502 * modesets, which can be aborted for any reason (including on
503 * userspace's request to just check whether a configuration would be
504 * possible). Drivers MUST NOT touch any persistent state (hardware or
505 * software) or data structures except the passed in @state parameter.
506 *
507 * Also since userspace controls in which order properties are set this
508 * function must not do any input validation (since the state update is
509 * incomplete and hence likely inconsistent). Instead any such input
510 * validation must be done in the various atomic_check callbacks.
511 *
512 * RETURNS:
513 *
514 * 0 if the property has been found, -EINVAL if the property isn't
515 * implemented by the driver (which should never happen, the core only
516 * asks for properties attached to this CRTC). No other validation is
517 * allowed by the driver. The core already checks that the property
518 * value is within the range (integer, valid enum value, ...) the driver
519 * set when registering the property.
520 */
144ecb97
DV
521 int (*atomic_set_property)(struct drm_crtc *crtc,
522 struct drm_crtc_state *state,
523 struct drm_property *property,
524 uint64_t val);
88548636
DV
525 /**
526 * @atomic_get_property:
527 *
528 * Reads out the decoded driver-private property. This is used to
c6b0ca3e 529 * implement the GETCRTC IOCTL.
88548636
DV
530 *
531 * Do not call this function directly, use
532 * drm_atomic_crtc_get_property() instead.
533 *
534 * This callback is optional if the driver does not support any
535 * driver-private atomic properties.
536 *
537 * RETURNS:
538 *
539 * 0 on success, -EINVAL if the property isn't implemented by the
540 * driver (which should never happen, the core only asks for
541 * properties attached to this CRTC).
542 */
ac9c9256
RC
543 int (*atomic_get_property)(struct drm_crtc *crtc,
544 const struct drm_crtc_state *state,
545 struct drm_property *property,
546 uint64_t *val);
79190ea2
BG
547
548 /**
549 * @late_register:
550 *
551 * This optional hook can be used to register additional userspace
552 * interfaces attached to the crtc like debugfs interfaces.
553 * It is called late in the driver load sequence from drm_dev_register().
554 * Everything added from this callback should be unregistered in
555 * the early_unregister callback.
556 *
557 * Returns:
558 *
559 * 0 on success, or a negative error code on failure.
560 */
561 int (*late_register)(struct drm_crtc *crtc);
562
563 /**
564 * @early_unregister:
565 *
566 * This optional hook should be used to unregister the additional
567 * userspace interfaces attached to the crtc from
568 * late_unregister(). It is called from drm_dev_unregister(),
569 * early in the driver unload sequence to disable userspace access
570 * before data structures are torndown.
571 */
572 void (*early_unregister)(struct drm_crtc *crtc);
9edbf1fa
TV
573
574 /**
575 * @set_crc_source:
576 *
577 * Changes the source of CRC checksums of frames at the request of
578 * userspace, typically for testing purposes. The sources available are
579 * specific of each driver and a %NULL value indicates that CRC
580 * generation is to be switched off.
581 *
582 * When CRC generation is enabled, the driver should call
583 * drm_crtc_add_crc_entry() at each frame, providing any information
584 * that characterizes the frame contents in the crcN arguments, as
585 * provided from the configured source. Drivers must accept a "auto"
586 * source name that will select a default source for this CRTC.
587 *
588 * This callback is optional if the driver does not support any CRC
589 * generation functionality.
590 *
591 * RETURNS:
592 *
593 * 0 on success or a negative error code on failure.
594 */
595 int (*set_crc_source)(struct drm_crtc *crtc, const char *source,
596 size_t *values_cnt);
f453ba04
DA
597};
598
599/**
3bf0401c 600 * struct drm_crtc - central CRTC control structure
7749163e 601 * @dev: parent DRM device
2c0c33d4 602 * @port: OF node used by drm_of_find_possible_crtcs()
7749163e 603 * @head: list management
ac3ba4a5 604 * @name: human readable name, can be overwritten by the driver
51fd371b 605 * @mutex: per-CRTC locking
7749163e 606 * @base: base KMS object for ID tracking etc.
e13161af
MR
607 * @primary: primary plane for this CRTC
608 * @cursor: cursor plane for this CRTC
2c0c33d4
DV
609 * @cursor_x: current x position of the cursor, used for universal cursor planes
610 * @cursor_y: current y position of the cursor, used for universal cursor planes
f453ba04 611 * @enabled: is this CRTC enabled?
7749163e
JB
612 * @mode: current mode timings
613 * @hwmode: mode timings as programmed to hw regs
f453ba04
DA
614 * @x: x position on screen
615 * @y: y position on screen
f453ba04 616 * @funcs: CRTC control functions
7749163e
JB
617 * @gamma_size: size of gamma ramp
618 * @gamma_store: gamma ramp values
7749163e 619 * @helper_private: mid-layer private data
bffd9de0 620 * @properties: property tracking for this CRTC
f453ba04
DA
621 *
622 * Each CRTC may have one or more connectors associated with it. This structure
623 * allows the CRTC to be controlled.
624 */
625struct drm_crtc {
626 struct drm_device *dev;
7e435aad 627 struct device_node *port;
f453ba04
DA
628 struct list_head head;
629
fa3ab4c2
VS
630 char *name;
631
ac3ba4a5
DV
632 /**
633 * @mutex:
29494c17
DV
634 *
635 * This provides a read lock for the overall crtc state (mode, dpms
636 * state, ...) and a write lock for everything which can be update
ac3ba4a5
DV
637 * without a full modeset (fb, cursor data, crtc properties ...). Full
638 * modeset also need to grab dev->mode_config.connection_mutex.
29494c17 639 */
51fd371b 640 struct drm_modeset_lock mutex;
29494c17 641
f453ba04
DA
642 struct drm_mode_object base;
643
e13161af
MR
644 /* primary and cursor planes for CRTC */
645 struct drm_plane *primary;
646 struct drm_plane *cursor;
647
96094081
DV
648 /**
649 * @index: Position inside the mode_config.list, can be used as an array
650 * index. It is invariant over the lifetime of the CRTC.
651 */
490d3d1b
CW
652 unsigned index;
653
161d0dc1
MR
654 /* position of cursor plane on crtc */
655 int cursor_x;
656 int cursor_y;
657
f453ba04
DA
658 bool enabled;
659
27641c3f 660 /* Requested mode from modesetting. */
f453ba04
DA
661 struct drm_display_mode mode;
662
27641c3f
MK
663 /* Programmed mode in hw, after adjustments for encoders,
664 * crtc, panel scaling etc. Needed for timestamping etc.
665 */
666 struct drm_display_mode hwmode;
667
f453ba04 668 int x, y;
f453ba04
DA
669 const struct drm_crtc_funcs *funcs;
670
5488dc16 671 /* Legacy FB CRTC gamma size for reporting to userspace */
f453ba04
DA
672 uint32_t gamma_size;
673 uint16_t *gamma_store;
674
675 /* if you are using the helper */
4490d4c7 676 const struct drm_crtc_helper_funcs *helper_private;
bffd9de0
PZ
677
678 struct drm_object_properties properties;
d059f652 679
3b24f7d6
DV
680 /**
681 * @state:
682 *
683 * Current atomic state for this CRTC.
684 */
144ecb97
DV
685 struct drm_crtc_state *state;
686
3b24f7d6
DV
687 /**
688 * @commit_list:
689 *
690 * List of &drm_crtc_commit structures tracking pending commits.
691 * Protected by @commit_lock. This list doesn't hold its own full
692 * reference, but burrows it from the ongoing commit. Commit entries
693 * must be removed from this list once the commit is fully completed,
694 * but before it's correspoding &drm_atomic_state gets destroyed.
695 */
696 struct list_head commit_list;
697
698 /**
699 * @commit_lock:
700 *
701 * Spinlock to protect @commit_list.
702 */
703 spinlock_t commit_lock;
704
705 /**
706 * @acquire_ctx:
707 *
708 * Per-CRTC implicit acquire context used by atomic drivers for legacy
709 * IOCTLs, so that atomic drivers can get at the locking acquire
710 * context.
d059f652
DV
711 */
712 struct drm_modeset_acquire_ctx *acquire_ctx;
9edbf1fa
TV
713
714#ifdef CONFIG_DEBUG_FS
715 /**
716 * @debugfs_entry:
717 *
718 * Debugfs directory for this CRTC.
719 */
720 struct dentry *debugfs_entry;
721
722 /**
723 * @crc:
724 *
725 * Configuration settings of CRC capture.
726 */
727 struct drm_crtc_crc crc;
728#endif
f453ba04
DA
729};
730
f453ba04 731/**
3bf0401c 732 * struct drm_mode_set - new values for a CRTC config change
ef27351a
JB
733 * @fb: framebuffer to use for new config
734 * @crtc: CRTC whose configuration we're about to change
735 * @mode: mode timings to use
736 * @x: position of this CRTC relative to @fb
737 * @y: position of this CRTC relative to @fb
738 * @connectors: array of connectors to drive with this CRTC if possible
739 * @num_connectors: size of @connectors array
f453ba04
DA
740 *
741 * Represents a single crtc the connectors that it drives with what mode
742 * and from which framebuffer it scans out from.
743 *
744 * This is used to set modes.
745 */
746struct drm_mode_set {
f453ba04
DA
747 struct drm_framebuffer *fb;
748 struct drm_crtc *crtc;
749 struct drm_display_mode *mode;
750
751 uint32_t x;
752 uint32_t y;
753
754 struct drm_connector **connectors;
755 size_t num_connectors;
756};
757
758/**
550cebcd 759 * struct drm_mode_config_funcs - basic driver provided mode setting functions
550cebcd
JB
760 *
761 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
762 * involve drivers.
f453ba04
DA
763 */
764struct drm_mode_config_funcs {
9953f417
DV
765 /**
766 * @fb_create:
767 *
768 * Create a new framebuffer object. The core does basic checks on the
769 * requested metadata, but most of that is left to the driver. See
770 * struct &drm_mode_fb_cmd2 for details.
771 *
d55f5320
DV
772 * If the parameters are deemed valid and the backing storage objects in
773 * the underlying memory manager all exist, then the driver allocates
774 * a new &drm_framebuffer structure, subclassed to contain
775 * driver-specific information (like the internal native buffer object
776 * references). It also needs to fill out all relevant metadata, which
777 * should be done by calling drm_helper_mode_fill_fb_struct().
778 *
779 * The initialization is finalized by calling drm_framebuffer_init(),
780 * which registers the framebuffer and makes it accessible to other
781 * threads.
782 *
9953f417
DV
783 * RETURNS:
784 *
785 * A new framebuffer with an initial reference count of 1 or a negative
786 * error code encoded with ERR_PTR().
787 */
550cebcd
JB
788 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
789 struct drm_file *file_priv,
1eb83451 790 const struct drm_mode_fb_cmd2 *mode_cmd);
9953f417
DV
791
792 /**
793 * @output_poll_changed:
794 *
795 * Callback used by helpers to inform the driver of output configuration
796 * changes.
797 *
798 * Drivers implementing fbdev emulation with the helpers can call
799 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
800 * helper of output changes.
801 *
802 * FIXME:
803 *
804 * Except that there's no vtable for device-level helper callbacks
805 * there's no reason this is a core function.
806 */
eb1f8e4f 807 void (*output_poll_changed)(struct drm_device *dev);
cc4ceb48 808
9953f417
DV
809 /**
810 * @atomic_check:
811 *
812 * This is the only hook to validate an atomic modeset update. This
813 * function must reject any modeset and state changes which the hardware
814 * or driver doesn't support. This includes but is of course not limited
815 * to:
816 *
817 * - Checking that the modes, framebuffers, scaling and placement
818 * requirements and so on are within the limits of the hardware.
819 *
820 * - Checking that any hidden shared resources are not oversubscribed.
821 * This can be shared PLLs, shared lanes, overall memory bandwidth,
822 * display fifo space (where shared between planes or maybe even
823 * CRTCs).
824 *
825 * - Checking that virtualized resources exported to userspace are not
826 * oversubscribed. For various reasons it can make sense to expose
827 * more planes, crtcs or encoders than which are physically there. One
828 * example is dual-pipe operations (which generally should be hidden
829 * from userspace if when lockstepped in hardware, exposed otherwise),
830 * where a plane might need 1 hardware plane (if it's just on one
831 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
832 * shared a hardware plane with a 2nd plane (if there's a compatible
833 * plane requested on the area handled by the other pipe).
834 *
835 * - Check that any transitional state is possible and that if
836 * requested, the update can indeed be done in the vblank period
837 * without temporarily disabling some functions.
838 *
839 * - Check any other constraints the driver or hardware might have.
840 *
841 * - This callback also needs to correctly fill out the &drm_crtc_state
842 * in this update to make sure that drm_atomic_crtc_needs_modeset()
843 * reflects the nature of the possible update and returns true if and
844 * only if the update cannot be applied without tearing within one
845 * vblank on that CRTC. The core uses that information to reject
846 * updates which require a full modeset (i.e. blanking the screen, or
847 * at least pausing updates for a substantial amount of time) if
848 * userspace has disallowed that in its request.
849 *
850 * - The driver also does not need to repeat basic input validation
851 * like done for the corresponding legacy entry points. The core does
852 * that before calling this hook.
853 *
854 * See the documentation of @atomic_commit for an exhaustive list of
855 * error conditions which don't have to be checked at the
856 * ->atomic_check() stage?
857 *
858 * See the documentation for struct &drm_atomic_state for how exactly
859 * an atomic modeset update is described.
860 *
861 * Drivers using the atomic helpers can implement this hook using
862 * drm_atomic_helper_check(), or one of the exported sub-functions of
863 * it.
864 *
865 * RETURNS:
866 *
867 * 0 on success or one of the below negative error codes:
868 *
869 * - -EINVAL, if any of the above constraints are violated.
870 *
871 * - -EDEADLK, when returned from an attempt to acquire an additional
872 * &drm_modeset_lock through drm_modeset_lock().
873 *
874 * - -ENOMEM, if allocating additional state sub-structures failed due
875 * to lack of memory.
876 *
877 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
878 * This can either be due to a pending signal, or because the driver
879 * needs to completely bail out to recover from an exceptional
880 * situation like a GPU hang. From a userspace point all errors are
881 * treated equally.
882 */
cc4ceb48 883 int (*atomic_check)(struct drm_device *dev,
9953f417
DV
884 struct drm_atomic_state *state);
885
886 /**
887 * @atomic_commit:
888 *
889 * This is the only hook to commit an atomic modeset update. The core
890 * guarantees that @atomic_check has been called successfully before
891 * calling this function, and that nothing has been changed in the
892 * interim.
893 *
894 * See the documentation for struct &drm_atomic_state for how exactly
895 * an atomic modeset update is described.
896 *
897 * Drivers using the atomic helpers can implement this hook using
898 * drm_atomic_helper_commit(), or one of the exported sub-functions of
899 * it.
900 *
286dbb8d 901 * Nonblocking commits (as indicated with the nonblock parameter) must
9953f417
DV
902 * do any preparatory work which might result in an unsuccessful commit
903 * in the context of this callback. The only exceptions are hardware
904 * errors resulting in -EIO. But even in that case the driver must
905 * ensure that the display pipe is at least running, to avoid
906 * compositors crashing when pageflips don't work. Anything else,
907 * specifically committing the update to the hardware, should be done
908 * without blocking the caller. For updates which do not require a
909 * modeset this must be guaranteed.
910 *
911 * The driver must wait for any pending rendering to the new
912 * framebuffers to complete before executing the flip. It should also
913 * wait for any pending rendering from other drivers if the underlying
286dbb8d 914 * buffer is a shared dma-buf. Nonblocking commits must not wait for
9953f417
DV
915 * rendering in the context of this callback.
916 *
917 * An application can request to be notified when the atomic commit has
918 * completed. These events are per-CRTC and can be distinguished by the
919 * CRTC index supplied in &drm_event to userspace.
920 *
921 * The drm core will supply a struct &drm_event in the event
61802130
DV
922 * member of each CRTC's &drm_crtc_state structure. See the
923 * documentation for &drm_crtc_state for more details about the precise
924 * semantics of this event.
9953f417
DV
925 *
926 * NOTE:
927 *
928 * Drivers are not allowed to shut down any display pipe successfully
929 * enabled through an atomic commit on their own. Doing so can result in
930 * compositors crashing if a page flip is suddenly rejected because the
931 * pipe is off.
932 *
933 * RETURNS:
934 *
935 * 0 on success or one of the below negative error codes:
936 *
286dbb8d 937 * - -EBUSY, if a nonblocking updated is requested and there is
9953f417
DV
938 * an earlier updated pending. Drivers are allowed to support a queue
939 * of outstanding updates, but currently no driver supports that.
940 * Note that drivers must wait for preceding updates to complete if a
941 * synchronous update is requested, they are not allowed to fail the
942 * commit in that case.
943 *
944 * - -ENOMEM, if the driver failed to allocate memory. Specifically
945 * this can happen when trying to pin framebuffers, which must only
946 * be done when committing the state.
947 *
948 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
949 * that the driver has run out of vram, iommu space or similar GPU
950 * address space needed for framebuffer.
951 *
952 * - -EIO, if the hardware completely died.
953 *
954 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
955 * This can either be due to a pending signal, or because the driver
956 * needs to completely bail out to recover from an exceptional
957 * situation like a GPU hang. From a userspace point of view all errors are
958 * treated equally.
959 *
960 * This list is exhaustive. Specifically this hook is not allowed to
961 * return -EINVAL (any invalid requests should be caught in
962 * @atomic_check) or -EDEADLK (this function must not acquire
963 * additional modeset locks).
964 */
cc4ceb48 965 int (*atomic_commit)(struct drm_device *dev,
9953f417 966 struct drm_atomic_state *state,
286dbb8d 967 bool nonblock);
9953f417
DV
968
969 /**
970 * @atomic_state_alloc:
971 *
972 * This optional hook can be used by drivers that want to subclass struct
973 * &drm_atomic_state to be able to track their own driver-private global
974 * state easily. If this hook is implemented, drivers must also
975 * implement @atomic_state_clear and @atomic_state_free.
976 *
977 * RETURNS:
978 *
979 * A new &drm_atomic_state on success or NULL on failure.
980 */
036ef573 981 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
9953f417
DV
982
983 /**
984 * @atomic_state_clear:
985 *
986 * This hook must clear any driver private state duplicated into the
987 * passed-in &drm_atomic_state. This hook is called when the caller
988 * encountered a &drm_modeset_lock deadlock and needs to drop all
989 * already acquired locks as part of the deadlock avoidance dance
990 * implemented in drm_modeset_lock_backoff().
991 *
992 * Any duplicated state must be invalidated since a concurrent atomic
993 * update might change it, and the drm atomic interfaces always apply
994 * updates as relative changes to the current state.
995 *
996 * Drivers that implement this must call drm_atomic_state_default_clear()
997 * to clear common state.
998 */
036ef573 999 void (*atomic_state_clear)(struct drm_atomic_state *state);
9953f417
DV
1000
1001 /**
1002 * @atomic_state_free:
1003 *
1004 * This hook needs driver private resources and the &drm_atomic_state
1005 * itself. Note that the core first calls drm_atomic_state_clear() to
1006 * avoid code duplicate between the clear and free hooks.
1007 *
1008 * Drivers that implement this must call drm_atomic_state_default_free()
1009 * to release common resources.
1010 */
036ef573 1011 void (*atomic_state_free)(struct drm_atomic_state *state);
f453ba04
DA
1012};
1013
f453ba04 1014/**
2c0c33d4 1015 * struct drm_mode_config - Mode configuration control structure
a62c93d5 1016 * @mutex: mutex protecting KMS related lists and structures
2c0c33d4
DV
1017 * @connection_mutex: ww mutex protecting connector state and routing
1018 * @acquire_ctx: global implicit acquire context used by atomic drivers for
c6b0ca3e 1019 * legacy IOCTLs
2c0c33d4 1020 * @fb_lock: mutex to protect fb state and lists
a62c93d5
JB
1021 * @num_fb: number of fbs available
1022 * @fb_list: list of framebuffers available
a62c93d5
JB
1023 * @num_encoder: number of encoders on this device
1024 * @encoder_list: list of encoder objects
2c0c33d4
DV
1025 * @num_overlay_plane: number of overlay planes on this device
1026 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1027 * @plane_list: list of plane objects
a62c93d5
JB
1028 * @num_crtc: number of CRTCs on this device
1029 * @crtc_list: list of CRTC objects
2c0c33d4 1030 * @property_list: list of property objects
a62c93d5
JB
1031 * @min_width: minimum pixel width on this device
1032 * @min_height: minimum pixel height on this device
1033 * @max_width: maximum pixel width on this device
1034 * @max_height: maximum pixel height on this device
1035 * @funcs: core driver provided mode setting functions
1036 * @fb_base: base address of the framebuffer
2c0c33d4
DV
1037 * @poll_enabled: track polling support for this device
1038 * @poll_running: track polling status for this device
ac3ba4a5 1039 * @delayed_event: track delayed poll uevent deliver for this device
a62c93d5 1040 * @output_poll_work: delayed work for polling in process context
2c0c33d4 1041 * @property_blob_list: list of all the blob property objects
8fb6e7a5 1042 * @blob_lock: mutex for blob property allocation and management
a62c93d5 1043 * @*_property: core property tracking
2c0c33d4
DV
1044 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1045 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2c0c33d4
DV
1046 * @cursor_width: hint to userspace for max cursor width
1047 * @cursor_height: hint to userspace for max cursor height
9f2a7950 1048 * @helper_private: mid-layer private data
f453ba04 1049 *
a62c93d5
JB
1050 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1051 * enumerated by the driver are added here, as are global properties. Some
1052 * global restrictions are also here, e.g. dimension restrictions.
f453ba04
DA
1053 */
1054struct drm_mode_config {
ad2563c2 1055 struct mutex mutex; /* protects configuration (mode lists etc.) */
51fd371b
RC
1056 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1057 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
ac3ba4a5
DV
1058
1059 /**
1060 * @idr_mutex:
1061 *
1062 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1063 * and @tile_idr.
1064 */
1065 struct mutex idr_mutex;
1066
1067 /**
1068 * @crtc_idr:
1069 *
1070 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1071 * connector, modes - just makes life easier to have only one.
1072 */
1073 struct idr crtc_idr;
1074
1075 /**
1076 * @tile_idr:
1077 *
1078 * Use this idr for allocating new IDs for tiled sinks like use in some
1079 * high-res DP MST screens.
1080 */
1081 struct idr tile_idr;
4b096ac1 1082
2c0c33d4 1083 struct mutex fb_lock; /* proctects global and per-file fb lists */
f453ba04
DA
1084 int num_fb;
1085 struct list_head fb_list;
4b096ac1 1086
96094081
DV
1087 /**
1088 * @num_connector: Number of connectors on this device.
1089 */
f453ba04 1090 int num_connector;
96094081
DV
1091 /**
1092 * @connector_ida: ID allocator for connector indices.
1093 */
5fff80bb 1094 struct ida connector_ida;
96094081
DV
1095 /**
1096 * @connector_list: List of connector objects.
1097 */
f453ba04
DA
1098 struct list_head connector_list;
1099 int num_encoder;
1100 struct list_head encoder_list;
e27dde3e
MR
1101
1102 /*
1103 * Track # of overlay planes separately from # of total planes. By
1104 * default we only advertise overlay planes to userspace; if userspace
1105 * sets the "universal plane" capability bit, we'll go ahead and
1106 * expose all planes.
1107 */
1108 int num_overlay_plane;
1109 int num_total_plane;
8cf5c917 1110 struct list_head plane_list;
f453ba04
DA
1111
1112 int num_crtc;
1113 struct list_head crtc_list;
1114
1115 struct list_head property_list;
1116
f453ba04
DA
1117 int min_width, min_height;
1118 int max_width, max_height;
e6ecefaa 1119 const struct drm_mode_config_funcs *funcs;
d883f7f1 1120 resource_size_t fb_base;
f453ba04 1121
eb1f8e4f
DA
1122 /* output poll support */
1123 bool poll_enabled;
905bc9ff 1124 bool poll_running;
162b6a57 1125 bool delayed_event;
991ea75c 1126 struct delayed_work output_poll_work;
eb1f8e4f 1127
8fb6e7a5
DS
1128 struct mutex blob_lock;
1129
f453ba04
DA
1130 /* pointers to standard properties */
1131 struct list_head property_blob_list;
9a6bc03c
DV
1132 /**
1133 * @edid_property: Default connector property to hold the EDID of the
1134 * currently connected sink, if any.
1135 */
f453ba04 1136 struct drm_property *edid_property;
9a6bc03c
DV
1137 /**
1138 * @dpms_property: Default connector property to control the
1139 * connector's DPMS state.
1140 */
f453ba04 1141 struct drm_property *dpms_property;
9a6bc03c
DV
1142 /**
1143 * @path_property: Default connector property to hold the DP MST path
1144 * for the port.
1145 */
43aba7eb 1146 struct drm_property *path_property;
9a6bc03c
DV
1147 /**
1148 * @tile_property: Default connector property to store the tile
1149 * position of a tiled screen, for sinks which need to be driven with
1150 * multiple CRTCs.
1151 */
6f134d7b 1152 struct drm_property *tile_property;
9a6bc03c
DV
1153 /**
1154 * @plane_type_property: Default plane property to differentiate
1155 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1156 */
9922ab5a 1157 struct drm_property *plane_type_property;
9a6bc03c
DV
1158 /**
1159 * @prop_src_x: Default atomic plane property for the plane source
1160 * position in the connected &drm_framebuffer.
1161 */
6b4959f4 1162 struct drm_property *prop_src_x;
9a6bc03c
DV
1163 /**
1164 * @prop_src_y: Default atomic plane property for the plane source
1165 * position in the connected &drm_framebuffer.
1166 */
6b4959f4 1167 struct drm_property *prop_src_y;
9a6bc03c
DV
1168 /**
1169 * @prop_src_w: Default atomic plane property for the plane source
1170 * position in the connected &drm_framebuffer.
1171 */
6b4959f4 1172 struct drm_property *prop_src_w;
9a6bc03c
DV
1173 /**
1174 * @prop_src_h: Default atomic plane property for the plane source
1175 * position in the connected &drm_framebuffer.
1176 */
6b4959f4 1177 struct drm_property *prop_src_h;
9a6bc03c
DV
1178 /**
1179 * @prop_crtc_x: Default atomic plane property for the plane destination
1180 * position in the &drm_crtc is is being shown on.
1181 */
6b4959f4 1182 struct drm_property *prop_crtc_x;
9a6bc03c
DV
1183 /**
1184 * @prop_crtc_y: Default atomic plane property for the plane destination
1185 * position in the &drm_crtc is is being shown on.
1186 */
6b4959f4 1187 struct drm_property *prop_crtc_y;
9a6bc03c
DV
1188 /**
1189 * @prop_crtc_w: Default atomic plane property for the plane destination
1190 * position in the &drm_crtc is is being shown on.
1191 */
6b4959f4 1192 struct drm_property *prop_crtc_w;
9a6bc03c
DV
1193 /**
1194 * @prop_crtc_h: Default atomic plane property for the plane destination
1195 * position in the &drm_crtc is is being shown on.
1196 */
6b4959f4 1197 struct drm_property *prop_crtc_h;
9a6bc03c
DV
1198 /**
1199 * @prop_fb_id: Default atomic plane property to specify the
1200 * &drm_framebuffer.
1201 */
6b4959f4 1202 struct drm_property *prop_fb_id;
9a6bc03c
DV
1203 /**
1204 * @prop_crtc_id: Default atomic plane property to specify the
1205 * &drm_crtc.
1206 */
6b4959f4 1207 struct drm_property *prop_crtc_id;
9a6bc03c
DV
1208 /**
1209 * @prop_active: Default atomic CRTC property to control the active
1210 * state, which is the simplified implementation for DPMS in atomic
1211 * drivers.
1212 */
eab3bbef 1213 struct drm_property *prop_active;
9a6bc03c
DV
1214 /**
1215 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1216 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1217 * connectors must be of and active must be set to disabled, too.
1218 */
955f3c33 1219 struct drm_property *prop_mode_id;
f453ba04 1220
9a6bc03c
DV
1221 /**
1222 * @dvi_i_subconnector_property: Optional DVI-I property to
1223 * differentiate between analog or digital mode.
1224 */
f453ba04 1225 struct drm_property *dvi_i_subconnector_property;
9a6bc03c
DV
1226 /**
1227 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1228 * select between analog or digital mode.
1229 */
f453ba04
DA
1230 struct drm_property *dvi_i_select_subconnector_property;
1231
9a6bc03c
DV
1232 /**
1233 * @tv_subconnector_property: Optional TV property to differentiate
1234 * between different TV connector types.
1235 */
f453ba04 1236 struct drm_property *tv_subconnector_property;
9a6bc03c
DV
1237 /**
1238 * @tv_select_subconnector_property: Optional TV property to select
1239 * between different TV connector types.
1240 */
f453ba04 1241 struct drm_property *tv_select_subconnector_property;
9a6bc03c
DV
1242 /**
1243 * @tv_mode_property: Optional TV property to select
1244 * the output TV mode.
1245 */
f453ba04 1246 struct drm_property *tv_mode_property;
9a6bc03c
DV
1247 /**
1248 * @tv_left_margin_property: Optional TV property to set the left
1249 * margin.
1250 */
f453ba04 1251 struct drm_property *tv_left_margin_property;
9a6bc03c
DV
1252 /**
1253 * @tv_right_margin_property: Optional TV property to set the right
1254 * margin.
1255 */
f453ba04 1256 struct drm_property *tv_right_margin_property;
9a6bc03c
DV
1257 /**
1258 * @tv_top_margin_property: Optional TV property to set the right
1259 * margin.
1260 */
f453ba04 1261 struct drm_property *tv_top_margin_property;
9a6bc03c
DV
1262 /**
1263 * @tv_bottom_margin_property: Optional TV property to set the right
1264 * margin.
1265 */
f453ba04 1266 struct drm_property *tv_bottom_margin_property;
9a6bc03c
DV
1267 /**
1268 * @tv_brightness_property: Optional TV property to set the
1269 * brightness.
1270 */
b6b7902e 1271 struct drm_property *tv_brightness_property;
9a6bc03c
DV
1272 /**
1273 * @tv_contrast_property: Optional TV property to set the
1274 * contrast.
1275 */
b6b7902e 1276 struct drm_property *tv_contrast_property;
9a6bc03c
DV
1277 /**
1278 * @tv_flicker_reduction_property: Optional TV property to control the
1279 * flicker reduction mode.
1280 */
b6b7902e 1281 struct drm_property *tv_flicker_reduction_property;
9a6bc03c
DV
1282 /**
1283 * @tv_overscan_property: Optional TV property to control the overscan
1284 * setting.
1285 */
a75f0236 1286 struct drm_property *tv_overscan_property;
9a6bc03c
DV
1287 /**
1288 * @tv_saturation_property: Optional TV property to set the
1289 * saturation.
1290 */
a75f0236 1291 struct drm_property *tv_saturation_property;
9a6bc03c
DV
1292 /**
1293 * @tv_hue_property: Optional TV property to set the hue.
1294 */
a75f0236 1295 struct drm_property *tv_hue_property;
f453ba04 1296
9a6bc03c
DV
1297 /**
1298 * @scaling_mode_property: Optional connector property to control the
1299 * upscaling, mostly used for built-in panels.
1300 */
f453ba04 1301 struct drm_property *scaling_mode_property;
9a6bc03c
DV
1302 /**
1303 * @aspect_ratio_property: Optional connector property to control the
1304 * HDMI infoframe aspect ratio setting.
1305 */
ff587e45 1306 struct drm_property *aspect_ratio_property;
9a6bc03c
DV
1307 /**
1308 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1309 * convert the framebuffer's colors to linear gamma.
1310 */
5488dc16 1311 struct drm_property *degamma_lut_property;
9a6bc03c
DV
1312 /**
1313 * @degamma_lut_size_property: Optional CRTC property for the size of
1314 * the degamma LUT as supported by the driver (read-only).
1315 */
5488dc16 1316 struct drm_property *degamma_lut_size_property;
9a6bc03c
DV
1317 /**
1318 * @ctm_property: Optional CRTC property to set the
1319 * matrix used to convert colors after the lookup in the
1320 * degamma LUT.
1321 */
5488dc16 1322 struct drm_property *ctm_property;
9a6bc03c
DV
1323 /**
1324 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1325 * convert the colors, after the CTM matrix, to the gamma space of the
1326 * connected screen.
1327 */
5488dc16 1328 struct drm_property *gamma_lut_property;
9a6bc03c
DV
1329 /**
1330 * @gamma_lut_size_property: Optional CRTC property for the size of the
1331 * gamma LUT as supported by the driver (read-only).
1332 */
5488dc16
LL
1333 struct drm_property *gamma_lut_size_property;
1334
9a6bc03c
DV
1335 /**
1336 * @suggested_x_property: Optional connector property with a hint for
1337 * the position of the output on the host's screen.
1338 */
5bb2bbf5 1339 struct drm_property *suggested_x_property;
9a6bc03c
DV
1340 /**
1341 * @suggested_y_property: Optional connector property with a hint for
1342 * the position of the output on the host's screen.
1343 */
5bb2bbf5
DA
1344 struct drm_property *suggested_y_property;
1345
019d96cb
DA
1346 /* dumb ioctl parameters */
1347 uint32_t preferred_depth, prefer_shadow;
62f2104f 1348
9a6bc03c
DV
1349 /**
1350 * @async_page_flip: Does this device support async flips on the primary
1351 * plane?
1352 */
62f2104f 1353 bool async_page_flip;
8716ed4e 1354
ac3ba4a5
DV
1355 /**
1356 * @allow_fb_modifiers:
1357 *
1358 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1359 */
e3eb3250
RC
1360 bool allow_fb_modifiers;
1361
8716ed4e
AD
1362 /* cursor size */
1363 uint32_t cursor_width, cursor_height;
9f2a7950
DV
1364
1365 struct drm_mode_config_helper_funcs *helper_private;
f453ba04
DA
1366};
1367
1368#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
f453ba04 1369
f9882876
VS
1370extern __printf(6, 7)
1371int drm_crtc_init_with_planes(struct drm_device *dev,
1372 struct drm_crtc *crtc,
1373 struct drm_plane *primary,
1374 struct drm_plane *cursor,
1375 const struct drm_crtc_funcs *funcs,
1376 const char *name, ...);
f453ba04 1377extern void drm_crtc_cleanup(struct drm_crtc *crtc);
490d3d1b
CW
1378
1379/**
1380 * drm_crtc_index - find the index of a registered CRTC
1381 * @crtc: CRTC to find index for
1382 *
1383 * Given a registered CRTC, return the index of that CRTC within a DRM
1384 * device's list of CRTCs.
1385 */
a5bd451b 1386static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)
490d3d1b
CW
1387{
1388 return crtc->index;
1389}
db5f7a6e
RK
1390
1391/**
1392 * drm_crtc_mask - find the mask of a registered CRTC
1393 * @crtc: CRTC to find mask for
1394 *
1395 * Given a registered CRTC, return the mask bit of that CRTC for an
1396 * encoder's possible_crtcs field.
1397 */
1dfdb0ed 1398static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc)
db5f7a6e
RK
1399{
1400 return 1 << drm_crtc_index(crtc);
1401}
f453ba04 1402
ecb7e16b
GP
1403extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1404 int *hdisplay, int *vdisplay);
6a0d9528
LW
1405extern int drm_crtc_force_disable(struct drm_crtc *crtc);
1406extern int drm_crtc_force_disable_all(struct drm_device *dev);
8cf5c917 1407
f453ba04 1408extern void drm_mode_config_init(struct drm_device *dev);
eb033556 1409extern void drm_mode_config_reset(struct drm_device *dev);
f453ba04 1410extern void drm_mode_config_cleanup(struct drm_device *dev);
55310008 1411
2d13b679 1412extern int drm_mode_set_config_internal(struct drm_mode_set *set);
81065548 1413
138f9ebb
DA
1414extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1415 char topology[8]);
1416extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1417 char topology[8]);
1418extern void drm_mode_put_tile_group(struct drm_device *dev,
1419 struct drm_tile_group *tg);
ff72145b 1420
96f60e37
RK
1421/* Helpers */
1422static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1423 uint32_t id)
1424{
1425 struct drm_mode_object *mo;
1426 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1427 return mo ? obj_to_crtc(mo) : NULL;
1428}
1429
6295d607
DV
1430#define drm_for_each_crtc(crtc, dev) \
1431 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1432
7a3f3d66
DV
1433static inline void
1434assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1435{
cff20ba2
DV
1436 /*
1437 * The connector hotadd/remove code currently grabs both locks when
1438 * updating lists. Hence readers need only hold either of them to be
1439 * safe and the check amounts to
1440 *
1441 * WARN_ON(not_holding(A) && not_holding(B)).
1442 */
1443 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
1444 !drm_modeset_is_locked(&mode_config->connection_mutex));
7a3f3d66
DV
1445}
1446
f453ba04 1447#endif /* __DRM_CRTC_H__ */