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>
30 #include "i915_reg_defs.h"
31 #include "intel_display_limits.h"
33 enum drm_scaling_filter;
35 struct drm_atomic_state;
38 struct drm_display_mode;
41 struct drm_format_info;
42 struct drm_framebuffer;
43 struct drm_i915_gem_object;
44 struct drm_i915_private;
45 struct drm_mode_fb_cmd2;
46 struct drm_modeset_acquire_ctx;
48 struct drm_plane_state;
49 struct i915_address_space;
51 struct intel_atomic_state;
53 struct intel_crtc_state;
54 struct intel_digital_port;
57 struct intel_initial_plane_config;
58 struct intel_link_m_n;
60 struct intel_plane_state;
61 struct intel_power_domain_mask;
62 struct intel_remapped_info;
63 struct intel_rotation_info;
68 #define pipe_name(p) ((p) + 'A')
70 static inline const char *transcoder_name(enum transcoder transcoder)
83 case TRANSCODER_DSI_A:
85 case TRANSCODER_DSI_C:
92 static inline bool transcoder_is_dsi(enum transcoder transcoder)
94 return transcoder == TRANSCODER_DSI_A || transcoder == TRANSCODER_DSI_C;
98 * Global legacy plane identifier. Valid only for primary/sprite
99 * planes on pre-g4x, and only for primary planes on g4x-bdw.
107 #define plane_name(p) ((p) + 'A')
108 #define sprite_name(p, s) ((p) * DISPLAY_RUNTIME_INFO(dev_priv)->num_sprites[(p)] + (s) + 'A')
110 #define for_each_plane_id_on_crtc(__crtc, __p) \
111 for ((__p) = PLANE_PRIMARY; (__p) < I915_MAX_PLANES; (__p)++) \
112 for_each_if((__crtc)->plane_ids_mask & BIT(__p))
114 #define for_each_dbuf_slice(__dev_priv, __slice) \
115 for ((__slice) = DBUF_S1; (__slice) < I915_MAX_DBUF_SLICES; (__slice)++) \
116 for_each_if(DISPLAY_INFO(__dev_priv)->dbuf.slice_mask & BIT(__slice))
118 #define for_each_dbuf_slice_in_mask(__dev_priv, __slice, __mask) \
119 for_each_dbuf_slice((__dev_priv), (__slice)) \
120 for_each_if((__mask) & BIT(__slice))
122 #define port_name(p) ((p) + 'A')
125 * Ports identifier referenced from other drivers.
126 * Expected to remain stable over time
128 static inline const char *port_identifier(enum port port)
181 AUX_CH_USBC1 = AUX_CH_D,
188 /* XE_LPD repositions D/E offsets and bitfields */
189 AUX_CH_D_XELPD = AUX_CH_USBC5,
209 #define phy_name(a) ((a) + 'A')
217 #define for_each_hpd_pin(__pin) \
218 for ((__pin) = (HPD_NONE + 1); (__pin) < HPD_NUM_PINS; (__pin)++)
220 #define for_each_pipe(__dev_priv, __p) \
221 for ((__p) = 0; (__p) < I915_MAX_PIPES; (__p)++) \
222 for_each_if(DISPLAY_RUNTIME_INFO(__dev_priv)->pipe_mask & BIT(__p))
224 #define for_each_pipe_masked(__dev_priv, __p, __mask) \
225 for_each_pipe(__dev_priv, __p) \
226 for_each_if((__mask) & BIT(__p))
228 #define for_each_cpu_transcoder(__dev_priv, __t) \
229 for ((__t) = 0; (__t) < I915_MAX_TRANSCODERS; (__t)++) \
230 for_each_if (DISPLAY_RUNTIME_INFO(__dev_priv)->cpu_transcoder_mask & BIT(__t))
232 #define for_each_cpu_transcoder_masked(__dev_priv, __t, __mask) \
233 for_each_cpu_transcoder(__dev_priv, __t) \
234 for_each_if ((__mask) & BIT(__t))
236 #define for_each_sprite(__dev_priv, __p, __s) \
238 (__s) < DISPLAY_RUNTIME_INFO(__dev_priv)->num_sprites[(__p)]; \
241 #define for_each_port(__port) \
242 for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++)
244 #define for_each_port_masked(__port, __ports_mask) \
245 for_each_port(__port) \
246 for_each_if((__ports_mask) & BIT(__port))
248 #define for_each_phy_masked(__phy, __phys_mask) \
249 for ((__phy) = PHY_A; (__phy) < I915_MAX_PHYS; (__phy)++) \
250 for_each_if((__phys_mask) & BIT(__phy))
252 #define for_each_crtc(dev, crtc) \
253 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
255 #define for_each_intel_plane(dev, intel_plane) \
256 list_for_each_entry(intel_plane, \
257 &(dev)->mode_config.plane_list, \
260 #define for_each_intel_plane_mask(dev, intel_plane, plane_mask) \
261 list_for_each_entry(intel_plane, \
262 &(dev)->mode_config.plane_list, \
264 for_each_if((plane_mask) & \
265 drm_plane_mask(&intel_plane->base))
267 #define for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) \
268 list_for_each_entry(intel_plane, \
269 &(dev)->mode_config.plane_list, \
271 for_each_if((intel_plane)->pipe == (intel_crtc)->pipe)
273 #define for_each_intel_crtc(dev, intel_crtc) \
274 list_for_each_entry(intel_crtc, \
275 &(dev)->mode_config.crtc_list, \
278 #define for_each_intel_crtc_in_pipe_mask(dev, intel_crtc, pipe_mask) \
279 list_for_each_entry(intel_crtc, \
280 &(dev)->mode_config.crtc_list, \
282 for_each_if((pipe_mask) & BIT(intel_crtc->pipe))
284 #define for_each_intel_encoder(dev, intel_encoder) \
285 list_for_each_entry(intel_encoder, \
286 &(dev)->mode_config.encoder_list, \
289 #define for_each_intel_encoder_mask(dev, intel_encoder, encoder_mask) \
290 list_for_each_entry(intel_encoder, \
291 &(dev)->mode_config.encoder_list, \
293 for_each_if((encoder_mask) & \
294 drm_encoder_mask(&intel_encoder->base))
296 #define for_each_intel_encoder_mask_with_psr(dev, intel_encoder, encoder_mask) \
297 list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
298 for_each_if(((encoder_mask) & drm_encoder_mask(&(intel_encoder)->base)) && \
299 intel_encoder_can_psr(intel_encoder))
301 #define for_each_intel_dp(dev, intel_encoder) \
302 for_each_intel_encoder(dev, intel_encoder) \
303 for_each_if(intel_encoder_is_dp(intel_encoder))
305 #define for_each_intel_encoder_with_psr(dev, intel_encoder) \
306 for_each_intel_encoder((dev), (intel_encoder)) \
307 for_each_if(intel_encoder_can_psr(intel_encoder))
309 #define for_each_intel_connector_iter(intel_connector, iter) \
310 while ((intel_connector = to_intel_connector(drm_connector_list_iter_next(iter))))
312 #define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
313 list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
314 for_each_if((intel_encoder)->base.crtc == (__crtc))
316 #define for_each_old_intel_plane_in_state(__state, plane, old_plane_state, __i) \
318 (__i) < (__state)->base.dev->mode_config.num_total_plane && \
319 ((plane) = to_intel_plane((__state)->base.planes[__i].ptr), \
320 (old_plane_state) = to_intel_plane_state((__state)->base.planes[__i].old_state), 1); \
324 #define for_each_old_intel_crtc_in_state(__state, crtc, old_crtc_state, __i) \
326 (__i) < (__state)->base.dev->mode_config.num_crtc && \
327 ((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
328 (old_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].old_state), 1); \
332 #define for_each_new_intel_plane_in_state(__state, plane, new_plane_state, __i) \
334 (__i) < (__state)->base.dev->mode_config.num_total_plane && \
335 ((plane) = to_intel_plane((__state)->base.planes[__i].ptr), \
336 (new_plane_state) = to_intel_plane_state((__state)->base.planes[__i].new_state), 1); \
340 #define for_each_new_intel_crtc_in_state(__state, crtc, new_crtc_state, __i) \
342 (__i) < (__state)->base.dev->mode_config.num_crtc && \
343 ((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
344 (new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
348 #define for_each_oldnew_intel_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
350 (__i) < (__state)->base.dev->mode_config.num_total_plane && \
351 ((plane) = to_intel_plane((__state)->base.planes[__i].ptr), \
352 (old_plane_state) = to_intel_plane_state((__state)->base.planes[__i].old_state), \
353 (new_plane_state) = to_intel_plane_state((__state)->base.planes[__i].new_state), 1); \
357 #define for_each_oldnew_intel_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
359 (__i) < (__state)->base.dev->mode_config.num_crtc && \
360 ((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
361 (old_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].old_state), \
362 (new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
366 #define for_each_oldnew_intel_crtc_in_state_reverse(__state, crtc, old_crtc_state, new_crtc_state, __i) \
367 for ((__i) = (__state)->base.dev->mode_config.num_crtc - 1; \
369 ((crtc) = to_intel_crtc((__state)->base.crtcs[__i].ptr), \
370 (old_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].old_state), \
371 (new_crtc_state) = to_intel_crtc_state((__state)->base.crtcs[__i].new_state), 1); \
375 #define intel_atomic_crtc_state_for_each_plane_state( \
376 plane, plane_state, \
378 for_each_intel_plane_mask(((crtc_state)->uapi.state->dev), (plane), \
379 ((crtc_state)->uapi.plane_mask)) \
380 for_each_if ((plane_state = \
381 to_intel_plane_state(__drm_atomic_get_current_plane_state((crtc_state)->uapi.state, &plane->base))))
383 #define for_each_new_intel_connector_in_state(__state, connector, new_connector_state, __i) \
385 (__i) < (__state)->base.num_connector; \
387 for_each_if ((__state)->base.connectors[__i].ptr && \
388 ((connector) = to_intel_connector((__state)->base.connectors[__i].ptr), \
389 (new_connector_state) = to_intel_digital_connector_state((__state)->base.connectors[__i].new_state), 1))
391 int intel_atomic_check(struct drm_device *dev, struct drm_atomic_state *state);
392 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
393 struct intel_crtc *crtc);
394 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
396 void intel_link_compute_m_n(u16 bpp, int nlanes,
397 int pixel_clock, int link_clock,
398 struct intel_link_m_n *m_n,
400 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
401 u32 pixel_format, u64 modifier);
403 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
404 const struct drm_display_mode *mode,
407 intel_cpu_transcoder_mode_valid(struct drm_i915_private *i915,
408 const struct drm_display_mode *mode);
409 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port);
410 bool is_trans_port_sync_mode(const struct intel_crtc_state *state);
411 bool is_trans_port_sync_master(const struct intel_crtc_state *state);
412 bool intel_crtc_is_bigjoiner_slave(const struct intel_crtc_state *crtc_state);
413 bool intel_crtc_is_bigjoiner_master(const struct intel_crtc_state *crtc_state);
414 u8 intel_crtc_bigjoiner_slave_pipes(const struct intel_crtc_state *crtc_state);
415 struct intel_crtc *intel_master_crtc(const struct intel_crtc_state *crtc_state);
416 bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state);
417 bool intel_pipe_config_compare(const struct intel_crtc_state *current_config,
418 const struct intel_crtc_state *pipe_config,
421 void intel_plane_destroy(struct drm_plane *plane);
422 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
423 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state);
424 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state);
425 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state);
426 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe);
427 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe);
428 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv);
429 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
430 const char *name, u32 reg, int ref_freq);
431 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
432 const char *name, u32 reg);
433 void intel_init_display_hooks(struct drm_i915_private *dev_priv);
434 unsigned int intel_fb_xy_to_linear(int x, int y,
435 const struct intel_plane_state *state,
437 void intel_add_fb_offsets(int *x, int *y,
438 const struct intel_plane_state *state, int plane);
439 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info);
440 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info);
441 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv);
442 void intel_encoder_destroy(struct drm_encoder *encoder);
443 struct drm_display_mode *
444 intel_encoder_current_mode(struct intel_encoder *encoder);
445 void intel_encoder_get_config(struct intel_encoder *encoder,
446 struct intel_crtc_state *crtc_state);
447 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy);
448 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy);
449 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy);
450 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv,
452 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
453 struct drm_file *file_priv);
455 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp);
456 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
457 struct intel_digital_port *dig_port,
458 unsigned int expected_mask);
459 struct drm_framebuffer *
460 intel_framebuffer_create(struct drm_i915_gem_object *obj,
461 struct drm_mode_fb_cmd2 *mode_cmd);
463 bool intel_fuzzy_clock_check(int clock1, int clock2);
465 void intel_zero_m_n(struct intel_link_m_n *m_n);
466 void intel_set_m_n(struct drm_i915_private *i915,
467 const struct intel_link_m_n *m_n,
468 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
469 i915_reg_t link_m_reg, i915_reg_t link_n_reg);
470 void intel_get_m_n(struct drm_i915_private *i915,
471 struct intel_link_m_n *m_n,
472 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
473 i915_reg_t link_m_reg, i915_reg_t link_n_reg);
474 bool intel_cpu_transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
475 enum transcoder transcoder);
476 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc,
477 enum transcoder cpu_transcoder,
478 const struct intel_link_m_n *m_n);
479 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc,
480 enum transcoder cpu_transcoder,
481 const struct intel_link_m_n *m_n);
482 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc,
483 enum transcoder cpu_transcoder,
484 struct intel_link_m_n *m_n);
485 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc,
486 enum transcoder cpu_transcoder,
487 struct intel_link_m_n *m_n);
488 void i9xx_crtc_clock_get(struct intel_crtc *crtc,
489 struct intel_crtc_state *pipe_config);
490 int intel_dotclock_calculate(int link_freq, const struct intel_link_m_n *m_n);
491 int intel_crtc_dotclock(const struct intel_crtc_state *pipe_config);
492 enum intel_display_power_domain intel_port_to_power_domain(struct intel_digital_port *dig_port);
493 enum intel_display_power_domain
494 intel_aux_power_domain(struct intel_digital_port *dig_port);
495 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
496 struct intel_crtc_state *crtc_state);
497 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state);
499 int bdw_get_pipe_misc_bpp(struct intel_crtc *crtc);
500 unsigned int intel_plane_fence_y_offset(const struct intel_plane_state *plane_state);
502 bool intel_plane_uses_fence(const struct intel_plane_state *plane_state);
504 struct intel_encoder *
505 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
506 const struct intel_crtc_state *crtc_state);
507 void intel_plane_disable_noatomic(struct intel_crtc *crtc,
508 struct intel_plane *plane);
509 void intel_set_plane_visible(struct intel_crtc_state *crtc_state,
510 struct intel_plane_state *plane_state,
512 void intel_plane_fixup_bitmasks(struct intel_crtc_state *crtc_state);
514 void intel_update_watermarks(struct drm_i915_private *i915);
517 int intel_modeset_pipes_in_mask_early(struct intel_atomic_state *state,
518 const char *reason, u8 pipe_mask);
519 int intel_modeset_all_pipes_late(struct intel_atomic_state *state,
521 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state,
522 struct intel_power_domain_mask *old_domains);
523 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc,
524 struct intel_power_domain_mask *domains);
526 /* interface for intel_display_driver.c */
527 void intel_setup_outputs(struct drm_i915_private *i915);
528 int intel_initial_commit(struct drm_device *dev);
529 void intel_panel_sanitize_ssc(struct drm_i915_private *i915);
530 void intel_update_czclk(struct drm_i915_private *i915);
531 void intel_atomic_helper_free_state_worker(struct work_struct *work);
532 enum drm_mode_status intel_mode_valid(struct drm_device *dev,
533 const struct drm_display_mode *mode);
534 int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *_state,
537 void intel_hpd_poll_fini(struct drm_i915_private *i915);
539 /* modesetting asserts */
540 void assert_transcoder(struct drm_i915_private *dev_priv,
541 enum transcoder cpu_transcoder, bool state);
542 #define assert_transcoder_enabled(d, t) assert_transcoder(d, t, true)
543 #define assert_transcoder_disabled(d, t) assert_transcoder(d, t, false)
545 bool assert_port_valid(struct drm_i915_private *i915, enum port port);
548 * Use I915_STATE_WARN(x) (rather than WARN() and WARN_ON()) for hw state sanity
549 * checks to check for unexpected conditions which may not necessarily be a user
550 * visible problem. This will either WARN() or DRM_ERROR() depending on the
551 * verbose_state_checks module param, to enable distros and users to tailor
552 * their preferred amount of i915 abrt spam.
554 #define I915_STATE_WARN(__i915, condition, format...) ({ \
555 struct drm_device *drm = &(__i915)->drm; \
556 int __ret_warn_on = !!(condition); \
557 if (unlikely(__ret_warn_on)) \
558 if (!drm_WARN(drm, i915_modparams.verbose_state_checks, format)) \
559 drm_err(drm, format); \
560 unlikely(__ret_warn_on); \
563 bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915);