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 }; 62 63 #define DRM_OBJECT_MAX_PROPERTY 24 64 struct drm_object_properties { 65 int count, atomic_count; 66 /* NOTE: if we ever start dynamically destroying properties (ie. 67 * not at drm_mode_config_cleanup() time), then we'd have to do 68 * a better job of detaching property from mode objects to avoid 69 * dangling property pointers: 70 */ 71 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY]; 72 /* do not read/write values directly, but use drm_object_property_get_value() 73 * and drm_object_property_set_value(): 74 */ 75 uint64_t values[DRM_OBJECT_MAX_PROPERTY]; 76 }; 77 78 static inline int64_t U642I64(uint64_t val) 79 { 80 return (int64_t)*((int64_t *)&val); 81 } 82 static inline uint64_t I642U64(int64_t val) 83 { 84 return (uint64_t)*((uint64_t *)&val); 85 } 86 87 /* rotation property bits */ 88 #define DRM_ROTATE_0 0 89 #define DRM_ROTATE_90 1 90 #define DRM_ROTATE_180 2 91 #define DRM_ROTATE_270 3 92 #define DRM_REFLECT_X 4 93 #define DRM_REFLECT_Y 5 94 95 enum drm_connector_force { 96 DRM_FORCE_UNSPECIFIED, 97 DRM_FORCE_OFF, 98 DRM_FORCE_ON, /* force on analog part normally */ 99 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */ 100 }; 101 102 #include <drm/drm_modes.h> 103 104 enum drm_connector_status { 105 connector_status_connected = 1, 106 connector_status_disconnected = 2, 107 connector_status_unknown = 3, 108 }; 109 110 enum subpixel_order { 111 SubPixelUnknown = 0, 112 SubPixelHorizontalRGB, 113 SubPixelHorizontalBGR, 114 SubPixelVerticalRGB, 115 SubPixelVerticalBGR, 116 SubPixelNone, 117 }; 118 119 #define DRM_COLOR_FORMAT_RGB444 (1<<0) 120 #define DRM_COLOR_FORMAT_YCRCB444 (1<<1) 121 #define DRM_COLOR_FORMAT_YCRCB422 (1<<2) 122 /* 123 * Describes a given display (e.g. CRT or flat panel) and its limitations. 124 */ 125 struct drm_display_info { 126 char name[DRM_DISPLAY_INFO_LEN]; 127 128 /* Physical size */ 129 unsigned int width_mm; 130 unsigned int height_mm; 131 132 /* Clock limits FIXME: storage format */ 133 unsigned int min_vfreq, max_vfreq; 134 unsigned int min_hfreq, max_hfreq; 135 unsigned int pixel_clock; 136 unsigned int bpc; 137 138 enum subpixel_order subpixel_order; 139 u32 color_formats; 140 141 u32 *bus_formats; 142 unsigned int num_bus_formats; 143 144 /* Mask of supported hdmi deep color modes */ 145 u8 edid_hdmi_dc_modes; 146 147 u8 cea_rev; 148 }; 149 150 /* data corresponds to displayid vend/prod/serial */ 151 struct drm_tile_group { 152 struct kref refcount; 153 struct drm_device *dev; 154 int id; 155 u8 group_data[8]; 156 }; 157 158 struct drm_framebuffer_funcs { 159 /* note: use drm_framebuffer_remove() */ 160 void (*destroy)(struct drm_framebuffer *framebuffer); 161 int (*create_handle)(struct drm_framebuffer *fb, 162 struct drm_file *file_priv, 163 unsigned int *handle); 164 /* 165 * Optional callback for the dirty fb ioctl. 166 * 167 * Userspace can notify the driver via this callback 168 * that a area of the framebuffer has changed and should 169 * be flushed to the display hardware. 170 * 171 * See documentation in drm_mode.h for the struct 172 * drm_mode_fb_dirty_cmd for more information as all 173 * the semantics and arguments have a one to one mapping 174 * on this function. 175 */ 176 int (*dirty)(struct drm_framebuffer *framebuffer, 177 struct drm_file *file_priv, unsigned flags, 178 unsigned color, struct drm_clip_rect *clips, 179 unsigned num_clips); 180 }; 181 182 struct drm_framebuffer { 183 struct drm_device *dev; 184 /* 185 * Note that the fb is refcounted for the benefit of driver internals, 186 * for example some hw, disabling a CRTC/plane is asynchronous, and 187 * scanout does not actually complete until the next vblank. So some 188 * cleanup (like releasing the reference(s) on the backing GEM bo(s)) 189 * should be deferred. In cases like this, the driver would like to 190 * hold a ref to the fb even though it has already been removed from 191 * userspace perspective. 192 */ 193 struct kref refcount; 194 /* 195 * Place on the dev->mode_config.fb_list, access protected by 196 * dev->mode_config.fb_lock. 197 */ 198 struct list_head head; 199 struct drm_mode_object base; 200 const struct drm_framebuffer_funcs *funcs; 201 unsigned int pitches[4]; 202 unsigned int offsets[4]; 203 uint64_t modifier[4]; 204 unsigned int width; 205 unsigned int height; 206 /* depth can be 15 or 16 */ 207 unsigned int depth; 208 int bits_per_pixel; 209 int flags; 210 uint32_t pixel_format; /* fourcc format */ 211 struct list_head filp_head; 212 /* if you are using the helper */ 213 void *helper_private; 214 }; 215 216 struct drm_property_blob { 217 struct drm_mode_object base; 218 struct drm_device *dev; 219 struct kref refcount; 220 struct list_head head_global; 221 struct list_head head_file; 222 size_t length; 223 unsigned char data[]; 224 }; 225 226 struct drm_property_enum { 227 uint64_t value; 228 struct list_head head; 229 char name[DRM_PROP_NAME_LEN]; 230 }; 231 232 struct drm_property { 233 struct list_head head; 234 struct drm_mode_object base; 235 uint32_t flags; 236 char name[DRM_PROP_NAME_LEN]; 237 uint32_t num_values; 238 uint64_t *values; 239 struct drm_device *dev; 240 241 struct list_head enum_list; 242 }; 243 244 struct drm_crtc; 245 struct drm_connector; 246 struct drm_encoder; 247 struct drm_pending_vblank_event; 248 struct drm_plane; 249 struct drm_bridge; 250 struct drm_atomic_state; 251 252 /** 253 * struct drm_crtc_state - mutable CRTC state 254 * @crtc: backpointer to the CRTC 255 * @enable: whether the CRTC should be enabled, gates all other state 256 * @active: whether the CRTC is actively displaying (used for DPMS) 257 * @mode_changed: for use by helpers and drivers when computing state updates 258 * @active_changed: for use by helpers and drivers when computing state updates 259 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes 260 * @last_vblank_count: for helpers and drivers to capture the vblank of the 261 * update to ensure framebuffer cleanup isn't done too early 262 * @planes_changed: for use by helpers and drivers when computing state updates 263 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings 264 * @mode: current mode timings 265 * @event: optional pointer to a DRM event to signal upon completion of the 266 * state update 267 * @state: backpointer to global drm_atomic_state 268 * 269 * Note that the distinction between @enable and @active is rather subtile: 270 * Flipping @active while @enable is set without changing anything else may 271 * never return in a failure from the ->atomic_check callback. Userspace assumes 272 * that a DPMS On will always succeed. In other words: @enable controls resource 273 * assignment, @active controls the actual hardware state. 274 */ 275 struct drm_crtc_state { 276 struct drm_crtc *crtc; 277 278 bool enable; 279 bool active; 280 281 /* computed state bits used by helpers and drivers */ 282 bool planes_changed : 1; 283 bool mode_changed : 1; 284 bool active_changed : 1; 285 286 /* attached planes bitmask: 287 * WARNING: transitional helpers do not maintain plane_mask so 288 * drivers not converted over to atomic helpers should not rely 289 * on plane_mask being accurate! 290 */ 291 u32 plane_mask; 292 293 /* last_vblank_count: for vblank waits before cleanup */ 294 u32 last_vblank_count; 295 296 /* adjusted_mode: for use by helpers and drivers */ 297 struct drm_display_mode adjusted_mode; 298 299 struct drm_display_mode mode; 300 301 /* blob property to expose current mode to atomic userspace */ 302 struct drm_property_blob *mode_blob; 303 304 struct drm_pending_vblank_event *event; 305 306 struct drm_atomic_state *state; 307 }; 308 309 /** 310 * struct drm_crtc_funcs - control CRTCs for a given device 311 * @save: save CRTC state 312 * @restore: restore CRTC state 313 * @reset: reset CRTC after state has been invalidated (e.g. resume) 314 * @cursor_set: setup the cursor 315 * @cursor_set2: setup the cursor with hotspot, superseeds @cursor_set if set 316 * @cursor_move: move the cursor 317 * @gamma_set: specify color ramp for CRTC 318 * @destroy: deinit and free object 319 * @set_property: called when a property is changed 320 * @set_config: apply a new CRTC configuration 321 * @page_flip: initiate a page flip 322 * @atomic_duplicate_state: duplicate the atomic state for this CRTC 323 * @atomic_destroy_state: destroy an atomic state for this CRTC 324 * @atomic_set_property: set a property on an atomic state for this CRTC 325 * (do not call directly, use drm_atomic_crtc_set_property()) 326 * @atomic_get_property: get a property on an atomic state for this CRTC 327 * (do not call directly, use drm_atomic_crtc_get_property()) 328 * 329 * The drm_crtc_funcs structure is the central CRTC management structure 330 * in the DRM. Each CRTC controls one or more connectors (note that the name 331 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc. 332 * connectors, not just CRTs). 333 * 334 * Each driver is responsible for filling out this structure at startup time, 335 * in addition to providing other modesetting features, like i2c and DDC 336 * bus accessors. 337 */ 338 struct drm_crtc_funcs { 339 /* Save CRTC state */ 340 void (*save)(struct drm_crtc *crtc); /* suspend? */ 341 /* Restore CRTC state */ 342 void (*restore)(struct drm_crtc *crtc); /* resume? */ 343 /* Reset CRTC state */ 344 void (*reset)(struct drm_crtc *crtc); 345 346 /* cursor controls */ 347 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv, 348 uint32_t handle, uint32_t width, uint32_t height); 349 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv, 350 uint32_t handle, uint32_t width, uint32_t height, 351 int32_t hot_x, int32_t hot_y); 352 int (*cursor_move)(struct drm_crtc *crtc, int x, int y); 353 354 /* Set gamma on the CRTC */ 355 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, 356 uint32_t start, uint32_t size); 357 /* Object destroy routine */ 358 void (*destroy)(struct drm_crtc *crtc); 359 360 int (*set_config)(struct drm_mode_set *set); 361 362 /* 363 * Flip to the given framebuffer. This implements the page 364 * flip ioctl described in drm_mode.h, specifically, the 365 * implementation must return immediately and block all 366 * rendering to the current fb until the flip has completed. 367 * If userspace set the event flag in the ioctl, the event 368 * argument will point to an event to send back when the flip 369 * completes, otherwise it will be NULL. 370 */ 371 int (*page_flip)(struct drm_crtc *crtc, 372 struct drm_framebuffer *fb, 373 struct drm_pending_vblank_event *event, 374 uint32_t flags); 375 376 int (*set_property)(struct drm_crtc *crtc, 377 struct drm_property *property, uint64_t val); 378 379 /* atomic update handling */ 380 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc); 381 void (*atomic_destroy_state)(struct drm_crtc *crtc, 382 struct drm_crtc_state *state); 383 int (*atomic_set_property)(struct drm_crtc *crtc, 384 struct drm_crtc_state *state, 385 struct drm_property *property, 386 uint64_t val); 387 int (*atomic_get_property)(struct drm_crtc *crtc, 388 const struct drm_crtc_state *state, 389 struct drm_property *property, 390 uint64_t *val); 391 }; 392 393 /** 394 * struct drm_crtc - central CRTC control structure 395 * @dev: parent DRM device 396 * @port: OF node used by drm_of_find_possible_crtcs() 397 * @head: list management 398 * @mutex: per-CRTC locking 399 * @base: base KMS object for ID tracking etc. 400 * @primary: primary plane for this CRTC 401 * @cursor: cursor plane for this CRTC 402 * @cursor_x: current x position of the cursor, used for universal cursor planes 403 * @cursor_y: current y position of the cursor, used for universal cursor planes 404 * @enabled: is this CRTC enabled? 405 * @mode: current mode timings 406 * @hwmode: mode timings as programmed to hw regs 407 * @invert_dimensions: for purposes of error checking crtc vs fb sizes, 408 * invert the width/height of the crtc. This is used if the driver 409 * is performing 90 or 270 degree rotated scanout 410 * @x: x position on screen 411 * @y: y position on screen 412 * @funcs: CRTC control functions 413 * @gamma_size: size of gamma ramp 414 * @gamma_store: gamma ramp values 415 * @framedur_ns: precise frame timing 416 * @linedur_ns: precise line timing 417 * @pixeldur_ns: precise pixel timing 418 * @helper_private: mid-layer private data 419 * @properties: property tracking for this CRTC 420 * @state: current atomic state for this CRTC 421 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for 422 * legacy ioctls 423 * 424 * Each CRTC may have one or more connectors associated with it. This structure 425 * allows the CRTC to be controlled. 426 */ 427 struct drm_crtc { 428 struct drm_device *dev; 429 struct device_node *port; 430 struct list_head head; 431 432 /* 433 * crtc mutex 434 * 435 * This provides a read lock for the overall crtc state (mode, dpms 436 * state, ...) and a write lock for everything which can be update 437 * without a full modeset (fb, cursor data, ...) 438 */ 439 struct drm_modeset_lock mutex; 440 441 struct drm_mode_object base; 442 443 /* primary and cursor planes for CRTC */ 444 struct drm_plane *primary; 445 struct drm_plane *cursor; 446 447 /* position of cursor plane on crtc */ 448 int cursor_x; 449 int cursor_y; 450 451 bool enabled; 452 453 /* Requested mode from modesetting. */ 454 struct drm_display_mode mode; 455 456 /* Programmed mode in hw, after adjustments for encoders, 457 * crtc, panel scaling etc. Needed for timestamping etc. 458 */ 459 struct drm_display_mode hwmode; 460 461 bool invert_dimensions; 462 463 int x, y; 464 const struct drm_crtc_funcs *funcs; 465 466 /* CRTC gamma size for reporting to userspace */ 467 uint32_t gamma_size; 468 uint16_t *gamma_store; 469 470 /* Constants needed for precise vblank and swap timestamping. */ 471 int framedur_ns, linedur_ns, pixeldur_ns; 472 473 /* if you are using the helper */ 474 const void *helper_private; 475 476 struct drm_object_properties properties; 477 478 struct drm_crtc_state *state; 479 480 /* 481 * For legacy crtc ioctls so that atomic drivers can get at the locking 482 * acquire context. 483 */ 484 struct drm_modeset_acquire_ctx *acquire_ctx; 485 }; 486 487 /** 488 * struct drm_connector_state - mutable connector state 489 * @connector: backpointer to the connector 490 * @crtc: CRTC to connect connector to, NULL if disabled 491 * @best_encoder: can be used by helpers and drivers to select the encoder 492 * @state: backpointer to global drm_atomic_state 493 */ 494 struct drm_connector_state { 495 struct drm_connector *connector; 496 497 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */ 498 499 struct drm_encoder *best_encoder; 500 501 struct drm_atomic_state *state; 502 }; 503 504 /** 505 * struct drm_connector_funcs - control connectors on a given device 506 * @dpms: set power state 507 * @save: save connector state 508 * @restore: restore connector state 509 * @reset: reset connector after state has been invalidated (e.g. resume) 510 * @detect: is this connector active? 511 * @fill_modes: fill mode list for this connector 512 * @set_property: property for this connector may need an update 513 * @destroy: make object go away 514 * @force: notify the driver that the connector is forced on 515 * @atomic_duplicate_state: duplicate the atomic state for this connector 516 * @atomic_destroy_state: destroy an atomic state for this connector 517 * @atomic_set_property: set a property on an atomic state for this connector 518 * (do not call directly, use drm_atomic_connector_set_property()) 519 * @atomic_get_property: get a property on an atomic state for this connector 520 * (do not call directly, use drm_atomic_connector_get_property()) 521 * 522 * Each CRTC may have one or more connectors attached to it. The functions 523 * below allow the core DRM code to control connectors, enumerate available modes, 524 * etc. 525 */ 526 struct drm_connector_funcs { 527 void (*dpms)(struct drm_connector *connector, int mode); 528 void (*save)(struct drm_connector *connector); 529 void (*restore)(struct drm_connector *connector); 530 void (*reset)(struct drm_connector *connector); 531 532 /* Check to see if anything is attached to the connector. 533 * @force is set to false whilst polling, true when checking the 534 * connector due to user request. @force can be used by the driver 535 * to avoid expensive, destructive operations during automated 536 * probing. 537 */ 538 enum drm_connector_status (*detect)(struct drm_connector *connector, 539 bool force); 540 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height); 541 int (*set_property)(struct drm_connector *connector, struct drm_property *property, 542 uint64_t val); 543 void (*destroy)(struct drm_connector *connector); 544 void (*force)(struct drm_connector *connector); 545 546 /* atomic update handling */ 547 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector); 548 void (*atomic_destroy_state)(struct drm_connector *connector, 549 struct drm_connector_state *state); 550 int (*atomic_set_property)(struct drm_connector *connector, 551 struct drm_connector_state *state, 552 struct drm_property *property, 553 uint64_t val); 554 int (*atomic_get_property)(struct drm_connector *connector, 555 const struct drm_connector_state *state, 556 struct drm_property *property, 557 uint64_t *val); 558 }; 559 560 /** 561 * struct drm_encoder_funcs - encoder controls 562 * @reset: reset state (e.g. at init or resume time) 563 * @destroy: cleanup and free associated data 564 * 565 * Encoders sit between CRTCs and connectors. 566 */ 567 struct drm_encoder_funcs { 568 void (*reset)(struct drm_encoder *encoder); 569 void (*destroy)(struct drm_encoder *encoder); 570 }; 571 572 #define DRM_CONNECTOR_MAX_ENCODER 3 573 574 /** 575 * struct drm_encoder - central DRM encoder structure 576 * @dev: parent DRM device 577 * @head: list management 578 * @base: base KMS object 579 * @name: encoder name 580 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h 581 * @possible_crtcs: bitmask of potential CRTC bindings 582 * @possible_clones: bitmask of potential sibling encoders for cloning 583 * @crtc: currently bound CRTC 584 * @bridge: bridge associated to the encoder 585 * @funcs: control functions 586 * @helper_private: mid-layer private data 587 * 588 * CRTCs drive pixels to encoders, which convert them into signals 589 * appropriate for a given connector or set of connectors. 590 */ 591 struct drm_encoder { 592 struct drm_device *dev; 593 struct list_head head; 594 595 struct drm_mode_object base; 596 char *name; 597 int encoder_type; 598 uint32_t possible_crtcs; 599 uint32_t possible_clones; 600 601 struct drm_crtc *crtc; 602 struct drm_bridge *bridge; 603 const struct drm_encoder_funcs *funcs; 604 void *helper_private; 605 }; 606 607 /* should we poll this connector for connects and disconnects */ 608 /* hot plug detectable */ 609 #define DRM_CONNECTOR_POLL_HPD (1 << 0) 610 /* poll for connections */ 611 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1) 612 /* can cleanly poll for disconnections without flickering the screen */ 613 /* DACs should rarely do this without a lot of testing */ 614 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2) 615 616 #define MAX_ELD_BYTES 128 617 618 /** 619 * struct drm_connector - central DRM connector control structure 620 * @dev: parent DRM device 621 * @kdev: kernel device for sysfs attributes 622 * @attr: sysfs attributes 623 * @head: list management 624 * @base: base KMS object 625 * @name: connector name 626 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h 627 * @connector_type_id: index into connector type enum 628 * @interlace_allowed: can this connector handle interlaced modes? 629 * @doublescan_allowed: can this connector handle doublescan? 630 * @stereo_allowed: can this connector handle stereo modes? 631 * @modes: modes available on this connector (from fill_modes() + user) 632 * @status: one of the drm_connector_status enums (connected, not, or unknown) 633 * @probed_modes: list of modes derived directly from the display 634 * @display_info: information about attached display (e.g. from EDID) 635 * @funcs: connector control functions 636 * @edid_blob_ptr: DRM property containing EDID if present 637 * @properties: property tracking for this connector 638 * @path_blob_ptr: DRM blob property data for the DP MST path property 639 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling 640 * @dpms: current dpms state 641 * @helper_private: mid-layer private data 642 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector 643 * @force: a %DRM_FORCE_<foo> state for forced mode sets 644 * @override_edid: has the EDID been overwritten through debugfs for testing? 645 * @encoder_ids: valid encoders for this connector 646 * @encoder: encoder driving this connector, if any 647 * @eld: EDID-like data, if present 648 * @dvi_dual: dual link DVI, if found 649 * @max_tmds_clock: max clock rate, if found 650 * @latency_present: AV delay info from ELD, if found 651 * @video_latency: video latency info from ELD, if found 652 * @audio_latency: audio latency info from ELD, if found 653 * @null_edid_counter: track sinks that give us all zeros for the EDID 654 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum 655 * @edid_corrupt: indicates whether the last read EDID was corrupt 656 * @debugfs_entry: debugfs directory for this connector 657 * @state: current atomic state for this connector 658 * @has_tile: is this connector connected to a tiled monitor 659 * @tile_group: tile group for the connected monitor 660 * @tile_is_single_monitor: whether the tile is one monitor housing 661 * @num_h_tile: number of horizontal tiles in the tile group 662 * @num_v_tile: number of vertical tiles in the tile group 663 * @tile_h_loc: horizontal location of this tile 664 * @tile_v_loc: vertical location of this tile 665 * @tile_h_size: horizontal size of this tile. 666 * @tile_v_size: vertical size of this tile. 667 * 668 * Each connector may be connected to one or more CRTCs, or may be clonable by 669 * another connector if they can share a CRTC. Each connector also has a specific 670 * position in the broader display (referred to as a 'screen' though it could 671 * span multiple monitors). 672 */ 673 struct drm_connector { 674 struct drm_device *dev; 675 struct device *kdev; 676 struct device_attribute *attr; 677 struct list_head head; 678 679 struct drm_mode_object base; 680 681 char *name; 682 int connector_type; 683 int connector_type_id; 684 bool interlace_allowed; 685 bool doublescan_allowed; 686 bool stereo_allowed; 687 struct list_head modes; /* list of modes on this connector */ 688 689 enum drm_connector_status status; 690 691 /* these are modes added by probing with DDC or the BIOS */ 692 struct list_head probed_modes; 693 694 struct drm_display_info display_info; 695 const struct drm_connector_funcs *funcs; 696 697 struct drm_property_blob *edid_blob_ptr; 698 struct drm_object_properties properties; 699 700 struct drm_property_blob *path_blob_ptr; 701 702 struct drm_property_blob *tile_blob_ptr; 703 704 uint8_t polled; /* DRM_CONNECTOR_POLL_* */ 705 706 /* requested DPMS state */ 707 int dpms; 708 709 void *helper_private; 710 711 /* forced on connector */ 712 struct drm_cmdline_mode cmdline_mode; 713 enum drm_connector_force force; 714 bool override_edid; 715 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER]; 716 struct drm_encoder *encoder; /* currently active encoder */ 717 718 /* EDID bits */ 719 uint8_t eld[MAX_ELD_BYTES]; 720 bool dvi_dual; 721 int max_tmds_clock; /* in MHz */ 722 bool latency_present[2]; 723 int video_latency[2]; /* [0]: progressive, [1]: interlaced */ 724 int audio_latency[2]; 725 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */ 726 unsigned bad_edid_counter; 727 728 /* Flag for raw EDID header corruption - used in Displayport 729 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6 730 */ 731 bool edid_corrupt; 732 733 struct dentry *debugfs_entry; 734 735 struct drm_connector_state *state; 736 737 /* DisplayID bits */ 738 bool has_tile; 739 struct drm_tile_group *tile_group; 740 bool tile_is_single_monitor; 741 742 uint8_t num_h_tile, num_v_tile; 743 uint8_t tile_h_loc, tile_v_loc; 744 uint16_t tile_h_size, tile_v_size; 745 }; 746 747 /** 748 * struct drm_plane_state - mutable plane state 749 * @plane: backpointer to the plane 750 * @crtc: currently bound CRTC, NULL if disabled 751 * @fb: currently bound framebuffer 752 * @fence: optional fence to wait for before scanning out @fb 753 * @crtc_x: left position of visible portion of plane on crtc 754 * @crtc_y: upper position of visible portion of plane on crtc 755 * @crtc_w: width of visible portion of plane on crtc 756 * @crtc_h: height of visible portion of plane on crtc 757 * @src_x: left position of visible portion of plane within 758 * plane (in 16.16) 759 * @src_y: upper position of visible portion of plane within 760 * plane (in 16.16) 761 * @src_w: width of visible portion of plane (in 16.16) 762 * @src_h: height of visible portion of plane (in 16.16) 763 * @state: backpointer to global drm_atomic_state 764 */ 765 struct drm_plane_state { 766 struct drm_plane *plane; 767 768 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */ 769 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */ 770 struct fence *fence; 771 772 /* Signed dest location allows it to be partially off screen */ 773 int32_t crtc_x, crtc_y; 774 uint32_t crtc_w, crtc_h; 775 776 /* Source values are 16.16 fixed point */ 777 uint32_t src_x, src_y; 778 uint32_t src_h, src_w; 779 780 /* Plane rotation */ 781 unsigned int rotation; 782 783 struct drm_atomic_state *state; 784 }; 785 786 787 /** 788 * struct drm_plane_funcs - driver plane control functions 789 * @update_plane: update the plane configuration 790 * @disable_plane: shut down the plane 791 * @destroy: clean up plane resources 792 * @reset: reset plane after state has been invalidated (e.g. resume) 793 * @set_property: called when a property is changed 794 * @atomic_duplicate_state: duplicate the atomic state for this plane 795 * @atomic_destroy_state: destroy an atomic state for this plane 796 * @atomic_set_property: set a property on an atomic state for this plane 797 * (do not call directly, use drm_atomic_plane_set_property()) 798 * @atomic_get_property: get a property on an atomic state for this plane 799 * (do not call directly, use drm_atomic_plane_get_property()) 800 */ 801 struct drm_plane_funcs { 802 int (*update_plane)(struct drm_plane *plane, 803 struct drm_crtc *crtc, struct drm_framebuffer *fb, 804 int crtc_x, int crtc_y, 805 unsigned int crtc_w, unsigned int crtc_h, 806 uint32_t src_x, uint32_t src_y, 807 uint32_t src_w, uint32_t src_h); 808 int (*disable_plane)(struct drm_plane *plane); 809 void (*destroy)(struct drm_plane *plane); 810 void (*reset)(struct drm_plane *plane); 811 812 int (*set_property)(struct drm_plane *plane, 813 struct drm_property *property, uint64_t val); 814 815 /* atomic update handling */ 816 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane); 817 void (*atomic_destroy_state)(struct drm_plane *plane, 818 struct drm_plane_state *state); 819 int (*atomic_set_property)(struct drm_plane *plane, 820 struct drm_plane_state *state, 821 struct drm_property *property, 822 uint64_t val); 823 int (*atomic_get_property)(struct drm_plane *plane, 824 const struct drm_plane_state *state, 825 struct drm_property *property, 826 uint64_t *val); 827 }; 828 829 enum drm_plane_type { 830 DRM_PLANE_TYPE_OVERLAY, 831 DRM_PLANE_TYPE_PRIMARY, 832 DRM_PLANE_TYPE_CURSOR, 833 }; 834 835 /** 836 * struct drm_plane - central DRM plane control structure 837 * @dev: DRM device this plane belongs to 838 * @head: for list management 839 * @base: base mode object 840 * @possible_crtcs: pipes this plane can be bound to 841 * @format_types: array of formats supported by this plane 842 * @format_count: number of formats supported 843 * @format_default: driver hasn't supplied supported formats for the plane 844 * @crtc: currently bound CRTC 845 * @fb: currently bound fb 846 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by 847 * drm_mode_set_config_internal() to implement correct refcounting. 848 * @funcs: helper functions 849 * @properties: property tracking for this plane 850 * @type: type of plane (overlay, primary, cursor) 851 * @state: current atomic state for this plane 852 */ 853 struct drm_plane { 854 struct drm_device *dev; 855 struct list_head head; 856 857 struct drm_modeset_lock mutex; 858 859 struct drm_mode_object base; 860 861 uint32_t possible_crtcs; 862 uint32_t *format_types; 863 uint32_t format_count; 864 bool format_default; 865 866 struct drm_crtc *crtc; 867 struct drm_framebuffer *fb; 868 869 struct drm_framebuffer *old_fb; 870 871 const struct drm_plane_funcs *funcs; 872 873 struct drm_object_properties properties; 874 875 enum drm_plane_type type; 876 877 const void *helper_private; 878 879 struct drm_plane_state *state; 880 }; 881 882 /** 883 * struct drm_bridge_funcs - drm_bridge control functions 884 * @attach: Called during drm_bridge_attach 885 * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge 886 * @disable: Called right before encoder prepare, disables the bridge 887 * @post_disable: Called right after encoder prepare, for lockstepped disable 888 * @mode_set: Set this mode to the bridge 889 * @pre_enable: Called right before encoder commit, for lockstepped commit 890 * @enable: Called right after encoder commit, enables the bridge 891 */ 892 struct drm_bridge_funcs { 893 int (*attach)(struct drm_bridge *bridge); 894 bool (*mode_fixup)(struct drm_bridge *bridge, 895 const struct drm_display_mode *mode, 896 struct drm_display_mode *adjusted_mode); 897 void (*disable)(struct drm_bridge *bridge); 898 void (*post_disable)(struct drm_bridge *bridge); 899 void (*mode_set)(struct drm_bridge *bridge, 900 struct drm_display_mode *mode, 901 struct drm_display_mode *adjusted_mode); 902 void (*pre_enable)(struct drm_bridge *bridge); 903 void (*enable)(struct drm_bridge *bridge); 904 }; 905 906 /** 907 * struct drm_bridge - central DRM bridge control structure 908 * @dev: DRM device this bridge belongs to 909 * @encoder: encoder to which this bridge is connected 910 * @next: the next bridge in the encoder chain 911 * @of_node: device node pointer to the bridge 912 * @list: to keep track of all added bridges 913 * @base: base mode object 914 * @funcs: control functions 915 * @driver_private: pointer to the bridge driver's internal context 916 */ 917 struct drm_bridge { 918 struct drm_device *dev; 919 struct drm_encoder *encoder; 920 struct drm_bridge *next; 921 #ifdef CONFIG_OF 922 struct device_node *of_node; 923 #endif 924 struct list_head list; 925 926 const struct drm_bridge_funcs *funcs; 927 void *driver_private; 928 }; 929 930 /** 931 * struct drm_atomic_state - the global state object for atomic updates 932 * @dev: parent DRM device 933 * @allow_modeset: allow full modeset 934 * @legacy_cursor_update: hint to enforce legacy cursor ioctl semantics 935 * @planes: pointer to array of plane pointers 936 * @plane_states: pointer to array of plane states pointers 937 * @crtcs: pointer to array of CRTC pointers 938 * @crtc_states: pointer to array of CRTC states pointers 939 * @num_connector: size of the @connectors and @connector_states arrays 940 * @connectors: pointer to array of connector pointers 941 * @connector_states: pointer to array of connector states pointers 942 * @acquire_ctx: acquire context for this atomic modeset state update 943 */ 944 struct drm_atomic_state { 945 struct drm_device *dev; 946 bool allow_modeset : 1; 947 bool legacy_cursor_update : 1; 948 struct drm_plane **planes; 949 struct drm_plane_state **plane_states; 950 struct drm_crtc **crtcs; 951 struct drm_crtc_state **crtc_states; 952 int num_connector; 953 struct drm_connector **connectors; 954 struct drm_connector_state **connector_states; 955 956 struct drm_modeset_acquire_ctx *acquire_ctx; 957 }; 958 959 960 /** 961 * struct drm_mode_set - new values for a CRTC config change 962 * @fb: framebuffer to use for new config 963 * @crtc: CRTC whose configuration we're about to change 964 * @mode: mode timings to use 965 * @x: position of this CRTC relative to @fb 966 * @y: position of this CRTC relative to @fb 967 * @connectors: array of connectors to drive with this CRTC if possible 968 * @num_connectors: size of @connectors array 969 * 970 * Represents a single crtc the connectors that it drives with what mode 971 * and from which framebuffer it scans out from. 972 * 973 * This is used to set modes. 974 */ 975 struct drm_mode_set { 976 struct drm_framebuffer *fb; 977 struct drm_crtc *crtc; 978 struct drm_display_mode *mode; 979 980 uint32_t x; 981 uint32_t y; 982 983 struct drm_connector **connectors; 984 size_t num_connectors; 985 }; 986 987 /** 988 * struct drm_mode_config_funcs - basic driver provided mode setting functions 989 * @fb_create: create a new framebuffer object 990 * @output_poll_changed: function to handle output configuration changes 991 * @atomic_check: check whether a given atomic state update is possible 992 * @atomic_commit: commit an atomic state update previously verified with 993 * atomic_check() 994 * @atomic_state_alloc: allocate a new atomic state 995 * @atomic_state_clear: clear the atomic state 996 * @atomic_state_free: free the atomic state 997 * 998 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that 999 * involve drivers. 1000 */ 1001 struct drm_mode_config_funcs { 1002 struct drm_framebuffer *(*fb_create)(struct drm_device *dev, 1003 struct drm_file *file_priv, 1004 struct drm_mode_fb_cmd2 *mode_cmd); 1005 void (*output_poll_changed)(struct drm_device *dev); 1006 1007 int (*atomic_check)(struct drm_device *dev, 1008 struct drm_atomic_state *a); 1009 int (*atomic_commit)(struct drm_device *dev, 1010 struct drm_atomic_state *a, 1011 bool async); 1012 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev); 1013 void (*atomic_state_clear)(struct drm_atomic_state *state); 1014 void (*atomic_state_free)(struct drm_atomic_state *state); 1015 }; 1016 1017 /** 1018 * struct drm_mode_group - group of mode setting resources for potential sub-grouping 1019 * @num_crtcs: CRTC count 1020 * @num_encoders: encoder count 1021 * @num_connectors: connector count 1022 * @num_bridges: bridge count 1023 * @id_list: list of KMS object IDs in this group 1024 * 1025 * Currently this simply tracks the global mode setting state. But in the 1026 * future it could allow groups of objects to be set aside into independent 1027 * control groups for use by different user level processes (e.g. two X servers 1028 * running simultaneously on different heads, each with their own mode 1029 * configuration and freedom of mode setting). 1030 */ 1031 struct drm_mode_group { 1032 uint32_t num_crtcs; 1033 uint32_t num_encoders; 1034 uint32_t num_connectors; 1035 1036 /* list of object IDs for this group */ 1037 uint32_t *id_list; 1038 }; 1039 1040 /** 1041 * struct drm_mode_config - Mode configuration control structure 1042 * @mutex: mutex protecting KMS related lists and structures 1043 * @connection_mutex: ww mutex protecting connector state and routing 1044 * @acquire_ctx: global implicit acquire context used by atomic drivers for 1045 * legacy ioctls 1046 * @idr_mutex: mutex for KMS ID allocation and management 1047 * @crtc_idr: main KMS ID tracking object 1048 * @fb_lock: mutex to protect fb state and lists 1049 * @num_fb: number of fbs available 1050 * @fb_list: list of framebuffers available 1051 * @num_connector: number of connectors on this device 1052 * @connector_list: list of connector objects 1053 * @num_encoder: number of encoders on this device 1054 * @encoder_list: list of encoder objects 1055 * @num_overlay_plane: number of overlay planes on this device 1056 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device 1057 * @plane_list: list of plane objects 1058 * @num_crtc: number of CRTCs on this device 1059 * @crtc_list: list of CRTC objects 1060 * @property_list: list of property objects 1061 * @min_width: minimum pixel width on this device 1062 * @min_height: minimum pixel height on this device 1063 * @max_width: maximum pixel width on this device 1064 * @max_height: maximum pixel height on this device 1065 * @funcs: core driver provided mode setting functions 1066 * @fb_base: base address of the framebuffer 1067 * @poll_enabled: track polling support for this device 1068 * @poll_running: track polling status for this device 1069 * @output_poll_work: delayed work for polling in process context 1070 * @property_blob_list: list of all the blob property objects 1071 * @blob_lock: mutex for blob property allocation and management 1072 * @*_property: core property tracking 1073 * @preferred_depth: preferred RBG pixel depth, used by fb helpers 1074 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering 1075 * @async_page_flip: does this device support async flips on the primary plane? 1076 * @cursor_width: hint to userspace for max cursor width 1077 * @cursor_height: hint to userspace for max cursor height 1078 * 1079 * Core mode resource tracking structure. All CRTC, encoders, and connectors 1080 * enumerated by the driver are added here, as are global properties. Some 1081 * global restrictions are also here, e.g. dimension restrictions. 1082 */ 1083 struct drm_mode_config { 1084 struct lock mutex; /* protects configuration (mode lists etc.) */ 1085 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */ 1086 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */ 1087 struct lock idr_mutex; /* for IDR management */ 1088 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */ 1089 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */ 1090 /* this is limited to one for now */ 1091 1092 struct lock fb_lock; /* proctects global and per-file fb lists */ 1093 int num_fb; 1094 struct list_head fb_list; 1095 1096 int num_connector; 1097 struct list_head connector_list; 1098 int num_encoder; 1099 struct list_head encoder_list; 1100 1101 /* 1102 * Track # of overlay planes separately from # of total planes. By 1103 * default we only advertise overlay planes to userspace; if userspace 1104 * sets the "universal plane" capability bit, we'll go ahead and 1105 * expose all planes. 1106 */ 1107 int num_overlay_plane; 1108 int num_total_plane; 1109 struct list_head plane_list; 1110 1111 int num_crtc; 1112 struct list_head crtc_list; 1113 1114 struct list_head property_list; 1115 1116 int min_width, min_height; 1117 int max_width, max_height; 1118 const struct drm_mode_config_funcs *funcs; 1119 resource_size_t fb_base; 1120 1121 /* output poll support */ 1122 bool poll_enabled; 1123 bool poll_running; 1124 bool delayed_event; 1125 struct delayed_work output_poll_work; 1126 1127 struct lock blob_lock; 1128 1129 /* pointers to standard properties */ 1130 struct list_head property_blob_list; 1131 struct drm_property *edid_property; 1132 struct drm_property *dpms_property; 1133 struct drm_property *path_property; 1134 struct drm_property *tile_property; 1135 struct drm_property *plane_type_property; 1136 struct drm_property *rotation_property; 1137 struct drm_property *prop_src_x; 1138 struct drm_property *prop_src_y; 1139 struct drm_property *prop_src_w; 1140 struct drm_property *prop_src_h; 1141 struct drm_property *prop_crtc_x; 1142 struct drm_property *prop_crtc_y; 1143 struct drm_property *prop_crtc_w; 1144 struct drm_property *prop_crtc_h; 1145 struct drm_property *prop_fb_id; 1146 struct drm_property *prop_crtc_id; 1147 struct drm_property *prop_active; 1148 struct drm_property *prop_mode_id; 1149 1150 /* DVI-I properties */ 1151 struct drm_property *dvi_i_subconnector_property; 1152 struct drm_property *dvi_i_select_subconnector_property; 1153 1154 /* TV properties */ 1155 struct drm_property *tv_subconnector_property; 1156 struct drm_property *tv_select_subconnector_property; 1157 struct drm_property *tv_mode_property; 1158 struct drm_property *tv_left_margin_property; 1159 struct drm_property *tv_right_margin_property; 1160 struct drm_property *tv_top_margin_property; 1161 struct drm_property *tv_bottom_margin_property; 1162 struct drm_property *tv_brightness_property; 1163 struct drm_property *tv_contrast_property; 1164 struct drm_property *tv_flicker_reduction_property; 1165 struct drm_property *tv_overscan_property; 1166 struct drm_property *tv_saturation_property; 1167 struct drm_property *tv_hue_property; 1168 1169 /* Optional properties */ 1170 struct drm_property *scaling_mode_property; 1171 struct drm_property *aspect_ratio_property; 1172 struct drm_property *dirty_info_property; 1173 1174 /* properties for virtual machine layout */ 1175 struct drm_property *suggested_x_property; 1176 struct drm_property *suggested_y_property; 1177 1178 /* dumb ioctl parameters */ 1179 uint32_t preferred_depth, prefer_shadow; 1180 1181 /* whether async page flip is supported or not */ 1182 bool async_page_flip; 1183 1184 /* whether the driver supports fb modifiers */ 1185 bool allow_fb_modifiers; 1186 1187 /* cursor size */ 1188 uint32_t cursor_width, cursor_height; 1189 }; 1190 1191 /** 1192 * drm_for_each_plane_mask - iterate over planes specified by bitmask 1193 * @plane: the loop cursor 1194 * @dev: the DRM device 1195 * @plane_mask: bitmask of plane indices 1196 * 1197 * Iterate over all planes specified by bitmask. 1198 */ 1199 #define drm_for_each_plane_mask(plane, dev, plane_mask) \ 1200 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \ 1201 if ((plane_mask) & (1 << drm_plane_index(plane))) 1202 1203 1204 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base) 1205 #define obj_to_connector(x) container_of(x, struct drm_connector, base) 1206 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base) 1207 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base) 1208 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base) 1209 #define obj_to_property(x) container_of(x, struct drm_property, base) 1210 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base) 1211 #define obj_to_plane(x) container_of(x, struct drm_plane, base) 1212 1213 struct drm_prop_enum_list { 1214 int type; 1215 char *name; 1216 }; 1217 1218 extern int drm_crtc_init_with_planes(struct drm_device *dev, 1219 struct drm_crtc *crtc, 1220 struct drm_plane *primary, 1221 struct drm_plane *cursor, 1222 const struct drm_crtc_funcs *funcs); 1223 extern void drm_crtc_cleanup(struct drm_crtc *crtc); 1224 extern unsigned int drm_crtc_index(struct drm_crtc *crtc); 1225 1226 /** 1227 * drm_crtc_mask - find the mask of a registered CRTC 1228 * @crtc: CRTC to find mask for 1229 * 1230 * Given a registered CRTC, return the mask bit of that CRTC for an 1231 * encoder's possible_crtcs field. 1232 */ 1233 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc) 1234 { 1235 return 1 << drm_crtc_index(crtc); 1236 } 1237 1238 extern void drm_connector_ida_init(void); 1239 extern void drm_connector_ida_destroy(void); 1240 extern int drm_connector_init(struct drm_device *dev, 1241 struct drm_connector *connector, 1242 const struct drm_connector_funcs *funcs, 1243 int connector_type); 1244 int drm_connector_register(struct drm_connector *connector); 1245 void drm_connector_unregister(struct drm_connector *connector); 1246 1247 extern void drm_connector_cleanup(struct drm_connector *connector); 1248 extern unsigned int drm_connector_index(struct drm_connector *connector); 1249 /* helper to unplug all connectors from sysfs for device */ 1250 extern void drm_connector_unplug_all(struct drm_device *dev); 1251 1252 extern int drm_bridge_add(struct drm_bridge *bridge); 1253 extern void drm_bridge_remove(struct drm_bridge *bridge); 1254 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np); 1255 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge); 1256 1257 bool drm_bridge_mode_fixup(struct drm_bridge *bridge, 1258 const struct drm_display_mode *mode, 1259 struct drm_display_mode *adjusted_mode); 1260 void drm_bridge_disable(struct drm_bridge *bridge); 1261 void drm_bridge_post_disable(struct drm_bridge *bridge); 1262 void drm_bridge_mode_set(struct drm_bridge *bridge, 1263 struct drm_display_mode *mode, 1264 struct drm_display_mode *adjusted_mode); 1265 void drm_bridge_pre_enable(struct drm_bridge *bridge); 1266 void drm_bridge_enable(struct drm_bridge *bridge); 1267 1268 extern int drm_encoder_init(struct drm_device *dev, 1269 struct drm_encoder *encoder, 1270 const struct drm_encoder_funcs *funcs, 1271 int encoder_type); 1272 1273 /** 1274 * drm_encoder_crtc_ok - can a given crtc drive a given encoder? 1275 * @encoder: encoder to test 1276 * @crtc: crtc to test 1277 * 1278 * Return false if @encoder can't be driven by @crtc, true otherwise. 1279 */ 1280 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder, 1281 struct drm_crtc *crtc) 1282 { 1283 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc)); 1284 } 1285 1286 extern int drm_universal_plane_init(struct drm_device *dev, 1287 struct drm_plane *plane, 1288 unsigned long possible_crtcs, 1289 const struct drm_plane_funcs *funcs, 1290 const uint32_t *formats, 1291 uint32_t format_count, 1292 enum drm_plane_type type); 1293 extern int drm_plane_init(struct drm_device *dev, 1294 struct drm_plane *plane, 1295 unsigned long possible_crtcs, 1296 const struct drm_plane_funcs *funcs, 1297 const uint32_t *formats, uint32_t format_count, 1298 bool is_primary); 1299 extern void drm_plane_cleanup(struct drm_plane *plane); 1300 extern unsigned int drm_plane_index(struct drm_plane *plane); 1301 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx); 1302 extern void drm_plane_force_disable(struct drm_plane *plane); 1303 extern int drm_plane_check_pixel_format(const struct drm_plane *plane, 1304 u32 format); 1305 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, 1306 int *hdisplay, int *vdisplay); 1307 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc, 1308 int x, int y, 1309 const struct drm_display_mode *mode, 1310 const struct drm_framebuffer *fb); 1311 1312 extern void drm_encoder_cleanup(struct drm_encoder *encoder); 1313 1314 extern const char *drm_get_connector_status_name(enum drm_connector_status status); 1315 extern const char *drm_get_subpixel_order_name(enum subpixel_order order); 1316 extern const char *drm_get_dpms_name(int val); 1317 extern const char *drm_get_dvi_i_subconnector_name(int val); 1318 extern const char *drm_get_dvi_i_select_name(int val); 1319 extern const char *drm_get_tv_subconnector_name(int val); 1320 extern const char *drm_get_tv_select_name(int val); 1321 extern void drm_fb_release(struct drm_file *file_priv); 1322 extern void drm_property_destroy_user_blobs(struct drm_device *dev, 1323 struct drm_file *file_priv); 1324 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group); 1325 extern void drm_mode_group_destroy(struct drm_mode_group *group); 1326 extern void drm_reinit_primary_mode_group(struct drm_device *dev); 1327 extern bool drm_probe_ddc(struct i2c_adapter *adapter); 1328 extern struct edid *drm_get_edid(struct drm_connector *connector, 1329 struct i2c_adapter *adapter); 1330 extern struct edid *drm_edid_duplicate(const struct edid *edid); 1331 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); 1332 extern void drm_mode_config_init(struct drm_device *dev); 1333 extern void drm_mode_config_reset(struct drm_device *dev); 1334 extern void drm_mode_config_cleanup(struct drm_device *dev); 1335 1336 extern int drm_mode_connector_set_path_property(struct drm_connector *connector, 1337 const char *path); 1338 int drm_mode_connector_set_tile_property(struct drm_connector *connector); 1339 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector, 1340 const struct edid *edid); 1341 1342 extern int drm_display_info_set_bus_formats(struct drm_display_info *info, 1343 const u32 *formats, 1344 unsigned int num_formats); 1345 1346 static inline bool drm_property_type_is(struct drm_property *property, 1347 uint32_t type) 1348 { 1349 /* instanceof for props.. handles extended type vs original types: */ 1350 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) 1351 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type; 1352 return property->flags & type; 1353 } 1354 1355 static inline bool drm_property_type_valid(struct drm_property *property) 1356 { 1357 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) 1358 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE); 1359 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE); 1360 } 1361 1362 extern int drm_object_property_set_value(struct drm_mode_object *obj, 1363 struct drm_property *property, 1364 uint64_t val); 1365 extern int drm_object_property_get_value(struct drm_mode_object *obj, 1366 struct drm_property *property, 1367 uint64_t *value); 1368 extern int drm_framebuffer_init(struct drm_device *dev, 1369 struct drm_framebuffer *fb, 1370 const struct drm_framebuffer_funcs *funcs); 1371 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, 1372 uint32_t id); 1373 extern void drm_framebuffer_unreference(struct drm_framebuffer *fb); 1374 extern void drm_framebuffer_reference(struct drm_framebuffer *fb); 1375 extern void drm_framebuffer_remove(struct drm_framebuffer *fb); 1376 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb); 1377 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb); 1378 1379 extern void drm_object_attach_property(struct drm_mode_object *obj, 1380 struct drm_property *property, 1381 uint64_t init_val); 1382 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags, 1383 const char *name, int num_values); 1384 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, 1385 const char *name, 1386 const struct drm_prop_enum_list *props, 1387 int num_values); 1388 struct drm_property *drm_property_create_bitmask(struct drm_device *dev, 1389 int flags, const char *name, 1390 const struct drm_prop_enum_list *props, 1391 int num_props, 1392 uint64_t supported_bits); 1393 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, 1394 const char *name, 1395 uint64_t min, uint64_t max); 1396 struct drm_property *drm_property_create_signed_range(struct drm_device *dev, 1397 int flags, const char *name, 1398 int64_t min, int64_t max); 1399 struct drm_property *drm_property_create_object(struct drm_device *dev, 1400 int flags, const char *name, uint32_t type); 1401 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags, 1402 const char *name); 1403 struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, 1404 size_t length, 1405 const void *data); 1406 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev, 1407 uint32_t id); 1408 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob); 1409 void drm_property_unreference_blob(struct drm_property_blob *blob); 1410 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property); 1411 extern int drm_property_add_enum(struct drm_property *property, int index, 1412 uint64_t value, const char *name); 1413 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev); 1414 extern int drm_mode_create_tv_properties(struct drm_device *dev, 1415 unsigned int num_modes, 1416 char *modes[]); 1417 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev); 1418 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev); 1419 extern int drm_mode_create_dirty_info_property(struct drm_device *dev); 1420 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev); 1421 extern bool drm_property_change_valid_get(struct drm_property *property, 1422 uint64_t value, struct drm_mode_object **ref); 1423 extern void drm_property_change_valid_put(struct drm_property *property, 1424 struct drm_mode_object *ref); 1425 1426 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector, 1427 struct drm_encoder *encoder); 1428 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, 1429 int gamma_size); 1430 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, 1431 uint32_t id, uint32_t type); 1432 1433 /* IOCTLs */ 1434 extern int drm_mode_getresources(struct drm_device *dev, 1435 void *data, struct drm_file *file_priv); 1436 extern int drm_mode_getplane_res(struct drm_device *dev, void *data, 1437 struct drm_file *file_priv); 1438 extern int drm_mode_getcrtc(struct drm_device *dev, 1439 void *data, struct drm_file *file_priv); 1440 extern int drm_mode_getconnector(struct drm_device *dev, 1441 void *data, struct drm_file *file_priv); 1442 extern int drm_mode_set_config_internal(struct drm_mode_set *set); 1443 extern int drm_mode_setcrtc(struct drm_device *dev, 1444 void *data, struct drm_file *file_priv); 1445 extern int drm_mode_getplane(struct drm_device *dev, 1446 void *data, struct drm_file *file_priv); 1447 extern int drm_mode_setplane(struct drm_device *dev, 1448 void *data, struct drm_file *file_priv); 1449 extern int drm_mode_cursor_ioctl(struct drm_device *dev, 1450 void *data, struct drm_file *file_priv); 1451 extern int drm_mode_cursor2_ioctl(struct drm_device *dev, 1452 void *data, struct drm_file *file_priv); 1453 extern int drm_mode_addfb(struct drm_device *dev, 1454 void *data, struct drm_file *file_priv); 1455 extern int drm_mode_addfb2(struct drm_device *dev, 1456 void *data, struct drm_file *file_priv); 1457 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); 1458 extern int drm_mode_rmfb(struct drm_device *dev, 1459 void *data, struct drm_file *file_priv); 1460 extern int drm_mode_getfb(struct drm_device *dev, 1461 void *data, struct drm_file *file_priv); 1462 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev, 1463 void *data, struct drm_file *file_priv); 1464 1465 extern int drm_mode_getproperty_ioctl(struct drm_device *dev, 1466 void *data, struct drm_file *file_priv); 1467 extern int drm_mode_getblob_ioctl(struct drm_device *dev, 1468 void *data, struct drm_file *file_priv); 1469 extern int drm_mode_createblob_ioctl(struct drm_device *dev, 1470 void *data, struct drm_file *file_priv); 1471 extern int drm_mode_destroyblob_ioctl(struct drm_device *dev, 1472 void *data, struct drm_file *file_priv); 1473 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev, 1474 void *data, struct drm_file *file_priv); 1475 extern int drm_mode_getencoder(struct drm_device *dev, 1476 void *data, struct drm_file *file_priv); 1477 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev, 1478 void *data, struct drm_file *file_priv); 1479 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev, 1480 void *data, struct drm_file *file_priv); 1481 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match); 1482 extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code); 1483 extern bool drm_detect_hdmi_monitor(struct edid *edid); 1484 extern bool drm_detect_monitor_audio(struct edid *edid); 1485 extern bool drm_rgb_quant_range_selectable(struct edid *edid); 1486 extern int drm_mode_page_flip_ioctl(struct drm_device *dev, 1487 void *data, struct drm_file *file_priv); 1488 extern int drm_add_modes_noedid(struct drm_connector *connector, 1489 int hdisplay, int vdisplay); 1490 extern void drm_set_preferred_mode(struct drm_connector *connector, 1491 int hpref, int vpref); 1492 1493 extern int drm_edid_header_is_valid(const u8 *raw_edid); 1494 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, 1495 bool *edid_corrupt); 1496 extern bool drm_edid_is_valid(struct edid *edid); 1497 1498 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 1499 char topology[8]); 1500 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, 1501 char topology[8]); 1502 extern void drm_mode_put_tile_group(struct drm_device *dev, 1503 struct drm_tile_group *tg); 1504 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, 1505 int hsize, int vsize, int fresh, 1506 bool rb); 1507 1508 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev, 1509 void *data, struct drm_file *file_priv); 1510 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev, 1511 void *data, struct drm_file *file_priv); 1512 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev, 1513 void *data, struct drm_file *file_priv); 1514 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, 1515 struct drm_file *file_priv); 1516 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, 1517 struct drm_file *file_priv); 1518 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane, 1519 struct drm_property *property, 1520 uint64_t value); 1521 1522 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, 1523 int *bpp); 1524 extern int drm_format_num_planes(uint32_t format); 1525 extern int drm_format_plane_cpp(uint32_t format, int plane); 1526 extern int drm_format_horz_chroma_subsampling(uint32_t format); 1527 extern int drm_format_vert_chroma_subsampling(uint32_t format); 1528 extern const char *drm_get_format_name(uint32_t format); 1529 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, 1530 unsigned int supported_rotations); 1531 extern unsigned int drm_rotation_simplify(unsigned int rotation, 1532 unsigned int supported_rotations); 1533 1534 /* Helpers */ 1535 1536 static inline struct drm_plane *drm_plane_find(struct drm_device *dev, 1537 uint32_t id) 1538 { 1539 struct drm_mode_object *mo; 1540 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE); 1541 return mo ? obj_to_plane(mo) : NULL; 1542 } 1543 1544 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev, 1545 uint32_t id) 1546 { 1547 struct drm_mode_object *mo; 1548 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC); 1549 return mo ? obj_to_crtc(mo) : NULL; 1550 } 1551 1552 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev, 1553 uint32_t id) 1554 { 1555 struct drm_mode_object *mo; 1556 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER); 1557 return mo ? obj_to_encoder(mo) : NULL; 1558 } 1559 1560 static inline struct drm_connector *drm_connector_find(struct drm_device *dev, 1561 uint32_t id) 1562 { 1563 struct drm_mode_object *mo; 1564 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR); 1565 return mo ? obj_to_connector(mo) : NULL; 1566 } 1567 1568 static inline struct drm_property *drm_property_find(struct drm_device *dev, 1569 uint32_t id) 1570 { 1571 struct drm_mode_object *mo; 1572 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY); 1573 return mo ? obj_to_property(mo) : NULL; 1574 } 1575 1576 /* Plane list iterator for legacy (overlay only) planes. */ 1577 #define drm_for_each_legacy_plane(plane, planelist) \ 1578 list_for_each_entry(plane, planelist, head) \ 1579 if (plane->type == DRM_PLANE_TYPE_OVERLAY) 1580 1581 #endif /* __DRM_CRTC_H__ */ 1582