xref: /linux/include/drm/drm_crtc.h (revision b3b77c8caef1750ebeea1054e39e358550ea9f55)
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 #ifndef __DRM_CRTC_H__
26 #define __DRM_CRTC_H__
27 
28 #include <linux/i2c.h>
29 #include <linux/spinlock.h>
30 #include <linux/types.h>
31 #include <linux/idr.h>
32 
33 #include <linux/fb.h>
34 #include <linux/slow-work.h>
35 
36 struct drm_device;
37 struct drm_mode_set;
38 struct drm_framebuffer;
39 
40 
41 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
42 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
43 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
44 #define DRM_MODE_OBJECT_MODE 0xdededede
45 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
46 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
47 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
48 
49 struct drm_mode_object {
50 	uint32_t id;
51 	uint32_t type;
52 };
53 
54 /*
55  * Note on terminology:  here, for brevity and convenience, we refer to connector
56  * control chips as 'CRTCs'.  They can control any type of connector, VGA, LVDS,
57  * DVI, etc.  And 'screen' refers to the whole of the visible display, which
58  * may span multiple monitors (and therefore multiple CRTC and connector
59  * structures).
60  */
61 
62 enum drm_mode_status {
63     MODE_OK	= 0,	/* Mode OK */
64     MODE_HSYNC,		/* hsync out of range */
65     MODE_VSYNC,		/* vsync out of range */
66     MODE_H_ILLEGAL,	/* mode has illegal horizontal timings */
67     MODE_V_ILLEGAL,	/* mode has illegal horizontal timings */
68     MODE_BAD_WIDTH,	/* requires an unsupported linepitch */
69     MODE_NOMODE,	/* no mode with a maching name */
70     MODE_NO_INTERLACE,	/* interlaced mode not supported */
71     MODE_NO_DBLESCAN,	/* doublescan mode not supported */
72     MODE_NO_VSCAN,	/* multiscan mode not supported */
73     MODE_MEM,		/* insufficient video memory */
74     MODE_VIRTUAL_X,	/* mode width too large for specified virtual size */
75     MODE_VIRTUAL_Y,	/* mode height too large for specified virtual size */
76     MODE_MEM_VIRT,	/* insufficient video memory given virtual size */
77     MODE_NOCLOCK,	/* no fixed clock available */
78     MODE_CLOCK_HIGH,	/* clock required is too high */
79     MODE_CLOCK_LOW,	/* clock required is too low */
80     MODE_CLOCK_RANGE,	/* clock/mode isn't in a ClockRange */
81     MODE_BAD_HVALUE,	/* horizontal timing was out of range */
82     MODE_BAD_VVALUE,	/* vertical timing was out of range */
83     MODE_BAD_VSCAN,	/* VScan value out of range */
84     MODE_HSYNC_NARROW,	/* horizontal sync too narrow */
85     MODE_HSYNC_WIDE,	/* horizontal sync too wide */
86     MODE_HBLANK_NARROW,	/* horizontal blanking too narrow */
87     MODE_HBLANK_WIDE,	/* horizontal blanking too wide */
88     MODE_VSYNC_NARROW,	/* vertical sync too narrow */
89     MODE_VSYNC_WIDE,	/* vertical sync too wide */
90     MODE_VBLANK_NARROW,	/* vertical blanking too narrow */
91     MODE_VBLANK_WIDE,	/* vertical blanking too wide */
92     MODE_PANEL,         /* exceeds panel dimensions */
93     MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
94     MODE_ONE_WIDTH,     /* only one width is supported */
95     MODE_ONE_HEIGHT,    /* only one height is supported */
96     MODE_ONE_SIZE,      /* only one resolution is supported */
97     MODE_NO_REDUCED,    /* monitor doesn't accept reduced blanking */
98     MODE_UNVERIFIED = -3, /* mode needs to reverified */
99     MODE_BAD = -2,	/* unspecified reason */
100     MODE_ERROR	= -1	/* error condition */
101 };
102 
103 #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
104 				    DRM_MODE_TYPE_CRTC_C)
105 
106 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
107 	.name = nm, .status = 0, .type = (t), .clock = (c), \
108 	.hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
109 	.htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
110 	.vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
111 	.vscan = (vs), .flags = (f), .vrefresh = 0
112 
113 #define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */
114 
115 struct drm_display_mode {
116 	/* Header */
117 	struct list_head head;
118 	struct drm_mode_object base;
119 
120 	char name[DRM_DISPLAY_MODE_LEN];
121 
122 	int connector_count;
123 	enum drm_mode_status status;
124 	int type;
125 
126 	/* Proposed mode values */
127 	int clock;		/* in kHz */
128 	int hdisplay;
129 	int hsync_start;
130 	int hsync_end;
131 	int htotal;
132 	int hskew;
133 	int vdisplay;
134 	int vsync_start;
135 	int vsync_end;
136 	int vtotal;
137 	int vscan;
138 	unsigned int flags;
139 
140 	/* Addressable image size (may be 0 for projectors, etc.) */
141 	int width_mm;
142 	int height_mm;
143 
144 	/* Actual mode we give to hw */
145 	int clock_index;
146 	int synth_clock;
147 	int crtc_hdisplay;
148 	int crtc_hblank_start;
149 	int crtc_hblank_end;
150 	int crtc_hsync_start;
151 	int crtc_hsync_end;
152 	int crtc_htotal;
153 	int crtc_hskew;
154 	int crtc_vdisplay;
155 	int crtc_vblank_start;
156 	int crtc_vblank_end;
157 	int crtc_vsync_start;
158 	int crtc_vsync_end;
159 	int crtc_vtotal;
160 	int crtc_hadjusted;
161 	int crtc_vadjusted;
162 
163 	/* Driver private mode info */
164 	int private_size;
165 	int *private;
166 	int private_flags;
167 
168 	int vrefresh;		/* in Hz */
169 	int hsync;		/* in kHz */
170 };
171 
172 enum drm_connector_status {
173 	connector_status_connected = 1,
174 	connector_status_disconnected = 2,
175 	connector_status_unknown = 3,
176 };
177 
178 enum subpixel_order {
179 	SubPixelUnknown = 0,
180 	SubPixelHorizontalRGB,
181 	SubPixelHorizontalBGR,
182 	SubPixelVerticalRGB,
183 	SubPixelVerticalBGR,
184 	SubPixelNone,
185 };
186 
187 
188 /*
189  * Describes a given display (e.g. CRT or flat panel) and its limitations.
190  */
191 struct drm_display_info {
192 	char name[DRM_DISPLAY_INFO_LEN];
193 	/* Input info */
194 	bool serration_vsync;
195 	bool sync_on_green;
196 	bool composite_sync;
197 	bool separate_syncs;
198 	bool blank_to_black;
199 	unsigned char video_level;
200 	bool digital;
201 	/* Physical size */
202         unsigned int width_mm;
203 	unsigned int height_mm;
204 
205 	/* Display parameters */
206 	unsigned char gamma; /* FIXME: storage format */
207 	bool gtf_supported;
208 	bool standard_color;
209 	enum {
210 		monochrome = 0,
211 		rgb,
212 		other,
213 		unknown,
214 	} display_type;
215 	bool active_off_supported;
216 	bool suspend_supported;
217 	bool standby_supported;
218 
219 	/* Color info FIXME: storage format */
220 	unsigned short redx, redy;
221 	unsigned short greenx, greeny;
222 	unsigned short bluex, bluey;
223 	unsigned short whitex, whitey;
224 
225 	/* Clock limits FIXME: storage format */
226 	unsigned int min_vfreq, max_vfreq;
227 	unsigned int min_hfreq, max_hfreq;
228 	unsigned int pixel_clock;
229 
230 	/* White point indices FIXME: storage format */
231 	unsigned int wpx1, wpy1;
232 	unsigned int wpgamma1;
233 	unsigned int wpx2, wpy2;
234 	unsigned int wpgamma2;
235 
236 	enum subpixel_order subpixel_order;
237 
238 	char *raw_edid; /* if any */
239 };
240 
241 struct drm_framebuffer_funcs {
242 	void (*destroy)(struct drm_framebuffer *framebuffer);
243 	int (*create_handle)(struct drm_framebuffer *fb,
244 			     struct drm_file *file_priv,
245 			     unsigned int *handle);
246 	/**
247 	 * Optinal callback for the dirty fb ioctl.
248 	 *
249 	 * Userspace can notify the driver via this callback
250 	 * that a area of the framebuffer has changed and should
251 	 * be flushed to the display hardware.
252 	 *
253 	 * See documentation in drm_mode.h for the struct
254 	 * drm_mode_fb_dirty_cmd for more information as all
255 	 * the semantics and arguments have a one to one mapping
256 	 * on this function.
257 	 */
258 	int (*dirty)(struct drm_framebuffer *framebuffer, unsigned flags,
259 		     unsigned color, struct drm_clip_rect *clips,
260 		     unsigned num_clips);
261 };
262 
263 struct drm_framebuffer {
264 	struct drm_device *dev;
265 	struct list_head head;
266 	struct drm_mode_object base;
267 	const struct drm_framebuffer_funcs *funcs;
268 	unsigned int pitch;
269 	unsigned int width;
270 	unsigned int height;
271 	/* depth can be 15 or 16 */
272 	unsigned int depth;
273 	int bits_per_pixel;
274 	int flags;
275 	struct list_head filp_head;
276 	/* if you are using the helper */
277 	void *helper_private;
278 };
279 
280 struct drm_property_blob {
281 	struct drm_mode_object base;
282 	struct list_head head;
283 	unsigned int length;
284 	void *data;
285 };
286 
287 struct drm_property_enum {
288 	uint64_t value;
289 	struct list_head head;
290 	char name[DRM_PROP_NAME_LEN];
291 };
292 
293 struct drm_property {
294 	struct list_head head;
295 	struct drm_mode_object base;
296 	uint32_t flags;
297 	char name[DRM_PROP_NAME_LEN];
298 	uint32_t num_values;
299 	uint64_t *values;
300 
301 	struct list_head enum_blob_list;
302 };
303 
304 struct drm_crtc;
305 struct drm_connector;
306 struct drm_encoder;
307 struct drm_pending_vblank_event;
308 
309 /**
310  * drm_crtc_funcs - control CRTCs for a given device
311  * @dpms: control display power levels
312  * @save: save CRTC state
313  * @resore: restore CRTC state
314  * @lock: lock the CRTC
315  * @unlock: unlock the CRTC
316  * @shadow_allocate: allocate shadow pixmap
317  * @shadow_create: create shadow pixmap for rotation support
318  * @shadow_destroy: free shadow pixmap
319  * @mode_fixup: fixup proposed mode
320  * @mode_set: set the desired mode on the CRTC
321  * @gamma_set: specify color ramp for CRTC
322  * @destroy: deinit and free object.
323  *
324  * The drm_crtc_funcs structure is the central CRTC management structure
325  * in the DRM.  Each CRTC controls one or more connectors (note that the name
326  * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
327  * connectors, not just CRTs).
328  *
329  * Each driver is responsible for filling out this structure at startup time,
330  * in addition to providing other modesetting features, like i2c and DDC
331  * bus accessors.
332  */
333 struct drm_crtc_funcs {
334 	/* Save CRTC state */
335 	void (*save)(struct drm_crtc *crtc); /* suspend? */
336 	/* Restore CRTC state */
337 	void (*restore)(struct drm_crtc *crtc); /* resume? */
338 
339 	/* cursor controls */
340 	int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
341 			  uint32_t handle, uint32_t width, uint32_t height);
342 	int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
343 
344 	/* Set gamma on the CRTC */
345 	void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
346 			  uint32_t size);
347 	/* Object destroy routine */
348 	void (*destroy)(struct drm_crtc *crtc);
349 
350 	int (*set_config)(struct drm_mode_set *set);
351 
352 	/*
353 	 * Flip to the given framebuffer.  This implements the page
354 	 * flip ioctl descibed in drm_mode.h, specifically, the
355 	 * implementation must return immediately and block all
356 	 * rendering to the current fb until the flip has completed.
357 	 * If userspace set the event flag in the ioctl, the event
358 	 * argument will point to an event to send back when the flip
359 	 * completes, otherwise it will be NULL.
360 	 */
361 	int (*page_flip)(struct drm_crtc *crtc,
362 			 struct drm_framebuffer *fb,
363 			 struct drm_pending_vblank_event *event);
364 };
365 
366 /**
367  * drm_crtc - central CRTC control structure
368  * @enabled: is this CRTC enabled?
369  * @x: x position on screen
370  * @y: y position on screen
371  * @funcs: CRTC control functions
372  *
373  * Each CRTC may have one or more connectors associated with it.  This structure
374  * allows the CRTC to be controlled.
375  */
376 struct drm_crtc {
377 	struct drm_device *dev;
378 	struct list_head head;
379 
380 	struct drm_mode_object base;
381 
382 	/* framebuffer the connector is currently bound to */
383 	struct drm_framebuffer *fb;
384 
385 	bool enabled;
386 
387 	struct drm_display_mode mode;
388 
389 	int x, y;
390 	const struct drm_crtc_funcs *funcs;
391 
392 	/* CRTC gamma size for reporting to userspace */
393 	uint32_t gamma_size;
394 	uint16_t *gamma_store;
395 
396 	/* if you are using the helper */
397 	void *helper_private;
398 };
399 
400 
401 /**
402  * drm_connector_funcs - control connectors on a given device
403  * @dpms: set power state (see drm_crtc_funcs above)
404  * @save: save connector state
405  * @restore: restore connector state
406  * @mode_valid: is this mode valid on the given connector?
407  * @mode_fixup: try to fixup proposed mode for this connector
408  * @mode_set: set this mode
409  * @detect: is this connector active?
410  * @get_modes: get mode list for this connector
411  * @set_property: property for this connector may need update
412  * @destroy: make object go away
413  * @force: notify the driver the connector is forced on
414  *
415  * Each CRTC may have one or more connectors attached to it.  The functions
416  * below allow the core DRM code to control connectors, enumerate available modes,
417  * etc.
418  */
419 struct drm_connector_funcs {
420 	void (*dpms)(struct drm_connector *connector, int mode);
421 	void (*save)(struct drm_connector *connector);
422 	void (*restore)(struct drm_connector *connector);
423 	enum drm_connector_status (*detect)(struct drm_connector *connector);
424 	int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
425 	int (*set_property)(struct drm_connector *connector, struct drm_property *property,
426 			     uint64_t val);
427 	void (*destroy)(struct drm_connector *connector);
428 	void (*force)(struct drm_connector *connector);
429 };
430 
431 struct drm_encoder_funcs {
432 	void (*destroy)(struct drm_encoder *encoder);
433 };
434 
435 #define DRM_CONNECTOR_MAX_UMODES 16
436 #define DRM_CONNECTOR_MAX_PROPERTY 16
437 #define DRM_CONNECTOR_LEN 32
438 #define DRM_CONNECTOR_MAX_ENCODER 2
439 
440 /**
441  * drm_encoder - central DRM encoder structure
442  */
443 struct drm_encoder {
444 	struct drm_device *dev;
445 	struct list_head head;
446 
447 	struct drm_mode_object base;
448 	int encoder_type;
449 	uint32_t possible_crtcs;
450 	uint32_t possible_clones;
451 
452 	struct drm_crtc *crtc;
453 	const struct drm_encoder_funcs *funcs;
454 	void *helper_private;
455 };
456 
457 enum drm_connector_force {
458 	DRM_FORCE_UNSPECIFIED,
459 	DRM_FORCE_OFF,
460 	DRM_FORCE_ON,         /* force on analog part normally */
461 	DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
462 };
463 
464 /* should we poll this connector for connects and disconnects */
465 /* hot plug detectable */
466 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
467 /* poll for connections */
468 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
469 /* can cleanly poll for disconnections without flickering the screen */
470 /* DACs should rarely do this without a lot of testing */
471 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
472 
473 /**
474  * drm_connector - central DRM connector control structure
475  * @crtc: CRTC this connector is currently connected to, NULL if none
476  * @interlace_allowed: can this connector handle interlaced modes?
477  * @doublescan_allowed: can this connector handle doublescan?
478  * @available_modes: modes available on this connector (from get_modes() + user)
479  * @initial_x: initial x position for this connector
480  * @initial_y: initial y position for this connector
481  * @status: connector connected?
482  * @funcs: connector control functions
483  *
484  * Each connector may be connected to one or more CRTCs, or may be clonable by
485  * another connector if they can share a CRTC.  Each connector also has a specific
486  * position in the broader display (referred to as a 'screen' though it could
487  * span multiple monitors).
488  */
489 struct drm_connector {
490 	struct drm_device *dev;
491 	struct device kdev;
492 	struct device_attribute *attr;
493 	struct list_head head;
494 
495 	struct drm_mode_object base;
496 
497 	int connector_type;
498 	int connector_type_id;
499 	bool interlace_allowed;
500 	bool doublescan_allowed;
501 	struct list_head modes; /* list of modes on this connector */
502 
503 	int initial_x, initial_y;
504 	enum drm_connector_status status;
505 
506 	/* these are modes added by probing with DDC or the BIOS */
507 	struct list_head probed_modes;
508 
509 	struct drm_display_info display_info;
510 	const struct drm_connector_funcs *funcs;
511 
512 	struct list_head user_modes;
513 	struct drm_property_blob *edid_blob_ptr;
514 	u32 property_ids[DRM_CONNECTOR_MAX_PROPERTY];
515 	uint64_t property_values[DRM_CONNECTOR_MAX_PROPERTY];
516 
517 	uint8_t polled; /* DRM_CONNECTOR_POLL_* */
518 
519 	/* requested DPMS state */
520 	int dpms;
521 
522 	void *helper_private;
523 
524 	/* forced on connector */
525 	enum drm_connector_force force;
526 	uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
527 	uint32_t force_encoder_id;
528 	struct drm_encoder *encoder; /* currently active encoder */
529 };
530 
531 /**
532  * struct drm_mode_set
533  *
534  * Represents a single crtc the connectors that it drives with what mode
535  * and from which framebuffer it scans out from.
536  *
537  * This is used to set modes.
538  */
539 struct drm_mode_set {
540 	struct list_head head;
541 
542 	struct drm_framebuffer *fb;
543 	struct drm_crtc *crtc;
544 	struct drm_display_mode *mode;
545 
546 	uint32_t x;
547 	uint32_t y;
548 
549 	struct drm_connector **connectors;
550 	size_t num_connectors;
551 };
552 
553 /**
554  * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
555  */
556 struct drm_mode_config_funcs {
557 	struct drm_framebuffer *(*fb_create)(struct drm_device *dev, struct drm_file *file_priv, struct drm_mode_fb_cmd *mode_cmd);
558 	void (*output_poll_changed)(struct drm_device *dev);
559 };
560 
561 struct drm_mode_group {
562 	uint32_t num_crtcs;
563 	uint32_t num_encoders;
564 	uint32_t num_connectors;
565 
566 	/* list of object IDs for this group */
567 	uint32_t *id_list;
568 };
569 
570 /**
571  * drm_mode_config - Mode configuration control structure
572  *
573  */
574 struct drm_mode_config {
575 	struct mutex mutex; /* protects configuration (mode lists etc.) */
576 	struct mutex idr_mutex; /* for IDR management */
577 	struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
578 	/* this is limited to one for now */
579 	int num_fb;
580 	struct list_head fb_list;
581 	int num_connector;
582 	struct list_head connector_list;
583 	int num_encoder;
584 	struct list_head encoder_list;
585 
586 	int num_crtc;
587 	struct list_head crtc_list;
588 
589 	struct list_head property_list;
590 
591 	int min_width, min_height;
592 	int max_width, max_height;
593 	struct drm_mode_config_funcs *funcs;
594 	resource_size_t fb_base;
595 
596 	/* output poll support */
597 	bool poll_enabled;
598 	struct delayed_slow_work output_poll_slow_work;
599 
600 	/* pointers to standard properties */
601 	struct list_head property_blob_list;
602 	struct drm_property *edid_property;
603 	struct drm_property *dpms_property;
604 
605 	/* DVI-I properties */
606 	struct drm_property *dvi_i_subconnector_property;
607 	struct drm_property *dvi_i_select_subconnector_property;
608 
609 	/* TV properties */
610 	struct drm_property *tv_subconnector_property;
611 	struct drm_property *tv_select_subconnector_property;
612 	struct drm_property *tv_mode_property;
613 	struct drm_property *tv_left_margin_property;
614 	struct drm_property *tv_right_margin_property;
615 	struct drm_property *tv_top_margin_property;
616 	struct drm_property *tv_bottom_margin_property;
617 	struct drm_property *tv_brightness_property;
618 	struct drm_property *tv_contrast_property;
619 	struct drm_property *tv_flicker_reduction_property;
620 	struct drm_property *tv_overscan_property;
621 	struct drm_property *tv_saturation_property;
622 	struct drm_property *tv_hue_property;
623 
624 	/* Optional properties */
625 	struct drm_property *scaling_mode_property;
626 	struct drm_property *dithering_mode_property;
627 	struct drm_property *dirty_info_property;
628 };
629 
630 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
631 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
632 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
633 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
634 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
635 #define obj_to_property(x) container_of(x, struct drm_property, base)
636 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
637 
638 
639 extern void drm_crtc_init(struct drm_device *dev,
640 			  struct drm_crtc *crtc,
641 			  const struct drm_crtc_funcs *funcs);
642 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
643 
644 extern void drm_connector_init(struct drm_device *dev,
645 			    struct drm_connector *connector,
646 			    const struct drm_connector_funcs *funcs,
647 			    int connector_type);
648 
649 extern void drm_connector_cleanup(struct drm_connector *connector);
650 
651 extern void drm_encoder_init(struct drm_device *dev,
652 			     struct drm_encoder *encoder,
653 			     const struct drm_encoder_funcs *funcs,
654 			     int encoder_type);
655 
656 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
657 
658 extern char *drm_get_connector_name(struct drm_connector *connector);
659 extern char *drm_get_dpms_name(int val);
660 extern char *drm_get_dvi_i_subconnector_name(int val);
661 extern char *drm_get_dvi_i_select_name(int val);
662 extern char *drm_get_tv_subconnector_name(int val);
663 extern char *drm_get_tv_select_name(int val);
664 extern void drm_fb_release(struct drm_file *file_priv);
665 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
666 extern struct edid *drm_get_edid(struct drm_connector *connector,
667 				 struct i2c_adapter *adapter);
668 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
669 extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
670 extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
671 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
672 						   struct drm_display_mode *mode);
673 extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
674 extern void drm_mode_config_init(struct drm_device *dev);
675 extern void drm_mode_config_cleanup(struct drm_device *dev);
676 extern void drm_mode_set_name(struct drm_display_mode *mode);
677 extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
678 extern int drm_mode_width(struct drm_display_mode *mode);
679 extern int drm_mode_height(struct drm_display_mode *mode);
680 
681 /* for us by fb module */
682 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
683 				    struct drm_crtc *crtc,
684 				    struct drm_display_mode *mode);
685 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
686 
687 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
688 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
689 extern void drm_mode_list_concat(struct list_head *head,
690 				 struct list_head *new);
691 extern void drm_mode_validate_size(struct drm_device *dev,
692 				   struct list_head *mode_list,
693 				   int maxX, int maxY, int maxPitch);
694 extern void drm_mode_prune_invalid(struct drm_device *dev,
695 				   struct list_head *mode_list, bool verbose);
696 extern void drm_mode_sort(struct list_head *mode_list);
697 extern int drm_mode_hsync(struct drm_display_mode *mode);
698 extern int drm_mode_vrefresh(struct drm_display_mode *mode);
699 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
700 				  int adjust_flags);
701 extern void drm_mode_connector_list_update(struct drm_connector *connector);
702 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
703 						struct edid *edid);
704 extern int drm_connector_property_set_value(struct drm_connector *connector,
705 					 struct drm_property *property,
706 					 uint64_t value);
707 extern int drm_connector_property_get_value(struct drm_connector *connector,
708 					 struct drm_property *property,
709 					 uint64_t *value);
710 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
711 extern void drm_framebuffer_set_object(struct drm_device *dev,
712 				       unsigned long handle);
713 extern int drm_framebuffer_init(struct drm_device *dev,
714 				struct drm_framebuffer *fb,
715 				const struct drm_framebuffer_funcs *funcs);
716 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
717 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
718 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
719 extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
720 extern bool drm_crtc_in_use(struct drm_crtc *crtc);
721 
722 extern int drm_connector_attach_property(struct drm_connector *connector,
723 				      struct drm_property *property, uint64_t init_val);
724 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
725 						const char *name, int num_values);
726 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
727 extern int drm_property_add_enum(struct drm_property *property, int index,
728 				 uint64_t value, const char *name);
729 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
730 extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
731 				     char *formats[]);
732 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
733 extern int drm_mode_create_dithering_property(struct drm_device *dev);
734 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
735 extern char *drm_get_encoder_name(struct drm_encoder *encoder);
736 
737 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
738 					     struct drm_encoder *encoder);
739 extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
740 					   struct drm_encoder *encoder);
741 extern bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
742 					 int gamma_size);
743 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
744 		uint32_t id, uint32_t type);
745 /* IOCTLs */
746 extern int drm_mode_getresources(struct drm_device *dev,
747 				 void *data, struct drm_file *file_priv);
748 
749 extern int drm_mode_getcrtc(struct drm_device *dev,
750 			    void *data, struct drm_file *file_priv);
751 extern int drm_mode_getconnector(struct drm_device *dev,
752 			      void *data, struct drm_file *file_priv);
753 extern int drm_mode_setcrtc(struct drm_device *dev,
754 			    void *data, struct drm_file *file_priv);
755 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
756 				void *data, struct drm_file *file_priv);
757 extern int drm_mode_addfb(struct drm_device *dev,
758 			  void *data, struct drm_file *file_priv);
759 extern int drm_mode_rmfb(struct drm_device *dev,
760 			 void *data, struct drm_file *file_priv);
761 extern int drm_mode_getfb(struct drm_device *dev,
762 			  void *data, struct drm_file *file_priv);
763 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
764 				  void *data, struct drm_file *file_priv);
765 extern int drm_mode_addmode_ioctl(struct drm_device *dev,
766 				  void *data, struct drm_file *file_priv);
767 extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
768 				 void *data, struct drm_file *file_priv);
769 extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
770 				     void *data, struct drm_file *file_priv);
771 extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
772 				     void *data, struct drm_file *file_priv);
773 
774 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
775 				      void *data, struct drm_file *file_priv);
776 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
777 				  void *data, struct drm_file *file_priv);
778 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
779 					      void *data, struct drm_file *file_priv);
780 extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
781 				  void *data, struct drm_file *file_priv);
782 extern int drm_mode_replacefb(struct drm_device *dev,
783 			      void *data, struct drm_file *file_priv);
784 extern int drm_mode_getencoder(struct drm_device *dev,
785 			       void *data, struct drm_file *file_priv);
786 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
787 				    void *data, struct drm_file *file_priv);
788 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
789 				    void *data, struct drm_file *file_priv);
790 extern bool drm_detect_hdmi_monitor(struct edid *edid);
791 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
792 				    void *data, struct drm_file *file_priv);
793 extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
794 				int hdisplay, int vdisplay, int vrefresh,
795 				bool reduced, bool interlaced, bool margins);
796 extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
797 				int hdisplay, int vdisplay, int vrefresh,
798 				bool interlaced, int margins);
799 extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
800 				int hdisplay, int vdisplay, int vrefresh,
801 				bool interlaced, int margins, int GTF_M,
802 				int GTF_2C, int GTF_K, int GTF_2J);
803 extern int drm_add_modes_noedid(struct drm_connector *connector,
804 				int hdisplay, int vdisplay);
805 
806 extern bool drm_edid_is_valid(struct edid *edid);
807 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
808 					   int hsize, int vsize, int fresh);
809 #endif /* __DRM_CRTC_H__ */
810