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