Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / display / intel_fifo_underrun.c
blob813a4f7033e1c108de91ccb57b40108976d4e24a
1 /*
2 * Copyright © 2014 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
13 * Software.
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
21 * IN THE SOFTWARE.
23 * Authors:
24 * Daniel Vetter <daniel.vetter@ffwll.ch>
28 #include "i915_drv.h"
29 #include "i915_trace.h"
30 #include "intel_display_types.h"
31 #include "intel_fbc.h"
32 #include "intel_fifo_underrun.h"
34 /**
35 * DOC: fifo underrun handling
37 * The i915 driver checks for display fifo underruns using the interrupt signals
38 * provided by the hardware. This is enabled by default and fairly useful to
39 * debug display issues, especially watermark settings.
41 * If an underrun is detected this is logged into dmesg. To avoid flooding logs
42 * and occupying the cpu underrun interrupts are disabled after the first
43 * occurrence until the next modeset on a given pipe.
45 * Note that underrun detection on gmch platforms is a bit more ugly since there
46 * is no interrupt (despite that the signalling bit is in the PIPESTAT pipe
47 * interrupt register). Also on some other platforms underrun interrupts are
48 * shared, which means that if we detect an underrun we need to disable underrun
49 * reporting on all pipes.
51 * The code also supports underrun detection on the PCH transcoder.
54 static bool ivb_can_enable_err_int(struct drm_device *dev)
56 struct drm_i915_private *dev_priv = to_i915(dev);
57 struct intel_crtc *crtc;
58 enum pipe pipe;
60 lockdep_assert_held(&dev_priv->irq_lock);
62 for_each_pipe(dev_priv, pipe) {
63 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
65 if (crtc->cpu_fifo_underrun_disabled)
66 return false;
69 return true;
72 static bool cpt_can_enable_serr_int(struct drm_device *dev)
74 struct drm_i915_private *dev_priv = to_i915(dev);
75 enum pipe pipe;
76 struct intel_crtc *crtc;
78 lockdep_assert_held(&dev_priv->irq_lock);
80 for_each_pipe(dev_priv, pipe) {
81 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
83 if (crtc->pch_fifo_underrun_disabled)
84 return false;
87 return true;
90 static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
92 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
93 i915_reg_t reg = PIPESTAT(crtc->pipe);
94 u32 enable_mask;
96 lockdep_assert_held(&dev_priv->irq_lock);
98 if ((intel_de_read(dev_priv, reg) & PIPE_FIFO_UNDERRUN_STATUS) == 0)
99 return;
101 enable_mask = i915_pipestat_enable_mask(dev_priv, crtc->pipe);
102 intel_de_write(dev_priv, reg, enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
103 intel_de_posting_read(dev_priv, reg);
105 trace_intel_cpu_fifo_underrun(dev_priv, crtc->pipe);
106 drm_err(&dev_priv->drm, "pipe %c underrun\n", pipe_name(crtc->pipe));
109 static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
110 enum pipe pipe,
111 bool enable, bool old)
113 struct drm_i915_private *dev_priv = to_i915(dev);
114 i915_reg_t reg = PIPESTAT(pipe);
116 lockdep_assert_held(&dev_priv->irq_lock);
118 if (enable) {
119 u32 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
121 intel_de_write(dev_priv, reg,
122 enable_mask | PIPE_FIFO_UNDERRUN_STATUS);
123 intel_de_posting_read(dev_priv, reg);
124 } else {
125 if (old && intel_de_read(dev_priv, reg) & PIPE_FIFO_UNDERRUN_STATUS)
126 drm_err(&dev_priv->drm, "pipe %c underrun\n",
127 pipe_name(pipe));
131 static void ilk_set_fifo_underrun_reporting(struct drm_device *dev,
132 enum pipe pipe, bool enable)
134 struct drm_i915_private *dev_priv = to_i915(dev);
135 u32 bit = (pipe == PIPE_A) ?
136 DE_PIPEA_FIFO_UNDERRUN : DE_PIPEB_FIFO_UNDERRUN;
138 if (enable)
139 ilk_enable_display_irq(dev_priv, bit);
140 else
141 ilk_disable_display_irq(dev_priv, bit);
144 static void ivb_check_fifo_underruns(struct intel_crtc *crtc)
146 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
147 enum pipe pipe = crtc->pipe;
148 u32 err_int = intel_de_read(dev_priv, GEN7_ERR_INT);
150 lockdep_assert_held(&dev_priv->irq_lock);
152 if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
153 return;
155 intel_de_write(dev_priv, GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
156 intel_de_posting_read(dev_priv, GEN7_ERR_INT);
158 trace_intel_cpu_fifo_underrun(dev_priv, pipe);
159 drm_err(&dev_priv->drm, "fifo underrun on pipe %c\n", pipe_name(pipe));
162 static void ivb_set_fifo_underrun_reporting(struct drm_device *dev,
163 enum pipe pipe, bool enable,
164 bool old)
166 struct drm_i915_private *dev_priv = to_i915(dev);
167 if (enable) {
168 intel_de_write(dev_priv, GEN7_ERR_INT,
169 ERR_INT_FIFO_UNDERRUN(pipe));
171 if (!ivb_can_enable_err_int(dev))
172 return;
174 ilk_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
175 } else {
176 ilk_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
178 if (old &&
179 intel_de_read(dev_priv, GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
180 drm_err(&dev_priv->drm,
181 "uncleared fifo underrun on pipe %c\n",
182 pipe_name(pipe));
187 static void bdw_set_fifo_underrun_reporting(struct drm_device *dev,
188 enum pipe pipe, bool enable)
190 struct drm_i915_private *dev_priv = to_i915(dev);
192 if (enable)
193 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_FIFO_UNDERRUN);
194 else
195 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_FIFO_UNDERRUN);
198 static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
199 enum pipe pch_transcoder,
200 bool enable)
202 struct drm_i915_private *dev_priv = to_i915(dev);
203 u32 bit = (pch_transcoder == PIPE_A) ?
204 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
206 if (enable)
207 ibx_enable_display_interrupt(dev_priv, bit);
208 else
209 ibx_disable_display_interrupt(dev_priv, bit);
212 static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
214 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
215 enum pipe pch_transcoder = crtc->pipe;
216 u32 serr_int = intel_de_read(dev_priv, SERR_INT);
218 lockdep_assert_held(&dev_priv->irq_lock);
220 if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
221 return;
223 intel_de_write(dev_priv, SERR_INT,
224 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
225 intel_de_posting_read(dev_priv, SERR_INT);
227 trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
228 drm_err(&dev_priv->drm, "pch fifo underrun on pch transcoder %c\n",
229 pipe_name(pch_transcoder));
232 static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
233 enum pipe pch_transcoder,
234 bool enable, bool old)
236 struct drm_i915_private *dev_priv = to_i915(dev);
238 if (enable) {
239 intel_de_write(dev_priv, SERR_INT,
240 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
242 if (!cpt_can_enable_serr_int(dev))
243 return;
245 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
246 } else {
247 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
249 if (old && intel_de_read(dev_priv, SERR_INT) &
250 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
251 drm_err(&dev_priv->drm,
252 "uncleared pch fifo underrun on pch transcoder %c\n",
253 pipe_name(pch_transcoder));
258 static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
259 enum pipe pipe, bool enable)
261 struct drm_i915_private *dev_priv = to_i915(dev);
262 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
263 bool old;
265 lockdep_assert_held(&dev_priv->irq_lock);
267 old = !crtc->cpu_fifo_underrun_disabled;
268 crtc->cpu_fifo_underrun_disabled = !enable;
270 if (HAS_GMCH(dev_priv))
271 i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
272 else if (IS_GEN_RANGE(dev_priv, 5, 6))
273 ilk_set_fifo_underrun_reporting(dev, pipe, enable);
274 else if (IS_GEN(dev_priv, 7))
275 ivb_set_fifo_underrun_reporting(dev, pipe, enable, old);
276 else if (INTEL_GEN(dev_priv) >= 8)
277 bdw_set_fifo_underrun_reporting(dev, pipe, enable);
279 return old;
283 * intel_set_cpu_fifo_underrun_reporting - set cpu fifo underrrun reporting state
284 * @dev_priv: i915 device instance
285 * @pipe: (CPU) pipe to set state for
286 * @enable: whether underruns should be reported or not
288 * This function sets the fifo underrun state for @pipe. It is used in the
289 * modeset code to avoid false positives since on many platforms underruns are
290 * expected when disabling or enabling the pipe.
292 * Notice that on some platforms disabling underrun reports for one pipe
293 * disables for all due to shared interrupts. Actual reporting is still per-pipe
294 * though.
296 * Returns the previous state of underrun reporting.
298 bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
299 enum pipe pipe, bool enable)
301 unsigned long flags;
302 bool ret;
304 spin_lock_irqsave(&dev_priv->irq_lock, flags);
305 ret = __intel_set_cpu_fifo_underrun_reporting(&dev_priv->drm, pipe,
306 enable);
307 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
309 return ret;
313 * intel_set_pch_fifo_underrun_reporting - set PCH fifo underrun reporting state
314 * @dev_priv: i915 device instance
315 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
316 * @enable: whether underruns should be reported or not
318 * This function makes us disable or enable PCH fifo underruns for a specific
319 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
320 * underrun reporting for one transcoder may also disable all the other PCH
321 * error interruts for the other transcoders, due to the fact that there's just
322 * one interrupt mask/enable bit for all the transcoders.
324 * Returns the previous state of underrun reporting.
326 bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
327 enum pipe pch_transcoder,
328 bool enable)
330 struct intel_crtc *crtc =
331 intel_get_crtc_for_pipe(dev_priv, pch_transcoder);
332 unsigned long flags;
333 bool old;
336 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
337 * has only one pch transcoder A that all pipes can use. To avoid racy
338 * pch transcoder -> pipe lookups from interrupt code simply store the
339 * underrun statistics in crtc A. Since we never expose this anywhere
340 * nor use it outside of the fifo underrun code here using the "wrong"
341 * crtc on LPT won't cause issues.
344 spin_lock_irqsave(&dev_priv->irq_lock, flags);
346 old = !crtc->pch_fifo_underrun_disabled;
347 crtc->pch_fifo_underrun_disabled = !enable;
349 if (HAS_PCH_IBX(dev_priv))
350 ibx_set_fifo_underrun_reporting(&dev_priv->drm,
351 pch_transcoder,
352 enable);
353 else
354 cpt_set_fifo_underrun_reporting(&dev_priv->drm,
355 pch_transcoder,
356 enable, old);
358 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
359 return old;
363 * intel_cpu_fifo_underrun_irq_handler - handle CPU fifo underrun interrupt
364 * @dev_priv: i915 device instance
365 * @pipe: (CPU) pipe to set state for
367 * This handles a CPU fifo underrun interrupt, generating an underrun warning
368 * into dmesg if underrun reporting is enabled and then disables the underrun
369 * interrupt to avoid an irq storm.
371 void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
372 enum pipe pipe)
374 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
376 /* We may be called too early in init, thanks BIOS! */
377 if (crtc == NULL)
378 return;
380 /* GMCH can't disable fifo underruns, filter them. */
381 if (HAS_GMCH(dev_priv) &&
382 crtc->cpu_fifo_underrun_disabled)
383 return;
385 if (intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false)) {
386 trace_intel_cpu_fifo_underrun(dev_priv, pipe);
387 drm_err(&dev_priv->drm, "CPU pipe %c FIFO underrun\n",
388 pipe_name(pipe));
391 intel_fbc_handle_fifo_underrun_irq(dev_priv);
395 * intel_pch_fifo_underrun_irq_handler - handle PCH fifo underrun interrupt
396 * @dev_priv: i915 device instance
397 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
399 * This handles a PCH fifo underrun interrupt, generating an underrun warning
400 * into dmesg if underrun reporting is enabled and then disables the underrun
401 * interrupt to avoid an irq storm.
403 void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
404 enum pipe pch_transcoder)
406 if (intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder,
407 false)) {
408 trace_intel_pch_fifo_underrun(dev_priv, pch_transcoder);
409 drm_err(&dev_priv->drm, "PCH transcoder %c FIFO underrun\n",
410 pipe_name(pch_transcoder));
415 * intel_check_cpu_fifo_underruns - check for CPU fifo underruns immediately
416 * @dev_priv: i915 device instance
418 * Check for CPU fifo underruns immediately. Useful on IVB/HSW where the shared
419 * error interrupt may have been disabled, and so CPU fifo underruns won't
420 * necessarily raise an interrupt, and on GMCH platforms where underruns never
421 * raise an interrupt.
423 void intel_check_cpu_fifo_underruns(struct drm_i915_private *dev_priv)
425 struct intel_crtc *crtc;
427 spin_lock_irq(&dev_priv->irq_lock);
429 for_each_intel_crtc(&dev_priv->drm, crtc) {
430 if (crtc->cpu_fifo_underrun_disabled)
431 continue;
433 if (HAS_GMCH(dev_priv))
434 i9xx_check_fifo_underruns(crtc);
435 else if (IS_GEN(dev_priv, 7))
436 ivb_check_fifo_underruns(crtc);
439 spin_unlock_irq(&dev_priv->irq_lock);
443 * intel_check_pch_fifo_underruns - check for PCH fifo underruns immediately
444 * @dev_priv: i915 device instance
446 * Check for PCH fifo underruns immediately. Useful on CPT/PPT where the shared
447 * error interrupt may have been disabled, and so PCH fifo underruns won't
448 * necessarily raise an interrupt.
450 void intel_check_pch_fifo_underruns(struct drm_i915_private *dev_priv)
452 struct intel_crtc *crtc;
454 spin_lock_irq(&dev_priv->irq_lock);
456 for_each_intel_crtc(&dev_priv->drm, crtc) {
457 if (crtc->pch_fifo_underrun_disabled)
458 continue;
460 if (HAS_PCH_CPT(dev_priv))
461 cpt_check_pch_fifo_underruns(crtc);
464 spin_unlock_irq(&dev_priv->irq_lock);