2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
25 #ifndef __DRM_CRTC_H__
26 #define __DRM_CRTC_H__
28 #include <linux/i2c.h>
29 #include <linux/spinlock.h>
30 #include <linux/types.h>
31 #include <linux/idr.h>
33 #include <linux/hdmi.h>
34 #include <linux/media-bus-format.h>
35 #include <uapi/drm/drm_mode.h>
36 #include <uapi/drm/drm_fourcc.h>
37 #include <drm/drm_modeset_lock.h>
41 struct drm_framebuffer;
42 struct drm_object_properties;
48 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
49 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
50 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
51 #define DRM_MODE_OBJECT_MODE 0xdededede
52 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
53 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
54 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
55 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
56 #define DRM_MODE_OBJECT_ANY 0
58 struct drm_mode_object {
61 struct drm_object_properties *properties;
64 #define DRM_OBJECT_MAX_PROPERTY 24
65 struct drm_object_properties {
66 int count, atomic_count;
67 /* NOTE: if we ever start dynamically destroying properties (ie.
68 * not at drm_mode_config_cleanup() time), then we'd have to do
69 * a better job of detaching property from mode objects to avoid
70 * dangling property pointers:
72 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
73 /* do not read/write values directly, but use drm_object_property_get_value()
74 * and drm_object_property_set_value():
76 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
79 static inline int64_t U642I64(uint64_t val)
81 return (int64_t)*((int64_t *)&val);
83 static inline uint64_t I642U64(int64_t val)
85 return (uint64_t)*((uint64_t *)&val);
88 /* rotation property bits */
89 #define DRM_ROTATE_MASK 0x0f
90 #define DRM_ROTATE_0 0
91 #define DRM_ROTATE_90 1
92 #define DRM_ROTATE_180 2
93 #define DRM_ROTATE_270 3
94 #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
95 #define DRM_REFLECT_X 4
96 #define DRM_REFLECT_Y 5
98 enum drm_connector_force {
99 DRM_FORCE_UNSPECIFIED,
101 DRM_FORCE_ON, /* force on analog part normally */
102 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
105 #include <drm/drm_modes.h>
107 enum drm_connector_status {
108 connector_status_connected = 1,
109 connector_status_disconnected = 2,
110 connector_status_unknown = 3,
113 enum subpixel_order {
115 SubPixelHorizontalRGB,
116 SubPixelHorizontalBGR,
124 * struct drm_scrambling: sink's scrambling support.
126 struct drm_scrambling {
128 * @supported: scrambling supported for rates > 340 Mhz.
132 * @low_rates: scrambling supported for rates <= 340 Mhz.
138 * struct drm_scdc - Information about scdc capabilities of a HDMI 2.0 sink
140 * Provides SCDC register support and capabilities related information on a
141 * HDMI 2.0 sink. In case of a HDMI 1.4 sink, all parameter must be 0.
145 * @supported: status control & data channel present.
149 * @read_request: sink is capable of generating scdc read request.
153 * @scrambling: sink's scrambling capabilities
155 struct drm_scrambling scrambling;
160 * struct drm_hdmi_info - runtime information about the connected HDMI sink
162 * Describes if a given display supports advanced HDMI 2.0 features.
163 * This information is available in CEA-861-F extension blocks (like HF-VSDB).
165 struct drm_hdmi_info {
166 struct drm_scdc scdc;
169 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
170 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
171 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
173 * Describes a given display (e.g. CRT or flat panel) and its limitations.
175 struct drm_display_info {
176 char name[DRM_DISPLAY_INFO_LEN];
179 unsigned int width_mm;
180 unsigned int height_mm;
182 /* Clock limits FIXME: storage format */
183 unsigned int min_vfreq, max_vfreq;
184 unsigned int min_hfreq, max_hfreq;
185 unsigned int pixel_clock;
188 enum subpixel_order subpixel_order;
191 const u32 *bus_formats;
192 unsigned int num_bus_formats;
195 * @max_tmds_clock: Maximum TMDS clock rate supported by the
196 * sink in kHz. 0 means undefined.
201 * @dvi_dual: Dual-link DVI sink?
205 /* Mask of supported hdmi deep color modes */
206 u8 edid_hdmi_dc_modes;
211 * @hdmi: advance features of a HDMI sink.
213 struct drm_hdmi_info hdmi;
216 /* data corresponds to displayid vend/prod/serial */
217 struct drm_tile_group {
218 struct kref refcount;
219 struct drm_device *dev;
224 struct drm_framebuffer_funcs {
225 /* note: use drm_framebuffer_remove() */
226 void (*destroy)(struct drm_framebuffer *framebuffer);
227 int (*create_handle)(struct drm_framebuffer *fb,
228 struct drm_file *file_priv,
229 unsigned int *handle);
231 * Optional callback for the dirty fb ioctl.
233 * Userspace can notify the driver via this callback
234 * that a area of the framebuffer has changed and should
235 * be flushed to the display hardware.
237 * See documentation in drm_mode.h for the struct
238 * drm_mode_fb_dirty_cmd for more information as all
239 * the semantics and arguments have a one to one mapping
242 int (*dirty)(struct drm_framebuffer *framebuffer,
243 struct drm_file *file_priv, unsigned flags,
244 unsigned color, struct drm_clip_rect *clips,
248 struct drm_framebuffer {
249 struct drm_device *dev;
251 * Note that the fb is refcounted for the benefit of driver internals,
252 * for example some hw, disabling a CRTC/plane is asynchronous, and
253 * scanout does not actually complete until the next vblank. So some
254 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
255 * should be deferred. In cases like this, the driver would like to
256 * hold a ref to the fb even though it has already been removed from
257 * userspace perspective.
259 struct kref refcount;
261 * Place on the dev->mode_config.fb_list, access protected by
262 * dev->mode_config.fb_lock.
264 struct list_head head;
265 struct drm_mode_object base;
266 const struct drm_framebuffer_funcs *funcs;
267 unsigned int pitches[4];
268 unsigned int offsets[4];
269 uint64_t modifier[4];
272 /* depth can be 15 or 16 */
276 uint32_t pixel_format; /* fourcc format */
277 struct list_head filp_head;
280 struct drm_property_blob {
281 struct drm_mode_object base;
282 struct drm_device *dev;
283 struct kref refcount;
284 struct list_head head_global;
285 struct list_head head_file;
287 unsigned char data[];
290 struct drm_property_enum {
292 struct list_head head;
293 char name[DRM_PROP_NAME_LEN];
296 struct drm_property {
297 struct list_head head;
298 struct drm_mode_object base;
300 char name[DRM_PROP_NAME_LEN];
303 struct drm_device *dev;
305 struct list_head enum_list;
309 struct drm_connector;
311 struct drm_pending_vblank_event;
314 struct drm_atomic_state;
317 * struct drm_crtc_state - mutable CRTC state
318 * @crtc: backpointer to the CRTC
319 * @enable: whether the CRTC should be enabled, gates all other state
320 * @active: whether the CRTC is actively displaying (used for DPMS)
321 * @planes_changed: planes on this crtc are updated
322 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
323 * @active_changed: crtc_state->active has been toggled.
324 * @connectors_changed: connectors to this crtc have been updated
325 * @color_mgmt_changed: color management properties have changed (degamma or
326 * gamma LUT or CSC matrix)
327 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
328 * @last_vblank_count: for helpers and drivers to capture the vblank of the
329 * update to ensure framebuffer cleanup isn't done too early
330 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
331 * @mode: current mode timings
332 * @degamma_lut: Lookup table for converting framebuffer pixel data
333 * before apply the conversion matrix
334 * @ctm: Transformation matrix
335 * @gamma_lut: Lookup table for converting pixel data after the
337 * @event: optional pointer to a DRM event to signal upon completion of the
339 * @state: backpointer to global drm_atomic_state
341 * Note that the distinction between @enable and @active is rather subtile:
342 * Flipping @active while @enable is set without changing anything else may
343 * never return in a failure from the ->atomic_check callback. Userspace assumes
344 * that a DPMS On will always succeed. In other words: @enable controls resource
345 * assignment, @active controls the actual hardware state.
347 struct drm_crtc_state {
348 struct drm_crtc *crtc;
353 /* computed state bits used by helpers and drivers */
354 bool planes_changed : 1;
355 bool mode_changed : 1;
356 bool active_changed : 1;
357 bool connectors_changed : 1;
358 bool color_mgmt_changed : 1;
360 /* attached planes bitmask:
361 * WARNING: transitional helpers do not maintain plane_mask so
362 * drivers not converted over to atomic helpers should not rely
363 * on plane_mask being accurate!
367 /* last_vblank_count: for vblank waits before cleanup */
368 u32 last_vblank_count;
370 /* adjusted_mode: for use by helpers and drivers */
371 struct drm_display_mode adjusted_mode;
373 struct drm_display_mode mode;
375 /* blob property to expose current mode to atomic userspace */
376 struct drm_property_blob *mode_blob;
378 /* blob property to expose color management to userspace */
379 struct drm_property_blob *degamma_lut;
380 struct drm_property_blob *ctm;
381 struct drm_property_blob *gamma_lut;
383 struct drm_pending_vblank_event *event;
385 struct drm_atomic_state *state;
389 * struct drm_crtc_funcs - control CRTCs for a given device
390 * @save: save CRTC state
391 * @restore: restore CRTC state
392 * @reset: reset CRTC after state has been invalidated (e.g. resume)
393 * @cursor_set: setup the cursor
394 * @cursor_set2: setup the cursor with hotspot, superseeds @cursor_set if set
395 * @cursor_move: move the cursor
396 * @gamma_set: specify color ramp for CRTC
397 * @destroy: deinit and free object
398 * @set_property: called when a property is changed
399 * @set_config: apply a new CRTC configuration
400 * @page_flip: initiate a page flip
401 * @atomic_duplicate_state: duplicate the atomic state for this CRTC
402 * @atomic_destroy_state: destroy an atomic state for this CRTC
403 * @atomic_set_property: set a property on an atomic state for this CRTC
404 * (do not call directly, use drm_atomic_crtc_set_property())
405 * @atomic_get_property: get a property on an atomic state for this CRTC
406 * (do not call directly, use drm_atomic_crtc_get_property())
408 * The drm_crtc_funcs structure is the central CRTC management structure
409 * in the DRM. Each CRTC controls one or more connectors (note that the name
410 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
411 * connectors, not just CRTs).
413 * Each driver is responsible for filling out this structure at startup time,
414 * in addition to providing other modesetting features, like i2c and DDC
417 struct drm_crtc_funcs {
418 /* Save CRTC state */
419 void (*save)(struct drm_crtc *crtc); /* suspend? */
420 /* Restore CRTC state */
421 void (*restore)(struct drm_crtc *crtc); /* resume? */
422 /* Reset CRTC state */
423 void (*reset)(struct drm_crtc *crtc);
425 /* cursor controls */
426 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
427 uint32_t handle, uint32_t width, uint32_t height);
428 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
429 uint32_t handle, uint32_t width, uint32_t height,
430 int32_t hot_x, int32_t hot_y);
431 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
433 /* Set gamma on the CRTC */
434 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
435 uint32_t start, uint32_t size);
436 /* Object destroy routine */
437 void (*destroy)(struct drm_crtc *crtc);
439 int (*set_config)(struct drm_mode_set *set);
442 * Flip to the given framebuffer. This implements the page
443 * flip ioctl described in drm_mode.h, specifically, the
444 * implementation must return immediately and block all
445 * rendering to the current fb until the flip has completed.
446 * If userspace set the event flag in the ioctl, the event
447 * argument will point to an event to send back when the flip
448 * completes, otherwise it will be NULL.
450 int (*page_flip)(struct drm_crtc *crtc,
451 struct drm_framebuffer *fb,
452 struct drm_pending_vblank_event *event,
455 int (*set_property)(struct drm_crtc *crtc,
456 struct drm_property *property, uint64_t val);
458 /* atomic update handling */
459 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
460 void (*atomic_destroy_state)(struct drm_crtc *crtc,
461 struct drm_crtc_state *state);
462 int (*atomic_set_property)(struct drm_crtc *crtc,
463 struct drm_crtc_state *state,
464 struct drm_property *property,
466 int (*atomic_get_property)(struct drm_crtc *crtc,
467 const struct drm_crtc_state *state,
468 struct drm_property *property,
474 * This optional hook can be used to register additional userspace
475 * interfaces attached to the crtc like debugfs interfaces.
476 * It is called late in the driver load sequence from drm_dev_register().
477 * Everything added from this callback should be unregistered in
478 * the early_unregister callback.
482 * 0 on success, or a negative error code on failure.
484 int (*late_register)(struct drm_crtc *crtc);
489 * This optional hook should be used to unregister the additional
490 * userspace interfaces attached to the crtc from
491 * late_unregister(). It is called from drm_dev_unregister(),
492 * early in the driver unload sequence to disable userspace access
493 * before data structures are torndown.
495 void (*early_unregister)(struct drm_crtc *crtc);
499 * struct drm_crtc - central CRTC control structure
500 * @dev: parent DRM device
501 * @port: OF node used by drm_of_find_possible_crtcs()
502 * @head: list management
503 * @mutex: per-CRTC locking
504 * @base: base KMS object for ID tracking etc.
505 * @primary: primary plane for this CRTC
506 * @cursor: cursor plane for this CRTC
507 * @cursor_x: current x position of the cursor, used for universal cursor planes
508 * @cursor_y: current y position of the cursor, used for universal cursor planes
509 * @enabled: is this CRTC enabled?
510 * @mode: current mode timings
511 * @hwmode: mode timings as programmed to hw regs
512 * @x: x position on screen
513 * @y: y position on screen
514 * @funcs: CRTC control functions
515 * @gamma_size: size of gamma ramp
516 * @gamma_store: gamma ramp values
517 * @helper_private: mid-layer private data
518 * @properties: property tracking for this CRTC
519 * @state: current atomic state for this CRTC
520 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
523 * Each CRTC may have one or more connectors associated with it. This structure
524 * allows the CRTC to be controlled.
527 struct drm_device *dev;
528 struct device_node *port;
529 struct list_head head;
534 * This provides a read lock for the overall crtc state (mode, dpms
535 * state, ...) and a write lock for everything which can be update
536 * without a full modeset (fb, cursor data, ...)
538 struct drm_modeset_lock mutex;
540 struct drm_mode_object base;
542 /* primary and cursor planes for CRTC */
543 struct drm_plane *primary;
544 struct drm_plane *cursor;
546 /* position of cursor plane on crtc */
552 /* Requested mode from modesetting. */
553 struct drm_display_mode mode;
555 /* Programmed mode in hw, after adjustments for encoders,
556 * crtc, panel scaling etc. Needed for timestamping etc.
558 struct drm_display_mode hwmode;
561 const struct drm_crtc_funcs *funcs;
563 /* Legacy FB CRTC gamma size for reporting to userspace */
565 uint16_t *gamma_store;
567 /* if you are using the helper */
568 const void *helper_private;
570 struct drm_object_properties properties;
572 struct drm_crtc_state *state;
575 * For legacy crtc ioctls so that atomic drivers can get at the locking
578 struct drm_modeset_acquire_ctx *acquire_ctx;
582 * struct drm_connector_state - mutable connector state
583 * @connector: backpointer to the connector
584 * @crtc: CRTC to connect connector to, NULL if disabled
585 * @best_encoder: can be used by helpers and drivers to select the encoder
586 * @state: backpointer to global drm_atomic_state
588 struct drm_connector_state {
589 struct drm_connector *connector;
591 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
593 struct drm_encoder *best_encoder;
595 struct drm_atomic_state *state;
599 * struct drm_connector_funcs - control connectors on a given device
600 * @dpms: set power state
601 * @save: save connector state
602 * @restore: restore connector state
603 * @reset: reset connector after state has been invalidated (e.g. resume)
604 * @detect: is this connector active?
605 * @fill_modes: fill mode list for this connector
606 * @set_property: property for this connector may need an update
607 * @destroy: make object go away
608 * @force: notify the driver that the connector is forced on
609 * @atomic_duplicate_state: duplicate the atomic state for this connector
610 * @atomic_destroy_state: destroy an atomic state for this connector
611 * @atomic_set_property: set a property on an atomic state for this connector
612 * (do not call directly, use drm_atomic_connector_set_property())
613 * @atomic_get_property: get a property on an atomic state for this connector
614 * (do not call directly, use drm_atomic_connector_get_property())
616 * Each CRTC may have one or more connectors attached to it. The functions
617 * below allow the core DRM code to control connectors, enumerate available modes,
620 struct drm_connector_funcs {
621 int (*dpms)(struct drm_connector *connector, int mode);
622 void (*save)(struct drm_connector *connector);
623 void (*restore)(struct drm_connector *connector);
624 void (*reset)(struct drm_connector *connector);
626 /* Check to see if anything is attached to the connector.
627 * @force is set to false whilst polling, true when checking the
628 * connector due to user request. @force can be used by the driver
629 * to avoid expensive, destructive operations during automated
632 enum drm_connector_status (*detect)(struct drm_connector *connector,
634 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
635 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
641 * This optional hook can be used to register additional userspace
642 * interfaces attached to the connector, light backlight control, i2c,
643 * DP aux or similar interfaces. It is called late in the driver load
644 * sequence from drm_connector_register() when registering all the
645 * core drm connector interfaces. Everything added from this callback
646 * should be unregistered in the early_unregister callback.
650 * 0 on success, or a negative error code on failure.
652 int (*late_register)(struct drm_connector *connector);
657 * This optional hook should be used to unregister the additional
658 * userspace interfaces attached to the connector from
659 * late_unregister(). It is called from drm_connector_unregister(),
660 * early in the driver unload sequence to disable userspace access
661 * before data structures are torndown.
663 void (*early_unregister)(struct drm_connector *connector);
665 void (*destroy)(struct drm_connector *connector);
666 void (*force)(struct drm_connector *connector);
668 /* atomic update handling */
669 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
670 void (*atomic_destroy_state)(struct drm_connector *connector,
671 struct drm_connector_state *state);
672 int (*atomic_set_property)(struct drm_connector *connector,
673 struct drm_connector_state *state,
674 struct drm_property *property,
676 int (*atomic_get_property)(struct drm_connector *connector,
677 const struct drm_connector_state *state,
678 struct drm_property *property,
683 * struct drm_encoder_funcs - encoder controls
684 * @reset: reset state (e.g. at init or resume time)
685 * @destroy: cleanup and free associated data
687 * Encoders sit between CRTCs and connectors.
689 struct drm_encoder_funcs {
690 void (*reset)(struct drm_encoder *encoder);
691 void (*destroy)(struct drm_encoder *encoder);
696 * This optional hook can be used to register additional userspace
697 * interfaces attached to the encoder like debugfs interfaces.
698 * It is called late in the driver load sequence from drm_dev_register().
699 * Everything added from this callback should be unregistered in
700 * the early_unregister callback.
704 * 0 on success, or a negative error code on failure.
706 int (*late_register)(struct drm_encoder *encoder);
711 * This optional hook should be used to unregister the additional
712 * userspace interfaces attached to the encoder from
713 * late_unregister(). It is called from drm_dev_unregister(),
714 * early in the driver unload sequence to disable userspace access
715 * before data structures are torndown.
717 void (*early_unregister)(struct drm_encoder *encoder);
720 #define DRM_CONNECTOR_MAX_ENCODER 3
723 * struct drm_encoder - central DRM encoder structure
724 * @dev: parent DRM device
725 * @port: OF node used by find encoder by node
726 * @head: list management
727 * @base: base KMS object
728 * @name: encoder name
729 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
730 * @possible_crtcs: bitmask of potential CRTC bindings
731 * @possible_clones: bitmask of potential sibling encoders for cloning
732 * @crtc: currently bound CRTC
733 * @bridge: bridge associated to the encoder
734 * @funcs: control functions
735 * @helper_private: mid-layer private data
737 * CRTCs drive pixels to encoders, which convert them into signals
738 * appropriate for a given connector or set of connectors.
741 struct drm_device *dev;
742 struct device_node *port;
743 struct list_head head;
745 struct drm_mode_object base;
748 uint32_t possible_crtcs;
749 uint32_t possible_clones;
752 struct drm_crtc *crtc;
753 struct drm_bridge *bridge;
754 const struct drm_encoder_funcs *funcs;
755 const void *helper_private;
758 /* should we poll this connector for connects and disconnects */
759 /* hot plug detectable */
760 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
761 /* poll for connections */
762 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
763 /* can cleanly poll for disconnections without flickering the screen */
764 /* DACs should rarely do this without a lot of testing */
765 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
767 #define MAX_ELD_BYTES 128
770 * struct drm_connector - central DRM connector control structure
771 * @dev: parent DRM device
772 * @port: OF node used by find connector by node.
773 * @kdev: kernel device for sysfs attributes
774 * @attr: sysfs attributes
775 * @head: list management
776 * @base: base KMS object
777 * @name: connector name
778 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
779 * @connector_type_id: index into connector type enum
780 * @interlace_allowed: can this connector handle interlaced modes?
781 * @doublescan_allowed: can this connector handle doublescan?
782 * @stereo_allowed: can this connector handle stereo modes?
783 * @modes: modes available on this connector (from fill_modes() + user)
784 * @status: one of the drm_connector_status enums (connected, not, or unknown)
785 * @probed_modes: list of modes derived directly from the display
786 * @display_info: information about attached display (e.g. from EDID)
787 * @funcs: connector control functions
788 * @edid_blob_ptr: DRM property containing EDID if present
789 * @properties: property tracking for this connector
790 * @path_blob_ptr: DRM blob property data for the DP MST path property
791 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
792 * @dpms: current dpms state
793 * @helper_private: mid-layer private data
794 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
795 * @force: a %DRM_FORCE_<foo> state for forced mode sets
796 * @override_edid: has the EDID been overwritten through debugfs for testing?
797 * @encoder_ids: valid encoders for this connector
798 * @encoder: encoder driving this connector, if any
799 * @eld: EDID-like data, if present
800 * @latency_present: AV delay info from ELD, if found
801 * @video_latency: video latency info from ELD, if found
802 * @audio_latency: audio latency info from ELD, if found
803 * @null_edid_counter: track sinks that give us all zeros for the EDID
804 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
805 * @edid_corrupt: indicates whether the last read EDID was corrupt
806 * @debugfs_entry: debugfs directory for this connector
807 * @state: current atomic state for this connector
808 * @has_tile: is this connector connected to a tiled monitor
809 * @tile_group: tile group for the connected monitor
810 * @tile_is_single_monitor: whether the tile is one monitor housing
811 * @num_h_tile: number of horizontal tiles in the tile group
812 * @num_v_tile: number of vertical tiles in the tile group
813 * @tile_h_loc: horizontal location of this tile
814 * @tile_v_loc: vertical location of this tile
815 * @tile_h_size: horizontal size of this tile.
816 * @tile_v_size: vertical size of this tile.
818 * Each connector may be connected to one or more CRTCs, or may be clonable by
819 * another connector if they can share a CRTC. Each connector also has a specific
820 * position in the broader display (referred to as a 'screen' though it could
821 * span multiple monitors).
823 struct drm_connector {
824 struct drm_device *dev;
825 struct device_node *port;
827 struct device_attribute *attr;
828 struct list_head head;
830 struct drm_mode_object base;
834 int connector_type_id;
835 bool interlace_allowed;
836 bool doublescan_allowed;
838 struct list_head modes; /* list of modes on this connector */
840 enum drm_connector_status status;
842 /* these are modes added by probing with DDC or the BIOS */
843 struct list_head probed_modes;
845 struct drm_display_info display_info;
846 const struct drm_connector_funcs *funcs;
848 struct drm_property_blob *edid_blob_ptr;
849 struct drm_object_properties properties;
851 struct drm_property_blob *path_blob_ptr;
853 struct drm_property_blob *tile_blob_ptr;
855 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
857 /* requested DPMS state */
860 const void *helper_private;
862 /* forced on connector */
863 struct drm_cmdline_mode cmdline_mode;
864 enum drm_connector_force force;
866 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
867 struct drm_encoder *encoder; /* currently active encoder */
871 uint8_t eld[MAX_ELD_BYTES];
872 bool latency_present[2];
873 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
874 int audio_latency[2];
875 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
876 unsigned bad_edid_counter;
878 /* Flag for raw EDID header corruption - used in Displayport
879 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
883 struct dentry *debugfs_entry;
885 struct drm_connector_state *state;
889 struct drm_tile_group *tile_group;
890 bool tile_is_single_monitor;
892 uint8_t num_h_tile, num_v_tile;
893 uint8_t tile_h_loc, tile_v_loc;
894 uint16_t tile_h_size, tile_v_size;
898 * struct drm_plane_state - mutable plane state
899 * @plane: backpointer to the plane
900 * @crtc: currently bound CRTC, NULL if disabled
901 * @fb: currently bound framebuffer
902 * @fence: optional fence to wait for before scanning out @fb
903 * @crtc_x: left position of visible portion of plane on crtc
904 * @crtc_y: upper position of visible portion of plane on crtc
905 * @crtc_w: width of visible portion of plane on crtc
906 * @crtc_h: height of visible portion of plane on crtc
907 * @src_x: left position of visible portion of plane within
909 * @src_y: upper position of visible portion of plane within
911 * @src_w: width of visible portion of plane (in 16.16)
912 * @src_h: height of visible portion of plane (in 16.16)
913 * @state: backpointer to global drm_atomic_state
915 struct drm_plane_state {
916 struct drm_plane *plane;
918 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
919 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
922 /* Signed dest location allows it to be partially off screen */
923 int32_t crtc_x, crtc_y;
924 uint32_t crtc_w, crtc_h;
926 /* Source values are 16.16 fixed point */
927 uint32_t src_x, src_y;
928 uint32_t src_h, src_w;
931 unsigned int rotation;
933 struct drm_atomic_state *state;
938 * struct drm_plane_funcs - driver plane control functions
939 * @update_plane: update the plane configuration
940 * @disable_plane: shut down the plane
941 * @destroy: clean up plane resources
942 * @reset: reset plane after state has been invalidated (e.g. resume)
943 * @set_property: called when a property is changed
944 * @atomic_duplicate_state: duplicate the atomic state for this plane
945 * @atomic_destroy_state: destroy an atomic state for this plane
946 * @atomic_set_property: set a property on an atomic state for this plane
947 * (do not call directly, use drm_atomic_plane_set_property())
948 * @atomic_get_property: get a property on an atomic state for this plane
949 * (do not call directly, use drm_atomic_plane_get_property())
951 struct drm_plane_funcs {
952 int (*update_plane)(struct drm_plane *plane,
953 struct drm_crtc *crtc, struct drm_framebuffer *fb,
954 int crtc_x, int crtc_y,
955 unsigned int crtc_w, unsigned int crtc_h,
956 uint32_t src_x, uint32_t src_y,
957 uint32_t src_w, uint32_t src_h);
958 int (*disable_plane)(struct drm_plane *plane);
959 void (*destroy)(struct drm_plane *plane);
960 void (*reset)(struct drm_plane *plane);
962 int (*set_property)(struct drm_plane *plane,
963 struct drm_property *property, uint64_t val);
965 /* atomic update handling */
966 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
967 void (*atomic_destroy_state)(struct drm_plane *plane,
968 struct drm_plane_state *state);
969 int (*atomic_set_property)(struct drm_plane *plane,
970 struct drm_plane_state *state,
971 struct drm_property *property,
973 int (*atomic_get_property)(struct drm_plane *plane,
974 const struct drm_plane_state *state,
975 struct drm_property *property,
980 * This optional hook can be used to register additional userspace
981 * interfaces attached to the plane like debugfs interfaces.
982 * It is called late in the driver load sequence from drm_dev_register().
983 * Everything added from this callback should be unregistered in
984 * the early_unregister callback.
988 * 0 on success, or a negative error code on failure.
990 int (*late_register)(struct drm_plane *plane);
995 * This optional hook should be used to unregister the additional
996 * userspace interfaces attached to the plane from
997 * late_unregister(). It is called from drm_dev_unregister(),
998 * early in the driver unload sequence to disable userspace access
999 * before data structures are torndown.
1001 void (*early_unregister)(struct drm_plane *plane);
1004 enum drm_plane_type {
1005 DRM_PLANE_TYPE_OVERLAY,
1006 DRM_PLANE_TYPE_PRIMARY,
1007 DRM_PLANE_TYPE_CURSOR,
1011 * struct drm_plane - central DRM plane control structure
1012 * @dev: DRM device this plane belongs to
1013 * @parent: this plane share some resources with parent plane.
1014 * @head: for list management
1015 * @base: base mode object
1016 * @possible_crtcs: pipes this plane can be bound to
1017 * @format_types: array of formats supported by this plane
1018 * @format_count: number of formats supported
1019 * @format_default: driver hasn't supplied supported formats for the plane
1020 * @crtc: currently bound CRTC
1021 * @fb: currently bound fb
1022 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1023 * drm_mode_set_config_internal() to implement correct refcounting.
1024 * @funcs: helper functions
1025 * @properties: property tracking for this plane
1026 * @type: type of plane (overlay, primary, cursor)
1027 * @state: current atomic state for this plane
1030 struct drm_device *dev;
1031 struct drm_plane *parent;
1032 struct list_head head;
1034 struct drm_modeset_lock mutex;
1036 struct drm_mode_object base;
1038 uint32_t possible_crtcs;
1039 uint32_t *format_types;
1040 unsigned int format_count;
1041 bool format_default;
1043 struct drm_crtc *crtc;
1044 struct drm_framebuffer *fb;
1046 struct drm_framebuffer *old_fb;
1048 const struct drm_plane_funcs *funcs;
1050 struct drm_object_properties properties;
1052 enum drm_plane_type type;
1054 const void *helper_private;
1056 struct drm_plane_state *state;
1060 * struct drm_bridge_funcs - drm_bridge control functions
1061 * @attach: Called during drm_bridge_attach
1062 * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
1063 * @disable: Called right before encoder prepare, disables the bridge
1064 * @post_disable: Called right after encoder prepare, for lockstepped disable
1065 * @mode_set: Set this mode to the bridge
1066 * @pre_enable: Called right before encoder commit, for lockstepped commit
1067 * @enable: Called right after encoder commit, enables the bridge
1069 struct drm_bridge_funcs {
1070 int (*attach)(struct drm_bridge *bridge);
1071 bool (*mode_fixup)(struct drm_bridge *bridge,
1072 const struct drm_display_mode *mode,
1073 struct drm_display_mode *adjusted_mode);
1074 void (*disable)(struct drm_bridge *bridge);
1075 void (*post_disable)(struct drm_bridge *bridge);
1076 void (*mode_set)(struct drm_bridge *bridge,
1077 struct drm_display_mode *mode,
1078 struct drm_display_mode *adjusted_mode);
1079 void (*pre_enable)(struct drm_bridge *bridge);
1080 void (*enable)(struct drm_bridge *bridge);
1084 * struct drm_bridge - central DRM bridge control structure
1085 * @dev: DRM device this bridge belongs to
1086 * @encoder: encoder to which this bridge is connected
1087 * @next: the next bridge in the encoder chain
1088 * @of_node: device node pointer to the bridge
1089 * @list: to keep track of all added bridges
1090 * @funcs: control functions
1091 * @driver_private: pointer to the bridge driver's internal context
1094 struct drm_device *dev;
1095 struct drm_encoder *encoder;
1096 struct drm_bridge *next;
1098 struct device_node *of_node;
1100 struct list_head list;
1102 const struct drm_bridge_funcs *funcs;
1103 void *driver_private;
1107 * struct drm_atomic_state - the global state object for atomic updates
1108 * @dev: parent DRM device
1109 * @allow_modeset: allow full modeset
1110 * @legacy_cursor_update: hint to enforce legacy cursor ioctl semantics
1111 * @planes: pointer to array of plane pointers
1112 * @plane_states: pointer to array of plane states pointers
1113 * @crtcs: pointer to array of CRTC pointers
1114 * @crtc_states: pointer to array of CRTC states pointers
1115 * @num_connector: size of the @connectors and @connector_states arrays
1116 * @connectors: pointer to array of connector pointers
1117 * @connector_states: pointer to array of connector states pointers
1118 * @acquire_ctx: acquire context for this atomic modeset state update
1120 struct drm_atomic_state {
1121 struct drm_device *dev;
1122 bool allow_modeset : 1;
1123 bool legacy_cursor_update : 1;
1124 struct drm_plane **planes;
1125 struct drm_plane_state **plane_states;
1126 struct drm_crtc **crtcs;
1127 struct drm_crtc_state **crtc_states;
1129 struct drm_connector **connectors;
1130 struct drm_connector_state **connector_states;
1132 struct drm_modeset_acquire_ctx *acquire_ctx;
1137 * struct drm_mode_set - new values for a CRTC config change
1138 * @fb: framebuffer to use for new config
1139 * @crtc: CRTC whose configuration we're about to change
1140 * @mode: mode timings to use
1141 * @x: position of this CRTC relative to @fb
1142 * @y: position of this CRTC relative to @fb
1143 * @connectors: array of connectors to drive with this CRTC if possible
1144 * @num_connectors: size of @connectors array
1146 * Represents a single crtc the connectors that it drives with what mode
1147 * and from which framebuffer it scans out from.
1149 * This is used to set modes.
1151 struct drm_mode_set {
1152 struct drm_framebuffer *fb;
1153 struct drm_crtc *crtc;
1154 struct drm_display_mode *mode;
1159 struct drm_connector **connectors;
1160 size_t num_connectors;
1164 * struct drm_mode_config_funcs - basic driver provided mode setting functions
1165 * @fb_create: create a new framebuffer object
1166 * @output_poll_changed: function to handle output configuration changes
1167 * @atomic_check: check whether a given atomic state update is possible
1168 * @atomic_commit: commit an atomic state update previously verified with
1170 * @atomic_state_alloc: allocate a new atomic state
1171 * @atomic_state_clear: clear the atomic state
1172 * @atomic_state_free: free the atomic state
1174 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1177 struct drm_mode_config_funcs {
1178 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1179 struct drm_file *file_priv,
1180 struct drm_mode_fb_cmd2 *mode_cmd);
1181 void (*output_poll_changed)(struct drm_device *dev);
1183 int (*atomic_check)(struct drm_device *dev,
1184 struct drm_atomic_state *a);
1185 int (*atomic_commit)(struct drm_device *dev,
1186 struct drm_atomic_state *a,
1188 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
1189 void (*atomic_state_clear)(struct drm_atomic_state *state);
1190 void (*atomic_state_free)(struct drm_atomic_state *state);
1194 * struct drm_mode_config - Mode configuration control structure
1195 * @mutex: mutex protecting KMS related lists and structures
1196 * @connection_mutex: ww mutex protecting connector state and routing
1197 * @acquire_ctx: global implicit acquire context used by atomic drivers for
1199 * @idr_mutex: mutex for KMS ID allocation and management
1200 * @crtc_idr: main KMS ID tracking object
1201 * @fb_lock: mutex to protect fb state and lists
1202 * @num_fb: number of fbs available
1203 * @fb_list: list of framebuffers available
1204 * @num_connector: number of connectors on this device
1205 * @connector_list: list of connector objects
1206 * @num_encoder: number of encoders on this device
1207 * @encoder_list: list of encoder objects
1208 * @num_overlay_plane: number of overlay planes on this device
1209 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1210 * @plane_list: list of plane objects
1211 * @num_crtc: number of CRTCs on this device
1212 * @crtc_list: list of CRTC objects
1213 * @property_list: list of property objects
1214 * @min_width: minimum pixel width on this device
1215 * @min_height: minimum pixel height on this device
1216 * @max_width: maximum pixel width on this device
1217 * @max_height: maximum pixel height on this device
1218 * @funcs: core driver provided mode setting functions
1219 * @fb_base: base address of the framebuffer
1220 * @poll_enabled: track polling support for this device
1221 * @poll_running: track polling status for this device
1222 * @output_poll_work: delayed work for polling in process context
1223 * @property_blob_list: list of all the blob property objects
1224 * @blob_lock: mutex for blob property allocation and management
1225 * @*_property: core property tracking
1226 * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear
1228 * @degamma_lut_size_property: size of the degamma LUT as supported by the
1229 * driver (read-only)
1230 * @ctm_property: Matrix used to convert colors after the lookup in the
1232 * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to
1233 * the gamma space of the connected screen (read-only)
1234 * @gamma_lut_size_property: size of the gamma LUT as supported by the driver
1235 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1236 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
1237 * @async_page_flip: does this device support async flips on the primary plane?
1238 * @cursor_width: hint to userspace for max cursor width
1239 * @cursor_height: hint to userspace for max cursor height
1241 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1242 * enumerated by the driver are added here, as are global properties. Some
1243 * global restrictions are also here, e.g. dimension restrictions.
1245 struct drm_mode_config {
1246 struct mutex mutex; /* protects configuration (mode lists etc.) */
1247 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1248 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
1249 struct mutex idr_mutex; /* for IDR management */
1250 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
1251 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
1252 /* this is limited to one for now */
1254 struct mutex fb_lock; /* proctects global and per-file fb lists */
1256 struct list_head fb_list;
1259 struct list_head connector_list;
1261 struct list_head encoder_list;
1264 * Track # of overlay planes separately from # of total planes. By
1265 * default we only advertise overlay planes to userspace; if userspace
1266 * sets the "universal plane" capability bit, we'll go ahead and
1267 * expose all planes.
1269 int num_overlay_plane;
1270 int num_total_plane;
1271 int num_share_plane;
1272 int num_share_overlay_plane;
1273 struct list_head plane_list;
1276 struct list_head crtc_list;
1278 struct list_head property_list;
1280 int min_width, min_height;
1281 int max_width, max_height;
1282 const struct drm_mode_config_funcs *funcs;
1283 resource_size_t fb_base;
1285 /* output poll support */
1289 struct delayed_work output_poll_work;
1291 struct mutex blob_lock;
1293 /* pointers to share properties */
1294 struct drm_property *prop_share_id;
1295 struct drm_property *prop_share_flags;
1297 /* pointers to standard properties */
1298 struct list_head property_blob_list;
1299 struct drm_property *edid_property;
1300 struct drm_property *dpms_property;
1301 struct drm_property *path_property;
1302 struct drm_property *tile_property;
1303 struct drm_property *plane_type_property;
1304 struct drm_property *rotation_property;
1305 struct drm_property *prop_src_x;
1306 struct drm_property *prop_src_y;
1307 struct drm_property *prop_src_w;
1308 struct drm_property *prop_src_h;
1309 struct drm_property *prop_crtc_x;
1310 struct drm_property *prop_crtc_y;
1311 struct drm_property *prop_crtc_w;
1312 struct drm_property *prop_crtc_h;
1313 struct drm_property *prop_fb_id;
1314 struct drm_property *prop_crtc_id;
1315 struct drm_property *prop_active;
1316 struct drm_property *prop_mode_id;
1318 /* DVI-I properties */
1319 struct drm_property *dvi_i_subconnector_property;
1320 struct drm_property *dvi_i_select_subconnector_property;
1323 struct drm_property *tv_subconnector_property;
1324 struct drm_property *tv_select_subconnector_property;
1325 struct drm_property *tv_mode_property;
1326 struct drm_property *tv_left_margin_property;
1327 struct drm_property *tv_right_margin_property;
1328 struct drm_property *tv_top_margin_property;
1329 struct drm_property *tv_bottom_margin_property;
1330 struct drm_property *tv_brightness_property;
1331 struct drm_property *tv_contrast_property;
1332 struct drm_property *tv_flicker_reduction_property;
1333 struct drm_property *tv_overscan_property;
1334 struct drm_property *tv_saturation_property;
1335 struct drm_property *tv_hue_property;
1337 /* Optional properties */
1338 struct drm_property *scaling_mode_property;
1339 struct drm_property *aspect_ratio_property;
1340 struct drm_property *dirty_info_property;
1342 /* Optional color correction properties */
1343 struct drm_property *degamma_lut_property;
1344 struct drm_property *degamma_lut_size_property;
1345 struct drm_property *ctm_property;
1346 struct drm_property *gamma_lut_property;
1347 struct drm_property *gamma_lut_size_property;
1349 /* properties for virtual machine layout */
1350 struct drm_property *suggested_x_property;
1351 struct drm_property *suggested_y_property;
1353 /* dumb ioctl parameters */
1354 uint32_t preferred_depth, prefer_shadow;
1356 /* whether async page flip is supported or not */
1357 bool async_page_flip;
1359 /* whether the driver supports fb modifiers */
1360 bool allow_fb_modifiers;
1363 uint32_t cursor_width, cursor_height;
1367 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1368 * @plane: the loop cursor
1369 * @dev: the DRM device
1370 * @plane_mask: bitmask of plane indices
1372 * Iterate over all planes specified by bitmask.
1374 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
1375 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
1376 if ((plane_mask) & (1 << drm_plane_index(plane)))
1379 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1380 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
1381 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
1382 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
1383 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
1384 #define obj_to_property(x) container_of(x, struct drm_property, base)
1385 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
1386 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
1388 struct drm_prop_enum_list {
1393 extern __printf(6, 7)
1394 int drm_crtc_init_with_planes(struct drm_device *dev,
1395 struct drm_crtc *crtc,
1396 struct drm_plane *primary,
1397 struct drm_plane *cursor,
1398 const struct drm_crtc_funcs *funcs,
1399 const char *name, ...);
1400 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
1401 extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
1404 * drm_crtc_mask - find the mask of a registered CRTC
1405 * @crtc: CRTC to find mask for
1407 * Given a registered CRTC, return the mask bit of that CRTC for an
1408 * encoder's possible_crtcs field.
1410 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1412 return 1 << drm_crtc_index(crtc);
1415 extern void drm_connector_ida_init(void);
1416 extern void drm_connector_ida_destroy(void);
1417 extern int drm_connector_init(struct drm_device *dev,
1418 struct drm_connector *connector,
1419 const struct drm_connector_funcs *funcs,
1420 int connector_type);
1421 int drm_connector_register(struct drm_connector *connector);
1422 void drm_connector_unregister(struct drm_connector *connector);
1424 extern void drm_connector_cleanup(struct drm_connector *connector);
1425 extern unsigned int drm_connector_index(struct drm_connector *connector);
1427 /* helpers to {un}register all connectors from sysfs for device */
1428 extern int drm_connector_register_all(struct drm_device *dev);
1429 extern void drm_connector_unregister_all(struct drm_device *dev);
1431 extern int drm_bridge_add(struct drm_bridge *bridge);
1432 extern void drm_bridge_remove(struct drm_bridge *bridge);
1433 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
1434 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
1436 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
1437 const struct drm_display_mode *mode,
1438 struct drm_display_mode *adjusted_mode);
1439 void drm_bridge_disable(struct drm_bridge *bridge);
1440 void drm_bridge_post_disable(struct drm_bridge *bridge);
1441 void drm_bridge_mode_set(struct drm_bridge *bridge,
1442 struct drm_display_mode *mode,
1443 struct drm_display_mode *adjusted_mode);
1444 void drm_bridge_pre_enable(struct drm_bridge *bridge);
1445 void drm_bridge_enable(struct drm_bridge *bridge);
1447 extern __printf(5, 6)
1448 int drm_encoder_init(struct drm_device *dev,
1449 struct drm_encoder *encoder,
1450 const struct drm_encoder_funcs *funcs,
1451 int encoder_type, const char *name, ...);
1454 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
1455 * @encoder: encoder to test
1456 * @crtc: crtc to test
1458 * Return false if @encoder can't be driven by @crtc, true otherwise.
1460 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
1461 struct drm_crtc *crtc)
1463 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
1466 extern __printf(8, 9)
1467 int drm_universal_plane_init(struct drm_device *dev,
1468 struct drm_plane *plane,
1469 unsigned long possible_crtcs,
1470 const struct drm_plane_funcs *funcs,
1471 const uint32_t *formats,
1472 unsigned int format_count,
1473 enum drm_plane_type type,
1474 const char *name, ...);
1475 extern int drm_plane_init(struct drm_device *dev,
1476 struct drm_plane *plane,
1477 unsigned long possible_crtcs,
1478 const struct drm_plane_funcs *funcs,
1479 const uint32_t *formats, unsigned int format_count,
1481 extern int drm_share_plane_init(struct drm_device *dev, struct drm_plane *plane,
1482 struct drm_plane *parent,
1483 unsigned long possible_crtcs,
1484 const struct drm_plane_funcs *funcs,
1485 const uint32_t *formats,
1486 unsigned int format_count,
1487 enum drm_plane_type type);
1488 extern void drm_plane_cleanup(struct drm_plane *plane);
1489 extern unsigned int drm_plane_index(struct drm_plane *plane);
1490 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
1491 extern void drm_plane_force_disable(struct drm_plane *plane);
1492 extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
1494 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1495 int *hdisplay, int *vdisplay);
1496 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
1498 const struct drm_display_mode *mode,
1499 const struct drm_framebuffer *fb);
1501 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
1503 extern const char *drm_get_connector_status_name(enum drm_connector_status status);
1504 extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
1505 extern const char *drm_get_dpms_name(int val);
1506 extern const char *drm_get_dvi_i_subconnector_name(int val);
1507 extern const char *drm_get_dvi_i_select_name(int val);
1508 extern const char *drm_get_tv_subconnector_name(int val);
1509 extern const char *drm_get_tv_select_name(int val);
1510 extern const char *drm_get_connector_name(int val);
1511 extern void drm_fb_release(struct drm_file *file_priv);
1512 extern void drm_property_destroy_user_blobs(struct drm_device *dev,
1513 struct drm_file *file_priv);
1514 extern bool drm_probe_ddc(struct i2c_adapter *adapter);
1515 extern struct edid *drm_get_edid(struct drm_connector *connector,
1516 struct i2c_adapter *adapter);
1517 extern struct edid *drm_edid_duplicate(const struct edid *edid);
1518 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
1519 extern void drm_mode_config_init(struct drm_device *dev);
1520 extern void drm_mode_config_reset(struct drm_device *dev);
1521 extern void drm_mode_config_cleanup(struct drm_device *dev);
1523 extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
1525 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
1526 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
1527 const struct edid *edid);
1529 extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
1531 unsigned int num_formats);
1533 static inline bool drm_property_type_is(struct drm_property *property,
1536 /* instanceof for props.. handles extended type vs original types: */
1537 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1538 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
1539 return property->flags & type;
1542 static inline bool drm_property_type_valid(struct drm_property *property)
1544 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1545 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1546 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1549 extern int drm_object_property_set_value(struct drm_mode_object *obj,
1550 struct drm_property *property,
1552 extern int drm_object_property_get_value(struct drm_mode_object *obj,
1553 struct drm_property *property,
1555 extern int drm_framebuffer_init(struct drm_device *dev,
1556 struct drm_framebuffer *fb,
1557 const struct drm_framebuffer_funcs *funcs);
1558 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
1560 extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
1561 extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
1562 extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
1563 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
1564 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
1566 extern void drm_object_attach_property(struct drm_mode_object *obj,
1567 struct drm_property *property,
1569 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
1570 const char *name, int num_values);
1571 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
1573 const struct drm_prop_enum_list *props,
1575 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
1576 int flags, const char *name,
1577 const struct drm_prop_enum_list *props,
1579 uint64_t supported_bits);
1580 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
1582 uint64_t min, uint64_t max);
1583 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
1584 int flags, const char *name,
1585 int64_t min, int64_t max);
1586 struct drm_property *drm_property_create_object(struct drm_device *dev,
1587 int flags, const char *name, uint32_t type);
1588 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
1590 struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
1593 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
1595 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
1596 void drm_property_unreference_blob(struct drm_property_blob *blob);
1597 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
1598 extern int drm_property_add_enum(struct drm_property *property, int index,
1599 uint64_t value, const char *name);
1600 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
1601 extern int drm_mode_create_tv_properties(struct drm_device *dev,
1602 unsigned int num_modes,
1603 const char * const modes[]);
1604 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
1605 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
1606 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
1607 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
1608 extern bool drm_property_change_valid_get(struct drm_property *property,
1609 uint64_t value, struct drm_mode_object **ref);
1610 extern void drm_property_change_valid_put(struct drm_property *property,
1611 struct drm_mode_object *ref);
1613 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
1614 struct drm_encoder *encoder);
1615 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
1617 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
1618 uint32_t id, uint32_t type);
1621 extern int drm_mode_getresources(struct drm_device *dev,
1622 void *data, struct drm_file *file_priv);
1623 extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
1624 struct drm_file *file_priv);
1625 extern int drm_mode_getcrtc(struct drm_device *dev,
1626 void *data, struct drm_file *file_priv);
1627 extern int drm_mode_getconnector(struct drm_device *dev,
1628 void *data, struct drm_file *file_priv);
1629 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
1630 extern int drm_mode_setcrtc(struct drm_device *dev,
1631 void *data, struct drm_file *file_priv);
1632 extern int drm_mode_getplane(struct drm_device *dev,
1633 void *data, struct drm_file *file_priv);
1634 extern int drm_mode_setplane(struct drm_device *dev,
1635 void *data, struct drm_file *file_priv);
1636 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
1637 void *data, struct drm_file *file_priv);
1638 extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
1639 void *data, struct drm_file *file_priv);
1640 extern int drm_mode_addfb(struct drm_device *dev,
1641 void *data, struct drm_file *file_priv);
1642 extern int drm_mode_addfb2(struct drm_device *dev,
1643 void *data, struct drm_file *file_priv);
1644 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
1645 extern int drm_mode_rmfb(struct drm_device *dev,
1646 void *data, struct drm_file *file_priv);
1647 extern int drm_mode_getfb(struct drm_device *dev,
1648 void *data, struct drm_file *file_priv);
1649 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1650 void *data, struct drm_file *file_priv);
1652 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
1653 void *data, struct drm_file *file_priv);
1654 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
1655 void *data, struct drm_file *file_priv);
1656 extern int drm_mode_createblob_ioctl(struct drm_device *dev,
1657 void *data, struct drm_file *file_priv);
1658 extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
1659 void *data, struct drm_file *file_priv);
1660 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
1661 void *data, struct drm_file *file_priv);
1662 extern int drm_mode_getencoder(struct drm_device *dev,
1663 void *data, struct drm_file *file_priv);
1664 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
1665 void *data, struct drm_file *file_priv);
1666 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
1667 void *data, struct drm_file *file_priv);
1668 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
1669 extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
1670 extern bool drm_detect_hdmi_monitor(struct edid *edid);
1671 extern bool drm_detect_monitor_audio(struct edid *edid);
1672 extern bool drm_rgb_quant_range_selectable(struct edid *edid);
1673 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
1674 void *data, struct drm_file *file_priv);
1675 extern int drm_add_modes_noedid(struct drm_connector *connector,
1676 int hdisplay, int vdisplay);
1677 extern void drm_set_preferred_mode(struct drm_connector *connector,
1678 int hpref, int vpref);
1680 extern int drm_edid_header_is_valid(const u8 *raw_edid);
1681 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1682 bool *edid_corrupt);
1683 extern bool drm_edid_is_valid(struct edid *edid);
1685 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1687 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1689 extern void drm_mode_put_tile_group(struct drm_device *dev,
1690 struct drm_tile_group *tg);
1691 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
1692 int hsize, int vsize, int fresh,
1695 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
1696 void *data, struct drm_file *file_priv);
1697 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
1698 void *data, struct drm_file *file_priv);
1699 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
1700 void *data, struct drm_file *file_priv);
1701 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
1702 struct drm_file *file_priv);
1703 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
1704 struct drm_file *file_priv);
1705 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
1706 struct drm_property *property,
1708 extern int drm_mode_atomic_ioctl(struct drm_device *dev,
1709 void *data, struct drm_file *file_priv);
1711 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
1713 extern int drm_format_num_planes(uint32_t format);
1714 extern int drm_format_plane_bpp(uint32_t format, int plane);
1715 extern int drm_format_plane_cpp(uint32_t format, int plane);
1716 extern int drm_format_horz_chroma_subsampling(uint32_t format);
1717 extern int drm_format_vert_chroma_subsampling(uint32_t format);
1718 extern const char *drm_get_format_name(uint32_t format);
1719 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
1720 unsigned int supported_rotations);
1721 extern unsigned int drm_rotation_simplify(unsigned int rotation,
1722 unsigned int supported_rotations);
1726 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
1729 struct drm_mode_object *mo;
1730 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
1731 return mo ? obj_to_plane(mo) : NULL;
1734 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1737 struct drm_mode_object *mo;
1738 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1739 return mo ? obj_to_crtc(mo) : NULL;
1742 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
1745 struct drm_mode_object *mo;
1746 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
1747 return mo ? obj_to_encoder(mo) : NULL;
1750 static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
1753 struct drm_mode_object *mo;
1754 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
1755 return mo ? obj_to_connector(mo) : NULL;
1758 static inline struct drm_property *drm_property_find(struct drm_device *dev,
1761 struct drm_mode_object *mo;
1762 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
1763 return mo ? obj_to_property(mo) : NULL;
1767 * Extract a degamma/gamma LUT value provided by user and round it to the
1768 * precision supported by the hardware.
1770 static inline uint32_t drm_color_lut_extract(uint32_t user_input,
1771 uint32_t bit_precision)
1773 uint32_t val = user_input + (1 << (16 - bit_precision - 1));
1774 uint32_t max = 0xffff >> (16 - bit_precision);
1776 val >>= 16 - bit_precision;
1778 return clamp_val(val, 0, max);
1781 /* Plane list iterator for legacy (overlay only) planes. */
1782 #define drm_for_each_legacy_plane(plane, dev) \
1783 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
1784 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1786 #define drm_for_each_plane(plane, dev) \
1787 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
1789 #define drm_for_each_crtc(crtc, dev) \
1790 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1793 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1796 * The connector hotadd/remove code currently grabs both locks when
1797 * updating lists. Hence readers need only hold either of them to be
1798 * safe and the check amounts to
1800 * WARN_ON(not_holding(A) && not_holding(B)).
1802 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
1803 !drm_modeset_is_locked(&mode_config->connection_mutex));
1806 #define drm_for_each_connector(connector, dev) \
1807 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
1808 connector = list_first_entry(&(dev)->mode_config.connector_list, \
1809 struct drm_connector, head); \
1810 &connector->head != (&(dev)->mode_config.connector_list); \
1811 connector = list_next_entry(connector, head))
1813 #define drm_for_each_encoder(encoder, dev) \
1814 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
1816 #define drm_for_each_fb(fb, dev) \
1817 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
1818 fb = list_first_entry(&(dev)->mode_config.fb_list, \
1819 struct drm_framebuffer, head); \
1820 &fb->head != (&(dev)->mode_config.fb_list); \
1821 fb = list_next_entry(fb, head))
1823 #endif /* __DRM_CRTC_H__ */