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