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