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 #ifndef __DRM_CRTC_H__ 26 #define __DRM_CRTC_H__ 27 28 #include <linux/i2c.h> 29 #include <linux/spinlock.h> 30 #include <linux/types.h> 31 #include <linux/idr.h> 32 #include <linux/fb.h> 33 #include <linux/hdmi.h> 34 #include <linux/media-bus-format.h> 35 #include <uapi/drm/drm_mode.h> 36 #include <uapi/drm/drm_fourcc.h> 37 #include <drm/drm_modeset_lock.h> 38 #include <drm/drm_rect.h> 39 #include <drm/drm_mode_object.h> 40 #include <drm/drm_framebuffer.h> 41 #include <drm/drm_modes.h> 42 #include <drm/drm_connector.h> 43 #include <drm/drm_encoder.h> 44 #include <drm/drm_property.h> 45 #include <drm/drm_bridge.h> 46 #include <drm/drm_edid.h> 47 #include <drm/drm_plane.h> 48 #include <drm/drm_blend.h> 49 #include <drm/drm_color_mgmt.h> 50 #include <drm/drm_debugfs_crc.h> 51 52 struct drm_device; 53 struct drm_mode_set; 54 struct drm_file; 55 struct drm_clip_rect; 56 struct drm_printer; 57 struct device_node; 58 struct dma_fence; 59 struct edid; 60 61 static inline int64_t U642I64(uint64_t val) 62 { 63 return (int64_t)*((int64_t *)&val); 64 } 65 static inline uint64_t I642U64(int64_t val) 66 { 67 return (uint64_t)*((uint64_t *)&val); 68 } 69 70 /* data corresponds to displayid vend/prod/serial */ 71 struct drm_tile_group { 72 struct kref refcount; 73 struct drm_device *dev; 74 int id; 75 u8 group_data[8]; 76 }; 77 78 struct drm_crtc; 79 struct drm_encoder; 80 struct drm_pending_vblank_event; 81 struct drm_plane; 82 struct drm_bridge; 83 struct drm_atomic_state; 84 85 struct drm_crtc_helper_funcs; 86 struct drm_encoder_helper_funcs; 87 struct drm_plane_helper_funcs; 88 89 /** 90 * struct drm_crtc_state - mutable CRTC state 91 * @crtc: backpointer to the CRTC 92 * @enable: whether the CRTC should be enabled, gates all other state 93 * @active: whether the CRTC is actively displaying (used for DPMS) 94 * @planes_changed: planes on this crtc are updated 95 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed 96 * @active_changed: crtc_state->active has been toggled. 97 * @connectors_changed: connectors to this crtc have been updated 98 * @zpos_changed: zpos values of planes on this crtc have been updated 99 * @color_mgmt_changed: color management properties have changed (degamma or 100 * gamma LUT or CSC matrix) 101 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes 102 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors 103 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders 104 * @last_vblank_count: for helpers and drivers to capture the vblank of the 105 * update to ensure framebuffer cleanup isn't done too early 106 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings 107 * @mode: current mode timings 108 * @mode_blob: &drm_property_blob for @mode 109 * @degamma_lut: Lookup table for converting framebuffer pixel data 110 * before apply the conversion matrix 111 * @ctm: Transformation matrix 112 * @gamma_lut: Lookup table for converting pixel data after the 113 * conversion matrix 114 * @state: backpointer to global drm_atomic_state 115 * 116 * Note that the distinction between @enable and @active is rather subtile: 117 * Flipping @active while @enable is set without changing anything else may 118 * never return in a failure from the ->atomic_check callback. Userspace assumes 119 * that a DPMS On will always succeed. In other words: @enable controls resource 120 * assignment, @active controls the actual hardware state. 121 * 122 * The three booleans active_changed, connectors_changed and mode_changed are 123 * intended to indicate whether a full modeset is needed, rather than strictly 124 * describing what has changed in a commit. 125 * See also: drm_atomic_crtc_needs_modeset() 126 */ 127 struct drm_crtc_state { 128 struct drm_crtc *crtc; 129 130 bool enable; 131 bool active; 132 133 /* computed state bits used by helpers and drivers */ 134 bool planes_changed : 1; 135 bool mode_changed : 1; 136 bool active_changed : 1; 137 bool connectors_changed : 1; 138 bool zpos_changed : 1; 139 bool color_mgmt_changed : 1; 140 141 /* attached planes bitmask: 142 * WARNING: transitional helpers do not maintain plane_mask so 143 * drivers not converted over to atomic helpers should not rely 144 * on plane_mask being accurate! 145 */ 146 u32 plane_mask; 147 148 u32 connector_mask; 149 u32 encoder_mask; 150 151 /* last_vblank_count: for vblank waits before cleanup */ 152 u32 last_vblank_count; 153 154 /* adjusted_mode: for use by helpers and drivers */ 155 struct drm_display_mode adjusted_mode; 156 157 struct drm_display_mode mode; 158 159 /* blob property to expose current mode to atomic userspace */ 160 struct drm_property_blob *mode_blob; 161 162 /* blob property to expose color management to userspace */ 163 struct drm_property_blob *degamma_lut; 164 struct drm_property_blob *ctm; 165 struct drm_property_blob *gamma_lut; 166 167 /** 168 * @event: 169 * 170 * Optional pointer to a DRM event to signal upon completion of the 171 * state update. The driver must send out the event when the atomic 172 * commit operation completes. There are two cases: 173 * 174 * - The event is for a CRTC which is being disabled through this 175 * atomic commit. In that case the event can be send out any time 176 * after the hardware has stopped scanning out the current 177 * framebuffers. It should contain the timestamp and counter for the 178 * last vblank before the display pipeline was shut off. 179 * 180 * - For a CRTC which is enabled at the end of the commit (even when it 181 * undergoes an full modeset) the vblank timestamp and counter must 182 * be for the vblank right before the first frame that scans out the 183 * new set of buffers. Again the event can only be sent out after the 184 * hardware has stopped scanning out the old buffers. 185 * 186 * - Events for disabled CRTCs are not allowed, and drivers can ignore 187 * that case. 188 * 189 * This can be handled by the drm_crtc_send_vblank_event() function, 190 * which the driver should call on the provided event upon completion of 191 * the atomic commit. Note that if the driver supports vblank signalling 192 * and timestamping the vblank counters and timestamps must agree with 193 * the ones returned from page flip events. With the current vblank 194 * helper infrastructure this can be achieved by holding a vblank 195 * reference while the page flip is pending, acquired through 196 * drm_crtc_vblank_get() and released with drm_crtc_vblank_put(). 197 * Drivers are free to implement their own vblank counter and timestamp 198 * tracking though, e.g. if they have accurate timestamp registers in 199 * hardware. 200 * 201 * For hardware which supports some means to synchronize vblank 202 * interrupt delivery with committing display state there's also 203 * drm_crtc_arm_vblank_event(). See the documentation of that function 204 * for a detailed discussion of the constraints it needs to be used 205 * safely. 206 */ 207 struct drm_pending_vblank_event *event; 208 209 struct drm_atomic_state *state; 210 }; 211 212 /** 213 * struct drm_crtc_funcs - control CRTCs for a given device 214 * 215 * The drm_crtc_funcs structure is the central CRTC management structure 216 * in the DRM. Each CRTC controls one or more connectors (note that the name 217 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc. 218 * connectors, not just CRTs). 219 * 220 * Each driver is responsible for filling out this structure at startup time, 221 * in addition to providing other modesetting features, like i2c and DDC 222 * bus accessors. 223 */ 224 struct drm_crtc_funcs { 225 /** 226 * @reset: 227 * 228 * Reset CRTC hardware and software state to off. This function isn't 229 * called by the core directly, only through drm_mode_config_reset(). 230 * It's not a helper hook only for historical reasons. 231 * 232 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset 233 * atomic state using this hook. 234 */ 235 void (*reset)(struct drm_crtc *crtc); 236 237 /** 238 * @cursor_set: 239 * 240 * Update the cursor image. The cursor position is relative to the CRTC 241 * and can be partially or fully outside of the visible area. 242 * 243 * Note that contrary to all other KMS functions the legacy cursor entry 244 * points don't take a framebuffer object, but instead take directly a 245 * raw buffer object id from the driver's buffer manager (which is 246 * either GEM or TTM for current drivers). 247 * 248 * This entry point is deprecated, drivers should instead implement 249 * universal plane support and register a proper cursor plane using 250 * drm_crtc_init_with_planes(). 251 * 252 * This callback is optional 253 * 254 * RETURNS: 255 * 256 * 0 on success or a negative error code on failure. 257 */ 258 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv, 259 uint32_t handle, uint32_t width, uint32_t height); 260 261 /** 262 * @cursor_set2: 263 * 264 * Update the cursor image, including hotspot information. The hotspot 265 * must not affect the cursor position in CRTC coordinates, but is only 266 * meant as a hint for virtualized display hardware to coordinate the 267 * guests and hosts cursor position. The cursor hotspot is relative to 268 * the cursor image. Otherwise this works exactly like @cursor_set. 269 * 270 * This entry point is deprecated, drivers should instead implement 271 * universal plane support and register a proper cursor plane using 272 * drm_crtc_init_with_planes(). 273 * 274 * This callback is optional. 275 * 276 * RETURNS: 277 * 278 * 0 on success or a negative error code on failure. 279 */ 280 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv, 281 uint32_t handle, uint32_t width, uint32_t height, 282 int32_t hot_x, int32_t hot_y); 283 284 /** 285 * @cursor_move: 286 * 287 * Update the cursor position. The cursor does not need to be visible 288 * when this hook is called. 289 * 290 * This entry point is deprecated, drivers should instead implement 291 * universal plane support and register a proper cursor plane using 292 * drm_crtc_init_with_planes(). 293 * 294 * This callback is optional. 295 * 296 * RETURNS: 297 * 298 * 0 on success or a negative error code on failure. 299 */ 300 int (*cursor_move)(struct drm_crtc *crtc, int x, int y); 301 302 /** 303 * @gamma_set: 304 * 305 * Set gamma on the CRTC. 306 * 307 * This callback is optional. 308 * 309 * NOTE: 310 * 311 * Drivers that support gamma tables and also fbdev emulation through 312 * the provided helper library need to take care to fill out the gamma 313 * hooks for both. Currently there's a bit an unfortunate duplication 314 * going on, which should eventually be unified to just one set of 315 * hooks. 316 */ 317 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, 318 uint32_t size); 319 320 /** 321 * @destroy: 322 * 323 * Clean up plane resources. This is only called at driver unload time 324 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged 325 * in DRM. 326 */ 327 void (*destroy)(struct drm_crtc *crtc); 328 329 /** 330 * @set_config: 331 * 332 * This is the main legacy entry point to change the modeset state on a 333 * CRTC. All the details of the desired configuration are passed in a 334 * struct &drm_mode_set - see there for details. 335 * 336 * Drivers implementing atomic modeset should use 337 * drm_atomic_helper_set_config() to implement this hook. 338 * 339 * RETURNS: 340 * 341 * 0 on success or a negative error code on failure. 342 */ 343 int (*set_config)(struct drm_mode_set *set); 344 345 /** 346 * @page_flip: 347 * 348 * Legacy entry point to schedule a flip to the given framebuffer. 349 * 350 * Page flipping is a synchronization mechanism that replaces the frame 351 * buffer being scanned out by the CRTC with a new frame buffer during 352 * vertical blanking, avoiding tearing (except when requested otherwise 353 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application 354 * requests a page flip the DRM core verifies that the new frame buffer 355 * is large enough to be scanned out by the CRTC in the currently 356 * configured mode and then calls the CRTC ->page_flip() operation with a 357 * pointer to the new frame buffer. 358 * 359 * The driver must wait for any pending rendering to the new framebuffer 360 * to complete before executing the flip. It should also wait for any 361 * pending rendering from other drivers if the underlying buffer is a 362 * shared dma-buf. 363 * 364 * An application can request to be notified when the page flip has 365 * completed. The drm core will supply a struct &drm_event in the event 366 * parameter in this case. This can be handled by the 367 * drm_crtc_send_vblank_event() function, which the driver should call on 368 * the provided event upon completion of the flip. Note that if 369 * the driver supports vblank signalling and timestamping the vblank 370 * counters and timestamps must agree with the ones returned from page 371 * flip events. With the current vblank helper infrastructure this can 372 * be achieved by holding a vblank reference while the page flip is 373 * pending, acquired through drm_crtc_vblank_get() and released with 374 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank 375 * counter and timestamp tracking though, e.g. if they have accurate 376 * timestamp registers in hardware. 377 * 378 * This callback is optional. 379 * 380 * NOTE: 381 * 382 * Very early versions of the KMS ABI mandated that the driver must 383 * block (but not reject) any rendering to the old framebuffer until the 384 * flip operation has completed and the old framebuffer is no longer 385 * visible. This requirement has been lifted, and userspace is instead 386 * expected to request delivery of an event and wait with recycling old 387 * buffers until such has been received. 388 * 389 * RETURNS: 390 * 391 * 0 on success or a negative error code on failure. Note that if a 392 * ->page_flip() operation is already pending the callback should return 393 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode 394 * or just runtime disabled through DPMS respectively the new atomic 395 * "ACTIVE" state) should result in an -EINVAL error code. Note that 396 * drm_atomic_helper_page_flip() checks this already for atomic drivers. 397 */ 398 int (*page_flip)(struct drm_crtc *crtc, 399 struct drm_framebuffer *fb, 400 struct drm_pending_vblank_event *event, 401 uint32_t flags); 402 403 /** 404 * @page_flip_target: 405 * 406 * Same as @page_flip but with an additional parameter specifying the 407 * absolute target vertical blank period (as reported by 408 * drm_crtc_vblank_count()) when the flip should take effect. 409 * 410 * Note that the core code calls drm_crtc_vblank_get before this entry 411 * point, and will call drm_crtc_vblank_put if this entry point returns 412 * any non-0 error code. It's the driver's responsibility to call 413 * drm_crtc_vblank_put after this entry point returns 0, typically when 414 * the flip completes. 415 */ 416 int (*page_flip_target)(struct drm_crtc *crtc, 417 struct drm_framebuffer *fb, 418 struct drm_pending_vblank_event *event, 419 uint32_t flags, uint32_t target); 420 421 /** 422 * @set_property: 423 * 424 * This is the legacy entry point to update a property attached to the 425 * CRTC. 426 * 427 * Drivers implementing atomic modeset should use 428 * drm_atomic_helper_crtc_set_property() to implement this hook. 429 * 430 * This callback is optional if the driver does not support any legacy 431 * driver-private properties. 432 * 433 * RETURNS: 434 * 435 * 0 on success or a negative error code on failure. 436 */ 437 int (*set_property)(struct drm_crtc *crtc, 438 struct drm_property *property, uint64_t val); 439 440 /** 441 * @atomic_duplicate_state: 442 * 443 * Duplicate the current atomic state for this CRTC and return it. 444 * The core and helpers gurantee that any atomic state duplicated with 445 * this hook and still owned by the caller (i.e. not transferred to the 446 * driver by calling ->atomic_commit() from struct 447 * &drm_mode_config_funcs) will be cleaned up by calling the 448 * @atomic_destroy_state hook in this structure. 449 * 450 * Atomic drivers which don't subclass struct &drm_crtc should use 451 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the 452 * state structure to extend it with driver-private state should use 453 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is 454 * duplicated in a consistent fashion across drivers. 455 * 456 * It is an error to call this hook before crtc->state has been 457 * initialized correctly. 458 * 459 * NOTE: 460 * 461 * If the duplicate state references refcounted resources this hook must 462 * acquire a reference for each of them. The driver must release these 463 * references again in @atomic_destroy_state. 464 * 465 * RETURNS: 466 * 467 * Duplicated atomic state or NULL when the allocation failed. 468 */ 469 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc); 470 471 /** 472 * @atomic_destroy_state: 473 * 474 * Destroy a state duplicated with @atomic_duplicate_state and release 475 * or unreference all resources it references 476 */ 477 void (*atomic_destroy_state)(struct drm_crtc *crtc, 478 struct drm_crtc_state *state); 479 480 /** 481 * @atomic_set_property: 482 * 483 * Decode a driver-private property value and store the decoded value 484 * into the passed-in state structure. Since the atomic core decodes all 485 * standardized properties (even for extensions beyond the core set of 486 * properties which might not be implemented by all drivers) this 487 * requires drivers to subclass the state structure. 488 * 489 * Such driver-private properties should really only be implemented for 490 * truly hardware/vendor specific state. Instead it is preferred to 491 * standardize atomic extension and decode the properties used to expose 492 * such an extension in the core. 493 * 494 * Do not call this function directly, use 495 * drm_atomic_crtc_set_property() instead. 496 * 497 * This callback is optional if the driver does not support any 498 * driver-private atomic properties. 499 * 500 * NOTE: 501 * 502 * This function is called in the state assembly phase of atomic 503 * modesets, which can be aborted for any reason (including on 504 * userspace's request to just check whether a configuration would be 505 * possible). Drivers MUST NOT touch any persistent state (hardware or 506 * software) or data structures except the passed in @state parameter. 507 * 508 * Also since userspace controls in which order properties are set this 509 * function must not do any input validation (since the state update is 510 * incomplete and hence likely inconsistent). Instead any such input 511 * validation must be done in the various atomic_check callbacks. 512 * 513 * RETURNS: 514 * 515 * 0 if the property has been found, -EINVAL if the property isn't 516 * implemented by the driver (which should never happen, the core only 517 * asks for properties attached to this CRTC). No other validation is 518 * allowed by the driver. The core already checks that the property 519 * value is within the range (integer, valid enum value, ...) the driver 520 * set when registering the property. 521 */ 522 int (*atomic_set_property)(struct drm_crtc *crtc, 523 struct drm_crtc_state *state, 524 struct drm_property *property, 525 uint64_t val); 526 /** 527 * @atomic_get_property: 528 * 529 * Reads out the decoded driver-private property. This is used to 530 * implement the GETCRTC IOCTL. 531 * 532 * Do not call this function directly, use 533 * drm_atomic_crtc_get_property() instead. 534 * 535 * This callback is optional if the driver does not support any 536 * driver-private atomic properties. 537 * 538 * RETURNS: 539 * 540 * 0 on success, -EINVAL if the property isn't implemented by the 541 * driver (which should never happen, the core only asks for 542 * properties attached to this CRTC). 543 */ 544 int (*atomic_get_property)(struct drm_crtc *crtc, 545 const struct drm_crtc_state *state, 546 struct drm_property *property, 547 uint64_t *val); 548 549 /** 550 * @late_register: 551 * 552 * This optional hook can be used to register additional userspace 553 * interfaces attached to the crtc like debugfs interfaces. 554 * It is called late in the driver load sequence from drm_dev_register(). 555 * Everything added from this callback should be unregistered in 556 * the early_unregister callback. 557 * 558 * Returns: 559 * 560 * 0 on success, or a negative error code on failure. 561 */ 562 int (*late_register)(struct drm_crtc *crtc); 563 564 /** 565 * @early_unregister: 566 * 567 * This optional hook should be used to unregister the additional 568 * userspace interfaces attached to the crtc from 569 * late_unregister(). It is called from drm_dev_unregister(), 570 * early in the driver unload sequence to disable userspace access 571 * before data structures are torndown. 572 */ 573 void (*early_unregister)(struct drm_crtc *crtc); 574 575 /** 576 * @set_crc_source: 577 * 578 * Changes the source of CRC checksums of frames at the request of 579 * userspace, typically for testing purposes. The sources available are 580 * specific of each driver and a %NULL value indicates that CRC 581 * generation is to be switched off. 582 * 583 * When CRC generation is enabled, the driver should call 584 * drm_crtc_add_crc_entry() at each frame, providing any information 585 * that characterizes the frame contents in the crcN arguments, as 586 * provided from the configured source. Drivers must accept a "auto" 587 * source name that will select a default source for this CRTC. 588 * 589 * This callback is optional if the driver does not support any CRC 590 * generation functionality. 591 * 592 * RETURNS: 593 * 594 * 0 on success or a negative error code on failure. 595 */ 596 int (*set_crc_source)(struct drm_crtc *crtc, const char *source, 597 size_t *values_cnt); 598 599 /** 600 * @atomic_print_state: 601 * 602 * If driver subclasses struct &drm_crtc_state, it should implement 603 * this optional hook for printing additional driver specific state. 604 * 605 * Do not call this directly, use drm_atomic_crtc_print_state() 606 * instead. 607 */ 608 void (*atomic_print_state)(struct drm_printer *p, 609 const struct drm_crtc_state *state); 610 }; 611 612 /** 613 * struct drm_crtc - central CRTC control structure 614 * @dev: parent DRM device 615 * @port: OF node used by drm_of_find_possible_crtcs() 616 * @head: list management 617 * @name: human readable name, can be overwritten by the driver 618 * @mutex: per-CRTC locking 619 * @base: base KMS object for ID tracking etc. 620 * @primary: primary plane for this CRTC 621 * @cursor: cursor plane for this CRTC 622 * @cursor_x: current x position of the cursor, used for universal cursor planes 623 * @cursor_y: current y position of the cursor, used for universal cursor planes 624 * @enabled: is this CRTC enabled? 625 * @mode: current mode timings 626 * @hwmode: mode timings as programmed to hw regs 627 * @x: x position on screen 628 * @y: y position on screen 629 * @funcs: CRTC control functions 630 * @gamma_size: size of gamma ramp 631 * @gamma_store: gamma ramp values 632 * @helper_private: mid-layer private data 633 * @properties: property tracking for this CRTC 634 * 635 * Each CRTC may have one or more connectors associated with it. This structure 636 * allows the CRTC to be controlled. 637 */ 638 struct drm_crtc { 639 struct drm_device *dev; 640 struct device_node *port; 641 struct list_head head; 642 643 char *name; 644 645 /** 646 * @mutex: 647 * 648 * This provides a read lock for the overall crtc state (mode, dpms 649 * state, ...) and a write lock for everything which can be update 650 * without a full modeset (fb, cursor data, crtc properties ...). Full 651 * modeset also need to grab dev->mode_config.connection_mutex. 652 */ 653 struct drm_modeset_lock mutex; 654 655 struct drm_mode_object base; 656 657 /* primary and cursor planes for CRTC */ 658 struct drm_plane *primary; 659 struct drm_plane *cursor; 660 661 /** 662 * @index: Position inside the mode_config.list, can be used as an array 663 * index. It is invariant over the lifetime of the CRTC. 664 */ 665 unsigned index; 666 667 /* position of cursor plane on crtc */ 668 int cursor_x; 669 int cursor_y; 670 671 bool enabled; 672 673 /* Requested mode from modesetting. */ 674 struct drm_display_mode mode; 675 676 /* Programmed mode in hw, after adjustments for encoders, 677 * crtc, panel scaling etc. Needed for timestamping etc. 678 */ 679 struct drm_display_mode hwmode; 680 681 int x, y; 682 const struct drm_crtc_funcs *funcs; 683 684 /* Legacy FB CRTC gamma size for reporting to userspace */ 685 uint32_t gamma_size; 686 uint16_t *gamma_store; 687 688 /* if you are using the helper */ 689 const struct drm_crtc_helper_funcs *helper_private; 690 691 struct drm_object_properties properties; 692 693 /** 694 * @state: 695 * 696 * Current atomic state for this CRTC. 697 */ 698 struct drm_crtc_state *state; 699 700 /** 701 * @commit_list: 702 * 703 * List of &drm_crtc_commit structures tracking pending commits. 704 * Protected by @commit_lock. This list doesn't hold its own full 705 * reference, but burrows it from the ongoing commit. Commit entries 706 * must be removed from this list once the commit is fully completed, 707 * but before it's correspoding &drm_atomic_state gets destroyed. 708 */ 709 struct list_head commit_list; 710 711 /** 712 * @commit_lock: 713 * 714 * Spinlock to protect @commit_list. 715 */ 716 spinlock_t commit_lock; 717 718 /** 719 * @acquire_ctx: 720 * 721 * Per-CRTC implicit acquire context used by atomic drivers for legacy 722 * IOCTLs, so that atomic drivers can get at the locking acquire 723 * context. 724 */ 725 struct drm_modeset_acquire_ctx *acquire_ctx; 726 727 #ifdef CONFIG_DEBUG_FS 728 /** 729 * @debugfs_entry: 730 * 731 * Debugfs directory for this CRTC. 732 */ 733 struct dentry *debugfs_entry; 734 735 /** 736 * @crc: 737 * 738 * Configuration settings of CRC capture. 739 */ 740 struct drm_crtc_crc crc; 741 #endif 742 }; 743 744 /** 745 * struct drm_mode_set - new values for a CRTC config change 746 * @fb: framebuffer to use for new config 747 * @crtc: CRTC whose configuration we're about to change 748 * @mode: mode timings to use 749 * @x: position of this CRTC relative to @fb 750 * @y: position of this CRTC relative to @fb 751 * @connectors: array of connectors to drive with this CRTC if possible 752 * @num_connectors: size of @connectors array 753 * 754 * Represents a single crtc the connectors that it drives with what mode 755 * and from which framebuffer it scans out from. 756 * 757 * This is used to set modes. 758 */ 759 struct drm_mode_set { 760 struct drm_framebuffer *fb; 761 struct drm_crtc *crtc; 762 struct drm_display_mode *mode; 763 764 uint32_t x; 765 uint32_t y; 766 767 struct drm_connector **connectors; 768 size_t num_connectors; 769 }; 770 771 /** 772 * struct drm_mode_config_funcs - basic driver provided mode setting functions 773 * 774 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that 775 * involve drivers. 776 */ 777 struct drm_mode_config_funcs { 778 /** 779 * @fb_create: 780 * 781 * Create a new framebuffer object. The core does basic checks on the 782 * requested metadata, but most of that is left to the driver. See 783 * struct &drm_mode_fb_cmd2 for details. 784 * 785 * If the parameters are deemed valid and the backing storage objects in 786 * the underlying memory manager all exist, then the driver allocates 787 * a new &drm_framebuffer structure, subclassed to contain 788 * driver-specific information (like the internal native buffer object 789 * references). It also needs to fill out all relevant metadata, which 790 * should be done by calling drm_helper_mode_fill_fb_struct(). 791 * 792 * The initialization is finalized by calling drm_framebuffer_init(), 793 * which registers the framebuffer and makes it accessible to other 794 * threads. 795 * 796 * RETURNS: 797 * 798 * A new framebuffer with an initial reference count of 1 or a negative 799 * error code encoded with ERR_PTR(). 800 */ 801 struct drm_framebuffer *(*fb_create)(struct drm_device *dev, 802 struct drm_file *file_priv, 803 const struct drm_mode_fb_cmd2 *mode_cmd); 804 805 /** 806 * @output_poll_changed: 807 * 808 * Callback used by helpers to inform the driver of output configuration 809 * changes. 810 * 811 * Drivers implementing fbdev emulation with the helpers can call 812 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev 813 * helper of output changes. 814 * 815 * FIXME: 816 * 817 * Except that there's no vtable for device-level helper callbacks 818 * there's no reason this is a core function. 819 */ 820 void (*output_poll_changed)(struct drm_device *dev); 821 822 /** 823 * @atomic_check: 824 * 825 * This is the only hook to validate an atomic modeset update. This 826 * function must reject any modeset and state changes which the hardware 827 * or driver doesn't support. This includes but is of course not limited 828 * to: 829 * 830 * - Checking that the modes, framebuffers, scaling and placement 831 * requirements and so on are within the limits of the hardware. 832 * 833 * - Checking that any hidden shared resources are not oversubscribed. 834 * This can be shared PLLs, shared lanes, overall memory bandwidth, 835 * display fifo space (where shared between planes or maybe even 836 * CRTCs). 837 * 838 * - Checking that virtualized resources exported to userspace are not 839 * oversubscribed. For various reasons it can make sense to expose 840 * more planes, crtcs or encoders than which are physically there. One 841 * example is dual-pipe operations (which generally should be hidden 842 * from userspace if when lockstepped in hardware, exposed otherwise), 843 * where a plane might need 1 hardware plane (if it's just on one 844 * pipe), 2 hardware planes (when it spans both pipes) or maybe even 845 * shared a hardware plane with a 2nd plane (if there's a compatible 846 * plane requested on the area handled by the other pipe). 847 * 848 * - Check that any transitional state is possible and that if 849 * requested, the update can indeed be done in the vblank period 850 * without temporarily disabling some functions. 851 * 852 * - Check any other constraints the driver or hardware might have. 853 * 854 * - This callback also needs to correctly fill out the &drm_crtc_state 855 * in this update to make sure that drm_atomic_crtc_needs_modeset() 856 * reflects the nature of the possible update and returns true if and 857 * only if the update cannot be applied without tearing within one 858 * vblank on that CRTC. The core uses that information to reject 859 * updates which require a full modeset (i.e. blanking the screen, or 860 * at least pausing updates for a substantial amount of time) if 861 * userspace has disallowed that in its request. 862 * 863 * - The driver also does not need to repeat basic input validation 864 * like done for the corresponding legacy entry points. The core does 865 * that before calling this hook. 866 * 867 * See the documentation of @atomic_commit for an exhaustive list of 868 * error conditions which don't have to be checked at the 869 * ->atomic_check() stage? 870 * 871 * See the documentation for struct &drm_atomic_state for how exactly 872 * an atomic modeset update is described. 873 * 874 * Drivers using the atomic helpers can implement this hook using 875 * drm_atomic_helper_check(), or one of the exported sub-functions of 876 * it. 877 * 878 * RETURNS: 879 * 880 * 0 on success or one of the below negative error codes: 881 * 882 * - -EINVAL, if any of the above constraints are violated. 883 * 884 * - -EDEADLK, when returned from an attempt to acquire an additional 885 * &drm_modeset_lock through drm_modeset_lock(). 886 * 887 * - -ENOMEM, if allocating additional state sub-structures failed due 888 * to lack of memory. 889 * 890 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted. 891 * This can either be due to a pending signal, or because the driver 892 * needs to completely bail out to recover from an exceptional 893 * situation like a GPU hang. From a userspace point all errors are 894 * treated equally. 895 */ 896 int (*atomic_check)(struct drm_device *dev, 897 struct drm_atomic_state *state); 898 899 /** 900 * @atomic_commit: 901 * 902 * This is the only hook to commit an atomic modeset update. The core 903 * guarantees that @atomic_check has been called successfully before 904 * calling this function, and that nothing has been changed in the 905 * interim. 906 * 907 * See the documentation for struct &drm_atomic_state for how exactly 908 * an atomic modeset update is described. 909 * 910 * Drivers using the atomic helpers can implement this hook using 911 * drm_atomic_helper_commit(), or one of the exported sub-functions of 912 * it. 913 * 914 * Nonblocking commits (as indicated with the nonblock parameter) must 915 * do any preparatory work which might result in an unsuccessful commit 916 * in the context of this callback. The only exceptions are hardware 917 * errors resulting in -EIO. But even in that case the driver must 918 * ensure that the display pipe is at least running, to avoid 919 * compositors crashing when pageflips don't work. Anything else, 920 * specifically committing the update to the hardware, should be done 921 * without blocking the caller. For updates which do not require a 922 * modeset this must be guaranteed. 923 * 924 * The driver must wait for any pending rendering to the new 925 * framebuffers to complete before executing the flip. It should also 926 * wait for any pending rendering from other drivers if the underlying 927 * buffer is a shared dma-buf. Nonblocking commits must not wait for 928 * rendering in the context of this callback. 929 * 930 * An application can request to be notified when the atomic commit has 931 * completed. These events are per-CRTC and can be distinguished by the 932 * CRTC index supplied in &drm_event to userspace. 933 * 934 * The drm core will supply a struct &drm_event in the event 935 * member of each CRTC's &drm_crtc_state structure. See the 936 * documentation for &drm_crtc_state for more details about the precise 937 * semantics of this event. 938 * 939 * NOTE: 940 * 941 * Drivers are not allowed to shut down any display pipe successfully 942 * enabled through an atomic commit on their own. Doing so can result in 943 * compositors crashing if a page flip is suddenly rejected because the 944 * pipe is off. 945 * 946 * RETURNS: 947 * 948 * 0 on success or one of the below negative error codes: 949 * 950 * - -EBUSY, if a nonblocking updated is requested and there is 951 * an earlier updated pending. Drivers are allowed to support a queue 952 * of outstanding updates, but currently no driver supports that. 953 * Note that drivers must wait for preceding updates to complete if a 954 * synchronous update is requested, they are not allowed to fail the 955 * commit in that case. 956 * 957 * - -ENOMEM, if the driver failed to allocate memory. Specifically 958 * this can happen when trying to pin framebuffers, which must only 959 * be done when committing the state. 960 * 961 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate 962 * that the driver has run out of vram, iommu space or similar GPU 963 * address space needed for framebuffer. 964 * 965 * - -EIO, if the hardware completely died. 966 * 967 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted. 968 * This can either be due to a pending signal, or because the driver 969 * needs to completely bail out to recover from an exceptional 970 * situation like a GPU hang. From a userspace point of view all errors are 971 * treated equally. 972 * 973 * This list is exhaustive. Specifically this hook is not allowed to 974 * return -EINVAL (any invalid requests should be caught in 975 * @atomic_check) or -EDEADLK (this function must not acquire 976 * additional modeset locks). 977 */ 978 int (*atomic_commit)(struct drm_device *dev, 979 struct drm_atomic_state *state, 980 bool nonblock); 981 982 /** 983 * @atomic_state_alloc: 984 * 985 * This optional hook can be used by drivers that want to subclass struct 986 * &drm_atomic_state to be able to track their own driver-private global 987 * state easily. If this hook is implemented, drivers must also 988 * implement @atomic_state_clear and @atomic_state_free. 989 * 990 * RETURNS: 991 * 992 * A new &drm_atomic_state on success or NULL on failure. 993 */ 994 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev); 995 996 /** 997 * @atomic_state_clear: 998 * 999 * This hook must clear any driver private state duplicated into the 1000 * passed-in &drm_atomic_state. This hook is called when the caller 1001 * encountered a &drm_modeset_lock deadlock and needs to drop all 1002 * already acquired locks as part of the deadlock avoidance dance 1003 * implemented in drm_modeset_lock_backoff(). 1004 * 1005 * Any duplicated state must be invalidated since a concurrent atomic 1006 * update might change it, and the drm atomic interfaces always apply 1007 * updates as relative changes to the current state. 1008 * 1009 * Drivers that implement this must call drm_atomic_state_default_clear() 1010 * to clear common state. 1011 */ 1012 void (*atomic_state_clear)(struct drm_atomic_state *state); 1013 1014 /** 1015 * @atomic_state_free: 1016 * 1017 * This hook needs driver private resources and the &drm_atomic_state 1018 * itself. Note that the core first calls drm_atomic_state_clear() to 1019 * avoid code duplicate between the clear and free hooks. 1020 * 1021 * Drivers that implement this must call drm_atomic_state_default_free() 1022 * to release common resources. 1023 */ 1024 void (*atomic_state_free)(struct drm_atomic_state *state); 1025 }; 1026 1027 /** 1028 * struct drm_mode_config - Mode configuration control structure 1029 * @mutex: mutex protecting KMS related lists and structures 1030 * @connection_mutex: ww mutex protecting connector state and routing 1031 * @acquire_ctx: global implicit acquire context used by atomic drivers for 1032 * legacy IOCTLs 1033 * @fb_lock: mutex to protect fb state and lists 1034 * @num_fb: number of fbs available 1035 * @fb_list: list of framebuffers available 1036 * @num_encoder: number of encoders on this device 1037 * @encoder_list: list of encoder objects 1038 * @num_overlay_plane: number of overlay planes on this device 1039 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device 1040 * @plane_list: list of plane objects 1041 * @num_crtc: number of CRTCs on this device 1042 * @crtc_list: list of CRTC objects 1043 * @property_list: list of property objects 1044 * @min_width: minimum pixel width on this device 1045 * @min_height: minimum pixel height on this device 1046 * @max_width: maximum pixel width on this device 1047 * @max_height: maximum pixel height on this device 1048 * @funcs: core driver provided mode setting functions 1049 * @fb_base: base address of the framebuffer 1050 * @poll_enabled: track polling support for this device 1051 * @poll_running: track polling status for this device 1052 * @delayed_event: track delayed poll uevent deliver for this device 1053 * @output_poll_work: delayed work for polling in process context 1054 * @property_blob_list: list of all the blob property objects 1055 * @blob_lock: mutex for blob property allocation and management 1056 * @*_property: core property tracking 1057 * @preferred_depth: preferred RBG pixel depth, used by fb helpers 1058 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering 1059 * @cursor_width: hint to userspace for max cursor width 1060 * @cursor_height: hint to userspace for max cursor height 1061 * @helper_private: mid-layer private data 1062 * 1063 * Core mode resource tracking structure. All CRTC, encoders, and connectors 1064 * enumerated by the driver are added here, as are global properties. Some 1065 * global restrictions are also here, e.g. dimension restrictions. 1066 */ 1067 struct drm_mode_config { 1068 struct mutex mutex; /* protects configuration (mode lists etc.) */ 1069 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */ 1070 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */ 1071 1072 /** 1073 * @idr_mutex: 1074 * 1075 * Mutex for KMS ID allocation and management. Protects both @crtc_idr 1076 * and @tile_idr. 1077 */ 1078 struct mutex idr_mutex; 1079 1080 /** 1081 * @crtc_idr: 1082 * 1083 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc, 1084 * connector, modes - just makes life easier to have only one. 1085 */ 1086 struct idr crtc_idr; 1087 1088 /** 1089 * @tile_idr: 1090 * 1091 * Use this idr for allocating new IDs for tiled sinks like use in some 1092 * high-res DP MST screens. 1093 */ 1094 struct idr tile_idr; 1095 1096 struct mutex fb_lock; /* proctects global and per-file fb lists */ 1097 int num_fb; 1098 struct list_head fb_list; 1099 1100 /** 1101 * @num_connector: Number of connectors on this device. 1102 */ 1103 int num_connector; 1104 /** 1105 * @connector_ida: ID allocator for connector indices. 1106 */ 1107 struct ida connector_ida; 1108 /** 1109 * @connector_list: List of connector objects. 1110 */ 1111 struct list_head connector_list; 1112 int num_encoder; 1113 struct list_head encoder_list; 1114 1115 /* 1116 * Track # of overlay planes separately from # of total planes. By 1117 * default we only advertise overlay planes to userspace; if userspace 1118 * sets the "universal plane" capability bit, we'll go ahead and 1119 * expose all planes. 1120 */ 1121 int num_overlay_plane; 1122 int num_total_plane; 1123 struct list_head plane_list; 1124 1125 int num_crtc; 1126 struct list_head crtc_list; 1127 1128 struct list_head property_list; 1129 1130 int min_width, min_height; 1131 int max_width, max_height; 1132 const struct drm_mode_config_funcs *funcs; 1133 resource_size_t fb_base; 1134 1135 /* output poll support */ 1136 bool poll_enabled; 1137 bool poll_running; 1138 bool delayed_event; 1139 struct delayed_work output_poll_work; 1140 1141 struct mutex blob_lock; 1142 1143 /* pointers to standard properties */ 1144 struct list_head property_blob_list; 1145 /** 1146 * @edid_property: Default connector property to hold the EDID of the 1147 * currently connected sink, if any. 1148 */ 1149 struct drm_property *edid_property; 1150 /** 1151 * @dpms_property: Default connector property to control the 1152 * connector's DPMS state. 1153 */ 1154 struct drm_property *dpms_property; 1155 /** 1156 * @path_property: Default connector property to hold the DP MST path 1157 * for the port. 1158 */ 1159 struct drm_property *path_property; 1160 /** 1161 * @tile_property: Default connector property to store the tile 1162 * position of a tiled screen, for sinks which need to be driven with 1163 * multiple CRTCs. 1164 */ 1165 struct drm_property *tile_property; 1166 /** 1167 * @plane_type_property: Default plane property to differentiate 1168 * CURSOR, PRIMARY and OVERLAY legacy uses of planes. 1169 */ 1170 struct drm_property *plane_type_property; 1171 /** 1172 * @prop_src_x: Default atomic plane property for the plane source 1173 * position in the connected &drm_framebuffer. 1174 */ 1175 struct drm_property *prop_src_x; 1176 /** 1177 * @prop_src_y: Default atomic plane property for the plane source 1178 * position in the connected &drm_framebuffer. 1179 */ 1180 struct drm_property *prop_src_y; 1181 /** 1182 * @prop_src_w: Default atomic plane property for the plane source 1183 * position in the connected &drm_framebuffer. 1184 */ 1185 struct drm_property *prop_src_w; 1186 /** 1187 * @prop_src_h: Default atomic plane property for the plane source 1188 * position in the connected &drm_framebuffer. 1189 */ 1190 struct drm_property *prop_src_h; 1191 /** 1192 * @prop_crtc_x: Default atomic plane property for the plane destination 1193 * position in the &drm_crtc is is being shown on. 1194 */ 1195 struct drm_property *prop_crtc_x; 1196 /** 1197 * @prop_crtc_y: Default atomic plane property for the plane destination 1198 * position in the &drm_crtc is is being shown on. 1199 */ 1200 struct drm_property *prop_crtc_y; 1201 /** 1202 * @prop_crtc_w: Default atomic plane property for the plane destination 1203 * position in the &drm_crtc is is being shown on. 1204 */ 1205 struct drm_property *prop_crtc_w; 1206 /** 1207 * @prop_crtc_h: Default atomic plane property for the plane destination 1208 * position in the &drm_crtc is is being shown on. 1209 */ 1210 struct drm_property *prop_crtc_h; 1211 /** 1212 * @prop_fb_id: Default atomic plane property to specify the 1213 * &drm_framebuffer. 1214 */ 1215 struct drm_property *prop_fb_id; 1216 /** 1217 * @prop_crtc_id: Default atomic plane property to specify the 1218 * &drm_crtc. 1219 */ 1220 struct drm_property *prop_crtc_id; 1221 /** 1222 * @prop_active: Default atomic CRTC property to control the active 1223 * state, which is the simplified implementation for DPMS in atomic 1224 * drivers. 1225 */ 1226 struct drm_property *prop_active; 1227 /** 1228 * @prop_mode_id: Default atomic CRTC property to set the mode for a 1229 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all 1230 * connectors must be of and active must be set to disabled, too. 1231 */ 1232 struct drm_property *prop_mode_id; 1233 1234 /** 1235 * @dvi_i_subconnector_property: Optional DVI-I property to 1236 * differentiate between analog or digital mode. 1237 */ 1238 struct drm_property *dvi_i_subconnector_property; 1239 /** 1240 * @dvi_i_select_subconnector_property: Optional DVI-I property to 1241 * select between analog or digital mode. 1242 */ 1243 struct drm_property *dvi_i_select_subconnector_property; 1244 1245 /** 1246 * @tv_subconnector_property: Optional TV property to differentiate 1247 * between different TV connector types. 1248 */ 1249 struct drm_property *tv_subconnector_property; 1250 /** 1251 * @tv_select_subconnector_property: Optional TV property to select 1252 * between different TV connector types. 1253 */ 1254 struct drm_property *tv_select_subconnector_property; 1255 /** 1256 * @tv_mode_property: Optional TV property to select 1257 * the output TV mode. 1258 */ 1259 struct drm_property *tv_mode_property; 1260 /** 1261 * @tv_left_margin_property: Optional TV property to set the left 1262 * margin. 1263 */ 1264 struct drm_property *tv_left_margin_property; 1265 /** 1266 * @tv_right_margin_property: Optional TV property to set the right 1267 * margin. 1268 */ 1269 struct drm_property *tv_right_margin_property; 1270 /** 1271 * @tv_top_margin_property: Optional TV property to set the right 1272 * margin. 1273 */ 1274 struct drm_property *tv_top_margin_property; 1275 /** 1276 * @tv_bottom_margin_property: Optional TV property to set the right 1277 * margin. 1278 */ 1279 struct drm_property *tv_bottom_margin_property; 1280 /** 1281 * @tv_brightness_property: Optional TV property to set the 1282 * brightness. 1283 */ 1284 struct drm_property *tv_brightness_property; 1285 /** 1286 * @tv_contrast_property: Optional TV property to set the 1287 * contrast. 1288 */ 1289 struct drm_property *tv_contrast_property; 1290 /** 1291 * @tv_flicker_reduction_property: Optional TV property to control the 1292 * flicker reduction mode. 1293 */ 1294 struct drm_property *tv_flicker_reduction_property; 1295 /** 1296 * @tv_overscan_property: Optional TV property to control the overscan 1297 * setting. 1298 */ 1299 struct drm_property *tv_overscan_property; 1300 /** 1301 * @tv_saturation_property: Optional TV property to set the 1302 * saturation. 1303 */ 1304 struct drm_property *tv_saturation_property; 1305 /** 1306 * @tv_hue_property: Optional TV property to set the hue. 1307 */ 1308 struct drm_property *tv_hue_property; 1309 1310 /** 1311 * @scaling_mode_property: Optional connector property to control the 1312 * upscaling, mostly used for built-in panels. 1313 */ 1314 struct drm_property *scaling_mode_property; 1315 /** 1316 * @aspect_ratio_property: Optional connector property to control the 1317 * HDMI infoframe aspect ratio setting. 1318 */ 1319 struct drm_property *aspect_ratio_property; 1320 /** 1321 * @degamma_lut_property: Optional CRTC property to set the LUT used to 1322 * convert the framebuffer's colors to linear gamma. 1323 */ 1324 struct drm_property *degamma_lut_property; 1325 /** 1326 * @degamma_lut_size_property: Optional CRTC property for the size of 1327 * the degamma LUT as supported by the driver (read-only). 1328 */ 1329 struct drm_property *degamma_lut_size_property; 1330 /** 1331 * @ctm_property: Optional CRTC property to set the 1332 * matrix used to convert colors after the lookup in the 1333 * degamma LUT. 1334 */ 1335 struct drm_property *ctm_property; 1336 /** 1337 * @gamma_lut_property: Optional CRTC property to set the LUT used to 1338 * convert the colors, after the CTM matrix, to the gamma space of the 1339 * connected screen. 1340 */ 1341 struct drm_property *gamma_lut_property; 1342 /** 1343 * @gamma_lut_size_property: Optional CRTC property for the size of the 1344 * gamma LUT as supported by the driver (read-only). 1345 */ 1346 struct drm_property *gamma_lut_size_property; 1347 1348 /** 1349 * @suggested_x_property: Optional connector property with a hint for 1350 * the position of the output on the host's screen. 1351 */ 1352 struct drm_property *suggested_x_property; 1353 /** 1354 * @suggested_y_property: Optional connector property with a hint for 1355 * the position of the output on the host's screen. 1356 */ 1357 struct drm_property *suggested_y_property; 1358 1359 /* dumb ioctl parameters */ 1360 uint32_t preferred_depth, prefer_shadow; 1361 1362 /** 1363 * @async_page_flip: Does this device support async flips on the primary 1364 * plane? 1365 */ 1366 bool async_page_flip; 1367 1368 /** 1369 * @allow_fb_modifiers: 1370 * 1371 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call. 1372 */ 1373 bool allow_fb_modifiers; 1374 1375 /* cursor size */ 1376 uint32_t cursor_width, cursor_height; 1377 1378 struct drm_mode_config_helper_funcs *helper_private; 1379 }; 1380 1381 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base) 1382 1383 extern __printf(6, 7) 1384 int drm_crtc_init_with_planes(struct drm_device *dev, 1385 struct drm_crtc *crtc, 1386 struct drm_plane *primary, 1387 struct drm_plane *cursor, 1388 const struct drm_crtc_funcs *funcs, 1389 const char *name, ...); 1390 extern void drm_crtc_cleanup(struct drm_crtc *crtc); 1391 1392 /** 1393 * drm_crtc_index - find the index of a registered CRTC 1394 * @crtc: CRTC to find index for 1395 * 1396 * Given a registered CRTC, return the index of that CRTC within a DRM 1397 * device's list of CRTCs. 1398 */ 1399 static inline unsigned int drm_crtc_index(const struct drm_crtc *crtc) 1400 { 1401 return crtc->index; 1402 } 1403 1404 /** 1405 * drm_crtc_mask - find the mask of a registered CRTC 1406 * @crtc: CRTC to find mask for 1407 * 1408 * Given a registered CRTC, return the mask bit of that CRTC for an 1409 * encoder's possible_crtcs field. 1410 */ 1411 static inline uint32_t drm_crtc_mask(const struct drm_crtc *crtc) 1412 { 1413 return 1 << drm_crtc_index(crtc); 1414 } 1415 1416 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, 1417 int *hdisplay, int *vdisplay); 1418 extern int drm_crtc_force_disable(struct drm_crtc *crtc); 1419 extern int drm_crtc_force_disable_all(struct drm_device *dev); 1420 1421 extern void drm_mode_config_init(struct drm_device *dev); 1422 extern void drm_mode_config_reset(struct drm_device *dev); 1423 extern void drm_mode_config_cleanup(struct drm_device *dev); 1424 1425 extern int drm_mode_set_config_internal(struct drm_mode_set *set); 1426 1427 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 1428 char topology[8]); 1429 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, 1430 char topology[8]); 1431 extern void drm_mode_put_tile_group(struct drm_device *dev, 1432 struct drm_tile_group *tg); 1433 1434 /* Helpers */ 1435 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev, 1436 uint32_t id) 1437 { 1438 struct drm_mode_object *mo; 1439 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC); 1440 return mo ? obj_to_crtc(mo) : NULL; 1441 } 1442 1443 #define drm_for_each_crtc(crtc, dev) \ 1444 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head) 1445 1446 static inline void 1447 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config) 1448 { 1449 /* 1450 * The connector hotadd/remove code currently grabs both locks when 1451 * updating lists. Hence readers need only hold either of them to be 1452 * safe and the check amounts to 1453 * 1454 * WARN_ON(not_holding(A) && not_holding(B)). 1455 */ 1456 WARN_ON(!mutex_is_locked(&mode_config->mutex) && 1457 !drm_modeset_is_locked(&mode_config->connection_mutex)); 1458 } 1459 1460 #endif /* __DRM_CRTC_H__ */ 1461