1 /* BEGIN CSTYLED */ 2 3 /* 4 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 5 */ 6 7 /* 8 * Copyright © 2006 Keith Packard 9 * Copyright © 2007-2008 Dave Airlie 10 * Copyright (c) 2007-2008, 2013, Intel Corporation 11 * Jesse Barnes <jesse.barnes@intel.com> 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining a 14 * copy of this software and associated documentation files (the "Software"), 15 * to deal in the Software without restriction, including without limitation 16 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 * and/or sell copies of the Software, and to permit persons to whom the 18 * Software is furnished to do so, subject to the following conditions: 19 * 20 * The above copyright notice and this permission notice shall be included in 21 * all copies or substantial portions of the Software. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 27 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 28 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 29 * OTHER DEALINGS IN THE SOFTWARE. 30 */ 31 #ifndef __DRM_CRTC_H__ 32 #define __DRM_CRTC_H__ 33 34 #include <sys/ksynch.h> 35 #include "drm.h" 36 #include "drmP.h" 37 #include "drm_sun_idr.h" 38 #include "drm_sun_i2c.h" 39 #include "drm_fourcc.h" 40 41 struct drm_device; 42 struct drm_mode_set; 43 struct drm_framebuffer; 44 struct drm_object_properties; 45 46 47 #define DRM_MODE_OBJECT_CRTC 0xcccccccc 48 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0 49 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0 50 #define DRM_MODE_OBJECT_MODE 0xdededede 51 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0 52 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb 53 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb 54 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee 55 56 struct drm_mode_object { 57 uint32_t id; 58 uint32_t type; 59 struct drm_object_properties *properties; 60 }; 61 62 #define DRM_OBJECT_MAX_PROPERTY 24 63 struct drm_object_properties { 64 int count; 65 uint32_t ids[DRM_OBJECT_MAX_PROPERTY]; 66 uint64_t values[DRM_OBJECT_MAX_PROPERTY]; 67 }; 68 69 /* 70 * Note on terminology: here, for brevity and convenience, we refer to connector 71 * control chips as 'CRTCs'. They can control any type of connector, VGA, LVDS, 72 * DVI, etc. And 'screen' refers to the whole of the visible display, which 73 * may span multiple monitors (and therefore multiple CRTC and connector 74 * structures). 75 */ 76 77 enum drm_mode_status { 78 MODE_OK = 0, /* Mode OK */ 79 MODE_HSYNC, /* hsync out of range */ 80 MODE_VSYNC, /* vsync out of range */ 81 MODE_H_ILLEGAL, /* mode has illegal horizontal timings */ 82 MODE_V_ILLEGAL, /* mode has illegal horizontal timings */ 83 MODE_BAD_WIDTH, /* requires an unsupported linepitch */ 84 MODE_NOMODE, /* no mode with a maching name */ 85 MODE_NO_INTERLACE, /* interlaced mode not supported */ 86 MODE_NO_DBLESCAN, /* doublescan mode not supported */ 87 MODE_NO_VSCAN, /* multiscan mode not supported */ 88 MODE_MEM, /* insufficient video memory */ 89 MODE_VIRTUAL_X, /* mode width too large for specified virtual size */ 90 MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */ 91 MODE_MEM_VIRT, /* insufficient video memory given virtual size */ 92 MODE_NOCLOCK, /* no fixed clock available */ 93 MODE_CLOCK_HIGH, /* clock required is too high */ 94 MODE_CLOCK_LOW, /* clock required is too low */ 95 MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */ 96 MODE_BAD_HVALUE, /* horizontal timing was out of range */ 97 MODE_BAD_VVALUE, /* vertical timing was out of range */ 98 MODE_BAD_VSCAN, /* VScan value out of range */ 99 MODE_HSYNC_NARROW, /* horizontal sync too narrow */ 100 MODE_HSYNC_WIDE, /* horizontal sync too wide */ 101 MODE_HBLANK_NARROW, /* horizontal blanking too narrow */ 102 MODE_HBLANK_WIDE, /* horizontal blanking too wide */ 103 MODE_VSYNC_NARROW, /* vertical sync too narrow */ 104 MODE_VSYNC_WIDE, /* vertical sync too wide */ 105 MODE_VBLANK_NARROW, /* vertical blanking too narrow */ 106 MODE_VBLANK_WIDE, /* vertical blanking too wide */ 107 MODE_PANEL, /* exceeds panel dimensions */ 108 MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */ 109 MODE_ONE_WIDTH, /* only one width is supported */ 110 MODE_ONE_HEIGHT, /* only one height is supported */ 111 MODE_ONE_SIZE, /* only one resolution is supported */ 112 MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */ 113 MODE_UNVERIFIED = -3, /* mode needs to reverified */ 114 MODE_BAD = -2, /* unspecified reason */ 115 MODE_ERROR = -1 /* error condition */ 116 }; 117 118 #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \ 119 DRM_MODE_TYPE_CRTC_C) 120 121 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \ 122 .name = nm, .status = 0, .type = (t), .clock = (c), \ 123 .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \ 124 .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \ 125 .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \ 126 .vscan = (vs), .flags = (f), \ 127 .base.type = DRM_MODE_OBJECT_MODE 128 129 #define CRTC_INTERLACE_HALVE_V 0x1 /* halve V values for interlacing */ 130 131 struct drm_display_mode { 132 /* Header */ 133 struct list_head head; 134 struct drm_mode_object base; 135 136 char name[DRM_DISPLAY_MODE_LEN]; 137 138 enum drm_mode_status status; 139 unsigned int type; 140 141 /* Proposed mode values */ 142 int clock; /* in kHz */ 143 int hdisplay; 144 int hsync_start; 145 int hsync_end; 146 int htotal; 147 int hskew; 148 int vdisplay; 149 int vsync_start; 150 int vsync_end; 151 int vtotal; 152 int vscan; 153 unsigned int flags; 154 155 /* Addressable image size (may be 0 for projectors, etc.) */ 156 int width_mm; 157 int height_mm; 158 159 /* Actual mode we give to hw */ 160 int clock_index; 161 int synth_clock; 162 int crtc_hdisplay; 163 int crtc_hblank_start; 164 int crtc_hblank_end; 165 int crtc_hsync_start; 166 int crtc_hsync_end; 167 int crtc_htotal; 168 int crtc_hskew; 169 int crtc_vdisplay; 170 int crtc_vblank_start; 171 int crtc_vblank_end; 172 int crtc_vsync_start; 173 int crtc_vsync_end; 174 int crtc_vtotal; 175 176 /* Driver private mode info */ 177 int private_size; 178 int *private; 179 int private_flags; 180 181 int vrefresh; /* in Hz */ 182 int hsync; /* in kHz */ 183 }; 184 185 enum drm_connector_status { 186 connector_status_connected = 1, 187 connector_status_disconnected = 2, 188 connector_status_unknown = 3, 189 }; 190 191 enum subpixel_order { 192 SubPixelUnknown = 0, 193 SubPixelHorizontalRGB, 194 SubPixelHorizontalBGR, 195 SubPixelVerticalRGB, 196 SubPixelVerticalBGR, 197 SubPixelNone, 198 }; 199 200 #define DRM_COLOR_FORMAT_RGB444 (1<<0) 201 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1) 202 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2) 203 /* 204 * Describes a given display (e.g. CRT or flat panel) and its limitations. 205 */ 206 struct drm_display_info { 207 char name[DRM_DISPLAY_INFO_LEN]; 208 209 /* Physical size */ 210 unsigned int width_mm; 211 unsigned int height_mm; 212 213 /* Clock limits FIXME: storage format */ 214 unsigned int min_vfreq, max_vfreq; 215 unsigned int min_hfreq, max_hfreq; 216 unsigned int pixel_clock; 217 unsigned int bpc; 218 219 enum subpixel_order subpixel_order; 220 u32 color_formats; 221 222 u8 cea_rev; 223 }; 224 225 struct drm_framebuffer_funcs { 226 /* note: use drm_framebuffer_remove() */ 227 void (*destroy)(struct drm_framebuffer *framebuffer); 228 int (*create_handle)(struct drm_framebuffer *fb, 229 struct drm_file *file_priv, 230 unsigned int *handle); 231 /** 232 * Optinal callback for the dirty fb ioctl. 233 * 234 * Userspace can notify the driver via this callback 235 * that a area of the framebuffer has changed and should 236 * be flushed to the display hardware. 237 * 238 * See documentation in drm_mode.h for the struct 239 * drm_mode_fb_dirty_cmd for more information as all 240 * the semantics and arguments have a one to one mapping 241 * on this function. 242 */ 243 int (*dirty)(struct drm_framebuffer *framebuffer, 244 struct drm_file *file_priv, unsigned flags, 245 unsigned color, struct drm_clip_rect *clips, 246 unsigned num_clips); 247 }; 248 249 struct drm_framebuffer { 250 struct drm_device *dev; 251 /* 252 * Note that the fb is refcounted for the benefit of driver internals, 253 * for example some hw, disabling a CRTC/plane is asynchronous, and 254 * scanout does not actually complete until the next vblank. So some 255 * cleanup (like releasing the reference(s) on the backing GEM bo(s)) 256 * should be deferred. In cases like this, the driver would like to 257 * hold a ref to the fb even though it has already been removed from 258 * userspace perspective. 259 */ 260 struct kref refcount; 261 /* 262 * Place on the dev->mode_config.fb_list, access protected by 263 * dev->mode_config.fb_lock. 264 */ 265 struct list_head head; 266 struct drm_mode_object base; 267 const struct drm_framebuffer_funcs *funcs; 268 unsigned int pitches[4]; 269 unsigned int offsets[4]; 270 unsigned int width; 271 unsigned int height; 272 /* depth can be 15 or 16 */ 273 unsigned int depth; 274 int bits_per_pixel; 275 int flags; 276 uint32_t pixel_format; /* fourcc format */ 277 struct list_head filp_head; 278 /* if you are using the helper */ 279 void *helper_private; 280 }; 281 282 struct drm_property_blob { 283 struct drm_mode_object base; 284 struct list_head head; 285 unsigned int length; 286 unsigned char data[]; 287 }; 288 289 struct drm_property_enum { 290 uint64_t value; 291 struct list_head head; 292 char name[DRM_PROP_NAME_LEN]; 293 }; 294 295 struct drm_property { 296 struct list_head head; 297 struct drm_mode_object base; 298 uint32_t flags; 299 char name[DRM_PROP_NAME_LEN]; 300 uint32_t num_values; 301 uint64_t *values; 302 303 struct list_head enum_blob_list; 304 }; 305 306 struct drm_crtc; 307 struct drm_connector; 308 struct drm_encoder; 309 struct drm_pending_vblank_event; 310 struct drm_plane; 311 312 /** 313 * drm_crtc_funcs - control CRTCs for a given device 314 * @save: save CRTC state 315 * @restore: restore CRTC state 316 * @reset: reset CRTC after state has been invalidate (e.g. resume) 317 * @cursor_set: setup the cursor 318 * @cursor_move: move the cursor 319 * @gamma_set: specify color ramp for CRTC 320 * @destroy: deinit and free object 321 * @set_property: called when a property is changed 322 * @set_config: apply a new CRTC configuration 323 * @page_flip: initiate a page flip 324 * 325 * The drm_crtc_funcs structure is the central CRTC management structure 326 * in the DRM. Each CRTC controls one or more connectors (note that the name 327 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc. 328 * connectors, not just CRTs). 329 * 330 * Each driver is responsible for filling out this structure at startup time, 331 * in addition to providing other modesetting features, like i2c and DDC 332 * bus accessors. 333 */ 334 struct drm_crtc_funcs { 335 /* Save CRTC state */ 336 void (*save)(struct drm_crtc *crtc); /* suspend? */ 337 /* Restore CRTC state */ 338 void (*restore)(struct drm_crtc *crtc); /* resume? */ 339 /* Reset CRTC state */ 340 void (*reset)(struct drm_crtc *crtc); 341 342 /* cursor controls */ 343 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv, 344 uint32_t handle, uint32_t width, uint32_t height); 345 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv, 346 uint32_t handle, uint32_t width, uint32_t height, 347 int32_t hot_x, int32_t hot_y); 348 int (*cursor_move)(struct drm_crtc *crtc, int x, int y); 349 350 /* Set gamma on the CRTC */ 351 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, 352 uint32_t start, uint32_t size); 353 /* Object destroy routine */ 354 void (*destroy)(struct drm_crtc *crtc); 355 356 int (*set_config)(struct drm_mode_set *set); 357 358 /* 359 * Flip to the given framebuffer. This implements the page 360 * flip ioctl descibed in drm_mode.h, specifically, the 361 * implementation must return immediately and block all 362 * rendering to the current fb until the flip has completed. 363 * If userspace set the event flag in the ioctl, the event 364 * argument will point to an event to send back when the flip 365 * completes, otherwise it will be NULL. 366 */ 367 int (*page_flip)(struct drm_crtc *crtc, 368 struct drm_framebuffer *fb, 369 struct drm_pending_vblank_event *event); 370 371 int (*set_property)(struct drm_crtc *crtc, 372 struct drm_property *property, uint64_t val); 373 }; 374 375 /** 376 * drm_crtc - central CRTC control structure 377 * @dev: parent DRM device 378 * @head: list management 379 * @base: base KMS object for ID tracking etc. 380 * @enabled: is this CRTC enabled? 381 * @mode: current mode timings 382 * @hwmode: mode timings as programmed to hw regs 383 * @invert_dimensions: for purposes of error checking crtc vs fb sizes, 384 * invert the width/height of the crtc. This is used if the driver 385 * is performing 90 or 270 degree rotated scanout 386 * @x: x position on screen 387 * @y: y position on screen 388 * @funcs: CRTC control functions 389 * @gamma_size: size of gamma ramp 390 * @gamma_store: gamma ramp values 391 * @framedur_ns: precise frame timing 392 * @framedur_ns: precise line timing 393 * @pixeldur_ns: precise pixel timing 394 * @helper_private: mid-layer private data 395 * @properties: property tracking for this CRTC 396 * 397 * Each CRTC may have one or more connectors associated with it. This structure 398 * allows the CRTC to be controlled. 399 */ 400 struct drm_crtc { 401 struct drm_device *dev; 402 struct list_head head; 403 404 /** 405 * crtc mutex 406 * 407 * This provides a read lock for the overall crtc state (mode, dpms 408 * state, ...) and a write lock for everything which can be update 409 * without a full modeset (fb, cursor data, ...) 410 */ 411 struct mutex mutex; 412 413 struct drm_mode_object base; 414 415 /* framebuffer the connector is currently bound to */ 416 struct drm_framebuffer *fb; 417 418 /* Temporary tracking of the old fb while a modeset is ongoing. Used 419 * by drm_mode_set_config_internal to implement correct refcounting. */ 420 struct drm_framebuffer *old_fb; 421 422 bool enabled; 423 424 /* Requested mode from modesetting. */ 425 struct drm_display_mode mode; 426 427 /* Programmed mode in hw, after adjustments for encoders, 428 * crtc, panel scaling etc. Needed for timestamping etc. 429 */ 430 struct drm_display_mode hwmode; 431 432 bool invert_dimensions; 433 434 int x, y; 435 const struct drm_crtc_funcs *funcs; 436 437 /* CRTC gamma size for reporting to userspace */ 438 uint32_t gamma_size; 439 uint16_t *gamma_store; 440 441 /* Constants needed for precise vblank and swap timestamping. */ 442 s64 framedur_ns, linedur_ns, pixeldur_ns; 443 444 /* if you are using the helper */ 445 void *helper_private; 446 447 struct drm_object_properties properties; 448 }; 449 450 451 /** 452 * drm_connector_funcs - control connectors on a given device 453 * @dpms: set power state (see drm_crtc_funcs above) 454 * @save: save connector state 455 * @restore: restore connector state 456 * @reset: reset connector after state has been invalidate (e.g. resume) 457 * @detect: is this connector active? 458 * @get_modes: get mode list for this connector 459 * @set_property: property for this connector may need update 460 * @destroy: make object go away 461 * @force: notify the driver the connector is forced on 462 * 463 * Each CRTC may have one or more connectors attached to it. The functions 464 * below allow the core DRM code to control connectors, enumerate available modes, 465 * etc. 466 */ 467 struct drm_connector_funcs { 468 void (*dpms)(struct drm_connector *connector, int mode); 469 void (*save)(struct drm_connector *connector); 470 void (*restore)(struct drm_connector *connector); 471 void (*reset)(struct drm_connector *connector); 472 473 /* Check to see if anything is attached to the connector. 474 * @force is set to false whilst polling, true when checking the 475 * connector due to user request. @force can be used by the driver 476 * to avoid expensive, destructive operations during automated 477 * probing. 478 */ 479 enum drm_connector_status (*detect)(struct drm_connector *connector, 480 bool force); 481 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height); 482 int (*set_property)(struct drm_connector *connector, struct drm_property *property, 483 uint64_t val); 484 void (*destroy)(struct drm_connector *connector); 485 void (*force)(struct drm_connector *connector); 486 }; 487 488 /** 489 * drm_encoder_funcs - encoder controls 490 * @reset: reset state (e.g. at init or resume time) 491 * @destroy: cleanup and free associated data 492 * 493 * Encoders sit between CRTCs and connectors. 494 */ 495 struct drm_encoder_funcs { 496 void (*reset)(struct drm_encoder *encoder); 497 void (*destroy)(struct drm_encoder *encoder); 498 }; 499 500 #define DRM_CONNECTOR_MAX_UMODES 16 501 #define DRM_CONNECTOR_LEN 32 502 #define DRM_CONNECTOR_MAX_ENCODER 3 503 504 /** 505 * drm_encoder - central DRM encoder structure 506 * @dev: parent DRM device 507 * @head: list management 508 * @base: base KMS object 509 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h 510 * @possible_crtcs: bitmask of potential CRTC bindings 511 * @possible_clones: bitmask of potential sibling encoders for cloning 512 * @crtc: currently bound CRTC 513 * @funcs: control functions 514 * @helper_private: mid-layer private data 515 * 516 * CRTCs drive pixels to encoders, which convert them into signals 517 * appropriate for a given connector or set of connectors. 518 */ 519 struct drm_encoder { 520 struct drm_device *dev; 521 struct list_head head; 522 523 struct drm_mode_object base; 524 int encoder_type; 525 uint32_t possible_crtcs; 526 uint32_t possible_clones; 527 528 struct drm_crtc *crtc; 529 const struct drm_encoder_funcs *funcs; 530 void *helper_private; 531 }; 532 533 enum drm_connector_force { 534 DRM_FORCE_UNSPECIFIED, 535 DRM_FORCE_OFF, 536 DRM_FORCE_ON, /* force on analog part normally */ 537 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */ 538 }; 539 540 /* should we poll this connector for connects and disconnects */ 541 /* hot plug detectable */ 542 #define DRM_CONNECTOR_POLL_HPD (1 << 0) 543 /* poll for connections */ 544 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1) 545 /* can cleanly poll for disconnections without flickering the screen */ 546 /* DACs should rarely do this without a lot of testing */ 547 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2) 548 549 #define MAX_ELD_BYTES 128 550 551 /** 552 * drm_connector - central DRM connector control structure 553 * @dev: parent DRM device 554 * @kdev: kernel device for sysfs attributes 555 * @attr: sysfs attributes 556 * @head: list management 557 * @base: base KMS object 558 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h 559 * @connector_type_id: index into connector type enum 560 * @interlace_allowed: can this connector handle interlaced modes? 561 * @doublescan_allowed: can this connector handle doublescan? 562 * @modes: modes available on this connector (from fill_modes() + user) 563 * @status: one of the drm_connector_status enums (connected, not, or unknown) 564 * @probed_modes: list of modes derived directly from the display 565 * @display_info: information about attached display (e.g. from EDID) 566 * @funcs: connector control functions 567 * @edid_blob_ptr: DRM property containing EDID if present 568 * @property_ids: property tracking for this connector 569 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling 570 * @dpms: current dpms state 571 * @helper_private: mid-layer private data 572 * @force: a %DRM_FORCE_<foo> state for forced mode sets 573 * @encoder_ids: valid encoders for this connector 574 * @encoder: encoder driving this connector, if any 575 * @eld: EDID-like data, if present 576 * @dvi_dual: dual link DVI, if found 577 * @max_tmds_clock: max clock rate, if found 578 * @latency_present: AV delay info from ELD, if found 579 * @video_latency: video latency info from ELD, if found 580 * @audio_latency: audio latency info from ELD, if found 581 * @null_edid_counter: track sinks that give us all zeros for the EDID 582 * 583 * Each connector may be connected to one or more CRTCs, or may be clonable by 584 * another connector if they can share a CRTC. Each connector also has a specific 585 * position in the broader display (referred to as a 'screen' though it could 586 * span multiple monitors). 587 */ 588 struct drm_connector { 589 struct drm_device *dev; 590 //struct device kdev; 591 struct device_attribute *attr; 592 struct list_head head; 593 594 struct drm_mode_object base; 595 596 int connector_type; 597 int connector_type_id; 598 bool interlace_allowed; 599 bool doublescan_allowed; 600 struct list_head modes; /* list of modes on this connector */ 601 602 enum drm_connector_status status; 603 604 /* these are modes added by probing with DDC or the BIOS */ 605 struct list_head probed_modes; 606 607 struct drm_display_info display_info; 608 const struct drm_connector_funcs *funcs; 609 610 struct drm_property_blob *edid_blob_ptr; 611 struct drm_object_properties properties; 612 613 uint8_t polled; /* DRM_CONNECTOR_POLL_* */ 614 615 /* requested DPMS state */ 616 int dpms; 617 618 void *helper_private; 619 620 /* forced on connector */ 621 enum drm_connector_force force; 622 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER]; 623 struct drm_encoder *encoder; /* currently active encoder */ 624 625 /* EDID bits */ 626 uint8_t eld[MAX_ELD_BYTES]; 627 bool dvi_dual; 628 int max_tmds_clock; /* in MHz */ 629 bool latency_present[2]; 630 int video_latency[2]; /* [0]: progressive, [1]: interlaced */ 631 int audio_latency[2]; 632 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */ 633 unsigned bad_edid_counter; 634 }; 635 636 /** 637 * drm_plane_funcs - driver plane control functions 638 * @update_plane: update the plane configuration 639 * @disable_plane: shut down the plane 640 * @destroy: clean up plane resources 641 * @set_property: called when a property is changed 642 */ 643 struct drm_plane_funcs { 644 int (*update_plane)(struct drm_plane *plane, 645 struct drm_crtc *crtc, struct drm_framebuffer *fb, 646 int crtc_x, int crtc_y, 647 unsigned int crtc_w, unsigned int crtc_h, 648 uint32_t src_x, uint32_t src_y, 649 uint32_t src_w, uint32_t src_h); 650 int (*disable_plane)(struct drm_plane *plane); 651 void (*destroy)(struct drm_plane *plane); 652 653 int (*set_property)(struct drm_plane *plane, 654 struct drm_property *property, uint64_t val); 655 }; 656 657 /** 658 * drm_plane - central DRM plane control structure 659 * @dev: DRM device this plane belongs to 660 * @head: for list management 661 * @base: base mode object 662 * @possible_crtcs: pipes this plane can be bound to 663 * @format_types: array of formats supported by this plane 664 * @format_count: number of formats supported 665 * @crtc: currently bound CRTC 666 * @fb: currently bound fb 667 * @funcs: helper functions 668 * @properties: property tracking for this plane 669 */ 670 struct drm_plane { 671 struct drm_device *dev; 672 struct list_head head; 673 674 struct drm_mode_object base; 675 676 uint32_t possible_crtcs; 677 uint32_t *format_types; 678 uint32_t format_count; 679 680 struct drm_crtc *crtc; 681 struct drm_framebuffer *fb; 682 683 const struct drm_plane_funcs *funcs; 684 685 struct drm_object_properties properties; 686 }; 687 688 /** 689 * drm_mode_set - new values for a CRTC config change 690 * @head: list management 691 * @fb: framebuffer to use for new config 692 * @crtc: CRTC whose configuration we're about to change 693 * @mode: mode timings to use 694 * @x: position of this CRTC relative to @fb 695 * @y: position of this CRTC relative to @fb 696 * @connectors: array of connectors to drive with this CRTC if possible 697 * @num_connectors: size of @connectors array 698 * 699 * Represents a single crtc the connectors that it drives with what mode 700 * and from which framebuffer it scans out from. 701 * 702 * This is used to set modes. 703 */ 704 struct drm_mode_set { 705 struct drm_framebuffer *fb; 706 struct drm_crtc *crtc; 707 struct drm_display_mode *mode; 708 709 uint32_t x; 710 uint32_t y; 711 712 struct drm_connector **connectors; 713 size_t num_connectors; 714 }; 715 716 /** 717 * struct drm_mode_config_funcs - basic driver provided mode setting functions 718 * @fb_create: create a new framebuffer object 719 * @output_poll_changed: function to handle output configuration changes 720 * 721 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that 722 * involve drivers. 723 */ 724 struct drm_mode_config_funcs { 725 struct drm_framebuffer *(*fb_create)(struct drm_device *dev, 726 struct drm_file *file_priv, 727 struct drm_mode_fb_cmd2 *mode_cmd); 728 void (*output_poll_changed)(struct drm_device *dev); 729 }; 730 731 /** 732 * drm_mode_group - group of mode setting resources for potential sub-grouping 733 * @num_crtcs: CRTC count 734 * @num_encoders: encoder count 735 * @num_connectors: connector count 736 * @id_list: list of KMS object IDs in this group 737 * 738 * Currently this simply tracks the global mode setting state. But in the 739 * future it could allow groups of objects to be set aside into independent 740 * control groups for use by different user level processes (e.g. two X servers 741 * running simultaneously on different heads, each with their own mode 742 * configuration and freedom of mode setting). 743 */ 744 struct drm_mode_group { 745 uint32_t num_crtcs; 746 uint32_t num_encoders; 747 uint32_t num_connectors; 748 749 /* list of object IDs for this group */ 750 uint32_t *id_list; 751 }; 752 753 /** 754 * drm_mode_config - Mode configuration control structure 755 * @mutex: mutex protecting KMS related lists and structures 756 * @idr_mutex: mutex for KMS ID allocation and management 757 * @crtc_idr: main KMS ID tracking object 758 * @num_fb: number of fbs available 759 * @fb_list: list of framebuffers available 760 * @num_connector: number of connectors on this device 761 * @connector_list: list of connector objects 762 * @num_encoder: number of encoders on this device 763 * @encoder_list: list of encoder objects 764 * @num_crtc: number of CRTCs on this device 765 * @crtc_list: list of CRTC objects 766 * @min_width: minimum pixel width on this device 767 * @min_height: minimum pixel height on this device 768 * @max_width: maximum pixel width on this device 769 * @max_height: maximum pixel height on this device 770 * @funcs: core driver provided mode setting functions 771 * @fb_base: base address of the framebuffer 772 * @poll_enabled: track polling status for this device 773 * @output_poll_work: delayed work for polling in process context 774 * @*_property: core property tracking 775 * 776 * Core mode resource tracking structure. All CRTC, encoders, and connectors 777 * enumerated by the driver are added here, as are global properties. Some 778 * global restrictions are also here, e.g. dimension restrictions. 779 */ 780 struct drm_mode_config { 781 kmutex_t mutex; /* protects configuration (mode lists etc.) */ 782 kmutex_t idr_mutex; /* for IDR management */ 783 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */ 784 /** 785 * fb_lock - mutex to protect fb state 786 * 787 * Besides the global fb list his also protects the fbs list in the 788 * file_priv 789 */ 790 struct mutex fb_lock; 791 /* this is limited to one for now */ 792 int num_fb; 793 struct list_head fb_list; 794 int num_connector; 795 struct list_head connector_list; 796 int num_encoder; 797 struct list_head encoder_list; 798 int num_plane; 799 struct list_head plane_list; 800 801 int num_crtc; 802 struct list_head crtc_list; 803 804 struct list_head property_list; 805 806 int min_width, min_height; 807 int max_width, max_height; 808 const struct drm_mode_config_funcs *funcs; 809 resource_size_t fb_base; 810 811 /* output poll support */ 812 bool poll_enabled; 813 bool poll_running; 814 815 /* pointers to standard properties */ 816 struct list_head property_blob_list; 817 struct drm_property *edid_property; 818 struct drm_property *dpms_property; 819 820 /* DVI-I properties */ 821 struct drm_property *dvi_i_subconnector_property; 822 struct drm_property *dvi_i_select_subconnector_property; 823 824 /* TV properties */ 825 struct drm_property *tv_subconnector_property; 826 struct drm_property *tv_select_subconnector_property; 827 struct drm_property *tv_mode_property; 828 struct drm_property *tv_left_margin_property; 829 struct drm_property *tv_right_margin_property; 830 struct drm_property *tv_top_margin_property; 831 struct drm_property *tv_bottom_margin_property; 832 struct drm_property *tv_brightness_property; 833 struct drm_property *tv_contrast_property; 834 struct drm_property *tv_flicker_reduction_property; 835 struct drm_property *tv_overscan_property; 836 struct drm_property *tv_saturation_property; 837 struct drm_property *tv_hue_property; 838 839 /* Optional properties */ 840 struct drm_property *scaling_mode_property; 841 struct drm_property *dithering_mode_property; 842 struct drm_property *dirty_info_property; 843 844 /* dumb ioctl parameters */ 845 uint32_t preferred_depth, prefer_shadow; 846 }; 847 848 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base) 849 #define obj_to_connector(x) container_of(x, struct drm_connector, base) 850 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base) 851 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base) 852 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base) 853 #define obj_to_property(x) container_of(x, struct drm_property, base) 854 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base) 855 #define obj_to_plane(x) container_of(x, struct drm_plane, base) 856 857 struct drm_prop_enum_list { 858 int type; 859 char *name; 860 }; 861 862 extern void drm_modeset_lock_all(struct drm_device *dev); 863 extern void drm_modeset_unlock_all(struct drm_device *dev); 864 865 extern int drm_crtc_init(struct drm_device *dev, 866 struct drm_crtc *crtc, 867 const struct drm_crtc_funcs *funcs); 868 extern void drm_crtc_cleanup(struct drm_crtc *crtc); 869 870 extern int drm_connector_init(struct drm_device *dev, 871 struct drm_connector *connector, 872 const struct drm_connector_funcs *funcs, 873 int connector_type); 874 875 extern void drm_connector_cleanup(struct drm_connector *connector); 876 /* helper to unplug all connectors from sysfs for device */ 877 extern void drm_connector_unplug_all(struct drm_device *dev); 878 879 extern int drm_encoder_init(struct drm_device *dev, 880 struct drm_encoder *encoder, 881 const struct drm_encoder_funcs *funcs, 882 int encoder_type); 883 884 extern int drm_plane_init(struct drm_device *dev, 885 struct drm_plane *plane, 886 unsigned long possible_crtcs, 887 const struct drm_plane_funcs *funcs, 888 const uint32_t *formats, uint32_t format_count, 889 bool priv); 890 extern void drm_plane_cleanup(struct drm_plane *plane); 891 extern void drm_plane_force_disable(struct drm_plane *plane); 892 893 extern void drm_encoder_cleanup(struct drm_encoder *encoder); 894 895 extern const char *drm_get_connector_name(const struct drm_connector *connector); 896 extern const char *drm_get_connector_status_name(enum drm_connector_status status); 897 extern const char *drm_get_dpms_name(int val); 898 extern const char *drm_get_dvi_i_subconnector_name(int val); 899 extern const char *drm_get_dvi_i_select_name(int val); 900 extern const char *drm_get_tv_subconnector_name(int val); 901 extern const char *drm_get_tv_select_name(int val); 902 extern void drm_fb_release(struct drm_file *file_priv); 903 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group); 904 extern bool drm_probe_ddc(struct i2c_adapter *adapter); 905 extern struct edid *drm_get_edid(struct drm_connector *connector, 906 struct i2c_adapter *adapter); 907 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); 908 extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode); 909 extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode); 910 extern void drm_mode_copy(struct drm_display_mode *dst, const struct drm_display_mode *src); 911 extern struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev, 912 const struct drm_display_mode *mode); 913 extern void drm_mode_debug_printmodeline(const struct drm_display_mode *mode); 914 extern void drm_mode_config_init(struct drm_device *dev); 915 extern void drm_mode_config_reset(struct drm_device *dev); 916 extern void drm_mode_config_cleanup(struct drm_device *dev); 917 extern void drm_mode_set_name(struct drm_display_mode *mode); 918 extern bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2); 919 extern bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2); 920 extern int drm_mode_width(const struct drm_display_mode *mode); 921 extern int drm_mode_height(const struct drm_display_mode *mode); 922 923 /* for us by fb module */ 924 extern struct drm_display_mode *drm_mode_create(struct drm_device *dev); 925 extern void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode); 926 extern void drm_mode_list_concat(struct list_head *head, 927 struct list_head *new); 928 extern void drm_mode_validate_size(struct drm_device *dev, 929 struct list_head *mode_list, 930 int maxX, int maxY, int maxPitch); 931 extern void drm_mode_validate_clocks(struct drm_device *dev, 932 struct list_head *mode_list, 933 int *min, int *max, int n_ranges); 934 extern void drm_mode_prune_invalid(struct drm_device *dev, 935 struct list_head *mode_list, bool verbose); 936 extern void drm_mode_sort(struct list_head *mode_list); 937 extern int drm_mode_hsync(const struct drm_display_mode *mode); 938 extern int drm_mode_vrefresh(const struct drm_display_mode *mode); 939 extern void drm_mode_set_crtcinfo(struct drm_display_mode *p, 940 int adjust_flags); 941 extern void drm_mode_connector_list_update(struct drm_connector *connector); 942 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector, 943 struct edid *edid); 944 extern int drm_object_property_set_value(struct drm_mode_object *obj, 945 struct drm_property *property, 946 uint64_t val); 947 extern int drm_object_property_get_value(struct drm_mode_object *obj, 948 struct drm_property *property, 949 uint64_t *value); 950 extern struct drm_display_mode *drm_crtc_mode_create(struct drm_device *dev); 951 extern void drm_framebuffer_set_object(struct drm_device *dev, 952 unsigned long handle); 953 extern int drm_framebuffer_init(struct drm_device *dev, 954 struct drm_framebuffer *fb, 955 const struct drm_framebuffer_funcs *funcs); 956 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, 957 uint32_t id); 958 extern void drm_framebuffer_unreference(struct drm_framebuffer *fb); 959 extern void drm_framebuffer_reference(struct drm_framebuffer *fb); 960 extern void drm_framebuffer_remove(struct drm_framebuffer *fb); 961 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb); 962 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb); 963 extern int drmfb_probe(struct drm_device *dev, struct drm_crtc *crtc); 964 extern int drmfb_remove(struct drm_device *dev, struct drm_framebuffer *fb); 965 extern void drm_crtc_probe_connector_modes(struct drm_device *dev, int maxX, int maxY); 966 extern bool drm_crtc_in_use(struct drm_crtc *crtc); 967 968 extern void drm_object_attach_property(struct drm_mode_object *obj, 969 struct drm_property *property, 970 uint64_t init_val); 971 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags, 972 const char *name, int num_values); 973 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, 974 const char *name, 975 const struct drm_prop_enum_list *props, 976 int num_values); 977 struct drm_property *drm_property_create_bitmask(struct drm_device *dev, 978 int flags, const char *name, 979 const struct drm_prop_enum_list *props, 980 int num_values); 981 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, 982 const char *name, 983 uint64_t min, uint64_t max); 984 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property); 985 extern int drm_property_add_enum(struct drm_property *property, int index, 986 uint64_t value, const char *name); 987 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev); 988 extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats, 989 char *formats[]); 990 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev); 991 extern int drm_mode_create_dithering_property(struct drm_device *dev); 992 extern int drm_mode_create_dirty_info_property(struct drm_device *dev); 993 extern const char *drm_get_encoder_name(const struct drm_encoder *encoder); 994 995 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector, 996 struct drm_encoder *encoder); 997 extern void drm_mode_connector_detach_encoder(struct drm_connector *connector, 998 struct drm_encoder *encoder); 999 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, 1000 int gamma_size); 1001 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, 1002 uint32_t id, uint32_t type); 1003 extern int drm_mode_set_config_internal(struct drm_mode_set *set); 1004 /* IOCTLs */ 1005 extern int drm_mode_getresources(DRM_IOCTL_ARGS); 1006 extern int drm_mode_getplane_res(DRM_IOCTL_ARGS); 1007 extern int drm_mode_getcrtc(DRM_IOCTL_ARGS); 1008 extern int drm_mode_getconnector(DRM_IOCTL_ARGS); 1009 extern int drm_mode_setcrtc(DRM_IOCTL_ARGS); 1010 extern int drm_mode_getplane(DRM_IOCTL_ARGS); 1011 extern int drm_mode_setplane(DRM_IOCTL_ARGS); 1012 extern int drm_mode_cursor_ioctl(DRM_IOCTL_ARGS); 1013 extern int drm_mode_cursor2_ioctl(DRM_IOCTL_ARGS); 1014 extern int drm_mode_addfb(DRM_IOCTL_ARGS); 1015 extern int drm_mode_addfb2(DRM_IOCTL_ARGS); 1016 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); 1017 extern int drm_mode_rmfb(DRM_IOCTL_ARGS); 1018 extern int drm_mode_getfb(DRM_IOCTL_ARGS); 1019 extern int drm_mode_dirtyfb_ioctl(DRM_IOCTL_ARGS); 1020 extern int drm_mode_getproperty_ioctl(DRM_IOCTL_ARGS); 1021 extern int drm_mode_getblob_ioctl(DRM_IOCTL_ARGS); 1022 extern int drm_mode_connector_property_set_ioctl(DRM_IOCTL_ARGS); 1023 extern int drm_mode_hotplug_ioctl(DRM_IOCTL_ARGS); 1024 extern int drm_mode_replacefb(DRM_IOCTL_ARGS); 1025 extern int drm_mode_getencoder(DRM_IOCTL_ARGS); 1026 extern int drm_mode_gamma_get_ioctl(DRM_IOCTL_ARGS); 1027 extern int drm_mode_gamma_set_ioctl(DRM_IOCTL_ARGS); 1028 extern u8 *drm_find_cea_extension(struct edid *edid); 1029 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match); 1030 extern bool drm_detect_hdmi_monitor(struct edid *edid); 1031 extern bool drm_detect_monitor_audio(struct edid *edid); 1032 extern bool drm_rgb_quant_range_selectable(struct edid *edid); 1033 extern int drm_mode_page_flip_ioctl(DRM_IOCTL_ARGS); 1034 extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, 1035 int hdisplay, int vdisplay, int vrefresh, 1036 bool reduced, bool interlaced, bool margins); 1037 extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev, 1038 int hdisplay, int vdisplay, int vrefresh, 1039 bool interlaced, int margins); 1040 extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev, 1041 int hdisplay, int vdisplay, int vrefresh, 1042 bool interlaced, int margins, int GTF_M, 1043 int GTF_2C, int GTF_K, int GTF_2J); 1044 extern int drm_add_modes_noedid(struct drm_connector *connector, 1045 int hdisplay, int vdisplay); 1046 1047 extern int drm_edid_header_is_valid(const u8 *raw_edid); 1048 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid); 1049 extern bool drm_edid_is_valid(struct edid *edid); 1050 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, 1051 int hsize, int vsize, int fresh, 1052 bool rb); 1053 1054 extern int drm_mode_create_dumb_ioctl(DRM_IOCTL_ARGS); 1055 extern int drm_mode_mmap_dumb_ioctl(DRM_IOCTL_ARGS); 1056 extern int drm_mode_destroy_dumb_ioctl(DRM_IOCTL_ARGS); 1057 extern int drm_mode_obj_get_properties_ioctl(DRM_IOCTL_ARGS); 1058 extern int drm_mode_obj_set_property_ioctl(DRM_IOCTL_ARGS); 1059 1060 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, 1061 int *bpp); 1062 extern int drm_format_num_planes(uint32_t format); 1063 extern int drm_format_plane_cpp(uint32_t format, int plane); 1064 extern int drm_format_horz_chroma_subsampling(uint32_t format); 1065 extern int drm_format_vert_chroma_subsampling(uint32_t format); 1066 extern const char *drm_get_format_name(uint32_t format); 1067 1068 #endif /* __DRM_CRTC_H__ */ 1069