1 /* 2 * Copyright (c) 2006 Dave Airlie <airlied@linux.ie> 3 * Copyright (c) 2007-2008 Intel Corporation 4 * Jesse Barnes <jesse.barnes@intel.com> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the next 14 * paragraph) shall be included in all copies or substantial portions of the 15 * 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 * IN THE SOFTWARE. 24 */ 25 26 #ifndef __INTEL_DISPLAY_TYPES_H__ 27 #define __INTEL_DISPLAY_TYPES_H__ 28 29 #include <linux/pm_qos.h> 30 #include <linux/pwm.h> 31 32 #include <drm/display/drm_dp_dual_mode_helper.h> 33 #include <drm/display/drm_dp_mst_helper.h> 34 #include <drm/display/drm_dp_tunnel.h> 35 #include <drm/display/drm_dsc.h> 36 #include <drm/drm_atomic.h> 37 #include <drm/drm_colorop.h> 38 #include <drm/drm_crtc.h> 39 #include <drm/drm_encoder.h> 40 #include <drm/drm_framebuffer.h> 41 #include <drm/drm_panel.h> 42 #include <drm/drm_rect.h> 43 #include <drm/drm_vblank_work.h> 44 #include <drm/intel/i915_hdcp_interface.h> 45 #include <uapi/drm/i915_drm.h> 46 47 #include "i915_gtt_view_types.h" 48 #include "intel_bios.h" 49 #include "intel_display.h" 50 #include "intel_display_conversion.h" 51 #include "intel_display_limits.h" 52 #include "intel_display_power.h" 53 #include "intel_dpll_mgr.h" 54 #include "intel_dsi_vbt_defs.h" 55 #include "intel_wm_types.h" 56 57 struct cec_notifier; 58 struct drm_printer; 59 struct intel_connector; 60 struct intel_ddi_buf_trans; 61 struct intel_fbc; 62 struct intel_global_objs_state; 63 struct intel_hdcp_shim; 64 struct intel_panic; 65 struct intel_tc_port; 66 67 /* 68 * Display related stuff 69 */ 70 71 /* these are outputs from the chip - integrated only 72 external chips are via DVO or SDVO output */ 73 enum intel_output_type { 74 INTEL_OUTPUT_UNUSED = 0, 75 INTEL_OUTPUT_ANALOG = 1, 76 INTEL_OUTPUT_DVO = 2, 77 INTEL_OUTPUT_SDVO = 3, 78 INTEL_OUTPUT_LVDS = 4, 79 INTEL_OUTPUT_TVOUT = 5, 80 INTEL_OUTPUT_HDMI = 6, 81 INTEL_OUTPUT_DP = 7, 82 INTEL_OUTPUT_EDP = 8, 83 INTEL_OUTPUT_DSI = 9, 84 INTEL_OUTPUT_DDI = 10, 85 INTEL_OUTPUT_DP_MST = 11, 86 }; 87 88 enum hdmi_force_audio { 89 HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */ 90 HDMI_AUDIO_OFF, /* force turn off HDMI audio */ 91 HDMI_AUDIO_AUTO, /* trust EDID */ 92 HDMI_AUDIO_ON, /* force turn on HDMI audio */ 93 }; 94 95 /* "Broadcast RGB" property */ 96 enum intel_broadcast_rgb { 97 INTEL_BROADCAST_RGB_AUTO, 98 INTEL_BROADCAST_RGB_FULL, 99 INTEL_BROADCAST_RGB_LIMITED, 100 }; 101 102 struct intel_fb_view { 103 /* 104 * The remap information used in the remapped and rotated views to 105 * create the DMA scatter-gather list for each FB color plane. This sg 106 * list is created along with the view type (gtt.type) specific 107 * i915_vma object and contains the list of FB object pages (reordered 108 * in the rotated view) that are visible in the view. 109 * In the normal view the FB object's backing store sg list is used 110 * directly and hence the remap information here is not used. 111 */ 112 struct i915_gtt_view gtt; 113 114 /* 115 * The GTT view (gtt.type) specific information for each FB color 116 * plane. In the normal GTT view all formats (up to 4 color planes), 117 * in the rotated and remapped GTT view all no-CCS formats (up to 2 118 * color planes) are supported. 119 * 120 * The view information shared by all FB color planes in the FB, 121 * like dst x/y and src/dst width, is stored separately in 122 * intel_plane_state. 123 */ 124 struct i915_color_plane_view { 125 u32 offset; 126 unsigned int x, y; 127 /* 128 * Plane stride in: 129 * bytes for 0/180 degree rotation 130 * pixels for 90/270 degree rotation 131 */ 132 unsigned int mapping_stride; 133 unsigned int scanout_stride; 134 } color_plane[4]; 135 }; 136 137 struct intel_framebuffer { 138 struct drm_framebuffer base; 139 struct intel_frontbuffer *frontbuffer; 140 141 /* Params to remap the FB pages and program the plane registers in each view. */ 142 struct intel_fb_view normal_view; 143 union { 144 struct intel_fb_view rotated_view; 145 struct intel_fb_view remapped_view; 146 }; 147 148 struct intel_dpt *dpt; 149 150 unsigned int min_alignment; 151 unsigned int vtd_guard; 152 153 unsigned int (*panic_tiling)(unsigned int x, unsigned int y, unsigned int width); 154 struct intel_panic *panic; 155 }; 156 157 enum intel_hotplug_state { 158 INTEL_HOTPLUG_UNCHANGED, 159 INTEL_HOTPLUG_CHANGED, 160 INTEL_HOTPLUG_RETRY, 161 }; 162 163 struct intel_encoder { 164 struct drm_encoder base; 165 166 enum intel_output_type type; 167 enum port port; 168 u16 cloneable; 169 u8 pipe_mask; 170 171 /* Check and recover a bad link state. */ 172 struct delayed_work link_check_work; 173 void (*link_check)(struct intel_encoder *encoder); 174 175 enum intel_hotplug_state (*hotplug)(struct intel_encoder *encoder, 176 struct intel_connector *connector); 177 enum intel_output_type (*compute_output_type)(struct intel_encoder *, 178 struct intel_crtc_state *, 179 struct drm_connector_state *); 180 int (*compute_config)(struct intel_encoder *, 181 struct intel_crtc_state *, 182 struct drm_connector_state *); 183 int (*compute_config_late)(struct intel_encoder *, 184 struct intel_crtc_state *, 185 struct drm_connector_state *); 186 void (*pre_pll_enable)(struct intel_atomic_state *, 187 struct intel_encoder *, 188 const struct intel_crtc_state *, 189 const struct drm_connector_state *); 190 void (*pre_enable)(struct intel_atomic_state *, 191 struct intel_encoder *, 192 const struct intel_crtc_state *, 193 const struct drm_connector_state *); 194 void (*enable)(struct intel_atomic_state *, 195 struct intel_encoder *, 196 const struct intel_crtc_state *, 197 const struct drm_connector_state *); 198 void (*disable)(struct intel_atomic_state *, 199 struct intel_encoder *, 200 const struct intel_crtc_state *, 201 const struct drm_connector_state *); 202 void (*post_disable)(struct intel_atomic_state *, 203 struct intel_encoder *, 204 const struct intel_crtc_state *, 205 const struct drm_connector_state *); 206 void (*post_pll_disable)(struct intel_atomic_state *, 207 struct intel_encoder *, 208 const struct intel_crtc_state *, 209 const struct drm_connector_state *); 210 void (*update_pipe)(struct intel_atomic_state *, 211 struct intel_encoder *, 212 const struct intel_crtc_state *, 213 const struct drm_connector_state *); 214 void (*audio_enable)(struct intel_encoder *encoder, 215 const struct intel_crtc_state *crtc_state, 216 const struct drm_connector_state *conn_state); 217 void (*audio_disable)(struct intel_encoder *encoder, 218 const struct intel_crtc_state *old_crtc_state, 219 const struct drm_connector_state *old_conn_state); 220 /* Read out the current hw state of this connector, returning true if 221 * the encoder is active. If the encoder is enabled it also set the pipe 222 * it is connected to in the pipe parameter. */ 223 bool (*get_hw_state)(struct intel_encoder *, enum pipe *pipe); 224 /* Reconstructs the equivalent mode flags for the current hardware 225 * state. This must be called _after_ display->get_pipe_config has 226 * pre-filled the pipe config. Note that intel_encoder->base.crtc must 227 * be set correctly before calling this function. */ 228 void (*get_config)(struct intel_encoder *, 229 struct intel_crtc_state *pipe_config); 230 231 /* 232 * Optional hook called during init/resume to sync any state 233 * stored in the encoder (eg. DP link parameters) wrt. the HW state. 234 */ 235 void (*sync_state)(struct intel_encoder *encoder, 236 const struct intel_crtc_state *crtc_state); 237 238 /* 239 * Optional hook, returning true if this encoder allows a fastset 240 * during the initial commit, false otherwise. 241 */ 242 bool (*initial_fastset_check)(struct intel_encoder *encoder, 243 struct intel_crtc_state *crtc_state); 244 245 /* 246 * Acquires the power domains needed for an active encoder during 247 * hardware state readout. 248 */ 249 void (*get_power_domains)(struct intel_encoder *encoder, 250 struct intel_crtc_state *crtc_state); 251 /* 252 * Called during system suspend after all pending requests for the 253 * encoder are flushed (for example for DP AUX transactions) and 254 * device interrupts are disabled. 255 * All modeset locks are held while the hook is called. 256 */ 257 void (*suspend)(struct intel_encoder *); 258 /* 259 * Called without the modeset locks held after the suspend() hook for 260 * all encoders have been called. 261 */ 262 void (*suspend_complete)(struct intel_encoder *encoder); 263 /* 264 * Called during system reboot/shutdown after all the 265 * encoders have been disabled and suspended. 266 * All modeset locks are held while the hook is called. 267 */ 268 void (*shutdown)(struct intel_encoder *encoder); 269 /* 270 * Called without the modeset locks held after the shutdown() hook for 271 * all encoders have been called. 272 */ 273 void (*shutdown_complete)(struct intel_encoder *encoder); 274 /* 275 * Enable/disable the clock to the port. 276 */ 277 void (*enable_clock)(struct intel_encoder *encoder, 278 const struct intel_crtc_state *crtc_state); 279 void (*disable_clock)(struct intel_encoder *encoder); 280 /* 281 * Returns whether the port clock is enabled or not. 282 */ 283 bool (*is_clock_enabled)(struct intel_encoder *encoder); 284 /* 285 * Returns the PLL type the port uses. 286 */ 287 enum icl_port_dpll_id (*port_pll_type)(struct intel_encoder *encoder, 288 const struct intel_crtc_state *crtc_state); 289 const struct intel_ddi_buf_trans *(*get_buf_trans)(struct intel_encoder *encoder, 290 const struct intel_crtc_state *crtc_state, 291 int *n_entries); 292 void (*set_signal_levels)(struct intel_encoder *encoder, 293 const struct intel_crtc_state *crtc_state); 294 295 enum hpd_pin hpd_pin; 296 enum intel_display_power_domain power_domain; 297 298 /* VBT information for this encoder (may be NULL for older platforms) */ 299 const struct intel_bios_encoder_data *devdata; 300 }; 301 302 struct intel_panel_bl_funcs { 303 /* Connector and platform specific backlight functions */ 304 int (*setup)(struct intel_connector *connector, enum pipe pipe); 305 u32 (*get)(struct intel_connector *connector, enum pipe pipe); 306 void (*set)(const struct drm_connector_state *conn_state, u32 level); 307 void (*disable)(const struct drm_connector_state *conn_state, u32 level); 308 void (*enable)(const struct intel_crtc_state *crtc_state, 309 const struct drm_connector_state *conn_state, u32 level); 310 u32 (*hz_to_pwm)(struct intel_connector *connector, u32 hz); 311 }; 312 313 /* in 100us units */ 314 struct intel_pps_delays { 315 u16 power_up; /* eDP: T1+T3, LVDS: T1+T2 */ 316 u16 backlight_on; /* eDP: T8, LVDS: T5 */ 317 u16 backlight_off; /* eDP: T9, LVDS: T6/TX */ 318 u16 power_down; /* eDP: T10, LVDS: T3 */ 319 u16 power_cycle; /* eDP: T11+T12, LVDS: T7+T4 */ 320 }; 321 322 enum drrs_type { 323 DRRS_TYPE_NONE, 324 DRRS_TYPE_STATIC, 325 DRRS_TYPE_SEAMLESS, 326 }; 327 328 struct intel_vbt_panel_data { 329 struct drm_display_mode *lfp_vbt_mode; /* if any */ 330 struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */ 331 332 /* Feature bits */ 333 int panel_type; 334 unsigned int lvds_dither:1; 335 unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */ 336 337 bool vrr; 338 339 u8 seamless_drrs_min_refresh_rate; 340 enum drrs_type drrs_type; 341 342 struct { 343 int max_link_rate; 344 int rate; 345 int lanes; 346 int preemphasis; 347 int vswing; 348 int bpp; 349 struct intel_pps_delays pps; 350 u8 drrs_msa_timing_delay; 351 bool low_vswing; 352 bool hobl; 353 bool dsc_disable; 354 bool pipe_joiner_enable; 355 } edp; 356 357 struct { 358 bool enable; 359 bool full_link; 360 bool require_aux_wakeup; 361 int idle_frames; 362 int tp1_wakeup_time_us; 363 int tp2_tp3_wakeup_time_us; 364 int psr2_tp2_tp3_wakeup_time_us; 365 } psr; 366 367 struct { 368 u16 pwm_freq_hz; 369 u16 brightness_precision_bits; 370 u16 hdr_dpcd_refresh_timeout; 371 bool present; 372 bool active_low_pwm; 373 u8 min_brightness; /* min_brightness/255 of max */ 374 s8 controller; /* brightness controller number */ 375 enum intel_backlight_type type; 376 } backlight; 377 378 /* MIPI DSI */ 379 struct { 380 u16 panel_id; 381 struct mipi_config *config; 382 struct mipi_pps_data *pps; 383 u16 bl_ports; 384 u16 cabc_ports; 385 u8 seq_version; 386 u32 size; 387 u8 *data; 388 const u8 *sequence[MIPI_SEQ_MAX]; 389 u8 *deassert_seq; /* Used by fixup_mipi_sequences() */ 390 enum drm_panel_orientation orientation; 391 } dsi; 392 }; 393 394 struct intel_panel { 395 /* Simple drm_panel */ 396 struct drm_panel *base; 397 398 /* Fixed EDID for eDP and LVDS. May hold ERR_PTR for invalid EDID. */ 399 const struct drm_edid *fixed_edid; 400 401 struct list_head fixed_modes; 402 403 /* backlight */ 404 struct { 405 bool present; 406 u32 level; 407 u32 min; 408 u32 max; 409 bool enabled; 410 bool combination_mode; /* gen 2/4 only */ 411 bool active_low_pwm; 412 bool alternate_pwm_increment; /* lpt+ */ 413 414 /* PWM chip */ 415 u32 pwm_level_min; 416 u32 pwm_level_max; 417 bool pwm_enabled; 418 bool util_pin_active_low; /* bxt+ */ 419 u8 controller; /* bxt+ only */ 420 struct pwm_device *pwm; 421 struct pwm_state pwm_state; 422 423 /* DPCD backlight */ 424 union { 425 struct { 426 struct drm_edp_backlight_info info; 427 bool luminance_control_support; 428 } vesa; 429 struct { 430 bool sdr_uses_aux; 431 bool supports_2084_decode; 432 bool supports_2020_gamut; 433 bool supports_segmented_backlight; 434 bool supports_sdp_colorimetry; 435 bool supports_tone_mapping; 436 } intel_cap; 437 } edp; 438 439 struct backlight_device *device; 440 441 const struct intel_panel_bl_funcs *funcs; 442 const struct intel_panel_bl_funcs *pwm_funcs; 443 void (*power)(struct intel_connector *, bool enable); 444 } backlight; 445 446 struct intel_vbt_panel_data vbt; 447 }; 448 449 struct intel_digital_port; 450 451 struct intel_hdcp { 452 const struct intel_hdcp_shim *shim; 453 /* Mutex for hdcp state of the connector */ 454 struct mutex mutex; 455 u64 value; 456 struct delayed_work check_work; 457 struct work_struct prop_work; 458 459 /* HDCP1.4 Encryption status */ 460 bool hdcp_encrypted; 461 462 /* HDCP2.2 related definitions */ 463 /* Flag indicates whether this connector supports HDCP2.2 or not. */ 464 bool hdcp2_supported; 465 466 /* HDCP2.2 Encryption status */ 467 bool hdcp2_encrypted; 468 469 /* 470 * Content Stream Type defined by content owner. TYPE0(0x0) content can 471 * flow in the link protected by HDCP2.2 or HDCP1.4, where as TYPE1(0x1) 472 * content can flow only through a link protected by HDCP2.2. 473 */ 474 u8 content_type; 475 476 bool is_paired; 477 bool is_repeater; 478 479 /* 480 * Count of ReceiverID_List received. Initialized to 0 at AKE_INIT. 481 * Incremented after processing the RepeaterAuth_Send_ReceiverID_List. 482 * When it rolls over re-auth has to be triggered. 483 */ 484 u32 seq_num_v; 485 486 /* 487 * Count of RepeaterAuth_Stream_Manage msg propagated. 488 * Initialized to 0 on AKE_INIT. Incremented after every successful 489 * transmission of RepeaterAuth_Stream_Manage message. When it rolls 490 * over re-Auth has to be triggered. 491 */ 492 u32 seq_num_m; 493 494 /* 495 * Work queue to signal the CP_IRQ. Used for the waiters to read the 496 * available information from HDCP DP sink. 497 */ 498 wait_queue_head_t cp_irq_queue; 499 atomic_t cp_irq_count; 500 int cp_irq_count_cached; 501 502 /* 503 * HDCP register access for gen12+ need the transcoder associated. 504 * Transcoder attached to the connector could be changed at modeset. 505 * Hence caching the transcoder here. 506 */ 507 enum transcoder cpu_transcoder; 508 /* Only used for DP MST stream encryption */ 509 enum transcoder stream_transcoder; 510 /* Used to force HDCP 1.4 bypassing HDCP 2.x */ 511 bool force_hdcp14; 512 }; 513 514 enum intel_panel_replay_dsc_support { 515 INTEL_DP_PANEL_REPLAY_DSC_NOT_SUPPORTED, 516 INTEL_DP_PANEL_REPLAY_DSC_FULL_FRAME_ONLY, 517 INTEL_DP_PANEL_REPLAY_DSC_SELECTIVE_UPDATE, 518 }; 519 520 struct intel_connector { 521 struct drm_connector base; 522 /* 523 * The fixed encoder this connector is connected to. 524 */ 525 struct intel_encoder *encoder; 526 527 /* ACPI device id for ACPI and driver cooperation */ 528 u32 acpi_device_id; 529 530 /* Reads out the current hw, returning true if the connector is enabled 531 * and active (i.e. dpms ON state). */ 532 bool (*get_hw_state)(struct intel_connector *); 533 534 /* 535 * Optional hook called during init/resume to sync any state 536 * stored in the connector (eg. DSC state) wrt. the HW state. 537 */ 538 void (*sync_state)(struct intel_connector *connector, 539 const struct intel_crtc_state *crtc_state); 540 541 /* Panel info for eDP and LVDS */ 542 struct intel_panel panel; 543 544 /* Cached EDID for detect. */ 545 const struct drm_edid *detect_edid; 546 547 /* Number of times hotplug detection was tried after an HPD interrupt */ 548 int hotplug_retries; 549 550 /* since POLL and HPD connectors may use the same HPD line keep the native 551 state of connector->polled in case hotplug storm detection changes it */ 552 u8 polled; 553 554 int force_joined_pipes; 555 556 struct { 557 struct drm_dp_aux *dsc_decompression_aux; 558 u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]; 559 u8 fec_capability; 560 561 u8 dsc_hblank_expansion_quirk:1; 562 u8 dsc_throughput_quirk:1; 563 u8 dsc_decompression_enabled:1; 564 565 struct { 566 struct { 567 int rgb_yuv444; 568 int yuv422_420; 569 } overall_throughput; 570 int max_line_width; 571 } dsc_branch_caps; 572 573 struct { 574 u8 dpcd[DP_PANEL_REPLAY_CAP_SIZE]; 575 #define INTEL_PR_DPCD_INDEX(pr_dpcd_register) ((pr_dpcd_register) - DP_PANEL_REPLAY_CAP_SUPPORT) 576 577 bool support; 578 bool su_support; 579 enum intel_panel_replay_dsc_support dsc_support; 580 581 u16 su_w_granularity; 582 u16 su_y_granularity; 583 } panel_replay_caps; 584 585 struct { 586 u8 dpcd[EDP_PSR_RECEIVER_CAP_SIZE]; 587 588 bool support; 589 bool su_support; 590 591 u16 su_w_granularity; 592 u16 su_y_granularity; 593 594 u8 sync_latency; 595 } psr_caps; 596 } dp; 597 598 struct { 599 struct drm_dp_mst_port *port; 600 struct intel_dp *dp; 601 } mst; 602 603 struct { 604 int force_bpp_x16; 605 } link; 606 607 /* Work struct to schedule a uevent on link train failure */ 608 struct work_struct modeset_retry_work; 609 610 struct intel_hdcp hdcp; 611 }; 612 613 struct intel_digital_connector_state { 614 struct drm_connector_state base; 615 616 enum hdmi_force_audio force_audio; 617 int broadcast_rgb; 618 }; 619 620 #define to_intel_digital_connector_state(conn_state) \ 621 container_of_const((conn_state), struct intel_digital_connector_state, base) 622 623 struct dpll { 624 /* given values */ 625 int n; 626 int m1, m2; 627 int p1, p2; 628 /* derived values */ 629 int dot; 630 int vco; 631 int m; 632 int p; 633 }; 634 635 struct intel_atomic_state { 636 struct drm_atomic_state base; 637 638 struct ref_tracker *wakeref; 639 640 struct intel_global_objs_state *global_objs; 641 int num_global_objs; 642 643 /* Internal commit, as opposed to userspace/client initiated one */ 644 bool internal; 645 646 bool dpll_set, modeset; 647 648 struct intel_dpll_state dpll_state[I915_NUM_PLLS]; 649 650 struct intel_dp_tunnel_inherited_state *inherited_dp_tunnels; 651 652 /* 653 * Current watermarks can't be trusted during hardware readout, so 654 * don't bother calculating intermediate watermarks. 655 */ 656 bool skip_intermediate_wm; 657 658 bool rps_interactive; 659 660 struct work_struct cleanup_work; 661 }; 662 663 struct intel_plane_state { 664 struct drm_plane_state uapi; 665 666 /* 667 * actual hardware state, the state we program to the hardware. 668 * The following members are used to verify the hardware state: 669 * During initial hw readout, they need to be copied from uapi. 670 */ 671 struct { 672 struct drm_crtc *crtc; 673 struct drm_framebuffer *fb; 674 675 u16 alpha; 676 u16 pixel_blend_mode; 677 unsigned int rotation; 678 enum drm_color_encoding color_encoding; 679 enum drm_color_range color_range; 680 enum drm_scaling_filter scaling_filter; 681 struct drm_property_blob *ctm, *degamma_lut, *gamma_lut, *lut_3d; 682 } hw; 683 684 struct i915_vma *ggtt_vma; 685 struct i915_vma *dpt_vma; 686 unsigned long flags; 687 #define PLANE_HAS_FENCE BIT(0) 688 689 struct intel_fb_view view; 690 691 /* for legacy cursor fb unpin */ 692 struct drm_vblank_work unpin_work; 693 694 /* Plane pxp decryption state */ 695 bool decrypt; 696 697 /* Plane state to display black pixels when pxp is borked */ 698 bool force_black; 699 700 /* Acting as Y plane for another UV plane? */ 701 bool is_y_plane; 702 703 /* plane control register */ 704 u32 ctl; 705 706 /* plane color control register */ 707 u32 color_ctl; 708 709 /* chroma upsampler control register */ 710 u32 cus_ctl; 711 712 /* surface address register */ 713 u32 surf; 714 715 /* 716 * scaler_id 717 * = -1 : not using a scaler 718 * >= 0 : using a scalers 719 * 720 * plane requiring a scaler: 721 * - During check_plane, its bit is set in 722 * crtc_state->scaler_state.scaler_users by calling helper function 723 * update_scaler_plane. 724 * - scaler_id indicates the scaler it got assigned. 725 * 726 * plane doesn't require a scaler: 727 * - this can happen when scaling is no more required or plane simply 728 * got disabled. 729 * - During check_plane, corresponding bit is reset in 730 * crtc_state->scaler_state.scaler_users by calling helper function 731 * update_scaler_plane. 732 */ 733 int scaler_id; 734 735 /* 736 * planar_linked_plane: 737 * 738 * ICL planar formats require 2 planes that are updated as pairs. 739 * This member is used to make sure the other plane is also updated 740 * when required, and for update_slave() to find the correct 741 * plane_state to pass as argument. 742 */ 743 struct intel_plane *planar_linked_plane; 744 745 struct drm_intel_sprite_colorkey ckey; 746 747 struct drm_rect psr2_sel_fetch_area; 748 749 /* Clear Color Value */ 750 u64 ccval; 751 752 const char *no_fbc_reason; 753 754 struct drm_rect damage; 755 }; 756 757 struct intel_initial_plane_config { 758 struct intel_framebuffer *fb; 759 struct intel_memory_region *mem; 760 resource_size_t phys_base; 761 struct i915_vma *vma; 762 int size; 763 u32 base; 764 u8 rotation; 765 }; 766 767 struct intel_scaler { 768 u32 mode; 769 bool in_use; 770 int hscale; 771 int vscale; 772 }; 773 774 struct intel_crtc_scaler_state { 775 #define SKL_NUM_SCALERS 2 776 struct intel_scaler scalers[SKL_NUM_SCALERS]; 777 778 /* 779 * scaler_users: keeps track of users requesting scalers on this crtc. 780 * 781 * If a bit is set, a user is using a scaler. 782 * Here user can be a plane or crtc as defined below: 783 * bits 0-30 - plane (bit position is index from drm_plane_index) 784 * bit 31 - crtc 785 * 786 * Instead of creating a new index to cover planes and crtc, using 787 * existing drm_plane_index for planes which is well less than 31 788 * planes and bit 31 for crtc. This should be fine to cover all 789 * our platforms. 790 * 791 * intel_atomic_setup_scalers will setup available scalers to users 792 * requesting scalers. It will gracefully fail if request exceeds 793 * availability. 794 */ 795 #define SKL_CRTC_INDEX 31 796 unsigned scaler_users; 797 798 /* scaler used by crtc for panel fitting purpose */ 799 int scaler_id; 800 }; 801 802 /* {crtc,crtc_state}->mode_flags */ 803 /* Flag to get scanline using frame time stamps */ 804 #define I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP (1<<1) 805 /* Flag to use the scanline counter instead of the pixel counter */ 806 #define I915_MODE_FLAG_USE_SCANLINE_COUNTER (1<<2) 807 /* 808 * TE0 or TE1 flag is set if the crtc has a DSI encoder which 809 * is operating in command mode. 810 * Flag to use TE from DSI0 instead of VBI in command mode 811 */ 812 #define I915_MODE_FLAG_DSI_USE_TE0 (1<<3) 813 /* Flag to use TE from DSI1 instead of VBI in command mode */ 814 #define I915_MODE_FLAG_DSI_USE_TE1 (1<<4) 815 /* Flag to indicate mipi dsi periodic command mode where we do not get TE */ 816 #define I915_MODE_FLAG_DSI_PERIODIC_CMD_MODE (1<<5) 817 /* Do tricks to make vblank timestamps sane with VRR? */ 818 #define I915_MODE_FLAG_VRR (1<<6) 819 820 struct intel_wm_level { 821 bool enable; 822 u32 pri_val; 823 u32 spr_val; 824 u32 cur_val; 825 u32 fbc_val; 826 }; 827 828 struct intel_pipe_wm { 829 struct intel_wm_level wm[5]; 830 bool fbc_wm_enabled; 831 bool pipe_enabled; 832 bool sprites_enabled; 833 bool sprites_scaled; 834 }; 835 836 struct skl_wm_level { 837 u16 min_ddb_alloc; 838 u16 min_ddb_alloc_uv; /* for pre-icl */ 839 u16 blocks; 840 u8 lines; 841 bool enable; 842 bool ignore_lines; 843 bool auto_min_alloc_wm_enable; 844 bool can_sagv; 845 }; 846 847 struct skl_plane_wm { 848 struct skl_wm_level wm[8]; 849 struct skl_wm_level trans_wm; 850 struct { 851 struct skl_wm_level wm0; 852 struct skl_wm_level trans_wm; 853 } sagv; 854 }; 855 856 struct skl_pipe_wm { 857 struct skl_plane_wm planes[I915_MAX_PLANES]; 858 bool use_sagv_wm; 859 }; 860 861 enum vlv_wm_level { 862 VLV_WM_LEVEL_PM2, 863 VLV_WM_LEVEL_PM5, 864 VLV_WM_LEVEL_DDR_DVFS, 865 NUM_VLV_WM_LEVELS, 866 }; 867 868 struct vlv_wm_state { 869 struct g4x_pipe_wm wm[NUM_VLV_WM_LEVELS]; 870 struct g4x_sr_wm sr[NUM_VLV_WM_LEVELS]; 871 u8 num_levels; 872 bool cxsr; 873 }; 874 875 struct vlv_fifo_state { 876 u16 plane[I915_MAX_PLANES]; 877 }; 878 879 enum g4x_wm_level { 880 G4X_WM_LEVEL_NORMAL, 881 G4X_WM_LEVEL_SR, 882 G4X_WM_LEVEL_HPLL, 883 NUM_G4X_WM_LEVELS, 884 }; 885 886 struct g4x_wm_state { 887 struct g4x_pipe_wm wm; 888 struct g4x_sr_wm sr; 889 struct g4x_sr_wm hpll; 890 bool cxsr; 891 bool hpll_en; 892 bool fbc_en; 893 }; 894 895 struct intel_crtc_wm_state { 896 union { 897 /* 898 * raw: 899 * The "raw" watermark values produced by the formula 900 * given the plane's current state. They do not consider 901 * how much FIFO is actually allocated for each plane. 902 * 903 * optimal: 904 * The "optimal" watermark values given the current 905 * state of the planes and the amount of FIFO 906 * allocated to each, ignoring any previous state 907 * of the planes. 908 * 909 * intermediate: 910 * The "intermediate" watermark values when transitioning 911 * between the old and new "optimal" values. Used when 912 * the watermark registers are single buffered and hence 913 * their state changes asynchronously with regards to the 914 * actual plane registers. These are essentially the 915 * worst case combination of the old and new "optimal" 916 * watermarks, which are therefore safe to use when the 917 * plane is in either its old or new state. 918 */ 919 struct { 920 struct intel_pipe_wm intermediate; 921 struct intel_pipe_wm optimal; 922 } ilk; 923 924 struct { 925 struct skl_pipe_wm raw; 926 /* gen9+ only needs 1-step wm programming */ 927 struct skl_pipe_wm optimal; 928 struct skl_ddb_entry ddb; 929 /* 930 * pre-icl: for packed/planar CbCr 931 * icl+: for everything 932 */ 933 struct skl_ddb_entry plane_ddb[I915_MAX_PLANES]; 934 /* pre-icl: for planar Y */ 935 struct skl_ddb_entry plane_ddb_y[I915_MAX_PLANES]; 936 937 /* 938 * xe3: Minimum amount of display blocks and minimum 939 * sagv allocation required for async flip 940 */ 941 u16 plane_min_ddb[I915_MAX_PLANES]; 942 u16 plane_interim_ddb[I915_MAX_PLANES]; 943 } skl; 944 945 struct { 946 struct g4x_pipe_wm raw[NUM_VLV_WM_LEVELS]; /* not inverted */ 947 struct vlv_wm_state intermediate; /* inverted */ 948 struct vlv_wm_state optimal; /* inverted */ 949 struct vlv_fifo_state fifo_state; 950 } vlv; 951 952 struct { 953 struct g4x_pipe_wm raw[NUM_G4X_WM_LEVELS]; 954 struct g4x_wm_state intermediate; 955 struct g4x_wm_state optimal; 956 } g4x; 957 }; 958 959 /* 960 * Platforms with two-step watermark programming will need to 961 * update watermark programming post-vblank to switch from the 962 * safe intermediate watermarks to the optimal final 963 * watermarks. 964 */ 965 bool need_postvbl_update; 966 }; 967 968 enum intel_output_format { 969 INTEL_OUTPUT_FORMAT_RGB, 970 INTEL_OUTPUT_FORMAT_YCBCR420, 971 INTEL_OUTPUT_FORMAT_YCBCR444, 972 }; 973 974 /* Used by dp and fdi links */ 975 struct intel_link_m_n { 976 u32 tu; 977 u32 data_m; 978 u32 data_n; 979 u32 link_m; 980 u32 link_n; 981 }; 982 983 struct intel_csc_matrix { 984 u16 coeff[9]; 985 u16 preoff[3]; 986 u16 postoff[3]; 987 }; 988 989 struct scaler_filter_coeff { 990 u16 sign; 991 u16 exp; 992 u16 mantissa; 993 }; 994 995 struct intel_casf { 996 #define SCALER_FILTER_NUM_TAPS 7 997 struct scaler_filter_coeff coeff[SCALER_FILTER_NUM_TAPS]; 998 u8 strength; 999 u8 win_size; 1000 bool casf_enable; 1001 }; 1002 1003 struct intel_crtc_state { 1004 /* 1005 * uapi (drm) state. This is the software state shown to userspace. 1006 * In particular, the following members are used for bookkeeping: 1007 * - crtc 1008 * - state 1009 * - *_changed 1010 * - event 1011 * - commit 1012 * - mode_blob 1013 */ 1014 struct drm_crtc_state uapi; 1015 1016 /* 1017 * actual hardware state, the state we program to the hardware. 1018 * The following members are used to verify the hardware state: 1019 * - enable 1020 * - active 1021 * - mode / pipe_mode / adjusted_mode 1022 * - color property blobs. 1023 * 1024 * During initial hw readout, they need to be copied to uapi. 1025 * 1026 * Joiner will allow a transcoder mode that spans 2 pipes; 1027 * Use the pipe_mode for calculations like watermarks, pipe 1028 * scaler, and bandwidth. 1029 * 1030 * Use adjusted_mode for things that need to know the full 1031 * mode on the transcoder, which spans all pipes. 1032 */ 1033 struct { 1034 bool active, enable; 1035 /* logical state of LUTs */ 1036 struct drm_property_blob *degamma_lut, *gamma_lut, *ctm; 1037 struct drm_display_mode mode, pipe_mode, adjusted_mode; 1038 enum drm_scaling_filter scaling_filter; 1039 struct intel_casf casf_params; 1040 } hw; 1041 1042 /* actual state of LUTs */ 1043 struct drm_property_blob *pre_csc_lut, *post_csc_lut; 1044 1045 struct intel_csc_matrix csc, output_csc; 1046 1047 /** 1048 * quirks - bitfield with hw state readout quirks 1049 * 1050 * For various reasons the hw state readout code might not be able to 1051 * completely faithfully read out the current state. These cases are 1052 * tracked with quirk flags so that fastboot and state checker can act 1053 * accordingly. 1054 */ 1055 #define PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS (1<<0) /* unreliable sync mode.flags */ 1056 unsigned long quirks; 1057 1058 unsigned fb_bits; /* framebuffers to flip */ 1059 bool update_pipe; /* can a fast modeset be performed? */ 1060 bool update_m_n; /* update M/N seamlessly during fastset? */ 1061 bool update_lrr; /* update TRANS_VTOTAL/etc. during fastset? */ 1062 bool disable_cxsr; 1063 bool update_wm_pre, update_wm_post; /* watermarks are updated */ 1064 bool fifo_changed; /* FIFO split is changed */ 1065 bool preload_luts; 1066 bool inherited; /* state inherited from BIOS? */ 1067 1068 /* Ask the hardware to actually async flip? */ 1069 bool do_async_flip; 1070 1071 /* Pipe source size (ie. panel fitter input size) 1072 * All planes will be positioned inside this space, 1073 * and get clipped at the edges. */ 1074 struct drm_rect pipe_src; 1075 1076 /* 1077 * Pipe pixel rate, adjusted for 1078 * panel fitter/pipe scaler downscaling. 1079 */ 1080 unsigned int pixel_rate; 1081 1082 /* Whether to set up the PCH/FDI. Note that we never allow sharing 1083 * between pch encoders and cpu encoders. */ 1084 bool has_pch_encoder; 1085 1086 /* Are we sending infoframes on the attached port */ 1087 bool has_infoframe; 1088 1089 /* CPU Transcoder for the pipe. Currently this can only differ from the 1090 * pipe on Haswell and later (where we have a special eDP transcoder) 1091 * and Broxton (where we have special DSI transcoders). */ 1092 enum transcoder cpu_transcoder; 1093 1094 /* 1095 * Use reduced/limited/broadcast rbg range, compressing from the full 1096 * range fed into the crtcs. 1097 */ 1098 bool limited_color_range; 1099 1100 /* Bitmask of encoder types (enum intel_output_type) 1101 * driven by the pipe. 1102 */ 1103 unsigned int output_types; 1104 1105 /* Whether we should send NULL infoframes. Required for audio. */ 1106 bool has_hdmi_sink; 1107 1108 /* Audio enabled on this pipe. Only valid if either has_hdmi_sink or 1109 * has_dp_encoder is set. */ 1110 bool has_audio; 1111 1112 /* 1113 * Enable dithering, used when the selected pipe bpp doesn't match the 1114 * plane bpp. 1115 */ 1116 bool dither; 1117 1118 /* 1119 * Dither gets enabled for 18bpp which causes CRC mismatch errors for 1120 * compliance video pattern tests. 1121 * Disable dither only if it is a compliance test request for 1122 * 18bpp. 1123 */ 1124 bool dither_force_disable; 1125 1126 /* Controls for the clock computation, to override various stages. */ 1127 bool clock_set; 1128 1129 /* SDVO TV has a bunch of special case. To make multifunction encoders 1130 * work correctly, we need to track this at runtime.*/ 1131 bool sdvo_tv_clock; 1132 1133 /* 1134 * crtc bandwidth limit, don't increase pipe bpp or clock if not really 1135 * required. This is set in the 2nd loop of calling encoder's 1136 * ->compute_config if the first pick doesn't work out. 1137 */ 1138 bool bw_constrained; 1139 1140 /* Settings for the intel dpll used on pretty much everything but 1141 * haswell. */ 1142 struct dpll dpll; 1143 1144 /* Selected dpll or NULL. */ 1145 struct intel_dpll *intel_dpll; 1146 1147 /* Actual register state of the dpll, for shared dpll cross-checking. */ 1148 struct intel_dpll_hw_state dpll_hw_state; 1149 1150 /* 1151 * ICL reserved DPLLs for the CRTC/port. The active PLL is selected by 1152 * setting shared_dpll and dpll_hw_state to one of these reserved ones. 1153 */ 1154 struct icl_port_dpll { 1155 struct intel_dpll *pll; 1156 struct intel_dpll_hw_state hw_state; 1157 } icl_port_dplls[ICL_PORT_DPLL_COUNT]; 1158 1159 /* DSI PLL registers */ 1160 struct { 1161 u32 ctrl, div; 1162 } dsi_pll; 1163 1164 int max_link_bpp_x16; /* in 1/16 bpp units */ 1165 int max_pipe_bpp; /* in 1 bpp units */ 1166 int pipe_bpp; /* in 1 bpp units */ 1167 int min_hblank; 1168 struct intel_link_m_n dp_m_n; 1169 1170 /* m2_n2 for eDP downclock */ 1171 struct intel_link_m_n dp_m2_n2; 1172 bool has_drrs; 1173 1174 /* PSR is supported but might not be enabled due the lack of enabled planes */ 1175 bool has_psr; 1176 bool has_sel_update; 1177 bool enable_psr2_sel_fetch; 1178 bool enable_psr2_su_region_et; 1179 bool req_psr2_sdp_prior_scanline; 1180 bool has_panel_replay; 1181 bool link_off_after_as_sdp_when_pr_active; 1182 bool disable_as_sdp_when_pr_active; 1183 bool wm_level_disabled; 1184 bool pkg_c_latency_used; 1185 /* Only used for state verification. */ 1186 enum intel_panel_replay_dsc_support panel_replay_dsc_support; 1187 u32 dc3co_exitline; 1188 u16 su_y_granularity; 1189 u8 active_non_psr_pipes; 1190 u8 entry_setup_frames; 1191 const char *no_psr_reason; 1192 1193 /* 1194 * Frequency the dpll for the port should run at. Differs from the 1195 * adjusted dotclock e.g. for DP or 10/12bpc hdmi mode. This is also 1196 * already multiplied by pixel_multiplier. 1197 */ 1198 int port_clock; 1199 1200 /* Used by SDVO (and if we ever fix it, HDMI). */ 1201 unsigned pixel_multiplier; 1202 1203 /* I915_MODE_FLAG_* */ 1204 u8 mode_flags; 1205 1206 u8 lane_count; 1207 1208 /* 1209 * Used by platforms having DP/HDMI PHY with programmable lane 1210 * latency optimization. 1211 */ 1212 u8 lane_lat_optim_mask; 1213 1214 /* minimum acceptable voltage level */ 1215 u8 min_voltage_level; 1216 1217 /* Panel fitter controls for gen2-gen4 + VLV */ 1218 struct { 1219 u32 control; 1220 u32 pgm_ratios; 1221 u32 lvds_border_bits; 1222 } gmch_pfit; 1223 1224 /* Panel fitter placement and size for Ironlake+ */ 1225 struct { 1226 struct drm_rect dst; 1227 bool enabled; 1228 bool force_thru; 1229 } pch_pfit; 1230 1231 /* FDI configuration, only valid if has_pch_encoder is set. */ 1232 int fdi_lanes; 1233 struct intel_link_m_n fdi_m_n; 1234 1235 bool ips_enabled; 1236 1237 bool crc_enabled; 1238 1239 bool double_wide; 1240 1241 struct intel_crtc_scaler_state scaler_state; 1242 1243 /* w/a for waiting 2 vblanks during crtc enable */ 1244 enum pipe hsw_workaround_pipe; 1245 1246 struct intel_crtc_wm_state wm; 1247 1248 int min_cdclk; 1249 1250 int plane_min_cdclk[I915_MAX_PLANES]; 1251 1252 /* for packed/planar CbCr */ 1253 u32 data_rate[I915_MAX_PLANES]; 1254 /* for planar Y */ 1255 u32 data_rate_y[I915_MAX_PLANES]; 1256 1257 /* FIXME unify with data_rate[]? */ 1258 u64 rel_data_rate[I915_MAX_PLANES]; 1259 u64 rel_data_rate_y[I915_MAX_PLANES]; 1260 1261 /* Gamma mode programmed on the pipe */ 1262 u32 gamma_mode; 1263 1264 union { 1265 /* CSC mode programmed on the pipe */ 1266 u32 csc_mode; 1267 1268 /* CHV CGM mode */ 1269 u32 cgm_mode; 1270 }; 1271 1272 /* bitmask of logically enabled planes (enum plane_id) */ 1273 u8 enabled_planes; 1274 1275 /* bitmask of actually visible planes (enum plane_id) */ 1276 u8 active_planes; 1277 u8 scaled_planes; 1278 u8 nv12_planes; 1279 u8 c8_planes; 1280 1281 /* bitmask of planes that will be updated during the commit */ 1282 u8 update_planes; 1283 1284 /* bitmask of planes with async flip active */ 1285 u8 async_flip_planes; 1286 1287 u8 framestart_delay; /* 1-4 */ 1288 u8 msa_timing_delay; /* 0-3 */ 1289 1290 struct { 1291 u32 enable; 1292 u32 gcp; 1293 union hdmi_infoframe avi; 1294 union hdmi_infoframe spd; 1295 union hdmi_infoframe hdmi; 1296 union hdmi_infoframe drm; 1297 struct drm_dp_vsc_sdp vsc; 1298 struct drm_dp_as_sdp as_sdp; 1299 } infoframes; 1300 1301 u8 eld[MAX_ELD_BYTES]; 1302 1303 /* HDMI scrambling status */ 1304 bool hdmi_scrambling; 1305 1306 /* HDMI High TMDS char rate ratio */ 1307 bool hdmi_high_tmds_clock_ratio; 1308 1309 /* 1310 * Output format RGB/YCBCR etc., that is coming out 1311 * at the end of the pipe. 1312 */ 1313 enum intel_output_format output_format; 1314 1315 /* 1316 * Sink output format RGB/YCBCR etc., that is going 1317 * into the sink. 1318 */ 1319 enum intel_output_format sink_format; 1320 1321 /* enable pipe gamma? */ 1322 bool gamma_enable; 1323 1324 /* enable pipe csc? */ 1325 bool csc_enable; 1326 1327 /* enable vlv/chv wgc csc? */ 1328 bool wgc_enable; 1329 1330 /* joiner pipe bitmask */ 1331 u8 joiner_pipes; 1332 1333 /* Display Stream compression state */ 1334 struct { 1335 /* Only used for state computation, not read out from the HW. */ 1336 bool compression_enabled_on_link; 1337 bool compression_enable; 1338 struct intel_dsc_slice_config { 1339 int pipes_per_line; 1340 int streams_per_pipe; 1341 int slices_per_stream; 1342 } slice_config; 1343 /* Compressed Bpp in U6.4 format (first 4 bits for fractional part) */ 1344 u16 compressed_bpp_x16; 1345 struct drm_dsc_config config; 1346 } dsc; 1347 1348 /* DP tunnel used for BW allocation. */ 1349 struct drm_dp_tunnel_ref dp_tunnel_ref; 1350 1351 /* HSW+ linetime watermarks */ 1352 u16 linetime; 1353 u16 ips_linetime; 1354 1355 bool enhanced_framing; 1356 1357 /* 1358 * Forward Error Correction. 1359 * 1360 * Note: This will be false for 128b/132b, which will always have FEC 1361 * enabled automatically. 1362 */ 1363 bool fec_enable; 1364 1365 bool sdp_split_enable; 1366 1367 /* Pointer to master transcoder in case of tiled displays */ 1368 enum transcoder master_transcoder; 1369 1370 /* Bitmask to indicate slaves attached */ 1371 u8 sync_mode_slaves_mask; 1372 1373 /* Only valid on TGL+ */ 1374 enum transcoder mst_master_transcoder; 1375 1376 /* For DSB based pipe updates */ 1377 struct intel_dsb *dsb_color, *dsb_commit; 1378 bool use_dsb; 1379 bool use_flipq; 1380 1381 u32 psr2_man_track_ctl; 1382 1383 u32 pipe_srcsz_early_tpt; 1384 1385 struct drm_rect psr2_su_area; 1386 1387 /* Variable Refresh Rate state */ 1388 struct { 1389 bool enable, in_range; 1390 u8 pipeline_full; 1391 u16 flipline, vmin, vmax, guardband; 1392 u32 vsync_end, vsync_start; 1393 struct { 1394 bool enable; 1395 u16 vmin, vmax; 1396 u16 guardband, slope; 1397 u16 max_increase, max_decrease; 1398 u16 vblank_target; 1399 } dc_balance; 1400 } vrr; 1401 1402 /* Content Match Refresh Rate state */ 1403 struct { 1404 bool enable; 1405 u64 cmrr_n, cmrr_m; 1406 } cmrr; 1407 1408 /* Stream Splitter for eDP MSO */ 1409 struct { 1410 bool enable; 1411 u8 link_count; 1412 u8 pixel_overlap; 1413 } splitter; 1414 1415 /* for loading single buffered registers during vblank */ 1416 struct drm_vblank_work vblank_work; 1417 1418 /* LOBF flag */ 1419 bool has_lobf; 1420 1421 /* W2 window or 'set context latency' lines */ 1422 u16 set_context_latency; 1423 1424 struct { 1425 u8 io_wake_lines; 1426 u8 fast_wake_lines; 1427 1428 /* LNL and beyond */ 1429 u8 check_entry_lines; 1430 u8 aux_less_wake_lines; 1431 u8 silence_period_sym_clocks; 1432 u8 lfps_half_cycle_num_of_syms; 1433 } alpm_state; 1434 1435 /* to track changes in plane color blocks */ 1436 bool plane_color_changed; 1437 }; 1438 1439 enum intel_pipe_crc_source { 1440 INTEL_PIPE_CRC_SOURCE_NONE, 1441 INTEL_PIPE_CRC_SOURCE_PLANE1, 1442 INTEL_PIPE_CRC_SOURCE_PLANE2, 1443 INTEL_PIPE_CRC_SOURCE_PLANE3, 1444 INTEL_PIPE_CRC_SOURCE_PLANE4, 1445 INTEL_PIPE_CRC_SOURCE_PLANE5, 1446 INTEL_PIPE_CRC_SOURCE_PLANE6, 1447 INTEL_PIPE_CRC_SOURCE_PLANE7, 1448 INTEL_PIPE_CRC_SOURCE_PIPE, 1449 /* TV/DP on pre-gen5/vlv can't use the pipe source. */ 1450 INTEL_PIPE_CRC_SOURCE_TV, 1451 INTEL_PIPE_CRC_SOURCE_DP_B, 1452 INTEL_PIPE_CRC_SOURCE_DP_C, 1453 INTEL_PIPE_CRC_SOURCE_DP_D, 1454 INTEL_PIPE_CRC_SOURCE_AUTO, 1455 INTEL_PIPE_CRC_SOURCE_MAX, 1456 }; 1457 1458 enum drrs_refresh_rate { 1459 DRRS_REFRESH_RATE_HIGH, 1460 DRRS_REFRESH_RATE_LOW, 1461 }; 1462 1463 #define INTEL_PIPE_CRC_ENTRIES_NR 128 1464 struct intel_pipe_crc { 1465 spinlock_t lock; 1466 int skipped; 1467 enum intel_pipe_crc_source source; 1468 }; 1469 1470 enum intel_flipq_id { 1471 INTEL_FLIPQ_PLANE_1, 1472 INTEL_FLIPQ_PLANE_2, 1473 INTEL_FLIPQ_PLANE_3, 1474 INTEL_FLIPQ_GENERAL, 1475 INTEL_FLIPQ_FAST, 1476 MAX_INTEL_FLIPQ, 1477 }; 1478 1479 struct intel_flipq { 1480 u32 start_mmioaddr; 1481 enum intel_flipq_id flipq_id; 1482 u8 tail; 1483 }; 1484 1485 struct intel_crtc { 1486 struct drm_crtc base; 1487 enum pipe pipe; 1488 /* 1489 * Whether the crtc and the connected output pipeline is active. Implies 1490 * that crtc->enabled is set, i.e. the current mode configuration has 1491 * some outputs connected to this crtc. 1492 */ 1493 bool active; 1494 u8 plane_ids_mask; 1495 1496 /* I915_MODE_FLAG_* */ 1497 u8 mode_flags; 1498 1499 u16 vmax_vblank_start; 1500 1501 struct intel_display_power_domain_set enabled_power_domains; 1502 struct intel_display_power_domain_set hw_readout_power_domains; 1503 struct intel_overlay *overlay; 1504 1505 struct intel_crtc_state *config; 1506 1507 /* armed event for async flip */ 1508 struct drm_pending_vblank_event *flip_done_event; 1509 /* armed event for DSB based updates */ 1510 struct drm_pending_vblank_event *dsb_event; 1511 /* armed event for flip queue based updates */ 1512 struct drm_pending_vblank_event *flipq_event; 1513 1514 /* Access to these should be protected by display->irq.lock. */ 1515 bool cpu_fifo_underrun_disabled; 1516 bool pch_fifo_underrun_disabled; 1517 1518 struct intel_flipq flipq[MAX_INTEL_FLIPQ]; 1519 1520 /* per-pipe watermark state */ 1521 struct { 1522 /* watermarks currently being used */ 1523 union { 1524 struct intel_pipe_wm ilk; 1525 struct vlv_wm_state vlv; 1526 struct g4x_wm_state g4x; 1527 } active; 1528 } wm; 1529 1530 struct { 1531 struct mutex mutex; 1532 struct delayed_work work; 1533 enum drrs_refresh_rate refresh_rate; 1534 unsigned int frontbuffer_bits; 1535 unsigned int busy_frontbuffer_bits; 1536 enum transcoder cpu_transcoder; 1537 struct intel_link_m_n m_n, m2_n2; 1538 } drrs; 1539 1540 struct { 1541 u64 flip_count; 1542 } dc_balance; 1543 1544 int scanline_offset; 1545 1546 struct { 1547 unsigned start_vbl_count; 1548 ktime_t start_vbl_time; 1549 int min_vbl, max_vbl; 1550 int scanline_start; 1551 #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE 1552 struct { 1553 u64 min; 1554 u64 max; 1555 u64 sum; 1556 unsigned int over; 1557 unsigned int times[17]; /* [1us, 16ms] */ 1558 } vbl; 1559 #endif 1560 } debug; 1561 1562 /* scalers available on this crtc */ 1563 int num_scalers; 1564 1565 /* for loading single buffered registers during vblank */ 1566 struct pm_qos_request vblank_pm_qos; 1567 1568 #ifdef CONFIG_DEBUG_FS 1569 struct intel_pipe_crc pipe_crc; 1570 #endif 1571 1572 bool vblank_psr_notify; 1573 }; 1574 1575 struct intel_plane_error { 1576 u32 ctl, surf, surflive; 1577 }; 1578 1579 struct intel_plane { 1580 struct drm_plane base; 1581 enum i9xx_plane_id i9xx_plane; 1582 enum plane_id id; 1583 enum pipe pipe; 1584 bool need_async_flip_toggle_wa; 1585 u8 vtd_guard; 1586 u32 frontbuffer_bit; 1587 1588 struct { 1589 u32 base, cntl, size; 1590 } cursor; 1591 1592 struct intel_fbc *fbc; 1593 1594 /* 1595 * NOTE: Do not place new plane state fields here (e.g., when adding 1596 * new plane properties). New runtime state should now be placed in 1597 * the intel_plane_state structure and accessed via plane_state. 1598 */ 1599 1600 int (*min_width)(const struct drm_framebuffer *fb, 1601 int color_plane, 1602 unsigned int rotation); 1603 int (*max_width)(const struct drm_framebuffer *fb, 1604 int color_plane, 1605 unsigned int rotation); 1606 int (*max_height)(const struct drm_framebuffer *fb, 1607 int color_plane, 1608 unsigned int rotation); 1609 unsigned int (*min_alignment)(struct intel_plane *plane, 1610 const struct drm_framebuffer *fb, 1611 int color_plane); 1612 unsigned int (*max_stride)(struct intel_plane *plane, 1613 const struct drm_format_info *info, 1614 u64 modifier, unsigned int rotation); 1615 bool (*can_async_flip)(u64 modifier); 1616 /* Write all non-self arming plane registers */ 1617 void (*update_noarm)(struct intel_dsb *dsb, 1618 struct intel_plane *plane, 1619 const struct intel_crtc_state *crtc_state, 1620 const struct intel_plane_state *plane_state); 1621 /* Write all self-arming plane registers */ 1622 void (*update_arm)(struct intel_dsb *dsb, 1623 struct intel_plane *plane, 1624 const struct intel_crtc_state *crtc_state, 1625 const struct intel_plane_state *plane_state); 1626 /* Disable the plane, must arm */ 1627 void (*disable_arm)(struct intel_dsb *dsb, 1628 struct intel_plane *plane, 1629 const struct intel_crtc_state *crtc_state); 1630 void (*capture_error)(struct intel_crtc *crtc, 1631 struct intel_plane *plane, 1632 struct intel_plane_error *error); 1633 bool (*get_hw_state)(struct intel_plane *plane, enum pipe *pipe); 1634 int (*check_plane)(struct intel_crtc_state *crtc_state, 1635 struct intel_plane_state *plane_state); 1636 u32 (*surf_offset)(const struct intel_plane_state *plane_state); 1637 int (*min_cdclk)(const struct intel_crtc_state *crtc_state, 1638 const struct intel_plane_state *plane_state); 1639 void (*async_flip)(struct intel_dsb *dsb, 1640 struct intel_plane *plane, 1641 const struct intel_crtc_state *crtc_state, 1642 const struct intel_plane_state *plane_state, 1643 bool async_flip); 1644 void (*enable_flip_done)(struct intel_plane *plane); 1645 void (*disable_flip_done)(struct intel_plane *plane); 1646 /* For drm_panic */ 1647 void (*disable_tiling)(struct intel_plane *plane); 1648 }; 1649 1650 #define to_intel_atomic_state(x) container_of(x, struct intel_atomic_state, base) 1651 #define to_intel_crtc(x) container_of(x, struct intel_crtc, base) 1652 #define to_intel_connector(x) container_of(x, struct intel_connector, base) 1653 #define to_intel_encoder(x) container_of(x, struct intel_encoder, base) 1654 #define to_intel_plane(x) container_of(x, struct intel_plane, base) 1655 1656 #define to_intel_crtc_state(crtc_state) \ 1657 container_of_const((crtc_state), struct intel_crtc_state, uapi) 1658 #define to_intel_plane_state(plane_state) \ 1659 container_of_const((plane_state), struct intel_plane_state, uapi) 1660 #define to_intel_framebuffer(fb) \ 1661 container_of_const((fb), struct intel_framebuffer, base) 1662 1663 struct intel_hdmi { 1664 i915_reg_t hdmi_reg; 1665 struct { 1666 enum drm_dp_dual_mode_type type; 1667 int max_tmds_clock; 1668 } dp_dual_mode; 1669 struct intel_connector *attached_connector; 1670 struct cec_notifier *cec_notifier; 1671 }; 1672 1673 struct intel_dp_mst_encoder; 1674 1675 struct intel_dp_compliance_data { 1676 unsigned long edid; 1677 u8 video_pattern; 1678 u16 hdisplay, vdisplay; 1679 u8 bpc; 1680 struct drm_dp_phy_test_params phytest; 1681 }; 1682 1683 struct intel_dp_compliance { 1684 unsigned long test_type; 1685 struct intel_dp_compliance_data test_data; 1686 bool test_active; 1687 int test_link_rate; 1688 u8 test_lane_count; 1689 }; 1690 1691 struct intel_dp_pcon_frl { 1692 bool is_trained; 1693 int trained_rate_gbps; 1694 }; 1695 1696 struct intel_pps { 1697 int panel_power_up_delay; 1698 int panel_power_down_delay; 1699 int panel_power_cycle_delay; 1700 int backlight_on_delay; 1701 int backlight_off_delay; 1702 struct delayed_work panel_vdd_work; 1703 bool want_panel_vdd; 1704 bool initializing; 1705 unsigned long last_power_on; 1706 unsigned long last_backlight_off; 1707 ktime_t panel_power_off_time; 1708 struct ref_tracker *vdd_wakeref; 1709 1710 union { 1711 /* 1712 * Pipe whose power sequencer is currently locked into 1713 * this port. Only relevant on VLV/CHV. 1714 */ 1715 enum pipe vlv_pps_pipe; 1716 1717 /* 1718 * Power sequencer index. Only relevant on BXT+. 1719 */ 1720 int pps_idx; 1721 }; 1722 1723 /* 1724 * Pipe currently driving the port. Used for preventing 1725 * the use of the PPS for any pipe currentrly driving 1726 * external DP as that will mess things up on VLV. 1727 */ 1728 enum pipe vlv_active_pipe; 1729 /* 1730 * Set if the sequencer may be reset due to a power transition, 1731 * requiring a reinitialization. Only relevant on BXT+. 1732 */ 1733 bool bxt_pps_reset; 1734 struct intel_pps_delays pps_delays; 1735 struct intel_pps_delays bios_pps_delays; 1736 }; 1737 1738 struct intel_psr { 1739 /* Mutex for PSR state of the transcoder */ 1740 struct mutex lock; 1741 1742 #define I915_PSR_DEBUG_MODE_MASK 0x0f 1743 #define I915_PSR_DEBUG_DEFAULT 0x00 1744 #define I915_PSR_DEBUG_DISABLE 0x01 1745 #define I915_PSR_DEBUG_ENABLE 0x02 1746 #define I915_PSR_DEBUG_FORCE_PSR1 0x03 1747 #define I915_PSR_DEBUG_ENABLE_SEL_FETCH 0x4 1748 #define I915_PSR_DEBUG_IRQ 0x10 1749 #define I915_PSR_DEBUG_SU_REGION_ET_DISABLE 0x20 1750 #define I915_PSR_DEBUG_PANEL_REPLAY_DISABLE 0x40 1751 1752 u32 debug; 1753 bool sink_support; 1754 bool source_support; 1755 bool enabled; 1756 int pause_counter; 1757 enum pipe pipe; 1758 enum transcoder transcoder; 1759 bool active; 1760 struct work_struct work; 1761 unsigned int busy_frontbuffer_bits; 1762 bool link_standby; 1763 bool sel_update_enabled; 1764 bool psr2_sel_fetch_enabled; 1765 bool psr2_sel_fetch_cff_enabled; 1766 bool su_region_et_enabled; 1767 bool req_psr2_sdp_prior_scanline; 1768 ktime_t last_entry_attempt; 1769 ktime_t last_exit; 1770 bool sink_not_reliable; 1771 bool irq_aux_error; 1772 u16 su_w_granularity; 1773 u16 su_y_granularity; 1774 bool source_panel_replay_support; 1775 bool sink_panel_replay_support; 1776 bool panel_replay_enabled; 1777 u32 dc3co_exitline; 1778 u32 dc3co_exit_delay; 1779 struct delayed_work dc3co_work; 1780 u8 entry_setup_frames; 1781 1782 u8 io_wake_lines; 1783 u8 fast_wake_lines; 1784 1785 bool link_ok; 1786 bool pkg_c_latency_used; 1787 1788 u8 active_non_psr_pipes; 1789 1790 const char *no_psr_reason; 1791 }; 1792 1793 struct intel_dp { 1794 i915_reg_t output_reg; 1795 u32 DP; 1796 int link_rate; 1797 u8 lane_count; 1798 u8 sink_count; 1799 bool downstream_port_changed; 1800 bool needs_modeset_retry; 1801 bool use_max_params; 1802 u8 dpcd[DP_RECEIVER_CAP_SIZE]; 1803 1804 u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS]; 1805 u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE]; 1806 u8 lttpr_common_caps[DP_LTTPR_COMMON_CAP_SIZE]; 1807 u8 lttpr_phy_caps[DP_MAX_LTTPR_COUNT][DP_LTTPR_PHY_CAP_SIZE]; 1808 u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]; 1809 /* source rates */ 1810 int num_source_rates; 1811 const int *source_rates; 1812 /* sink rates as reported by DP_MAX_LINK_RATE/DP_SUPPORTED_LINK_RATES */ 1813 int num_sink_rates; 1814 int sink_rates[DP_MAX_SUPPORTED_RATES]; 1815 bool use_rate_select; 1816 /* Max sink lane count as reported by DP_MAX_LANE_COUNT */ 1817 int max_sink_lane_count; 1818 /* intersection of source and sink rates */ 1819 int num_common_rates; 1820 int common_rates[DP_MAX_SUPPORTED_RATES]; 1821 struct { 1822 /* TODO: move the rest of link specific fields to here */ 1823 bool active; 1824 /* common rate,lane_count configs in bw order */ 1825 int num_configs; 1826 #define INTEL_DP_MAX_LANE_COUNT 4 1827 #define INTEL_DP_MAX_SUPPORTED_LANE_CONFIGS (ilog2(INTEL_DP_MAX_LANE_COUNT) + 1) 1828 #define INTEL_DP_LANE_COUNT_EXP_BITS order_base_2(INTEL_DP_MAX_SUPPORTED_LANE_CONFIGS) 1829 #define INTEL_DP_LINK_RATE_IDX_BITS (BITS_PER_TYPE(u8) - INTEL_DP_LANE_COUNT_EXP_BITS) 1830 #define INTEL_DP_MAX_LINK_CONFIGS (DP_MAX_SUPPORTED_RATES * \ 1831 INTEL_DP_MAX_SUPPORTED_LANE_CONFIGS) 1832 struct intel_dp_link_config { 1833 u8 link_rate_idx:INTEL_DP_LINK_RATE_IDX_BITS; 1834 u8 lane_count_exp:INTEL_DP_LANE_COUNT_EXP_BITS; 1835 } configs[INTEL_DP_MAX_LINK_CONFIGS]; 1836 /* Max lane count for the current link */ 1837 int max_lane_count; 1838 /* Max rate for the current link */ 1839 int max_rate; 1840 /* 1841 * Link parameters for which the MST topology was probed. 1842 * Tracking these ensures that the MST path resources are 1843 * re-enumerated whenever the link is retrained with new link 1844 * parameters, as required by the DP standard. 1845 */ 1846 int mst_probed_lane_count; 1847 int mst_probed_rate; 1848 int force_lane_count; 1849 int force_rate; 1850 bool retrain_disabled; 1851 /* Sequential link training failures after a passing LT */ 1852 int seq_train_failures; 1853 int force_train_failure; 1854 bool force_retrain; 1855 } link; 1856 bool reset_link_params; 1857 int mso_link_count; 1858 int mso_pixel_overlap; 1859 /* sink or branch descriptor */ 1860 struct drm_dp_desc desc; 1861 struct drm_dp_aux aux; 1862 u32 aux_busy_last_status; 1863 u8 train_set[4]; 1864 1865 struct intel_pps pps; 1866 1867 bool is_mst; 1868 enum drm_dp_mst_mode mst_detect; 1869 1870 /* connector directly attached - won't be use for modeset in mst world */ 1871 struct intel_connector *attached_connector; 1872 bool as_sdp_supported; 1873 1874 struct drm_dp_tunnel *tunnel; 1875 bool tunnel_suspended:1; 1876 1877 struct { 1878 struct intel_dp_mst_encoder *stream_encoders[I915_MAX_PIPES]; 1879 struct drm_dp_mst_topology_mgr mgr; 1880 int active_streams; 1881 } mst; 1882 1883 u32 (*get_aux_clock_divider)(struct intel_dp *dp, int index); 1884 /* 1885 * This function returns the value we have to program the AUX_CTL 1886 * register with to kick off an AUX transaction. 1887 */ 1888 u32 (*get_aux_send_ctl)(struct intel_dp *dp, int send_bytes, 1889 u32 aux_clock_divider); 1890 1891 i915_reg_t (*aux_ch_ctl_reg)(struct intel_dp *dp); 1892 i915_reg_t (*aux_ch_data_reg)(struct intel_dp *dp, int index); 1893 1894 /* This is called before a link training is starterd */ 1895 void (*prepare_link_retrain)(struct intel_dp *intel_dp, 1896 const struct intel_crtc_state *crtc_state); 1897 void (*set_link_train)(struct intel_dp *intel_dp, 1898 const struct intel_crtc_state *crtc_state, 1899 u8 dp_train_pat); 1900 void (*set_idle_link_train)(struct intel_dp *intel_dp, 1901 const struct intel_crtc_state *crtc_state); 1902 1903 u8 (*preemph_max)(struct intel_dp *intel_dp); 1904 u8 (*voltage_max)(struct intel_dp *intel_dp, 1905 const struct intel_crtc_state *crtc_state); 1906 1907 /* Displayport compliance testing */ 1908 struct intel_dp_compliance compliance; 1909 1910 /* Downstream facing port caps */ 1911 struct { 1912 int min_tmds_clock, max_tmds_clock; 1913 int max_dotclock; 1914 int pcon_max_frl_bw; 1915 u8 max_bpc; 1916 bool ycbcr_444_to_420; 1917 bool ycbcr420_passthrough; 1918 bool rgb_to_ycbcr; 1919 } dfp; 1920 1921 /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */ 1922 struct pm_qos_request pm_qos; 1923 1924 /* Display stream compression testing */ 1925 bool force_dsc_en; 1926 int force_dsc_output_format; 1927 bool force_dsc_fractional_bpp_en; 1928 int force_dsc_bpc; 1929 1930 bool hobl_failed; 1931 bool hobl_active; 1932 1933 struct intel_dp_pcon_frl frl; 1934 1935 struct intel_psr psr; 1936 1937 /* When we last wrote the OUI for eDP */ 1938 unsigned long last_oui_write; 1939 bool oui_valid; 1940 1941 bool colorimetry_support; 1942 1943 struct { 1944 enum transcoder transcoder; 1945 struct mutex lock; 1946 1947 bool lobf_disable_debug; 1948 bool sink_alpm_error; 1949 } alpm; 1950 1951 u8 alpm_dpcd; 1952 1953 struct { 1954 unsigned long mask; 1955 } quirks; 1956 }; 1957 1958 enum lspcon_vendor { 1959 LSPCON_VENDOR_MCA, 1960 LSPCON_VENDOR_PARADE 1961 }; 1962 1963 struct intel_lspcon { 1964 bool active; 1965 bool hdr_supported; 1966 enum drm_lspcon_mode mode; 1967 enum lspcon_vendor vendor; 1968 }; 1969 1970 struct intel_digital_port { 1971 struct intel_encoder base; 1972 struct intel_dp dp; 1973 struct intel_hdmi hdmi; 1974 struct intel_lspcon lspcon; 1975 enum irqreturn (*hpd_pulse)(struct intel_digital_port *, bool); 1976 1977 bool lane_reversal; 1978 bool ddi_a_4_lanes; 1979 bool release_cl2_override; 1980 bool dedicated_external; 1981 u8 max_lanes; 1982 /* Used for DP and ICL+ TypeC/DP and TypeC/HDMI ports. */ 1983 enum aux_ch aux_ch; 1984 enum intel_display_power_domain ddi_io_power_domain; 1985 struct ref_tracker *ddi_io_wakeref; 1986 struct ref_tracker *aux_wakeref; 1987 1988 struct intel_tc_port *tc; 1989 1990 struct { 1991 /* protects num_streams reference count, port_data and auth_status */ 1992 struct mutex mutex; 1993 /* the number of pipes using HDCP signalling out of this port */ 1994 unsigned int num_streams; 1995 /* port HDCP auth status */ 1996 bool auth_status; 1997 /* HDCP port data need to pass to security f/w */ 1998 struct hdcp_port_data port_data; 1999 /* Whether the MST topology supports HDCP Type 1 Content */ 2000 bool mst_type1_capable; 2001 } hdcp; 2002 2003 void (*write_infoframe)(struct intel_encoder *encoder, 2004 const struct intel_crtc_state *crtc_state, 2005 unsigned int type, 2006 const void *frame, ssize_t len); 2007 void (*read_infoframe)(struct intel_encoder *encoder, 2008 const struct intel_crtc_state *crtc_state, 2009 unsigned int type, 2010 void *frame, ssize_t len); 2011 void (*set_infoframes)(struct intel_encoder *encoder, 2012 bool enable, 2013 const struct intel_crtc_state *crtc_state, 2014 const struct drm_connector_state *conn_state); 2015 u32 (*infoframes_enabled)(struct intel_encoder *encoder, 2016 const struct intel_crtc_state *pipe_config); 2017 bool (*connected)(struct intel_encoder *encoder); 2018 2019 void (*lock)(struct intel_digital_port *dig_port); 2020 void (*unlock)(struct intel_digital_port *dig_port); 2021 }; 2022 2023 struct intel_dp_mst_encoder { 2024 struct intel_encoder base; 2025 enum pipe pipe; 2026 struct intel_digital_port *primary; 2027 struct intel_connector *connector; 2028 }; 2029 2030 struct intel_colorop { 2031 struct drm_colorop base; 2032 enum intel_color_block id; 2033 }; 2034 2035 static inline struct intel_encoder * 2036 intel_attached_encoder(struct intel_connector *connector) 2037 { 2038 return connector->encoder; 2039 } 2040 2041 static inline bool intel_encoder_is_dig_port(struct intel_encoder *encoder) 2042 { 2043 switch (encoder->type) { 2044 case INTEL_OUTPUT_DDI: 2045 case INTEL_OUTPUT_DP: 2046 case INTEL_OUTPUT_EDP: 2047 case INTEL_OUTPUT_HDMI: 2048 return true; 2049 default: 2050 return false; 2051 } 2052 } 2053 2054 static inline bool intel_encoder_is_mst(struct intel_encoder *encoder) 2055 { 2056 return encoder->type == INTEL_OUTPUT_DP_MST; 2057 } 2058 2059 static inline struct intel_dp_mst_encoder * 2060 enc_to_mst(struct intel_encoder *encoder) 2061 { 2062 return container_of(&encoder->base, struct intel_dp_mst_encoder, 2063 base.base); 2064 } 2065 2066 static inline struct intel_digital_port * 2067 enc_to_dig_port(struct intel_encoder *encoder) 2068 { 2069 struct intel_encoder *intel_encoder = encoder; 2070 2071 if (intel_encoder_is_dig_port(intel_encoder)) 2072 return container_of(&encoder->base, struct intel_digital_port, 2073 base.base); 2074 else if (intel_encoder_is_mst(intel_encoder)) 2075 return enc_to_mst(encoder)->primary; 2076 else 2077 return NULL; 2078 } 2079 2080 static inline struct intel_digital_port * 2081 intel_attached_dig_port(struct intel_connector *connector) 2082 { 2083 return enc_to_dig_port(intel_attached_encoder(connector)); 2084 } 2085 2086 static inline struct intel_hdmi * 2087 enc_to_intel_hdmi(struct intel_encoder *encoder) 2088 { 2089 return &enc_to_dig_port(encoder)->hdmi; 2090 } 2091 2092 static inline struct intel_hdmi * 2093 intel_attached_hdmi(struct intel_connector *connector) 2094 { 2095 return enc_to_intel_hdmi(intel_attached_encoder(connector)); 2096 } 2097 2098 static inline struct intel_dp *enc_to_intel_dp(struct intel_encoder *encoder) 2099 { 2100 return &enc_to_dig_port(encoder)->dp; 2101 } 2102 2103 static inline struct intel_dp *intel_attached_dp(struct intel_connector *connector) 2104 { 2105 if (connector->mst.dp) 2106 return connector->mst.dp; 2107 else 2108 return enc_to_intel_dp(intel_attached_encoder(connector)); 2109 } 2110 2111 static inline bool intel_encoder_is_dp(struct intel_encoder *encoder) 2112 { 2113 switch (encoder->type) { 2114 case INTEL_OUTPUT_DP: 2115 case INTEL_OUTPUT_EDP: 2116 return true; 2117 case INTEL_OUTPUT_DDI: 2118 /* Skip pure HDMI/DVI DDI encoders */ 2119 return i915_mmio_reg_valid(enc_to_intel_dp(encoder)->output_reg); 2120 default: 2121 return false; 2122 } 2123 } 2124 2125 static inline bool intel_encoder_is_hdmi(struct intel_encoder *encoder) 2126 { 2127 switch (encoder->type) { 2128 case INTEL_OUTPUT_HDMI: 2129 return true; 2130 case INTEL_OUTPUT_DDI: 2131 /* See if the HDMI encoder is valid. */ 2132 return i915_mmio_reg_valid(enc_to_intel_hdmi(encoder)->hdmi_reg); 2133 default: 2134 return false; 2135 } 2136 } 2137 2138 static inline struct intel_digital_port * 2139 dp_to_dig_port(struct intel_dp *intel_dp) 2140 { 2141 return container_of(intel_dp, struct intel_digital_port, dp); 2142 } 2143 2144 static inline struct intel_digital_port * 2145 hdmi_to_dig_port(struct intel_hdmi *intel_hdmi) 2146 { 2147 return container_of(intel_hdmi, struct intel_digital_port, hdmi); 2148 } 2149 2150 static inline struct intel_plane_state * 2151 intel_atomic_get_plane_state(struct intel_atomic_state *state, 2152 struct intel_plane *plane) 2153 { 2154 struct drm_plane_state *ret = 2155 drm_atomic_get_plane_state(&state->base, &plane->base); 2156 2157 if (IS_ERR(ret)) 2158 return ERR_CAST(ret); 2159 2160 return to_intel_plane_state(ret); 2161 } 2162 2163 static inline struct intel_plane_state * 2164 intel_atomic_get_old_plane_state(struct intel_atomic_state *state, 2165 struct intel_plane *plane) 2166 { 2167 return to_intel_plane_state(drm_atomic_get_old_plane_state(&state->base, 2168 &plane->base)); 2169 } 2170 2171 static inline struct intel_plane_state * 2172 intel_atomic_get_new_plane_state(struct intel_atomic_state *state, 2173 struct intel_plane *plane) 2174 { 2175 return to_intel_plane_state(drm_atomic_get_new_plane_state(&state->base, 2176 &plane->base)); 2177 } 2178 2179 static inline struct intel_crtc_state * 2180 intel_atomic_get_old_crtc_state(struct intel_atomic_state *state, 2181 struct intel_crtc *crtc) 2182 { 2183 return to_intel_crtc_state(drm_atomic_get_old_crtc_state(&state->base, 2184 &crtc->base)); 2185 } 2186 2187 static inline struct intel_crtc_state * 2188 intel_atomic_get_new_crtc_state(struct intel_atomic_state *state, 2189 struct intel_crtc *crtc) 2190 { 2191 return to_intel_crtc_state(drm_atomic_get_new_crtc_state(&state->base, 2192 &crtc->base)); 2193 } 2194 2195 static inline struct intel_digital_connector_state * 2196 intel_atomic_get_new_connector_state(struct intel_atomic_state *state, 2197 struct intel_connector *connector) 2198 { 2199 return to_intel_digital_connector_state( 2200 drm_atomic_get_new_connector_state(&state->base, 2201 &connector->base)); 2202 } 2203 2204 static inline struct intel_digital_connector_state * 2205 intel_atomic_get_old_connector_state(struct intel_atomic_state *state, 2206 struct intel_connector *connector) 2207 { 2208 return to_intel_digital_connector_state( 2209 drm_atomic_get_old_connector_state(&state->base, 2210 &connector->base)); 2211 } 2212 2213 /* intel_display.c */ 2214 static inline bool 2215 intel_crtc_has_type(const struct intel_crtc_state *crtc_state, 2216 enum intel_output_type type) 2217 { 2218 return crtc_state->output_types & BIT(type); 2219 } 2220 2221 static inline bool 2222 intel_crtc_has_dp_encoder(const struct intel_crtc_state *crtc_state) 2223 { 2224 return crtc_state->output_types & 2225 (BIT(INTEL_OUTPUT_DP) | 2226 BIT(INTEL_OUTPUT_DP_MST) | 2227 BIT(INTEL_OUTPUT_EDP)); 2228 } 2229 2230 static inline bool 2231 intel_crtc_needs_modeset(const struct intel_crtc_state *crtc_state) 2232 { 2233 return drm_atomic_crtc_needs_modeset(&crtc_state->uapi); 2234 } 2235 2236 static inline bool 2237 intel_crtc_needs_fastset(const struct intel_crtc_state *crtc_state) 2238 { 2239 return crtc_state->update_pipe; 2240 } 2241 2242 static inline bool 2243 intel_crtc_needs_color_update(const struct intel_crtc_state *crtc_state) 2244 { 2245 return crtc_state->uapi.color_mgmt_changed || 2246 intel_crtc_needs_fastset(crtc_state) || 2247 intel_crtc_needs_modeset(crtc_state); 2248 } 2249 2250 static inline struct intel_frontbuffer * 2251 to_intel_frontbuffer(struct drm_framebuffer *fb) 2252 { 2253 return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL; 2254 } 2255 2256 /* 2257 * Conversion functions/macros from various pointer types to struct 2258 * intel_display pointer. 2259 */ 2260 #define __drm_device_to_intel_display(p) \ 2261 ((p) ? __drm_to_display(p) : NULL) 2262 #define __device_to_intel_display(p) \ 2263 __drm_device_to_intel_display(dev_get_drvdata(p)) 2264 #define __pci_dev_to_intel_display(p) \ 2265 __drm_device_to_intel_display(pci_get_drvdata(p)) 2266 #define __intel_atomic_state_to_intel_display(p) \ 2267 __drm_device_to_intel_display((p)->base.dev) 2268 #define __intel_connector_to_intel_display(p) \ 2269 __drm_device_to_intel_display((p)->base.dev) 2270 #define __intel_crtc_to_intel_display(p) \ 2271 __drm_device_to_intel_display((p)->base.dev) 2272 #define __intel_crtc_state_to_intel_display(p) \ 2273 __drm_device_to_intel_display((p)->uapi.crtc->dev) 2274 #define __intel_digital_port_to_intel_display(p) \ 2275 __drm_device_to_intel_display((p)->base.base.dev) 2276 #define __intel_dp_to_intel_display(p) \ 2277 __drm_device_to_intel_display(dp_to_dig_port(p)->base.base.dev) 2278 #define __intel_encoder_to_intel_display(p) \ 2279 __drm_device_to_intel_display((p)->base.dev) 2280 #define __intel_hdmi_to_intel_display(p) \ 2281 __drm_device_to_intel_display(hdmi_to_dig_port(p)->base.base.dev) 2282 #define __intel_plane_to_intel_display(p) \ 2283 __drm_device_to_intel_display((p)->base.dev) 2284 #define __intel_plane_state_to_intel_display(p) \ 2285 __drm_device_to_intel_display((p)->uapi.plane->dev) 2286 2287 /* Helper for generic association. Map types to conversion functions/macros. */ 2288 #define __assoc(type, p) \ 2289 struct type: __##type##_to_intel_display((struct type *)(p)) 2290 2291 /* Convert various pointer types to struct intel_display pointer. */ 2292 #define to_intel_display(p) \ 2293 _Generic(*p, \ 2294 __assoc(drm_device, p), \ 2295 __assoc(device, p), \ 2296 __assoc(pci_dev, p), \ 2297 __assoc(intel_atomic_state, p), \ 2298 __assoc(intel_connector, p), \ 2299 __assoc(intel_crtc, p), \ 2300 __assoc(intel_crtc_state, p), \ 2301 __assoc(intel_digital_port, p), \ 2302 __assoc(intel_dp, p), \ 2303 __assoc(intel_encoder, p), \ 2304 __assoc(intel_hdmi, p), \ 2305 __assoc(intel_plane, p), \ 2306 __assoc(intel_plane_state, p)) 2307 2308 #endif /* __INTEL_DISPLAY_TYPES_H__ */ 2309