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 enum subpixel_order subpixel_order;
230 /* Preferred mode (if any) */
231 struct drm_display_mode *preferred_mode;
232 char *raw_edid; /* if any */
235 struct drm_framebuffer {
236 struct drm_device *dev;
237 struct list_head head;
238 int id; /* idr assigned */
242 /* depth can be 15 or 16 */
246 struct drm_buffer_object *bo;
248 u32 pseudo_palette[17];
249 struct drm_bo_kmap_obj kmap;
250 struct list_head filp_head;
253 struct drm_property_blob {
254 struct list_head head;
260 struct drm_property_enum {
262 struct list_head head;
263 char name[DRM_PROP_NAME_LEN];
266 struct drm_property {
267 struct list_head head;
268 int id; /* idr assigned */
270 char name[DRM_PROP_NAME_LEN];
274 struct list_head enum_blob_list;
281 * drm_crtc_funcs - control CRTCs for a given device
282 * @dpms: control display power levels
283 * @save: save CRTC state
284 * @resore: restore CRTC state
285 * @lock: lock the CRTC
286 * @unlock: unlock the CRTC
287 * @shadow_allocate: allocate shadow pixmap
288 * @shadow_create: create shadow pixmap for rotation support
289 * @shadow_destroy: free shadow pixmap
290 * @mode_fixup: fixup proposed mode
291 * @mode_set: set the desired mode on the CRTC
292 * @gamma_set: specify color ramp for CRTC
293 * @cleanup: cleanup driver private state prior to close
295 * The drm_crtc_funcs structure is the central CRTC management structure
296 * in the DRM. Each CRTC controls one or more outputs (note that the name
297 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
298 * outputs, not just CRTs).
300 * Each driver is responsible for filling out this structure at startup time,
301 * in addition to providing other modesetting features, like i2c and DDC
304 struct drm_crtc_funcs {
306 * Control power levels on the CRTC. If the mode passed in is
307 * unsupported, the provider must use the next lowest power level.
309 void (*dpms)(struct drm_crtc *crtc, int mode);
311 /* Save CRTC state */
312 void (*save)(struct drm_crtc *crtc); /* suspend? */
313 /* Restore CRTC state */
314 void (*restore)(struct drm_crtc *crtc); /* resume? */
316 void (*prepare)(struct drm_crtc *crtc);
317 void (*commit)(struct drm_crtc *crtc);
319 /* Provider can fixup or change mode timings before modeset occurs */
320 bool (*mode_fixup)(struct drm_crtc *crtc,
321 struct drm_display_mode *mode,
322 struct drm_display_mode *adjusted_mode);
323 /* Actually set the mode */
324 void (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
325 struct drm_display_mode *adjusted_mode, int x, int y);
327 /* Move the crtc on the current fb to the given position *optional* */
328 void (*mode_set_base)(struct drm_crtc *crtc, int x, int y);
330 /* cursor controls */
331 int (*cursor_set)(struct drm_crtc *crtc, struct drm_buffer_object *bo,
332 uint32_t width, uint32_t height);
333 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
335 /* Set gamma on the CRTC */
336 void (*gamma_set)(struct drm_crtc *crtc, u16 r, u16 g, u16 b,
338 /* Driver cleanup routine */
339 void (*cleanup)(struct drm_crtc *crtc);
343 * drm_crtc - central CRTC control structure
344 * @enabled: is this CRTC enabled?
345 * @x: x position on screen
346 * @y: y position on screen
347 * @desired_mode: new desired mode
348 * @desired_x: desired x for desired_mode
349 * @desired_y: desired y for desired_mode
350 * @funcs: CRTC control functions
351 * @driver_private: arbitrary driver data
353 * Each CRTC may have one or more outputs associated with it. This structure
354 * allows the CRTC to be controlled.
357 struct drm_device *dev;
358 struct list_head head;
360 int id; /* idr assigned */
362 /* framebuffer the output is currently bound to */
363 struct drm_framebuffer *fb;
367 struct drm_display_mode mode;
370 struct drm_display_mode *desired_mode;
371 int desired_x, desired_y;
372 const struct drm_crtc_funcs *funcs;
373 void *driver_private;
376 extern struct drm_crtc *drm_crtc_create(struct drm_device *dev,
377 const struct drm_crtc_funcs *funcs);
380 * drm_output_funcs - control outputs on a given device
381 * @init: setup this output
382 * @dpms: set power state (see drm_crtc_funcs above)
383 * @save: save output state
384 * @restore: restore output state
385 * @mode_valid: is this mode valid on the given output?
386 * @mode_fixup: try to fixup proposed mode for this output
387 * @mode_set: set this mode
388 * @detect: is this output active?
389 * @get_modes: get mode list for this output
390 * @set_property: property for this output may need update
391 * @cleanup: output is going away, cleanup
393 * Each CRTC may have one or more outputs attached to it. The functions
394 * below allow the core DRM code to control outputs, enumerate available modes,
397 struct drm_output_funcs {
398 void (*init)(struct drm_output *output);
399 void (*dpms)(struct drm_output *output, int mode);
400 void (*save)(struct drm_output *output);
401 void (*restore)(struct drm_output *output);
402 int (*mode_valid)(struct drm_output *output,
403 struct drm_display_mode *mode);
404 bool (*mode_fixup)(struct drm_output *output,
405 struct drm_display_mode *mode,
406 struct drm_display_mode *adjusted_mode);
407 void (*prepare)(struct drm_output *output);
408 void (*commit)(struct drm_output *output);
409 void (*mode_set)(struct drm_output *output,
410 struct drm_display_mode *mode,
411 struct drm_display_mode *adjusted_mode);
412 enum drm_output_status (*detect)(struct drm_output *output);
413 int (*get_modes)(struct drm_output *output);
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 * @funcs: output control functions
434 * @driver_private: private driver data
436 * Each output may be connected to one or more CRTCs, or may be clonable by
437 * another output if they can share a CRTC. Each output also has a specific
438 * position in the broader display (referred to as a 'screen' though it could
439 * span multiple monitors).
442 struct drm_device *dev;
444 struct device_attribute *attr;
445 struct list_head head;
446 struct drm_crtc *crtc;
447 int id; /* idr assigned */
451 unsigned long possible_crtcs;
452 unsigned long possible_clones;
453 bool interlace_allowed;
454 bool doublescan_allowed;
455 struct list_head modes; /* list of modes on this output */
457 int initial_x, initial_y;
458 enum drm_output_status status;
460 /* these are modes added by probing with DDC or the BIOS */
461 struct list_head probed_modes;
463 struct drm_display_info display_info;
464 const struct drm_output_funcs *funcs;
465 void *driver_private;
467 struct list_head user_modes;
468 struct drm_property_blob *edid_blob_ptr;
469 u32 property_ids[DRM_OUTPUT_MAX_PROPERTY];
470 uint64_t property_values[DRM_OUTPUT_MAX_PROPERTY];
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.
481 struct drm_framebuffer *fb;
482 struct drm_crtc *crtc;
484 struct drm_output **outputs;
489 * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
490 * @resize: adjust CRTCs as necessary for the proposed layout
492 * Currently only a resize hook is available. DRM will call back into the
493 * driver with a new screen width and height. If the driver can't support
494 * the proposed size, it can return false. Otherwise it should adjust
495 * the CRTC<->output mappings as needed and update its view of the screen.
497 struct drm_mode_config_funcs {
498 bool (*resize)(struct drm_device *dev, int width, int height);
502 * drm_mode_config - Mode configuration control structure
505 struct drm_mode_config {
506 struct mutex mutex; /* protects configuration and IDR */
507 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, output, modes - just makes life easier */
508 /* this is limited to one for now */
510 struct list_head fb_list;
512 struct list_head output_list;
515 struct list_head crtc_list;
517 struct list_head property_list;
519 int min_width, min_height;
520 int max_width, max_height;
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_property *tv_mode_property;
533 struct drm_property *tv_left_margin_property;
534 struct drm_property *tv_right_margin_property;
535 struct drm_property *tv_top_margin_property;
536 struct drm_property *tv_bottom_margin_property;
539 uint32_t hotplug_counter;
542 struct drm_output *drm_output_create(struct drm_device *dev,
543 const struct drm_output_funcs *funcs,
546 extern char *drm_get_output_name(struct drm_output *output);
547 extern char *drm_get_dpms_name(int val);
548 extern void drm_output_destroy(struct drm_output *output);
549 extern void drm_fb_release(struct file *filp);
551 extern struct edid *drm_get_edid(struct drm_output *output,
552 struct i2c_adapter *adapter);
553 extern int drm_add_edid_modes(struct drm_output *output, struct edid *edid);
554 extern void drm_mode_probed_add(struct drm_output *output, struct drm_display_mode *mode);
555 extern void drm_mode_remove(struct drm_output *output, struct drm_display_mode *mode);
556 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
557 struct drm_display_mode *mode);
558 extern void drm_mode_debug_printmodeline(struct drm_device *dev,
559 struct drm_display_mode *mode);
560 extern void drm_mode_config_init(struct drm_device *dev);
561 extern void drm_mode_config_cleanup(struct drm_device *dev);
562 extern void drm_mode_set_name(struct drm_display_mode *mode);
563 extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
564 extern void drm_disable_unused_functions(struct drm_device *dev);
566 /* for us by fb module */
567 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
568 struct drm_crtc *crtc,
569 struct drm_display_mode *mode);
570 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
572 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
573 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
574 extern void drm_mode_list_concat(struct list_head *head,
575 struct list_head *new);
576 extern void drm_mode_validate_size(struct drm_device *dev,
577 struct list_head *mode_list,
578 int maxX, int maxY, int maxPitch);
579 extern void drm_mode_prune_invalid(struct drm_device *dev,
580 struct list_head *mode_list, bool verbose);
581 extern void drm_mode_sort(struct list_head *mode_list);
582 extern int drm_mode_vrefresh(struct drm_display_mode *mode);
583 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
585 extern void drm_mode_output_list_update(struct drm_output *output);
586 extern int drm_mode_output_update_edid_property(struct drm_output *output,
588 extern int drm_output_property_set_value(struct drm_output *output,
589 struct drm_property *property,
591 extern int drm_output_property_get_value(struct drm_output *output,
592 struct drm_property *property,
594 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
595 extern bool drm_initial_config(struct drm_device *dev, bool cangrow);
596 extern void drm_framebuffer_set_object(struct drm_device *dev,
597 unsigned long handle);
598 extern struct drm_framebuffer *drm_framebuffer_create(struct drm_device *dev);
599 extern void drm_framebuffer_destroy(struct drm_framebuffer *fb);
600 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
601 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
602 extern bool drm_crtc_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
604 extern bool drm_crtc_in_use(struct drm_crtc *crtc);
605 extern int drm_hotplug_stage_two(struct drm_device *dev, struct drm_output *output, bool connected);
607 extern int drm_output_attach_property(struct drm_output *output,
608 struct drm_property *property, uint64_t init_val);
609 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
610 const char *name, int num_values);
611 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
612 extern int drm_property_add_enum(struct drm_property *property, int index,
613 uint64_t value, const char *name);
614 extern bool drm_create_tv_properties(struct drm_device *dev, int num_formats,
618 extern int drm_mode_getresources(struct drm_device *dev,
619 void *data, struct drm_file *file_priv);
621 extern int drm_mode_getcrtc(struct drm_device *dev,
622 void *data, struct drm_file *file_priv);
623 extern int drm_mode_getoutput(struct drm_device *dev,
624 void *data, struct drm_file *file_priv);
625 extern int drm_mode_setcrtc(struct drm_device *dev,
626 void *data, struct drm_file *file_priv);
627 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
628 void *data, struct drm_file *file_priv);
629 extern int drm_mode_addfb(struct drm_device *dev,
630 void *data, struct drm_file *file_priv);
631 extern int drm_mode_rmfb(struct drm_device *dev,
632 void *data, struct drm_file *file_priv);
633 extern int drm_mode_getfb(struct drm_device *dev,
634 void *data, struct drm_file *file_priv);
635 extern int drm_mode_addmode_ioctl(struct drm_device *dev,
636 void *data, struct drm_file *file_priv);
637 extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
638 void *data, struct drm_file *file_priv);
639 extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
640 void *data, struct drm_file *file_priv);
641 extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
642 void *data, struct drm_file *file_priv);
644 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
645 void *data, struct drm_file *file_priv);
646 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
647 void *data, struct drm_file *file_priv);
648 extern int drm_mode_output_property_set_ioctl(struct drm_device *dev,
649 void *data, struct drm_file *file_priv);
650 extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
651 void *data, struct drm_file *file_priv);
653 #endif /* __DRM_CRTC_H__ */