xref: /openbmc/linux/include/drm/drm_crtc.h (revision f4284724)
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/fb.h>
32 #include <linux/hdmi.h>
33 #include <linux/media-bus-format.h>
34 #include <uapi/drm/drm_mode.h>
35 #include <uapi/drm/drm_fourcc.h>
36 #include <drm/drm_modeset_lock.h>
37 #include <drm/drm_rect.h>
38 #include <drm/drm_mode_object.h>
39 #include <drm/drm_modes.h>
40 #include <drm/drm_device.h>
41 #include <drm/drm_property.h>
42 #include <drm/drm_plane.h>
43 #include <drm/drm_color_mgmt.h>
44 #include <drm/drm_debugfs_crc.h>
45 #include <drm/drm_mode_config.h>
46 
47 struct drm_connector;
48 struct drm_device;
49 struct drm_framebuffer;
50 struct drm_mode_set;
51 struct drm_file;
52 struct drm_clip_rect;
53 struct drm_printer;
54 struct drm_self_refresh_data;
55 struct device_node;
56 struct dma_fence;
57 struct edid;
58 
59 static inline int64_t U642I64(uint64_t val)
60 {
61 	return (int64_t)*((int64_t *)&val);
62 }
63 static inline uint64_t I642U64(int64_t val)
64 {
65 	return (uint64_t)*((uint64_t *)&val);
66 }
67 
68 struct drm_crtc;
69 struct drm_pending_vblank_event;
70 struct drm_plane;
71 struct drm_bridge;
72 struct drm_atomic_state;
73 
74 struct drm_crtc_helper_funcs;
75 struct drm_plane_helper_funcs;
76 
77 /**
78  * struct drm_crtc_state - mutable CRTC state
79  *
80  * Note that the distinction between @enable and @active is rather subtle:
81  * Flipping @active while @enable is set without changing anything else may
82  * never return in a failure from the &drm_mode_config_funcs.atomic_check
83  * callback. Userspace assumes that a DPMS On will always succeed. In other
84  * words: @enable controls resource assignment, @active controls the actual
85  * hardware state.
86  *
87  * The three booleans active_changed, connectors_changed and mode_changed are
88  * intended to indicate whether a full modeset is needed, rather than strictly
89  * describing what has changed in a commit. See also:
90  * drm_atomic_crtc_needs_modeset()
91  *
92  * WARNING: Transitional helpers (like drm_helper_crtc_mode_set() or
93  * drm_helper_crtc_mode_set_base()) do not maintain many of the derived control
94  * state like @plane_mask so drivers not converted over to atomic helpers should
95  * not rely on these being accurate!
96  */
97 struct drm_crtc_state {
98 	/** @crtc: backpointer to the CRTC */
99 	struct drm_crtc *crtc;
100 
101 	/**
102 	 * @enable: Whether the CRTC should be enabled, gates all other state.
103 	 * This controls reservations of shared resources. Actual hardware state
104 	 * is controlled by @active.
105 	 */
106 	bool enable;
107 
108 	/**
109 	 * @active: Whether the CRTC is actively displaying (used for DPMS).
110 	 * Implies that @enable is set. The driver must not release any shared
111 	 * resources if @active is set to false but @enable still true, because
112 	 * userspace expects that a DPMS ON always succeeds.
113 	 *
114 	 * Hence drivers must not consult @active in their various
115 	 * &drm_mode_config_funcs.atomic_check callback to reject an atomic
116 	 * commit. They can consult it to aid in the computation of derived
117 	 * hardware state, since even in the DPMS OFF state the display hardware
118 	 * should be as much powered down as when the CRTC is completely
119 	 * disabled through setting @enable to false.
120 	 */
121 	bool active;
122 
123 	/**
124 	 * @planes_changed: Planes on this crtc are updated. Used by the atomic
125 	 * helpers and drivers to steer the atomic commit control flow.
126 	 */
127 	bool planes_changed : 1;
128 
129 	/**
130 	 * @mode_changed: @mode or @enable has been changed. Used by the atomic
131 	 * helpers and drivers to steer the atomic commit control flow. See also
132 	 * drm_atomic_crtc_needs_modeset().
133 	 *
134 	 * Drivers are supposed to set this for any CRTC state changes that
135 	 * require a full modeset. They can also reset it to false if e.g. a
136 	 * @mode change can be done without a full modeset by only changing
137 	 * scaler settings.
138 	 */
139 	bool mode_changed : 1;
140 
141 	/**
142 	 * @active_changed: @active has been toggled. Used by the atomic
143 	 * helpers and drivers to steer the atomic commit control flow. See also
144 	 * drm_atomic_crtc_needs_modeset().
145 	 */
146 	bool active_changed : 1;
147 
148 	/**
149 	 * @connectors_changed: Connectors to this crtc have been updated,
150 	 * either in their state or routing. Used by the atomic
151 	 * helpers and drivers to steer the atomic commit control flow. See also
152 	 * drm_atomic_crtc_needs_modeset().
153 	 *
154 	 * Drivers are supposed to set this as-needed from their own atomic
155 	 * check code, e.g. from &drm_encoder_helper_funcs.atomic_check
156 	 */
157 	bool connectors_changed : 1;
158 	/**
159 	 * @zpos_changed: zpos values of planes on this crtc have been updated.
160 	 * Used by the atomic helpers and drivers to steer the atomic commit
161 	 * control flow.
162 	 */
163 	bool zpos_changed : 1;
164 	/**
165 	 * @color_mgmt_changed: Color management properties have changed
166 	 * (@gamma_lut, @degamma_lut or @ctm). Used by the atomic helpers and
167 	 * drivers to steer the atomic commit control flow.
168 	 */
169 	bool color_mgmt_changed : 1;
170 
171 	/**
172 	 * @no_vblank:
173 	 *
174 	 * Reflects the ability of a CRTC to send VBLANK events. This state
175 	 * usually depends on the pipeline configuration. If set to true, DRM
176 	 * atomic helpers will send out a fake VBLANK event during display
177 	 * updates after all hardware changes have been committed. This is
178 	 * implemented in drm_atomic_helper_fake_vblank().
179 	 *
180 	 * One usage is for drivers and/or hardware without support for VBLANK
181 	 * interrupts. Such drivers typically do not initialize vblanking
182 	 * (i.e., call drm_vblank_init() with the number of CRTCs). For CRTCs
183 	 * without initialized vblanking, this field is set to true in
184 	 * drm_atomic_helper_check_modeset(), and a fake VBLANK event will be
185 	 * send out on each update of the display pipeline by
186 	 * drm_atomic_helper_fake_vblank().
187 	 *
188 	 * Another usage is CRTCs feeding a writeback connector operating in
189 	 * oneshot mode. In this case the fake VBLANK event is only generated
190 	 * when a job is queued to the writeback connector, and we want the
191 	 * core to fake VBLANK events when this part of the pipeline hasn't
192 	 * changed but others had or when the CRTC and connectors are being
193 	 * disabled.
194 	 *
195 	 * __drm_atomic_helper_crtc_duplicate_state() will not reset the value
196 	 * from the current state, the CRTC driver is then responsible for
197 	 * updating this field when needed.
198 	 *
199 	 * Note that the combination of &drm_crtc_state.event == NULL and
200 	 * &drm_crtc_state.no_blank == true is valid and usually used when the
201 	 * writeback connector attached to the CRTC has a new job queued. In
202 	 * this case the driver will send the VBLANK event on its own when the
203 	 * writeback job is complete.
204 	 */
205 	bool no_vblank : 1;
206 
207 	/**
208 	 * @plane_mask: Bitmask of drm_plane_mask(plane) of planes attached to
209 	 * this CRTC.
210 	 */
211 	u32 plane_mask;
212 
213 	/**
214 	 * @connector_mask: Bitmask of drm_connector_mask(connector) of
215 	 * connectors attached to this CRTC.
216 	 */
217 	u32 connector_mask;
218 
219 	/**
220 	 * @encoder_mask: Bitmask of drm_encoder_mask(encoder) of encoders
221 	 * attached to this CRTC.
222 	 */
223 	u32 encoder_mask;
224 
225 	/**
226 	 * @adjusted_mode:
227 	 *
228 	 * Internal display timings which can be used by the driver to handle
229 	 * differences between the mode requested by userspace in @mode and what
230 	 * is actually programmed into the hardware.
231 	 *
232 	 * For drivers using &drm_bridge, this stores hardware display timings
233 	 * used between the CRTC and the first bridge. For other drivers, the
234 	 * meaning of the adjusted_mode field is purely driver implementation
235 	 * defined information, and will usually be used to store the hardware
236 	 * display timings used between the CRTC and encoder blocks.
237 	 */
238 	struct drm_display_mode adjusted_mode;
239 
240 	/**
241 	 * @mode:
242 	 *
243 	 * Display timings requested by userspace. The driver should try to
244 	 * match the refresh rate as close as possible (but note that it's
245 	 * undefined what exactly is close enough, e.g. some of the HDMI modes
246 	 * only differ in less than 1% of the refresh rate). The active width
247 	 * and height as observed by userspace for positioning planes must match
248 	 * exactly.
249 	 *
250 	 * For external connectors where the sink isn't fixed (like with a
251 	 * built-in panel), this mode here should match the physical mode on the
252 	 * wire to the last details (i.e. including sync polarities and
253 	 * everything).
254 	 */
255 	struct drm_display_mode mode;
256 
257 	/**
258 	 * @mode_blob: &drm_property_blob for @mode, for exposing the mode to
259 	 * atomic userspace.
260 	 */
261 	struct drm_property_blob *mode_blob;
262 
263 	/**
264 	 * @degamma_lut:
265 	 *
266 	 * Lookup table for converting framebuffer pixel data before apply the
267 	 * color conversion matrix @ctm. See drm_crtc_enable_color_mgmt(). The
268 	 * blob (if not NULL) is an array of &struct drm_color_lut.
269 	 */
270 	struct drm_property_blob *degamma_lut;
271 
272 	/**
273 	 * @ctm:
274 	 *
275 	 * Color transformation matrix. See drm_crtc_enable_color_mgmt(). The
276 	 * blob (if not NULL) is a &struct drm_color_ctm.
277 	 */
278 	struct drm_property_blob *ctm;
279 
280 	/**
281 	 * @gamma_lut:
282 	 *
283 	 * Lookup table for converting pixel data after the color conversion
284 	 * matrix @ctm.  See drm_crtc_enable_color_mgmt(). The blob (if not
285 	 * NULL) is an array of &struct drm_color_lut.
286 	 *
287 	 * Note that for mostly historical reasons stemming from Xorg heritage,
288 	 * this is also used to store the color map (also sometimes color lut,
289 	 * CLUT or color palette) for indexed formats like DRM_FORMAT_C8.
290 	 */
291 	struct drm_property_blob *gamma_lut;
292 
293 	/**
294 	 * @target_vblank:
295 	 *
296 	 * Target vertical blank period when a page flip
297 	 * should take effect.
298 	 */
299 	u32 target_vblank;
300 
301 	/**
302 	 * @async_flip:
303 	 *
304 	 * This is set when DRM_MODE_PAGE_FLIP_ASYNC is set in the legacy
305 	 * PAGE_FLIP IOCTL. It's not wired up for the atomic IOCTL itself yet.
306 	 */
307 	bool async_flip;
308 
309 	/**
310 	 * @vrr_enabled:
311 	 *
312 	 * Indicates if variable refresh rate should be enabled for the CRTC.
313 	 * Support for the requested vrr state will depend on driver and
314 	 * hardware capabiltiy - lacking support is not treated as failure.
315 	 */
316 	bool vrr_enabled;
317 
318 	/**
319 	 * @self_refresh_active:
320 	 *
321 	 * Used by the self refresh helpers to denote when a self refresh
322 	 * transition is occurring. This will be set on enable/disable callbacks
323 	 * when self refresh is being enabled or disabled. In some cases, it may
324 	 * not be desirable to fully shut off the crtc during self refresh.
325 	 * CRTC's can inspect this flag and determine the best course of action.
326 	 */
327 	bool self_refresh_active;
328 
329 	/**
330 	 * @scaling_filter:
331 	 *
332 	 * Scaling filter to be applied
333 	 */
334 	enum drm_scaling_filter scaling_filter;
335 
336 	/**
337 	 * @event:
338 	 *
339 	 * Optional pointer to a DRM event to signal upon completion of the
340 	 * state update. The driver must send out the event when the atomic
341 	 * commit operation completes. There are two cases:
342 	 *
343 	 *  - The event is for a CRTC which is being disabled through this
344 	 *    atomic commit. In that case the event can be send out any time
345 	 *    after the hardware has stopped scanning out the current
346 	 *    framebuffers. It should contain the timestamp and counter for the
347 	 *    last vblank before the display pipeline was shut off. The simplest
348 	 *    way to achieve that is calling drm_crtc_send_vblank_event()
349 	 *    somewhen after drm_crtc_vblank_off() has been called.
350 	 *
351 	 *  - For a CRTC which is enabled at the end of the commit (even when it
352 	 *    undergoes an full modeset) the vblank timestamp and counter must
353 	 *    be for the vblank right before the first frame that scans out the
354 	 *    new set of buffers. Again the event can only be sent out after the
355 	 *    hardware has stopped scanning out the old buffers.
356 	 *
357 	 *  - Events for disabled CRTCs are not allowed, and drivers can ignore
358 	 *    that case.
359 	 *
360 	 * For very simple hardware without VBLANK interrupt, enabling
361 	 * &struct drm_crtc_state.no_vblank makes DRM's atomic commit helpers
362 	 * send a fake VBLANK event at the end of the display update after all
363 	 * hardware changes have been applied. See
364 	 * drm_atomic_helper_fake_vblank().
365 	 *
366 	 * For more complex hardware this
367 	 * can be handled by the drm_crtc_send_vblank_event() function,
368 	 * which the driver should call on the provided event upon completion of
369 	 * the atomic commit. Note that if the driver supports vblank signalling
370 	 * and timestamping the vblank counters and timestamps must agree with
371 	 * the ones returned from page flip events. With the current vblank
372 	 * helper infrastructure this can be achieved by holding a vblank
373 	 * reference while the page flip is pending, acquired through
374 	 * drm_crtc_vblank_get() and released with drm_crtc_vblank_put().
375 	 * Drivers are free to implement their own vblank counter and timestamp
376 	 * tracking though, e.g. if they have accurate timestamp registers in
377 	 * hardware.
378 	 *
379 	 * For hardware which supports some means to synchronize vblank
380 	 * interrupt delivery with committing display state there's also
381 	 * drm_crtc_arm_vblank_event(). See the documentation of that function
382 	 * for a detailed discussion of the constraints it needs to be used
383 	 * safely.
384 	 *
385 	 * If the device can't notify of flip completion in a race-free way
386 	 * at all, then the event should be armed just after the page flip is
387 	 * committed. In the worst case the driver will send the event to
388 	 * userspace one frame too late. This doesn't allow for a real atomic
389 	 * update, but it should avoid tearing.
390 	 */
391 	struct drm_pending_vblank_event *event;
392 
393 	/**
394 	 * @commit:
395 	 *
396 	 * This tracks how the commit for this update proceeds through the
397 	 * various phases. This is never cleared, except when we destroy the
398 	 * state, so that subsequent commits can synchronize with previous ones.
399 	 */
400 	struct drm_crtc_commit *commit;
401 
402 	/** @state: backpointer to global drm_atomic_state */
403 	struct drm_atomic_state *state;
404 };
405 
406 /**
407  * struct drm_crtc_funcs - control CRTCs for a given device
408  *
409  * The drm_crtc_funcs structure is the central CRTC management structure
410  * in the DRM.  Each CRTC controls one or more connectors (note that the name
411  * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
412  * connectors, not just CRTs).
413  *
414  * Each driver is responsible for filling out this structure at startup time,
415  * in addition to providing other modesetting features, like i2c and DDC
416  * bus accessors.
417  */
418 struct drm_crtc_funcs {
419 	/**
420 	 * @reset:
421 	 *
422 	 * Reset CRTC hardware and software state to off. This function isn't
423 	 * called by the core directly, only through drm_mode_config_reset().
424 	 * It's not a helper hook only for historical reasons.
425 	 *
426 	 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
427 	 * atomic state using this hook.
428 	 */
429 	void (*reset)(struct drm_crtc *crtc);
430 
431 	/**
432 	 * @cursor_set:
433 	 *
434 	 * Update the cursor image. The cursor position is relative to the CRTC
435 	 * and can be partially or fully outside of the visible area.
436 	 *
437 	 * Note that contrary to all other KMS functions the legacy cursor entry
438 	 * points don't take a framebuffer object, but instead take directly a
439 	 * raw buffer object id from the driver's buffer manager (which is
440 	 * either GEM or TTM for current drivers).
441 	 *
442 	 * This entry point is deprecated, drivers should instead implement
443 	 * universal plane support and register a proper cursor plane using
444 	 * drm_crtc_init_with_planes().
445 	 *
446 	 * This callback is optional
447 	 *
448 	 * RETURNS:
449 	 *
450 	 * 0 on success or a negative error code on failure.
451 	 */
452 	int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
453 			  uint32_t handle, uint32_t width, uint32_t height);
454 
455 	/**
456 	 * @cursor_set2:
457 	 *
458 	 * Update the cursor image, including hotspot information. The hotspot
459 	 * must not affect the cursor position in CRTC coordinates, but is only
460 	 * meant as a hint for virtualized display hardware to coordinate the
461 	 * guests and hosts cursor position. The cursor hotspot is relative to
462 	 * the cursor image. Otherwise this works exactly like @cursor_set.
463 	 *
464 	 * This entry point is deprecated, drivers should instead implement
465 	 * universal plane support and register a proper cursor plane using
466 	 * drm_crtc_init_with_planes().
467 	 *
468 	 * This callback is optional.
469 	 *
470 	 * RETURNS:
471 	 *
472 	 * 0 on success or a negative error code on failure.
473 	 */
474 	int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
475 			   uint32_t handle, uint32_t width, uint32_t height,
476 			   int32_t hot_x, int32_t hot_y);
477 
478 	/**
479 	 * @cursor_move:
480 	 *
481 	 * Update the cursor position. The cursor does not need to be visible
482 	 * when this hook is called.
483 	 *
484 	 * This entry point is deprecated, drivers should instead implement
485 	 * universal plane support and register a proper cursor plane using
486 	 * drm_crtc_init_with_planes().
487 	 *
488 	 * This callback is optional.
489 	 *
490 	 * RETURNS:
491 	 *
492 	 * 0 on success or a negative error code on failure.
493 	 */
494 	int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
495 
496 	/**
497 	 * @gamma_set:
498 	 *
499 	 * Set gamma on the CRTC.
500 	 *
501 	 * This callback is optional.
502 	 *
503 	 * Atomic drivers who want to support gamma tables should implement the
504 	 * atomic color management support, enabled by calling
505 	 * drm_crtc_enable_color_mgmt(), which then supports the legacy gamma
506 	 * interface through the drm_atomic_helper_legacy_gamma_set()
507 	 * compatibility implementation.
508 	 */
509 	int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
510 			 uint32_t size,
511 			 struct drm_modeset_acquire_ctx *ctx);
512 
513 	/**
514 	 * @destroy:
515 	 *
516 	 * Clean up CRTC resources. This is only called at driver unload time
517 	 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
518 	 * in DRM.
519 	 */
520 	void (*destroy)(struct drm_crtc *crtc);
521 
522 	/**
523 	 * @set_config:
524 	 *
525 	 * This is the main legacy entry point to change the modeset state on a
526 	 * CRTC. All the details of the desired configuration are passed in a
527 	 * &struct drm_mode_set - see there for details.
528 	 *
529 	 * Drivers implementing atomic modeset should use
530 	 * drm_atomic_helper_set_config() to implement this hook.
531 	 *
532 	 * RETURNS:
533 	 *
534 	 * 0 on success or a negative error code on failure.
535 	 */
536 	int (*set_config)(struct drm_mode_set *set,
537 			  struct drm_modeset_acquire_ctx *ctx);
538 
539 	/**
540 	 * @page_flip:
541 	 *
542 	 * Legacy entry point to schedule a flip to the given framebuffer.
543 	 *
544 	 * Page flipping is a synchronization mechanism that replaces the frame
545 	 * buffer being scanned out by the CRTC with a new frame buffer during
546 	 * vertical blanking, avoiding tearing (except when requested otherwise
547 	 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
548 	 * requests a page flip the DRM core verifies that the new frame buffer
549 	 * is large enough to be scanned out by the CRTC in the currently
550 	 * configured mode and then calls this hook with a pointer to the new
551 	 * frame buffer.
552 	 *
553 	 * The driver must wait for any pending rendering to the new framebuffer
554 	 * to complete before executing the flip. It should also wait for any
555 	 * pending rendering from other drivers if the underlying buffer is a
556 	 * shared dma-buf.
557 	 *
558 	 * An application can request to be notified when the page flip has
559 	 * completed. The drm core will supply a &struct drm_event in the event
560 	 * parameter in this case. This can be handled by the
561 	 * drm_crtc_send_vblank_event() function, which the driver should call on
562 	 * the provided event upon completion of the flip. Note that if
563 	 * the driver supports vblank signalling and timestamping the vblank
564 	 * counters and timestamps must agree with the ones returned from page
565 	 * flip events. With the current vblank helper infrastructure this can
566 	 * be achieved by holding a vblank reference while the page flip is
567 	 * pending, acquired through drm_crtc_vblank_get() and released with
568 	 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
569 	 * counter and timestamp tracking though, e.g. if they have accurate
570 	 * timestamp registers in hardware.
571 	 *
572 	 * This callback is optional.
573 	 *
574 	 * NOTE:
575 	 *
576 	 * Very early versions of the KMS ABI mandated that the driver must
577 	 * block (but not reject) any rendering to the old framebuffer until the
578 	 * flip operation has completed and the old framebuffer is no longer
579 	 * visible. This requirement has been lifted, and userspace is instead
580 	 * expected to request delivery of an event and wait with recycling old
581 	 * buffers until such has been received.
582 	 *
583 	 * RETURNS:
584 	 *
585 	 * 0 on success or a negative error code on failure. Note that if a
586 	 * page flip operation is already pending the callback should return
587 	 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
588 	 * or just runtime disabled through DPMS respectively the new atomic
589 	 * "ACTIVE" state) should result in an -EINVAL error code. Note that
590 	 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
591 	 */
592 	int (*page_flip)(struct drm_crtc *crtc,
593 			 struct drm_framebuffer *fb,
594 			 struct drm_pending_vblank_event *event,
595 			 uint32_t flags,
596 			 struct drm_modeset_acquire_ctx *ctx);
597 
598 	/**
599 	 * @page_flip_target:
600 	 *
601 	 * Same as @page_flip but with an additional parameter specifying the
602 	 * absolute target vertical blank period (as reported by
603 	 * drm_crtc_vblank_count()) when the flip should take effect.
604 	 *
605 	 * Note that the core code calls drm_crtc_vblank_get before this entry
606 	 * point, and will call drm_crtc_vblank_put if this entry point returns
607 	 * any non-0 error code. It's the driver's responsibility to call
608 	 * drm_crtc_vblank_put after this entry point returns 0, typically when
609 	 * the flip completes.
610 	 */
611 	int (*page_flip_target)(struct drm_crtc *crtc,
612 				struct drm_framebuffer *fb,
613 				struct drm_pending_vblank_event *event,
614 				uint32_t flags, uint32_t target,
615 				struct drm_modeset_acquire_ctx *ctx);
616 
617 	/**
618 	 * @set_property:
619 	 *
620 	 * This is the legacy entry point to update a property attached to the
621 	 * CRTC.
622 	 *
623 	 * This callback is optional if the driver does not support any legacy
624 	 * driver-private properties. For atomic drivers it is not used because
625 	 * property handling is done entirely in the DRM core.
626 	 *
627 	 * RETURNS:
628 	 *
629 	 * 0 on success or a negative error code on failure.
630 	 */
631 	int (*set_property)(struct drm_crtc *crtc,
632 			    struct drm_property *property, uint64_t val);
633 
634 	/**
635 	 * @atomic_duplicate_state:
636 	 *
637 	 * Duplicate the current atomic state for this CRTC and return it.
638 	 * The core and helpers guarantee that any atomic state duplicated with
639 	 * this hook and still owned by the caller (i.e. not transferred to the
640 	 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
641 	 * cleaned up by calling the @atomic_destroy_state hook in this
642 	 * structure.
643 	 *
644 	 * This callback is mandatory for atomic drivers.
645 	 *
646 	 * Atomic drivers which don't subclass &struct drm_crtc_state should use
647 	 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
648 	 * state structure to extend it with driver-private state should use
649 	 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
650 	 * duplicated in a consistent fashion across drivers.
651 	 *
652 	 * It is an error to call this hook before &drm_crtc.state has been
653 	 * initialized correctly.
654 	 *
655 	 * NOTE:
656 	 *
657 	 * If the duplicate state references refcounted resources this hook must
658 	 * acquire a reference for each of them. The driver must release these
659 	 * references again in @atomic_destroy_state.
660 	 *
661 	 * RETURNS:
662 	 *
663 	 * Duplicated atomic state or NULL when the allocation failed.
664 	 */
665 	struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
666 
667 	/**
668 	 * @atomic_destroy_state:
669 	 *
670 	 * Destroy a state duplicated with @atomic_duplicate_state and release
671 	 * or unreference all resources it references
672 	 *
673 	 * This callback is mandatory for atomic drivers.
674 	 */
675 	void (*atomic_destroy_state)(struct drm_crtc *crtc,
676 				     struct drm_crtc_state *state);
677 
678 	/**
679 	 * @atomic_set_property:
680 	 *
681 	 * Decode a driver-private property value and store the decoded value
682 	 * into the passed-in state structure. Since the atomic core decodes all
683 	 * standardized properties (even for extensions beyond the core set of
684 	 * properties which might not be implemented by all drivers) this
685 	 * requires drivers to subclass the state structure.
686 	 *
687 	 * Such driver-private properties should really only be implemented for
688 	 * truly hardware/vendor specific state. Instead it is preferred to
689 	 * standardize atomic extension and decode the properties used to expose
690 	 * such an extension in the core.
691 	 *
692 	 * Do not call this function directly, use
693 	 * drm_atomic_crtc_set_property() instead.
694 	 *
695 	 * This callback is optional if the driver does not support any
696 	 * driver-private atomic properties.
697 	 *
698 	 * NOTE:
699 	 *
700 	 * This function is called in the state assembly phase of atomic
701 	 * modesets, which can be aborted for any reason (including on
702 	 * userspace's request to just check whether a configuration would be
703 	 * possible). Drivers MUST NOT touch any persistent state (hardware or
704 	 * software) or data structures except the passed in @state parameter.
705 	 *
706 	 * Also since userspace controls in which order properties are set this
707 	 * function must not do any input validation (since the state update is
708 	 * incomplete and hence likely inconsistent). Instead any such input
709 	 * validation must be done in the various atomic_check callbacks.
710 	 *
711 	 * RETURNS:
712 	 *
713 	 * 0 if the property has been found, -EINVAL if the property isn't
714 	 * implemented by the driver (which should never happen, the core only
715 	 * asks for properties attached to this CRTC). No other validation is
716 	 * allowed by the driver. The core already checks that the property
717 	 * value is within the range (integer, valid enum value, ...) the driver
718 	 * set when registering the property.
719 	 */
720 	int (*atomic_set_property)(struct drm_crtc *crtc,
721 				   struct drm_crtc_state *state,
722 				   struct drm_property *property,
723 				   uint64_t val);
724 	/**
725 	 * @atomic_get_property:
726 	 *
727 	 * Reads out the decoded driver-private property. This is used to
728 	 * implement the GETCRTC IOCTL.
729 	 *
730 	 * Do not call this function directly, use
731 	 * drm_atomic_crtc_get_property() instead.
732 	 *
733 	 * This callback is optional if the driver does not support any
734 	 * driver-private atomic properties.
735 	 *
736 	 * RETURNS:
737 	 *
738 	 * 0 on success, -EINVAL if the property isn't implemented by the
739 	 * driver (which should never happen, the core only asks for
740 	 * properties attached to this CRTC).
741 	 */
742 	int (*atomic_get_property)(struct drm_crtc *crtc,
743 				   const struct drm_crtc_state *state,
744 				   struct drm_property *property,
745 				   uint64_t *val);
746 
747 	/**
748 	 * @late_register:
749 	 *
750 	 * This optional hook can be used to register additional userspace
751 	 * interfaces attached to the crtc like debugfs interfaces.
752 	 * It is called late in the driver load sequence from drm_dev_register().
753 	 * Everything added from this callback should be unregistered in
754 	 * the early_unregister callback.
755 	 *
756 	 * Returns:
757 	 *
758 	 * 0 on success, or a negative error code on failure.
759 	 */
760 	int (*late_register)(struct drm_crtc *crtc);
761 
762 	/**
763 	 * @early_unregister:
764 	 *
765 	 * This optional hook should be used to unregister the additional
766 	 * userspace interfaces attached to the crtc from
767 	 * @late_register. It is called from drm_dev_unregister(),
768 	 * early in the driver unload sequence to disable userspace access
769 	 * before data structures are torndown.
770 	 */
771 	void (*early_unregister)(struct drm_crtc *crtc);
772 
773 	/**
774 	 * @set_crc_source:
775 	 *
776 	 * Changes the source of CRC checksums of frames at the request of
777 	 * userspace, typically for testing purposes. The sources available are
778 	 * specific of each driver and a %NULL value indicates that CRC
779 	 * generation is to be switched off.
780 	 *
781 	 * When CRC generation is enabled, the driver should call
782 	 * drm_crtc_add_crc_entry() at each frame, providing any information
783 	 * that characterizes the frame contents in the crcN arguments, as
784 	 * provided from the configured source. Drivers must accept an "auto"
785 	 * source name that will select a default source for this CRTC.
786 	 *
787 	 * This may trigger an atomic modeset commit if necessary, to enable CRC
788 	 * generation.
789 	 *
790 	 * Note that "auto" can depend upon the current modeset configuration,
791 	 * e.g. it could pick an encoder or output specific CRC sampling point.
792 	 *
793 	 * This callback is optional if the driver does not support any CRC
794 	 * generation functionality.
795 	 *
796 	 * RETURNS:
797 	 *
798 	 * 0 on success or a negative error code on failure.
799 	 */
800 	int (*set_crc_source)(struct drm_crtc *crtc, const char *source);
801 
802 	/**
803 	 * @verify_crc_source:
804 	 *
805 	 * verifies the source of CRC checksums of frames before setting the
806 	 * source for CRC and during crc open. Source parameter can be NULL
807 	 * while disabling crc source.
808 	 *
809 	 * This callback is optional if the driver does not support any CRC
810 	 * generation functionality.
811 	 *
812 	 * RETURNS:
813 	 *
814 	 * 0 on success or a negative error code on failure.
815 	 */
816 	int (*verify_crc_source)(struct drm_crtc *crtc, const char *source,
817 				 size_t *values_cnt);
818 	/**
819 	 * @get_crc_sources:
820 	 *
821 	 * Driver callback for getting a list of all the available sources for
822 	 * CRC generation. This callback depends upon verify_crc_source, So
823 	 * verify_crc_source callback should be implemented before implementing
824 	 * this. Driver can pass full list of available crc sources, this
825 	 * callback does the verification on each crc-source before passing it
826 	 * to userspace.
827 	 *
828 	 * This callback is optional if the driver does not support exporting of
829 	 * possible CRC sources list.
830 	 *
831 	 * RETURNS:
832 	 *
833 	 * a constant character pointer to the list of all the available CRC
834 	 * sources. On failure driver should return NULL. count should be
835 	 * updated with number of sources in list. if zero we don't process any
836 	 * source from the list.
837 	 */
838 	const char *const *(*get_crc_sources)(struct drm_crtc *crtc,
839 					      size_t *count);
840 
841 	/**
842 	 * @atomic_print_state:
843 	 *
844 	 * If driver subclasses &struct drm_crtc_state, it should implement
845 	 * this optional hook for printing additional driver specific state.
846 	 *
847 	 * Do not call this directly, use drm_atomic_crtc_print_state()
848 	 * instead.
849 	 */
850 	void (*atomic_print_state)(struct drm_printer *p,
851 				   const struct drm_crtc_state *state);
852 
853 	/**
854 	 * @get_vblank_counter:
855 	 *
856 	 * Driver callback for fetching a raw hardware vblank counter for the
857 	 * CRTC. It's meant to be used by new drivers as the replacement of
858 	 * &drm_driver.get_vblank_counter hook.
859 	 *
860 	 * This callback is optional. If a device doesn't have a hardware
861 	 * counter, the driver can simply leave the hook as NULL. The DRM core
862 	 * will account for missed vblank events while interrupts where disabled
863 	 * based on system timestamps.
864 	 *
865 	 * Wraparound handling and loss of events due to modesetting is dealt
866 	 * with in the DRM core code, as long as drivers call
867 	 * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or
868 	 * enabling a CRTC.
869 	 *
870 	 * See also &drm_device.vblank_disable_immediate and
871 	 * &drm_device.max_vblank_count.
872 	 *
873 	 * Returns:
874 	 *
875 	 * Raw vblank counter value.
876 	 */
877 	u32 (*get_vblank_counter)(struct drm_crtc *crtc);
878 
879 	/**
880 	 * @enable_vblank:
881 	 *
882 	 * Enable vblank interrupts for the CRTC. It's meant to be used by
883 	 * new drivers as the replacement of &drm_driver.enable_vblank hook.
884 	 *
885 	 * Returns:
886 	 *
887 	 * Zero on success, appropriate errno if the vblank interrupt cannot
888 	 * be enabled.
889 	 */
890 	int (*enable_vblank)(struct drm_crtc *crtc);
891 
892 	/**
893 	 * @disable_vblank:
894 	 *
895 	 * Disable vblank interrupts for the CRTC. It's meant to be used by
896 	 * new drivers as the replacement of &drm_driver.disable_vblank hook.
897 	 */
898 	void (*disable_vblank)(struct drm_crtc *crtc);
899 
900 	/**
901 	 * @get_vblank_timestamp:
902 	 *
903 	 * Called by drm_get_last_vbltimestamp(). Should return a precise
904 	 * timestamp when the most recent vblank interval ended or will end.
905 	 *
906 	 * Specifically, the timestamp in @vblank_time should correspond as
907 	 * closely as possible to the time when the first video scanline of
908 	 * the video frame after the end of vblank will start scanning out,
909 	 * the time immediately after end of the vblank interval. If the
910 	 * @crtc is currently inside vblank, this will be a time in the future.
911 	 * If the @crtc is currently scanning out a frame, this will be the
912 	 * past start time of the current scanout. This is meant to adhere
913 	 * to the OpenML OML_sync_control extension specification.
914 	 *
915 	 * Parameters:
916 	 *
917 	 * crtc:
918 	 *     CRTC for which timestamp should be returned.
919 	 * max_error:
920 	 *     Maximum allowable timestamp error in nanoseconds.
921 	 *     Implementation should strive to provide timestamp
922 	 *     with an error of at most max_error nanoseconds.
923 	 *     Returns true upper bound on error for timestamp.
924 	 * vblank_time:
925 	 *     Target location for returned vblank timestamp.
926 	 * in_vblank_irq:
927 	 *     True when called from drm_crtc_handle_vblank().  Some drivers
928 	 *     need to apply some workarounds for gpu-specific vblank irq quirks
929 	 *     if flag is set.
930 	 *
931 	 * Returns:
932 	 *
933 	 * True on success, false on failure, which means the core should
934 	 * fallback to a simple timestamp taken in drm_crtc_handle_vblank().
935 	 */
936 	bool (*get_vblank_timestamp)(struct drm_crtc *crtc,
937 				     int *max_error,
938 				     ktime_t *vblank_time,
939 				     bool in_vblank_irq);
940 };
941 
942 /**
943  * struct drm_crtc - central CRTC control structure
944  *
945  * Each CRTC may have one or more connectors associated with it.  This structure
946  * allows the CRTC to be controlled.
947  */
948 struct drm_crtc {
949 	/** @dev: parent DRM device */
950 	struct drm_device *dev;
951 	/** @port: OF node used by drm_of_find_possible_crtcs(). */
952 	struct device_node *port;
953 	/**
954 	 * @head:
955 	 *
956 	 * List of all CRTCs on @dev, linked from &drm_mode_config.crtc_list.
957 	 * Invariant over the lifetime of @dev and therefore does not need
958 	 * locking.
959 	 */
960 	struct list_head head;
961 
962 	/** @name: human readable name, can be overwritten by the driver */
963 	char *name;
964 
965 	/**
966 	 * @mutex:
967 	 *
968 	 * This provides a read lock for the overall CRTC state (mode, dpms
969 	 * state, ...) and a write lock for everything which can be update
970 	 * without a full modeset (fb, cursor data, CRTC properties ...). A full
971 	 * modeset also need to grab &drm_mode_config.connection_mutex.
972 	 *
973 	 * For atomic drivers specifically this protects @state.
974 	 */
975 	struct drm_modeset_lock mutex;
976 
977 	/** @base: base KMS object for ID tracking etc. */
978 	struct drm_mode_object base;
979 
980 	/**
981 	 * @primary:
982 	 * Primary plane for this CRTC. Note that this is only
983 	 * relevant for legacy IOCTL, it specifies the plane implicitly used by
984 	 * the SETCRTC and PAGE_FLIP IOCTLs. It does not have any significance
985 	 * beyond that.
986 	 */
987 	struct drm_plane *primary;
988 
989 	/**
990 	 * @cursor:
991 	 * Cursor plane for this CRTC. Note that this is only relevant for
992 	 * legacy IOCTL, it specifies the plane implicitly used by the SETCURSOR
993 	 * and SETCURSOR2 IOCTLs. It does not have any significance
994 	 * beyond that.
995 	 */
996 	struct drm_plane *cursor;
997 
998 	/**
999 	 * @index: Position inside the mode_config.list, can be used as an array
1000 	 * index. It is invariant over the lifetime of the CRTC.
1001 	 */
1002 	unsigned index;
1003 
1004 	/**
1005 	 * @cursor_x: Current x position of the cursor, used for universal
1006 	 * cursor planes because the SETCURSOR IOCTL only can update the
1007 	 * framebuffer without supplying the coordinates. Drivers should not use
1008 	 * this directly, atomic drivers should look at &drm_plane_state.crtc_x
1009 	 * of the cursor plane instead.
1010 	 */
1011 	int cursor_x;
1012 	/**
1013 	 * @cursor_y: Current y position of the cursor, used for universal
1014 	 * cursor planes because the SETCURSOR IOCTL only can update the
1015 	 * framebuffer without supplying the coordinates. Drivers should not use
1016 	 * this directly, atomic drivers should look at &drm_plane_state.crtc_y
1017 	 * of the cursor plane instead.
1018 	 */
1019 	int cursor_y;
1020 
1021 	/**
1022 	 * @enabled:
1023 	 *
1024 	 * Is this CRTC enabled? Should only be used by legacy drivers, atomic
1025 	 * drivers should instead consult &drm_crtc_state.enable and
1026 	 * &drm_crtc_state.active. Atomic drivers can update this by calling
1027 	 * drm_atomic_helper_update_legacy_modeset_state().
1028 	 */
1029 	bool enabled;
1030 
1031 	/**
1032 	 * @mode:
1033 	 *
1034 	 * Current mode timings. Should only be used by legacy drivers, atomic
1035 	 * drivers should instead consult &drm_crtc_state.mode. Atomic drivers
1036 	 * can update this by calling
1037 	 * drm_atomic_helper_update_legacy_modeset_state().
1038 	 */
1039 	struct drm_display_mode mode;
1040 
1041 	/**
1042 	 * @hwmode:
1043 	 *
1044 	 * Programmed mode in hw, after adjustments for encoders, crtc, panel
1045 	 * scaling etc. Should only be used by legacy drivers, for high
1046 	 * precision vblank timestamps in
1047 	 * drm_crtc_vblank_helper_get_vblank_timestamp().
1048 	 *
1049 	 * Note that atomic drivers should not use this, but instead use
1050 	 * &drm_crtc_state.adjusted_mode. And for high-precision timestamps
1051 	 * drm_crtc_vblank_helper_get_vblank_timestamp() used
1052 	 * &drm_vblank_crtc.hwmode,
1053 	 * which is filled out by calling drm_calc_timestamping_constants().
1054 	 */
1055 	struct drm_display_mode hwmode;
1056 
1057 	/**
1058 	 * @x:
1059 	 * x position on screen. Should only be used by legacy drivers, atomic
1060 	 * drivers should look at &drm_plane_state.crtc_x of the primary plane
1061 	 * instead. Updated by calling
1062 	 * drm_atomic_helper_update_legacy_modeset_state().
1063 	 */
1064 	int x;
1065 	/**
1066 	 * @y:
1067 	 * y position on screen. Should only be used by legacy drivers, atomic
1068 	 * drivers should look at &drm_plane_state.crtc_y of the primary plane
1069 	 * instead. Updated by calling
1070 	 * drm_atomic_helper_update_legacy_modeset_state().
1071 	 */
1072 	int y;
1073 
1074 	/** @funcs: CRTC control functions */
1075 	const struct drm_crtc_funcs *funcs;
1076 
1077 	/**
1078 	 * @gamma_size: Size of legacy gamma ramp reported to userspace. Set up
1079 	 * by calling drm_mode_crtc_set_gamma_size().
1080 	 *
1081 	 * Note that atomic drivers need to instead use
1082 	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
1083 	 */
1084 	uint32_t gamma_size;
1085 
1086 	/**
1087 	 * @gamma_store: Gamma ramp values used by the legacy SETGAMMA and
1088 	 * GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().
1089 	 *
1090 	 * Note that atomic drivers need to instead use
1091 	 * &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().
1092 	 */
1093 	uint16_t *gamma_store;
1094 
1095 	/** @helper_private: mid-layer private data */
1096 	const struct drm_crtc_helper_funcs *helper_private;
1097 
1098 	/** @properties: property tracking for this CRTC */
1099 	struct drm_object_properties properties;
1100 
1101 	/**
1102 	 * @scaling_filter_property: property to apply a particular filter while
1103 	 * scaling.
1104 	 */
1105 	struct drm_property *scaling_filter_property;
1106 
1107 	/**
1108 	 * @state:
1109 	 *
1110 	 * Current atomic state for this CRTC.
1111 	 *
1112 	 * This is protected by @mutex. Note that nonblocking atomic commits
1113 	 * access the current CRTC state without taking locks. Either by going
1114 	 * through the &struct drm_atomic_state pointers, see
1115 	 * for_each_oldnew_crtc_in_state(), for_each_old_crtc_in_state() and
1116 	 * for_each_new_crtc_in_state(). Or through careful ordering of atomic
1117 	 * commit operations as implemented in the atomic helpers, see
1118 	 * &struct drm_crtc_commit.
1119 	 */
1120 	struct drm_crtc_state *state;
1121 
1122 	/**
1123 	 * @commit_list:
1124 	 *
1125 	 * List of &drm_crtc_commit structures tracking pending commits.
1126 	 * Protected by @commit_lock. This list holds its own full reference,
1127 	 * as does the ongoing commit.
1128 	 *
1129 	 * "Note that the commit for a state change is also tracked in
1130 	 * &drm_crtc_state.commit. For accessing the immediately preceding
1131 	 * commit in an atomic update it is recommended to just use that
1132 	 * pointer in the old CRTC state, since accessing that doesn't need
1133 	 * any locking or list-walking. @commit_list should only be used to
1134 	 * stall for framebuffer cleanup that's signalled through
1135 	 * &drm_crtc_commit.cleanup_done."
1136 	 */
1137 	struct list_head commit_list;
1138 
1139 	/**
1140 	 * @commit_lock:
1141 	 *
1142 	 * Spinlock to protect @commit_list.
1143 	 */
1144 	spinlock_t commit_lock;
1145 
1146 	/**
1147 	 * @debugfs_entry:
1148 	 *
1149 	 * Debugfs directory for this CRTC.
1150 	 */
1151 	struct dentry *debugfs_entry;
1152 
1153 	/**
1154 	 * @crc:
1155 	 *
1156 	 * Configuration settings of CRC capture.
1157 	 */
1158 	struct drm_crtc_crc crc;
1159 
1160 	/**
1161 	 * @fence_context:
1162 	 *
1163 	 * timeline context used for fence operations.
1164 	 */
1165 	unsigned int fence_context;
1166 
1167 	/**
1168 	 * @fence_lock:
1169 	 *
1170 	 * spinlock to protect the fences in the fence_context.
1171 	 */
1172 	spinlock_t fence_lock;
1173 	/**
1174 	 * @fence_seqno:
1175 	 *
1176 	 * Seqno variable used as monotonic counter for the fences
1177 	 * created on the CRTC's timeline.
1178 	 */
1179 	unsigned long fence_seqno;
1180 
1181 	/**
1182 	 * @timeline_name:
1183 	 *
1184 	 * The name of the CRTC's fence timeline.
1185 	 */
1186 	char timeline_name[32];
1187 
1188 	/**
1189 	 * @self_refresh_data: Holds the state for the self refresh helpers
1190 	 *
1191 	 * Initialized via drm_self_refresh_helper_init().
1192 	 */
1193 	struct drm_self_refresh_data *self_refresh_data;
1194 };
1195 
1196 /**
1197  * struct drm_mode_set - new values for a CRTC config change
1198  * @fb: framebuffer to use for new config
1199  * @crtc: CRTC whose configuration we're about to change
1200  * @mode: mode timings to use
1201  * @x: position of this CRTC relative to @fb
1202  * @y: position of this CRTC relative to @fb
1203  * @connectors: array of connectors to drive with this CRTC if possible
1204  * @num_connectors: size of @connectors array
1205  *
1206  * This represents a modeset configuration for the legacy SETCRTC ioctl and is
1207  * also used internally. Atomic drivers instead use &drm_atomic_state.
1208  */
1209 struct drm_mode_set {
1210 	struct drm_framebuffer *fb;
1211 	struct drm_crtc *crtc;
1212 	struct drm_display_mode *mode;
1213 
1214 	uint32_t x;
1215 	uint32_t y;
1216 
1217 	struct drm_connector **connectors;
1218 	size_t num_connectors;
1219 };
1220 
1221 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1222 
1223 __printf(6, 7)
1224 int drm_crtc_init_with_planes(struct drm_device *dev,
1225 			      struct drm_crtc *crtc,
1226 			      struct drm_plane *primary,
1227 			      struct drm_plane *cursor,
1228 			      const struct drm_crtc_funcs *funcs,
1229 			      const char *name, ...);
1230 void drm_crtc_cleanup(struct drm_crtc *crtc);
1231 
1232 __printf(7, 8)
1233 void *__drmm_crtc_alloc_with_planes(struct drm_device *dev,
1234 				    size_t size, size_t offset,
1235 				    struct drm_plane *primary,
1236 				    struct drm_plane *cursor,
1237 				    const struct drm_crtc_funcs *funcs,
1238 				    const char *name, ...);
1239 
1240 /**
1241  * drmm_crtc_alloc_with_planes - Allocate and initialize a new CRTC object with
1242  *    specified primary and cursor planes.
1243  * @dev: DRM device
1244  * @type: the type of the struct which contains struct &drm_crtc
1245  * @member: the name of the &drm_crtc within @type.
1246  * @primary: Primary plane for CRTC
1247  * @cursor: Cursor plane for CRTC
1248  * @funcs: callbacks for the new CRTC
1249  * @name: printf style format string for the CRTC name, or NULL for default name
1250  *
1251  * Allocates and initializes a new crtc object. Cleanup is automatically
1252  * handled through registering drmm_crtc_cleanup() with drmm_add_action().
1253  *
1254  * The @drm_crtc_funcs.destroy hook must be NULL.
1255  *
1256  * Returns:
1257  * Pointer to new crtc, or ERR_PTR on failure.
1258  */
1259 #define drmm_crtc_alloc_with_planes(dev, type, member, primary, cursor, funcs, name, ...) \
1260 	((type *)__drmm_crtc_alloc_with_planes(dev, sizeof(type), \
1261 					       offsetof(type, member), \
1262 					       primary, cursor, funcs, \
1263 					       name, ##__VA_ARGS__))
1264 
1265 /**
1266  * drm_crtc_index - find the index of a registered CRTC
1267  * @crtc: CRTC to find index for
1268  *
1269  * Given a registered CRTC, return the index of that CRTC within a DRM
1270  * device's list of CRTCs.
1271  */
1272 static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)
1273 {
1274 	return crtc->index;
1275 }
1276 
1277 /**
1278  * drm_crtc_mask - find the mask of a registered CRTC
1279  * @crtc: CRTC to find mask for
1280  *
1281  * Given a registered CRTC, return the mask bit of that CRTC for the
1282  * &drm_encoder.possible_crtcs and &drm_plane.possible_crtcs fields.
1283  */
1284 static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc)
1285 {
1286 	return 1 << drm_crtc_index(crtc);
1287 }
1288 
1289 int drm_mode_set_config_internal(struct drm_mode_set *set);
1290 struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx);
1291 
1292 /**
1293  * drm_crtc_find - look up a CRTC object from its ID
1294  * @dev: DRM device
1295  * @file_priv: drm file to check for lease against.
1296  * @id: &drm_mode_object ID
1297  *
1298  * This can be used to look up a CRTC from its userspace ID. Only used by
1299  * drivers for legacy IOCTLs and interface, nowadays extensions to the KMS
1300  * userspace interface should be done using &drm_property.
1301  */
1302 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1303 		struct drm_file *file_priv,
1304 		uint32_t id)
1305 {
1306 	struct drm_mode_object *mo;
1307 	mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_CRTC);
1308 	return mo ? obj_to_crtc(mo) : NULL;
1309 }
1310 
1311 /**
1312  * drm_for_each_crtc - iterate over all CRTCs
1313  * @crtc: a &struct drm_crtc as the loop cursor
1314  * @dev: the &struct drm_device
1315  *
1316  * Iterate over all CRTCs of @dev.
1317  */
1318 #define drm_for_each_crtc(crtc, dev) \
1319 	list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1320 
1321 /**
1322  * drm_for_each_crtc_reverse - iterate over all CRTCs in reverse order
1323  * @crtc: a &struct drm_crtc as the loop cursor
1324  * @dev: the &struct drm_device
1325  *
1326  * Iterate over all CRTCs of @dev.
1327  */
1328 #define drm_for_each_crtc_reverse(crtc, dev) \
1329 	list_for_each_entry_reverse(crtc, &(dev)->mode_config.crtc_list, head)
1330 
1331 int drm_crtc_create_scaling_filter_property(struct drm_crtc *crtc,
1332 					    unsigned int supported_filters);
1333 
1334 #endif /* __DRM_CRTC_H__ */
1335