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>
45 #include <drm/drm_bridge.h>
46 #include <drm/drm_edid.h>
56 static inline int64_t U642I64(uint64_t val
)
58 return (int64_t)*((int64_t *)&val
);
60 static inline uint64_t I642U64(int64_t val
)
62 return (uint64_t)*((uint64_t *)&val
);
66 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
67 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
68 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
70 #define DRM_ROTATE_0 BIT(0)
71 #define DRM_ROTATE_90 BIT(1)
72 #define DRM_ROTATE_180 BIT(2)
73 #define DRM_ROTATE_270 BIT(3)
74 #define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
75 DRM_ROTATE_180 | DRM_ROTATE_270)
76 #define DRM_REFLECT_X BIT(4)
77 #define DRM_REFLECT_Y BIT(5)
78 #define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
80 /* data corresponds to displayid vend/prod/serial */
81 struct drm_tile_group
{
83 struct drm_device
*dev
;
90 struct drm_pending_vblank_event
;
93 struct drm_atomic_state
;
95 struct drm_crtc_helper_funcs
;
96 struct drm_encoder_helper_funcs
;
97 struct drm_plane_helper_funcs
;
100 * struct drm_crtc_state - mutable CRTC state
101 * @crtc: backpointer to the CRTC
102 * @enable: whether the CRTC should be enabled, gates all other state
103 * @active: whether the CRTC is actively displaying (used for DPMS)
104 * @planes_changed: planes on this crtc are updated
105 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
106 * @active_changed: crtc_state->active has been toggled.
107 * @connectors_changed: connectors to this crtc have been updated
108 * @zpos_changed: zpos values of planes on this crtc have been updated
109 * @color_mgmt_changed: color management properties have changed (degamma or
110 * gamma LUT or CSC matrix)
111 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
112 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
113 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
114 * @last_vblank_count: for helpers and drivers to capture the vblank of the
115 * update to ensure framebuffer cleanup isn't done too early
116 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
117 * @mode: current mode timings
118 * @mode_blob: &drm_property_blob for @mode
119 * @degamma_lut: Lookup table for converting framebuffer pixel data
120 * before apply the conversion matrix
121 * @ctm: Transformation matrix
122 * @gamma_lut: Lookup table for converting pixel data after the
124 * @event: optional pointer to a DRM event to signal upon completion of the
126 * @state: backpointer to global drm_atomic_state
128 * Note that the distinction between @enable and @active is rather subtile:
129 * Flipping @active while @enable is set without changing anything else may
130 * never return in a failure from the ->atomic_check callback. Userspace assumes
131 * that a DPMS On will always succeed. In other words: @enable controls resource
132 * assignment, @active controls the actual hardware state.
134 struct drm_crtc_state
{
135 struct drm_crtc
*crtc
;
140 /* computed state bits used by helpers and drivers */
141 bool planes_changed
: 1;
142 bool mode_changed
: 1;
143 bool active_changed
: 1;
144 bool connectors_changed
: 1;
145 bool zpos_changed
: 1;
146 bool color_mgmt_changed
: 1;
148 /* attached planes bitmask:
149 * WARNING: transitional helpers do not maintain plane_mask so
150 * drivers not converted over to atomic helpers should not rely
151 * on plane_mask being accurate!
158 /* last_vblank_count: for vblank waits before cleanup */
159 u32 last_vblank_count
;
161 /* adjusted_mode: for use by helpers and drivers */
162 struct drm_display_mode adjusted_mode
;
164 struct drm_display_mode mode
;
166 /* blob property to expose current mode to atomic userspace */
167 struct drm_property_blob
*mode_blob
;
169 /* blob property to expose color management to userspace */
170 struct drm_property_blob
*degamma_lut
;
171 struct drm_property_blob
*ctm
;
172 struct drm_property_blob
*gamma_lut
;
174 struct drm_pending_vblank_event
*event
;
176 struct drm_atomic_state
*state
;
180 * struct drm_crtc_funcs - control CRTCs for a given device
182 * The drm_crtc_funcs structure is the central CRTC management structure
183 * in the DRM. Each CRTC controls one or more connectors (note that the name
184 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
185 * connectors, not just CRTs).
187 * Each driver is responsible for filling out this structure at startup time,
188 * in addition to providing other modesetting features, like i2c and DDC
191 struct drm_crtc_funcs
{
195 * Reset CRTC hardware and software state to off. This function isn't
196 * called by the core directly, only through drm_mode_config_reset().
197 * It's not a helper hook only for historical reasons.
199 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
200 * atomic state using this hook.
202 void (*reset
)(struct drm_crtc
*crtc
);
207 * Update the cursor image. The cursor position is relative to the CRTC
208 * and can be partially or fully outside of the visible area.
210 * Note that contrary to all other KMS functions the legacy cursor entry
211 * points don't take a framebuffer object, but instead take directly a
212 * raw buffer object id from the driver's buffer manager (which is
213 * either GEM or TTM for current drivers).
215 * This entry point is deprecated, drivers should instead implement
216 * universal plane support and register a proper cursor plane using
217 * drm_crtc_init_with_planes().
219 * This callback is optional
223 * 0 on success or a negative error code on failure.
225 int (*cursor_set
)(struct drm_crtc
*crtc
, struct drm_file
*file_priv
,
226 uint32_t handle
, uint32_t width
, uint32_t height
);
231 * Update the cursor image, including hotspot information. The hotspot
232 * must not affect the cursor position in CRTC coordinates, but is only
233 * meant as a hint for virtualized display hardware to coordinate the
234 * guests and hosts cursor position. The cursor hotspot is relative to
235 * the cursor image. Otherwise this works exactly like @cursor_set.
237 * This entry point is deprecated, drivers should instead implement
238 * universal plane support and register a proper cursor plane using
239 * drm_crtc_init_with_planes().
241 * This callback is optional.
245 * 0 on success or a negative error code on failure.
247 int (*cursor_set2
)(struct drm_crtc
*crtc
, struct drm_file
*file_priv
,
248 uint32_t handle
, uint32_t width
, uint32_t height
,
249 int32_t hot_x
, int32_t hot_y
);
254 * Update the cursor position. The cursor does not need to be visible
255 * when this hook is called.
257 * This entry point is deprecated, drivers should instead implement
258 * universal plane support and register a proper cursor plane using
259 * drm_crtc_init_with_planes().
261 * This callback is optional.
265 * 0 on success or a negative error code on failure.
267 int (*cursor_move
)(struct drm_crtc
*crtc
, int x
, int y
);
272 * Set gamma on the CRTC.
274 * This callback is optional.
278 * Drivers that support gamma tables and also fbdev emulation through
279 * the provided helper library need to take care to fill out the gamma
280 * hooks for both. Currently there's a bit an unfortunate duplication
281 * going on, which should eventually be unified to just one set of
284 int (*gamma_set
)(struct drm_crtc
*crtc
, u16
*r
, u16
*g
, u16
*b
,
290 * Clean up plane resources. This is only called at driver unload time
291 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
294 void (*destroy
)(struct drm_crtc
*crtc
);
299 * This is the main legacy entry point to change the modeset state on a
300 * CRTC. All the details of the desired configuration are passed in a
301 * struct &drm_mode_set - see there for details.
303 * Drivers implementing atomic modeset should use
304 * drm_atomic_helper_set_config() to implement this hook.
308 * 0 on success or a negative error code on failure.
310 int (*set_config
)(struct drm_mode_set
*set
);
315 * Legacy entry point to schedule a flip to the given framebuffer.
317 * Page flipping is a synchronization mechanism that replaces the frame
318 * buffer being scanned out by the CRTC with a new frame buffer during
319 * vertical blanking, avoiding tearing (except when requested otherwise
320 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
321 * requests a page flip the DRM core verifies that the new frame buffer
322 * is large enough to be scanned out by the CRTC in the currently
323 * configured mode and then calls the CRTC ->page_flip() operation with a
324 * pointer to the new frame buffer.
326 * The driver must wait for any pending rendering to the new framebuffer
327 * to complete before executing the flip. It should also wait for any
328 * pending rendering from other drivers if the underlying buffer is a
331 * An application can request to be notified when the page flip has
332 * completed. The drm core will supply a struct &drm_event in the event
333 * parameter in this case. This can be handled by the
334 * drm_crtc_send_vblank_event() function, which the driver should call on
335 * the provided event upon completion of the flip. Note that if
336 * the driver supports vblank signalling and timestamping the vblank
337 * counters and timestamps must agree with the ones returned from page
338 * flip events. With the current vblank helper infrastructure this can
339 * be achieved by holding a vblank reference while the page flip is
340 * pending, acquired through drm_crtc_vblank_get() and released with
341 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
342 * counter and timestamp tracking though, e.g. if they have accurate
343 * timestamp registers in hardware.
345 * This callback is optional.
349 * Very early versions of the KMS ABI mandated that the driver must
350 * block (but not reject) any rendering to the old framebuffer until the
351 * flip operation has completed and the old framebuffer is no longer
352 * visible. This requirement has been lifted, and userspace is instead
353 * expected to request delivery of an event and wait with recycling old
354 * buffers until such has been received.
358 * 0 on success or a negative error code on failure. Note that if a
359 * ->page_flip() operation is already pending the callback should return
360 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
361 * or just runtime disabled through DPMS respectively the new atomic
362 * "ACTIVE" state) should result in an -EINVAL error code. Note that
363 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
365 int (*page_flip
)(struct drm_crtc
*crtc
,
366 struct drm_framebuffer
*fb
,
367 struct drm_pending_vblank_event
*event
,
373 * Same as @page_flip but with an additional parameter specifying the
374 * absolute target vertical blank period (as reported by
375 * drm_crtc_vblank_count()) when the flip should take effect.
377 * Note that the core code calls drm_crtc_vblank_get before this entry
378 * point, and will call drm_crtc_vblank_put if this entry point returns
379 * any non-0 error code. It's the driver's responsibility to call
380 * drm_crtc_vblank_put after this entry point returns 0, typically when
381 * the flip completes.
383 int (*page_flip_target
)(struct drm_crtc
*crtc
,
384 struct drm_framebuffer
*fb
,
385 struct drm_pending_vblank_event
*event
,
386 uint32_t flags
, uint32_t target
);
391 * This is the legacy entry point to update a property attached to the
394 * Drivers implementing atomic modeset should use
395 * drm_atomic_helper_crtc_set_property() to implement this hook.
397 * This callback is optional if the driver does not support any legacy
398 * driver-private properties.
402 * 0 on success or a negative error code on failure.
404 int (*set_property
)(struct drm_crtc
*crtc
,
405 struct drm_property
*property
, uint64_t val
);
408 * @atomic_duplicate_state:
410 * Duplicate the current atomic state for this CRTC and return it.
411 * The core and helpers gurantee that any atomic state duplicated with
412 * this hook and still owned by the caller (i.e. not transferred to the
413 * driver by calling ->atomic_commit() from struct
414 * &drm_mode_config_funcs) will be cleaned up by calling the
415 * @atomic_destroy_state hook in this structure.
417 * Atomic drivers which don't subclass struct &drm_crtc should use
418 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
419 * state structure to extend it with driver-private state should use
420 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
421 * duplicated in a consistent fashion across drivers.
423 * It is an error to call this hook before crtc->state has been
424 * initialized correctly.
428 * If the duplicate state references refcounted resources this hook must
429 * acquire a reference for each of them. The driver must release these
430 * references again in @atomic_destroy_state.
434 * Duplicated atomic state or NULL when the allocation failed.
436 struct drm_crtc_state
*(*atomic_duplicate_state
)(struct drm_crtc
*crtc
);
439 * @atomic_destroy_state:
441 * Destroy a state duplicated with @atomic_duplicate_state and release
442 * or unreference all resources it references
444 void (*atomic_destroy_state
)(struct drm_crtc
*crtc
,
445 struct drm_crtc_state
*state
);
448 * @atomic_set_property:
450 * Decode a driver-private property value and store the decoded value
451 * into the passed-in state structure. Since the atomic core decodes all
452 * standardized properties (even for extensions beyond the core set of
453 * properties which might not be implemented by all drivers) this
454 * requires drivers to subclass the state structure.
456 * Such driver-private properties should really only be implemented for
457 * truly hardware/vendor specific state. Instead it is preferred to
458 * standardize atomic extension and decode the properties used to expose
459 * such an extension in the core.
461 * Do not call this function directly, use
462 * drm_atomic_crtc_set_property() instead.
464 * This callback is optional if the driver does not support any
465 * driver-private atomic properties.
469 * This function is called in the state assembly phase of atomic
470 * modesets, which can be aborted for any reason (including on
471 * userspace's request to just check whether a configuration would be
472 * possible). Drivers MUST NOT touch any persistent state (hardware or
473 * software) or data structures except the passed in @state parameter.
475 * Also since userspace controls in which order properties are set this
476 * function must not do any input validation (since the state update is
477 * incomplete and hence likely inconsistent). Instead any such input
478 * validation must be done in the various atomic_check callbacks.
482 * 0 if the property has been found, -EINVAL if the property isn't
483 * implemented by the driver (which should never happen, the core only
484 * asks for properties attached to this CRTC). No other validation is
485 * allowed by the driver. The core already checks that the property
486 * value is within the range (integer, valid enum value, ...) the driver
487 * set when registering the property.
489 int (*atomic_set_property
)(struct drm_crtc
*crtc
,
490 struct drm_crtc_state
*state
,
491 struct drm_property
*property
,
494 * @atomic_get_property:
496 * Reads out the decoded driver-private property. This is used to
497 * implement the GETCRTC IOCTL.
499 * Do not call this function directly, use
500 * drm_atomic_crtc_get_property() instead.
502 * This callback is optional if the driver does not support any
503 * driver-private atomic properties.
507 * 0 on success, -EINVAL if the property isn't implemented by the
508 * driver (which should never happen, the core only asks for
509 * properties attached to this CRTC).
511 int (*atomic_get_property
)(struct drm_crtc
*crtc
,
512 const struct drm_crtc_state
*state
,
513 struct drm_property
*property
,
519 * This optional hook can be used to register additional userspace
520 * interfaces attached to the crtc like debugfs interfaces.
521 * It is called late in the driver load sequence from drm_dev_register().
522 * Everything added from this callback should be unregistered in
523 * the early_unregister callback.
527 * 0 on success, or a negative error code on failure.
529 int (*late_register
)(struct drm_crtc
*crtc
);
534 * This optional hook should be used to unregister the additional
535 * userspace interfaces attached to the crtc from
536 * late_unregister(). It is called from drm_dev_unregister(),
537 * early in the driver unload sequence to disable userspace access
538 * before data structures are torndown.
540 void (*early_unregister
)(struct drm_crtc
*crtc
);
544 * struct drm_crtc - central CRTC control structure
545 * @dev: parent DRM device
546 * @port: OF node used by drm_of_find_possible_crtcs()
547 * @head: list management
548 * @name: human readable name, can be overwritten by the driver
549 * @mutex: per-CRTC locking
550 * @base: base KMS object for ID tracking etc.
551 * @primary: primary plane for this CRTC
552 * @cursor: cursor plane for this CRTC
553 * @cursor_x: current x position of the cursor, used for universal cursor planes
554 * @cursor_y: current y position of the cursor, used for universal cursor planes
555 * @enabled: is this CRTC enabled?
556 * @mode: current mode timings
557 * @hwmode: mode timings as programmed to hw regs
558 * @x: x position on screen
559 * @y: y position on screen
560 * @funcs: CRTC control functions
561 * @gamma_size: size of gamma ramp
562 * @gamma_store: gamma ramp values
563 * @helper_private: mid-layer private data
564 * @properties: property tracking for this CRTC
566 * Each CRTC may have one or more connectors associated with it. This structure
567 * allows the CRTC to be controlled.
570 struct drm_device
*dev
;
571 struct device_node
*port
;
572 struct list_head head
;
579 * This provides a read lock for the overall crtc state (mode, dpms
580 * state, ...) and a write lock for everything which can be update
581 * without a full modeset (fb, cursor data, crtc properties ...). Full
582 * modeset also need to grab dev->mode_config.connection_mutex.
584 struct drm_modeset_lock mutex
;
586 struct drm_mode_object base
;
588 /* primary and cursor planes for CRTC */
589 struct drm_plane
*primary
;
590 struct drm_plane
*cursor
;
593 * @index: Position inside the mode_config.list, can be used as an array
594 * index. It is invariant over the lifetime of the CRTC.
598 /* position of cursor plane on crtc */
604 /* Requested mode from modesetting. */
605 struct drm_display_mode mode
;
607 /* Programmed mode in hw, after adjustments for encoders,
608 * crtc, panel scaling etc. Needed for timestamping etc.
610 struct drm_display_mode hwmode
;
613 const struct drm_crtc_funcs
*funcs
;
615 /* Legacy FB CRTC gamma size for reporting to userspace */
617 uint16_t *gamma_store
;
619 /* if you are using the helper */
620 const struct drm_crtc_helper_funcs
*helper_private
;
622 struct drm_object_properties properties
;
627 * Current atomic state for this CRTC.
629 struct drm_crtc_state
*state
;
634 * List of &drm_crtc_commit structures tracking pending commits.
635 * Protected by @commit_lock. This list doesn't hold its own full
636 * reference, but burrows it from the ongoing commit. Commit entries
637 * must be removed from this list once the commit is fully completed,
638 * but before it's correspoding &drm_atomic_state gets destroyed.
640 struct list_head commit_list
;
645 * Spinlock to protect @commit_list.
647 spinlock_t commit_lock
;
652 * Per-CRTC implicit acquire context used by atomic drivers for legacy
653 * IOCTLs, so that atomic drivers can get at the locking acquire
656 struct drm_modeset_acquire_ctx
*acquire_ctx
;
660 * struct drm_plane_state - mutable plane state
661 * @plane: backpointer to the plane
662 * @crtc: currently bound CRTC, NULL if disabled
663 * @fb: currently bound framebuffer
664 * @fence: optional fence to wait for before scanning out @fb
665 * @crtc_x: left position of visible portion of plane on crtc
666 * @crtc_y: upper position of visible portion of plane on crtc
667 * @crtc_w: width of visible portion of plane on crtc
668 * @crtc_h: height of visible portion of plane on crtc
669 * @src_x: left position of visible portion of plane within
671 * @src_y: upper position of visible portion of plane within
673 * @src_w: width of visible portion of plane (in 16.16)
674 * @src_h: height of visible portion of plane (in 16.16)
675 * @rotation: rotation of the plane
676 * @zpos: priority of the given plane on crtc (optional)
677 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
678 * where N is the number of active planes for given crtc
679 * @src: clipped source coordinates of the plane (in 16.16)
680 * @dst: clipped destination coordinates of the plane
681 * @visible: visibility of the plane
682 * @state: backpointer to global drm_atomic_state
684 struct drm_plane_state
{
685 struct drm_plane
*plane
;
687 struct drm_crtc
*crtc
; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
688 struct drm_framebuffer
*fb
; /* do not write directly, use drm_atomic_set_fb_for_plane() */
691 /* Signed dest location allows it to be partially off screen */
692 int32_t crtc_x
, crtc_y
;
693 uint32_t crtc_w
, crtc_h
;
695 /* Source values are 16.16 fixed point */
696 uint32_t src_x
, src_y
;
697 uint32_t src_h
, src_w
;
700 unsigned int rotation
;
704 unsigned int normalized_zpos
;
706 /* Clipped coordinates */
707 struct drm_rect src
, dst
;
710 * Is the plane actually visible? Can be false even
711 * if fb!=NULL and crtc!=NULL, due to clipping.
715 struct drm_atomic_state
*state
;
720 * struct drm_plane_funcs - driver plane control functions
722 struct drm_plane_funcs
{
726 * This is the legacy entry point to enable and configure the plane for
727 * the given CRTC and framebuffer. It is never called to disable the
728 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
730 * The source rectangle in frame buffer memory coordinates is given by
731 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
732 * values). Devices that don't support subpixel plane coordinates can
733 * ignore the fractional part.
735 * The destination rectangle in CRTC coordinates is given by the
736 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
737 * Devices scale the source rectangle to the destination rectangle. If
738 * scaling is not supported, and the source rectangle size doesn't match
739 * the destination rectangle size, the driver must return a
740 * -<errorname>EINVAL</errorname> error.
742 * Drivers implementing atomic modeset should use
743 * drm_atomic_helper_update_plane() to implement this hook.
747 * 0 on success or a negative error code on failure.
749 int (*update_plane
)(struct drm_plane
*plane
,
750 struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
751 int crtc_x
, int crtc_y
,
752 unsigned int crtc_w
, unsigned int crtc_h
,
753 uint32_t src_x
, uint32_t src_y
,
754 uint32_t src_w
, uint32_t src_h
);
759 * This is the legacy entry point to disable the plane. The DRM core
760 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
761 * with the frame buffer ID set to 0. Disabled planes must not be
762 * processed by the CRTC.
764 * Drivers implementing atomic modeset should use
765 * drm_atomic_helper_disable_plane() to implement this hook.
769 * 0 on success or a negative error code on failure.
771 int (*disable_plane
)(struct drm_plane
*plane
);
776 * Clean up plane resources. This is only called at driver unload time
777 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
780 void (*destroy
)(struct drm_plane
*plane
);
785 * Reset plane hardware and software state to off. This function isn't
786 * called by the core directly, only through drm_mode_config_reset().
787 * It's not a helper hook only for historical reasons.
789 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
790 * atomic state using this hook.
792 void (*reset
)(struct drm_plane
*plane
);
797 * This is the legacy entry point to update a property attached to the
800 * Drivers implementing atomic modeset should use
801 * drm_atomic_helper_plane_set_property() to implement this hook.
803 * This callback is optional if the driver does not support any legacy
804 * driver-private properties.
808 * 0 on success or a negative error code on failure.
810 int (*set_property
)(struct drm_plane
*plane
,
811 struct drm_property
*property
, uint64_t val
);
814 * @atomic_duplicate_state:
816 * Duplicate the current atomic state for this plane and return it.
817 * The core and helpers gurantee that any atomic state duplicated with
818 * this hook and still owned by the caller (i.e. not transferred to the
819 * driver by calling ->atomic_commit() from struct
820 * &drm_mode_config_funcs) will be cleaned up by calling the
821 * @atomic_destroy_state hook in this structure.
823 * Atomic drivers which don't subclass struct &drm_plane_state should use
824 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
825 * state structure to extend it with driver-private state should use
826 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
827 * duplicated in a consistent fashion across drivers.
829 * It is an error to call this hook before plane->state has been
830 * initialized correctly.
834 * If the duplicate state references refcounted resources this hook must
835 * acquire a reference for each of them. The driver must release these
836 * references again in @atomic_destroy_state.
840 * Duplicated atomic state or NULL when the allocation failed.
842 struct drm_plane_state
*(*atomic_duplicate_state
)(struct drm_plane
*plane
);
845 * @atomic_destroy_state:
847 * Destroy a state duplicated with @atomic_duplicate_state and release
848 * or unreference all resources it references
850 void (*atomic_destroy_state
)(struct drm_plane
*plane
,
851 struct drm_plane_state
*state
);
854 * @atomic_set_property:
856 * Decode a driver-private property value and store the decoded value
857 * into the passed-in state structure. Since the atomic core decodes all
858 * standardized properties (even for extensions beyond the core set of
859 * properties which might not be implemented by all drivers) this
860 * requires drivers to subclass the state structure.
862 * Such driver-private properties should really only be implemented for
863 * truly hardware/vendor specific state. Instead it is preferred to
864 * standardize atomic extension and decode the properties used to expose
865 * such an extension in the core.
867 * Do not call this function directly, use
868 * drm_atomic_plane_set_property() instead.
870 * This callback is optional if the driver does not support any
871 * driver-private atomic properties.
875 * This function is called in the state assembly phase of atomic
876 * modesets, which can be aborted for any reason (including on
877 * userspace's request to just check whether a configuration would be
878 * possible). Drivers MUST NOT touch any persistent state (hardware or
879 * software) or data structures except the passed in @state parameter.
881 * Also since userspace controls in which order properties are set this
882 * function must not do any input validation (since the state update is
883 * incomplete and hence likely inconsistent). Instead any such input
884 * validation must be done in the various atomic_check callbacks.
888 * 0 if the property has been found, -EINVAL if the property isn't
889 * implemented by the driver (which shouldn't ever happen, the core only
890 * asks for properties attached to this plane). No other validation is
891 * allowed by the driver. The core already checks that the property
892 * value is within the range (integer, valid enum value, ...) the driver
893 * set when registering the property.
895 int (*atomic_set_property
)(struct drm_plane
*plane
,
896 struct drm_plane_state
*state
,
897 struct drm_property
*property
,
901 * @atomic_get_property:
903 * Reads out the decoded driver-private property. This is used to
904 * implement the GETPLANE IOCTL.
906 * Do not call this function directly, use
907 * drm_atomic_plane_get_property() instead.
909 * This callback is optional if the driver does not support any
910 * driver-private atomic properties.
914 * 0 on success, -EINVAL if the property isn't implemented by the
915 * driver (which should never happen, the core only asks for
916 * properties attached to this plane).
918 int (*atomic_get_property
)(struct drm_plane
*plane
,
919 const struct drm_plane_state
*state
,
920 struct drm_property
*property
,
925 * This optional hook can be used to register additional userspace
926 * interfaces attached to the plane like debugfs interfaces.
927 * It is called late in the driver load sequence from drm_dev_register().
928 * Everything added from this callback should be unregistered in
929 * the early_unregister callback.
933 * 0 on success, or a negative error code on failure.
935 int (*late_register
)(struct drm_plane
*plane
);
940 * This optional hook should be used to unregister the additional
941 * userspace interfaces attached to the plane from
942 * late_unregister(). It is called from drm_dev_unregister(),
943 * early in the driver unload sequence to disable userspace access
944 * before data structures are torndown.
946 void (*early_unregister
)(struct drm_plane
*plane
);
949 enum drm_plane_type
{
950 DRM_PLANE_TYPE_OVERLAY
,
951 DRM_PLANE_TYPE_PRIMARY
,
952 DRM_PLANE_TYPE_CURSOR
,
957 * struct drm_plane - central DRM plane control structure
958 * @dev: DRM device this plane belongs to
959 * @head: for list management
960 * @name: human readable name, can be overwritten by the driver
961 * @base: base mode object
962 * @possible_crtcs: pipes this plane can be bound to
963 * @format_types: array of formats supported by this plane
964 * @format_count: number of formats supported
965 * @format_default: driver hasn't supplied supported formats for the plane
966 * @crtc: currently bound CRTC
967 * @fb: currently bound fb
968 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
969 * drm_mode_set_config_internal() to implement correct refcounting.
970 * @funcs: helper functions
971 * @properties: property tracking for this plane
972 * @type: type of plane (overlay, primary, cursor)
973 * @state: current atomic state for this plane
974 * @zpos_property: zpos property for this plane
975 * @helper_private: mid-layer private data
978 struct drm_device
*dev
;
979 struct list_head head
;
986 * Protects modeset plane state, together with the mutex of &drm_crtc
987 * this plane is linked to (when active, getting actived or getting
990 struct drm_modeset_lock mutex
;
992 struct drm_mode_object base
;
994 uint32_t possible_crtcs
;
995 uint32_t *format_types
;
996 unsigned int format_count
;
999 struct drm_crtc
*crtc
;
1000 struct drm_framebuffer
*fb
;
1002 struct drm_framebuffer
*old_fb
;
1004 const struct drm_plane_funcs
*funcs
;
1006 struct drm_object_properties properties
;
1008 enum drm_plane_type type
;
1011 * @index: Position inside the mode_config.list, can be used as an array
1012 * index. It is invariant over the lifetime of the plane.
1016 const struct drm_plane_helper_funcs
*helper_private
;
1018 struct drm_plane_state
*state
;
1020 struct drm_property
*zpos_property
;
1024 * struct drm_crtc_commit - track modeset commits on a CRTC
1026 * This structure is used to track pending modeset changes and atomic commit on
1027 * a per-CRTC basis. Since updating the list should never block this structure
1028 * is reference counted to allow waiters to safely wait on an event to complete,
1029 * without holding any locks.
1031 * It has 3 different events in total to allow a fine-grained synchronization
1032 * between outstanding updates::
1034 * atomic commit thread hardware
1036 * write new state into hardware ----> ...
1038 * switch to new state on next
1041 * wait for buffers to show up ...
1043 * ... send completion irq
1044 * irq handler signals flip_done
1045 * cleanup old buffers
1047 * signal cleanup_done
1049 * wait for flip_done <----
1050 * clean up atomic state
1052 * The important bit to know is that cleanup_done is the terminal event, but the
1053 * ordering between flip_done and hw_done is entirely up to the specific driver
1054 * and modeset state change.
1056 * For an implementation of how to use this look at
1057 * drm_atomic_helper_setup_commit() from the atomic helper library.
1059 struct drm_crtc_commit
{
1063 * DRM CRTC for this commit.
1065 struct drm_crtc
*crtc
;
1070 * Reference count for this structure. Needed to allow blocking on
1071 * completions without the risk of the completion disappearing
1079 * Will be signaled when the hardware has flipped to the new set of
1080 * buffers. Signals at the same time as when the drm event for this
1081 * commit is sent to userspace, or when an out-fence is singalled. Note
1082 * that for most hardware, in most cases this happens after @hw_done is
1085 struct completion flip_done
;
1090 * Will be signalled when all hw register changes for this commit have
1091 * been written out. Especially when disabling a pipe this can be much
1092 * later than than @flip_done, since that can signal already when the
1093 * screen goes black, whereas to fully shut down a pipe more register
1096 * Note that this does not need to include separately reference-counted
1097 * resources like backing storage buffer pinning, or runtime pm
1100 struct completion hw_done
;
1105 * Will be signalled after old buffers have been cleaned up by calling
1106 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1107 * a vblank wait completed it might be a bit later. This completion is
1108 * useful to throttle updates and avoid hardware updates getting ahead
1109 * of the buffer cleanup too much.
1111 struct completion cleanup_done
;
1116 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1118 struct list_head commit_entry
;
1123 * &drm_pending_vblank_event pointer to clean up private events.
1125 struct drm_pending_vblank_event
*event
;
1128 struct __drm_planes_state
{
1129 struct drm_plane
*ptr
;
1130 struct drm_plane_state
*state
;
1133 struct __drm_crtcs_state
{
1134 struct drm_crtc
*ptr
;
1135 struct drm_crtc_state
*state
;
1136 struct drm_crtc_commit
*commit
;
1139 struct __drm_connnectors_state
{
1140 struct drm_connector
*ptr
;
1141 struct drm_connector_state
*state
;
1145 * struct drm_atomic_state - the global state object for atomic updates
1146 * @dev: parent DRM device
1147 * @allow_modeset: allow full modeset
1148 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
1149 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
1150 * @planes: pointer to array of structures with per-plane data
1151 * @crtcs: pointer to array of CRTC pointers
1152 * @num_connector: size of the @connectors and @connector_states arrays
1153 * @connectors: pointer to array of structures with per-connector data
1154 * @acquire_ctx: acquire context for this atomic modeset state update
1156 struct drm_atomic_state
{
1157 struct drm_device
*dev
;
1158 bool allow_modeset
: 1;
1159 bool legacy_cursor_update
: 1;
1160 bool legacy_set_config
: 1;
1161 struct __drm_planes_state
*planes
;
1162 struct __drm_crtcs_state
*crtcs
;
1164 struct __drm_connnectors_state
*connectors
;
1166 struct drm_modeset_acquire_ctx
*acquire_ctx
;
1171 * Work item which can be used by the driver or helpers to execute the
1172 * commit without blocking.
1174 struct work_struct commit_work
;
1179 * struct drm_mode_set - new values for a CRTC config change
1180 * @fb: framebuffer to use for new config
1181 * @crtc: CRTC whose configuration we're about to change
1182 * @mode: mode timings to use
1183 * @x: position of this CRTC relative to @fb
1184 * @y: position of this CRTC relative to @fb
1185 * @connectors: array of connectors to drive with this CRTC if possible
1186 * @num_connectors: size of @connectors array
1188 * Represents a single crtc the connectors that it drives with what mode
1189 * and from which framebuffer it scans out from.
1191 * This is used to set modes.
1193 struct drm_mode_set
{
1194 struct drm_framebuffer
*fb
;
1195 struct drm_crtc
*crtc
;
1196 struct drm_display_mode
*mode
;
1201 struct drm_connector
**connectors
;
1202 size_t num_connectors
;
1206 * struct drm_mode_config_funcs - basic driver provided mode setting functions
1208 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1211 struct drm_mode_config_funcs
{
1215 * Create a new framebuffer object. The core does basic checks on the
1216 * requested metadata, but most of that is left to the driver. See
1217 * struct &drm_mode_fb_cmd2 for details.
1219 * If the parameters are deemed valid and the backing storage objects in
1220 * the underlying memory manager all exist, then the driver allocates
1221 * a new &drm_framebuffer structure, subclassed to contain
1222 * driver-specific information (like the internal native buffer object
1223 * references). It also needs to fill out all relevant metadata, which
1224 * should be done by calling drm_helper_mode_fill_fb_struct().
1226 * The initialization is finalized by calling drm_framebuffer_init(),
1227 * which registers the framebuffer and makes it accessible to other
1232 * A new framebuffer with an initial reference count of 1 or a negative
1233 * error code encoded with ERR_PTR().
1235 struct drm_framebuffer
*(*fb_create
)(struct drm_device
*dev
,
1236 struct drm_file
*file_priv
,
1237 const struct drm_mode_fb_cmd2
*mode_cmd
);
1240 * @output_poll_changed:
1242 * Callback used by helpers to inform the driver of output configuration
1245 * Drivers implementing fbdev emulation with the helpers can call
1246 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1247 * helper of output changes.
1251 * Except that there's no vtable for device-level helper callbacks
1252 * there's no reason this is a core function.
1254 void (*output_poll_changed
)(struct drm_device
*dev
);
1259 * This is the only hook to validate an atomic modeset update. This
1260 * function must reject any modeset and state changes which the hardware
1261 * or driver doesn't support. This includes but is of course not limited
1264 * - Checking that the modes, framebuffers, scaling and placement
1265 * requirements and so on are within the limits of the hardware.
1267 * - Checking that any hidden shared resources are not oversubscribed.
1268 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1269 * display fifo space (where shared between planes or maybe even
1272 * - Checking that virtualized resources exported to userspace are not
1273 * oversubscribed. For various reasons it can make sense to expose
1274 * more planes, crtcs or encoders than which are physically there. One
1275 * example is dual-pipe operations (which generally should be hidden
1276 * from userspace if when lockstepped in hardware, exposed otherwise),
1277 * where a plane might need 1 hardware plane (if it's just on one
1278 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1279 * shared a hardware plane with a 2nd plane (if there's a compatible
1280 * plane requested on the area handled by the other pipe).
1282 * - Check that any transitional state is possible and that if
1283 * requested, the update can indeed be done in the vblank period
1284 * without temporarily disabling some functions.
1286 * - Check any other constraints the driver or hardware might have.
1288 * - This callback also needs to correctly fill out the &drm_crtc_state
1289 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1290 * reflects the nature of the possible update and returns true if and
1291 * only if the update cannot be applied without tearing within one
1292 * vblank on that CRTC. The core uses that information to reject
1293 * updates which require a full modeset (i.e. blanking the screen, or
1294 * at least pausing updates for a substantial amount of time) if
1295 * userspace has disallowed that in its request.
1297 * - The driver also does not need to repeat basic input validation
1298 * like done for the corresponding legacy entry points. The core does
1299 * that before calling this hook.
1301 * See the documentation of @atomic_commit for an exhaustive list of
1302 * error conditions which don't have to be checked at the
1303 * ->atomic_check() stage?
1305 * See the documentation for struct &drm_atomic_state for how exactly
1306 * an atomic modeset update is described.
1308 * Drivers using the atomic helpers can implement this hook using
1309 * drm_atomic_helper_check(), or one of the exported sub-functions of
1314 * 0 on success or one of the below negative error codes:
1316 * - -EINVAL, if any of the above constraints are violated.
1318 * - -EDEADLK, when returned from an attempt to acquire an additional
1319 * &drm_modeset_lock through drm_modeset_lock().
1321 * - -ENOMEM, if allocating additional state sub-structures failed due
1322 * to lack of memory.
1324 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1325 * This can either be due to a pending signal, or because the driver
1326 * needs to completely bail out to recover from an exceptional
1327 * situation like a GPU hang. From a userspace point all errors are
1330 int (*atomic_check
)(struct drm_device
*dev
,
1331 struct drm_atomic_state
*state
);
1336 * This is the only hook to commit an atomic modeset update. The core
1337 * guarantees that @atomic_check has been called successfully before
1338 * calling this function, and that nothing has been changed in the
1341 * See the documentation for struct &drm_atomic_state for how exactly
1342 * an atomic modeset update is described.
1344 * Drivers using the atomic helpers can implement this hook using
1345 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1348 * Nonblocking commits (as indicated with the nonblock parameter) must
1349 * do any preparatory work which might result in an unsuccessful commit
1350 * in the context of this callback. The only exceptions are hardware
1351 * errors resulting in -EIO. But even in that case the driver must
1352 * ensure that the display pipe is at least running, to avoid
1353 * compositors crashing when pageflips don't work. Anything else,
1354 * specifically committing the update to the hardware, should be done
1355 * without blocking the caller. For updates which do not require a
1356 * modeset this must be guaranteed.
1358 * The driver must wait for any pending rendering to the new
1359 * framebuffers to complete before executing the flip. It should also
1360 * wait for any pending rendering from other drivers if the underlying
1361 * buffer is a shared dma-buf. Nonblocking commits must not wait for
1362 * rendering in the context of this callback.
1364 * An application can request to be notified when the atomic commit has
1365 * completed. These events are per-CRTC and can be distinguished by the
1366 * CRTC index supplied in &drm_event to userspace.
1368 * The drm core will supply a struct &drm_event in the event
1369 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1370 * drm_crtc_send_vblank_event() function, which the driver should call on
1371 * the provided event upon completion of the atomic commit. Note that if
1372 * the driver supports vblank signalling and timestamping the vblank
1373 * counters and timestamps must agree with the ones returned from page
1374 * flip events. With the current vblank helper infrastructure this can
1375 * be achieved by holding a vblank reference while the page flip is
1376 * pending, acquired through drm_crtc_vblank_get() and released with
1377 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1378 * counter and timestamp tracking though, e.g. if they have accurate
1379 * timestamp registers in hardware.
1383 * Drivers are not allowed to shut down any display pipe successfully
1384 * enabled through an atomic commit on their own. Doing so can result in
1385 * compositors crashing if a page flip is suddenly rejected because the
1390 * 0 on success or one of the below negative error codes:
1392 * - -EBUSY, if a nonblocking updated is requested and there is
1393 * an earlier updated pending. Drivers are allowed to support a queue
1394 * of outstanding updates, but currently no driver supports that.
1395 * Note that drivers must wait for preceding updates to complete if a
1396 * synchronous update is requested, they are not allowed to fail the
1397 * commit in that case.
1399 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1400 * this can happen when trying to pin framebuffers, which must only
1401 * be done when committing the state.
1403 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1404 * that the driver has run out of vram, iommu space or similar GPU
1405 * address space needed for framebuffer.
1407 * - -EIO, if the hardware completely died.
1409 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1410 * This can either be due to a pending signal, or because the driver
1411 * needs to completely bail out to recover from an exceptional
1412 * situation like a GPU hang. From a userspace point of view all errors are
1415 * This list is exhaustive. Specifically this hook is not allowed to
1416 * return -EINVAL (any invalid requests should be caught in
1417 * @atomic_check) or -EDEADLK (this function must not acquire
1418 * additional modeset locks).
1420 int (*atomic_commit
)(struct drm_device
*dev
,
1421 struct drm_atomic_state
*state
,
1425 * @atomic_state_alloc:
1427 * This optional hook can be used by drivers that want to subclass struct
1428 * &drm_atomic_state to be able to track their own driver-private global
1429 * state easily. If this hook is implemented, drivers must also
1430 * implement @atomic_state_clear and @atomic_state_free.
1434 * A new &drm_atomic_state on success or NULL on failure.
1436 struct drm_atomic_state
*(*atomic_state_alloc
)(struct drm_device
*dev
);
1439 * @atomic_state_clear:
1441 * This hook must clear any driver private state duplicated into the
1442 * passed-in &drm_atomic_state. This hook is called when the caller
1443 * encountered a &drm_modeset_lock deadlock and needs to drop all
1444 * already acquired locks as part of the deadlock avoidance dance
1445 * implemented in drm_modeset_lock_backoff().
1447 * Any duplicated state must be invalidated since a concurrent atomic
1448 * update might change it, and the drm atomic interfaces always apply
1449 * updates as relative changes to the current state.
1451 * Drivers that implement this must call drm_atomic_state_default_clear()
1452 * to clear common state.
1454 void (*atomic_state_clear
)(struct drm_atomic_state
*state
);
1457 * @atomic_state_free:
1459 * This hook needs driver private resources and the &drm_atomic_state
1460 * itself. Note that the core first calls drm_atomic_state_clear() to
1461 * avoid code duplicate between the clear and free hooks.
1463 * Drivers that implement this must call drm_atomic_state_default_free()
1464 * to release common resources.
1466 void (*atomic_state_free
)(struct drm_atomic_state
*state
);
1470 * struct drm_mode_config - Mode configuration control structure
1471 * @mutex: mutex protecting KMS related lists and structures
1472 * @connection_mutex: ww mutex protecting connector state and routing
1473 * @acquire_ctx: global implicit acquire context used by atomic drivers for
1475 * @fb_lock: mutex to protect fb state and lists
1476 * @num_fb: number of fbs available
1477 * @fb_list: list of framebuffers available
1478 * @num_encoder: number of encoders on this device
1479 * @encoder_list: list of encoder objects
1480 * @num_overlay_plane: number of overlay planes on this device
1481 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1482 * @plane_list: list of plane objects
1483 * @num_crtc: number of CRTCs on this device
1484 * @crtc_list: list of CRTC objects
1485 * @property_list: list of property objects
1486 * @min_width: minimum pixel width on this device
1487 * @min_height: minimum pixel height on this device
1488 * @max_width: maximum pixel width on this device
1489 * @max_height: maximum pixel height on this device
1490 * @funcs: core driver provided mode setting functions
1491 * @fb_base: base address of the framebuffer
1492 * @poll_enabled: track polling support for this device
1493 * @poll_running: track polling status for this device
1494 * @delayed_event: track delayed poll uevent deliver for this device
1495 * @output_poll_work: delayed work for polling in process context
1496 * @property_blob_list: list of all the blob property objects
1497 * @blob_lock: mutex for blob property allocation and management
1498 * @*_property: core property tracking
1499 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1500 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
1501 * @cursor_width: hint to userspace for max cursor width
1502 * @cursor_height: hint to userspace for max cursor height
1503 * @helper_private: mid-layer private data
1505 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1506 * enumerated by the driver are added here, as are global properties. Some
1507 * global restrictions are also here, e.g. dimension restrictions.
1509 struct drm_mode_config
{
1510 struct mutex mutex
; /* protects configuration (mode lists etc.) */
1511 struct drm_modeset_lock connection_mutex
; /* protects connector->encoder and encoder->crtc links */
1512 struct drm_modeset_acquire_ctx
*acquire_ctx
; /* for legacy _lock_all() / _unlock_all() */
1517 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1520 struct mutex idr_mutex
;
1525 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1526 * connector, modes - just makes life easier to have only one.
1528 struct idr crtc_idr
;
1533 * Use this idr for allocating new IDs for tiled sinks like use in some
1534 * high-res DP MST screens.
1536 struct idr tile_idr
;
1538 struct mutex fb_lock
; /* proctects global and per-file fb lists */
1540 struct list_head fb_list
;
1543 * @num_connector: Number of connectors on this device.
1547 * @connector_ida: ID allocator for connector indices.
1549 struct ida connector_ida
;
1551 * @connector_list: List of connector objects.
1553 struct list_head connector_list
;
1555 struct list_head encoder_list
;
1558 * Track # of overlay planes separately from # of total planes. By
1559 * default we only advertise overlay planes to userspace; if userspace
1560 * sets the "universal plane" capability bit, we'll go ahead and
1561 * expose all planes.
1563 int num_overlay_plane
;
1564 int num_total_plane
;
1565 struct list_head plane_list
;
1568 struct list_head crtc_list
;
1570 struct list_head property_list
;
1572 int min_width
, min_height
;
1573 int max_width
, max_height
;
1574 const struct drm_mode_config_funcs
*funcs
;
1575 resource_size_t fb_base
;
1577 /* output poll support */
1581 struct delayed_work output_poll_work
;
1583 struct mutex blob_lock
;
1585 /* pointers to standard properties */
1586 struct list_head property_blob_list
;
1588 * @edid_property: Default connector property to hold the EDID of the
1589 * currently connected sink, if any.
1591 struct drm_property
*edid_property
;
1593 * @dpms_property: Default connector property to control the
1594 * connector's DPMS state.
1596 struct drm_property
*dpms_property
;
1598 * @path_property: Default connector property to hold the DP MST path
1601 struct drm_property
*path_property
;
1603 * @tile_property: Default connector property to store the tile
1604 * position of a tiled screen, for sinks which need to be driven with
1607 struct drm_property
*tile_property
;
1609 * @plane_type_property: Default plane property to differentiate
1610 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1612 struct drm_property
*plane_type_property
;
1614 * @rotation_property: Optional property for planes or CRTCs to specifiy
1617 struct drm_property
*rotation_property
;
1619 * @prop_src_x: Default atomic plane property for the plane source
1620 * position in the connected &drm_framebuffer.
1622 struct drm_property
*prop_src_x
;
1624 * @prop_src_y: Default atomic plane property for the plane source
1625 * position in the connected &drm_framebuffer.
1627 struct drm_property
*prop_src_y
;
1629 * @prop_src_w: Default atomic plane property for the plane source
1630 * position in the connected &drm_framebuffer.
1632 struct drm_property
*prop_src_w
;
1634 * @prop_src_h: Default atomic plane property for the plane source
1635 * position in the connected &drm_framebuffer.
1637 struct drm_property
*prop_src_h
;
1639 * @prop_crtc_x: Default atomic plane property for the plane destination
1640 * position in the &drm_crtc is is being shown on.
1642 struct drm_property
*prop_crtc_x
;
1644 * @prop_crtc_y: Default atomic plane property for the plane destination
1645 * position in the &drm_crtc is is being shown on.
1647 struct drm_property
*prop_crtc_y
;
1649 * @prop_crtc_w: Default atomic plane property for the plane destination
1650 * position in the &drm_crtc is is being shown on.
1652 struct drm_property
*prop_crtc_w
;
1654 * @prop_crtc_h: Default atomic plane property for the plane destination
1655 * position in the &drm_crtc is is being shown on.
1657 struct drm_property
*prop_crtc_h
;
1659 * @prop_fb_id: Default atomic plane property to specify the
1662 struct drm_property
*prop_fb_id
;
1664 * @prop_crtc_id: Default atomic plane property to specify the
1667 struct drm_property
*prop_crtc_id
;
1669 * @prop_active: Default atomic CRTC property to control the active
1670 * state, which is the simplified implementation for DPMS in atomic
1673 struct drm_property
*prop_active
;
1675 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1676 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1677 * connectors must be of and active must be set to disabled, too.
1679 struct drm_property
*prop_mode_id
;
1682 * @dvi_i_subconnector_property: Optional DVI-I property to
1683 * differentiate between analog or digital mode.
1685 struct drm_property
*dvi_i_subconnector_property
;
1687 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1688 * select between analog or digital mode.
1690 struct drm_property
*dvi_i_select_subconnector_property
;
1693 * @tv_subconnector_property: Optional TV property to differentiate
1694 * between different TV connector types.
1696 struct drm_property
*tv_subconnector_property
;
1698 * @tv_select_subconnector_property: Optional TV property to select
1699 * between different TV connector types.
1701 struct drm_property
*tv_select_subconnector_property
;
1703 * @tv_mode_property: Optional TV property to select
1704 * the output TV mode.
1706 struct drm_property
*tv_mode_property
;
1708 * @tv_left_margin_property: Optional TV property to set the left
1711 struct drm_property
*tv_left_margin_property
;
1713 * @tv_right_margin_property: Optional TV property to set the right
1716 struct drm_property
*tv_right_margin_property
;
1718 * @tv_top_margin_property: Optional TV property to set the right
1721 struct drm_property
*tv_top_margin_property
;
1723 * @tv_bottom_margin_property: Optional TV property to set the right
1726 struct drm_property
*tv_bottom_margin_property
;
1728 * @tv_brightness_property: Optional TV property to set the
1731 struct drm_property
*tv_brightness_property
;
1733 * @tv_contrast_property: Optional TV property to set the
1736 struct drm_property
*tv_contrast_property
;
1738 * @tv_flicker_reduction_property: Optional TV property to control the
1739 * flicker reduction mode.
1741 struct drm_property
*tv_flicker_reduction_property
;
1743 * @tv_overscan_property: Optional TV property to control the overscan
1746 struct drm_property
*tv_overscan_property
;
1748 * @tv_saturation_property: Optional TV property to set the
1751 struct drm_property
*tv_saturation_property
;
1753 * @tv_hue_property: Optional TV property to set the hue.
1755 struct drm_property
*tv_hue_property
;
1758 * @scaling_mode_property: Optional connector property to control the
1759 * upscaling, mostly used for built-in panels.
1761 struct drm_property
*scaling_mode_property
;
1763 * @aspect_ratio_property: Optional connector property to control the
1764 * HDMI infoframe aspect ratio setting.
1766 struct drm_property
*aspect_ratio_property
;
1768 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1769 * convert the framebuffer's colors to linear gamma.
1771 struct drm_property
*degamma_lut_property
;
1773 * @degamma_lut_size_property: Optional CRTC property for the size of
1774 * the degamma LUT as supported by the driver (read-only).
1776 struct drm_property
*degamma_lut_size_property
;
1778 * @ctm_property: Optional CRTC property to set the
1779 * matrix used to convert colors after the lookup in the
1782 struct drm_property
*ctm_property
;
1784 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1785 * convert the colors, after the CTM matrix, to the gamma space of the
1788 struct drm_property
*gamma_lut_property
;
1790 * @gamma_lut_size_property: Optional CRTC property for the size of the
1791 * gamma LUT as supported by the driver (read-only).
1793 struct drm_property
*gamma_lut_size_property
;
1796 * @suggested_x_property: Optional connector property with a hint for
1797 * the position of the output on the host's screen.
1799 struct drm_property
*suggested_x_property
;
1801 * @suggested_y_property: Optional connector property with a hint for
1802 * the position of the output on the host's screen.
1804 struct drm_property
*suggested_y_property
;
1806 /* dumb ioctl parameters */
1807 uint32_t preferred_depth
, prefer_shadow
;
1810 * @async_page_flip: Does this device support async flips on the primary
1813 bool async_page_flip
;
1816 * @allow_fb_modifiers:
1818 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1820 bool allow_fb_modifiers
;
1823 uint32_t cursor_width
, cursor_height
;
1825 struct drm_mode_config_helper_funcs
*helper_private
;
1829 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1830 * @plane: the loop cursor
1831 * @dev: the DRM device
1832 * @plane_mask: bitmask of plane indices
1834 * Iterate over all planes specified by bitmask.
1836 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
1837 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
1838 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
1840 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1841 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
1843 extern __printf(6, 7)
1844 int drm_crtc_init_with_planes(struct drm_device
*dev
,
1845 struct drm_crtc
*crtc
,
1846 struct drm_plane
*primary
,
1847 struct drm_plane
*cursor
,
1848 const struct drm_crtc_funcs
*funcs
,
1849 const char *name
, ...);
1850 extern void drm_crtc_cleanup(struct drm_crtc
*crtc
);
1853 * drm_crtc_index - find the index of a registered CRTC
1854 * @crtc: CRTC to find index for
1856 * Given a registered CRTC, return the index of that CRTC within a DRM
1857 * device's list of CRTCs.
1859 static inline unsigned int drm_crtc_index(struct drm_crtc
*crtc
)
1865 * drm_crtc_mask - find the mask of a registered CRTC
1866 * @crtc: CRTC to find mask for
1868 * Given a registered CRTC, return the mask bit of that CRTC for an
1869 * encoder's possible_crtcs field.
1871 static inline uint32_t drm_crtc_mask(struct drm_crtc
*crtc
)
1873 return 1 << drm_crtc_index(crtc
);
1876 extern __printf(8, 9)
1877 int drm_universal_plane_init(struct drm_device
*dev
,
1878 struct drm_plane
*plane
,
1879 unsigned long possible_crtcs
,
1880 const struct drm_plane_funcs
*funcs
,
1881 const uint32_t *formats
,
1882 unsigned int format_count
,
1883 enum drm_plane_type type
,
1884 const char *name
, ...);
1885 extern int drm_plane_init(struct drm_device
*dev
,
1886 struct drm_plane
*plane
,
1887 unsigned long possible_crtcs
,
1888 const struct drm_plane_funcs
*funcs
,
1889 const uint32_t *formats
, unsigned int format_count
,
1891 extern void drm_plane_cleanup(struct drm_plane
*plane
);
1894 * drm_plane_index - find the index of a registered plane
1895 * @plane: plane to find index for
1897 * Given a registered plane, return the index of that plane within a DRM
1898 * device's list of planes.
1900 static inline unsigned int drm_plane_index(struct drm_plane
*plane
)
1902 return plane
->index
;
1904 extern struct drm_plane
* drm_plane_from_index(struct drm_device
*dev
, int idx
);
1905 extern void drm_plane_force_disable(struct drm_plane
*plane
);
1906 extern void drm_crtc_get_hv_timing(const struct drm_display_mode
*mode
,
1907 int *hdisplay
, int *vdisplay
);
1908 extern int drm_crtc_force_disable(struct drm_crtc
*crtc
);
1909 extern int drm_crtc_force_disable_all(struct drm_device
*dev
);
1911 extern void drm_mode_config_init(struct drm_device
*dev
);
1912 extern void drm_mode_config_reset(struct drm_device
*dev
);
1913 extern void drm_mode_config_cleanup(struct drm_device
*dev
);
1915 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
1918 extern int drm_mode_set_config_internal(struct drm_mode_set
*set
);
1920 extern struct drm_tile_group
*drm_mode_create_tile_group(struct drm_device
*dev
,
1922 extern struct drm_tile_group
*drm_mode_get_tile_group(struct drm_device
*dev
,
1924 extern void drm_mode_put_tile_group(struct drm_device
*dev
,
1925 struct drm_tile_group
*tg
);
1927 extern int drm_mode_plane_set_obj_prop(struct drm_plane
*plane
,
1928 struct drm_property
*property
,
1931 extern struct drm_property
*drm_mode_create_rotation_property(struct drm_device
*dev
,
1932 unsigned int supported_rotations
);
1933 extern unsigned int drm_rotation_simplify(unsigned int rotation
,
1934 unsigned int supported_rotations
);
1935 extern void drm_crtc_enable_color_mgmt(struct drm_crtc
*crtc
,
1936 uint degamma_lut_size
,
1938 uint gamma_lut_size
);
1940 int drm_plane_create_zpos_property(struct drm_plane
*plane
,
1942 unsigned int min
, unsigned int max
);
1944 int drm_plane_create_zpos_immutable_property(struct drm_plane
*plane
,
1948 static inline struct drm_plane
*drm_plane_find(struct drm_device
*dev
,
1951 struct drm_mode_object
*mo
;
1952 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_PLANE
);
1953 return mo
? obj_to_plane(mo
) : NULL
;
1956 static inline struct drm_crtc
*drm_crtc_find(struct drm_device
*dev
,
1959 struct drm_mode_object
*mo
;
1960 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_CRTC
);
1961 return mo
? obj_to_crtc(mo
) : NULL
;
1965 * Extract a degamma/gamma LUT value provided by user and round it to the
1966 * precision supported by the hardware.
1968 static inline uint32_t drm_color_lut_extract(uint32_t user_input
,
1969 uint32_t bit_precision
)
1971 uint32_t val
= user_input
;
1972 uint32_t max
= 0xffff >> (16 - bit_precision
);
1974 /* Round only if we're not using full precision. */
1975 if (bit_precision
< 16) {
1976 val
+= 1UL << (16 - bit_precision
- 1);
1977 val
>>= 16 - bit_precision
;
1980 return clamp_val(val
, 0, max
);
1983 /* Plane list iterator for legacy (overlay only) planes. */
1984 #define drm_for_each_legacy_plane(plane, dev) \
1985 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
1986 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1988 #define drm_for_each_plane(plane, dev) \
1989 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
1991 #define drm_for_each_crtc(crtc, dev) \
1992 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1995 assert_drm_connector_list_read_locked(struct drm_mode_config
*mode_config
)
1998 * The connector hotadd/remove code currently grabs both locks when
1999 * updating lists. Hence readers need only hold either of them to be
2000 * safe and the check amounts to
2002 * WARN_ON(not_holding(A) && not_holding(B)).
2004 WARN_ON(!mutex_is_locked(&mode_config
->mutex
) &&
2005 !drm_modeset_is_locked(&mode_config
->connection_mutex
));
2008 #endif /* __DRM_CRTC_H__ */