]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/gpu/drm/i915/i915_irq.c
drm/i915: Update DRIVER_DATE to 20150928
[mirror_ubuntu-zesty-kernel.git] / drivers / gpu / drm / i915 / i915_irq.c
1 /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
2 */
3 /*
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 */
28
29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
31 #include <linux/sysrq.h>
32 #include <linux/slab.h>
33 #include <linux/circ_buf.h>
34 #include <drm/drmP.h>
35 #include <drm/i915_drm.h>
36 #include "i915_drv.h"
37 #include "i915_trace.h"
38 #include "intel_drv.h"
39
40 /**
41 * DOC: interrupt handling
42 *
43 * These functions provide the basic support for enabling and disabling the
44 * interrupt handling support. There's a lot more functionality in i915_irq.c
45 * and related files, but that will be described in separate chapters.
46 */
47
48 static const u32 hpd_ilk[HPD_NUM_PINS] = {
49 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
50 };
51
52 static const u32 hpd_ivb[HPD_NUM_PINS] = {
53 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
54 };
55
56 static const u32 hpd_bdw[HPD_NUM_PINS] = {
57 [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG,
58 };
59
60 static const u32 hpd_ibx[HPD_NUM_PINS] = {
61 [HPD_CRT] = SDE_CRT_HOTPLUG,
62 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
63 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
64 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
65 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
66 };
67
68 static const u32 hpd_cpt[HPD_NUM_PINS] = {
69 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
70 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
71 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
72 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
73 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
74 };
75
76 static const u32 hpd_spt[HPD_NUM_PINS] = {
77 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
78 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
79 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
80 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
81 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT
82 };
83
84 static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
85 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
86 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
87 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
88 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
89 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
90 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
91 };
92
93 static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
94 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
95 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
96 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
97 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
98 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
99 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
100 };
101
102 static const u32 hpd_status_i915[HPD_NUM_PINS] = {
103 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
104 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
105 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
106 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
107 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
108 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
109 };
110
111 /* BXT hpd list */
112 static const u32 hpd_bxt[HPD_NUM_PINS] = {
113 [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA,
114 [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB,
115 [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC
116 };
117
118 /* IIR can theoretically queue up two events. Be paranoid. */
119 #define GEN8_IRQ_RESET_NDX(type, which) do { \
120 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
121 POSTING_READ(GEN8_##type##_IMR(which)); \
122 I915_WRITE(GEN8_##type##_IER(which), 0); \
123 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
124 POSTING_READ(GEN8_##type##_IIR(which)); \
125 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
126 POSTING_READ(GEN8_##type##_IIR(which)); \
127 } while (0)
128
129 #define GEN5_IRQ_RESET(type) do { \
130 I915_WRITE(type##IMR, 0xffffffff); \
131 POSTING_READ(type##IMR); \
132 I915_WRITE(type##IER, 0); \
133 I915_WRITE(type##IIR, 0xffffffff); \
134 POSTING_READ(type##IIR); \
135 I915_WRITE(type##IIR, 0xffffffff); \
136 POSTING_READ(type##IIR); \
137 } while (0)
138
139 /*
140 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
141 */
142 #define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \
143 u32 val = I915_READ(reg); \
144 if (val) { \
145 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \
146 (reg), val); \
147 I915_WRITE((reg), 0xffffffff); \
148 POSTING_READ(reg); \
149 I915_WRITE((reg), 0xffffffff); \
150 POSTING_READ(reg); \
151 } \
152 } while (0)
153
154 #define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
155 GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \
156 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
157 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
158 POSTING_READ(GEN8_##type##_IMR(which)); \
159 } while (0)
160
161 #define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
162 GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \
163 I915_WRITE(type##IER, (ier_val)); \
164 I915_WRITE(type##IMR, (imr_val)); \
165 POSTING_READ(type##IMR); \
166 } while (0)
167
168 static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
169
170 /* For display hotplug interrupt */
171 static inline void
172 i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
173 uint32_t mask,
174 uint32_t bits)
175 {
176 uint32_t val;
177
178 assert_spin_locked(&dev_priv->irq_lock);
179 WARN_ON(bits & ~mask);
180
181 val = I915_READ(PORT_HOTPLUG_EN);
182 val &= ~mask;
183 val |= bits;
184 I915_WRITE(PORT_HOTPLUG_EN, val);
185 }
186
187 /**
188 * i915_hotplug_interrupt_update - update hotplug interrupt enable
189 * @dev_priv: driver private
190 * @mask: bits to update
191 * @bits: bits to enable
192 * NOTE: the HPD enable bits are modified both inside and outside
193 * of an interrupt context. To avoid that read-modify-write cycles
194 * interfer, these bits are protected by a spinlock. Since this
195 * function is usually not called from a context where the lock is
196 * held already, this function acquires the lock itself. A non-locking
197 * version is also available.
198 */
199 void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
200 uint32_t mask,
201 uint32_t bits)
202 {
203 spin_lock_irq(&dev_priv->irq_lock);
204 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
205 spin_unlock_irq(&dev_priv->irq_lock);
206 }
207
208 /**
209 * ilk_update_display_irq - update DEIMR
210 * @dev_priv: driver private
211 * @interrupt_mask: mask of interrupt bits to update
212 * @enabled_irq_mask: mask of interrupt bits to enable
213 */
214 static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
215 uint32_t interrupt_mask,
216 uint32_t enabled_irq_mask)
217 {
218 uint32_t new_val;
219
220 assert_spin_locked(&dev_priv->irq_lock);
221
222 WARN_ON(enabled_irq_mask & ~interrupt_mask);
223
224 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
225 return;
226
227 new_val = dev_priv->irq_mask;
228 new_val &= ~interrupt_mask;
229 new_val |= (~enabled_irq_mask & interrupt_mask);
230
231 if (new_val != dev_priv->irq_mask) {
232 dev_priv->irq_mask = new_val;
233 I915_WRITE(DEIMR, dev_priv->irq_mask);
234 POSTING_READ(DEIMR);
235 }
236 }
237
238 void
239 ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
240 {
241 ilk_update_display_irq(dev_priv, mask, mask);
242 }
243
244 void
245 ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
246 {
247 ilk_update_display_irq(dev_priv, mask, 0);
248 }
249
250 /**
251 * ilk_update_gt_irq - update GTIMR
252 * @dev_priv: driver private
253 * @interrupt_mask: mask of interrupt bits to update
254 * @enabled_irq_mask: mask of interrupt bits to enable
255 */
256 static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
257 uint32_t interrupt_mask,
258 uint32_t enabled_irq_mask)
259 {
260 assert_spin_locked(&dev_priv->irq_lock);
261
262 WARN_ON(enabled_irq_mask & ~interrupt_mask);
263
264 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
265 return;
266
267 dev_priv->gt_irq_mask &= ~interrupt_mask;
268 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
269 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
270 POSTING_READ(GTIMR);
271 }
272
273 void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
274 {
275 ilk_update_gt_irq(dev_priv, mask, mask);
276 }
277
278 void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
279 {
280 ilk_update_gt_irq(dev_priv, mask, 0);
281 }
282
283 static u32 gen6_pm_iir(struct drm_i915_private *dev_priv)
284 {
285 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
286 }
287
288 static u32 gen6_pm_imr(struct drm_i915_private *dev_priv)
289 {
290 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
291 }
292
293 static u32 gen6_pm_ier(struct drm_i915_private *dev_priv)
294 {
295 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
296 }
297
298 /**
299 * snb_update_pm_irq - update GEN6_PMIMR
300 * @dev_priv: driver private
301 * @interrupt_mask: mask of interrupt bits to update
302 * @enabled_irq_mask: mask of interrupt bits to enable
303 */
304 static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
305 uint32_t interrupt_mask,
306 uint32_t enabled_irq_mask)
307 {
308 uint32_t new_val;
309
310 WARN_ON(enabled_irq_mask & ~interrupt_mask);
311
312 assert_spin_locked(&dev_priv->irq_lock);
313
314 new_val = dev_priv->pm_irq_mask;
315 new_val &= ~interrupt_mask;
316 new_val |= (~enabled_irq_mask & interrupt_mask);
317
318 if (new_val != dev_priv->pm_irq_mask) {
319 dev_priv->pm_irq_mask = new_val;
320 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
321 POSTING_READ(gen6_pm_imr(dev_priv));
322 }
323 }
324
325 void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
326 {
327 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
328 return;
329
330 snb_update_pm_irq(dev_priv, mask, mask);
331 }
332
333 static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
334 uint32_t mask)
335 {
336 snb_update_pm_irq(dev_priv, mask, 0);
337 }
338
339 void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
340 {
341 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
342 return;
343
344 __gen6_disable_pm_irq(dev_priv, mask);
345 }
346
347 void gen6_reset_rps_interrupts(struct drm_device *dev)
348 {
349 struct drm_i915_private *dev_priv = dev->dev_private;
350 uint32_t reg = gen6_pm_iir(dev_priv);
351
352 spin_lock_irq(&dev_priv->irq_lock);
353 I915_WRITE(reg, dev_priv->pm_rps_events);
354 I915_WRITE(reg, dev_priv->pm_rps_events);
355 POSTING_READ(reg);
356 dev_priv->rps.pm_iir = 0;
357 spin_unlock_irq(&dev_priv->irq_lock);
358 }
359
360 void gen6_enable_rps_interrupts(struct drm_device *dev)
361 {
362 struct drm_i915_private *dev_priv = dev->dev_private;
363
364 spin_lock_irq(&dev_priv->irq_lock);
365
366 WARN_ON(dev_priv->rps.pm_iir);
367 WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
368 dev_priv->rps.interrupts_enabled = true;
369 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
370 dev_priv->pm_rps_events);
371 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
372
373 spin_unlock_irq(&dev_priv->irq_lock);
374 }
375
376 u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
377 {
378 /*
379 * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
380 * if GEN6_PM_UP_EI_EXPIRED is masked.
381 *
382 * TODO: verify if this can be reproduced on VLV,CHV.
383 */
384 if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
385 mask &= ~GEN6_PM_RP_UP_EI_EXPIRED;
386
387 if (INTEL_INFO(dev_priv)->gen >= 8)
388 mask &= ~GEN8_PMINTR_REDIRECT_TO_NON_DISP;
389
390 return mask;
391 }
392
393 void gen6_disable_rps_interrupts(struct drm_device *dev)
394 {
395 struct drm_i915_private *dev_priv = dev->dev_private;
396
397 spin_lock_irq(&dev_priv->irq_lock);
398 dev_priv->rps.interrupts_enabled = false;
399 spin_unlock_irq(&dev_priv->irq_lock);
400
401 cancel_work_sync(&dev_priv->rps.work);
402
403 spin_lock_irq(&dev_priv->irq_lock);
404
405 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
406
407 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
408 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
409 ~dev_priv->pm_rps_events);
410
411 spin_unlock_irq(&dev_priv->irq_lock);
412
413 synchronize_irq(dev->irq);
414 }
415
416 /**
417 * bdw_update_port_irq - update DE port interrupt
418 * @dev_priv: driver private
419 * @interrupt_mask: mask of interrupt bits to update
420 * @enabled_irq_mask: mask of interrupt bits to enable
421 */
422 static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
423 uint32_t interrupt_mask,
424 uint32_t enabled_irq_mask)
425 {
426 uint32_t new_val;
427 uint32_t old_val;
428
429 assert_spin_locked(&dev_priv->irq_lock);
430
431 WARN_ON(enabled_irq_mask & ~interrupt_mask);
432
433 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
434 return;
435
436 old_val = I915_READ(GEN8_DE_PORT_IMR);
437
438 new_val = old_val;
439 new_val &= ~interrupt_mask;
440 new_val |= (~enabled_irq_mask & interrupt_mask);
441
442 if (new_val != old_val) {
443 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
444 POSTING_READ(GEN8_DE_PORT_IMR);
445 }
446 }
447
448 /**
449 * ibx_display_interrupt_update - update SDEIMR
450 * @dev_priv: driver private
451 * @interrupt_mask: mask of interrupt bits to update
452 * @enabled_irq_mask: mask of interrupt bits to enable
453 */
454 void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
455 uint32_t interrupt_mask,
456 uint32_t enabled_irq_mask)
457 {
458 uint32_t sdeimr = I915_READ(SDEIMR);
459 sdeimr &= ~interrupt_mask;
460 sdeimr |= (~enabled_irq_mask & interrupt_mask);
461
462 WARN_ON(enabled_irq_mask & ~interrupt_mask);
463
464 assert_spin_locked(&dev_priv->irq_lock);
465
466 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
467 return;
468
469 I915_WRITE(SDEIMR, sdeimr);
470 POSTING_READ(SDEIMR);
471 }
472
473 static void
474 __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
475 u32 enable_mask, u32 status_mask)
476 {
477 u32 reg = PIPESTAT(pipe);
478 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
479
480 assert_spin_locked(&dev_priv->irq_lock);
481 WARN_ON(!intel_irqs_enabled(dev_priv));
482
483 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
484 status_mask & ~PIPESTAT_INT_STATUS_MASK,
485 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
486 pipe_name(pipe), enable_mask, status_mask))
487 return;
488
489 if ((pipestat & enable_mask) == enable_mask)
490 return;
491
492 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
493
494 /* Enable the interrupt, clear any pending status */
495 pipestat |= enable_mask | status_mask;
496 I915_WRITE(reg, pipestat);
497 POSTING_READ(reg);
498 }
499
500 static void
501 __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
502 u32 enable_mask, u32 status_mask)
503 {
504 u32 reg = PIPESTAT(pipe);
505 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
506
507 assert_spin_locked(&dev_priv->irq_lock);
508 WARN_ON(!intel_irqs_enabled(dev_priv));
509
510 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
511 status_mask & ~PIPESTAT_INT_STATUS_MASK,
512 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
513 pipe_name(pipe), enable_mask, status_mask))
514 return;
515
516 if ((pipestat & enable_mask) == 0)
517 return;
518
519 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
520
521 pipestat &= ~enable_mask;
522 I915_WRITE(reg, pipestat);
523 POSTING_READ(reg);
524 }
525
526 static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
527 {
528 u32 enable_mask = status_mask << 16;
529
530 /*
531 * On pipe A we don't support the PSR interrupt yet,
532 * on pipe B and C the same bit MBZ.
533 */
534 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
535 return 0;
536 /*
537 * On pipe B and C we don't support the PSR interrupt yet, on pipe
538 * A the same bit is for perf counters which we don't use either.
539 */
540 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
541 return 0;
542
543 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
544 SPRITE0_FLIP_DONE_INT_EN_VLV |
545 SPRITE1_FLIP_DONE_INT_EN_VLV);
546 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
547 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
548 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
549 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
550
551 return enable_mask;
552 }
553
554 void
555 i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
556 u32 status_mask)
557 {
558 u32 enable_mask;
559
560 if (IS_VALLEYVIEW(dev_priv->dev))
561 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
562 status_mask);
563 else
564 enable_mask = status_mask << 16;
565 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
566 }
567
568 void
569 i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
570 u32 status_mask)
571 {
572 u32 enable_mask;
573
574 if (IS_VALLEYVIEW(dev_priv->dev))
575 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
576 status_mask);
577 else
578 enable_mask = status_mask << 16;
579 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
580 }
581
582 /**
583 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
584 */
585 static void i915_enable_asle_pipestat(struct drm_device *dev)
586 {
587 struct drm_i915_private *dev_priv = dev->dev_private;
588
589 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
590 return;
591
592 spin_lock_irq(&dev_priv->irq_lock);
593
594 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
595 if (INTEL_INFO(dev)->gen >= 4)
596 i915_enable_pipestat(dev_priv, PIPE_A,
597 PIPE_LEGACY_BLC_EVENT_STATUS);
598
599 spin_unlock_irq(&dev_priv->irq_lock);
600 }
601
602 /*
603 * This timing diagram depicts the video signal in and
604 * around the vertical blanking period.
605 *
606 * Assumptions about the fictitious mode used in this example:
607 * vblank_start >= 3
608 * vsync_start = vblank_start + 1
609 * vsync_end = vblank_start + 2
610 * vtotal = vblank_start + 3
611 *
612 * start of vblank:
613 * latch double buffered registers
614 * increment frame counter (ctg+)
615 * generate start of vblank interrupt (gen4+)
616 * |
617 * | frame start:
618 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
619 * | may be shifted forward 1-3 extra lines via PIPECONF
620 * | |
621 * | | start of vsync:
622 * | | generate vsync interrupt
623 * | | |
624 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
625 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
626 * ----va---> <-----------------vb--------------------> <--------va-------------
627 * | | <----vs-----> |
628 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
629 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
630 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
631 * | | |
632 * last visible pixel first visible pixel
633 * | increment frame counter (gen3/4)
634 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
635 *
636 * x = horizontal active
637 * _ = horizontal blanking
638 * hs = horizontal sync
639 * va = vertical active
640 * vb = vertical blanking
641 * vs = vertical sync
642 * vbs = vblank_start (number)
643 *
644 * Summary:
645 * - most events happen at the start of horizontal sync
646 * - frame start happens at the start of horizontal blank, 1-4 lines
647 * (depending on PIPECONF settings) after the start of vblank
648 * - gen3/4 pixel and frame counter are synchronized with the start
649 * of horizontal active on the first line of vertical active
650 */
651
652 static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
653 {
654 /* Gen2 doesn't have a hardware frame counter */
655 return 0;
656 }
657
658 /* Called from drm generic code, passed a 'crtc', which
659 * we use as a pipe index
660 */
661 static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
662 {
663 struct drm_i915_private *dev_priv = dev->dev_private;
664 unsigned long high_frame;
665 unsigned long low_frame;
666 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
667 struct intel_crtc *intel_crtc =
668 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
669 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
670
671 htotal = mode->crtc_htotal;
672 hsync_start = mode->crtc_hsync_start;
673 vbl_start = mode->crtc_vblank_start;
674 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
675 vbl_start = DIV_ROUND_UP(vbl_start, 2);
676
677 /* Convert to pixel count */
678 vbl_start *= htotal;
679
680 /* Start of vblank event occurs at start of hsync */
681 vbl_start -= htotal - hsync_start;
682
683 high_frame = PIPEFRAME(pipe);
684 low_frame = PIPEFRAMEPIXEL(pipe);
685
686 /*
687 * High & low register fields aren't synchronized, so make sure
688 * we get a low value that's stable across two reads of the high
689 * register.
690 */
691 do {
692 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
693 low = I915_READ(low_frame);
694 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
695 } while (high1 != high2);
696
697 high1 >>= PIPE_FRAME_HIGH_SHIFT;
698 pixel = low & PIPE_PIXEL_MASK;
699 low >>= PIPE_FRAME_LOW_SHIFT;
700
701 /*
702 * The frame counter increments at beginning of active.
703 * Cook up a vblank counter by also checking the pixel
704 * counter against vblank start.
705 */
706 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
707 }
708
709 static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
710 {
711 struct drm_i915_private *dev_priv = dev->dev_private;
712 int reg = PIPE_FRMCOUNT_GM45(pipe);
713
714 return I915_READ(reg);
715 }
716
717 /* raw reads, only for fast reads of display block, no need for forcewake etc. */
718 #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
719
720 static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
721 {
722 struct drm_device *dev = crtc->base.dev;
723 struct drm_i915_private *dev_priv = dev->dev_private;
724 const struct drm_display_mode *mode = &crtc->base.hwmode;
725 enum pipe pipe = crtc->pipe;
726 int position, vtotal;
727
728 vtotal = mode->crtc_vtotal;
729 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
730 vtotal /= 2;
731
732 if (IS_GEN2(dev))
733 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
734 else
735 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
736
737 /*
738 * See update_scanline_offset() for the details on the
739 * scanline_offset adjustment.
740 */
741 return (position + crtc->scanline_offset) % vtotal;
742 }
743
744 static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
745 unsigned int flags, int *vpos, int *hpos,
746 ktime_t *stime, ktime_t *etime)
747 {
748 struct drm_i915_private *dev_priv = dev->dev_private;
749 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
750 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
751 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
752 int position;
753 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
754 bool in_vbl = true;
755 int ret = 0;
756 unsigned long irqflags;
757
758 if (WARN_ON(!mode->crtc_clock)) {
759 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
760 "pipe %c\n", pipe_name(pipe));
761 return 0;
762 }
763
764 htotal = mode->crtc_htotal;
765 hsync_start = mode->crtc_hsync_start;
766 vtotal = mode->crtc_vtotal;
767 vbl_start = mode->crtc_vblank_start;
768 vbl_end = mode->crtc_vblank_end;
769
770 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
771 vbl_start = DIV_ROUND_UP(vbl_start, 2);
772 vbl_end /= 2;
773 vtotal /= 2;
774 }
775
776 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
777
778 /*
779 * Lock uncore.lock, as we will do multiple timing critical raw
780 * register reads, potentially with preemption disabled, so the
781 * following code must not block on uncore.lock.
782 */
783 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
784
785 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
786
787 /* Get optional system timestamp before query. */
788 if (stime)
789 *stime = ktime_get();
790
791 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
792 /* No obvious pixelcount register. Only query vertical
793 * scanout position from Display scan line register.
794 */
795 position = __intel_get_crtc_scanline(intel_crtc);
796 } else {
797 /* Have access to pixelcount since start of frame.
798 * We can split this into vertical and horizontal
799 * scanout position.
800 */
801 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
802
803 /* convert to pixel counts */
804 vbl_start *= htotal;
805 vbl_end *= htotal;
806 vtotal *= htotal;
807
808 /*
809 * In interlaced modes, the pixel counter counts all pixels,
810 * so one field will have htotal more pixels. In order to avoid
811 * the reported position from jumping backwards when the pixel
812 * counter is beyond the length of the shorter field, just
813 * clamp the position the length of the shorter field. This
814 * matches how the scanline counter based position works since
815 * the scanline counter doesn't count the two half lines.
816 */
817 if (position >= vtotal)
818 position = vtotal - 1;
819
820 /*
821 * Start of vblank interrupt is triggered at start of hsync,
822 * just prior to the first active line of vblank. However we
823 * consider lines to start at the leading edge of horizontal
824 * active. So, should we get here before we've crossed into
825 * the horizontal active of the first line in vblank, we would
826 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
827 * always add htotal-hsync_start to the current pixel position.
828 */
829 position = (position + htotal - hsync_start) % vtotal;
830 }
831
832 /* Get optional system timestamp after query. */
833 if (etime)
834 *etime = ktime_get();
835
836 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
837
838 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
839
840 in_vbl = position >= vbl_start && position < vbl_end;
841
842 /*
843 * While in vblank, position will be negative
844 * counting up towards 0 at vbl_end. And outside
845 * vblank, position will be positive counting
846 * up since vbl_end.
847 */
848 if (position >= vbl_start)
849 position -= vbl_end;
850 else
851 position += vtotal - vbl_end;
852
853 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
854 *vpos = position;
855 *hpos = 0;
856 } else {
857 *vpos = position / htotal;
858 *hpos = position - (*vpos * htotal);
859 }
860
861 /* In vblank? */
862 if (in_vbl)
863 ret |= DRM_SCANOUTPOS_IN_VBLANK;
864
865 return ret;
866 }
867
868 int intel_get_crtc_scanline(struct intel_crtc *crtc)
869 {
870 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
871 unsigned long irqflags;
872 int position;
873
874 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
875 position = __intel_get_crtc_scanline(crtc);
876 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
877
878 return position;
879 }
880
881 static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
882 int *max_error,
883 struct timeval *vblank_time,
884 unsigned flags)
885 {
886 struct drm_crtc *crtc;
887
888 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
889 DRM_ERROR("Invalid crtc %d\n", pipe);
890 return -EINVAL;
891 }
892
893 /* Get drm_crtc to timestamp: */
894 crtc = intel_get_crtc_for_pipe(dev, pipe);
895 if (crtc == NULL) {
896 DRM_ERROR("Invalid crtc %d\n", pipe);
897 return -EINVAL;
898 }
899
900 if (!crtc->hwmode.crtc_clock) {
901 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
902 return -EBUSY;
903 }
904
905 /* Helper routine in DRM core does all the work: */
906 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
907 vblank_time, flags,
908 crtc,
909 &crtc->hwmode);
910 }
911
912 static void ironlake_rps_change_irq_handler(struct drm_device *dev)
913 {
914 struct drm_i915_private *dev_priv = dev->dev_private;
915 u32 busy_up, busy_down, max_avg, min_avg;
916 u8 new_delay;
917
918 spin_lock(&mchdev_lock);
919
920 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
921
922 new_delay = dev_priv->ips.cur_delay;
923
924 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
925 busy_up = I915_READ(RCPREVBSYTUPAVG);
926 busy_down = I915_READ(RCPREVBSYTDNAVG);
927 max_avg = I915_READ(RCBMAXAVG);
928 min_avg = I915_READ(RCBMINAVG);
929
930 /* Handle RCS change request from hw */
931 if (busy_up > max_avg) {
932 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
933 new_delay = dev_priv->ips.cur_delay - 1;
934 if (new_delay < dev_priv->ips.max_delay)
935 new_delay = dev_priv->ips.max_delay;
936 } else if (busy_down < min_avg) {
937 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
938 new_delay = dev_priv->ips.cur_delay + 1;
939 if (new_delay > dev_priv->ips.min_delay)
940 new_delay = dev_priv->ips.min_delay;
941 }
942
943 if (ironlake_set_drps(dev, new_delay))
944 dev_priv->ips.cur_delay = new_delay;
945
946 spin_unlock(&mchdev_lock);
947
948 return;
949 }
950
951 static void notify_ring(struct intel_engine_cs *ring)
952 {
953 if (!intel_ring_initialized(ring))
954 return;
955
956 trace_i915_gem_request_notify(ring);
957
958 wake_up_all(&ring->irq_queue);
959 }
960
961 static void vlv_c0_read(struct drm_i915_private *dev_priv,
962 struct intel_rps_ei *ei)
963 {
964 ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
965 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
966 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
967 }
968
969 static bool vlv_c0_above(struct drm_i915_private *dev_priv,
970 const struct intel_rps_ei *old,
971 const struct intel_rps_ei *now,
972 int threshold)
973 {
974 u64 time, c0;
975
976 if (old->cz_clock == 0)
977 return false;
978
979 time = now->cz_clock - old->cz_clock;
980 time *= threshold * dev_priv->mem_freq;
981
982 /* Workload can be split between render + media, e.g. SwapBuffers
983 * being blitted in X after being rendered in mesa. To account for
984 * this we need to combine both engines into our activity counter.
985 */
986 c0 = now->render_c0 - old->render_c0;
987 c0 += now->media_c0 - old->media_c0;
988 c0 *= 100 * VLV_CZ_CLOCK_TO_MILLI_SEC * 4 / 1000;
989
990 return c0 >= time;
991 }
992
993 void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
994 {
995 vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
996 dev_priv->rps.up_ei = dev_priv->rps.down_ei;
997 }
998
999 static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1000 {
1001 struct intel_rps_ei now;
1002 u32 events = 0;
1003
1004 if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
1005 return 0;
1006
1007 vlv_c0_read(dev_priv, &now);
1008 if (now.cz_clock == 0)
1009 return 0;
1010
1011 if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
1012 if (!vlv_c0_above(dev_priv,
1013 &dev_priv->rps.down_ei, &now,
1014 dev_priv->rps.down_threshold))
1015 events |= GEN6_PM_RP_DOWN_THRESHOLD;
1016 dev_priv->rps.down_ei = now;
1017 }
1018
1019 if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1020 if (vlv_c0_above(dev_priv,
1021 &dev_priv->rps.up_ei, &now,
1022 dev_priv->rps.up_threshold))
1023 events |= GEN6_PM_RP_UP_THRESHOLD;
1024 dev_priv->rps.up_ei = now;
1025 }
1026
1027 return events;
1028 }
1029
1030 static bool any_waiters(struct drm_i915_private *dev_priv)
1031 {
1032 struct intel_engine_cs *ring;
1033 int i;
1034
1035 for_each_ring(ring, dev_priv, i)
1036 if (ring->irq_refcount)
1037 return true;
1038
1039 return false;
1040 }
1041
1042 static void gen6_pm_rps_work(struct work_struct *work)
1043 {
1044 struct drm_i915_private *dev_priv =
1045 container_of(work, struct drm_i915_private, rps.work);
1046 bool client_boost;
1047 int new_delay, adj, min, max;
1048 u32 pm_iir;
1049
1050 spin_lock_irq(&dev_priv->irq_lock);
1051 /* Speed up work cancelation during disabling rps interrupts. */
1052 if (!dev_priv->rps.interrupts_enabled) {
1053 spin_unlock_irq(&dev_priv->irq_lock);
1054 return;
1055 }
1056 pm_iir = dev_priv->rps.pm_iir;
1057 dev_priv->rps.pm_iir = 0;
1058 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1059 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
1060 client_boost = dev_priv->rps.client_boost;
1061 dev_priv->rps.client_boost = false;
1062 spin_unlock_irq(&dev_priv->irq_lock);
1063
1064 /* Make sure we didn't queue anything we're not going to process. */
1065 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
1066
1067 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
1068 return;
1069
1070 mutex_lock(&dev_priv->rps.hw_lock);
1071
1072 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1073
1074 adj = dev_priv->rps.last_adj;
1075 new_delay = dev_priv->rps.cur_freq;
1076 min = dev_priv->rps.min_freq_softlimit;
1077 max = dev_priv->rps.max_freq_softlimit;
1078
1079 if (client_boost) {
1080 new_delay = dev_priv->rps.max_freq_softlimit;
1081 adj = 0;
1082 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
1083 if (adj > 0)
1084 adj *= 2;
1085 else /* CHV needs even encode values */
1086 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
1087 /*
1088 * For better performance, jump directly
1089 * to RPe if we're below it.
1090 */
1091 if (new_delay < dev_priv->rps.efficient_freq - adj) {
1092 new_delay = dev_priv->rps.efficient_freq;
1093 adj = 0;
1094 }
1095 } else if (any_waiters(dev_priv)) {
1096 adj = 0;
1097 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
1098 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1099 new_delay = dev_priv->rps.efficient_freq;
1100 else
1101 new_delay = dev_priv->rps.min_freq_softlimit;
1102 adj = 0;
1103 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1104 if (adj < 0)
1105 adj *= 2;
1106 else /* CHV needs even encode values */
1107 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
1108 } else { /* unknown event */
1109 adj = 0;
1110 }
1111
1112 dev_priv->rps.last_adj = adj;
1113
1114 /* sysfs frequency interfaces may have snuck in while servicing the
1115 * interrupt
1116 */
1117 new_delay += adj;
1118 new_delay = clamp_t(int, new_delay, min, max);
1119
1120 intel_set_rps(dev_priv->dev, new_delay);
1121
1122 mutex_unlock(&dev_priv->rps.hw_lock);
1123 }
1124
1125
1126 /**
1127 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1128 * occurred.
1129 * @work: workqueue struct
1130 *
1131 * Doesn't actually do anything except notify userspace. As a consequence of
1132 * this event, userspace should try to remap the bad rows since statistically
1133 * it is likely the same row is more likely to go bad again.
1134 */
1135 static void ivybridge_parity_work(struct work_struct *work)
1136 {
1137 struct drm_i915_private *dev_priv =
1138 container_of(work, struct drm_i915_private, l3_parity.error_work);
1139 u32 error_status, row, bank, subbank;
1140 char *parity_event[6];
1141 uint32_t misccpctl;
1142 uint8_t slice = 0;
1143
1144 /* We must turn off DOP level clock gating to access the L3 registers.
1145 * In order to prevent a get/put style interface, acquire struct mutex
1146 * any time we access those registers.
1147 */
1148 mutex_lock(&dev_priv->dev->struct_mutex);
1149
1150 /* If we've screwed up tracking, just let the interrupt fire again */
1151 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1152 goto out;
1153
1154 misccpctl = I915_READ(GEN7_MISCCPCTL);
1155 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1156 POSTING_READ(GEN7_MISCCPCTL);
1157
1158 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1159 u32 reg;
1160
1161 slice--;
1162 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1163 break;
1164
1165 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1166
1167 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1168
1169 error_status = I915_READ(reg);
1170 row = GEN7_PARITY_ERROR_ROW(error_status);
1171 bank = GEN7_PARITY_ERROR_BANK(error_status);
1172 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1173
1174 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1175 POSTING_READ(reg);
1176
1177 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1178 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1179 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1180 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1181 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1182 parity_event[5] = NULL;
1183
1184 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
1185 KOBJ_CHANGE, parity_event);
1186
1187 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1188 slice, row, bank, subbank);
1189
1190 kfree(parity_event[4]);
1191 kfree(parity_event[3]);
1192 kfree(parity_event[2]);
1193 kfree(parity_event[1]);
1194 }
1195
1196 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1197
1198 out:
1199 WARN_ON(dev_priv->l3_parity.which_slice);
1200 spin_lock_irq(&dev_priv->irq_lock);
1201 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
1202 spin_unlock_irq(&dev_priv->irq_lock);
1203
1204 mutex_unlock(&dev_priv->dev->struct_mutex);
1205 }
1206
1207 static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
1208 {
1209 struct drm_i915_private *dev_priv = dev->dev_private;
1210
1211 if (!HAS_L3_DPF(dev))
1212 return;
1213
1214 spin_lock(&dev_priv->irq_lock);
1215 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
1216 spin_unlock(&dev_priv->irq_lock);
1217
1218 iir &= GT_PARITY_ERROR(dev);
1219 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1220 dev_priv->l3_parity.which_slice |= 1 << 1;
1221
1222 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1223 dev_priv->l3_parity.which_slice |= 1 << 0;
1224
1225 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
1226 }
1227
1228 static void ilk_gt_irq_handler(struct drm_device *dev,
1229 struct drm_i915_private *dev_priv,
1230 u32 gt_iir)
1231 {
1232 if (gt_iir &
1233 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1234 notify_ring(&dev_priv->ring[RCS]);
1235 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1236 notify_ring(&dev_priv->ring[VCS]);
1237 }
1238
1239 static void snb_gt_irq_handler(struct drm_device *dev,
1240 struct drm_i915_private *dev_priv,
1241 u32 gt_iir)
1242 {
1243
1244 if (gt_iir &
1245 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1246 notify_ring(&dev_priv->ring[RCS]);
1247 if (gt_iir & GT_BSD_USER_INTERRUPT)
1248 notify_ring(&dev_priv->ring[VCS]);
1249 if (gt_iir & GT_BLT_USER_INTERRUPT)
1250 notify_ring(&dev_priv->ring[BCS]);
1251
1252 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1253 GT_BSD_CS_ERROR_INTERRUPT |
1254 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1255 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
1256
1257 if (gt_iir & GT_PARITY_ERROR(dev))
1258 ivybridge_parity_error_irq_handler(dev, gt_iir);
1259 }
1260
1261 static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1262 u32 master_ctl)
1263 {
1264 irqreturn_t ret = IRQ_NONE;
1265
1266 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1267 u32 tmp = I915_READ_FW(GEN8_GT_IIR(0));
1268 if (tmp) {
1269 I915_WRITE_FW(GEN8_GT_IIR(0), tmp);
1270 ret = IRQ_HANDLED;
1271
1272 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
1273 intel_lrc_irq_handler(&dev_priv->ring[RCS]);
1274 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
1275 notify_ring(&dev_priv->ring[RCS]);
1276
1277 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
1278 intel_lrc_irq_handler(&dev_priv->ring[BCS]);
1279 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
1280 notify_ring(&dev_priv->ring[BCS]);
1281 } else
1282 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1283 }
1284
1285 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
1286 u32 tmp = I915_READ_FW(GEN8_GT_IIR(1));
1287 if (tmp) {
1288 I915_WRITE_FW(GEN8_GT_IIR(1), tmp);
1289 ret = IRQ_HANDLED;
1290
1291 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
1292 intel_lrc_irq_handler(&dev_priv->ring[VCS]);
1293 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
1294 notify_ring(&dev_priv->ring[VCS]);
1295
1296 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
1297 intel_lrc_irq_handler(&dev_priv->ring[VCS2]);
1298 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
1299 notify_ring(&dev_priv->ring[VCS2]);
1300 } else
1301 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1302 }
1303
1304 if (master_ctl & GEN8_GT_VECS_IRQ) {
1305 u32 tmp = I915_READ_FW(GEN8_GT_IIR(3));
1306 if (tmp) {
1307 I915_WRITE_FW(GEN8_GT_IIR(3), tmp);
1308 ret = IRQ_HANDLED;
1309
1310 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
1311 intel_lrc_irq_handler(&dev_priv->ring[VECS]);
1312 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
1313 notify_ring(&dev_priv->ring[VECS]);
1314 } else
1315 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1316 }
1317
1318 if (master_ctl & GEN8_GT_PM_IRQ) {
1319 u32 tmp = I915_READ_FW(GEN8_GT_IIR(2));
1320 if (tmp & dev_priv->pm_rps_events) {
1321 I915_WRITE_FW(GEN8_GT_IIR(2),
1322 tmp & dev_priv->pm_rps_events);
1323 ret = IRQ_HANDLED;
1324 gen6_rps_irq_handler(dev_priv, tmp);
1325 } else
1326 DRM_ERROR("The master control interrupt lied (PM)!\n");
1327 }
1328
1329 return ret;
1330 }
1331
1332 static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1333 {
1334 switch (port) {
1335 case PORT_A:
1336 return val & PORTA_HOTPLUG_LONG_DETECT;
1337 case PORT_B:
1338 return val & PORTB_HOTPLUG_LONG_DETECT;
1339 case PORT_C:
1340 return val & PORTC_HOTPLUG_LONG_DETECT;
1341 default:
1342 return false;
1343 }
1344 }
1345
1346 static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1347 {
1348 switch (port) {
1349 case PORT_E:
1350 return val & PORTE_HOTPLUG_LONG_DETECT;
1351 default:
1352 return false;
1353 }
1354 }
1355
1356 static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1357 {
1358 switch (port) {
1359 case PORT_A:
1360 return val & PORTA_HOTPLUG_LONG_DETECT;
1361 case PORT_B:
1362 return val & PORTB_HOTPLUG_LONG_DETECT;
1363 case PORT_C:
1364 return val & PORTC_HOTPLUG_LONG_DETECT;
1365 case PORT_D:
1366 return val & PORTD_HOTPLUG_LONG_DETECT;
1367 default:
1368 return false;
1369 }
1370 }
1371
1372 static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1373 {
1374 switch (port) {
1375 case PORT_A:
1376 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1377 default:
1378 return false;
1379 }
1380 }
1381
1382 static bool pch_port_hotplug_long_detect(enum port port, u32 val)
1383 {
1384 switch (port) {
1385 case PORT_B:
1386 return val & PORTB_HOTPLUG_LONG_DETECT;
1387 case PORT_C:
1388 return val & PORTC_HOTPLUG_LONG_DETECT;
1389 case PORT_D:
1390 return val & PORTD_HOTPLUG_LONG_DETECT;
1391 default:
1392 return false;
1393 }
1394 }
1395
1396 static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
1397 {
1398 switch (port) {
1399 case PORT_B:
1400 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
1401 case PORT_C:
1402 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
1403 case PORT_D:
1404 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1405 default:
1406 return false;
1407 }
1408 }
1409
1410 /*
1411 * Get a bit mask of pins that have triggered, and which ones may be long.
1412 * This can be called multiple times with the same masks to accumulate
1413 * hotplug detection results from several registers.
1414 *
1415 * Note that the caller is expected to zero out the masks initially.
1416 */
1417 static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
1418 u32 hotplug_trigger, u32 dig_hotplug_reg,
1419 const u32 hpd[HPD_NUM_PINS],
1420 bool long_pulse_detect(enum port port, u32 val))
1421 {
1422 enum port port;
1423 int i;
1424
1425 for_each_hpd_pin(i) {
1426 if ((hpd[i] & hotplug_trigger) == 0)
1427 continue;
1428
1429 *pin_mask |= BIT(i);
1430
1431 if (!intel_hpd_pin_to_port(i, &port))
1432 continue;
1433
1434 if (long_pulse_detect(port, dig_hotplug_reg))
1435 *long_mask |= BIT(i);
1436 }
1437
1438 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1439 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1440
1441 }
1442
1443 static void gmbus_irq_handler(struct drm_device *dev)
1444 {
1445 struct drm_i915_private *dev_priv = dev->dev_private;
1446
1447 wake_up_all(&dev_priv->gmbus_wait_queue);
1448 }
1449
1450 static void dp_aux_irq_handler(struct drm_device *dev)
1451 {
1452 struct drm_i915_private *dev_priv = dev->dev_private;
1453
1454 wake_up_all(&dev_priv->gmbus_wait_queue);
1455 }
1456
1457 #if defined(CONFIG_DEBUG_FS)
1458 static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1459 uint32_t crc0, uint32_t crc1,
1460 uint32_t crc2, uint32_t crc3,
1461 uint32_t crc4)
1462 {
1463 struct drm_i915_private *dev_priv = dev->dev_private;
1464 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1465 struct intel_pipe_crc_entry *entry;
1466 int head, tail;
1467
1468 spin_lock(&pipe_crc->lock);
1469
1470 if (!pipe_crc->entries) {
1471 spin_unlock(&pipe_crc->lock);
1472 DRM_DEBUG_KMS("spurious interrupt\n");
1473 return;
1474 }
1475
1476 head = pipe_crc->head;
1477 tail = pipe_crc->tail;
1478
1479 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1480 spin_unlock(&pipe_crc->lock);
1481 DRM_ERROR("CRC buffer overflowing\n");
1482 return;
1483 }
1484
1485 entry = &pipe_crc->entries[head];
1486
1487 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
1488 entry->crc[0] = crc0;
1489 entry->crc[1] = crc1;
1490 entry->crc[2] = crc2;
1491 entry->crc[3] = crc3;
1492 entry->crc[4] = crc4;
1493
1494 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1495 pipe_crc->head = head;
1496
1497 spin_unlock(&pipe_crc->lock);
1498
1499 wake_up_interruptible(&pipe_crc->wq);
1500 }
1501 #else
1502 static inline void
1503 display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1504 uint32_t crc0, uint32_t crc1,
1505 uint32_t crc2, uint32_t crc3,
1506 uint32_t crc4) {}
1507 #endif
1508
1509
1510 static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
1511 {
1512 struct drm_i915_private *dev_priv = dev->dev_private;
1513
1514 display_pipe_crc_irq_handler(dev, pipe,
1515 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1516 0, 0, 0, 0);
1517 }
1518
1519 static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
1520 {
1521 struct drm_i915_private *dev_priv = dev->dev_private;
1522
1523 display_pipe_crc_irq_handler(dev, pipe,
1524 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1525 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1526 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1527 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1528 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
1529 }
1530
1531 static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
1532 {
1533 struct drm_i915_private *dev_priv = dev->dev_private;
1534 uint32_t res1, res2;
1535
1536 if (INTEL_INFO(dev)->gen >= 3)
1537 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1538 else
1539 res1 = 0;
1540
1541 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1542 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1543 else
1544 res2 = 0;
1545
1546 display_pipe_crc_irq_handler(dev, pipe,
1547 I915_READ(PIPE_CRC_RES_RED(pipe)),
1548 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1549 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1550 res1, res2);
1551 }
1552
1553 /* The RPS events need forcewake, so we add them to a work queue and mask their
1554 * IMR bits until the work is done. Other interrupts can be processed without
1555 * the work queue. */
1556 static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
1557 {
1558 if (pm_iir & dev_priv->pm_rps_events) {
1559 spin_lock(&dev_priv->irq_lock);
1560 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
1561 if (dev_priv->rps.interrupts_enabled) {
1562 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1563 queue_work(dev_priv->wq, &dev_priv->rps.work);
1564 }
1565 spin_unlock(&dev_priv->irq_lock);
1566 }
1567
1568 if (INTEL_INFO(dev_priv)->gen >= 8)
1569 return;
1570
1571 if (HAS_VEBOX(dev_priv->dev)) {
1572 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1573 notify_ring(&dev_priv->ring[VECS]);
1574
1575 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1576 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
1577 }
1578 }
1579
1580 static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
1581 {
1582 if (!drm_handle_vblank(dev, pipe))
1583 return false;
1584
1585 return true;
1586 }
1587
1588 static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1589 {
1590 struct drm_i915_private *dev_priv = dev->dev_private;
1591 u32 pipe_stats[I915_MAX_PIPES] = { };
1592 int pipe;
1593
1594 spin_lock(&dev_priv->irq_lock);
1595 for_each_pipe(dev_priv, pipe) {
1596 int reg;
1597 u32 mask, iir_bit = 0;
1598
1599 /*
1600 * PIPESTAT bits get signalled even when the interrupt is
1601 * disabled with the mask bits, and some of the status bits do
1602 * not generate interrupts at all (like the underrun bit). Hence
1603 * we need to be careful that we only handle what we want to
1604 * handle.
1605 */
1606
1607 /* fifo underruns are filterered in the underrun handler. */
1608 mask = PIPE_FIFO_UNDERRUN_STATUS;
1609
1610 switch (pipe) {
1611 case PIPE_A:
1612 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1613 break;
1614 case PIPE_B:
1615 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1616 break;
1617 case PIPE_C:
1618 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1619 break;
1620 }
1621 if (iir & iir_bit)
1622 mask |= dev_priv->pipestat_irq_mask[pipe];
1623
1624 if (!mask)
1625 continue;
1626
1627 reg = PIPESTAT(pipe);
1628 mask |= PIPESTAT_INT_ENABLE_MASK;
1629 pipe_stats[pipe] = I915_READ(reg) & mask;
1630
1631 /*
1632 * Clear the PIPE*STAT regs before the IIR
1633 */
1634 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1635 PIPESTAT_INT_STATUS_MASK))
1636 I915_WRITE(reg, pipe_stats[pipe]);
1637 }
1638 spin_unlock(&dev_priv->irq_lock);
1639
1640 for_each_pipe(dev_priv, pipe) {
1641 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1642 intel_pipe_handle_vblank(dev, pipe))
1643 intel_check_page_flip(dev, pipe);
1644
1645 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
1646 intel_prepare_page_flip(dev, pipe);
1647 intel_finish_page_flip(dev, pipe);
1648 }
1649
1650 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1651 i9xx_pipe_crc_irq_handler(dev, pipe);
1652
1653 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1654 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1655 }
1656
1657 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1658 gmbus_irq_handler(dev);
1659 }
1660
1661 static void i9xx_hpd_irq_handler(struct drm_device *dev)
1662 {
1663 struct drm_i915_private *dev_priv = dev->dev_private;
1664 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1665 u32 pin_mask = 0, long_mask = 0;
1666
1667 if (!hotplug_status)
1668 return;
1669
1670 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1671 /*
1672 * Make sure hotplug status is cleared before we clear IIR, or else we
1673 * may miss hotplug events.
1674 */
1675 POSTING_READ(PORT_HOTPLUG_STAT);
1676
1677 if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
1678 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
1679
1680 if (hotplug_trigger) {
1681 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1682 hotplug_trigger, hpd_status_g4x,
1683 i9xx_port_hotplug_long_detect);
1684
1685 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1686 }
1687
1688 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1689 dp_aux_irq_handler(dev);
1690 } else {
1691 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1692
1693 if (hotplug_trigger) {
1694 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1695 hotplug_trigger, hpd_status_g4x,
1696 i9xx_port_hotplug_long_detect);
1697
1698 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1699 }
1700 }
1701 }
1702
1703 static irqreturn_t valleyview_irq_handler(int irq, void *arg)
1704 {
1705 struct drm_device *dev = arg;
1706 struct drm_i915_private *dev_priv = dev->dev_private;
1707 u32 iir, gt_iir, pm_iir;
1708 irqreturn_t ret = IRQ_NONE;
1709
1710 if (!intel_irqs_enabled(dev_priv))
1711 return IRQ_NONE;
1712
1713 while (true) {
1714 /* Find, clear, then process each source of interrupt */
1715
1716 gt_iir = I915_READ(GTIIR);
1717 if (gt_iir)
1718 I915_WRITE(GTIIR, gt_iir);
1719
1720 pm_iir = I915_READ(GEN6_PMIIR);
1721 if (pm_iir)
1722 I915_WRITE(GEN6_PMIIR, pm_iir);
1723
1724 iir = I915_READ(VLV_IIR);
1725 if (iir) {
1726 /* Consume port before clearing IIR or we'll miss events */
1727 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1728 i9xx_hpd_irq_handler(dev);
1729 I915_WRITE(VLV_IIR, iir);
1730 }
1731
1732 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1733 goto out;
1734
1735 ret = IRQ_HANDLED;
1736
1737 if (gt_iir)
1738 snb_gt_irq_handler(dev, dev_priv, gt_iir);
1739 if (pm_iir)
1740 gen6_rps_irq_handler(dev_priv, pm_iir);
1741 /* Call regardless, as some status bits might not be
1742 * signalled in iir */
1743 valleyview_pipestat_irq_handler(dev, iir);
1744 }
1745
1746 out:
1747 return ret;
1748 }
1749
1750 static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1751 {
1752 struct drm_device *dev = arg;
1753 struct drm_i915_private *dev_priv = dev->dev_private;
1754 u32 master_ctl, iir;
1755 irqreturn_t ret = IRQ_NONE;
1756
1757 if (!intel_irqs_enabled(dev_priv))
1758 return IRQ_NONE;
1759
1760 for (;;) {
1761 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1762 iir = I915_READ(VLV_IIR);
1763
1764 if (master_ctl == 0 && iir == 0)
1765 break;
1766
1767 ret = IRQ_HANDLED;
1768
1769 I915_WRITE(GEN8_MASTER_IRQ, 0);
1770
1771 /* Find, clear, then process each source of interrupt */
1772
1773 if (iir) {
1774 /* Consume port before clearing IIR or we'll miss events */
1775 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1776 i9xx_hpd_irq_handler(dev);
1777 I915_WRITE(VLV_IIR, iir);
1778 }
1779
1780 gen8_gt_irq_handler(dev_priv, master_ctl);
1781
1782 /* Call regardless, as some status bits might not be
1783 * signalled in iir */
1784 valleyview_pipestat_irq_handler(dev, iir);
1785
1786 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
1787 POSTING_READ(GEN8_MASTER_IRQ);
1788 }
1789
1790 return ret;
1791 }
1792
1793 static void ibx_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
1794 const u32 hpd[HPD_NUM_PINS])
1795 {
1796 struct drm_i915_private *dev_priv = to_i915(dev);
1797 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1798
1799 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1800 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1801
1802 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1803 dig_hotplug_reg, hpd,
1804 pch_port_hotplug_long_detect);
1805
1806 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1807 }
1808
1809 static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
1810 {
1811 struct drm_i915_private *dev_priv = dev->dev_private;
1812 int pipe;
1813 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
1814
1815 if (hotplug_trigger)
1816 ibx_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1817
1818 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1819 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1820 SDE_AUDIO_POWER_SHIFT);
1821 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
1822 port_name(port));
1823 }
1824
1825 if (pch_iir & SDE_AUX_MASK)
1826 dp_aux_irq_handler(dev);
1827
1828 if (pch_iir & SDE_GMBUS)
1829 gmbus_irq_handler(dev);
1830
1831 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1832 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1833
1834 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1835 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1836
1837 if (pch_iir & SDE_POISON)
1838 DRM_ERROR("PCH poison interrupt\n");
1839
1840 if (pch_iir & SDE_FDI_MASK)
1841 for_each_pipe(dev_priv, pipe)
1842 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1843 pipe_name(pipe),
1844 I915_READ(FDI_RX_IIR(pipe)));
1845
1846 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1847 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1848
1849 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1850 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1851
1852 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
1853 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
1854
1855 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1856 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
1857 }
1858
1859 static void ivb_err_int_handler(struct drm_device *dev)
1860 {
1861 struct drm_i915_private *dev_priv = dev->dev_private;
1862 u32 err_int = I915_READ(GEN7_ERR_INT);
1863 enum pipe pipe;
1864
1865 if (err_int & ERR_INT_POISON)
1866 DRM_ERROR("Poison interrupt\n");
1867
1868 for_each_pipe(dev_priv, pipe) {
1869 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1870 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1871
1872 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1873 if (IS_IVYBRIDGE(dev))
1874 ivb_pipe_crc_irq_handler(dev, pipe);
1875 else
1876 hsw_pipe_crc_irq_handler(dev, pipe);
1877 }
1878 }
1879
1880 I915_WRITE(GEN7_ERR_INT, err_int);
1881 }
1882
1883 static void cpt_serr_int_handler(struct drm_device *dev)
1884 {
1885 struct drm_i915_private *dev_priv = dev->dev_private;
1886 u32 serr_int = I915_READ(SERR_INT);
1887
1888 if (serr_int & SERR_INT_POISON)
1889 DRM_ERROR("PCH poison interrupt\n");
1890
1891 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1892 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
1893
1894 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1895 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
1896
1897 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1898 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
1899
1900 I915_WRITE(SERR_INT, serr_int);
1901 }
1902
1903 static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1904 {
1905 struct drm_i915_private *dev_priv = dev->dev_private;
1906 int pipe;
1907 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
1908
1909 if (hotplug_trigger)
1910 ibx_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1911
1912 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1913 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1914 SDE_AUDIO_POWER_SHIFT_CPT);
1915 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1916 port_name(port));
1917 }
1918
1919 if (pch_iir & SDE_AUX_MASK_CPT)
1920 dp_aux_irq_handler(dev);
1921
1922 if (pch_iir & SDE_GMBUS_CPT)
1923 gmbus_irq_handler(dev);
1924
1925 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1926 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1927
1928 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1929 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1930
1931 if (pch_iir & SDE_FDI_MASK_CPT)
1932 for_each_pipe(dev_priv, pipe)
1933 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1934 pipe_name(pipe),
1935 I915_READ(FDI_RX_IIR(pipe)));
1936
1937 if (pch_iir & SDE_ERROR_CPT)
1938 cpt_serr_int_handler(dev);
1939 }
1940
1941 static void spt_irq_handler(struct drm_device *dev, u32 pch_iir)
1942 {
1943 struct drm_i915_private *dev_priv = dev->dev_private;
1944 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
1945 ~SDE_PORTE_HOTPLUG_SPT;
1946 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
1947 u32 pin_mask = 0, long_mask = 0;
1948
1949 if (hotplug_trigger) {
1950 u32 dig_hotplug_reg;
1951
1952 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1953 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1954
1955 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1956 dig_hotplug_reg, hpd_spt,
1957 spt_port_hotplug_long_detect);
1958 }
1959
1960 if (hotplug2_trigger) {
1961 u32 dig_hotplug_reg;
1962
1963 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
1964 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
1965
1966 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
1967 dig_hotplug_reg, hpd_spt,
1968 spt_port_hotplug2_long_detect);
1969 }
1970
1971 if (pin_mask)
1972 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1973
1974 if (pch_iir & SDE_GMBUS_CPT)
1975 gmbus_irq_handler(dev);
1976 }
1977
1978 static void ilk_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
1979 const u32 hpd[HPD_NUM_PINS])
1980 {
1981 struct drm_i915_private *dev_priv = to_i915(dev);
1982 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1983
1984 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
1985 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
1986
1987 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1988 dig_hotplug_reg, hpd,
1989 ilk_port_hotplug_long_detect);
1990
1991 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1992 }
1993
1994 static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1995 {
1996 struct drm_i915_private *dev_priv = dev->dev_private;
1997 enum pipe pipe;
1998 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
1999
2000 if (hotplug_trigger)
2001 ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_ilk);
2002
2003 if (de_iir & DE_AUX_CHANNEL_A)
2004 dp_aux_irq_handler(dev);
2005
2006 if (de_iir & DE_GSE)
2007 intel_opregion_asle_intr(dev);
2008
2009 if (de_iir & DE_POISON)
2010 DRM_ERROR("Poison interrupt\n");
2011
2012 for_each_pipe(dev_priv, pipe) {
2013 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2014 intel_pipe_handle_vblank(dev, pipe))
2015 intel_check_page_flip(dev, pipe);
2016
2017 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
2018 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2019
2020 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2021 i9xx_pipe_crc_irq_handler(dev, pipe);
2022
2023 /* plane/pipes map 1:1 on ilk+ */
2024 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
2025 intel_prepare_page_flip(dev, pipe);
2026 intel_finish_page_flip_plane(dev, pipe);
2027 }
2028 }
2029
2030 /* check event from PCH */
2031 if (de_iir & DE_PCH_EVENT) {
2032 u32 pch_iir = I915_READ(SDEIIR);
2033
2034 if (HAS_PCH_CPT(dev))
2035 cpt_irq_handler(dev, pch_iir);
2036 else
2037 ibx_irq_handler(dev, pch_iir);
2038
2039 /* should clear PCH hotplug event before clear CPU irq */
2040 I915_WRITE(SDEIIR, pch_iir);
2041 }
2042
2043 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
2044 ironlake_rps_change_irq_handler(dev);
2045 }
2046
2047 static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
2048 {
2049 struct drm_i915_private *dev_priv = dev->dev_private;
2050 enum pipe pipe;
2051 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2052
2053 if (hotplug_trigger)
2054 ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_ivb);
2055
2056 if (de_iir & DE_ERR_INT_IVB)
2057 ivb_err_int_handler(dev);
2058
2059 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2060 dp_aux_irq_handler(dev);
2061
2062 if (de_iir & DE_GSE_IVB)
2063 intel_opregion_asle_intr(dev);
2064
2065 for_each_pipe(dev_priv, pipe) {
2066 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2067 intel_pipe_handle_vblank(dev, pipe))
2068 intel_check_page_flip(dev, pipe);
2069
2070 /* plane/pipes map 1:1 on ilk+ */
2071 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
2072 intel_prepare_page_flip(dev, pipe);
2073 intel_finish_page_flip_plane(dev, pipe);
2074 }
2075 }
2076
2077 /* check event from PCH */
2078 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
2079 u32 pch_iir = I915_READ(SDEIIR);
2080
2081 cpt_irq_handler(dev, pch_iir);
2082
2083 /* clear PCH hotplug event before clear CPU irq */
2084 I915_WRITE(SDEIIR, pch_iir);
2085 }
2086 }
2087
2088 /*
2089 * To handle irqs with the minimum potential races with fresh interrupts, we:
2090 * 1 - Disable Master Interrupt Control.
2091 * 2 - Find the source(s) of the interrupt.
2092 * 3 - Clear the Interrupt Identity bits (IIR).
2093 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2094 * 5 - Re-enable Master Interrupt Control.
2095 */
2096 static irqreturn_t ironlake_irq_handler(int irq, void *arg)
2097 {
2098 struct drm_device *dev = arg;
2099 struct drm_i915_private *dev_priv = dev->dev_private;
2100 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
2101 irqreturn_t ret = IRQ_NONE;
2102
2103 if (!intel_irqs_enabled(dev_priv))
2104 return IRQ_NONE;
2105
2106 /* We get interrupts on unclaimed registers, so check for this before we
2107 * do any I915_{READ,WRITE}. */
2108 intel_uncore_check_errors(dev);
2109
2110 /* disable master interrupt before clearing iir */
2111 de_ier = I915_READ(DEIER);
2112 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
2113 POSTING_READ(DEIER);
2114
2115 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2116 * interrupts will will be stored on its back queue, and then we'll be
2117 * able to process them after we restore SDEIER (as soon as we restore
2118 * it, we'll get an interrupt if SDEIIR still has something to process
2119 * due to its back queue). */
2120 if (!HAS_PCH_NOP(dev)) {
2121 sde_ier = I915_READ(SDEIER);
2122 I915_WRITE(SDEIER, 0);
2123 POSTING_READ(SDEIER);
2124 }
2125
2126 /* Find, clear, then process each source of interrupt */
2127
2128 gt_iir = I915_READ(GTIIR);
2129 if (gt_iir) {
2130 I915_WRITE(GTIIR, gt_iir);
2131 ret = IRQ_HANDLED;
2132 if (INTEL_INFO(dev)->gen >= 6)
2133 snb_gt_irq_handler(dev, dev_priv, gt_iir);
2134 else
2135 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
2136 }
2137
2138 de_iir = I915_READ(DEIIR);
2139 if (de_iir) {
2140 I915_WRITE(DEIIR, de_iir);
2141 ret = IRQ_HANDLED;
2142 if (INTEL_INFO(dev)->gen >= 7)
2143 ivb_display_irq_handler(dev, de_iir);
2144 else
2145 ilk_display_irq_handler(dev, de_iir);
2146 }
2147
2148 if (INTEL_INFO(dev)->gen >= 6) {
2149 u32 pm_iir = I915_READ(GEN6_PMIIR);
2150 if (pm_iir) {
2151 I915_WRITE(GEN6_PMIIR, pm_iir);
2152 ret = IRQ_HANDLED;
2153 gen6_rps_irq_handler(dev_priv, pm_iir);
2154 }
2155 }
2156
2157 I915_WRITE(DEIER, de_ier);
2158 POSTING_READ(DEIER);
2159 if (!HAS_PCH_NOP(dev)) {
2160 I915_WRITE(SDEIER, sde_ier);
2161 POSTING_READ(SDEIER);
2162 }
2163
2164 return ret;
2165 }
2166
2167 static void bxt_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
2168 const u32 hpd[HPD_NUM_PINS])
2169 {
2170 struct drm_i915_private *dev_priv = to_i915(dev);
2171 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2172
2173 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2174 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2175
2176 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2177 dig_hotplug_reg, hpd,
2178 bxt_port_hotplug_long_detect);
2179
2180 intel_hpd_irq_handler(dev, pin_mask, long_mask);
2181 }
2182
2183 static irqreturn_t gen8_irq_handler(int irq, void *arg)
2184 {
2185 struct drm_device *dev = arg;
2186 struct drm_i915_private *dev_priv = dev->dev_private;
2187 u32 master_ctl;
2188 irqreturn_t ret = IRQ_NONE;
2189 uint32_t tmp = 0;
2190 enum pipe pipe;
2191 u32 aux_mask = GEN8_AUX_CHANNEL_A;
2192
2193 if (!intel_irqs_enabled(dev_priv))
2194 return IRQ_NONE;
2195
2196 if (INTEL_INFO(dev_priv)->gen >= 9)
2197 aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
2198 GEN9_AUX_CHANNEL_D;
2199
2200 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2201 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2202 if (!master_ctl)
2203 return IRQ_NONE;
2204
2205 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2206
2207 /* Find, clear, then process each source of interrupt */
2208
2209 ret = gen8_gt_irq_handler(dev_priv, master_ctl);
2210
2211 if (master_ctl & GEN8_DE_MISC_IRQ) {
2212 tmp = I915_READ(GEN8_DE_MISC_IIR);
2213 if (tmp) {
2214 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2215 ret = IRQ_HANDLED;
2216 if (tmp & GEN8_DE_MISC_GSE)
2217 intel_opregion_asle_intr(dev);
2218 else
2219 DRM_ERROR("Unexpected DE Misc interrupt\n");
2220 }
2221 else
2222 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
2223 }
2224
2225 if (master_ctl & GEN8_DE_PORT_IRQ) {
2226 tmp = I915_READ(GEN8_DE_PORT_IIR);
2227 if (tmp) {
2228 bool found = false;
2229 u32 hotplug_trigger = 0;
2230
2231 if (IS_BROXTON(dev_priv))
2232 hotplug_trigger = tmp & BXT_DE_PORT_HOTPLUG_MASK;
2233 else if (IS_BROADWELL(dev_priv))
2234 hotplug_trigger = tmp & GEN8_PORT_DP_A_HOTPLUG;
2235
2236 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2237 ret = IRQ_HANDLED;
2238
2239 if (tmp & aux_mask) {
2240 dp_aux_irq_handler(dev);
2241 found = true;
2242 }
2243
2244 if (hotplug_trigger) {
2245 if (IS_BROXTON(dev))
2246 bxt_hpd_irq_handler(dev, hotplug_trigger, hpd_bxt);
2247 else
2248 ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_bdw);
2249 found = true;
2250 }
2251
2252 if (IS_BROXTON(dev) && (tmp & BXT_DE_PORT_GMBUS)) {
2253 gmbus_irq_handler(dev);
2254 found = true;
2255 }
2256
2257 if (!found)
2258 DRM_ERROR("Unexpected DE Port interrupt\n");
2259 }
2260 else
2261 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
2262 }
2263
2264 for_each_pipe(dev_priv, pipe) {
2265 uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
2266
2267 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2268 continue;
2269
2270 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2271 if (pipe_iir) {
2272 ret = IRQ_HANDLED;
2273 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
2274
2275 if (pipe_iir & GEN8_PIPE_VBLANK &&
2276 intel_pipe_handle_vblank(dev, pipe))
2277 intel_check_page_flip(dev, pipe);
2278
2279 if (INTEL_INFO(dev_priv)->gen >= 9)
2280 flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
2281 else
2282 flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
2283
2284 if (flip_done) {
2285 intel_prepare_page_flip(dev, pipe);
2286 intel_finish_page_flip_plane(dev, pipe);
2287 }
2288
2289 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2290 hsw_pipe_crc_irq_handler(dev, pipe);
2291
2292 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN)
2293 intel_cpu_fifo_underrun_irq_handler(dev_priv,
2294 pipe);
2295
2296
2297 if (INTEL_INFO(dev_priv)->gen >= 9)
2298 fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2299 else
2300 fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2301
2302 if (fault_errors)
2303 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2304 pipe_name(pipe),
2305 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
2306 } else
2307 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2308 }
2309
2310 if (HAS_PCH_SPLIT(dev) && !HAS_PCH_NOP(dev) &&
2311 master_ctl & GEN8_DE_PCH_IRQ) {
2312 /*
2313 * FIXME(BDW): Assume for now that the new interrupt handling
2314 * scheme also closed the SDE interrupt handling race we've seen
2315 * on older pch-split platforms. But this needs testing.
2316 */
2317 u32 pch_iir = I915_READ(SDEIIR);
2318 if (pch_iir) {
2319 I915_WRITE(SDEIIR, pch_iir);
2320 ret = IRQ_HANDLED;
2321
2322 if (HAS_PCH_SPT(dev_priv))
2323 spt_irq_handler(dev, pch_iir);
2324 else
2325 cpt_irq_handler(dev, pch_iir);
2326 } else
2327 DRM_ERROR("The master control interrupt lied (SDE)!\n");
2328
2329 }
2330
2331 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2332 POSTING_READ_FW(GEN8_MASTER_IRQ);
2333
2334 return ret;
2335 }
2336
2337 static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2338 bool reset_completed)
2339 {
2340 struct intel_engine_cs *ring;
2341 int i;
2342
2343 /*
2344 * Notify all waiters for GPU completion events that reset state has
2345 * been changed, and that they need to restart their wait after
2346 * checking for potential errors (and bail out to drop locks if there is
2347 * a gpu reset pending so that i915_error_work_func can acquire them).
2348 */
2349
2350 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2351 for_each_ring(ring, dev_priv, i)
2352 wake_up_all(&ring->irq_queue);
2353
2354 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2355 wake_up_all(&dev_priv->pending_flip_queue);
2356
2357 /*
2358 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2359 * reset state is cleared.
2360 */
2361 if (reset_completed)
2362 wake_up_all(&dev_priv->gpu_error.reset_queue);
2363 }
2364
2365 /**
2366 * i915_reset_and_wakeup - do process context error handling work
2367 *
2368 * Fire an error uevent so userspace can see that a hang or error
2369 * was detected.
2370 */
2371 static void i915_reset_and_wakeup(struct drm_device *dev)
2372 {
2373 struct drm_i915_private *dev_priv = to_i915(dev);
2374 struct i915_gpu_error *error = &dev_priv->gpu_error;
2375 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2376 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2377 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
2378 int ret;
2379
2380 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
2381
2382 /*
2383 * Note that there's only one work item which does gpu resets, so we
2384 * need not worry about concurrent gpu resets potentially incrementing
2385 * error->reset_counter twice. We only need to take care of another
2386 * racing irq/hangcheck declaring the gpu dead for a second time. A
2387 * quick check for that is good enough: schedule_work ensures the
2388 * correct ordering between hang detection and this work item, and since
2389 * the reset in-progress bit is only ever set by code outside of this
2390 * work we don't need to worry about any other races.
2391 */
2392 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
2393 DRM_DEBUG_DRIVER("resetting chip\n");
2394 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
2395 reset_event);
2396
2397 /*
2398 * In most cases it's guaranteed that we get here with an RPM
2399 * reference held, for example because there is a pending GPU
2400 * request that won't finish until the reset is done. This
2401 * isn't the case at least when we get here by doing a
2402 * simulated reset via debugs, so get an RPM reference.
2403 */
2404 intel_runtime_pm_get(dev_priv);
2405
2406 intel_prepare_reset(dev);
2407
2408 /*
2409 * All state reset _must_ be completed before we update the
2410 * reset counter, for otherwise waiters might miss the reset
2411 * pending state and not properly drop locks, resulting in
2412 * deadlocks with the reset work.
2413 */
2414 ret = i915_reset(dev);
2415
2416 intel_finish_reset(dev);
2417
2418 intel_runtime_pm_put(dev_priv);
2419
2420 if (ret == 0) {
2421 /*
2422 * After all the gem state is reset, increment the reset
2423 * counter and wake up everyone waiting for the reset to
2424 * complete.
2425 *
2426 * Since unlock operations are a one-sided barrier only,
2427 * we need to insert a barrier here to order any seqno
2428 * updates before
2429 * the counter increment.
2430 */
2431 smp_mb__before_atomic();
2432 atomic_inc(&dev_priv->gpu_error.reset_counter);
2433
2434 kobject_uevent_env(&dev->primary->kdev->kobj,
2435 KOBJ_CHANGE, reset_done_event);
2436 } else {
2437 atomic_set_mask(I915_WEDGED, &error->reset_counter);
2438 }
2439
2440 /*
2441 * Note: The wake_up also serves as a memory barrier so that
2442 * waiters see the update value of the reset counter atomic_t.
2443 */
2444 i915_error_wake_up(dev_priv, true);
2445 }
2446 }
2447
2448 static void i915_report_and_clear_eir(struct drm_device *dev)
2449 {
2450 struct drm_i915_private *dev_priv = dev->dev_private;
2451 uint32_t instdone[I915_NUM_INSTDONE_REG];
2452 u32 eir = I915_READ(EIR);
2453 int pipe, i;
2454
2455 if (!eir)
2456 return;
2457
2458 pr_err("render error detected, EIR: 0x%08x\n", eir);
2459
2460 i915_get_extra_instdone(dev, instdone);
2461
2462 if (IS_G4X(dev)) {
2463 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2464 u32 ipeir = I915_READ(IPEIR_I965);
2465
2466 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2467 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
2468 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2469 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
2470 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
2471 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
2472 I915_WRITE(IPEIR_I965, ipeir);
2473 POSTING_READ(IPEIR_I965);
2474 }
2475 if (eir & GM45_ERROR_PAGE_TABLE) {
2476 u32 pgtbl_err = I915_READ(PGTBL_ER);
2477 pr_err("page table error\n");
2478 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
2479 I915_WRITE(PGTBL_ER, pgtbl_err);
2480 POSTING_READ(PGTBL_ER);
2481 }
2482 }
2483
2484 if (!IS_GEN2(dev)) {
2485 if (eir & I915_ERROR_PAGE_TABLE) {
2486 u32 pgtbl_err = I915_READ(PGTBL_ER);
2487 pr_err("page table error\n");
2488 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
2489 I915_WRITE(PGTBL_ER, pgtbl_err);
2490 POSTING_READ(PGTBL_ER);
2491 }
2492 }
2493
2494 if (eir & I915_ERROR_MEMORY_REFRESH) {
2495 pr_err("memory refresh error:\n");
2496 for_each_pipe(dev_priv, pipe)
2497 pr_err("pipe %c stat: 0x%08x\n",
2498 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
2499 /* pipestat has already been acked */
2500 }
2501 if (eir & I915_ERROR_INSTRUCTION) {
2502 pr_err("instruction error\n");
2503 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
2504 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2505 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
2506 if (INTEL_INFO(dev)->gen < 4) {
2507 u32 ipeir = I915_READ(IPEIR);
2508
2509 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2510 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
2511 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
2512 I915_WRITE(IPEIR, ipeir);
2513 POSTING_READ(IPEIR);
2514 } else {
2515 u32 ipeir = I915_READ(IPEIR_I965);
2516
2517 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2518 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
2519 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
2520 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
2521 I915_WRITE(IPEIR_I965, ipeir);
2522 POSTING_READ(IPEIR_I965);
2523 }
2524 }
2525
2526 I915_WRITE(EIR, eir);
2527 POSTING_READ(EIR);
2528 eir = I915_READ(EIR);
2529 if (eir) {
2530 /*
2531 * some errors might have become stuck,
2532 * mask them.
2533 */
2534 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2535 I915_WRITE(EMR, I915_READ(EMR) | eir);
2536 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2537 }
2538 }
2539
2540 /**
2541 * i915_handle_error - handle a gpu error
2542 * @dev: drm device
2543 *
2544 * Do some basic checking of regsiter state at error time and
2545 * dump it to the syslog. Also call i915_capture_error_state() to make
2546 * sure we get a record and make it available in debugfs. Fire a uevent
2547 * so userspace knows something bad happened (should trigger collection
2548 * of a ring dump etc.).
2549 */
2550 void i915_handle_error(struct drm_device *dev, bool wedged,
2551 const char *fmt, ...)
2552 {
2553 struct drm_i915_private *dev_priv = dev->dev_private;
2554 va_list args;
2555 char error_msg[80];
2556
2557 va_start(args, fmt);
2558 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2559 va_end(args);
2560
2561 i915_capture_error_state(dev, wedged, error_msg);
2562 i915_report_and_clear_eir(dev);
2563
2564 if (wedged) {
2565 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2566 &dev_priv->gpu_error.reset_counter);
2567
2568 /*
2569 * Wakeup waiting processes so that the reset function
2570 * i915_reset_and_wakeup doesn't deadlock trying to grab
2571 * various locks. By bumping the reset counter first, the woken
2572 * processes will see a reset in progress and back off,
2573 * releasing their locks and then wait for the reset completion.
2574 * We must do this for _all_ gpu waiters that might hold locks
2575 * that the reset work needs to acquire.
2576 *
2577 * Note: The wake_up serves as the required memory barrier to
2578 * ensure that the waiters see the updated value of the reset
2579 * counter atomic_t.
2580 */
2581 i915_error_wake_up(dev_priv, false);
2582 }
2583
2584 i915_reset_and_wakeup(dev);
2585 }
2586
2587 /* Called from drm generic code, passed 'crtc' which
2588 * we use as a pipe index
2589 */
2590 static int i915_enable_vblank(struct drm_device *dev, int pipe)
2591 {
2592 struct drm_i915_private *dev_priv = dev->dev_private;
2593 unsigned long irqflags;
2594
2595 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2596 if (INTEL_INFO(dev)->gen >= 4)
2597 i915_enable_pipestat(dev_priv, pipe,
2598 PIPE_START_VBLANK_INTERRUPT_STATUS);
2599 else
2600 i915_enable_pipestat(dev_priv, pipe,
2601 PIPE_VBLANK_INTERRUPT_STATUS);
2602 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2603
2604 return 0;
2605 }
2606
2607 static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
2608 {
2609 struct drm_i915_private *dev_priv = dev->dev_private;
2610 unsigned long irqflags;
2611 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
2612 DE_PIPE_VBLANK(pipe);
2613
2614 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2615 ironlake_enable_display_irq(dev_priv, bit);
2616 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2617
2618 return 0;
2619 }
2620
2621 static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2622 {
2623 struct drm_i915_private *dev_priv = dev->dev_private;
2624 unsigned long irqflags;
2625
2626 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2627 i915_enable_pipestat(dev_priv, pipe,
2628 PIPE_START_VBLANK_INTERRUPT_STATUS);
2629 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2630
2631 return 0;
2632 }
2633
2634 static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2635 {
2636 struct drm_i915_private *dev_priv = dev->dev_private;
2637 unsigned long irqflags;
2638
2639 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2640 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2641 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2642 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
2643 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2644 return 0;
2645 }
2646
2647 /* Called from drm generic code, passed 'crtc' which
2648 * we use as a pipe index
2649 */
2650 static void i915_disable_vblank(struct drm_device *dev, int pipe)
2651 {
2652 struct drm_i915_private *dev_priv = dev->dev_private;
2653 unsigned long irqflags;
2654
2655 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2656 i915_disable_pipestat(dev_priv, pipe,
2657 PIPE_VBLANK_INTERRUPT_STATUS |
2658 PIPE_START_VBLANK_INTERRUPT_STATUS);
2659 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2660 }
2661
2662 static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
2663 {
2664 struct drm_i915_private *dev_priv = dev->dev_private;
2665 unsigned long irqflags;
2666 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
2667 DE_PIPE_VBLANK(pipe);
2668
2669 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2670 ironlake_disable_display_irq(dev_priv, bit);
2671 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2672 }
2673
2674 static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2675 {
2676 struct drm_i915_private *dev_priv = dev->dev_private;
2677 unsigned long irqflags;
2678
2679 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2680 i915_disable_pipestat(dev_priv, pipe,
2681 PIPE_START_VBLANK_INTERRUPT_STATUS);
2682 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2683 }
2684
2685 static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2686 {
2687 struct drm_i915_private *dev_priv = dev->dev_private;
2688 unsigned long irqflags;
2689
2690 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2691 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2692 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2693 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
2694 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2695 }
2696
2697 static bool
2698 ring_idle(struct intel_engine_cs *ring, u32 seqno)
2699 {
2700 return (list_empty(&ring->request_list) ||
2701 i915_seqno_passed(seqno, ring->last_submitted_seqno));
2702 }
2703
2704 static bool
2705 ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
2706 {
2707 if (INTEL_INFO(dev)->gen >= 8) {
2708 return (ipehr >> 23) == 0x1c;
2709 } else {
2710 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2711 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2712 MI_SEMAPHORE_REGISTER);
2713 }
2714 }
2715
2716 static struct intel_engine_cs *
2717 semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
2718 {
2719 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2720 struct intel_engine_cs *signaller;
2721 int i;
2722
2723 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
2724 for_each_ring(signaller, dev_priv, i) {
2725 if (ring == signaller)
2726 continue;
2727
2728 if (offset == signaller->semaphore.signal_ggtt[ring->id])
2729 return signaller;
2730 }
2731 } else {
2732 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2733
2734 for_each_ring(signaller, dev_priv, i) {
2735 if(ring == signaller)
2736 continue;
2737
2738 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
2739 return signaller;
2740 }
2741 }
2742
2743 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
2744 ring->id, ipehr, offset);
2745
2746 return NULL;
2747 }
2748
2749 static struct intel_engine_cs *
2750 semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
2751 {
2752 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2753 u32 cmd, ipehr, head;
2754 u64 offset = 0;
2755 int i, backwards;
2756
2757 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2758 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
2759 return NULL;
2760
2761 /*
2762 * HEAD is likely pointing to the dword after the actual command,
2763 * so scan backwards until we find the MBOX. But limit it to just 3
2764 * or 4 dwords depending on the semaphore wait command size.
2765 * Note that we don't care about ACTHD here since that might
2766 * point at at batch, and semaphores are always emitted into the
2767 * ringbuffer itself.
2768 */
2769 head = I915_READ_HEAD(ring) & HEAD_ADDR;
2770 backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
2771
2772 for (i = backwards; i; --i) {
2773 /*
2774 * Be paranoid and presume the hw has gone off into the wild -
2775 * our ring is smaller than what the hardware (and hence
2776 * HEAD_ADDR) allows. Also handles wrap-around.
2777 */
2778 head &= ring->buffer->size - 1;
2779
2780 /* This here seems to blow up */
2781 cmd = ioread32(ring->buffer->virtual_start + head);
2782 if (cmd == ipehr)
2783 break;
2784
2785 head -= 4;
2786 }
2787
2788 if (!i)
2789 return NULL;
2790
2791 *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
2792 if (INTEL_INFO(ring->dev)->gen >= 8) {
2793 offset = ioread32(ring->buffer->virtual_start + head + 12);
2794 offset <<= 32;
2795 offset = ioread32(ring->buffer->virtual_start + head + 8);
2796 }
2797 return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
2798 }
2799
2800 static int semaphore_passed(struct intel_engine_cs *ring)
2801 {
2802 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2803 struct intel_engine_cs *signaller;
2804 u32 seqno;
2805
2806 ring->hangcheck.deadlock++;
2807
2808 signaller = semaphore_waits_for(ring, &seqno);
2809 if (signaller == NULL)
2810 return -1;
2811
2812 /* Prevent pathological recursion due to driver bugs */
2813 if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
2814 return -1;
2815
2816 if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
2817 return 1;
2818
2819 /* cursory check for an unkickable deadlock */
2820 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2821 semaphore_passed(signaller) < 0)
2822 return -1;
2823
2824 return 0;
2825 }
2826
2827 static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2828 {
2829 struct intel_engine_cs *ring;
2830 int i;
2831
2832 for_each_ring(ring, dev_priv, i)
2833 ring->hangcheck.deadlock = 0;
2834 }
2835
2836 static enum intel_ring_hangcheck_action
2837 ring_stuck(struct intel_engine_cs *ring, u64 acthd)
2838 {
2839 struct drm_device *dev = ring->dev;
2840 struct drm_i915_private *dev_priv = dev->dev_private;
2841 u32 tmp;
2842
2843 if (acthd != ring->hangcheck.acthd) {
2844 if (acthd > ring->hangcheck.max_acthd) {
2845 ring->hangcheck.max_acthd = acthd;
2846 return HANGCHECK_ACTIVE;
2847 }
2848
2849 return HANGCHECK_ACTIVE_LOOP;
2850 }
2851
2852 if (IS_GEN2(dev))
2853 return HANGCHECK_HUNG;
2854
2855 /* Is the chip hanging on a WAIT_FOR_EVENT?
2856 * If so we can simply poke the RB_WAIT bit
2857 * and break the hang. This should work on
2858 * all but the second generation chipsets.
2859 */
2860 tmp = I915_READ_CTL(ring);
2861 if (tmp & RING_WAIT) {
2862 i915_handle_error(dev, false,
2863 "Kicking stuck wait on %s",
2864 ring->name);
2865 I915_WRITE_CTL(ring, tmp);
2866 return HANGCHECK_KICK;
2867 }
2868
2869 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2870 switch (semaphore_passed(ring)) {
2871 default:
2872 return HANGCHECK_HUNG;
2873 case 1:
2874 i915_handle_error(dev, false,
2875 "Kicking stuck semaphore on %s",
2876 ring->name);
2877 I915_WRITE_CTL(ring, tmp);
2878 return HANGCHECK_KICK;
2879 case 0:
2880 return HANGCHECK_WAIT;
2881 }
2882 }
2883
2884 return HANGCHECK_HUNG;
2885 }
2886
2887 /*
2888 * This is called when the chip hasn't reported back with completed
2889 * batchbuffers in a long time. We keep track per ring seqno progress and
2890 * if there are no progress, hangcheck score for that ring is increased.
2891 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2892 * we kick the ring. If we see no progress on three subsequent calls
2893 * we assume chip is wedged and try to fix it by resetting the chip.
2894 */
2895 static void i915_hangcheck_elapsed(struct work_struct *work)
2896 {
2897 struct drm_i915_private *dev_priv =
2898 container_of(work, typeof(*dev_priv),
2899 gpu_error.hangcheck_work.work);
2900 struct drm_device *dev = dev_priv->dev;
2901 struct intel_engine_cs *ring;
2902 int i;
2903 int busy_count = 0, rings_hung = 0;
2904 bool stuck[I915_NUM_RINGS] = { 0 };
2905 #define BUSY 1
2906 #define KICK 5
2907 #define HUNG 20
2908
2909 if (!i915.enable_hangcheck)
2910 return;
2911
2912 for_each_ring(ring, dev_priv, i) {
2913 u64 acthd;
2914 u32 seqno;
2915 bool busy = true;
2916
2917 semaphore_clear_deadlocks(dev_priv);
2918
2919 seqno = ring->get_seqno(ring, false);
2920 acthd = intel_ring_get_active_head(ring);
2921
2922 if (ring->hangcheck.seqno == seqno) {
2923 if (ring_idle(ring, seqno)) {
2924 ring->hangcheck.action = HANGCHECK_IDLE;
2925
2926 if (waitqueue_active(&ring->irq_queue)) {
2927 /* Issue a wake-up to catch stuck h/w. */
2928 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
2929 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2930 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2931 ring->name);
2932 else
2933 DRM_INFO("Fake missed irq on %s\n",
2934 ring->name);
2935 wake_up_all(&ring->irq_queue);
2936 }
2937 /* Safeguard against driver failure */
2938 ring->hangcheck.score += BUSY;
2939 } else
2940 busy = false;
2941 } else {
2942 /* We always increment the hangcheck score
2943 * if the ring is busy and still processing
2944 * the same request, so that no single request
2945 * can run indefinitely (such as a chain of
2946 * batches). The only time we do not increment
2947 * the hangcheck score on this ring, if this
2948 * ring is in a legitimate wait for another
2949 * ring. In that case the waiting ring is a
2950 * victim and we want to be sure we catch the
2951 * right culprit. Then every time we do kick
2952 * the ring, add a small increment to the
2953 * score so that we can catch a batch that is
2954 * being repeatedly kicked and so responsible
2955 * for stalling the machine.
2956 */
2957 ring->hangcheck.action = ring_stuck(ring,
2958 acthd);
2959
2960 switch (ring->hangcheck.action) {
2961 case HANGCHECK_IDLE:
2962 case HANGCHECK_WAIT:
2963 case HANGCHECK_ACTIVE:
2964 break;
2965 case HANGCHECK_ACTIVE_LOOP:
2966 ring->hangcheck.score += BUSY;
2967 break;
2968 case HANGCHECK_KICK:
2969 ring->hangcheck.score += KICK;
2970 break;
2971 case HANGCHECK_HUNG:
2972 ring->hangcheck.score += HUNG;
2973 stuck[i] = true;
2974 break;
2975 }
2976 }
2977 } else {
2978 ring->hangcheck.action = HANGCHECK_ACTIVE;
2979
2980 /* Gradually reduce the count so that we catch DoS
2981 * attempts across multiple batches.
2982 */
2983 if (ring->hangcheck.score > 0)
2984 ring->hangcheck.score--;
2985
2986 ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
2987 }
2988
2989 ring->hangcheck.seqno = seqno;
2990 ring->hangcheck.acthd = acthd;
2991 busy_count += busy;
2992 }
2993
2994 for_each_ring(ring, dev_priv, i) {
2995 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
2996 DRM_INFO("%s on %s\n",
2997 stuck[i] ? "stuck" : "no progress",
2998 ring->name);
2999 rings_hung++;
3000 }
3001 }
3002
3003 if (rings_hung)
3004 return i915_handle_error(dev, true, "Ring hung");
3005
3006 if (busy_count)
3007 /* Reset timer case chip hangs without another request
3008 * being added */
3009 i915_queue_hangcheck(dev);
3010 }
3011
3012 void i915_queue_hangcheck(struct drm_device *dev)
3013 {
3014 struct i915_gpu_error *e = &to_i915(dev)->gpu_error;
3015
3016 if (!i915.enable_hangcheck)
3017 return;
3018
3019 /* Don't continually defer the hangcheck so that it is always run at
3020 * least once after work has been scheduled on any ring. Otherwise,
3021 * we will ignore a hung ring if a second ring is kept busy.
3022 */
3023
3024 queue_delayed_work(e->hangcheck_wq, &e->hangcheck_work,
3025 round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES));
3026 }
3027
3028 static void ibx_irq_reset(struct drm_device *dev)
3029 {
3030 struct drm_i915_private *dev_priv = dev->dev_private;
3031
3032 if (HAS_PCH_NOP(dev))
3033 return;
3034
3035 GEN5_IRQ_RESET(SDE);
3036
3037 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3038 I915_WRITE(SERR_INT, 0xffffffff);
3039 }
3040
3041 /*
3042 * SDEIER is also touched by the interrupt handler to work around missed PCH
3043 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3044 * instead we unconditionally enable all PCH interrupt sources here, but then
3045 * only unmask them as needed with SDEIMR.
3046 *
3047 * This function needs to be called before interrupts are enabled.
3048 */
3049 static void ibx_irq_pre_postinstall(struct drm_device *dev)
3050 {
3051 struct drm_i915_private *dev_priv = dev->dev_private;
3052
3053 if (HAS_PCH_NOP(dev))
3054 return;
3055
3056 WARN_ON(I915_READ(SDEIER) != 0);
3057 I915_WRITE(SDEIER, 0xffffffff);
3058 POSTING_READ(SDEIER);
3059 }
3060
3061 static void gen5_gt_irq_reset(struct drm_device *dev)
3062 {
3063 struct drm_i915_private *dev_priv = dev->dev_private;
3064
3065 GEN5_IRQ_RESET(GT);
3066 if (INTEL_INFO(dev)->gen >= 6)
3067 GEN5_IRQ_RESET(GEN6_PM);
3068 }
3069
3070 /* drm_dma.h hooks
3071 */
3072 static void ironlake_irq_reset(struct drm_device *dev)
3073 {
3074 struct drm_i915_private *dev_priv = dev->dev_private;
3075
3076 I915_WRITE(HWSTAM, 0xffffffff);
3077
3078 GEN5_IRQ_RESET(DE);
3079 if (IS_GEN7(dev))
3080 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3081
3082 gen5_gt_irq_reset(dev);
3083
3084 ibx_irq_reset(dev);
3085 }
3086
3087 static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3088 {
3089 enum pipe pipe;
3090
3091 i915_hotplug_interrupt_update(dev_priv, 0xFFFFFFFF, 0);
3092 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3093
3094 for_each_pipe(dev_priv, pipe)
3095 I915_WRITE(PIPESTAT(pipe), 0xffff);
3096
3097 GEN5_IRQ_RESET(VLV_);
3098 }
3099
3100 static void valleyview_irq_preinstall(struct drm_device *dev)
3101 {
3102 struct drm_i915_private *dev_priv = dev->dev_private;
3103
3104 /* VLV magic */
3105 I915_WRITE(VLV_IMR, 0);
3106 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
3107 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
3108 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
3109
3110 gen5_gt_irq_reset(dev);
3111
3112 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3113
3114 vlv_display_irq_reset(dev_priv);
3115 }
3116
3117 static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3118 {
3119 GEN8_IRQ_RESET_NDX(GT, 0);
3120 GEN8_IRQ_RESET_NDX(GT, 1);
3121 GEN8_IRQ_RESET_NDX(GT, 2);
3122 GEN8_IRQ_RESET_NDX(GT, 3);
3123 }
3124
3125 static void gen8_irq_reset(struct drm_device *dev)
3126 {
3127 struct drm_i915_private *dev_priv = dev->dev_private;
3128 int pipe;
3129
3130 I915_WRITE(GEN8_MASTER_IRQ, 0);
3131 POSTING_READ(GEN8_MASTER_IRQ);
3132
3133 gen8_gt_irq_reset(dev_priv);
3134
3135 for_each_pipe(dev_priv, pipe)
3136 if (intel_display_power_is_enabled(dev_priv,
3137 POWER_DOMAIN_PIPE(pipe)))
3138 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
3139
3140 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3141 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3142 GEN5_IRQ_RESET(GEN8_PCU_);
3143
3144 if (HAS_PCH_SPLIT(dev))
3145 ibx_irq_reset(dev);
3146 }
3147
3148 void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3149 unsigned int pipe_mask)
3150 {
3151 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
3152
3153 spin_lock_irq(&dev_priv->irq_lock);
3154 if (pipe_mask & 1 << PIPE_A)
3155 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_A,
3156 dev_priv->de_irq_mask[PIPE_A],
3157 ~dev_priv->de_irq_mask[PIPE_A] | extra_ier);
3158 if (pipe_mask & 1 << PIPE_B)
3159 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B,
3160 dev_priv->de_irq_mask[PIPE_B],
3161 ~dev_priv->de_irq_mask[PIPE_B] | extra_ier);
3162 if (pipe_mask & 1 << PIPE_C)
3163 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C,
3164 dev_priv->de_irq_mask[PIPE_C],
3165 ~dev_priv->de_irq_mask[PIPE_C] | extra_ier);
3166 spin_unlock_irq(&dev_priv->irq_lock);
3167 }
3168
3169 static void cherryview_irq_preinstall(struct drm_device *dev)
3170 {
3171 struct drm_i915_private *dev_priv = dev->dev_private;
3172
3173 I915_WRITE(GEN8_MASTER_IRQ, 0);
3174 POSTING_READ(GEN8_MASTER_IRQ);
3175
3176 gen8_gt_irq_reset(dev_priv);
3177
3178 GEN5_IRQ_RESET(GEN8_PCU_);
3179
3180 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3181
3182 vlv_display_irq_reset(dev_priv);
3183 }
3184
3185 static u32 intel_hpd_enabled_irqs(struct drm_device *dev,
3186 const u32 hpd[HPD_NUM_PINS])
3187 {
3188 struct drm_i915_private *dev_priv = to_i915(dev);
3189 struct intel_encoder *encoder;
3190 u32 enabled_irqs = 0;
3191
3192 for_each_intel_encoder(dev, encoder)
3193 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3194 enabled_irqs |= hpd[encoder->hpd_pin];
3195
3196 return enabled_irqs;
3197 }
3198
3199 static void ibx_hpd_irq_setup(struct drm_device *dev)
3200 {
3201 struct drm_i915_private *dev_priv = dev->dev_private;
3202 u32 hotplug_irqs, hotplug, enabled_irqs;
3203
3204 if (HAS_PCH_IBX(dev)) {
3205 hotplug_irqs = SDE_HOTPLUG_MASK;
3206 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ibx);
3207 } else {
3208 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
3209 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_cpt);
3210 }
3211
3212 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3213
3214 /*
3215 * Enable digital hotplug on the PCH, and configure the DP short pulse
3216 * duration to 2ms (which is the minimum in the Display Port spec).
3217 * The pulse duration bits are reserved on LPT+.
3218 */
3219 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3220 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3221 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3222 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3223 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3224 /*
3225 * When CPU and PCH are on the same package, port A
3226 * HPD must be enabled in both north and south.
3227 */
3228 if (HAS_PCH_LPT_LP(dev))
3229 hotplug |= PORTA_HOTPLUG_ENABLE;
3230 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3231 }
3232
3233 static void spt_hpd_irq_setup(struct drm_device *dev)
3234 {
3235 struct drm_i915_private *dev_priv = dev->dev_private;
3236 u32 hotplug_irqs, hotplug, enabled_irqs;
3237
3238 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
3239 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_spt);
3240
3241 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3242
3243 /* Enable digital hotplug on the PCH */
3244 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3245 hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
3246 PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE;
3247 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3248
3249 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3250 hotplug |= PORTE_HOTPLUG_ENABLE;
3251 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3252 }
3253
3254 static void ilk_hpd_irq_setup(struct drm_device *dev)
3255 {
3256 struct drm_i915_private *dev_priv = dev->dev_private;
3257 u32 hotplug_irqs, hotplug, enabled_irqs;
3258
3259 if (INTEL_INFO(dev)->gen >= 8) {
3260 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
3261 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_bdw);
3262
3263 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3264 } else if (INTEL_INFO(dev)->gen >= 7) {
3265 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
3266 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ivb);
3267
3268 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3269 } else {
3270 hotplug_irqs = DE_DP_A_HOTPLUG;
3271 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ilk);
3272
3273 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3274 }
3275
3276 /*
3277 * Enable digital hotplug on the CPU, and configure the DP short pulse
3278 * duration to 2ms (which is the minimum in the Display Port spec)
3279 * The pulse duration bits are reserved on HSW+.
3280 */
3281 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3282 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3283 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms;
3284 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3285
3286 ibx_hpd_irq_setup(dev);
3287 }
3288
3289 static void bxt_hpd_irq_setup(struct drm_device *dev)
3290 {
3291 struct drm_i915_private *dev_priv = dev->dev_private;
3292 u32 hotplug_irqs, hotplug, enabled_irqs;
3293
3294 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_bxt);
3295 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3296
3297 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3298
3299 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3300 hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE |
3301 PORTA_HOTPLUG_ENABLE;
3302 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3303 }
3304
3305 static void ibx_irq_postinstall(struct drm_device *dev)
3306 {
3307 struct drm_i915_private *dev_priv = dev->dev_private;
3308 u32 mask;
3309
3310 if (HAS_PCH_NOP(dev))
3311 return;
3312
3313 if (HAS_PCH_IBX(dev))
3314 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
3315 else
3316 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
3317
3318 GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
3319 I915_WRITE(SDEIMR, ~mask);
3320 }
3321
3322 static void gen5_gt_irq_postinstall(struct drm_device *dev)
3323 {
3324 struct drm_i915_private *dev_priv = dev->dev_private;
3325 u32 pm_irqs, gt_irqs;
3326
3327 pm_irqs = gt_irqs = 0;
3328
3329 dev_priv->gt_irq_mask = ~0;
3330 if (HAS_L3_DPF(dev)) {
3331 /* L3 parity interrupt is always unmasked. */
3332 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3333 gt_irqs |= GT_PARITY_ERROR(dev);
3334 }
3335
3336 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3337 if (IS_GEN5(dev)) {
3338 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3339 ILK_BSD_USER_INTERRUPT;
3340 } else {
3341 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3342 }
3343
3344 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
3345
3346 if (INTEL_INFO(dev)->gen >= 6) {
3347 /*
3348 * RPS interrupts will get enabled/disabled on demand when RPS
3349 * itself is enabled/disabled.
3350 */
3351 if (HAS_VEBOX(dev))
3352 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3353
3354 dev_priv->pm_irq_mask = 0xffffffff;
3355 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
3356 }
3357 }
3358
3359 static int ironlake_irq_postinstall(struct drm_device *dev)
3360 {
3361 struct drm_i915_private *dev_priv = dev->dev_private;
3362 u32 display_mask, extra_mask;
3363
3364 if (INTEL_INFO(dev)->gen >= 7) {
3365 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3366 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3367 DE_PLANEB_FLIP_DONE_IVB |
3368 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
3369 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
3370 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3371 DE_DP_A_HOTPLUG_IVB);
3372 } else {
3373 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3374 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
3375 DE_AUX_CHANNEL_A |
3376 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3377 DE_POISON);
3378 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3379 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3380 DE_DP_A_HOTPLUG);
3381 }
3382
3383 dev_priv->irq_mask = ~display_mask;
3384
3385 I915_WRITE(HWSTAM, 0xeffe);
3386
3387 ibx_irq_pre_postinstall(dev);
3388
3389 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
3390
3391 gen5_gt_irq_postinstall(dev);
3392
3393 ibx_irq_postinstall(dev);
3394
3395 if (IS_IRONLAKE_M(dev)) {
3396 /* Enable PCU event interrupts
3397 *
3398 * spinlocking not required here for correctness since interrupt
3399 * setup is guaranteed to run in single-threaded context. But we
3400 * need it to make the assert_spin_locked happy. */
3401 spin_lock_irq(&dev_priv->irq_lock);
3402 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
3403 spin_unlock_irq(&dev_priv->irq_lock);
3404 }
3405
3406 return 0;
3407 }
3408
3409 static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3410 {
3411 u32 pipestat_mask;
3412 u32 iir_mask;
3413 enum pipe pipe;
3414
3415 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3416 PIPE_FIFO_UNDERRUN_STATUS;
3417
3418 for_each_pipe(dev_priv, pipe)
3419 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
3420 POSTING_READ(PIPESTAT(PIPE_A));
3421
3422 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3423 PIPE_CRC_DONE_INTERRUPT_STATUS;
3424
3425 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3426 for_each_pipe(dev_priv, pipe)
3427 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3428
3429 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3430 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3431 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3432 if (IS_CHERRYVIEW(dev_priv))
3433 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
3434 dev_priv->irq_mask &= ~iir_mask;
3435
3436 I915_WRITE(VLV_IIR, iir_mask);
3437 I915_WRITE(VLV_IIR, iir_mask);
3438 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3439 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3440 POSTING_READ(VLV_IMR);
3441 }
3442
3443 static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3444 {
3445 u32 pipestat_mask;
3446 u32 iir_mask;
3447 enum pipe pipe;
3448
3449 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3450 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3451 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3452 if (IS_CHERRYVIEW(dev_priv))
3453 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
3454
3455 dev_priv->irq_mask |= iir_mask;
3456 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3457 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3458 I915_WRITE(VLV_IIR, iir_mask);
3459 I915_WRITE(VLV_IIR, iir_mask);
3460 POSTING_READ(VLV_IIR);
3461
3462 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3463 PIPE_CRC_DONE_INTERRUPT_STATUS;
3464
3465 i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3466 for_each_pipe(dev_priv, pipe)
3467 i915_disable_pipestat(dev_priv, pipe, pipestat_mask);
3468
3469 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3470 PIPE_FIFO_UNDERRUN_STATUS;
3471
3472 for_each_pipe(dev_priv, pipe)
3473 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
3474 POSTING_READ(PIPESTAT(PIPE_A));
3475 }
3476
3477 void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3478 {
3479 assert_spin_locked(&dev_priv->irq_lock);
3480
3481 if (dev_priv->display_irqs_enabled)
3482 return;
3483
3484 dev_priv->display_irqs_enabled = true;
3485
3486 if (intel_irqs_enabled(dev_priv))
3487 valleyview_display_irqs_install(dev_priv);
3488 }
3489
3490 void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3491 {
3492 assert_spin_locked(&dev_priv->irq_lock);
3493
3494 if (!dev_priv->display_irqs_enabled)
3495 return;
3496
3497 dev_priv->display_irqs_enabled = false;
3498
3499 if (intel_irqs_enabled(dev_priv))
3500 valleyview_display_irqs_uninstall(dev_priv);
3501 }
3502
3503 static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3504 {
3505 dev_priv->irq_mask = ~0;
3506
3507 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
3508 POSTING_READ(PORT_HOTPLUG_EN);
3509
3510 I915_WRITE(VLV_IIR, 0xffffffff);
3511 I915_WRITE(VLV_IIR, 0xffffffff);
3512 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3513 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3514 POSTING_READ(VLV_IMR);
3515
3516 /* Interrupt setup is already guaranteed to be single-threaded, this is
3517 * just to make the assert_spin_locked check happy. */
3518 spin_lock_irq(&dev_priv->irq_lock);
3519 if (dev_priv->display_irqs_enabled)
3520 valleyview_display_irqs_install(dev_priv);
3521 spin_unlock_irq(&dev_priv->irq_lock);
3522 }
3523
3524 static int valleyview_irq_postinstall(struct drm_device *dev)
3525 {
3526 struct drm_i915_private *dev_priv = dev->dev_private;
3527
3528 vlv_display_irq_postinstall(dev_priv);
3529
3530 gen5_gt_irq_postinstall(dev);
3531
3532 /* ack & enable invalid PTE error interrupts */
3533 #if 0 /* FIXME: add support to irq handler for checking these bits */
3534 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3535 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3536 #endif
3537
3538 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
3539
3540 return 0;
3541 }
3542
3543 static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3544 {
3545 /* These are interrupts we'll toggle with the ring mask register */
3546 uint32_t gt_interrupts[] = {
3547 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
3548 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
3549 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
3550 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3551 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
3552 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3553 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3554 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3555 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
3556 0,
3557 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3558 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
3559 };
3560
3561 dev_priv->pm_irq_mask = 0xffffffff;
3562 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3563 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
3564 /*
3565 * RPS interrupts will get enabled/disabled on demand when RPS itself
3566 * is enabled/disabled.
3567 */
3568 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
3569 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
3570 }
3571
3572 static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3573 {
3574 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3575 uint32_t de_pipe_enables;
3576 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3577 u32 de_port_enables;
3578 enum pipe pipe;
3579
3580 if (INTEL_INFO(dev_priv)->gen >= 9) {
3581 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3582 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
3583 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3584 GEN9_AUX_CHANNEL_D;
3585 if (IS_BROXTON(dev_priv))
3586 de_port_masked |= BXT_DE_PORT_GMBUS;
3587 } else {
3588 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3589 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
3590 }
3591
3592 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3593 GEN8_PIPE_FIFO_UNDERRUN;
3594
3595 de_port_enables = de_port_masked;
3596 if (IS_BROXTON(dev_priv))
3597 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3598 else if (IS_BROADWELL(dev_priv))
3599 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3600
3601 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3602 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3603 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
3604
3605 for_each_pipe(dev_priv, pipe)
3606 if (intel_display_power_is_enabled(dev_priv,
3607 POWER_DOMAIN_PIPE(pipe)))
3608 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3609 dev_priv->de_irq_mask[pipe],
3610 de_pipe_enables);
3611
3612 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3613 }
3614
3615 static int gen8_irq_postinstall(struct drm_device *dev)
3616 {
3617 struct drm_i915_private *dev_priv = dev->dev_private;
3618
3619 if (HAS_PCH_SPLIT(dev))
3620 ibx_irq_pre_postinstall(dev);
3621
3622 gen8_gt_irq_postinstall(dev_priv);
3623 gen8_de_irq_postinstall(dev_priv);
3624
3625 if (HAS_PCH_SPLIT(dev))
3626 ibx_irq_postinstall(dev);
3627
3628 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3629 POSTING_READ(GEN8_MASTER_IRQ);
3630
3631 return 0;
3632 }
3633
3634 static int cherryview_irq_postinstall(struct drm_device *dev)
3635 {
3636 struct drm_i915_private *dev_priv = dev->dev_private;
3637
3638 vlv_display_irq_postinstall(dev_priv);
3639
3640 gen8_gt_irq_postinstall(dev_priv);
3641
3642 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3643 POSTING_READ(GEN8_MASTER_IRQ);
3644
3645 return 0;
3646 }
3647
3648 static void gen8_irq_uninstall(struct drm_device *dev)
3649 {
3650 struct drm_i915_private *dev_priv = dev->dev_private;
3651
3652 if (!dev_priv)
3653 return;
3654
3655 gen8_irq_reset(dev);
3656 }
3657
3658 static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv)
3659 {
3660 /* Interrupt setup is already guaranteed to be single-threaded, this is
3661 * just to make the assert_spin_locked check happy. */
3662 spin_lock_irq(&dev_priv->irq_lock);
3663 if (dev_priv->display_irqs_enabled)
3664 valleyview_display_irqs_uninstall(dev_priv);
3665 spin_unlock_irq(&dev_priv->irq_lock);
3666
3667 vlv_display_irq_reset(dev_priv);
3668
3669 dev_priv->irq_mask = ~0;
3670 }
3671
3672 static void valleyview_irq_uninstall(struct drm_device *dev)
3673 {
3674 struct drm_i915_private *dev_priv = dev->dev_private;
3675
3676 if (!dev_priv)
3677 return;
3678
3679 I915_WRITE(VLV_MASTER_IER, 0);
3680
3681 gen5_gt_irq_reset(dev);
3682
3683 I915_WRITE(HWSTAM, 0xffffffff);
3684
3685 vlv_display_irq_uninstall(dev_priv);
3686 }
3687
3688 static void cherryview_irq_uninstall(struct drm_device *dev)
3689 {
3690 struct drm_i915_private *dev_priv = dev->dev_private;
3691
3692 if (!dev_priv)
3693 return;
3694
3695 I915_WRITE(GEN8_MASTER_IRQ, 0);
3696 POSTING_READ(GEN8_MASTER_IRQ);
3697
3698 gen8_gt_irq_reset(dev_priv);
3699
3700 GEN5_IRQ_RESET(GEN8_PCU_);
3701
3702 vlv_display_irq_uninstall(dev_priv);
3703 }
3704
3705 static void ironlake_irq_uninstall(struct drm_device *dev)
3706 {
3707 struct drm_i915_private *dev_priv = dev->dev_private;
3708
3709 if (!dev_priv)
3710 return;
3711
3712 ironlake_irq_reset(dev);
3713 }
3714
3715 static void i8xx_irq_preinstall(struct drm_device * dev)
3716 {
3717 struct drm_i915_private *dev_priv = dev->dev_private;
3718 int pipe;
3719
3720 for_each_pipe(dev_priv, pipe)
3721 I915_WRITE(PIPESTAT(pipe), 0);
3722 I915_WRITE16(IMR, 0xffff);
3723 I915_WRITE16(IER, 0x0);
3724 POSTING_READ16(IER);
3725 }
3726
3727 static int i8xx_irq_postinstall(struct drm_device *dev)
3728 {
3729 struct drm_i915_private *dev_priv = dev->dev_private;
3730
3731 I915_WRITE16(EMR,
3732 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3733
3734 /* Unmask the interrupts that we always want on. */
3735 dev_priv->irq_mask =
3736 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3737 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3738 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3739 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
3740 I915_WRITE16(IMR, dev_priv->irq_mask);
3741
3742 I915_WRITE16(IER,
3743 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3744 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3745 I915_USER_INTERRUPT);
3746 POSTING_READ16(IER);
3747
3748 /* Interrupt setup is already guaranteed to be single-threaded, this is
3749 * just to make the assert_spin_locked check happy. */
3750 spin_lock_irq(&dev_priv->irq_lock);
3751 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3752 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3753 spin_unlock_irq(&dev_priv->irq_lock);
3754
3755 return 0;
3756 }
3757
3758 /*
3759 * Returns true when a page flip has completed.
3760 */
3761 static bool i8xx_handle_vblank(struct drm_device *dev,
3762 int plane, int pipe, u32 iir)
3763 {
3764 struct drm_i915_private *dev_priv = dev->dev_private;
3765 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3766
3767 if (!intel_pipe_handle_vblank(dev, pipe))
3768 return false;
3769
3770 if ((iir & flip_pending) == 0)
3771 goto check_page_flip;
3772
3773 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3774 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3775 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3776 * the flip is completed (no longer pending). Since this doesn't raise
3777 * an interrupt per se, we watch for the change at vblank.
3778 */
3779 if (I915_READ16(ISR) & flip_pending)
3780 goto check_page_flip;
3781
3782 intel_prepare_page_flip(dev, plane);
3783 intel_finish_page_flip(dev, pipe);
3784 return true;
3785
3786 check_page_flip:
3787 intel_check_page_flip(dev, pipe);
3788 return false;
3789 }
3790
3791 static irqreturn_t i8xx_irq_handler(int irq, void *arg)
3792 {
3793 struct drm_device *dev = arg;
3794 struct drm_i915_private *dev_priv = dev->dev_private;
3795 u16 iir, new_iir;
3796 u32 pipe_stats[2];
3797 int pipe;
3798 u16 flip_mask =
3799 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3800 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3801
3802 if (!intel_irqs_enabled(dev_priv))
3803 return IRQ_NONE;
3804
3805 iir = I915_READ16(IIR);
3806 if (iir == 0)
3807 return IRQ_NONE;
3808
3809 while (iir & ~flip_mask) {
3810 /* Can't rely on pipestat interrupt bit in iir as it might
3811 * have been cleared after the pipestat interrupt was received.
3812 * It doesn't set the bit in iir again, but it still produces
3813 * interrupts (for non-MSI).
3814 */
3815 spin_lock(&dev_priv->irq_lock);
3816 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3817 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3818
3819 for_each_pipe(dev_priv, pipe) {
3820 int reg = PIPESTAT(pipe);
3821 pipe_stats[pipe] = I915_READ(reg);
3822
3823 /*
3824 * Clear the PIPE*STAT regs before the IIR
3825 */
3826 if (pipe_stats[pipe] & 0x8000ffff)
3827 I915_WRITE(reg, pipe_stats[pipe]);
3828 }
3829 spin_unlock(&dev_priv->irq_lock);
3830
3831 I915_WRITE16(IIR, iir & ~flip_mask);
3832 new_iir = I915_READ16(IIR); /* Flush posted writes */
3833
3834 if (iir & I915_USER_INTERRUPT)
3835 notify_ring(&dev_priv->ring[RCS]);
3836
3837 for_each_pipe(dev_priv, pipe) {
3838 int plane = pipe;
3839 if (HAS_FBC(dev))
3840 plane = !plane;
3841
3842 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3843 i8xx_handle_vblank(dev, plane, pipe, iir))
3844 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
3845
3846 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
3847 i9xx_pipe_crc_irq_handler(dev, pipe);
3848
3849 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3850 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3851 pipe);
3852 }
3853
3854 iir = new_iir;
3855 }
3856
3857 return IRQ_HANDLED;
3858 }
3859
3860 static void i8xx_irq_uninstall(struct drm_device * dev)
3861 {
3862 struct drm_i915_private *dev_priv = dev->dev_private;
3863 int pipe;
3864
3865 for_each_pipe(dev_priv, pipe) {
3866 /* Clear enable bits; then clear status bits */
3867 I915_WRITE(PIPESTAT(pipe), 0);
3868 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3869 }
3870 I915_WRITE16(IMR, 0xffff);
3871 I915_WRITE16(IER, 0x0);
3872 I915_WRITE16(IIR, I915_READ16(IIR));
3873 }
3874
3875 static void i915_irq_preinstall(struct drm_device * dev)
3876 {
3877 struct drm_i915_private *dev_priv = dev->dev_private;
3878 int pipe;
3879
3880 if (I915_HAS_HOTPLUG(dev)) {
3881 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
3882 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3883 }
3884
3885 I915_WRITE16(HWSTAM, 0xeffe);
3886 for_each_pipe(dev_priv, pipe)
3887 I915_WRITE(PIPESTAT(pipe), 0);
3888 I915_WRITE(IMR, 0xffffffff);
3889 I915_WRITE(IER, 0x0);
3890 POSTING_READ(IER);
3891 }
3892
3893 static int i915_irq_postinstall(struct drm_device *dev)
3894 {
3895 struct drm_i915_private *dev_priv = dev->dev_private;
3896 u32 enable_mask;
3897
3898 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3899
3900 /* Unmask the interrupts that we always want on. */
3901 dev_priv->irq_mask =
3902 ~(I915_ASLE_INTERRUPT |
3903 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3904 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3905 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3906 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
3907
3908 enable_mask =
3909 I915_ASLE_INTERRUPT |
3910 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3911 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3912 I915_USER_INTERRUPT;
3913
3914 if (I915_HAS_HOTPLUG(dev)) {
3915 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
3916 POSTING_READ(PORT_HOTPLUG_EN);
3917
3918 /* Enable in IER... */
3919 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3920 /* and unmask in IMR */
3921 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3922 }
3923
3924 I915_WRITE(IMR, dev_priv->irq_mask);
3925 I915_WRITE(IER, enable_mask);
3926 POSTING_READ(IER);
3927
3928 i915_enable_asle_pipestat(dev);
3929
3930 /* Interrupt setup is already guaranteed to be single-threaded, this is
3931 * just to make the assert_spin_locked check happy. */
3932 spin_lock_irq(&dev_priv->irq_lock);
3933 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3934 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
3935 spin_unlock_irq(&dev_priv->irq_lock);
3936
3937 return 0;
3938 }
3939
3940 /*
3941 * Returns true when a page flip has completed.
3942 */
3943 static bool i915_handle_vblank(struct drm_device *dev,
3944 int plane, int pipe, u32 iir)
3945 {
3946 struct drm_i915_private *dev_priv = dev->dev_private;
3947 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3948
3949 if (!intel_pipe_handle_vblank(dev, pipe))
3950 return false;
3951
3952 if ((iir & flip_pending) == 0)
3953 goto check_page_flip;
3954
3955 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3956 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3957 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3958 * the flip is completed (no longer pending). Since this doesn't raise
3959 * an interrupt per se, we watch for the change at vblank.
3960 */
3961 if (I915_READ(ISR) & flip_pending)
3962 goto check_page_flip;
3963
3964 intel_prepare_page_flip(dev, plane);
3965 intel_finish_page_flip(dev, pipe);
3966 return true;
3967
3968 check_page_flip:
3969 intel_check_page_flip(dev, pipe);
3970 return false;
3971 }
3972
3973 static irqreturn_t i915_irq_handler(int irq, void *arg)
3974 {
3975 struct drm_device *dev = arg;
3976 struct drm_i915_private *dev_priv = dev->dev_private;
3977 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
3978 u32 flip_mask =
3979 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3980 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3981 int pipe, ret = IRQ_NONE;
3982
3983 if (!intel_irqs_enabled(dev_priv))
3984 return IRQ_NONE;
3985
3986 iir = I915_READ(IIR);
3987 do {
3988 bool irq_received = (iir & ~flip_mask) != 0;
3989 bool blc_event = false;
3990
3991 /* Can't rely on pipestat interrupt bit in iir as it might
3992 * have been cleared after the pipestat interrupt was received.
3993 * It doesn't set the bit in iir again, but it still produces
3994 * interrupts (for non-MSI).
3995 */
3996 spin_lock(&dev_priv->irq_lock);
3997 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3998 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3999
4000 for_each_pipe(dev_priv, pipe) {
4001 int reg = PIPESTAT(pipe);
4002 pipe_stats[pipe] = I915_READ(reg);
4003
4004 /* Clear the PIPE*STAT regs before the IIR */
4005 if (pipe_stats[pipe] & 0x8000ffff) {
4006 I915_WRITE(reg, pipe_stats[pipe]);
4007 irq_received = true;
4008 }
4009 }
4010 spin_unlock(&dev_priv->irq_lock);
4011
4012 if (!irq_received)
4013 break;
4014
4015 /* Consume port. Then clear IIR or we'll miss events */
4016 if (I915_HAS_HOTPLUG(dev) &&
4017 iir & I915_DISPLAY_PORT_INTERRUPT)
4018 i9xx_hpd_irq_handler(dev);
4019
4020 I915_WRITE(IIR, iir & ~flip_mask);
4021 new_iir = I915_READ(IIR); /* Flush posted writes */
4022
4023 if (iir & I915_USER_INTERRUPT)
4024 notify_ring(&dev_priv->ring[RCS]);
4025
4026 for_each_pipe(dev_priv, pipe) {
4027 int plane = pipe;
4028 if (HAS_FBC(dev))
4029 plane = !plane;
4030
4031 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4032 i915_handle_vblank(dev, plane, pipe, iir))
4033 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
4034
4035 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4036 blc_event = true;
4037
4038 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
4039 i9xx_pipe_crc_irq_handler(dev, pipe);
4040
4041 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4042 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4043 pipe);
4044 }
4045
4046 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4047 intel_opregion_asle_intr(dev);
4048
4049 /* With MSI, interrupts are only generated when iir
4050 * transitions from zero to nonzero. If another bit got
4051 * set while we were handling the existing iir bits, then
4052 * we would never get another interrupt.
4053 *
4054 * This is fine on non-MSI as well, as if we hit this path
4055 * we avoid exiting the interrupt handler only to generate
4056 * another one.
4057 *
4058 * Note that for MSI this could cause a stray interrupt report
4059 * if an interrupt landed in the time between writing IIR and
4060 * the posting read. This should be rare enough to never
4061 * trigger the 99% of 100,000 interrupts test for disabling
4062 * stray interrupts.
4063 */
4064 ret = IRQ_HANDLED;
4065 iir = new_iir;
4066 } while (iir & ~flip_mask);
4067
4068 return ret;
4069 }
4070
4071 static void i915_irq_uninstall(struct drm_device * dev)
4072 {
4073 struct drm_i915_private *dev_priv = dev->dev_private;
4074 int pipe;
4075
4076 if (I915_HAS_HOTPLUG(dev)) {
4077 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
4078 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4079 }
4080
4081 I915_WRITE16(HWSTAM, 0xffff);
4082 for_each_pipe(dev_priv, pipe) {
4083 /* Clear enable bits; then clear status bits */
4084 I915_WRITE(PIPESTAT(pipe), 0);
4085 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4086 }
4087 I915_WRITE(IMR, 0xffffffff);
4088 I915_WRITE(IER, 0x0);
4089
4090 I915_WRITE(IIR, I915_READ(IIR));
4091 }
4092
4093 static void i965_irq_preinstall(struct drm_device * dev)
4094 {
4095 struct drm_i915_private *dev_priv = dev->dev_private;
4096 int pipe;
4097
4098 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
4099 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4100
4101 I915_WRITE(HWSTAM, 0xeffe);
4102 for_each_pipe(dev_priv, pipe)
4103 I915_WRITE(PIPESTAT(pipe), 0);
4104 I915_WRITE(IMR, 0xffffffff);
4105 I915_WRITE(IER, 0x0);
4106 POSTING_READ(IER);
4107 }
4108
4109 static int i965_irq_postinstall(struct drm_device *dev)
4110 {
4111 struct drm_i915_private *dev_priv = dev->dev_private;
4112 u32 enable_mask;
4113 u32 error_mask;
4114
4115 /* Unmask the interrupts that we always want on. */
4116 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
4117 I915_DISPLAY_PORT_INTERRUPT |
4118 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4119 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4120 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4121 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4122 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4123
4124 enable_mask = ~dev_priv->irq_mask;
4125 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4126 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
4127 enable_mask |= I915_USER_INTERRUPT;
4128
4129 if (IS_G4X(dev))
4130 enable_mask |= I915_BSD_USER_INTERRUPT;
4131
4132 /* Interrupt setup is already guaranteed to be single-threaded, this is
4133 * just to make the assert_spin_locked check happy. */
4134 spin_lock_irq(&dev_priv->irq_lock);
4135 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4136 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4137 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
4138 spin_unlock_irq(&dev_priv->irq_lock);
4139
4140 /*
4141 * Enable some error detection, note the instruction error mask
4142 * bit is reserved, so we leave it masked.
4143 */
4144 if (IS_G4X(dev)) {
4145 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4146 GM45_ERROR_MEM_PRIV |
4147 GM45_ERROR_CP_PRIV |
4148 I915_ERROR_MEMORY_REFRESH);
4149 } else {
4150 error_mask = ~(I915_ERROR_PAGE_TABLE |
4151 I915_ERROR_MEMORY_REFRESH);
4152 }
4153 I915_WRITE(EMR, error_mask);
4154
4155 I915_WRITE(IMR, dev_priv->irq_mask);
4156 I915_WRITE(IER, enable_mask);
4157 POSTING_READ(IER);
4158
4159 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
4160 POSTING_READ(PORT_HOTPLUG_EN);
4161
4162 i915_enable_asle_pipestat(dev);
4163
4164 return 0;
4165 }
4166
4167 static void i915_hpd_irq_setup(struct drm_device *dev)
4168 {
4169 struct drm_i915_private *dev_priv = dev->dev_private;
4170 u32 hotplug_en;
4171
4172 assert_spin_locked(&dev_priv->irq_lock);
4173
4174 /* Note HDMI and DP share hotplug bits */
4175 /* enable bits are the same for all generations */
4176 hotplug_en = intel_hpd_enabled_irqs(dev, hpd_mask_i915);
4177 /* Programming the CRT detection parameters tends
4178 to generate a spurious hotplug event about three
4179 seconds later. So just do it once.
4180 */
4181 if (IS_G4X(dev))
4182 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
4183 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
4184
4185 /* Ignore TV since it's buggy */
4186 i915_hotplug_interrupt_update_locked(dev_priv,
4187 (HOTPLUG_INT_EN_MASK
4188 | CRT_HOTPLUG_VOLTAGE_COMPARE_MASK),
4189 hotplug_en);
4190 }
4191
4192 static irqreturn_t i965_irq_handler(int irq, void *arg)
4193 {
4194 struct drm_device *dev = arg;
4195 struct drm_i915_private *dev_priv = dev->dev_private;
4196 u32 iir, new_iir;
4197 u32 pipe_stats[I915_MAX_PIPES];
4198 int ret = IRQ_NONE, pipe;
4199 u32 flip_mask =
4200 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4201 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
4202
4203 if (!intel_irqs_enabled(dev_priv))
4204 return IRQ_NONE;
4205
4206 iir = I915_READ(IIR);
4207
4208 for (;;) {
4209 bool irq_received = (iir & ~flip_mask) != 0;
4210 bool blc_event = false;
4211
4212 /* Can't rely on pipestat interrupt bit in iir as it might
4213 * have been cleared after the pipestat interrupt was received.
4214 * It doesn't set the bit in iir again, but it still produces
4215 * interrupts (for non-MSI).
4216 */
4217 spin_lock(&dev_priv->irq_lock);
4218 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4219 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
4220
4221 for_each_pipe(dev_priv, pipe) {
4222 int reg = PIPESTAT(pipe);
4223 pipe_stats[pipe] = I915_READ(reg);
4224
4225 /*
4226 * Clear the PIPE*STAT regs before the IIR
4227 */
4228 if (pipe_stats[pipe] & 0x8000ffff) {
4229 I915_WRITE(reg, pipe_stats[pipe]);
4230 irq_received = true;
4231 }
4232 }
4233 spin_unlock(&dev_priv->irq_lock);
4234
4235 if (!irq_received)
4236 break;
4237
4238 ret = IRQ_HANDLED;
4239
4240 /* Consume port. Then clear IIR or we'll miss events */
4241 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4242 i9xx_hpd_irq_handler(dev);
4243
4244 I915_WRITE(IIR, iir & ~flip_mask);
4245 new_iir = I915_READ(IIR); /* Flush posted writes */
4246
4247 if (iir & I915_USER_INTERRUPT)
4248 notify_ring(&dev_priv->ring[RCS]);
4249 if (iir & I915_BSD_USER_INTERRUPT)
4250 notify_ring(&dev_priv->ring[VCS]);
4251
4252 for_each_pipe(dev_priv, pipe) {
4253 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
4254 i915_handle_vblank(dev, pipe, pipe, iir))
4255 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
4256
4257 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4258 blc_event = true;
4259
4260 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
4261 i9xx_pipe_crc_irq_handler(dev, pipe);
4262
4263 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4264 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
4265 }
4266
4267 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4268 intel_opregion_asle_intr(dev);
4269
4270 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4271 gmbus_irq_handler(dev);
4272
4273 /* With MSI, interrupts are only generated when iir
4274 * transitions from zero to nonzero. If another bit got
4275 * set while we were handling the existing iir bits, then
4276 * we would never get another interrupt.
4277 *
4278 * This is fine on non-MSI as well, as if we hit this path
4279 * we avoid exiting the interrupt handler only to generate
4280 * another one.
4281 *
4282 * Note that for MSI this could cause a stray interrupt report
4283 * if an interrupt landed in the time between writing IIR and
4284 * the posting read. This should be rare enough to never
4285 * trigger the 99% of 100,000 interrupts test for disabling
4286 * stray interrupts.
4287 */
4288 iir = new_iir;
4289 }
4290
4291 return ret;
4292 }
4293
4294 static void i965_irq_uninstall(struct drm_device * dev)
4295 {
4296 struct drm_i915_private *dev_priv = dev->dev_private;
4297 int pipe;
4298
4299 if (!dev_priv)
4300 return;
4301
4302 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
4303 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4304
4305 I915_WRITE(HWSTAM, 0xffffffff);
4306 for_each_pipe(dev_priv, pipe)
4307 I915_WRITE(PIPESTAT(pipe), 0);
4308 I915_WRITE(IMR, 0xffffffff);
4309 I915_WRITE(IER, 0x0);
4310
4311 for_each_pipe(dev_priv, pipe)
4312 I915_WRITE(PIPESTAT(pipe),
4313 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4314 I915_WRITE(IIR, I915_READ(IIR));
4315 }
4316
4317 /**
4318 * intel_irq_init - initializes irq support
4319 * @dev_priv: i915 device instance
4320 *
4321 * This function initializes all the irq support including work items, timers
4322 * and all the vtables. It does not setup the interrupt itself though.
4323 */
4324 void intel_irq_init(struct drm_i915_private *dev_priv)
4325 {
4326 struct drm_device *dev = dev_priv->dev;
4327
4328 intel_hpd_init_work(dev_priv);
4329
4330 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
4331 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
4332
4333 /* Let's track the enabled rps events */
4334 if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
4335 /* WaGsvRC0ResidencyMethod:vlv */
4336 dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
4337 else
4338 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
4339
4340 INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
4341 i915_hangcheck_elapsed);
4342
4343 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
4344
4345 if (IS_GEN2(dev_priv)) {
4346 dev->max_vblank_count = 0;
4347 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
4348 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
4349 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4350 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
4351 } else {
4352 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4353 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
4354 }
4355
4356 /*
4357 * Opt out of the vblank disable timer on everything except gen2.
4358 * Gen2 doesn't have a hardware frame counter and so depends on
4359 * vblank interrupts to produce sane vblank seuquence numbers.
4360 */
4361 if (!IS_GEN2(dev_priv))
4362 dev->vblank_disable_immediate = true;
4363
4364 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4365 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
4366
4367 if (IS_CHERRYVIEW(dev_priv)) {
4368 dev->driver->irq_handler = cherryview_irq_handler;
4369 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4370 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4371 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4372 dev->driver->enable_vblank = valleyview_enable_vblank;
4373 dev->driver->disable_vblank = valleyview_disable_vblank;
4374 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4375 } else if (IS_VALLEYVIEW(dev_priv)) {
4376 dev->driver->irq_handler = valleyview_irq_handler;
4377 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4378 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4379 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4380 dev->driver->enable_vblank = valleyview_enable_vblank;
4381 dev->driver->disable_vblank = valleyview_disable_vblank;
4382 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4383 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
4384 dev->driver->irq_handler = gen8_irq_handler;
4385 dev->driver->irq_preinstall = gen8_irq_reset;
4386 dev->driver->irq_postinstall = gen8_irq_postinstall;
4387 dev->driver->irq_uninstall = gen8_irq_uninstall;
4388 dev->driver->enable_vblank = gen8_enable_vblank;
4389 dev->driver->disable_vblank = gen8_disable_vblank;
4390 if (IS_BROXTON(dev))
4391 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
4392 else if (HAS_PCH_SPT(dev))
4393 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4394 else
4395 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
4396 } else if (HAS_PCH_SPLIT(dev)) {
4397 dev->driver->irq_handler = ironlake_irq_handler;
4398 dev->driver->irq_preinstall = ironlake_irq_reset;
4399 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4400 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4401 dev->driver->enable_vblank = ironlake_enable_vblank;
4402 dev->driver->disable_vblank = ironlake_disable_vblank;
4403 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
4404 } else {
4405 if (INTEL_INFO(dev_priv)->gen == 2) {
4406 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4407 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4408 dev->driver->irq_handler = i8xx_irq_handler;
4409 dev->driver->irq_uninstall = i8xx_irq_uninstall;
4410 } else if (INTEL_INFO(dev_priv)->gen == 3) {
4411 dev->driver->irq_preinstall = i915_irq_preinstall;
4412 dev->driver->irq_postinstall = i915_irq_postinstall;
4413 dev->driver->irq_uninstall = i915_irq_uninstall;
4414 dev->driver->irq_handler = i915_irq_handler;
4415 } else {
4416 dev->driver->irq_preinstall = i965_irq_preinstall;
4417 dev->driver->irq_postinstall = i965_irq_postinstall;
4418 dev->driver->irq_uninstall = i965_irq_uninstall;
4419 dev->driver->irq_handler = i965_irq_handler;
4420 }
4421 if (I915_HAS_HOTPLUG(dev_priv))
4422 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4423 dev->driver->enable_vblank = i915_enable_vblank;
4424 dev->driver->disable_vblank = i915_disable_vblank;
4425 }
4426 }
4427
4428 /**
4429 * intel_irq_install - enables the hardware interrupt
4430 * @dev_priv: i915 device instance
4431 *
4432 * This function enables the hardware interrupt handling, but leaves the hotplug
4433 * handling still disabled. It is called after intel_irq_init().
4434 *
4435 * In the driver load and resume code we need working interrupts in a few places
4436 * but don't want to deal with the hassle of concurrent probe and hotplug
4437 * workers. Hence the split into this two-stage approach.
4438 */
4439 int intel_irq_install(struct drm_i915_private *dev_priv)
4440 {
4441 /*
4442 * We enable some interrupt sources in our postinstall hooks, so mark
4443 * interrupts as enabled _before_ actually enabling them to avoid
4444 * special cases in our ordering checks.
4445 */
4446 dev_priv->pm.irqs_enabled = true;
4447
4448 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4449 }
4450
4451 /**
4452 * intel_irq_uninstall - finilizes all irq handling
4453 * @dev_priv: i915 device instance
4454 *
4455 * This stops interrupt and hotplug handling and unregisters and frees all
4456 * resources acquired in the init functions.
4457 */
4458 void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4459 {
4460 drm_irq_uninstall(dev_priv->dev);
4461 intel_hpd_cancel_work(dev_priv);
4462 dev_priv->pm.irqs_enabled = false;
4463 }
4464
4465 /**
4466 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4467 * @dev_priv: i915 device instance
4468 *
4469 * This function is used to disable interrupts at runtime, both in the runtime
4470 * pm and the system suspend/resume code.
4471 */
4472 void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
4473 {
4474 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
4475 dev_priv->pm.irqs_enabled = false;
4476 synchronize_irq(dev_priv->dev->irq);
4477 }
4478
4479 /**
4480 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4481 * @dev_priv: i915 device instance
4482 *
4483 * This function is used to enable interrupts at runtime, both in the runtime
4484 * pm and the system suspend/resume code.
4485 */
4486 void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
4487 {
4488 dev_priv->pm.irqs_enabled = true;
4489 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4490 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
4491 }