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