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