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 <drm/drm_mode.h>
35 #include <drm/drm_fourcc.h>
39 struct drm_framebuffer;
40 struct drm_object_properties;
44 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
45 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
46 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
47 #define DRM_MODE_OBJECT_MODE 0xdededede
48 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
49 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
50 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
51 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
52 #define DRM_MODE_OBJECT_BRIDGE 0xbdbdbdbd
53 #define DRM_MODE_OBJECT_ANY 0
55 struct drm_mode_object {
58 struct drm_object_properties *properties;
61 #define DRM_OBJECT_MAX_PROPERTY 24
62 struct drm_object_properties {
64 uint32_t ids[DRM_OBJECT_MAX_PROPERTY];
65 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
68 enum drm_connector_force {
69 DRM_FORCE_UNSPECIFIED,
71 DRM_FORCE_ON, /* force on analog part normally */
72 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
75 #include <drm/drm_modes.h>
77 enum drm_connector_status {
78 connector_status_connected = 1,
79 connector_status_disconnected = 2,
80 connector_status_unknown = 3,
85 SubPixelHorizontalRGB,
86 SubPixelHorizontalBGR,
92 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
93 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
94 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
96 * Describes a given display (e.g. CRT or flat panel) and its limitations.
98 struct drm_display_info {
99 char name[DRM_DISPLAY_INFO_LEN];
102 unsigned int width_mm;
103 unsigned int height_mm;
105 /* Clock limits FIXME: storage format */
106 unsigned int min_vfreq, max_vfreq;
107 unsigned int min_hfreq, max_hfreq;
108 unsigned int pixel_clock;
111 enum subpixel_order subpixel_order;
117 struct drm_framebuffer_funcs {
118 /* note: use drm_framebuffer_remove() */
119 void (*destroy)(struct drm_framebuffer *framebuffer);
120 int (*create_handle)(struct drm_framebuffer *fb,
121 struct drm_file *file_priv,
122 unsigned int *handle);
124 * Optinal callback for the dirty fb ioctl.
126 * Userspace can notify the driver via this callback
127 * that a area of the framebuffer has changed and should
128 * be flushed to the display hardware.
130 * See documentation in drm_mode.h for the struct
131 * drm_mode_fb_dirty_cmd for more information as all
132 * the semantics and arguments have a one to one mapping
135 int (*dirty)(struct drm_framebuffer *framebuffer,
136 struct drm_file *file_priv, unsigned flags,
137 unsigned color, struct drm_clip_rect *clips,
141 struct drm_framebuffer {
142 struct drm_device *dev;
144 * Note that the fb is refcounted for the benefit of driver internals,
145 * for example some hw, disabling a CRTC/plane is asynchronous, and
146 * scanout does not actually complete until the next vblank. So some
147 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
148 * should be deferred. In cases like this, the driver would like to
149 * hold a ref to the fb even though it has already been removed from
150 * userspace perspective.
152 struct kref refcount;
154 * Place on the dev->mode_config.fb_list, access protected by
155 * dev->mode_config.fb_lock.
157 struct list_head head;
158 struct drm_mode_object base;
159 const struct drm_framebuffer_funcs *funcs;
160 unsigned int pitches[4];
161 unsigned int offsets[4];
164 /* depth can be 15 or 16 */
168 uint32_t pixel_format; /* fourcc format */
169 struct list_head filp_head;
170 /* if you are using the helper */
171 void *helper_private;
174 struct drm_property_blob {
175 struct drm_mode_object base;
176 struct list_head head;
178 unsigned char data[];
181 struct drm_property_enum {
183 struct list_head head;
184 char name[DRM_PROP_NAME_LEN];
187 struct drm_property {
188 struct list_head head;
189 struct drm_mode_object base;
191 char name[DRM_PROP_NAME_LEN];
194 struct drm_device *dev;
196 struct list_head enum_blob_list;
200 struct drm_connector;
202 struct drm_pending_vblank_event;
207 * drm_crtc_funcs - control CRTCs for a given device
208 * @save: save CRTC state
209 * @restore: restore CRTC state
210 * @reset: reset CRTC after state has been invalidated (e.g. resume)
211 * @cursor_set: setup the cursor
212 * @cursor_move: move the cursor
213 * @gamma_set: specify color ramp for CRTC
214 * @destroy: deinit and free object
215 * @set_property: called when a property is changed
216 * @set_config: apply a new CRTC configuration
217 * @page_flip: initiate a page flip
219 * The drm_crtc_funcs structure is the central CRTC management structure
220 * in the DRM. Each CRTC controls one or more connectors (note that the name
221 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
222 * connectors, not just CRTs).
224 * Each driver is responsible for filling out this structure at startup time,
225 * in addition to providing other modesetting features, like i2c and DDC
228 struct drm_crtc_funcs {
229 /* Save CRTC state */
230 void (*save)(struct drm_crtc *crtc); /* suspend? */
231 /* Restore CRTC state */
232 void (*restore)(struct drm_crtc *crtc); /* resume? */
233 /* Reset CRTC state */
234 void (*reset)(struct drm_crtc *crtc);
236 /* cursor controls */
237 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
238 uint32_t handle, uint32_t width, uint32_t height);
239 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
240 uint32_t handle, uint32_t width, uint32_t height,
241 int32_t hot_x, int32_t hot_y);
242 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
244 /* Set gamma on the CRTC */
245 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
246 uint32_t start, uint32_t size);
247 /* Object destroy routine */
248 void (*destroy)(struct drm_crtc *crtc);
250 int (*set_config)(struct drm_mode_set *set);
253 * Flip to the given framebuffer. This implements the page
254 * flip ioctl described in drm_mode.h, specifically, the
255 * implementation must return immediately and block all
256 * rendering to the current fb until the flip has completed.
257 * If userspace set the event flag in the ioctl, the event
258 * argument will point to an event to send back when the flip
259 * completes, otherwise it will be NULL.
261 int (*page_flip)(struct drm_crtc *crtc,
262 struct drm_framebuffer *fb,
263 struct drm_pending_vblank_event *event,
266 int (*set_property)(struct drm_crtc *crtc,
267 struct drm_property *property, uint64_t val);
271 * drm_crtc - central CRTC control structure
272 * @dev: parent DRM device
273 * @head: list management
274 * @base: base KMS object for ID tracking etc.
275 * @primary: primary plane for this CRTC
276 * @cursor: cursor plane for this CRTC
277 * @enabled: is this CRTC enabled?
278 * @mode: current mode timings
279 * @hwmode: mode timings as programmed to hw regs
280 * @invert_dimensions: for purposes of error checking crtc vs fb sizes,
281 * invert the width/height of the crtc. This is used if the driver
282 * is performing 90 or 270 degree rotated scanout
283 * @x: x position on screen
284 * @y: y position on screen
285 * @funcs: CRTC control functions
286 * @gamma_size: size of gamma ramp
287 * @gamma_store: gamma ramp values
288 * @framedur_ns: precise frame timing
289 * @framedur_ns: precise line timing
290 * @pixeldur_ns: precise pixel timing
291 * @helper_private: mid-layer private data
292 * @properties: property tracking for this CRTC
294 * Each CRTC may have one or more connectors associated with it. This structure
295 * allows the CRTC to be controlled.
298 struct drm_device *dev;
299 struct list_head head;
304 * This provides a read lock for the overall crtc state (mode, dpms
305 * state, ...) and a write lock for everything which can be update
306 * without a full modeset (fb, cursor data, ...)
310 struct drm_mode_object base;
312 /* primary and cursor planes for CRTC */
313 struct drm_plane *primary;
314 struct drm_plane *cursor;
316 /* Temporary tracking of the old fb while a modeset is ongoing. Used
317 * by drm_mode_set_config_internal to implement correct refcounting. */
318 struct drm_framebuffer *old_fb;
322 /* Requested mode from modesetting. */
323 struct drm_display_mode mode;
325 /* Programmed mode in hw, after adjustments for encoders,
326 * crtc, panel scaling etc. Needed for timestamping etc.
328 struct drm_display_mode hwmode;
330 bool invert_dimensions;
333 const struct drm_crtc_funcs *funcs;
335 /* CRTC gamma size for reporting to userspace */
337 uint16_t *gamma_store;
339 /* Constants needed for precise vblank and swap timestamping. */
340 int framedur_ns, linedur_ns, pixeldur_ns;
342 /* if you are using the helper */
343 void *helper_private;
345 struct drm_object_properties properties;
350 * drm_connector_funcs - control connectors on a given device
351 * @dpms: set power state (see drm_crtc_funcs above)
352 * @save: save connector state
353 * @restore: restore connector state
354 * @reset: reset connector after state has been invalidated (e.g. resume)
355 * @detect: is this connector active?
356 * @fill_modes: fill mode list for this connector
357 * @set_property: property for this connector may need an update
358 * @destroy: make object go away
359 * @force: notify the driver that the connector is forced on
361 * Each CRTC may have one or more connectors attached to it. The functions
362 * below allow the core DRM code to control connectors, enumerate available modes,
365 struct drm_connector_funcs {
366 void (*dpms)(struct drm_connector *connector, int mode);
367 void (*save)(struct drm_connector *connector);
368 void (*restore)(struct drm_connector *connector);
369 void (*reset)(struct drm_connector *connector);
371 /* Check to see if anything is attached to the connector.
372 * @force is set to false whilst polling, true when checking the
373 * connector due to user request. @force can be used by the driver
374 * to avoid expensive, destructive operations during automated
377 enum drm_connector_status (*detect)(struct drm_connector *connector,
379 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
380 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
382 void (*destroy)(struct drm_connector *connector);
383 void (*force)(struct drm_connector *connector);
387 * drm_encoder_funcs - encoder controls
388 * @reset: reset state (e.g. at init or resume time)
389 * @destroy: cleanup and free associated data
391 * Encoders sit between CRTCs and connectors.
393 struct drm_encoder_funcs {
394 void (*reset)(struct drm_encoder *encoder);
395 void (*destroy)(struct drm_encoder *encoder);
398 #define DRM_CONNECTOR_MAX_ENCODER 3
401 * drm_encoder - central DRM encoder structure
402 * @dev: parent DRM device
403 * @head: list management
404 * @base: base KMS object
405 * @name: encoder name
406 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
407 * @possible_crtcs: bitmask of potential CRTC bindings
408 * @possible_clones: bitmask of potential sibling encoders for cloning
409 * @crtc: currently bound CRTC
410 * @bridge: bridge associated to the encoder
411 * @funcs: control functions
412 * @helper_private: mid-layer private data
414 * CRTCs drive pixels to encoders, which convert them into signals
415 * appropriate for a given connector or set of connectors.
418 struct drm_device *dev;
419 struct list_head head;
421 struct drm_mode_object base;
424 uint32_t possible_crtcs;
425 uint32_t possible_clones;
427 struct drm_crtc *crtc;
428 struct drm_bridge *bridge;
429 const struct drm_encoder_funcs *funcs;
430 void *helper_private;
433 /* should we poll this connector for connects and disconnects */
434 /* hot plug detectable */
435 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
436 /* poll for connections */
437 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
438 /* can cleanly poll for disconnections without flickering the screen */
439 /* DACs should rarely do this without a lot of testing */
440 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
442 #define MAX_ELD_BYTES 128
445 * drm_connector - central DRM connector control structure
446 * @dev: parent DRM device
447 * @kdev: kernel device for sysfs attributes
448 * @attr: sysfs attributes
449 * @head: list management
450 * @base: base KMS object
451 * @name: connector name
452 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
453 * @connector_type_id: index into connector type enum
454 * @interlace_allowed: can this connector handle interlaced modes?
455 * @doublescan_allowed: can this connector handle doublescan?
456 * @modes: modes available on this connector (from fill_modes() + user)
457 * @status: one of the drm_connector_status enums (connected, not, or unknown)
458 * @probed_modes: list of modes derived directly from the display
459 * @display_info: information about attached display (e.g. from EDID)
460 * @funcs: connector control functions
461 * @edid_blob_ptr: DRM property containing EDID if present
462 * @properties: property tracking for this connector
463 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
464 * @dpms: current dpms state
465 * @helper_private: mid-layer private data
466 * @force: a %DRM_FORCE_<foo> state for forced mode sets
467 * @encoder_ids: valid encoders for this connector
468 * @encoder: encoder driving this connector, if any
469 * @eld: EDID-like data, if present
470 * @dvi_dual: dual link DVI, if found
471 * @max_tmds_clock: max clock rate, if found
472 * @latency_present: AV delay info from ELD, if found
473 * @video_latency: video latency info from ELD, if found
474 * @audio_latency: audio latency info from ELD, if found
475 * @null_edid_counter: track sinks that give us all zeros for the EDID
477 * Each connector may be connected to one or more CRTCs, or may be clonable by
478 * another connector if they can share a CRTC. Each connector also has a specific
479 * position in the broader display (referred to as a 'screen' though it could
480 * span multiple monitors).
482 struct drm_connector {
483 struct drm_device *dev;
485 struct device_attribute *attr;
486 struct list_head head;
488 struct drm_mode_object base;
492 int connector_type_id;
493 bool interlace_allowed;
494 bool doublescan_allowed;
496 struct list_head modes; /* list of modes on this connector */
498 enum drm_connector_status status;
500 /* these are modes added by probing with DDC or the BIOS */
501 struct list_head probed_modes;
503 struct drm_display_info display_info;
504 const struct drm_connector_funcs *funcs;
506 struct drm_property_blob *edid_blob_ptr;
507 struct drm_object_properties properties;
509 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
511 /* requested DPMS state */
514 void *helper_private;
516 /* forced on connector */
517 enum drm_connector_force force;
518 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
519 struct drm_encoder *encoder; /* currently active encoder */
522 uint8_t eld[MAX_ELD_BYTES];
524 int max_tmds_clock; /* in MHz */
525 bool latency_present[2];
526 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
527 int audio_latency[2];
528 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
529 unsigned bad_edid_counter;
533 * drm_plane_funcs - driver plane control functions
534 * @update_plane: update the plane configuration
535 * @disable_plane: shut down the plane
536 * @destroy: clean up plane resources
537 * @set_property: called when a property is changed
539 struct drm_plane_funcs {
540 int (*update_plane)(struct drm_plane *plane,
541 struct drm_crtc *crtc, struct drm_framebuffer *fb,
542 int crtc_x, int crtc_y,
543 unsigned int crtc_w, unsigned int crtc_h,
544 uint32_t src_x, uint32_t src_y,
545 uint32_t src_w, uint32_t src_h);
546 int (*disable_plane)(struct drm_plane *plane);
547 void (*destroy)(struct drm_plane *plane);
549 int (*set_property)(struct drm_plane *plane,
550 struct drm_property *property, uint64_t val);
553 enum drm_plane_type {
554 DRM_PLANE_TYPE_OVERLAY,
555 DRM_PLANE_TYPE_PRIMARY,
556 DRM_PLANE_TYPE_CURSOR,
560 * drm_plane - central DRM plane control structure
561 * @dev: DRM device this plane belongs to
562 * @head: for list management
563 * @base: base mode object
564 * @possible_crtcs: pipes this plane can be bound to
565 * @format_types: array of formats supported by this plane
566 * @format_count: number of formats supported
567 * @crtc: currently bound CRTC
568 * @fb: currently bound fb
569 * @funcs: helper functions
570 * @properties: property tracking for this plane
571 * @type: type of plane (overlay, primary, cursor)
574 struct drm_device *dev;
575 struct list_head head;
577 struct drm_mode_object base;
579 uint32_t possible_crtcs;
580 uint32_t *format_types;
581 uint32_t format_count;
583 struct drm_crtc *crtc;
584 struct drm_framebuffer *fb;
586 const struct drm_plane_funcs *funcs;
588 struct drm_object_properties properties;
590 enum drm_plane_type type;
594 * drm_bridge_funcs - drm_bridge control functions
595 * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
596 * @disable: Called right before encoder prepare, disables the bridge
597 * @post_disable: Called right after encoder prepare, for lockstepped disable
598 * @mode_set: Set this mode to the bridge
599 * @pre_enable: Called right before encoder commit, for lockstepped commit
600 * @enable: Called right after encoder commit, enables the bridge
601 * @destroy: make object go away
603 struct drm_bridge_funcs {
604 bool (*mode_fixup)(struct drm_bridge *bridge,
605 const struct drm_display_mode *mode,
606 struct drm_display_mode *adjusted_mode);
607 void (*disable)(struct drm_bridge *bridge);
608 void (*post_disable)(struct drm_bridge *bridge);
609 void (*mode_set)(struct drm_bridge *bridge,
610 struct drm_display_mode *mode,
611 struct drm_display_mode *adjusted_mode);
612 void (*pre_enable)(struct drm_bridge *bridge);
613 void (*enable)(struct drm_bridge *bridge);
614 void (*destroy)(struct drm_bridge *bridge);
618 * drm_bridge - central DRM bridge control structure
619 * @dev: DRM device this bridge belongs to
620 * @head: list management
621 * @base: base mode object
622 * @funcs: control functions
623 * @driver_private: pointer to the bridge driver's internal context
626 struct drm_device *dev;
627 struct list_head head;
629 struct drm_mode_object base;
631 const struct drm_bridge_funcs *funcs;
632 void *driver_private;
636 * drm_mode_set - new values for a CRTC config change
637 * @head: list management
638 * @fb: framebuffer to use for new config
639 * @crtc: CRTC whose configuration we're about to change
640 * @mode: mode timings to use
641 * @x: position of this CRTC relative to @fb
642 * @y: position of this CRTC relative to @fb
643 * @connectors: array of connectors to drive with this CRTC if possible
644 * @num_connectors: size of @connectors array
646 * Represents a single crtc the connectors that it drives with what mode
647 * and from which framebuffer it scans out from.
649 * This is used to set modes.
651 struct drm_mode_set {
652 struct drm_framebuffer *fb;
653 struct drm_crtc *crtc;
654 struct drm_display_mode *mode;
659 struct drm_connector **connectors;
660 size_t num_connectors;
664 * struct drm_mode_config_funcs - basic driver provided mode setting functions
665 * @fb_create: create a new framebuffer object
666 * @output_poll_changed: function to handle output configuration changes
668 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
671 struct drm_mode_config_funcs {
672 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
673 struct drm_file *file_priv,
674 struct drm_mode_fb_cmd2 *mode_cmd);
675 void (*output_poll_changed)(struct drm_device *dev);
679 * drm_mode_group - group of mode setting resources for potential sub-grouping
680 * @num_crtcs: CRTC count
681 * @num_encoders: encoder count
682 * @num_connectors: connector count
683 * @id_list: list of KMS object IDs in this group
685 * Currently this simply tracks the global mode setting state. But in the
686 * future it could allow groups of objects to be set aside into independent
687 * control groups for use by different user level processes (e.g. two X servers
688 * running simultaneously on different heads, each with their own mode
689 * configuration and freedom of mode setting).
691 struct drm_mode_group {
693 uint32_t num_encoders;
694 uint32_t num_connectors;
695 uint32_t num_bridges;
697 /* list of object IDs for this group */
702 * drm_mode_config - Mode configuration control structure
703 * @mutex: mutex protecting KMS related lists and structures
704 * @idr_mutex: mutex for KMS ID allocation and management
705 * @crtc_idr: main KMS ID tracking object
706 * @num_fb: number of fbs available
707 * @fb_list: list of framebuffers available
708 * @num_connector: number of connectors on this device
709 * @connector_list: list of connector objects
710 * @num_bridge: number of bridges on this device
711 * @bridge_list: list of bridge objects
712 * @num_encoder: number of encoders on this device
713 * @encoder_list: list of encoder objects
714 * @num_crtc: number of CRTCs on this device
715 * @crtc_list: list of CRTC objects
716 * @min_width: minimum pixel width on this device
717 * @min_height: minimum pixel height on this device
718 * @max_width: maximum pixel width on this device
719 * @max_height: maximum pixel height on this device
720 * @funcs: core driver provided mode setting functions
721 * @fb_base: base address of the framebuffer
722 * @poll_enabled: track polling status for this device
723 * @output_poll_work: delayed work for polling in process context
724 * @*_property: core property tracking
726 * Core mode resource tracking structure. All CRTC, encoders, and connectors
727 * enumerated by the driver are added here, as are global properties. Some
728 * global restrictions are also here, e.g. dimension restrictions.
730 struct drm_mode_config {
731 struct mutex mutex; /* protects configuration (mode lists etc.) */
732 struct mutex idr_mutex; /* for IDR management */
733 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
734 /* this is limited to one for now */
738 * fb_lock - mutex to protect fb state
740 * Besides the global fb list his also protects the fbs list in the
743 struct mutex fb_lock;
745 struct list_head fb_list;
748 struct list_head connector_list;
750 struct list_head bridge_list;
752 struct list_head encoder_list;
755 * Track # of overlay planes separately from # of total planes. By
756 * default we only advertise overlay planes to userspace; if userspace
757 * sets the "universal plane" capability bit, we'll go ahead and
760 int num_overlay_plane;
762 struct list_head plane_list;
765 struct list_head crtc_list;
767 struct list_head property_list;
769 int min_width, min_height;
770 int max_width, max_height;
771 const struct drm_mode_config_funcs *funcs;
772 resource_size_t fb_base;
774 /* output poll support */
777 struct delayed_work output_poll_work;
779 /* pointers to standard properties */
780 struct list_head property_blob_list;
781 struct drm_property *edid_property;
782 struct drm_property *dpms_property;
783 struct drm_property *plane_type_property;
785 /* DVI-I properties */
786 struct drm_property *dvi_i_subconnector_property;
787 struct drm_property *dvi_i_select_subconnector_property;
790 struct drm_property *tv_subconnector_property;
791 struct drm_property *tv_select_subconnector_property;
792 struct drm_property *tv_mode_property;
793 struct drm_property *tv_left_margin_property;
794 struct drm_property *tv_right_margin_property;
795 struct drm_property *tv_top_margin_property;
796 struct drm_property *tv_bottom_margin_property;
797 struct drm_property *tv_brightness_property;
798 struct drm_property *tv_contrast_property;
799 struct drm_property *tv_flicker_reduction_property;
800 struct drm_property *tv_overscan_property;
801 struct drm_property *tv_saturation_property;
802 struct drm_property *tv_hue_property;
804 /* Optional properties */
805 struct drm_property *scaling_mode_property;
806 struct drm_property *dirty_info_property;
808 /* dumb ioctl parameters */
809 uint32_t preferred_depth, prefer_shadow;
811 /* whether async page flip is supported or not */
812 bool async_page_flip;
815 uint32_t cursor_width, cursor_height;
818 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
819 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
820 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
821 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
822 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
823 #define obj_to_property(x) container_of(x, struct drm_property, base)
824 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
825 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
827 struct drm_prop_enum_list {
832 extern void drm_modeset_lock_all(struct drm_device *dev);
833 extern void drm_modeset_unlock_all(struct drm_device *dev);
834 extern void drm_warn_on_modeset_not_all_locked(struct drm_device *dev);
836 extern int drm_crtc_init_with_planes(struct drm_device *dev,
837 struct drm_crtc *crtc,
838 struct drm_plane *primary,
840 const struct drm_crtc_funcs *funcs);
841 extern int drm_crtc_init(struct drm_device *dev,
842 struct drm_crtc *crtc,
843 const struct drm_crtc_funcs *funcs);
844 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
845 extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
848 * drm_crtc_mask - find the mask of a registered CRTC
849 * @crtc: CRTC to find mask for
851 * Given a registered CRTC, return the mask bit of that CRTC for an
852 * encoder's possible_crtcs field.
854 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
856 return 1 << drm_crtc_index(crtc);
859 extern void drm_connector_ida_init(void);
860 extern void drm_connector_ida_destroy(void);
861 extern int drm_connector_init(struct drm_device *dev,
862 struct drm_connector *connector,
863 const struct drm_connector_funcs *funcs,
866 extern void drm_connector_cleanup(struct drm_connector *connector);
867 /* helper to unplug all connectors from sysfs for device */
868 extern void drm_connector_unplug_all(struct drm_device *dev);
870 extern int drm_bridge_init(struct drm_device *dev, struct drm_bridge *bridge,
871 const struct drm_bridge_funcs *funcs);
872 extern void drm_bridge_cleanup(struct drm_bridge *bridge);
874 extern int drm_encoder_init(struct drm_device *dev,
875 struct drm_encoder *encoder,
876 const struct drm_encoder_funcs *funcs,
880 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
881 * @encoder: encoder to test
882 * @crtc: crtc to test
884 * Return false if @encoder can't be driven by @crtc, true otherwise.
886 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
887 struct drm_crtc *crtc)
889 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
892 extern int drm_universal_plane_init(struct drm_device *dev,
893 struct drm_plane *plane,
894 unsigned long possible_crtcs,
895 const struct drm_plane_funcs *funcs,
896 const uint32_t *formats,
897 uint32_t format_count,
898 enum drm_plane_type type);
899 extern int drm_plane_init(struct drm_device *dev,
900 struct drm_plane *plane,
901 unsigned long possible_crtcs,
902 const struct drm_plane_funcs *funcs,
903 const uint32_t *formats, uint32_t format_count,
905 extern void drm_plane_cleanup(struct drm_plane *plane);
906 extern void drm_plane_force_disable(struct drm_plane *plane);
907 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
909 const struct drm_display_mode *mode,
910 const struct drm_framebuffer *fb);
912 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
914 extern const char *drm_get_connector_status_name(enum drm_connector_status status);
915 extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
916 extern const char *drm_get_dpms_name(int val);
917 extern const char *drm_get_dvi_i_subconnector_name(int val);
918 extern const char *drm_get_dvi_i_select_name(int val);
919 extern const char *drm_get_tv_subconnector_name(int val);
920 extern const char *drm_get_tv_select_name(int val);
921 extern void drm_fb_release(struct drm_file *file_priv);
922 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
923 extern void drm_mode_group_destroy(struct drm_mode_group *group);
924 extern bool drm_probe_ddc(struct i2c_adapter *adapter);
925 extern struct edid *drm_get_edid(struct drm_connector *connector,
926 struct i2c_adapter *adapter);
927 extern struct edid *drm_edid_duplicate(const struct edid *edid);
928 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
929 extern void drm_mode_config_init(struct drm_device *dev);
930 extern void drm_mode_config_reset(struct drm_device *dev);
931 extern void drm_mode_config_cleanup(struct drm_device *dev);
933 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
936 static inline bool drm_property_type_is(struct drm_property *property,
939 /* instanceof for props.. handles extended type vs original types: */
940 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
941 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
942 return property->flags & type;
945 static inline bool drm_property_type_valid(struct drm_property *property)
947 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
948 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
949 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
952 extern int drm_object_property_set_value(struct drm_mode_object *obj,
953 struct drm_property *property,
955 extern int drm_object_property_get_value(struct drm_mode_object *obj,
956 struct drm_property *property,
958 extern int drm_framebuffer_init(struct drm_device *dev,
959 struct drm_framebuffer *fb,
960 const struct drm_framebuffer_funcs *funcs);
961 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
963 extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
964 extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
965 extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
966 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
967 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
969 extern void drm_object_attach_property(struct drm_mode_object *obj,
970 struct drm_property *property,
972 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
973 const char *name, int num_values);
974 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
976 const struct drm_prop_enum_list *props,
978 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
979 int flags, const char *name,
980 const struct drm_prop_enum_list *props,
982 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
984 uint64_t min, uint64_t max);
985 struct drm_property *drm_property_create_object(struct drm_device *dev,
986 int flags, const char *name, uint32_t type);
987 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
988 extern int drm_property_add_enum(struct drm_property *property, int index,
989 uint64_t value, const char *name);
990 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
991 extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
993 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
994 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
996 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
997 struct drm_encoder *encoder);
998 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
1000 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
1001 uint32_t id, uint32_t type);
1004 extern int drm_mode_getresources(struct drm_device *dev,
1005 void *data, struct drm_file *file_priv);
1006 extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
1007 struct drm_file *file_priv);
1008 extern int drm_mode_getcrtc(struct drm_device *dev,
1009 void *data, struct drm_file *file_priv);
1010 extern int drm_mode_getconnector(struct drm_device *dev,
1011 void *data, struct drm_file *file_priv);
1012 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
1013 extern int drm_mode_setcrtc(struct drm_device *dev,
1014 void *data, struct drm_file *file_priv);
1015 extern int drm_mode_getplane(struct drm_device *dev,
1016 void *data, struct drm_file *file_priv);
1017 extern int drm_mode_setplane(struct drm_device *dev,
1018 void *data, struct drm_file *file_priv);
1019 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
1020 void *data, struct drm_file *file_priv);
1021 extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
1022 void *data, struct drm_file *file_priv);
1023 extern int drm_mode_addfb(struct drm_device *dev,
1024 void *data, struct drm_file *file_priv);
1025 extern int drm_mode_addfb2(struct drm_device *dev,
1026 void *data, struct drm_file *file_priv);
1027 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
1028 extern int drm_mode_rmfb(struct drm_device *dev,
1029 void *data, struct drm_file *file_priv);
1030 extern int drm_mode_getfb(struct drm_device *dev,
1031 void *data, struct drm_file *file_priv);
1032 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1033 void *data, struct drm_file *file_priv);
1035 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
1036 void *data, struct drm_file *file_priv);
1037 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
1038 void *data, struct drm_file *file_priv);
1039 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
1040 void *data, struct drm_file *file_priv);
1041 extern int drm_mode_getencoder(struct drm_device *dev,
1042 void *data, struct drm_file *file_priv);
1043 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
1044 void *data, struct drm_file *file_priv);
1045 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
1046 void *data, struct drm_file *file_priv);
1047 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
1048 extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
1049 extern bool drm_detect_hdmi_monitor(struct edid *edid);
1050 extern bool drm_detect_monitor_audio(struct edid *edid);
1051 extern bool drm_rgb_quant_range_selectable(struct edid *edid);
1052 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
1053 void *data, struct drm_file *file_priv);
1054 extern int drm_add_modes_noedid(struct drm_connector *connector,
1055 int hdisplay, int vdisplay);
1056 extern void drm_set_preferred_mode(struct drm_connector *connector,
1057 int hpref, int vpref);
1059 extern int drm_edid_header_is_valid(const u8 *raw_edid);
1060 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid);
1061 extern bool drm_edid_is_valid(struct edid *edid);
1062 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
1063 int hsize, int vsize, int fresh,
1066 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
1067 void *data, struct drm_file *file_priv);
1068 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
1069 void *data, struct drm_file *file_priv);
1070 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
1071 void *data, struct drm_file *file_priv);
1072 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
1073 struct drm_file *file_priv);
1074 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
1075 struct drm_file *file_priv);
1077 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
1079 extern int drm_format_num_planes(uint32_t format);
1080 extern int drm_format_plane_cpp(uint32_t format, int plane);
1081 extern int drm_format_horz_chroma_subsampling(uint32_t format);
1082 extern int drm_format_vert_chroma_subsampling(uint32_t format);
1083 extern const char *drm_get_format_name(uint32_t format);
1087 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
1090 struct drm_mode_object *mo;
1091 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
1092 return mo ? obj_to_plane(mo) : NULL;
1095 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1098 struct drm_mode_object *mo;
1099 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1100 return mo ? obj_to_crtc(mo) : NULL;
1103 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
1106 struct drm_mode_object *mo;
1107 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
1108 return mo ? obj_to_encoder(mo) : NULL;
1111 static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
1114 struct drm_mode_object *mo;
1115 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
1116 return mo ? obj_to_connector(mo) : NULL;
1119 static inline struct drm_property *drm_property_find(struct drm_device *dev,
1122 struct drm_mode_object *mo;
1123 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
1124 return mo ? obj_to_property(mo) : NULL;
1127 static inline struct drm_property_blob *
1128 drm_property_blob_find(struct drm_device *dev, uint32_t id)
1130 struct drm_mode_object *mo;
1131 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_BLOB);
1132 return mo ? obj_to_blob(mo) : NULL;
1135 /* Plane list iterator for legacy (overlay only) planes. */
1136 #define drm_for_each_legacy_plane(plane, planelist) \
1137 list_for_each_entry(plane, planelist, head) \
1138 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1140 #endif /* __DRM_CRTC_H__ */