2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
10 #include <linux/spinlock.h>
11 #include <linux/types.h>
12 #include <linux/idr.h>
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
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 */
67 #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
70 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
71 .name = nm, .status = 0, .type = (t), .clock = (c), \
72 .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
73 .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
74 .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
75 .vscan = (vs), .flags = (f), .vrefresh = 0
77 struct drm_display_mode {
79 struct list_head head;
80 char name[DRM_DISPLAY_MODE_LEN];
83 enum drm_mode_status status;
86 /* Proposed mode values */
100 /* Actual mode we give to hw */
104 int crtc_hblank_start;
106 int crtc_hsync_start;
111 int crtc_vblank_start;
113 int crtc_vsync_start;
119 /* Driver private mode info */
128 /* Video mode flags */
129 #define V_PHSYNC (1<<0)
130 #define V_NHSYNC (1<<1)
131 #define V_PVSYNC (1<<2)
132 #define V_NVSYNC (1<<3)
133 #define V_INTERLACE (1<<4)
134 #define V_DBLSCAN (1<<5)
135 #define V_CSYNC (1<<6)
136 #define V_PCSYNC (1<<7)
137 #define V_NCSYNC (1<<8)
138 #define V_HSKEW (1<<9) /* hskew provided */
139 #define V_BCAST (1<<10)
140 #define V_PIXMUX (1<<11)
141 #define V_DBLCLK (1<<12)
142 #define V_CLKDIV2 (1<<13)
144 #define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */
147 #define DPMSModeStandby 1
148 #define DPMSModeSuspend 2
149 #define DPMSModeOff 3
151 #define ConnectorUnknown 0
152 #define ConnectorVGA 1
153 #define ConnectorDVII 2
154 #define ConnectorDVID 3
155 #define ConnectorDVIA 4
156 #define ConnectorComposite 5
157 #define ConnectorSVIDEO 6
158 #define ConnectorLVDS 7
159 #define ConnectorComponent 8
160 #define Connector9PinDIN 9
161 #define ConnectorDisplayPort 10
162 #define ConnectorHDMIA 11
163 #define ConnectorHDMIB 12
165 enum drm_output_status {
166 output_status_connected = 1,
167 output_status_disconnected = 2,
168 output_status_unknown = 3,
171 enum subpixel_order {
173 SubPixelHorizontalRGB,
174 SubPixelHorizontalBGR,
181 * Describes a given display (e.g. CRT or flat panel) and its limitations.
183 struct drm_display_info {
184 char name[DRM_DISPLAY_INFO_LEN];
186 bool serration_vsync;
191 unsigned char video_level;
194 unsigned int width_mm;
195 unsigned int height_mm;
197 /* Display parameters */
198 unsigned char gamma; /* FIXME: storage format */
207 bool active_off_supported;
208 bool suspend_supported;
209 bool standby_supported;
211 /* Color info FIXME: storage format */
212 unsigned short redx, redy;
213 unsigned short greenx, greeny;
214 unsigned short bluex, bluey;
215 unsigned short whitex, whitey;
217 /* Clock limits FIXME: storage format */
218 unsigned int min_vfreq, max_vfreq;
219 unsigned int min_hfreq, max_hfreq;
220 unsigned int pixel_clock;
222 /* White point indices FIXME: storage format */
223 unsigned int wpx1, wpy1;
224 unsigned int wpgamma1;
225 unsigned int wpx2, wpy2;
226 unsigned int wpgamma2;
228 /* Preferred mode (if any) */
229 struct drm_display_mode *preferred_mode;
230 char *raw_edid; /* if any */
233 struct drm_framebuffer {
234 struct drm_device *dev;
235 struct list_head head;
236 int id; /* idr assigned */
238 unsigned long offset;
241 /* depth can be 15 or 16 */
245 struct drm_buffer_object *bo;
247 u32 pseudo_palette[17];
249 struct list_head filp_head;
252 struct drm_property_blob {
253 struct list_head head;
259 struct drm_property_enum {
261 struct list_head head;
262 unsigned char name[DRM_PROP_NAME_LEN];
265 struct drm_property {
266 struct list_head head;
267 int id; /* idr assigned */
269 char name[DRM_PROP_NAME_LEN];
273 struct list_head enum_blob_list;
280 * drm_crtc_funcs - control CRTCs for a given device
281 * @dpms: control display power levels
282 * @save: save CRTC state
283 * @resore: restore CRTC state
284 * @lock: lock the CRTC
285 * @unlock: unlock the CRTC
286 * @shadow_allocate: allocate shadow pixmap
287 * @shadow_create: create shadow pixmap for rotation support
288 * @shadow_destroy: free shadow pixmap
289 * @mode_fixup: fixup proposed mode
290 * @mode_set: set the desired mode on the CRTC
291 * @gamma_set: specify color ramp for CRTC
292 * @cleanup: cleanup driver private state prior to close
294 * The drm_crtc_funcs structure is the central CRTC management structure
295 * in the DRM. Each CRTC controls one or more outputs (note that the name
296 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
297 * outputs, not just CRTs).
299 * Each driver is responsible for filling out this structure at startup time,
300 * in addition to providing other modesetting features, like i2c and DDC
303 struct drm_crtc_funcs {
305 * Control power levels on the CRTC. If the mode passed in is
306 * unsupported, the provider must use the next lowest power level.
308 void (*dpms)(struct drm_crtc *crtc, int mode);
310 /* JJJ: Are these needed? */
311 /* Save CRTC state */
312 void (*save)(struct drm_crtc *crtc); /* suspend? */
313 /* Restore CRTC state */
314 void (*restore)(struct drm_crtc *crtc); /* resume? */
315 bool (*lock)(struct drm_crtc *crtc);
316 void (*unlock)(struct drm_crtc *crtc);
318 void (*prepare)(struct drm_crtc *crtc);
319 void (*commit)(struct drm_crtc *crtc);
321 /* Provider can fixup or change mode timings before modeset occurs */
322 bool (*mode_fixup)(struct drm_crtc *crtc,
323 struct drm_display_mode *mode,
324 struct drm_display_mode *adjusted_mode);
325 /* Actually set the mode */
326 void (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
327 struct drm_display_mode *adjusted_mode, int x, int y);
328 /* Set gamma on the CRTC */
329 void (*gamma_set)(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
331 /* Driver cleanup routine */
332 void (*cleanup)(struct drm_crtc *crtc);
336 * drm_crtc - central CRTC control structure
337 * @enabled: is this CRTC enabled?
338 * @x: x position on screen
339 * @y: y position on screen
340 * @desired_mode: new desired mode
341 * @desired_x: desired x for desired_mode
342 * @desired_y: desired y for desired_mode
343 * @funcs: CRTC control functions
344 * @driver_private: arbitrary driver data
346 * Each CRTC may have one or more outputs associated with it. This structure
347 * allows the CRTC to be controlled.
350 struct drm_device *dev;
351 struct list_head head;
353 int id; /* idr assigned */
355 /* framebuffer the output is currently bound to */
356 struct drm_framebuffer *fb;
360 /* JJJ: are these needed? */
361 bool cursor_in_range;
364 struct drm_display_mode mode;
367 struct drm_display_mode *desired_mode;
368 int desired_x, desired_y;
369 const struct drm_crtc_funcs *funcs;
370 void *driver_private;
372 /* RRCrtcPtr randr_crtc? */
375 extern struct drm_crtc *drm_crtc_create(struct drm_device *dev,
376 const struct drm_crtc_funcs *funcs);
379 * drm_output_funcs - control outputs on a given device
380 * @init: setup this output
381 * @dpms: set power state (see drm_crtc_funcs above)
382 * @save: save output state
383 * @restore: restore output state
384 * @mode_valid: is this mode valid on the given output?
385 * @mode_fixup: try to fixup proposed mode for this output
386 * @mode_set: set this mode
387 * @detect: is this output active?
388 * @get_modes: get mode list for this output
389 * @set_property: property for this output may need update
390 * @cleanup: output is going away, cleanup
392 * Each CRTC may have one or more outputs attached to it. The functions
393 * below allow the core DRM code to control outputs, enumerate available modes,
396 struct drm_output_funcs {
397 void (*init)(struct drm_output *output);
398 void (*dpms)(struct drm_output *output, int mode);
399 void (*save)(struct drm_output *output);
400 void (*restore)(struct drm_output *output);
401 int (*mode_valid)(struct drm_output *output,
402 struct drm_display_mode *mode);
403 bool (*mode_fixup)(struct drm_output *output,
404 struct drm_display_mode *mode,
405 struct drm_display_mode *adjusted_mode);
406 void (*prepare)(struct drm_output *output);
407 void (*commit)(struct drm_output *output);
408 void (*mode_set)(struct drm_output *output,
409 struct drm_display_mode *mode,
410 struct drm_display_mode *adjusted_mode);
411 enum drm_output_status (*detect)(struct drm_output *output);
412 int (*get_modes)(struct drm_output *output);
413 /* JJJ: type checking for properties via property value type */
414 bool (*set_property)(struct drm_output *output, struct drm_property *property,
416 void (*cleanup)(struct drm_output *output);
419 #define DRM_OUTPUT_MAX_UMODES 16
420 #define DRM_OUTPUT_MAX_PROPERTY 16
421 #define DRM_OUTPUT_LEN 32
423 * drm_output - central DRM output control structure
424 * @crtc: CRTC this output is currently connected to, NULL if none
425 * @possible_crtcs: bitmap of CRTCS this output could be attached to
426 * @possible_clones: bitmap of possible outputs this output could clone
427 * @interlace_allowed: can this output handle interlaced modes?
428 * @doublescan_allowed: can this output handle doublescan?
429 * @available_modes: modes available on this output (from get_modes() + user)
430 * @initial_x: initial x position for this output
431 * @initial_y: initial y position for this output
432 * @status: output connected?
433 * @subpixel_order: for this output
434 * @mm_width: displayable width of output in mm
435 * @mm_height: displayable height of output in mm
436 * @funcs: output control functions
437 * @driver_private: private driver data
439 * Each output may be connected to one or more CRTCs, or may be clonable by
440 * another output if they can share a CRTC. Each output also has a specific
441 * position in the broader display (referred to as a 'screen' though it could
442 * span multiple monitors).
445 struct drm_device *dev;
446 struct list_head head;
447 struct drm_crtc *crtc;
448 int id; /* idr assigned */
452 unsigned long possible_crtcs;
453 unsigned long possible_clones;
454 bool interlace_allowed;
455 bool doublescan_allowed;
456 struct list_head modes; /* list of modes on this output */
459 OptionInfoPtr options;
460 XF86ConfMonitorPtr conf_monitor;
462 int initial_x, initial_y;
463 enum drm_output_status status;
465 /* these are modes added by probing with DDC or the BIOS */
466 struct list_head probed_modes;
468 /* xf86MonPtr MonInfo; */
469 enum subpixel_order subpixel_order;
470 int mm_width, mm_height;
471 struct drm_display_info *monitor_info; /* if any */
472 const struct drm_output_funcs *funcs;
473 void *driver_private;
474 uint32_t make_shit_work;
475 struct list_head user_modes;
476 struct drm_property_blob *edid_blob_ptr;
477 u32 property_ids[DRM_OUTPUT_MAX_PROPERTY];
478 uint64_t property_values[DRM_OUTPUT_MAX_PROPERTY];
482 * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
483 * @resize: adjust CRTCs as necessary for the proposed layout
485 * Currently only a resize hook is available. DRM will call back into the
486 * driver with a new screen width and height. If the driver can't support
487 * the proposed size, it can return false. Otherwise it should adjust
488 * the CRTC<->output mappings as needed and update its view of the screen.
490 struct drm_mode_config_funcs {
491 bool (*resize)(struct drm_device *dev, int width, int height);
495 * drm_mode_config - Mode configuration control structure
498 struct drm_mode_config {
499 struct mutex mutex; /* protects configuration and IDR */
500 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, output, modes - just makes life easier */
501 /* this is limited to one for now */
503 struct list_head fb_list;
505 struct list_head output_list;
507 /* int compat_output? */
509 struct list_head crtc_list;
511 struct list_head property_list;
513 int min_width, min_height;
514 int max_width, max_height;
515 /* DamagePtr rotationDamage? */
517 struct drm_mode_config_funcs *funcs;
518 unsigned long fb_base;
520 /* pointers to standard properties */
521 struct list_head property_blob_list;
522 struct drm_property *edid_property;
523 struct drm_property *dpms_property;
524 struct drm_property *connector_type_property;
525 struct drm_property *connector_num_property;
528 struct drm_output *drm_output_create(struct drm_device *dev,
529 const struct drm_output_funcs *funcs,
532 extern char *drm_get_output_name(struct drm_output *output);
533 extern void drm_output_destroy(struct drm_output *output);
534 extern void drm_fb_release(struct file *filp);
536 extern struct edid *drm_get_edid(struct drm_output *output,
537 struct i2c_adapter *adapter);
538 extern int drm_add_edid_modes(struct drm_output *output, struct edid *edid);
539 extern void drm_mode_probed_add(struct drm_output *output, struct drm_display_mode *mode);
540 extern void drm_mode_remove(struct drm_output *output, struct drm_display_mode *mode);
541 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
542 struct drm_display_mode *mode);
543 extern void drm_mode_debug_printmodeline(struct drm_device *dev,
544 struct drm_display_mode *mode);
545 extern void drm_mode_config_init(struct drm_device *dev);
546 extern void drm_mode_config_cleanup(struct drm_device *dev);
547 extern void drm_mode_set_name(struct drm_display_mode *mode);
548 extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
549 extern void drm_disable_unused_functions(struct drm_device *dev);
551 /* for us by fb module */
552 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
553 struct drm_crtc *crtc,
554 struct drm_display_mode *mode);
555 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
557 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
558 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
559 extern void drm_mode_list_concat(struct list_head *head,
560 struct list_head *new);
561 extern void drm_mode_validate_size(struct drm_device *dev,
562 struct list_head *mode_list,
563 int maxX, int maxY, int maxPitch);
564 extern void drm_mode_prune_invalid(struct drm_device *dev,
565 struct list_head *mode_list, bool verbose);
566 extern void drm_mode_sort(struct list_head *mode_list);
567 extern int drm_mode_vrefresh(struct drm_display_mode *mode);
568 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
570 extern void drm_mode_output_list_update(struct drm_output *output);
571 extern int drm_mode_output_update_edid_property(struct drm_output *output, unsigned char *edid);
572 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
573 extern bool drm_initial_config(struct drm_device *dev, bool cangrow);
574 extern void drm_framebuffer_set_object(struct drm_device *dev,
575 unsigned long handle);
576 extern struct drm_framebuffer *drm_framebuffer_create(struct drm_device *dev);
577 extern void drm_framebuffer_destroy(struct drm_framebuffer *fb);
578 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
579 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
580 extern bool drm_crtc_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
582 extern int drm_hotplug_stage_two(struct drm_device *dev, struct drm_output *output);
584 extern int drm_output_attach_property(struct drm_output *output,
585 struct drm_property *property, uint64_t init_val);
586 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
587 const char *name, int num_values);
588 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
589 extern int drm_property_add_enum(struct drm_property *property, int index,
590 uint64_t value, const char *name);
593 extern int drm_mode_getresources(struct drm_device *dev,
594 void *data, struct drm_file *file_priv);
596 extern int drm_mode_getcrtc(struct drm_device *dev,
597 void *data, struct drm_file *file_priv);
598 extern int drm_mode_getoutput(struct drm_device *dev,
599 void *data, struct drm_file *file_priv);
600 extern int drm_mode_setcrtc(struct drm_device *dev,
601 void *data, struct drm_file *file_priv);
602 extern int drm_mode_addfb(struct drm_device *dev,
603 void *data, struct drm_file *file_priv);
604 extern int drm_mode_rmfb(struct drm_device *dev,
605 void *data, struct drm_file *file_priv);
606 extern int drm_mode_getfb(struct drm_device *dev,
607 void *data, struct drm_file *file_priv);
608 extern int drm_mode_addmode_ioctl(struct drm_device *dev,
609 void *data, struct drm_file *file_priv);
610 extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
611 void *data, struct drm_file *file_priv);
612 extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
613 void *data, struct drm_file *file_priv);
614 extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
615 void *data, struct drm_file *file_priv);
617 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
618 void *data, struct drm_file *file_priv);
619 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
620 void *data, struct drm_file *file_priv);
621 extern int drm_mode_output_property_set_ioctl(struct drm_device *dev,
622 void *data, struct drm_file *file_priv);
623 #endif /* __DRM_CRTC_H__ */