]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/drm/drm_crtc.h
drm: Switch drm_plane_state to inline kerneldoc style
[mirror_ubuntu-jammy-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>
f453ba04 31#include <linux/fb.h>
985e5dc2 32#include <linux/hdmi.h>
b5571e9d 33#include <linux/media-bus-format.h>
d7d2c48e
DH
34#include <uapi/drm/drm_mode.h>
35#include <uapi/drm/drm_fourcc.h>
51fd371b 36#include <drm/drm_modeset_lock.h>
d7da824d 37#include <drm/drm_rect.h>
949619f3 38#include <drm/drm_mode_object.h>
7520a277
DV
39#include <drm/drm_framebuffer.h>
40#include <drm/drm_modes.h>
52217195 41#include <drm/drm_connector.h>
59e71ee7 42#include <drm/drm_property.h>
199e4e96 43#include <drm/drm_bridge.h>
cdc3d09f 44#include <drm/drm_edid.h>
43968d7b 45#include <drm/drm_plane.h>
18733802 46#include <drm/drm_blend.h>
f1e2f66c 47#include <drm/drm_color_mgmt.h>
9edbf1fa 48#include <drm/drm_debugfs_crc.h>
28575f16 49#include <drm/drm_mode_config.h>
308e5bcb 50
f453ba04
DA
51struct drm_device;
52struct drm_mode_set;
595887eb
TR
53struct drm_file;
54struct drm_clip_rect;
fceffb32 55struct drm_printer;
7e435aad 56struct device_node;
f54d1867 57struct dma_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
f453ba04 69struct drm_crtc;
d91d8a3f 70struct drm_pending_vblank_event;
8cf5c917 71struct drm_plane;
3b336ec4 72struct drm_bridge;
144ecb97
DV
73struct drm_atomic_state;
74
4490d4c7 75struct drm_crtc_helper_funcs;
4490d4c7
DV
76struct drm_plane_helper_funcs;
77
144ecb97 78/**
cc4ceb48 79 * struct drm_crtc_state - mutable CRTC state
07cc0ef6 80 * @crtc: backpointer to the CRTC
144ecb97 81 * @enable: whether the CRTC should be enabled, gates all other state
d9b13620 82 * @active: whether the CRTC is actively displaying (used for DPMS)
fc596660 83 * @planes_changed: planes on this crtc are updated
d574528a
DV
84 * @mode_changed: @mode or @enable has been changed
85 * @active_changed: @active has been toggled.
fc596660 86 * @connectors_changed: connectors to this crtc have been updated
44d1240d 87 * @zpos_changed: zpos values of planes on this crtc have been updated
5488dc16
LL
88 * @color_mgmt_changed: color management properties have changed (degamma or
89 * gamma LUT or CSC matrix)
6ddd388a 90 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
4cd9fa52 91 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
e87a52b3 92 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
ac3ba4a5 93 * @mode_blob: &drm_property_blob for @mode
144ecb97 94 * @state: backpointer to global drm_atomic_state
d9b13620
DV
95 *
96 * Note that the distinction between @enable and @active is rather subtile:
97 * Flipping @active while @enable is set without changing anything else may
d574528a
DV
98 * never return in a failure from the &drm_mode_config_funcs.atomic_check
99 * callback. Userspace assumes that a DPMS On will always succeed. In other
100 * words: @enable controls resource assignment, @active controls the actual
101 * hardware state.
d807ed1c
BS
102 *
103 * The three booleans active_changed, connectors_changed and mode_changed are
104 * intended to indicate whether a full modeset is needed, rather than strictly
105 * describing what has changed in a commit.
106 * See also: drm_atomic_crtc_needs_modeset()
144ecb97
DV
107 */
108struct drm_crtc_state {
07cc0ef6
DV
109 struct drm_crtc *crtc;
110
cc4ceb48 111 bool enable;
d9b13620 112 bool active;
144ecb97 113
c2fcd274
DV
114 /* computed state bits used by helpers and drivers */
115 bool planes_changed : 1;
623369e5 116 bool mode_changed : 1;
eab3bbef 117 bool active_changed : 1;
fc596660 118 bool connectors_changed : 1;
44d1240d 119 bool zpos_changed : 1;
5488dc16 120 bool color_mgmt_changed : 1;
623369e5 121
b25c60af
BB
122 /**
123 * @no_vblank:
124 *
125 * Reflects the ability of a CRTC to send VBLANK events. This state
126 * usually depends on the pipeline configuration, and the main usuage
127 * is CRTCs feeding a writeback connector operating in oneshot mode.
128 * In this case the VBLANK event is only generated when a job is queued
129 * to the writeback connector, and we want the core to fake VBLANK
130 * events when this part of the pipeline hasn't changed but others had
131 * or when the CRTC and connectors are being disabled.
132 *
133 * __drm_atomic_helper_crtc_duplicate_state() will not reset the value
134 * from the current state, the CRTC driver is then responsible for
135 * updating this field when needed.
136 *
137 * Note that the combination of &drm_crtc_state.event == NULL and
138 * &drm_crtc_state.no_blank == true is valid and usually used when the
139 * writeback connector attached to the CRTC has a new job queued. In
140 * this case the driver will send the VBLANK event on its own when the
141 * writeback job is complete.
142 */
143 bool no_vblank : 1;
144
6ddd388a
RC
145 /* attached planes bitmask:
146 * WARNING: transitional helpers do not maintain plane_mask so
147 * drivers not converted over to atomic helpers should not rely
148 * on plane_mask being accurate!
149 */
150 u32 plane_mask;
151
4cd9fa52 152 u32 connector_mask;
e87a52b3 153 u32 encoder_mask;
4cd9fa52 154
9de5d4a6
DV
155 /**
156 * @adjusted_mode:
157 *
158 * Internal display timings which can be used by the driver to handle
159 * differences between the mode requested by userspace in @mode and what
584a0146
PC
160 * is actually programmed into the hardware.
161 *
162 * For drivers using drm_bridge, this stores hardware display timings
163 * used between the CRTC and the first bridge. For other drivers, the
164 * meaning of the adjusted_mode field is purely driver implementation
165 * defined information, and will usually be used to store the hardware
166 * display timings used between the CRTC and encoder blocks.
9de5d4a6 167 */
2f324b42
DV
168 struct drm_display_mode adjusted_mode;
169
9de5d4a6
DV
170 /**
171 * @mode:
172 *
173 * Display timings requested by userspace. The driver should try to
174 * match the refresh rate as close as possible (but note that it's
175 * undefined what exactly is close enough, e.g. some of the HDMI modes
176 * only differ in less than 1% of the refresh rate). The active width
177 * and height as observed by userspace for positioning planes must match
178 * exactly.
179 *
180 * For external connectors where the sink isn't fixed (like with a
181 * built-in panel), this mode here should match the physical mode on the
182 * wire to the last details (i.e. including sync polarities and
183 * everything).
184 */
144ecb97
DV
185 struct drm_display_mode mode;
186
99cf4a29
DS
187 /* blob property to expose current mode to atomic userspace */
188 struct drm_property_blob *mode_blob;
189
2e38178e
DV
190 /**
191 * @degamma_lut:
192 *
193 * Lookup table for converting framebuffer pixel data before apply the
194 * color conversion matrix @ctm. See drm_crtc_enable_color_mgmt(). The
195 * blob (if not NULL) is an array of &struct drm_color_lut.
196 */
5488dc16 197 struct drm_property_blob *degamma_lut;
2e38178e
DV
198
199 /**
200 * @ctm:
201 *
202 * Color transformation matrix. See drm_crtc_enable_color_mgmt(). The
203 * blob (if not NULL) is a &struct drm_color_ctm.
204 */
5488dc16 205 struct drm_property_blob *ctm;
2e38178e
DV
206
207 /**
208 * @gamma_lut:
209 *
210 * Lookup table for converting pixel data after the color conversion
211 * matrix @ctm. See drm_crtc_enable_color_mgmt(). The blob (if not
212 * NULL) is an array of &struct drm_color_lut.
213 */
5488dc16
LL
214 struct drm_property_blob *gamma_lut;
215
f869a6ec
AG
216 /**
217 * @target_vblank:
218 *
219 * Target vertical blank period when a page flip
220 * should take effect.
221 */
f869a6ec
AG
222 u32 target_vblank;
223
6cbe5c46
AG
224 /**
225 * @pageflip_flags:
226 *
227 * DRM_MODE_PAGE_FLIP_* flags, as passed to the page flip ioctl.
228 * Zero in any other case.
229 */
230 u32 pageflip_flags;
231
61802130
DV
232 /**
233 * @event:
234 *
235 * Optional pointer to a DRM event to signal upon completion of the
236 * state update. The driver must send out the event when the atomic
237 * commit operation completes. There are two cases:
238 *
239 * - The event is for a CRTC which is being disabled through this
240 * atomic commit. In that case the event can be send out any time
241 * after the hardware has stopped scanning out the current
242 * framebuffers. It should contain the timestamp and counter for the
8938d135
DV
243 * last vblank before the display pipeline was shut off. The simplest
244 * way to achieve that is calling drm_crtc_send_vblank_event()
245 * somewhen after drm_crtc_vblank_off() has been called.
61802130
DV
246 *
247 * - For a CRTC which is enabled at the end of the commit (even when it
248 * undergoes an full modeset) the vblank timestamp and counter must
249 * be for the vblank right before the first frame that scans out the
250 * new set of buffers. Again the event can only be sent out after the
251 * hardware has stopped scanning out the old buffers.
252 *
253 * - Events for disabled CRTCs are not allowed, and drivers can ignore
254 * that case.
255 *
256 * This can be handled by the drm_crtc_send_vblank_event() function,
257 * which the driver should call on the provided event upon completion of
258 * the atomic commit. Note that if the driver supports vblank signalling
259 * and timestamping the vblank counters and timestamps must agree with
260 * the ones returned from page flip events. With the current vblank
261 * helper infrastructure this can be achieved by holding a vblank
262 * reference while the page flip is pending, acquired through
263 * drm_crtc_vblank_get() and released with drm_crtc_vblank_put().
264 * Drivers are free to implement their own vblank counter and timestamp
265 * tracking though, e.g. if they have accurate timestamp registers in
266 * hardware.
267 *
268 * For hardware which supports some means to synchronize vblank
269 * interrupt delivery with committing display state there's also
270 * drm_crtc_arm_vblank_event(). See the documentation of that function
271 * for a detailed discussion of the constraints it needs to be used
272 * safely.
66f8c100
DV
273 *
274 * If the device can't notify of flip completion in a race-free way
275 * at all, then the event should be armed just after the page flip is
276 * committed. In the worst case the driver will send the event to
277 * userspace one frame too late. This doesn't allow for a real atomic
278 * update, but it should avoid tearing.
61802130 279 */
144ecb97
DV
280 struct drm_pending_vblank_event *event;
281
163bcc2c
ML
282 /**
283 * @commit:
284 *
285 * This tracks how the commit for this update proceeds through the
286 * various phases. This is never cleared, except when we destroy the
287 * state, so that subsequent commits can synchronize with previous ones.
288 */
289 struct drm_crtc_commit *commit;
290
144ecb97
DV
291 struct drm_atomic_state *state;
292};
f453ba04
DA
293
294/**
3bf0401c 295 * struct drm_crtc_funcs - control CRTCs for a given device
f453ba04
DA
296 *
297 * The drm_crtc_funcs structure is the central CRTC management structure
298 * in the DRM. Each CRTC controls one or more connectors (note that the name
299 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
300 * connectors, not just CRTs).
301 *
302 * Each driver is responsible for filling out this structure at startup time,
303 * in addition to providing other modesetting features, like i2c and DDC
304 * bus accessors.
305 */
306struct drm_crtc_funcs {
88548636
DV
307 /**
308 * @reset:
309 *
310 * Reset CRTC hardware and software state to off. This function isn't
311 * called by the core directly, only through drm_mode_config_reset().
312 * It's not a helper hook only for historical reasons.
313 *
314 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
315 * atomic state using this hook.
316 */
eb033556 317 void (*reset)(struct drm_crtc *crtc);
f453ba04 318
f6da8c6e
DV
319 /**
320 * @cursor_set:
321 *
322 * Update the cursor image. The cursor position is relative to the CRTC
323 * and can be partially or fully outside of the visible area.
324 *
325 * Note that contrary to all other KMS functions the legacy cursor entry
326 * points don't take a framebuffer object, but instead take directly a
327 * raw buffer object id from the driver's buffer manager (which is
328 * either GEM or TTM for current drivers).
329 *
330 * This entry point is deprecated, drivers should instead implement
331 * universal plane support and register a proper cursor plane using
332 * drm_crtc_init_with_planes().
333 *
334 * This callback is optional
335 *
336 * RETURNS:
337 *
338 * 0 on success or a negative error code on failure.
339 */
f453ba04
DA
340 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
341 uint32_t handle, uint32_t width, uint32_t height);
f6da8c6e
DV
342
343 /**
344 * @cursor_set2:
345 *
346 * Update the cursor image, including hotspot information. The hotspot
347 * must not affect the cursor position in CRTC coordinates, but is only
348 * meant as a hint for virtualized display hardware to coordinate the
349 * guests and hosts cursor position. The cursor hotspot is relative to
350 * the cursor image. Otherwise this works exactly like @cursor_set.
351 *
352 * This entry point is deprecated, drivers should instead implement
353 * universal plane support and register a proper cursor plane using
354 * drm_crtc_init_with_planes().
355 *
356 * This callback is optional.
357 *
358 * RETURNS:
359 *
360 * 0 on success or a negative error code on failure.
361 */
4c813d4d
DA
362 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
363 uint32_t handle, uint32_t width, uint32_t height,
364 int32_t hot_x, int32_t hot_y);
f6da8c6e
DV
365
366 /**
367 * @cursor_move:
368 *
369 * Update the cursor position. The cursor does not need to be visible
370 * when this hook is called.
371 *
372 * This entry point is deprecated, drivers should instead implement
373 * universal plane support and register a proper cursor plane using
374 * drm_crtc_init_with_planes().
375 *
376 * This callback is optional.
377 *
378 * RETURNS:
379 *
380 * 0 on success or a negative error code on failure.
381 */
f453ba04
DA
382 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
383
f6da8c6e
DV
384 /**
385 * @gamma_set:
386 *
387 * Set gamma on the CRTC.
388 *
389 * This callback is optional.
390 *
2e38178e
DV
391 * Atomic drivers who want to support gamma tables should implement the
392 * atomic color management support, enabled by calling
393 * drm_crtc_enable_color_mgmt(), which then supports the legacy gamma
394 * interface through the drm_atomic_helper_legacy_gamma_set()
395 * compatibility implementation.
f6da8c6e 396 */
7ea77283 397 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
6d124ff8
DV
398 uint32_t size,
399 struct drm_modeset_acquire_ctx *ctx);
88548636
DV
400
401 /**
402 * @destroy:
403 *
404 * Clean up plane resources. This is only called at driver unload time
405 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
406 * in DRM.
407 */
f453ba04
DA
408 void (*destroy)(struct drm_crtc *crtc);
409
f6da8c6e
DV
410 /**
411 * @set_config:
412 *
413 * This is the main legacy entry point to change the modeset state on a
414 * CRTC. All the details of the desired configuration are passed in a
ea0dd85a 415 * &struct drm_mode_set - see there for details.
f6da8c6e
DV
416 *
417 * Drivers implementing atomic modeset should use
418 * drm_atomic_helper_set_config() to implement this hook.
419 *
420 * RETURNS:
421 *
422 * 0 on success or a negative error code on failure.
423 */
a4eff9aa
DV
424 int (*set_config)(struct drm_mode_set *set,
425 struct drm_modeset_acquire_ctx *ctx);
d91d8a3f 426
f6da8c6e
DV
427 /**
428 * @page_flip:
429 *
430 * Legacy entry point to schedule a flip to the given framebuffer.
431 *
432 * Page flipping is a synchronization mechanism that replaces the frame
433 * buffer being scanned out by the CRTC with a new frame buffer during
434 * vertical blanking, avoiding tearing (except when requested otherwise
435 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
436 * requests a page flip the DRM core verifies that the new frame buffer
437 * is large enough to be scanned out by the CRTC in the currently
d574528a
DV
438 * configured mode and then calls this hook with a pointer to the new
439 * frame buffer.
f6da8c6e
DV
440 *
441 * The driver must wait for any pending rendering to the new framebuffer
442 * to complete before executing the flip. It should also wait for any
443 * pending rendering from other drivers if the underlying buffer is a
444 * shared dma-buf.
445 *
446 * An application can request to be notified when the page flip has
ea0dd85a 447 * completed. The drm core will supply a &struct drm_event in the event
f6da8c6e
DV
448 * parameter in this case. This can be handled by the
449 * drm_crtc_send_vblank_event() function, which the driver should call on
450 * the provided event upon completion of the flip. Note that if
451 * the driver supports vblank signalling and timestamping the vblank
452 * counters and timestamps must agree with the ones returned from page
453 * flip events. With the current vblank helper infrastructure this can
454 * be achieved by holding a vblank reference while the page flip is
455 * pending, acquired through drm_crtc_vblank_get() and released with
456 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
457 * counter and timestamp tracking though, e.g. if they have accurate
458 * timestamp registers in hardware.
459 *
f6da8c6e
DV
460 * This callback is optional.
461 *
462 * NOTE:
463 *
464 * Very early versions of the KMS ABI mandated that the driver must
465 * block (but not reject) any rendering to the old framebuffer until the
466 * flip operation has completed and the old framebuffer is no longer
467 * visible. This requirement has been lifted, and userspace is instead
468 * expected to request delivery of an event and wait with recycling old
469 * buffers until such has been received.
470 *
471 * RETURNS:
472 *
473 * 0 on success or a negative error code on failure. Note that if a
d574528a 474 * page flip operation is already pending the callback should return
f6da8c6e
DV
475 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
476 * or just runtime disabled through DPMS respectively the new atomic
4cba6850
DV
477 * "ACTIVE" state) should result in an -EINVAL error code. Note that
478 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
d91d8a3f
KH
479 */
480 int (*page_flip)(struct drm_crtc *crtc,
481 struct drm_framebuffer *fb,
ed8d1975 482 struct drm_pending_vblank_event *event,
41292b1f
DV
483 uint32_t flags,
484 struct drm_modeset_acquire_ctx *ctx);
bffd9de0 485
c229bfbb
MD
486 /**
487 * @page_flip_target:
488 *
489 * Same as @page_flip but with an additional parameter specifying the
490 * absolute target vertical blank period (as reported by
491 * drm_crtc_vblank_count()) when the flip should take effect.
492 *
493 * Note that the core code calls drm_crtc_vblank_get before this entry
494 * point, and will call drm_crtc_vblank_put if this entry point returns
495 * any non-0 error code. It's the driver's responsibility to call
496 * drm_crtc_vblank_put after this entry point returns 0, typically when
497 * the flip completes.
498 */
499 int (*page_flip_target)(struct drm_crtc *crtc,
500 struct drm_framebuffer *fb,
501 struct drm_pending_vblank_event *event,
41292b1f
DV
502 uint32_t flags, uint32_t target,
503 struct drm_modeset_acquire_ctx *ctx);
c229bfbb 504
88548636
DV
505 /**
506 * @set_property:
507 *
508 * This is the legacy entry point to update a property attached to the
509 * CRTC.
510 *
88548636 511 * This callback is optional if the driver does not support any legacy
144a7999
DV
512 * driver-private properties. For atomic drivers it is not used because
513 * property handling is done entirely in the DRM core.
88548636
DV
514 *
515 * RETURNS:
516 *
517 * 0 on success or a negative error code on failure.
518 */
bffd9de0
PZ
519 int (*set_property)(struct drm_crtc *crtc,
520 struct drm_property *property, uint64_t val);
144ecb97 521
88548636
DV
522 /**
523 * @atomic_duplicate_state:
524 *
525 * Duplicate the current atomic state for this CRTC and return it.
d574528a 526 * The core and helpers guarantee that any atomic state duplicated with
88548636 527 * this hook and still owned by the caller (i.e. not transferred to the
d574528a
DV
528 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
529 * cleaned up by calling the @atomic_destroy_state hook in this
530 * structure.
88548636 531 *
ba1f665f
HM
532 * This callback is mandatory for atomic drivers.
533 *
d574528a 534 * Atomic drivers which don't subclass &struct drm_crtc_state should use
88548636
DV
535 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
536 * state structure to extend it with driver-private state should use
537 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
538 * duplicated in a consistent fashion across drivers.
539 *
d574528a 540 * It is an error to call this hook before &drm_crtc.state has been
88548636
DV
541 * initialized correctly.
542 *
543 * NOTE:
544 *
545 * If the duplicate state references refcounted resources this hook must
546 * acquire a reference for each of them. The driver must release these
547 * references again in @atomic_destroy_state.
548 *
549 * RETURNS:
550 *
551 * Duplicated atomic state or NULL when the allocation failed.
552 */
144ecb97 553 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
88548636
DV
554
555 /**
556 * @atomic_destroy_state:
557 *
558 * Destroy a state duplicated with @atomic_duplicate_state and release
559 * or unreference all resources it references
ba1f665f
HM
560 *
561 * This callback is mandatory for atomic drivers.
88548636 562 */
144ecb97 563 void (*atomic_destroy_state)(struct drm_crtc *crtc,
cc4ceb48 564 struct drm_crtc_state *state);
88548636
DV
565
566 /**
567 * @atomic_set_property:
568 *
569 * Decode a driver-private property value and store the decoded value
570 * into the passed-in state structure. Since the atomic core decodes all
571 * standardized properties (even for extensions beyond the core set of
572 * properties which might not be implemented by all drivers) this
573 * requires drivers to subclass the state structure.
574 *
575 * Such driver-private properties should really only be implemented for
576 * truly hardware/vendor specific state. Instead it is preferred to
577 * standardize atomic extension and decode the properties used to expose
578 * such an extension in the core.
579 *
580 * Do not call this function directly, use
581 * drm_atomic_crtc_set_property() instead.
582 *
583 * This callback is optional if the driver does not support any
584 * driver-private atomic properties.
585 *
586 * NOTE:
587 *
588 * This function is called in the state assembly phase of atomic
589 * modesets, which can be aborted for any reason (including on
590 * userspace's request to just check whether a configuration would be
591 * possible). Drivers MUST NOT touch any persistent state (hardware or
592 * software) or data structures except the passed in @state parameter.
593 *
594 * Also since userspace controls in which order properties are set this
595 * function must not do any input validation (since the state update is
596 * incomplete and hence likely inconsistent). Instead any such input
597 * validation must be done in the various atomic_check callbacks.
598 *
599 * RETURNS:
600 *
601 * 0 if the property has been found, -EINVAL if the property isn't
602 * implemented by the driver (which should never happen, the core only
603 * asks for properties attached to this CRTC). No other validation is
604 * allowed by the driver. The core already checks that the property
605 * value is within the range (integer, valid enum value, ...) the driver
606 * set when registering the property.
607 */
144ecb97
DV
608 int (*atomic_set_property)(struct drm_crtc *crtc,
609 struct drm_crtc_state *state,
610 struct drm_property *property,
611 uint64_t val);
88548636
DV
612 /**
613 * @atomic_get_property:
614 *
615 * Reads out the decoded driver-private property. This is used to
c6b0ca3e 616 * implement the GETCRTC IOCTL.
88548636
DV
617 *
618 * Do not call this function directly, use
619 * drm_atomic_crtc_get_property() instead.
620 *
621 * This callback is optional if the driver does not support any
622 * driver-private atomic properties.
623 *
624 * RETURNS:
625 *
626 * 0 on success, -EINVAL if the property isn't implemented by the
627 * driver (which should never happen, the core only asks for
628 * properties attached to this CRTC).
629 */
ac9c9256
RC
630 int (*atomic_get_property)(struct drm_crtc *crtc,
631 const struct drm_crtc_state *state,
632 struct drm_property *property,
633 uint64_t *val);
79190ea2
BG
634
635 /**
636 * @late_register:
637 *
638 * This optional hook can be used to register additional userspace
639 * interfaces attached to the crtc like debugfs interfaces.
640 * It is called late in the driver load sequence from drm_dev_register().
641 * Everything added from this callback should be unregistered in
642 * the early_unregister callback.
643 *
644 * Returns:
645 *
646 * 0 on success, or a negative error code on failure.
647 */
648 int (*late_register)(struct drm_crtc *crtc);
649
650 /**
651 * @early_unregister:
652 *
653 * This optional hook should be used to unregister the additional
654 * userspace interfaces attached to the crtc from
559bdaf7 655 * @late_register. It is called from drm_dev_unregister(),
79190ea2
BG
656 * early in the driver unload sequence to disable userspace access
657 * before data structures are torndown.
658 */
659 void (*early_unregister)(struct drm_crtc *crtc);
9edbf1fa
TV
660
661 /**
662 * @set_crc_source:
663 *
664 * Changes the source of CRC checksums of frames at the request of
665 * userspace, typically for testing purposes. The sources available are
666 * specific of each driver and a %NULL value indicates that CRC
667 * generation is to be switched off.
668 *
669 * When CRC generation is enabled, the driver should call
670 * drm_crtc_add_crc_entry() at each frame, providing any information
671 * that characterizes the frame contents in the crcN arguments, as
760f71e7 672 * provided from the configured source. Drivers must accept an "auto"
9edbf1fa
TV
673 * source name that will select a default source for this CRTC.
674 *
760f71e7
DV
675 * Note that "auto" can depend upon the current modeset configuration,
676 * e.g. it could pick an encoder or output specific CRC sampling point.
677 *
9edbf1fa
TV
678 * This callback is optional if the driver does not support any CRC
679 * generation functionality.
680 *
681 * RETURNS:
682 *
683 * 0 on success or a negative error code on failure.
684 */
685 int (*set_crc_source)(struct drm_crtc *crtc, const char *source,
686 size_t *values_cnt);
fceffb32
RC
687
688 /**
689 * @atomic_print_state:
690 *
ea0dd85a 691 * If driver subclasses &struct drm_crtc_state, it should implement
fceffb32
RC
692 * this optional hook for printing additional driver specific state.
693 *
694 * Do not call this directly, use drm_atomic_crtc_print_state()
695 * instead.
696 */
697 void (*atomic_print_state)(struct drm_printer *p,
698 const struct drm_crtc_state *state);
84e35483
SG
699
700 /**
701 * @get_vblank_counter:
702 *
703 * Driver callback for fetching a raw hardware vblank counter for the
704 * CRTC. It's meant to be used by new drivers as the replacement of
705 * &drm_driver.get_vblank_counter hook.
706 *
707 * This callback is optional. If a device doesn't have a hardware
708 * counter, the driver can simply leave the hook as NULL. The DRM core
709 * will account for missed vblank events while interrupts where disabled
710 * based on system timestamps.
711 *
712 * Wraparound handling and loss of events due to modesetting is dealt
713 * with in the DRM core code, as long as drivers call
714 * drm_crtc_vblank_off() and drm_crtc_vblank_on() when disabling or
715 * enabling a CRTC.
716 *
57d30230
DV
717 * See also &drm_device.vblank_disable_immediate and
718 * &drm_device.max_vblank_count.
719 *
84e35483
SG
720 * Returns:
721 *
722 * Raw vblank counter value.
723 */
724 u32 (*get_vblank_counter)(struct drm_crtc *crtc);
725
726 /**
727 * @enable_vblank:
728 *
729 * Enable vblank interrupts for the CRTC. It's meant to be used by
730 * new drivers as the replacement of &drm_driver.enable_vblank hook.
731 *
732 * Returns:
733 *
734 * Zero on success, appropriate errno if the vblank interrupt cannot
735 * be enabled.
736 */
737 int (*enable_vblank)(struct drm_crtc *crtc);
738
739 /**
740 * @disable_vblank:
741 *
742 * Disable vblank interrupts for the CRTC. It's meant to be used by
743 * new drivers as the replacement of &drm_driver.disable_vblank hook.
744 */
745 void (*disable_vblank)(struct drm_crtc *crtc);
f453ba04
DA
746};
747
748/**
3bf0401c 749 * struct drm_crtc - central CRTC control structure
7749163e 750 * @dev: parent DRM device
2c0c33d4 751 * @port: OF node used by drm_of_find_possible_crtcs()
7749163e 752 * @head: list management
ac3ba4a5 753 * @name: human readable name, can be overwritten by the driver
51fd371b 754 * @mutex: per-CRTC locking
7749163e 755 * @base: base KMS object for ID tracking etc.
e13161af
MR
756 * @primary: primary plane for this CRTC
757 * @cursor: cursor plane for this CRTC
2c0c33d4
DV
758 * @cursor_x: current x position of the cursor, used for universal cursor planes
759 * @cursor_y: current y position of the cursor, used for universal cursor planes
f453ba04 760 * @enabled: is this CRTC enabled?
7749163e
JB
761 * @mode: current mode timings
762 * @hwmode: mode timings as programmed to hw regs
f453ba04
DA
763 * @x: x position on screen
764 * @y: y position on screen
f453ba04 765 * @funcs: CRTC control functions
7749163e
JB
766 * @gamma_size: size of gamma ramp
767 * @gamma_store: gamma ramp values
7749163e 768 * @helper_private: mid-layer private data
bffd9de0 769 * @properties: property tracking for this CRTC
f453ba04
DA
770 *
771 * Each CRTC may have one or more connectors associated with it. This structure
772 * allows the CRTC to be controlled.
773 */
774struct drm_crtc {
775 struct drm_device *dev;
7e435aad 776 struct device_node *port;
f453ba04
DA
777 struct list_head head;
778
fa3ab4c2
VS
779 char *name;
780
ac3ba4a5
DV
781 /**
782 * @mutex:
29494c17 783 *
c9e42b72 784 * This provides a read lock for the overall CRTC state (mode, dpms
29494c17 785 * state, ...) and a write lock for everything which can be update
c9e42b72 786 * without a full modeset (fb, cursor data, CRTC properties ...). A full
d574528a 787 * modeset also need to grab &drm_mode_config.connection_mutex.
c9e42b72
DV
788 *
789 * For atomic drivers specifically this protects @state.
29494c17 790 */
51fd371b 791 struct drm_modeset_lock mutex;
29494c17 792
f453ba04
DA
793 struct drm_mode_object base;
794
e13161af
MR
795 /* primary and cursor planes for CRTC */
796 struct drm_plane *primary;
797 struct drm_plane *cursor;
798
96094081
DV
799 /**
800 * @index: Position inside the mode_config.list, can be used as an array
801 * index. It is invariant over the lifetime of the CRTC.
802 */
490d3d1b
CW
803 unsigned index;
804
161d0dc1
MR
805 /* position of cursor plane on crtc */
806 int cursor_x;
807 int cursor_y;
808
f453ba04
DA
809 bool enabled;
810
27641c3f 811 /* Requested mode from modesetting. */
f453ba04
DA
812 struct drm_display_mode mode;
813
27641c3f
MK
814 /* Programmed mode in hw, after adjustments for encoders,
815 * crtc, panel scaling etc. Needed for timestamping etc.
816 */
817 struct drm_display_mode hwmode;
818
f453ba04 819 int x, y;
f453ba04
DA
820 const struct drm_crtc_funcs *funcs;
821
5488dc16 822 /* Legacy FB CRTC gamma size for reporting to userspace */
f453ba04
DA
823 uint32_t gamma_size;
824 uint16_t *gamma_store;
825
826 /* if you are using the helper */
4490d4c7 827 const struct drm_crtc_helper_funcs *helper_private;
bffd9de0
PZ
828
829 struct drm_object_properties properties;
d059f652 830
3b24f7d6
DV
831 /**
832 * @state:
833 *
834 * Current atomic state for this CRTC.
c9e42b72
DV
835 *
836 * This is protected by @mutex. Note that nonblocking atomic commits
837 * access the current CRTC state without taking locks. Either by going
838 * through the &struct drm_atomic_state pointers, see
77ac3b00
ML
839 * for_each_oldnew_crtc_in_state(), for_each_old_crtc_in_state() and
840 * for_each_new_crtc_in_state(). Or through careful ordering of atomic
841 * commit operations as implemented in the atomic helpers, see
842 * &struct drm_crtc_commit.
3b24f7d6 843 */
144ecb97
DV
844 struct drm_crtc_state *state;
845
3b24f7d6
DV
846 /**
847 * @commit_list:
848 *
849 * List of &drm_crtc_commit structures tracking pending commits.
163bcc2c
ML
850 * Protected by @commit_lock. This list holds its own full reference,
851 * as does the ongoing commit.
852 *
853 * "Note that the commit for a state change is also tracked in
854 * &drm_crtc_state.commit. For accessing the immediately preceding
855 * commit in an atomic update it is recommended to just use that
856 * pointer in the old CRTC state, since accessing that doesn't need
857 * any locking or list-walking. @commit_list should only be used to
858 * stall for framebuffer cleanup that's signalled through
859 * &drm_crtc_commit.cleanup_done."
3b24f7d6
DV
860 */
861 struct list_head commit_list;
862
863 /**
864 * @commit_lock:
865 *
866 * Spinlock to protect @commit_list.
867 */
868 spinlock_t commit_lock;
869
9edbf1fa
TV
870#ifdef CONFIG_DEBUG_FS
871 /**
872 * @debugfs_entry:
873 *
874 * Debugfs directory for this CRTC.
875 */
876 struct dentry *debugfs_entry;
47f6cdd2 877#endif
9edbf1fa
TV
878
879 /**
880 * @crc:
881 *
882 * Configuration settings of CRC capture.
883 */
884 struct drm_crtc_crc crc;
6d6003c4
GP
885
886 /**
887 * @fence_context:
888 *
889 * timeline context used for fence operations.
890 */
891 unsigned int fence_context;
892
893 /**
894 * @fence_lock:
895 *
896 * spinlock to protect the fences in the fence_context.
897 */
898
899 spinlock_t fence_lock;
900 /**
901 * @fence_seqno:
902 *
903 * Seqno variable used as monotonic counter for the fences
904 * created on the CRTC's timeline.
905 */
906 unsigned long fence_seqno;
907
908 /**
909 * @timeline_name:
910 *
911 * The name of the CRTC's fence timeline.
912 */
913 char timeline_name[32];
f453ba04
DA
914};
915
f453ba04 916/**
3bf0401c 917 * struct drm_mode_set - new values for a CRTC config change
ef27351a
JB
918 * @fb: framebuffer to use for new config
919 * @crtc: CRTC whose configuration we're about to change
920 * @mode: mode timings to use
921 * @x: position of this CRTC relative to @fb
922 * @y: position of this CRTC relative to @fb
923 * @connectors: array of connectors to drive with this CRTC if possible
924 * @num_connectors: size of @connectors array
f453ba04 925 *
d5d487eb
DV
926 * This represents a modeset configuration for the legacy SETCRTC ioctl and is
927 * also used internally. Atomic drivers instead use &drm_atomic_state.
f453ba04
DA
928 */
929struct drm_mode_set {
f453ba04
DA
930 struct drm_framebuffer *fb;
931 struct drm_crtc *crtc;
932 struct drm_display_mode *mode;
933
934 uint32_t x;
935 uint32_t y;
936
937 struct drm_connector **connectors;
938 size_t num_connectors;
939};
940
f453ba04 941#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
f453ba04 942
edd420ea 943__printf(6, 7)
f9882876
VS
944int drm_crtc_init_with_planes(struct drm_device *dev,
945 struct drm_crtc *crtc,
946 struct drm_plane *primary,
947 struct drm_plane *cursor,
948 const struct drm_crtc_funcs *funcs,
949 const char *name, ...);
edd420ea 950void drm_crtc_cleanup(struct drm_crtc *crtc);
490d3d1b
CW
951
952/**
953 * drm_crtc_index - find the index of a registered CRTC
954 * @crtc: CRTC to find index for
955 *
956 * Given a registered CRTC, return the index of that CRTC within a DRM
957 * device's list of CRTCs.
958 */
a5bd451b 959static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc)
490d3d1b
CW
960{
961 return crtc->index;
962}
db5f7a6e
RK
963
964/**
965 * drm_crtc_mask - find the mask of a registered CRTC
966 * @crtc: CRTC to find mask for
967 *
968 * Given a registered CRTC, return the mask bit of that CRTC for an
969 * encoder's possible_crtcs field.
970 */
1dfdb0ed 971static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc)
db5f7a6e
RK
972{
973 return 1 << drm_crtc_index(crtc);
974}
f453ba04 975
edd420ea
DV
976int drm_crtc_force_disable(struct drm_crtc *crtc);
977int drm_crtc_force_disable_all(struct drm_device *dev);
8cf5c917 978
edd420ea 979int drm_mode_set_config_internal(struct drm_mode_set *set);
6d1b81d8 980struct drm_crtc *drm_crtc_from_index(struct drm_device *dev, int idx);
81065548 981
d5d487eb
DV
982/**
983 * drm_crtc_find - look up a CRTC object from its ID
984 * @dev: DRM device
e7e62c7e 985 * @file_priv: drm file to check for lease against.
d5d487eb
DV
986 * @id: &drm_mode_object ID
987 *
988 * This can be used to look up a CRTC from its userspace ID. Only used by
989 * drivers for legacy IOCTLs and interface, nowadays extensions to the KMS
990 * userspace interface should be done using &drm_property.
991 */
96f60e37 992static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
418da172
KP
993 struct drm_file *file_priv,
994 uint32_t id)
96f60e37
RK
995{
996 struct drm_mode_object *mo;
418da172 997 mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_CRTC);
96f60e37
RK
998 return mo ? obj_to_crtc(mo) : NULL;
999}
1000
d5d487eb
DV
1001/**
1002 * drm_for_each_crtc - iterate over all CRTCs
1003 * @crtc: a &struct drm_crtc as the loop cursor
1004 * @dev: the &struct drm_device
1005 *
1006 * Iterate over all CRTCs of @dev.
1007 */
6295d607
DV
1008#define drm_for_each_crtc(crtc, dev) \
1009 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1010
f453ba04 1011#endif /* __DRM_CRTC_H__ */