2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
25 #ifndef __DRM_CRTC_H__
26 #define __DRM_CRTC_H__
28 #include <linux/i2c.h>
29 #include <linux/spinlock.h>
30 #include <linux/types.h>
31 #include <linux/idr.h>
33 #include <linux/hdmi.h>
34 #include <linux/media-bus-format.h>
35 #include <uapi/drm/drm_mode.h>
36 #include <uapi/drm/drm_fourcc.h>
37 #include <drm/drm_modeset_lock.h>
41 struct drm_framebuffer;
42 struct drm_object_properties;
49 struct drm_mode_object {
52 struct drm_object_properties *properties;
54 void (*free_cb)(struct kref *kref);
57 #define DRM_OBJECT_MAX_PROPERTY 24
58 struct drm_object_properties {
59 int count, atomic_count;
60 /* NOTE: if we ever start dynamically destroying properties (ie.
61 * not at drm_mode_config_cleanup() time), then we'd have to do
62 * a better job of detaching property from mode objects to avoid
63 * dangling property pointers:
65 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
66 /* do not read/write values directly, but use drm_object_property_get_value()
67 * and drm_object_property_set_value():
69 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
72 static inline int64_t U642I64(uint64_t val)
74 return (int64_t)*((int64_t *)&val);
76 static inline uint64_t I642U64(int64_t val)
78 return (uint64_t)*((uint64_t *)&val);
82 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
83 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
84 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
86 #define DRM_ROTATE_0 BIT(0)
87 #define DRM_ROTATE_90 BIT(1)
88 #define DRM_ROTATE_180 BIT(2)
89 #define DRM_ROTATE_270 BIT(3)
90 #define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
91 DRM_ROTATE_180 | DRM_ROTATE_270)
92 #define DRM_REFLECT_X BIT(4)
93 #define DRM_REFLECT_Y BIT(5)
94 #define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
96 enum drm_connector_force {
97 DRM_FORCE_UNSPECIFIED,
99 DRM_FORCE_ON, /* force on analog part normally */
100 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
103 #include <drm/drm_modes.h>
105 enum drm_connector_status {
106 connector_status_connected = 1,
107 connector_status_disconnected = 2,
108 connector_status_unknown = 3,
111 enum subpixel_order {
113 SubPixelHorizontalRGB,
114 SubPixelHorizontalBGR,
120 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
121 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
122 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
124 #define DRM_BUS_FLAG_DE_LOW (1<<0)
125 #define DRM_BUS_FLAG_DE_HIGH (1<<1)
126 /* drive data on pos. edge */
127 #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
128 /* drive data on neg. edge */
129 #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
132 * Describes a given display (e.g. CRT or flat panel) and its limitations.
134 struct drm_display_info {
135 char name[DRM_DISPLAY_INFO_LEN];
138 unsigned int width_mm;
139 unsigned int height_mm;
141 /* Clock limits FIXME: storage format */
142 unsigned int min_vfreq, max_vfreq;
143 unsigned int min_hfreq, max_hfreq;
144 unsigned int pixel_clock;
147 enum subpixel_order subpixel_order;
150 const u32 *bus_formats;
151 unsigned int num_bus_formats;
154 /* Mask of supported hdmi deep color modes */
155 u8 edid_hdmi_dc_modes;
160 /* data corresponds to displayid vend/prod/serial */
161 struct drm_tile_group {
162 struct kref refcount;
163 struct drm_device *dev;
169 * struct drm_framebuffer_funcs - framebuffer hooks
171 struct drm_framebuffer_funcs {
175 * Clean up framebuffer resources, specifically also unreference the
176 * backing storage. The core guarantees to call this function for every
177 * framebuffer successfully created by ->fb_create() in
178 * &drm_mode_config_funcs. Drivers must also call
179 * drm_framebuffer_cleanup() to release DRM core resources for this
182 void (*destroy)(struct drm_framebuffer *framebuffer);
187 * Create a buffer handle in the driver-specific buffer manager (either
188 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
189 * the core to implement the GETFB IOCTL, which returns (for
190 * sufficiently priviledged user) also a native buffer handle. This can
191 * be used for seamless transitions between modesetting clients by
192 * copying the current screen contents to a private buffer and blending
193 * between that and the new contents.
195 * GEM based drivers should call drm_gem_handle_create() to create the
200 * 0 on success or a negative error code on failure.
202 int (*create_handle)(struct drm_framebuffer *fb,
203 struct drm_file *file_priv,
204 unsigned int *handle);
208 * Optional callback for the dirty fb IOCTL.
210 * Userspace can notify the driver via this callback that an area of the
211 * framebuffer has changed and should be flushed to the display
212 * hardware. This can also be used internally, e.g. by the fbdev
213 * emulation, though that's not the case currently.
215 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
216 * for more information as all the semantics and arguments have a one to
217 * one mapping on this function.
221 * 0 on success or a negative error code on failure.
223 int (*dirty)(struct drm_framebuffer *framebuffer,
224 struct drm_file *file_priv, unsigned flags,
225 unsigned color, struct drm_clip_rect *clips,
229 struct drm_framebuffer {
230 struct drm_device *dev;
232 * Note that the fb is refcounted for the benefit of driver internals,
233 * for example some hw, disabling a CRTC/plane is asynchronous, and
234 * scanout does not actually complete until the next vblank. So some
235 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
236 * should be deferred. In cases like this, the driver would like to
237 * hold a ref to the fb even though it has already been removed from
238 * userspace perspective.
239 * The refcount is stored inside the mode object.
242 * Place on the dev->mode_config.fb_list, access protected by
243 * dev->mode_config.fb_lock.
245 struct list_head head;
246 struct drm_mode_object base;
247 const struct drm_framebuffer_funcs *funcs;
248 unsigned int pitches[4];
249 unsigned int offsets[4];
250 uint64_t modifier[4];
253 /* depth can be 15 or 16 */
257 uint32_t pixel_format; /* fourcc format */
260 struct list_head filp_head;
263 struct drm_property_blob {
264 struct drm_mode_object base;
265 struct drm_device *dev;
266 struct list_head head_global;
267 struct list_head head_file;
269 unsigned char data[];
272 struct drm_property_enum {
274 struct list_head head;
275 char name[DRM_PROP_NAME_LEN];
278 struct drm_property {
279 struct list_head head;
280 struct drm_mode_object base;
282 char name[DRM_PROP_NAME_LEN];
285 struct drm_device *dev;
287 struct list_head enum_list;
291 struct drm_connector;
293 struct drm_pending_vblank_event;
296 struct drm_atomic_state;
298 struct drm_crtc_helper_funcs;
299 struct drm_encoder_helper_funcs;
300 struct drm_connector_helper_funcs;
301 struct drm_plane_helper_funcs;
304 * struct drm_crtc_state - mutable CRTC state
305 * @crtc: backpointer to the CRTC
306 * @enable: whether the CRTC should be enabled, gates all other state
307 * @active: whether the CRTC is actively displaying (used for DPMS)
308 * @planes_changed: planes on this crtc are updated
309 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
310 * @active_changed: crtc_state->active has been toggled.
311 * @connectors_changed: connectors to this crtc have been updated
312 * @zpos_changed: zpos values of planes on this crtc have been updated
313 * @color_mgmt_changed: color management properties have changed (degamma or
314 * gamma LUT or CSC matrix)
315 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
316 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
317 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
318 * @last_vblank_count: for helpers and drivers to capture the vblank of the
319 * update to ensure framebuffer cleanup isn't done too early
320 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
321 * @mode: current mode timings
322 * @mode_blob: &drm_property_blob for @mode
323 * @degamma_lut: Lookup table for converting framebuffer pixel data
324 * before apply the conversion matrix
325 * @ctm: Transformation matrix
326 * @gamma_lut: Lookup table for converting pixel data after the
328 * @event: optional pointer to a DRM event to signal upon completion of the
330 * @state: backpointer to global drm_atomic_state
332 * Note that the distinction between @enable and @active is rather subtile:
333 * Flipping @active while @enable is set without changing anything else may
334 * never return in a failure from the ->atomic_check callback. Userspace assumes
335 * that a DPMS On will always succeed. In other words: @enable controls resource
336 * assignment, @active controls the actual hardware state.
338 struct drm_crtc_state {
339 struct drm_crtc *crtc;
344 /* computed state bits used by helpers and drivers */
345 bool planes_changed : 1;
346 bool mode_changed : 1;
347 bool active_changed : 1;
348 bool connectors_changed : 1;
349 bool zpos_changed : 1;
350 bool color_mgmt_changed : 1;
352 /* attached planes bitmask:
353 * WARNING: transitional helpers do not maintain plane_mask so
354 * drivers not converted over to atomic helpers should not rely
355 * on plane_mask being accurate!
362 /* last_vblank_count: for vblank waits before cleanup */
363 u32 last_vblank_count;
365 /* adjusted_mode: for use by helpers and drivers */
366 struct drm_display_mode adjusted_mode;
368 struct drm_display_mode mode;
370 /* blob property to expose current mode to atomic userspace */
371 struct drm_property_blob *mode_blob;
373 /* blob property to expose color management to userspace */
374 struct drm_property_blob *degamma_lut;
375 struct drm_property_blob *ctm;
376 struct drm_property_blob *gamma_lut;
378 struct drm_pending_vblank_event *event;
380 struct drm_atomic_state *state;
384 * struct drm_crtc_funcs - control CRTCs for a given device
386 * The drm_crtc_funcs structure is the central CRTC management structure
387 * in the DRM. Each CRTC controls one or more connectors (note that the name
388 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
389 * connectors, not just CRTs).
391 * Each driver is responsible for filling out this structure at startup time,
392 * in addition to providing other modesetting features, like i2c and DDC
395 struct drm_crtc_funcs {
399 * Reset CRTC hardware and software state to off. This function isn't
400 * called by the core directly, only through drm_mode_config_reset().
401 * It's not a helper hook only for historical reasons.
403 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
404 * atomic state using this hook.
406 void (*reset)(struct drm_crtc *crtc);
411 * Update the cursor image. The cursor position is relative to the CRTC
412 * and can be partially or fully outside of the visible area.
414 * Note that contrary to all other KMS functions the legacy cursor entry
415 * points don't take a framebuffer object, but instead take directly a
416 * raw buffer object id from the driver's buffer manager (which is
417 * either GEM or TTM for current drivers).
419 * This entry point is deprecated, drivers should instead implement
420 * universal plane support and register a proper cursor plane using
421 * drm_crtc_init_with_planes().
423 * This callback is optional
427 * 0 on success or a negative error code on failure.
429 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
430 uint32_t handle, uint32_t width, uint32_t height);
435 * Update the cursor image, including hotspot information. The hotspot
436 * must not affect the cursor position in CRTC coordinates, but is only
437 * meant as a hint for virtualized display hardware to coordinate the
438 * guests and hosts cursor position. The cursor hotspot is relative to
439 * the cursor image. Otherwise this works exactly like @cursor_set.
441 * This entry point is deprecated, drivers should instead implement
442 * universal plane support and register a proper cursor plane using
443 * drm_crtc_init_with_planes().
445 * This callback is optional.
449 * 0 on success or a negative error code on failure.
451 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
452 uint32_t handle, uint32_t width, uint32_t height,
453 int32_t hot_x, int32_t hot_y);
458 * Update the cursor position. The cursor does not need to be visible
459 * when this hook is called.
461 * This entry point is deprecated, drivers should instead implement
462 * universal plane support and register a proper cursor plane using
463 * drm_crtc_init_with_planes().
465 * This callback is optional.
469 * 0 on success or a negative error code on failure.
471 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
476 * Set gamma on the CRTC.
478 * This callback is optional.
482 * Drivers that support gamma tables and also fbdev emulation through
483 * the provided helper library need to take care to fill out the gamma
484 * hooks for both. Currently there's a bit an unfortunate duplication
485 * going on, which should eventually be unified to just one set of
488 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
494 * Clean up plane resources. This is only called at driver unload time
495 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
498 void (*destroy)(struct drm_crtc *crtc);
503 * This is the main legacy entry point to change the modeset state on a
504 * CRTC. All the details of the desired configuration are passed in a
505 * struct &drm_mode_set - see there for details.
507 * Drivers implementing atomic modeset should use
508 * drm_atomic_helper_set_config() to implement this hook.
512 * 0 on success or a negative error code on failure.
514 int (*set_config)(struct drm_mode_set *set);
519 * Legacy entry point to schedule a flip to the given framebuffer.
521 * Page flipping is a synchronization mechanism that replaces the frame
522 * buffer being scanned out by the CRTC with a new frame buffer during
523 * vertical blanking, avoiding tearing (except when requested otherwise
524 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
525 * requests a page flip the DRM core verifies that the new frame buffer
526 * is large enough to be scanned out by the CRTC in the currently
527 * configured mode and then calls the CRTC ->page_flip() operation with a
528 * pointer to the new frame buffer.
530 * The driver must wait for any pending rendering to the new framebuffer
531 * to complete before executing the flip. It should also wait for any
532 * pending rendering from other drivers if the underlying buffer is a
535 * An application can request to be notified when the page flip has
536 * completed. The drm core will supply a struct &drm_event in the event
537 * parameter in this case. This can be handled by the
538 * drm_crtc_send_vblank_event() function, which the driver should call on
539 * the provided event upon completion of the flip. Note that if
540 * the driver supports vblank signalling and timestamping the vblank
541 * counters and timestamps must agree with the ones returned from page
542 * flip events. With the current vblank helper infrastructure this can
543 * be achieved by holding a vblank reference while the page flip is
544 * pending, acquired through drm_crtc_vblank_get() and released with
545 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
546 * counter and timestamp tracking though, e.g. if they have accurate
547 * timestamp registers in hardware.
551 * Up to that point drivers need to manage events themselves and can use
552 * even->base.list freely for that. Specifically they need to ensure
553 * that they don't send out page flip (or vblank) events for which the
554 * corresponding drm file has been closed already. The drm core
555 * unfortunately does not (yet) take care of that. Therefore drivers
556 * currently must clean up and release pending events in their
557 * ->preclose driver function.
559 * This callback is optional.
563 * Very early versions of the KMS ABI mandated that the driver must
564 * block (but not reject) any rendering to the old framebuffer until the
565 * flip operation has completed and the old framebuffer is no longer
566 * visible. This requirement has been lifted, and userspace is instead
567 * expected to request delivery of an event and wait with recycling old
568 * buffers until such has been received.
572 * 0 on success or a negative error code on failure. Note that if a
573 * ->page_flip() operation is already pending the callback should return
574 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
575 * or just runtime disabled through DPMS respectively the new atomic
576 * "ACTIVE" state) should result in an -EINVAL error code. Note that
577 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
579 int (*page_flip)(struct drm_crtc *crtc,
580 struct drm_framebuffer *fb,
581 struct drm_pending_vblank_event *event,
587 * This is the legacy entry point to update a property attached to the
590 * Drivers implementing atomic modeset should use
591 * drm_atomic_helper_crtc_set_property() to implement this hook.
593 * This callback is optional if the driver does not support any legacy
594 * driver-private properties.
598 * 0 on success or a negative error code on failure.
600 int (*set_property)(struct drm_crtc *crtc,
601 struct drm_property *property, uint64_t val);
604 * @atomic_duplicate_state:
606 * Duplicate the current atomic state for this CRTC and return it.
607 * The core and helpers gurantee that any atomic state duplicated with
608 * this hook and still owned by the caller (i.e. not transferred to the
609 * driver by calling ->atomic_commit() from struct
610 * &drm_mode_config_funcs) will be cleaned up by calling the
611 * @atomic_destroy_state hook in this structure.
613 * Atomic drivers which don't subclass struct &drm_crtc should use
614 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
615 * state structure to extend it with driver-private state should use
616 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
617 * duplicated in a consistent fashion across drivers.
619 * It is an error to call this hook before crtc->state has been
620 * initialized correctly.
624 * If the duplicate state references refcounted resources this hook must
625 * acquire a reference for each of them. The driver must release these
626 * references again in @atomic_destroy_state.
630 * Duplicated atomic state or NULL when the allocation failed.
632 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
635 * @atomic_destroy_state:
637 * Destroy a state duplicated with @atomic_duplicate_state and release
638 * or unreference all resources it references
640 void (*atomic_destroy_state)(struct drm_crtc *crtc,
641 struct drm_crtc_state *state);
644 * @atomic_set_property:
646 * Decode a driver-private property value and store the decoded value
647 * into the passed-in state structure. Since the atomic core decodes all
648 * standardized properties (even for extensions beyond the core set of
649 * properties which might not be implemented by all drivers) this
650 * requires drivers to subclass the state structure.
652 * Such driver-private properties should really only be implemented for
653 * truly hardware/vendor specific state. Instead it is preferred to
654 * standardize atomic extension and decode the properties used to expose
655 * such an extension in the core.
657 * Do not call this function directly, use
658 * drm_atomic_crtc_set_property() instead.
660 * This callback is optional if the driver does not support any
661 * driver-private atomic properties.
665 * This function is called in the state assembly phase of atomic
666 * modesets, which can be aborted for any reason (including on
667 * userspace's request to just check whether a configuration would be
668 * possible). Drivers MUST NOT touch any persistent state (hardware or
669 * software) or data structures except the passed in @state parameter.
671 * Also since userspace controls in which order properties are set this
672 * function must not do any input validation (since the state update is
673 * incomplete and hence likely inconsistent). Instead any such input
674 * validation must be done in the various atomic_check callbacks.
678 * 0 if the property has been found, -EINVAL if the property isn't
679 * implemented by the driver (which should never happen, the core only
680 * asks for properties attached to this CRTC). No other validation is
681 * allowed by the driver. The core already checks that the property
682 * value is within the range (integer, valid enum value, ...) the driver
683 * set when registering the property.
685 int (*atomic_set_property)(struct drm_crtc *crtc,
686 struct drm_crtc_state *state,
687 struct drm_property *property,
690 * @atomic_get_property:
692 * Reads out the decoded driver-private property. This is used to
693 * implement the GETCRTC IOCTL.
695 * Do not call this function directly, use
696 * drm_atomic_crtc_get_property() instead.
698 * This callback is optional if the driver does not support any
699 * driver-private atomic properties.
703 * 0 on success, -EINVAL if the property isn't implemented by the
704 * driver (which should never happen, the core only asks for
705 * properties attached to this CRTC).
707 int (*atomic_get_property)(struct drm_crtc *crtc,
708 const struct drm_crtc_state *state,
709 struct drm_property *property,
715 * This optional hook can be used to register additional userspace
716 * interfaces attached to the crtc like debugfs interfaces.
717 * It is called late in the driver load sequence from drm_dev_register().
718 * Everything added from this callback should be unregistered in
719 * the early_unregister callback.
723 * 0 on success, or a negative error code on failure.
725 int (*late_register)(struct drm_crtc *crtc);
730 * This optional hook should be used to unregister the additional
731 * userspace interfaces attached to the crtc from
732 * late_unregister(). It is called from drm_dev_unregister(),
733 * early in the driver unload sequence to disable userspace access
734 * before data structures are torndown.
736 void (*early_unregister)(struct drm_crtc *crtc);
740 * struct drm_crtc - central CRTC control structure
741 * @dev: parent DRM device
742 * @port: OF node used by drm_of_find_possible_crtcs()
743 * @head: list management
744 * @name: human readable name, can be overwritten by the driver
745 * @mutex: per-CRTC locking
746 * @base: base KMS object for ID tracking etc.
747 * @primary: primary plane for this CRTC
748 * @cursor: cursor plane for this CRTC
749 * @cursor_x: current x position of the cursor, used for universal cursor planes
750 * @cursor_y: current y position of the cursor, used for universal cursor planes
751 * @enabled: is this CRTC enabled?
752 * @mode: current mode timings
753 * @hwmode: mode timings as programmed to hw regs
754 * @x: x position on screen
755 * @y: y position on screen
756 * @funcs: CRTC control functions
757 * @gamma_size: size of gamma ramp
758 * @gamma_store: gamma ramp values
759 * @helper_private: mid-layer private data
760 * @properties: property tracking for this CRTC
762 * Each CRTC may have one or more connectors associated with it. This structure
763 * allows the CRTC to be controlled.
766 struct drm_device *dev;
767 struct device_node *port;
768 struct list_head head;
775 * This provides a read lock for the overall crtc state (mode, dpms
776 * state, ...) and a write lock for everything which can be update
777 * without a full modeset (fb, cursor data, crtc properties ...). Full
778 * modeset also need to grab dev->mode_config.connection_mutex.
780 struct drm_modeset_lock mutex;
782 struct drm_mode_object base;
784 /* primary and cursor planes for CRTC */
785 struct drm_plane *primary;
786 struct drm_plane *cursor;
789 * @index: Position inside the mode_config.list, can be used as an array
790 * index. It is invariant over the lifetime of the CRTC.
794 /* position of cursor plane on crtc */
800 /* Requested mode from modesetting. */
801 struct drm_display_mode mode;
803 /* Programmed mode in hw, after adjustments for encoders,
804 * crtc, panel scaling etc. Needed for timestamping etc.
806 struct drm_display_mode hwmode;
809 const struct drm_crtc_funcs *funcs;
811 /* Legacy FB CRTC gamma size for reporting to userspace */
813 uint16_t *gamma_store;
815 /* if you are using the helper */
816 const struct drm_crtc_helper_funcs *helper_private;
818 struct drm_object_properties properties;
823 * Current atomic state for this CRTC.
825 struct drm_crtc_state *state;
830 * List of &drm_crtc_commit structures tracking pending commits.
831 * Protected by @commit_lock. This list doesn't hold its own full
832 * reference, but burrows it from the ongoing commit. Commit entries
833 * must be removed from this list once the commit is fully completed,
834 * but before it's correspoding &drm_atomic_state gets destroyed.
836 struct list_head commit_list;
841 * Spinlock to protect @commit_list.
843 spinlock_t commit_lock;
848 * Per-CRTC implicit acquire context used by atomic drivers for legacy
849 * IOCTLs, so that atomic drivers can get at the locking acquire
852 struct drm_modeset_acquire_ctx *acquire_ctx;
856 * struct drm_connector_state - mutable connector state
857 * @connector: backpointer to the connector
858 * @crtc: CRTC to connect connector to, NULL if disabled
859 * @best_encoder: can be used by helpers and drivers to select the encoder
860 * @state: backpointer to global drm_atomic_state
862 struct drm_connector_state {
863 struct drm_connector *connector;
865 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
867 struct drm_encoder *best_encoder;
869 struct drm_atomic_state *state;
873 * struct drm_connector_funcs - control connectors on a given device
875 * Each CRTC may have one or more connectors attached to it. The functions
876 * below allow the core DRM code to control connectors, enumerate available modes,
879 struct drm_connector_funcs {
883 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
884 * is exposed as a standard property on the connector, but diverted to
885 * this callback in the drm core. Note that atomic drivers don't
886 * implement the 4 level DPMS support on the connector any more, but
887 * instead only have an on/off "ACTIVE" property on the CRTC object.
889 * Drivers implementing atomic modeset should use
890 * drm_atomic_helper_connector_dpms() to implement this hook.
894 * 0 on success or a negative error code on failure.
896 int (*dpms)(struct drm_connector *connector, int mode);
901 * Reset connector hardware and software state to off. This function isn't
902 * called by the core directly, only through drm_mode_config_reset().
903 * It's not a helper hook only for historical reasons.
905 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
906 * atomic state using this hook.
908 void (*reset)(struct drm_connector *connector);
913 * Check to see if anything is attached to the connector. The parameter
914 * force is set to false whilst polling, true when checking the
915 * connector due to a user request. force can be used by the driver to
916 * avoid expensive, destructive operations during automated probing.
920 * Note that this hook is only called by the probe helper. It's not in
921 * the helper library vtable purely for historical reasons. The only DRM
922 * core entry point to probe connector state is @fill_modes.
926 * drm_connector_status indicating the connector's status.
928 enum drm_connector_status (*detect)(struct drm_connector *connector,
934 * This function is called to update internal encoder state when the
935 * connector is forced to a certain state by userspace, either through
936 * the sysfs interfaces or on the kernel cmdline. In that case the
937 * @detect callback isn't called.
941 * Note that this hook is only called by the probe helper. It's not in
942 * the helper library vtable purely for historical reasons. The only DRM
943 * core entry point to probe connector state is @fill_modes.
945 void (*force)(struct drm_connector *connector);
950 * Entry point for output detection and basic mode validation. The
951 * driver should reprobe the output if needed (e.g. when hotplug
952 * handling is unreliable), add all detected modes to connector->modes
953 * and filter out any the device can't support in any configuration. It
954 * also needs to filter out any modes wider or higher than the
955 * parameters max_width and max_height indicate.
957 * The drivers must also prune any modes no longer valid from
958 * connector->modes. Furthermore it must update connector->status and
959 * connector->edid. If no EDID has been received for this output
960 * connector->edid must be NULL.
962 * Drivers using the probe helpers should use
963 * drm_helper_probe_single_connector_modes() or
964 * drm_helper_probe_single_connector_modes_nomerge() to implement this
969 * The number of modes detected and filled into connector->modes.
971 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
976 * This is the legacy entry point to update a property attached to the
979 * Drivers implementing atomic modeset should use
980 * drm_atomic_helper_connector_set_property() to implement this hook.
982 * This callback is optional if the driver does not support any legacy
983 * driver-private properties.
987 * 0 on success or a negative error code on failure.
989 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
995 * This optional hook can be used to register additional userspace
996 * interfaces attached to the connector, light backlight control, i2c,
997 * DP aux or similar interfaces. It is called late in the driver load
998 * sequence from drm_connector_register() when registering all the
999 * core drm connector interfaces. Everything added from this callback
1000 * should be unregistered in the early_unregister callback.
1004 * 0 on success, or a negative error code on failure.
1006 int (*late_register)(struct drm_connector *connector);
1009 * @early_unregister:
1011 * This optional hook should be used to unregister the additional
1012 * userspace interfaces attached to the connector from
1013 * late_unregister(). It is called from drm_connector_unregister(),
1014 * early in the driver unload sequence to disable userspace access
1015 * before data structures are torndown.
1017 void (*early_unregister)(struct drm_connector *connector);
1022 * Clean up connector resources. This is called at driver unload time
1023 * through drm_mode_config_cleanup(). It can also be called at runtime
1024 * when a connector is being hot-unplugged for drivers that support
1025 * connector hotplugging (e.g. DisplayPort MST).
1027 void (*destroy)(struct drm_connector *connector);
1030 * @atomic_duplicate_state:
1032 * Duplicate the current atomic state for this connector and return it.
1033 * The core and helpers gurantee that any atomic state duplicated with
1034 * this hook and still owned by the caller (i.e. not transferred to the
1035 * driver by calling ->atomic_commit() from struct
1036 * &drm_mode_config_funcs) will be cleaned up by calling the
1037 * @atomic_destroy_state hook in this structure.
1039 * Atomic drivers which don't subclass struct &drm_connector_state should use
1040 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
1041 * state structure to extend it with driver-private state should use
1042 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
1043 * duplicated in a consistent fashion across drivers.
1045 * It is an error to call this hook before connector->state has been
1046 * initialized correctly.
1050 * If the duplicate state references refcounted resources this hook must
1051 * acquire a reference for each of them. The driver must release these
1052 * references again in @atomic_destroy_state.
1056 * Duplicated atomic state or NULL when the allocation failed.
1058 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
1061 * @atomic_destroy_state:
1063 * Destroy a state duplicated with @atomic_duplicate_state and release
1064 * or unreference all resources it references
1066 void (*atomic_destroy_state)(struct drm_connector *connector,
1067 struct drm_connector_state *state);
1070 * @atomic_set_property:
1072 * Decode a driver-private property value and store the decoded value
1073 * into the passed-in state structure. Since the atomic core decodes all
1074 * standardized properties (even for extensions beyond the core set of
1075 * properties which might not be implemented by all drivers) this
1076 * requires drivers to subclass the state structure.
1078 * Such driver-private properties should really only be implemented for
1079 * truly hardware/vendor specific state. Instead it is preferred to
1080 * standardize atomic extension and decode the properties used to expose
1081 * such an extension in the core.
1083 * Do not call this function directly, use
1084 * drm_atomic_connector_set_property() instead.
1086 * This callback is optional if the driver does not support any
1087 * driver-private atomic properties.
1091 * This function is called in the state assembly phase of atomic
1092 * modesets, which can be aborted for any reason (including on
1093 * userspace's request to just check whether a configuration would be
1094 * possible). Drivers MUST NOT touch any persistent state (hardware or
1095 * software) or data structures except the passed in @state parameter.
1097 * Also since userspace controls in which order properties are set this
1098 * function must not do any input validation (since the state update is
1099 * incomplete and hence likely inconsistent). Instead any such input
1100 * validation must be done in the various atomic_check callbacks.
1104 * 0 if the property has been found, -EINVAL if the property isn't
1105 * implemented by the driver (which shouldn't ever happen, the core only
1106 * asks for properties attached to this connector). No other validation
1107 * is allowed by the driver. The core already checks that the property
1108 * value is within the range (integer, valid enum value, ...) the driver
1109 * set when registering the property.
1111 int (*atomic_set_property)(struct drm_connector *connector,
1112 struct drm_connector_state *state,
1113 struct drm_property *property,
1117 * @atomic_get_property:
1119 * Reads out the decoded driver-private property. This is used to
1120 * implement the GETCONNECTOR IOCTL.
1122 * Do not call this function directly, use
1123 * drm_atomic_connector_get_property() instead.
1125 * This callback is optional if the driver does not support any
1126 * driver-private atomic properties.
1130 * 0 on success, -EINVAL if the property isn't implemented by the
1131 * driver (which shouldn't ever happen, the core only asks for
1132 * properties attached to this connector).
1134 int (*atomic_get_property)(struct drm_connector *connector,
1135 const struct drm_connector_state *state,
1136 struct drm_property *property,
1141 * struct drm_encoder_funcs - encoder controls
1143 * Encoders sit between CRTCs and connectors.
1145 struct drm_encoder_funcs {
1149 * Reset encoder hardware and software state to off. This function isn't
1150 * called by the core directly, only through drm_mode_config_reset().
1151 * It's not a helper hook only for historical reasons.
1153 void (*reset)(struct drm_encoder *encoder);
1158 * Clean up encoder resources. This is only called at driver unload time
1159 * through drm_mode_config_cleanup() since an encoder cannot be
1160 * hotplugged in DRM.
1162 void (*destroy)(struct drm_encoder *encoder);
1167 * This optional hook can be used to register additional userspace
1168 * interfaces attached to the encoder like debugfs interfaces.
1169 * It is called late in the driver load sequence from drm_dev_register().
1170 * Everything added from this callback should be unregistered in
1171 * the early_unregister callback.
1175 * 0 on success, or a negative error code on failure.
1177 int (*late_register)(struct drm_encoder *encoder);
1180 * @early_unregister:
1182 * This optional hook should be used to unregister the additional
1183 * userspace interfaces attached to the encoder from
1184 * late_unregister(). It is called from drm_dev_unregister(),
1185 * early in the driver unload sequence to disable userspace access
1186 * before data structures are torndown.
1188 void (*early_unregister)(struct drm_encoder *encoder);
1191 #define DRM_CONNECTOR_MAX_ENCODER 3
1194 * struct drm_encoder - central DRM encoder structure
1195 * @dev: parent DRM device
1196 * @head: list management
1197 * @base: base KMS object
1198 * @name: human readable name, can be overwritten by the driver
1199 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1200 * @possible_crtcs: bitmask of potential CRTC bindings
1201 * @possible_clones: bitmask of potential sibling encoders for cloning
1202 * @crtc: currently bound CRTC
1203 * @bridge: bridge associated to the encoder
1204 * @funcs: control functions
1205 * @helper_private: mid-layer private data
1207 * CRTCs drive pixels to encoders, which convert them into signals
1208 * appropriate for a given connector or set of connectors.
1210 struct drm_encoder {
1211 struct drm_device *dev;
1212 struct list_head head;
1214 struct drm_mode_object base;
1219 * @index: Position inside the mode_config.list, can be used as an array
1220 * index. It is invariant over the lifetime of the encoder.
1224 uint32_t possible_crtcs;
1225 uint32_t possible_clones;
1227 struct drm_crtc *crtc;
1228 struct drm_bridge *bridge;
1229 const struct drm_encoder_funcs *funcs;
1230 const struct drm_encoder_helper_funcs *helper_private;
1233 /* should we poll this connector for connects and disconnects */
1234 /* hot plug detectable */
1235 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
1236 /* poll for connections */
1237 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1238 /* can cleanly poll for disconnections without flickering the screen */
1239 /* DACs should rarely do this without a lot of testing */
1240 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1242 #define MAX_ELD_BYTES 128
1245 * struct drm_connector - central DRM connector control structure
1246 * @dev: parent DRM device
1247 * @kdev: kernel device for sysfs attributes
1248 * @attr: sysfs attributes
1249 * @head: list management
1250 * @base: base KMS object
1251 * @name: human readable name, can be overwritten by the driver
1252 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1253 * @connector_type_id: index into connector type enum
1254 * @interlace_allowed: can this connector handle interlaced modes?
1255 * @doublescan_allowed: can this connector handle doublescan?
1256 * @stereo_allowed: can this connector handle stereo modes?
1257 * @registered: is this connector exposed (registered) with userspace?
1258 * @modes: modes available on this connector (from fill_modes() + user)
1259 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1260 * @probed_modes: list of modes derived directly from the display
1261 * @display_info: information about attached display (e.g. from EDID)
1262 * @funcs: connector control functions
1263 * @edid_blob_ptr: DRM property containing EDID if present
1264 * @properties: property tracking for this connector
1265 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1266 * @dpms: current dpms state
1267 * @helper_private: mid-layer private data
1268 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
1269 * @force: a %DRM_FORCE_<foo> state for forced mode sets
1270 * @override_edid: has the EDID been overwritten through debugfs for testing?
1271 * @encoder_ids: valid encoders for this connector
1272 * @encoder: encoder driving this connector, if any
1273 * @eld: EDID-like data, if present
1274 * @dvi_dual: dual link DVI, if found
1275 * @max_tmds_clock: max clock rate, if found
1276 * @latency_present: AV delay info from ELD, if found
1277 * @video_latency: video latency info from ELD, if found
1278 * @audio_latency: audio latency info from ELD, if found
1279 * @null_edid_counter: track sinks that give us all zeros for the EDID
1280 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
1281 * @edid_corrupt: indicates whether the last read EDID was corrupt
1282 * @debugfs_entry: debugfs directory for this connector
1283 * @state: current atomic state for this connector
1284 * @has_tile: is this connector connected to a tiled monitor
1285 * @tile_group: tile group for the connected monitor
1286 * @tile_is_single_monitor: whether the tile is one monitor housing
1287 * @num_h_tile: number of horizontal tiles in the tile group
1288 * @num_v_tile: number of vertical tiles in the tile group
1289 * @tile_h_loc: horizontal location of this tile
1290 * @tile_v_loc: vertical location of this tile
1291 * @tile_h_size: horizontal size of this tile.
1292 * @tile_v_size: vertical size of this tile.
1294 * Each connector may be connected to one or more CRTCs, or may be clonable by
1295 * another connector if they can share a CRTC. Each connector also has a specific
1296 * position in the broader display (referred to as a 'screen' though it could
1297 * span multiple monitors).
1299 struct drm_connector {
1300 struct drm_device *dev;
1301 struct device *kdev;
1302 struct device_attribute *attr;
1303 struct list_head head;
1305 struct drm_mode_object base;
1310 * @index: Compacted connector index, which matches the position inside
1311 * the mode_config.list for drivers not supporting hot-add/removing. Can
1312 * be used as an array index. It is invariant over the lifetime of the
1318 int connector_type_id;
1319 bool interlace_allowed;
1320 bool doublescan_allowed;
1321 bool stereo_allowed;
1323 struct list_head modes; /* list of modes on this connector */
1325 enum drm_connector_status status;
1327 /* these are modes added by probing with DDC or the BIOS */
1328 struct list_head probed_modes;
1330 struct drm_display_info display_info;
1331 const struct drm_connector_funcs *funcs;
1333 struct drm_property_blob *edid_blob_ptr;
1334 struct drm_object_properties properties;
1339 * DRM blob property data for the DP MST path property.
1341 struct drm_property_blob *path_blob_ptr;
1346 * DRM blob property data for the tile property (used mostly by DP MST).
1347 * This is meant for screens which are driven through separate display
1348 * pipelines represented by &drm_crtc, which might not be running with
1349 * genlocked clocks. For tiled panels which are genlocked, like
1350 * dual-link LVDS or dual-link DSI, the driver should try to not expose
1351 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1353 struct drm_property_blob *tile_blob_ptr;
1355 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1357 /* requested DPMS state */
1360 const struct drm_connector_helper_funcs *helper_private;
1362 /* forced on connector */
1363 struct drm_cmdline_mode cmdline_mode;
1364 enum drm_connector_force force;
1366 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
1367 struct drm_encoder *encoder; /* currently active encoder */
1370 uint8_t eld[MAX_ELD_BYTES];
1372 int max_tmds_clock; /* in MHz */
1373 bool latency_present[2];
1374 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1375 int audio_latency[2];
1376 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
1377 unsigned bad_edid_counter;
1379 /* Flag for raw EDID header corruption - used in Displayport
1380 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1384 struct dentry *debugfs_entry;
1386 struct drm_connector_state *state;
1388 /* DisplayID bits */
1390 struct drm_tile_group *tile_group;
1391 bool tile_is_single_monitor;
1393 uint8_t num_h_tile, num_v_tile;
1394 uint8_t tile_h_loc, tile_v_loc;
1395 uint16_t tile_h_size, tile_v_size;
1399 * struct drm_plane_state - mutable plane state
1400 * @plane: backpointer to the plane
1401 * @crtc: currently bound CRTC, NULL if disabled
1402 * @fb: currently bound framebuffer
1403 * @fence: optional fence to wait for before scanning out @fb
1404 * @crtc_x: left position of visible portion of plane on crtc
1405 * @crtc_y: upper position of visible portion of plane on crtc
1406 * @crtc_w: width of visible portion of plane on crtc
1407 * @crtc_h: height of visible portion of plane on crtc
1408 * @src_x: left position of visible portion of plane within
1410 * @src_y: upper position of visible portion of plane within
1412 * @src_w: width of visible portion of plane (in 16.16)
1413 * @src_h: height of visible portion of plane (in 16.16)
1414 * @rotation: rotation of the plane
1415 * @zpos: priority of the given plane on crtc (optional)
1416 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
1417 * where N is the number of active planes for given crtc
1418 * @state: backpointer to global drm_atomic_state
1420 struct drm_plane_state {
1421 struct drm_plane *plane;
1423 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1424 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
1425 struct fence *fence;
1427 /* Signed dest location allows it to be partially off screen */
1428 int32_t crtc_x, crtc_y;
1429 uint32_t crtc_w, crtc_h;
1431 /* Source values are 16.16 fixed point */
1432 uint32_t src_x, src_y;
1433 uint32_t src_h, src_w;
1435 /* Plane rotation */
1436 unsigned int rotation;
1440 unsigned int normalized_zpos;
1442 struct drm_atomic_state *state;
1447 * struct drm_plane_funcs - driver plane control functions
1449 struct drm_plane_funcs {
1453 * This is the legacy entry point to enable and configure the plane for
1454 * the given CRTC and framebuffer. It is never called to disable the
1455 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1457 * The source rectangle in frame buffer memory coordinates is given by
1458 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1459 * values). Devices that don't support subpixel plane coordinates can
1460 * ignore the fractional part.
1462 * The destination rectangle in CRTC coordinates is given by the
1463 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1464 * Devices scale the source rectangle to the destination rectangle. If
1465 * scaling is not supported, and the source rectangle size doesn't match
1466 * the destination rectangle size, the driver must return a
1467 * -<errorname>EINVAL</errorname> error.
1469 * Drivers implementing atomic modeset should use
1470 * drm_atomic_helper_update_plane() to implement this hook.
1474 * 0 on success or a negative error code on failure.
1476 int (*update_plane)(struct drm_plane *plane,
1477 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1478 int crtc_x, int crtc_y,
1479 unsigned int crtc_w, unsigned int crtc_h,
1480 uint32_t src_x, uint32_t src_y,
1481 uint32_t src_w, uint32_t src_h);
1486 * This is the legacy entry point to disable the plane. The DRM core
1487 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
1488 * with the frame buffer ID set to 0. Disabled planes must not be
1489 * processed by the CRTC.
1491 * Drivers implementing atomic modeset should use
1492 * drm_atomic_helper_disable_plane() to implement this hook.
1496 * 0 on success or a negative error code on failure.
1498 int (*disable_plane)(struct drm_plane *plane);
1503 * Clean up plane resources. This is only called at driver unload time
1504 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1507 void (*destroy)(struct drm_plane *plane);
1512 * Reset plane hardware and software state to off. This function isn't
1513 * called by the core directly, only through drm_mode_config_reset().
1514 * It's not a helper hook only for historical reasons.
1516 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1517 * atomic state using this hook.
1519 void (*reset)(struct drm_plane *plane);
1524 * This is the legacy entry point to update a property attached to the
1527 * Drivers implementing atomic modeset should use
1528 * drm_atomic_helper_plane_set_property() to implement this hook.
1530 * This callback is optional if the driver does not support any legacy
1531 * driver-private properties.
1535 * 0 on success or a negative error code on failure.
1537 int (*set_property)(struct drm_plane *plane,
1538 struct drm_property *property, uint64_t val);
1541 * @atomic_duplicate_state:
1543 * Duplicate the current atomic state for this plane and return it.
1544 * The core and helpers gurantee that any atomic state duplicated with
1545 * this hook and still owned by the caller (i.e. not transferred to the
1546 * driver by calling ->atomic_commit() from struct
1547 * &drm_mode_config_funcs) will be cleaned up by calling the
1548 * @atomic_destroy_state hook in this structure.
1550 * Atomic drivers which don't subclass struct &drm_plane_state should use
1551 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1552 * state structure to extend it with driver-private state should use
1553 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1554 * duplicated in a consistent fashion across drivers.
1556 * It is an error to call this hook before plane->state has been
1557 * initialized correctly.
1561 * If the duplicate state references refcounted resources this hook must
1562 * acquire a reference for each of them. The driver must release these
1563 * references again in @atomic_destroy_state.
1567 * Duplicated atomic state or NULL when the allocation failed.
1569 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
1572 * @atomic_destroy_state:
1574 * Destroy a state duplicated with @atomic_duplicate_state and release
1575 * or unreference all resources it references
1577 void (*atomic_destroy_state)(struct drm_plane *plane,
1578 struct drm_plane_state *state);
1581 * @atomic_set_property:
1583 * Decode a driver-private property value and store the decoded value
1584 * into the passed-in state structure. Since the atomic core decodes all
1585 * standardized properties (even for extensions beyond the core set of
1586 * properties which might not be implemented by all drivers) this
1587 * requires drivers to subclass the state structure.
1589 * Such driver-private properties should really only be implemented for
1590 * truly hardware/vendor specific state. Instead it is preferred to
1591 * standardize atomic extension and decode the properties used to expose
1592 * such an extension in the core.
1594 * Do not call this function directly, use
1595 * drm_atomic_plane_set_property() instead.
1597 * This callback is optional if the driver does not support any
1598 * driver-private atomic properties.
1602 * This function is called in the state assembly phase of atomic
1603 * modesets, which can be aborted for any reason (including on
1604 * userspace's request to just check whether a configuration would be
1605 * possible). Drivers MUST NOT touch any persistent state (hardware or
1606 * software) or data structures except the passed in @state parameter.
1608 * Also since userspace controls in which order properties are set this
1609 * function must not do any input validation (since the state update is
1610 * incomplete and hence likely inconsistent). Instead any such input
1611 * validation must be done in the various atomic_check callbacks.
1615 * 0 if the property has been found, -EINVAL if the property isn't
1616 * implemented by the driver (which shouldn't ever happen, the core only
1617 * asks for properties attached to this plane). No other validation is
1618 * allowed by the driver. The core already checks that the property
1619 * value is within the range (integer, valid enum value, ...) the driver
1620 * set when registering the property.
1622 int (*atomic_set_property)(struct drm_plane *plane,
1623 struct drm_plane_state *state,
1624 struct drm_property *property,
1628 * @atomic_get_property:
1630 * Reads out the decoded driver-private property. This is used to
1631 * implement the GETPLANE IOCTL.
1633 * Do not call this function directly, use
1634 * drm_atomic_plane_get_property() instead.
1636 * This callback is optional if the driver does not support any
1637 * driver-private atomic properties.
1641 * 0 on success, -EINVAL if the property isn't implemented by the
1642 * driver (which should never happen, the core only asks for
1643 * properties attached to this plane).
1645 int (*atomic_get_property)(struct drm_plane *plane,
1646 const struct drm_plane_state *state,
1647 struct drm_property *property,
1652 * This optional hook can be used to register additional userspace
1653 * interfaces attached to the plane like debugfs interfaces.
1654 * It is called late in the driver load sequence from drm_dev_register().
1655 * Everything added from this callback should be unregistered in
1656 * the early_unregister callback.
1660 * 0 on success, or a negative error code on failure.
1662 int (*late_register)(struct drm_plane *plane);
1665 * @early_unregister:
1667 * This optional hook should be used to unregister the additional
1668 * userspace interfaces attached to the plane from
1669 * late_unregister(). It is called from drm_dev_unregister(),
1670 * early in the driver unload sequence to disable userspace access
1671 * before data structures are torndown.
1673 void (*early_unregister)(struct drm_plane *plane);
1676 enum drm_plane_type {
1677 DRM_PLANE_TYPE_OVERLAY,
1678 DRM_PLANE_TYPE_PRIMARY,
1679 DRM_PLANE_TYPE_CURSOR,
1684 * struct drm_plane - central DRM plane control structure
1685 * @dev: DRM device this plane belongs to
1686 * @head: for list management
1687 * @name: human readable name, can be overwritten by the driver
1688 * @base: base mode object
1689 * @possible_crtcs: pipes this plane can be bound to
1690 * @format_types: array of formats supported by this plane
1691 * @format_count: number of formats supported
1692 * @format_default: driver hasn't supplied supported formats for the plane
1693 * @crtc: currently bound CRTC
1694 * @fb: currently bound fb
1695 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1696 * drm_mode_set_config_internal() to implement correct refcounting.
1697 * @funcs: helper functions
1698 * @properties: property tracking for this plane
1699 * @type: type of plane (overlay, primary, cursor)
1700 * @state: current atomic state for this plane
1701 * @zpos_property: zpos property for this plane
1702 * @helper_private: mid-layer private data
1705 struct drm_device *dev;
1706 struct list_head head;
1713 * Protects modeset plane state, together with the mutex of &drm_crtc
1714 * this plane is linked to (when active, getting actived or getting
1717 struct drm_modeset_lock mutex;
1719 struct drm_mode_object base;
1721 uint32_t possible_crtcs;
1722 uint32_t *format_types;
1723 unsigned int format_count;
1724 bool format_default;
1726 struct drm_crtc *crtc;
1727 struct drm_framebuffer *fb;
1729 struct drm_framebuffer *old_fb;
1731 const struct drm_plane_funcs *funcs;
1733 struct drm_object_properties properties;
1735 enum drm_plane_type type;
1738 * @index: Position inside the mode_config.list, can be used as an array
1739 * index. It is invariant over the lifetime of the plane.
1743 const struct drm_plane_helper_funcs *helper_private;
1745 struct drm_plane_state *state;
1747 struct drm_property *zpos_property;
1751 * struct drm_bridge_funcs - drm_bridge control functions
1752 * @attach: Called during drm_bridge_attach
1754 struct drm_bridge_funcs {
1755 int (*attach)(struct drm_bridge *bridge);
1760 * This callback is used to validate and adjust a mode. The paramater
1761 * mode is the display mode that should be fed to the next element in
1762 * the display chain, either the final &drm_connector or the next
1763 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1764 * requires. It can be modified by this callback and does not need to
1767 * This is the only hook that allows a bridge to reject a modeset. If
1768 * this function passes all other callbacks must succeed for this
1773 * This function is called in the check phase of atomic modesets, which
1774 * can be aborted for any reason (including on userspace's request to
1775 * just check whether a configuration would be possible). Drivers MUST
1776 * NOT touch any persistent state (hardware or software) or data
1777 * structures except the passed in @state parameter.
1781 * True if an acceptable configuration is possible, false if the modeset
1782 * operation should be rejected.
1784 bool (*mode_fixup)(struct drm_bridge *bridge,
1785 const struct drm_display_mode *mode,
1786 struct drm_display_mode *adjusted_mode);
1790 * This callback should disable the bridge. It is called right before
1791 * the preceding element in the display pipe is disabled. If the
1792 * preceding element is a bridge this means it's called before that
1793 * bridge's ->disable() function. If the preceding element is a
1794 * &drm_encoder it's called right before the encoder's ->disable(),
1795 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1797 * The bridge can assume that the display pipe (i.e. clocks and timing
1798 * signals) feeding it is still running when this callback is called.
1800 * The disable callback is optional.
1802 void (*disable)(struct drm_bridge *bridge);
1807 * This callback should disable the bridge. It is called right after
1808 * the preceding element in the display pipe is disabled. If the
1809 * preceding element is a bridge this means it's called after that
1810 * bridge's ->post_disable() function. If the preceding element is a
1811 * &drm_encoder it's called right after the encoder's ->disable(),
1812 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1814 * The bridge must assume that the display pipe (i.e. clocks and timing
1815 * singals) feeding it is no longer running when this callback is
1818 * The post_disable callback is optional.
1820 void (*post_disable)(struct drm_bridge *bridge);
1825 * This callback should set the given mode on the bridge. It is called
1826 * after the ->mode_set() callback for the preceding element in the
1827 * display pipeline has been called already. The display pipe (i.e.
1828 * clocks and timing signals) is off when this function is called.
1830 void (*mode_set)(struct drm_bridge *bridge,
1831 struct drm_display_mode *mode,
1832 struct drm_display_mode *adjusted_mode);
1836 * This callback should enable the bridge. It is called right before
1837 * the preceding element in the display pipe is enabled. If the
1838 * preceding element is a bridge this means it's called before that
1839 * bridge's ->pre_enable() function. If the preceding element is a
1840 * &drm_encoder it's called right before the encoder's ->enable(),
1841 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1843 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1844 * will not yet be running when this callback is called. The bridge must
1845 * not enable the display link feeding the next bridge in the chain (if
1846 * there is one) when this callback is called.
1848 * The pre_enable callback is optional.
1850 void (*pre_enable)(struct drm_bridge *bridge);
1855 * This callback should enable the bridge. It is called right after
1856 * the preceding element in the display pipe is enabled. If the
1857 * preceding element is a bridge this means it's called after that
1858 * bridge's ->enable() function. If the preceding element is a
1859 * &drm_encoder it's called right after the encoder's ->enable(),
1860 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1862 * The bridge can assume that the display pipe (i.e. clocks and timing
1863 * signals) feeding it is running when this callback is called. This
1864 * callback must enable the display link feeding the next bridge in the
1865 * chain if there is one.
1867 * The enable callback is optional.
1869 void (*enable)(struct drm_bridge *bridge);
1873 * struct drm_bridge - central DRM bridge control structure
1874 * @dev: DRM device this bridge belongs to
1875 * @encoder: encoder to which this bridge is connected
1876 * @next: the next bridge in the encoder chain
1877 * @of_node: device node pointer to the bridge
1878 * @list: to keep track of all added bridges
1879 * @funcs: control functions
1880 * @driver_private: pointer to the bridge driver's internal context
1883 struct drm_device *dev;
1884 struct drm_encoder *encoder;
1885 struct drm_bridge *next;
1887 struct device_node *of_node;
1889 struct list_head list;
1891 const struct drm_bridge_funcs *funcs;
1892 void *driver_private;
1896 * struct drm_crtc_commit - track modeset commits on a CRTC
1898 * This structure is used to track pending modeset changes and atomic commit on
1899 * a per-CRTC basis. Since updating the list should never block this structure
1900 * is reference counted to allow waiters to safely wait on an event to complete,
1901 * without holding any locks.
1903 * It has 3 different events in total to allow a fine-grained synchronization
1904 * between outstanding updates::
1906 * atomic commit thread hardware
1908 * write new state into hardware ----> ...
1910 * switch to new state on next
1913 * wait for buffers to show up ...
1915 * ... send completion irq
1916 * irq handler signals flip_done
1917 * cleanup old buffers
1919 * signal cleanup_done
1921 * wait for flip_done <----
1922 * clean up atomic state
1924 * The important bit to know is that cleanup_done is the terminal event, but the
1925 * ordering between flip_done and hw_done is entirely up to the specific driver
1926 * and modeset state change.
1928 * For an implementation of how to use this look at
1929 * drm_atomic_helper_setup_commit() from the atomic helper library.
1931 struct drm_crtc_commit {
1935 * DRM CRTC for this commit.
1937 struct drm_crtc *crtc;
1942 * Reference count for this structure. Needed to allow blocking on
1943 * completions without the risk of the completion disappearing
1951 * Will be signaled when the hardware has flipped to the new set of
1952 * buffers. Signals at the same time as when the drm event for this
1953 * commit is sent to userspace, or when an out-fence is singalled. Note
1954 * that for most hardware, in most cases this happens after @hw_done is
1957 struct completion flip_done;
1962 * Will be signalled when all hw register changes for this commit have
1963 * been written out. Especially when disabling a pipe this can be much
1964 * later than than @flip_done, since that can signal already when the
1965 * screen goes black, whereas to fully shut down a pipe more register
1968 * Note that this does not need to include separately reference-counted
1969 * resources like backing storage buffer pinning, or runtime pm
1972 struct completion hw_done;
1977 * Will be signalled after old buffers have been cleaned up by calling
1978 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1979 * a vblank wait completed it might be a bit later. This completion is
1980 * useful to throttle updates and avoid hardware updates getting ahead
1981 * of the buffer cleanup too much.
1983 struct completion cleanup_done;
1988 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1990 struct list_head commit_entry;
1995 * &drm_pending_vblank_event pointer to clean up private events.
1997 struct drm_pending_vblank_event *event;
2000 struct __drm_planes_state {
2001 struct drm_plane *ptr;
2002 struct drm_plane_state *state;
2005 struct __drm_crtcs_state {
2006 struct drm_crtc *ptr;
2007 struct drm_crtc_state *state;
2008 struct drm_crtc_commit *commit;
2011 struct __drm_connnectors_state {
2012 struct drm_connector *ptr;
2013 struct drm_connector_state *state;
2017 * struct drm_atomic_state - the global state object for atomic updates
2018 * @dev: parent DRM device
2019 * @allow_modeset: allow full modeset
2020 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
2021 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
2022 * @planes: pointer to array of structures with per-plane data
2023 * @crtcs: pointer to array of CRTC pointers
2024 * @num_connector: size of the @connectors and @connector_states arrays
2025 * @connectors: pointer to array of structures with per-connector data
2026 * @acquire_ctx: acquire context for this atomic modeset state update
2028 struct drm_atomic_state {
2029 struct drm_device *dev;
2030 bool allow_modeset : 1;
2031 bool legacy_cursor_update : 1;
2032 bool legacy_set_config : 1;
2033 struct __drm_planes_state *planes;
2034 struct __drm_crtcs_state *crtcs;
2036 struct __drm_connnectors_state *connectors;
2038 struct drm_modeset_acquire_ctx *acquire_ctx;
2043 * Work item which can be used by the driver or helpers to execute the
2044 * commit without blocking.
2046 struct work_struct commit_work;
2051 * struct drm_mode_set - new values for a CRTC config change
2052 * @fb: framebuffer to use for new config
2053 * @crtc: CRTC whose configuration we're about to change
2054 * @mode: mode timings to use
2055 * @x: position of this CRTC relative to @fb
2056 * @y: position of this CRTC relative to @fb
2057 * @connectors: array of connectors to drive with this CRTC if possible
2058 * @num_connectors: size of @connectors array
2060 * Represents a single crtc the connectors that it drives with what mode
2061 * and from which framebuffer it scans out from.
2063 * This is used to set modes.
2065 struct drm_mode_set {
2066 struct drm_framebuffer *fb;
2067 struct drm_crtc *crtc;
2068 struct drm_display_mode *mode;
2073 struct drm_connector **connectors;
2074 size_t num_connectors;
2078 * struct drm_mode_config_funcs - basic driver provided mode setting functions
2080 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
2083 struct drm_mode_config_funcs {
2087 * Create a new framebuffer object. The core does basic checks on the
2088 * requested metadata, but most of that is left to the driver. See
2089 * struct &drm_mode_fb_cmd2 for details.
2091 * If the parameters are deemed valid and the backing storage objects in
2092 * the underlying memory manager all exist, then the driver allocates
2093 * a new &drm_framebuffer structure, subclassed to contain
2094 * driver-specific information (like the internal native buffer object
2095 * references). It also needs to fill out all relevant metadata, which
2096 * should be done by calling drm_helper_mode_fill_fb_struct().
2098 * The initialization is finalized by calling drm_framebuffer_init(),
2099 * which registers the framebuffer and makes it accessible to other
2104 * A new framebuffer with an initial reference count of 1 or a negative
2105 * error code encoded with ERR_PTR().
2107 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
2108 struct drm_file *file_priv,
2109 const struct drm_mode_fb_cmd2 *mode_cmd);
2112 * @output_poll_changed:
2114 * Callback used by helpers to inform the driver of output configuration
2117 * Drivers implementing fbdev emulation with the helpers can call
2118 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
2119 * helper of output changes.
2123 * Except that there's no vtable for device-level helper callbacks
2124 * there's no reason this is a core function.
2126 void (*output_poll_changed)(struct drm_device *dev);
2131 * This is the only hook to validate an atomic modeset update. This
2132 * function must reject any modeset and state changes which the hardware
2133 * or driver doesn't support. This includes but is of course not limited
2136 * - Checking that the modes, framebuffers, scaling and placement
2137 * requirements and so on are within the limits of the hardware.
2139 * - Checking that any hidden shared resources are not oversubscribed.
2140 * This can be shared PLLs, shared lanes, overall memory bandwidth,
2141 * display fifo space (where shared between planes or maybe even
2144 * - Checking that virtualized resources exported to userspace are not
2145 * oversubscribed. For various reasons it can make sense to expose
2146 * more planes, crtcs or encoders than which are physically there. One
2147 * example is dual-pipe operations (which generally should be hidden
2148 * from userspace if when lockstepped in hardware, exposed otherwise),
2149 * where a plane might need 1 hardware plane (if it's just on one
2150 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
2151 * shared a hardware plane with a 2nd plane (if there's a compatible
2152 * plane requested on the area handled by the other pipe).
2154 * - Check that any transitional state is possible and that if
2155 * requested, the update can indeed be done in the vblank period
2156 * without temporarily disabling some functions.
2158 * - Check any other constraints the driver or hardware might have.
2160 * - This callback also needs to correctly fill out the &drm_crtc_state
2161 * in this update to make sure that drm_atomic_crtc_needs_modeset()
2162 * reflects the nature of the possible update and returns true if and
2163 * only if the update cannot be applied without tearing within one
2164 * vblank on that CRTC. The core uses that information to reject
2165 * updates which require a full modeset (i.e. blanking the screen, or
2166 * at least pausing updates for a substantial amount of time) if
2167 * userspace has disallowed that in its request.
2169 * - The driver also does not need to repeat basic input validation
2170 * like done for the corresponding legacy entry points. The core does
2171 * that before calling this hook.
2173 * See the documentation of @atomic_commit for an exhaustive list of
2174 * error conditions which don't have to be checked at the
2175 * ->atomic_check() stage?
2177 * See the documentation for struct &drm_atomic_state for how exactly
2178 * an atomic modeset update is described.
2180 * Drivers using the atomic helpers can implement this hook using
2181 * drm_atomic_helper_check(), or one of the exported sub-functions of
2186 * 0 on success or one of the below negative error codes:
2188 * - -EINVAL, if any of the above constraints are violated.
2190 * - -EDEADLK, when returned from an attempt to acquire an additional
2191 * &drm_modeset_lock through drm_modeset_lock().
2193 * - -ENOMEM, if allocating additional state sub-structures failed due
2194 * to lack of memory.
2196 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2197 * This can either be due to a pending signal, or because the driver
2198 * needs to completely bail out to recover from an exceptional
2199 * situation like a GPU hang. From a userspace point all errors are
2202 int (*atomic_check)(struct drm_device *dev,
2203 struct drm_atomic_state *state);
2208 * This is the only hook to commit an atomic modeset update. The core
2209 * guarantees that @atomic_check has been called successfully before
2210 * calling this function, and that nothing has been changed in the
2213 * See the documentation for struct &drm_atomic_state for how exactly
2214 * an atomic modeset update is described.
2216 * Drivers using the atomic helpers can implement this hook using
2217 * drm_atomic_helper_commit(), or one of the exported sub-functions of
2220 * Nonblocking commits (as indicated with the nonblock parameter) must
2221 * do any preparatory work which might result in an unsuccessful commit
2222 * in the context of this callback. The only exceptions are hardware
2223 * errors resulting in -EIO. But even in that case the driver must
2224 * ensure that the display pipe is at least running, to avoid
2225 * compositors crashing when pageflips don't work. Anything else,
2226 * specifically committing the update to the hardware, should be done
2227 * without blocking the caller. For updates which do not require a
2228 * modeset this must be guaranteed.
2230 * The driver must wait for any pending rendering to the new
2231 * framebuffers to complete before executing the flip. It should also
2232 * wait for any pending rendering from other drivers if the underlying
2233 * buffer is a shared dma-buf. Nonblocking commits must not wait for
2234 * rendering in the context of this callback.
2236 * An application can request to be notified when the atomic commit has
2237 * completed. These events are per-CRTC and can be distinguished by the
2238 * CRTC index supplied in &drm_event to userspace.
2240 * The drm core will supply a struct &drm_event in the event
2241 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
2242 * drm_crtc_send_vblank_event() function, which the driver should call on
2243 * the provided event upon completion of the atomic commit. Note that if
2244 * the driver supports vblank signalling and timestamping the vblank
2245 * counters and timestamps must agree with the ones returned from page
2246 * flip events. With the current vblank helper infrastructure this can
2247 * be achieved by holding a vblank reference while the page flip is
2248 * pending, acquired through drm_crtc_vblank_get() and released with
2249 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
2250 * counter and timestamp tracking though, e.g. if they have accurate
2251 * timestamp registers in hardware.
2255 * Drivers are not allowed to shut down any display pipe successfully
2256 * enabled through an atomic commit on their own. Doing so can result in
2257 * compositors crashing if a page flip is suddenly rejected because the
2262 * 0 on success or one of the below negative error codes:
2264 * - -EBUSY, if a nonblocking updated is requested and there is
2265 * an earlier updated pending. Drivers are allowed to support a queue
2266 * of outstanding updates, but currently no driver supports that.
2267 * Note that drivers must wait for preceding updates to complete if a
2268 * synchronous update is requested, they are not allowed to fail the
2269 * commit in that case.
2271 * - -ENOMEM, if the driver failed to allocate memory. Specifically
2272 * this can happen when trying to pin framebuffers, which must only
2273 * be done when committing the state.
2275 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
2276 * that the driver has run out of vram, iommu space or similar GPU
2277 * address space needed for framebuffer.
2279 * - -EIO, if the hardware completely died.
2281 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2282 * This can either be due to a pending signal, or because the driver
2283 * needs to completely bail out to recover from an exceptional
2284 * situation like a GPU hang. From a userspace point of view all errors are
2287 * This list is exhaustive. Specifically this hook is not allowed to
2288 * return -EINVAL (any invalid requests should be caught in
2289 * @atomic_check) or -EDEADLK (this function must not acquire
2290 * additional modeset locks).
2292 int (*atomic_commit)(struct drm_device *dev,
2293 struct drm_atomic_state *state,
2297 * @atomic_state_alloc:
2299 * This optional hook can be used by drivers that want to subclass struct
2300 * &drm_atomic_state to be able to track their own driver-private global
2301 * state easily. If this hook is implemented, drivers must also
2302 * implement @atomic_state_clear and @atomic_state_free.
2306 * A new &drm_atomic_state on success or NULL on failure.
2308 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
2311 * @atomic_state_clear:
2313 * This hook must clear any driver private state duplicated into the
2314 * passed-in &drm_atomic_state. This hook is called when the caller
2315 * encountered a &drm_modeset_lock deadlock and needs to drop all
2316 * already acquired locks as part of the deadlock avoidance dance
2317 * implemented in drm_modeset_lock_backoff().
2319 * Any duplicated state must be invalidated since a concurrent atomic
2320 * update might change it, and the drm atomic interfaces always apply
2321 * updates as relative changes to the current state.
2323 * Drivers that implement this must call drm_atomic_state_default_clear()
2324 * to clear common state.
2326 void (*atomic_state_clear)(struct drm_atomic_state *state);
2329 * @atomic_state_free:
2331 * This hook needs driver private resources and the &drm_atomic_state
2332 * itself. Note that the core first calls drm_atomic_state_clear() to
2333 * avoid code duplicate between the clear and free hooks.
2335 * Drivers that implement this must call drm_atomic_state_default_free()
2336 * to release common resources.
2338 void (*atomic_state_free)(struct drm_atomic_state *state);
2342 * struct drm_mode_config - Mode configuration control structure
2343 * @mutex: mutex protecting KMS related lists and structures
2344 * @connection_mutex: ww mutex protecting connector state and routing
2345 * @acquire_ctx: global implicit acquire context used by atomic drivers for
2347 * @fb_lock: mutex to protect fb state and lists
2348 * @num_fb: number of fbs available
2349 * @fb_list: list of framebuffers available
2350 * @num_encoder: number of encoders on this device
2351 * @encoder_list: list of encoder objects
2352 * @num_overlay_plane: number of overlay planes on this device
2353 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2354 * @plane_list: list of plane objects
2355 * @num_crtc: number of CRTCs on this device
2356 * @crtc_list: list of CRTC objects
2357 * @property_list: list of property objects
2358 * @min_width: minimum pixel width on this device
2359 * @min_height: minimum pixel height on this device
2360 * @max_width: maximum pixel width on this device
2361 * @max_height: maximum pixel height on this device
2362 * @funcs: core driver provided mode setting functions
2363 * @fb_base: base address of the framebuffer
2364 * @poll_enabled: track polling support for this device
2365 * @poll_running: track polling status for this device
2366 * @delayed_event: track delayed poll uevent deliver for this device
2367 * @output_poll_work: delayed work for polling in process context
2368 * @property_blob_list: list of all the blob property objects
2369 * @blob_lock: mutex for blob property allocation and management
2370 * @*_property: core property tracking
2371 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2372 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2373 * @cursor_width: hint to userspace for max cursor width
2374 * @cursor_height: hint to userspace for max cursor height
2375 * @helper_private: mid-layer private data
2377 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2378 * enumerated by the driver are added here, as are global properties. Some
2379 * global restrictions are also here, e.g. dimension restrictions.
2381 struct drm_mode_config {
2382 struct mutex mutex; /* protects configuration (mode lists etc.) */
2383 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2384 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
2389 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
2392 struct mutex idr_mutex;
2397 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
2398 * connector, modes - just makes life easier to have only one.
2400 struct idr crtc_idr;
2405 * Use this idr for allocating new IDs for tiled sinks like use in some
2406 * high-res DP MST screens.
2408 struct idr tile_idr;
2410 struct mutex fb_lock; /* proctects global and per-file fb lists */
2412 struct list_head fb_list;
2415 * @num_connector: Number of connectors on this device.
2419 * @connector_ida: ID allocator for connector indices.
2421 struct ida connector_ida;
2423 * @connector_list: List of connector objects.
2425 struct list_head connector_list;
2427 struct list_head encoder_list;
2430 * Track # of overlay planes separately from # of total planes. By
2431 * default we only advertise overlay planes to userspace; if userspace
2432 * sets the "universal plane" capability bit, we'll go ahead and
2433 * expose all planes.
2435 int num_overlay_plane;
2436 int num_total_plane;
2437 struct list_head plane_list;
2440 struct list_head crtc_list;
2442 struct list_head property_list;
2444 int min_width, min_height;
2445 int max_width, max_height;
2446 const struct drm_mode_config_funcs *funcs;
2447 resource_size_t fb_base;
2449 /* output poll support */
2453 struct delayed_work output_poll_work;
2455 struct mutex blob_lock;
2457 /* pointers to standard properties */
2458 struct list_head property_blob_list;
2460 * @edid_property: Default connector property to hold the EDID of the
2461 * currently connected sink, if any.
2463 struct drm_property *edid_property;
2465 * @dpms_property: Default connector property to control the
2466 * connector's DPMS state.
2468 struct drm_property *dpms_property;
2470 * @path_property: Default connector property to hold the DP MST path
2473 struct drm_property *path_property;
2475 * @tile_property: Default connector property to store the tile
2476 * position of a tiled screen, for sinks which need to be driven with
2479 struct drm_property *tile_property;
2481 * @plane_type_property: Default plane property to differentiate
2482 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
2484 struct drm_property *plane_type_property;
2486 * @rotation_property: Optional property for planes or CRTCs to specifiy
2489 struct drm_property *rotation_property;
2491 * @prop_src_x: Default atomic plane property for the plane source
2492 * position in the connected &drm_framebuffer.
2494 struct drm_property *prop_src_x;
2496 * @prop_src_y: Default atomic plane property for the plane source
2497 * position in the connected &drm_framebuffer.
2499 struct drm_property *prop_src_y;
2501 * @prop_src_w: Default atomic plane property for the plane source
2502 * position in the connected &drm_framebuffer.
2504 struct drm_property *prop_src_w;
2506 * @prop_src_h: Default atomic plane property for the plane source
2507 * position in the connected &drm_framebuffer.
2509 struct drm_property *prop_src_h;
2511 * @prop_crtc_x: Default atomic plane property for the plane destination
2512 * position in the &drm_crtc is is being shown on.
2514 struct drm_property *prop_crtc_x;
2516 * @prop_crtc_y: Default atomic plane property for the plane destination
2517 * position in the &drm_crtc is is being shown on.
2519 struct drm_property *prop_crtc_y;
2521 * @prop_crtc_w: Default atomic plane property for the plane destination
2522 * position in the &drm_crtc is is being shown on.
2524 struct drm_property *prop_crtc_w;
2526 * @prop_crtc_h: Default atomic plane property for the plane destination
2527 * position in the &drm_crtc is is being shown on.
2529 struct drm_property *prop_crtc_h;
2531 * @prop_fb_id: Default atomic plane property to specify the
2534 struct drm_property *prop_fb_id;
2536 * @prop_crtc_id: Default atomic plane property to specify the
2539 struct drm_property *prop_crtc_id;
2541 * @prop_active: Default atomic CRTC property to control the active
2542 * state, which is the simplified implementation for DPMS in atomic
2545 struct drm_property *prop_active;
2547 * @prop_mode_id: Default atomic CRTC property to set the mode for a
2548 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
2549 * connectors must be of and active must be set to disabled, too.
2551 struct drm_property *prop_mode_id;
2554 * @dvi_i_subconnector_property: Optional DVI-I property to
2555 * differentiate between analog or digital mode.
2557 struct drm_property *dvi_i_subconnector_property;
2559 * @dvi_i_select_subconnector_property: Optional DVI-I property to
2560 * select between analog or digital mode.
2562 struct drm_property *dvi_i_select_subconnector_property;
2565 * @tv_subconnector_property: Optional TV property to differentiate
2566 * between different TV connector types.
2568 struct drm_property *tv_subconnector_property;
2570 * @tv_select_subconnector_property: Optional TV property to select
2571 * between different TV connector types.
2573 struct drm_property *tv_select_subconnector_property;
2575 * @tv_mode_property: Optional TV property to select
2576 * the output TV mode.
2578 struct drm_property *tv_mode_property;
2580 * @tv_left_margin_property: Optional TV property to set the left
2583 struct drm_property *tv_left_margin_property;
2585 * @tv_right_margin_property: Optional TV property to set the right
2588 struct drm_property *tv_right_margin_property;
2590 * @tv_top_margin_property: Optional TV property to set the right
2593 struct drm_property *tv_top_margin_property;
2595 * @tv_bottom_margin_property: Optional TV property to set the right
2598 struct drm_property *tv_bottom_margin_property;
2600 * @tv_brightness_property: Optional TV property to set the
2603 struct drm_property *tv_brightness_property;
2605 * @tv_contrast_property: Optional TV property to set the
2608 struct drm_property *tv_contrast_property;
2610 * @tv_flicker_reduction_property: Optional TV property to control the
2611 * flicker reduction mode.
2613 struct drm_property *tv_flicker_reduction_property;
2615 * @tv_overscan_property: Optional TV property to control the overscan
2618 struct drm_property *tv_overscan_property;
2620 * @tv_saturation_property: Optional TV property to set the
2623 struct drm_property *tv_saturation_property;
2625 * @tv_hue_property: Optional TV property to set the hue.
2627 struct drm_property *tv_hue_property;
2630 * @scaling_mode_property: Optional connector property to control the
2631 * upscaling, mostly used for built-in panels.
2633 struct drm_property *scaling_mode_property;
2635 * @aspect_ratio_property: Optional connector property to control the
2636 * HDMI infoframe aspect ratio setting.
2638 struct drm_property *aspect_ratio_property;
2640 * @dirty_info_property: Optional connector property to give userspace a
2641 * hint that the DIRTY_FB ioctl should be used.
2643 struct drm_property *dirty_info_property;
2646 * @degamma_lut_property: Optional CRTC property to set the LUT used to
2647 * convert the framebuffer's colors to linear gamma.
2649 struct drm_property *degamma_lut_property;
2651 * @degamma_lut_size_property: Optional CRTC property for the size of
2652 * the degamma LUT as supported by the driver (read-only).
2654 struct drm_property *degamma_lut_size_property;
2656 * @ctm_property: Optional CRTC property to set the
2657 * matrix used to convert colors after the lookup in the
2660 struct drm_property *ctm_property;
2662 * @gamma_lut_property: Optional CRTC property to set the LUT used to
2663 * convert the colors, after the CTM matrix, to the gamma space of the
2666 struct drm_property *gamma_lut_property;
2668 * @gamma_lut_size_property: Optional CRTC property for the size of the
2669 * gamma LUT as supported by the driver (read-only).
2671 struct drm_property *gamma_lut_size_property;
2674 * @suggested_x_property: Optional connector property with a hint for
2675 * the position of the output on the host's screen.
2677 struct drm_property *suggested_x_property;
2679 * @suggested_y_property: Optional connector property with a hint for
2680 * the position of the output on the host's screen.
2682 struct drm_property *suggested_y_property;
2684 /* dumb ioctl parameters */
2685 uint32_t preferred_depth, prefer_shadow;
2688 * @async_page_flip: Does this device support async flips on the primary
2691 bool async_page_flip;
2694 * @allow_fb_modifiers:
2696 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
2698 bool allow_fb_modifiers;
2701 uint32_t cursor_width, cursor_height;
2703 struct drm_mode_config_helper_funcs *helper_private;
2707 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2708 * @plane: the loop cursor
2709 * @dev: the DRM device
2710 * @plane_mask: bitmask of plane indices
2712 * Iterate over all planes specified by bitmask.
2714 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
2715 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
2716 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
2719 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2720 * @encoder: the loop cursor
2721 * @dev: the DRM device
2722 * @encoder_mask: bitmask of encoder indices
2724 * Iterate over all encoders specified by bitmask.
2726 #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2727 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2728 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
2730 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2731 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
2732 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2733 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2734 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2735 #define obj_to_property(x) container_of(x, struct drm_property, base)
2736 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
2737 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
2739 struct drm_prop_enum_list {
2744 extern __printf(6, 7)
2745 int drm_crtc_init_with_planes(struct drm_device *dev,
2746 struct drm_crtc *crtc,
2747 struct drm_plane *primary,
2748 struct drm_plane *cursor,
2749 const struct drm_crtc_funcs *funcs,
2750 const char *name, ...);
2751 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
2754 * drm_crtc_index - find the index of a registered CRTC
2755 * @crtc: CRTC to find index for
2757 * Given a registered CRTC, return the index of that CRTC within a DRM
2758 * device's list of CRTCs.
2760 static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2766 * drm_crtc_mask - find the mask of a registered CRTC
2767 * @crtc: CRTC to find mask for
2769 * Given a registered CRTC, return the mask bit of that CRTC for an
2770 * encoder's possible_crtcs field.
2772 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2774 return 1 << drm_crtc_index(crtc);
2777 int drm_connector_init(struct drm_device *dev,
2778 struct drm_connector *connector,
2779 const struct drm_connector_funcs *funcs,
2780 int connector_type);
2781 int drm_connector_register(struct drm_connector *connector);
2782 void drm_connector_unregister(struct drm_connector *connector);
2784 extern void drm_connector_cleanup(struct drm_connector *connector);
2785 static inline unsigned drm_connector_index(struct drm_connector *connector)
2787 return connector->index;
2790 extern __printf(5, 6)
2791 int drm_encoder_init(struct drm_device *dev,
2792 struct drm_encoder *encoder,
2793 const struct drm_encoder_funcs *funcs,
2794 int encoder_type, const char *name, ...);
2797 * drm_encoder_index - find the index of a registered encoder
2798 * @encoder: encoder to find index for
2800 * Given a registered encoder, return the index of that encoder within a DRM
2801 * device's list of encoders.
2803 static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
2805 return encoder->index;
2809 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2810 * @encoder: encoder to test
2811 * @crtc: crtc to test
2813 * Return false if @encoder can't be driven by @crtc, true otherwise.
2815 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2816 struct drm_crtc *crtc)
2818 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2821 extern __printf(8, 9)
2822 int drm_universal_plane_init(struct drm_device *dev,
2823 struct drm_plane *plane,
2824 unsigned long possible_crtcs,
2825 const struct drm_plane_funcs *funcs,
2826 const uint32_t *formats,
2827 unsigned int format_count,
2828 enum drm_plane_type type,
2829 const char *name, ...);
2830 extern int drm_plane_init(struct drm_device *dev,
2831 struct drm_plane *plane,
2832 unsigned long possible_crtcs,
2833 const struct drm_plane_funcs *funcs,
2834 const uint32_t *formats, unsigned int format_count,
2836 extern void drm_plane_cleanup(struct drm_plane *plane);
2839 * drm_plane_index - find the index of a registered plane
2840 * @plane: plane to find index for
2842 * Given a registered plane, return the index of that plane within a DRM
2843 * device's list of planes.
2845 static inline unsigned int drm_plane_index(struct drm_plane *plane)
2847 return plane->index;
2849 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
2850 extern void drm_plane_force_disable(struct drm_plane *plane);
2851 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2852 int *hdisplay, int *vdisplay);
2853 extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2854 extern int drm_crtc_force_disable_all(struct drm_device *dev);
2856 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2858 extern const char *drm_get_connector_status_name(enum drm_connector_status status);
2859 extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
2860 extern const char *drm_get_dpms_name(int val);
2861 extern const char *drm_get_dvi_i_subconnector_name(int val);
2862 extern const char *drm_get_dvi_i_select_name(int val);
2863 extern const char *drm_get_tv_subconnector_name(int val);
2864 extern const char *drm_get_tv_select_name(int val);
2865 extern void drm_mode_config_init(struct drm_device *dev);
2866 extern void drm_mode_config_reset(struct drm_device *dev);
2867 extern void drm_mode_config_cleanup(struct drm_device *dev);
2869 extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
2871 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
2872 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
2873 const struct edid *edid);
2875 extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2877 unsigned int num_formats);
2879 static inline bool drm_property_type_is(struct drm_property *property,
2882 /* instanceof for props.. handles extended type vs original types: */
2883 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2884 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2885 return property->flags & type;
2888 extern int drm_object_property_set_value(struct drm_mode_object *obj,
2889 struct drm_property *property,
2891 extern int drm_object_property_get_value(struct drm_mode_object *obj,
2892 struct drm_property *property,
2894 extern int drm_framebuffer_init(struct drm_device *dev,
2895 struct drm_framebuffer *fb,
2896 const struct drm_framebuffer_funcs *funcs);
2897 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2899 extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
2900 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
2901 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
2903 extern void drm_object_attach_property(struct drm_mode_object *obj,
2904 struct drm_property *property,
2906 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2907 const char *name, int num_values);
2908 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2910 const struct drm_prop_enum_list *props,
2912 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2913 int flags, const char *name,
2914 const struct drm_prop_enum_list *props,
2916 uint64_t supported_bits);
2917 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2919 uint64_t min, uint64_t max);
2920 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2921 int flags, const char *name,
2922 int64_t min, int64_t max);
2923 struct drm_property *drm_property_create_object(struct drm_device *dev,
2924 int flags, const char *name, uint32_t type);
2925 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2927 struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2930 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2932 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2933 void drm_property_unreference_blob(struct drm_property_blob *blob);
2934 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2935 extern int drm_property_add_enum(struct drm_property *property, int index,
2936 uint64_t value, const char *name);
2937 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
2938 extern int drm_mode_create_tv_properties(struct drm_device *dev,
2939 unsigned int num_modes,
2940 const char * const modes[]);
2941 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
2942 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
2943 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
2944 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
2946 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2947 struct drm_encoder *encoder);
2948 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
2951 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
2953 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
2955 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2957 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2959 extern void drm_mode_put_tile_group(struct drm_device *dev,
2960 struct drm_tile_group *tg);
2962 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2963 struct drm_property *property,
2966 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2967 unsigned int supported_rotations);
2968 extern unsigned int drm_rotation_simplify(unsigned int rotation,
2969 unsigned int supported_rotations);
2970 extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2971 uint degamma_lut_size,
2973 uint gamma_lut_size);
2975 int drm_plane_create_zpos_property(struct drm_plane *plane,
2977 unsigned int min, unsigned int max);
2979 int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
2983 struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2984 uint32_t id, uint32_t type);
2985 void drm_mode_object_reference(struct drm_mode_object *obj);
2986 void drm_mode_object_unreference(struct drm_mode_object *obj);
2988 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2991 struct drm_mode_object *mo;
2992 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2993 return mo ? obj_to_plane(mo) : NULL;
2996 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2999 struct drm_mode_object *mo;
3000 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
3001 return mo ? obj_to_crtc(mo) : NULL;
3004 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
3007 struct drm_mode_object *mo;
3008 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
3009 return mo ? obj_to_encoder(mo) : NULL;
3013 * drm_connector_lookup - lookup connector object
3015 * @id: connector object id
3017 * This function looks up the connector object specified by id
3018 * add takes a reference to it.
3020 static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
3023 struct drm_mode_object *mo;
3024 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
3025 return mo ? obj_to_connector(mo) : NULL;
3028 static inline struct drm_property *drm_property_find(struct drm_device *dev,
3031 struct drm_mode_object *mo;
3032 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
3033 return mo ? obj_to_property(mo) : NULL;
3037 * Extract a degamma/gamma LUT value provided by user and round it to the
3038 * precision supported by the hardware.
3040 static inline uint32_t drm_color_lut_extract(uint32_t user_input,
3041 uint32_t bit_precision)
3043 uint32_t val = user_input;
3044 uint32_t max = 0xffff >> (16 - bit_precision);
3046 /* Round only if we're not using full precision. */
3047 if (bit_precision < 16) {
3048 val += 1UL << (16 - bit_precision - 1);
3049 val >>= 16 - bit_precision;
3052 return clamp_val(val, 0, max);
3056 * drm_framebuffer_reference - incr the fb refcnt
3059 * This functions increments the fb's refcount.
3061 static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
3063 drm_mode_object_reference(&fb->base);
3067 * drm_framebuffer_unreference - unref a framebuffer
3068 * @fb: framebuffer to unref
3070 * This functions decrements the fb's refcount and frees it if it drops to zero.
3072 static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
3074 drm_mode_object_unreference(&fb->base);
3078 * drm_framebuffer_read_refcount - read the framebuffer reference count.
3081 * This functions returns the framebuffer's reference count.
3083 static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
3085 return atomic_read(&fb->base.refcount.refcount);
3089 * drm_connector_reference - incr the connector refcnt
3090 * @connector: connector
3092 * This function increments the connector's refcount.
3094 static inline void drm_connector_reference(struct drm_connector *connector)
3096 drm_mode_object_reference(&connector->base);
3100 * drm_connector_unreference - unref a connector
3101 * @connector: connector to unref
3103 * This function decrements the connector's refcount and frees it if it drops to zero.
3105 static inline void drm_connector_unreference(struct drm_connector *connector)
3107 drm_mode_object_unreference(&connector->base);
3110 /* Plane list iterator for legacy (overlay only) planes. */
3111 #define drm_for_each_legacy_plane(plane, dev) \
3112 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
3113 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
3115 #define drm_for_each_plane(plane, dev) \
3116 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
3118 #define drm_for_each_crtc(crtc, dev) \
3119 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
3122 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
3125 * The connector hotadd/remove code currently grabs both locks when
3126 * updating lists. Hence readers need only hold either of them to be
3127 * safe and the check amounts to
3129 * WARN_ON(not_holding(A) && not_holding(B)).
3131 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
3132 !drm_modeset_is_locked(&mode_config->connection_mutex));
3135 #define drm_for_each_connector(connector, dev) \
3136 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
3137 connector = list_first_entry(&(dev)->mode_config.connector_list, \
3138 struct drm_connector, head); \
3139 &connector->head != (&(dev)->mode_config.connector_list); \
3140 connector = list_next_entry(connector, head))
3142 #define drm_for_each_encoder(encoder, dev) \
3143 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
3145 #define drm_for_each_fb(fb, dev) \
3146 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
3147 fb = list_first_entry(&(dev)->mode_config.fb_list, \
3148 struct drm_framebuffer, head); \
3149 &fb->head != (&(dev)->mode_config.fb_list); \
3150 fb = list_next_entry(fb, head))
3153 bool drm_probe_ddc(struct i2c_adapter *adapter);
3154 struct edid *drm_get_edid(struct drm_connector *connector,
3155 struct i2c_adapter *adapter);
3156 struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
3157 struct i2c_adapter *adapter);
3158 struct edid *drm_edid_duplicate(const struct edid *edid);
3159 int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
3161 u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
3162 enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
3163 bool drm_detect_hdmi_monitor(struct edid *edid);
3164 bool drm_detect_monitor_audio(struct edid *edid);
3165 bool drm_rgb_quant_range_selectable(struct edid *edid);
3166 int drm_add_modes_noedid(struct drm_connector *connector,
3167 int hdisplay, int vdisplay);
3168 void drm_set_preferred_mode(struct drm_connector *connector,
3169 int hpref, int vpref);
3171 int drm_edid_header_is_valid(const u8 *raw_edid);
3172 bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
3173 bool *edid_corrupt);
3174 bool drm_edid_is_valid(struct edid *edid);
3175 void drm_edid_get_monitor_name(struct edid *edid, char *name,
3177 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
3178 int hsize, int vsize, int fresh,
3182 extern int drm_bridge_add(struct drm_bridge *bridge);
3183 extern void drm_bridge_remove(struct drm_bridge *bridge);
3184 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
3185 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
3187 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
3188 const struct drm_display_mode *mode,
3189 struct drm_display_mode *adjusted_mode);
3190 void drm_bridge_disable(struct drm_bridge *bridge);
3191 void drm_bridge_post_disable(struct drm_bridge *bridge);
3192 void drm_bridge_mode_set(struct drm_bridge *bridge,
3193 struct drm_display_mode *mode,
3194 struct drm_display_mode *adjusted_mode);
3195 void drm_bridge_pre_enable(struct drm_bridge *bridge);
3196 void drm_bridge_enable(struct drm_bridge *bridge);
3198 #endif /* __DRM_CRTC_H__ */