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 39 struct drm_device; 40 struct drm_mode_set; 41 struct drm_framebuffer; 42 struct drm_object_properties; 43 struct drm_file; 44 struct drm_clip_rect; 45 struct device_node; 46 struct fence; 47 48 struct drm_mode_object { 49 uint32_t id; 50 uint32_t type; 51 struct drm_object_properties *properties; 52 struct kref refcount; 53 void (*free_cb)(struct kref *kref); 54 }; 55 56 #define DRM_OBJECT_MAX_PROPERTY 24 57 struct drm_object_properties { 58 int count, atomic_count; 59 /* NOTE: if we ever start dynamically destroying properties (ie. 60 * not at drm_mode_config_cleanup() time), then we'd have to do 61 * a better job of detaching property from mode objects to avoid 62 * dangling property pointers: 63 */ 64 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY]; 65 /* do not read/write values directly, but use drm_object_property_get_value() 66 * and drm_object_property_set_value(): 67 */ 68 uint64_t values[DRM_OBJECT_MAX_PROPERTY]; 69 }; 70 71 static inline int64_t U642I64(uint64_t val) 72 { 73 return (int64_t)*((int64_t *)&val); 74 } 75 static inline uint64_t I642U64(int64_t val) 76 { 77 return (uint64_t)*((uint64_t *)&val); 78 } 79 80 /* 81 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the 82 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and 83 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation 84 */ 85 #define DRM_ROTATE_MASK 0x0f 86 #define DRM_ROTATE_0 0 87 #define DRM_ROTATE_90 1 88 #define DRM_ROTATE_180 2 89 #define DRM_ROTATE_270 3 90 #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK) 91 #define DRM_REFLECT_X 4 92 #define DRM_REFLECT_Y 5 93 94 enum drm_connector_force { 95 DRM_FORCE_UNSPECIFIED, 96 DRM_FORCE_OFF, 97 DRM_FORCE_ON, /* force on analog part normally */ 98 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */ 99 }; 100 101 #include <drm/drm_modes.h> 102 103 enum drm_connector_status { 104 connector_status_connected = 1, 105 connector_status_disconnected = 2, 106 connector_status_unknown = 3, 107 }; 108 109 enum subpixel_order { 110 SubPixelUnknown = 0, 111 SubPixelHorizontalRGB, 112 SubPixelHorizontalBGR, 113 SubPixelVerticalRGB, 114 SubPixelVerticalBGR, 115 SubPixelNone, 116 }; 117 118 #define DRM_COLOR_FORMAT_RGB444 (1<<0) 119 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1) 120 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2) 121 /* 122 * Describes a given display (e.g. CRT or flat panel) and its limitations. 123 */ 124 struct drm_display_info { 125 char name[DRM_DISPLAY_INFO_LEN]; 126 127 /* Physical size */ 128 unsigned int width_mm; 129 unsigned int height_mm; 130 131 /* Clock limits FIXME: storage format */ 132 unsigned int min_vfreq, max_vfreq; 133 unsigned int min_hfreq, max_hfreq; 134 unsigned int pixel_clock; 135 unsigned int bpc; 136 137 enum subpixel_order subpixel_order; 138 u32 color_formats; 139 140 const u32 *bus_formats; 141 unsigned int num_bus_formats; 142 143 /* Mask of supported hdmi deep color modes */ 144 u8 edid_hdmi_dc_modes; 145 146 u8 cea_rev; 147 }; 148 149 /* data corresponds to displayid vend/prod/serial */ 150 struct drm_tile_group { 151 struct kref refcount; 152 struct drm_device *dev; 153 int id; 154 u8 group_data[8]; 155 }; 156 157 /** 158 * struct drm_framebuffer_funcs - framebuffer hooks 159 */ 160 struct drm_framebuffer_funcs { 161 /** 162 * @destroy: 163 * 164 * Clean up framebuffer resources, specifically also unreference the 165 * backing storage. The core guarantees to call this function for every 166 * framebuffer successfully created by ->fb_create() in 167 * &drm_mode_config_funcs. Drivers must also call 168 * drm_framebuffer_cleanup() to release DRM core resources for this 169 * framebuffer. 170 */ 171 void (*destroy)(struct drm_framebuffer *framebuffer); 172 173 /** 174 * @create_handle: 175 * 176 * Create a buffer handle in the driver-specific buffer manager (either 177 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by 178 * the core to implement the GETFB IOCTL, which returns (for 179 * sufficiently priviledged user) also a native buffer handle. This can 180 * be used for seamless transitions between modesetting clients by 181 * copying the current screen contents to a private buffer and blending 182 * between that and the new contents. 183 * 184 * GEM based drivers should call drm_gem_handle_create() to create the 185 * handle. 186 * 187 * RETURNS: 188 * 189 * 0 on success or a negative error code on failure. 190 */ 191 int (*create_handle)(struct drm_framebuffer *fb, 192 struct drm_file *file_priv, 193 unsigned int *handle); 194 /** 195 * @dirty: 196 * 197 * Optional callback for the dirty fb IOCTL. 198 * 199 * Userspace can notify the driver via this callback that an area of the 200 * framebuffer has changed and should be flushed to the display 201 * hardware. This can also be used internally, e.g. by the fbdev 202 * emulation, though that's not the case currently. 203 * 204 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd 205 * for more information as all the semantics and arguments have a one to 206 * one mapping on this function. 207 * 208 * RETURNS: 209 * 210 * 0 on success or a negative error code on failure. 211 */ 212 int (*dirty)(struct drm_framebuffer *framebuffer, 213 struct drm_file *file_priv, unsigned flags, 214 unsigned color, struct drm_clip_rect *clips, 215 unsigned num_clips); 216 }; 217 218 struct drm_framebuffer { 219 struct drm_device *dev; 220 /* 221 * Note that the fb is refcounted for the benefit of driver internals, 222 * for example some hw, disabling a CRTC/plane is asynchronous, and 223 * scanout does not actually complete until the next vblank. So some 224 * cleanup (like releasing the reference(s) on the backing GEM bo(s)) 225 * should be deferred. In cases like this, the driver would like to 226 * hold a ref to the fb even though it has already been removed from 227 * userspace perspective. 228 * The refcount is stored inside the mode object. 229 */ 230 /* 231 * Place on the dev->mode_config.fb_list, access protected by 232 * dev->mode_config.fb_lock. 233 */ 234 struct list_head head; 235 struct drm_mode_object base; 236 const struct drm_framebuffer_funcs *funcs; 237 unsigned int pitches[4]; 238 unsigned int offsets[4]; 239 uint64_t modifier[4]; 240 unsigned int width; 241 unsigned int height; 242 /* depth can be 15 or 16 */ 243 unsigned int depth; 244 int bits_per_pixel; 245 int flags; 246 uint32_t pixel_format; /* fourcc format */ 247 struct list_head filp_head; 248 }; 249 250 struct drm_property_blob { 251 struct drm_mode_object base; 252 struct drm_device *dev; 253 struct list_head head_global; 254 struct list_head head_file; 255 size_t length; 256 unsigned char data[]; 257 }; 258 259 struct drm_property_enum { 260 uint64_t value; 261 struct list_head head; 262 char name[DRM_PROP_NAME_LEN]; 263 }; 264 265 struct drm_property { 266 struct list_head head; 267 struct drm_mode_object base; 268 uint32_t flags; 269 char name[DRM_PROP_NAME_LEN]; 270 uint32_t num_values; 271 uint64_t *values; 272 struct drm_device *dev; 273 274 struct list_head enum_list; 275 }; 276 277 struct drm_crtc; 278 struct drm_connector; 279 struct drm_encoder; 280 struct drm_pending_vblank_event; 281 struct drm_plane; 282 struct drm_bridge; 283 struct drm_atomic_state; 284 285 struct drm_crtc_helper_funcs; 286 struct drm_encoder_helper_funcs; 287 struct drm_connector_helper_funcs; 288 struct drm_plane_helper_funcs; 289 290 /** 291 * struct drm_crtc_state - mutable CRTC state 292 * @crtc: backpointer to the CRTC 293 * @enable: whether the CRTC should be enabled, gates all other state 294 * @active: whether the CRTC is actively displaying (used for DPMS) 295 * @planes_changed: planes on this crtc are updated 296 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed 297 * @active_changed: crtc_state->active has been toggled. 298 * @connectors_changed: connectors to this crtc have been updated 299 * @color_mgmt_changed: color management properties have changed (degamma or 300 * gamma LUT or CSC matrix) 301 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes 302 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors 303 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders 304 * @last_vblank_count: for helpers and drivers to capture the vblank of the 305 * update to ensure framebuffer cleanup isn't done too early 306 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings 307 * @mode: current mode timings 308 * @degamma_lut: Lookup table for converting framebuffer pixel data 309 * before apply the conversion matrix 310 * @ctm: Transformation matrix 311 * @gamma_lut: Lookup table for converting pixel data after the 312 * conversion matrix 313 * @event: optional pointer to a DRM event to signal upon completion of the 314 * state update 315 * @state: backpointer to global drm_atomic_state 316 * 317 * Note that the distinction between @enable and @active is rather subtile: 318 * Flipping @active while @enable is set without changing anything else may 319 * never return in a failure from the ->atomic_check callback. Userspace assumes 320 * that a DPMS On will always succeed. In other words: @enable controls resource 321 * assignment, @active controls the actual hardware state. 322 */ 323 struct drm_crtc_state { 324 struct drm_crtc *crtc; 325 326 bool enable; 327 bool active; 328 329 /* computed state bits used by helpers and drivers */ 330 bool planes_changed : 1; 331 bool mode_changed : 1; 332 bool active_changed : 1; 333 bool connectors_changed : 1; 334 bool color_mgmt_changed : 1; 335 336 /* attached planes bitmask: 337 * WARNING: transitional helpers do not maintain plane_mask so 338 * drivers not converted over to atomic helpers should not rely 339 * on plane_mask being accurate! 340 */ 341 u32 plane_mask; 342 343 u32 connector_mask; 344 u32 encoder_mask; 345 346 /* last_vblank_count: for vblank waits before cleanup */ 347 u32 last_vblank_count; 348 349 /* adjusted_mode: for use by helpers and drivers */ 350 struct drm_display_mode adjusted_mode; 351 352 struct drm_display_mode mode; 353 354 /* blob property to expose current mode to atomic userspace */ 355 struct drm_property_blob *mode_blob; 356 357 /* blob property to expose color management to userspace */ 358 struct drm_property_blob *degamma_lut; 359 struct drm_property_blob *ctm; 360 struct drm_property_blob *gamma_lut; 361 362 struct drm_pending_vblank_event *event; 363 364 struct drm_atomic_state *state; 365 }; 366 367 /** 368 * struct drm_crtc_funcs - control CRTCs for a given device 369 * 370 * The drm_crtc_funcs structure is the central CRTC management structure 371 * in the DRM. Each CRTC controls one or more connectors (note that the name 372 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc. 373 * connectors, not just CRTs). 374 * 375 * Each driver is responsible for filling out this structure at startup time, 376 * in addition to providing other modesetting features, like i2c and DDC 377 * bus accessors. 378 */ 379 struct drm_crtc_funcs { 380 /** 381 * @reset: 382 * 383 * Reset CRTC hardware and software state to off. This function isn't 384 * called by the core directly, only through drm_mode_config_reset(). 385 * It's not a helper hook only for historical reasons. 386 * 387 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset 388 * atomic state using this hook. 389 */ 390 void (*reset)(struct drm_crtc *crtc); 391 392 /** 393 * @cursor_set: 394 * 395 * Update the cursor image. The cursor position is relative to the CRTC 396 * and can be partially or fully outside of the visible area. 397 * 398 * Note that contrary to all other KMS functions the legacy cursor entry 399 * points don't take a framebuffer object, but instead take directly a 400 * raw buffer object id from the driver's buffer manager (which is 401 * either GEM or TTM for current drivers). 402 * 403 * This entry point is deprecated, drivers should instead implement 404 * universal plane support and register a proper cursor plane using 405 * drm_crtc_init_with_planes(). 406 * 407 * This callback is optional 408 * 409 * RETURNS: 410 * 411 * 0 on success or a negative error code on failure. 412 */ 413 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv, 414 uint32_t handle, uint32_t width, uint32_t height); 415 416 /** 417 * @cursor_set2: 418 * 419 * Update the cursor image, including hotspot information. The hotspot 420 * must not affect the cursor position in CRTC coordinates, but is only 421 * meant as a hint for virtualized display hardware to coordinate the 422 * guests and hosts cursor position. The cursor hotspot is relative to 423 * the cursor image. Otherwise this works exactly like @cursor_set. 424 * 425 * This entry point is deprecated, drivers should instead implement 426 * universal plane support and register a proper cursor plane using 427 * drm_crtc_init_with_planes(). 428 * 429 * This callback is optional. 430 * 431 * RETURNS: 432 * 433 * 0 on success or a negative error code on failure. 434 */ 435 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv, 436 uint32_t handle, uint32_t width, uint32_t height, 437 int32_t hot_x, int32_t hot_y); 438 439 /** 440 * @cursor_move: 441 * 442 * Update the cursor position. The cursor does not need to be visible 443 * when this hook is called. 444 * 445 * This entry point is deprecated, drivers should instead implement 446 * universal plane support and register a proper cursor plane using 447 * drm_crtc_init_with_planes(). 448 * 449 * This callback is optional. 450 * 451 * RETURNS: 452 * 453 * 0 on success or a negative error code on failure. 454 */ 455 int (*cursor_move)(struct drm_crtc *crtc, int x, int y); 456 457 /** 458 * @gamma_set: 459 * 460 * Set gamma on the CRTC. 461 * 462 * This callback is optional. 463 * 464 * NOTE: 465 * 466 * Drivers that support gamma tables and also fbdev emulation through 467 * the provided helper library need to take care to fill out the gamma 468 * hooks for both. Currently there's a bit an unfortunate duplication 469 * going on, which should eventually be unified to just one set of 470 * hooks. 471 */ 472 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, 473 uint32_t start, uint32_t size); 474 475 /** 476 * @destroy: 477 * 478 * Clean up plane resources. This is only called at driver unload time 479 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged 480 * in DRM. 481 */ 482 void (*destroy)(struct drm_crtc *crtc); 483 484 /** 485 * @set_config: 486 * 487 * This is the main legacy entry point to change the modeset state on a 488 * CRTC. All the details of the desired configuration are passed in a 489 * struct &drm_mode_set - see there for details. 490 * 491 * Drivers implementing atomic modeset should use 492 * drm_atomic_helper_set_config() to implement this hook. 493 * 494 * RETURNS: 495 * 496 * 0 on success or a negative error code on failure. 497 */ 498 int (*set_config)(struct drm_mode_set *set); 499 500 /** 501 * @page_flip: 502 * 503 * Legacy entry point to schedule a flip to the given framebuffer. 504 * 505 * Page flipping is a synchronization mechanism that replaces the frame 506 * buffer being scanned out by the CRTC with a new frame buffer during 507 * vertical blanking, avoiding tearing (except when requested otherwise 508 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application 509 * requests a page flip the DRM core verifies that the new frame buffer 510 * is large enough to be scanned out by the CRTC in the currently 511 * configured mode and then calls the CRTC ->page_flip() operation with a 512 * pointer to the new frame buffer. 513 * 514 * The driver must wait for any pending rendering to the new framebuffer 515 * to complete before executing the flip. It should also wait for any 516 * pending rendering from other drivers if the underlying buffer is a 517 * shared dma-buf. 518 * 519 * An application can request to be notified when the page flip has 520 * completed. The drm core will supply a struct &drm_event in the event 521 * parameter in this case. This can be handled by the 522 * drm_crtc_send_vblank_event() function, which the driver should call on 523 * the provided event upon completion of the flip. Note that if 524 * the driver supports vblank signalling and timestamping the vblank 525 * counters and timestamps must agree with the ones returned from page 526 * flip events. With the current vblank helper infrastructure this can 527 * be achieved by holding a vblank reference while the page flip is 528 * pending, acquired through drm_crtc_vblank_get() and released with 529 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank 530 * counter and timestamp tracking though, e.g. if they have accurate 531 * timestamp registers in hardware. 532 * 533 * FIXME: 534 * 535 * Up to that point drivers need to manage events themselves and can use 536 * even->base.list freely for that. Specifically they need to ensure 537 * that they don't send out page flip (or vblank) events for which the 538 * corresponding drm file has been closed already. The drm core 539 * unfortunately does not (yet) take care of that. Therefore drivers 540 * currently must clean up and release pending events in their 541 * ->preclose driver function. 542 * 543 * This callback is optional. 544 * 545 * NOTE: 546 * 547 * Very early versions of the KMS ABI mandated that the driver must 548 * block (but not reject) any rendering to the old framebuffer until the 549 * flip operation has completed and the old framebuffer is no longer 550 * visible. This requirement has been lifted, and userspace is instead 551 * expected to request delivery of an event and wait with recycling old 552 * buffers until such has been received. 553 * 554 * RETURNS: 555 * 556 * 0 on success or a negative error code on failure. Note that if a 557 * ->page_flip() operation is already pending the callback should return 558 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode 559 * or just runtime disabled through DPMS respectively the new atomic 560 * "ACTIVE" state) should result in an -EINVAL error code. Note that 561 * drm_atomic_helper_page_flip() checks this already for atomic drivers. 562 */ 563 int (*page_flip)(struct drm_crtc *crtc, 564 struct drm_framebuffer *fb, 565 struct drm_pending_vblank_event *event, 566 uint32_t flags); 567 568 /** 569 * @set_property: 570 * 571 * This is the legacy entry point to update a property attached to the 572 * CRTC. 573 * 574 * Drivers implementing atomic modeset should use 575 * drm_atomic_helper_crtc_set_property() to implement this hook. 576 * 577 * This callback is optional if the driver does not support any legacy 578 * driver-private properties. 579 * 580 * RETURNS: 581 * 582 * 0 on success or a negative error code on failure. 583 */ 584 int (*set_property)(struct drm_crtc *crtc, 585 struct drm_property *property, uint64_t val); 586 587 /** 588 * @atomic_duplicate_state: 589 * 590 * Duplicate the current atomic state for this CRTC and return it. 591 * The core and helpers gurantee that any atomic state duplicated with 592 * this hook and still owned by the caller (i.e. not transferred to the 593 * driver by calling ->atomic_commit() from struct 594 * &drm_mode_config_funcs) will be cleaned up by calling the 595 * @atomic_destroy_state hook in this structure. 596 * 597 * Atomic drivers which don't subclass struct &drm_crtc should use 598 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the 599 * state structure to extend it with driver-private state should use 600 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is 601 * duplicated in a consistent fashion across drivers. 602 * 603 * It is an error to call this hook before crtc->state has been 604 * initialized correctly. 605 * 606 * NOTE: 607 * 608 * If the duplicate state references refcounted resources this hook must 609 * acquire a reference for each of them. The driver must release these 610 * references again in @atomic_destroy_state. 611 * 612 * RETURNS: 613 * 614 * Duplicated atomic state or NULL when the allocation failed. 615 */ 616 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc); 617 618 /** 619 * @atomic_destroy_state: 620 * 621 * Destroy a state duplicated with @atomic_duplicate_state and release 622 * or unreference all resources it references 623 */ 624 void (*atomic_destroy_state)(struct drm_crtc *crtc, 625 struct drm_crtc_state *state); 626 627 /** 628 * @atomic_set_property: 629 * 630 * Decode a driver-private property value and store the decoded value 631 * into the passed-in state structure. Since the atomic core decodes all 632 * standardized properties (even for extensions beyond the core set of 633 * properties which might not be implemented by all drivers) this 634 * requires drivers to subclass the state structure. 635 * 636 * Such driver-private properties should really only be implemented for 637 * truly hardware/vendor specific state. Instead it is preferred to 638 * standardize atomic extension and decode the properties used to expose 639 * such an extension in the core. 640 * 641 * Do not call this function directly, use 642 * drm_atomic_crtc_set_property() instead. 643 * 644 * This callback is optional if the driver does not support any 645 * driver-private atomic properties. 646 * 647 * NOTE: 648 * 649 * This function is called in the state assembly phase of atomic 650 * modesets, which can be aborted for any reason (including on 651 * userspace's request to just check whether a configuration would be 652 * possible). Drivers MUST NOT touch any persistent state (hardware or 653 * software) or data structures except the passed in @state parameter. 654 * 655 * Also since userspace controls in which order properties are set this 656 * function must not do any input validation (since the state update is 657 * incomplete and hence likely inconsistent). Instead any such input 658 * validation must be done in the various atomic_check callbacks. 659 * 660 * RETURNS: 661 * 662 * 0 if the property has been found, -EINVAL if the property isn't 663 * implemented by the driver (which should never happen, the core only 664 * asks for properties attached to this CRTC). No other validation is 665 * allowed by the driver. The core already checks that the property 666 * value is within the range (integer, valid enum value, ...) the driver 667 * set when registering the property. 668 */ 669 int (*atomic_set_property)(struct drm_crtc *crtc, 670 struct drm_crtc_state *state, 671 struct drm_property *property, 672 uint64_t val); 673 /** 674 * @atomic_get_property: 675 * 676 * Reads out the decoded driver-private property. This is used to 677 * implement the GETCRTC IOCTL. 678 * 679 * Do not call this function directly, use 680 * drm_atomic_crtc_get_property() instead. 681 * 682 * This callback is optional if the driver does not support any 683 * driver-private atomic properties. 684 * 685 * RETURNS: 686 * 687 * 0 on success, -EINVAL if the property isn't implemented by the 688 * driver (which should never happen, the core only asks for 689 * properties attached to this CRTC). 690 */ 691 int (*atomic_get_property)(struct drm_crtc *crtc, 692 const struct drm_crtc_state *state, 693 struct drm_property *property, 694 uint64_t *val); 695 }; 696 697 /** 698 * struct drm_crtc - central CRTC control structure 699 * @dev: parent DRM device 700 * @port: OF node used by drm_of_find_possible_crtcs() 701 * @head: list management 702 * @mutex: per-CRTC locking 703 * @base: base KMS object for ID tracking etc. 704 * @primary: primary plane for this CRTC 705 * @cursor: cursor plane for this CRTC 706 * @cursor_x: current x position of the cursor, used for universal cursor planes 707 * @cursor_y: current y position of the cursor, used for universal cursor planes 708 * @enabled: is this CRTC enabled? 709 * @mode: current mode timings 710 * @hwmode: mode timings as programmed to hw regs 711 * @x: x position on screen 712 * @y: y position on screen 713 * @funcs: CRTC control functions 714 * @gamma_size: size of gamma ramp 715 * @gamma_store: gamma ramp values 716 * @helper_private: mid-layer private data 717 * @properties: property tracking for this CRTC 718 * @state: current atomic state for this CRTC 719 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for 720 * legacy IOCTLs 721 * 722 * Each CRTC may have one or more connectors associated with it. This structure 723 * allows the CRTC to be controlled. 724 */ 725 struct drm_crtc { 726 struct drm_device *dev; 727 struct device_node *port; 728 struct list_head head; 729 730 char *name; 731 732 /* 733 * crtc mutex 734 * 735 * This provides a read lock for the overall crtc state (mode, dpms 736 * state, ...) and a write lock for everything which can be update 737 * without a full modeset (fb, cursor data, ...) 738 */ 739 struct drm_modeset_lock mutex; 740 741 struct drm_mode_object base; 742 743 /* primary and cursor planes for CRTC */ 744 struct drm_plane *primary; 745 struct drm_plane *cursor; 746 747 /* position of cursor plane on crtc */ 748 int cursor_x; 749 int cursor_y; 750 751 bool enabled; 752 753 /* Requested mode from modesetting. */ 754 struct drm_display_mode mode; 755 756 /* Programmed mode in hw, after adjustments for encoders, 757 * crtc, panel scaling etc. Needed for timestamping etc. 758 */ 759 struct drm_display_mode hwmode; 760 761 int x, y; 762 const struct drm_crtc_funcs *funcs; 763 764 /* Legacy FB CRTC gamma size for reporting to userspace */ 765 uint32_t gamma_size; 766 uint16_t *gamma_store; 767 768 /* if you are using the helper */ 769 const struct drm_crtc_helper_funcs *helper_private; 770 771 struct drm_object_properties properties; 772 773 struct drm_crtc_state *state; 774 775 /* 776 * For legacy crtc IOCTLs so that atomic drivers can get at the locking 777 * acquire context. 778 */ 779 struct drm_modeset_acquire_ctx *acquire_ctx; 780 }; 781 782 /** 783 * struct drm_connector_state - mutable connector state 784 * @connector: backpointer to the connector 785 * @crtc: CRTC to connect connector to, NULL if disabled 786 * @best_encoder: can be used by helpers and drivers to select the encoder 787 * @state: backpointer to global drm_atomic_state 788 */ 789 struct drm_connector_state { 790 struct drm_connector *connector; 791 792 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */ 793 794 struct drm_encoder *best_encoder; 795 796 struct drm_atomic_state *state; 797 }; 798 799 /** 800 * struct drm_connector_funcs - control connectors on a given device 801 * 802 * Each CRTC may have one or more connectors attached to it. The functions 803 * below allow the core DRM code to control connectors, enumerate available modes, 804 * etc. 805 */ 806 struct drm_connector_funcs { 807 /** 808 * @dpms: 809 * 810 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS 811 * is exposed as a standard property on the connector, but diverted to 812 * this callback in the drm core. Note that atomic drivers don't 813 * implement the 4 level DPMS support on the connector any more, but 814 * instead only have an on/off "ACTIVE" property on the CRTC object. 815 * 816 * Drivers implementing atomic modeset should use 817 * drm_atomic_helper_connector_dpms() to implement this hook. 818 * 819 * RETURNS: 820 * 821 * 0 on success or a negative error code on failure. 822 */ 823 int (*dpms)(struct drm_connector *connector, int mode); 824 825 /** 826 * @reset: 827 * 828 * Reset connector hardware and software state to off. This function isn't 829 * called by the core directly, only through drm_mode_config_reset(). 830 * It's not a helper hook only for historical reasons. 831 * 832 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset 833 * atomic state using this hook. 834 */ 835 void (*reset)(struct drm_connector *connector); 836 837 /** 838 * @detect: 839 * 840 * Check to see if anything is attached to the connector. The parameter 841 * force is set to false whilst polling, true when checking the 842 * connector due to a user request. force can be used by the driver to 843 * avoid expensive, destructive operations during automated probing. 844 * 845 * FIXME: 846 * 847 * Note that this hook is only called by the probe helper. It's not in 848 * the helper library vtable purely for historical reasons. The only DRM 849 * core entry point to probe connector state is @fill_modes. 850 * 851 * RETURNS: 852 * 853 * drm_connector_status indicating the connector's status. 854 */ 855 enum drm_connector_status (*detect)(struct drm_connector *connector, 856 bool force); 857 858 /** 859 * @force: 860 * 861 * This function is called to update internal encoder state when the 862 * connector is forced to a certain state by userspace, either through 863 * the sysfs interfaces or on the kernel cmdline. In that case the 864 * @detect callback isn't called. 865 * 866 * FIXME: 867 * 868 * Note that this hook is only called by the probe helper. It's not in 869 * the helper library vtable purely for historical reasons. The only DRM 870 * core entry point to probe connector state is @fill_modes. 871 */ 872 void (*force)(struct drm_connector *connector); 873 874 /** 875 * @fill_modes: 876 * 877 * Entry point for output detection and basic mode validation. The 878 * driver should reprobe the output if needed (e.g. when hotplug 879 * handling is unreliable), add all detected modes to connector->modes 880 * and filter out any the device can't support in any configuration. It 881 * also needs to filter out any modes wider or higher than the 882 * parameters max_width and max_height indicate. 883 * 884 * The drivers must also prune any modes no longer valid from 885 * connector->modes. Furthermore it must update connector->status and 886 * connector->edid. If no EDID has been received for this output 887 * connector->edid must be NULL. 888 * 889 * Drivers using the probe helpers should use 890 * drm_helper_probe_single_connector_modes() or 891 * drm_helper_probe_single_connector_modes_nomerge() to implement this 892 * function. 893 * 894 * RETURNS: 895 * 896 * The number of modes detected and filled into connector->modes. 897 */ 898 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height); 899 900 /** 901 * @set_property: 902 * 903 * This is the legacy entry point to update a property attached to the 904 * connector. 905 * 906 * Drivers implementing atomic modeset should use 907 * drm_atomic_helper_connector_set_property() to implement this hook. 908 * 909 * This callback is optional if the driver does not support any legacy 910 * driver-private properties. 911 * 912 * RETURNS: 913 * 914 * 0 on success or a negative error code on failure. 915 */ 916 int (*set_property)(struct drm_connector *connector, struct drm_property *property, 917 uint64_t val); 918 919 /** 920 * @destroy: 921 * 922 * Clean up connector resources. This is called at driver unload time 923 * through drm_mode_config_cleanup(). It can also be called at runtime 924 * when a connector is being hot-unplugged for drivers that support 925 * connector hotplugging (e.g. DisplayPort MST). 926 */ 927 void (*destroy)(struct drm_connector *connector); 928 929 /** 930 * @atomic_duplicate_state: 931 * 932 * Duplicate the current atomic state for this connector and return it. 933 * The core and helpers gurantee that any atomic state duplicated with 934 * this hook and still owned by the caller (i.e. not transferred to the 935 * driver by calling ->atomic_commit() from struct 936 * &drm_mode_config_funcs) will be cleaned up by calling the 937 * @atomic_destroy_state hook in this structure. 938 * 939 * Atomic drivers which don't subclass struct &drm_connector_state should use 940 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the 941 * state structure to extend it with driver-private state should use 942 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is 943 * duplicated in a consistent fashion across drivers. 944 * 945 * It is an error to call this hook before connector->state has been 946 * initialized correctly. 947 * 948 * NOTE: 949 * 950 * If the duplicate state references refcounted resources this hook must 951 * acquire a reference for each of them. The driver must release these 952 * references again in @atomic_destroy_state. 953 * 954 * RETURNS: 955 * 956 * Duplicated atomic state or NULL when the allocation failed. 957 */ 958 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector); 959 960 /** 961 * @atomic_destroy_state: 962 * 963 * Destroy a state duplicated with @atomic_duplicate_state and release 964 * or unreference all resources it references 965 */ 966 void (*atomic_destroy_state)(struct drm_connector *connector, 967 struct drm_connector_state *state); 968 969 /** 970 * @atomic_set_property: 971 * 972 * Decode a driver-private property value and store the decoded value 973 * into the passed-in state structure. Since the atomic core decodes all 974 * standardized properties (even for extensions beyond the core set of 975 * properties which might not be implemented by all drivers) this 976 * requires drivers to subclass the state structure. 977 * 978 * Such driver-private properties should really only be implemented for 979 * truly hardware/vendor specific state. Instead it is preferred to 980 * standardize atomic extension and decode the properties used to expose 981 * such an extension in the core. 982 * 983 * Do not call this function directly, use 984 * drm_atomic_connector_set_property() instead. 985 * 986 * This callback is optional if the driver does not support any 987 * driver-private atomic properties. 988 * 989 * NOTE: 990 * 991 * This function is called in the state assembly phase of atomic 992 * modesets, which can be aborted for any reason (including on 993 * userspace's request to just check whether a configuration would be 994 * possible). Drivers MUST NOT touch any persistent state (hardware or 995 * software) or data structures except the passed in @state parameter. 996 * 997 * Also since userspace controls in which order properties are set this 998 * function must not do any input validation (since the state update is 999 * incomplete and hence likely inconsistent). Instead any such input 1000 * validation must be done in the various atomic_check callbacks. 1001 * 1002 * RETURNS: 1003 * 1004 * 0 if the property has been found, -EINVAL if the property isn't 1005 * implemented by the driver (which shouldn't ever happen, the core only 1006 * asks for properties attached to this connector). No other validation 1007 * is allowed by the driver. The core already checks that the property 1008 * value is within the range (integer, valid enum value, ...) the driver 1009 * set when registering the property. 1010 */ 1011 int (*atomic_set_property)(struct drm_connector *connector, 1012 struct drm_connector_state *state, 1013 struct drm_property *property, 1014 uint64_t val); 1015 1016 /** 1017 * @atomic_get_property: 1018 * 1019 * Reads out the decoded driver-private property. This is used to 1020 * implement the GETCONNECTOR IOCTL. 1021 * 1022 * Do not call this function directly, use 1023 * drm_atomic_connector_get_property() instead. 1024 * 1025 * This callback is optional if the driver does not support any 1026 * driver-private atomic properties. 1027 * 1028 * RETURNS: 1029 * 1030 * 0 on success, -EINVAL if the property isn't implemented by the 1031 * driver (which shouldn't ever happen, the core only asks for 1032 * properties attached to this connector). 1033 */ 1034 int (*atomic_get_property)(struct drm_connector *connector, 1035 const struct drm_connector_state *state, 1036 struct drm_property *property, 1037 uint64_t *val); 1038 }; 1039 1040 /** 1041 * struct drm_encoder_funcs - encoder controls 1042 * 1043 * Encoders sit between CRTCs and connectors. 1044 */ 1045 struct drm_encoder_funcs { 1046 /** 1047 * @reset: 1048 * 1049 * Reset encoder hardware and software state to off. This function isn't 1050 * called by the core directly, only through drm_mode_config_reset(). 1051 * It's not a helper hook only for historical reasons. 1052 */ 1053 void (*reset)(struct drm_encoder *encoder); 1054 1055 /** 1056 * @destroy: 1057 * 1058 * Clean up encoder resources. This is only called at driver unload time 1059 * through drm_mode_config_cleanup() since an encoder cannot be 1060 * hotplugged in DRM. 1061 */ 1062 void (*destroy)(struct drm_encoder *encoder); 1063 }; 1064 1065 #define DRM_CONNECTOR_MAX_ENCODER 3 1066 1067 /** 1068 * struct drm_encoder - central DRM encoder structure 1069 * @dev: parent DRM device 1070 * @head: list management 1071 * @base: base KMS object 1072 * @name: encoder name 1073 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h 1074 * @possible_crtcs: bitmask of potential CRTC bindings 1075 * @possible_clones: bitmask of potential sibling encoders for cloning 1076 * @crtc: currently bound CRTC 1077 * @bridge: bridge associated to the encoder 1078 * @funcs: control functions 1079 * @helper_private: mid-layer private data 1080 * 1081 * CRTCs drive pixels to encoders, which convert them into signals 1082 * appropriate for a given connector or set of connectors. 1083 */ 1084 struct drm_encoder { 1085 struct drm_device *dev; 1086 struct list_head head; 1087 1088 struct drm_mode_object base; 1089 char *name; 1090 int encoder_type; 1091 uint32_t possible_crtcs; 1092 uint32_t possible_clones; 1093 1094 struct drm_crtc *crtc; 1095 struct drm_bridge *bridge; 1096 const struct drm_encoder_funcs *funcs; 1097 const struct drm_encoder_helper_funcs *helper_private; 1098 }; 1099 1100 /* should we poll this connector for connects and disconnects */ 1101 /* hot plug detectable */ 1102 #define DRM_CONNECTOR_POLL_HPD (1 << 0) 1103 /* poll for connections */ 1104 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1) 1105 /* can cleanly poll for disconnections without flickering the screen */ 1106 /* DACs should rarely do this without a lot of testing */ 1107 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2) 1108 1109 #define MAX_ELD_BYTES 128 1110 1111 /** 1112 * struct drm_connector - central DRM connector control structure 1113 * @dev: parent DRM device 1114 * @kdev: kernel device for sysfs attributes 1115 * @attr: sysfs attributes 1116 * @head: list management 1117 * @base: base KMS object 1118 * @name: connector name 1119 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h 1120 * @connector_type_id: index into connector type enum 1121 * @interlace_allowed: can this connector handle interlaced modes? 1122 * @doublescan_allowed: can this connector handle doublescan? 1123 * @stereo_allowed: can this connector handle stereo modes? 1124 * @modes: modes available on this connector (from fill_modes() + user) 1125 * @status: one of the drm_connector_status enums (connected, not, or unknown) 1126 * @probed_modes: list of modes derived directly from the display 1127 * @display_info: information about attached display (e.g. from EDID) 1128 * @funcs: connector control functions 1129 * @edid_blob_ptr: DRM property containing EDID if present 1130 * @properties: property tracking for this connector 1131 * @path_blob_ptr: DRM blob property data for the DP MST path property 1132 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling 1133 * @dpms: current dpms state 1134 * @helper_private: mid-layer private data 1135 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector 1136 * @force: a %DRM_FORCE_<foo> state for forced mode sets 1137 * @override_edid: has the EDID been overwritten through debugfs for testing? 1138 * @encoder_ids: valid encoders for this connector 1139 * @encoder: encoder driving this connector, if any 1140 * @eld: EDID-like data, if present 1141 * @dvi_dual: dual link DVI, if found 1142 * @max_tmds_clock: max clock rate, if found 1143 * @latency_present: AV delay info from ELD, if found 1144 * @video_latency: video latency info from ELD, if found 1145 * @audio_latency: audio latency info from ELD, if found 1146 * @null_edid_counter: track sinks that give us all zeros for the EDID 1147 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum 1148 * @edid_corrupt: indicates whether the last read EDID was corrupt 1149 * @debugfs_entry: debugfs directory for this connector 1150 * @state: current atomic state for this connector 1151 * @has_tile: is this connector connected to a tiled monitor 1152 * @tile_group: tile group for the connected monitor 1153 * @tile_is_single_monitor: whether the tile is one monitor housing 1154 * @num_h_tile: number of horizontal tiles in the tile group 1155 * @num_v_tile: number of vertical tiles in the tile group 1156 * @tile_h_loc: horizontal location of this tile 1157 * @tile_v_loc: vertical location of this tile 1158 * @tile_h_size: horizontal size of this tile. 1159 * @tile_v_size: vertical size of this tile. 1160 * 1161 * Each connector may be connected to one or more CRTCs, or may be clonable by 1162 * another connector if they can share a CRTC. Each connector also has a specific 1163 * position in the broader display (referred to as a 'screen' though it could 1164 * span multiple monitors). 1165 */ 1166 struct drm_connector { 1167 struct drm_device *dev; 1168 struct device *kdev; 1169 struct device_attribute *attr; 1170 struct list_head head; 1171 1172 struct drm_mode_object base; 1173 1174 char *name; 1175 int connector_id; 1176 int connector_type; 1177 int connector_type_id; 1178 bool interlace_allowed; 1179 bool doublescan_allowed; 1180 bool stereo_allowed; 1181 struct list_head modes; /* list of modes on this connector */ 1182 1183 enum drm_connector_status status; 1184 1185 /* these are modes added by probing with DDC or the BIOS */ 1186 struct list_head probed_modes; 1187 1188 struct drm_display_info display_info; 1189 const struct drm_connector_funcs *funcs; 1190 1191 struct drm_property_blob *edid_blob_ptr; 1192 struct drm_object_properties properties; 1193 1194 struct drm_property_blob *path_blob_ptr; 1195 1196 struct drm_property_blob *tile_blob_ptr; 1197 1198 uint8_t polled; /* DRM_CONNECTOR_POLL_* */ 1199 1200 /* requested DPMS state */ 1201 int dpms; 1202 1203 const struct drm_connector_helper_funcs *helper_private; 1204 1205 /* forced on connector */ 1206 struct drm_cmdline_mode cmdline_mode; 1207 enum drm_connector_force force; 1208 bool override_edid; 1209 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER]; 1210 struct drm_encoder *encoder; /* currently active encoder */ 1211 1212 /* EDID bits */ 1213 uint8_t eld[MAX_ELD_BYTES]; 1214 bool dvi_dual; 1215 int max_tmds_clock; /* in MHz */ 1216 bool latency_present[2]; 1217 int video_latency[2]; /* [0]: progressive, [1]: interlaced */ 1218 int audio_latency[2]; 1219 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */ 1220 unsigned bad_edid_counter; 1221 1222 /* Flag for raw EDID header corruption - used in Displayport 1223 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6 1224 */ 1225 bool edid_corrupt; 1226 1227 struct dentry *debugfs_entry; 1228 1229 struct drm_connector_state *state; 1230 1231 /* DisplayID bits */ 1232 bool has_tile; 1233 struct drm_tile_group *tile_group; 1234 bool tile_is_single_monitor; 1235 1236 uint8_t num_h_tile, num_v_tile; 1237 uint8_t tile_h_loc, tile_v_loc; 1238 uint16_t tile_h_size, tile_v_size; 1239 }; 1240 1241 /** 1242 * struct drm_plane_state - mutable plane state 1243 * @plane: backpointer to the plane 1244 * @crtc: currently bound CRTC, NULL if disabled 1245 * @fb: currently bound framebuffer 1246 * @fence: optional fence to wait for before scanning out @fb 1247 * @crtc_x: left position of visible portion of plane on crtc 1248 * @crtc_y: upper position of visible portion of plane on crtc 1249 * @crtc_w: width of visible portion of plane on crtc 1250 * @crtc_h: height of visible portion of plane on crtc 1251 * @src_x: left position of visible portion of plane within 1252 * plane (in 16.16) 1253 * @src_y: upper position of visible portion of plane within 1254 * plane (in 16.16) 1255 * @src_w: width of visible portion of plane (in 16.16) 1256 * @src_h: height of visible portion of plane (in 16.16) 1257 * @state: backpointer to global drm_atomic_state 1258 */ 1259 struct drm_plane_state { 1260 struct drm_plane *plane; 1261 1262 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */ 1263 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */ 1264 struct fence *fence; 1265 1266 /* Signed dest location allows it to be partially off screen */ 1267 int32_t crtc_x, crtc_y; 1268 uint32_t crtc_w, crtc_h; 1269 1270 /* Source values are 16.16 fixed point */ 1271 uint32_t src_x, src_y; 1272 uint32_t src_h, src_w; 1273 1274 /* Plane rotation */ 1275 unsigned int rotation; 1276 1277 struct drm_atomic_state *state; 1278 }; 1279 1280 1281 /** 1282 * struct drm_plane_funcs - driver plane control functions 1283 */ 1284 struct drm_plane_funcs { 1285 /** 1286 * @update_plane: 1287 * 1288 * This is the legacy entry point to enable and configure the plane for 1289 * the given CRTC and framebuffer. It is never called to disable the 1290 * plane, i.e. the passed-in crtc and fb paramters are never NULL. 1291 * 1292 * The source rectangle in frame buffer memory coordinates is given by 1293 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point 1294 * values). Devices that don't support subpixel plane coordinates can 1295 * ignore the fractional part. 1296 * 1297 * The destination rectangle in CRTC coordinates is given by the 1298 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values). 1299 * Devices scale the source rectangle to the destination rectangle. If 1300 * scaling is not supported, and the source rectangle size doesn't match 1301 * the destination rectangle size, the driver must return a 1302 * -<errorname>EINVAL</errorname> error. 1303 * 1304 * Drivers implementing atomic modeset should use 1305 * drm_atomic_helper_update_plane() to implement this hook. 1306 * 1307 * RETURNS: 1308 * 1309 * 0 on success or a negative error code on failure. 1310 */ 1311 int (*update_plane)(struct drm_plane *plane, 1312 struct drm_crtc *crtc, struct drm_framebuffer *fb, 1313 int crtc_x, int crtc_y, 1314 unsigned int crtc_w, unsigned int crtc_h, 1315 uint32_t src_x, uint32_t src_y, 1316 uint32_t src_w, uint32_t src_h); 1317 1318 /** 1319 * @disable_plane: 1320 * 1321 * This is the legacy entry point to disable the plane. The DRM core 1322 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call 1323 * with the frame buffer ID set to 0. Disabled planes must not be 1324 * processed by the CRTC. 1325 * 1326 * Drivers implementing atomic modeset should use 1327 * drm_atomic_helper_disable_plane() to implement this hook. 1328 * 1329 * RETURNS: 1330 * 1331 * 0 on success or a negative error code on failure. 1332 */ 1333 int (*disable_plane)(struct drm_plane *plane); 1334 1335 /** 1336 * @destroy: 1337 * 1338 * Clean up plane resources. This is only called at driver unload time 1339 * through drm_mode_config_cleanup() since a plane cannot be hotplugged 1340 * in DRM. 1341 */ 1342 void (*destroy)(struct drm_plane *plane); 1343 1344 /** 1345 * @reset: 1346 * 1347 * Reset plane hardware and software state to off. This function isn't 1348 * called by the core directly, only through drm_mode_config_reset(). 1349 * It's not a helper hook only for historical reasons. 1350 * 1351 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset 1352 * atomic state using this hook. 1353 */ 1354 void (*reset)(struct drm_plane *plane); 1355 1356 /** 1357 * @set_property: 1358 * 1359 * This is the legacy entry point to update a property attached to the 1360 * plane. 1361 * 1362 * Drivers implementing atomic modeset should use 1363 * drm_atomic_helper_plane_set_property() to implement this hook. 1364 * 1365 * This callback is optional if the driver does not support any legacy 1366 * driver-private properties. 1367 * 1368 * RETURNS: 1369 * 1370 * 0 on success or a negative error code on failure. 1371 */ 1372 int (*set_property)(struct drm_plane *plane, 1373 struct drm_property *property, uint64_t val); 1374 1375 /** 1376 * @atomic_duplicate_state: 1377 * 1378 * Duplicate the current atomic state for this plane and return it. 1379 * The core and helpers gurantee that any atomic state duplicated with 1380 * this hook and still owned by the caller (i.e. not transferred to the 1381 * driver by calling ->atomic_commit() from struct 1382 * &drm_mode_config_funcs) will be cleaned up by calling the 1383 * @atomic_destroy_state hook in this structure. 1384 * 1385 * Atomic drivers which don't subclass struct &drm_plane_state should use 1386 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the 1387 * state structure to extend it with driver-private state should use 1388 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is 1389 * duplicated in a consistent fashion across drivers. 1390 * 1391 * It is an error to call this hook before plane->state has been 1392 * initialized correctly. 1393 * 1394 * NOTE: 1395 * 1396 * If the duplicate state references refcounted resources this hook must 1397 * acquire a reference for each of them. The driver must release these 1398 * references again in @atomic_destroy_state. 1399 * 1400 * RETURNS: 1401 * 1402 * Duplicated atomic state or NULL when the allocation failed. 1403 */ 1404 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane); 1405 1406 /** 1407 * @atomic_destroy_state: 1408 * 1409 * Destroy a state duplicated with @atomic_duplicate_state and release 1410 * or unreference all resources it references 1411 */ 1412 void (*atomic_destroy_state)(struct drm_plane *plane, 1413 struct drm_plane_state *state); 1414 1415 /** 1416 * @atomic_set_property: 1417 * 1418 * Decode a driver-private property value and store the decoded value 1419 * into the passed-in state structure. Since the atomic core decodes all 1420 * standardized properties (even for extensions beyond the core set of 1421 * properties which might not be implemented by all drivers) this 1422 * requires drivers to subclass the state structure. 1423 * 1424 * Such driver-private properties should really only be implemented for 1425 * truly hardware/vendor specific state. Instead it is preferred to 1426 * standardize atomic extension and decode the properties used to expose 1427 * such an extension in the core. 1428 * 1429 * Do not call this function directly, use 1430 * drm_atomic_plane_set_property() instead. 1431 * 1432 * This callback is optional if the driver does not support any 1433 * driver-private atomic properties. 1434 * 1435 * NOTE: 1436 * 1437 * This function is called in the state assembly phase of atomic 1438 * modesets, which can be aborted for any reason (including on 1439 * userspace's request to just check whether a configuration would be 1440 * possible). Drivers MUST NOT touch any persistent state (hardware or 1441 * software) or data structures except the passed in @state parameter. 1442 * 1443 * Also since userspace controls in which order properties are set this 1444 * function must not do any input validation (since the state update is 1445 * incomplete and hence likely inconsistent). Instead any such input 1446 * validation must be done in the various atomic_check callbacks. 1447 * 1448 * RETURNS: 1449 * 1450 * 0 if the property has been found, -EINVAL if the property isn't 1451 * implemented by the driver (which shouldn't ever happen, the core only 1452 * asks for properties attached to this plane). No other validation is 1453 * allowed by the driver. The core already checks that the property 1454 * value is within the range (integer, valid enum value, ...) the driver 1455 * set when registering the property. 1456 */ 1457 int (*atomic_set_property)(struct drm_plane *plane, 1458 struct drm_plane_state *state, 1459 struct drm_property *property, 1460 uint64_t val); 1461 1462 /** 1463 * @atomic_get_property: 1464 * 1465 * Reads out the decoded driver-private property. This is used to 1466 * implement the GETPLANE IOCTL. 1467 * 1468 * Do not call this function directly, use 1469 * drm_atomic_plane_get_property() instead. 1470 * 1471 * This callback is optional if the driver does not support any 1472 * driver-private atomic properties. 1473 * 1474 * RETURNS: 1475 * 1476 * 0 on success, -EINVAL if the property isn't implemented by the 1477 * driver (which should never happen, the core only asks for 1478 * properties attached to this plane). 1479 */ 1480 int (*atomic_get_property)(struct drm_plane *plane, 1481 const struct drm_plane_state *state, 1482 struct drm_property *property, 1483 uint64_t *val); 1484 }; 1485 1486 enum drm_plane_type { 1487 DRM_PLANE_TYPE_OVERLAY, 1488 DRM_PLANE_TYPE_PRIMARY, 1489 DRM_PLANE_TYPE_CURSOR, 1490 }; 1491 1492 1493 /** 1494 * struct drm_plane - central DRM plane control structure 1495 * @dev: DRM device this plane belongs to 1496 * @head: for list management 1497 * @base: base mode object 1498 * @possible_crtcs: pipes this plane can be bound to 1499 * @format_types: array of formats supported by this plane 1500 * @format_count: number of formats supported 1501 * @format_default: driver hasn't supplied supported formats for the plane 1502 * @crtc: currently bound CRTC 1503 * @fb: currently bound fb 1504 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by 1505 * drm_mode_set_config_internal() to implement correct refcounting. 1506 * @funcs: helper functions 1507 * @properties: property tracking for this plane 1508 * @type: type of plane (overlay, primary, cursor) 1509 * @state: current atomic state for this plane 1510 */ 1511 struct drm_plane { 1512 struct drm_device *dev; 1513 struct list_head head; 1514 1515 char *name; 1516 1517 struct drm_modeset_lock mutex; 1518 1519 struct drm_mode_object base; 1520 1521 uint32_t possible_crtcs; 1522 uint32_t *format_types; 1523 unsigned int format_count; 1524 bool format_default; 1525 1526 struct drm_crtc *crtc; 1527 struct drm_framebuffer *fb; 1528 1529 struct drm_framebuffer *old_fb; 1530 1531 const struct drm_plane_funcs *funcs; 1532 1533 struct drm_object_properties properties; 1534 1535 enum drm_plane_type type; 1536 1537 const struct drm_plane_helper_funcs *helper_private; 1538 1539 struct drm_plane_state *state; 1540 }; 1541 1542 /** 1543 * struct drm_bridge_funcs - drm_bridge control functions 1544 * @attach: Called during drm_bridge_attach 1545 */ 1546 struct drm_bridge_funcs { 1547 int (*attach)(struct drm_bridge *bridge); 1548 1549 /** 1550 * @mode_fixup: 1551 * 1552 * This callback is used to validate and adjust a mode. The paramater 1553 * mode is the display mode that should be fed to the next element in 1554 * the display chain, either the final &drm_connector or the next 1555 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge 1556 * requires. It can be modified by this callback and does not need to 1557 * match mode. 1558 * 1559 * This is the only hook that allows a bridge to reject a modeset. If 1560 * this function passes all other callbacks must succeed for this 1561 * configuration. 1562 * 1563 * NOTE: 1564 * 1565 * This function is called in the check phase of atomic modesets, which 1566 * can be aborted for any reason (including on userspace's request to 1567 * just check whether a configuration would be possible). Drivers MUST 1568 * NOT touch any persistent state (hardware or software) or data 1569 * structures except the passed in @state parameter. 1570 * 1571 * RETURNS: 1572 * 1573 * True if an acceptable configuration is possible, false if the modeset 1574 * operation should be rejected. 1575 */ 1576 bool (*mode_fixup)(struct drm_bridge *bridge, 1577 const struct drm_display_mode *mode, 1578 struct drm_display_mode *adjusted_mode); 1579 /** 1580 * @disable: 1581 * 1582 * This callback should disable the bridge. It is called right before 1583 * the preceding element in the display pipe is disabled. If the 1584 * preceding element is a bridge this means it's called before that 1585 * bridge's ->disable() function. If the preceding element is a 1586 * &drm_encoder it's called right before the encoder's ->disable(), 1587 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs. 1588 * 1589 * The bridge can assume that the display pipe (i.e. clocks and timing 1590 * signals) feeding it is still running when this callback is called. 1591 * 1592 * The disable callback is optional. 1593 */ 1594 void (*disable)(struct drm_bridge *bridge); 1595 1596 /** 1597 * @post_disable: 1598 * 1599 * This callback should disable the bridge. It is called right after 1600 * the preceding element in the display pipe is disabled. If the 1601 * preceding element is a bridge this means it's called after that 1602 * bridge's ->post_disable() function. If the preceding element is a 1603 * &drm_encoder it's called right after the encoder's ->disable(), 1604 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs. 1605 * 1606 * The bridge must assume that the display pipe (i.e. clocks and timing 1607 * singals) feeding it is no longer running when this callback is 1608 * called. 1609 * 1610 * The post_disable callback is optional. 1611 */ 1612 void (*post_disable)(struct drm_bridge *bridge); 1613 1614 /** 1615 * @mode_set: 1616 * 1617 * This callback should set the given mode on the bridge. It is called 1618 * after the ->mode_set() callback for the preceding element in the 1619 * display pipeline has been called already. The display pipe (i.e. 1620 * clocks and timing signals) is off when this function is called. 1621 */ 1622 void (*mode_set)(struct drm_bridge *bridge, 1623 struct drm_display_mode *mode, 1624 struct drm_display_mode *adjusted_mode); 1625 /** 1626 * @pre_enable: 1627 * 1628 * This callback should enable the bridge. It is called right before 1629 * the preceding element in the display pipe is enabled. If the 1630 * preceding element is a bridge this means it's called before that 1631 * bridge's ->pre_enable() function. If the preceding element is a 1632 * &drm_encoder it's called right before the encoder's ->enable(), 1633 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs. 1634 * 1635 * The display pipe (i.e. clocks and timing signals) feeding this bridge 1636 * will not yet be running when this callback is called. The bridge must 1637 * not enable the display link feeding the next bridge in the chain (if 1638 * there is one) when this callback is called. 1639 * 1640 * The pre_enable callback is optional. 1641 */ 1642 void (*pre_enable)(struct drm_bridge *bridge); 1643 1644 /** 1645 * @enable: 1646 * 1647 * This callback should enable the bridge. It is called right after 1648 * the preceding element in the display pipe is enabled. If the 1649 * preceding element is a bridge this means it's called after that 1650 * bridge's ->enable() function. If the preceding element is a 1651 * &drm_encoder it's called right after the encoder's ->enable(), 1652 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs. 1653 * 1654 * The bridge can assume that the display pipe (i.e. clocks and timing 1655 * signals) feeding it is running when this callback is called. This 1656 * callback must enable the display link feeding the next bridge in the 1657 * chain if there is one. 1658 * 1659 * The enable callback is optional. 1660 */ 1661 void (*enable)(struct drm_bridge *bridge); 1662 }; 1663 1664 /** 1665 * struct drm_bridge - central DRM bridge control structure 1666 * @dev: DRM device this bridge belongs to 1667 * @encoder: encoder to which this bridge is connected 1668 * @next: the next bridge in the encoder chain 1669 * @of_node: device node pointer to the bridge 1670 * @list: to keep track of all added bridges 1671 * @funcs: control functions 1672 * @driver_private: pointer to the bridge driver's internal context 1673 */ 1674 struct drm_bridge { 1675 struct drm_device *dev; 1676 struct drm_encoder *encoder; 1677 struct drm_bridge *next; 1678 #ifdef CONFIG_OF 1679 struct device_node *of_node; 1680 #endif 1681 struct list_head list; 1682 1683 const struct drm_bridge_funcs *funcs; 1684 void *driver_private; 1685 }; 1686 1687 /** 1688 * struct drm_atomic_state - the global state object for atomic updates 1689 * @dev: parent DRM device 1690 * @allow_modeset: allow full modeset 1691 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics 1692 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL. 1693 * @planes: pointer to array of plane pointers 1694 * @plane_states: pointer to array of plane states pointers 1695 * @crtcs: pointer to array of CRTC pointers 1696 * @crtc_states: pointer to array of CRTC states pointers 1697 * @num_connector: size of the @connectors and @connector_states arrays 1698 * @connectors: pointer to array of connector pointers 1699 * @connector_states: pointer to array of connector states pointers 1700 * @acquire_ctx: acquire context for this atomic modeset state update 1701 */ 1702 struct drm_atomic_state { 1703 struct drm_device *dev; 1704 bool allow_modeset : 1; 1705 bool legacy_cursor_update : 1; 1706 bool legacy_set_config : 1; 1707 struct drm_plane **planes; 1708 struct drm_plane_state **plane_states; 1709 struct drm_crtc **crtcs; 1710 struct drm_crtc_state **crtc_states; 1711 int num_connector; 1712 struct drm_connector **connectors; 1713 struct drm_connector_state **connector_states; 1714 1715 struct drm_modeset_acquire_ctx *acquire_ctx; 1716 }; 1717 1718 1719 /** 1720 * struct drm_mode_set - new values for a CRTC config change 1721 * @fb: framebuffer to use for new config 1722 * @crtc: CRTC whose configuration we're about to change 1723 * @mode: mode timings to use 1724 * @x: position of this CRTC relative to @fb 1725 * @y: position of this CRTC relative to @fb 1726 * @connectors: array of connectors to drive with this CRTC if possible 1727 * @num_connectors: size of @connectors array 1728 * 1729 * Represents a single crtc the connectors that it drives with what mode 1730 * and from which framebuffer it scans out from. 1731 * 1732 * This is used to set modes. 1733 */ 1734 struct drm_mode_set { 1735 struct drm_framebuffer *fb; 1736 struct drm_crtc *crtc; 1737 struct drm_display_mode *mode; 1738 1739 uint32_t x; 1740 uint32_t y; 1741 1742 struct drm_connector **connectors; 1743 size_t num_connectors; 1744 }; 1745 1746 /** 1747 * struct drm_mode_config_funcs - basic driver provided mode setting functions 1748 * 1749 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that 1750 * involve drivers. 1751 */ 1752 struct drm_mode_config_funcs { 1753 /** 1754 * @fb_create: 1755 * 1756 * Create a new framebuffer object. The core does basic checks on the 1757 * requested metadata, but most of that is left to the driver. See 1758 * struct &drm_mode_fb_cmd2 for details. 1759 * 1760 * If the parameters are deemed valid and the backing storage objects in 1761 * the underlying memory manager all exist, then the driver allocates 1762 * a new &drm_framebuffer structure, subclassed to contain 1763 * driver-specific information (like the internal native buffer object 1764 * references). It also needs to fill out all relevant metadata, which 1765 * should be done by calling drm_helper_mode_fill_fb_struct(). 1766 * 1767 * The initialization is finalized by calling drm_framebuffer_init(), 1768 * which registers the framebuffer and makes it accessible to other 1769 * threads. 1770 * 1771 * RETURNS: 1772 * 1773 * A new framebuffer with an initial reference count of 1 or a negative 1774 * error code encoded with ERR_PTR(). 1775 */ 1776 struct drm_framebuffer *(*fb_create)(struct drm_device *dev, 1777 struct drm_file *file_priv, 1778 const struct drm_mode_fb_cmd2 *mode_cmd); 1779 1780 /** 1781 * @output_poll_changed: 1782 * 1783 * Callback used by helpers to inform the driver of output configuration 1784 * changes. 1785 * 1786 * Drivers implementing fbdev emulation with the helpers can call 1787 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev 1788 * helper of output changes. 1789 * 1790 * FIXME: 1791 * 1792 * Except that there's no vtable for device-level helper callbacks 1793 * there's no reason this is a core function. 1794 */ 1795 void (*output_poll_changed)(struct drm_device *dev); 1796 1797 /** 1798 * @atomic_check: 1799 * 1800 * This is the only hook to validate an atomic modeset update. This 1801 * function must reject any modeset and state changes which the hardware 1802 * or driver doesn't support. This includes but is of course not limited 1803 * to: 1804 * 1805 * - Checking that the modes, framebuffers, scaling and placement 1806 * requirements and so on are within the limits of the hardware. 1807 * 1808 * - Checking that any hidden shared resources are not oversubscribed. 1809 * This can be shared PLLs, shared lanes, overall memory bandwidth, 1810 * display fifo space (where shared between planes or maybe even 1811 * CRTCs). 1812 * 1813 * - Checking that virtualized resources exported to userspace are not 1814 * oversubscribed. For various reasons it can make sense to expose 1815 * more planes, crtcs or encoders than which are physically there. One 1816 * example is dual-pipe operations (which generally should be hidden 1817 * from userspace if when lockstepped in hardware, exposed otherwise), 1818 * where a plane might need 1 hardware plane (if it's just on one 1819 * pipe), 2 hardware planes (when it spans both pipes) or maybe even 1820 * shared a hardware plane with a 2nd plane (if there's a compatible 1821 * plane requested on the area handled by the other pipe). 1822 * 1823 * - Check that any transitional state is possible and that if 1824 * requested, the update can indeed be done in the vblank period 1825 * without temporarily disabling some functions. 1826 * 1827 * - Check any other constraints the driver or hardware might have. 1828 * 1829 * - This callback also needs to correctly fill out the &drm_crtc_state 1830 * in this update to make sure that drm_atomic_crtc_needs_modeset() 1831 * reflects the nature of the possible update and returns true if and 1832 * only if the update cannot be applied without tearing within one 1833 * vblank on that CRTC. The core uses that information to reject 1834 * updates which require a full modeset (i.e. blanking the screen, or 1835 * at least pausing updates for a substantial amount of time) if 1836 * userspace has disallowed that in its request. 1837 * 1838 * - The driver also does not need to repeat basic input validation 1839 * like done for the corresponding legacy entry points. The core does 1840 * that before calling this hook. 1841 * 1842 * See the documentation of @atomic_commit for an exhaustive list of 1843 * error conditions which don't have to be checked at the 1844 * ->atomic_check() stage? 1845 * 1846 * See the documentation for struct &drm_atomic_state for how exactly 1847 * an atomic modeset update is described. 1848 * 1849 * Drivers using the atomic helpers can implement this hook using 1850 * drm_atomic_helper_check(), or one of the exported sub-functions of 1851 * it. 1852 * 1853 * RETURNS: 1854 * 1855 * 0 on success or one of the below negative error codes: 1856 * 1857 * - -EINVAL, if any of the above constraints are violated. 1858 * 1859 * - -EDEADLK, when returned from an attempt to acquire an additional 1860 * &drm_modeset_lock through drm_modeset_lock(). 1861 * 1862 * - -ENOMEM, if allocating additional state sub-structures failed due 1863 * to lack of memory. 1864 * 1865 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted. 1866 * This can either be due to a pending signal, or because the driver 1867 * needs to completely bail out to recover from an exceptional 1868 * situation like a GPU hang. From a userspace point all errors are 1869 * treated equally. 1870 */ 1871 int (*atomic_check)(struct drm_device *dev, 1872 struct drm_atomic_state *state); 1873 1874 /** 1875 * @atomic_commit: 1876 * 1877 * This is the only hook to commit an atomic modeset update. The core 1878 * guarantees that @atomic_check has been called successfully before 1879 * calling this function, and that nothing has been changed in the 1880 * interim. 1881 * 1882 * See the documentation for struct &drm_atomic_state for how exactly 1883 * an atomic modeset update is described. 1884 * 1885 * Drivers using the atomic helpers can implement this hook using 1886 * drm_atomic_helper_commit(), or one of the exported sub-functions of 1887 * it. 1888 * 1889 * Asynchronous commits (as indicated with the async parameter) must 1890 * do any preparatory work which might result in an unsuccessful commit 1891 * in the context of this callback. The only exceptions are hardware 1892 * errors resulting in -EIO. But even in that case the driver must 1893 * ensure that the display pipe is at least running, to avoid 1894 * compositors crashing when pageflips don't work. Anything else, 1895 * specifically committing the update to the hardware, should be done 1896 * without blocking the caller. For updates which do not require a 1897 * modeset this must be guaranteed. 1898 * 1899 * The driver must wait for any pending rendering to the new 1900 * framebuffers to complete before executing the flip. It should also 1901 * wait for any pending rendering from other drivers if the underlying 1902 * buffer is a shared dma-buf. Asynchronous commits must not wait for 1903 * rendering in the context of this callback. 1904 * 1905 * An application can request to be notified when the atomic commit has 1906 * completed. These events are per-CRTC and can be distinguished by the 1907 * CRTC index supplied in &drm_event to userspace. 1908 * 1909 * The drm core will supply a struct &drm_event in the event 1910 * member of each CRTC's &drm_crtc_state structure. This can be handled by the 1911 * drm_crtc_send_vblank_event() function, which the driver should call on 1912 * the provided event upon completion of the atomic commit. Note that if 1913 * the driver supports vblank signalling and timestamping the vblank 1914 * counters and timestamps must agree with the ones returned from page 1915 * flip events. With the current vblank helper infrastructure this can 1916 * be achieved by holding a vblank reference while the page flip is 1917 * pending, acquired through drm_crtc_vblank_get() and released with 1918 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank 1919 * counter and timestamp tracking though, e.g. if they have accurate 1920 * timestamp registers in hardware. 1921 * 1922 * NOTE: 1923 * 1924 * Drivers are not allowed to shut down any display pipe successfully 1925 * enabled through an atomic commit on their own. Doing so can result in 1926 * compositors crashing if a page flip is suddenly rejected because the 1927 * pipe is off. 1928 * 1929 * RETURNS: 1930 * 1931 * 0 on success or one of the below negative error codes: 1932 * 1933 * - -EBUSY, if an asynchronous updated is requested and there is 1934 * an earlier updated pending. Drivers are allowed to support a queue 1935 * of outstanding updates, but currently no driver supports that. 1936 * Note that drivers must wait for preceding updates to complete if a 1937 * synchronous update is requested, they are not allowed to fail the 1938 * commit in that case. 1939 * 1940 * - -ENOMEM, if the driver failed to allocate memory. Specifically 1941 * this can happen when trying to pin framebuffers, which must only 1942 * be done when committing the state. 1943 * 1944 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate 1945 * that the driver has run out of vram, iommu space or similar GPU 1946 * address space needed for framebuffer. 1947 * 1948 * - -EIO, if the hardware completely died. 1949 * 1950 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted. 1951 * This can either be due to a pending signal, or because the driver 1952 * needs to completely bail out to recover from an exceptional 1953 * situation like a GPU hang. From a userspace point of view all errors are 1954 * treated equally. 1955 * 1956 * This list is exhaustive. Specifically this hook is not allowed to 1957 * return -EINVAL (any invalid requests should be caught in 1958 * @atomic_check) or -EDEADLK (this function must not acquire 1959 * additional modeset locks). 1960 */ 1961 int (*atomic_commit)(struct drm_device *dev, 1962 struct drm_atomic_state *state, 1963 bool async); 1964 1965 /** 1966 * @atomic_state_alloc: 1967 * 1968 * This optional hook can be used by drivers that want to subclass struct 1969 * &drm_atomic_state to be able to track their own driver-private global 1970 * state easily. If this hook is implemented, drivers must also 1971 * implement @atomic_state_clear and @atomic_state_free. 1972 * 1973 * RETURNS: 1974 * 1975 * A new &drm_atomic_state on success or NULL on failure. 1976 */ 1977 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev); 1978 1979 /** 1980 * @atomic_state_clear: 1981 * 1982 * This hook must clear any driver private state duplicated into the 1983 * passed-in &drm_atomic_state. This hook is called when the caller 1984 * encountered a &drm_modeset_lock deadlock and needs to drop all 1985 * already acquired locks as part of the deadlock avoidance dance 1986 * implemented in drm_modeset_lock_backoff(). 1987 * 1988 * Any duplicated state must be invalidated since a concurrent atomic 1989 * update might change it, and the drm atomic interfaces always apply 1990 * updates as relative changes to the current state. 1991 * 1992 * Drivers that implement this must call drm_atomic_state_default_clear() 1993 * to clear common state. 1994 */ 1995 void (*atomic_state_clear)(struct drm_atomic_state *state); 1996 1997 /** 1998 * @atomic_state_free: 1999 * 2000 * This hook needs driver private resources and the &drm_atomic_state 2001 * itself. Note that the core first calls drm_atomic_state_clear() to 2002 * avoid code duplicate between the clear and free hooks. 2003 * 2004 * Drivers that implement this must call drm_atomic_state_default_free() 2005 * to release common resources. 2006 */ 2007 void (*atomic_state_free)(struct drm_atomic_state *state); 2008 }; 2009 2010 /** 2011 * struct drm_mode_config - Mode configuration control structure 2012 * @mutex: mutex protecting KMS related lists and structures 2013 * @connection_mutex: ww mutex protecting connector state and routing 2014 * @acquire_ctx: global implicit acquire context used by atomic drivers for 2015 * legacy IOCTLs 2016 * @idr_mutex: mutex for KMS ID allocation and management 2017 * @crtc_idr: main KMS ID tracking object 2018 * @fb_lock: mutex to protect fb state and lists 2019 * @num_fb: number of fbs available 2020 * @fb_list: list of framebuffers available 2021 * @num_connector: number of connectors on this device 2022 * @connector_list: list of connector objects 2023 * @num_encoder: number of encoders on this device 2024 * @encoder_list: list of encoder objects 2025 * @num_overlay_plane: number of overlay planes on this device 2026 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device 2027 * @plane_list: list of plane objects 2028 * @num_crtc: number of CRTCs on this device 2029 * @crtc_list: list of CRTC objects 2030 * @property_list: list of property objects 2031 * @min_width: minimum pixel width on this device 2032 * @min_height: minimum pixel height on this device 2033 * @max_width: maximum pixel width on this device 2034 * @max_height: maximum pixel height on this device 2035 * @funcs: core driver provided mode setting functions 2036 * @fb_base: base address of the framebuffer 2037 * @poll_enabled: track polling support for this device 2038 * @poll_running: track polling status for this device 2039 * @output_poll_work: delayed work for polling in process context 2040 * @property_blob_list: list of all the blob property objects 2041 * @blob_lock: mutex for blob property allocation and management 2042 * @*_property: core property tracking 2043 * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear 2044 * gamma 2045 * @degamma_lut_size_property: size of the degamma LUT as supported by the 2046 * driver (read-only) 2047 * @ctm_property: Matrix used to convert colors after the lookup in the 2048 * degamma LUT 2049 * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to 2050 * the gamma space of the connected screen (read-only) 2051 * @gamma_lut_size_property: size of the gamma LUT as supported by the driver 2052 * @preferred_depth: preferred RBG pixel depth, used by fb helpers 2053 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering 2054 * @async_page_flip: does this device support async flips on the primary plane? 2055 * @cursor_width: hint to userspace for max cursor width 2056 * @cursor_height: hint to userspace for max cursor height 2057 * 2058 * Core mode resource tracking structure. All CRTC, encoders, and connectors 2059 * enumerated by the driver are added here, as are global properties. Some 2060 * global restrictions are also here, e.g. dimension restrictions. 2061 */ 2062 struct drm_mode_config { 2063 struct mutex mutex; /* protects configuration (mode lists etc.) */ 2064 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */ 2065 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */ 2066 struct mutex idr_mutex; /* for IDR management */ 2067 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */ 2068 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */ 2069 /* this is limited to one for now */ 2070 2071 struct mutex fb_lock; /* proctects global and per-file fb lists */ 2072 int num_fb; 2073 struct list_head fb_list; 2074 2075 int num_connector; 2076 struct ida connector_ida; 2077 struct list_head connector_list; 2078 int num_encoder; 2079 struct list_head encoder_list; 2080 2081 /* 2082 * Track # of overlay planes separately from # of total planes. By 2083 * default we only advertise overlay planes to userspace; if userspace 2084 * sets the "universal plane" capability bit, we'll go ahead and 2085 * expose all planes. 2086 */ 2087 int num_overlay_plane; 2088 int num_total_plane; 2089 struct list_head plane_list; 2090 2091 int num_crtc; 2092 struct list_head crtc_list; 2093 2094 struct list_head property_list; 2095 2096 int min_width, min_height; 2097 int max_width, max_height; 2098 const struct drm_mode_config_funcs *funcs; 2099 resource_size_t fb_base; 2100 2101 /* output poll support */ 2102 bool poll_enabled; 2103 bool poll_running; 2104 bool delayed_event; 2105 struct delayed_work output_poll_work; 2106 2107 struct mutex blob_lock; 2108 2109 /* pointers to standard properties */ 2110 struct list_head property_blob_list; 2111 struct drm_property *edid_property; 2112 struct drm_property *dpms_property; 2113 struct drm_property *path_property; 2114 struct drm_property *tile_property; 2115 struct drm_property *plane_type_property; 2116 struct drm_property *rotation_property; 2117 struct drm_property *prop_src_x; 2118 struct drm_property *prop_src_y; 2119 struct drm_property *prop_src_w; 2120 struct drm_property *prop_src_h; 2121 struct drm_property *prop_crtc_x; 2122 struct drm_property *prop_crtc_y; 2123 struct drm_property *prop_crtc_w; 2124 struct drm_property *prop_crtc_h; 2125 struct drm_property *prop_fb_id; 2126 struct drm_property *prop_crtc_id; 2127 struct drm_property *prop_active; 2128 struct drm_property *prop_mode_id; 2129 2130 /* DVI-I properties */ 2131 struct drm_property *dvi_i_subconnector_property; 2132 struct drm_property *dvi_i_select_subconnector_property; 2133 2134 /* TV properties */ 2135 struct drm_property *tv_subconnector_property; 2136 struct drm_property *tv_select_subconnector_property; 2137 struct drm_property *tv_mode_property; 2138 struct drm_property *tv_left_margin_property; 2139 struct drm_property *tv_right_margin_property; 2140 struct drm_property *tv_top_margin_property; 2141 struct drm_property *tv_bottom_margin_property; 2142 struct drm_property *tv_brightness_property; 2143 struct drm_property *tv_contrast_property; 2144 struct drm_property *tv_flicker_reduction_property; 2145 struct drm_property *tv_overscan_property; 2146 struct drm_property *tv_saturation_property; 2147 struct drm_property *tv_hue_property; 2148 2149 /* Optional properties */ 2150 struct drm_property *scaling_mode_property; 2151 struct drm_property *aspect_ratio_property; 2152 struct drm_property *dirty_info_property; 2153 2154 /* Optional color correction properties */ 2155 struct drm_property *degamma_lut_property; 2156 struct drm_property *degamma_lut_size_property; 2157 struct drm_property *ctm_property; 2158 struct drm_property *gamma_lut_property; 2159 struct drm_property *gamma_lut_size_property; 2160 2161 /* properties for virtual machine layout */ 2162 struct drm_property *suggested_x_property; 2163 struct drm_property *suggested_y_property; 2164 2165 /* dumb ioctl parameters */ 2166 uint32_t preferred_depth, prefer_shadow; 2167 2168 /* whether async page flip is supported or not */ 2169 bool async_page_flip; 2170 2171 /* whether the driver supports fb modifiers */ 2172 bool allow_fb_modifiers; 2173 2174 /* cursor size */ 2175 uint32_t cursor_width, cursor_height; 2176 }; 2177 2178 /** 2179 * drm_for_each_plane_mask - iterate over planes specified by bitmask 2180 * @plane: the loop cursor 2181 * @dev: the DRM device 2182 * @plane_mask: bitmask of plane indices 2183 * 2184 * Iterate over all planes specified by bitmask. 2185 */ 2186 #define drm_for_each_plane_mask(plane, dev, plane_mask) \ 2187 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \ 2188 for_each_if ((plane_mask) & (1 << drm_plane_index(plane))) 2189 2190 /** 2191 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask 2192 * @encoder: the loop cursor 2193 * @dev: the DRM device 2194 * @encoder_mask: bitmask of encoder indices 2195 * 2196 * Iterate over all encoders specified by bitmask. 2197 */ 2198 #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \ 2199 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \ 2200 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder))) 2201 2202 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base) 2203 #define obj_to_connector(x) container_of(x, struct drm_connector, base) 2204 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base) 2205 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base) 2206 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base) 2207 #define obj_to_property(x) container_of(x, struct drm_property, base) 2208 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base) 2209 #define obj_to_plane(x) container_of(x, struct drm_plane, base) 2210 2211 struct drm_prop_enum_list { 2212 int type; 2213 char *name; 2214 }; 2215 2216 extern __printf(6, 7) 2217 int drm_crtc_init_with_planes(struct drm_device *dev, 2218 struct drm_crtc *crtc, 2219 struct drm_plane *primary, 2220 struct drm_plane *cursor, 2221 const struct drm_crtc_funcs *funcs, 2222 const char *name, ...); 2223 extern void drm_crtc_cleanup(struct drm_crtc *crtc); 2224 extern unsigned int drm_crtc_index(struct drm_crtc *crtc); 2225 2226 /** 2227 * drm_crtc_mask - find the mask of a registered CRTC 2228 * @crtc: CRTC to find mask for 2229 * 2230 * Given a registered CRTC, return the mask bit of that CRTC for an 2231 * encoder's possible_crtcs field. 2232 */ 2233 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc) 2234 { 2235 return 1 << drm_crtc_index(crtc); 2236 } 2237 2238 extern void drm_connector_ida_init(void); 2239 extern void drm_connector_ida_destroy(void); 2240 extern int drm_connector_init(struct drm_device *dev, 2241 struct drm_connector *connector, 2242 const struct drm_connector_funcs *funcs, 2243 int connector_type); 2244 int drm_connector_register(struct drm_connector *connector); 2245 void drm_connector_unregister(struct drm_connector *connector); 2246 2247 extern void drm_connector_cleanup(struct drm_connector *connector); 2248 static inline unsigned drm_connector_index(struct drm_connector *connector) 2249 { 2250 return connector->connector_id; 2251 } 2252 2253 /* helpers to {un}register all connectors from sysfs for device */ 2254 extern int drm_connector_register_all(struct drm_device *dev); 2255 extern void drm_connector_unregister_all(struct drm_device *dev); 2256 2257 extern int drm_bridge_add(struct drm_bridge *bridge); 2258 extern void drm_bridge_remove(struct drm_bridge *bridge); 2259 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np); 2260 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge); 2261 2262 bool drm_bridge_mode_fixup(struct drm_bridge *bridge, 2263 const struct drm_display_mode *mode, 2264 struct drm_display_mode *adjusted_mode); 2265 void drm_bridge_disable(struct drm_bridge *bridge); 2266 void drm_bridge_post_disable(struct drm_bridge *bridge); 2267 void drm_bridge_mode_set(struct drm_bridge *bridge, 2268 struct drm_display_mode *mode, 2269 struct drm_display_mode *adjusted_mode); 2270 void drm_bridge_pre_enable(struct drm_bridge *bridge); 2271 void drm_bridge_enable(struct drm_bridge *bridge); 2272 2273 extern __printf(5, 6) 2274 int drm_encoder_init(struct drm_device *dev, 2275 struct drm_encoder *encoder, 2276 const struct drm_encoder_funcs *funcs, 2277 int encoder_type, const char *name, ...); 2278 extern unsigned int drm_encoder_index(struct drm_encoder *encoder); 2279 2280 /** 2281 * drm_encoder_crtc_ok - can a given crtc drive a given encoder? 2282 * @encoder: encoder to test 2283 * @crtc: crtc to test 2284 * 2285 * Return false if @encoder can't be driven by @crtc, true otherwise. 2286 */ 2287 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder, 2288 struct drm_crtc *crtc) 2289 { 2290 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc)); 2291 } 2292 2293 extern __printf(8, 9) 2294 int drm_universal_plane_init(struct drm_device *dev, 2295 struct drm_plane *plane, 2296 unsigned long possible_crtcs, 2297 const struct drm_plane_funcs *funcs, 2298 const uint32_t *formats, 2299 unsigned int format_count, 2300 enum drm_plane_type type, 2301 const char *name, ...); 2302 extern int drm_plane_init(struct drm_device *dev, 2303 struct drm_plane *plane, 2304 unsigned long possible_crtcs, 2305 const struct drm_plane_funcs *funcs, 2306 const uint32_t *formats, unsigned int format_count, 2307 bool is_primary); 2308 extern void drm_plane_cleanup(struct drm_plane *plane); 2309 extern unsigned int drm_plane_index(struct drm_plane *plane); 2310 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx); 2311 extern void drm_plane_force_disable(struct drm_plane *plane); 2312 extern int drm_plane_check_pixel_format(const struct drm_plane *plane, 2313 u32 format); 2314 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, 2315 int *hdisplay, int *vdisplay); 2316 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc, 2317 int x, int y, 2318 const struct drm_display_mode *mode, 2319 const struct drm_framebuffer *fb); 2320 2321 extern void drm_encoder_cleanup(struct drm_encoder *encoder); 2322 2323 extern const char *drm_get_connector_status_name(enum drm_connector_status status); 2324 extern const char *drm_get_subpixel_order_name(enum subpixel_order order); 2325 extern const char *drm_get_dpms_name(int val); 2326 extern const char *drm_get_dvi_i_subconnector_name(int val); 2327 extern const char *drm_get_dvi_i_select_name(int val); 2328 extern const char *drm_get_tv_subconnector_name(int val); 2329 extern const char *drm_get_tv_select_name(int val); 2330 extern void drm_fb_release(struct drm_file *file_priv); 2331 extern void drm_property_destroy_user_blobs(struct drm_device *dev, 2332 struct drm_file *file_priv); 2333 extern bool drm_probe_ddc(struct i2c_adapter *adapter); 2334 extern struct edid *drm_get_edid(struct drm_connector *connector, 2335 struct i2c_adapter *adapter); 2336 extern struct edid *drm_get_edid_switcheroo(struct drm_connector *connector, 2337 struct i2c_adapter *adapter); 2338 extern struct edid *drm_edid_duplicate(const struct edid *edid); 2339 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); 2340 extern void drm_mode_config_init(struct drm_device *dev); 2341 extern void drm_mode_config_reset(struct drm_device *dev); 2342 extern void drm_mode_config_cleanup(struct drm_device *dev); 2343 2344 extern int drm_mode_connector_set_path_property(struct drm_connector *connector, 2345 const char *path); 2346 int drm_mode_connector_set_tile_property(struct drm_connector *connector); 2347 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector, 2348 const struct edid *edid); 2349 2350 extern int drm_display_info_set_bus_formats(struct drm_display_info *info, 2351 const u32 *formats, 2352 unsigned int num_formats); 2353 2354 static inline bool drm_property_type_is(struct drm_property *property, 2355 uint32_t type) 2356 { 2357 /* instanceof for props.. handles extended type vs original types: */ 2358 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) 2359 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type; 2360 return property->flags & type; 2361 } 2362 2363 static inline bool drm_property_type_valid(struct drm_property *property) 2364 { 2365 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) 2366 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE); 2367 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE); 2368 } 2369 2370 extern int drm_object_property_set_value(struct drm_mode_object *obj, 2371 struct drm_property *property, 2372 uint64_t val); 2373 extern int drm_object_property_get_value(struct drm_mode_object *obj, 2374 struct drm_property *property, 2375 uint64_t *value); 2376 extern int drm_framebuffer_init(struct drm_device *dev, 2377 struct drm_framebuffer *fb, 2378 const struct drm_framebuffer_funcs *funcs); 2379 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, 2380 uint32_t id); 2381 extern void drm_framebuffer_remove(struct drm_framebuffer *fb); 2382 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb); 2383 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb); 2384 2385 extern void drm_object_attach_property(struct drm_mode_object *obj, 2386 struct drm_property *property, 2387 uint64_t init_val); 2388 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags, 2389 const char *name, int num_values); 2390 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, 2391 const char *name, 2392 const struct drm_prop_enum_list *props, 2393 int num_values); 2394 struct drm_property *drm_property_create_bitmask(struct drm_device *dev, 2395 int flags, const char *name, 2396 const struct drm_prop_enum_list *props, 2397 int num_props, 2398 uint64_t supported_bits); 2399 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, 2400 const char *name, 2401 uint64_t min, uint64_t max); 2402 struct drm_property *drm_property_create_signed_range(struct drm_device *dev, 2403 int flags, const char *name, 2404 int64_t min, int64_t max); 2405 struct drm_property *drm_property_create_object(struct drm_device *dev, 2406 int flags, const char *name, uint32_t type); 2407 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags, 2408 const char *name); 2409 struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, 2410 size_t length, 2411 const void *data); 2412 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev, 2413 uint32_t id); 2414 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob); 2415 void drm_property_unreference_blob(struct drm_property_blob *blob); 2416 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property); 2417 extern int drm_property_add_enum(struct drm_property *property, int index, 2418 uint64_t value, const char *name); 2419 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev); 2420 extern int drm_mode_create_tv_properties(struct drm_device *dev, 2421 unsigned int num_modes, 2422 const char * const modes[]); 2423 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev); 2424 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev); 2425 extern int drm_mode_create_dirty_info_property(struct drm_device *dev); 2426 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev); 2427 extern bool drm_property_change_valid_get(struct drm_property *property, 2428 uint64_t value, struct drm_mode_object **ref); 2429 extern void drm_property_change_valid_put(struct drm_property *property, 2430 struct drm_mode_object *ref); 2431 2432 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector, 2433 struct drm_encoder *encoder); 2434 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, 2435 int gamma_size); 2436 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, 2437 uint32_t id, uint32_t type); 2438 void drm_mode_object_reference(struct drm_mode_object *obj); 2439 void drm_mode_object_unreference(struct drm_mode_object *obj); 2440 2441 /* IOCTLs */ 2442 extern int drm_mode_getresources(struct drm_device *dev, 2443 void *data, struct drm_file *file_priv); 2444 extern int drm_mode_getplane_res(struct drm_device *dev, void *data, 2445 struct drm_file *file_priv); 2446 extern int drm_mode_getcrtc(struct drm_device *dev, 2447 void *data, struct drm_file *file_priv); 2448 extern int drm_mode_getconnector(struct drm_device *dev, 2449 void *data, struct drm_file *file_priv); 2450 extern int drm_mode_set_config_internal(struct drm_mode_set *set); 2451 extern int drm_mode_setcrtc(struct drm_device *dev, 2452 void *data, struct drm_file *file_priv); 2453 extern int drm_mode_getplane(struct drm_device *dev, 2454 void *data, struct drm_file *file_priv); 2455 extern int drm_mode_setplane(struct drm_device *dev, 2456 void *data, struct drm_file *file_priv); 2457 extern int drm_mode_cursor_ioctl(struct drm_device *dev, 2458 void *data, struct drm_file *file_priv); 2459 extern int drm_mode_cursor2_ioctl(struct drm_device *dev, 2460 void *data, struct drm_file *file_priv); 2461 extern int drm_mode_addfb(struct drm_device *dev, 2462 void *data, struct drm_file *file_priv); 2463 extern int drm_mode_addfb2(struct drm_device *dev, 2464 void *data, struct drm_file *file_priv); 2465 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); 2466 extern int drm_mode_rmfb(struct drm_device *dev, 2467 void *data, struct drm_file *file_priv); 2468 extern int drm_mode_getfb(struct drm_device *dev, 2469 void *data, struct drm_file *file_priv); 2470 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev, 2471 void *data, struct drm_file *file_priv); 2472 2473 extern int drm_mode_getproperty_ioctl(struct drm_device *dev, 2474 void *data, struct drm_file *file_priv); 2475 extern int drm_mode_getblob_ioctl(struct drm_device *dev, 2476 void *data, struct drm_file *file_priv); 2477 extern int drm_mode_createblob_ioctl(struct drm_device *dev, 2478 void *data, struct drm_file *file_priv); 2479 extern int drm_mode_destroyblob_ioctl(struct drm_device *dev, 2480 void *data, struct drm_file *file_priv); 2481 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev, 2482 void *data, struct drm_file *file_priv); 2483 extern int drm_mode_getencoder(struct drm_device *dev, 2484 void *data, struct drm_file *file_priv); 2485 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev, 2486 void *data, struct drm_file *file_priv); 2487 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev, 2488 void *data, struct drm_file *file_priv); 2489 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match); 2490 extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code); 2491 extern bool drm_detect_hdmi_monitor(struct edid *edid); 2492 extern bool drm_detect_monitor_audio(struct edid *edid); 2493 extern bool drm_rgb_quant_range_selectable(struct edid *edid); 2494 extern int drm_mode_page_flip_ioctl(struct drm_device *dev, 2495 void *data, struct drm_file *file_priv); 2496 extern int drm_add_modes_noedid(struct drm_connector *connector, 2497 int hdisplay, int vdisplay); 2498 extern void drm_set_preferred_mode(struct drm_connector *connector, 2499 int hpref, int vpref); 2500 2501 extern int drm_edid_header_is_valid(const u8 *raw_edid); 2502 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, 2503 bool *edid_corrupt); 2504 extern bool drm_edid_is_valid(struct edid *edid); 2505 extern void drm_edid_get_monitor_name(struct edid *edid, char *name, 2506 int buflen); 2507 2508 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 2509 char topology[8]); 2510 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, 2511 char topology[8]); 2512 extern void drm_mode_put_tile_group(struct drm_device *dev, 2513 struct drm_tile_group *tg); 2514 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, 2515 int hsize, int vsize, int fresh, 2516 bool rb); 2517 2518 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev, 2519 void *data, struct drm_file *file_priv); 2520 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev, 2521 void *data, struct drm_file *file_priv); 2522 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev, 2523 void *data, struct drm_file *file_priv); 2524 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, 2525 struct drm_file *file_priv); 2526 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, 2527 struct drm_file *file_priv); 2528 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane, 2529 struct drm_property *property, 2530 uint64_t value); 2531 extern int drm_mode_atomic_ioctl(struct drm_device *dev, 2532 void *data, struct drm_file *file_priv); 2533 2534 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, 2535 int *bpp); 2536 extern int drm_format_num_planes(uint32_t format); 2537 extern int drm_format_plane_cpp(uint32_t format, int plane); 2538 extern int drm_format_horz_chroma_subsampling(uint32_t format); 2539 extern int drm_format_vert_chroma_subsampling(uint32_t format); 2540 extern int drm_format_plane_width(int width, uint32_t format, int plane); 2541 extern int drm_format_plane_height(int height, uint32_t format, int plane); 2542 extern const char *drm_get_format_name(uint32_t format); 2543 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, 2544 unsigned int supported_rotations); 2545 extern unsigned int drm_rotation_simplify(unsigned int rotation, 2546 unsigned int supported_rotations); 2547 2548 /* Helpers */ 2549 2550 static inline struct drm_plane *drm_plane_find(struct drm_device *dev, 2551 uint32_t id) 2552 { 2553 struct drm_mode_object *mo; 2554 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE); 2555 return mo ? obj_to_plane(mo) : NULL; 2556 } 2557 2558 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev, 2559 uint32_t id) 2560 { 2561 struct drm_mode_object *mo; 2562 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC); 2563 return mo ? obj_to_crtc(mo) : NULL; 2564 } 2565 2566 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev, 2567 uint32_t id) 2568 { 2569 struct drm_mode_object *mo; 2570 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER); 2571 return mo ? obj_to_encoder(mo) : NULL; 2572 } 2573 2574 static inline struct drm_connector *drm_connector_find(struct drm_device *dev, 2575 uint32_t id) 2576 { 2577 struct drm_mode_object *mo; 2578 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR); 2579 return mo ? obj_to_connector(mo) : NULL; 2580 } 2581 2582 static inline struct drm_property *drm_property_find(struct drm_device *dev, 2583 uint32_t id) 2584 { 2585 struct drm_mode_object *mo; 2586 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY); 2587 return mo ? obj_to_property(mo) : NULL; 2588 } 2589 2590 /* 2591 * Extract a degamma/gamma LUT value provided by user and round it to the 2592 * precision supported by the hardware. 2593 */ 2594 static inline uint32_t drm_color_lut_extract(uint32_t user_input, 2595 uint32_t bit_precision) 2596 { 2597 uint32_t val = user_input; 2598 uint32_t max = 0xffff >> (16 - bit_precision); 2599 2600 /* Round only if we're not using full precision. */ 2601 if (bit_precision < 16) { 2602 val += 1UL << (16 - bit_precision - 1); 2603 val >>= 16 - bit_precision; 2604 } 2605 2606 return clamp_val(val, 0, max); 2607 } 2608 2609 /* 2610 * drm_framebuffer_reference - incr the fb refcnt 2611 * @fb: framebuffer 2612 * 2613 * This functions increments the fb's refcount. 2614 */ 2615 static inline void drm_framebuffer_reference(struct drm_framebuffer *fb) 2616 { 2617 drm_mode_object_reference(&fb->base); 2618 } 2619 2620 /** 2621 * drm_framebuffer_unreference - unref a framebuffer 2622 * @fb: framebuffer to unref 2623 * 2624 * This functions decrements the fb's refcount and frees it if it drops to zero. 2625 */ 2626 static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb) 2627 { 2628 drm_mode_object_unreference(&fb->base); 2629 } 2630 2631 /** 2632 * drm_framebuffer_read_refcount - read the framebuffer reference count. 2633 * @fb: framebuffer 2634 * 2635 * This functions returns the framebuffer's reference count. 2636 */ 2637 static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb) 2638 { 2639 return atomic_read(&fb->base.refcount.refcount); 2640 } 2641 2642 /* Plane list iterator for legacy (overlay only) planes. */ 2643 #define drm_for_each_legacy_plane(plane, dev) \ 2644 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \ 2645 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY) 2646 2647 #define drm_for_each_plane(plane, dev) \ 2648 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) 2649 2650 #define drm_for_each_crtc(crtc, dev) \ 2651 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head) 2652 2653 static inline void 2654 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config) 2655 { 2656 /* 2657 * The connector hotadd/remove code currently grabs both locks when 2658 * updating lists. Hence readers need only hold either of them to be 2659 * safe and the check amounts to 2660 * 2661 * WARN_ON(not_holding(A) && not_holding(B)). 2662 */ 2663 WARN_ON(!mutex_is_locked(&mode_config->mutex) && 2664 !drm_modeset_is_locked(&mode_config->connection_mutex)); 2665 } 2666 2667 #define drm_for_each_connector(connector, dev) \ 2668 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \ 2669 connector = list_first_entry(&(dev)->mode_config.connector_list, \ 2670 struct drm_connector, head); \ 2671 &connector->head != (&(dev)->mode_config.connector_list); \ 2672 connector = list_next_entry(connector, head)) 2673 2674 #define drm_for_each_encoder(encoder, dev) \ 2675 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head) 2676 2677 #define drm_for_each_fb(fb, dev) \ 2678 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \ 2679 fb = list_first_entry(&(dev)->mode_config.fb_list, \ 2680 struct drm_framebuffer, head); \ 2681 &fb->head != (&(dev)->mode_config.fb_list); \ 2682 fb = list_next_entry(fb, head)) 2683 2684 #endif /* __DRM_CRTC_H__ */ 2685