1 // SPDX-License-Identifier: MIT
3 * Copyright © 2022 Intel Corporation
9 #include "intel_color_regs.h"
11 #include "intel_display_types.h"
12 #include "intel_pcode.h"
14 static void hsw_ips_enable(const struct intel_crtc_state *crtc_state)
16 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
17 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
20 if (!crtc_state->ips_enabled)
24 * We can only enable IPS after we enable a plane and wait for a vblank
25 * This function is called from post_plane_update, which is run after
28 drm_WARN_ON(&i915->drm,
29 !(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
33 if (i915->display.ips.false_color)
34 val |= IPS_FALSE_COLOR;
36 if (IS_BROADWELL(i915)) {
37 drm_WARN_ON(&i915->drm,
38 snb_pcode_write(&i915->uncore, DISPLAY_IPS_CONTROL,
39 val | IPS_PCODE_CONTROL));
41 * Quoting Art Runyan: "its not safe to expect any particular
42 * value in IPS_CTL bit 31 after enabling IPS through the
43 * mailbox." Moreover, the mailbox may return a bogus state,
44 * so we need to just enable it and continue on.
47 intel_de_write(i915, IPS_CTL, val);
49 * The bit only becomes 1 in the next vblank, so this wait here
50 * is essentially intel_wait_for_vblank. If we don't have this
51 * and don't wait for vblanks until the end of crtc_enable, then
52 * the HW state readout code will complain that the expected
53 * IPS_CTL value is not the one we read.
55 if (intel_de_wait_for_set(i915, IPS_CTL, IPS_ENABLE, 50))
57 "Timed out waiting for IPS enable\n");
61 bool hsw_ips_disable(const struct intel_crtc_state *crtc_state)
63 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
64 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
65 bool need_vblank_wait = false;
67 if (!crtc_state->ips_enabled)
68 return need_vblank_wait;
70 if (IS_BROADWELL(i915)) {
71 drm_WARN_ON(&i915->drm,
72 snb_pcode_write(&i915->uncore, DISPLAY_IPS_CONTROL, 0));
74 * Wait for PCODE to finish disabling IPS. The BSpec specified
75 * 42ms timeout value leads to occasional timeouts so use 100ms
78 if (intel_de_wait_for_clear(i915, IPS_CTL, IPS_ENABLE, 100))
80 "Timed out waiting for IPS disable\n");
82 intel_de_write(i915, IPS_CTL, 0);
83 intel_de_posting_read(i915, IPS_CTL);
86 /* We need to wait for a vblank before we can disable the plane. */
87 need_vblank_wait = true;
89 return need_vblank_wait;
92 static bool hsw_ips_need_disable(struct intel_atomic_state *state,
93 struct intel_crtc *crtc)
95 struct drm_i915_private *i915 = to_i915(state->base.dev);
96 const struct intel_crtc_state *old_crtc_state =
97 intel_atomic_get_old_crtc_state(state, crtc);
98 const struct intel_crtc_state *new_crtc_state =
99 intel_atomic_get_new_crtc_state(state, crtc);
101 if (!old_crtc_state->ips_enabled)
104 if (intel_crtc_needs_modeset(new_crtc_state))
108 * Workaround : Do not read or write the pipe palette/gamma data while
109 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
111 * Disable IPS before we program the LUT.
113 if (IS_HASWELL(i915) &&
114 intel_crtc_needs_color_update(new_crtc_state) &&
115 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
118 return !new_crtc_state->ips_enabled;
121 bool hsw_ips_pre_update(struct intel_atomic_state *state,
122 struct intel_crtc *crtc)
124 const struct intel_crtc_state *old_crtc_state =
125 intel_atomic_get_old_crtc_state(state, crtc);
127 if (!hsw_ips_need_disable(state, crtc))
130 return hsw_ips_disable(old_crtc_state);
133 static bool hsw_ips_need_enable(struct intel_atomic_state *state,
134 struct intel_crtc *crtc)
136 struct drm_i915_private *i915 = to_i915(state->base.dev);
137 const struct intel_crtc_state *old_crtc_state =
138 intel_atomic_get_old_crtc_state(state, crtc);
139 const struct intel_crtc_state *new_crtc_state =
140 intel_atomic_get_new_crtc_state(state, crtc);
142 if (!new_crtc_state->ips_enabled)
145 if (intel_crtc_needs_modeset(new_crtc_state))
149 * Workaround : Do not read or write the pipe palette/gamma data while
150 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
152 * Re-enable IPS after the LUT has been programmed.
154 if (IS_HASWELL(i915) &&
155 intel_crtc_needs_color_update(new_crtc_state) &&
156 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
160 * We can't read out IPS on broadwell, assume the worst and
161 * forcibly enable IPS on the first fastset.
163 if (intel_crtc_needs_fastset(new_crtc_state) && old_crtc_state->inherited)
166 return !old_crtc_state->ips_enabled;
169 void hsw_ips_post_update(struct intel_atomic_state *state,
170 struct intel_crtc *crtc)
172 const struct intel_crtc_state *new_crtc_state =
173 intel_atomic_get_new_crtc_state(state, crtc);
175 if (!hsw_ips_need_enable(state, crtc))
178 hsw_ips_enable(new_crtc_state);
181 /* IPS only exists on ULT machines and is tied to pipe A. */
182 bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
184 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
187 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
189 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
190 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
192 /* IPS only exists on ULT machines and is tied to pipe A. */
193 if (!hsw_crtc_supports_ips(crtc))
196 if (!i915->display.params.enable_ips)
199 if (crtc_state->pipe_bpp > 24)
203 * We compare against max which means we must take
204 * the increased cdclk requirement into account when
205 * calculating the new cdclk.
207 * Should measure whether using a lower cdclk w/o IPS
209 if (IS_BROADWELL(i915) &&
210 crtc_state->pixel_rate > i915->display.cdclk.max_cdclk_freq * 95 / 100)
216 int hsw_ips_compute_config(struct intel_atomic_state *state,
217 struct intel_crtc *crtc)
219 struct drm_i915_private *i915 = to_i915(state->base.dev);
220 struct intel_crtc_state *crtc_state =
221 intel_atomic_get_new_crtc_state(state, crtc);
223 crtc_state->ips_enabled = false;
225 if (!hsw_crtc_state_ips_capable(crtc_state))
229 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
230 * enabled and disabled dynamically based on package C states,
231 * user space can't make reliable use of the CRCs, so let's just
232 * completely disable it.
234 if (crtc_state->crc_enabled)
237 /* IPS should be fine as long as at least one plane is enabled. */
238 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
241 if (IS_BROADWELL(i915)) {
242 const struct intel_cdclk_state *cdclk_state;
244 cdclk_state = intel_atomic_get_cdclk_state(state);
245 if (IS_ERR(cdclk_state))
246 return PTR_ERR(cdclk_state);
248 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
249 if (crtc_state->pixel_rate > cdclk_state->logical.cdclk * 95 / 100)
253 crtc_state->ips_enabled = true;
258 void hsw_ips_get_config(struct intel_crtc_state *crtc_state)
260 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
261 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
263 if (!hsw_crtc_supports_ips(crtc))
266 if (IS_HASWELL(i915)) {
267 crtc_state->ips_enabled = intel_de_read(i915, IPS_CTL) & IPS_ENABLE;
270 * We cannot readout IPS state on broadwell, set to
271 * true so we can set it to a defined state on first
274 crtc_state->ips_enabled = true;
278 static int hsw_ips_debugfs_false_color_get(void *data, u64 *val)
280 struct intel_crtc *crtc = data;
281 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
283 *val = i915->display.ips.false_color;
288 static int hsw_ips_debugfs_false_color_set(void *data, u64 val)
290 struct intel_crtc *crtc = data;
291 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
292 struct intel_crtc_state *crtc_state;
295 ret = drm_modeset_lock(&crtc->base.mutex, NULL);
299 i915->display.ips.false_color = val;
301 crtc_state = to_intel_crtc_state(crtc->base.state);
303 if (!crtc_state->hw.active)
306 if (crtc_state->uapi.commit &&
307 !try_wait_for_completion(&crtc_state->uapi.commit->hw_done))
310 hsw_ips_enable(crtc_state);
313 drm_modeset_unlock(&crtc->base.mutex);
318 DEFINE_DEBUGFS_ATTRIBUTE(hsw_ips_debugfs_false_color_fops,
319 hsw_ips_debugfs_false_color_get,
320 hsw_ips_debugfs_false_color_set,
323 static int hsw_ips_debugfs_status_show(struct seq_file *m, void *unused)
325 struct intel_crtc *crtc = m->private;
326 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
327 intel_wakeref_t wakeref;
329 wakeref = intel_runtime_pm_get(&i915->runtime_pm);
331 seq_printf(m, "Enabled by kernel parameter: %s\n",
332 str_yes_no(i915->display.params.enable_ips));
334 if (DISPLAY_VER(i915) >= 8) {
335 seq_puts(m, "Currently: unknown\n");
337 if (intel_de_read(i915, IPS_CTL) & IPS_ENABLE)
338 seq_puts(m, "Currently: enabled\n");
340 seq_puts(m, "Currently: disabled\n");
343 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
348 DEFINE_SHOW_ATTRIBUTE(hsw_ips_debugfs_status);
350 void hsw_ips_crtc_debugfs_add(struct intel_crtc *crtc)
352 if (!hsw_crtc_supports_ips(crtc))
355 debugfs_create_file("i915_ips_false_color", 0644, crtc->base.debugfs_entry,
356 crtc, &hsw_ips_debugfs_false_color_fops);
358 debugfs_create_file("i915_ips_status", 0444, crtc->base.debugfs_entry,
359 crtc, &hsw_ips_debugfs_status_fops);