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>
18 struct drm_framebuffer;
21 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
22 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
23 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
24 #define DRM_MODE_OBJECT_MODE 0xdededede
25 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
26 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
27 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
29 struct drm_mode_object {
35 * Note on terminology: here, for brevity and convenience, we refer to connector
36 * control chips as 'CRTCs'. They can control any type of connector, VGA, LVDS,
37 * DVI, etc. And 'screen' refers to the whole of the visible display, which
38 * may span multiple monitors (and therefore multiple CRTC and connector
42 enum drm_mode_status {
43 MODE_OK = 0, /* Mode OK */
44 MODE_HSYNC, /* hsync out of range */
45 MODE_VSYNC, /* vsync out of range */
46 MODE_H_ILLEGAL, /* mode has illegal horizontal timings */
47 MODE_V_ILLEGAL, /* mode has illegal horizontal timings */
48 MODE_BAD_WIDTH, /* requires an unsupported linepitch */
49 MODE_NOMODE, /* no mode with a maching name */
50 MODE_NO_INTERLACE, /* interlaced mode not supported */
51 MODE_NO_DBLESCAN, /* doublescan mode not supported */
52 MODE_NO_VSCAN, /* multiscan mode not supported */
53 MODE_MEM, /* insufficient video memory */
54 MODE_VIRTUAL_X, /* mode width too large for specified virtual size */
55 MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */
56 MODE_MEM_VIRT, /* insufficient video memory given virtual size */
57 MODE_NOCLOCK, /* no fixed clock available */
58 MODE_CLOCK_HIGH, /* clock required is too high */
59 MODE_CLOCK_LOW, /* clock required is too low */
60 MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */
61 MODE_BAD_HVALUE, /* horizontal timing was out of range */
62 MODE_BAD_VVALUE, /* vertical timing was out of range */
63 MODE_BAD_VSCAN, /* VScan value out of range */
64 MODE_HSYNC_NARROW, /* horizontal sync too narrow */
65 MODE_HSYNC_WIDE, /* horizontal sync too wide */
66 MODE_HBLANK_NARROW, /* horizontal blanking too narrow */
67 MODE_HBLANK_WIDE, /* horizontal blanking too wide */
68 MODE_VSYNC_NARROW, /* vertical sync too narrow */
69 MODE_VSYNC_WIDE, /* vertical sync too wide */
70 MODE_VBLANK_NARROW, /* vertical blanking too narrow */
71 MODE_VBLANK_WIDE, /* vertical blanking too wide */
72 MODE_PANEL, /* exceeds panel dimensions */
73 MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
74 MODE_ONE_WIDTH, /* only one width is supported */
75 MODE_ONE_HEIGHT, /* only one height is supported */
76 MODE_ONE_SIZE, /* only one resolution is supported */
77 MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */
78 MODE_UNVERIFIED = -3, /* mode needs to reverified */
79 MODE_BAD = -2, /* unspecified reason */
80 MODE_ERROR = -1 /* error condition */
83 #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
86 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
87 .name = nm, .status = 0, .type = (t), .clock = (c), \
88 .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
89 .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
90 .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
91 .vscan = (vs), .flags = (f), .vrefresh = 0
93 #define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */
95 struct drm_display_mode {
97 struct list_head head;
98 struct drm_mode_object base;
100 char name[DRM_DISPLAY_MODE_LEN];
103 enum drm_mode_status status;
106 /* Proposed mode values */
120 /* Addressable image size (may be 0 for projectors, etc.) */
124 /* Actual mode we give to hw */
128 int crtc_hblank_start;
130 int crtc_hsync_start;
135 int crtc_vblank_start;
137 int crtc_vsync_start;
143 /* Driver private mode info */
152 enum drm_connector_status {
153 connector_status_connected = 1,
154 connector_status_disconnected = 2,
155 connector_status_unknown = 3,
158 enum subpixel_order {
160 SubPixelHorizontalRGB,
161 SubPixelHorizontalBGR,
169 * Describes a given display (e.g. CRT or flat panel) and its limitations.
171 struct drm_display_info {
172 char name[DRM_DISPLAY_INFO_LEN];
174 bool serration_vsync;
179 unsigned char video_level;
182 unsigned int width_mm;
183 unsigned int height_mm;
185 /* Display parameters */
186 unsigned char gamma; /* FIXME: storage format */
195 bool active_off_supported;
196 bool suspend_supported;
197 bool standby_supported;
199 /* Color info FIXME: storage format */
200 unsigned short redx, redy;
201 unsigned short greenx, greeny;
202 unsigned short bluex, bluey;
203 unsigned short whitex, whitey;
205 /* Clock limits FIXME: storage format */
206 unsigned int min_vfreq, max_vfreq;
207 unsigned int min_hfreq, max_hfreq;
208 unsigned int pixel_clock;
210 /* White point indices FIXME: storage format */
211 unsigned int wpx1, wpy1;
212 unsigned int wpgamma1;
213 unsigned int wpx2, wpy2;
214 unsigned int wpgamma2;
216 enum subpixel_order subpixel_order;
218 char *raw_edid; /* if any */
221 struct drm_framebuffer_funcs {
222 void (*destroy)(struct drm_framebuffer *framebuffer);
225 struct drm_framebuffer {
226 struct drm_device *dev;
227 struct list_head head;
228 struct drm_mode_object base;
229 const struct drm_framebuffer_funcs *funcs;
233 /* depth can be 15 or 16 */
238 u32 pseudo_palette[17];
239 struct list_head filp_head;
243 struct drm_property_blob {
244 struct drm_mode_object base;
245 struct list_head head;
250 struct drm_property_enum {
252 struct list_head head;
253 char name[DRM_PROP_NAME_LEN];
256 struct drm_property {
257 struct list_head head;
258 struct drm_mode_object base;
260 char name[DRM_PROP_NAME_LEN];
264 struct list_head enum_blob_list;
268 struct drm_connector;
272 * drm_crtc_funcs - control CRTCs for a given device
273 * @dpms: control display power levels
274 * @save: save CRTC state
275 * @resore: restore CRTC state
276 * @lock: lock the CRTC
277 * @unlock: unlock the CRTC
278 * @shadow_allocate: allocate shadow pixmap
279 * @shadow_create: create shadow pixmap for rotation support
280 * @shadow_destroy: free shadow pixmap
281 * @mode_fixup: fixup proposed mode
282 * @mode_set: set the desired mode on the CRTC
283 * @gamma_set: specify color ramp for CRTC
284 * @destroy: deinit and free object.
286 * The drm_crtc_funcs structure is the central CRTC management structure
287 * in the DRM. Each CRTC controls one or more connectors (note that the name
288 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
289 * connectors, not just CRTs).
291 * Each driver is responsible for filling out this structure at startup time,
292 * in addition to providing other modesetting features, like i2c and DDC
295 struct drm_crtc_funcs {
296 /* Save CRTC state */
297 void (*save)(struct drm_crtc *crtc); /* suspend? */
298 /* Restore CRTC state */
299 void (*restore)(struct drm_crtc *crtc); /* resume? */
301 /* cursor controls */
302 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
303 uint32_t handle, uint32_t width, uint32_t height);
304 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
306 /* Set gamma on the CRTC */
307 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
309 /* Object destroy routine */
310 void (*destroy)(struct drm_crtc *crtc);
312 int (*set_config)(struct drm_mode_set *set);
316 * drm_crtc - central CRTC control structure
317 * @enabled: is this CRTC enabled?
318 * @x: x position on screen
319 * @y: y position on screen
320 * @desired_mode: new desired mode
321 * @desired_x: desired x for desired_mode
322 * @desired_y: desired y for desired_mode
323 * @funcs: CRTC control functions
325 * Each CRTC may have one or more connectors associated with it. This structure
326 * allows the CRTC to be controlled.
329 struct drm_device *dev;
330 struct list_head head;
332 struct drm_mode_object base;
334 /* framebuffer the connector is currently bound to */
335 struct drm_framebuffer *fb;
339 struct drm_display_mode mode;
342 struct drm_display_mode *desired_mode;
343 int desired_x, desired_y;
344 const struct drm_crtc_funcs *funcs;
346 /* CRTC gamma size for reporting to userspace */
348 uint16_t *gamma_store;
350 /* if you are using the helper */
351 void *helper_private;
356 * drm_connector_funcs - control connectors on a given device
357 * @dpms: set power state (see drm_crtc_funcs above)
358 * @save: save connector state
359 * @restore: restore connector state
360 * @mode_valid: is this mode valid on the given connector?
361 * @mode_fixup: try to fixup proposed mode for this connector
362 * @mode_set: set this mode
363 * @detect: is this connector active?
364 * @get_modes: get mode list for this connector
365 * @set_property: property for this connector may need update
366 * @destroy: make object go away
368 * Each CRTC may have one or more connectors attached to it. The functions
369 * below allow the core DRM code to control connectors, enumerate available modes,
372 struct drm_connector_funcs {
373 void (*dpms)(struct drm_connector *connector, int mode);
374 void (*save)(struct drm_connector *connector);
375 void (*restore)(struct drm_connector *connector);
376 enum drm_connector_status (*detect)(struct drm_connector *connector);
377 void (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
378 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
380 void (*destroy)(struct drm_connector *connector);
383 struct drm_encoder_funcs {
384 void (*destroy)(struct drm_encoder *encoder);
387 #define DRM_CONNECTOR_MAX_UMODES 16
388 #define DRM_CONNECTOR_MAX_PROPERTY 16
389 #define DRM_CONNECTOR_LEN 32
390 #define DRM_CONNECTOR_MAX_ENCODER 2
393 * drm_encoder - central DRM encoder structure
396 struct drm_device *dev;
397 struct list_head head;
399 struct drm_mode_object base;
401 uint32_t possible_crtcs;
402 uint32_t possible_clones;
404 struct drm_crtc *crtc;
405 const struct drm_encoder_funcs *funcs;
406 void *helper_private;
410 * drm_connector - central DRM connector control structure
411 * @crtc: CRTC this connector is currently connected to, NULL if none
412 * @interlace_allowed: can this connector handle interlaced modes?
413 * @doublescan_allowed: can this connector handle doublescan?
414 * @available_modes: modes available on this connector (from get_modes() + user)
415 * @initial_x: initial x position for this connector
416 * @initial_y: initial y position for this connector
417 * @status: connector connected?
418 * @funcs: connector control functions
420 * Each connector may be connected to one or more CRTCs, or may be clonable by
421 * another connector if they can share a CRTC. Each connector also has a specific
422 * position in the broader display (referred to as a 'screen' though it could
423 * span multiple monitors).
425 struct drm_connector {
426 struct drm_device *dev;
428 struct device_attribute *attr;
429 struct list_head head;
431 struct drm_mode_object base;
434 int connector_type_id;
435 bool interlace_allowed;
436 bool doublescan_allowed;
437 struct list_head modes; /* list of modes on this connector */
439 int initial_x, initial_y;
440 enum drm_connector_status status;
442 /* these are modes added by probing with DDC or the BIOS */
443 struct list_head probed_modes;
445 struct drm_display_info display_info;
446 const struct drm_connector_funcs *funcs;
448 struct list_head user_modes;
449 struct drm_property_blob *edid_blob_ptr;
450 u32 property_ids[DRM_CONNECTOR_MAX_PROPERTY];
451 uint64_t property_values[DRM_CONNECTOR_MAX_PROPERTY];
453 void *helper_private;
455 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
456 uint32_t force_encoder_id;
457 struct drm_encoder *encoder; /* currently active encoder */
461 * struct drm_mode_set
463 * Represents a single crtc the connectors that it drives with what mode
464 * and from which framebuffer it scans out from.
466 * This is used to set modes.
468 struct drm_mode_set {
469 struct list_head head;
471 struct drm_framebuffer *fb;
472 struct drm_crtc *crtc;
473 struct drm_display_mode *mode;
478 struct drm_connector **connectors;
479 size_t num_connectors;
483 * struct drm_mode_config_funcs - configure CRTCs for a given screen layout
484 * @resize: adjust CRTCs as necessary for the proposed layout
486 * Currently only a resize hook is available. DRM will call back into the
487 * driver with a new screen width and height. If the driver can't support
488 * the proposed size, it can return false. Otherwise it should adjust
489 * the CRTC<->connector mappings as needed and update its view of the screen.
491 struct drm_mode_config_funcs {
492 int (*resize_fb)(struct drm_device *dev, struct drm_file *file_priv, struct drm_framebuffer *fb, struct drm_mode_fb_cmd *mode_cmd);
493 struct drm_framebuffer *(*fb_create)(struct drm_device *dev, struct drm_file *file_priv, struct drm_mode_fb_cmd *mode_cmd);
494 int (*fb_changed)(struct drm_device *dev);
497 struct drm_mode_group {
499 uint32_t num_encoders;
500 uint32_t num_connectors;
502 /* list of object IDs for this group */
507 * drm_mode_config - Mode configuration control structure
510 struct drm_mode_config {
511 struct mutex mutex; /* protects configuration and IDR */
512 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
513 /* this is limited to one for now */
515 struct list_head fb_list;
517 struct list_head connector_list;
519 struct list_head encoder_list;
522 struct list_head crtc_list;
524 struct list_head property_list;
526 /* in-kernel framebuffers - hung of filp_head in drm_framebuffer */
527 struct list_head fb_kernel_list;
529 int min_width, min_height;
530 int max_width, max_height;
531 struct drm_mode_config_funcs *funcs;
532 unsigned long fb_base;
534 /* pointers to standard properties */
535 struct list_head property_blob_list;
536 struct drm_property *edid_property;
537 struct drm_property *dpms_property;
539 /* DVI-I properties */
540 struct drm_property *dvi_i_subconnector_property;
541 struct drm_property *dvi_i_select_subconnector_property;
544 struct drm_property *tv_subconnector_property;
545 struct drm_property *tv_select_subconnector_property;
546 struct drm_property *tv_mode_property;
547 struct drm_property *tv_left_margin_property;
548 struct drm_property *tv_right_margin_property;
549 struct drm_property *tv_top_margin_property;
550 struct drm_property *tv_bottom_margin_property;
552 /* Optional properties */
553 struct drm_property *scaling_mode_property;
554 struct drm_property *dithering_mode_property;
557 uint32_t hotplug_counter;
560 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
561 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
562 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
563 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
564 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
565 #define obj_to_property(x) container_of(x, struct drm_property, base)
566 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
569 extern void drm_crtc_init(struct drm_device *dev,
570 struct drm_crtc *crtc,
571 const struct drm_crtc_funcs *funcs);
572 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
574 extern void drm_connector_init(struct drm_device *dev,
575 struct drm_connector *connector,
576 const struct drm_connector_funcs *funcs,
579 extern void drm_connector_cleanup(struct drm_connector *connector);
581 extern void drm_encoder_init(struct drm_device *dev,
582 struct drm_encoder *encoder,
583 const struct drm_encoder_funcs *funcs,
586 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
588 extern char *drm_get_connector_name(struct drm_connector *connector);
589 extern char *drm_get_dpms_name(int val);
590 extern char *drm_get_select_subconnector_name(int val);
591 extern char *drm_get_subconnector_name(int val);
592 extern void drm_fb_release(struct file *filp);
593 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
594 extern struct edid *drm_get_edid(struct drm_connector *connector,
595 struct i2c_adapter *adapter);
596 extern unsigned char *drm_do_probe_ddc_edid(struct i2c_adapter *adapter);
597 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
598 extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
599 extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode);
600 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
601 struct drm_display_mode *mode);
602 extern void drm_mode_debug_printmodeline(struct drm_display_mode *mode);
603 extern void drm_mode_config_init(struct drm_device *dev);
604 extern void drm_mode_config_cleanup(struct drm_device *dev);
605 extern void drm_mode_set_name(struct drm_display_mode *mode);
606 extern bool drm_mode_equal(struct drm_display_mode *mode1, struct drm_display_mode *mode2);
608 /* for us by fb module */
609 extern int drm_mode_attachmode_crtc(struct drm_device *dev,
610 struct drm_crtc *crtc,
611 struct drm_display_mode *mode);
612 extern int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode);
614 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev);
615 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
616 extern void drm_mode_list_concat(struct list_head *head,
617 struct list_head *new);
618 extern void drm_mode_validate_size(struct drm_device *dev,
619 struct list_head *mode_list,
620 int maxX, int maxY, int maxPitch);
621 extern void drm_mode_prune_invalid(struct drm_device *dev,
622 struct list_head *mode_list, bool verbose);
623 extern void drm_mode_sort(struct list_head *mode_list);
624 extern int drm_mode_vrefresh(struct drm_display_mode *mode);
625 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p,
627 extern void drm_mode_connector_list_update(struct drm_connector *connector);
628 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
630 extern int drm_connector_property_set_value(struct drm_connector *connector,
631 struct drm_property *property,
633 extern int drm_connector_property_get_value(struct drm_connector *connector,
634 struct drm_property *property,
636 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev);
637 extern void drm_framebuffer_set_object(struct drm_device *dev,
638 unsigned long handle);
639 extern struct drm_framebuffer *drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
640 const struct drm_framebuffer_funcs *funcs);
641 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
642 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc);
643 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb);
644 extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY);
645 extern bool drm_crtc_in_use(struct drm_crtc *crtc);
647 extern int drm_connector_attach_property(struct drm_connector *connector,
648 struct drm_property *property, uint64_t init_val);
649 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
650 const char *name, int num_values);
651 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
652 extern int drm_property_add_enum(struct drm_property *property, int index,
653 uint64_t value, const char *name);
654 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
655 extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
657 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
658 extern int drm_mode_create_dithering_property(struct drm_device *dev);
659 extern char *drm_get_encoder_name(struct drm_encoder *encoder);
661 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
662 struct drm_encoder *encoder);
663 extern void drm_mode_connector_detach_encoder(struct drm_connector *connector,
664 struct drm_encoder *encoder);
665 extern bool drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
667 extern void *drm_mode_object_find(struct drm_device *dev, uint32_t id, uint32_t type);
669 extern int drm_mode_getresources(struct drm_device *dev,
670 void *data, struct drm_file *file_priv);
672 extern int drm_mode_getcrtc(struct drm_device *dev,
673 void *data, struct drm_file *file_priv);
674 extern int drm_mode_getconnector(struct drm_device *dev,
675 void *data, struct drm_file *file_priv);
676 extern int drm_mode_setcrtc(struct drm_device *dev,
677 void *data, struct drm_file *file_priv);
678 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
679 void *data, struct drm_file *file_priv);
680 extern int drm_mode_addfb(struct drm_device *dev,
681 void *data, struct drm_file *file_priv);
682 extern int drm_mode_rmfb(struct drm_device *dev,
683 void *data, struct drm_file *file_priv);
684 extern int drm_mode_getfb(struct drm_device *dev,
685 void *data, struct drm_file *file_priv);
686 extern int drm_mode_addmode_ioctl(struct drm_device *dev,
687 void *data, struct drm_file *file_priv);
688 extern int drm_mode_rmmode_ioctl(struct drm_device *dev,
689 void *data, struct drm_file *file_priv);
690 extern int drm_mode_attachmode_ioctl(struct drm_device *dev,
691 void *data, struct drm_file *file_priv);
692 extern int drm_mode_detachmode_ioctl(struct drm_device *dev,
693 void *data, struct drm_file *file_priv);
695 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
696 void *data, struct drm_file *file_priv);
697 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
698 void *data, struct drm_file *file_priv);
699 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
700 void *data, struct drm_file *file_priv);
701 extern int drm_mode_hotplug_ioctl(struct drm_device *dev,
702 void *data, struct drm_file *file_priv);
703 extern int drm_mode_replacefb(struct drm_device *dev,
704 void *data, struct drm_file *file_priv);
705 extern int drm_mode_getencoder(struct drm_device *dev,
706 void *data, struct drm_file *file_priv);
707 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
708 void *data, struct drm_file *file_priv);
709 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
710 void *data, struct drm_file *file_priv);
711 #endif /* __DRM_CRTC_H__ */