2 * Copyright © 2006-2019 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #ifndef _INTEL_DISPLAY_H_
26 #define _INTEL_DISPLAY_H_
28 #include <drm/drm_util.h>
29 #include <drm/i915_drm.h>
35 struct drm_display_mode;
38 struct drm_format_info;
39 struct drm_framebuffer;
40 struct drm_i915_error_state_buf;
41 struct drm_i915_gem_object;
42 struct drm_i915_private;
43 struct drm_modeset_acquire_ctx;
45 struct drm_plane_state;
46 struct i915_ggtt_view;
48 struct intel_crtc_state;
49 struct intel_digital_port;
52 struct intel_load_detect_pipe;
54 struct intel_plane_state;
55 struct intel_remapped_info;
56 struct intel_rotation_info;
57 struct intel_crtc_state;
78 * Keep the pipe enum values fixed: the code assumes that PIPE_A=0, the
79 * rest have consecutive values and match the enum values of transcoders
80 * with a 1:1 transcoder -> pipe mapping.
91 I915_MAX_PIPES = _PIPE_EDP
94 #define pipe_name(p) ((p) + 'A')
97 INVALID_TRANSCODER = -1,
99 * The following transcoders have a 1:1 transcoder -> pipe mapping,
100 * keep their values fixed: the code assumes that TRANSCODER_A=0, the
101 * rest have consecutive values and match the enum values of the pipes
104 TRANSCODER_A = PIPE_A,
105 TRANSCODER_B = PIPE_B,
106 TRANSCODER_C = PIPE_C,
107 TRANSCODER_D = PIPE_D,
110 * The following transcoders can map to any pipe, their enum value
111 * doesn't need to stay fixed.
116 TRANSCODER_DSI_A = TRANSCODER_DSI_0, /* legacy DSI */
117 TRANSCODER_DSI_C = TRANSCODER_DSI_1, /* legacy DSI */
122 static inline const char *transcoder_name(enum transcoder transcoder)
124 switch (transcoder) {
135 case TRANSCODER_DSI_A:
137 case TRANSCODER_DSI_C:
144 static inline bool transcoder_is_dsi(enum transcoder transcoder)
146 return transcoder == TRANSCODER_DSI_A || transcoder == TRANSCODER_DSI_C;
150 * Global legacy plane identifier. Valid only for primary/sprite
151 * planes on pre-g4x, and only for primary planes on g4x-bdw.
159 #define plane_name(p) ((p) + 'A')
160 #define sprite_name(p, s) ((p) * RUNTIME_INFO(dev_priv)->num_sprites[(p)] + (s) + 'A')
163 * Per-pipe plane identifier.
164 * I915_MAX_PLANES in the enum below is the maximum (across all platforms)
165 * number of planes per CRTC. Not all platforms really have this many planes,
166 * which means some arrays of size I915_MAX_PLANES may have unused entries
167 * between the topmost sprite plane and the cursor plane.
169 * This is expected to be passed to various register macros
170 * (eg. PLANE_CTL(), PS_PLANE_SEL(), etc.) so adjust with care.
185 #define for_each_plane_id_on_crtc(__crtc, __p) \
186 for ((__p) = PLANE_PRIMARY; (__p) < I915_MAX_PLANES; (__p)++) \
187 for_each_if((__crtc)->plane_ids_mask & BIT(__p))
205 #define port_name(p) ((p) + 'A')
208 * Ports identifier referenced from other drivers.
209 * Expected to remain stable over time
211 static inline const char *port_identifier(enum port port)
267 #define I915_NUM_PHYS_VLV 2
279 #define aux_ch_name(a) ((a) + 'A')
281 /* Used by dp and fdi links */
282 struct intel_link_m_n {
306 #define phy_name(a) ((a) + 'A')
314 #define for_each_pipe(__dev_priv, __p) \
315 for ((__p) = 0; (__p) < INTEL_NUM_PIPES(__dev_priv); (__p)++)
317 #define for_each_pipe_masked(__dev_priv, __p, __mask) \
318 for ((__p) = 0; (__p) < INTEL_NUM_PIPES(__dev_priv); (__p)++) \
319 for_each_if((__mask) & BIT(__p))
321 #define for_each_cpu_transcoder_masked(__dev_priv, __t, __mask) \
322 for ((__t) = 0; (__t) < I915_MAX_TRANSCODERS; (__t)++) \
323 for_each_if ((__mask) & (1 << (__t)))
325 #define for_each_universal_plane(__dev_priv, __pipe, __p) \
327 (__p) < RUNTIME_INFO(__dev_priv)->num_sprites[(__pipe)] + 1; \
330 #define for_each_sprite(__dev_priv, __p, __s) \
332 (__s) < RUNTIME_INFO(__dev_priv)->num_sprites[(__p)]; \
335 #define for_each_port(__port) \
336 for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++)
338 #define for_each_port_masked(__port, __ports_mask) \
339 for_each_port(__port) \
340 for_each_if((__ports_mask) & BIT(__port))
342 #define for_each_phy_masked(__phy, __phys_mask) \
343 for ((__phy) = PHY_A; (__phy) < I915_MAX_PHYS; (__phy)++) \
344 for_each_if((__phys_mask) & BIT(__phy))
346 #define for_each_crtc(dev, crtc) \
347 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
349 #define for_each_intel_plane(dev, intel_plane) \
350 list_for_each_entry(intel_plane, \
351 &(dev)->mode_config.plane_list, \
354 #define for_each_intel_plane_mask(dev, intel_plane, plane_mask) \
355 list_for_each_entry(intel_plane, \
356 &(dev)->mode_config.plane_list, \
358 for_each_if((plane_mask) & \
359 drm_plane_mask(&intel_plane->base))
361 #define for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) \
362 list_for_each_entry(intel_plane, \
363 &(dev)->mode_config.plane_list, \
365 for_each_if((intel_plane)->pipe == (intel_crtc)->pipe)
367 #define for_each_intel_crtc(dev, intel_crtc) \
368 list_for_each_entry(intel_crtc, \
369 &(dev)->mode_config.crtc_list, \
372 #define for_each_intel_crtc_mask(dev, intel_crtc, crtc_mask) \
373 list_for_each_entry(intel_crtc, \
374 &(dev)->mode_config.crtc_list, \
376 for_each_if((crtc_mask) & drm_crtc_mask(&intel_crtc->base))
378 #define for_each_intel_encoder(dev, intel_encoder) \
379 list_for_each_entry(intel_encoder, \
380 &(dev)->mode_config.encoder_list, \
383 #define for_each_intel_encoder_mask(dev, intel_encoder, encoder_mask) \
384 list_for_each_entry(intel_encoder, \
385 &(dev)->mode_config.encoder_list, \
387 for_each_if((encoder_mask) & \
388 drm_encoder_mask(&intel_encoder->base))
390 #define for_each_intel_dp(dev, intel_encoder) \
391 for_each_intel_encoder(dev, intel_encoder) \
392 for_each_if(intel_encoder_is_dp(intel_encoder))
394 #define for_each_intel_connector_iter(intel_connector, iter) \
395 while ((intel_connector = to_intel_connector(drm_connector_list_iter_next(iter))))
397 #define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
398 list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
399 for_each_if((intel_encoder)->base.crtc == (__crtc))
401 #define for_each_connector_on_encoder(dev, __encoder, intel_connector) \
402 list_for_each_entry((intel_connector), &(dev)->mode_config.connector_list, base.head) \
403 for_each_if((intel_connector)->base.encoder == (__encoder))
405 #define for_each_old_intel_plane_in_state(__state, plane, old_plane_state, __i) \
407 (__i) < (__state)->base.dev->mode_config.num_total_plane && \
408 ((plane) = to_intel_plane((__state)->base.planes[__i].ptr), \
409 (old_plane_state) = to_intel_plane_state((__state)->base.planes[__i].old_state), 1); \
413 #define for_each_new_intel_plane_in_state(__state, plane, new_plane_state, __i) \
415 (__i) < (__state)->base.dev->mode_config.num_total_plane && \
416 ((plane) = to_intel_plane((__state)->base.planes[__i].ptr), \
417 (new_plane_state) = to_intel_plane_state((__state)->base.planes[__i].new_state), 1); \
421 #define for_each_new_intel_crtc_in_state(__state, crtc, new_crtc_state, __i) \
423 (__i) < (__state)->base.dev->mode_config.num_crtc && \
424 ((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
425 (new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
429 #define for_each_oldnew_intel_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
431 (__i) < (__state)->base.dev->mode_config.num_total_plane && \
432 ((plane) = to_intel_plane((__state)->base.planes[__i].ptr), \
433 (old_plane_state) = to_intel_plane_state((__state)->base.planes[__i].old_state), \
434 (new_plane_state) = to_intel_plane_state((__state)->base.planes[__i].new_state), 1); \
438 #define for_each_oldnew_intel_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
440 (__i) < (__state)->base.dev->mode_config.num_crtc && \
441 ((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
442 (old_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].old_state), \
443 (new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
447 #define for_each_oldnew_intel_crtc_in_state_reverse(__state, crtc, old_crtc_state, new_crtc_state, __i) \
448 for ((__i) = (__state)->base.dev->mode_config.num_crtc - 1; \
450 ((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
451 (old_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].old_state), \
452 (new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
456 #define intel_atomic_crtc_state_for_each_plane_state( \
457 plane, plane_state, \
459 for_each_intel_plane_mask(((crtc_state)->uapi.state->dev), (plane), \
460 ((crtc_state)->uapi.plane_mask)) \
461 for_each_if ((plane_state = \
462 to_intel_plane_state(__drm_atomic_get_current_plane_state((crtc_state)->uapi.state, &plane->base))))
464 #define for_each_new_intel_connector_in_state(__state, connector, new_connector_state, __i) \
466 (__i) < (__state)->base.num_connector; \
468 for_each_if ((__state)->base.connectors[__i].ptr && \
469 ((connector) = to_intel_connector((__state)->base.connectors[__i].ptr), \
470 (new_connector_state) = to_intel_digital_connector_state((__state)->base.connectors[__i].new_state), 1))
472 void intel_link_compute_m_n(u16 bpp, int nlanes,
473 int pixel_clock, int link_clock,
474 struct intel_link_m_n *m_n,
475 bool constant_n, bool fec_enable);
476 bool is_ccs_modifier(u64 modifier);
477 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv);
478 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
479 u32 pixel_format, u64 modifier);
480 bool intel_plane_can_remap(const struct intel_plane_state *plane_state);
482 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
483 const struct drm_display_mode *mode);
484 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port);
485 bool is_trans_port_sync_mode(const struct intel_crtc_state *state);
487 void intel_plane_destroy(struct drm_plane *plane);
488 void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state);
489 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe);
490 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe);
491 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc);
492 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv);
493 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
494 const char *name, u32 reg, int ref_freq);
495 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
496 const char *name, u32 reg);
497 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv);
498 void lpt_disable_iclkip(struct drm_i915_private *dev_priv);
499 void intel_init_display_hooks(struct drm_i915_private *dev_priv);
500 unsigned int intel_fb_xy_to_linear(int x, int y,
501 const struct intel_plane_state *state,
503 unsigned int intel_fb_align_height(const struct drm_framebuffer *fb,
504 int color_plane, unsigned int height);
505 void intel_add_fb_offsets(int *x, int *y,
506 const struct intel_plane_state *state, int plane);
507 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info);
508 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info);
509 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv);
510 int intel_display_suspend(struct drm_device *dev);
511 void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv);
512 void intel_encoder_destroy(struct drm_encoder *encoder);
513 struct drm_display_mode *
514 intel_encoder_current_mode(struct intel_encoder *encoder);
515 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy);
516 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy);
517 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv,
519 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
520 struct drm_file *file_priv);
521 u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc);
522 void intel_crtc_vblank_off(const struct intel_crtc_state *crtc_state);
524 int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp);
525 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
526 struct intel_digital_port *dport,
527 unsigned int expected_mask);
528 int intel_get_load_detect_pipe(struct drm_connector *connector,
529 struct intel_load_detect_pipe *old,
530 struct drm_modeset_acquire_ctx *ctx);
531 void intel_release_load_detect_pipe(struct drm_connector *connector,
532 struct intel_load_detect_pipe *old,
533 struct drm_modeset_acquire_ctx *ctx);
535 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
536 const struct i915_ggtt_view *view,
538 unsigned long *out_flags);
539 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags);
540 struct drm_framebuffer *
541 intel_framebuffer_create(struct drm_i915_gem_object *obj,
542 struct drm_mode_fb_cmd2 *mode_cmd);
543 int intel_prepare_plane_fb(struct drm_plane *plane,
544 struct drm_plane_state *new_state);
545 void intel_cleanup_plane_fb(struct drm_plane *plane,
546 struct drm_plane_state *old_state);
548 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
551 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
552 const struct dpll *dpll);
553 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe);
554 int lpt_get_iclkip(struct drm_i915_private *dev_priv);
555 bool intel_fuzzy_clock_check(int clock1, int clock2);
557 void intel_prepare_reset(struct drm_i915_private *dev_priv);
558 void intel_finish_reset(struct drm_i915_private *dev_priv);
559 void intel_dp_get_m_n(struct intel_crtc *crtc,
560 struct intel_crtc_state *pipe_config);
561 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state,
562 enum link_m_n_set m_n);
563 int intel_dotclock_calculate(int link_freq, const struct intel_link_m_n *m_n);
564 bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state,
565 struct dpll *best_clock);
566 int chv_calc_dpll_params(int refclk, struct dpll *pll_clock);
568 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state);
569 void hsw_enable_ips(const struct intel_crtc_state *crtc_state);
570 void hsw_disable_ips(const struct intel_crtc_state *crtc_state);
571 enum intel_display_power_domain intel_port_to_power_domain(enum port port);
572 enum intel_display_power_domain
573 intel_aux_power_domain(struct intel_digital_port *dig_port);
574 void intel_mode_from_pipe_config(struct drm_display_mode *mode,
575 struct intel_crtc_state *pipe_config);
576 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
577 struct intel_crtc_state *crtc_state);
579 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_center);
580 int skl_update_scaler_crtc(struct intel_crtc_state *crtc_state);
581 void skylake_scaler_disable(const struct intel_crtc_state *old_crtc_state);
582 void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
583 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
584 const struct intel_plane_state *plane_state);
585 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state);
586 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
587 const struct intel_plane_state *plane_state);
588 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state);
589 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
591 int skl_check_plane_surface(struct intel_plane_state *plane_state);
592 int i9xx_check_plane_surface(struct intel_plane_state *plane_state);
593 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha);
594 unsigned int i9xx_plane_max_stride(struct intel_plane *plane,
595 u32 pixel_format, u64 modifier,
596 unsigned int rotation);
597 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc);
599 struct intel_display_error_state *
600 intel_display_capture_error_state(struct drm_i915_private *dev_priv);
601 void intel_display_print_error_state(struct drm_i915_error_state_buf *e,
602 struct intel_display_error_state *error);
605 void intel_modeset_init_hw(struct drm_i915_private *i915);
606 int intel_modeset_init(struct drm_i915_private *i915);
607 void intel_modeset_driver_remove(struct drm_i915_private *i915);
608 void intel_display_resume(struct drm_device *dev);
609 void intel_init_pch_refclk(struct drm_i915_private *dev_priv);
611 /* modesetting asserts */
612 void assert_panel_unlocked(struct drm_i915_private *dev_priv,
614 void assert_pll(struct drm_i915_private *dev_priv,
615 enum pipe pipe, bool state);
616 #define assert_pll_enabled(d, p) assert_pll(d, p, true)
617 #define assert_pll_disabled(d, p) assert_pll(d, p, false)
618 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state);
619 #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
620 #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
621 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
622 enum pipe pipe, bool state);
623 #define assert_fdi_rx_pll_enabled(d, p) assert_fdi_rx_pll(d, p, true)
624 #define assert_fdi_rx_pll_disabled(d, p) assert_fdi_rx_pll(d, p, false)
625 void assert_pipe(struct drm_i915_private *dev_priv,
626 enum transcoder cpu_transcoder, bool state);
627 #define assert_pipe_enabled(d, t) assert_pipe(d, t, true)
628 #define assert_pipe_disabled(d, t) assert_pipe(d, t, false)
630 /* Use I915_STATE_WARN(x) and I915_STATE_WARN_ON() (rather than WARN() and
631 * WARN_ON()) for hw state sanity checks to check for unexpected conditions
632 * which may not necessarily be a user visible problem. This will either
633 * WARN() or DRM_ERROR() depending on the verbose_checks moduleparam, to
634 * enable distros and users to tailor their preferred amount of i915 abrt
637 #define I915_STATE_WARN(condition, format...) ({ \
638 int __ret_warn_on = !!(condition); \
639 if (unlikely(__ret_warn_on)) \
640 if (!WARN(i915_modparams.verbose_state_checks, format)) \
642 unlikely(__ret_warn_on); \
645 #define I915_STATE_WARN_ON(x) \
646 I915_STATE_WARN((x), "%s", "WARN_ON(" __stringify(x) ")")