1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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"
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54static bool ivb_can_enable_err_int(struct drm_device *dev)
55{
56 struct drm_i915_private *dev_priv = to_i915(dev);
57 struct intel_crtc *crtc;
58 enum pipe pipe;
59
60 lockdep_assert_held(&dev_priv->irq_lock);
61
62 for_each_pipe(dev_priv, pipe) {
63 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
64
65 if (crtc->cpu_fifo_underrun_disabled)
66 return false;
67 }
68
69 return true;
70}
71
72static bool cpt_can_enable_serr_int(struct drm_device *dev)
73{
74 struct drm_i915_private *dev_priv = to_i915(dev);
75 enum pipe pipe;
76 struct intel_crtc *crtc;
77
78 lockdep_assert_held(&dev_priv->irq_lock);
79
80 for_each_pipe(dev_priv, pipe) {
81 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
82
83 if (crtc->pch_fifo_underrun_disabled)
84 return false;
85 }
86
87 return true;
88}
89
90static void i9xx_check_fifo_underruns(struct intel_crtc *crtc)
91{
92 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
93 i915_reg_t reg = PIPESTAT(crtc->pipe);
94 u32 enable_mask;
95
96 lockdep_assert_held(&dev_priv->irq_lock);
97
98 if ((intel_de_read(dev_priv, reg) & PIPE_FIFO_UNDERRUN_STATUS) == 0)
99 return;
100
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);
104
105 trace_intel_cpu_fifo_underrun(dev_priv, crtc->pipe);
106 drm_err(&dev_priv->drm, "pipe %c underrun\n", pipe_name(crtc->pipe));
107}
108
109static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
110 enum pipe pipe,
111 bool enable, bool old)
112{
113 struct drm_i915_private *dev_priv = to_i915(dev);
114 i915_reg_t reg = PIPESTAT(pipe);
115
116 lockdep_assert_held(&dev_priv->irq_lock);
117
118 if (enable) {
119 u32 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
120
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));
128 }
129}
130
131static void ilk_set_fifo_underrun_reporting(struct drm_device *dev,
132 enum pipe pipe, bool enable)
133{
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;
137
138 if (enable)
139 ilk_enable_display_irq(dev_priv, bit);
140 else
141 ilk_disable_display_irq(dev_priv, bit);
142}
143
144static void ivb_check_fifo_underruns(struct intel_crtc *crtc)
145{
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);
149
150 lockdep_assert_held(&dev_priv->irq_lock);
151
152 if ((err_int & ERR_INT_FIFO_UNDERRUN(pipe)) == 0)
153 return;
154
155 intel_de_write(dev_priv, GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
156 intel_de_posting_read(dev_priv, GEN7_ERR_INT);
157
158 trace_intel_cpu_fifo_underrun(dev_priv, pipe);
159 drm_err(&dev_priv->drm, "fifo underrun on pipe %c\n", pipe_name(pipe));
160}
161
162static void ivb_set_fifo_underrun_reporting(struct drm_device *dev,
163 enum pipe pipe, bool enable,
164 bool old)
165{
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));
170
171 if (!ivb_can_enable_err_int(dev))
172 return;
173
174 ilk_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
175 } else {
176 ilk_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
177
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));
183 }
184 }
185}
186
187static void bdw_set_fifo_underrun_reporting(struct drm_device *dev,
188 enum pipe pipe, bool enable)
189{
190 struct drm_i915_private *dev_priv = to_i915(dev);
191
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);
196}
197
198static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
199 enum pipe pch_transcoder,
200 bool enable)
201{
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;
205
206 if (enable)
207 ibx_enable_display_interrupt(dev_priv, bit);
208 else
209 ibx_disable_display_interrupt(dev_priv, bit);
210}
211
212static void cpt_check_pch_fifo_underruns(struct intel_crtc *crtc)
213{
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);
217
218 lockdep_assert_held(&dev_priv->irq_lock);
219
220 if ((serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) == 0)
221 return;
222
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);
226
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));
230}
231
232static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
233 enum pipe pch_transcoder,
234 bool enable, bool old)
235{
236 struct drm_i915_private *dev_priv = to_i915(dev);
237
238 if (enable) {
239 intel_de_write(dev_priv, SERR_INT,
240 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
241
242 if (!cpt_can_enable_serr_int(dev))
243 return;
244
245 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
246 } else {
247 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
248
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));
254 }
255 }
256}
257
258static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
259 enum pipe pipe, bool enable)
260{
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;
264
265 lockdep_assert_held(&dev_priv->irq_lock);
266
267 old = !crtc->cpu_fifo_underrun_disabled;
268 crtc->cpu_fifo_underrun_disabled = !enable;
269
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);
278
279 return old;
280}
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298bool intel_set_cpu_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
299 enum pipe pipe, bool enable)
300{
301 unsigned long flags;
302 bool ret;
303
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);
308
309 return ret;
310}
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326bool intel_set_pch_fifo_underrun_reporting(struct drm_i915_private *dev_priv,
327 enum pipe pch_transcoder,
328 bool enable)
329{
330 struct intel_crtc *crtc =
331 intel_get_crtc_for_pipe(dev_priv, pch_transcoder);
332 unsigned long flags;
333 bool old;
334
335
336
337
338
339
340
341
342
343
344 spin_lock_irqsave(&dev_priv->irq_lock, flags);
345
346 old = !crtc->pch_fifo_underrun_disabled;
347 crtc->pch_fifo_underrun_disabled = !enable;
348
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);
357
358 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
359 return old;
360}
361
362
363
364
365
366
367
368
369
370
371void intel_cpu_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
372 enum pipe pipe)
373{
374 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
375
376
377 if (crtc == NULL)
378 return;
379
380
381 if (HAS_GMCH(dev_priv) &&
382 crtc->cpu_fifo_underrun_disabled)
383 return;
384
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));
389 }
390
391 intel_fbc_handle_fifo_underrun_irq(dev_priv);
392}
393
394
395
396
397
398
399
400
401
402
403void intel_pch_fifo_underrun_irq_handler(struct drm_i915_private *dev_priv,
404 enum pipe pch_transcoder)
405{
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));
411 }
412}
413
414
415
416
417
418
419
420
421
422
423void intel_check_cpu_fifo_underruns(struct drm_i915_private *dev_priv)
424{
425 struct intel_crtc *crtc;
426
427 spin_lock_irq(&dev_priv->irq_lock);
428
429 for_each_intel_crtc(&dev_priv->drm, crtc) {
430 if (crtc->cpu_fifo_underrun_disabled)
431 continue;
432
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);
437 }
438
439 spin_unlock_irq(&dev_priv->irq_lock);
440}
441
442
443
444
445
446
447
448
449
450void intel_check_pch_fifo_underruns(struct drm_i915_private *dev_priv)
451{
452 struct intel_crtc *crtc;
453
454 spin_lock_irq(&dev_priv->irq_lock);
455
456 for_each_intel_crtc(&dev_priv->drm, crtc) {
457 if (crtc->pch_fifo_underrun_disabled)
458 continue;
459
460 if (HAS_PCH_CPT(dev_priv))
461 cpt_check_pch_fifo_underruns(crtc);
462 }
463
464 spin_unlock_irq(&dev_priv->irq_lock);
465}
466