1 // SPDX-License-Identifier: MIT
3 * Copyright © 2022 Intel Corporation
10 #include "intel_display_types.h"
11 #include "intel_pcode.h"
13 static void hsw_ips_enable(const struct intel_crtc_state *crtc_state)
15 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
16 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
19 if (!crtc_state->ips_enabled)
23 * We can only enable IPS after we enable a plane and wait for a vblank
24 * This function is called from post_plane_update, which is run after
27 drm_WARN_ON(&i915->drm,
28 !(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
32 if (i915->display.ips.false_color)
33 val |= IPS_FALSE_COLOR;
35 if (IS_BROADWELL(i915)) {
36 drm_WARN_ON(&i915->drm,
37 snb_pcode_write(&i915->uncore, DISPLAY_IPS_CONTROL,
38 val | IPS_PCODE_CONTROL));
40 * Quoting Art Runyan: "its not safe to expect any particular
41 * value in IPS_CTL bit 31 after enabling IPS through the
42 * mailbox." Moreover, the mailbox may return a bogus state,
43 * so we need to just enable it and continue on.
46 intel_de_write(i915, IPS_CTL, val);
48 * The bit only becomes 1 in the next vblank, so this wait here
49 * is essentially intel_wait_for_vblank. If we don't have this
50 * and don't wait for vblanks until the end of crtc_enable, then
51 * the HW state readout code will complain that the expected
52 * IPS_CTL value is not the one we read.
54 if (intel_de_wait_for_set(i915, IPS_CTL, IPS_ENABLE, 50))
56 "Timed out waiting for IPS enable\n");
60 bool hsw_ips_disable(const struct intel_crtc_state *crtc_state)
62 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
63 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
64 bool need_vblank_wait = false;
66 if (!crtc_state->ips_enabled)
67 return need_vblank_wait;
69 if (IS_BROADWELL(i915)) {
70 drm_WARN_ON(&i915->drm,
71 snb_pcode_write(&i915->uncore, DISPLAY_IPS_CONTROL, 0));
73 * Wait for PCODE to finish disabling IPS. The BSpec specified
74 * 42ms timeout value leads to occasional timeouts so use 100ms
77 if (intel_de_wait_for_clear(i915, IPS_CTL, IPS_ENABLE, 100))
79 "Timed out waiting for IPS disable\n");
81 intel_de_write(i915, IPS_CTL, 0);
82 intel_de_posting_read(i915, IPS_CTL);
85 /* We need to wait for a vblank before we can disable the plane. */
86 need_vblank_wait = true;
88 return need_vblank_wait;
91 static bool hsw_ips_need_disable(struct intel_atomic_state *state,
92 struct intel_crtc *crtc)
94 struct drm_i915_private *i915 = to_i915(state->base.dev);
95 const struct intel_crtc_state *old_crtc_state =
96 intel_atomic_get_old_crtc_state(state, crtc);
97 const struct intel_crtc_state *new_crtc_state =
98 intel_atomic_get_new_crtc_state(state, crtc);
100 if (!old_crtc_state->ips_enabled)
103 if (intel_crtc_needs_modeset(new_crtc_state))
107 * Workaround : Do not read or write the pipe palette/gamma data while
108 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
110 * Disable IPS before we program the LUT.
112 if (IS_HASWELL(i915) &&
113 intel_crtc_needs_color_update(new_crtc_state) &&
114 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
117 return !new_crtc_state->ips_enabled;
120 bool hsw_ips_pre_update(struct intel_atomic_state *state,
121 struct intel_crtc *crtc)
123 const struct intel_crtc_state *old_crtc_state =
124 intel_atomic_get_old_crtc_state(state, crtc);
126 if (!hsw_ips_need_disable(state, crtc))
129 return hsw_ips_disable(old_crtc_state);
132 static bool hsw_ips_need_enable(struct intel_atomic_state *state,
133 struct intel_crtc *crtc)
135 struct drm_i915_private *i915 = to_i915(state->base.dev);
136 const struct intel_crtc_state *old_crtc_state =
137 intel_atomic_get_old_crtc_state(state, crtc);
138 const struct intel_crtc_state *new_crtc_state =
139 intel_atomic_get_new_crtc_state(state, crtc);
141 if (!new_crtc_state->ips_enabled)
144 if (intel_crtc_needs_modeset(new_crtc_state))
148 * Workaround : Do not read or write the pipe palette/gamma data while
149 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
151 * Re-enable IPS after the LUT has been programmed.
153 if (IS_HASWELL(i915) &&
154 intel_crtc_needs_color_update(new_crtc_state) &&
155 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
159 * We can't read out IPS on broadwell, assume the worst and
160 * forcibly enable IPS on the first fastset.
162 if (intel_crtc_needs_fastset(new_crtc_state) && old_crtc_state->inherited)
165 return !old_crtc_state->ips_enabled;
168 void hsw_ips_post_update(struct intel_atomic_state *state,
169 struct intel_crtc *crtc)
171 const struct intel_crtc_state *new_crtc_state =
172 intel_atomic_get_new_crtc_state(state, crtc);
174 if (!hsw_ips_need_enable(state, crtc))
177 hsw_ips_enable(new_crtc_state);
180 /* IPS only exists on ULT machines and is tied to pipe A. */
181 bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
183 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
186 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
188 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
189 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
191 /* IPS only exists on ULT machines and is tied to pipe A. */
192 if (!hsw_crtc_supports_ips(crtc))
195 if (!i915->params.enable_ips)
198 if (crtc_state->pipe_bpp > 24)
202 * We compare against max which means we must take
203 * the increased cdclk requirement into account when
204 * calculating the new cdclk.
206 * Should measure whether using a lower cdclk w/o IPS
208 if (IS_BROADWELL(i915) &&
209 crtc_state->pixel_rate > i915->display.cdclk.max_cdclk_freq * 95 / 100)
215 int hsw_ips_compute_config(struct intel_atomic_state *state,
216 struct intel_crtc *crtc)
218 struct drm_i915_private *i915 = to_i915(state->base.dev);
219 struct intel_crtc_state *crtc_state =
220 intel_atomic_get_new_crtc_state(state, crtc);
222 crtc_state->ips_enabled = false;
224 if (!hsw_crtc_state_ips_capable(crtc_state))
228 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
229 * enabled and disabled dynamically based on package C states,
230 * user space can't make reliable use of the CRCs, so let's just
231 * completely disable it.
233 if (crtc_state->crc_enabled)
236 /* IPS should be fine as long as at least one plane is enabled. */
237 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
240 if (IS_BROADWELL(i915)) {
241 const struct intel_cdclk_state *cdclk_state;
243 cdclk_state = intel_atomic_get_cdclk_state(state);
244 if (IS_ERR(cdclk_state))
245 return PTR_ERR(cdclk_state);
247 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
248 if (crtc_state->pixel_rate > cdclk_state->logical.cdclk * 95 / 100)
252 crtc_state->ips_enabled = true;
257 void hsw_ips_get_config(struct intel_crtc_state *crtc_state)
259 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
260 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
262 if (!hsw_crtc_supports_ips(crtc))
265 if (IS_HASWELL(i915)) {
266 crtc_state->ips_enabled = intel_de_read(i915, IPS_CTL) & IPS_ENABLE;
269 * We cannot readout IPS state on broadwell, set to
270 * true so we can set it to a defined state on first
273 crtc_state->ips_enabled = true;
277 static int hsw_ips_debugfs_false_color_get(void *data, u64 *val)
279 struct intel_crtc *crtc = data;
280 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
282 *val = i915->display.ips.false_color;
287 static int hsw_ips_debugfs_false_color_set(void *data, u64 val)
289 struct intel_crtc *crtc = data;
290 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
291 struct intel_crtc_state *crtc_state;
294 ret = drm_modeset_lock(&crtc->base.mutex, NULL);
298 i915->display.ips.false_color = val;
300 crtc_state = to_intel_crtc_state(crtc->base.state);
302 if (!crtc_state->hw.active)
305 if (crtc_state->uapi.commit &&
306 !try_wait_for_completion(&crtc_state->uapi.commit->hw_done))
309 hsw_ips_enable(crtc_state);
312 drm_modeset_unlock(&crtc->base.mutex);
317 DEFINE_DEBUGFS_ATTRIBUTE(hsw_ips_debugfs_false_color_fops,
318 hsw_ips_debugfs_false_color_get,
319 hsw_ips_debugfs_false_color_set,
322 static int hsw_ips_debugfs_status_show(struct seq_file *m, void *unused)
324 struct intel_crtc *crtc = m->private;
325 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
326 intel_wakeref_t wakeref;
328 wakeref = intel_runtime_pm_get(&i915->runtime_pm);
330 seq_printf(m, "Enabled by kernel parameter: %s\n",
331 str_yes_no(i915->params.enable_ips));
333 if (DISPLAY_VER(i915) >= 8) {
334 seq_puts(m, "Currently: unknown\n");
336 if (intel_de_read(i915, IPS_CTL) & IPS_ENABLE)
337 seq_puts(m, "Currently: enabled\n");
339 seq_puts(m, "Currently: disabled\n");
342 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
347 DEFINE_SHOW_ATTRIBUTE(hsw_ips_debugfs_status);
349 void hsw_ips_crtc_debugfs_add(struct intel_crtc *crtc)
351 if (!hsw_crtc_supports_ips(crtc))
354 debugfs_create_file("i915_ips_false_color", 0644, crtc->base.debugfs_entry,
355 crtc, &hsw_ips_debugfs_false_color_fops);
357 debugfs_create_file("i915_ips_status", 0444, crtc->base.debugfs_entry,
358 crtc, &hsw_ips_debugfs_status_fops);