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 <uapi_drm/drm_mode.h>
35 #include <uapi_drm/drm_fourcc.h>
36 #include <drm/drm_modeset_lock.h>
40 struct drm_framebuffer;
41 struct drm_object_properties;
47 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
48 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
49 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
50 #define DRM_MODE_OBJECT_MODE 0xdededede
51 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
52 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
53 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
54 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
55 #define DRM_MODE_OBJECT_ANY 0
57 struct drm_mode_object {
60 struct drm_object_properties *properties;
62 void (*free_cb)(struct kref *kref);
65 #define DRM_OBJECT_MAX_PROPERTY 24
66 struct drm_object_properties {
67 int count, atomic_count;
68 /* NOTE: if we ever start dynamically destroying properties (ie.
69 * not at drm_mode_config_cleanup() time), then we'd have to do
70 * a better job of detaching property from mode objects to avoid
71 * dangling property pointers:
73 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
74 /* do not read/write values directly, but use drm_object_property_get_value()
75 * and drm_object_property_set_value():
77 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
80 static inline int64_t U642I64(uint64_t val)
82 return (int64_t)*((int64_t *)&val);
84 static inline uint64_t I642U64(int64_t val)
86 return (uint64_t)*((uint64_t *)&val);
90 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
91 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
92 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
94 #define DRM_ROTATE_MASK 0x0f
95 #define DRM_ROTATE_0 0
96 #define DRM_ROTATE_90 1
97 #define DRM_ROTATE_180 2
98 #define DRM_ROTATE_270 3
99 #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
100 #define DRM_REFLECT_X 4
101 #define DRM_REFLECT_Y 5
103 enum drm_connector_force {
104 DRM_FORCE_UNSPECIFIED,
106 DRM_FORCE_ON, /* force on analog part normally */
107 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
110 #include <drm/drm_modes.h>
112 enum drm_connector_status {
113 connector_status_connected = 1,
114 connector_status_disconnected = 2,
115 connector_status_unknown = 3,
118 enum subpixel_order {
120 SubPixelHorizontalRGB,
121 SubPixelHorizontalBGR,
127 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
128 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
129 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
131 * Describes a given display (e.g. CRT or flat panel) and its limitations.
133 struct drm_display_info {
134 char name[DRM_DISPLAY_INFO_LEN];
137 unsigned int width_mm;
138 unsigned int height_mm;
140 /* Clock limits FIXME: storage format */
141 unsigned int min_vfreq, max_vfreq;
142 unsigned int min_hfreq, max_hfreq;
143 unsigned int pixel_clock;
146 enum subpixel_order subpixel_order;
150 unsigned int num_bus_formats;
152 /* Mask of supported hdmi deep color modes */
153 u8 edid_hdmi_dc_modes;
158 /* data corresponds to displayid vend/prod/serial */
159 struct drm_tile_group {
160 struct kref refcount;
161 struct drm_device *dev;
167 * struct drm_framebuffer_funcs - framebuffer hooks
169 struct drm_framebuffer_funcs {
173 * Clean up framebuffer resources, specifically also unreference the
174 * backing storage. The core guarantees to call this function for every
175 * framebuffer successfully created by ->fb_create() in
176 * &drm_mode_config_funcs. Drivers must also call
177 * drm_framebuffer_cleanup() to release DRM core resources for this
180 void (*destroy)(struct drm_framebuffer *framebuffer);
185 * Create a buffer handle in the driver-specific buffer manager (either
186 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
187 * the core to implement the GETFB IOCTL, which returns (for
188 * sufficiently priviledged user) also a native buffer handle. This can
189 * be used for seamless transitions between modesetting clients by
190 * copying the current screen contents to a private buffer and blending
191 * between that and the new contents.
193 * GEM based drivers should call drm_gem_handle_create() to create the
198 * 0 on success or a negative error code on failure.
200 int (*create_handle)(struct drm_framebuffer *fb,
201 struct drm_file *file_priv,
202 unsigned int *handle);
206 * Optional callback for the dirty fb IOCTL.
208 * Userspace can notify the driver via this callback that an area of the
209 * framebuffer has changed and should be flushed to the display
210 * hardware. This can also be used internally, e.g. by the fbdev
211 * emulation, though that's not the case currently.
213 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
214 * for more information as all the semantics and arguments have a one to
215 * one mapping on this function.
219 * 0 on success or a negative error code on failure.
221 int (*dirty)(struct drm_framebuffer *framebuffer,
222 struct drm_file *file_priv, unsigned flags,
223 unsigned color, struct drm_clip_rect *clips,
227 struct drm_framebuffer {
228 struct drm_device *dev;
230 * Note that the fb is refcounted for the benefit of driver internals,
231 * for example some hw, disabling a CRTC/plane is asynchronous, and
232 * scanout does not actually complete until the next vblank. So some
233 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
234 * should be deferred. In cases like this, the driver would like to
235 * hold a ref to the fb even though it has already been removed from
236 * userspace perspective.
237 * The refcount is stored inside the mode object.
240 * Place on the dev->mode_config.fb_list, access protected by
241 * dev->mode_config.fb_lock.
243 struct list_head head;
244 struct drm_mode_object base;
245 const struct drm_framebuffer_funcs *funcs;
246 unsigned int pitches[4];
247 unsigned int offsets[4];
248 uint64_t modifier[4];
251 /* depth can be 15 or 16 */
255 uint32_t pixel_format; /* fourcc format */
256 struct list_head filp_head;
259 struct drm_property_blob {
260 struct drm_mode_object base;
261 struct drm_device *dev;
262 struct kref refcount;
263 struct list_head head_global;
264 struct list_head head_file;
266 unsigned char data[];
269 struct drm_property_enum {
271 struct list_head head;
272 char name[DRM_PROP_NAME_LEN];
275 struct drm_property {
276 struct list_head head;
277 struct drm_mode_object base;
279 char name[DRM_PROP_NAME_LEN];
282 struct drm_device *dev;
284 struct list_head enum_list;
288 struct drm_connector;
290 struct drm_pending_vblank_event;
293 struct drm_atomic_state;
295 struct drm_crtc_helper_funcs;
296 struct drm_encoder_helper_funcs;
297 struct drm_connector_helper_funcs;
298 struct drm_plane_helper_funcs;
301 * struct drm_crtc_state - mutable CRTC state
302 * @crtc: backpointer to the CRTC
303 * @enable: whether the CRTC should be enabled, gates all other state
304 * @active: whether the CRTC is actively displaying (used for DPMS)
305 * @planes_changed: planes on this crtc are updated
306 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
307 * @active_changed: crtc_state->active has been toggled.
308 * @connectors_changed: connectors to this crtc have been updated
309 * @color_mgmt_changed: color management properties have changed (degamma or
310 * gamma LUT or CSC matrix)
311 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
312 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
313 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
314 * @last_vblank_count: for helpers and drivers to capture the vblank of the
315 * update to ensure framebuffer cleanup isn't done too early
316 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
317 * @mode: current mode timings
318 * @degamma_lut: Lookup table for converting framebuffer pixel data
319 * before apply the conversion matrix
320 * @ctm: Transformation matrix
321 * @gamma_lut: Lookup table for converting pixel data after the
323 * @event: optional pointer to a DRM event to signal upon completion of the
325 * @state: backpointer to global drm_atomic_state
327 * Note that the distinction between @enable and @active is rather subtile:
328 * Flipping @active while @enable is set without changing anything else may
329 * never return in a failure from the ->atomic_check callback. Userspace assumes
330 * that a DPMS On will always succeed. In other words: @enable controls resource
331 * assignment, @active controls the actual hardware state.
333 struct drm_crtc_state {
334 struct drm_crtc *crtc;
339 /* computed state bits used by helpers and drivers */
340 bool planes_changed : 1;
341 bool mode_changed : 1;
342 bool active_changed : 1;
343 bool connectors_changed : 1;
344 bool color_mgmt_changed : 1;
346 /* attached planes bitmask:
347 * WARNING: transitional helpers do not maintain plane_mask so
348 * drivers not converted over to atomic helpers should not rely
349 * on plane_mask being accurate!
356 /* last_vblank_count: for vblank waits before cleanup */
357 u32 last_vblank_count;
359 /* adjusted_mode: for use by helpers and drivers */
360 struct drm_display_mode adjusted_mode;
362 struct drm_display_mode mode;
364 /* blob property to expose current mode to atomic userspace */
365 struct drm_property_blob *mode_blob;
367 /* blob property to expose color management to userspace */
368 struct drm_property_blob *degamma_lut;
369 struct drm_property_blob *ctm;
370 struct drm_property_blob *gamma_lut;
372 struct drm_pending_vblank_event *event;
374 struct drm_atomic_state *state;
378 * struct drm_crtc_funcs - control CRTCs for a given device
380 * The drm_crtc_funcs structure is the central CRTC management structure
381 * in the DRM. Each CRTC controls one or more connectors (note that the name
382 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
383 * connectors, not just CRTs).
385 * Each driver is responsible for filling out this structure at startup time,
386 * in addition to providing other modesetting features, like i2c and DDC
389 struct drm_crtc_funcs {
393 * Reset CRTC hardware and software state to off. This function isn't
394 * called by the core directly, only through drm_mode_config_reset().
395 * It's not a helper hook only for historical reasons.
397 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
398 * atomic state using this hook.
400 void (*reset)(struct drm_crtc *crtc);
405 * Update the cursor image. The cursor position is relative to the CRTC
406 * and can be partially or fully outside of the visible area.
408 * Note that contrary to all other KMS functions the legacy cursor entry
409 * points don't take a framebuffer object, but instead take directly a
410 * raw buffer object id from the driver's buffer manager (which is
411 * either GEM or TTM for current drivers).
413 * This entry point is deprecated, drivers should instead implement
414 * universal plane support and register a proper cursor plane using
415 * drm_crtc_init_with_planes().
417 * This callback is optional
421 * 0 on success or a negative error code on failure.
423 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
424 uint32_t handle, uint32_t width, uint32_t height);
429 * Update the cursor image, including hotspot information. The hotspot
430 * must not affect the cursor position in CRTC coordinates, but is only
431 * meant as a hint for virtualized display hardware to coordinate the
432 * guests and hosts cursor position. The cursor hotspot is relative to
433 * the cursor image. Otherwise this works exactly like @cursor_set.
435 * This entry point is deprecated, drivers should instead implement
436 * universal plane support and register a proper cursor plane using
437 * drm_crtc_init_with_planes().
439 * This callback is optional.
443 * 0 on success or a negative error code on failure.
445 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
446 uint32_t handle, uint32_t width, uint32_t height,
447 int32_t hot_x, int32_t hot_y);
452 * Update the cursor position. The cursor does not need to be visible
453 * when this hook is called.
455 * This entry point is deprecated, drivers should instead implement
456 * universal plane support and register a proper cursor plane using
457 * drm_crtc_init_with_planes().
459 * This callback is optional.
463 * 0 on success or a negative error code on failure.
465 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
470 * Set gamma on the CRTC.
472 * This callback is optional.
476 * Drivers that support gamma tables and also fbdev emulation through
477 * the provided helper library need to take care to fill out the gamma
478 * hooks for both. Currently there's a bit an unfortunate duplication
479 * going on, which should eventually be unified to just one set of
482 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
483 uint32_t start, uint32_t size);
488 * Clean up plane resources. This is only called at driver unload time
489 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
492 void (*destroy)(struct drm_crtc *crtc);
497 * This is the main legacy entry point to change the modeset state on a
498 * CRTC. All the details of the desired configuration are passed in a
499 * struct &drm_mode_set - see there for details.
501 * Drivers implementing atomic modeset should use
502 * drm_atomic_helper_set_config() to implement this hook.
506 * 0 on success or a negative error code on failure.
508 int (*set_config)(struct drm_mode_set *set);
513 * Legacy entry point to schedule a flip to the given framebuffer.
515 * Page flipping is a synchronization mechanism that replaces the frame
516 * buffer being scanned out by the CRTC with a new frame buffer during
517 * vertical blanking, avoiding tearing (except when requested otherwise
518 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
519 * requests a page flip the DRM core verifies that the new frame buffer
520 * is large enough to be scanned out by the CRTC in the currently
521 * configured mode and then calls the CRTC ->page_flip() operation with a
522 * pointer to the new frame buffer.
524 * The driver must wait for any pending rendering to the new framebuffer
525 * to complete before executing the flip. It should also wait for any
526 * pending rendering from other drivers if the underlying buffer is a
529 * An application can request to be notified when the page flip has
530 * completed. The drm core will supply a struct &drm_event in the event
531 * parameter in this case. This can be handled by the
532 * drm_crtc_send_vblank_event() function, which the driver should call on
533 * the provided event upon completion of the flip. Note that if
534 * the driver supports vblank signalling and timestamping the vblank
535 * counters and timestamps must agree with the ones returned from page
536 * flip events. With the current vblank helper infrastructure this can
537 * be achieved by holding a vblank reference while the page flip is
538 * pending, acquired through drm_crtc_vblank_get() and released with
539 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
540 * counter and timestamp tracking though, e.g. if they have accurate
541 * timestamp registers in hardware.
545 * Up to that point drivers need to manage events themselves and can use
546 * even->base.list freely for that. Specifically they need to ensure
547 * that they don't send out page flip (or vblank) events for which the
548 * corresponding drm file has been closed already. The drm core
549 * unfortunately does not (yet) take care of that. Therefore drivers
550 * currently must clean up and release pending events in their
551 * ->preclose driver function.
553 * This callback is optional.
557 * Very early versions of the KMS ABI mandated that the driver must
558 * block (but not reject) any rendering to the old framebuffer until the
559 * flip operation has completed and the old framebuffer is no longer
560 * visible. This requirement has been lifted, and userspace is instead
561 * expected to request delivery of an event and wait with recycling old
562 * buffers until such has been received.
566 * 0 on success or a negative error code on failure. Note that if a
567 * ->page_flip() operation is already pending the callback should return
568 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
569 * or just runtime disabled through DPMS respectively the new atomic
570 * "ACTIVE" state) should result in an -EINVAL error code. Note that
571 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
573 int (*page_flip)(struct drm_crtc *crtc,
574 struct drm_framebuffer *fb,
575 struct drm_pending_vblank_event *event,
581 * This is the legacy entry point to update a property attached to the
584 * Drivers implementing atomic modeset should use
585 * drm_atomic_helper_crtc_set_property() to implement this hook.
587 * This callback is optional if the driver does not support any legacy
588 * driver-private properties.
592 * 0 on success or a negative error code on failure.
594 int (*set_property)(struct drm_crtc *crtc,
595 struct drm_property *property, uint64_t val);
598 * @atomic_duplicate_state:
600 * Duplicate the current atomic state for this CRTC and return it.
601 * The core and helpers gurantee that any atomic state duplicated with
602 * this hook and still owned by the caller (i.e. not transferred to the
603 * driver by calling ->atomic_commit() from struct
604 * &drm_mode_config_funcs) will be cleaned up by calling the
605 * @atomic_destroy_state hook in this structure.
607 * Atomic drivers which don't subclass struct &drm_crtc should use
608 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
609 * state structure to extend it with driver-private state should use
610 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
611 * duplicated in a consistent fashion across drivers.
613 * It is an error to call this hook before crtc->state has been
614 * initialized correctly.
618 * If the duplicate state references refcounted resources this hook must
619 * acquire a reference for each of them. The driver must release these
620 * references again in @atomic_destroy_state.
624 * Duplicated atomic state or NULL when the allocation failed.
626 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
629 * @atomic_destroy_state:
631 * Destroy a state duplicated with @atomic_duplicate_state and release
632 * or unreference all resources it references
634 void (*atomic_destroy_state)(struct drm_crtc *crtc,
635 struct drm_crtc_state *state);
638 * @atomic_set_property:
640 * Decode a driver-private property value and store the decoded value
641 * into the passed-in state structure. Since the atomic core decodes all
642 * standardized properties (even for extensions beyond the core set of
643 * properties which might not be implemented by all drivers) this
644 * requires drivers to subclass the state structure.
646 * Such driver-private properties should really only be implemented for
647 * truly hardware/vendor specific state. Instead it is preferred to
648 * standardize atomic extension and decode the properties used to expose
649 * such an extension in the core.
651 * Do not call this function directly, use
652 * drm_atomic_crtc_set_property() instead.
654 * This callback is optional if the driver does not support any
655 * driver-private atomic properties.
659 * This function is called in the state assembly phase of atomic
660 * modesets, which can be aborted for any reason (including on
661 * userspace's request to just check whether a configuration would be
662 * possible). Drivers MUST NOT touch any persistent state (hardware or
663 * software) or data structures except the passed in @state parameter.
665 * Also since userspace controls in which order properties are set this
666 * function must not do any input validation (since the state update is
667 * incomplete and hence likely inconsistent). Instead any such input
668 * validation must be done in the various atomic_check callbacks.
672 * 0 if the property has been found, -EINVAL if the property isn't
673 * implemented by the driver (which should never happen, the core only
674 * asks for properties attached to this CRTC). No other validation is
675 * allowed by the driver. The core already checks that the property
676 * value is within the range (integer, valid enum value, ...) the driver
677 * set when registering the property.
679 int (*atomic_set_property)(struct drm_crtc *crtc,
680 struct drm_crtc_state *state,
681 struct drm_property *property,
684 * @atomic_get_property:
686 * Reads out the decoded driver-private property. This is used to
687 * implement the GETCRTC IOCTL.
689 * Do not call this function directly, use
690 * drm_atomic_crtc_get_property() instead.
692 * This callback is optional if the driver does not support any
693 * driver-private atomic properties.
697 * 0 on success, -EINVAL if the property isn't implemented by the
698 * driver (which should never happen, the core only asks for
699 * properties attached to this CRTC).
701 int (*atomic_get_property)(struct drm_crtc *crtc,
702 const struct drm_crtc_state *state,
703 struct drm_property *property,
708 * struct drm_crtc - central CRTC control structure
709 * @dev: parent DRM device
710 * @port: OF node used by drm_of_find_possible_crtcs()
711 * @head: list management
712 * @mutex: per-CRTC locking
713 * @base: base KMS object for ID tracking etc.
714 * @primary: primary plane for this CRTC
715 * @cursor: cursor plane for this CRTC
716 * @cursor_x: current x position of the cursor, used for universal cursor planes
717 * @cursor_y: current y position of the cursor, used for universal cursor planes
718 * @enabled: is this CRTC enabled?
719 * @mode: current mode timings
720 * @hwmode: mode timings as programmed to hw regs
721 * @x: x position on screen
722 * @y: y position on screen
723 * @funcs: CRTC control functions
724 * @gamma_size: size of gamma ramp
725 * @gamma_store: gamma ramp values
726 * @helper_private: mid-layer private data
727 * @properties: property tracking for this CRTC
728 * @state: current atomic state for this CRTC
729 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
732 * Each CRTC may have one or more connectors associated with it. This structure
733 * allows the CRTC to be controlled.
736 struct drm_device *dev;
737 struct device_node *port;
738 struct list_head head;
745 * This provides a read lock for the overall crtc state (mode, dpms
746 * state, ...) and a write lock for everything which can be update
747 * without a full modeset (fb, cursor data, ...)
749 struct drm_modeset_lock mutex;
751 struct drm_mode_object base;
753 /* primary and cursor planes for CRTC */
754 struct drm_plane *primary;
755 struct drm_plane *cursor;
757 /* position of cursor plane on crtc */
763 /* Requested mode from modesetting. */
764 struct drm_display_mode mode;
766 /* Programmed mode in hw, after adjustments for encoders,
767 * crtc, panel scaling etc. Needed for timestamping etc.
769 struct drm_display_mode hwmode;
772 const struct drm_crtc_funcs *funcs;
774 /* Legacy FB CRTC gamma size for reporting to userspace */
776 uint16_t *gamma_store;
778 /* if you are using the helper */
779 const struct drm_crtc_helper_funcs *helper_private;
781 struct drm_object_properties properties;
783 struct drm_crtc_state *state;
786 * For legacy crtc IOCTLs so that atomic drivers can get at the locking
789 struct drm_modeset_acquire_ctx *acquire_ctx;
793 * struct drm_connector_state - mutable connector state
794 * @connector: backpointer to the connector
795 * @crtc: CRTC to connect connector to, NULL if disabled
796 * @best_encoder: can be used by helpers and drivers to select the encoder
797 * @state: backpointer to global drm_atomic_state
799 struct drm_connector_state {
800 struct drm_connector *connector;
802 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
804 struct drm_encoder *best_encoder;
806 struct drm_atomic_state *state;
810 * struct drm_connector_funcs - control connectors on a given device
812 * Each CRTC may have one or more connectors attached to it. The functions
813 * below allow the core DRM code to control connectors, enumerate available modes,
816 struct drm_connector_funcs {
820 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
821 * is exposed as a standard property on the connector, but diverted to
822 * this callback in the drm core. Note that atomic drivers don't
823 * implement the 4 level DPMS support on the connector any more, but
824 * instead only have an on/off "ACTIVE" property on the CRTC object.
826 * Drivers implementing atomic modeset should use
827 * drm_atomic_helper_connector_dpms() to implement this hook.
831 * 0 on success or a negative error code on failure.
833 int (*dpms)(struct drm_connector *connector, int mode);
838 * Reset connector hardware and software state to off. This function isn't
839 * called by the core directly, only through drm_mode_config_reset().
840 * It's not a helper hook only for historical reasons.
842 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
843 * atomic state using this hook.
845 void (*reset)(struct drm_connector *connector);
850 * Check to see if anything is attached to the connector. The parameter
851 * force is set to false whilst polling, true when checking the
852 * connector due to a user request. force can be used by the driver to
853 * avoid expensive, destructive operations during automated probing.
857 * Note that this hook is only called by the probe helper. It's not in
858 * the helper library vtable purely for historical reasons. The only DRM
859 * core entry point to probe connector state is @fill_modes.
863 * drm_connector_status indicating the connector's status.
865 enum drm_connector_status (*detect)(struct drm_connector *connector,
871 * This function is called to update internal encoder state when the
872 * connector is forced to a certain state by userspace, either through
873 * the sysfs interfaces or on the kernel cmdline. In that case the
874 * @detect callback isn't called.
878 * Note that this hook is only called by the probe helper. It's not in
879 * the helper library vtable purely for historical reasons. The only DRM
880 * core entry point to probe connector state is @fill_modes.
882 void (*force)(struct drm_connector *connector);
887 * Entry point for output detection and basic mode validation. The
888 * driver should reprobe the output if needed (e.g. when hotplug
889 * handling is unreliable), add all detected modes to connector->modes
890 * and filter out any the device can't support in any configuration. It
891 * also needs to filter out any modes wider or higher than the
892 * parameters max_width and max_height indicate.
894 * The drivers must also prune any modes no longer valid from
895 * connector->modes. Furthermore it must update connector->status and
896 * connector->edid. If no EDID has been received for this output
897 * connector->edid must be NULL.
899 * Drivers using the probe helpers should use
900 * drm_helper_probe_single_connector_modes() or
901 * drm_helper_probe_single_connector_modes_nomerge() to implement this
906 * The number of modes detected and filled into connector->modes.
908 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
913 * This is the legacy entry point to update a property attached to the
916 * Drivers implementing atomic modeset should use
917 * drm_atomic_helper_connector_set_property() to implement this hook.
919 * This callback is optional if the driver does not support any legacy
920 * driver-private properties.
924 * 0 on success or a negative error code on failure.
926 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
932 * Clean up connector resources. This is called at driver unload time
933 * through drm_mode_config_cleanup(). It can also be called at runtime
934 * when a connector is being hot-unplugged for drivers that support
935 * connector hotplugging (e.g. DisplayPort MST).
937 void (*destroy)(struct drm_connector *connector);
940 * @atomic_duplicate_state:
942 * Duplicate the current atomic state for this connector and return it.
943 * The core and helpers gurantee that any atomic state duplicated with
944 * this hook and still owned by the caller (i.e. not transferred to the
945 * driver by calling ->atomic_commit() from struct
946 * &drm_mode_config_funcs) will be cleaned up by calling the
947 * @atomic_destroy_state hook in this structure.
949 * Atomic drivers which don't subclass struct &drm_connector_state should use
950 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
951 * state structure to extend it with driver-private state should use
952 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
953 * duplicated in a consistent fashion across drivers.
955 * It is an error to call this hook before connector->state has been
956 * initialized correctly.
960 * If the duplicate state references refcounted resources this hook must
961 * acquire a reference for each of them. The driver must release these
962 * references again in @atomic_destroy_state.
966 * Duplicated atomic state or NULL when the allocation failed.
968 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
971 * @atomic_destroy_state:
973 * Destroy a state duplicated with @atomic_duplicate_state and release
974 * or unreference all resources it references
976 void (*atomic_destroy_state)(struct drm_connector *connector,
977 struct drm_connector_state *state);
980 * @atomic_set_property:
982 * Decode a driver-private property value and store the decoded value
983 * into the passed-in state structure. Since the atomic core decodes all
984 * standardized properties (even for extensions beyond the core set of
985 * properties which might not be implemented by all drivers) this
986 * requires drivers to subclass the state structure.
988 * Such driver-private properties should really only be implemented for
989 * truly hardware/vendor specific state. Instead it is preferred to
990 * standardize atomic extension and decode the properties used to expose
991 * such an extension in the core.
993 * Do not call this function directly, use
994 * drm_atomic_connector_set_property() instead.
996 * This callback is optional if the driver does not support any
997 * driver-private atomic properties.
1001 * This function is called in the state assembly phase of atomic
1002 * modesets, which can be aborted for any reason (including on
1003 * userspace's request to just check whether a configuration would be
1004 * possible). Drivers MUST NOT touch any persistent state (hardware or
1005 * software) or data structures except the passed in @state parameter.
1007 * Also since userspace controls in which order properties are set this
1008 * function must not do any input validation (since the state update is
1009 * incomplete and hence likely inconsistent). Instead any such input
1010 * validation must be done in the various atomic_check callbacks.
1014 * 0 if the property has been found, -EINVAL if the property isn't
1015 * implemented by the driver (which shouldn't ever happen, the core only
1016 * asks for properties attached to this connector). No other validation
1017 * is allowed by the driver. The core already checks that the property
1018 * value is within the range (integer, valid enum value, ...) the driver
1019 * set when registering the property.
1021 int (*atomic_set_property)(struct drm_connector *connector,
1022 struct drm_connector_state *state,
1023 struct drm_property *property,
1027 * @atomic_get_property:
1029 * Reads out the decoded driver-private property. This is used to
1030 * implement the GETCONNECTOR IOCTL.
1032 * Do not call this function directly, use
1033 * drm_atomic_connector_get_property() instead.
1035 * This callback is optional if the driver does not support any
1036 * driver-private atomic properties.
1040 * 0 on success, -EINVAL if the property isn't implemented by the
1041 * driver (which shouldn't ever happen, the core only asks for
1042 * properties attached to this connector).
1044 int (*atomic_get_property)(struct drm_connector *connector,
1045 const struct drm_connector_state *state,
1046 struct drm_property *property,
1051 * struct drm_encoder_funcs - encoder controls
1053 * Encoders sit between CRTCs and connectors.
1055 struct drm_encoder_funcs {
1059 * Reset encoder hardware and software state to off. This function isn't
1060 * called by the core directly, only through drm_mode_config_reset().
1061 * It's not a helper hook only for historical reasons.
1063 void (*reset)(struct drm_encoder *encoder);
1068 * Clean up encoder resources. This is only called at driver unload time
1069 * through drm_mode_config_cleanup() since an encoder cannot be
1070 * hotplugged in DRM.
1072 void (*destroy)(struct drm_encoder *encoder);
1075 #define DRM_CONNECTOR_MAX_ENCODER 3
1078 * struct drm_encoder - central DRM encoder structure
1079 * @dev: parent DRM device
1080 * @head: list management
1081 * @base: base KMS object
1082 * @name: encoder name
1083 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1084 * @possible_crtcs: bitmask of potential CRTC bindings
1085 * @possible_clones: bitmask of potential sibling encoders for cloning
1086 * @crtc: currently bound CRTC
1087 * @bridge: bridge associated to the encoder
1088 * @funcs: control functions
1089 * @helper_private: mid-layer private data
1091 * CRTCs drive pixels to encoders, which convert them into signals
1092 * appropriate for a given connector or set of connectors.
1094 struct drm_encoder {
1095 struct drm_device *dev;
1096 struct list_head head;
1098 struct drm_mode_object base;
1101 uint32_t possible_crtcs;
1102 uint32_t possible_clones;
1104 struct drm_crtc *crtc;
1105 struct drm_bridge *bridge;
1106 const struct drm_encoder_funcs *funcs;
1107 const struct drm_encoder_helper_funcs *helper_private;
1110 /* should we poll this connector for connects and disconnects */
1111 /* hot plug detectable */
1112 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
1113 /* poll for connections */
1114 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1115 /* can cleanly poll for disconnections without flickering the screen */
1116 /* DACs should rarely do this without a lot of testing */
1117 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1119 #define MAX_ELD_BYTES 128
1122 * struct drm_connector - central DRM connector control structure
1123 * @dev: parent DRM device
1124 * @kdev: kernel device for sysfs attributes
1125 * @attr: sysfs attributes
1126 * @head: list management
1127 * @base: base KMS object
1128 * @name: connector name
1129 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1130 * @connector_type_id: index into connector type enum
1131 * @interlace_allowed: can this connector handle interlaced modes?
1132 * @doublescan_allowed: can this connector handle doublescan?
1133 * @stereo_allowed: can this connector handle stereo modes?
1134 * @modes: modes available on this connector (from fill_modes() + user)
1135 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1136 * @probed_modes: list of modes derived directly from the display
1137 * @display_info: information about attached display (e.g. from EDID)
1138 * @funcs: connector control functions
1139 * @edid_blob_ptr: DRM property containing EDID if present
1140 * @properties: property tracking for this connector
1141 * @path_blob_ptr: DRM blob property data for the DP MST path property
1142 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1143 * @dpms: current dpms state
1144 * @helper_private: mid-layer private data
1145 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
1146 * @force: a %DRM_FORCE_<foo> state for forced mode sets
1147 * @override_edid: has the EDID been overwritten through debugfs for testing?
1148 * @encoder_ids: valid encoders for this connector
1149 * @encoder: encoder driving this connector, if any
1150 * @eld: EDID-like data, if present
1151 * @dvi_dual: dual link DVI, if found
1152 * @max_tmds_clock: max clock rate, if found
1153 * @latency_present: AV delay info from ELD, if found
1154 * @video_latency: video latency info from ELD, if found
1155 * @audio_latency: audio latency info from ELD, if found
1156 * @null_edid_counter: track sinks that give us all zeros for the EDID
1157 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
1158 * @edid_corrupt: indicates whether the last read EDID was corrupt
1159 * @debugfs_entry: debugfs directory for this connector
1160 * @state: current atomic state for this connector
1161 * @has_tile: is this connector connected to a tiled monitor
1162 * @tile_group: tile group for the connected monitor
1163 * @tile_is_single_monitor: whether the tile is one monitor housing
1164 * @num_h_tile: number of horizontal tiles in the tile group
1165 * @num_v_tile: number of vertical tiles in the tile group
1166 * @tile_h_loc: horizontal location of this tile
1167 * @tile_v_loc: vertical location of this tile
1168 * @tile_h_size: horizontal size of this tile.
1169 * @tile_v_size: vertical size of this tile.
1171 * Each connector may be connected to one or more CRTCs, or may be clonable by
1172 * another connector if they can share a CRTC. Each connector also has a specific
1173 * position in the broader display (referred to as a 'screen' though it could
1174 * span multiple monitors).
1176 struct drm_connector {
1177 struct drm_device *dev;
1178 struct device *kdev;
1179 struct device_attribute *attr;
1180 struct list_head head;
1182 struct drm_mode_object base;
1187 int connector_type_id;
1188 bool interlace_allowed;
1189 bool doublescan_allowed;
1190 bool stereo_allowed;
1191 struct list_head modes; /* list of modes on this connector */
1193 enum drm_connector_status status;
1195 /* these are modes added by probing with DDC or the BIOS */
1196 struct list_head probed_modes;
1198 struct drm_display_info display_info;
1199 const struct drm_connector_funcs *funcs;
1201 struct drm_property_blob *edid_blob_ptr;
1202 struct drm_object_properties properties;
1204 struct drm_property_blob *path_blob_ptr;
1206 struct drm_property_blob *tile_blob_ptr;
1208 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1210 /* requested DPMS state */
1213 const struct drm_connector_helper_funcs *helper_private;
1215 /* forced on connector */
1216 struct drm_cmdline_mode cmdline_mode;
1217 enum drm_connector_force force;
1219 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
1220 struct drm_encoder *encoder; /* currently active encoder */
1223 uint8_t eld[MAX_ELD_BYTES];
1225 int max_tmds_clock; /* in MHz */
1226 bool latency_present[2];
1227 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1228 int audio_latency[2];
1229 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
1230 unsigned bad_edid_counter;
1232 /* Flag for raw EDID header corruption - used in Displayport
1233 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1237 struct dentry *debugfs_entry;
1239 struct drm_connector_state *state;
1241 /* DisplayID bits */
1243 struct drm_tile_group *tile_group;
1244 bool tile_is_single_monitor;
1246 uint8_t num_h_tile, num_v_tile;
1247 uint8_t tile_h_loc, tile_v_loc;
1248 uint16_t tile_h_size, tile_v_size;
1252 * struct drm_plane_state - mutable plane state
1253 * @plane: backpointer to the plane
1254 * @crtc: currently bound CRTC, NULL if disabled
1255 * @fb: currently bound framebuffer
1256 * @fence: optional fence to wait for before scanning out @fb
1257 * @crtc_x: left position of visible portion of plane on crtc
1258 * @crtc_y: upper position of visible portion of plane on crtc
1259 * @crtc_w: width of visible portion of plane on crtc
1260 * @crtc_h: height of visible portion of plane on crtc
1261 * @src_x: left position of visible portion of plane within
1263 * @src_y: upper position of visible portion of plane within
1265 * @src_w: width of visible portion of plane (in 16.16)
1266 * @src_h: height of visible portion of plane (in 16.16)
1267 * @state: backpointer to global drm_atomic_state
1269 struct drm_plane_state {
1270 struct drm_plane *plane;
1272 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1273 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
1274 struct fence *fence;
1276 /* Signed dest location allows it to be partially off screen */
1277 int32_t crtc_x, crtc_y;
1278 uint32_t crtc_w, crtc_h;
1280 /* Source values are 16.16 fixed point */
1281 uint32_t src_x, src_y;
1282 uint32_t src_h, src_w;
1284 /* Plane rotation */
1285 unsigned int rotation;
1287 struct drm_atomic_state *state;
1292 * struct drm_plane_funcs - driver plane control functions
1294 struct drm_plane_funcs {
1298 * This is the legacy entry point to enable and configure the plane for
1299 * the given CRTC and framebuffer. It is never called to disable the
1300 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1302 * The source rectangle in frame buffer memory coordinates is given by
1303 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1304 * values). Devices that don't support subpixel plane coordinates can
1305 * ignore the fractional part.
1307 * The destination rectangle in CRTC coordinates is given by the
1308 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1309 * Devices scale the source rectangle to the destination rectangle. If
1310 * scaling is not supported, and the source rectangle size doesn't match
1311 * the destination rectangle size, the driver must return a
1312 * -<errorname>EINVAL</errorname> error.
1314 * Drivers implementing atomic modeset should use
1315 * drm_atomic_helper_update_plane() to implement this hook.
1319 * 0 on success or a negative error code on failure.
1321 int (*update_plane)(struct drm_plane *plane,
1322 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1323 int crtc_x, int crtc_y,
1324 unsigned int crtc_w, unsigned int crtc_h,
1325 uint32_t src_x, uint32_t src_y,
1326 uint32_t src_w, uint32_t src_h);
1331 * This is the legacy entry point to disable the plane. The DRM core
1332 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
1333 * with the frame buffer ID set to 0. Disabled planes must not be
1334 * processed by the CRTC.
1336 * Drivers implementing atomic modeset should use
1337 * drm_atomic_helper_disable_plane() to implement this hook.
1341 * 0 on success or a negative error code on failure.
1343 int (*disable_plane)(struct drm_plane *plane);
1348 * Clean up plane resources. This is only called at driver unload time
1349 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1352 void (*destroy)(struct drm_plane *plane);
1357 * Reset plane hardware and software state to off. This function isn't
1358 * called by the core directly, only through drm_mode_config_reset().
1359 * It's not a helper hook only for historical reasons.
1361 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1362 * atomic state using this hook.
1364 void (*reset)(struct drm_plane *plane);
1369 * This is the legacy entry point to update a property attached to the
1372 * Drivers implementing atomic modeset should use
1373 * drm_atomic_helper_plane_set_property() to implement this hook.
1375 * This callback is optional if the driver does not support any legacy
1376 * driver-private properties.
1380 * 0 on success or a negative error code on failure.
1382 int (*set_property)(struct drm_plane *plane,
1383 struct drm_property *property, uint64_t val);
1386 * @atomic_duplicate_state:
1388 * Duplicate the current atomic state for this plane and return it.
1389 * The core and helpers gurantee that any atomic state duplicated with
1390 * this hook and still owned by the caller (i.e. not transferred to the
1391 * driver by calling ->atomic_commit() from struct
1392 * &drm_mode_config_funcs) will be cleaned up by calling the
1393 * @atomic_destroy_state hook in this structure.
1395 * Atomic drivers which don't subclass struct &drm_plane_state should use
1396 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1397 * state structure to extend it with driver-private state should use
1398 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1399 * duplicated in a consistent fashion across drivers.
1401 * It is an error to call this hook before plane->state has been
1402 * initialized correctly.
1406 * If the duplicate state references refcounted resources this hook must
1407 * acquire a reference for each of them. The driver must release these
1408 * references again in @atomic_destroy_state.
1412 * Duplicated atomic state or NULL when the allocation failed.
1414 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
1417 * @atomic_destroy_state:
1419 * Destroy a state duplicated with @atomic_duplicate_state and release
1420 * or unreference all resources it references
1422 void (*atomic_destroy_state)(struct drm_plane *plane,
1423 struct drm_plane_state *state);
1426 * @atomic_set_property:
1428 * Decode a driver-private property value and store the decoded value
1429 * into the passed-in state structure. Since the atomic core decodes all
1430 * standardized properties (even for extensions beyond the core set of
1431 * properties which might not be implemented by all drivers) this
1432 * requires drivers to subclass the state structure.
1434 * Such driver-private properties should really only be implemented for
1435 * truly hardware/vendor specific state. Instead it is preferred to
1436 * standardize atomic extension and decode the properties used to expose
1437 * such an extension in the core.
1439 * Do not call this function directly, use
1440 * drm_atomic_plane_set_property() instead.
1442 * This callback is optional if the driver does not support any
1443 * driver-private atomic properties.
1447 * This function is called in the state assembly phase of atomic
1448 * modesets, which can be aborted for any reason (including on
1449 * userspace's request to just check whether a configuration would be
1450 * possible). Drivers MUST NOT touch any persistent state (hardware or
1451 * software) or data structures except the passed in @state parameter.
1453 * Also since userspace controls in which order properties are set this
1454 * function must not do any input validation (since the state update is
1455 * incomplete and hence likely inconsistent). Instead any such input
1456 * validation must be done in the various atomic_check callbacks.
1460 * 0 if the property has been found, -EINVAL if the property isn't
1461 * implemented by the driver (which shouldn't ever happen, the core only
1462 * asks for properties attached to this plane). No other validation is
1463 * allowed by the driver. The core already checks that the property
1464 * value is within the range (integer, valid enum value, ...) the driver
1465 * set when registering the property.
1467 int (*atomic_set_property)(struct drm_plane *plane,
1468 struct drm_plane_state *state,
1469 struct drm_property *property,
1473 * @atomic_get_property:
1475 * Reads out the decoded driver-private property. This is used to
1476 * implement the GETPLANE IOCTL.
1478 * Do not call this function directly, use
1479 * drm_atomic_plane_get_property() instead.
1481 * This callback is optional if the driver does not support any
1482 * driver-private atomic properties.
1486 * 0 on success, -EINVAL if the property isn't implemented by the
1487 * driver (which should never happen, the core only asks for
1488 * properties attached to this plane).
1490 int (*atomic_get_property)(struct drm_plane *plane,
1491 const struct drm_plane_state *state,
1492 struct drm_property *property,
1496 enum drm_plane_type {
1497 DRM_PLANE_TYPE_OVERLAY,
1498 DRM_PLANE_TYPE_PRIMARY,
1499 DRM_PLANE_TYPE_CURSOR,
1504 * struct drm_plane - central DRM plane control structure
1505 * @dev: DRM device this plane belongs to
1506 * @head: for list management
1507 * @base: base mode object
1508 * @possible_crtcs: pipes this plane can be bound to
1509 * @format_types: array of formats supported by this plane
1510 * @format_count: number of formats supported
1511 * @format_default: driver hasn't supplied supported formats for the plane
1512 * @crtc: currently bound CRTC
1513 * @fb: currently bound fb
1514 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1515 * drm_mode_set_config_internal() to implement correct refcounting.
1516 * @funcs: helper functions
1517 * @properties: property tracking for this plane
1518 * @type: type of plane (overlay, primary, cursor)
1519 * @state: current atomic state for this plane
1522 struct drm_device *dev;
1523 struct list_head head;
1527 struct drm_modeset_lock mutex;
1529 struct drm_mode_object base;
1531 uint32_t possible_crtcs;
1532 uint32_t *format_types;
1533 unsigned int format_count;
1534 bool format_default;
1536 struct drm_crtc *crtc;
1537 struct drm_framebuffer *fb;
1539 struct drm_framebuffer *old_fb;
1541 const struct drm_plane_funcs *funcs;
1543 struct drm_object_properties properties;
1545 enum drm_plane_type type;
1547 const struct drm_plane_helper_funcs *helper_private;
1549 struct drm_plane_state *state;
1553 * struct drm_bridge_funcs - drm_bridge control functions
1554 * @attach: Called during drm_bridge_attach
1556 struct drm_bridge_funcs {
1557 int (*attach)(struct drm_bridge *bridge);
1562 * This callback is used to validate and adjust a mode. The paramater
1563 * mode is the display mode that should be fed to the next element in
1564 * the display chain, either the final &drm_connector or the next
1565 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1566 * requires. It can be modified by this callback and does not need to
1569 * This is the only hook that allows a bridge to reject a modeset. If
1570 * this function passes all other callbacks must succeed for this
1575 * This function is called in the check phase of atomic modesets, which
1576 * can be aborted for any reason (including on userspace's request to
1577 * just check whether a configuration would be possible). Drivers MUST
1578 * NOT touch any persistent state (hardware or software) or data
1579 * structures except the passed in @state parameter.
1583 * True if an acceptable configuration is possible, false if the modeset
1584 * operation should be rejected.
1586 bool (*mode_fixup)(struct drm_bridge *bridge,
1587 const struct drm_display_mode *mode,
1588 struct drm_display_mode *adjusted_mode);
1592 * This callback should disable the bridge. It is called right before
1593 * the preceding element in the display pipe is disabled. If the
1594 * preceding element is a bridge this means it's called before that
1595 * bridge's ->disable() function. If the preceding element is a
1596 * &drm_encoder it's called right before the encoder's ->disable(),
1597 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1599 * The bridge can assume that the display pipe (i.e. clocks and timing
1600 * signals) feeding it is still running when this callback is called.
1602 * The disable callback is optional.
1604 void (*disable)(struct drm_bridge *bridge);
1609 * This callback should disable the bridge. It is called right after
1610 * the preceding element in the display pipe is disabled. If the
1611 * preceding element is a bridge this means it's called after that
1612 * bridge's ->post_disable() function. If the preceding element is a
1613 * &drm_encoder it's called right after the encoder's ->disable(),
1614 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1616 * The bridge must assume that the display pipe (i.e. clocks and timing
1617 * singals) feeding it is no longer running when this callback is
1620 * The post_disable callback is optional.
1622 void (*post_disable)(struct drm_bridge *bridge);
1627 * This callback should set the given mode on the bridge. It is called
1628 * after the ->mode_set() callback for the preceding element in the
1629 * display pipeline has been called already. The display pipe (i.e.
1630 * clocks and timing signals) is off when this function is called.
1632 void (*mode_set)(struct drm_bridge *bridge,
1633 struct drm_display_mode *mode,
1634 struct drm_display_mode *adjusted_mode);
1638 * This callback should enable the bridge. It is called right before
1639 * the preceding element in the display pipe is enabled. If the
1640 * preceding element is a bridge this means it's called before that
1641 * bridge's ->pre_enable() function. If the preceding element is a
1642 * &drm_encoder it's called right before the encoder's ->enable(),
1643 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1645 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1646 * will not yet be running when this callback is called. The bridge must
1647 * not enable the display link feeding the next bridge in the chain (if
1648 * there is one) when this callback is called.
1650 * The pre_enable callback is optional.
1652 void (*pre_enable)(struct drm_bridge *bridge);
1657 * This callback should enable the bridge. It is called right after
1658 * the preceding element in the display pipe is enabled. If the
1659 * preceding element is a bridge this means it's called after that
1660 * bridge's ->enable() function. If the preceding element is a
1661 * &drm_encoder it's called right after the encoder's ->enable(),
1662 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1664 * The bridge can assume that the display pipe (i.e. clocks and timing
1665 * signals) feeding it is running when this callback is called. This
1666 * callback must enable the display link feeding the next bridge in the
1667 * chain if there is one.
1669 * The enable callback is optional.
1671 void (*enable)(struct drm_bridge *bridge);
1675 * struct drm_bridge - central DRM bridge control structure
1676 * @dev: DRM device this bridge belongs to
1677 * @encoder: encoder to which this bridge is connected
1678 * @next: the next bridge in the encoder chain
1679 * @of_node: device node pointer to the bridge
1680 * @list: to keep track of all added bridges
1681 * @funcs: control functions
1682 * @driver_private: pointer to the bridge driver's internal context
1685 struct drm_device *dev;
1686 struct drm_encoder *encoder;
1687 struct drm_bridge *next;
1689 struct device_node *of_node;
1691 struct list_head list;
1693 const struct drm_bridge_funcs *funcs;
1694 void *driver_private;
1698 * struct drm_atomic_state - the global state object for atomic updates
1699 * @dev: parent DRM device
1700 * @allow_modeset: allow full modeset
1701 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
1702 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
1703 * @planes: pointer to array of plane pointers
1704 * @plane_states: pointer to array of plane states pointers
1705 * @crtcs: pointer to array of CRTC pointers
1706 * @crtc_states: pointer to array of CRTC states pointers
1707 * @num_connector: size of the @connectors and @connector_states arrays
1708 * @connectors: pointer to array of connector pointers
1709 * @connector_states: pointer to array of connector states pointers
1710 * @acquire_ctx: acquire context for this atomic modeset state update
1712 struct drm_atomic_state {
1713 struct drm_device *dev;
1714 bool allow_modeset : 1;
1715 bool legacy_cursor_update : 1;
1716 bool legacy_set_config : 1;
1717 struct drm_plane **planes;
1718 struct drm_plane_state **plane_states;
1719 struct drm_crtc **crtcs;
1720 struct drm_crtc_state **crtc_states;
1722 struct drm_connector **connectors;
1723 struct drm_connector_state **connector_states;
1725 struct drm_modeset_acquire_ctx *acquire_ctx;
1730 * struct drm_mode_set - new values for a CRTC config change
1731 * @fb: framebuffer to use for new config
1732 * @crtc: CRTC whose configuration we're about to change
1733 * @mode: mode timings to use
1734 * @x: position of this CRTC relative to @fb
1735 * @y: position of this CRTC relative to @fb
1736 * @connectors: array of connectors to drive with this CRTC if possible
1737 * @num_connectors: size of @connectors array
1739 * Represents a single crtc the connectors that it drives with what mode
1740 * and from which framebuffer it scans out from.
1742 * This is used to set modes.
1744 struct drm_mode_set {
1745 struct drm_framebuffer *fb;
1746 struct drm_crtc *crtc;
1747 struct drm_display_mode *mode;
1752 struct drm_connector **connectors;
1753 size_t num_connectors;
1757 * struct drm_mode_config_funcs - basic driver provided mode setting functions
1759 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1762 struct drm_mode_config_funcs {
1766 * Create a new framebuffer object. The core does basic checks on the
1767 * requested metadata, but most of that is left to the driver. See
1768 * struct &drm_mode_fb_cmd2 for details.
1770 * If the parameters are deemed valid and the backing storage objects in
1771 * the underlying memory manager all exist, then the driver allocates
1772 * a new &drm_framebuffer structure, subclassed to contain
1773 * driver-specific information (like the internal native buffer object
1774 * references). It also needs to fill out all relevant metadata, which
1775 * should be done by calling drm_helper_mode_fill_fb_struct().
1777 * The initialization is finalized by calling drm_framebuffer_init(),
1778 * which registers the framebuffer and makes it accessible to other
1783 * A new framebuffer with an initial reference count of 1 or a negative
1784 * error code encoded with ERR_PTR().
1786 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1787 struct drm_file *file_priv,
1788 const struct drm_mode_fb_cmd2 *mode_cmd);
1791 * @output_poll_changed:
1793 * Callback used by helpers to inform the driver of output configuration
1796 * Drivers implementing fbdev emulation with the helpers can call
1797 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1798 * helper of output changes.
1802 * Except that there's no vtable for device-level helper callbacks
1803 * there's no reason this is a core function.
1805 void (*output_poll_changed)(struct drm_device *dev);
1810 * This is the only hook to validate an atomic modeset update. This
1811 * function must reject any modeset and state changes which the hardware
1812 * or driver doesn't support. This includes but is of course not limited
1815 * - Checking that the modes, framebuffers, scaling and placement
1816 * requirements and so on are within the limits of the hardware.
1818 * - Checking that any hidden shared resources are not oversubscribed.
1819 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1820 * display fifo space (where shared between planes or maybe even
1823 * - Checking that virtualized resources exported to userspace are not
1824 * oversubscribed. For various reasons it can make sense to expose
1825 * more planes, crtcs or encoders than which are physically there. One
1826 * example is dual-pipe operations (which generally should be hidden
1827 * from userspace if when lockstepped in hardware, exposed otherwise),
1828 * where a plane might need 1 hardware plane (if it's just on one
1829 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1830 * shared a hardware plane with a 2nd plane (if there's a compatible
1831 * plane requested on the area handled by the other pipe).
1833 * - Check that any transitional state is possible and that if
1834 * requested, the update can indeed be done in the vblank period
1835 * without temporarily disabling some functions.
1837 * - Check any other constraints the driver or hardware might have.
1839 * - This callback also needs to correctly fill out the &drm_crtc_state
1840 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1841 * reflects the nature of the possible update and returns true if and
1842 * only if the update cannot be applied without tearing within one
1843 * vblank on that CRTC. The core uses that information to reject
1844 * updates which require a full modeset (i.e. blanking the screen, or
1845 * at least pausing updates for a substantial amount of time) if
1846 * userspace has disallowed that in its request.
1848 * - The driver also does not need to repeat basic input validation
1849 * like done for the corresponding legacy entry points. The core does
1850 * that before calling this hook.
1852 * See the documentation of @atomic_commit for an exhaustive list of
1853 * error conditions which don't have to be checked at the
1854 * ->atomic_check() stage?
1856 * See the documentation for struct &drm_atomic_state for how exactly
1857 * an atomic modeset update is described.
1859 * Drivers using the atomic helpers can implement this hook using
1860 * drm_atomic_helper_check(), or one of the exported sub-functions of
1865 * 0 on success or one of the below negative error codes:
1867 * - -EINVAL, if any of the above constraints are violated.
1869 * - -EDEADLK, when returned from an attempt to acquire an additional
1870 * &drm_modeset_lock through drm_modeset_lock().
1872 * - -ENOMEM, if allocating additional state sub-structures failed due
1873 * to lack of memory.
1875 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1876 * This can either be due to a pending signal, or because the driver
1877 * needs to completely bail out to recover from an exceptional
1878 * situation like a GPU hang. From a userspace point all errors are
1881 int (*atomic_check)(struct drm_device *dev,
1882 struct drm_atomic_state *state);
1887 * This is the only hook to commit an atomic modeset update. The core
1888 * guarantees that @atomic_check has been called successfully before
1889 * calling this function, and that nothing has been changed in the
1892 * See the documentation for struct &drm_atomic_state for how exactly
1893 * an atomic modeset update is described.
1895 * Drivers using the atomic helpers can implement this hook using
1896 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1899 * Asynchronous commits (as indicated with the async parameter) must
1900 * do any preparatory work which might result in an unsuccessful commit
1901 * in the context of this callback. The only exceptions are hardware
1902 * errors resulting in -EIO. But even in that case the driver must
1903 * ensure that the display pipe is at least running, to avoid
1904 * compositors crashing when pageflips don't work. Anything else,
1905 * specifically committing the update to the hardware, should be done
1906 * without blocking the caller. For updates which do not require a
1907 * modeset this must be guaranteed.
1909 * The driver must wait for any pending rendering to the new
1910 * framebuffers to complete before executing the flip. It should also
1911 * wait for any pending rendering from other drivers if the underlying
1912 * buffer is a shared dma-buf. Asynchronous commits must not wait for
1913 * rendering in the context of this callback.
1915 * An application can request to be notified when the atomic commit has
1916 * completed. These events are per-CRTC and can be distinguished by the
1917 * CRTC index supplied in &drm_event to userspace.
1919 * The drm core will supply a struct &drm_event in the event
1920 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1921 * drm_crtc_send_vblank_event() function, which the driver should call on
1922 * the provided event upon completion of the atomic commit. Note that if
1923 * the driver supports vblank signalling and timestamping the vblank
1924 * counters and timestamps must agree with the ones returned from page
1925 * flip events. With the current vblank helper infrastructure this can
1926 * be achieved by holding a vblank reference while the page flip is
1927 * pending, acquired through drm_crtc_vblank_get() and released with
1928 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1929 * counter and timestamp tracking though, e.g. if they have accurate
1930 * timestamp registers in hardware.
1934 * Drivers are not allowed to shut down any display pipe successfully
1935 * enabled through an atomic commit on their own. Doing so can result in
1936 * compositors crashing if a page flip is suddenly rejected because the
1941 * 0 on success or one of the below negative error codes:
1943 * - -EBUSY, if an asynchronous updated is requested and there is
1944 * an earlier updated pending. Drivers are allowed to support a queue
1945 * of outstanding updates, but currently no driver supports that.
1946 * Note that drivers must wait for preceding updates to complete if a
1947 * synchronous update is requested, they are not allowed to fail the
1948 * commit in that case.
1950 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1951 * this can happen when trying to pin framebuffers, which must only
1952 * be done when committing the state.
1954 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1955 * that the driver has run out of vram, iommu space or similar GPU
1956 * address space needed for framebuffer.
1958 * - -EIO, if the hardware completely died.
1960 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1961 * This can either be due to a pending signal, or because the driver
1962 * needs to completely bail out to recover from an exceptional
1963 * situation like a GPU hang. From a userspace point of view all errors are
1966 * This list is exhaustive. Specifically this hook is not allowed to
1967 * return -EINVAL (any invalid requests should be caught in
1968 * @atomic_check) or -EDEADLK (this function must not acquire
1969 * additional modeset locks).
1971 int (*atomic_commit)(struct drm_device *dev,
1972 struct drm_atomic_state *state,
1976 * @atomic_state_alloc:
1978 * This optional hook can be used by drivers that want to subclass struct
1979 * &drm_atomic_state to be able to track their own driver-private global
1980 * state easily. If this hook is implemented, drivers must also
1981 * implement @atomic_state_clear and @atomic_state_free.
1985 * A new &drm_atomic_state on success or NULL on failure.
1987 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
1990 * @atomic_state_clear:
1992 * This hook must clear any driver private state duplicated into the
1993 * passed-in &drm_atomic_state. This hook is called when the caller
1994 * encountered a &drm_modeset_lock deadlock and needs to drop all
1995 * already acquired locks as part of the deadlock avoidance dance
1996 * implemented in drm_modeset_lock_backoff().
1998 * Any duplicated state must be invalidated since a concurrent atomic
1999 * update might change it, and the drm atomic interfaces always apply
2000 * updates as relative changes to the current state.
2002 * Drivers that implement this must call drm_atomic_state_default_clear()
2003 * to clear common state.
2005 void (*atomic_state_clear)(struct drm_atomic_state *state);
2008 * @atomic_state_free:
2010 * This hook needs driver private resources and the &drm_atomic_state
2011 * itself. Note that the core first calls drm_atomic_state_clear() to
2012 * avoid code duplicate between the clear and free hooks.
2014 * Drivers that implement this must call drm_atomic_state_default_free()
2015 * to release common resources.
2017 void (*atomic_state_free)(struct drm_atomic_state *state);
2021 * struct drm_mode_config - Mode configuration control structure
2022 * @mutex: mutex protecting KMS related lists and structures
2023 * @connection_mutex: ww mutex protecting connector state and routing
2024 * @acquire_ctx: global implicit acquire context used by atomic drivers for
2026 * @idr_mutex: mutex for KMS ID allocation and management
2027 * @crtc_idr: main KMS ID tracking object
2028 * @fb_lock: mutex to protect fb state and lists
2029 * @num_fb: number of fbs available
2030 * @fb_list: list of framebuffers available
2031 * @num_connector: number of connectors on this device
2032 * @connector_list: list of connector objects
2033 * @num_encoder: number of encoders on this device
2034 * @encoder_list: list of encoder objects
2035 * @num_overlay_plane: number of overlay planes on this device
2036 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2037 * @plane_list: list of plane objects
2038 * @num_crtc: number of CRTCs on this device
2039 * @crtc_list: list of CRTC objects
2040 * @property_list: list of property objects
2041 * @min_width: minimum pixel width on this device
2042 * @min_height: minimum pixel height on this device
2043 * @max_width: maximum pixel width on this device
2044 * @max_height: maximum pixel height on this device
2045 * @funcs: core driver provided mode setting functions
2046 * @fb_base: base address of the framebuffer
2047 * @poll_enabled: track polling support for this device
2048 * @poll_running: track polling status for this device
2049 * @output_poll_work: delayed work for polling in process context
2050 * @property_blob_list: list of all the blob property objects
2051 * @blob_lock: mutex for blob property allocation and management
2052 * @*_property: core property tracking
2053 * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear
2055 * @degamma_lut_size_property: size of the degamma LUT as supported by the
2056 * driver (read-only)
2057 * @ctm_property: Matrix used to convert colors after the lookup in the
2059 * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to
2060 * the gamma space of the connected screen (read-only)
2061 * @gamma_lut_size_property: size of the gamma LUT as supported by the driver
2062 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2063 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2064 * @async_page_flip: does this device support async flips on the primary plane?
2065 * @cursor_width: hint to userspace for max cursor width
2066 * @cursor_height: hint to userspace for max cursor height
2068 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2069 * enumerated by the driver are added here, as are global properties. Some
2070 * global restrictions are also here, e.g. dimension restrictions.
2072 struct drm_mode_config {
2073 struct lock mutex; /* protects configuration (mode lists etc.) */
2074 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2075 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
2076 struct lock idr_mutex; /* for IDR management */
2077 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
2078 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
2079 /* this is limited to one for now */
2081 struct lock fb_lock; /* proctects global and per-file fb lists */
2083 struct list_head fb_list;
2086 struct ida connector_ida;
2087 struct list_head connector_list;
2089 struct list_head encoder_list;
2092 * Track # of overlay planes separately from # of total planes. By
2093 * default we only advertise overlay planes to userspace; if userspace
2094 * sets the "universal plane" capability bit, we'll go ahead and
2095 * expose all planes.
2097 int num_overlay_plane;
2098 int num_total_plane;
2099 struct list_head plane_list;
2102 struct list_head crtc_list;
2104 struct list_head property_list;
2106 int min_width, min_height;
2107 int max_width, max_height;
2108 const struct drm_mode_config_funcs *funcs;
2109 resource_size_t fb_base;
2111 /* output poll support */
2115 struct delayed_work output_poll_work;
2117 struct lock blob_lock;
2119 /* pointers to standard properties */
2120 struct list_head property_blob_list;
2121 struct drm_property *edid_property;
2122 struct drm_property *dpms_property;
2123 struct drm_property *path_property;
2124 struct drm_property *tile_property;
2125 struct drm_property *plane_type_property;
2126 struct drm_property *rotation_property;
2127 struct drm_property *prop_src_x;
2128 struct drm_property *prop_src_y;
2129 struct drm_property *prop_src_w;
2130 struct drm_property *prop_src_h;
2131 struct drm_property *prop_crtc_x;
2132 struct drm_property *prop_crtc_y;
2133 struct drm_property *prop_crtc_w;
2134 struct drm_property *prop_crtc_h;
2135 struct drm_property *prop_fb_id;
2136 struct drm_property *prop_crtc_id;
2137 struct drm_property *prop_active;
2138 struct drm_property *prop_mode_id;
2140 /* DVI-I properties */
2141 struct drm_property *dvi_i_subconnector_property;
2142 struct drm_property *dvi_i_select_subconnector_property;
2145 struct drm_property *tv_subconnector_property;
2146 struct drm_property *tv_select_subconnector_property;
2147 struct drm_property *tv_mode_property;
2148 struct drm_property *tv_left_margin_property;
2149 struct drm_property *tv_right_margin_property;
2150 struct drm_property *tv_top_margin_property;
2151 struct drm_property *tv_bottom_margin_property;
2152 struct drm_property *tv_brightness_property;
2153 struct drm_property *tv_contrast_property;
2154 struct drm_property *tv_flicker_reduction_property;
2155 struct drm_property *tv_overscan_property;
2156 struct drm_property *tv_saturation_property;
2157 struct drm_property *tv_hue_property;
2159 /* Optional properties */
2160 struct drm_property *scaling_mode_property;
2161 struct drm_property *aspect_ratio_property;
2162 struct drm_property *dirty_info_property;
2164 /* Optional color correction properties */
2165 struct drm_property *degamma_lut_property;
2166 struct drm_property *degamma_lut_size_property;
2167 struct drm_property *ctm_property;
2168 struct drm_property *gamma_lut_property;
2169 struct drm_property *gamma_lut_size_property;
2171 /* properties for virtual machine layout */
2172 struct drm_property *suggested_x_property;
2173 struct drm_property *suggested_y_property;
2175 /* dumb ioctl parameters */
2176 uint32_t preferred_depth, prefer_shadow;
2178 /* whether async page flip is supported or not */
2179 bool async_page_flip;
2181 /* whether the driver supports fb modifiers */
2182 bool allow_fb_modifiers;
2185 uint32_t cursor_width, cursor_height;
2189 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2190 * @plane: the loop cursor
2191 * @dev: the DRM device
2192 * @plane_mask: bitmask of plane indices
2194 * Iterate over all planes specified by bitmask.
2196 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
2197 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
2198 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
2201 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2202 * @encoder: the loop cursor
2203 * @dev: the DRM device
2204 * @encoder_mask: bitmask of encoder indices
2206 * Iterate over all encoders specified by bitmask.
2208 #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2209 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2210 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
2212 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2213 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
2214 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2215 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2216 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2217 #define obj_to_property(x) container_of(x, struct drm_property, base)
2218 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
2219 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
2221 struct drm_prop_enum_list {
2227 int drm_crtc_init_with_planes(struct drm_device *dev,
2228 struct drm_crtc *crtc,
2229 struct drm_plane *primary,
2230 struct drm_plane *cursor,
2231 const struct drm_crtc_funcs *funcs,
2232 const char *name, ...);
2233 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
2234 extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
2237 * drm_crtc_mask - find the mask of a registered CRTC
2238 * @crtc: CRTC to find mask for
2240 * Given a registered CRTC, return the mask bit of that CRTC for an
2241 * encoder's possible_crtcs field.
2243 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2245 return 1 << drm_crtc_index(crtc);
2248 extern void drm_connector_ida_init(void);
2249 extern void drm_connector_ida_destroy(void);
2250 extern int drm_connector_init(struct drm_device *dev,
2251 struct drm_connector *connector,
2252 const struct drm_connector_funcs *funcs,
2253 int connector_type);
2254 int drm_connector_register(struct drm_connector *connector);
2255 void drm_connector_unregister(struct drm_connector *connector);
2257 extern void drm_connector_cleanup(struct drm_connector *connector);
2258 extern unsigned int drm_connector_index(struct drm_connector *connector);
2260 /* helpers to {un}register all connectors from sysfs for device */
2261 extern int drm_connector_register_all(struct drm_device *dev);
2262 extern void drm_connector_unregister_all(struct drm_device *dev);
2264 extern int drm_bridge_add(struct drm_bridge *bridge);
2265 extern void drm_bridge_remove(struct drm_bridge *bridge);
2266 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2267 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
2269 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2270 const struct drm_display_mode *mode,
2271 struct drm_display_mode *adjusted_mode);
2272 void drm_bridge_disable(struct drm_bridge *bridge);
2273 void drm_bridge_post_disable(struct drm_bridge *bridge);
2274 void drm_bridge_mode_set(struct drm_bridge *bridge,
2275 struct drm_display_mode *mode,
2276 struct drm_display_mode *adjusted_mode);
2277 void drm_bridge_pre_enable(struct drm_bridge *bridge);
2278 void drm_bridge_enable(struct drm_bridge *bridge);
2281 int drm_encoder_init(struct drm_device *dev,
2282 struct drm_encoder *encoder,
2283 const struct drm_encoder_funcs *funcs,
2284 int encoder_type, const char *name, ...);
2285 extern unsigned int drm_encoder_index(struct drm_encoder *encoder);
2288 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2289 * @encoder: encoder to test
2290 * @crtc: crtc to test
2292 * Return false if @encoder can't be driven by @crtc, true otherwise.
2294 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2295 struct drm_crtc *crtc)
2297 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2301 int drm_universal_plane_init(struct drm_device *dev,
2302 struct drm_plane *plane,
2303 unsigned long possible_crtcs,
2304 const struct drm_plane_funcs *funcs,
2305 const uint32_t *formats,
2306 unsigned int format_count,
2307 enum drm_plane_type type,
2308 const char *name, ...);
2309 extern int drm_plane_init(struct drm_device *dev,
2310 struct drm_plane *plane,
2311 unsigned long possible_crtcs,
2312 const struct drm_plane_funcs *funcs,
2313 const uint32_t *formats, unsigned int format_count,
2315 extern void drm_plane_cleanup(struct drm_plane *plane);
2316 extern unsigned int drm_plane_index(struct drm_plane *plane);
2317 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
2318 extern void drm_plane_force_disable(struct drm_plane *plane);
2319 extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2321 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2322 int *hdisplay, int *vdisplay);
2323 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2325 const struct drm_display_mode *mode,
2326 const struct drm_framebuffer *fb);
2328 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2330 extern const char *drm_get_connector_status_name(enum drm_connector_status status);
2331 extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
2332 extern const char *drm_get_dpms_name(int val);
2333 extern const char *drm_get_dvi_i_subconnector_name(int val);
2334 extern const char *drm_get_dvi_i_select_name(int val);
2335 extern const char *drm_get_tv_subconnector_name(int val);
2336 extern const char *drm_get_tv_select_name(int val);
2337 extern void drm_fb_release(struct drm_file *file_priv);
2338 extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2339 struct drm_file *file_priv);
2340 extern bool drm_probe_ddc(struct i2c_adapter *adapter);
2341 extern struct edid *drm_get_edid(struct drm_connector *connector,
2342 struct i2c_adapter *adapter);
2343 extern struct edid *drm_get_edid_iic(struct drm_connector *connector,
2345 extern struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2346 struct i2c_adapter *adapter);
2347 extern struct edid *drm_edid_duplicate(const struct edid *edid);
2348 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2349 extern void drm_mode_config_init(struct drm_device *dev);
2350 extern void drm_mode_config_reset(struct drm_device *dev);
2351 extern void drm_mode_config_cleanup(struct drm_device *dev);
2353 extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
2355 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
2356 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
2357 const struct edid *edid);
2359 extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2361 unsigned int num_formats);
2363 static inline bool drm_property_type_is(struct drm_property *property,
2366 /* instanceof for props.. handles extended type vs original types: */
2367 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2368 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2369 return property->flags & type;
2372 static inline bool drm_property_type_valid(struct drm_property *property)
2374 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2375 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2376 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2379 extern int drm_object_property_set_value(struct drm_mode_object *obj,
2380 struct drm_property *property,
2382 extern int drm_object_property_get_value(struct drm_mode_object *obj,
2383 struct drm_property *property,
2385 extern int drm_framebuffer_init(struct drm_device *dev,
2386 struct drm_framebuffer *fb,
2387 const struct drm_framebuffer_funcs *funcs);
2388 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2390 extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
2391 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
2392 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
2394 extern void drm_object_attach_property(struct drm_mode_object *obj,
2395 struct drm_property *property,
2397 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2398 const char *name, int num_values);
2399 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2401 const struct drm_prop_enum_list *props,
2403 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2404 int flags, const char *name,
2405 const struct drm_prop_enum_list *props,
2407 uint64_t supported_bits);
2408 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2410 uint64_t min, uint64_t max);
2411 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2412 int flags, const char *name,
2413 int64_t min, int64_t max);
2414 struct drm_property *drm_property_create_object(struct drm_device *dev,
2415 int flags, const char *name, uint32_t type);
2416 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2418 struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2421 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2423 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2424 void drm_property_unreference_blob(struct drm_property_blob *blob);
2425 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2426 extern int drm_property_add_enum(struct drm_property *property, int index,
2427 uint64_t value, const char *name);
2428 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
2429 extern int drm_mode_create_tv_properties(struct drm_device *dev,
2430 unsigned int num_modes,
2431 const char * const modes[]);
2432 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
2433 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
2434 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
2435 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
2436 extern bool drm_property_change_valid_get(struct drm_property *property,
2437 uint64_t value, struct drm_mode_object **ref);
2438 extern void drm_property_change_valid_put(struct drm_property *property,
2439 struct drm_mode_object *ref);
2441 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2442 struct drm_encoder *encoder);
2443 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
2445 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2446 uint32_t id, uint32_t type);
2447 void drm_mode_object_reference(struct drm_mode_object *obj);
2448 void drm_mode_object_unreference(struct drm_mode_object *obj);
2451 extern int drm_mode_getresources(struct drm_device *dev,
2452 void *data, struct drm_file *file_priv);
2453 extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2454 struct drm_file *file_priv);
2455 extern int drm_mode_getcrtc(struct drm_device *dev,
2456 void *data, struct drm_file *file_priv);
2457 extern int drm_mode_getconnector(struct drm_device *dev,
2458 void *data, struct drm_file *file_priv);
2459 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
2460 extern int drm_mode_setcrtc(struct drm_device *dev,
2461 void *data, struct drm_file *file_priv);
2462 extern int drm_mode_getplane(struct drm_device *dev,
2463 void *data, struct drm_file *file_priv);
2464 extern int drm_mode_setplane(struct drm_device *dev,
2465 void *data, struct drm_file *file_priv);
2466 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2467 void *data, struct drm_file *file_priv);
2468 extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2469 void *data, struct drm_file *file_priv);
2470 extern int drm_mode_addfb(struct drm_device *dev,
2471 void *data, struct drm_file *file_priv);
2472 extern int drm_mode_addfb2(struct drm_device *dev,
2473 void *data, struct drm_file *file_priv);
2474 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
2475 extern int drm_mode_rmfb(struct drm_device *dev,
2476 void *data, struct drm_file *file_priv);
2477 extern int drm_mode_getfb(struct drm_device *dev,
2478 void *data, struct drm_file *file_priv);
2479 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2480 void *data, struct drm_file *file_priv);
2482 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2483 void *data, struct drm_file *file_priv);
2484 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2485 void *data, struct drm_file *file_priv);
2486 extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2487 void *data, struct drm_file *file_priv);
2488 extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2489 void *data, struct drm_file *file_priv);
2490 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2491 void *data, struct drm_file *file_priv);
2492 extern int drm_mode_getencoder(struct drm_device *dev,
2493 void *data, struct drm_file *file_priv);
2494 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2495 void *data, struct drm_file *file_priv);
2496 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2497 void *data, struct drm_file *file_priv);
2498 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2499 extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2500 extern bool drm_detect_hdmi_monitor(struct edid *edid);
2501 extern bool drm_detect_monitor_audio(struct edid *edid);
2502 extern bool drm_rgb_quant_range_selectable(struct edid *edid);
2503 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2504 void *data, struct drm_file *file_priv);
2505 extern int drm_add_modes_noedid(struct drm_connector *connector,
2506 int hdisplay, int vdisplay);
2507 extern void drm_set_preferred_mode(struct drm_connector *connector,
2508 int hpref, int vpref);
2510 extern int drm_edid_header_is_valid(const u8 *raw_edid);
2511 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2512 bool *edid_corrupt);
2513 extern bool drm_edid_is_valid(struct edid *edid);
2514 extern void drm_edid_get_monitor_name(struct edid *edid, char *name,
2517 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2519 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2521 extern void drm_mode_put_tile_group(struct drm_device *dev,
2522 struct drm_tile_group *tg);
2523 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2524 int hsize, int vsize, int fresh,
2527 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2528 void *data, struct drm_file *file_priv);
2529 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2530 void *data, struct drm_file *file_priv);
2531 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2532 void *data, struct drm_file *file_priv);
2533 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2534 struct drm_file *file_priv);
2535 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2536 struct drm_file *file_priv);
2537 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2538 struct drm_property *property,
2541 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2543 extern int drm_format_num_planes(uint32_t format);
2544 extern int drm_format_plane_cpp(uint32_t format, int plane);
2545 extern int drm_format_horz_chroma_subsampling(uint32_t format);
2546 extern int drm_format_vert_chroma_subsampling(uint32_t format);
2547 extern int drm_format_plane_width(int width, uint32_t format, int plane);
2548 extern int drm_format_plane_height(int height, uint32_t format, int plane);
2549 extern const char *drm_get_format_name(uint32_t format);
2550 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2551 unsigned int supported_rotations);
2552 extern unsigned int drm_rotation_simplify(unsigned int rotation,
2553 unsigned int supported_rotations);
2557 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2560 struct drm_mode_object *mo;
2561 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2562 return mo ? obj_to_plane(mo) : NULL;
2565 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2568 struct drm_mode_object *mo;
2569 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2570 return mo ? obj_to_crtc(mo) : NULL;
2573 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2576 struct drm_mode_object *mo;
2577 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2578 return mo ? obj_to_encoder(mo) : NULL;
2582 * drm_connector_lookup - lookup connector object
2584 * @id: connector object id
2586 * This function looks up the connector object specified by id
2587 * add takes a reference to it.
2589 static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
2593 struct drm_mode_object *mo;
2594 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2595 return mo ? obj_to_connector(mo) : NULL;
2598 static inline struct drm_property *drm_property_find(struct drm_device *dev,
2601 struct drm_mode_object *mo;
2602 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2603 return mo ? obj_to_property(mo) : NULL;
2607 * Extract a degamma/gamma LUT value provided by user and round it to the
2608 * precision supported by the hardware.
2610 static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2611 uint32_t bit_precision)
2613 uint32_t val = user_input + (1 << (16 - bit_precision - 1));
2614 uint32_t max = 0xffff >> (16 - bit_precision);
2616 val >>= 16 - bit_precision;
2618 return clamp_val(val, 0, max);
2622 * drm_framebuffer_reference - incr the fb refcnt
2625 * This functions increments the fb's refcount.
2627 static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
2629 drm_mode_object_reference(&fb->base);
2633 * drm_framebuffer_unreference - unref a framebuffer
2634 * @fb: framebuffer to unref
2636 * This functions decrements the fb's refcount and frees it if it drops to zero.
2638 static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
2640 drm_mode_object_unreference(&fb->base);
2644 * drm_framebuffer_read_refcount - read the framebuffer reference count.
2647 * This functions returns the framebuffer's reference count.
2649 static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
2651 return atomic_read(&fb->base.refcount.refcount);
2655 * drm_connector_reference - incr the connector refcnt
2656 * @connector: connector
2658 * This function increments the connector's refcount.
2660 static inline void drm_connector_reference(struct drm_connector *connector)
2662 drm_mode_object_reference(&connector->base);
2666 * drm_connector_unreference - unref a connector
2667 * @connector: connector to unref
2669 * This function decrements the connector's refcount and frees it if it drops to zero.
2671 static inline void drm_connector_unreference(struct drm_connector *connector)
2673 drm_mode_object_unreference(&connector->base);
2676 /* Plane list iterator for legacy (overlay only) planes. */
2677 #define drm_for_each_legacy_plane(plane, dev) \
2678 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
2679 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
2681 #define drm_for_each_plane(plane, dev) \
2682 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2684 #define drm_for_each_crtc(crtc, dev) \
2685 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2688 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2691 * The connector hotadd/remove code currently grabs both locks when
2692 * updating lists. Hence readers need only hold either of them to be
2693 * safe and the check amounts to
2695 * WARN_ON(not_holding(A) && not_holding(B)).
2697 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2698 !drm_modeset_is_locked(&mode_config->connection_mutex));
2701 #define drm_for_each_connector(connector, dev) \
2702 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2703 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2704 struct drm_connector, head); \
2705 &connector->head != (&(dev)->mode_config.connector_list); \
2706 connector = list_next_entry(connector, head))
2708 #define drm_for_each_encoder(encoder, dev) \
2709 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2711 #define drm_for_each_fb(fb, dev) \
2712 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2713 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2714 struct drm_framebuffer, head); \
2715 &fb->head != (&(dev)->mode_config.fb_list); \
2716 fb = list_next_entry(fb, head))
2718 #endif /* __DRM_CRTC_H__ */