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>
41 struct drm_framebuffer
;
42 struct drm_object_properties
;
48 struct drm_mode_object
{
51 struct drm_object_properties
*properties
;
53 void (*free_cb
)(struct kref
*kref
);
56 #define DRM_OBJECT_MAX_PROPERTY 24
57 struct drm_object_properties
{
58 int count
, atomic_count
;
59 /* NOTE: if we ever start dynamically destroying properties (ie.
60 * not at drm_mode_config_cleanup() time), then we'd have to do
61 * a better job of detaching property from mode objects to avoid
62 * dangling property pointers:
64 struct drm_property
*properties
[DRM_OBJECT_MAX_PROPERTY
];
65 /* do not read/write values directly, but use drm_object_property_get_value()
66 * and drm_object_property_set_value():
68 uint64_t values
[DRM_OBJECT_MAX_PROPERTY
];
71 static inline int64_t U642I64(uint64_t val
)
73 return (int64_t)*((int64_t *)&val
);
75 static inline uint64_t I642U64(int64_t val
)
77 return (uint64_t)*((uint64_t *)&val
);
81 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
82 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
83 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
85 #define DRM_ROTATE_MASK 0x0f
86 #define DRM_ROTATE_0 0
87 #define DRM_ROTATE_90 1
88 #define DRM_ROTATE_180 2
89 #define DRM_ROTATE_270 3
90 #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
91 #define DRM_REFLECT_X 4
92 #define DRM_REFLECT_Y 5
94 enum drm_connector_force
{
95 DRM_FORCE_UNSPECIFIED
,
97 DRM_FORCE_ON
, /* force on analog part normally */
98 DRM_FORCE_ON_DIGITAL
, /* for DVI-I use digital connector */
101 #include <drm/drm_modes.h>
103 enum drm_connector_status
{
104 connector_status_connected
= 1,
105 connector_status_disconnected
= 2,
106 connector_status_unknown
= 3,
109 enum subpixel_order
{
111 SubPixelHorizontalRGB
,
112 SubPixelHorizontalBGR
,
118 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
119 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
120 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
122 #define DRM_BUS_FLAG_DE_LOW (1<<0)
123 #define DRM_BUS_FLAG_DE_HIGH (1<<1)
124 /* drive data on pos. edge */
125 #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
126 /* drive data on neg. edge */
127 #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
130 * Describes a given display (e.g. CRT or flat panel) and its limitations.
132 struct drm_display_info
{
133 char name
[DRM_DISPLAY_INFO_LEN
];
136 unsigned int width_mm
;
137 unsigned int height_mm
;
139 /* Clock limits FIXME: storage format */
140 unsigned int min_vfreq
, max_vfreq
;
141 unsigned int min_hfreq
, max_hfreq
;
142 unsigned int pixel_clock
;
145 enum subpixel_order subpixel_order
;
148 const u32
*bus_formats
;
149 unsigned int num_bus_formats
;
152 /* Mask of supported hdmi deep color modes */
153 u8 edid_hdmi_dc_modes
;
158 /* data corresponds to displayid vend/prod/serial */
159 struct drm_tile_group
{
160 struct kref refcount
;
161 struct drm_device
*dev
;
167 * struct drm_framebuffer_funcs - framebuffer hooks
169 struct drm_framebuffer_funcs
{
173 * Clean up framebuffer resources, specifically also unreference the
174 * backing storage. The core guarantees to call this function for every
175 * framebuffer successfully created by ->fb_create() in
176 * &drm_mode_config_funcs. Drivers must also call
177 * drm_framebuffer_cleanup() to release DRM core resources for this
180 void (*destroy
)(struct drm_framebuffer
*framebuffer
);
185 * Create a buffer handle in the driver-specific buffer manager (either
186 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
187 * the core to implement the GETFB IOCTL, which returns (for
188 * sufficiently priviledged user) also a native buffer handle. This can
189 * be used for seamless transitions between modesetting clients by
190 * copying the current screen contents to a private buffer and blending
191 * between that and the new contents.
193 * GEM based drivers should call drm_gem_handle_create() to create the
198 * 0 on success or a negative error code on failure.
200 int (*create_handle
)(struct drm_framebuffer
*fb
,
201 struct drm_file
*file_priv
,
202 unsigned int *handle
);
206 * Optional callback for the dirty fb IOCTL.
208 * Userspace can notify the driver via this callback that an area of the
209 * framebuffer has changed and should be flushed to the display
210 * hardware. This can also be used internally, e.g. by the fbdev
211 * emulation, though that's not the case currently.
213 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
214 * for more information as all the semantics and arguments have a one to
215 * one mapping on this function.
219 * 0 on success or a negative error code on failure.
221 int (*dirty
)(struct drm_framebuffer
*framebuffer
,
222 struct drm_file
*file_priv
, unsigned flags
,
223 unsigned color
, struct drm_clip_rect
*clips
,
227 struct drm_framebuffer
{
228 struct drm_device
*dev
;
230 * Note that the fb is refcounted for the benefit of driver internals,
231 * for example some hw, disabling a CRTC/plane is asynchronous, and
232 * scanout does not actually complete until the next vblank. So some
233 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
234 * should be deferred. In cases like this, the driver would like to
235 * hold a ref to the fb even though it has already been removed from
236 * userspace perspective.
237 * The refcount is stored inside the mode object.
240 * Place on the dev->mode_config.fb_list, access protected by
241 * dev->mode_config.fb_lock.
243 struct list_head head
;
244 struct drm_mode_object base
;
245 const struct drm_framebuffer_funcs
*funcs
;
246 unsigned int pitches
[4];
247 unsigned int offsets
[4];
248 uint64_t modifier
[4];
251 /* depth can be 15 or 16 */
255 uint32_t pixel_format
; /* fourcc format */
258 struct list_head filp_head
;
261 struct drm_property_blob
{
262 struct drm_mode_object base
;
263 struct drm_device
*dev
;
264 struct list_head head_global
;
265 struct list_head head_file
;
267 unsigned char data
[];
270 struct drm_property_enum
{
272 struct list_head head
;
273 char name
[DRM_PROP_NAME_LEN
];
276 struct drm_property
{
277 struct list_head head
;
278 struct drm_mode_object base
;
280 char name
[DRM_PROP_NAME_LEN
];
283 struct drm_device
*dev
;
285 struct list_head enum_list
;
289 struct drm_connector
;
291 struct drm_pending_vblank_event
;
294 struct drm_atomic_state
;
296 struct drm_crtc_helper_funcs
;
297 struct drm_encoder_helper_funcs
;
298 struct drm_connector_helper_funcs
;
299 struct drm_plane_helper_funcs
;
302 * struct drm_crtc_state - mutable CRTC state
303 * @crtc: backpointer to the CRTC
304 * @enable: whether the CRTC should be enabled, gates all other state
305 * @active: whether the CRTC is actively displaying (used for DPMS)
306 * @planes_changed: planes on this crtc are updated
307 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
308 * @active_changed: crtc_state->active has been toggled.
309 * @connectors_changed: connectors to this crtc have been updated
310 * @color_mgmt_changed: color management properties have changed (degamma or
311 * gamma LUT or CSC matrix)
312 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
313 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
314 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
315 * @last_vblank_count: for helpers and drivers to capture the vblank of the
316 * update to ensure framebuffer cleanup isn't done too early
317 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
318 * @mode: current mode timings
319 * @mode_blob: &drm_property_blob for @mode
320 * @degamma_lut: Lookup table for converting framebuffer pixel data
321 * before apply the conversion matrix
322 * @ctm: Transformation matrix
323 * @gamma_lut: Lookup table for converting pixel data after the
325 * @event: optional pointer to a DRM event to signal upon completion of the
327 * @state: backpointer to global drm_atomic_state
329 * Note that the distinction between @enable and @active is rather subtile:
330 * Flipping @active while @enable is set without changing anything else may
331 * never return in a failure from the ->atomic_check callback. Userspace assumes
332 * that a DPMS On will always succeed. In other words: @enable controls resource
333 * assignment, @active controls the actual hardware state.
335 struct drm_crtc_state
{
336 struct drm_crtc
*crtc
;
341 /* computed state bits used by helpers and drivers */
342 bool planes_changed
: 1;
343 bool mode_changed
: 1;
344 bool active_changed
: 1;
345 bool connectors_changed
: 1;
346 bool color_mgmt_changed
: 1;
348 /* attached planes bitmask:
349 * WARNING: transitional helpers do not maintain plane_mask so
350 * drivers not converted over to atomic helpers should not rely
351 * on plane_mask being accurate!
358 /* last_vblank_count: for vblank waits before cleanup */
359 u32 last_vblank_count
;
361 /* adjusted_mode: for use by helpers and drivers */
362 struct drm_display_mode adjusted_mode
;
364 struct drm_display_mode mode
;
366 /* blob property to expose current mode to atomic userspace */
367 struct drm_property_blob
*mode_blob
;
369 /* blob property to expose color management to userspace */
370 struct drm_property_blob
*degamma_lut
;
371 struct drm_property_blob
*ctm
;
372 struct drm_property_blob
*gamma_lut
;
374 struct drm_pending_vblank_event
*event
;
376 struct drm_atomic_state
*state
;
380 * struct drm_crtc_funcs - control CRTCs for a given device
382 * The drm_crtc_funcs structure is the central CRTC management structure
383 * in the DRM. Each CRTC controls one or more connectors (note that the name
384 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
385 * connectors, not just CRTs).
387 * Each driver is responsible for filling out this structure at startup time,
388 * in addition to providing other modesetting features, like i2c and DDC
391 struct drm_crtc_funcs
{
395 * Reset CRTC hardware and software state to off. This function isn't
396 * called by the core directly, only through drm_mode_config_reset().
397 * It's not a helper hook only for historical reasons.
399 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
400 * atomic state using this hook.
402 void (*reset
)(struct drm_crtc
*crtc
);
407 * Update the cursor image. The cursor position is relative to the CRTC
408 * and can be partially or fully outside of the visible area.
410 * Note that contrary to all other KMS functions the legacy cursor entry
411 * points don't take a framebuffer object, but instead take directly a
412 * raw buffer object id from the driver's buffer manager (which is
413 * either GEM or TTM for current drivers).
415 * This entry point is deprecated, drivers should instead implement
416 * universal plane support and register a proper cursor plane using
417 * drm_crtc_init_with_planes().
419 * This callback is optional
423 * 0 on success or a negative error code on failure.
425 int (*cursor_set
)(struct drm_crtc
*crtc
, struct drm_file
*file_priv
,
426 uint32_t handle
, uint32_t width
, uint32_t height
);
431 * Update the cursor image, including hotspot information. The hotspot
432 * must not affect the cursor position in CRTC coordinates, but is only
433 * meant as a hint for virtualized display hardware to coordinate the
434 * guests and hosts cursor position. The cursor hotspot is relative to
435 * the cursor image. Otherwise this works exactly like @cursor_set.
437 * This entry point is deprecated, drivers should instead implement
438 * universal plane support and register a proper cursor plane using
439 * drm_crtc_init_with_planes().
441 * This callback is optional.
445 * 0 on success or a negative error code on failure.
447 int (*cursor_set2
)(struct drm_crtc
*crtc
, struct drm_file
*file_priv
,
448 uint32_t handle
, uint32_t width
, uint32_t height
,
449 int32_t hot_x
, int32_t hot_y
);
454 * Update the cursor position. The cursor does not need to be visible
455 * when this hook is called.
457 * This entry point is deprecated, drivers should instead implement
458 * universal plane support and register a proper cursor plane using
459 * drm_crtc_init_with_planes().
461 * This callback is optional.
465 * 0 on success or a negative error code on failure.
467 int (*cursor_move
)(struct drm_crtc
*crtc
, int x
, int y
);
472 * Set gamma on the CRTC.
474 * This callback is optional.
478 * Drivers that support gamma tables and also fbdev emulation through
479 * the provided helper library need to take care to fill out the gamma
480 * hooks for both. Currently there's a bit an unfortunate duplication
481 * going on, which should eventually be unified to just one set of
484 int (*gamma_set
)(struct drm_crtc
*crtc
, u16
*r
, u16
*g
, u16
*b
,
490 * Clean up plane resources. This is only called at driver unload time
491 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
494 void (*destroy
)(struct drm_crtc
*crtc
);
499 * This is the main legacy entry point to change the modeset state on a
500 * CRTC. All the details of the desired configuration are passed in a
501 * struct &drm_mode_set - see there for details.
503 * Drivers implementing atomic modeset should use
504 * drm_atomic_helper_set_config() to implement this hook.
508 * 0 on success or a negative error code on failure.
510 int (*set_config
)(struct drm_mode_set
*set
);
515 * Legacy entry point to schedule a flip to the given framebuffer.
517 * Page flipping is a synchronization mechanism that replaces the frame
518 * buffer being scanned out by the CRTC with a new frame buffer during
519 * vertical blanking, avoiding tearing (except when requested otherwise
520 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
521 * requests a page flip the DRM core verifies that the new frame buffer
522 * is large enough to be scanned out by the CRTC in the currently
523 * configured mode and then calls the CRTC ->page_flip() operation with a
524 * pointer to the new frame buffer.
526 * The driver must wait for any pending rendering to the new framebuffer
527 * to complete before executing the flip. It should also wait for any
528 * pending rendering from other drivers if the underlying buffer is a
531 * An application can request to be notified when the page flip has
532 * completed. The drm core will supply a struct &drm_event in the event
533 * parameter in this case. This can be handled by the
534 * drm_crtc_send_vblank_event() function, which the driver should call on
535 * the provided event upon completion of the flip. Note that if
536 * the driver supports vblank signalling and timestamping the vblank
537 * counters and timestamps must agree with the ones returned from page
538 * flip events. With the current vblank helper infrastructure this can
539 * be achieved by holding a vblank reference while the page flip is
540 * pending, acquired through drm_crtc_vblank_get() and released with
541 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
542 * counter and timestamp tracking though, e.g. if they have accurate
543 * timestamp registers in hardware.
547 * Up to that point drivers need to manage events themselves and can use
548 * even->base.list freely for that. Specifically they need to ensure
549 * that they don't send out page flip (or vblank) events for which the
550 * corresponding drm file has been closed already. The drm core
551 * unfortunately does not (yet) take care of that. Therefore drivers
552 * currently must clean up and release pending events in their
553 * ->preclose driver function.
555 * This callback is optional.
559 * Very early versions of the KMS ABI mandated that the driver must
560 * block (but not reject) any rendering to the old framebuffer until the
561 * flip operation has completed and the old framebuffer is no longer
562 * visible. This requirement has been lifted, and userspace is instead
563 * expected to request delivery of an event and wait with recycling old
564 * buffers until such has been received.
568 * 0 on success or a negative error code on failure. Note that if a
569 * ->page_flip() operation is already pending the callback should return
570 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
571 * or just runtime disabled through DPMS respectively the new atomic
572 * "ACTIVE" state) should result in an -EINVAL error code. Note that
573 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
575 int (*page_flip
)(struct drm_crtc
*crtc
,
576 struct drm_framebuffer
*fb
,
577 struct drm_pending_vblank_event
*event
,
583 * This is the legacy entry point to update a property attached to the
586 * Drivers implementing atomic modeset should use
587 * drm_atomic_helper_crtc_set_property() to implement this hook.
589 * This callback is optional if the driver does not support any legacy
590 * driver-private properties.
594 * 0 on success or a negative error code on failure.
596 int (*set_property
)(struct drm_crtc
*crtc
,
597 struct drm_property
*property
, uint64_t val
);
600 * @atomic_duplicate_state:
602 * Duplicate the current atomic state for this CRTC and return it.
603 * The core and helpers gurantee that any atomic state duplicated with
604 * this hook and still owned by the caller (i.e. not transferred to the
605 * driver by calling ->atomic_commit() from struct
606 * &drm_mode_config_funcs) will be cleaned up by calling the
607 * @atomic_destroy_state hook in this structure.
609 * Atomic drivers which don't subclass struct &drm_crtc should use
610 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
611 * state structure to extend it with driver-private state should use
612 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
613 * duplicated in a consistent fashion across drivers.
615 * It is an error to call this hook before crtc->state has been
616 * initialized correctly.
620 * If the duplicate state references refcounted resources this hook must
621 * acquire a reference for each of them. The driver must release these
622 * references again in @atomic_destroy_state.
626 * Duplicated atomic state or NULL when the allocation failed.
628 struct drm_crtc_state
*(*atomic_duplicate_state
)(struct drm_crtc
*crtc
);
631 * @atomic_destroy_state:
633 * Destroy a state duplicated with @atomic_duplicate_state and release
634 * or unreference all resources it references
636 void (*atomic_destroy_state
)(struct drm_crtc
*crtc
,
637 struct drm_crtc_state
*state
);
640 * @atomic_set_property:
642 * Decode a driver-private property value and store the decoded value
643 * into the passed-in state structure. Since the atomic core decodes all
644 * standardized properties (even for extensions beyond the core set of
645 * properties which might not be implemented by all drivers) this
646 * requires drivers to subclass the state structure.
648 * Such driver-private properties should really only be implemented for
649 * truly hardware/vendor specific state. Instead it is preferred to
650 * standardize atomic extension and decode the properties used to expose
651 * such an extension in the core.
653 * Do not call this function directly, use
654 * drm_atomic_crtc_set_property() instead.
656 * This callback is optional if the driver does not support any
657 * driver-private atomic properties.
661 * This function is called in the state assembly phase of atomic
662 * modesets, which can be aborted for any reason (including on
663 * userspace's request to just check whether a configuration would be
664 * possible). Drivers MUST NOT touch any persistent state (hardware or
665 * software) or data structures except the passed in @state parameter.
667 * Also since userspace controls in which order properties are set this
668 * function must not do any input validation (since the state update is
669 * incomplete and hence likely inconsistent). Instead any such input
670 * validation must be done in the various atomic_check callbacks.
674 * 0 if the property has been found, -EINVAL if the property isn't
675 * implemented by the driver (which should never happen, the core only
676 * asks for properties attached to this CRTC). No other validation is
677 * allowed by the driver. The core already checks that the property
678 * value is within the range (integer, valid enum value, ...) the driver
679 * set when registering the property.
681 int (*atomic_set_property
)(struct drm_crtc
*crtc
,
682 struct drm_crtc_state
*state
,
683 struct drm_property
*property
,
686 * @atomic_get_property:
688 * Reads out the decoded driver-private property. This is used to
689 * implement the GETCRTC IOCTL.
691 * Do not call this function directly, use
692 * drm_atomic_crtc_get_property() instead.
694 * This callback is optional if the driver does not support any
695 * driver-private atomic properties.
699 * 0 on success, -EINVAL if the property isn't implemented by the
700 * driver (which should never happen, the core only asks for
701 * properties attached to this CRTC).
703 int (*atomic_get_property
)(struct drm_crtc
*crtc
,
704 const struct drm_crtc_state
*state
,
705 struct drm_property
*property
,
710 * struct drm_crtc - central CRTC control structure
711 * @dev: parent DRM device
712 * @port: OF node used by drm_of_find_possible_crtcs()
713 * @head: list management
714 * @name: human readable name, can be overwritten by the driver
715 * @mutex: per-CRTC locking
716 * @base: base KMS object for ID tracking etc.
717 * @primary: primary plane for this CRTC
718 * @cursor: cursor plane for this CRTC
719 * @cursor_x: current x position of the cursor, used for universal cursor planes
720 * @cursor_y: current y position of the cursor, used for universal cursor planes
721 * @enabled: is this CRTC enabled?
722 * @mode: current mode timings
723 * @hwmode: mode timings as programmed to hw regs
724 * @x: x position on screen
725 * @y: y position on screen
726 * @funcs: CRTC control functions
727 * @gamma_size: size of gamma ramp
728 * @gamma_store: gamma ramp values
729 * @helper_private: mid-layer private data
730 * @properties: property tracking for this CRTC
731 * @state: current atomic state for this CRTC
732 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
735 * Each CRTC may have one or more connectors associated with it. This structure
736 * allows the CRTC to be controlled.
739 struct drm_device
*dev
;
740 struct device_node
*port
;
741 struct list_head head
;
748 * This provides a read lock for the overall crtc state (mode, dpms
749 * state, ...) and a write lock for everything which can be update
750 * without a full modeset (fb, cursor data, crtc properties ...). Full
751 * modeset also need to grab dev->mode_config.connection_mutex.
753 struct drm_modeset_lock mutex
;
755 struct drm_mode_object base
;
757 /* primary and cursor planes for CRTC */
758 struct drm_plane
*primary
;
759 struct drm_plane
*cursor
;
761 /* position inside the mode_config.list, can be used as a [] idx */
764 /* position of cursor plane on crtc */
770 /* Requested mode from modesetting. */
771 struct drm_display_mode mode
;
773 /* Programmed mode in hw, after adjustments for encoders,
774 * crtc, panel scaling etc. Needed for timestamping etc.
776 struct drm_display_mode hwmode
;
779 const struct drm_crtc_funcs
*funcs
;
781 /* Legacy FB CRTC gamma size for reporting to userspace */
783 uint16_t *gamma_store
;
785 /* if you are using the helper */
786 const struct drm_crtc_helper_funcs
*helper_private
;
788 struct drm_object_properties properties
;
790 struct drm_crtc_state
*state
;
793 * For legacy crtc IOCTLs so that atomic drivers can get at the locking
796 struct drm_modeset_acquire_ctx
*acquire_ctx
;
800 * struct drm_connector_state - mutable connector state
801 * @connector: backpointer to the connector
802 * @crtc: CRTC to connect connector to, NULL if disabled
803 * @best_encoder: can be used by helpers and drivers to select the encoder
804 * @state: backpointer to global drm_atomic_state
806 struct drm_connector_state
{
807 struct drm_connector
*connector
;
809 struct drm_crtc
*crtc
; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
811 struct drm_encoder
*best_encoder
;
813 struct drm_atomic_state
*state
;
817 * struct drm_connector_funcs - control connectors on a given device
819 * Each CRTC may have one or more connectors attached to it. The functions
820 * below allow the core DRM code to control connectors, enumerate available modes,
823 struct drm_connector_funcs
{
827 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
828 * is exposed as a standard property on the connector, but diverted to
829 * this callback in the drm core. Note that atomic drivers don't
830 * implement the 4 level DPMS support on the connector any more, but
831 * instead only have an on/off "ACTIVE" property on the CRTC object.
833 * Drivers implementing atomic modeset should use
834 * drm_atomic_helper_connector_dpms() to implement this hook.
838 * 0 on success or a negative error code on failure.
840 int (*dpms
)(struct drm_connector
*connector
, int mode
);
845 * Reset connector hardware and software state to off. This function isn't
846 * called by the core directly, only through drm_mode_config_reset().
847 * It's not a helper hook only for historical reasons.
849 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
850 * atomic state using this hook.
852 void (*reset
)(struct drm_connector
*connector
);
857 * Check to see if anything is attached to the connector. The parameter
858 * force is set to false whilst polling, true when checking the
859 * connector due to a user request. force can be used by the driver to
860 * avoid expensive, destructive operations during automated probing.
864 * Note that this hook is only called by the probe helper. It's not in
865 * the helper library vtable purely for historical reasons. The only DRM
866 * core entry point to probe connector state is @fill_modes.
870 * drm_connector_status indicating the connector's status.
872 enum drm_connector_status (*detect
)(struct drm_connector
*connector
,
878 * This function is called to update internal encoder state when the
879 * connector is forced to a certain state by userspace, either through
880 * the sysfs interfaces or on the kernel cmdline. In that case the
881 * @detect callback isn't called.
885 * Note that this hook is only called by the probe helper. It's not in
886 * the helper library vtable purely for historical reasons. The only DRM
887 * core entry point to probe connector state is @fill_modes.
889 void (*force
)(struct drm_connector
*connector
);
894 * Entry point for output detection and basic mode validation. The
895 * driver should reprobe the output if needed (e.g. when hotplug
896 * handling is unreliable), add all detected modes to connector->modes
897 * and filter out any the device can't support in any configuration. It
898 * also needs to filter out any modes wider or higher than the
899 * parameters max_width and max_height indicate.
901 * The drivers must also prune any modes no longer valid from
902 * connector->modes. Furthermore it must update connector->status and
903 * connector->edid. If no EDID has been received for this output
904 * connector->edid must be NULL.
906 * Drivers using the probe helpers should use
907 * drm_helper_probe_single_connector_modes() or
908 * drm_helper_probe_single_connector_modes_nomerge() to implement this
913 * The number of modes detected and filled into connector->modes.
915 int (*fill_modes
)(struct drm_connector
*connector
, uint32_t max_width
, uint32_t max_height
);
920 * This is the legacy entry point to update a property attached to the
923 * Drivers implementing atomic modeset should use
924 * drm_atomic_helper_connector_set_property() to implement this hook.
926 * This callback is optional if the driver does not support any legacy
927 * driver-private properties.
931 * 0 on success or a negative error code on failure.
933 int (*set_property
)(struct drm_connector
*connector
, struct drm_property
*property
,
939 * Clean up connector resources. This is called at driver unload time
940 * through drm_mode_config_cleanup(). It can also be called at runtime
941 * when a connector is being hot-unplugged for drivers that support
942 * connector hotplugging (e.g. DisplayPort MST).
944 void (*destroy
)(struct drm_connector
*connector
);
947 * @atomic_duplicate_state:
949 * Duplicate the current atomic state for this connector and return it.
950 * The core and helpers gurantee that any atomic state duplicated with
951 * this hook and still owned by the caller (i.e. not transferred to the
952 * driver by calling ->atomic_commit() from struct
953 * &drm_mode_config_funcs) will be cleaned up by calling the
954 * @atomic_destroy_state hook in this structure.
956 * Atomic drivers which don't subclass struct &drm_connector_state should use
957 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
958 * state structure to extend it with driver-private state should use
959 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
960 * duplicated in a consistent fashion across drivers.
962 * It is an error to call this hook before connector->state has been
963 * initialized correctly.
967 * If the duplicate state references refcounted resources this hook must
968 * acquire a reference for each of them. The driver must release these
969 * references again in @atomic_destroy_state.
973 * Duplicated atomic state or NULL when the allocation failed.
975 struct drm_connector_state
*(*atomic_duplicate_state
)(struct drm_connector
*connector
);
978 * @atomic_destroy_state:
980 * Destroy a state duplicated with @atomic_duplicate_state and release
981 * or unreference all resources it references
983 void (*atomic_destroy_state
)(struct drm_connector
*connector
,
984 struct drm_connector_state
*state
);
987 * @atomic_set_property:
989 * Decode a driver-private property value and store the decoded value
990 * into the passed-in state structure. Since the atomic core decodes all
991 * standardized properties (even for extensions beyond the core set of
992 * properties which might not be implemented by all drivers) this
993 * requires drivers to subclass the state structure.
995 * Such driver-private properties should really only be implemented for
996 * truly hardware/vendor specific state. Instead it is preferred to
997 * standardize atomic extension and decode the properties used to expose
998 * such an extension in the core.
1000 * Do not call this function directly, use
1001 * drm_atomic_connector_set_property() instead.
1003 * This callback is optional if the driver does not support any
1004 * driver-private atomic properties.
1008 * This function is called in the state assembly phase of atomic
1009 * modesets, which can be aborted for any reason (including on
1010 * userspace's request to just check whether a configuration would be
1011 * possible). Drivers MUST NOT touch any persistent state (hardware or
1012 * software) or data structures except the passed in @state parameter.
1014 * Also since userspace controls in which order properties are set this
1015 * function must not do any input validation (since the state update is
1016 * incomplete and hence likely inconsistent). Instead any such input
1017 * validation must be done in the various atomic_check callbacks.
1021 * 0 if the property has been found, -EINVAL if the property isn't
1022 * implemented by the driver (which shouldn't ever happen, the core only
1023 * asks for properties attached to this connector). No other validation
1024 * is allowed by the driver. The core already checks that the property
1025 * value is within the range (integer, valid enum value, ...) the driver
1026 * set when registering the property.
1028 int (*atomic_set_property
)(struct drm_connector
*connector
,
1029 struct drm_connector_state
*state
,
1030 struct drm_property
*property
,
1034 * @atomic_get_property:
1036 * Reads out the decoded driver-private property. This is used to
1037 * implement the GETCONNECTOR IOCTL.
1039 * Do not call this function directly, use
1040 * drm_atomic_connector_get_property() instead.
1042 * This callback is optional if the driver does not support any
1043 * driver-private atomic properties.
1047 * 0 on success, -EINVAL if the property isn't implemented by the
1048 * driver (which shouldn't ever happen, the core only asks for
1049 * properties attached to this connector).
1051 int (*atomic_get_property
)(struct drm_connector
*connector
,
1052 const struct drm_connector_state
*state
,
1053 struct drm_property
*property
,
1058 * struct drm_encoder_funcs - encoder controls
1060 * Encoders sit between CRTCs and connectors.
1062 struct drm_encoder_funcs
{
1066 * Reset encoder hardware and software state to off. This function isn't
1067 * called by the core directly, only through drm_mode_config_reset().
1068 * It's not a helper hook only for historical reasons.
1070 void (*reset
)(struct drm_encoder
*encoder
);
1075 * Clean up encoder resources. This is only called at driver unload time
1076 * through drm_mode_config_cleanup() since an encoder cannot be
1077 * hotplugged in DRM.
1079 void (*destroy
)(struct drm_encoder
*encoder
);
1082 #define DRM_CONNECTOR_MAX_ENCODER 3
1085 * struct drm_encoder - central DRM encoder structure
1086 * @dev: parent DRM device
1087 * @head: list management
1088 * @base: base KMS object
1089 * @name: human readable name, can be overwritten by the driver
1090 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1091 * @possible_crtcs: bitmask of potential CRTC bindings
1092 * @possible_clones: bitmask of potential sibling encoders for cloning
1093 * @crtc: currently bound CRTC
1094 * @bridge: bridge associated to the encoder
1095 * @funcs: control functions
1096 * @helper_private: mid-layer private data
1098 * CRTCs drive pixels to encoders, which convert them into signals
1099 * appropriate for a given connector or set of connectors.
1101 struct drm_encoder
{
1102 struct drm_device
*dev
;
1103 struct list_head head
;
1105 struct drm_mode_object base
;
1109 /* position inside the mode_config.list, can be used as a [] idx */
1112 uint32_t possible_crtcs
;
1113 uint32_t possible_clones
;
1115 struct drm_crtc
*crtc
;
1116 struct drm_bridge
*bridge
;
1117 const struct drm_encoder_funcs
*funcs
;
1118 const struct drm_encoder_helper_funcs
*helper_private
;
1121 /* should we poll this connector for connects and disconnects */
1122 /* hot plug detectable */
1123 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
1124 /* poll for connections */
1125 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1126 /* can cleanly poll for disconnections without flickering the screen */
1127 /* DACs should rarely do this without a lot of testing */
1128 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1130 #define MAX_ELD_BYTES 128
1133 * struct drm_connector - central DRM connector control structure
1134 * @dev: parent DRM device
1135 * @kdev: kernel device for sysfs attributes
1136 * @attr: sysfs attributes
1137 * @head: list management
1138 * @base: base KMS object
1139 * @name: human readable name, can be overwritten by the driver
1140 * @connector_id: compacted connector id useful indexing arrays
1141 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1142 * @connector_type_id: index into connector type enum
1143 * @interlace_allowed: can this connector handle interlaced modes?
1144 * @doublescan_allowed: can this connector handle doublescan?
1145 * @stereo_allowed: can this connector handle stereo modes?
1146 * @modes: modes available on this connector (from fill_modes() + user)
1147 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1148 * @probed_modes: list of modes derived directly from the display
1149 * @display_info: information about attached display (e.g. from EDID)
1150 * @funcs: connector control functions
1151 * @edid_blob_ptr: DRM property containing EDID if present
1152 * @properties: property tracking for this connector
1153 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1154 * @dpms: current dpms state
1155 * @helper_private: mid-layer private data
1156 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
1157 * @force: a %DRM_FORCE_<foo> state for forced mode sets
1158 * @override_edid: has the EDID been overwritten through debugfs for testing?
1159 * @encoder_ids: valid encoders for this connector
1160 * @encoder: encoder driving this connector, if any
1161 * @eld: EDID-like data, if present
1162 * @dvi_dual: dual link DVI, if found
1163 * @max_tmds_clock: max clock rate, if found
1164 * @latency_present: AV delay info from ELD, if found
1165 * @video_latency: video latency info from ELD, if found
1166 * @audio_latency: audio latency info from ELD, if found
1167 * @null_edid_counter: track sinks that give us all zeros for the EDID
1168 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
1169 * @edid_corrupt: indicates whether the last read EDID was corrupt
1170 * @debugfs_entry: debugfs directory for this connector
1171 * @state: current atomic state for this connector
1172 * @has_tile: is this connector connected to a tiled monitor
1173 * @tile_group: tile group for the connected monitor
1174 * @tile_is_single_monitor: whether the tile is one monitor housing
1175 * @num_h_tile: number of horizontal tiles in the tile group
1176 * @num_v_tile: number of vertical tiles in the tile group
1177 * @tile_h_loc: horizontal location of this tile
1178 * @tile_v_loc: vertical location of this tile
1179 * @tile_h_size: horizontal size of this tile.
1180 * @tile_v_size: vertical size of this tile.
1182 * Each connector may be connected to one or more CRTCs, or may be clonable by
1183 * another connector if they can share a CRTC. Each connector also has a specific
1184 * position in the broader display (referred to as a 'screen' though it could
1185 * span multiple monitors).
1187 struct drm_connector
{
1188 struct drm_device
*dev
;
1189 struct device
*kdev
;
1190 struct device_attribute
*attr
;
1191 struct list_head head
;
1193 struct drm_mode_object base
;
1198 int connector_type_id
;
1199 bool interlace_allowed
;
1200 bool doublescan_allowed
;
1201 bool stereo_allowed
;
1202 struct list_head modes
; /* list of modes on this connector */
1204 enum drm_connector_status status
;
1206 /* these are modes added by probing with DDC or the BIOS */
1207 struct list_head probed_modes
;
1209 struct drm_display_info display_info
;
1210 const struct drm_connector_funcs
*funcs
;
1212 struct drm_property_blob
*edid_blob_ptr
;
1213 struct drm_object_properties properties
;
1218 * DRM blob property data for the DP MST path property.
1220 struct drm_property_blob
*path_blob_ptr
;
1225 * DRM blob property data for the tile property (used mostly by DP MST).
1226 * This is meant for screens which are driven through separate display
1227 * pipelines represented by &drm_crtc, which might not be running with
1228 * genlocked clocks. For tiled panels which are genlocked, like
1229 * dual-link LVDS or dual-link DSI, the driver should try to not expose
1230 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1232 struct drm_property_blob
*tile_blob_ptr
;
1234 uint8_t polled
; /* DRM_CONNECTOR_POLL_* */
1236 /* requested DPMS state */
1239 const struct drm_connector_helper_funcs
*helper_private
;
1241 /* forced on connector */
1242 struct drm_cmdline_mode cmdline_mode
;
1243 enum drm_connector_force force
;
1245 uint32_t encoder_ids
[DRM_CONNECTOR_MAX_ENCODER
];
1246 struct drm_encoder
*encoder
; /* currently active encoder */
1249 uint8_t eld
[MAX_ELD_BYTES
];
1251 int max_tmds_clock
; /* in MHz */
1252 bool latency_present
[2];
1253 int video_latency
[2]; /* [0]: progressive, [1]: interlaced */
1254 int audio_latency
[2];
1255 int null_edid_counter
; /* needed to workaround some HW bugs where we get all 0s */
1256 unsigned bad_edid_counter
;
1258 /* Flag for raw EDID header corruption - used in Displayport
1259 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1263 struct dentry
*debugfs_entry
;
1265 struct drm_connector_state
*state
;
1267 /* DisplayID bits */
1269 struct drm_tile_group
*tile_group
;
1270 bool tile_is_single_monitor
;
1272 uint8_t num_h_tile
, num_v_tile
;
1273 uint8_t tile_h_loc
, tile_v_loc
;
1274 uint16_t tile_h_size
, tile_v_size
;
1278 * struct drm_plane_state - mutable plane state
1279 * @plane: backpointer to the plane
1280 * @crtc: currently bound CRTC, NULL if disabled
1281 * @fb: currently bound framebuffer
1282 * @fence: optional fence to wait for before scanning out @fb
1283 * @crtc_x: left position of visible portion of plane on crtc
1284 * @crtc_y: upper position of visible portion of plane on crtc
1285 * @crtc_w: width of visible portion of plane on crtc
1286 * @crtc_h: height of visible portion of plane on crtc
1287 * @src_x: left position of visible portion of plane within
1289 * @src_y: upper position of visible portion of plane within
1291 * @src_w: width of visible portion of plane (in 16.16)
1292 * @src_h: height of visible portion of plane (in 16.16)
1293 * @rotation: rotation of the plane
1294 * @state: backpointer to global drm_atomic_state
1296 struct drm_plane_state
{
1297 struct drm_plane
*plane
;
1299 struct drm_crtc
*crtc
; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1300 struct drm_framebuffer
*fb
; /* do not write directly, use drm_atomic_set_fb_for_plane() */
1301 struct fence
*fence
;
1303 /* Signed dest location allows it to be partially off screen */
1304 int32_t crtc_x
, crtc_y
;
1305 uint32_t crtc_w
, crtc_h
;
1307 /* Source values are 16.16 fixed point */
1308 uint32_t src_x
, src_y
;
1309 uint32_t src_h
, src_w
;
1311 /* Plane rotation */
1312 unsigned int rotation
;
1314 struct drm_atomic_state
*state
;
1319 * struct drm_plane_funcs - driver plane control functions
1321 struct drm_plane_funcs
{
1325 * This is the legacy entry point to enable and configure the plane for
1326 * the given CRTC and framebuffer. It is never called to disable the
1327 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1329 * The source rectangle in frame buffer memory coordinates is given by
1330 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1331 * values). Devices that don't support subpixel plane coordinates can
1332 * ignore the fractional part.
1334 * The destination rectangle in CRTC coordinates is given by the
1335 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1336 * Devices scale the source rectangle to the destination rectangle. If
1337 * scaling is not supported, and the source rectangle size doesn't match
1338 * the destination rectangle size, the driver must return a
1339 * -<errorname>EINVAL</errorname> error.
1341 * Drivers implementing atomic modeset should use
1342 * drm_atomic_helper_update_plane() to implement this hook.
1346 * 0 on success or a negative error code on failure.
1348 int (*update_plane
)(struct drm_plane
*plane
,
1349 struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
1350 int crtc_x
, int crtc_y
,
1351 unsigned int crtc_w
, unsigned int crtc_h
,
1352 uint32_t src_x
, uint32_t src_y
,
1353 uint32_t src_w
, uint32_t src_h
);
1358 * This is the legacy entry point to disable the plane. The DRM core
1359 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
1360 * with the frame buffer ID set to 0. Disabled planes must not be
1361 * processed by the CRTC.
1363 * Drivers implementing atomic modeset should use
1364 * drm_atomic_helper_disable_plane() to implement this hook.
1368 * 0 on success or a negative error code on failure.
1370 int (*disable_plane
)(struct drm_plane
*plane
);
1375 * Clean up plane resources. This is only called at driver unload time
1376 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1379 void (*destroy
)(struct drm_plane
*plane
);
1384 * Reset plane hardware and software state to off. This function isn't
1385 * called by the core directly, only through drm_mode_config_reset().
1386 * It's not a helper hook only for historical reasons.
1388 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1389 * atomic state using this hook.
1391 void (*reset
)(struct drm_plane
*plane
);
1396 * This is the legacy entry point to update a property attached to the
1399 * Drivers implementing atomic modeset should use
1400 * drm_atomic_helper_plane_set_property() to implement this hook.
1402 * This callback is optional if the driver does not support any legacy
1403 * driver-private properties.
1407 * 0 on success or a negative error code on failure.
1409 int (*set_property
)(struct drm_plane
*plane
,
1410 struct drm_property
*property
, uint64_t val
);
1413 * @atomic_duplicate_state:
1415 * Duplicate the current atomic state for this plane and return it.
1416 * The core and helpers gurantee that any atomic state duplicated with
1417 * this hook and still owned by the caller (i.e. not transferred to the
1418 * driver by calling ->atomic_commit() from struct
1419 * &drm_mode_config_funcs) will be cleaned up by calling the
1420 * @atomic_destroy_state hook in this structure.
1422 * Atomic drivers which don't subclass struct &drm_plane_state should use
1423 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1424 * state structure to extend it with driver-private state should use
1425 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1426 * duplicated in a consistent fashion across drivers.
1428 * It is an error to call this hook before plane->state has been
1429 * initialized correctly.
1433 * If the duplicate state references refcounted resources this hook must
1434 * acquire a reference for each of them. The driver must release these
1435 * references again in @atomic_destroy_state.
1439 * Duplicated atomic state or NULL when the allocation failed.
1441 struct drm_plane_state
*(*atomic_duplicate_state
)(struct drm_plane
*plane
);
1444 * @atomic_destroy_state:
1446 * Destroy a state duplicated with @atomic_duplicate_state and release
1447 * or unreference all resources it references
1449 void (*atomic_destroy_state
)(struct drm_plane
*plane
,
1450 struct drm_plane_state
*state
);
1453 * @atomic_set_property:
1455 * Decode a driver-private property value and store the decoded value
1456 * into the passed-in state structure. Since the atomic core decodes all
1457 * standardized properties (even for extensions beyond the core set of
1458 * properties which might not be implemented by all drivers) this
1459 * requires drivers to subclass the state structure.
1461 * Such driver-private properties should really only be implemented for
1462 * truly hardware/vendor specific state. Instead it is preferred to
1463 * standardize atomic extension and decode the properties used to expose
1464 * such an extension in the core.
1466 * Do not call this function directly, use
1467 * drm_atomic_plane_set_property() instead.
1469 * This callback is optional if the driver does not support any
1470 * driver-private atomic properties.
1474 * This function is called in the state assembly phase of atomic
1475 * modesets, which can be aborted for any reason (including on
1476 * userspace's request to just check whether a configuration would be
1477 * possible). Drivers MUST NOT touch any persistent state (hardware or
1478 * software) or data structures except the passed in @state parameter.
1480 * Also since userspace controls in which order properties are set this
1481 * function must not do any input validation (since the state update is
1482 * incomplete and hence likely inconsistent). Instead any such input
1483 * validation must be done in the various atomic_check callbacks.
1487 * 0 if the property has been found, -EINVAL if the property isn't
1488 * implemented by the driver (which shouldn't ever happen, the core only
1489 * asks for properties attached to this plane). No other validation is
1490 * allowed by the driver. The core already checks that the property
1491 * value is within the range (integer, valid enum value, ...) the driver
1492 * set when registering the property.
1494 int (*atomic_set_property
)(struct drm_plane
*plane
,
1495 struct drm_plane_state
*state
,
1496 struct drm_property
*property
,
1500 * @atomic_get_property:
1502 * Reads out the decoded driver-private property. This is used to
1503 * implement the GETPLANE IOCTL.
1505 * Do not call this function directly, use
1506 * drm_atomic_plane_get_property() instead.
1508 * This callback is optional if the driver does not support any
1509 * driver-private atomic properties.
1513 * 0 on success, -EINVAL if the property isn't implemented by the
1514 * driver (which should never happen, the core only asks for
1515 * properties attached to this plane).
1517 int (*atomic_get_property
)(struct drm_plane
*plane
,
1518 const struct drm_plane_state
*state
,
1519 struct drm_property
*property
,
1523 enum drm_plane_type
{
1524 DRM_PLANE_TYPE_OVERLAY
,
1525 DRM_PLANE_TYPE_PRIMARY
,
1526 DRM_PLANE_TYPE_CURSOR
,
1531 * struct drm_plane - central DRM plane control structure
1532 * @dev: DRM device this plane belongs to
1533 * @head: for list management
1534 * @name: human readable name, can be overwritten by the driver
1535 * @base: base mode object
1536 * @possible_crtcs: pipes this plane can be bound to
1537 * @format_types: array of formats supported by this plane
1538 * @format_count: number of formats supported
1539 * @format_default: driver hasn't supplied supported formats for the plane
1540 * @crtc: currently bound CRTC
1541 * @fb: currently bound fb
1542 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1543 * drm_mode_set_config_internal() to implement correct refcounting.
1544 * @funcs: helper functions
1545 * @properties: property tracking for this plane
1546 * @type: type of plane (overlay, primary, cursor)
1547 * @state: current atomic state for this plane
1548 * @helper_private: mid-layer private data
1551 struct drm_device
*dev
;
1552 struct list_head head
;
1559 * Protects modeset plane state, together with the mutex of &drm_crtc
1560 * this plane is linked to (when active, getting actived or getting
1563 struct drm_modeset_lock mutex
;
1565 struct drm_mode_object base
;
1567 uint32_t possible_crtcs
;
1568 uint32_t *format_types
;
1569 unsigned int format_count
;
1570 bool format_default
;
1572 struct drm_crtc
*crtc
;
1573 struct drm_framebuffer
*fb
;
1575 struct drm_framebuffer
*old_fb
;
1577 const struct drm_plane_funcs
*funcs
;
1579 struct drm_object_properties properties
;
1581 enum drm_plane_type type
;
1583 /* position inside the mode_config.list, can be used as a [] idx */
1586 const struct drm_plane_helper_funcs
*helper_private
;
1588 struct drm_plane_state
*state
;
1592 * struct drm_bridge_funcs - drm_bridge control functions
1593 * @attach: Called during drm_bridge_attach
1595 struct drm_bridge_funcs
{
1596 int (*attach
)(struct drm_bridge
*bridge
);
1601 * This callback is used to validate and adjust a mode. The paramater
1602 * mode is the display mode that should be fed to the next element in
1603 * the display chain, either the final &drm_connector or the next
1604 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1605 * requires. It can be modified by this callback and does not need to
1608 * This is the only hook that allows a bridge to reject a modeset. If
1609 * this function passes all other callbacks must succeed for this
1614 * This function is called in the check phase of atomic modesets, which
1615 * can be aborted for any reason (including on userspace's request to
1616 * just check whether a configuration would be possible). Drivers MUST
1617 * NOT touch any persistent state (hardware or software) or data
1618 * structures except the passed in @state parameter.
1622 * True if an acceptable configuration is possible, false if the modeset
1623 * operation should be rejected.
1625 bool (*mode_fixup
)(struct drm_bridge
*bridge
,
1626 const struct drm_display_mode
*mode
,
1627 struct drm_display_mode
*adjusted_mode
);
1631 * This callback should disable the bridge. It is called right before
1632 * the preceding element in the display pipe is disabled. If the
1633 * preceding element is a bridge this means it's called before that
1634 * bridge's ->disable() function. If the preceding element is a
1635 * &drm_encoder it's called right before the encoder's ->disable(),
1636 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1638 * The bridge can assume that the display pipe (i.e. clocks and timing
1639 * signals) feeding it is still running when this callback is called.
1641 * The disable callback is optional.
1643 void (*disable
)(struct drm_bridge
*bridge
);
1648 * This callback should disable the bridge. It is called right after
1649 * the preceding element in the display pipe is disabled. If the
1650 * preceding element is a bridge this means it's called after that
1651 * bridge's ->post_disable() function. If the preceding element is a
1652 * &drm_encoder it's called right after the encoder's ->disable(),
1653 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1655 * The bridge must assume that the display pipe (i.e. clocks and timing
1656 * singals) feeding it is no longer running when this callback is
1659 * The post_disable callback is optional.
1661 void (*post_disable
)(struct drm_bridge
*bridge
);
1666 * This callback should set the given mode on the bridge. It is called
1667 * after the ->mode_set() callback for the preceding element in the
1668 * display pipeline has been called already. The display pipe (i.e.
1669 * clocks and timing signals) is off when this function is called.
1671 void (*mode_set
)(struct drm_bridge
*bridge
,
1672 struct drm_display_mode
*mode
,
1673 struct drm_display_mode
*adjusted_mode
);
1677 * This callback should enable the bridge. It is called right before
1678 * the preceding element in the display pipe is enabled. If the
1679 * preceding element is a bridge this means it's called before that
1680 * bridge's ->pre_enable() function. If the preceding element is a
1681 * &drm_encoder it's called right before the encoder's ->enable(),
1682 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1684 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1685 * will not yet be running when this callback is called. The bridge must
1686 * not enable the display link feeding the next bridge in the chain (if
1687 * there is one) when this callback is called.
1689 * The pre_enable callback is optional.
1691 void (*pre_enable
)(struct drm_bridge
*bridge
);
1696 * This callback should enable the bridge. It is called right after
1697 * the preceding element in the display pipe is enabled. If the
1698 * preceding element is a bridge this means it's called after that
1699 * bridge's ->enable() function. If the preceding element is a
1700 * &drm_encoder it's called right after the encoder's ->enable(),
1701 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1703 * The bridge can assume that the display pipe (i.e. clocks and timing
1704 * signals) feeding it is running when this callback is called. This
1705 * callback must enable the display link feeding the next bridge in the
1706 * chain if there is one.
1708 * The enable callback is optional.
1710 void (*enable
)(struct drm_bridge
*bridge
);
1714 * struct drm_bridge - central DRM bridge control structure
1715 * @dev: DRM device this bridge belongs to
1716 * @encoder: encoder to which this bridge is connected
1717 * @next: the next bridge in the encoder chain
1718 * @of_node: device node pointer to the bridge
1719 * @list: to keep track of all added bridges
1720 * @funcs: control functions
1721 * @driver_private: pointer to the bridge driver's internal context
1724 struct drm_device
*dev
;
1725 struct drm_encoder
*encoder
;
1726 struct drm_bridge
*next
;
1728 struct device_node
*of_node
;
1730 struct list_head list
;
1732 const struct drm_bridge_funcs
*funcs
;
1733 void *driver_private
;
1736 struct __drm_planes_state
{
1737 struct drm_plane
*ptr
;
1738 struct drm_plane_state
*state
;
1741 struct __drm_crtcs_state
{
1742 struct drm_crtc
*ptr
;
1743 struct drm_crtc_state
*state
;
1746 struct __drm_connnectors_state
{
1747 struct drm_connector
*ptr
;
1748 struct drm_connector_state
*state
;
1752 * struct drm_atomic_state - the global state object for atomic updates
1753 * @dev: parent DRM device
1754 * @allow_modeset: allow full modeset
1755 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
1756 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
1757 * @planes: pointer to array of structures with per-plane data
1758 * @crtcs: pointer to array of CRTC pointers
1759 * @num_connector: size of the @connectors and @connector_states arrays
1760 * @connectors: pointer to array of structures with per-connector data
1761 * @acquire_ctx: acquire context for this atomic modeset state update
1763 struct drm_atomic_state
{
1764 struct drm_device
*dev
;
1765 bool allow_modeset
: 1;
1766 bool legacy_cursor_update
: 1;
1767 bool legacy_set_config
: 1;
1768 struct __drm_planes_state
*planes
;
1769 struct __drm_crtcs_state
*crtcs
;
1771 struct __drm_connnectors_state
*connectors
;
1773 struct drm_modeset_acquire_ctx
*acquire_ctx
;
1778 * struct drm_mode_set - new values for a CRTC config change
1779 * @fb: framebuffer to use for new config
1780 * @crtc: CRTC whose configuration we're about to change
1781 * @mode: mode timings to use
1782 * @x: position of this CRTC relative to @fb
1783 * @y: position of this CRTC relative to @fb
1784 * @connectors: array of connectors to drive with this CRTC if possible
1785 * @num_connectors: size of @connectors array
1787 * Represents a single crtc the connectors that it drives with what mode
1788 * and from which framebuffer it scans out from.
1790 * This is used to set modes.
1792 struct drm_mode_set
{
1793 struct drm_framebuffer
*fb
;
1794 struct drm_crtc
*crtc
;
1795 struct drm_display_mode
*mode
;
1800 struct drm_connector
**connectors
;
1801 size_t num_connectors
;
1805 * struct drm_mode_config_funcs - basic driver provided mode setting functions
1807 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1810 struct drm_mode_config_funcs
{
1814 * Create a new framebuffer object. The core does basic checks on the
1815 * requested metadata, but most of that is left to the driver. See
1816 * struct &drm_mode_fb_cmd2 for details.
1818 * If the parameters are deemed valid and the backing storage objects in
1819 * the underlying memory manager all exist, then the driver allocates
1820 * a new &drm_framebuffer structure, subclassed to contain
1821 * driver-specific information (like the internal native buffer object
1822 * references). It also needs to fill out all relevant metadata, which
1823 * should be done by calling drm_helper_mode_fill_fb_struct().
1825 * The initialization is finalized by calling drm_framebuffer_init(),
1826 * which registers the framebuffer and makes it accessible to other
1831 * A new framebuffer with an initial reference count of 1 or a negative
1832 * error code encoded with ERR_PTR().
1834 struct drm_framebuffer
*(*fb_create
)(struct drm_device
*dev
,
1835 struct drm_file
*file_priv
,
1836 const struct drm_mode_fb_cmd2
*mode_cmd
);
1839 * @output_poll_changed:
1841 * Callback used by helpers to inform the driver of output configuration
1844 * Drivers implementing fbdev emulation with the helpers can call
1845 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1846 * helper of output changes.
1850 * Except that there's no vtable for device-level helper callbacks
1851 * there's no reason this is a core function.
1853 void (*output_poll_changed
)(struct drm_device
*dev
);
1858 * This is the only hook to validate an atomic modeset update. This
1859 * function must reject any modeset and state changes which the hardware
1860 * or driver doesn't support. This includes but is of course not limited
1863 * - Checking that the modes, framebuffers, scaling and placement
1864 * requirements and so on are within the limits of the hardware.
1866 * - Checking that any hidden shared resources are not oversubscribed.
1867 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1868 * display fifo space (where shared between planes or maybe even
1871 * - Checking that virtualized resources exported to userspace are not
1872 * oversubscribed. For various reasons it can make sense to expose
1873 * more planes, crtcs or encoders than which are physically there. One
1874 * example is dual-pipe operations (which generally should be hidden
1875 * from userspace if when lockstepped in hardware, exposed otherwise),
1876 * where a plane might need 1 hardware plane (if it's just on one
1877 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1878 * shared a hardware plane with a 2nd plane (if there's a compatible
1879 * plane requested on the area handled by the other pipe).
1881 * - Check that any transitional state is possible and that if
1882 * requested, the update can indeed be done in the vblank period
1883 * without temporarily disabling some functions.
1885 * - Check any other constraints the driver or hardware might have.
1887 * - This callback also needs to correctly fill out the &drm_crtc_state
1888 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1889 * reflects the nature of the possible update and returns true if and
1890 * only if the update cannot be applied without tearing within one
1891 * vblank on that CRTC. The core uses that information to reject
1892 * updates which require a full modeset (i.e. blanking the screen, or
1893 * at least pausing updates for a substantial amount of time) if
1894 * userspace has disallowed that in its request.
1896 * - The driver also does not need to repeat basic input validation
1897 * like done for the corresponding legacy entry points. The core does
1898 * that before calling this hook.
1900 * See the documentation of @atomic_commit for an exhaustive list of
1901 * error conditions which don't have to be checked at the
1902 * ->atomic_check() stage?
1904 * See the documentation for struct &drm_atomic_state for how exactly
1905 * an atomic modeset update is described.
1907 * Drivers using the atomic helpers can implement this hook using
1908 * drm_atomic_helper_check(), or one of the exported sub-functions of
1913 * 0 on success or one of the below negative error codes:
1915 * - -EINVAL, if any of the above constraints are violated.
1917 * - -EDEADLK, when returned from an attempt to acquire an additional
1918 * &drm_modeset_lock through drm_modeset_lock().
1920 * - -ENOMEM, if allocating additional state sub-structures failed due
1921 * to lack of memory.
1923 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1924 * This can either be due to a pending signal, or because the driver
1925 * needs to completely bail out to recover from an exceptional
1926 * situation like a GPU hang. From a userspace point all errors are
1929 int (*atomic_check
)(struct drm_device
*dev
,
1930 struct drm_atomic_state
*state
);
1935 * This is the only hook to commit an atomic modeset update. The core
1936 * guarantees that @atomic_check has been called successfully before
1937 * calling this function, and that nothing has been changed in the
1940 * See the documentation for struct &drm_atomic_state for how exactly
1941 * an atomic modeset update is described.
1943 * Drivers using the atomic helpers can implement this hook using
1944 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1947 * Nonblocking commits (as indicated with the nonblock parameter) must
1948 * do any preparatory work which might result in an unsuccessful commit
1949 * in the context of this callback. The only exceptions are hardware
1950 * errors resulting in -EIO. But even in that case the driver must
1951 * ensure that the display pipe is at least running, to avoid
1952 * compositors crashing when pageflips don't work. Anything else,
1953 * specifically committing the update to the hardware, should be done
1954 * without blocking the caller. For updates which do not require a
1955 * modeset this must be guaranteed.
1957 * The driver must wait for any pending rendering to the new
1958 * framebuffers to complete before executing the flip. It should also
1959 * wait for any pending rendering from other drivers if the underlying
1960 * buffer is a shared dma-buf. Nonblocking commits must not wait for
1961 * rendering in the context of this callback.
1963 * An application can request to be notified when the atomic commit has
1964 * completed. These events are per-CRTC and can be distinguished by the
1965 * CRTC index supplied in &drm_event to userspace.
1967 * The drm core will supply a struct &drm_event in the event
1968 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1969 * drm_crtc_send_vblank_event() function, which the driver should call on
1970 * the provided event upon completion of the atomic commit. Note that if
1971 * the driver supports vblank signalling and timestamping the vblank
1972 * counters and timestamps must agree with the ones returned from page
1973 * flip events. With the current vblank helper infrastructure this can
1974 * be achieved by holding a vblank reference while the page flip is
1975 * pending, acquired through drm_crtc_vblank_get() and released with
1976 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1977 * counter and timestamp tracking though, e.g. if they have accurate
1978 * timestamp registers in hardware.
1982 * Drivers are not allowed to shut down any display pipe successfully
1983 * enabled through an atomic commit on their own. Doing so can result in
1984 * compositors crashing if a page flip is suddenly rejected because the
1989 * 0 on success or one of the below negative error codes:
1991 * - -EBUSY, if a nonblocking updated is requested and there is
1992 * an earlier updated pending. Drivers are allowed to support a queue
1993 * of outstanding updates, but currently no driver supports that.
1994 * Note that drivers must wait for preceding updates to complete if a
1995 * synchronous update is requested, they are not allowed to fail the
1996 * commit in that case.
1998 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1999 * this can happen when trying to pin framebuffers, which must only
2000 * be done when committing the state.
2002 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
2003 * that the driver has run out of vram, iommu space or similar GPU
2004 * address space needed for framebuffer.
2006 * - -EIO, if the hardware completely died.
2008 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2009 * This can either be due to a pending signal, or because the driver
2010 * needs to completely bail out to recover from an exceptional
2011 * situation like a GPU hang. From a userspace point of view all errors are
2014 * This list is exhaustive. Specifically this hook is not allowed to
2015 * return -EINVAL (any invalid requests should be caught in
2016 * @atomic_check) or -EDEADLK (this function must not acquire
2017 * additional modeset locks).
2019 int (*atomic_commit
)(struct drm_device
*dev
,
2020 struct drm_atomic_state
*state
,
2024 * @atomic_state_alloc:
2026 * This optional hook can be used by drivers that want to subclass struct
2027 * &drm_atomic_state to be able to track their own driver-private global
2028 * state easily. If this hook is implemented, drivers must also
2029 * implement @atomic_state_clear and @atomic_state_free.
2033 * A new &drm_atomic_state on success or NULL on failure.
2035 struct drm_atomic_state
*(*atomic_state_alloc
)(struct drm_device
*dev
);
2038 * @atomic_state_clear:
2040 * This hook must clear any driver private state duplicated into the
2041 * passed-in &drm_atomic_state. This hook is called when the caller
2042 * encountered a &drm_modeset_lock deadlock and needs to drop all
2043 * already acquired locks as part of the deadlock avoidance dance
2044 * implemented in drm_modeset_lock_backoff().
2046 * Any duplicated state must be invalidated since a concurrent atomic
2047 * update might change it, and the drm atomic interfaces always apply
2048 * updates as relative changes to the current state.
2050 * Drivers that implement this must call drm_atomic_state_default_clear()
2051 * to clear common state.
2053 void (*atomic_state_clear
)(struct drm_atomic_state
*state
);
2056 * @atomic_state_free:
2058 * This hook needs driver private resources and the &drm_atomic_state
2059 * itself. Note that the core first calls drm_atomic_state_clear() to
2060 * avoid code duplicate between the clear and free hooks.
2062 * Drivers that implement this must call drm_atomic_state_default_free()
2063 * to release common resources.
2065 void (*atomic_state_free
)(struct drm_atomic_state
*state
);
2069 * struct drm_mode_config - Mode configuration control structure
2070 * @mutex: mutex protecting KMS related lists and structures
2071 * @connection_mutex: ww mutex protecting connector state and routing
2072 * @acquire_ctx: global implicit acquire context used by atomic drivers for
2074 * @fb_lock: mutex to protect fb state and lists
2075 * @num_fb: number of fbs available
2076 * @fb_list: list of framebuffers available
2077 * @num_connector: number of connectors on this device
2078 * @connector_list: list of connector objects
2079 * @num_encoder: number of encoders on this device
2080 * @encoder_list: list of encoder objects
2081 * @num_overlay_plane: number of overlay planes on this device
2082 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2083 * @plane_list: list of plane objects
2084 * @num_crtc: number of CRTCs on this device
2085 * @crtc_list: list of CRTC objects
2086 * @property_list: list of property objects
2087 * @min_width: minimum pixel width on this device
2088 * @min_height: minimum pixel height on this device
2089 * @max_width: maximum pixel width on this device
2090 * @max_height: maximum pixel height on this device
2091 * @funcs: core driver provided mode setting functions
2092 * @fb_base: base address of the framebuffer
2093 * @poll_enabled: track polling support for this device
2094 * @poll_running: track polling status for this device
2095 * @delayed_event: track delayed poll uevent deliver for this device
2096 * @output_poll_work: delayed work for polling in process context
2097 * @property_blob_list: list of all the blob property objects
2098 * @blob_lock: mutex for blob property allocation and management
2099 * @*_property: core property tracking
2100 * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear
2102 * @degamma_lut_size_property: size of the degamma LUT as supported by the
2103 * driver (read-only)
2104 * @ctm_property: Matrix used to convert colors after the lookup in the
2106 * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to
2107 * the gamma space of the connected screen (read-only)
2108 * @gamma_lut_size_property: size of the gamma LUT as supported by the driver
2109 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2110 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2111 * @async_page_flip: does this device support async flips on the primary plane?
2112 * @cursor_width: hint to userspace for max cursor width
2113 * @cursor_height: hint to userspace for max cursor height
2115 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2116 * enumerated by the driver are added here, as are global properties. Some
2117 * global restrictions are also here, e.g. dimension restrictions.
2119 struct drm_mode_config
{
2120 struct mutex mutex
; /* protects configuration (mode lists etc.) */
2121 struct drm_modeset_lock connection_mutex
; /* protects connector->encoder and encoder->crtc links */
2122 struct drm_modeset_acquire_ctx
*acquire_ctx
; /* for legacy _lock_all() / _unlock_all() */
2127 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
2130 struct mutex idr_mutex
;
2135 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
2136 * connector, modes - just makes life easier to have only one.
2138 struct idr crtc_idr
;
2143 * Use this idr for allocating new IDs for tiled sinks like use in some
2144 * high-res DP MST screens.
2146 struct idr tile_idr
;
2148 struct mutex fb_lock
; /* proctects global and per-file fb lists */
2150 struct list_head fb_list
;
2153 struct ida connector_ida
;
2154 struct list_head connector_list
;
2156 struct list_head encoder_list
;
2159 * Track # of overlay planes separately from # of total planes. By
2160 * default we only advertise overlay planes to userspace; if userspace
2161 * sets the "universal plane" capability bit, we'll go ahead and
2162 * expose all planes.
2164 int num_overlay_plane
;
2165 int num_total_plane
;
2166 struct list_head plane_list
;
2169 struct list_head crtc_list
;
2171 struct list_head property_list
;
2173 int min_width
, min_height
;
2174 int max_width
, max_height
;
2175 const struct drm_mode_config_funcs
*funcs
;
2176 resource_size_t fb_base
;
2178 /* output poll support */
2182 struct delayed_work output_poll_work
;
2184 struct mutex blob_lock
;
2186 /* pointers to standard properties */
2187 struct list_head property_blob_list
;
2188 struct drm_property
*edid_property
;
2189 struct drm_property
*dpms_property
;
2190 struct drm_property
*path_property
;
2191 struct drm_property
*tile_property
;
2192 struct drm_property
*plane_type_property
;
2193 struct drm_property
*rotation_property
;
2194 struct drm_property
*prop_src_x
;
2195 struct drm_property
*prop_src_y
;
2196 struct drm_property
*prop_src_w
;
2197 struct drm_property
*prop_src_h
;
2198 struct drm_property
*prop_crtc_x
;
2199 struct drm_property
*prop_crtc_y
;
2200 struct drm_property
*prop_crtc_w
;
2201 struct drm_property
*prop_crtc_h
;
2202 struct drm_property
*prop_fb_id
;
2203 struct drm_property
*prop_crtc_id
;
2204 struct drm_property
*prop_active
;
2205 struct drm_property
*prop_mode_id
;
2207 /* DVI-I properties */
2208 struct drm_property
*dvi_i_subconnector_property
;
2209 struct drm_property
*dvi_i_select_subconnector_property
;
2212 struct drm_property
*tv_subconnector_property
;
2213 struct drm_property
*tv_select_subconnector_property
;
2214 struct drm_property
*tv_mode_property
;
2215 struct drm_property
*tv_left_margin_property
;
2216 struct drm_property
*tv_right_margin_property
;
2217 struct drm_property
*tv_top_margin_property
;
2218 struct drm_property
*tv_bottom_margin_property
;
2219 struct drm_property
*tv_brightness_property
;
2220 struct drm_property
*tv_contrast_property
;
2221 struct drm_property
*tv_flicker_reduction_property
;
2222 struct drm_property
*tv_overscan_property
;
2223 struct drm_property
*tv_saturation_property
;
2224 struct drm_property
*tv_hue_property
;
2226 /* Optional properties */
2227 struct drm_property
*scaling_mode_property
;
2228 struct drm_property
*aspect_ratio_property
;
2229 struct drm_property
*dirty_info_property
;
2231 /* Optional color correction properties */
2232 struct drm_property
*degamma_lut_property
;
2233 struct drm_property
*degamma_lut_size_property
;
2234 struct drm_property
*ctm_property
;
2235 struct drm_property
*gamma_lut_property
;
2236 struct drm_property
*gamma_lut_size_property
;
2238 /* properties for virtual machine layout */
2239 struct drm_property
*suggested_x_property
;
2240 struct drm_property
*suggested_y_property
;
2242 /* dumb ioctl parameters */
2243 uint32_t preferred_depth
, prefer_shadow
;
2245 /* whether async page flip is supported or not */
2246 bool async_page_flip
;
2249 * @allow_fb_modifiers:
2251 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
2253 bool allow_fb_modifiers
;
2256 uint32_t cursor_width
, cursor_height
;
2260 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2261 * @plane: the loop cursor
2262 * @dev: the DRM device
2263 * @plane_mask: bitmask of plane indices
2265 * Iterate over all planes specified by bitmask.
2267 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
2268 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
2269 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
2272 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2273 * @encoder: the loop cursor
2274 * @dev: the DRM device
2275 * @encoder_mask: bitmask of encoder indices
2277 * Iterate over all encoders specified by bitmask.
2279 #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2280 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2281 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
2283 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2284 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
2285 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2286 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2287 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2288 #define obj_to_property(x) container_of(x, struct drm_property, base)
2289 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
2290 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
2292 struct drm_prop_enum_list
{
2297 extern __printf(6, 7)
2298 int drm_crtc_init_with_planes(struct drm_device
*dev
,
2299 struct drm_crtc
*crtc
,
2300 struct drm_plane
*primary
,
2301 struct drm_plane
*cursor
,
2302 const struct drm_crtc_funcs
*funcs
,
2303 const char *name
, ...);
2304 extern void drm_crtc_cleanup(struct drm_crtc
*crtc
);
2307 * drm_crtc_index - find the index of a registered CRTC
2308 * @crtc: CRTC to find index for
2310 * Given a registered CRTC, return the index of that CRTC within a DRM
2311 * device's list of CRTCs.
2313 static inline unsigned int drm_crtc_index(struct drm_crtc
*crtc
)
2319 * drm_crtc_mask - find the mask of a registered CRTC
2320 * @crtc: CRTC to find mask for
2322 * Given a registered CRTC, return the mask bit of that CRTC for an
2323 * encoder's possible_crtcs field.
2325 static inline uint32_t drm_crtc_mask(struct drm_crtc
*crtc
)
2327 return 1 << drm_crtc_index(crtc
);
2330 extern void drm_connector_ida_init(void);
2331 extern void drm_connector_ida_destroy(void);
2332 extern int drm_connector_init(struct drm_device
*dev
,
2333 struct drm_connector
*connector
,
2334 const struct drm_connector_funcs
*funcs
,
2335 int connector_type
);
2336 int drm_connector_register(struct drm_connector
*connector
);
2337 void drm_connector_unregister(struct drm_connector
*connector
);
2339 extern void drm_connector_cleanup(struct drm_connector
*connector
);
2340 static inline unsigned drm_connector_index(struct drm_connector
*connector
)
2342 return connector
->connector_id
;
2345 /* helpers to {un}register all connectors from sysfs for device */
2346 extern int drm_connector_register_all(struct drm_device
*dev
);
2347 extern void drm_connector_unregister_all(struct drm_device
*dev
);
2349 extern int drm_bridge_add(struct drm_bridge
*bridge
);
2350 extern void drm_bridge_remove(struct drm_bridge
*bridge
);
2351 extern struct drm_bridge
*of_drm_find_bridge(struct device_node
*np
);
2352 extern int drm_bridge_attach(struct drm_device
*dev
, struct drm_bridge
*bridge
);
2354 bool drm_bridge_mode_fixup(struct drm_bridge
*bridge
,
2355 const struct drm_display_mode
*mode
,
2356 struct drm_display_mode
*adjusted_mode
);
2357 void drm_bridge_disable(struct drm_bridge
*bridge
);
2358 void drm_bridge_post_disable(struct drm_bridge
*bridge
);
2359 void drm_bridge_mode_set(struct drm_bridge
*bridge
,
2360 struct drm_display_mode
*mode
,
2361 struct drm_display_mode
*adjusted_mode
);
2362 void drm_bridge_pre_enable(struct drm_bridge
*bridge
);
2363 void drm_bridge_enable(struct drm_bridge
*bridge
);
2365 extern __printf(5, 6)
2366 int drm_encoder_init(struct drm_device
*dev
,
2367 struct drm_encoder
*encoder
,
2368 const struct drm_encoder_funcs
*funcs
,
2369 int encoder_type
, const char *name
, ...);
2372 * drm_encoder_index - find the index of a registered encoder
2373 * @encoder: encoder to find index for
2375 * Given a registered encoder, return the index of that encoder within a DRM
2376 * device's list of encoders.
2378 static inline unsigned int drm_encoder_index(struct drm_encoder
*encoder
)
2380 return encoder
->index
;
2384 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2385 * @encoder: encoder to test
2386 * @crtc: crtc to test
2388 * Return false if @encoder can't be driven by @crtc, true otherwise.
2390 static inline bool drm_encoder_crtc_ok(struct drm_encoder
*encoder
,
2391 struct drm_crtc
*crtc
)
2393 return !!(encoder
->possible_crtcs
& drm_crtc_mask(crtc
));
2396 extern __printf(8, 9)
2397 int drm_universal_plane_init(struct drm_device
*dev
,
2398 struct drm_plane
*plane
,
2399 unsigned long possible_crtcs
,
2400 const struct drm_plane_funcs
*funcs
,
2401 const uint32_t *formats
,
2402 unsigned int format_count
,
2403 enum drm_plane_type type
,
2404 const char *name
, ...);
2405 extern int drm_plane_init(struct drm_device
*dev
,
2406 struct drm_plane
*plane
,
2407 unsigned long possible_crtcs
,
2408 const struct drm_plane_funcs
*funcs
,
2409 const uint32_t *formats
, unsigned int format_count
,
2411 extern void drm_plane_cleanup(struct drm_plane
*plane
);
2414 * drm_plane_index - find the index of a registered plane
2415 * @plane: plane to find index for
2417 * Given a registered plane, return the index of that plane within a DRM
2418 * device's list of planes.
2420 static inline unsigned int drm_plane_index(struct drm_plane
*plane
)
2422 return plane
->index
;
2424 extern struct drm_plane
* drm_plane_from_index(struct drm_device
*dev
, int idx
);
2425 extern void drm_plane_force_disable(struct drm_plane
*plane
);
2426 extern int drm_plane_check_pixel_format(const struct drm_plane
*plane
,
2428 extern void drm_crtc_get_hv_timing(const struct drm_display_mode
*mode
,
2429 int *hdisplay
, int *vdisplay
);
2430 extern int drm_crtc_check_viewport(const struct drm_crtc
*crtc
,
2432 const struct drm_display_mode
*mode
,
2433 const struct drm_framebuffer
*fb
);
2435 extern void drm_encoder_cleanup(struct drm_encoder
*encoder
);
2437 extern const char *drm_get_connector_status_name(enum drm_connector_status status
);
2438 extern const char *drm_get_subpixel_order_name(enum subpixel_order order
);
2439 extern const char *drm_get_dpms_name(int val
);
2440 extern const char *drm_get_dvi_i_subconnector_name(int val
);
2441 extern const char *drm_get_dvi_i_select_name(int val
);
2442 extern const char *drm_get_tv_subconnector_name(int val
);
2443 extern const char *drm_get_tv_select_name(int val
);
2444 extern void drm_fb_release(struct drm_file
*file_priv
);
2445 extern void drm_property_destroy_user_blobs(struct drm_device
*dev
,
2446 struct drm_file
*file_priv
);
2447 extern bool drm_probe_ddc(struct i2c_adapter
*adapter
);
2448 extern struct edid
*drm_get_edid(struct drm_connector
*connector
,
2449 struct i2c_adapter
*adapter
);
2450 extern struct edid
*drm_get_edid_switcheroo(struct drm_connector
*connector
,
2451 struct i2c_adapter
*adapter
);
2452 extern struct edid
*drm_edid_duplicate(const struct edid
*edid
);
2453 extern int drm_add_edid_modes(struct drm_connector
*connector
, struct edid
*edid
);
2454 extern void drm_mode_config_init(struct drm_device
*dev
);
2455 extern void drm_mode_config_reset(struct drm_device
*dev
);
2456 extern void drm_mode_config_cleanup(struct drm_device
*dev
);
2458 extern int drm_mode_connector_set_path_property(struct drm_connector
*connector
,
2460 int drm_mode_connector_set_tile_property(struct drm_connector
*connector
);
2461 extern int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2462 const struct edid
*edid
);
2464 extern int drm_display_info_set_bus_formats(struct drm_display_info
*info
,
2466 unsigned int num_formats
);
2468 static inline bool drm_property_type_is(struct drm_property
*property
,
2471 /* instanceof for props.. handles extended type vs original types: */
2472 if (property
->flags
& DRM_MODE_PROP_EXTENDED_TYPE
)
2473 return (property
->flags
& DRM_MODE_PROP_EXTENDED_TYPE
) == type
;
2474 return property
->flags
& type
;
2477 static inline bool drm_property_type_valid(struct drm_property
*property
)
2479 if (property
->flags
& DRM_MODE_PROP_EXTENDED_TYPE
)
2480 return !(property
->flags
& DRM_MODE_PROP_LEGACY_TYPE
);
2481 return !!(property
->flags
& DRM_MODE_PROP_LEGACY_TYPE
);
2484 extern int drm_object_property_set_value(struct drm_mode_object
*obj
,
2485 struct drm_property
*property
,
2487 extern int drm_object_property_get_value(struct drm_mode_object
*obj
,
2488 struct drm_property
*property
,
2490 extern int drm_framebuffer_init(struct drm_device
*dev
,
2491 struct drm_framebuffer
*fb
,
2492 const struct drm_framebuffer_funcs
*funcs
);
2493 extern struct drm_framebuffer
*drm_framebuffer_lookup(struct drm_device
*dev
,
2495 extern void drm_framebuffer_remove(struct drm_framebuffer
*fb
);
2496 extern void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
);
2497 extern void drm_framebuffer_unregister_private(struct drm_framebuffer
*fb
);
2499 extern void drm_object_attach_property(struct drm_mode_object
*obj
,
2500 struct drm_property
*property
,
2502 extern struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2503 const char *name
, int num_values
);
2504 extern struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2506 const struct drm_prop_enum_list
*props
,
2508 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2509 int flags
, const char *name
,
2510 const struct drm_prop_enum_list
*props
,
2512 uint64_t supported_bits
);
2513 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
2515 uint64_t min
, uint64_t max
);
2516 struct drm_property
*drm_property_create_signed_range(struct drm_device
*dev
,
2517 int flags
, const char *name
,
2518 int64_t min
, int64_t max
);
2519 struct drm_property
*drm_property_create_object(struct drm_device
*dev
,
2520 int flags
, const char *name
, uint32_t type
);
2521 struct drm_property
*drm_property_create_bool(struct drm_device
*dev
, int flags
,
2523 struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
,
2526 struct drm_property_blob
*drm_property_lookup_blob(struct drm_device
*dev
,
2528 struct drm_property_blob
*drm_property_reference_blob(struct drm_property_blob
*blob
);
2529 void drm_property_unreference_blob(struct drm_property_blob
*blob
);
2530 extern void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
);
2531 extern int drm_property_add_enum(struct drm_property
*property
, int index
,
2532 uint64_t value
, const char *name
);
2533 extern int drm_mode_create_dvi_i_properties(struct drm_device
*dev
);
2534 extern int drm_mode_create_tv_properties(struct drm_device
*dev
,
2535 unsigned int num_modes
,
2536 const char * const modes
[]);
2537 extern int drm_mode_create_scaling_mode_property(struct drm_device
*dev
);
2538 extern int drm_mode_create_aspect_ratio_property(struct drm_device
*dev
);
2539 extern int drm_mode_create_dirty_info_property(struct drm_device
*dev
);
2540 extern int drm_mode_create_suggested_offset_properties(struct drm_device
*dev
);
2541 extern bool drm_property_change_valid_get(struct drm_property
*property
,
2542 uint64_t value
, struct drm_mode_object
**ref
);
2543 extern void drm_property_change_valid_put(struct drm_property
*property
,
2544 struct drm_mode_object
*ref
);
2546 extern int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2547 struct drm_encoder
*encoder
);
2548 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
2550 extern struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
2551 uint32_t id
, uint32_t type
);
2552 void drm_mode_object_reference(struct drm_mode_object
*obj
);
2553 void drm_mode_object_unreference(struct drm_mode_object
*obj
);
2556 extern int drm_mode_getresources(struct drm_device
*dev
,
2557 void *data
, struct drm_file
*file_priv
);
2558 extern int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
2559 struct drm_file
*file_priv
);
2560 extern int drm_mode_getcrtc(struct drm_device
*dev
,
2561 void *data
, struct drm_file
*file_priv
);
2562 extern int drm_mode_getconnector(struct drm_device
*dev
,
2563 void *data
, struct drm_file
*file_priv
);
2564 extern int drm_mode_set_config_internal(struct drm_mode_set
*set
);
2565 extern int drm_mode_setcrtc(struct drm_device
*dev
,
2566 void *data
, struct drm_file
*file_priv
);
2567 extern int drm_mode_getplane(struct drm_device
*dev
,
2568 void *data
, struct drm_file
*file_priv
);
2569 extern int drm_mode_setplane(struct drm_device
*dev
,
2570 void *data
, struct drm_file
*file_priv
);
2571 extern int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2572 void *data
, struct drm_file
*file_priv
);
2573 extern int drm_mode_cursor2_ioctl(struct drm_device
*dev
,
2574 void *data
, struct drm_file
*file_priv
);
2575 extern int drm_mode_addfb(struct drm_device
*dev
,
2576 void *data
, struct drm_file
*file_priv
);
2577 extern int drm_mode_addfb2(struct drm_device
*dev
,
2578 void *data
, struct drm_file
*file_priv
);
2579 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
);
2580 extern int drm_mode_rmfb(struct drm_device
*dev
,
2581 void *data
, struct drm_file
*file_priv
);
2582 extern int drm_mode_getfb(struct drm_device
*dev
,
2583 void *data
, struct drm_file
*file_priv
);
2584 extern int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2585 void *data
, struct drm_file
*file_priv
);
2587 extern int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2588 void *data
, struct drm_file
*file_priv
);
2589 extern int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2590 void *data
, struct drm_file
*file_priv
);
2591 extern int drm_mode_createblob_ioctl(struct drm_device
*dev
,
2592 void *data
, struct drm_file
*file_priv
);
2593 extern int drm_mode_destroyblob_ioctl(struct drm_device
*dev
,
2594 void *data
, struct drm_file
*file_priv
);
2595 extern int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2596 void *data
, struct drm_file
*file_priv
);
2597 extern int drm_mode_getencoder(struct drm_device
*dev
,
2598 void *data
, struct drm_file
*file_priv
);
2599 extern int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
2600 void *data
, struct drm_file
*file_priv
);
2601 extern int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
2602 void *data
, struct drm_file
*file_priv
);
2603 extern u8
drm_match_cea_mode(const struct drm_display_mode
*to_match
);
2604 extern enum hdmi_picture_aspect
drm_get_cea_aspect_ratio(const u8 video_code
);
2605 extern bool drm_detect_hdmi_monitor(struct edid
*edid
);
2606 extern bool drm_detect_monitor_audio(struct edid
*edid
);
2607 extern bool drm_rgb_quant_range_selectable(struct edid
*edid
);
2608 extern int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
2609 void *data
, struct drm_file
*file_priv
);
2610 extern int drm_add_modes_noedid(struct drm_connector
*connector
,
2611 int hdisplay
, int vdisplay
);
2612 extern void drm_set_preferred_mode(struct drm_connector
*connector
,
2613 int hpref
, int vpref
);
2615 extern int drm_edid_header_is_valid(const u8
*raw_edid
);
2616 extern bool drm_edid_block_valid(u8
*raw_edid
, int block
, bool print_bad_edid
,
2617 bool *edid_corrupt
);
2618 extern bool drm_edid_is_valid(struct edid
*edid
);
2619 extern void drm_edid_get_monitor_name(struct edid
*edid
, char *name
,
2622 extern struct drm_tile_group
*drm_mode_create_tile_group(struct drm_device
*dev
,
2624 extern struct drm_tile_group
*drm_mode_get_tile_group(struct drm_device
*dev
,
2626 extern void drm_mode_put_tile_group(struct drm_device
*dev
,
2627 struct drm_tile_group
*tg
);
2628 struct drm_display_mode
*drm_mode_find_dmt(struct drm_device
*dev
,
2629 int hsize
, int vsize
, int fresh
,
2632 extern int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
2633 void *data
, struct drm_file
*file_priv
);
2634 extern int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
2635 void *data
, struct drm_file
*file_priv
);
2636 extern int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
2637 void *data
, struct drm_file
*file_priv
);
2638 extern int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
2639 struct drm_file
*file_priv
);
2640 extern int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
2641 struct drm_file
*file_priv
);
2642 extern int drm_mode_plane_set_obj_prop(struct drm_plane
*plane
,
2643 struct drm_property
*property
,
2645 extern int drm_mode_atomic_ioctl(struct drm_device
*dev
,
2646 void *data
, struct drm_file
*file_priv
);
2648 extern void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
2650 extern int drm_format_num_planes(uint32_t format
);
2651 extern int drm_format_plane_cpp(uint32_t format
, int plane
);
2652 extern int drm_format_horz_chroma_subsampling(uint32_t format
);
2653 extern int drm_format_vert_chroma_subsampling(uint32_t format
);
2654 extern int drm_format_plane_width(int width
, uint32_t format
, int plane
);
2655 extern int drm_format_plane_height(int height
, uint32_t format
, int plane
);
2656 extern const char *drm_get_format_name(uint32_t format
);
2657 extern struct drm_property
*drm_mode_create_rotation_property(struct drm_device
*dev
,
2658 unsigned int supported_rotations
);
2659 extern unsigned int drm_rotation_simplify(unsigned int rotation
,
2660 unsigned int supported_rotations
);
2661 extern void drm_crtc_enable_color_mgmt(struct drm_crtc
*crtc
,
2662 uint degamma_lut_size
,
2664 uint gamma_lut_size
);
2667 static inline struct drm_plane
*drm_plane_find(struct drm_device
*dev
,
2670 struct drm_mode_object
*mo
;
2671 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_PLANE
);
2672 return mo
? obj_to_plane(mo
) : NULL
;
2675 static inline struct drm_crtc
*drm_crtc_find(struct drm_device
*dev
,
2678 struct drm_mode_object
*mo
;
2679 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_CRTC
);
2680 return mo
? obj_to_crtc(mo
) : NULL
;
2683 static inline struct drm_encoder
*drm_encoder_find(struct drm_device
*dev
,
2686 struct drm_mode_object
*mo
;
2687 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
2688 return mo
? obj_to_encoder(mo
) : NULL
;
2692 * drm_connector_lookup - lookup connector object
2694 * @id: connector object id
2696 * This function looks up the connector object specified by id
2697 * add takes a reference to it.
2699 static inline struct drm_connector
*drm_connector_lookup(struct drm_device
*dev
,
2702 struct drm_mode_object
*mo
;
2703 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_CONNECTOR
);
2704 return mo
? obj_to_connector(mo
) : NULL
;
2707 static inline struct drm_property
*drm_property_find(struct drm_device
*dev
,
2710 struct drm_mode_object
*mo
;
2711 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_PROPERTY
);
2712 return mo
? obj_to_property(mo
) : NULL
;
2716 * Extract a degamma/gamma LUT value provided by user and round it to the
2717 * precision supported by the hardware.
2719 static inline uint32_t drm_color_lut_extract(uint32_t user_input
,
2720 uint32_t bit_precision
)
2722 uint32_t val
= user_input
;
2723 uint32_t max
= 0xffff >> (16 - bit_precision
);
2725 /* Round only if we're not using full precision. */
2726 if (bit_precision
< 16) {
2727 val
+= 1UL << (16 - bit_precision
- 1);
2728 val
>>= 16 - bit_precision
;
2731 return clamp_val(val
, 0, max
);
2735 * drm_framebuffer_reference - incr the fb refcnt
2738 * This functions increments the fb's refcount.
2740 static inline void drm_framebuffer_reference(struct drm_framebuffer
*fb
)
2742 drm_mode_object_reference(&fb
->base
);
2746 * drm_framebuffer_unreference - unref a framebuffer
2747 * @fb: framebuffer to unref
2749 * This functions decrements the fb's refcount and frees it if it drops to zero.
2751 static inline void drm_framebuffer_unreference(struct drm_framebuffer
*fb
)
2753 drm_mode_object_unreference(&fb
->base
);
2757 * drm_framebuffer_read_refcount - read the framebuffer reference count.
2760 * This functions returns the framebuffer's reference count.
2762 static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer
*fb
)
2764 return atomic_read(&fb
->base
.refcount
.refcount
);
2768 * drm_connector_reference - incr the connector refcnt
2769 * @connector: connector
2771 * This function increments the connector's refcount.
2773 static inline void drm_connector_reference(struct drm_connector
*connector
)
2775 drm_mode_object_reference(&connector
->base
);
2779 * drm_connector_unreference - unref a connector
2780 * @connector: connector to unref
2782 * This function decrements the connector's refcount and frees it if it drops to zero.
2784 static inline void drm_connector_unreference(struct drm_connector
*connector
)
2786 drm_mode_object_unreference(&connector
->base
);
2789 /* Plane list iterator for legacy (overlay only) planes. */
2790 #define drm_for_each_legacy_plane(plane, dev) \
2791 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
2792 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
2794 #define drm_for_each_plane(plane, dev) \
2795 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2797 #define drm_for_each_crtc(crtc, dev) \
2798 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2801 assert_drm_connector_list_read_locked(struct drm_mode_config
*mode_config
)
2804 * The connector hotadd/remove code currently grabs both locks when
2805 * updating lists. Hence readers need only hold either of them to be
2806 * safe and the check amounts to
2808 * WARN_ON(not_holding(A) && not_holding(B)).
2810 WARN_ON(!mutex_is_locked(&mode_config
->mutex
) &&
2811 !drm_modeset_is_locked(&mode_config
->connection_mutex
));
2814 #define drm_for_each_connector(connector, dev) \
2815 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2816 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2817 struct drm_connector, head); \
2818 &connector->head != (&(dev)->mode_config.connector_list); \
2819 connector = list_next_entry(connector, head))
2821 #define drm_for_each_encoder(encoder, dev) \
2822 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2824 #define drm_for_each_fb(fb, dev) \
2825 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2826 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2827 struct drm_framebuffer, head); \
2828 &fb->head != (&(dev)->mode_config.fb_list); \
2829 fb = list_next_entry(fb, head))
2831 #endif /* __DRM_CRTC_H__ */