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 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
49 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
50 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
51 #define DRM_MODE_OBJECT_MODE 0xdededede
52 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
53 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
54 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
55 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
56 #define DRM_MODE_OBJECT_ANY 0
58 struct drm_mode_object
{
61 struct drm_object_properties
*properties
;
64 #define DRM_OBJECT_MAX_PROPERTY 24
65 struct drm_object_properties
{
66 int count
, atomic_count
;
67 /* NOTE: if we ever start dynamically destroying properties (ie.
68 * not at drm_mode_config_cleanup() time), then we'd have to do
69 * a better job of detaching property from mode objects to avoid
70 * dangling property pointers:
72 struct drm_property
*properties
[DRM_OBJECT_MAX_PROPERTY
];
73 /* do not read/write values directly, but use drm_object_property_get_value()
74 * and drm_object_property_set_value():
76 uint64_t values
[DRM_OBJECT_MAX_PROPERTY
];
79 static inline int64_t U642I64(uint64_t val
)
81 return (int64_t)*((int64_t *)&val
);
83 static inline uint64_t I642U64(int64_t val
)
85 return (uint64_t)*((uint64_t *)&val
);
89 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
90 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
91 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
93 #define DRM_ROTATE_MASK 0x0f
94 #define DRM_ROTATE_0 0
95 #define DRM_ROTATE_90 1
96 #define DRM_ROTATE_180 2
97 #define DRM_ROTATE_270 3
98 #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
99 #define DRM_REFLECT_X 4
100 #define DRM_REFLECT_Y 5
102 enum drm_connector_force
{
103 DRM_FORCE_UNSPECIFIED
,
105 DRM_FORCE_ON
, /* force on analog part normally */
106 DRM_FORCE_ON_DIGITAL
, /* for DVI-I use digital connector */
109 #include <drm/drm_modes.h>
111 enum drm_connector_status
{
112 connector_status_connected
= 1,
113 connector_status_disconnected
= 2,
114 connector_status_unknown
= 3,
117 enum subpixel_order
{
119 SubPixelHorizontalRGB
,
120 SubPixelHorizontalBGR
,
126 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
127 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
128 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
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
;
151 /* Mask of supported hdmi deep color modes */
152 u8 edid_hdmi_dc_modes
;
157 /* data corresponds to displayid vend/prod/serial */
158 struct drm_tile_group
{
159 struct kref refcount
;
160 struct drm_device
*dev
;
166 * struct drm_framebuffer_funcs - framebuffer hooks
168 struct drm_framebuffer_funcs
{
172 * Clean up framebuffer resources, specifically also unreference the
173 * backing storage. The core guarantees to call this function for every
174 * framebuffer successfully created by ->fb_create() in
175 * &drm_mode_config_funcs.
177 void (*destroy
)(struct drm_framebuffer
*framebuffer
);
182 * Create a buffer handle in the driver-specific buffer manager (either
183 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
184 * the core to implement the GETFB IOCTL, which returns (for
185 * sufficiently priviledged user) also a native buffer handle. This can
186 * be used for seamless transitions between modesetting clients by
187 * copying the current screen contents to a private buffer and blending
188 * between that and the new contents.
192 * 0 on success or a negative error code on failure.
194 int (*create_handle
)(struct drm_framebuffer
*fb
,
195 struct drm_file
*file_priv
,
196 unsigned int *handle
);
200 * Optional callback for the dirty fb IOCTL.
202 * Userspace can notify the driver via this callback that an area of the
203 * framebuffer has changed and should be flushed to the display
204 * hardware. This can also be used internally, e.g. by the fbdev
205 * emulation, though that's not the case currently.
207 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
208 * for more information as all the semantics and arguments have a one to
209 * one mapping on this function.
213 * 0 on success or a negative error code on failure.
215 int (*dirty
)(struct drm_framebuffer
*framebuffer
,
216 struct drm_file
*file_priv
, unsigned flags
,
217 unsigned color
, struct drm_clip_rect
*clips
,
221 struct drm_framebuffer
{
222 struct drm_device
*dev
;
224 * Note that the fb is refcounted for the benefit of driver internals,
225 * for example some hw, disabling a CRTC/plane is asynchronous, and
226 * scanout does not actually complete until the next vblank. So some
227 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
228 * should be deferred. In cases like this, the driver would like to
229 * hold a ref to the fb even though it has already been removed from
230 * userspace perspective.
232 struct kref refcount
;
234 * Place on the dev->mode_config.fb_list, access protected by
235 * dev->mode_config.fb_lock.
237 struct list_head head
;
238 struct drm_mode_object base
;
239 const struct drm_framebuffer_funcs
*funcs
;
240 unsigned int pitches
[4];
241 unsigned int offsets
[4];
242 uint64_t modifier
[4];
245 /* depth can be 15 or 16 */
249 uint32_t pixel_format
; /* fourcc format */
250 struct list_head filp_head
;
253 struct drm_property_blob
{
254 struct drm_mode_object base
;
255 struct drm_device
*dev
;
256 struct kref refcount
;
257 struct list_head head_global
;
258 struct list_head head_file
;
260 unsigned char data
[];
263 struct drm_property_enum
{
265 struct list_head head
;
266 char name
[DRM_PROP_NAME_LEN
];
269 struct drm_property
{
270 struct list_head head
;
271 struct drm_mode_object base
;
273 char name
[DRM_PROP_NAME_LEN
];
276 struct drm_device
*dev
;
278 struct list_head enum_list
;
282 struct drm_connector
;
284 struct drm_pending_vblank_event
;
287 struct drm_atomic_state
;
289 struct drm_crtc_helper_funcs
;
290 struct drm_encoder_helper_funcs
;
291 struct drm_connector_helper_funcs
;
292 struct drm_plane_helper_funcs
;
295 * struct drm_crtc_state - mutable CRTC state
296 * @crtc: backpointer to the CRTC
297 * @enable: whether the CRTC should be enabled, gates all other state
298 * @active: whether the CRTC is actively displaying (used for DPMS)
299 * @planes_changed: planes on this crtc are updated
300 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
301 * @active_changed: crtc_state->active has been toggled.
302 * @connectors_changed: connectors to this crtc have been updated
303 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
304 * @last_vblank_count: for helpers and drivers to capture the vblank of the
305 * update to ensure framebuffer cleanup isn't done too early
306 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
307 * @mode: current mode timings
308 * @event: optional pointer to a DRM event to signal upon completion of the
310 * @state: backpointer to global drm_atomic_state
312 * Note that the distinction between @enable and @active is rather subtile:
313 * Flipping @active while @enable is set without changing anything else may
314 * never return in a failure from the ->atomic_check callback. Userspace assumes
315 * that a DPMS On will always succeed. In other words: @enable controls resource
316 * assignment, @active controls the actual hardware state.
318 struct drm_crtc_state
{
319 struct drm_crtc
*crtc
;
324 /* computed state bits used by helpers and drivers */
325 bool planes_changed
: 1;
326 bool mode_changed
: 1;
327 bool active_changed
: 1;
328 bool connectors_changed
: 1;
330 /* attached planes bitmask:
331 * WARNING: transitional helpers do not maintain plane_mask so
332 * drivers not converted over to atomic helpers should not rely
333 * on plane_mask being accurate!
337 /* last_vblank_count: for vblank waits before cleanup */
338 u32 last_vblank_count
;
340 /* adjusted_mode: for use by helpers and drivers */
341 struct drm_display_mode adjusted_mode
;
343 struct drm_display_mode mode
;
345 /* blob property to expose current mode to atomic userspace */
346 struct drm_property_blob
*mode_blob
;
348 struct drm_pending_vblank_event
*event
;
350 struct drm_atomic_state
*state
;
354 * struct drm_crtc_funcs - control CRTCs for a given device
356 * The drm_crtc_funcs structure is the central CRTC management structure
357 * in the DRM. Each CRTC controls one or more connectors (note that the name
358 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
359 * connectors, not just CRTs).
361 * Each driver is responsible for filling out this structure at startup time,
362 * in addition to providing other modesetting features, like i2c and DDC
365 struct drm_crtc_funcs
{
369 * Reset CRTC hardware and software state to off. This function isn't
370 * called by the core directly, only through drm_mode_config_reset().
371 * It's not a helper hook only for historical reasons.
373 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
374 * atomic state using this hook.
376 void (*reset
)(struct drm_crtc
*crtc
);
381 * Update the cursor image. The cursor position is relative to the CRTC
382 * and can be partially or fully outside of the visible area.
384 * Note that contrary to all other KMS functions the legacy cursor entry
385 * points don't take a framebuffer object, but instead take directly a
386 * raw buffer object id from the driver's buffer manager (which is
387 * either GEM or TTM for current drivers).
389 * This entry point is deprecated, drivers should instead implement
390 * universal plane support and register a proper cursor plane using
391 * drm_crtc_init_with_planes().
393 * This callback is optional
397 * 0 on success or a negative error code on failure.
399 int (*cursor_set
)(struct drm_crtc
*crtc
, struct drm_file
*file_priv
,
400 uint32_t handle
, uint32_t width
, uint32_t height
);
405 * Update the cursor image, including hotspot information. The hotspot
406 * must not affect the cursor position in CRTC coordinates, but is only
407 * meant as a hint for virtualized display hardware to coordinate the
408 * guests and hosts cursor position. The cursor hotspot is relative to
409 * the cursor image. Otherwise this works exactly like @cursor_set.
411 * This entry point is deprecated, drivers should instead implement
412 * universal plane support and register a proper cursor plane using
413 * drm_crtc_init_with_planes().
415 * This callback is optional.
419 * 0 on success or a negative error code on failure.
421 int (*cursor_set2
)(struct drm_crtc
*crtc
, struct drm_file
*file_priv
,
422 uint32_t handle
, uint32_t width
, uint32_t height
,
423 int32_t hot_x
, int32_t hot_y
);
428 * Update the cursor position. The cursor does not need to be visible
429 * when this hook is called.
431 * This entry point is deprecated, drivers should instead implement
432 * universal plane support and register a proper cursor plane using
433 * drm_crtc_init_with_planes().
435 * This callback is optional.
439 * 0 on success or a negative error code on failure.
441 int (*cursor_move
)(struct drm_crtc
*crtc
, int x
, int y
);
446 * Set gamma on the CRTC.
448 * This callback is optional.
452 * Drivers that support gamma tables and also fbdev emulation through
453 * the provided helper library need to take care to fill out the gamma
454 * hooks for both. Currently there's a bit an unfortunate duplication
455 * going on, which should eventually be unified to just one set of
458 void (*gamma_set
)(struct drm_crtc
*crtc
, u16
*r
, u16
*g
, u16
*b
,
459 uint32_t start
, uint32_t size
);
464 * Clean up plane resources. This is only called at driver unload time
465 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
468 void (*destroy
)(struct drm_crtc
*crtc
);
473 * This is the main legacy entry point to change the modeset state on a
474 * CRTC. All the details of the desired configuration are passed in a
475 * struct &drm_mode_set - see there for details.
477 * Drivers implementing atomic modeset should use
478 * drm_atomic_helper_set_config() to implement this hook.
482 * 0 on success or a negative error code on failure.
484 int (*set_config
)(struct drm_mode_set
*set
);
489 * Legacy entry point to schedule a flip to the given framebuffer.
491 * Page flipping is a synchronization mechanism that replaces the frame
492 * buffer being scanned out by the CRTC with a new frame buffer during
493 * vertical blanking, avoiding tearing (except when requested otherwise
494 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
495 * requests a page flip the DRM core verifies that the new frame buffer
496 * is large enough to be scanned out by the CRTC in the currently
497 * configured mode and then calls the CRTC ->page_flip() operation with a
498 * pointer to the new frame buffer.
500 * The driver must wait for any pending rendering to the new framebuffer
501 * to complete before executing the flip. It should also wait for any
502 * pending rendering from other drivers if the underlying buffer is a
505 * An application can request to be notified when the page flip has
506 * completed. The drm core will supply a struct &drm_event in the event
507 * parameter in this case. This can be handled by the
508 * drm_crtc_send_vblank_event() function, which the driver should call on
509 * the provided event upon completion of the flip. Note that if
510 * the driver supports vblank signalling and timestamping the vblank
511 * counters and timestamps must agree with the ones returned from page
512 * flip events. With the current vblank helper infrastructure this can
513 * be achieved by holding a vblank reference while the page flip is
514 * pending, acquired through drm_crtc_vblank_get() and released with
515 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
516 * counter and timestamp tracking though, e.g. if they have accurate
517 * timestamp registers in hardware.
521 * Up to that point drivers need to manage events themselves and can use
522 * even->base.list freely for that. Specifically they need to ensure
523 * that they don't send out page flip (or vblank) events for which the
524 * corresponding drm file has been closed already. The drm core
525 * unfortunately does not (yet) take care of that. Therefore drivers
526 * currently must clean up and release pending events in their
527 * ->preclose driver function.
529 * This callback is optional.
533 * Very early versions of the KMS ABI mandated that the driver must
534 * block (but not reject) any rendering to the old framebuffer until the
535 * flip operation has completed and the old framebuffer is no longer
536 * visible. This requirement has been lifted, and userspace is instead
537 * expected to request delivery of an event and wait with recycling old
538 * buffers until such has been received.
542 * 0 on success or a negative error code on failure. Note that if a
543 * ->page_flip() operation is already pending the callback should return
544 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
545 * or just runtime disabled through DPMS respectively the new atomic
546 * "ACTIVE" state) should result in an -EINVAL error code.
548 int (*page_flip
)(struct drm_crtc
*crtc
,
549 struct drm_framebuffer
*fb
,
550 struct drm_pending_vblank_event
*event
,
556 * This is the legacy entry point to update a property attached to the
559 * Drivers implementing atomic modeset should use
560 * drm_atomic_helper_crtc_set_property() to implement this hook.
562 * This callback is optional if the driver does not support any legacy
563 * driver-private properties.
567 * 0 on success or a negative error code on failure.
569 int (*set_property
)(struct drm_crtc
*crtc
,
570 struct drm_property
*property
, uint64_t val
);
573 * @atomic_duplicate_state:
575 * Duplicate the current atomic state for this CRTC and return it.
576 * The core and helpers gurantee that any atomic state duplicated with
577 * this hook and still owned by the caller (i.e. not transferred to the
578 * driver by calling ->atomic_commit() from struct
579 * &drm_mode_config_funcs) will be cleaned up by calling the
580 * @atomic_destroy_state hook in this structure.
582 * Atomic drivers which don't subclass struct &drm_crtc should use
583 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
584 * state structure to extend it with driver-private state should use
585 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
586 * duplicated in a consistent fashion across drivers.
588 * It is an error to call this hook before crtc->state has been
589 * initialized correctly.
593 * If the duplicate state references refcounted resources this hook must
594 * acquire a reference for each of them. The driver must release these
595 * references again in @atomic_destroy_state.
599 * Duplicated atomic state or NULL when the allocation failed.
601 struct drm_crtc_state
*(*atomic_duplicate_state
)(struct drm_crtc
*crtc
);
604 * @atomic_destroy_state:
606 * Destroy a state duplicated with @atomic_duplicate_state and release
607 * or unreference all resources it references
609 void (*atomic_destroy_state
)(struct drm_crtc
*crtc
,
610 struct drm_crtc_state
*state
);
613 * @atomic_set_property:
615 * Decode a driver-private property value and store the decoded value
616 * into the passed-in state structure. Since the atomic core decodes all
617 * standardized properties (even for extensions beyond the core set of
618 * properties which might not be implemented by all drivers) this
619 * requires drivers to subclass the state structure.
621 * Such driver-private properties should really only be implemented for
622 * truly hardware/vendor specific state. Instead it is preferred to
623 * standardize atomic extension and decode the properties used to expose
624 * such an extension in the core.
626 * Do not call this function directly, use
627 * drm_atomic_crtc_set_property() instead.
629 * This callback is optional if the driver does not support any
630 * driver-private atomic properties.
634 * This function is called in the state assembly phase of atomic
635 * modesets, which can be aborted for any reason (including on
636 * userspace's request to just check whether a configuration would be
637 * possible). Drivers MUST NOT touch any persistent state (hardware or
638 * software) or data structures except the passed in @state parameter.
640 * Also since userspace controls in which order properties are set this
641 * function must not do any input validation (since the state update is
642 * incomplete and hence likely inconsistent). Instead any such input
643 * validation must be done in the various atomic_check callbacks.
647 * 0 if the property has been found, -EINVAL if the property isn't
648 * implemented by the driver (which should never happen, the core only
649 * asks for properties attached to this CRTC). No other validation is
650 * allowed by the driver. The core already checks that the property
651 * value is within the range (integer, valid enum value, ...) the driver
652 * set when registering the property.
654 int (*atomic_set_property
)(struct drm_crtc
*crtc
,
655 struct drm_crtc_state
*state
,
656 struct drm_property
*property
,
659 * @atomic_get_property:
661 * Reads out the decoded driver-private property. This is used to
662 * implement the GETCRTC IOCTL.
664 * Do not call this function directly, use
665 * drm_atomic_crtc_get_property() instead.
667 * This callback is optional if the driver does not support any
668 * driver-private atomic properties.
672 * 0 on success, -EINVAL if the property isn't implemented by the
673 * driver (which should never happen, the core only asks for
674 * properties attached to this CRTC).
676 int (*atomic_get_property
)(struct drm_crtc
*crtc
,
677 const struct drm_crtc_state
*state
,
678 struct drm_property
*property
,
683 * struct drm_crtc - central CRTC control structure
684 * @dev: parent DRM device
685 * @port: OF node used by drm_of_find_possible_crtcs()
686 * @head: list management
687 * @mutex: per-CRTC locking
688 * @base: base KMS object for ID tracking etc.
689 * @primary: primary plane for this CRTC
690 * @cursor: cursor plane for this CRTC
691 * @cursor_x: current x position of the cursor, used for universal cursor planes
692 * @cursor_y: current y position of the cursor, used for universal cursor planes
693 * @enabled: is this CRTC enabled?
694 * @mode: current mode timings
695 * @hwmode: mode timings as programmed to hw regs
696 * @x: x position on screen
697 * @y: y position on screen
698 * @funcs: CRTC control functions
699 * @gamma_size: size of gamma ramp
700 * @gamma_store: gamma ramp values
701 * @helper_private: mid-layer private data
702 * @properties: property tracking for this CRTC
703 * @state: current atomic state for this CRTC
704 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
707 * Each CRTC may have one or more connectors associated with it. This structure
708 * allows the CRTC to be controlled.
711 struct drm_device
*dev
;
712 struct device_node
*port
;
713 struct list_head head
;
718 * This provides a read lock for the overall crtc state (mode, dpms
719 * state, ...) and a write lock for everything which can be update
720 * without a full modeset (fb, cursor data, ...)
722 struct drm_modeset_lock mutex
;
724 struct drm_mode_object base
;
726 /* primary and cursor planes for CRTC */
727 struct drm_plane
*primary
;
728 struct drm_plane
*cursor
;
730 /* position of cursor plane on crtc */
736 /* Requested mode from modesetting. */
737 struct drm_display_mode mode
;
739 /* Programmed mode in hw, after adjustments for encoders,
740 * crtc, panel scaling etc. Needed for timestamping etc.
742 struct drm_display_mode hwmode
;
745 const struct drm_crtc_funcs
*funcs
;
747 /* CRTC gamma size for reporting to userspace */
749 uint16_t *gamma_store
;
751 /* if you are using the helper */
752 const struct drm_crtc_helper_funcs
*helper_private
;
754 struct drm_object_properties properties
;
756 struct drm_crtc_state
*state
;
759 * For legacy crtc IOCTLs so that atomic drivers can get at the locking
762 struct drm_modeset_acquire_ctx
*acquire_ctx
;
766 * struct drm_connector_state - mutable connector state
767 * @connector: backpointer to the connector
768 * @crtc: CRTC to connect connector to, NULL if disabled
769 * @best_encoder: can be used by helpers and drivers to select the encoder
770 * @state: backpointer to global drm_atomic_state
772 struct drm_connector_state
{
773 struct drm_connector
*connector
;
775 struct drm_crtc
*crtc
; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
777 struct drm_encoder
*best_encoder
;
779 struct drm_atomic_state
*state
;
783 * struct drm_connector_funcs - control connectors on a given device
785 * Each CRTC may have one or more connectors attached to it. The functions
786 * below allow the core DRM code to control connectors, enumerate available modes,
789 struct drm_connector_funcs
{
793 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
794 * is exposed as a standard property on the connector, but diverted to
795 * this callback in the drm core. Note that atomic drivers don't
796 * implement the 4 level DPMS support on the connector any more, but
797 * instead only have an on/off "ACTIVE" property on the CRTC object.
799 * Drivers implementing atomic modeset should use
800 * drm_atomic_helper_connector_dpms() to implement this hook.
804 * 0 on success or a negative error code on failure.
806 int (*dpms
)(struct drm_connector
*connector
, int mode
);
811 * Reset connector hardware and software state to off. This function isn't
812 * called by the core directly, only through drm_mode_config_reset().
813 * It's not a helper hook only for historical reasons.
815 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
816 * atomic state using this hook.
818 void (*reset
)(struct drm_connector
*connector
);
823 * Check to see if anything is attached to the connector. The parameter
824 * force is set to false whilst polling, true when checking the
825 * connector due to a user request. force can be used by the driver to
826 * avoid expensive, destructive operations during automated probing.
830 * Note that this hook is only called by the probe helper. It's not in
831 * the helper library vtable purely for historical reasons. The only DRM
832 * core entry point to probe connector state is @fill_modes.
836 * drm_connector_status indicating the connector's status.
838 enum drm_connector_status (*detect
)(struct drm_connector
*connector
,
844 * This function is called to update internal encoder state when the
845 * connector is forced to a certain state by userspace, either through
846 * the sysfs interfaces or on the kernel cmdline. In that case the
847 * @detect callback isn't called.
851 * Note that this hook is only called by the probe helper. It's not in
852 * the helper library vtable purely for historical reasons. The only DRM
853 * core entry point to probe connector state is @fill_modes.
855 void (*force
)(struct drm_connector
*connector
);
860 * Entry point for output detection and basic mode validation. The
861 * driver should reprobe the output if needed (e.g. when hotplug
862 * handling is unreliable), add all detected modes to connector->modes
863 * and filter out any the device can't support in any configuration. It
864 * also needs to filter out any modes wider or higher than the
865 * parameters max_width and max_height indicate.
867 * The drivers must also prune any modes no longer valid from
868 * connector->modes. Furthermore it must update connector->status and
869 * connector->edid. If no EDID has been received for this output
870 * connector->edid must be NULL.
872 * Drivers using the probe helpers should use
873 * drm_helper_probe_single_connector_modes() or
874 * drm_helper_probe_single_connector_modes_nomerge() to implement this
879 * The number of modes detected and filled into connector->modes.
881 int (*fill_modes
)(struct drm_connector
*connector
, uint32_t max_width
, uint32_t max_height
);
886 * This is the legacy entry point to update a property attached to the
889 * Drivers implementing atomic modeset should use
890 * drm_atomic_helper_connector_set_property() to implement this hook.
892 * This callback is optional if the driver does not support any legacy
893 * driver-private properties.
897 * 0 on success or a negative error code on failure.
899 int (*set_property
)(struct drm_connector
*connector
, struct drm_property
*property
,
905 * Clean up connector resources. This is called at driver unload time
906 * through drm_mode_config_cleanup(). It can also be called at runtime
907 * when a connector is being hot-unplugged for drivers that support
908 * connector hotplugging (e.g. DisplayPort MST).
910 void (*destroy
)(struct drm_connector
*connector
);
913 * @atomic_duplicate_state:
915 * Duplicate the current atomic state for this connector and return it.
916 * The core and helpers gurantee that any atomic state duplicated with
917 * this hook and still owned by the caller (i.e. not transferred to the
918 * driver by calling ->atomic_commit() from struct
919 * &drm_mode_config_funcs) will be cleaned up by calling the
920 * @atomic_destroy_state hook in this structure.
922 * Atomic drivers which don't subclass struct &drm_connector_state should use
923 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
924 * state structure to extend it with driver-private state should use
925 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
926 * duplicated in a consistent fashion across drivers.
928 * It is an error to call this hook before connector->state has been
929 * initialized correctly.
933 * If the duplicate state references refcounted resources this hook must
934 * acquire a reference for each of them. The driver must release these
935 * references again in @atomic_destroy_state.
939 * Duplicated atomic state or NULL when the allocation failed.
941 struct drm_connector_state
*(*atomic_duplicate_state
)(struct drm_connector
*connector
);
944 * @atomic_destroy_state:
946 * Destroy a state duplicated with @atomic_duplicate_state and release
947 * or unreference all resources it references
949 void (*atomic_destroy_state
)(struct drm_connector
*connector
,
950 struct drm_connector_state
*state
);
953 * @atomic_set_property:
955 * Decode a driver-private property value and store the decoded value
956 * into the passed-in state structure. Since the atomic core decodes all
957 * standardized properties (even for extensions beyond the core set of
958 * properties which might not be implemented by all drivers) this
959 * requires drivers to subclass the state structure.
961 * Such driver-private properties should really only be implemented for
962 * truly hardware/vendor specific state. Instead it is preferred to
963 * standardize atomic extension and decode the properties used to expose
964 * such an extension in the core.
966 * Do not call this function directly, use
967 * drm_atomic_connector_set_property() instead.
969 * This callback is optional if the driver does not support any
970 * driver-private atomic properties.
974 * This function is called in the state assembly phase of atomic
975 * modesets, which can be aborted for any reason (including on
976 * userspace's request to just check whether a configuration would be
977 * possible). Drivers MUST NOT touch any persistent state (hardware or
978 * software) or data structures except the passed in @state parameter.
980 * Also since userspace controls in which order properties are set this
981 * function must not do any input validation (since the state update is
982 * incomplete and hence likely inconsistent). Instead any such input
983 * validation must be done in the various atomic_check callbacks.
987 * 0 if the property has been found, -EINVAL if the property isn't
988 * implemented by the driver (which shouldn't ever happen, the core only
989 * asks for properties attached to this connector). No other validation
990 * is allowed by the driver. The core already checks that the property
991 * value is within the range (integer, valid enum value, ...) the driver
992 * set when registering the property.
994 int (*atomic_set_property
)(struct drm_connector
*connector
,
995 struct drm_connector_state
*state
,
996 struct drm_property
*property
,
1000 * @atomic_get_property:
1002 * Reads out the decoded driver-private property. This is used to
1003 * implement the GETCONNECTOR IOCTL.
1005 * Do not call this function directly, use
1006 * drm_atomic_connector_get_property() instead.
1008 * This callback is optional if the driver does not support any
1009 * driver-private atomic properties.
1013 * 0 on success, -EINVAL if the property isn't implemented by the
1014 * driver (which shouldn't ever happen, the core only asks for
1015 * properties attached to this connector).
1017 int (*atomic_get_property
)(struct drm_connector
*connector
,
1018 const struct drm_connector_state
*state
,
1019 struct drm_property
*property
,
1024 * struct drm_encoder_funcs - encoder controls
1026 * Encoders sit between CRTCs and connectors.
1028 struct drm_encoder_funcs
{
1032 * Reset encoder hardware and software state to off. This function isn't
1033 * called by the core directly, only through drm_mode_config_reset().
1034 * It's not a helper hook only for historical reasons.
1036 void (*reset
)(struct drm_encoder
*encoder
);
1041 * Clean up encoder resources. This is only called at driver unload time
1042 * through drm_mode_config_cleanup() since an encoder cannot be
1043 * hotplugged in DRM.
1045 void (*destroy
)(struct drm_encoder
*encoder
);
1048 #define DRM_CONNECTOR_MAX_ENCODER 3
1051 * struct drm_encoder - central DRM encoder structure
1052 * @dev: parent DRM device
1053 * @head: list management
1054 * @base: base KMS object
1055 * @name: encoder name
1056 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1057 * @possible_crtcs: bitmask of potential CRTC bindings
1058 * @possible_clones: bitmask of potential sibling encoders for cloning
1059 * @crtc: currently bound CRTC
1060 * @bridge: bridge associated to the encoder
1061 * @funcs: control functions
1062 * @helper_private: mid-layer private data
1064 * CRTCs drive pixels to encoders, which convert them into signals
1065 * appropriate for a given connector or set of connectors.
1067 struct drm_encoder
{
1068 struct drm_device
*dev
;
1069 struct list_head head
;
1071 struct drm_mode_object base
;
1074 uint32_t possible_crtcs
;
1075 uint32_t possible_clones
;
1077 struct drm_crtc
*crtc
;
1078 struct drm_bridge
*bridge
;
1079 const struct drm_encoder_funcs
*funcs
;
1080 const struct drm_encoder_helper_funcs
*helper_private
;
1083 /* should we poll this connector for connects and disconnects */
1084 /* hot plug detectable */
1085 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
1086 /* poll for connections */
1087 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1088 /* can cleanly poll for disconnections without flickering the screen */
1089 /* DACs should rarely do this without a lot of testing */
1090 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1092 #define MAX_ELD_BYTES 128
1095 * struct drm_connector - central DRM connector control structure
1096 * @dev: parent DRM device
1097 * @kdev: kernel device for sysfs attributes
1098 * @attr: sysfs attributes
1099 * @head: list management
1100 * @base: base KMS object
1101 * @name: connector name
1102 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1103 * @connector_type_id: index into connector type enum
1104 * @interlace_allowed: can this connector handle interlaced modes?
1105 * @doublescan_allowed: can this connector handle doublescan?
1106 * @stereo_allowed: can this connector handle stereo modes?
1107 * @modes: modes available on this connector (from fill_modes() + user)
1108 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1109 * @probed_modes: list of modes derived directly from the display
1110 * @display_info: information about attached display (e.g. from EDID)
1111 * @funcs: connector control functions
1112 * @edid_blob_ptr: DRM property containing EDID if present
1113 * @properties: property tracking for this connector
1114 * @path_blob_ptr: DRM blob property data for the DP MST path property
1115 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1116 * @dpms: current dpms state
1117 * @helper_private: mid-layer private data
1118 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
1119 * @force: a %DRM_FORCE_<foo> state for forced mode sets
1120 * @override_edid: has the EDID been overwritten through debugfs for testing?
1121 * @encoder_ids: valid encoders for this connector
1122 * @encoder: encoder driving this connector, if any
1123 * @eld: EDID-like data, if present
1124 * @dvi_dual: dual link DVI, if found
1125 * @max_tmds_clock: max clock rate, if found
1126 * @latency_present: AV delay info from ELD, if found
1127 * @video_latency: video latency info from ELD, if found
1128 * @audio_latency: audio latency info from ELD, if found
1129 * @null_edid_counter: track sinks that give us all zeros for the EDID
1130 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
1131 * @edid_corrupt: indicates whether the last read EDID was corrupt
1132 * @debugfs_entry: debugfs directory for this connector
1133 * @state: current atomic state for this connector
1134 * @has_tile: is this connector connected to a tiled monitor
1135 * @tile_group: tile group for the connected monitor
1136 * @tile_is_single_monitor: whether the tile is one monitor housing
1137 * @num_h_tile: number of horizontal tiles in the tile group
1138 * @num_v_tile: number of vertical tiles in the tile group
1139 * @tile_h_loc: horizontal location of this tile
1140 * @tile_v_loc: vertical location of this tile
1141 * @tile_h_size: horizontal size of this tile.
1142 * @tile_v_size: vertical size of this tile.
1144 * Each connector may be connected to one or more CRTCs, or may be clonable by
1145 * another connector if they can share a CRTC. Each connector also has a specific
1146 * position in the broader display (referred to as a 'screen' though it could
1147 * span multiple monitors).
1149 struct drm_connector
{
1150 struct drm_device
*dev
;
1151 struct device
*kdev
;
1152 struct device_attribute
*attr
;
1153 struct list_head head
;
1155 struct drm_mode_object base
;
1159 int connector_type_id
;
1160 bool interlace_allowed
;
1161 bool doublescan_allowed
;
1162 bool stereo_allowed
;
1163 struct list_head modes
; /* list of modes on this connector */
1165 enum drm_connector_status status
;
1167 /* these are modes added by probing with DDC or the BIOS */
1168 struct list_head probed_modes
;
1170 struct drm_display_info display_info
;
1171 const struct drm_connector_funcs
*funcs
;
1173 struct drm_property_blob
*edid_blob_ptr
;
1174 struct drm_object_properties properties
;
1176 struct drm_property_blob
*path_blob_ptr
;
1178 struct drm_property_blob
*tile_blob_ptr
;
1180 uint8_t polled
; /* DRM_CONNECTOR_POLL_* */
1182 /* requested DPMS state */
1185 const struct drm_connector_helper_funcs
*helper_private
;
1187 /* forced on connector */
1188 struct drm_cmdline_mode cmdline_mode
;
1189 enum drm_connector_force force
;
1191 uint32_t encoder_ids
[DRM_CONNECTOR_MAX_ENCODER
];
1192 struct drm_encoder
*encoder
; /* currently active encoder */
1195 uint8_t eld
[MAX_ELD_BYTES
];
1197 int max_tmds_clock
; /* in MHz */
1198 bool latency_present
[2];
1199 int video_latency
[2]; /* [0]: progressive, [1]: interlaced */
1200 int audio_latency
[2];
1201 int null_edid_counter
; /* needed to workaround some HW bugs where we get all 0s */
1202 unsigned bad_edid_counter
;
1204 /* Flag for raw EDID header corruption - used in Displayport
1205 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1209 struct dentry
*debugfs_entry
;
1211 struct drm_connector_state
*state
;
1213 /* DisplayID bits */
1215 struct drm_tile_group
*tile_group
;
1216 bool tile_is_single_monitor
;
1218 uint8_t num_h_tile
, num_v_tile
;
1219 uint8_t tile_h_loc
, tile_v_loc
;
1220 uint16_t tile_h_size
, tile_v_size
;
1224 * struct drm_plane_state - mutable plane state
1225 * @plane: backpointer to the plane
1226 * @crtc: currently bound CRTC, NULL if disabled
1227 * @fb: currently bound framebuffer
1228 * @fence: optional fence to wait for before scanning out @fb
1229 * @crtc_x: left position of visible portion of plane on crtc
1230 * @crtc_y: upper position of visible portion of plane on crtc
1231 * @crtc_w: width of visible portion of plane on crtc
1232 * @crtc_h: height of visible portion of plane on crtc
1233 * @src_x: left position of visible portion of plane within
1235 * @src_y: upper position of visible portion of plane within
1237 * @src_w: width of visible portion of plane (in 16.16)
1238 * @src_h: height of visible portion of plane (in 16.16)
1239 * @state: backpointer to global drm_atomic_state
1241 struct drm_plane_state
{
1242 struct drm_plane
*plane
;
1244 struct drm_crtc
*crtc
; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1245 struct drm_framebuffer
*fb
; /* do not write directly, use drm_atomic_set_fb_for_plane() */
1246 struct fence
*fence
;
1248 /* Signed dest location allows it to be partially off screen */
1249 int32_t crtc_x
, crtc_y
;
1250 uint32_t crtc_w
, crtc_h
;
1252 /* Source values are 16.16 fixed point */
1253 uint32_t src_x
, src_y
;
1254 uint32_t src_h
, src_w
;
1256 /* Plane rotation */
1257 unsigned int rotation
;
1259 struct drm_atomic_state
*state
;
1264 * struct drm_plane_funcs - driver plane control functions
1266 struct drm_plane_funcs
{
1270 * This is the legacy entry point to enable and configure the plane for
1271 * the given CRTC and framebuffer. It is never called to disable the
1272 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1274 * The source rectangle in frame buffer memory coordinates is given by
1275 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1276 * values). Devices that don't support subpixel plane coordinates can
1277 * ignore the fractional part.
1279 * The destination rectangle in CRTC coordinates is given by the
1280 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1281 * Devices scale the source rectangle to the destination rectangle. If
1282 * scaling is not supported, and the source rectangle size doesn't match
1283 * the destination rectangle size, the driver must return a
1284 * -<errorname>EINVAL</errorname> error.
1286 * Drivers implementing atomic modeset should use
1287 * drm_atomic_helper_update_plane() to implement this hook.
1291 * 0 on success or a negative error code on failure.
1293 int (*update_plane
)(struct drm_plane
*plane
,
1294 struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
1295 int crtc_x
, int crtc_y
,
1296 unsigned int crtc_w
, unsigned int crtc_h
,
1297 uint32_t src_x
, uint32_t src_y
,
1298 uint32_t src_w
, uint32_t src_h
);
1303 * This is the legacy entry point to disable the plane. The DRM core
1304 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
1305 * with the frame buffer ID set to 0. Disabled planes must not be
1306 * processed by the CRTC.
1308 * Drivers implementing atomic modeset should use
1309 * drm_atomic_helper_disable_plane() to implement this hook.
1313 * 0 on success or a negative error code on failure.
1315 int (*disable_plane
)(struct drm_plane
*plane
);
1320 * Clean up plane resources. This is only called at driver unload time
1321 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1324 void (*destroy
)(struct drm_plane
*plane
);
1329 * Reset plane hardware and software state to off. This function isn't
1330 * called by the core directly, only through drm_mode_config_reset().
1331 * It's not a helper hook only for historical reasons.
1333 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1334 * atomic state using this hook.
1336 void (*reset
)(struct drm_plane
*plane
);
1341 * This is the legacy entry point to update a property attached to the
1344 * Drivers implementing atomic modeset should use
1345 * drm_atomic_helper_plane_set_property() to implement this hook.
1347 * This callback is optional if the driver does not support any legacy
1348 * driver-private properties.
1352 * 0 on success or a negative error code on failure.
1354 int (*set_property
)(struct drm_plane
*plane
,
1355 struct drm_property
*property
, uint64_t val
);
1358 * @atomic_duplicate_state:
1360 * Duplicate the current atomic state for this plane and return it.
1361 * The core and helpers gurantee that any atomic state duplicated with
1362 * this hook and still owned by the caller (i.e. not transferred to the
1363 * driver by calling ->atomic_commit() from struct
1364 * &drm_mode_config_funcs) will be cleaned up by calling the
1365 * @atomic_destroy_state hook in this structure.
1367 * Atomic drivers which don't subclass struct &drm_plane_state should use
1368 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1369 * state structure to extend it with driver-private state should use
1370 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1371 * duplicated in a consistent fashion across drivers.
1373 * It is an error to call this hook before plane->state has been
1374 * initialized correctly.
1378 * If the duplicate state references refcounted resources this hook must
1379 * acquire a reference for each of them. The driver must release these
1380 * references again in @atomic_destroy_state.
1384 * Duplicated atomic state or NULL when the allocation failed.
1386 struct drm_plane_state
*(*atomic_duplicate_state
)(struct drm_plane
*plane
);
1389 * @atomic_destroy_state:
1391 * Destroy a state duplicated with @atomic_duplicate_state and release
1392 * or unreference all resources it references
1394 void (*atomic_destroy_state
)(struct drm_plane
*plane
,
1395 struct drm_plane_state
*state
);
1398 * @atomic_set_property:
1400 * Decode a driver-private property value and store the decoded value
1401 * into the passed-in state structure. Since the atomic core decodes all
1402 * standardized properties (even for extensions beyond the core set of
1403 * properties which might not be implemented by all drivers) this
1404 * requires drivers to subclass the state structure.
1406 * Such driver-private properties should really only be implemented for
1407 * truly hardware/vendor specific state. Instead it is preferred to
1408 * standardize atomic extension and decode the properties used to expose
1409 * such an extension in the core.
1411 * Do not call this function directly, use
1412 * drm_atomic_plane_set_property() instead.
1414 * This callback is optional if the driver does not support any
1415 * driver-private atomic properties.
1419 * This function is called in the state assembly phase of atomic
1420 * modesets, which can be aborted for any reason (including on
1421 * userspace's request to just check whether a configuration would be
1422 * possible). Drivers MUST NOT touch any persistent state (hardware or
1423 * software) or data structures except the passed in @state parameter.
1425 * Also since userspace controls in which order properties are set this
1426 * function must not do any input validation (since the state update is
1427 * incomplete and hence likely inconsistent). Instead any such input
1428 * validation must be done in the various atomic_check callbacks.
1432 * 0 if the property has been found, -EINVAL if the property isn't
1433 * implemented by the driver (which shouldn't ever happen, the core only
1434 * asks for properties attached to this plane). No other validation is
1435 * allowed by the driver. The core already checks that the property
1436 * value is within the range (integer, valid enum value, ...) the driver
1437 * set when registering the property.
1439 int (*atomic_set_property
)(struct drm_plane
*plane
,
1440 struct drm_plane_state
*state
,
1441 struct drm_property
*property
,
1445 * @atomic_get_property:
1447 * Reads out the decoded driver-private property. This is used to
1448 * implement the GETPLANE IOCTL.
1450 * Do not call this function directly, use
1451 * drm_atomic_plane_get_property() instead.
1453 * This callback is optional if the driver does not support any
1454 * driver-private atomic properties.
1458 * 0 on success, -EINVAL if the property isn't implemented by the
1459 * driver (which should never happen, the core only asks for
1460 * properties attached to this plane).
1462 int (*atomic_get_property
)(struct drm_plane
*plane
,
1463 const struct drm_plane_state
*state
,
1464 struct drm_property
*property
,
1468 enum drm_plane_type
{
1469 DRM_PLANE_TYPE_OVERLAY
,
1470 DRM_PLANE_TYPE_PRIMARY
,
1471 DRM_PLANE_TYPE_CURSOR
,
1476 * struct drm_plane - central DRM plane control structure
1477 * @dev: DRM device this plane belongs to
1478 * @head: for list management
1479 * @base: base mode object
1480 * @possible_crtcs: pipes this plane can be bound to
1481 * @format_types: array of formats supported by this plane
1482 * @format_count: number of formats supported
1483 * @format_default: driver hasn't supplied supported formats for the plane
1484 * @crtc: currently bound CRTC
1485 * @fb: currently bound fb
1486 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1487 * drm_mode_set_config_internal() to implement correct refcounting.
1488 * @funcs: helper functions
1489 * @properties: property tracking for this plane
1490 * @type: type of plane (overlay, primary, cursor)
1491 * @state: current atomic state for this plane
1494 struct drm_device
*dev
;
1495 struct list_head head
;
1497 struct drm_modeset_lock mutex
;
1499 struct drm_mode_object base
;
1501 uint32_t possible_crtcs
;
1502 uint32_t *format_types
;
1503 unsigned int format_count
;
1504 bool format_default
;
1506 struct drm_crtc
*crtc
;
1507 struct drm_framebuffer
*fb
;
1509 struct drm_framebuffer
*old_fb
;
1511 const struct drm_plane_funcs
*funcs
;
1513 struct drm_object_properties properties
;
1515 enum drm_plane_type type
;
1517 const struct drm_plane_helper_funcs
*helper_private
;
1519 struct drm_plane_state
*state
;
1523 * struct drm_bridge_funcs - drm_bridge control functions
1524 * @attach: Called during drm_bridge_attach
1526 struct drm_bridge_funcs
{
1527 int (*attach
)(struct drm_bridge
*bridge
);
1532 * This callback is used to validate and adjust a mode. The paramater
1533 * mode is the display mode that should be fed to the next element in
1534 * the display chain, either the final &drm_connector or the next
1535 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1536 * requires. It can be modified by this callback and does not need to
1539 * This is the only hook that allows a bridge to reject a modeset. If
1540 * this function passes all other callbacks must succeed for this
1545 * This function is called in the check phase of atomic modesets, which
1546 * can be aborted for any reason (including on userspace's request to
1547 * just check whether a configuration would be possible). Drivers MUST
1548 * NOT touch any persistent state (hardware or software) or data
1549 * structures except the passed in @state parameter.
1553 * True if an acceptable configuration is possible, false if the modeset
1554 * operation should be rejected.
1556 bool (*mode_fixup
)(struct drm_bridge
*bridge
,
1557 const struct drm_display_mode
*mode
,
1558 struct drm_display_mode
*adjusted_mode
);
1562 * This callback should disable the bridge. It is called right before
1563 * the preceding element in the display pipe is disabled. If the
1564 * preceding element is a bridge this means it's called before that
1565 * bridge's ->disable() function. If the preceding element is a
1566 * &drm_encoder it's called right before the encoder's ->disable(),
1567 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1569 * The bridge can assume that the display pipe (i.e. clocks and timing
1570 * signals) feeding it is still running when this callback is called.
1572 void (*disable
)(struct drm_bridge
*bridge
);
1577 * This callback should disable the bridge. It is called right after
1578 * the preceding element in the display pipe is disabled. If the
1579 * preceding element is a bridge this means it's called after that
1580 * bridge's ->post_disable() function. If the preceding element is a
1581 * &drm_encoder it's called right after the encoder's ->disable(),
1582 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1584 * The bridge must assume that the display pipe (i.e. clocks and timing
1585 * singals) feeding it is no longer running when this callback is
1588 void (*post_disable
)(struct drm_bridge
*bridge
);
1593 * This callback should set the given mode on the bridge. It is called
1594 * after the ->mode_set() callback for the preceding element in the
1595 * display pipeline has been called already. The display pipe (i.e.
1596 * clocks and timing signals) is off when this function is called.
1598 void (*mode_set
)(struct drm_bridge
*bridge
,
1599 struct drm_display_mode
*mode
,
1600 struct drm_display_mode
*adjusted_mode
);
1604 * This callback should enable the bridge. It is called right before
1605 * the preceding element in the display pipe is enabled. If the
1606 * preceding element is a bridge this means it's called before that
1607 * bridge's ->pre_enable() function. If the preceding element is a
1608 * &drm_encoder it's called right before the encoder's ->enable(),
1609 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1611 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1612 * will not yet be running when this callback is called. The bridge must
1613 * not enable the display link feeding the next bridge in the chain (if
1614 * there is one) when this callback is called.
1616 void (*pre_enable
)(struct drm_bridge
*bridge
);
1621 * This callback should enable the bridge. It is called right after
1622 * the preceding element in the display pipe is enabled. If the
1623 * preceding element is a bridge this means it's called after that
1624 * bridge's ->enable() function. If the preceding element is a
1625 * &drm_encoder it's called right after the encoder's ->enable(),
1626 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1628 * The bridge can assume that the display pipe (i.e. clocks and timing
1629 * signals) feeding it is running when this callback is called. This
1630 * callback must enable the display link feeding the next bridge in the
1631 * chain if there is one.
1633 void (*enable
)(struct drm_bridge
*bridge
);
1637 * struct drm_bridge - central DRM bridge control structure
1638 * @dev: DRM device this bridge belongs to
1639 * @encoder: encoder to which this bridge is connected
1640 * @next: the next bridge in the encoder chain
1641 * @of_node: device node pointer to the bridge
1642 * @list: to keep track of all added bridges
1643 * @funcs: control functions
1644 * @driver_private: pointer to the bridge driver's internal context
1647 struct drm_device
*dev
;
1648 struct drm_encoder
*encoder
;
1649 struct drm_bridge
*next
;
1651 struct device_node
*of_node
;
1653 struct list_head list
;
1655 const struct drm_bridge_funcs
*funcs
;
1656 void *driver_private
;
1660 * struct drm_atomic_state - the global state object for atomic updates
1661 * @dev: parent DRM device
1662 * @allow_modeset: allow full modeset
1663 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
1664 * @planes: pointer to array of plane pointers
1665 * @plane_states: pointer to array of plane states pointers
1666 * @crtcs: pointer to array of CRTC pointers
1667 * @crtc_states: pointer to array of CRTC states pointers
1668 * @num_connector: size of the @connectors and @connector_states arrays
1669 * @connectors: pointer to array of connector pointers
1670 * @connector_states: pointer to array of connector states pointers
1671 * @acquire_ctx: acquire context for this atomic modeset state update
1673 struct drm_atomic_state
{
1674 struct drm_device
*dev
;
1675 bool allow_modeset
: 1;
1676 bool legacy_cursor_update
: 1;
1677 struct drm_plane
**planes
;
1678 struct drm_plane_state
**plane_states
;
1679 struct drm_crtc
**crtcs
;
1680 struct drm_crtc_state
**crtc_states
;
1682 struct drm_connector
**connectors
;
1683 struct drm_connector_state
**connector_states
;
1685 struct drm_modeset_acquire_ctx
*acquire_ctx
;
1690 * struct drm_mode_set - new values for a CRTC config change
1691 * @fb: framebuffer to use for new config
1692 * @crtc: CRTC whose configuration we're about to change
1693 * @mode: mode timings to use
1694 * @x: position of this CRTC relative to @fb
1695 * @y: position of this CRTC relative to @fb
1696 * @connectors: array of connectors to drive with this CRTC if possible
1697 * @num_connectors: size of @connectors array
1699 * Represents a single crtc the connectors that it drives with what mode
1700 * and from which framebuffer it scans out from.
1702 * This is used to set modes.
1704 struct drm_mode_set
{
1705 struct drm_framebuffer
*fb
;
1706 struct drm_crtc
*crtc
;
1707 struct drm_display_mode
*mode
;
1712 struct drm_connector
**connectors
;
1713 size_t num_connectors
;
1717 * struct drm_mode_config_funcs - basic driver provided mode setting functions
1719 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1722 struct drm_mode_config_funcs
{
1726 * Create a new framebuffer object. The core does basic checks on the
1727 * requested metadata, but most of that is left to the driver. See
1728 * struct &drm_mode_fb_cmd2 for details.
1732 * A new framebuffer with an initial reference count of 1 or a negative
1733 * error code encoded with ERR_PTR().
1735 struct drm_framebuffer
*(*fb_create
)(struct drm_device
*dev
,
1736 struct drm_file
*file_priv
,
1737 const struct drm_mode_fb_cmd2
*mode_cmd
);
1740 * @output_poll_changed:
1742 * Callback used by helpers to inform the driver of output configuration
1745 * Drivers implementing fbdev emulation with the helpers can call
1746 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1747 * helper of output changes.
1751 * Except that there's no vtable for device-level helper callbacks
1752 * there's no reason this is a core function.
1754 void (*output_poll_changed
)(struct drm_device
*dev
);
1759 * This is the only hook to validate an atomic modeset update. This
1760 * function must reject any modeset and state changes which the hardware
1761 * or driver doesn't support. This includes but is of course not limited
1764 * - Checking that the modes, framebuffers, scaling and placement
1765 * requirements and so on are within the limits of the hardware.
1767 * - Checking that any hidden shared resources are not oversubscribed.
1768 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1769 * display fifo space (where shared between planes or maybe even
1772 * - Checking that virtualized resources exported to userspace are not
1773 * oversubscribed. For various reasons it can make sense to expose
1774 * more planes, crtcs or encoders than which are physically there. One
1775 * example is dual-pipe operations (which generally should be hidden
1776 * from userspace if when lockstepped in hardware, exposed otherwise),
1777 * where a plane might need 1 hardware plane (if it's just on one
1778 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1779 * shared a hardware plane with a 2nd plane (if there's a compatible
1780 * plane requested on the area handled by the other pipe).
1782 * - Check that any transitional state is possible and that if
1783 * requested, the update can indeed be done in the vblank period
1784 * without temporarily disabling some functions.
1786 * - Check any other constraints the driver or hardware might have.
1788 * - This callback also needs to correctly fill out the &drm_crtc_state
1789 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1790 * reflects the nature of the possible update and returns true if and
1791 * only if the update cannot be applied without tearing within one
1792 * vblank on that CRTC. The core uses that information to reject
1793 * updates which require a full modeset (i.e. blanking the screen, or
1794 * at least pausing updates for a substantial amount of time) if
1795 * userspace has disallowed that in its request.
1797 * - The driver also does not need to repeat basic input validation
1798 * like done for the corresponding legacy entry points. The core does
1799 * that before calling this hook.
1801 * See the documentation of @atomic_commit for an exhaustive list of
1802 * error conditions which don't have to be checked at the
1803 * ->atomic_check() stage?
1805 * See the documentation for struct &drm_atomic_state for how exactly
1806 * an atomic modeset update is described.
1808 * Drivers using the atomic helpers can implement this hook using
1809 * drm_atomic_helper_check(), or one of the exported sub-functions of
1814 * 0 on success or one of the below negative error codes:
1816 * - -EINVAL, if any of the above constraints are violated.
1818 * - -EDEADLK, when returned from an attempt to acquire an additional
1819 * &drm_modeset_lock through drm_modeset_lock().
1821 * - -ENOMEM, if allocating additional state sub-structures failed due
1822 * to lack of memory.
1824 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1825 * This can either be due to a pending signal, or because the driver
1826 * needs to completely bail out to recover from an exceptional
1827 * situation like a GPU hang. From a userspace point all errors are
1830 int (*atomic_check
)(struct drm_device
*dev
,
1831 struct drm_atomic_state
*state
);
1836 * This is the only hook to commit an atomic modeset update. The core
1837 * guarantees that @atomic_check has been called successfully before
1838 * calling this function, and that nothing has been changed in the
1841 * See the documentation for struct &drm_atomic_state for how exactly
1842 * an atomic modeset update is described.
1844 * Drivers using the atomic helpers can implement this hook using
1845 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1848 * Asynchronous commits (as indicated with the async parameter) must
1849 * do any preparatory work which might result in an unsuccessful commit
1850 * in the context of this callback. The only exceptions are hardware
1851 * errors resulting in -EIO. But even in that case the driver must
1852 * ensure that the display pipe is at least running, to avoid
1853 * compositors crashing when pageflips don't work. Anything else,
1854 * specifically committing the update to the hardware, should be done
1855 * without blocking the caller. For updates which do not require a
1856 * modeset this must be guaranteed.
1858 * The driver must wait for any pending rendering to the new
1859 * framebuffers to complete before executing the flip. It should also
1860 * wait for any pending rendering from other drivers if the underlying
1861 * buffer is a shared dma-buf. Asynchronous commits must not wait for
1862 * rendering in the context of this callback.
1864 * An application can request to be notified when the atomic commit has
1865 * completed. These events are per-CRTC and can be distinguished by the
1866 * CRTC index supplied in &drm_event to userspace.
1868 * The drm core will supply a struct &drm_event in the event
1869 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1870 * drm_crtc_send_vblank_event() function, which the driver should call on
1871 * the provided event upon completion of the atomic commit. Note that if
1872 * the driver supports vblank signalling and timestamping the vblank
1873 * counters and timestamps must agree with the ones returned from page
1874 * flip events. With the current vblank helper infrastructure this can
1875 * be achieved by holding a vblank reference while the page flip is
1876 * pending, acquired through drm_crtc_vblank_get() and released with
1877 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1878 * counter and timestamp tracking though, e.g. if they have accurate
1879 * timestamp registers in hardware.
1883 * Drivers are not allowed to shut down any display pipe successfully
1884 * enabled through an atomic commit on their own. Doing so can result in
1885 * compositors crashing if a page flip is suddenly rejected because the
1890 * 0 on success or one of the below negative error codes:
1892 * - -EBUSY, if an asynchronous updated is requested and there is
1893 * an earlier updated pending. Drivers are allowed to support a queue
1894 * of outstanding updates, but currently no driver supports that.
1895 * Note that drivers must wait for preceding updates to complete if a
1896 * synchronous update is requested, they are not allowed to fail the
1897 * commit in that case.
1899 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1900 * this can happen when trying to pin framebuffers, which must only
1901 * be done when committing the state.
1903 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1904 * that the driver has run out of vram, iommu space or similar GPU
1905 * address space needed for framebuffer.
1907 * - -EIO, if the hardware completely died.
1909 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1910 * This can either be due to a pending signal, or because the driver
1911 * needs to completely bail out to recover from an exceptional
1912 * situation like a GPU hang. From a userspace point of view all errors are
1915 * This list is exhaustive. Specifically this hook is not allowed to
1916 * return -EINVAL (any invalid requests should be caught in
1917 * @atomic_check) or -EDEADLK (this function must not acquire
1918 * additional modeset locks).
1920 int (*atomic_commit
)(struct drm_device
*dev
,
1921 struct drm_atomic_state
*state
,
1925 * @atomic_state_alloc:
1927 * This optional hook can be used by drivers that want to subclass struct
1928 * &drm_atomic_state to be able to track their own driver-private global
1929 * state easily. If this hook is implemented, drivers must also
1930 * implement @atomic_state_clear and @atomic_state_free.
1934 * A new &drm_atomic_state on success or NULL on failure.
1936 struct drm_atomic_state
*(*atomic_state_alloc
)(struct drm_device
*dev
);
1939 * @atomic_state_clear:
1941 * This hook must clear any driver private state duplicated into the
1942 * passed-in &drm_atomic_state. This hook is called when the caller
1943 * encountered a &drm_modeset_lock deadlock and needs to drop all
1944 * already acquired locks as part of the deadlock avoidance dance
1945 * implemented in drm_modeset_lock_backoff().
1947 * Any duplicated state must be invalidated since a concurrent atomic
1948 * update might change it, and the drm atomic interfaces always apply
1949 * updates as relative changes to the current state.
1951 * Drivers that implement this must call drm_atomic_state_default_clear()
1952 * to clear common state.
1954 void (*atomic_state_clear
)(struct drm_atomic_state
*state
);
1957 * @atomic_state_free:
1959 * This hook needs driver private resources and the &drm_atomic_state
1960 * itself. Note that the core first calls drm_atomic_state_clear() to
1961 * avoid code duplicate between the clear and free hooks.
1963 * Drivers that implement this must call drm_atomic_state_default_free()
1964 * to release common resources.
1966 void (*atomic_state_free
)(struct drm_atomic_state
*state
);
1970 * struct drm_mode_config - Mode configuration control structure
1971 * @mutex: mutex protecting KMS related lists and structures
1972 * @connection_mutex: ww mutex protecting connector state and routing
1973 * @acquire_ctx: global implicit acquire context used by atomic drivers for
1975 * @idr_mutex: mutex for KMS ID allocation and management
1976 * @crtc_idr: main KMS ID tracking object
1977 * @fb_lock: mutex to protect fb state and lists
1978 * @num_fb: number of fbs available
1979 * @fb_list: list of framebuffers available
1980 * @num_connector: number of connectors on this device
1981 * @connector_list: list of connector objects
1982 * @num_encoder: number of encoders on this device
1983 * @encoder_list: list of encoder objects
1984 * @num_overlay_plane: number of overlay planes on this device
1985 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1986 * @plane_list: list of plane objects
1987 * @num_crtc: number of CRTCs on this device
1988 * @crtc_list: list of CRTC objects
1989 * @property_list: list of property objects
1990 * @min_width: minimum pixel width on this device
1991 * @min_height: minimum pixel height on this device
1992 * @max_width: maximum pixel width on this device
1993 * @max_height: maximum pixel height on this device
1994 * @funcs: core driver provided mode setting functions
1995 * @fb_base: base address of the framebuffer
1996 * @poll_enabled: track polling support for this device
1997 * @poll_running: track polling status for this device
1998 * @output_poll_work: delayed work for polling in process context
1999 * @property_blob_list: list of all the blob property objects
2000 * @blob_lock: mutex for blob property allocation and management
2001 * @*_property: core property tracking
2002 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2003 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2004 * @async_page_flip: does this device support async flips on the primary plane?
2005 * @cursor_width: hint to userspace for max cursor width
2006 * @cursor_height: hint to userspace for max cursor height
2008 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2009 * enumerated by the driver are added here, as are global properties. Some
2010 * global restrictions are also here, e.g. dimension restrictions.
2012 struct drm_mode_config
{
2013 struct mutex mutex
; /* protects configuration (mode lists etc.) */
2014 struct drm_modeset_lock connection_mutex
; /* protects connector->encoder and encoder->crtc links */
2015 struct drm_modeset_acquire_ctx
*acquire_ctx
; /* for legacy _lock_all() / _unlock_all() */
2016 struct mutex idr_mutex
; /* for IDR management */
2017 struct idr crtc_idr
; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
2018 struct idr tile_idr
; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
2019 /* this is limited to one for now */
2021 struct mutex fb_lock
; /* proctects global and per-file fb lists */
2023 struct list_head fb_list
;
2026 struct list_head connector_list
;
2028 struct list_head encoder_list
;
2031 * Track # of overlay planes separately from # of total planes. By
2032 * default we only advertise overlay planes to userspace; if userspace
2033 * sets the "universal plane" capability bit, we'll go ahead and
2034 * expose all planes.
2036 int num_overlay_plane
;
2037 int num_total_plane
;
2038 struct list_head plane_list
;
2041 struct list_head crtc_list
;
2043 struct list_head property_list
;
2045 int min_width
, min_height
;
2046 int max_width
, max_height
;
2047 const struct drm_mode_config_funcs
*funcs
;
2048 resource_size_t fb_base
;
2050 /* output poll support */
2054 struct delayed_work output_poll_work
;
2056 struct mutex blob_lock
;
2058 /* pointers to standard properties */
2059 struct list_head property_blob_list
;
2060 struct drm_property
*edid_property
;
2061 struct drm_property
*dpms_property
;
2062 struct drm_property
*path_property
;
2063 struct drm_property
*tile_property
;
2064 struct drm_property
*plane_type_property
;
2065 struct drm_property
*rotation_property
;
2066 struct drm_property
*prop_src_x
;
2067 struct drm_property
*prop_src_y
;
2068 struct drm_property
*prop_src_w
;
2069 struct drm_property
*prop_src_h
;
2070 struct drm_property
*prop_crtc_x
;
2071 struct drm_property
*prop_crtc_y
;
2072 struct drm_property
*prop_crtc_w
;
2073 struct drm_property
*prop_crtc_h
;
2074 struct drm_property
*prop_fb_id
;
2075 struct drm_property
*prop_crtc_id
;
2076 struct drm_property
*prop_active
;
2077 struct drm_property
*prop_mode_id
;
2079 /* DVI-I properties */
2080 struct drm_property
*dvi_i_subconnector_property
;
2081 struct drm_property
*dvi_i_select_subconnector_property
;
2084 struct drm_property
*tv_subconnector_property
;
2085 struct drm_property
*tv_select_subconnector_property
;
2086 struct drm_property
*tv_mode_property
;
2087 struct drm_property
*tv_left_margin_property
;
2088 struct drm_property
*tv_right_margin_property
;
2089 struct drm_property
*tv_top_margin_property
;
2090 struct drm_property
*tv_bottom_margin_property
;
2091 struct drm_property
*tv_brightness_property
;
2092 struct drm_property
*tv_contrast_property
;
2093 struct drm_property
*tv_flicker_reduction_property
;
2094 struct drm_property
*tv_overscan_property
;
2095 struct drm_property
*tv_saturation_property
;
2096 struct drm_property
*tv_hue_property
;
2098 /* Optional properties */
2099 struct drm_property
*scaling_mode_property
;
2100 struct drm_property
*aspect_ratio_property
;
2101 struct drm_property
*dirty_info_property
;
2103 /* properties for virtual machine layout */
2104 struct drm_property
*suggested_x_property
;
2105 struct drm_property
*suggested_y_property
;
2107 /* dumb ioctl parameters */
2108 uint32_t preferred_depth
, prefer_shadow
;
2110 /* whether async page flip is supported or not */
2111 bool async_page_flip
;
2113 /* whether the driver supports fb modifiers */
2114 bool allow_fb_modifiers
;
2117 uint32_t cursor_width
, cursor_height
;
2121 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2122 * @plane: the loop cursor
2123 * @dev: the DRM device
2124 * @plane_mask: bitmask of plane indices
2126 * Iterate over all planes specified by bitmask.
2128 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
2129 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
2130 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
2133 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2134 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
2135 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2136 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2137 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2138 #define obj_to_property(x) container_of(x, struct drm_property, base)
2139 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
2140 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
2142 struct drm_prop_enum_list
{
2147 extern __printf(6, 7)
2148 int drm_crtc_init_with_planes(struct drm_device
*dev
,
2149 struct drm_crtc
*crtc
,
2150 struct drm_plane
*primary
,
2151 struct drm_plane
*cursor
,
2152 const struct drm_crtc_funcs
*funcs
,
2153 const char *name
, ...);
2154 extern void drm_crtc_cleanup(struct drm_crtc
*crtc
);
2155 extern unsigned int drm_crtc_index(struct drm_crtc
*crtc
);
2158 * drm_crtc_mask - find the mask of a registered CRTC
2159 * @crtc: CRTC to find mask for
2161 * Given a registered CRTC, return the mask bit of that CRTC for an
2162 * encoder's possible_crtcs field.
2164 static inline uint32_t drm_crtc_mask(struct drm_crtc
*crtc
)
2166 return 1 << drm_crtc_index(crtc
);
2169 extern void drm_connector_ida_init(void);
2170 extern void drm_connector_ida_destroy(void);
2171 extern int drm_connector_init(struct drm_device
*dev
,
2172 struct drm_connector
*connector
,
2173 const struct drm_connector_funcs
*funcs
,
2174 int connector_type
);
2175 int drm_connector_register(struct drm_connector
*connector
);
2176 void drm_connector_unregister(struct drm_connector
*connector
);
2178 extern void drm_connector_cleanup(struct drm_connector
*connector
);
2179 extern unsigned int drm_connector_index(struct drm_connector
*connector
);
2180 /* helper to unplug all connectors from sysfs for device */
2181 extern void drm_connector_unplug_all(struct drm_device
*dev
);
2183 extern int drm_bridge_add(struct drm_bridge
*bridge
);
2184 extern void drm_bridge_remove(struct drm_bridge
*bridge
);
2185 extern struct drm_bridge
*of_drm_find_bridge(struct device_node
*np
);
2186 extern int drm_bridge_attach(struct drm_device
*dev
, struct drm_bridge
*bridge
);
2188 bool drm_bridge_mode_fixup(struct drm_bridge
*bridge
,
2189 const struct drm_display_mode
*mode
,
2190 struct drm_display_mode
*adjusted_mode
);
2191 void drm_bridge_disable(struct drm_bridge
*bridge
);
2192 void drm_bridge_post_disable(struct drm_bridge
*bridge
);
2193 void drm_bridge_mode_set(struct drm_bridge
*bridge
,
2194 struct drm_display_mode
*mode
,
2195 struct drm_display_mode
*adjusted_mode
);
2196 void drm_bridge_pre_enable(struct drm_bridge
*bridge
);
2197 void drm_bridge_enable(struct drm_bridge
*bridge
);
2199 extern __printf(5, 6)
2200 int drm_encoder_init(struct drm_device
*dev
,
2201 struct drm_encoder
*encoder
,
2202 const struct drm_encoder_funcs
*funcs
,
2203 int encoder_type
, const char *name
, ...);
2206 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2207 * @encoder: encoder to test
2208 * @crtc: crtc to test
2210 * Return false if @encoder can't be driven by @crtc, true otherwise.
2212 static inline bool drm_encoder_crtc_ok(struct drm_encoder
*encoder
,
2213 struct drm_crtc
*crtc
)
2215 return !!(encoder
->possible_crtcs
& drm_crtc_mask(crtc
));
2218 extern __printf(8, 9)
2219 int drm_universal_plane_init(struct drm_device
*dev
,
2220 struct drm_plane
*plane
,
2221 unsigned long possible_crtcs
,
2222 const struct drm_plane_funcs
*funcs
,
2223 const uint32_t *formats
,
2224 unsigned int format_count
,
2225 enum drm_plane_type type
,
2226 const char *name
, ...);
2227 extern int drm_plane_init(struct drm_device
*dev
,
2228 struct drm_plane
*plane
,
2229 unsigned long possible_crtcs
,
2230 const struct drm_plane_funcs
*funcs
,
2231 const uint32_t *formats
, unsigned int format_count
,
2233 extern void drm_plane_cleanup(struct drm_plane
*plane
);
2234 extern unsigned int drm_plane_index(struct drm_plane
*plane
);
2235 extern struct drm_plane
* drm_plane_from_index(struct drm_device
*dev
, int idx
);
2236 extern void drm_plane_force_disable(struct drm_plane
*plane
);
2237 extern int drm_plane_check_pixel_format(const struct drm_plane
*plane
,
2239 extern void drm_crtc_get_hv_timing(const struct drm_display_mode
*mode
,
2240 int *hdisplay
, int *vdisplay
);
2241 extern int drm_crtc_check_viewport(const struct drm_crtc
*crtc
,
2243 const struct drm_display_mode
*mode
,
2244 const struct drm_framebuffer
*fb
);
2246 extern void drm_encoder_cleanup(struct drm_encoder
*encoder
);
2248 extern const char *drm_get_connector_status_name(enum drm_connector_status status
);
2249 extern const char *drm_get_subpixel_order_name(enum subpixel_order order
);
2250 extern const char *drm_get_dpms_name(int val
);
2251 extern const char *drm_get_dvi_i_subconnector_name(int val
);
2252 extern const char *drm_get_dvi_i_select_name(int val
);
2253 extern const char *drm_get_tv_subconnector_name(int val
);
2254 extern const char *drm_get_tv_select_name(int val
);
2255 extern void drm_fb_release(struct drm_file
*file_priv
);
2256 extern void drm_property_destroy_user_blobs(struct drm_device
*dev
,
2257 struct drm_file
*file_priv
);
2258 extern bool drm_probe_ddc(struct i2c_adapter
*adapter
);
2259 extern struct edid
*drm_get_edid(struct drm_connector
*connector
,
2260 struct i2c_adapter
*adapter
);
2261 extern struct edid
*drm_edid_duplicate(const struct edid
*edid
);
2262 extern int drm_add_edid_modes(struct drm_connector
*connector
, struct edid
*edid
);
2263 extern void drm_mode_config_init(struct drm_device
*dev
);
2264 extern void drm_mode_config_reset(struct drm_device
*dev
);
2265 extern void drm_mode_config_cleanup(struct drm_device
*dev
);
2267 extern int drm_mode_connector_set_path_property(struct drm_connector
*connector
,
2269 int drm_mode_connector_set_tile_property(struct drm_connector
*connector
);
2270 extern int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2271 const struct edid
*edid
);
2273 extern int drm_display_info_set_bus_formats(struct drm_display_info
*info
,
2275 unsigned int num_formats
);
2277 static inline bool drm_property_type_is(struct drm_property
*property
,
2280 /* instanceof for props.. handles extended type vs original types: */
2281 if (property
->flags
& DRM_MODE_PROP_EXTENDED_TYPE
)
2282 return (property
->flags
& DRM_MODE_PROP_EXTENDED_TYPE
) == type
;
2283 return property
->flags
& type
;
2286 static inline bool drm_property_type_valid(struct drm_property
*property
)
2288 if (property
->flags
& DRM_MODE_PROP_EXTENDED_TYPE
)
2289 return !(property
->flags
& DRM_MODE_PROP_LEGACY_TYPE
);
2290 return !!(property
->flags
& DRM_MODE_PROP_LEGACY_TYPE
);
2293 extern int drm_object_property_set_value(struct drm_mode_object
*obj
,
2294 struct drm_property
*property
,
2296 extern int drm_object_property_get_value(struct drm_mode_object
*obj
,
2297 struct drm_property
*property
,
2299 extern int drm_framebuffer_init(struct drm_device
*dev
,
2300 struct drm_framebuffer
*fb
,
2301 const struct drm_framebuffer_funcs
*funcs
);
2302 extern struct drm_framebuffer
*drm_framebuffer_lookup(struct drm_device
*dev
,
2304 extern void drm_framebuffer_unreference(struct drm_framebuffer
*fb
);
2305 extern void drm_framebuffer_reference(struct drm_framebuffer
*fb
);
2306 extern void drm_framebuffer_remove(struct drm_framebuffer
*fb
);
2307 extern void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
);
2308 extern void drm_framebuffer_unregister_private(struct drm_framebuffer
*fb
);
2310 extern void drm_object_attach_property(struct drm_mode_object
*obj
,
2311 struct drm_property
*property
,
2313 extern struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2314 const char *name
, int num_values
);
2315 extern struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2317 const struct drm_prop_enum_list
*props
,
2319 struct drm_property
*drm_property_create_bitmask(struct drm_device
*dev
,
2320 int flags
, const char *name
,
2321 const struct drm_prop_enum_list
*props
,
2323 uint64_t supported_bits
);
2324 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
2326 uint64_t min
, uint64_t max
);
2327 struct drm_property
*drm_property_create_signed_range(struct drm_device
*dev
,
2328 int flags
, const char *name
,
2329 int64_t min
, int64_t max
);
2330 struct drm_property
*drm_property_create_object(struct drm_device
*dev
,
2331 int flags
, const char *name
, uint32_t type
);
2332 struct drm_property
*drm_property_create_bool(struct drm_device
*dev
, int flags
,
2334 struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
,
2337 struct drm_property_blob
*drm_property_lookup_blob(struct drm_device
*dev
,
2339 struct drm_property_blob
*drm_property_reference_blob(struct drm_property_blob
*blob
);
2340 void drm_property_unreference_blob(struct drm_property_blob
*blob
);
2341 extern void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
);
2342 extern int drm_property_add_enum(struct drm_property
*property
, int index
,
2343 uint64_t value
, const char *name
);
2344 extern int drm_mode_create_dvi_i_properties(struct drm_device
*dev
);
2345 extern int drm_mode_create_tv_properties(struct drm_device
*dev
,
2346 unsigned int num_modes
,
2347 const char * const modes
[]);
2348 extern int drm_mode_create_scaling_mode_property(struct drm_device
*dev
);
2349 extern int drm_mode_create_aspect_ratio_property(struct drm_device
*dev
);
2350 extern int drm_mode_create_dirty_info_property(struct drm_device
*dev
);
2351 extern int drm_mode_create_suggested_offset_properties(struct drm_device
*dev
);
2352 extern bool drm_property_change_valid_get(struct drm_property
*property
,
2353 uint64_t value
, struct drm_mode_object
**ref
);
2354 extern void drm_property_change_valid_put(struct drm_property
*property
,
2355 struct drm_mode_object
*ref
);
2357 extern int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2358 struct drm_encoder
*encoder
);
2359 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
2361 extern struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
2362 uint32_t id
, uint32_t type
);
2365 extern int drm_mode_getresources(struct drm_device
*dev
,
2366 void *data
, struct drm_file
*file_priv
);
2367 extern int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
2368 struct drm_file
*file_priv
);
2369 extern int drm_mode_getcrtc(struct drm_device
*dev
,
2370 void *data
, struct drm_file
*file_priv
);
2371 extern int drm_mode_getconnector(struct drm_device
*dev
,
2372 void *data
, struct drm_file
*file_priv
);
2373 extern int drm_mode_set_config_internal(struct drm_mode_set
*set
);
2374 extern int drm_mode_setcrtc(struct drm_device
*dev
,
2375 void *data
, struct drm_file
*file_priv
);
2376 extern int drm_mode_getplane(struct drm_device
*dev
,
2377 void *data
, struct drm_file
*file_priv
);
2378 extern int drm_mode_setplane(struct drm_device
*dev
,
2379 void *data
, struct drm_file
*file_priv
);
2380 extern int drm_mode_cursor_ioctl(struct drm_device
*dev
,
2381 void *data
, struct drm_file
*file_priv
);
2382 extern int drm_mode_cursor2_ioctl(struct drm_device
*dev
,
2383 void *data
, struct drm_file
*file_priv
);
2384 extern int drm_mode_addfb(struct drm_device
*dev
,
2385 void *data
, struct drm_file
*file_priv
);
2386 extern int drm_mode_addfb2(struct drm_device
*dev
,
2387 void *data
, struct drm_file
*file_priv
);
2388 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
);
2389 extern int drm_mode_rmfb(struct drm_device
*dev
,
2390 void *data
, struct drm_file
*file_priv
);
2391 extern int drm_mode_getfb(struct drm_device
*dev
,
2392 void *data
, struct drm_file
*file_priv
);
2393 extern int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2394 void *data
, struct drm_file
*file_priv
);
2396 extern int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2397 void *data
, struct drm_file
*file_priv
);
2398 extern int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2399 void *data
, struct drm_file
*file_priv
);
2400 extern int drm_mode_createblob_ioctl(struct drm_device
*dev
,
2401 void *data
, struct drm_file
*file_priv
);
2402 extern int drm_mode_destroyblob_ioctl(struct drm_device
*dev
,
2403 void *data
, struct drm_file
*file_priv
);
2404 extern int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2405 void *data
, struct drm_file
*file_priv
);
2406 extern int drm_mode_getencoder(struct drm_device
*dev
,
2407 void *data
, struct drm_file
*file_priv
);
2408 extern int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
2409 void *data
, struct drm_file
*file_priv
);
2410 extern int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
2411 void *data
, struct drm_file
*file_priv
);
2412 extern u8
drm_match_cea_mode(const struct drm_display_mode
*to_match
);
2413 extern enum hdmi_picture_aspect
drm_get_cea_aspect_ratio(const u8 video_code
);
2414 extern bool drm_detect_hdmi_monitor(struct edid
*edid
);
2415 extern bool drm_detect_monitor_audio(struct edid
*edid
);
2416 extern bool drm_rgb_quant_range_selectable(struct edid
*edid
);
2417 extern int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
2418 void *data
, struct drm_file
*file_priv
);
2419 extern int drm_add_modes_noedid(struct drm_connector
*connector
,
2420 int hdisplay
, int vdisplay
);
2421 extern void drm_set_preferred_mode(struct drm_connector
*connector
,
2422 int hpref
, int vpref
);
2424 extern int drm_edid_header_is_valid(const u8
*raw_edid
);
2425 extern bool drm_edid_block_valid(u8
*raw_edid
, int block
, bool print_bad_edid
,
2426 bool *edid_corrupt
);
2427 extern bool drm_edid_is_valid(struct edid
*edid
);
2429 extern struct drm_tile_group
*drm_mode_create_tile_group(struct drm_device
*dev
,
2431 extern struct drm_tile_group
*drm_mode_get_tile_group(struct drm_device
*dev
,
2433 extern void drm_mode_put_tile_group(struct drm_device
*dev
,
2434 struct drm_tile_group
*tg
);
2435 struct drm_display_mode
*drm_mode_find_dmt(struct drm_device
*dev
,
2436 int hsize
, int vsize
, int fresh
,
2439 extern int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
2440 void *data
, struct drm_file
*file_priv
);
2441 extern int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
2442 void *data
, struct drm_file
*file_priv
);
2443 extern int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
2444 void *data
, struct drm_file
*file_priv
);
2445 extern int drm_mode_obj_get_properties_ioctl(struct drm_device
*dev
, void *data
,
2446 struct drm_file
*file_priv
);
2447 extern int drm_mode_obj_set_property_ioctl(struct drm_device
*dev
, void *data
,
2448 struct drm_file
*file_priv
);
2449 extern int drm_mode_plane_set_obj_prop(struct drm_plane
*plane
,
2450 struct drm_property
*property
,
2452 extern int drm_mode_atomic_ioctl(struct drm_device
*dev
,
2453 void *data
, struct drm_file
*file_priv
);
2455 extern void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
2457 extern int drm_format_num_planes(uint32_t format
);
2458 extern int drm_format_plane_cpp(uint32_t format
, int plane
);
2459 extern int drm_format_horz_chroma_subsampling(uint32_t format
);
2460 extern int drm_format_vert_chroma_subsampling(uint32_t format
);
2461 extern const char *drm_get_format_name(uint32_t format
);
2462 extern struct drm_property
*drm_mode_create_rotation_property(struct drm_device
*dev
,
2463 unsigned int supported_rotations
);
2464 extern unsigned int drm_rotation_simplify(unsigned int rotation
,
2465 unsigned int supported_rotations
);
2469 static inline struct drm_plane
*drm_plane_find(struct drm_device
*dev
,
2472 struct drm_mode_object
*mo
;
2473 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_PLANE
);
2474 return mo
? obj_to_plane(mo
) : NULL
;
2477 static inline struct drm_crtc
*drm_crtc_find(struct drm_device
*dev
,
2480 struct drm_mode_object
*mo
;
2481 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_CRTC
);
2482 return mo
? obj_to_crtc(mo
) : NULL
;
2485 static inline struct drm_encoder
*drm_encoder_find(struct drm_device
*dev
,
2488 struct drm_mode_object
*mo
;
2489 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_ENCODER
);
2490 return mo
? obj_to_encoder(mo
) : NULL
;
2493 static inline struct drm_connector
*drm_connector_find(struct drm_device
*dev
,
2496 struct drm_mode_object
*mo
;
2497 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_CONNECTOR
);
2498 return mo
? obj_to_connector(mo
) : NULL
;
2501 static inline struct drm_property
*drm_property_find(struct drm_device
*dev
,
2504 struct drm_mode_object
*mo
;
2505 mo
= drm_mode_object_find(dev
, id
, DRM_MODE_OBJECT_PROPERTY
);
2506 return mo
? obj_to_property(mo
) : NULL
;
2509 /* Plane list iterator for legacy (overlay only) planes. */
2510 #define drm_for_each_legacy_plane(plane, dev) \
2511 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
2512 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
2514 #define drm_for_each_plane(plane, dev) \
2515 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2517 #define drm_for_each_crtc(crtc, dev) \
2518 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2521 assert_drm_connector_list_read_locked(struct drm_mode_config
*mode_config
)
2524 * The connector hotadd/remove code currently grabs both locks when
2525 * updating lists. Hence readers need only hold either of them to be
2526 * safe and the check amounts to
2528 * WARN_ON(not_holding(A) && not_holding(B)).
2530 WARN_ON(!mutex_is_locked(&mode_config
->mutex
) &&
2531 !drm_modeset_is_locked(&mode_config
->connection_mutex
));
2534 #define drm_for_each_connector(connector, dev) \
2535 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2536 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2537 struct drm_connector, head); \
2538 &connector->head != (&(dev)->mode_config.connector_list); \
2539 connector = list_next_entry(connector, head))
2541 #define drm_for_each_encoder(encoder, dev) \
2542 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2544 #define drm_for_each_fb(fb, dev) \
2545 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2546 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2547 struct drm_framebuffer, head); \
2548 &fb->head != (&(dev)->mode_config.fb_list); \
2549 fb = list_next_entry(fb, head))
2551 #endif /* __DRM_CRTC_H__ */