OSDN Git Service

Merge branch 'master' into modesetting-101 - TTM & typedef removal
[android-x86/external-libdrm.git] / linux-core / drm_crtc.h
1 /*
2  * Copyright © 2006 Keith Packard
3  * Copyright © 2007 Intel Corporation
4  *   Jesse Barnes <jesse.barnes@intel.com>
5  */
6 #ifndef __DRM_CRTC_H__
7 #define __DRM_CRTC_H__
8
9 #include <linux/i2c.h>
10 #include <linux/spinlock.h>
11 #include <linux/types.h>
12 #include <linux/idr.h>
13
14 #include <linux/fb.h>
15
16 struct drm_device;
17
18 /*
19  * Note on terminology:  here, for brevity and convenience, we refer to output
20  * control chips as 'CRTCs'.  They can control any type of output, VGA, LVDS,
21  * DVI, etc.  And 'screen' refers to the whole of the visible display, which
22  * may span multiple monitors (and therefore multiple CRTC and output
23  * structures).
24  */
25
26 enum drm_mode_status {
27     MODE_OK     = 0,    /* Mode OK */
28     MODE_HSYNC,         /* hsync out of range */
29     MODE_VSYNC,         /* vsync out of range */
30     MODE_H_ILLEGAL,     /* mode has illegal horizontal timings */
31     MODE_V_ILLEGAL,     /* mode has illegal horizontal timings */
32     MODE_BAD_WIDTH,     /* requires an unsupported linepitch */
33     MODE_NOMODE,        /* no mode with a maching name */
34     MODE_NO_INTERLACE,  /* interlaced mode not supported */
35     MODE_NO_DBLESCAN,   /* doublescan mode not supported */
36     MODE_NO_VSCAN,      /* multiscan mode not supported */
37     MODE_MEM,           /* insufficient video memory */
38     MODE_VIRTUAL_X,     /* mode width too large for specified virtual size */
39     MODE_VIRTUAL_Y,     /* mode height too large for specified virtual size */
40     MODE_MEM_VIRT,      /* insufficient video memory given virtual size */
41     MODE_NOCLOCK,       /* no fixed clock available */
42     MODE_CLOCK_HIGH,    /* clock required is too high */
43     MODE_CLOCK_LOW,     /* clock required is too low */
44     MODE_CLOCK_RANGE,   /* clock/mode isn't in a ClockRange */
45     MODE_BAD_HVALUE,    /* horizontal timing was out of range */
46     MODE_BAD_VVALUE,    /* vertical timing was out of range */
47     MODE_BAD_VSCAN,     /* VScan value out of range */
48     MODE_HSYNC_NARROW,  /* horizontal sync too narrow */
49     MODE_HSYNC_WIDE,    /* horizontal sync too wide */
50     MODE_HBLANK_NARROW, /* horizontal blanking too narrow */
51     MODE_HBLANK_WIDE,   /* horizontal blanking too wide */
52     MODE_VSYNC_NARROW,  /* vertical sync too narrow */
53     MODE_VSYNC_WIDE,    /* vertical sync too wide */
54     MODE_VBLANK_NARROW, /* vertical blanking too narrow */
55     MODE_VBLANK_WIDE,   /* vertical blanking too wide */
56     MODE_PANEL,         /* exceeds panel dimensions */
57     MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
58     MODE_ONE_WIDTH,     /* only one width is supported */
59     MODE_ONE_HEIGHT,    /* only one height is supported */
60     MODE_ONE_SIZE,      /* only one resolution is supported */
61     MODE_NO_REDUCED,    /* monitor doesn't accept reduced blanking */
62     MODE_UNVERIFIED = -3, /* mode needs to reverified */
63     MODE_BAD = -2,      /* unspecified reason */
64     MODE_ERROR  = -1    /* error condition */
65 };
66
67 #define DRM_MODE_TYPE_BUILTIN   (1<<0)
68 #define DRM_MODE_TYPE_CLOCK_C   ((1<<1) | DRM_MODE_TYPE_BUILTIN)
69 #define DRM_MODE_TYPE_CRTC_C    ((1<<2) | DRM_MODE_TYPE_BUILTIN)
70 #define DRM_MODE_TYPE_PREFERRED (1<<3)
71 #define DRM_MODE_TYPE_DEFAULT   (1<<4)
72 #define DRM_MODE_TYPE_USERDEF   (1<<5)
73 #define DRM_MODE_TYPE_DRIVER    (1<<6)
74
75 #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
76                                     DRM_MODE_TYPE_CRTC_C)
77
78 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
79         .name = nm, .status = 0, .type = (t), .clock = (c), \
80         .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
81         .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
82         .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
83         .vscan = (vs), .flags = (f), .vrefresh = 0
84
85 struct drm_display_mode {
86         /* Header */
87         struct list_head head;
88         char name[DRM_DISPLAY_MODE_LEN];
89         int mode_id;
90         int output_count;
91         enum drm_mode_status status;
92         int type;
93
94         /* Proposed mode values */
95         int clock;
96         int hdisplay;
97         int hsync_start;
98         int hsync_end;
99         int htotal;
100         int hskew;
101         int vdisplay;
102         int vsync_start;
103         int vsync_end;
104         int vtotal;
105         int vscan;
106         unsigned int flags;
107
108         /* Actual mode we give to hw */
109         int clock_index;
110         int synth_clock;
111         int crtc_hdisplay;
112         int crtc_hblank_start;
113         int crtc_hblank_end;
114         int crtc_hsync_start;
115         int crtc_hsync_end;
116         int crtc_htotal;
117         int crtc_hskew;
118         int crtc_vdisplay;
119         int crtc_vblank_start;
120         int crtc_vblank_end;
121         int crtc_vsync_start;
122         int crtc_vsync_end;
123         int crtc_vtotal;
124         int crtc_hadjusted;
125         int crtc_vadjusted;
126
127         /* Driver private mode info */
128         int private_size;
129         int *private;
130         int private_flags;
131
132         int vrefresh;
133         float hsync;
134 };
135
136 /* Video mode flags */
137 #define V_PHSYNC        (1<<0)
138 #define V_NHSYNC        (1<<1)
139 #define V_PVSYNC        (1<<2)
140 #define V_NVSYNC        (1<<3)
141 #define V_INTERLACE     (1<<4)
142 #define V_DBLSCAN       (1<<5)
143 #define V_CSYNC         (1<<6)
144 #define V_PCSYNC        (1<<7)
145 #define V_NCSYNC        (1<<8)
146 #define V_HSKEW         (1<<9) /* hskew provided */
147 #define V_BCAST         (1<<10)
148 #define V_PIXMUX        (1<<11)
149 #define V_DBLCLK        (1<<12)
150 #define V_CLKDIV2       (1<<13)
151
152 #define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */
153 #define DPMSModeOn 0
154 #define DPMSModeStandby 1
155 #define DPMSModeSuspend 2
156 #define DPMSModeOff 3
157
158 enum drm_output_status {
159         output_status_connected,
160         output_status_disconnected,
161         output_status_unknown,
162 };
163
164 enum subpixel_order {
165         SubPixelUnknown = 0,
166         SubPixelHorizontalRGB,
167         SubPixelHorizontalBGR,
168         SubPixelVerticalRGB,
169         SubPixelVerticalBGR,
170         SubPixelNone,
171 };
172
173 /*
174  * Describes a given display (e.g. CRT or flat panel) and its limitations.
175  */
176 struct drm_display_info {
177         char name[DRM_DISPLAY_INFO_LEN];
178         /* Input info */
179         bool serration_vsync;
180         bool sync_on_green;
181         bool composite_sync;
182         bool separate_syncs;
183         bool blank_to_black;
184         unsigned char video_level;
185         bool digital;
186         /* Physical size */
187         unsigned int width_mm;
188         unsigned int height_mm;
189
190         /* Display parameters */
191         unsigned char gamma; /* FIXME: storage format */
192         bool gtf_supported;
193         bool standard_color;
194         enum {
195                 monochrome,
196                 rgb,
197                 other,
198                 unknown,
199         } display_type;
200         bool active_off_supported;
201         bool suspend_supported;
202         bool standby_supported;
203
204         /* Color info FIXME: storage format */
205         unsigned short redx, redy;
206         unsigned short greenx, greeny;
207         unsigned short bluex, bluey;
208         unsigned short whitex, whitey;
209
210         /* Clock limits FIXME: storage format */
211         unsigned int min_vfreq, max_vfreq;
212         unsigned int min_hfreq, max_hfreq;
213         unsigned int pixel_clock;
214
215         /* White point indices FIXME: storage format */
216         unsigned int wpx1, wpy1;
217         unsigned int wpgamma1;
218         unsigned int wpx2, wpy2;
219         unsigned int wpgamma2;
220
221         /* Preferred mode (if any) */
222         struct drm_display_mode *preferred_mode;
223         char *raw_edid; /* if any */
224 };
225
226 struct drm_framebuffer {
227         struct drm_device *dev;
228         struct list_head head;
229         int id; /* idr assigned */
230         unsigned int pitch;
231         unsigned long offset;
232         unsigned int width;
233         unsigned int height;
234         /* depth can be 15 or 16 */
235         unsigned int depth;
236         int bits_per_pixel;
237         int flags;
238         struct drm_buffer_object *bo;
239         void *fbdev;
240         u32 pseudo_palette[17];
241         void *virtual_base;
242         struct list_head filp_head;
243 };
244 struct drm_crtc;
245 struct drm_output;
246
247 /**
248  * drm_crtc_funcs - control CRTCs for a given device
249  * @dpms: control display power levels
250  * @save: save CRTC state
251  * @resore: restore CRTC state
252  * @lock: lock the CRTC
253  * @unlock: unlock the CRTC
254  * @shadow_allocate: allocate shadow pixmap
255  * @shadow_create: create shadow pixmap for rotation support
256  * @shadow_destroy: free shadow pixmap
257  * @mode_fixup: fixup proposed mode
258  * @mode_set: set the desired mode on the CRTC
259  * @gamma_set: specify color ramp for CRTC
260  * @cleanup: cleanup driver private state prior to close
261  *
262  * The drm_crtc_funcs structure is the central CRTC management structure
263  * in the DRM.  Each CRTC controls one or more outputs (note that the name
264  * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
265  * outputs, not just CRTs).
266  *
267  * Each driver is responsible for filling out this structure at startup time,
268  * in addition to providing other modesetting features, like i2c and DDC
269  * bus accessors.
270  */
271 struct drm_crtc_funcs {
272         /*
273          * Control power levels on the CRTC.  If the mode passed in is
274          * unsupported, the provider must use the next lowest power level.
275          */
276         void (*dpms)(struct drm_crtc *crtc, int mode);
277
278         /* JJJ:  Are these needed? */
279         /* Save CRTC state */
280         void (*save)(struct drm_crtc *crtc); /* suspend? */
281         /* Restore CRTC state */
282         void (*restore)(struct drm_crtc *crtc); /* resume? */
283         bool (*lock)(struct drm_crtc *crtc);
284         void (*unlock)(struct drm_crtc *crtc);
285
286         void (*prepare)(struct drm_crtc *crtc);
287         void (*commit)(struct drm_crtc *crtc);
288
289         /* Provider can fixup or change mode timings before modeset occurs */
290         bool (*mode_fixup)(struct drm_crtc *crtc,
291                            struct drm_display_mode *mode,
292                            struct drm_display_mode *adjusted_mode);
293         /* Actually set the mode */
294         void (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
295                          struct drm_display_mode *adjusted_mode, int x, int y);
296         /* Set gamma on the CRTC */
297         void (*gamma_set)(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
298                           int regno);
299         /* Driver cleanup routine */
300         void (*cleanup)(struct drm_crtc *crtc);
301 };
302
303 /**
304  * drm_crtc - central CRTC control structure
305  * @enabled: is this CRTC enabled?
306  * @x: x position on screen
307  * @y: y position on screen
308  * @desired_mode: new desired mode
309  * @desired_x: desired x for desired_mode
310  * @desired_y: desired y for desired_mode
311  * @funcs: CRTC control functions
312  * @driver_private: arbitrary driver data
313  *
314  * Each CRTC may have one or more outputs associated with it.  This structure
315  * allows the CRTC to be controlled.
316  */
317 struct drm_crtc {
318         struct drm_device *dev;
319         struct list_head head;
320
321         int id; /* idr assigned */
322
323         /* framebuffer the output is currently bound to */
324         struct drm_framebuffer *fb;
325
326         bool enabled;
327
328         /* JJJ: are these needed? */
329         bool cursor_in_range;
330         bool cursor_shown;
331
332         struct drm_display_mode mode;
333
334         int x, y;
335         struct drm_display_mode *desired_mode;
336         int desired_x, desired_y;
337         const struct drm_crtc_funcs *funcs;
338         void *driver_private;
339
340         /* RRCrtcPtr randr_crtc? */
341 };
342
343 extern struct drm_crtc *drm_crtc_create(struct drm_device *dev,
344                                         const struct drm_crtc_funcs *funcs);
345
346 /**
347  * drm_output_funcs - control outputs on a given device
348  * @init: setup this output
349  * @dpms: set power state (see drm_crtc_funcs above)
350  * @save: save output state
351  * @restore: restore output state
352  * @mode_valid: is this mode valid on the given output?
353  * @mode_fixup: try to fixup proposed mode for this output
354  * @mode_set: set this mode
355  * @detect: is this output active?
356  * @get_modes: get mode list for this output
357  * @set_property: property for this output may need update
358  * @cleanup: output is going away, cleanup
359  *
360  * Each CRTC may have one or more outputs attached to it.  The functions
361  * below allow the core DRM code to control outputs, enumerate available modes,
362  * etc.
363  */
364 struct drm_output_funcs {
365         void (*init)(struct drm_output *output);
366         void (*dpms)(struct drm_output *output, int mode);
367         void (*save)(struct drm_output *output);
368         void (*restore)(struct drm_output *output);
369         int (*mode_valid)(struct drm_output *output,
370                           struct drm_display_mode *mode);
371         bool (*mode_fixup)(struct drm_output *output,
372                            struct drm_display_mode *mode,
373                            struct drm_display_mode *adjusted_mode);
374         void (*prepare)(struct drm_output *output);
375         void (*commit)(struct drm_output *output);
376         void (*mode_set)(struct drm_output *output,
377                          struct drm_display_mode *mode,
378                          struct drm_display_mode *adjusted_mode);
379         enum drm_output_status (*detect)(struct drm_output *output);
380         int (*get_modes)(struct drm_output *output);
381         /* JJJ: type checking for properties via property value type */
382         bool (*set_property)(struct drm_output *output, int prop, void *val);
383         void (*cleanup)(struct drm_output *output);
384 };
385
386 #define DRM_OUTPUT_MAX_UMODES 16
387 #define DRM_OUTPUT_LEN 32
388 /**
389  * drm_output - central DRM output control structure
390  * @crtc: CRTC this output is currently connected to, NULL if none
391  * @possible_crtcs: bitmap of CRTCS this output could be attached to
392  * @possible_clones: bitmap of possible outputs this output could clone
393  * @interlace_allowed: can this output handle interlaced modes?
394  * @doublescan_allowed: can this output handle doublescan?
395  * @available_modes: modes available on this output (from get_modes() + user)
396  * @initial_x: initial x position for this output
397  * @initial_y: initial y position for this output
398  * @status: output connected?
399  * @subpixel_order: for this output
400  * @mm_width: displayable width of output in mm
401  * @mm_height: displayable height of output in mm
402  * @name: name of output (should be one of a few standard names)
403  * @funcs: output control functions
404  * @driver_private: private driver data
405  *
406  * Each output may be connected to one or more CRTCs, or may be clonable by
407  * another output if they can share a CRTC.  Each output also has a specific
408  * position in the broader display (referred to as a 'screen' though it could
409  * span multiple monitors).
410  */
411 struct drm_output {
412         struct drm_device *dev;
413         struct list_head head;
414         struct drm_crtc *crtc;
415         int id; /* idr assigned */
416         unsigned long possible_crtcs;
417         unsigned long possible_clones;
418         bool interlace_allowed;
419         bool doublescan_allowed;
420         struct list_head modes; /* list of modes on this output */
421
422         /*
423           OptionInfoPtr options;
424           XF86ConfMonitorPtr conf_monitor;
425          */
426         int initial_x, initial_y;
427         enum drm_output_status status;
428
429         /* these are modes added by probing with DDC or the BIOS */
430         struct list_head probed_modes;
431         
432         /* xf86MonPtr MonInfo; */
433         enum subpixel_order subpixel_order;
434         int mm_width, mm_height;
435         struct drm_display_info *monitor_info; /* if any */
436         char name[DRM_OUTPUT_LEN];
437         const struct drm_output_funcs *funcs;
438         void *driver_private;
439
440         u32 user_mode_ids[DRM_OUTPUT_MAX_UMODES];
441
442 };
443
444 /**
445  * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
446  * @resize: adjust CRTCs as necessary for the proposed layout
447  *
448  * Currently only a resize hook is available.  DRM will call back into the
449  * driver with a new screen width and height.  If the driver can't support
450  * the proposed size, it can return false.  Otherwise it should adjust
451  * the CRTC<->output mappings as needed and update its view of the screen.
452  */
453 struct drm_mode_config_funcs {
454         bool (*resize)(struct drm_device *dev, int width, int height);
455 };
456
457 /**
458  * drm_mode_config - Mode configuration control structure
459  *
460  */
461 struct drm_mode_config {
462         struct mutex mutex; /* protects configuration and IDR */
463         struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, output, modes - just makes life easier */
464         /* this is limited to one for now */
465         int num_fb;
466         struct list_head fb_list;
467         int num_output;
468         struct list_head output_list;
469
470         /* int compat_output? */
471         int num_crtc;
472         struct list_head crtc_list;
473
474         struct list_head usermode_list;
475         int min_width, min_height;
476         int max_width, max_height;
477         /* DamagePtr rotationDamage? */
478         /* DGA stuff? */
479         struct drm_mode_config_funcs *funcs;
480         unsigned long fb_base;
481 };
482
483 struct drm_output *drm_output_create(struct drm_device *dev,
484                                      const struct drm_output_funcs *funcs,
485                                      const char *name);
486 extern void drm_output_destroy(struct drm_output *output);
487 extern bool drm_output_rename(struct drm_output *output, const char *name);
488 extern void drm_fb_release(struct file *filp);
489
490 extern int drm_add_edid_modes(struct drm_output *output,
491                         struct i2c_adapter *adapter);
492 extern void drm_mode_probed_add(struct drm_output *output, struct drm_display_mode *mode);
493 extern void drm_mode_remove(struct drm_output *output, struct drm_display_mode *mode);
494 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
495                                                    struct drm_display_mode *mode);
496 extern void drm_mode_debug_printmodeline(struct drm_device *dev,
497                                          struct drm_display_mode *mode);
498 extern void drm_mode_config_init(struct drm_device *dev);
499 extern void drm_mode_config_cleanup(struct drm_device *dev);
500 extern void drm_mode_set_name(struct drm_display_mode *mode);
501 extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
502 extern void drm_disable_unused_functions(struct drm_device *dev);
503
504 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
505 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
506 extern void drm_mode_list_concat(struct list_head *head,
507                                  struct list_head *new);
508 extern void drm_mode_validate_size(struct drm_device *dev,
509                                    struct list_head *mode_list,
510                                    int maxX, int maxY, int maxPitch);
511 extern void drm_mode_prune_invalid(struct drm_device *dev,
512                                    struct list_head *mode_list, bool verbose);
513 extern void drm_mode_sort(struct list_head *mode_list);
514 extern int drm_mode_vrefresh(struct drm_display_mode *mode);
515 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
516                                   int adjust_flags);
517 extern void drm_mode_output_list_update(struct drm_output *output);
518
519 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
520 extern bool drm_initial_config(struct drm_device *dev, bool cangrow);
521 extern void drm_framebuffer_set_object(struct drm_device *dev,
522                                        unsigned long handle);
523 extern struct drm_framebuffer *drm_framebuffer_create(struct drm_device *dev);
524 extern void drm_framebuffer_destroy(struct drm_framebuffer *fb);
525 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
526 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
527 extern bool drm_crtc_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
528                        int x, int y);
529
530 /* IOCTLs */
531 extern int drm_mode_getresources(struct drm_device *dev,
532                                  void *data, struct drm_file *file_priv);
533
534 extern int drm_mode_getcrtc(struct drm_device *dev,
535                             void *data, struct drm_file *file_priv);
536 extern int drm_mode_getoutput(struct drm_device *dev,
537                               void *data, struct drm_file *file_priv);
538 extern int drm_mode_setcrtc(struct drm_device *dev,
539                             void *data, struct drm_file *file_priv);
540 extern int drm_mode_addfb(struct drm_device *dev,
541                           void *data, struct drm_file *file_priv);
542 extern int drm_mode_rmfb(struct drm_device *dev,
543                          void *data, struct drm_file *file_priv);
544 extern int drm_mode_getfb(struct drm_device *dev,
545                           void *data, struct drm_file *file_priv);
546 extern int drm_mode_addmode(struct drm_device *dev,
547                             void *data, struct drm_file *file_priv);
548 extern int drm_mode_rmmode(struct drm_device *dev,
549                            void *data, struct drm_file *file_priv);
550 extern int drm_mode_attachmode(struct drm_device *dev,
551                                void *data, struct drm_file *file_priv);
552 extern int drm_mode_detachmode(struct drm_device *dev,
553                                void *data, struct drm_file *file_priv);
554
555 #endif /* __DRM_CRTC_H__ */
556