2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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.
25 #ifndef __DRM_CRTC_H__
26 #define __DRM_CRTC_H__
28 #include <linux/i2c.h>
29 #include <linux/spinlock.h>
30 #include <linux/types.h>
31 #include <linux/idr.h>
33 #include <linux/hdmi.h>
34 #include <linux/media-bus-format.h>
35 #include <uapi/drm/drm_mode.h>
36 #include <uapi/drm/drm_fourcc.h>
37 #include <drm/drm_modeset_lock.h>
38 #include <drm/drm_rect.h>
39 #include <drm/drm_mode_object.h>
40 #include <drm/drm_framebuffer.h>
41 #include <drm/drm_modes.h>
42 #include <drm/drm_connector.h>
43 #include <drm/drm_encoder.h>
44 #include <drm/drm_property.h>
54 static inline int64_t U642I64(uint64_t val)
56 return (int64_t)*((int64_t *)&val);
58 static inline uint64_t I642U64(int64_t val)
60 return (uint64_t)*((uint64_t *)&val);
64 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
65 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
66 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
68 #define DRM_ROTATE_0 BIT(0)
69 #define DRM_ROTATE_90 BIT(1)
70 #define DRM_ROTATE_180 BIT(2)
71 #define DRM_ROTATE_270 BIT(3)
72 #define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
73 DRM_ROTATE_180 | DRM_ROTATE_270)
74 #define DRM_REFLECT_X BIT(4)
75 #define DRM_REFLECT_Y BIT(5)
76 #define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
78 /* data corresponds to displayid vend/prod/serial */
79 struct drm_tile_group {
81 struct drm_device *dev;
88 struct drm_pending_vblank_event;
91 struct drm_atomic_state;
93 struct drm_crtc_helper_funcs;
94 struct drm_encoder_helper_funcs;
95 struct drm_plane_helper_funcs;
98 * struct drm_crtc_state - mutable CRTC state
99 * @crtc: backpointer to the CRTC
100 * @enable: whether the CRTC should be enabled, gates all other state
101 * @active: whether the CRTC is actively displaying (used for DPMS)
102 * @planes_changed: planes on this crtc are updated
103 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
104 * @active_changed: crtc_state->active has been toggled.
105 * @connectors_changed: connectors to this crtc have been updated
106 * @zpos_changed: zpos values of planes on this crtc have been updated
107 * @color_mgmt_changed: color management properties have changed (degamma or
108 * gamma LUT or CSC matrix)
109 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
110 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
111 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
112 * @last_vblank_count: for helpers and drivers to capture the vblank of the
113 * update to ensure framebuffer cleanup isn't done too early
114 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
115 * @mode: current mode timings
116 * @mode_blob: &drm_property_blob for @mode
117 * @degamma_lut: Lookup table for converting framebuffer pixel data
118 * before apply the conversion matrix
119 * @ctm: Transformation matrix
120 * @gamma_lut: Lookup table for converting pixel data after the
122 * @event: optional pointer to a DRM event to signal upon completion of the
124 * @state: backpointer to global drm_atomic_state
126 * Note that the distinction between @enable and @active is rather subtile:
127 * Flipping @active while @enable is set without changing anything else may
128 * never return in a failure from the ->atomic_check callback. Userspace assumes
129 * that a DPMS On will always succeed. In other words: @enable controls resource
130 * assignment, @active controls the actual hardware state.
132 struct drm_crtc_state {
133 struct drm_crtc *crtc;
138 /* computed state bits used by helpers and drivers */
139 bool planes_changed : 1;
140 bool mode_changed : 1;
141 bool active_changed : 1;
142 bool connectors_changed : 1;
143 bool zpos_changed : 1;
144 bool color_mgmt_changed : 1;
146 /* attached planes bitmask:
147 * WARNING: transitional helpers do not maintain plane_mask so
148 * drivers not converted over to atomic helpers should not rely
149 * on plane_mask being accurate!
156 /* last_vblank_count: for vblank waits before cleanup */
157 u32 last_vblank_count;
159 /* adjusted_mode: for use by helpers and drivers */
160 struct drm_display_mode adjusted_mode;
162 struct drm_display_mode mode;
164 /* blob property to expose current mode to atomic userspace */
165 struct drm_property_blob *mode_blob;
167 /* blob property to expose color management to userspace */
168 struct drm_property_blob *degamma_lut;
169 struct drm_property_blob *ctm;
170 struct drm_property_blob *gamma_lut;
172 struct drm_pending_vblank_event *event;
174 struct drm_atomic_state *state;
178 * struct drm_crtc_funcs - control CRTCs for a given device
180 * The drm_crtc_funcs structure is the central CRTC management structure
181 * in the DRM. Each CRTC controls one or more connectors (note that the name
182 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
183 * connectors, not just CRTs).
185 * Each driver is responsible for filling out this structure at startup time,
186 * in addition to providing other modesetting features, like i2c and DDC
189 struct drm_crtc_funcs {
193 * Reset CRTC hardware and software state to off. This function isn't
194 * called by the core directly, only through drm_mode_config_reset().
195 * It's not a helper hook only for historical reasons.
197 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
198 * atomic state using this hook.
200 void (*reset)(struct drm_crtc *crtc);
205 * Update the cursor image. The cursor position is relative to the CRTC
206 * and can be partially or fully outside of the visible area.
208 * Note that contrary to all other KMS functions the legacy cursor entry
209 * points don't take a framebuffer object, but instead take directly a
210 * raw buffer object id from the driver's buffer manager (which is
211 * either GEM or TTM for current drivers).
213 * This entry point is deprecated, drivers should instead implement
214 * universal plane support and register a proper cursor plane using
215 * drm_crtc_init_with_planes().
217 * This callback is optional
221 * 0 on success or a negative error code on failure.
223 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
224 uint32_t handle, uint32_t width, uint32_t height);
229 * Update the cursor image, including hotspot information. The hotspot
230 * must not affect the cursor position in CRTC coordinates, but is only
231 * meant as a hint for virtualized display hardware to coordinate the
232 * guests and hosts cursor position. The cursor hotspot is relative to
233 * the cursor image. Otherwise this works exactly like @cursor_set.
235 * This entry point is deprecated, drivers should instead implement
236 * universal plane support and register a proper cursor plane using
237 * drm_crtc_init_with_planes().
239 * This callback is optional.
243 * 0 on success or a negative error code on failure.
245 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
246 uint32_t handle, uint32_t width, uint32_t height,
247 int32_t hot_x, int32_t hot_y);
252 * Update the cursor position. The cursor does not need to be visible
253 * when this hook is called.
255 * This entry point is deprecated, drivers should instead implement
256 * universal plane support and register a proper cursor plane using
257 * drm_crtc_init_with_planes().
259 * This callback is optional.
263 * 0 on success or a negative error code on failure.
265 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
270 * Set gamma on the CRTC.
272 * This callback is optional.
276 * Drivers that support gamma tables and also fbdev emulation through
277 * the provided helper library need to take care to fill out the gamma
278 * hooks for both. Currently there's a bit an unfortunate duplication
279 * going on, which should eventually be unified to just one set of
282 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
288 * Clean up plane resources. This is only called at driver unload time
289 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
292 void (*destroy)(struct drm_crtc *crtc);
297 * This is the main legacy entry point to change the modeset state on a
298 * CRTC. All the details of the desired configuration are passed in a
299 * struct &drm_mode_set - see there for details.
301 * Drivers implementing atomic modeset should use
302 * drm_atomic_helper_set_config() to implement this hook.
306 * 0 on success or a negative error code on failure.
308 int (*set_config)(struct drm_mode_set *set);
313 * Legacy entry point to schedule a flip to the given framebuffer.
315 * Page flipping is a synchronization mechanism that replaces the frame
316 * buffer being scanned out by the CRTC with a new frame buffer during
317 * vertical blanking, avoiding tearing (except when requested otherwise
318 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
319 * requests a page flip the DRM core verifies that the new frame buffer
320 * is large enough to be scanned out by the CRTC in the currently
321 * configured mode and then calls the CRTC ->page_flip() operation with a
322 * pointer to the new frame buffer.
324 * The driver must wait for any pending rendering to the new framebuffer
325 * to complete before executing the flip. It should also wait for any
326 * pending rendering from other drivers if the underlying buffer is a
329 * An application can request to be notified when the page flip has
330 * completed. The drm core will supply a struct &drm_event in the event
331 * parameter in this case. This can be handled by the
332 * drm_crtc_send_vblank_event() function, which the driver should call on
333 * the provided event upon completion of the flip. Note that if
334 * the driver supports vblank signalling and timestamping the vblank
335 * counters and timestamps must agree with the ones returned from page
336 * flip events. With the current vblank helper infrastructure this can
337 * be achieved by holding a vblank reference while the page flip is
338 * pending, acquired through drm_crtc_vblank_get() and released with
339 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
340 * counter and timestamp tracking though, e.g. if they have accurate
341 * timestamp registers in hardware.
343 * This callback is optional.
347 * Very early versions of the KMS ABI mandated that the driver must
348 * block (but not reject) any rendering to the old framebuffer until the
349 * flip operation has completed and the old framebuffer is no longer
350 * visible. This requirement has been lifted, and userspace is instead
351 * expected to request delivery of an event and wait with recycling old
352 * buffers until such has been received.
356 * 0 on success or a negative error code on failure. Note that if a
357 * ->page_flip() operation is already pending the callback should return
358 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
359 * or just runtime disabled through DPMS respectively the new atomic
360 * "ACTIVE" state) should result in an -EINVAL error code. Note that
361 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
363 int (*page_flip)(struct drm_crtc *crtc,
364 struct drm_framebuffer *fb,
365 struct drm_pending_vblank_event *event,
371 * This is the legacy entry point to update a property attached to the
374 * Drivers implementing atomic modeset should use
375 * drm_atomic_helper_crtc_set_property() to implement this hook.
377 * This callback is optional if the driver does not support any legacy
378 * driver-private properties.
382 * 0 on success or a negative error code on failure.
384 int (*set_property)(struct drm_crtc *crtc,
385 struct drm_property *property, uint64_t val);
388 * @atomic_duplicate_state:
390 * Duplicate the current atomic state for this CRTC and return it.
391 * The core and helpers gurantee that any atomic state duplicated with
392 * this hook and still owned by the caller (i.e. not transferred to the
393 * driver by calling ->atomic_commit() from struct
394 * &drm_mode_config_funcs) will be cleaned up by calling the
395 * @atomic_destroy_state hook in this structure.
397 * Atomic drivers which don't subclass struct &drm_crtc should use
398 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
399 * state structure to extend it with driver-private state should use
400 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
401 * duplicated in a consistent fashion across drivers.
403 * It is an error to call this hook before crtc->state has been
404 * initialized correctly.
408 * If the duplicate state references refcounted resources this hook must
409 * acquire a reference for each of them. The driver must release these
410 * references again in @atomic_destroy_state.
414 * Duplicated atomic state or NULL when the allocation failed.
416 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
419 * @atomic_destroy_state:
421 * Destroy a state duplicated with @atomic_duplicate_state and release
422 * or unreference all resources it references
424 void (*atomic_destroy_state)(struct drm_crtc *crtc,
425 struct drm_crtc_state *state);
428 * @atomic_set_property:
430 * Decode a driver-private property value and store the decoded value
431 * into the passed-in state structure. Since the atomic core decodes all
432 * standardized properties (even for extensions beyond the core set of
433 * properties which might not be implemented by all drivers) this
434 * requires drivers to subclass the state structure.
436 * Such driver-private properties should really only be implemented for
437 * truly hardware/vendor specific state. Instead it is preferred to
438 * standardize atomic extension and decode the properties used to expose
439 * such an extension in the core.
441 * Do not call this function directly, use
442 * drm_atomic_crtc_set_property() instead.
444 * This callback is optional if the driver does not support any
445 * driver-private atomic properties.
449 * This function is called in the state assembly phase of atomic
450 * modesets, which can be aborted for any reason (including on
451 * userspace's request to just check whether a configuration would be
452 * possible). Drivers MUST NOT touch any persistent state (hardware or
453 * software) or data structures except the passed in @state parameter.
455 * Also since userspace controls in which order properties are set this
456 * function must not do any input validation (since the state update is
457 * incomplete and hence likely inconsistent). Instead any such input
458 * validation must be done in the various atomic_check callbacks.
462 * 0 if the property has been found, -EINVAL if the property isn't
463 * implemented by the driver (which should never happen, the core only
464 * asks for properties attached to this CRTC). No other validation is
465 * allowed by the driver. The core already checks that the property
466 * value is within the range (integer, valid enum value, ...) the driver
467 * set when registering the property.
469 int (*atomic_set_property)(struct drm_crtc *crtc,
470 struct drm_crtc_state *state,
471 struct drm_property *property,
474 * @atomic_get_property:
476 * Reads out the decoded driver-private property. This is used to
477 * implement the GETCRTC IOCTL.
479 * Do not call this function directly, use
480 * drm_atomic_crtc_get_property() instead.
482 * This callback is optional if the driver does not support any
483 * driver-private atomic properties.
487 * 0 on success, -EINVAL if the property isn't implemented by the
488 * driver (which should never happen, the core only asks for
489 * properties attached to this CRTC).
491 int (*atomic_get_property)(struct drm_crtc *crtc,
492 const struct drm_crtc_state *state,
493 struct drm_property *property,
499 * This optional hook can be used to register additional userspace
500 * interfaces attached to the crtc like debugfs interfaces.
501 * It is called late in the driver load sequence from drm_dev_register().
502 * Everything added from this callback should be unregistered in
503 * the early_unregister callback.
507 * 0 on success, or a negative error code on failure.
509 int (*late_register)(struct drm_crtc *crtc);
514 * This optional hook should be used to unregister the additional
515 * userspace interfaces attached to the crtc from
516 * late_unregister(). It is called from drm_dev_unregister(),
517 * early in the driver unload sequence to disable userspace access
518 * before data structures are torndown.
520 void (*early_unregister)(struct drm_crtc *crtc);
524 * struct drm_crtc - central CRTC control structure
525 * @dev: parent DRM device
526 * @port: OF node used by drm_of_find_possible_crtcs()
527 * @head: list management
528 * @name: human readable name, can be overwritten by the driver
529 * @mutex: per-CRTC locking
530 * @base: base KMS object for ID tracking etc.
531 * @primary: primary plane for this CRTC
532 * @cursor: cursor plane for this CRTC
533 * @cursor_x: current x position of the cursor, used for universal cursor planes
534 * @cursor_y: current y position of the cursor, used for universal cursor planes
535 * @enabled: is this CRTC enabled?
536 * @mode: current mode timings
537 * @hwmode: mode timings as programmed to hw regs
538 * @x: x position on screen
539 * @y: y position on screen
540 * @funcs: CRTC control functions
541 * @gamma_size: size of gamma ramp
542 * @gamma_store: gamma ramp values
543 * @helper_private: mid-layer private data
544 * @properties: property tracking for this CRTC
546 * Each CRTC may have one or more connectors associated with it. This structure
547 * allows the CRTC to be controlled.
550 struct drm_device *dev;
551 struct device_node *port;
552 struct list_head head;
559 * This provides a read lock for the overall crtc state (mode, dpms
560 * state, ...) and a write lock for everything which can be update
561 * without a full modeset (fb, cursor data, crtc properties ...). Full
562 * modeset also need to grab dev->mode_config.connection_mutex.
564 struct drm_modeset_lock mutex;
566 struct drm_mode_object base;
568 /* primary and cursor planes for CRTC */
569 struct drm_plane *primary;
570 struct drm_plane *cursor;
573 * @index: Position inside the mode_config.list, can be used as an array
574 * index. It is invariant over the lifetime of the CRTC.
578 /* position of cursor plane on crtc */
584 /* Requested mode from modesetting. */
585 struct drm_display_mode mode;
587 /* Programmed mode in hw, after adjustments for encoders,
588 * crtc, panel scaling etc. Needed for timestamping etc.
590 struct drm_display_mode hwmode;
593 const struct drm_crtc_funcs *funcs;
595 /* Legacy FB CRTC gamma size for reporting to userspace */
597 uint16_t *gamma_store;
599 /* if you are using the helper */
600 const struct drm_crtc_helper_funcs *helper_private;
602 struct drm_object_properties properties;
607 * Current atomic state for this CRTC.
609 struct drm_crtc_state *state;
614 * List of &drm_crtc_commit structures tracking pending commits.
615 * Protected by @commit_lock. This list doesn't hold its own full
616 * reference, but burrows it from the ongoing commit. Commit entries
617 * must be removed from this list once the commit is fully completed,
618 * but before it's correspoding &drm_atomic_state gets destroyed.
620 struct list_head commit_list;
625 * Spinlock to protect @commit_list.
627 spinlock_t commit_lock;
632 * Per-CRTC implicit acquire context used by atomic drivers for legacy
633 * IOCTLs, so that atomic drivers can get at the locking acquire
636 struct drm_modeset_acquire_ctx *acquire_ctx;
640 * struct drm_plane_state - mutable plane state
641 * @plane: backpointer to the plane
642 * @crtc: currently bound CRTC, NULL if disabled
643 * @fb: currently bound framebuffer
644 * @fence: optional fence to wait for before scanning out @fb
645 * @crtc_x: left position of visible portion of plane on crtc
646 * @crtc_y: upper position of visible portion of plane on crtc
647 * @crtc_w: width of visible portion of plane on crtc
648 * @crtc_h: height of visible portion of plane on crtc
649 * @src_x: left position of visible portion of plane within
651 * @src_y: upper position of visible portion of plane within
653 * @src_w: width of visible portion of plane (in 16.16)
654 * @src_h: height of visible portion of plane (in 16.16)
655 * @rotation: rotation of the plane
656 * @zpos: priority of the given plane on crtc (optional)
657 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
658 * where N is the number of active planes for given crtc
659 * @src: clipped source coordinates of the plane (in 16.16)
660 * @dst: clipped destination coordinates of the plane
661 * @visible: visibility of the plane
662 * @state: backpointer to global drm_atomic_state
664 struct drm_plane_state {
665 struct drm_plane *plane;
667 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
668 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
671 /* Signed dest location allows it to be partially off screen */
672 int32_t crtc_x, crtc_y;
673 uint32_t crtc_w, crtc_h;
675 /* Source values are 16.16 fixed point */
676 uint32_t src_x, src_y;
677 uint32_t src_h, src_w;
680 unsigned int rotation;
684 unsigned int normalized_zpos;
686 /* Clipped coordinates */
687 struct drm_rect src, dst;
690 * Is the plane actually visible? Can be false even
691 * if fb!=NULL and crtc!=NULL, due to clipping.
695 struct drm_atomic_state *state;
700 * struct drm_plane_funcs - driver plane control functions
702 struct drm_plane_funcs {
706 * This is the legacy entry point to enable and configure the plane for
707 * the given CRTC and framebuffer. It is never called to disable the
708 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
710 * The source rectangle in frame buffer memory coordinates is given by
711 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
712 * values). Devices that don't support subpixel plane coordinates can
713 * ignore the fractional part.
715 * The destination rectangle in CRTC coordinates is given by the
716 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
717 * Devices scale the source rectangle to the destination rectangle. If
718 * scaling is not supported, and the source rectangle size doesn't match
719 * the destination rectangle size, the driver must return a
720 * -<errorname>EINVAL</errorname> error.
722 * Drivers implementing atomic modeset should use
723 * drm_atomic_helper_update_plane() to implement this hook.
727 * 0 on success or a negative error code on failure.
729 int (*update_plane)(struct drm_plane *plane,
730 struct drm_crtc *crtc, struct drm_framebuffer *fb,
731 int crtc_x, int crtc_y,
732 unsigned int crtc_w, unsigned int crtc_h,
733 uint32_t src_x, uint32_t src_y,
734 uint32_t src_w, uint32_t src_h);
739 * This is the legacy entry point to disable the plane. The DRM core
740 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
741 * with the frame buffer ID set to 0. Disabled planes must not be
742 * processed by the CRTC.
744 * Drivers implementing atomic modeset should use
745 * drm_atomic_helper_disable_plane() to implement this hook.
749 * 0 on success or a negative error code on failure.
751 int (*disable_plane)(struct drm_plane *plane);
756 * Clean up plane resources. This is only called at driver unload time
757 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
760 void (*destroy)(struct drm_plane *plane);
765 * Reset plane hardware and software state to off. This function isn't
766 * called by the core directly, only through drm_mode_config_reset().
767 * It's not a helper hook only for historical reasons.
769 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
770 * atomic state using this hook.
772 void (*reset)(struct drm_plane *plane);
777 * This is the legacy entry point to update a property attached to the
780 * Drivers implementing atomic modeset should use
781 * drm_atomic_helper_plane_set_property() to implement this hook.
783 * This callback is optional if the driver does not support any legacy
784 * driver-private properties.
788 * 0 on success or a negative error code on failure.
790 int (*set_property)(struct drm_plane *plane,
791 struct drm_property *property, uint64_t val);
794 * @atomic_duplicate_state:
796 * Duplicate the current atomic state for this plane and return it.
797 * The core and helpers gurantee that any atomic state duplicated with
798 * this hook and still owned by the caller (i.e. not transferred to the
799 * driver by calling ->atomic_commit() from struct
800 * &drm_mode_config_funcs) will be cleaned up by calling the
801 * @atomic_destroy_state hook in this structure.
803 * Atomic drivers which don't subclass struct &drm_plane_state should use
804 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
805 * state structure to extend it with driver-private state should use
806 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
807 * duplicated in a consistent fashion across drivers.
809 * It is an error to call this hook before plane->state has been
810 * initialized correctly.
814 * If the duplicate state references refcounted resources this hook must
815 * acquire a reference for each of them. The driver must release these
816 * references again in @atomic_destroy_state.
820 * Duplicated atomic state or NULL when the allocation failed.
822 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
825 * @atomic_destroy_state:
827 * Destroy a state duplicated with @atomic_duplicate_state and release
828 * or unreference all resources it references
830 void (*atomic_destroy_state)(struct drm_plane *plane,
831 struct drm_plane_state *state);
834 * @atomic_set_property:
836 * Decode a driver-private property value and store the decoded value
837 * into the passed-in state structure. Since the atomic core decodes all
838 * standardized properties (even for extensions beyond the core set of
839 * properties which might not be implemented by all drivers) this
840 * requires drivers to subclass the state structure.
842 * Such driver-private properties should really only be implemented for
843 * truly hardware/vendor specific state. Instead it is preferred to
844 * standardize atomic extension and decode the properties used to expose
845 * such an extension in the core.
847 * Do not call this function directly, use
848 * drm_atomic_plane_set_property() instead.
850 * This callback is optional if the driver does not support any
851 * driver-private atomic properties.
855 * This function is called in the state assembly phase of atomic
856 * modesets, which can be aborted for any reason (including on
857 * userspace's request to just check whether a configuration would be
858 * possible). Drivers MUST NOT touch any persistent state (hardware or
859 * software) or data structures except the passed in @state parameter.
861 * Also since userspace controls in which order properties are set this
862 * function must not do any input validation (since the state update is
863 * incomplete and hence likely inconsistent). Instead any such input
864 * validation must be done in the various atomic_check callbacks.
868 * 0 if the property has been found, -EINVAL if the property isn't
869 * implemented by the driver (which shouldn't ever happen, the core only
870 * asks for properties attached to this plane). No other validation is
871 * allowed by the driver. The core already checks that the property
872 * value is within the range (integer, valid enum value, ...) the driver
873 * set when registering the property.
875 int (*atomic_set_property)(struct drm_plane *plane,
876 struct drm_plane_state *state,
877 struct drm_property *property,
881 * @atomic_get_property:
883 * Reads out the decoded driver-private property. This is used to
884 * implement the GETPLANE IOCTL.
886 * Do not call this function directly, use
887 * drm_atomic_plane_get_property() instead.
889 * This callback is optional if the driver does not support any
890 * driver-private atomic properties.
894 * 0 on success, -EINVAL if the property isn't implemented by the
895 * driver (which should never happen, the core only asks for
896 * properties attached to this plane).
898 int (*atomic_get_property)(struct drm_plane *plane,
899 const struct drm_plane_state *state,
900 struct drm_property *property,
905 * This optional hook can be used to register additional userspace
906 * interfaces attached to the plane like debugfs interfaces.
907 * It is called late in the driver load sequence from drm_dev_register().
908 * Everything added from this callback should be unregistered in
909 * the early_unregister callback.
913 * 0 on success, or a negative error code on failure.
915 int (*late_register)(struct drm_plane *plane);
920 * This optional hook should be used to unregister the additional
921 * userspace interfaces attached to the plane from
922 * late_unregister(). It is called from drm_dev_unregister(),
923 * early in the driver unload sequence to disable userspace access
924 * before data structures are torndown.
926 void (*early_unregister)(struct drm_plane *plane);
929 enum drm_plane_type {
930 DRM_PLANE_TYPE_OVERLAY,
931 DRM_PLANE_TYPE_PRIMARY,
932 DRM_PLANE_TYPE_CURSOR,
937 * struct drm_plane - central DRM plane control structure
938 * @dev: DRM device this plane belongs to
939 * @head: for list management
940 * @name: human readable name, can be overwritten by the driver
941 * @base: base mode object
942 * @possible_crtcs: pipes this plane can be bound to
943 * @format_types: array of formats supported by this plane
944 * @format_count: number of formats supported
945 * @format_default: driver hasn't supplied supported formats for the plane
946 * @crtc: currently bound CRTC
947 * @fb: currently bound fb
948 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
949 * drm_mode_set_config_internal() to implement correct refcounting.
950 * @funcs: helper functions
951 * @properties: property tracking for this plane
952 * @type: type of plane (overlay, primary, cursor)
953 * @state: current atomic state for this plane
954 * @zpos_property: zpos property for this plane
955 * @helper_private: mid-layer private data
958 struct drm_device *dev;
959 struct list_head head;
966 * Protects modeset plane state, together with the mutex of &drm_crtc
967 * this plane is linked to (when active, getting actived or getting
970 struct drm_modeset_lock mutex;
972 struct drm_mode_object base;
974 uint32_t possible_crtcs;
975 uint32_t *format_types;
976 unsigned int format_count;
979 struct drm_crtc *crtc;
980 struct drm_framebuffer *fb;
982 struct drm_framebuffer *old_fb;
984 const struct drm_plane_funcs *funcs;
986 struct drm_object_properties properties;
988 enum drm_plane_type type;
991 * @index: Position inside the mode_config.list, can be used as an array
992 * index. It is invariant over the lifetime of the plane.
996 const struct drm_plane_helper_funcs *helper_private;
998 struct drm_plane_state *state;
1000 struct drm_property *zpos_property;
1004 * struct drm_bridge_funcs - drm_bridge control functions
1006 struct drm_bridge_funcs {
1010 * This callback is invoked whenever our bridge is being attached to a
1013 * The attach callback is optional.
1017 * Zero on success, error code on failure.
1019 int (*attach)(struct drm_bridge *bridge);
1024 * This callback is invoked whenever our bridge is being detached from a
1027 * The detach callback is optional.
1029 void (*detach)(struct drm_bridge *bridge);
1034 * This callback is used to validate and adjust a mode. The paramater
1035 * mode is the display mode that should be fed to the next element in
1036 * the display chain, either the final &drm_connector or the next
1037 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1038 * requires. It can be modified by this callback and does not need to
1041 * This is the only hook that allows a bridge to reject a modeset. If
1042 * this function passes all other callbacks must succeed for this
1045 * The mode_fixup callback is optional.
1049 * This function is called in the check phase of atomic modesets, which
1050 * can be aborted for any reason (including on userspace's request to
1051 * just check whether a configuration would be possible). Drivers MUST
1052 * NOT touch any persistent state (hardware or software) or data
1053 * structures except the passed in @state parameter.
1057 * True if an acceptable configuration is possible, false if the modeset
1058 * operation should be rejected.
1060 bool (*mode_fixup)(struct drm_bridge *bridge,
1061 const struct drm_display_mode *mode,
1062 struct drm_display_mode *adjusted_mode);
1066 * This callback should disable the bridge. It is called right before
1067 * the preceding element in the display pipe is disabled. If the
1068 * preceding element is a bridge this means it's called before that
1069 * bridge's ->disable() function. If the preceding element is a
1070 * &drm_encoder it's called right before the encoder's ->disable(),
1071 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1073 * The bridge can assume that the display pipe (i.e. clocks and timing
1074 * signals) feeding it is still running when this callback is called.
1076 * The disable callback is optional.
1078 void (*disable)(struct drm_bridge *bridge);
1083 * This callback should disable the bridge. It is called right after
1084 * the preceding element in the display pipe is disabled. If the
1085 * preceding element is a bridge this means it's called after that
1086 * bridge's ->post_disable() function. If the preceding element is a
1087 * &drm_encoder it's called right after the encoder's ->disable(),
1088 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1090 * The bridge must assume that the display pipe (i.e. clocks and timing
1091 * singals) feeding it is no longer running when this callback is
1094 * The post_disable callback is optional.
1096 void (*post_disable)(struct drm_bridge *bridge);
1101 * This callback should set the given mode on the bridge. It is called
1102 * after the ->mode_set() callback for the preceding element in the
1103 * display pipeline has been called already. The display pipe (i.e.
1104 * clocks and timing signals) is off when this function is called.
1106 void (*mode_set)(struct drm_bridge *bridge,
1107 struct drm_display_mode *mode,
1108 struct drm_display_mode *adjusted_mode);
1112 * This callback should enable the bridge. It is called right before
1113 * the preceding element in the display pipe is enabled. If the
1114 * preceding element is a bridge this means it's called before that
1115 * bridge's ->pre_enable() function. If the preceding element is a
1116 * &drm_encoder it's called right before the encoder's ->enable(),
1117 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1119 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1120 * will not yet be running when this callback is called. The bridge must
1121 * not enable the display link feeding the next bridge in the chain (if
1122 * there is one) when this callback is called.
1124 * The pre_enable callback is optional.
1126 void (*pre_enable)(struct drm_bridge *bridge);
1131 * This callback should enable the bridge. It is called right after
1132 * the preceding element in the display pipe is enabled. If the
1133 * preceding element is a bridge this means it's called after that
1134 * bridge's ->enable() function. If the preceding element is a
1135 * &drm_encoder it's called right after the encoder's ->enable(),
1136 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1138 * The bridge can assume that the display pipe (i.e. clocks and timing
1139 * signals) feeding it is running when this callback is called. This
1140 * callback must enable the display link feeding the next bridge in the
1141 * chain if there is one.
1143 * The enable callback is optional.
1145 void (*enable)(struct drm_bridge *bridge);
1149 * struct drm_bridge - central DRM bridge control structure
1150 * @dev: DRM device this bridge belongs to
1151 * @encoder: encoder to which this bridge is connected
1152 * @next: the next bridge in the encoder chain
1153 * @of_node: device node pointer to the bridge
1154 * @list: to keep track of all added bridges
1155 * @funcs: control functions
1156 * @driver_private: pointer to the bridge driver's internal context
1159 struct drm_device *dev;
1160 struct drm_encoder *encoder;
1161 struct drm_bridge *next;
1163 struct device_node *of_node;
1165 struct list_head list;
1167 const struct drm_bridge_funcs *funcs;
1168 void *driver_private;
1172 * struct drm_crtc_commit - track modeset commits on a CRTC
1174 * This structure is used to track pending modeset changes and atomic commit on
1175 * a per-CRTC basis. Since updating the list should never block this structure
1176 * is reference counted to allow waiters to safely wait on an event to complete,
1177 * without holding any locks.
1179 * It has 3 different events in total to allow a fine-grained synchronization
1180 * between outstanding updates::
1182 * atomic commit thread hardware
1184 * write new state into hardware ----> ...
1186 * switch to new state on next
1189 * wait for buffers to show up ...
1191 * ... send completion irq
1192 * irq handler signals flip_done
1193 * cleanup old buffers
1195 * signal cleanup_done
1197 * wait for flip_done <----
1198 * clean up atomic state
1200 * The important bit to know is that cleanup_done is the terminal event, but the
1201 * ordering between flip_done and hw_done is entirely up to the specific driver
1202 * and modeset state change.
1204 * For an implementation of how to use this look at
1205 * drm_atomic_helper_setup_commit() from the atomic helper library.
1207 struct drm_crtc_commit {
1211 * DRM CRTC for this commit.
1213 struct drm_crtc *crtc;
1218 * Reference count for this structure. Needed to allow blocking on
1219 * completions without the risk of the completion disappearing
1227 * Will be signaled when the hardware has flipped to the new set of
1228 * buffers. Signals at the same time as when the drm event for this
1229 * commit is sent to userspace, or when an out-fence is singalled. Note
1230 * that for most hardware, in most cases this happens after @hw_done is
1233 struct completion flip_done;
1238 * Will be signalled when all hw register changes for this commit have
1239 * been written out. Especially when disabling a pipe this can be much
1240 * later than than @flip_done, since that can signal already when the
1241 * screen goes black, whereas to fully shut down a pipe more register
1244 * Note that this does not need to include separately reference-counted
1245 * resources like backing storage buffer pinning, or runtime pm
1248 struct completion hw_done;
1253 * Will be signalled after old buffers have been cleaned up by calling
1254 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1255 * a vblank wait completed it might be a bit later. This completion is
1256 * useful to throttle updates and avoid hardware updates getting ahead
1257 * of the buffer cleanup too much.
1259 struct completion cleanup_done;
1264 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1266 struct list_head commit_entry;
1271 * &drm_pending_vblank_event pointer to clean up private events.
1273 struct drm_pending_vblank_event *event;
1276 struct __drm_planes_state {
1277 struct drm_plane *ptr;
1278 struct drm_plane_state *state;
1281 struct __drm_crtcs_state {
1282 struct drm_crtc *ptr;
1283 struct drm_crtc_state *state;
1284 struct drm_crtc_commit *commit;
1287 struct __drm_connnectors_state {
1288 struct drm_connector *ptr;
1289 struct drm_connector_state *state;
1293 * struct drm_atomic_state - the global state object for atomic updates
1294 * @dev: parent DRM device
1295 * @allow_modeset: allow full modeset
1296 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
1297 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
1298 * @planes: pointer to array of structures with per-plane data
1299 * @crtcs: pointer to array of CRTC pointers
1300 * @num_connector: size of the @connectors and @connector_states arrays
1301 * @connectors: pointer to array of structures with per-connector data
1302 * @acquire_ctx: acquire context for this atomic modeset state update
1304 struct drm_atomic_state {
1305 struct drm_device *dev;
1306 bool allow_modeset : 1;
1307 bool legacy_cursor_update : 1;
1308 bool legacy_set_config : 1;
1309 struct __drm_planes_state *planes;
1310 struct __drm_crtcs_state *crtcs;
1312 struct __drm_connnectors_state *connectors;
1314 struct drm_modeset_acquire_ctx *acquire_ctx;
1319 * Work item which can be used by the driver or helpers to execute the
1320 * commit without blocking.
1322 struct work_struct commit_work;
1327 * struct drm_mode_set - new values for a CRTC config change
1328 * @fb: framebuffer to use for new config
1329 * @crtc: CRTC whose configuration we're about to change
1330 * @mode: mode timings to use
1331 * @x: position of this CRTC relative to @fb
1332 * @y: position of this CRTC relative to @fb
1333 * @connectors: array of connectors to drive with this CRTC if possible
1334 * @num_connectors: size of @connectors array
1336 * Represents a single crtc the connectors that it drives with what mode
1337 * and from which framebuffer it scans out from.
1339 * This is used to set modes.
1341 struct drm_mode_set {
1342 struct drm_framebuffer *fb;
1343 struct drm_crtc *crtc;
1344 struct drm_display_mode *mode;
1349 struct drm_connector **connectors;
1350 size_t num_connectors;
1354 * struct drm_mode_config_funcs - basic driver provided mode setting functions
1356 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1359 struct drm_mode_config_funcs {
1363 * Create a new framebuffer object. The core does basic checks on the
1364 * requested metadata, but most of that is left to the driver. See
1365 * struct &drm_mode_fb_cmd2 for details.
1367 * If the parameters are deemed valid and the backing storage objects in
1368 * the underlying memory manager all exist, then the driver allocates
1369 * a new &drm_framebuffer structure, subclassed to contain
1370 * driver-specific information (like the internal native buffer object
1371 * references). It also needs to fill out all relevant metadata, which
1372 * should be done by calling drm_helper_mode_fill_fb_struct().
1374 * The initialization is finalized by calling drm_framebuffer_init(),
1375 * which registers the framebuffer and makes it accessible to other
1380 * A new framebuffer with an initial reference count of 1 or a negative
1381 * error code encoded with ERR_PTR().
1383 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1384 struct drm_file *file_priv,
1385 const struct drm_mode_fb_cmd2 *mode_cmd);
1388 * @output_poll_changed:
1390 * Callback used by helpers to inform the driver of output configuration
1393 * Drivers implementing fbdev emulation with the helpers can call
1394 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1395 * helper of output changes.
1399 * Except that there's no vtable for device-level helper callbacks
1400 * there's no reason this is a core function.
1402 void (*output_poll_changed)(struct drm_device *dev);
1407 * This is the only hook to validate an atomic modeset update. This
1408 * function must reject any modeset and state changes which the hardware
1409 * or driver doesn't support. This includes but is of course not limited
1412 * - Checking that the modes, framebuffers, scaling and placement
1413 * requirements and so on are within the limits of the hardware.
1415 * - Checking that any hidden shared resources are not oversubscribed.
1416 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1417 * display fifo space (where shared between planes or maybe even
1420 * - Checking that virtualized resources exported to userspace are not
1421 * oversubscribed. For various reasons it can make sense to expose
1422 * more planes, crtcs or encoders than which are physically there. One
1423 * example is dual-pipe operations (which generally should be hidden
1424 * from userspace if when lockstepped in hardware, exposed otherwise),
1425 * where a plane might need 1 hardware plane (if it's just on one
1426 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1427 * shared a hardware plane with a 2nd plane (if there's a compatible
1428 * plane requested on the area handled by the other pipe).
1430 * - Check that any transitional state is possible and that if
1431 * requested, the update can indeed be done in the vblank period
1432 * without temporarily disabling some functions.
1434 * - Check any other constraints the driver or hardware might have.
1436 * - This callback also needs to correctly fill out the &drm_crtc_state
1437 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1438 * reflects the nature of the possible update and returns true if and
1439 * only if the update cannot be applied without tearing within one
1440 * vblank on that CRTC. The core uses that information to reject
1441 * updates which require a full modeset (i.e. blanking the screen, or
1442 * at least pausing updates for a substantial amount of time) if
1443 * userspace has disallowed that in its request.
1445 * - The driver also does not need to repeat basic input validation
1446 * like done for the corresponding legacy entry points. The core does
1447 * that before calling this hook.
1449 * See the documentation of @atomic_commit for an exhaustive list of
1450 * error conditions which don't have to be checked at the
1451 * ->atomic_check() stage?
1453 * See the documentation for struct &drm_atomic_state for how exactly
1454 * an atomic modeset update is described.
1456 * Drivers using the atomic helpers can implement this hook using
1457 * drm_atomic_helper_check(), or one of the exported sub-functions of
1462 * 0 on success or one of the below negative error codes:
1464 * - -EINVAL, if any of the above constraints are violated.
1466 * - -EDEADLK, when returned from an attempt to acquire an additional
1467 * &drm_modeset_lock through drm_modeset_lock().
1469 * - -ENOMEM, if allocating additional state sub-structures failed due
1470 * to lack of memory.
1472 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1473 * This can either be due to a pending signal, or because the driver
1474 * needs to completely bail out to recover from an exceptional
1475 * situation like a GPU hang. From a userspace point all errors are
1478 int (*atomic_check)(struct drm_device *dev,
1479 struct drm_atomic_state *state);
1484 * This is the only hook to commit an atomic modeset update. The core
1485 * guarantees that @atomic_check has been called successfully before
1486 * calling this function, and that nothing has been changed in the
1489 * See the documentation for struct &drm_atomic_state for how exactly
1490 * an atomic modeset update is described.
1492 * Drivers using the atomic helpers can implement this hook using
1493 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1496 * Nonblocking commits (as indicated with the nonblock parameter) must
1497 * do any preparatory work which might result in an unsuccessful commit
1498 * in the context of this callback. The only exceptions are hardware
1499 * errors resulting in -EIO. But even in that case the driver must
1500 * ensure that the display pipe is at least running, to avoid
1501 * compositors crashing when pageflips don't work. Anything else,
1502 * specifically committing the update to the hardware, should be done
1503 * without blocking the caller. For updates which do not require a
1504 * modeset this must be guaranteed.
1506 * The driver must wait for any pending rendering to the new
1507 * framebuffers to complete before executing the flip. It should also
1508 * wait for any pending rendering from other drivers if the underlying
1509 * buffer is a shared dma-buf. Nonblocking commits must not wait for
1510 * rendering in the context of this callback.
1512 * An application can request to be notified when the atomic commit has
1513 * completed. These events are per-CRTC and can be distinguished by the
1514 * CRTC index supplied in &drm_event to userspace.
1516 * The drm core will supply a struct &drm_event in the event
1517 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1518 * drm_crtc_send_vblank_event() function, which the driver should call on
1519 * the provided event upon completion of the atomic commit. Note that if
1520 * the driver supports vblank signalling and timestamping the vblank
1521 * counters and timestamps must agree with the ones returned from page
1522 * flip events. With the current vblank helper infrastructure this can
1523 * be achieved by holding a vblank reference while the page flip is
1524 * pending, acquired through drm_crtc_vblank_get() and released with
1525 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1526 * counter and timestamp tracking though, e.g. if they have accurate
1527 * timestamp registers in hardware.
1531 * Drivers are not allowed to shut down any display pipe successfully
1532 * enabled through an atomic commit on their own. Doing so can result in
1533 * compositors crashing if a page flip is suddenly rejected because the
1538 * 0 on success or one of the below negative error codes:
1540 * - -EBUSY, if a nonblocking updated is requested and there is
1541 * an earlier updated pending. Drivers are allowed to support a queue
1542 * of outstanding updates, but currently no driver supports that.
1543 * Note that drivers must wait for preceding updates to complete if a
1544 * synchronous update is requested, they are not allowed to fail the
1545 * commit in that case.
1547 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1548 * this can happen when trying to pin framebuffers, which must only
1549 * be done when committing the state.
1551 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1552 * that the driver has run out of vram, iommu space or similar GPU
1553 * address space needed for framebuffer.
1555 * - -EIO, if the hardware completely died.
1557 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1558 * This can either be due to a pending signal, or because the driver
1559 * needs to completely bail out to recover from an exceptional
1560 * situation like a GPU hang. From a userspace point of view all errors are
1563 * This list is exhaustive. Specifically this hook is not allowed to
1564 * return -EINVAL (any invalid requests should be caught in
1565 * @atomic_check) or -EDEADLK (this function must not acquire
1566 * additional modeset locks).
1568 int (*atomic_commit)(struct drm_device *dev,
1569 struct drm_atomic_state *state,
1573 * @atomic_state_alloc:
1575 * This optional hook can be used by drivers that want to subclass struct
1576 * &drm_atomic_state to be able to track their own driver-private global
1577 * state easily. If this hook is implemented, drivers must also
1578 * implement @atomic_state_clear and @atomic_state_free.
1582 * A new &drm_atomic_state on success or NULL on failure.
1584 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
1587 * @atomic_state_clear:
1589 * This hook must clear any driver private state duplicated into the
1590 * passed-in &drm_atomic_state. This hook is called when the caller
1591 * encountered a &drm_modeset_lock deadlock and needs to drop all
1592 * already acquired locks as part of the deadlock avoidance dance
1593 * implemented in drm_modeset_lock_backoff().
1595 * Any duplicated state must be invalidated since a concurrent atomic
1596 * update might change it, and the drm atomic interfaces always apply
1597 * updates as relative changes to the current state.
1599 * Drivers that implement this must call drm_atomic_state_default_clear()
1600 * to clear common state.
1602 void (*atomic_state_clear)(struct drm_atomic_state *state);
1605 * @atomic_state_free:
1607 * This hook needs driver private resources and the &drm_atomic_state
1608 * itself. Note that the core first calls drm_atomic_state_clear() to
1609 * avoid code duplicate between the clear and free hooks.
1611 * Drivers that implement this must call drm_atomic_state_default_free()
1612 * to release common resources.
1614 void (*atomic_state_free)(struct drm_atomic_state *state);
1618 * struct drm_mode_config - Mode configuration control structure
1619 * @mutex: mutex protecting KMS related lists and structures
1620 * @connection_mutex: ww mutex protecting connector state and routing
1621 * @acquire_ctx: global implicit acquire context used by atomic drivers for
1623 * @fb_lock: mutex to protect fb state and lists
1624 * @num_fb: number of fbs available
1625 * @fb_list: list of framebuffers available
1626 * @num_encoder: number of encoders on this device
1627 * @encoder_list: list of encoder objects
1628 * @num_overlay_plane: number of overlay planes on this device
1629 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1630 * @plane_list: list of plane objects
1631 * @num_crtc: number of CRTCs on this device
1632 * @crtc_list: list of CRTC objects
1633 * @property_list: list of property objects
1634 * @min_width: minimum pixel width on this device
1635 * @min_height: minimum pixel height on this device
1636 * @max_width: maximum pixel width on this device
1637 * @max_height: maximum pixel height on this device
1638 * @funcs: core driver provided mode setting functions
1639 * @fb_base: base address of the framebuffer
1640 * @poll_enabled: track polling support for this device
1641 * @poll_running: track polling status for this device
1642 * @delayed_event: track delayed poll uevent deliver for this device
1643 * @output_poll_work: delayed work for polling in process context
1644 * @property_blob_list: list of all the blob property objects
1645 * @blob_lock: mutex for blob property allocation and management
1646 * @*_property: core property tracking
1647 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1648 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
1649 * @cursor_width: hint to userspace for max cursor width
1650 * @cursor_height: hint to userspace for max cursor height
1651 * @helper_private: mid-layer private data
1653 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1654 * enumerated by the driver are added here, as are global properties. Some
1655 * global restrictions are also here, e.g. dimension restrictions.
1657 struct drm_mode_config {
1658 struct mutex mutex; /* protects configuration (mode lists etc.) */
1659 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1660 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
1665 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1668 struct mutex idr_mutex;
1673 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1674 * connector, modes - just makes life easier to have only one.
1676 struct idr crtc_idr;
1681 * Use this idr for allocating new IDs for tiled sinks like use in some
1682 * high-res DP MST screens.
1684 struct idr tile_idr;
1686 struct mutex fb_lock; /* proctects global and per-file fb lists */
1688 struct list_head fb_list;
1691 * @num_connector: Number of connectors on this device.
1695 * @connector_ida: ID allocator for connector indices.
1697 struct ida connector_ida;
1699 * @connector_list: List of connector objects.
1701 struct list_head connector_list;
1703 struct list_head encoder_list;
1706 * Track # of overlay planes separately from # of total planes. By
1707 * default we only advertise overlay planes to userspace; if userspace
1708 * sets the "universal plane" capability bit, we'll go ahead and
1709 * expose all planes.
1711 int num_overlay_plane;
1712 int num_total_plane;
1713 struct list_head plane_list;
1716 struct list_head crtc_list;
1718 struct list_head property_list;
1720 int min_width, min_height;
1721 int max_width, max_height;
1722 const struct drm_mode_config_funcs *funcs;
1723 resource_size_t fb_base;
1725 /* output poll support */
1729 struct delayed_work output_poll_work;
1731 struct mutex blob_lock;
1733 /* pointers to standard properties */
1734 struct list_head property_blob_list;
1736 * @edid_property: Default connector property to hold the EDID of the
1737 * currently connected sink, if any.
1739 struct drm_property *edid_property;
1741 * @dpms_property: Default connector property to control the
1742 * connector's DPMS state.
1744 struct drm_property *dpms_property;
1746 * @path_property: Default connector property to hold the DP MST path
1749 struct drm_property *path_property;
1751 * @tile_property: Default connector property to store the tile
1752 * position of a tiled screen, for sinks which need to be driven with
1755 struct drm_property *tile_property;
1757 * @plane_type_property: Default plane property to differentiate
1758 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1760 struct drm_property *plane_type_property;
1762 * @rotation_property: Optional property for planes or CRTCs to specifiy
1765 struct drm_property *rotation_property;
1767 * @prop_src_x: Default atomic plane property for the plane source
1768 * position in the connected &drm_framebuffer.
1770 struct drm_property *prop_src_x;
1772 * @prop_src_y: Default atomic plane property for the plane source
1773 * position in the connected &drm_framebuffer.
1775 struct drm_property *prop_src_y;
1777 * @prop_src_w: Default atomic plane property for the plane source
1778 * position in the connected &drm_framebuffer.
1780 struct drm_property *prop_src_w;
1782 * @prop_src_h: Default atomic plane property for the plane source
1783 * position in the connected &drm_framebuffer.
1785 struct drm_property *prop_src_h;
1787 * @prop_crtc_x: Default atomic plane property for the plane destination
1788 * position in the &drm_crtc is is being shown on.
1790 struct drm_property *prop_crtc_x;
1792 * @prop_crtc_y: Default atomic plane property for the plane destination
1793 * position in the &drm_crtc is is being shown on.
1795 struct drm_property *prop_crtc_y;
1797 * @prop_crtc_w: Default atomic plane property for the plane destination
1798 * position in the &drm_crtc is is being shown on.
1800 struct drm_property *prop_crtc_w;
1802 * @prop_crtc_h: Default atomic plane property for the plane destination
1803 * position in the &drm_crtc is is being shown on.
1805 struct drm_property *prop_crtc_h;
1807 * @prop_fb_id: Default atomic plane property to specify the
1810 struct drm_property *prop_fb_id;
1812 * @prop_crtc_id: Default atomic plane property to specify the
1815 struct drm_property *prop_crtc_id;
1817 * @prop_active: Default atomic CRTC property to control the active
1818 * state, which is the simplified implementation for DPMS in atomic
1821 struct drm_property *prop_active;
1823 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1824 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1825 * connectors must be of and active must be set to disabled, too.
1827 struct drm_property *prop_mode_id;
1830 * @dvi_i_subconnector_property: Optional DVI-I property to
1831 * differentiate between analog or digital mode.
1833 struct drm_property *dvi_i_subconnector_property;
1835 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1836 * select between analog or digital mode.
1838 struct drm_property *dvi_i_select_subconnector_property;
1841 * @tv_subconnector_property: Optional TV property to differentiate
1842 * between different TV connector types.
1844 struct drm_property *tv_subconnector_property;
1846 * @tv_select_subconnector_property: Optional TV property to select
1847 * between different TV connector types.
1849 struct drm_property *tv_select_subconnector_property;
1851 * @tv_mode_property: Optional TV property to select
1852 * the output TV mode.
1854 struct drm_property *tv_mode_property;
1856 * @tv_left_margin_property: Optional TV property to set the left
1859 struct drm_property *tv_left_margin_property;
1861 * @tv_right_margin_property: Optional TV property to set the right
1864 struct drm_property *tv_right_margin_property;
1866 * @tv_top_margin_property: Optional TV property to set the right
1869 struct drm_property *tv_top_margin_property;
1871 * @tv_bottom_margin_property: Optional TV property to set the right
1874 struct drm_property *tv_bottom_margin_property;
1876 * @tv_brightness_property: Optional TV property to set the
1879 struct drm_property *tv_brightness_property;
1881 * @tv_contrast_property: Optional TV property to set the
1884 struct drm_property *tv_contrast_property;
1886 * @tv_flicker_reduction_property: Optional TV property to control the
1887 * flicker reduction mode.
1889 struct drm_property *tv_flicker_reduction_property;
1891 * @tv_overscan_property: Optional TV property to control the overscan
1894 struct drm_property *tv_overscan_property;
1896 * @tv_saturation_property: Optional TV property to set the
1899 struct drm_property *tv_saturation_property;
1901 * @tv_hue_property: Optional TV property to set the hue.
1903 struct drm_property *tv_hue_property;
1906 * @scaling_mode_property: Optional connector property to control the
1907 * upscaling, mostly used for built-in panels.
1909 struct drm_property *scaling_mode_property;
1911 * @aspect_ratio_property: Optional connector property to control the
1912 * HDMI infoframe aspect ratio setting.
1914 struct drm_property *aspect_ratio_property;
1916 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1917 * convert the framebuffer's colors to linear gamma.
1919 struct drm_property *degamma_lut_property;
1921 * @degamma_lut_size_property: Optional CRTC property for the size of
1922 * the degamma LUT as supported by the driver (read-only).
1924 struct drm_property *degamma_lut_size_property;
1926 * @ctm_property: Optional CRTC property to set the
1927 * matrix used to convert colors after the lookup in the
1930 struct drm_property *ctm_property;
1932 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1933 * convert the colors, after the CTM matrix, to the gamma space of the
1936 struct drm_property *gamma_lut_property;
1938 * @gamma_lut_size_property: Optional CRTC property for the size of the
1939 * gamma LUT as supported by the driver (read-only).
1941 struct drm_property *gamma_lut_size_property;
1944 * @suggested_x_property: Optional connector property with a hint for
1945 * the position of the output on the host's screen.
1947 struct drm_property *suggested_x_property;
1949 * @suggested_y_property: Optional connector property with a hint for
1950 * the position of the output on the host's screen.
1952 struct drm_property *suggested_y_property;
1954 /* dumb ioctl parameters */
1955 uint32_t preferred_depth, prefer_shadow;
1958 * @async_page_flip: Does this device support async flips on the primary
1961 bool async_page_flip;
1964 * @allow_fb_modifiers:
1966 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1968 bool allow_fb_modifiers;
1971 uint32_t cursor_width, cursor_height;
1973 struct drm_mode_config_helper_funcs *helper_private;
1977 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1978 * @plane: the loop cursor
1979 * @dev: the DRM device
1980 * @plane_mask: bitmask of plane indices
1982 * Iterate over all planes specified by bitmask.
1984 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
1985 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
1986 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
1989 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
1990 * @encoder: the loop cursor
1991 * @dev: the DRM device
1992 * @encoder_mask: bitmask of encoder indices
1994 * Iterate over all encoders specified by bitmask.
1996 #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
1997 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
1998 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
2000 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2001 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2002 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2003 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
2004 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
2006 extern __printf(6, 7)
2007 int drm_crtc_init_with_planes(struct drm_device *dev,
2008 struct drm_crtc *crtc,
2009 struct drm_plane *primary,
2010 struct drm_plane *cursor,
2011 const struct drm_crtc_funcs *funcs,
2012 const char *name, ...);
2013 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
2016 * drm_crtc_index - find the index of a registered CRTC
2017 * @crtc: CRTC to find index for
2019 * Given a registered CRTC, return the index of that CRTC within a DRM
2020 * device's list of CRTCs.
2022 static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2028 * drm_crtc_mask - find the mask of a registered CRTC
2029 * @crtc: CRTC to find mask for
2031 * Given a registered CRTC, return the mask bit of that CRTC for an
2032 * encoder's possible_crtcs field.
2034 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2036 return 1 << drm_crtc_index(crtc);
2039 extern __printf(8, 9)
2040 int drm_universal_plane_init(struct drm_device *dev,
2041 struct drm_plane *plane,
2042 unsigned long possible_crtcs,
2043 const struct drm_plane_funcs *funcs,
2044 const uint32_t *formats,
2045 unsigned int format_count,
2046 enum drm_plane_type type,
2047 const char *name, ...);
2048 extern int drm_plane_init(struct drm_device *dev,
2049 struct drm_plane *plane,
2050 unsigned long possible_crtcs,
2051 const struct drm_plane_funcs *funcs,
2052 const uint32_t *formats, unsigned int format_count,
2054 extern void drm_plane_cleanup(struct drm_plane *plane);
2057 * drm_plane_index - find the index of a registered plane
2058 * @plane: plane to find index for
2060 * Given a registered plane, return the index of that plane within a DRM
2061 * device's list of planes.
2063 static inline unsigned int drm_plane_index(struct drm_plane *plane)
2065 return plane->index;
2067 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
2068 extern void drm_plane_force_disable(struct drm_plane *plane);
2069 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2070 int *hdisplay, int *vdisplay);
2071 extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2072 extern int drm_crtc_force_disable_all(struct drm_device *dev);
2074 extern void drm_mode_config_init(struct drm_device *dev);
2075 extern void drm_mode_config_reset(struct drm_device *dev);
2076 extern void drm_mode_config_cleanup(struct drm_device *dev);
2078 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
2081 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
2083 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2085 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2087 extern void drm_mode_put_tile_group(struct drm_device *dev,
2088 struct drm_tile_group *tg);
2090 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2091 struct drm_property *property,
2094 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2095 unsigned int supported_rotations);
2096 extern unsigned int drm_rotation_simplify(unsigned int rotation,
2097 unsigned int supported_rotations);
2098 extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2099 uint degamma_lut_size,
2101 uint gamma_lut_size);
2103 int drm_plane_create_zpos_property(struct drm_plane *plane,
2105 unsigned int min, unsigned int max);
2107 int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
2111 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2114 struct drm_mode_object *mo;
2115 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2116 return mo ? obj_to_plane(mo) : NULL;
2119 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2122 struct drm_mode_object *mo;
2123 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2124 return mo ? obj_to_crtc(mo) : NULL;
2128 * Extract a degamma/gamma LUT value provided by user and round it to the
2129 * precision supported by the hardware.
2131 static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2132 uint32_t bit_precision)
2134 uint32_t val = user_input;
2135 uint32_t max = 0xffff >> (16 - bit_precision);
2137 /* Round only if we're not using full precision. */
2138 if (bit_precision < 16) {
2139 val += 1UL << (16 - bit_precision - 1);
2140 val >>= 16 - bit_precision;
2143 return clamp_val(val, 0, max);
2146 /* Plane list iterator for legacy (overlay only) planes. */
2147 #define drm_for_each_legacy_plane(plane, dev) \
2148 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
2149 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
2151 #define drm_for_each_plane(plane, dev) \
2152 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2154 #define drm_for_each_crtc(crtc, dev) \
2155 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2158 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2161 * The connector hotadd/remove code currently grabs both locks when
2162 * updating lists. Hence readers need only hold either of them to be
2163 * safe and the check amounts to
2165 * WARN_ON(not_holding(A) && not_holding(B)).
2167 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2168 !drm_modeset_is_locked(&mode_config->connection_mutex));
2171 #define drm_for_each_connector(connector, dev) \
2172 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2173 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2174 struct drm_connector, head); \
2175 &connector->head != (&(dev)->mode_config.connector_list); \
2176 connector = list_next_entry(connector, head))
2178 #define drm_for_each_encoder(encoder, dev) \
2179 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2181 #define drm_for_each_fb(fb, dev) \
2182 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2183 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2184 struct drm_framebuffer, head); \
2185 &fb->head != (&(dev)->mode_config.fb_list); \
2186 fb = list_next_entry(fb, head))
2189 bool drm_probe_ddc(struct i2c_adapter *adapter);
2190 struct edid *drm_get_edid(struct drm_connector *connector,
2191 struct i2c_adapter *adapter);
2192 struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2193 struct i2c_adapter *adapter);
2194 struct edid *drm_edid_duplicate(const struct edid *edid);
2195 int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2197 u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2198 enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2199 bool drm_detect_hdmi_monitor(struct edid *edid);
2200 bool drm_detect_monitor_audio(struct edid *edid);
2201 bool drm_rgb_quant_range_selectable(struct edid *edid);
2202 int drm_add_modes_noedid(struct drm_connector *connector,
2203 int hdisplay, int vdisplay);
2204 void drm_set_preferred_mode(struct drm_connector *connector,
2205 int hpref, int vpref);
2207 int drm_edid_header_is_valid(const u8 *raw_edid);
2208 bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2209 bool *edid_corrupt);
2210 bool drm_edid_is_valid(struct edid *edid);
2211 void drm_edid_get_monitor_name(struct edid *edid, char *name,
2213 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2214 int hsize, int vsize, int fresh,
2218 extern int drm_bridge_add(struct drm_bridge *bridge);
2219 extern void drm_bridge_remove(struct drm_bridge *bridge);
2220 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2221 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
2222 extern void drm_bridge_detach(struct drm_bridge *bridge);
2224 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2225 const struct drm_display_mode *mode,
2226 struct drm_display_mode *adjusted_mode);
2227 void drm_bridge_disable(struct drm_bridge *bridge);
2228 void drm_bridge_post_disable(struct drm_bridge *bridge);
2229 void drm_bridge_mode_set(struct drm_bridge *bridge,
2230 struct drm_display_mode *mode,
2231 struct drm_display_mode *adjusted_mode);
2232 void drm_bridge_pre_enable(struct drm_bridge *bridge);
2233 void drm_bridge_enable(struct drm_bridge *bridge);
2235 #endif /* __DRM_CRTC_H__ */