xref: /freebsd/sys/dev/drm2/drm_crtc.h (revision 47671d1b)
1 /*
2  * Copyright © 2006 Keith Packard
3  * Copyright © 2007-2008 Dave Airlie
4  * Copyright © 2007-2008 Intel Corporation
5  *   Jesse Barnes <jesse.barnes@intel.com>
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
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.
24  *
25  * $FreeBSD$
26  */
27 #ifndef __DRM_CRTC_H__
28 #define __DRM_CRTC_H__
29 
30 #include <dev/drm2/drm_gem_names.h>
31 #include <dev/drm2/drm_fourcc.h>
32 
33 struct drm_device;
34 struct drm_mode_set;
35 struct drm_framebuffer;
36 struct i2c_adapter;
37 
38 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
39 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
40 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
41 #define DRM_MODE_OBJECT_MODE 0xdededede
42 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
43 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
44 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
45 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
46 
47 struct drm_mode_object {
48 	uint32_t id;
49 	uint32_t type;
50 	struct drm_object_properties *properties;
51 };
52 
53 #define DRM_OBJECT_MAX_PROPERTY 16
54 struct drm_object_properties {
55 	int count;
56 	uint32_t ids[DRM_OBJECT_MAX_PROPERTY];
57 	uint64_t values[DRM_OBJECT_MAX_PROPERTY];
58 };
59 
60 /*
61  * Note on terminology:  here, for brevity and convenience, we refer to connector
62  * control chips as 'CRTCs'.  They can control any type of connector, VGA, LVDS,
63  * DVI, etc.  And 'screen' refers to the whole of the visible display, which
64  * may span multiple monitors (and therefore multiple CRTC and connector
65  * structures).
66  */
67 
68 enum drm_mode_status {
69     MODE_OK	= 0,	/* Mode OK */
70     MODE_HSYNC,		/* hsync out of range */
71     MODE_VSYNC,		/* vsync out of range */
72     MODE_H_ILLEGAL,	/* mode has illegal horizontal timings */
73     MODE_V_ILLEGAL,	/* mode has illegal horizontal timings */
74     MODE_BAD_WIDTH,	/* requires an unsupported linepitch */
75     MODE_NOMODE,	/* no mode with a maching name */
76     MODE_NO_INTERLACE,	/* interlaced mode not supported */
77     MODE_NO_DBLESCAN,	/* doublescan mode not supported */
78     MODE_NO_VSCAN,	/* multiscan mode not supported */
79     MODE_MEM,		/* insufficient video memory */
80     MODE_VIRTUAL_X,	/* mode width too large for specified virtual size */
81     MODE_VIRTUAL_Y,	/* mode height too large for specified virtual size */
82     MODE_MEM_VIRT,	/* insufficient video memory given virtual size */
83     MODE_NOCLOCK,	/* no fixed clock available */
84     MODE_CLOCK_HIGH,	/* clock required is too high */
85     MODE_CLOCK_LOW,	/* clock required is too low */
86     MODE_CLOCK_RANGE,	/* clock/mode isn't in a ClockRange */
87     MODE_BAD_HVALUE,	/* horizontal timing was out of range */
88     MODE_BAD_VVALUE,	/* vertical timing was out of range */
89     MODE_BAD_VSCAN,	/* VScan value out of range */
90     MODE_HSYNC_NARROW,	/* horizontal sync too narrow */
91     MODE_HSYNC_WIDE,	/* horizontal sync too wide */
92     MODE_HBLANK_NARROW,	/* horizontal blanking too narrow */
93     MODE_HBLANK_WIDE,	/* horizontal blanking too wide */
94     MODE_VSYNC_NARROW,	/* vertical sync too narrow */
95     MODE_VSYNC_WIDE,	/* vertical sync too wide */
96     MODE_VBLANK_NARROW,	/* vertical blanking too narrow */
97     MODE_VBLANK_WIDE,	/* vertical blanking too wide */
98     MODE_PANEL,         /* exceeds panel dimensions */
99     MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
100     MODE_ONE_WIDTH,     /* only one width is supported */
101     MODE_ONE_HEIGHT,    /* only one height is supported */
102     MODE_ONE_SIZE,      /* only one resolution is supported */
103     MODE_NO_REDUCED,    /* monitor doesn't accept reduced blanking */
104     MODE_UNVERIFIED = -3, /* mode needs to reverified */
105     MODE_BAD = -2,	/* unspecified reason */
106     MODE_ERROR	= -1	/* error condition */
107 };
108 
109 #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
110 				    DRM_MODE_TYPE_CRTC_C)
111 
112 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
113 	.name = nm, .status = 0, .type = (t), .clock = (c), \
114 	.hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
115 	.htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
116 	.vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
117 	.vscan = (vs), .flags = (f), .vrefresh = 0
118 
119 #define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */
120 
121 struct drm_display_mode {
122 	/* Header */
123 	struct list_head head;
124 	struct drm_mode_object base;
125 
126 	char name[DRM_DISPLAY_MODE_LEN];
127 
128 	int connector_count;
129 	enum drm_mode_status status;
130 	int type;
131 
132 	/* Proposed mode values */
133 	int clock;		/* in kHz */
134 	int hdisplay;
135 	int hsync_start;
136 	int hsync_end;
137 	int htotal;
138 	int hskew;
139 	int vdisplay;
140 	int vsync_start;
141 	int vsync_end;
142 	int vtotal;
143 	int vscan;
144 	unsigned int flags;
145 
146 	/* Addressable image size (may be 0 for projectors, etc.) */
147 	int width_mm;
148 	int height_mm;
149 
150 	/* Actual mode we give to hw */
151 	int clock_index;
152 	int synth_clock;
153 	int crtc_hdisplay;
154 	int crtc_hblank_start;
155 	int crtc_hblank_end;
156 	int crtc_hsync_start;
157 	int crtc_hsync_end;
158 	int crtc_htotal;
159 	int crtc_hskew;
160 	int crtc_vdisplay;
161 	int crtc_vblank_start;
162 	int crtc_vblank_end;
163 	int crtc_vsync_start;
164 	int crtc_vsync_end;
165 	int crtc_vtotal;
166 	int crtc_hadjusted;
167 	int crtc_vadjusted;
168 
169 	/* Driver private mode info */
170 	int private_size;
171 	int *private;
172 	int private_flags;
173 
174 	int vrefresh;		/* in Hz */
175 	int hsync;		/* in kHz */
176 };
177 
178 enum drm_connector_status {
179 	connector_status_connected = 1,
180 	connector_status_disconnected = 2,
181 	connector_status_unknown = 3,
182 };
183 
184 enum subpixel_order {
185 	SubPixelUnknown = 0,
186 	SubPixelHorizontalRGB,
187 	SubPixelHorizontalBGR,
188 	SubPixelVerticalRGB,
189 	SubPixelVerticalBGR,
190 	SubPixelNone,
191 };
192 
193 #define DRM_COLOR_FORMAT_RGB444		(1<<0)
194 #define DRM_COLOR_FORMAT_YCRCB444	(1<<1)
195 #define DRM_COLOR_FORMAT_YCRCB422	(1<<2)
196 /*
197  * Describes a given display (e.g. CRT or flat panel) and its limitations.
198  */
199 struct drm_display_info {
200 	char name[DRM_DISPLAY_INFO_LEN];
201 
202 	/* Physical size */
203         unsigned int width_mm;
204 	unsigned int height_mm;
205 
206 	/* Clock limits FIXME: storage format */
207 	unsigned int min_vfreq, max_vfreq;
208 	unsigned int min_hfreq, max_hfreq;
209 	unsigned int pixel_clock;
210 	unsigned int bpc;
211 
212 	enum subpixel_order subpixel_order;
213 	u32 color_formats;
214 
215 	u8 cea_rev;
216 
217 	char *raw_edid; /* if any */
218 };
219 
220 struct drm_framebuffer_funcs {
221 	void (*destroy)(struct drm_framebuffer *framebuffer);
222 	int (*create_handle)(struct drm_framebuffer *fb,
223 			     struct drm_file *file_priv,
224 			     unsigned int *handle);
225 	/**
226 	 * Optinal callback for the dirty fb ioctl.
227 	 *
228 	 * Userspace can notify the driver via this callback
229 	 * that a area of the framebuffer has changed and should
230 	 * be flushed to the display hardware.
231 	 *
232 	 * See documentation in drm_mode.h for the struct
233 	 * drm_mode_fb_dirty_cmd for more information as all
234 	 * the semantics and arguments have a one to one mapping
235 	 * on this function.
236 	 */
237 	int (*dirty)(struct drm_framebuffer *framebuffer,
238 		     struct drm_file *file_priv, unsigned flags,
239 		     unsigned color, struct drm_clip_rect *clips,
240 		     unsigned num_clips);
241 };
242 
243 struct drm_framebuffer {
244 	struct drm_device *dev;
245 	struct list_head head;
246 	struct drm_mode_object base;
247 	const struct drm_framebuffer_funcs *funcs;
248 	unsigned int pitches[4];
249 	unsigned int offsets[4];
250 	unsigned int width;
251 	unsigned int height;
252 	/* depth can be 15 or 16 */
253 	unsigned int depth;
254 	int bits_per_pixel;
255 	int flags;
256 	uint32_t pixel_format; /* fourcc format */
257 	struct list_head filp_head;
258 	/* if you are using the helper */
259 	void *helper_private;
260 };
261 
262 struct drm_property_blob {
263 	struct drm_mode_object base;
264 	struct list_head head;
265 	unsigned int length;
266 	unsigned char data[];
267 };
268 
269 struct drm_property_enum {
270 	uint64_t value;
271 	struct list_head head;
272 	char name[DRM_PROP_NAME_LEN];
273 };
274 
275 struct drm_property {
276 	struct list_head head;
277 	struct drm_mode_object base;
278 	uint32_t flags;
279 	char name[DRM_PROP_NAME_LEN];
280 	uint32_t num_values;
281 	uint64_t *values;
282 
283 	struct list_head enum_blob_list;
284 };
285 
286 struct drm_crtc;
287 struct drm_connector;
288 struct drm_encoder;
289 struct drm_pending_vblank_event;
290 struct drm_plane;
291 
292 /**
293  * drm_crtc_funcs - control CRTCs for a given device
294  * @reset: reset CRTC after state has been invalidate (e.g. resume)
295  * @dpms: control display power levels
296  * @save: save CRTC state
297  * @resore: restore CRTC state
298  * @lock: lock the CRTC
299  * @unlock: unlock the CRTC
300  * @shadow_allocate: allocate shadow pixmap
301  * @shadow_create: create shadow pixmap for rotation support
302  * @shadow_destroy: free shadow pixmap
303  * @mode_fixup: fixup proposed mode
304  * @mode_set: set the desired mode on the CRTC
305  * @gamma_set: specify color ramp for CRTC
306  * @destroy: deinit and free object
307  * @set_property: called when a property is changed
308  *
309  * The drm_crtc_funcs structure is the central CRTC management structure
310  * in the DRM.  Each CRTC controls one or more connectors (note that the name
311  * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
312  * connectors, not just CRTs).
313  *
314  * Each driver is responsible for filling out this structure at startup time,
315  * in addition to providing other modesetting features, like i2c and DDC
316  * bus accessors.
317  */
318 struct drm_crtc_funcs {
319 	/* Save CRTC state */
320 	void (*save)(struct drm_crtc *crtc); /* suspend? */
321 	/* Restore CRTC state */
322 	void (*restore)(struct drm_crtc *crtc); /* resume? */
323 	/* Reset CRTC state */
324 	void (*reset)(struct drm_crtc *crtc);
325 
326 	/* cursor controls */
327 	int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
328 			  uint32_t handle, uint32_t width, uint32_t height);
329 	int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
330 
331 	/* Set gamma on the CRTC */
332 	void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
333 			  uint32_t start, uint32_t size);
334 	/* Object destroy routine */
335 	void (*destroy)(struct drm_crtc *crtc);
336 
337 	int (*set_config)(struct drm_mode_set *set);
338 
339 	/*
340 	 * Flip to the given framebuffer.  This implements the page
341 	 * flip ioctl descibed in drm_mode.h, specifically, the
342 	 * implementation must return immediately and block all
343 	 * rendering to the current fb until the flip has completed.
344 	 * If userspace set the event flag in the ioctl, the event
345 	 * argument will point to an event to send back when the flip
346 	 * completes, otherwise it will be NULL.
347 	 */
348 	int (*page_flip)(struct drm_crtc *crtc,
349 			 struct drm_framebuffer *fb,
350 			 struct drm_pending_vblank_event *event);
351 	int (*set_property)(struct drm_crtc *crtc,
352 			    struct drm_property *property, uint64_t val);
353 };
354 
355 /**
356  * drm_crtc - central CRTC control structure
357  * @enabled: is this CRTC enabled?
358  * @x: x position on screen
359  * @y: y position on screen
360  * @funcs: CRTC control functions
361  * @properties: property tracking for this CRTC
362  *
363  * Each CRTC may have one or more connectors associated with it.  This structure
364  * allows the CRTC to be controlled.
365  */
366 struct drm_crtc {
367 	struct drm_device *dev;
368 	struct list_head head;
369 
370 	struct drm_mode_object base;
371 
372 	/* framebuffer the connector is currently bound to */
373 	struct drm_framebuffer *fb;
374 
375 	bool enabled;
376 
377 	/* Requested mode from modesetting. */
378 	struct drm_display_mode mode;
379 
380 	/* Programmed mode in hw, after adjustments for encoders,
381 	 * crtc, panel scaling etc. Needed for timestamping etc.
382 	 */
383 	struct drm_display_mode hwmode;
384 
385 	int x, y;
386 	const struct drm_crtc_funcs *funcs;
387 
388 	/* CRTC gamma size for reporting to userspace */
389 	uint32_t gamma_size;
390 	uint16_t *gamma_store;
391 
392 	/* Constants needed for precise vblank and swap timestamping. */
393 	int64_t framedur_ns, linedur_ns, pixeldur_ns;
394 
395 	/* if you are using the helper */
396 	void *helper_private;
397 
398 	struct drm_object_properties properties;
399 };
400 
401 
402 /**
403  * drm_connector_funcs - control connectors on a given device
404  * @dpms: set power state (see drm_crtc_funcs above)
405  * @save: save connector state
406  * @restore: restore connector state
407  * @reset: reset connector after state has been invalidate (e.g. resume)
408  * @mode_valid: is this mode valid on the given connector?
409  * @mode_fixup: try to fixup proposed mode for this connector
410  * @mode_set: set this mode
411  * @detect: is this connector active?
412  * @get_modes: get mode list for this connector
413  * @set_property: property for this connector may need update
414  * @destroy: make object go away
415  * @force: notify the driver the connector is forced on
416  *
417  * Each CRTC may have one or more connectors attached to it.  The functions
418  * below allow the core DRM code to control connectors, enumerate available modes,
419  * etc.
420  */
421 struct drm_connector_funcs {
422 	void (*dpms)(struct drm_connector *connector, int mode);
423 	void (*save)(struct drm_connector *connector);
424 	void (*restore)(struct drm_connector *connector);
425 	void (*reset)(struct drm_connector *connector);
426 
427 	/* Check to see if anything is attached to the connector.
428 	 * @force is set to false whilst polling, true when checking the
429 	 * connector due to user request. @force can be used by the driver
430 	 * to avoid expensive, destructive operations during automated
431 	 * probing.
432 	 */
433 	enum drm_connector_status (*detect)(struct drm_connector *connector,
434 					    bool force);
435 	int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
436 	int (*set_property)(struct drm_connector *connector, struct drm_property *property,
437 			     uint64_t val);
438 	void (*destroy)(struct drm_connector *connector);
439 	void (*force)(struct drm_connector *connector);
440 };
441 
442 struct drm_encoder_funcs {
443 	void (*reset)(struct drm_encoder *encoder);
444 	void (*destroy)(struct drm_encoder *encoder);
445 };
446 
447 #define DRM_CONNECTOR_MAX_UMODES 16
448 #define DRM_CONNECTOR_LEN 32
449 #define DRM_CONNECTOR_MAX_ENCODER 2
450 
451 /**
452  * drm_encoder - central DRM encoder structure
453  */
454 struct drm_encoder {
455 	struct drm_device *dev;
456 	struct list_head head;
457 
458 	struct drm_mode_object base;
459 	int encoder_type;
460 	uint32_t possible_crtcs;
461 	uint32_t possible_clones;
462 
463 	struct drm_crtc *crtc;
464 	const struct drm_encoder_funcs *funcs;
465 	void *helper_private;
466 };
467 
468 enum drm_connector_force {
469 	DRM_FORCE_UNSPECIFIED,
470 	DRM_FORCE_OFF,
471 	DRM_FORCE_ON,         /* force on analog part normally */
472 	DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
473 };
474 
475 /* should we poll this connector for connects and disconnects */
476 /* hot plug detectable */
477 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
478 /* poll for connections */
479 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
480 /* can cleanly poll for disconnections without flickering the screen */
481 /* DACs should rarely do this without a lot of testing */
482 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
483 
484 #define MAX_ELD_BYTES	128
485 
486 /**
487  * drm_connector - central DRM connector control structure
488  * @crtc: CRTC this connector is currently connected to, NULL if none
489  * @interlace_allowed: can this connector handle interlaced modes?
490  * @doublescan_allowed: can this connector handle doublescan?
491  * @available_modes: modes available on this connector (from get_modes() + user)
492  * @initial_x: initial x position for this connector
493  * @initial_y: initial y position for this connector
494  * @status: connector connected?
495  * @funcs: connector control functions
496  *
497  * Each connector may be connected to one or more CRTCs, or may be clonable by
498  * another connector if they can share a CRTC.  Each connector also has a specific
499  * position in the broader display (referred to as a 'screen' though it could
500  * span multiple monitors).
501  */
502 struct drm_connector {
503 	struct drm_device *dev;
504 	/* struct device kdev; XXXKIB */
505 	struct device_attribute *attr;
506 	struct list_head head;
507 
508 	struct drm_mode_object base;
509 
510 	int connector_type;
511 	int connector_type_id;
512 	bool interlace_allowed;
513 	bool doublescan_allowed;
514 	struct list_head modes; /* list of modes on this connector */
515 
516 	int initial_x, initial_y;
517 	enum drm_connector_status status;
518 
519 	/* these are modes added by probing with DDC or the BIOS */
520 	struct list_head probed_modes;
521 
522 	struct drm_display_info display_info;
523 	const struct drm_connector_funcs *funcs;
524 
525 	struct list_head user_modes;
526 	struct drm_property_blob *edid_blob_ptr;
527 	struct drm_object_properties properties;
528 
529 	uint8_t polled; /* DRM_CONNECTOR_POLL_* */
530 
531 	/* requested DPMS state */
532 	int dpms;
533 
534 	void *helper_private;
535 
536 	/* forced on connector */
537 	enum drm_connector_force force;
538 	uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
539 	uint32_t force_encoder_id;
540 	struct drm_encoder *encoder; /* currently active encoder */
541 
542 	/* EDID bits */
543 	uint8_t eld[MAX_ELD_BYTES];
544 	bool dvi_dual;
545 	int max_tmds_clock;	/* in MHz */
546 	bool latency_present[2];
547 	int video_latency[2];	/* [0]: progressive, [1]: interlaced */
548 	int audio_latency[2];
549 
550 	int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
551 };
552 
553 /**
554  * drm_plane_funcs - driver plane control functions
555  * @update_plane: update the plane configuration
556  * @disable_plane: shut down the plane
557  * @destroy: clean up plane resources
558  * @set_property: called when a property is changed
559  */
560 struct drm_plane_funcs {
561 	int (*update_plane)(struct drm_plane *plane,
562 			    struct drm_crtc *crtc, struct drm_framebuffer *fb,
563 			    int crtc_x, int crtc_y,
564 			    unsigned int crtc_w, unsigned int crtc_h,
565 			    uint32_t src_x, uint32_t src_y,
566 			    uint32_t src_w, uint32_t src_h);
567 	int (*disable_plane)(struct drm_plane *plane);
568 	void (*destroy)(struct drm_plane *plane);
569 	int (*set_property)(struct drm_plane *plane,
570 			    struct drm_property *property, uint64_t val);
571 };
572 
573 /**
574  * drm_plane - central DRM plane control structure
575  * @dev: DRM device this plane belongs to
576  * @head: for list management
577  * @base: base mode object
578  * @possible_crtcs: pipes this plane can be bound to
579  * @format_types: array of formats supported by this plane
580  * @format_count: number of formats supported
581  * @crtc: currently bound CRTC
582  * @fb: currently bound fb
583  * @gamma_size: size of gamma table
584  * @gamma_store: gamma correction table
585  * @enabled: enabled flag
586  * @funcs: helper functions
587  * @helper_private: storage for drver layer
588  @properties: property tracking for this plane
589  */
590 struct drm_plane {
591 	struct drm_device *dev;
592 	struct list_head head;
593 
594 	struct drm_mode_object base;
595 
596 	uint32_t possible_crtcs;
597 	uint32_t *format_types;
598 	uint32_t format_count;
599 
600 	struct drm_crtc *crtc;
601 	struct drm_framebuffer *fb;
602 
603 	/* CRTC gamma size for reporting to userspace */
604 	uint32_t gamma_size;
605 	uint16_t *gamma_store;
606 
607 	bool enabled;
608 
609 	const struct drm_plane_funcs *funcs;
610 	void *helper_private;
611 
612 	struct drm_object_properties properties;
613 };
614 
615 /**
616  * struct drm_mode_set
617  *
618  * Represents a single crtc the connectors that it drives with what mode
619  * and from which framebuffer it scans out from.
620  *
621  * This is used to set modes.
622  */
623 struct drm_mode_set {
624 	struct list_head head;
625 
626 	struct drm_framebuffer *fb;
627 	struct drm_crtc *crtc;
628 	struct drm_display_mode *mode;
629 
630 	uint32_t x;
631 	uint32_t y;
632 
633 	struct drm_connector **connectors;
634 	size_t num_connectors;
635 };
636 
637 /**
638  * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
639  */
640 struct drm_mode_config_funcs {
641 	int (*fb_create)(struct drm_device *dev,
642 	    struct drm_file *file_priv, struct drm_mode_fb_cmd2 *mode_cmd,
643 	    struct drm_framebuffer **res);
644 	void (*output_poll_changed)(struct drm_device *dev);
645 };
646 
647 struct drm_mode_group {
648 	uint32_t num_crtcs;
649 	uint32_t num_encoders;
650 	uint32_t num_connectors;
651 
652 	/* list of object IDs for this group */
653 	uint32_t *id_list;
654 };
655 
656 /**
657  * drm_mode_config - Mode configuration control structure
658  *
659  */
660 struct drm_mode_config {
661 	struct sx mutex; /* protects configuration (mode lists etc.) */
662 	struct drm_gem_names crtc_names; /* use this idr for all IDs, fb, crtc, connector, modes */
663 	/* this is limited to one for now */
664 	int num_fb;
665 	struct list_head fb_list;
666 	int num_connector;
667 	struct list_head connector_list;
668 	int num_encoder;
669 	struct list_head encoder_list;
670 	int num_plane;
671 	struct list_head plane_list;
672 
673 	int num_crtc;
674 	struct list_head crtc_list;
675 
676 	struct list_head property_list;
677 
678 	int min_width, min_height;
679 	int max_width, max_height;
680 	const struct drm_mode_config_funcs *funcs;
681 	resource_size_t fb_base;
682 
683 	/* output poll support */
684 	bool poll_enabled;
685 	struct timeout_task output_poll_task;
686 
687 	/* pointers to standard properties */
688 	struct list_head property_blob_list;
689 	struct drm_property *edid_property;
690 	struct drm_property *dpms_property;
691 
692 	/* DVI-I properties */
693 	struct drm_property *dvi_i_subconnector_property;
694 	struct drm_property *dvi_i_select_subconnector_property;
695 
696 	/* TV properties */
697 	struct drm_property *tv_subconnector_property;
698 	struct drm_property *tv_select_subconnector_property;
699 	struct drm_property *tv_mode_property;
700 	struct drm_property *tv_left_margin_property;
701 	struct drm_property *tv_right_margin_property;
702 	struct drm_property *tv_top_margin_property;
703 	struct drm_property *tv_bottom_margin_property;
704 	struct drm_property *tv_brightness_property;
705 	struct drm_property *tv_contrast_property;
706 	struct drm_property *tv_flicker_reduction_property;
707 	struct drm_property *tv_overscan_property;
708 	struct drm_property *tv_saturation_property;
709 	struct drm_property *tv_hue_property;
710 
711 	/* Optional properties */
712 	struct drm_property *scaling_mode_property;
713 	struct drm_property *dithering_mode_property;
714 	struct drm_property *dirty_info_property;
715 
716 	/* dumb ioctl parameters */
717 	uint32_t preferred_depth, prefer_shadow;
718 };
719 
720 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
721 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
722 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
723 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
724 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
725 #define obj_to_property(x) container_of(x, struct drm_property, base)
726 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
727 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
728 
729 struct drm_prop_enum_list {
730 	int type;
731 	char *name;
732 };
733 
734 #if defined(MODE_SETTING_LOCKING_IS_NOT_BROKEN)
735 #define	DRM_MODE_CONFIG_ASSERT_LOCKED(dev) \
736 	sx_assert(&dev->mode_config.mutex, SA_XLOCKED)
737 #else
738 #define	DRM_MODE_CONFIG_ASSERT_LOCKED(dev)
739 #endif
740 
741 extern char *drm_get_dirty_info_name(int val);
742 extern char *drm_get_connector_status_name(enum drm_connector_status status);
743 
744 extern int drm_crtc_init(struct drm_device *dev,
745 			 struct drm_crtc *crtc,
746 			 const struct drm_crtc_funcs *funcs);
747 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
748 
749 extern int drm_connector_init(struct drm_device *dev,
750 			      struct drm_connector *connector,
751 			      const struct drm_connector_funcs *funcs,
752 			      int connector_type);
753 
754 extern void drm_connector_cleanup(struct drm_connector *connector);
755 
756 extern int drm_encoder_init(struct drm_device *dev,
757 			    struct drm_encoder *encoder,
758 			    const struct drm_encoder_funcs *funcs,
759 			    int encoder_type);
760 
761 extern int drm_plane_init(struct drm_device *dev,
762 			  struct drm_plane *plane,
763 			  unsigned long possible_crtcs,
764 			  const struct drm_plane_funcs *funcs,
765 			  const uint32_t *formats, uint32_t format_count,
766 			  bool priv);
767 extern void drm_plane_cleanup(struct drm_plane *plane);
768 
769 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
770 
771 extern char *drm_get_connector_name(struct drm_connector *connector);
772 extern char *drm_get_dpms_name(int val);
773 extern char *drm_get_dvi_i_subconnector_name(int val);
774 extern char *drm_get_dvi_i_select_name(int val);
775 extern char *drm_get_tv_subconnector_name(int val);
776 extern char *drm_get_tv_select_name(int val);
777 extern void drm_fb_release(struct drm_file *file_priv);
778 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
779 extern struct edid *drm_get_edid(struct drm_connector *connector,
780 				 device_t adapter);
781 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
782 extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
783 extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
784 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
785     const struct drm_display_mode *mode);
786 extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
787 extern void drm_mode_config_init(struct drm_device *dev);
788 extern void drm_mode_config_reset(struct drm_device *dev);
789 extern void drm_mode_config_cleanup(struct drm_device *dev);
790 extern void drm_mode_set_name(struct drm_display_mode *mode);
791 extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
792 extern int drm_mode_width(struct drm_display_mode *mode);
793 extern int drm_mode_height(struct drm_display_mode *mode);
794 
795 /* for us by fb module */
796 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
797 				    struct drm_crtc *crtc,
798 				    const struct drm_display_mode *mode);
799 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
800 
801 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
802 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
803 extern void drm_mode_list_concat(struct list_head *head,
804 				 struct list_head *new);
805 extern void drm_mode_validate_size(struct drm_device *dev,
806 				   struct list_head *mode_list,
807 				   int maxX, int maxY, int maxPitch);
808 extern void drm_mode_validate_clocks(struct drm_device *dev,
809 			      struct list_head *mode_list,
810 			      int *min, int *max, int n_ranges);
811 extern void drm_mode_prune_invalid(struct drm_device *dev,
812 				   struct list_head *mode_list, bool verbose);
813 extern void drm_mode_sort(struct list_head *mode_list);
814 extern int drm_mode_hsync(const struct drm_display_mode *mode);
815 extern int drm_mode_vrefresh(const struct drm_display_mode *mode);
816 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
817 				  int adjust_flags);
818 extern void drm_mode_connector_list_update(struct drm_connector *connector);
819 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
820 						struct edid *edid);
821 extern int drm_connector_property_set_value(struct drm_connector *connector,
822 					 struct drm_property *property,
823 					 uint64_t value);
824 extern int drm_connector_property_get_value(struct drm_connector *connector,
825 					 struct drm_property *property,
826 					 uint64_t *value);
827 void drm_object_attach_property(struct drm_mode_object *obj,
828 				struct drm_property *property,
829 				uint64_t init_val);
830 extern int drm_object_property_set_value(struct drm_mode_object *obj,
831 					 struct drm_property *property,
832 					 uint64_t val);
833 extern int drm_object_property_get_value(struct drm_mode_object *obj,
834 					 struct drm_property *property,
835 					 uint64_t *value);
836 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
837 extern void drm_framebuffer_set_object(struct drm_device *dev,
838 				       unsigned long handle);
839 extern int drm_framebuffer_init(struct drm_device *dev,
840 				struct drm_framebuffer *fb,
841 				const struct drm_framebuffer_funcs *funcs);
842 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
843 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
844 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
845 extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
846 extern bool drm_crtc_in_use(struct drm_crtc *crtc);
847 
848 extern void drm_connector_attach_property(struct drm_connector *connector,
849 				      struct drm_property *property, uint64_t init_val);
850 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
851 						const char *name, int num_values);
852 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
853 					 const char *name,
854 					 const struct drm_prop_enum_list *props,
855 					 int num_values);
856 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
857 						 int flags, const char *name,
858 						 const struct drm_prop_enum_list *props,
859 						 int num_values);
860 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
861 					 const char *name,
862 					 uint64_t min, uint64_t max);
863 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
864 extern int drm_property_add_enum(struct drm_property *property, int index,
865 				 uint64_t value, const char *name);
866 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
867 extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
868 				     char *formats[]);
869 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
870 extern int drm_mode_create_dithering_property(struct drm_device *dev);
871 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
872 extern char *drm_get_encoder_name(struct drm_encoder *encoder);
873 
874 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
875 					     struct drm_encoder *encoder);
876 extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
877 					   struct drm_encoder *encoder);
878 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
879 					 int gamma_size);
880 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
881 		uint32_t id, uint32_t type);
882 /* IOCTLs */
883 extern int drm_mode_getresources(struct drm_device *dev,
884 				 void *data, struct drm_file *file_priv);
885 extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
886 				   struct drm_file *file_priv);
887 extern int drm_mode_getcrtc(struct drm_device *dev,
888 			    void *data, struct drm_file *file_priv);
889 extern int drm_mode_getconnector(struct drm_device *dev,
890 			      void *data, struct drm_file *file_priv);
891 extern int drm_mode_setcrtc(struct drm_device *dev,
892 			    void *data, struct drm_file *file_priv);
893 extern int drm_mode_getplane(struct drm_device *dev,
894 			       void *data, struct drm_file *file_priv);
895 extern int drm_mode_setplane(struct drm_device *dev,
896 			       void *data, struct drm_file *file_priv);
897 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
898 				void *data, struct drm_file *file_priv);
899 extern int drm_mode_addfb(struct drm_device *dev,
900 			  void *data, struct drm_file *file_priv);
901 extern int drm_mode_addfb2(struct drm_device *dev,
902 			   void *data, struct drm_file *file_priv);
903 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
904 extern int drm_mode_rmfb(struct drm_device *dev,
905 			 void *data, struct drm_file *file_priv);
906 extern int drm_mode_getfb(struct drm_device *dev,
907 			  void *data, struct drm_file *file_priv);
908 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
909 				  void *data, struct drm_file *file_priv);
910 extern int drm_mode_addmode_ioctl(struct drm_device *dev,
911 				  void *data, struct drm_file *file_priv);
912 extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
913 				 void *data, struct drm_file *file_priv);
914 extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
915 				     void *data, struct drm_file *file_priv);
916 extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
917 				     void *data, struct drm_file *file_priv);
918 
919 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
920 				      void *data, struct drm_file *file_priv);
921 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
922 				  void *data, struct drm_file *file_priv);
923 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
924 					      void *data, struct drm_file *file_priv);
925 extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
926 				  void *data, struct drm_file *file_priv);
927 extern int drm_mode_replacefb(struct drm_device *dev,
928 			      void *data, struct drm_file *file_priv);
929 extern int drm_mode_getencoder(struct drm_device *dev,
930 			       void *data, struct drm_file *file_priv);
931 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
932 				    void *data, struct drm_file *file_priv);
933 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
934 				    void *data, struct drm_file *file_priv);
935 extern bool drm_detect_hdmi_monitor(struct edid *edid);
936 extern bool drm_detect_monitor_audio(struct edid *edid);
937 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
938 				    void *data, struct drm_file *file_priv);
939 extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
940 				int hdisplay, int vdisplay, int vrefresh,
941 				bool reduced, bool interlaced, bool margins);
942 extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
943 				int hdisplay, int vdisplay, int vrefresh,
944 				bool interlaced, int margins);
945 extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
946 				int hdisplay, int vdisplay, int vrefresh,
947 				bool interlaced, int margins, int GTF_M,
948 				int GTF_2C, int GTF_K, int GTF_2J);
949 extern int drm_add_modes_noedid(struct drm_connector *connector,
950 				int hdisplay, int vdisplay);
951 
952 extern int drm_edid_header_is_valid(const u8 *raw_edid);
953 extern bool drm_edid_is_valid(struct edid *edid);
954 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
955 					   int hsize, int vsize, int fresh,
956 					   bool rb);
957 
958 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
959 				      void *data, struct drm_file *file_priv);
960 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
961 				    void *data, struct drm_file *file_priv);
962 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
963 				      void *data, struct drm_file *file_priv);
964 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
965 					     struct drm_file *file_priv);
966 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
967 					   struct drm_file *file_priv);
968 
969 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
970 				 int *bpp);
971 extern int drm_format_num_planes(uint32_t format);
972 extern int drm_format_plane_cpp(uint32_t format, int plane);
973 extern int drm_format_horz_chroma_subsampling(uint32_t format);
974 extern int drm_format_vert_chroma_subsampling(uint32_t format);
975 
976 #endif /* __DRM_CRTC_H__ */
977