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);
329 /* Move the crtc on the current fb to the given position *optional* */
330 void (*mode_set_base)(struct drm_crtc *crtc, int x, int y);
332 /* Set gamma on the CRTC */
333 void (*gamma_set)(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
335 /* Driver cleanup routine */
336 void (*cleanup)(struct drm_crtc *crtc);
340 * drm_crtc - central CRTC control structure
341 * @enabled: is this CRTC enabled?
342 * @x: x position on screen
343 * @y: y position on screen
344 * @desired_mode: new desired mode
345 * @desired_x: desired x for desired_mode
346 * @desired_y: desired y for desired_mode
347 * @funcs: CRTC control functions
348 * @driver_private: arbitrary driver data
350 * Each CRTC may have one or more outputs associated with it. This structure
351 * allows the CRTC to be controlled.
354 struct drm_device *dev;
355 struct list_head head;
357 int id; /* idr assigned */
359 /* framebuffer the output is currently bound to */
360 struct drm_framebuffer *fb;
364 /* JJJ: are these needed? */
365 bool cursor_in_range;
368 struct drm_display_mode mode;
371 struct drm_display_mode *desired_mode;
372 int desired_x, desired_y;
373 const struct drm_crtc_funcs *funcs;
374 void *driver_private;
376 /* RRCrtcPtr randr_crtc? */
379 extern struct drm_crtc *drm_crtc_create(struct drm_device *dev,
380 const struct drm_crtc_funcs *funcs);
383 * drm_output_funcs - control outputs on a given device
384 * @init: setup this output
385 * @dpms: set power state (see drm_crtc_funcs above)
386 * @save: save output state
387 * @restore: restore output state
388 * @mode_valid: is this mode valid on the given output?
389 * @mode_fixup: try to fixup proposed mode for this output
390 * @mode_set: set this mode
391 * @detect: is this output active?
392 * @get_modes: get mode list for this output
393 * @set_property: property for this output may need update
394 * @cleanup: output is going away, cleanup
396 * Each CRTC may have one or more outputs attached to it. The functions
397 * below allow the core DRM code to control outputs, enumerate available modes,
400 struct drm_output_funcs {
401 void (*init)(struct drm_output *output);
402 void (*dpms)(struct drm_output *output, int mode);
403 void (*save)(struct drm_output *output);
404 void (*restore)(struct drm_output *output);
405 int (*mode_valid)(struct drm_output *output,
406 struct drm_display_mode *mode);
407 bool (*mode_fixup)(struct drm_output *output,
408 struct drm_display_mode *mode,
409 struct drm_display_mode *adjusted_mode);
410 void (*prepare)(struct drm_output *output);
411 void (*commit)(struct drm_output *output);
412 void (*mode_set)(struct drm_output *output,
413 struct drm_display_mode *mode,
414 struct drm_display_mode *adjusted_mode);
415 enum drm_output_status (*detect)(struct drm_output *output);
416 int (*get_modes)(struct drm_output *output);
417 /* JJJ: type checking for properties via property value type */
418 bool (*set_property)(struct drm_output *output, struct drm_property *property,
420 void (*cleanup)(struct drm_output *output);
423 #define DRM_OUTPUT_MAX_UMODES 16
424 #define DRM_OUTPUT_MAX_PROPERTY 16
425 #define DRM_OUTPUT_LEN 32
427 * drm_output - central DRM output control structure
428 * @crtc: CRTC this output is currently connected to, NULL if none
429 * @possible_crtcs: bitmap of CRTCS this output could be attached to
430 * @possible_clones: bitmap of possible outputs this output could clone
431 * @interlace_allowed: can this output handle interlaced modes?
432 * @doublescan_allowed: can this output handle doublescan?
433 * @available_modes: modes available on this output (from get_modes() + user)
434 * @initial_x: initial x position for this output
435 * @initial_y: initial y position for this output
436 * @status: output connected?
437 * @subpixel_order: for this output
438 * @mm_width: displayable width of output in mm
439 * @mm_height: displayable height of output in mm
440 * @funcs: output control functions
441 * @driver_private: private driver data
443 * Each output may be connected to one or more CRTCs, or may be clonable by
444 * another output if they can share a CRTC. Each output also has a specific
445 * position in the broader display (referred to as a 'screen' though it could
446 * span multiple monitors).
449 struct drm_device *dev;
450 struct list_head head;
451 struct drm_crtc *crtc;
452 int id; /* idr assigned */
456 unsigned long possible_crtcs;
457 unsigned long possible_clones;
458 bool interlace_allowed;
459 bool doublescan_allowed;
460 struct list_head modes; /* list of modes on this output */
463 OptionInfoPtr options;
464 XF86ConfMonitorPtr conf_monitor;
466 int initial_x, initial_y;
467 enum drm_output_status status;
469 /* these are modes added by probing with DDC or the BIOS */
470 struct list_head probed_modes;
472 /* xf86MonPtr MonInfo; */
473 enum subpixel_order subpixel_order;
474 int mm_width, mm_height;
475 struct drm_display_info *monitor_info; /* if any */
476 const struct drm_output_funcs *funcs;
477 void *driver_private;
478 uint32_t make_shit_work;
479 struct list_head user_modes;
480 struct drm_property_blob *edid_blob_ptr;
481 u32 property_ids[DRM_OUTPUT_MAX_PROPERTY];
482 uint64_t property_values[DRM_OUTPUT_MAX_PROPERTY];
486 * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
487 * @resize: adjust CRTCs as necessary for the proposed layout
489 * Currently only a resize hook is available. DRM will call back into the
490 * driver with a new screen width and height. If the driver can't support
491 * the proposed size, it can return false. Otherwise it should adjust
492 * the CRTC<->output mappings as needed and update its view of the screen.
494 struct drm_mode_config_funcs {
495 bool (*resize)(struct drm_device *dev, int width, int height);
499 * drm_mode_config - Mode configuration control structure
502 struct drm_mode_config {
503 struct mutex mutex; /* protects configuration and IDR */
504 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, output, modes - just makes life easier */
505 /* this is limited to one for now */
507 struct list_head fb_list;
509 struct list_head output_list;
511 /* int compat_output? */
513 struct list_head crtc_list;
515 struct list_head property_list;
517 int min_width, min_height;
518 int max_width, max_height;
519 /* DamagePtr rotationDamage? */
521 struct drm_mode_config_funcs *funcs;
522 unsigned long fb_base;
524 /* pointers to standard properties */
525 struct list_head property_blob_list;
526 struct drm_property *edid_property;
527 struct drm_property *dpms_property;
528 struct drm_property *connector_type_property;
529 struct drm_property *connector_num_property;
532 struct drm_output *drm_output_create(struct drm_device *dev,
533 const struct drm_output_funcs *funcs,
536 extern char *drm_get_output_name(struct drm_output *output);
537 extern void drm_output_destroy(struct drm_output *output);
538 extern void drm_fb_release(struct file *filp);
540 extern struct edid *drm_get_edid(struct drm_output *output,
541 struct i2c_adapter *adapter);
542 extern int drm_add_edid_modes(struct drm_output *output, struct edid *edid);
543 extern void drm_mode_probed_add(struct drm_output *output, struct drm_display_mode *mode);
544 extern void drm_mode_remove(struct drm_output *output, struct drm_display_mode *mode);
545 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
546 struct drm_display_mode *mode);
547 extern void drm_mode_debug_printmodeline(struct drm_device *dev,
548 struct drm_display_mode *mode);
549 extern void drm_mode_config_init(struct drm_device *dev);
550 extern void drm_mode_config_cleanup(struct drm_device *dev);
551 extern void drm_mode_set_name(struct drm_display_mode *mode);
552 extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
553 extern void drm_disable_unused_functions(struct drm_device *dev);
555 /* for us by fb module */
556 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
557 struct drm_crtc *crtc,
558 struct drm_display_mode *mode);
559 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
561 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
562 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
563 extern void drm_mode_list_concat(struct list_head *head,
564 struct list_head *new);
565 extern void drm_mode_validate_size(struct drm_device *dev,
566 struct list_head *mode_list,
567 int maxX, int maxY, int maxPitch);
568 extern void drm_mode_prune_invalid(struct drm_device *dev,
569 struct list_head *mode_list, bool verbose);
570 extern void drm_mode_sort(struct list_head *mode_list);
571 extern int drm_mode_vrefresh(struct drm_display_mode *mode);
572 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
574 extern void drm_mode_output_list_update(struct drm_output *output);
575 extern int drm_mode_output_update_edid_property(struct drm_output *output, unsigned char *edid);
576 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
577 extern bool drm_initial_config(struct drm_device *dev, bool cangrow);
578 extern void drm_framebuffer_set_object(struct drm_device *dev,
579 unsigned long handle);
580 extern struct drm_framebuffer *drm_framebuffer_create(struct drm_device *dev);
581 extern void drm_framebuffer_destroy(struct drm_framebuffer *fb);
582 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
583 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
584 extern bool drm_crtc_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
586 extern int drm_hotplug_stage_two(struct drm_device *dev, struct drm_output *output);
588 extern int drm_output_attach_property(struct drm_output *output,
589 struct drm_property *property, uint64_t init_val);
590 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
591 const char *name, int num_values);
592 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
593 extern int drm_property_add_enum(struct drm_property *property, int index,
594 uint64_t value, const char *name);
597 extern int drm_mode_getresources(struct drm_device *dev,
598 void *data, struct drm_file *file_priv);
600 extern int drm_mode_getcrtc(struct drm_device *dev,
601 void *data, struct drm_file *file_priv);
602 extern int drm_mode_getoutput(struct drm_device *dev,
603 void *data, struct drm_file *file_priv);
604 extern int drm_mode_setcrtc(struct drm_device *dev,
605 void *data, struct drm_file *file_priv);
606 extern int drm_mode_addfb(struct drm_device *dev,
607 void *data, struct drm_file *file_priv);
608 extern int drm_mode_rmfb(struct drm_device *dev,
609 void *data, struct drm_file *file_priv);
610 extern int drm_mode_getfb(struct drm_device *dev,
611 void *data, struct drm_file *file_priv);
612 extern int drm_mode_addmode_ioctl(struct drm_device *dev,
613 void *data, struct drm_file *file_priv);
614 extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
615 void *data, struct drm_file *file_priv);
616 extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
617 void *data, struct drm_file *file_priv);
618 extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
619 void *data, struct drm_file *file_priv);
621 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
622 void *data, struct drm_file *file_priv);
623 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
624 void *data, struct drm_file *file_priv);
625 extern int drm_mode_output_property_set_ioctl(struct drm_device *dev,
626 void *data, struct drm_file *file_priv);
627 #endif /* __DRM_CRTC_H__ */