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>
20 * Note on terminology: here, for brevity and convenience, we refer to output
21 * control chips as 'CRTCs'. They can control any type of output, VGA, LVDS,
22 * DVI, etc. And 'screen' refers to the whole of the visible display, which
23 * may span multiple monitors (and therefore multiple CRTC and output
27 enum drm_mode_status {
28 MODE_OK = 0, /* Mode OK */
29 MODE_HSYNC, /* hsync out of range */
30 MODE_VSYNC, /* vsync out of range */
31 MODE_H_ILLEGAL, /* mode has illegal horizontal timings */
32 MODE_V_ILLEGAL, /* mode has illegal horizontal timings */
33 MODE_BAD_WIDTH, /* requires an unsupported linepitch */
34 MODE_NOMODE, /* no mode with a maching name */
35 MODE_NO_INTERLACE, /* interlaced mode not supported */
36 MODE_NO_DBLESCAN, /* doublescan mode not supported */
37 MODE_NO_VSCAN, /* multiscan mode not supported */
38 MODE_MEM, /* insufficient video memory */
39 MODE_VIRTUAL_X, /* mode width too large for specified virtual size */
40 MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */
41 MODE_MEM_VIRT, /* insufficient video memory given virtual size */
42 MODE_NOCLOCK, /* no fixed clock available */
43 MODE_CLOCK_HIGH, /* clock required is too high */
44 MODE_CLOCK_LOW, /* clock required is too low */
45 MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */
46 MODE_BAD_HVALUE, /* horizontal timing was out of range */
47 MODE_BAD_VVALUE, /* vertical timing was out of range */
48 MODE_BAD_VSCAN, /* VScan value out of range */
49 MODE_HSYNC_NARROW, /* horizontal sync too narrow */
50 MODE_HSYNC_WIDE, /* horizontal sync too wide */
51 MODE_HBLANK_NARROW, /* horizontal blanking too narrow */
52 MODE_HBLANK_WIDE, /* horizontal blanking too wide */
53 MODE_VSYNC_NARROW, /* vertical sync too narrow */
54 MODE_VSYNC_WIDE, /* vertical sync too wide */
55 MODE_VBLANK_NARROW, /* vertical blanking too narrow */
56 MODE_VBLANK_WIDE, /* vertical blanking too wide */
57 MODE_PANEL, /* exceeds panel dimensions */
58 MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
59 MODE_ONE_WIDTH, /* only one width is supported */
60 MODE_ONE_HEIGHT, /* only one height is supported */
61 MODE_ONE_SIZE, /* only one resolution is supported */
62 MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */
63 MODE_UNVERIFIED = -3, /* mode needs to reverified */
64 MODE_BAD = -2, /* unspecified reason */
65 MODE_ERROR = -1 /* error condition */
68 #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
71 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
72 .name = nm, .status = 0, .type = (t), .clock = (c), \
73 .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
74 .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
75 .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
76 .vscan = (vs), .flags = (f), .vrefresh = 0
78 struct drm_display_mode {
80 struct list_head head;
81 char name[DRM_DISPLAY_MODE_LEN];
84 enum drm_mode_status status;
87 /* Proposed mode values */
101 /* Actual mode we give to hw */
105 int crtc_hblank_start;
107 int crtc_hsync_start;
112 int crtc_vblank_start;
114 int crtc_vsync_start;
120 /* Driver private mode info */
129 /* Video mode flags */
130 #define V_PHSYNC (1<<0)
131 #define V_NHSYNC (1<<1)
132 #define V_PVSYNC (1<<2)
133 #define V_NVSYNC (1<<3)
134 #define V_INTERLACE (1<<4)
135 #define V_DBLSCAN (1<<5)
136 #define V_CSYNC (1<<6)
137 #define V_PCSYNC (1<<7)
138 #define V_NCSYNC (1<<8)
139 #define V_HSKEW (1<<9) /* hskew provided */
140 #define V_BCAST (1<<10)
141 #define V_PIXMUX (1<<11)
142 #define V_DBLCLK (1<<12)
143 #define V_CLKDIV2 (1<<13)
145 #define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */
148 #define DPMSModeStandby 1
149 #define DPMSModeSuspend 2
150 #define DPMSModeOff 3
152 #define ConnectorUnknown 0
153 #define ConnectorVGA 1
154 #define ConnectorDVII 2
155 #define ConnectorDVID 3
156 #define ConnectorDVIA 4
157 #define ConnectorComposite 5
158 #define ConnectorSVIDEO 6
159 #define ConnectorLVDS 7
160 #define ConnectorComponent 8
161 #define Connector9PinDIN 9
162 #define ConnectorDisplayPort 10
163 #define ConnectorHDMIA 11
164 #define ConnectorHDMIB 12
166 enum drm_output_status {
167 output_status_connected = 1,
168 output_status_disconnected = 2,
169 output_status_unknown = 3,
172 enum subpixel_order {
174 SubPixelHorizontalRGB,
175 SubPixelHorizontalBGR,
182 * Describes a given display (e.g. CRT or flat panel) and its limitations.
184 struct drm_display_info {
185 char name[DRM_DISPLAY_INFO_LEN];
187 bool serration_vsync;
192 unsigned char video_level;
195 unsigned int width_mm;
196 unsigned int height_mm;
198 /* Display parameters */
199 unsigned char gamma; /* FIXME: storage format */
208 bool active_off_supported;
209 bool suspend_supported;
210 bool standby_supported;
212 /* Color info FIXME: storage format */
213 unsigned short redx, redy;
214 unsigned short greenx, greeny;
215 unsigned short bluex, bluey;
216 unsigned short whitex, whitey;
218 /* Clock limits FIXME: storage format */
219 unsigned int min_vfreq, max_vfreq;
220 unsigned int min_hfreq, max_hfreq;
221 unsigned int pixel_clock;
223 /* White point indices FIXME: storage format */
224 unsigned int wpx1, wpy1;
225 unsigned int wpgamma1;
226 unsigned int wpx2, wpy2;
227 unsigned int wpgamma2;
229 enum subpixel_order subpixel_order;
231 /* Preferred mode (if any) */
232 struct drm_display_mode *preferred_mode;
233 char *raw_edid; /* if any */
236 struct drm_framebuffer {
237 struct drm_device *dev;
238 struct list_head head;
239 int id; /* idr assigned */
243 /* depth can be 15 or 16 */
247 struct drm_buffer_object *bo;
249 u32 pseudo_palette[17];
250 struct drm_bo_kmap_obj kmap;
251 struct list_head filp_head;
254 struct drm_property_blob {
255 struct list_head head;
261 struct drm_property_enum {
263 struct list_head head;
264 char name[DRM_PROP_NAME_LEN];
267 struct drm_property {
268 struct list_head head;
269 int id; /* idr assigned */
271 char name[DRM_PROP_NAME_LEN];
275 struct list_head enum_blob_list;
283 * drm_crtc_funcs - control CRTCs for a given device
284 * @dpms: control display power levels
285 * @save: save CRTC state
286 * @resore: restore CRTC state
287 * @lock: lock the CRTC
288 * @unlock: unlock the CRTC
289 * @shadow_allocate: allocate shadow pixmap
290 * @shadow_create: create shadow pixmap for rotation support
291 * @shadow_destroy: free shadow pixmap
292 * @mode_fixup: fixup proposed mode
293 * @mode_set: set the desired mode on the CRTC
294 * @gamma_set: specify color ramp for CRTC
295 * @destroy: deinit and free object.
297 * The drm_crtc_funcs structure is the central CRTC management structure
298 * in the DRM. Each CRTC controls one or more outputs (note that the name
299 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
300 * outputs, not just CRTs).
302 * Each driver is responsible for filling out this structure at startup time,
303 * in addition to providing other modesetting features, like i2c and DDC
306 struct drm_crtc_funcs {
308 * Control power levels on the CRTC. If the mode passed in is
309 * unsupported, the provider must use the next lowest power level.
311 void (*dpms)(struct drm_crtc *crtc, int mode);
313 /* Save CRTC state */
314 void (*save)(struct drm_crtc *crtc); /* suspend? */
315 /* Restore CRTC state */
316 void (*restore)(struct drm_crtc *crtc); /* resume? */
318 /* cursor controls */
319 int (*cursor_set)(struct drm_crtc *crtc, struct drm_buffer_object *bo,
320 uint32_t width, uint32_t height);
321 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
323 /* Set gamma on the CRTC */
324 void (*gamma_set)(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
326 /* Object destroy routine */
327 void (*destroy)(struct drm_crtc *crtc);
329 int (*set_config)(struct drm_mode_set *set);
333 * drm_crtc - central CRTC control structure
334 * @enabled: is this CRTC enabled?
335 * @x: x position on screen
336 * @y: y position on screen
337 * @desired_mode: new desired mode
338 * @desired_x: desired x for desired_mode
339 * @desired_y: desired y for desired_mode
340 * @funcs: CRTC control functions
342 * Each CRTC may have one or more outputs associated with it. This structure
343 * allows the CRTC to be controlled.
346 struct drm_device *dev;
347 struct list_head head;
349 int id; /* idr assigned */
351 /* framebuffer the output is currently bound to */
352 struct drm_framebuffer *fb;
356 struct drm_display_mode mode;
359 struct drm_display_mode *desired_mode;
360 int desired_x, desired_y;
361 const struct drm_crtc_funcs *funcs;
363 /* if you are using the helper */
364 void *helper_private;
368 * drm_output_funcs - control outputs on a given device
369 * @init: setup this output
370 * @dpms: set power state (see drm_crtc_funcs above)
371 * @save: save output state
372 * @restore: restore output state
373 * @mode_valid: is this mode valid on the given output?
374 * @mode_fixup: try to fixup proposed mode for this output
375 * @mode_set: set this mode
376 * @detect: is this output active?
377 * @get_modes: get mode list for this output
378 * @set_property: property for this output may need update
379 * @destroy: make object go away
381 * Each CRTC may have one or more outputs attached to it. The functions
382 * below allow the core DRM code to control outputs, enumerate available modes,
385 struct drm_output_funcs {
386 void (*dpms)(struct drm_output *output, int mode);
387 void (*save)(struct drm_output *output);
388 void (*restore)(struct drm_output *output);
389 enum drm_output_status (*detect)(struct drm_output *output);
390 int (*get_modes)(struct drm_output *output);
391 bool (*set_property)(struct drm_output *output, struct drm_property *property,
393 void (*destroy)(struct drm_output *output);
394 int (*mode_valid)(struct drm_output *output,
395 struct drm_display_mode *mode);
399 struct drm_encoder_funcs {
400 void (*destroy)(struct drm_encoder *encoder);
403 #define DRM_OUTPUT_MAX_UMODES 16
404 #define DRM_OUTPUT_MAX_PROPERTY 16
405 #define DRM_OUTPUT_LEN 32
408 * drm_encoder - central DRM encoder structure
411 struct drm_device *dev;
412 struct list_head head;
416 uint32_t possible_crtcs;
417 uint32_t possible_clones;
419 const struct drm_encoder_funcs *funcs;
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 * @funcs: output control functions
435 * Each output may be connected to one or more CRTCs, or may be clonable by
436 * another output if they can share a CRTC. Each output also has a specific
437 * position in the broader display (referred to as a 'screen' though it could
438 * span multiple monitors).
441 struct drm_device *dev;
443 struct device_attribute *attr;
444 struct list_head head;
445 struct drm_crtc *crtc;
446 int id; /* idr assigned */
450 unsigned long possible_crtcs;
451 unsigned long possible_clones;
452 bool interlace_allowed;
453 bool doublescan_allowed;
454 struct list_head modes; /* list of modes on this output */
456 int initial_x, initial_y;
457 enum drm_output_status status;
459 /* these are modes added by probing with DDC or the BIOS */
460 struct list_head probed_modes;
462 struct drm_display_info display_info;
463 const struct drm_output_funcs *funcs;
465 struct list_head user_modes;
466 struct drm_property_blob *edid_blob_ptr;
467 u32 property_ids[DRM_OUTPUT_MAX_PROPERTY];
468 uint64_t property_values[DRM_OUTPUT_MAX_PROPERTY];
470 void *helper_private;
474 * struct drm_mode_set
476 * Represents a single crtc the outputs that it drives with what mode
477 * and from which framebuffer it scans out from.
479 * This is used to set modes.
483 struct drm_framebuffer *fb;
484 struct drm_crtc *crtc;
485 struct drm_display_mode *mode;
490 struct drm_output **outputs;
495 * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
496 * @resize: adjust CRTCs as necessary for the proposed layout
498 * Currently only a resize hook is available. DRM will call back into the
499 * driver with a new screen width and height. If the driver can't support
500 * the proposed size, it can return false. Otherwise it should adjust
501 * the CRTC<->output mappings as needed and update its view of the screen.
503 struct drm_mode_config_funcs {
504 bool (*resize_fb)(struct drm_device *dev, struct drm_framebuffer *fb);
508 * drm_mode_config - Mode configuration control structure
511 struct drm_mode_config {
512 struct mutex mutex; /* protects configuration and IDR */
513 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, output, modes - just makes life easier */
514 /* this is limited to one for now */
516 struct list_head fb_list;
518 struct list_head output_list;
520 struct list_head encoder_list;
523 struct list_head crtc_list;
525 struct list_head property_list;
527 int min_width, min_height;
528 int max_width, max_height;
529 struct drm_mode_config_funcs *funcs;
530 unsigned long fb_base;
532 /* pointers to standard properties */
533 struct list_head property_blob_list;
534 struct drm_property *edid_property;
535 struct drm_property *dpms_property;
536 struct drm_property *connector_type_property;
537 struct drm_property *connector_num_property;
540 struct drm_property *tv_mode_property;
541 struct drm_property *tv_left_margin_property;
542 struct drm_property *tv_right_margin_property;
543 struct drm_property *tv_top_margin_property;
544 struct drm_property *tv_bottom_margin_property;
547 uint32_t hotplug_counter;
551 extern void drm_crtc_init(struct drm_device *dev,
552 struct drm_crtc *crtc,
553 const struct drm_crtc_funcs *funcs);
554 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
556 void drm_output_init(struct drm_device *dev,
557 struct drm_output *output,
558 const struct drm_output_funcs *funcs,
561 void drm_output_cleanup(struct drm_output *output);
563 extern char *drm_get_output_name(struct drm_output *output);
564 extern char *drm_get_dpms_name(int val);
565 extern void drm_fb_release(struct file *filp);
567 extern struct edid *drm_get_edid(struct drm_output *output,
568 struct i2c_adapter *adapter);
569 extern int drm_add_edid_modes(struct drm_output *output, struct edid *edid);
570 extern void drm_mode_probed_add(struct drm_output *output, struct drm_display_mode *mode);
571 extern void drm_mode_remove(struct drm_output *output, struct drm_display_mode *mode);
572 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
573 struct drm_display_mode *mode);
574 extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
575 extern void drm_mode_config_init(struct drm_device *dev);
576 extern void drm_mode_config_cleanup(struct drm_device *dev);
577 extern void drm_mode_set_name(struct drm_display_mode *mode);
578 extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
579 extern void drm_disable_unused_functions(struct drm_device *dev);
581 /* for us by fb module */
582 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
583 struct drm_crtc *crtc,
584 struct drm_display_mode *mode);
585 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
587 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
588 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
589 extern void drm_mode_list_concat(struct list_head *head,
590 struct list_head *new);
591 extern void drm_mode_validate_size(struct drm_device *dev,
592 struct list_head *mode_list,
593 int maxX, int maxY, int maxPitch);
594 extern void drm_mode_prune_invalid(struct drm_device *dev,
595 struct list_head *mode_list, bool verbose);
596 extern void drm_mode_sort(struct list_head *mode_list);
597 extern int drm_mode_vrefresh(struct drm_display_mode *mode);
598 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
600 extern void drm_mode_output_list_update(struct drm_output *output);
601 extern int drm_mode_output_update_edid_property(struct drm_output *output,
603 extern int drm_output_property_set_value(struct drm_output *output,
604 struct drm_property *property,
606 extern int drm_output_property_get_value(struct drm_output *output,
607 struct drm_property *property,
609 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
610 extern void drm_framebuffer_set_object(struct drm_device *dev,
611 unsigned long handle);
612 extern struct drm_framebuffer *drm_framebuffer_create(struct drm_device *dev);
613 extern void drm_framebuffer_destroy(struct drm_framebuffer *fb);
614 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
615 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
616 extern void drm_crtc_probe_output_modes(struct drm_device *dev, int maxX, int maxY);
617 extern bool drm_crtc_in_use(struct drm_crtc *crtc);
619 extern int drm_output_attach_property(struct drm_output *output,
620 struct drm_property *property, uint64_t init_val);
621 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
622 const char *name, int num_values);
623 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
624 extern int drm_property_add_enum(struct drm_property *property, int index,
625 uint64_t value, const char *name);
626 extern bool drm_create_tv_properties(struct drm_device *dev, int num_formats,
630 extern int drm_mode_getresources(struct drm_device *dev,
631 void *data, struct drm_file *file_priv);
633 extern int drm_mode_getcrtc(struct drm_device *dev,
634 void *data, struct drm_file *file_priv);
635 extern int drm_mode_getoutput(struct drm_device *dev,
636 void *data, struct drm_file *file_priv);
637 extern int drm_mode_setcrtc(struct drm_device *dev,
638 void *data, struct drm_file *file_priv);
639 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
640 void *data, struct drm_file *file_priv);
641 extern int drm_mode_addfb(struct drm_device *dev,
642 void *data, struct drm_file *file_priv);
643 extern int drm_mode_rmfb(struct drm_device *dev,
644 void *data, struct drm_file *file_priv);
645 extern int drm_mode_getfb(struct drm_device *dev,
646 void *data, struct drm_file *file_priv);
647 extern int drm_mode_addmode_ioctl(struct drm_device *dev,
648 void *data, struct drm_file *file_priv);
649 extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
650 void *data, struct drm_file *file_priv);
651 extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
652 void *data, struct drm_file *file_priv);
653 extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
654 void *data, struct drm_file *file_priv);
656 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
657 void *data, struct drm_file *file_priv);
658 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
659 void *data, struct drm_file *file_priv);
660 extern int drm_mode_output_property_set_ioctl(struct drm_device *dev,
661 void *data, struct drm_file *file_priv);
662 extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
663 void *data, struct drm_file *file_priv);
664 extern int drm_mode_replacefb(struct drm_device *dev,
665 void *data, struct drm_file *file_priv);
666 #endif /* __DRM_CRTC_H__ */