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>
34 #include <drm/drm_fourcc.h>
38 struct drm_framebuffer;
39 struct drm_object_properties;
42 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
43 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
44 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
45 #define DRM_MODE_OBJECT_MODE 0xdededede
46 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
47 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
48 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
49 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
50 #define DRM_MODE_OBJECT_BRIDGE 0xbdbdbdbd
52 struct drm_mode_object {
55 struct drm_object_properties *properties;
58 #define DRM_OBJECT_MAX_PROPERTY 16
59 struct drm_object_properties {
61 uint32_t ids[DRM_OBJECT_MAX_PROPERTY];
62 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
66 * Note on terminology: here, for brevity and convenience, we refer to connector
67 * control chips as 'CRTCs'. They can control any type of connector, VGA, LVDS,
68 * DVI, etc. And 'screen' refers to the whole of the visible display, which
69 * may span multiple monitors (and therefore multiple CRTC and connector
73 enum drm_mode_status {
74 MODE_OK = 0, /* Mode OK */
75 MODE_HSYNC, /* hsync out of range */
76 MODE_VSYNC, /* vsync out of range */
77 MODE_H_ILLEGAL, /* mode has illegal horizontal timings */
78 MODE_V_ILLEGAL, /* mode has illegal horizontal timings */
79 MODE_BAD_WIDTH, /* requires an unsupported linepitch */
80 MODE_NOMODE, /* no mode with a matching name */
81 MODE_NO_INTERLACE, /* interlaced mode not supported */
82 MODE_NO_DBLESCAN, /* doublescan mode not supported */
83 MODE_NO_VSCAN, /* multiscan mode not supported */
84 MODE_MEM, /* insufficient video memory */
85 MODE_VIRTUAL_X, /* mode width too large for specified virtual size */
86 MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */
87 MODE_MEM_VIRT, /* insufficient video memory given virtual size */
88 MODE_NOCLOCK, /* no fixed clock available */
89 MODE_CLOCK_HIGH, /* clock required is too high */
90 MODE_CLOCK_LOW, /* clock required is too low */
91 MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */
92 MODE_BAD_HVALUE, /* horizontal timing was out of range */
93 MODE_BAD_VVALUE, /* vertical timing was out of range */
94 MODE_BAD_VSCAN, /* VScan value out of range */
95 MODE_HSYNC_NARROW, /* horizontal sync too narrow */
96 MODE_HSYNC_WIDE, /* horizontal sync too wide */
97 MODE_HBLANK_NARROW, /* horizontal blanking too narrow */
98 MODE_HBLANK_WIDE, /* horizontal blanking too wide */
99 MODE_VSYNC_NARROW, /* vertical sync too narrow */
100 MODE_VSYNC_WIDE, /* vertical sync too wide */
101 MODE_VBLANK_NARROW, /* vertical blanking too narrow */
102 MODE_VBLANK_WIDE, /* vertical blanking too wide */
103 MODE_PANEL, /* exceeds panel dimensions */
104 MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
105 MODE_ONE_WIDTH, /* only one width is supported */
106 MODE_ONE_HEIGHT, /* only one height is supported */
107 MODE_ONE_SIZE, /* only one resolution is supported */
108 MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */
109 MODE_UNVERIFIED = -3, /* mode needs to reverified */
110 MODE_BAD = -2, /* unspecified reason */
111 MODE_ERROR = -1 /* error condition */
114 #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
115 DRM_MODE_TYPE_CRTC_C)
117 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
118 .name = nm, .status = 0, .type = (t), .clock = (c), \
119 .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
120 .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
121 .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
122 .vscan = (vs), .flags = (f), .vrefresh = 0
124 #define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */
126 struct drm_display_mode {
128 struct list_head head;
129 struct drm_mode_object base;
131 char name[DRM_DISPLAY_MODE_LEN];
133 enum drm_mode_status status;
136 /* Proposed mode values */
137 int clock; /* in kHz */
150 /* Addressable image size (may be 0 for projectors, etc.) */
154 /* Actual mode we give to hw */
158 int crtc_hblank_start;
160 int crtc_hsync_start;
165 int crtc_vblank_start;
167 int crtc_vsync_start;
173 /* Driver private mode info */
178 int vrefresh; /* in Hz */
179 int hsync; /* in kHz */
182 enum drm_connector_status {
183 connector_status_connected = 1,
184 connector_status_disconnected = 2,
185 connector_status_unknown = 3,
188 enum subpixel_order {
190 SubPixelHorizontalRGB,
191 SubPixelHorizontalBGR,
197 #define DRM_COLOR_FORMAT_RGB444 (1<<0)
198 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
199 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
201 * Describes a given display (e.g. CRT or flat panel) and its limitations.
203 struct drm_display_info {
204 char name[DRM_DISPLAY_INFO_LEN];
207 unsigned int width_mm;
208 unsigned int height_mm;
210 /* Clock limits FIXME: storage format */
211 unsigned int min_vfreq, max_vfreq;
212 unsigned int min_hfreq, max_hfreq;
213 unsigned int pixel_clock;
216 enum subpixel_order subpixel_order;
221 char *raw_edid; /* if any */
224 struct drm_framebuffer_funcs {
225 void (*destroy)(struct drm_framebuffer *framebuffer);
226 int (*create_handle)(struct drm_framebuffer *fb,
227 struct drm_file *file_priv,
228 unsigned int *handle);
230 * Optinal callback for the dirty fb ioctl.
232 * Userspace can notify the driver via this callback
233 * that a area of the framebuffer has changed and should
234 * be flushed to the display hardware.
236 * See documentation in drm_mode.h for the struct
237 * drm_mode_fb_dirty_cmd for more information as all
238 * the semantics and arguments have a one to one mapping
241 int (*dirty)(struct drm_framebuffer *framebuffer,
242 struct drm_file *file_priv, unsigned flags,
243 unsigned color, struct drm_clip_rect *clips,
247 struct drm_framebuffer {
248 struct drm_device *dev;
249 struct list_head head;
250 struct drm_mode_object base;
251 const struct drm_framebuffer_funcs *funcs;
252 unsigned int pitches[4];
253 unsigned int offsets[4];
256 /* depth can be 15 or 16 */
260 uint32_t pixel_format; /* fourcc format */
261 struct list_head filp_head;
262 /* if you are using the helper */
263 void *helper_private;
266 struct drm_property_blob {
267 struct drm_mode_object base;
268 struct list_head head;
270 unsigned char data[];
273 struct drm_property_enum {
275 struct list_head head;
276 char name[DRM_PROP_NAME_LEN];
279 struct drm_property {
280 struct list_head head;
281 struct drm_mode_object base;
283 char name[DRM_PROP_NAME_LEN];
287 struct list_head enum_blob_list;
291 struct drm_connector;
293 struct drm_pending_vblank_event;
298 * drm_crtc_funcs - control CRTCs for a given device
299 * @reset: reset CRTC after state has been invalidate (e.g. resume)
300 * @dpms: control display power levels
301 * @save: save CRTC state
302 * @resore: restore CRTC state
303 * @lock: lock the CRTC
304 * @unlock: unlock the CRTC
305 * @shadow_allocate: allocate shadow pixmap
306 * @shadow_create: create shadow pixmap for rotation support
307 * @shadow_destroy: free shadow pixmap
308 * @mode_fixup: fixup proposed mode
309 * @mode_set: set the desired mode on the CRTC
310 * @gamma_set: specify color ramp for CRTC
311 * @destroy: deinit and free object.
313 * The drm_crtc_funcs structure is the central CRTC management structure
314 * in the DRM. Each CRTC controls one or more connectors (note that the name
315 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
316 * connectors, not just CRTs).
318 * Each driver is responsible for filling out this structure at startup time,
319 * in addition to providing other modesetting features, like i2c and DDC
322 struct drm_crtc_funcs {
323 /* Save CRTC state */
324 void (*save)(struct drm_crtc *crtc); /* suspend? */
325 /* Restore CRTC state */
326 void (*restore)(struct drm_crtc *crtc); /* resume? */
327 /* Reset CRTC state */
328 void (*reset)(struct drm_crtc *crtc);
330 /* cursor controls */
331 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
332 uint32_t handle, uint32_t width, uint32_t height);
333 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
335 /* Set gamma on the CRTC */
336 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
337 uint32_t start, uint32_t size);
338 /* Object destroy routine */
339 void (*destroy)(struct drm_crtc *crtc);
341 int (*set_config)(struct drm_mode_set *set);
344 * Flip to the given framebuffer. This implements the page
345 * flip ioctl described in drm_mode.h, specifically, the
346 * implementation must return immediately and block all
347 * rendering to the current fb until the flip has completed.
348 * If userspace set the event flag in the ioctl, the event
349 * argument will point to an event to send back when the flip
350 * completes, otherwise it will be NULL.
352 int (*page_flip)(struct drm_crtc *crtc,
353 struct drm_framebuffer *fb,
354 struct drm_pending_vblank_event *event);
358 * drm_crtc - central CRTC control structure
359 * @dev: parent DRM device
360 * @head: list management
361 * @base: base KMS object for ID tracking etc.
362 * @enabled: is this CRTC enabled?
363 * @mode: current mode timings
364 * @hwmode: mode timings as programmed to hw regs
365 * @x: x position on screen
366 * @y: y position on screen
367 * @funcs: CRTC control functions
368 * @gamma_size: size of gamma ramp
369 * @gamma_store: gamma ramp values
370 * @framedur_ns: precise frame timing
371 * @framedur_ns: precise line timing
372 * @pixeldur_ns: precise pixel timing
373 * @helper_private: mid-layer private data
375 * Each CRTC may have one or more connectors associated with it. This structure
376 * allows the CRTC to be controlled.
379 struct drm_device *dev;
380 struct list_head head;
382 struct drm_mode_object base;
384 /* framebuffer the connector is currently bound to */
385 struct drm_framebuffer *fb;
389 /* Requested mode from modesetting. */
390 struct drm_display_mode mode;
392 /* Programmed mode in hw, after adjustments for encoders,
393 * crtc, panel scaling etc. Needed for timestamping etc.
395 struct drm_display_mode hwmode;
398 const struct drm_crtc_funcs *funcs;
400 /* CRTC gamma size for reporting to userspace */
402 uint16_t *gamma_store;
404 /* Constants needed for precise vblank and swap timestamping. */
405 s64 framedur_ns, linedur_ns, pixeldur_ns;
407 /* if you are using the helper */
408 void *helper_private;
413 * drm_connector_funcs - control connectors on a given device
414 * @dpms: set power state (see drm_crtc_funcs above)
415 * @save: save connector state
416 * @restore: restore connector state
417 * @reset: reset connector after state has been invalidate (e.g. resume)
418 * @mode_valid: is this mode valid on the given connector?
419 * @mode_fixup: try to fixup proposed mode for this connector
420 * @mode_set: set this mode
421 * @detect: is this connector active?
422 * @get_modes: get mode list for this connector
423 * @set_property: property for this connector may need update
424 * @destroy: make object go away
425 * @force: notify the driver the connector is forced on
427 * Each CRTC may have one or more connectors attached to it. The functions
428 * below allow the core DRM code to control connectors, enumerate available modes,
431 struct drm_connector_funcs {
432 void (*dpms)(struct drm_connector *connector, int mode);
433 void (*save)(struct drm_connector *connector);
434 void (*restore)(struct drm_connector *connector);
435 void (*reset)(struct drm_connector *connector);
437 /* Check to see if anything is attached to the connector.
438 * @force is set to false whilst polling, true when checking the
439 * connector due to user request. @force can be used by the driver
440 * to avoid expensive, destructive operations during automated
443 enum drm_connector_status (*detect)(struct drm_connector *connector,
445 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
446 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
448 void (*destroy)(struct drm_connector *connector);
449 void (*force)(struct drm_connector *connector);
453 * drm_encoder_funcs - encoder controls
454 * @reset: reset state (e.g. at init or resume time)
455 * @destroy: cleanup and free associated data
457 * Encoders sit between CRTCs and connectors.
459 struct drm_encoder_funcs {
460 void (*reset)(struct drm_encoder *encoder);
461 void (*destroy)(struct drm_encoder *encoder);
464 #define DRM_CONNECTOR_MAX_UMODES 16
465 #define DRM_CONNECTOR_LEN 32
466 #define DRM_CONNECTOR_MAX_ENCODER 3
469 * drm_encoder - central DRM encoder structure
470 * @dev: parent DRM device
471 * @head: list management
472 * @base: base KMS object
473 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
474 * @possible_crtcs: bitmask of potential CRTC bindings
475 * @possible_clones: bitmask of potential sibling encoders for cloning
476 * @crtc: currently bound CRTC
477 * @funcs: control functions
478 * @helper_private: mid-layer private data
480 * CRTCs drive pixels to encoders, which convert them into signals
481 * appropriate for a given connector or set of connectors.
484 struct drm_device *dev;
485 struct list_head head;
487 struct drm_mode_object base;
489 uint32_t possible_crtcs;
490 uint32_t possible_clones;
492 struct drm_crtc *crtc;
493 const struct drm_encoder_funcs *funcs;
494 void *helper_private;
497 enum drm_connector_force {
498 DRM_FORCE_UNSPECIFIED,
500 DRM_FORCE_ON, /* force on analog part normally */
501 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
504 /* should we poll this connector for connects and disconnects */
505 /* hot plug detectable */
506 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
507 /* poll for connections */
508 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
509 /* can cleanly poll for disconnections without flickering the screen */
510 /* DACs should rarely do this without a lot of testing */
511 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
513 #define MAX_ELD_BYTES 128
516 * drm_connector - central DRM connector control structure
517 * @dev: parent DRM device
518 * @kdev: kernel device for sysfs attributes
519 * @attr: sysfs attributes
520 * @head: list management
521 * @base: base KMS object
522 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
523 * @connector_type_id: index into connector type enum
524 * @interlace_allowed: can this connector handle interlaced modes?
525 * @doublescan_allowed: can this connector handle doublescan?
526 * @modes: modes available on this connector (from fill_modes() + user)
527 * @status: one of the drm_connector_status enums (connected, not, or unknown)
528 * @probed_modes: list of modes derived directly from the display
529 * @display_info: information about attached display (e.g. from EDID)
530 * @funcs: connector control functions
531 * @user_modes: user added mode list
532 * @edid_blob_ptr: DRM property containing EDID if present
533 * @properties: property tracking for this connector
534 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
535 * @dpms: current dpms state
536 * @helper_private: mid-layer private data
537 * @force: a %DRM_FORCE_<foo> state for forced mode sets
538 * @encoder_ids: valid encoders for this connector
539 * @encoder: encoder driving this connector, if any
540 * @bridge: bridge connected to this connector
541 * @eld: EDID-like data, if present
542 * @dvi_dual: dual link DVI, if found
543 * @max_tmds_clock: max clock rate, if found
544 * @latency_present: AV delay info from ELD, if found
545 * @video_latency: video latency info from ELD, if found
546 * @audio_latency: audio latency info from ELD, if found
547 * @null_edid_counter: track sinks that give us all zeros for the EDID
549 * Each connector may be connected to one or more CRTCs, or may be clonable by
550 * another connector if they can share a CRTC. Each connector also has a specific
551 * position in the broader display (referred to as a 'screen' though it could
552 * span multiple monitors).
554 struct drm_connector {
555 struct drm_device *dev;
557 struct device_attribute *attr;
558 struct list_head head;
560 struct drm_mode_object base;
563 int connector_type_id;
564 bool interlace_allowed;
565 bool doublescan_allowed;
566 struct list_head modes; /* list of modes on this connector */
568 enum drm_connector_status status;
570 /* these are modes added by probing with DDC or the BIOS */
571 struct list_head probed_modes;
573 struct drm_display_info display_info;
574 const struct drm_connector_funcs *funcs;
576 struct list_head user_modes;
577 struct drm_property_blob *edid_blob_ptr;
578 struct drm_object_properties properties;
580 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
582 /* requested DPMS state */
585 void *helper_private;
587 /* forced on connector */
588 enum drm_connector_force force;
589 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
590 struct drm_encoder *encoder; /* currently active encoder */
591 struct drm_bridge *bridge; /* currently active bridge */
594 uint8_t eld[MAX_ELD_BYTES];
596 int max_tmds_clock; /* in MHz */
597 bool latency_present[2];
598 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
599 int audio_latency[2];
600 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
604 * drm_plane_funcs - driver plane control functions
605 * @update_plane: update the plane configuration
606 * @disable_plane: shut down the plane
607 * @destroy: clean up plane resources
609 struct drm_plane_funcs {
610 int (*update_plane)(struct drm_plane *plane,
611 struct drm_crtc *crtc, struct drm_framebuffer *fb,
612 int crtc_x, int crtc_y,
613 unsigned int crtc_w, unsigned int crtc_h,
614 uint32_t src_x, uint32_t src_y,
615 uint32_t src_w, uint32_t src_h);
616 int (*disable_plane)(struct drm_plane *plane);
617 void (*destroy)(struct drm_plane *plane);
621 * drm_plane - central DRM plane control structure
622 * @dev: DRM device this plane belongs to
623 * @head: for list management
624 * @base: base mode object
625 * @possible_crtcs: pipes this plane can be bound to
626 * @format_types: array of formats supported by this plane
627 * @format_count: number of formats supported
628 * @crtc: currently bound CRTC
629 * @fb: currently bound fb
630 * @gamma_size: size of gamma table
631 * @gamma_store: gamma correction table
632 * @enabled: enabled flag
633 * @funcs: helper functions
634 * @helper_private: storage for drver layer
637 struct drm_device *dev;
638 struct list_head head;
640 struct drm_mode_object base;
642 uint32_t possible_crtcs;
643 uint32_t *format_types;
644 uint32_t format_count;
646 struct drm_crtc *crtc;
647 struct drm_framebuffer *fb;
649 /* CRTC gamma size for reporting to userspace */
651 uint16_t *gamma_store;
655 const struct drm_plane_funcs *funcs;
656 void *helper_private;
660 * drm_bridge_funcs - drm_bridge control functions
661 * @destroy: make object go away
663 struct drm_bridge_funcs {
664 void (*destroy)(struct drm_bridge *bridge);
668 * drm_bridge - central DRM bridge control structure
669 * @dev: DRM device this bridge belongs to
670 * @head: list management
671 * @base: base mode object
672 * @crtc: crtc we're currently attached to
673 * @connector_type: the type of connector this bridge can attach to
674 * @funcs: control functions
675 * @helper_private: mid-layer private data
678 struct drm_device *dev;
679 struct list_head head;
681 struct drm_mode_object base;
683 struct drm_crtc *crtc;
687 const struct drm_bridge_funcs *funcs;
688 void *helper_private;
692 * drm_mode_set - new values for a CRTC config change
693 * @head: list management
694 * @fb: framebuffer to use for new config
695 * @crtc: CRTC whose configuration we're about to change
696 * @mode: mode timings to use
697 * @x: position of this CRTC relative to @fb
698 * @y: position of this CRTC relative to @fb
699 * @connectors: array of connectors to drive with this CRTC if possible
700 * @num_connectors: size of @connectors array
702 * Represents a single crtc the connectors that it drives with what mode
703 * and from which framebuffer it scans out from.
705 * This is used to set modes.
707 struct drm_mode_set {
708 struct list_head head;
710 struct drm_framebuffer *fb;
711 struct drm_crtc *crtc;
712 struct drm_display_mode *mode;
717 struct drm_connector **connectors;
718 size_t num_connectors;
722 * struct drm_mode_config_funcs - basic driver provided mode setting functions
723 * @fb_create: create a new framebuffer object
724 * @output_poll_changed: function to handle output configuration changes
726 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
729 struct drm_mode_config_funcs {
730 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
731 struct drm_file *file_priv,
732 struct drm_mode_fb_cmd2 *mode_cmd);
733 void (*output_poll_changed)(struct drm_device *dev);
737 * drm_mode_group - group of mode setting resources for potential sub-grouping
738 * @num_crtcs: CRTC count
739 * @num_encoders: encoder count
740 * @num_connectors: connector count
741 * @id_list: list of KMS object IDs in this group
743 * Currently this simply tracks the global mode setting state. But in the
744 * future it could allow groups of objects to be set aside into independent
745 * control groups for use by different user level processes (e.g. two X servers
746 * running simultaneously on different heads, each with their own mode
747 * configuration and freedom of mode setting).
749 struct drm_mode_group {
751 uint32_t num_encoders;
752 uint32_t num_connectors;
753 uint32_t num_bridges;
755 /* list of object IDs for this group */
760 * drm_mode_config - Mode configuration control structure
761 * @mutex: mutex protecting KMS related lists and structures
762 * @idr_mutex: mutex for KMS ID allocation and management
763 * @crtc_idr: main KMS ID tracking object
764 * @num_fb: number of fbs available
765 * @fb_list: list of framebuffers available
766 * @num_connector: number of connectors on this device
767 * @connector_list: list of connector objects
768 * @num_bridge: number of bridges on this device
769 * @bridge_list: list of bridge objects
770 * @num_encoder: number of encoders on this device
771 * @encoder_list: list of encoder objects
772 * @num_crtc: number of CRTCs on this device
773 * @crtc_list: list of CRTC objects
774 * @min_width: minimum pixel width on this device
775 * @min_height: minimum pixel height on this device
776 * @max_width: maximum pixel width on this device
777 * @max_height: maximum pixel height on this device
778 * @funcs: core driver provided mode setting functions
779 * @fb_base: base address of the framebuffer
780 * @poll_enabled: track polling status for this device
781 * @output_poll_work: delayed work for polling in process context
782 * @*_property: core property tracking
784 * Core mode resource tracking structure. All CRTC, encoders, and connectors
785 * enumerated by the driver are added here, as are global properties. Some
786 * global restrictions are also here, e.g. dimension restrictions.
788 struct drm_mode_config {
789 struct mutex mutex; /* protects configuration (mode lists etc.) */
790 struct mutex idr_mutex; /* for IDR management */
791 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
792 /* this is limited to one for now */
794 struct list_head fb_list;
796 struct list_head connector_list;
798 struct list_head bridge_list;
800 struct list_head encoder_list;
802 struct list_head plane_list;
805 struct list_head crtc_list;
807 struct list_head property_list;
809 int min_width, min_height;
810 int max_width, max_height;
811 struct drm_mode_config_funcs *funcs;
812 resource_size_t fb_base;
814 /* output poll support */
816 struct delayed_work output_poll_work;
818 /* pointers to standard properties */
819 struct list_head property_blob_list;
820 struct drm_property *edid_property;
821 struct drm_property *dpms_property;
823 /* DVI-I properties */
824 struct drm_property *dvi_i_subconnector_property;
825 struct drm_property *dvi_i_select_subconnector_property;
828 struct drm_property *tv_subconnector_property;
829 struct drm_property *tv_select_subconnector_property;
830 struct drm_property *tv_mode_property;
831 struct drm_property *tv_left_margin_property;
832 struct drm_property *tv_right_margin_property;
833 struct drm_property *tv_top_margin_property;
834 struct drm_property *tv_bottom_margin_property;
835 struct drm_property *tv_brightness_property;
836 struct drm_property *tv_contrast_property;
837 struct drm_property *tv_flicker_reduction_property;
838 struct drm_property *tv_overscan_property;
839 struct drm_property *tv_saturation_property;
840 struct drm_property *tv_hue_property;
842 /* Optional properties */
843 struct drm_property *scaling_mode_property;
844 struct drm_property *dithering_mode_property;
845 struct drm_property *dirty_info_property;
847 /* dumb ioctl parameters */
848 uint32_t preferred_depth, prefer_shadow;
851 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
852 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
853 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
854 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
855 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
856 #define obj_to_property(x) container_of(x, struct drm_property, base)
857 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
858 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
860 struct drm_prop_enum_list {
865 extern int drm_crtc_init(struct drm_device *dev,
866 struct drm_crtc *crtc,
867 const struct drm_crtc_funcs *funcs);
868 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
870 extern int drm_connector_init(struct drm_device *dev,
871 struct drm_connector *connector,
872 const struct drm_connector_funcs *funcs,
875 extern void drm_connector_cleanup(struct drm_connector *connector);
876 /* helper to unplug all connectors from sysfs for device */
877 extern void drm_connector_unplug_all(struct drm_device *dev);
879 extern int drm_bridge_init(struct drm_device *dev, struct drm_bridge *bridge,
880 const struct drm_bridge_funcs *funcs);
881 extern void drm_bridge_cleanup(struct drm_bridge *bridge);
883 extern int drm_encoder_init(struct drm_device *dev,
884 struct drm_encoder *encoder,
885 const struct drm_encoder_funcs *funcs,
888 extern int drm_plane_init(struct drm_device *dev,
889 struct drm_plane *plane,
890 unsigned long possible_crtcs,
891 const struct drm_plane_funcs *funcs,
892 const uint32_t *formats, uint32_t format_count,
894 extern void drm_plane_cleanup(struct drm_plane *plane);
896 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
898 extern char *drm_get_connector_name(struct drm_connector *connector);
899 extern char *drm_get_dpms_name(int val);
900 extern char *drm_get_dvi_i_subconnector_name(int val);
901 extern char *drm_get_dvi_i_select_name(int val);
902 extern char *drm_get_tv_subconnector_name(int val);
903 extern char *drm_get_tv_select_name(int val);
904 extern void drm_fb_release(struct drm_file *file_priv);
905 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
906 extern struct edid *drm_get_edid(struct drm_connector *connector,
907 struct i2c_adapter *adapter);
908 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
909 extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
910 extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
911 extern void drm_mode_copy(struct drm_display_mode *dst, const struct drm_display_mode *src);
912 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
913 const struct drm_display_mode *mode);
914 extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
915 extern void drm_mode_config_init(struct drm_device *dev);
916 extern void drm_mode_config_reset(struct drm_device *dev);
917 extern void drm_mode_config_cleanup(struct drm_device *dev);
918 extern void drm_mode_set_name(struct drm_display_mode *mode);
919 extern bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2);
920 extern int drm_mode_width(struct drm_display_mode *mode);
921 extern int drm_mode_height(struct drm_display_mode *mode);
923 /* for us by fb module */
924 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
925 struct drm_crtc *crtc,
926 const struct drm_display_mode *mode);
927 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
929 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
930 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
931 extern void drm_mode_list_concat(struct list_head *head,
932 struct list_head *new);
933 extern void drm_mode_validate_size(struct drm_device *dev,
934 struct list_head *mode_list,
935 int maxX, int maxY, int maxPitch);
936 extern void drm_mode_prune_invalid(struct drm_device *dev,
937 struct list_head *mode_list, bool verbose);
938 extern void drm_mode_sort(struct list_head *mode_list);
939 extern int drm_mode_hsync(const struct drm_display_mode *mode);
940 extern int drm_mode_vrefresh(const struct drm_display_mode *mode);
941 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
943 extern void drm_mode_connector_list_update(struct drm_connector *connector);
944 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
946 extern int drm_connector_property_set_value(struct drm_connector *connector,
947 struct drm_property *property,
949 extern int drm_connector_property_get_value(struct drm_connector *connector,
950 struct drm_property *property,
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 struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
959 extern void drm_framebuffer_set_object(struct drm_device *dev,
960 unsigned long handle);
961 extern int drm_framebuffer_init(struct drm_device *dev,
962 struct drm_framebuffer *fb,
963 const struct drm_framebuffer_funcs *funcs);
964 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
965 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
966 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
967 extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
968 extern bool drm_crtc_in_use(struct drm_crtc *crtc);
970 extern void drm_connector_attach_property(struct drm_connector *connector,
971 struct drm_property *property, uint64_t init_val);
972 extern void drm_object_attach_property(struct drm_mode_object *obj,
973 struct drm_property *property,
975 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
976 const char *name, int num_values);
977 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
979 const struct drm_prop_enum_list *props,
981 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
983 uint64_t min, uint64_t max);
984 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
985 extern int drm_property_add_enum(struct drm_property *property, int index,
986 uint64_t value, const char *name);
987 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
988 extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
990 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
991 extern int drm_mode_create_dithering_property(struct drm_device *dev);
992 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
993 extern char *drm_get_encoder_name(struct drm_encoder *encoder);
995 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
996 struct drm_encoder *encoder);
997 extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
998 struct drm_encoder *encoder);
999 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
1001 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
1002 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_setcrtc(struct drm_device *dev,
1013 void *data, struct drm_file *file_priv);
1014 extern int drm_mode_getplane(struct drm_device *dev,
1015 void *data, struct drm_file *file_priv);
1016 extern int drm_mode_setplane(struct drm_device *dev,
1017 void *data, struct drm_file *file_priv);
1018 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
1019 void *data, struct drm_file *file_priv);
1020 extern int drm_mode_addfb(struct drm_device *dev,
1021 void *data, struct drm_file *file_priv);
1022 extern int drm_mode_addfb2(struct drm_device *dev,
1023 void *data, struct drm_file *file_priv);
1024 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
1025 extern int drm_mode_rmfb(struct drm_device *dev,
1026 void *data, struct drm_file *file_priv);
1027 extern int drm_mode_getfb(struct drm_device *dev,
1028 void *data, struct drm_file *file_priv);
1029 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1030 void *data, struct drm_file *file_priv);
1031 extern int drm_mode_addmode_ioctl(struct drm_device *dev,
1032 void *data, struct drm_file *file_priv);
1033 extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
1034 void *data, struct drm_file *file_priv);
1035 extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
1036 void *data, struct drm_file *file_priv);
1037 extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
1038 void *data, struct drm_file *file_priv);
1040 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
1041 void *data, struct drm_file *file_priv);
1042 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
1043 void *data, struct drm_file *file_priv);
1044 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
1045 void *data, struct drm_file *file_priv);
1046 extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
1047 void *data, struct drm_file *file_priv);
1048 extern int drm_mode_replacefb(struct drm_device *dev,
1049 void *data, struct drm_file *file_priv);
1050 extern int drm_mode_getencoder(struct drm_device *dev,
1051 void *data, struct drm_file *file_priv);
1052 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
1053 void *data, struct drm_file *file_priv);
1054 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
1055 void *data, struct drm_file *file_priv);
1056 extern u8 *drm_find_cea_extension(struct edid *edid);
1057 extern u8 drm_match_cea_mode(struct drm_display_mode *to_match);
1058 extern bool drm_detect_hdmi_monitor(struct edid *edid);
1059 extern bool drm_detect_monitor_audio(struct edid *edid);
1060 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
1061 void *data, struct drm_file *file_priv);
1062 extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
1063 int hdisplay, int vdisplay, int vrefresh,
1064 bool reduced, bool interlaced, bool margins);
1065 extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
1066 int hdisplay, int vdisplay, int vrefresh,
1067 bool interlaced, int margins);
1068 extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
1069 int hdisplay, int vdisplay, int vrefresh,
1070 bool interlaced, int margins, int GTF_M,
1071 int GTF_2C, int GTF_K, int GTF_2J);
1072 extern int drm_add_modes_noedid(struct drm_connector *connector,
1073 int hdisplay, int vdisplay);
1075 extern int drm_edid_header_is_valid(const u8 *raw_edid);
1076 extern bool drm_edid_block_valid(u8 *raw_edid);
1077 extern bool drm_edid_is_valid(struct edid *edid);
1078 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
1079 int hsize, int vsize, int fresh);
1081 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
1082 void *data, struct drm_file *file_priv);
1083 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
1084 void *data, struct drm_file *file_priv);
1085 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
1086 void *data, struct drm_file *file_priv);
1087 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
1088 struct drm_file *file_priv);
1089 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
1090 struct drm_file *file_priv);
1092 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
1094 #endif /* __DRM_CRTC_H__ */