drm/i915: Expose latest 200 CRC value for pipe through debugfs
[deliverable/linux.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 <drm/drmP.h>
34 #include <drm/i915_drm.h>
35 #include "i915_drv.h"
36 #include "i915_trace.h"
37 #include "intel_drv.h"
38
39 static const u32 hpd_ibx[] = {
40 [HPD_CRT] = SDE_CRT_HOTPLUG,
41 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
42 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
43 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
44 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
45 };
46
47 static const u32 hpd_cpt[] = {
48 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
49 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
50 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
51 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
52 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
53 };
54
55 static const u32 hpd_mask_i915[] = {
56 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
57 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
58 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
59 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
60 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
61 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
62 };
63
64 static const u32 hpd_status_gen4[] = {
65 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
66 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
67 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
68 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
69 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
70 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
71 };
72
73 static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
74 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
75 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
76 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
77 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
78 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
79 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
80 };
81
82 /* For display hotplug interrupt */
83 static void
84 ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
85 {
86 assert_spin_locked(&dev_priv->irq_lock);
87
88 if (dev_priv->pc8.irqs_disabled) {
89 WARN(1, "IRQs disabled\n");
90 dev_priv->pc8.regsave.deimr &= ~mask;
91 return;
92 }
93
94 if ((dev_priv->irq_mask & mask) != 0) {
95 dev_priv->irq_mask &= ~mask;
96 I915_WRITE(DEIMR, dev_priv->irq_mask);
97 POSTING_READ(DEIMR);
98 }
99 }
100
101 static void
102 ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
103 {
104 assert_spin_locked(&dev_priv->irq_lock);
105
106 if (dev_priv->pc8.irqs_disabled) {
107 WARN(1, "IRQs disabled\n");
108 dev_priv->pc8.regsave.deimr |= mask;
109 return;
110 }
111
112 if ((dev_priv->irq_mask & mask) != mask) {
113 dev_priv->irq_mask |= mask;
114 I915_WRITE(DEIMR, dev_priv->irq_mask);
115 POSTING_READ(DEIMR);
116 }
117 }
118
119 /**
120 * ilk_update_gt_irq - update GTIMR
121 * @dev_priv: driver private
122 * @interrupt_mask: mask of interrupt bits to update
123 * @enabled_irq_mask: mask of interrupt bits to enable
124 */
125 static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
126 uint32_t interrupt_mask,
127 uint32_t enabled_irq_mask)
128 {
129 assert_spin_locked(&dev_priv->irq_lock);
130
131 if (dev_priv->pc8.irqs_disabled) {
132 WARN(1, "IRQs disabled\n");
133 dev_priv->pc8.regsave.gtimr &= ~interrupt_mask;
134 dev_priv->pc8.regsave.gtimr |= (~enabled_irq_mask &
135 interrupt_mask);
136 return;
137 }
138
139 dev_priv->gt_irq_mask &= ~interrupt_mask;
140 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
141 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
142 POSTING_READ(GTIMR);
143 }
144
145 void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
146 {
147 ilk_update_gt_irq(dev_priv, mask, mask);
148 }
149
150 void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
151 {
152 ilk_update_gt_irq(dev_priv, mask, 0);
153 }
154
155 /**
156 * snb_update_pm_irq - update GEN6_PMIMR
157 * @dev_priv: driver private
158 * @interrupt_mask: mask of interrupt bits to update
159 * @enabled_irq_mask: mask of interrupt bits to enable
160 */
161 static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
162 uint32_t interrupt_mask,
163 uint32_t enabled_irq_mask)
164 {
165 uint32_t new_val;
166
167 assert_spin_locked(&dev_priv->irq_lock);
168
169 if (dev_priv->pc8.irqs_disabled) {
170 WARN(1, "IRQs disabled\n");
171 dev_priv->pc8.regsave.gen6_pmimr &= ~interrupt_mask;
172 dev_priv->pc8.regsave.gen6_pmimr |= (~enabled_irq_mask &
173 interrupt_mask);
174 return;
175 }
176
177 new_val = dev_priv->pm_irq_mask;
178 new_val &= ~interrupt_mask;
179 new_val |= (~enabled_irq_mask & interrupt_mask);
180
181 if (new_val != dev_priv->pm_irq_mask) {
182 dev_priv->pm_irq_mask = new_val;
183 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
184 POSTING_READ(GEN6_PMIMR);
185 }
186 }
187
188 void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
189 {
190 snb_update_pm_irq(dev_priv, mask, mask);
191 }
192
193 void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
194 {
195 snb_update_pm_irq(dev_priv, mask, 0);
196 }
197
198 static bool ivb_can_enable_err_int(struct drm_device *dev)
199 {
200 struct drm_i915_private *dev_priv = dev->dev_private;
201 struct intel_crtc *crtc;
202 enum pipe pipe;
203
204 assert_spin_locked(&dev_priv->irq_lock);
205
206 for_each_pipe(pipe) {
207 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
208
209 if (crtc->cpu_fifo_underrun_disabled)
210 return false;
211 }
212
213 return true;
214 }
215
216 static bool cpt_can_enable_serr_int(struct drm_device *dev)
217 {
218 struct drm_i915_private *dev_priv = dev->dev_private;
219 enum pipe pipe;
220 struct intel_crtc *crtc;
221
222 assert_spin_locked(&dev_priv->irq_lock);
223
224 for_each_pipe(pipe) {
225 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
226
227 if (crtc->pch_fifo_underrun_disabled)
228 return false;
229 }
230
231 return true;
232 }
233
234 static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
235 enum pipe pipe, bool enable)
236 {
237 struct drm_i915_private *dev_priv = dev->dev_private;
238 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
239 DE_PIPEB_FIFO_UNDERRUN;
240
241 if (enable)
242 ironlake_enable_display_irq(dev_priv, bit);
243 else
244 ironlake_disable_display_irq(dev_priv, bit);
245 }
246
247 static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
248 enum pipe pipe, bool enable)
249 {
250 struct drm_i915_private *dev_priv = dev->dev_private;
251 if (enable) {
252 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
253
254 if (!ivb_can_enable_err_int(dev))
255 return;
256
257 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
258 } else {
259 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
260
261 /* Change the state _after_ we've read out the current one. */
262 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
263
264 if (!was_enabled &&
265 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
266 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
267 pipe_name(pipe));
268 }
269 }
270 }
271
272 /**
273 * ibx_display_interrupt_update - update SDEIMR
274 * @dev_priv: driver private
275 * @interrupt_mask: mask of interrupt bits to update
276 * @enabled_irq_mask: mask of interrupt bits to enable
277 */
278 static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
279 uint32_t interrupt_mask,
280 uint32_t enabled_irq_mask)
281 {
282 uint32_t sdeimr = I915_READ(SDEIMR);
283 sdeimr &= ~interrupt_mask;
284 sdeimr |= (~enabled_irq_mask & interrupt_mask);
285
286 assert_spin_locked(&dev_priv->irq_lock);
287
288 if (dev_priv->pc8.irqs_disabled &&
289 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
290 WARN(1, "IRQs disabled\n");
291 dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
292 dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
293 interrupt_mask);
294 return;
295 }
296
297 I915_WRITE(SDEIMR, sdeimr);
298 POSTING_READ(SDEIMR);
299 }
300 #define ibx_enable_display_interrupt(dev_priv, bits) \
301 ibx_display_interrupt_update((dev_priv), (bits), (bits))
302 #define ibx_disable_display_interrupt(dev_priv, bits) \
303 ibx_display_interrupt_update((dev_priv), (bits), 0)
304
305 static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
306 enum transcoder pch_transcoder,
307 bool enable)
308 {
309 struct drm_i915_private *dev_priv = dev->dev_private;
310 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
311 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
312
313 if (enable)
314 ibx_enable_display_interrupt(dev_priv, bit);
315 else
316 ibx_disable_display_interrupt(dev_priv, bit);
317 }
318
319 static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
320 enum transcoder pch_transcoder,
321 bool enable)
322 {
323 struct drm_i915_private *dev_priv = dev->dev_private;
324
325 if (enable) {
326 I915_WRITE(SERR_INT,
327 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
328
329 if (!cpt_can_enable_serr_int(dev))
330 return;
331
332 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
333 } else {
334 uint32_t tmp = I915_READ(SERR_INT);
335 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
336
337 /* Change the state _after_ we've read out the current one. */
338 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
339
340 if (!was_enabled &&
341 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
342 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
343 transcoder_name(pch_transcoder));
344 }
345 }
346 }
347
348 /**
349 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
350 * @dev: drm device
351 * @pipe: pipe
352 * @enable: true if we want to report FIFO underrun errors, false otherwise
353 *
354 * This function makes us disable or enable CPU fifo underruns for a specific
355 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
356 * reporting for one pipe may also disable all the other CPU error interruts for
357 * the other pipes, due to the fact that there's just one interrupt mask/enable
358 * bit for all the pipes.
359 *
360 * Returns the previous state of underrun reporting.
361 */
362 bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
363 enum pipe pipe, bool enable)
364 {
365 struct drm_i915_private *dev_priv = dev->dev_private;
366 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
367 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
368 unsigned long flags;
369 bool ret;
370
371 spin_lock_irqsave(&dev_priv->irq_lock, flags);
372
373 ret = !intel_crtc->cpu_fifo_underrun_disabled;
374
375 if (enable == ret)
376 goto done;
377
378 intel_crtc->cpu_fifo_underrun_disabled = !enable;
379
380 if (IS_GEN5(dev) || IS_GEN6(dev))
381 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
382 else if (IS_GEN7(dev))
383 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
384
385 done:
386 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
387 return ret;
388 }
389
390 /**
391 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
392 * @dev: drm device
393 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
394 * @enable: true if we want to report FIFO underrun errors, false otherwise
395 *
396 * This function makes us disable or enable PCH fifo underruns for a specific
397 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
398 * underrun reporting for one transcoder may also disable all the other PCH
399 * error interruts for the other transcoders, due to the fact that there's just
400 * one interrupt mask/enable bit for all the transcoders.
401 *
402 * Returns the previous state of underrun reporting.
403 */
404 bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
405 enum transcoder pch_transcoder,
406 bool enable)
407 {
408 struct drm_i915_private *dev_priv = dev->dev_private;
409 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
410 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
411 unsigned long flags;
412 bool ret;
413
414 /*
415 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
416 * has only one pch transcoder A that all pipes can use. To avoid racy
417 * pch transcoder -> pipe lookups from interrupt code simply store the
418 * underrun statistics in crtc A. Since we never expose this anywhere
419 * nor use it outside of the fifo underrun code here using the "wrong"
420 * crtc on LPT won't cause issues.
421 */
422
423 spin_lock_irqsave(&dev_priv->irq_lock, flags);
424
425 ret = !intel_crtc->pch_fifo_underrun_disabled;
426
427 if (enable == ret)
428 goto done;
429
430 intel_crtc->pch_fifo_underrun_disabled = !enable;
431
432 if (HAS_PCH_IBX(dev))
433 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
434 else
435 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
436
437 done:
438 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
439 return ret;
440 }
441
442
443 void
444 i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
445 {
446 u32 reg = PIPESTAT(pipe);
447 u32 pipestat = I915_READ(reg) & 0x7fff0000;
448
449 assert_spin_locked(&dev_priv->irq_lock);
450
451 if ((pipestat & mask) == mask)
452 return;
453
454 /* Enable the interrupt, clear any pending status */
455 pipestat |= mask | (mask >> 16);
456 I915_WRITE(reg, pipestat);
457 POSTING_READ(reg);
458 }
459
460 void
461 i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
462 {
463 u32 reg = PIPESTAT(pipe);
464 u32 pipestat = I915_READ(reg) & 0x7fff0000;
465
466 assert_spin_locked(&dev_priv->irq_lock);
467
468 if ((pipestat & mask) == 0)
469 return;
470
471 pipestat &= ~mask;
472 I915_WRITE(reg, pipestat);
473 POSTING_READ(reg);
474 }
475
476 /**
477 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
478 */
479 static void i915_enable_asle_pipestat(struct drm_device *dev)
480 {
481 drm_i915_private_t *dev_priv = dev->dev_private;
482 unsigned long irqflags;
483
484 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
485 return;
486
487 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
488
489 i915_enable_pipestat(dev_priv, 1, PIPE_LEGACY_BLC_EVENT_ENABLE);
490 if (INTEL_INFO(dev)->gen >= 4)
491 i915_enable_pipestat(dev_priv, 0, PIPE_LEGACY_BLC_EVENT_ENABLE);
492
493 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
494 }
495
496 /**
497 * i915_pipe_enabled - check if a pipe is enabled
498 * @dev: DRM device
499 * @pipe: pipe to check
500 *
501 * Reading certain registers when the pipe is disabled can hang the chip.
502 * Use this routine to make sure the PLL is running and the pipe is active
503 * before reading such registers if unsure.
504 */
505 static int
506 i915_pipe_enabled(struct drm_device *dev, int pipe)
507 {
508 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
509
510 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
511 /* Locking is horribly broken here, but whatever. */
512 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
513 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
514
515 return intel_crtc->active;
516 } else {
517 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
518 }
519 }
520
521 static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
522 {
523 /* Gen2 doesn't have a hardware frame counter */
524 return 0;
525 }
526
527 /* Called from drm generic code, passed a 'crtc', which
528 * we use as a pipe index
529 */
530 static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
531 {
532 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
533 unsigned long high_frame;
534 unsigned long low_frame;
535 u32 high1, high2, low, pixel, vbl_start;
536
537 if (!i915_pipe_enabled(dev, pipe)) {
538 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
539 "pipe %c\n", pipe_name(pipe));
540 return 0;
541 }
542
543 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
544 struct intel_crtc *intel_crtc =
545 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
546 const struct drm_display_mode *mode =
547 &intel_crtc->config.adjusted_mode;
548
549 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
550 } else {
551 enum transcoder cpu_transcoder =
552 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
553 u32 htotal;
554
555 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
556 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
557
558 vbl_start *= htotal;
559 }
560
561 high_frame = PIPEFRAME(pipe);
562 low_frame = PIPEFRAMEPIXEL(pipe);
563
564 /*
565 * High & low register fields aren't synchronized, so make sure
566 * we get a low value that's stable across two reads of the high
567 * register.
568 */
569 do {
570 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
571 low = I915_READ(low_frame);
572 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
573 } while (high1 != high2);
574
575 high1 >>= PIPE_FRAME_HIGH_SHIFT;
576 pixel = low & PIPE_PIXEL_MASK;
577 low >>= PIPE_FRAME_LOW_SHIFT;
578
579 /*
580 * The frame counter increments at beginning of active.
581 * Cook up a vblank counter by also checking the pixel
582 * counter against vblank start.
583 */
584 return ((high1 << 8) | low) + (pixel >= vbl_start);
585 }
586
587 static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
588 {
589 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
590 int reg = PIPE_FRMCOUNT_GM45(pipe);
591
592 if (!i915_pipe_enabled(dev, pipe)) {
593 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
594 "pipe %c\n", pipe_name(pipe));
595 return 0;
596 }
597
598 return I915_READ(reg);
599 }
600
601 static bool intel_pipe_in_vblank(struct drm_device *dev, enum pipe pipe)
602 {
603 struct drm_i915_private *dev_priv = dev->dev_private;
604 uint32_t status;
605
606 if (IS_VALLEYVIEW(dev)) {
607 status = pipe == PIPE_A ?
608 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
609 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
610
611 return I915_READ(VLV_ISR) & status;
612 } else if (IS_GEN2(dev)) {
613 status = pipe == PIPE_A ?
614 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
615 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
616
617 return I915_READ16(ISR) & status;
618 } else if (INTEL_INFO(dev)->gen < 5) {
619 status = pipe == PIPE_A ?
620 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
621 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
622
623 return I915_READ(ISR) & status;
624 } else if (INTEL_INFO(dev)->gen < 7) {
625 status = pipe == PIPE_A ?
626 DE_PIPEA_VBLANK :
627 DE_PIPEB_VBLANK;
628
629 return I915_READ(DEISR) & status;
630 } else {
631 switch (pipe) {
632 default:
633 case PIPE_A:
634 status = DE_PIPEA_VBLANK_IVB;
635 break;
636 case PIPE_B:
637 status = DE_PIPEB_VBLANK_IVB;
638 break;
639 case PIPE_C:
640 status = DE_PIPEC_VBLANK_IVB;
641 break;
642 }
643
644 return I915_READ(DEISR) & status;
645 }
646 }
647
648 static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
649 int *vpos, int *hpos)
650 {
651 struct drm_i915_private *dev_priv = dev->dev_private;
652 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
653 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
654 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
655 int position;
656 int vbl_start, vbl_end, htotal, vtotal;
657 bool in_vbl = true;
658 int ret = 0;
659
660 if (!intel_crtc->active) {
661 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
662 "pipe %c\n", pipe_name(pipe));
663 return 0;
664 }
665
666 htotal = mode->crtc_htotal;
667 vtotal = mode->crtc_vtotal;
668 vbl_start = mode->crtc_vblank_start;
669 vbl_end = mode->crtc_vblank_end;
670
671 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
672
673 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
674 /* No obvious pixelcount register. Only query vertical
675 * scanout position from Display scan line register.
676 */
677 if (IS_GEN2(dev))
678 position = I915_READ(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
679 else
680 position = I915_READ(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
681
682 /*
683 * The scanline counter increments at the leading edge
684 * of hsync, ie. it completely misses the active portion
685 * of the line. Fix up the counter at both edges of vblank
686 * to get a more accurate picture whether we're in vblank
687 * or not.
688 */
689 in_vbl = intel_pipe_in_vblank(dev, pipe);
690 if ((in_vbl && position == vbl_start - 1) ||
691 (!in_vbl && position == vbl_end - 1))
692 position = (position + 1) % vtotal;
693 } else {
694 /* Have access to pixelcount since start of frame.
695 * We can split this into vertical and horizontal
696 * scanout position.
697 */
698 position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
699
700 /* convert to pixel counts */
701 vbl_start *= htotal;
702 vbl_end *= htotal;
703 vtotal *= htotal;
704 }
705
706 in_vbl = position >= vbl_start && position < vbl_end;
707
708 /*
709 * While in vblank, position will be negative
710 * counting up towards 0 at vbl_end. And outside
711 * vblank, position will be positive counting
712 * up since vbl_end.
713 */
714 if (position >= vbl_start)
715 position -= vbl_end;
716 else
717 position += vtotal - vbl_end;
718
719 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
720 *vpos = position;
721 *hpos = 0;
722 } else {
723 *vpos = position / htotal;
724 *hpos = position - (*vpos * htotal);
725 }
726
727 /* In vblank? */
728 if (in_vbl)
729 ret |= DRM_SCANOUTPOS_INVBL;
730
731 return ret;
732 }
733
734 static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
735 int *max_error,
736 struct timeval *vblank_time,
737 unsigned flags)
738 {
739 struct drm_crtc *crtc;
740
741 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
742 DRM_ERROR("Invalid crtc %d\n", pipe);
743 return -EINVAL;
744 }
745
746 /* Get drm_crtc to timestamp: */
747 crtc = intel_get_crtc_for_pipe(dev, pipe);
748 if (crtc == NULL) {
749 DRM_ERROR("Invalid crtc %d\n", pipe);
750 return -EINVAL;
751 }
752
753 if (!crtc->enabled) {
754 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
755 return -EBUSY;
756 }
757
758 /* Helper routine in DRM core does all the work: */
759 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
760 vblank_time, flags,
761 crtc);
762 }
763
764 static bool intel_hpd_irq_event(struct drm_device *dev,
765 struct drm_connector *connector)
766 {
767 enum drm_connector_status old_status;
768
769 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
770 old_status = connector->status;
771
772 connector->status = connector->funcs->detect(connector, false);
773 if (old_status == connector->status)
774 return false;
775
776 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
777 connector->base.id,
778 drm_get_connector_name(connector),
779 drm_get_connector_status_name(old_status),
780 drm_get_connector_status_name(connector->status));
781
782 return true;
783 }
784
785 /*
786 * Handle hotplug events outside the interrupt handler proper.
787 */
788 #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
789
790 static void i915_hotplug_work_func(struct work_struct *work)
791 {
792 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
793 hotplug_work);
794 struct drm_device *dev = dev_priv->dev;
795 struct drm_mode_config *mode_config = &dev->mode_config;
796 struct intel_connector *intel_connector;
797 struct intel_encoder *intel_encoder;
798 struct drm_connector *connector;
799 unsigned long irqflags;
800 bool hpd_disabled = false;
801 bool changed = false;
802 u32 hpd_event_bits;
803
804 /* HPD irq before everything is fully set up. */
805 if (!dev_priv->enable_hotplug_processing)
806 return;
807
808 mutex_lock(&mode_config->mutex);
809 DRM_DEBUG_KMS("running encoder hotplug functions\n");
810
811 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
812
813 hpd_event_bits = dev_priv->hpd_event_bits;
814 dev_priv->hpd_event_bits = 0;
815 list_for_each_entry(connector, &mode_config->connector_list, head) {
816 intel_connector = to_intel_connector(connector);
817 intel_encoder = intel_connector->encoder;
818 if (intel_encoder->hpd_pin > HPD_NONE &&
819 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
820 connector->polled == DRM_CONNECTOR_POLL_HPD) {
821 DRM_INFO("HPD interrupt storm detected on connector %s: "
822 "switching from hotplug detection to polling\n",
823 drm_get_connector_name(connector));
824 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
825 connector->polled = DRM_CONNECTOR_POLL_CONNECT
826 | DRM_CONNECTOR_POLL_DISCONNECT;
827 hpd_disabled = true;
828 }
829 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
830 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
831 drm_get_connector_name(connector), intel_encoder->hpd_pin);
832 }
833 }
834 /* if there were no outputs to poll, poll was disabled,
835 * therefore make sure it's enabled when disabling HPD on
836 * some connectors */
837 if (hpd_disabled) {
838 drm_kms_helper_poll_enable(dev);
839 mod_timer(&dev_priv->hotplug_reenable_timer,
840 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
841 }
842
843 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
844
845 list_for_each_entry(connector, &mode_config->connector_list, head) {
846 intel_connector = to_intel_connector(connector);
847 intel_encoder = intel_connector->encoder;
848 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
849 if (intel_encoder->hot_plug)
850 intel_encoder->hot_plug(intel_encoder);
851 if (intel_hpd_irq_event(dev, connector))
852 changed = true;
853 }
854 }
855 mutex_unlock(&mode_config->mutex);
856
857 if (changed)
858 drm_kms_helper_hotplug_event(dev);
859 }
860
861 static void ironlake_rps_change_irq_handler(struct drm_device *dev)
862 {
863 drm_i915_private_t *dev_priv = dev->dev_private;
864 u32 busy_up, busy_down, max_avg, min_avg;
865 u8 new_delay;
866
867 spin_lock(&mchdev_lock);
868
869 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
870
871 new_delay = dev_priv->ips.cur_delay;
872
873 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
874 busy_up = I915_READ(RCPREVBSYTUPAVG);
875 busy_down = I915_READ(RCPREVBSYTDNAVG);
876 max_avg = I915_READ(RCBMAXAVG);
877 min_avg = I915_READ(RCBMINAVG);
878
879 /* Handle RCS change request from hw */
880 if (busy_up > max_avg) {
881 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
882 new_delay = dev_priv->ips.cur_delay - 1;
883 if (new_delay < dev_priv->ips.max_delay)
884 new_delay = dev_priv->ips.max_delay;
885 } else if (busy_down < min_avg) {
886 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
887 new_delay = dev_priv->ips.cur_delay + 1;
888 if (new_delay > dev_priv->ips.min_delay)
889 new_delay = dev_priv->ips.min_delay;
890 }
891
892 if (ironlake_set_drps(dev, new_delay))
893 dev_priv->ips.cur_delay = new_delay;
894
895 spin_unlock(&mchdev_lock);
896
897 return;
898 }
899
900 static void notify_ring(struct drm_device *dev,
901 struct intel_ring_buffer *ring)
902 {
903 if (ring->obj == NULL)
904 return;
905
906 trace_i915_gem_request_complete(ring);
907
908 wake_up_all(&ring->irq_queue);
909 i915_queue_hangcheck(dev);
910 }
911
912 static void gen6_pm_rps_work(struct work_struct *work)
913 {
914 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
915 rps.work);
916 u32 pm_iir;
917 int new_delay, adj;
918
919 spin_lock_irq(&dev_priv->irq_lock);
920 pm_iir = dev_priv->rps.pm_iir;
921 dev_priv->rps.pm_iir = 0;
922 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
923 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
924 spin_unlock_irq(&dev_priv->irq_lock);
925
926 /* Make sure we didn't queue anything we're not going to process. */
927 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
928
929 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
930 return;
931
932 mutex_lock(&dev_priv->rps.hw_lock);
933
934 adj = dev_priv->rps.last_adj;
935 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
936 if (adj > 0)
937 adj *= 2;
938 else
939 adj = 1;
940 new_delay = dev_priv->rps.cur_delay + adj;
941
942 /*
943 * For better performance, jump directly
944 * to RPe if we're below it.
945 */
946 if (new_delay < dev_priv->rps.rpe_delay)
947 new_delay = dev_priv->rps.rpe_delay;
948 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
949 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
950 new_delay = dev_priv->rps.rpe_delay;
951 else
952 new_delay = dev_priv->rps.min_delay;
953 adj = 0;
954 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
955 if (adj < 0)
956 adj *= 2;
957 else
958 adj = -1;
959 new_delay = dev_priv->rps.cur_delay + adj;
960 } else { /* unknown event */
961 new_delay = dev_priv->rps.cur_delay;
962 }
963
964 /* sysfs frequency interfaces may have snuck in while servicing the
965 * interrupt
966 */
967 if (new_delay < (int)dev_priv->rps.min_delay)
968 new_delay = dev_priv->rps.min_delay;
969 if (new_delay > (int)dev_priv->rps.max_delay)
970 new_delay = dev_priv->rps.max_delay;
971 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
972
973 if (IS_VALLEYVIEW(dev_priv->dev))
974 valleyview_set_rps(dev_priv->dev, new_delay);
975 else
976 gen6_set_rps(dev_priv->dev, new_delay);
977
978 mutex_unlock(&dev_priv->rps.hw_lock);
979 }
980
981
982 /**
983 * ivybridge_parity_work - Workqueue called when a parity error interrupt
984 * occurred.
985 * @work: workqueue struct
986 *
987 * Doesn't actually do anything except notify userspace. As a consequence of
988 * this event, userspace should try to remap the bad rows since statistically
989 * it is likely the same row is more likely to go bad again.
990 */
991 static void ivybridge_parity_work(struct work_struct *work)
992 {
993 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
994 l3_parity.error_work);
995 u32 error_status, row, bank, subbank;
996 char *parity_event[6];
997 uint32_t misccpctl;
998 unsigned long flags;
999 uint8_t slice = 0;
1000
1001 /* We must turn off DOP level clock gating to access the L3 registers.
1002 * In order to prevent a get/put style interface, acquire struct mutex
1003 * any time we access those registers.
1004 */
1005 mutex_lock(&dev_priv->dev->struct_mutex);
1006
1007 /* If we've screwed up tracking, just let the interrupt fire again */
1008 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1009 goto out;
1010
1011 misccpctl = I915_READ(GEN7_MISCCPCTL);
1012 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1013 POSTING_READ(GEN7_MISCCPCTL);
1014
1015 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1016 u32 reg;
1017
1018 slice--;
1019 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1020 break;
1021
1022 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1023
1024 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1025
1026 error_status = I915_READ(reg);
1027 row = GEN7_PARITY_ERROR_ROW(error_status);
1028 bank = GEN7_PARITY_ERROR_BANK(error_status);
1029 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1030
1031 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1032 POSTING_READ(reg);
1033
1034 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1035 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1036 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1037 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1038 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1039 parity_event[5] = NULL;
1040
1041 kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj,
1042 KOBJ_CHANGE, parity_event);
1043
1044 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1045 slice, row, bank, subbank);
1046
1047 kfree(parity_event[4]);
1048 kfree(parity_event[3]);
1049 kfree(parity_event[2]);
1050 kfree(parity_event[1]);
1051 }
1052
1053 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1054
1055 out:
1056 WARN_ON(dev_priv->l3_parity.which_slice);
1057 spin_lock_irqsave(&dev_priv->irq_lock, flags);
1058 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
1059 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1060
1061 mutex_unlock(&dev_priv->dev->struct_mutex);
1062 }
1063
1064 static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
1065 {
1066 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1067
1068 if (!HAS_L3_DPF(dev))
1069 return;
1070
1071 spin_lock(&dev_priv->irq_lock);
1072 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
1073 spin_unlock(&dev_priv->irq_lock);
1074
1075 iir &= GT_PARITY_ERROR(dev);
1076 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1077 dev_priv->l3_parity.which_slice |= 1 << 1;
1078
1079 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1080 dev_priv->l3_parity.which_slice |= 1 << 0;
1081
1082 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
1083 }
1084
1085 static void ilk_gt_irq_handler(struct drm_device *dev,
1086 struct drm_i915_private *dev_priv,
1087 u32 gt_iir)
1088 {
1089 if (gt_iir &
1090 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1091 notify_ring(dev, &dev_priv->ring[RCS]);
1092 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1093 notify_ring(dev, &dev_priv->ring[VCS]);
1094 }
1095
1096 static void snb_gt_irq_handler(struct drm_device *dev,
1097 struct drm_i915_private *dev_priv,
1098 u32 gt_iir)
1099 {
1100
1101 if (gt_iir &
1102 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1103 notify_ring(dev, &dev_priv->ring[RCS]);
1104 if (gt_iir & GT_BSD_USER_INTERRUPT)
1105 notify_ring(dev, &dev_priv->ring[VCS]);
1106 if (gt_iir & GT_BLT_USER_INTERRUPT)
1107 notify_ring(dev, &dev_priv->ring[BCS]);
1108
1109 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1110 GT_BSD_CS_ERROR_INTERRUPT |
1111 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
1112 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1113 i915_handle_error(dev, false);
1114 }
1115
1116 if (gt_iir & GT_PARITY_ERROR(dev))
1117 ivybridge_parity_error_irq_handler(dev, gt_iir);
1118 }
1119
1120 #define HPD_STORM_DETECT_PERIOD 1000
1121 #define HPD_STORM_THRESHOLD 5
1122
1123 static inline void intel_hpd_irq_handler(struct drm_device *dev,
1124 u32 hotplug_trigger,
1125 const u32 *hpd)
1126 {
1127 drm_i915_private_t *dev_priv = dev->dev_private;
1128 int i;
1129 bool storm_detected = false;
1130
1131 if (!hotplug_trigger)
1132 return;
1133
1134 spin_lock(&dev_priv->irq_lock);
1135 for (i = 1; i < HPD_NUM_PINS; i++) {
1136
1137 WARN(((hpd[i] & hotplug_trigger) &&
1138 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED),
1139 "Received HPD interrupt although disabled\n");
1140
1141 if (!(hpd[i] & hotplug_trigger) ||
1142 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1143 continue;
1144
1145 dev_priv->hpd_event_bits |= (1 << i);
1146 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1147 dev_priv->hpd_stats[i].hpd_last_jiffies
1148 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1149 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1150 dev_priv->hpd_stats[i].hpd_cnt = 0;
1151 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
1152 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1153 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
1154 dev_priv->hpd_event_bits &= ~(1 << i);
1155 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
1156 storm_detected = true;
1157 } else {
1158 dev_priv->hpd_stats[i].hpd_cnt++;
1159 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1160 dev_priv->hpd_stats[i].hpd_cnt);
1161 }
1162 }
1163
1164 if (storm_detected)
1165 dev_priv->display.hpd_irq_setup(dev);
1166 spin_unlock(&dev_priv->irq_lock);
1167
1168 /*
1169 * Our hotplug handler can grab modeset locks (by calling down into the
1170 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1171 * queue for otherwise the flush_work in the pageflip code will
1172 * deadlock.
1173 */
1174 schedule_work(&dev_priv->hotplug_work);
1175 }
1176
1177 static void gmbus_irq_handler(struct drm_device *dev)
1178 {
1179 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1180
1181 wake_up_all(&dev_priv->gmbus_wait_queue);
1182 }
1183
1184 static void dp_aux_irq_handler(struct drm_device *dev)
1185 {
1186 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1187
1188 wake_up_all(&dev_priv->gmbus_wait_queue);
1189 }
1190
1191 #if defined(CONFIG_DEBUG_FS)
1192 static void ivb_pipe_crc_update(struct drm_device *dev, enum pipe pipe)
1193 {
1194 struct drm_i915_private *dev_priv = dev->dev_private;
1195 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1196 struct intel_pipe_crc_entry *entry;
1197 ktime_t now;
1198 int ts, slot;
1199
1200 now = ktime_get();
1201 ts = ktime_to_us(now);
1202
1203 slot = (atomic_read(&pipe_crc->slot) + 1) % INTEL_PIPE_CRC_ENTRIES_NR;
1204 entry = &pipe_crc->entries[slot];
1205 entry->timestamp = ts;
1206 entry->crc[0] = I915_READ(PIPE_CRC_RES_1_IVB(pipe));
1207 entry->crc[1] = I915_READ(PIPE_CRC_RES_2_IVB(pipe));
1208 entry->crc[2] = I915_READ(PIPE_CRC_RES_3_IVB(pipe));
1209 entry->crc[3] = I915_READ(PIPE_CRC_RES_4_IVB(pipe));
1210 entry->crc[4] = I915_READ(PIPE_CRC_RES_5_IVB(pipe));
1211 atomic_set(&dev_priv->pipe_crc[pipe].slot, slot);
1212 }
1213 #else
1214 static void ivb_pipe_crc_update(struct drm_device *dev, int pipe) {}
1215 #endif
1216
1217 /* The RPS events need forcewake, so we add them to a work queue and mask their
1218 * IMR bits until the work is done. Other interrupts can be processed without
1219 * the work queue. */
1220 static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
1221 {
1222 if (pm_iir & GEN6_PM_RPS_EVENTS) {
1223 spin_lock(&dev_priv->irq_lock);
1224 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
1225 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
1226 spin_unlock(&dev_priv->irq_lock);
1227
1228 queue_work(dev_priv->wq, &dev_priv->rps.work);
1229 }
1230
1231 if (HAS_VEBOX(dev_priv->dev)) {
1232 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1233 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
1234
1235 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1236 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1237 i915_handle_error(dev_priv->dev, false);
1238 }
1239 }
1240 }
1241
1242 static irqreturn_t valleyview_irq_handler(int irq, void *arg)
1243 {
1244 struct drm_device *dev = (struct drm_device *) arg;
1245 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1246 u32 iir, gt_iir, pm_iir;
1247 irqreturn_t ret = IRQ_NONE;
1248 unsigned long irqflags;
1249 int pipe;
1250 u32 pipe_stats[I915_MAX_PIPES];
1251
1252 atomic_inc(&dev_priv->irq_received);
1253
1254 while (true) {
1255 iir = I915_READ(VLV_IIR);
1256 gt_iir = I915_READ(GTIIR);
1257 pm_iir = I915_READ(GEN6_PMIIR);
1258
1259 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1260 goto out;
1261
1262 ret = IRQ_HANDLED;
1263
1264 snb_gt_irq_handler(dev, dev_priv, gt_iir);
1265
1266 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1267 for_each_pipe(pipe) {
1268 int reg = PIPESTAT(pipe);
1269 pipe_stats[pipe] = I915_READ(reg);
1270
1271 /*
1272 * Clear the PIPE*STAT regs before the IIR
1273 */
1274 if (pipe_stats[pipe] & 0x8000ffff) {
1275 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1276 DRM_DEBUG_DRIVER("pipe %c underrun\n",
1277 pipe_name(pipe));
1278 I915_WRITE(reg, pipe_stats[pipe]);
1279 }
1280 }
1281 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1282
1283 for_each_pipe(pipe) {
1284 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1285 drm_handle_vblank(dev, pipe);
1286
1287 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1288 intel_prepare_page_flip(dev, pipe);
1289 intel_finish_page_flip(dev, pipe);
1290 }
1291 }
1292
1293 /* Consume port. Then clear IIR or we'll miss events */
1294 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1295 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1296 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1297
1298 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1299 hotplug_status);
1300
1301 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1302
1303 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1304 I915_READ(PORT_HOTPLUG_STAT);
1305 }
1306
1307 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1308 gmbus_irq_handler(dev);
1309
1310 if (pm_iir)
1311 gen6_rps_irq_handler(dev_priv, pm_iir);
1312
1313 I915_WRITE(GTIIR, gt_iir);
1314 I915_WRITE(GEN6_PMIIR, pm_iir);
1315 I915_WRITE(VLV_IIR, iir);
1316 }
1317
1318 out:
1319 return ret;
1320 }
1321
1322 static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
1323 {
1324 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1325 int pipe;
1326 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
1327
1328 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1329
1330 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1331 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1332 SDE_AUDIO_POWER_SHIFT);
1333 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
1334 port_name(port));
1335 }
1336
1337 if (pch_iir & SDE_AUX_MASK)
1338 dp_aux_irq_handler(dev);
1339
1340 if (pch_iir & SDE_GMBUS)
1341 gmbus_irq_handler(dev);
1342
1343 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1344 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1345
1346 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1347 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1348
1349 if (pch_iir & SDE_POISON)
1350 DRM_ERROR("PCH poison interrupt\n");
1351
1352 if (pch_iir & SDE_FDI_MASK)
1353 for_each_pipe(pipe)
1354 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1355 pipe_name(pipe),
1356 I915_READ(FDI_RX_IIR(pipe)));
1357
1358 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1359 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1360
1361 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1362 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1363
1364 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
1365 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1366 false))
1367 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1368
1369 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1370 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1371 false))
1372 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1373 }
1374
1375 static void ivb_err_int_handler(struct drm_device *dev)
1376 {
1377 struct drm_i915_private *dev_priv = dev->dev_private;
1378 u32 err_int = I915_READ(GEN7_ERR_INT);
1379
1380 if (err_int & ERR_INT_POISON)
1381 DRM_ERROR("Poison interrupt\n");
1382
1383 if (err_int & ERR_INT_FIFO_UNDERRUN_A)
1384 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
1385 DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1386
1387 if (err_int & ERR_INT_FIFO_UNDERRUN_B)
1388 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
1389 DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1390
1391 if (err_int & ERR_INT_FIFO_UNDERRUN_C)
1392 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false))
1393 DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n");
1394
1395 if (err_int & ERR_INT_PIPE_CRC_DONE_A)
1396 ivb_pipe_crc_update(dev, PIPE_A);
1397
1398 if (err_int & ERR_INT_PIPE_CRC_DONE_B)
1399 ivb_pipe_crc_update(dev, PIPE_B);
1400
1401 if (err_int & ERR_INT_PIPE_CRC_DONE_C)
1402 ivb_pipe_crc_update(dev, PIPE_C);
1403
1404 I915_WRITE(GEN7_ERR_INT, err_int);
1405 }
1406
1407 static void cpt_serr_int_handler(struct drm_device *dev)
1408 {
1409 struct drm_i915_private *dev_priv = dev->dev_private;
1410 u32 serr_int = I915_READ(SERR_INT);
1411
1412 if (serr_int & SERR_INT_POISON)
1413 DRM_ERROR("PCH poison interrupt\n");
1414
1415 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1416 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1417 false))
1418 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1419
1420 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1421 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1422 false))
1423 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1424
1425 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1426 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1427 false))
1428 DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1429
1430 I915_WRITE(SERR_INT, serr_int);
1431 }
1432
1433 static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1434 {
1435 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1436 int pipe;
1437 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
1438
1439 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1440
1441 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1442 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1443 SDE_AUDIO_POWER_SHIFT_CPT);
1444 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1445 port_name(port));
1446 }
1447
1448 if (pch_iir & SDE_AUX_MASK_CPT)
1449 dp_aux_irq_handler(dev);
1450
1451 if (pch_iir & SDE_GMBUS_CPT)
1452 gmbus_irq_handler(dev);
1453
1454 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1455 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1456
1457 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1458 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1459
1460 if (pch_iir & SDE_FDI_MASK_CPT)
1461 for_each_pipe(pipe)
1462 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1463 pipe_name(pipe),
1464 I915_READ(FDI_RX_IIR(pipe)));
1465
1466 if (pch_iir & SDE_ERROR_CPT)
1467 cpt_serr_int_handler(dev);
1468 }
1469
1470 static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1471 {
1472 struct drm_i915_private *dev_priv = dev->dev_private;
1473
1474 if (de_iir & DE_AUX_CHANNEL_A)
1475 dp_aux_irq_handler(dev);
1476
1477 if (de_iir & DE_GSE)
1478 intel_opregion_asle_intr(dev);
1479
1480 if (de_iir & DE_PIPEA_VBLANK)
1481 drm_handle_vblank(dev, 0);
1482
1483 if (de_iir & DE_PIPEB_VBLANK)
1484 drm_handle_vblank(dev, 1);
1485
1486 if (de_iir & DE_POISON)
1487 DRM_ERROR("Poison interrupt\n");
1488
1489 if (de_iir & DE_PIPEA_FIFO_UNDERRUN)
1490 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
1491 DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1492
1493 if (de_iir & DE_PIPEB_FIFO_UNDERRUN)
1494 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
1495 DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1496
1497 if (de_iir & DE_PLANEA_FLIP_DONE) {
1498 intel_prepare_page_flip(dev, 0);
1499 intel_finish_page_flip_plane(dev, 0);
1500 }
1501
1502 if (de_iir & DE_PLANEB_FLIP_DONE) {
1503 intel_prepare_page_flip(dev, 1);
1504 intel_finish_page_flip_plane(dev, 1);
1505 }
1506
1507 /* check event from PCH */
1508 if (de_iir & DE_PCH_EVENT) {
1509 u32 pch_iir = I915_READ(SDEIIR);
1510
1511 if (HAS_PCH_CPT(dev))
1512 cpt_irq_handler(dev, pch_iir);
1513 else
1514 ibx_irq_handler(dev, pch_iir);
1515
1516 /* should clear PCH hotplug event before clear CPU irq */
1517 I915_WRITE(SDEIIR, pch_iir);
1518 }
1519
1520 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1521 ironlake_rps_change_irq_handler(dev);
1522 }
1523
1524 static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1525 {
1526 struct drm_i915_private *dev_priv = dev->dev_private;
1527 int i;
1528
1529 if (de_iir & DE_ERR_INT_IVB)
1530 ivb_err_int_handler(dev);
1531
1532 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1533 dp_aux_irq_handler(dev);
1534
1535 if (de_iir & DE_GSE_IVB)
1536 intel_opregion_asle_intr(dev);
1537
1538 for (i = 0; i < 3; i++) {
1539 if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
1540 drm_handle_vblank(dev, i);
1541 if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
1542 intel_prepare_page_flip(dev, i);
1543 intel_finish_page_flip_plane(dev, i);
1544 }
1545 }
1546
1547 /* check event from PCH */
1548 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1549 u32 pch_iir = I915_READ(SDEIIR);
1550
1551 cpt_irq_handler(dev, pch_iir);
1552
1553 /* clear PCH hotplug event before clear CPU irq */
1554 I915_WRITE(SDEIIR, pch_iir);
1555 }
1556 }
1557
1558 static irqreturn_t ironlake_irq_handler(int irq, void *arg)
1559 {
1560 struct drm_device *dev = (struct drm_device *) arg;
1561 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1562 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
1563 irqreturn_t ret = IRQ_NONE;
1564
1565 atomic_inc(&dev_priv->irq_received);
1566
1567 /* We get interrupts on unclaimed registers, so check for this before we
1568 * do any I915_{READ,WRITE}. */
1569 intel_uncore_check_errors(dev);
1570
1571 /* disable master interrupt before clearing iir */
1572 de_ier = I915_READ(DEIER);
1573 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
1574 POSTING_READ(DEIER);
1575
1576 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1577 * interrupts will will be stored on its back queue, and then we'll be
1578 * able to process them after we restore SDEIER (as soon as we restore
1579 * it, we'll get an interrupt if SDEIIR still has something to process
1580 * due to its back queue). */
1581 if (!HAS_PCH_NOP(dev)) {
1582 sde_ier = I915_READ(SDEIER);
1583 I915_WRITE(SDEIER, 0);
1584 POSTING_READ(SDEIER);
1585 }
1586
1587 gt_iir = I915_READ(GTIIR);
1588 if (gt_iir) {
1589 if (INTEL_INFO(dev)->gen >= 6)
1590 snb_gt_irq_handler(dev, dev_priv, gt_iir);
1591 else
1592 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
1593 I915_WRITE(GTIIR, gt_iir);
1594 ret = IRQ_HANDLED;
1595 }
1596
1597 de_iir = I915_READ(DEIIR);
1598 if (de_iir) {
1599 if (INTEL_INFO(dev)->gen >= 7)
1600 ivb_display_irq_handler(dev, de_iir);
1601 else
1602 ilk_display_irq_handler(dev, de_iir);
1603 I915_WRITE(DEIIR, de_iir);
1604 ret = IRQ_HANDLED;
1605 }
1606
1607 if (INTEL_INFO(dev)->gen >= 6) {
1608 u32 pm_iir = I915_READ(GEN6_PMIIR);
1609 if (pm_iir) {
1610 gen6_rps_irq_handler(dev_priv, pm_iir);
1611 I915_WRITE(GEN6_PMIIR, pm_iir);
1612 ret = IRQ_HANDLED;
1613 }
1614 }
1615
1616 I915_WRITE(DEIER, de_ier);
1617 POSTING_READ(DEIER);
1618 if (!HAS_PCH_NOP(dev)) {
1619 I915_WRITE(SDEIER, sde_ier);
1620 POSTING_READ(SDEIER);
1621 }
1622
1623 return ret;
1624 }
1625
1626 static void i915_error_wake_up(struct drm_i915_private *dev_priv,
1627 bool reset_completed)
1628 {
1629 struct intel_ring_buffer *ring;
1630 int i;
1631
1632 /*
1633 * Notify all waiters for GPU completion events that reset state has
1634 * been changed, and that they need to restart their wait after
1635 * checking for potential errors (and bail out to drop locks if there is
1636 * a gpu reset pending so that i915_error_work_func can acquire them).
1637 */
1638
1639 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
1640 for_each_ring(ring, dev_priv, i)
1641 wake_up_all(&ring->irq_queue);
1642
1643 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
1644 wake_up_all(&dev_priv->pending_flip_queue);
1645
1646 /*
1647 * Signal tasks blocked in i915_gem_wait_for_error that the pending
1648 * reset state is cleared.
1649 */
1650 if (reset_completed)
1651 wake_up_all(&dev_priv->gpu_error.reset_queue);
1652 }
1653
1654 /**
1655 * i915_error_work_func - do process context error handling work
1656 * @work: work struct
1657 *
1658 * Fire an error uevent so userspace can see that a hang or error
1659 * was detected.
1660 */
1661 static void i915_error_work_func(struct work_struct *work)
1662 {
1663 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1664 work);
1665 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1666 gpu_error);
1667 struct drm_device *dev = dev_priv->dev;
1668 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
1669 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
1670 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
1671 int ret;
1672
1673 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
1674
1675 /*
1676 * Note that there's only one work item which does gpu resets, so we
1677 * need not worry about concurrent gpu resets potentially incrementing
1678 * error->reset_counter twice. We only need to take care of another
1679 * racing irq/hangcheck declaring the gpu dead for a second time. A
1680 * quick check for that is good enough: schedule_work ensures the
1681 * correct ordering between hang detection and this work item, and since
1682 * the reset in-progress bit is only ever set by code outside of this
1683 * work we don't need to worry about any other races.
1684 */
1685 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
1686 DRM_DEBUG_DRIVER("resetting chip\n");
1687 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
1688 reset_event);
1689
1690 /*
1691 * All state reset _must_ be completed before we update the
1692 * reset counter, for otherwise waiters might miss the reset
1693 * pending state and not properly drop locks, resulting in
1694 * deadlocks with the reset work.
1695 */
1696 ret = i915_reset(dev);
1697
1698 intel_display_handle_reset(dev);
1699
1700 if (ret == 0) {
1701 /*
1702 * After all the gem state is reset, increment the reset
1703 * counter and wake up everyone waiting for the reset to
1704 * complete.
1705 *
1706 * Since unlock operations are a one-sided barrier only,
1707 * we need to insert a barrier here to order any seqno
1708 * updates before
1709 * the counter increment.
1710 */
1711 smp_mb__before_atomic_inc();
1712 atomic_inc(&dev_priv->gpu_error.reset_counter);
1713
1714 kobject_uevent_env(&dev->primary->kdev.kobj,
1715 KOBJ_CHANGE, reset_done_event);
1716 } else {
1717 atomic_set(&error->reset_counter, I915_WEDGED);
1718 }
1719
1720 /*
1721 * Note: The wake_up also serves as a memory barrier so that
1722 * waiters see the update value of the reset counter atomic_t.
1723 */
1724 i915_error_wake_up(dev_priv, true);
1725 }
1726 }
1727
1728 static void i915_report_and_clear_eir(struct drm_device *dev)
1729 {
1730 struct drm_i915_private *dev_priv = dev->dev_private;
1731 uint32_t instdone[I915_NUM_INSTDONE_REG];
1732 u32 eir = I915_READ(EIR);
1733 int pipe, i;
1734
1735 if (!eir)
1736 return;
1737
1738 pr_err("render error detected, EIR: 0x%08x\n", eir);
1739
1740 i915_get_extra_instdone(dev, instdone);
1741
1742 if (IS_G4X(dev)) {
1743 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
1744 u32 ipeir = I915_READ(IPEIR_I965);
1745
1746 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1747 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
1748 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1749 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
1750 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
1751 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
1752 I915_WRITE(IPEIR_I965, ipeir);
1753 POSTING_READ(IPEIR_I965);
1754 }
1755 if (eir & GM45_ERROR_PAGE_TABLE) {
1756 u32 pgtbl_err = I915_READ(PGTBL_ER);
1757 pr_err("page table error\n");
1758 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
1759 I915_WRITE(PGTBL_ER, pgtbl_err);
1760 POSTING_READ(PGTBL_ER);
1761 }
1762 }
1763
1764 if (!IS_GEN2(dev)) {
1765 if (eir & I915_ERROR_PAGE_TABLE) {
1766 u32 pgtbl_err = I915_READ(PGTBL_ER);
1767 pr_err("page table error\n");
1768 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
1769 I915_WRITE(PGTBL_ER, pgtbl_err);
1770 POSTING_READ(PGTBL_ER);
1771 }
1772 }
1773
1774 if (eir & I915_ERROR_MEMORY_REFRESH) {
1775 pr_err("memory refresh error:\n");
1776 for_each_pipe(pipe)
1777 pr_err("pipe %c stat: 0x%08x\n",
1778 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
1779 /* pipestat has already been acked */
1780 }
1781 if (eir & I915_ERROR_INSTRUCTION) {
1782 pr_err("instruction error\n");
1783 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
1784 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1785 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
1786 if (INTEL_INFO(dev)->gen < 4) {
1787 u32 ipeir = I915_READ(IPEIR);
1788
1789 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
1790 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
1791 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
1792 I915_WRITE(IPEIR, ipeir);
1793 POSTING_READ(IPEIR);
1794 } else {
1795 u32 ipeir = I915_READ(IPEIR_I965);
1796
1797 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1798 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
1799 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
1800 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
1801 I915_WRITE(IPEIR_I965, ipeir);
1802 POSTING_READ(IPEIR_I965);
1803 }
1804 }
1805
1806 I915_WRITE(EIR, eir);
1807 POSTING_READ(EIR);
1808 eir = I915_READ(EIR);
1809 if (eir) {
1810 /*
1811 * some errors might have become stuck,
1812 * mask them.
1813 */
1814 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
1815 I915_WRITE(EMR, I915_READ(EMR) | eir);
1816 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1817 }
1818 }
1819
1820 /**
1821 * i915_handle_error - handle an error interrupt
1822 * @dev: drm device
1823 *
1824 * Do some basic checking of regsiter state at error interrupt time and
1825 * dump it to the syslog. Also call i915_capture_error_state() to make
1826 * sure we get a record and make it available in debugfs. Fire a uevent
1827 * so userspace knows something bad happened (should trigger collection
1828 * of a ring dump etc.).
1829 */
1830 void i915_handle_error(struct drm_device *dev, bool wedged)
1831 {
1832 struct drm_i915_private *dev_priv = dev->dev_private;
1833
1834 i915_capture_error_state(dev);
1835 i915_report_and_clear_eir(dev);
1836
1837 if (wedged) {
1838 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
1839 &dev_priv->gpu_error.reset_counter);
1840
1841 /*
1842 * Wakeup waiting processes so that the reset work function
1843 * i915_error_work_func doesn't deadlock trying to grab various
1844 * locks. By bumping the reset counter first, the woken
1845 * processes will see a reset in progress and back off,
1846 * releasing their locks and then wait for the reset completion.
1847 * We must do this for _all_ gpu waiters that might hold locks
1848 * that the reset work needs to acquire.
1849 *
1850 * Note: The wake_up serves as the required memory barrier to
1851 * ensure that the waiters see the updated value of the reset
1852 * counter atomic_t.
1853 */
1854 i915_error_wake_up(dev_priv, false);
1855 }
1856
1857 /*
1858 * Our reset work can grab modeset locks (since it needs to reset the
1859 * state of outstanding pagelips). Hence it must not be run on our own
1860 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
1861 * code will deadlock.
1862 */
1863 schedule_work(&dev_priv->gpu_error.work);
1864 }
1865
1866 static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
1867 {
1868 drm_i915_private_t *dev_priv = dev->dev_private;
1869 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1870 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1871 struct drm_i915_gem_object *obj;
1872 struct intel_unpin_work *work;
1873 unsigned long flags;
1874 bool stall_detected;
1875
1876 /* Ignore early vblank irqs */
1877 if (intel_crtc == NULL)
1878 return;
1879
1880 spin_lock_irqsave(&dev->event_lock, flags);
1881 work = intel_crtc->unpin_work;
1882
1883 if (work == NULL ||
1884 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
1885 !work->enable_stall_check) {
1886 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
1887 spin_unlock_irqrestore(&dev->event_lock, flags);
1888 return;
1889 }
1890
1891 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
1892 obj = work->pending_flip_obj;
1893 if (INTEL_INFO(dev)->gen >= 4) {
1894 int dspsurf = DSPSURF(intel_crtc->plane);
1895 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
1896 i915_gem_obj_ggtt_offset(obj);
1897 } else {
1898 int dspaddr = DSPADDR(intel_crtc->plane);
1899 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
1900 crtc->y * crtc->fb->pitches[0] +
1901 crtc->x * crtc->fb->bits_per_pixel/8);
1902 }
1903
1904 spin_unlock_irqrestore(&dev->event_lock, flags);
1905
1906 if (stall_detected) {
1907 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
1908 intel_prepare_page_flip(dev, intel_crtc->plane);
1909 }
1910 }
1911
1912 /* Called from drm generic code, passed 'crtc' which
1913 * we use as a pipe index
1914 */
1915 static int i915_enable_vblank(struct drm_device *dev, int pipe)
1916 {
1917 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1918 unsigned long irqflags;
1919
1920 if (!i915_pipe_enabled(dev, pipe))
1921 return -EINVAL;
1922
1923 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1924 if (INTEL_INFO(dev)->gen >= 4)
1925 i915_enable_pipestat(dev_priv, pipe,
1926 PIPE_START_VBLANK_INTERRUPT_ENABLE);
1927 else
1928 i915_enable_pipestat(dev_priv, pipe,
1929 PIPE_VBLANK_INTERRUPT_ENABLE);
1930
1931 /* maintain vblank delivery even in deep C-states */
1932 if (dev_priv->info->gen == 3)
1933 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
1934 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1935
1936 return 0;
1937 }
1938
1939 static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
1940 {
1941 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1942 unsigned long irqflags;
1943 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
1944 DE_PIPE_VBLANK_ILK(pipe);
1945
1946 if (!i915_pipe_enabled(dev, pipe))
1947 return -EINVAL;
1948
1949 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1950 ironlake_enable_display_irq(dev_priv, bit);
1951 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1952
1953 return 0;
1954 }
1955
1956 static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
1957 {
1958 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1959 unsigned long irqflags;
1960 u32 imr;
1961
1962 if (!i915_pipe_enabled(dev, pipe))
1963 return -EINVAL;
1964
1965 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1966 imr = I915_READ(VLV_IMR);
1967 if (pipe == 0)
1968 imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
1969 else
1970 imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
1971 I915_WRITE(VLV_IMR, imr);
1972 i915_enable_pipestat(dev_priv, pipe,
1973 PIPE_START_VBLANK_INTERRUPT_ENABLE);
1974 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1975
1976 return 0;
1977 }
1978
1979 /* Called from drm generic code, passed 'crtc' which
1980 * we use as a pipe index
1981 */
1982 static void i915_disable_vblank(struct drm_device *dev, int pipe)
1983 {
1984 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1985 unsigned long irqflags;
1986
1987 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1988 if (dev_priv->info->gen == 3)
1989 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
1990
1991 i915_disable_pipestat(dev_priv, pipe,
1992 PIPE_VBLANK_INTERRUPT_ENABLE |
1993 PIPE_START_VBLANK_INTERRUPT_ENABLE);
1994 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1995 }
1996
1997 static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
1998 {
1999 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2000 unsigned long irqflags;
2001 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
2002 DE_PIPE_VBLANK_ILK(pipe);
2003
2004 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2005 ironlake_disable_display_irq(dev_priv, bit);
2006 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2007 }
2008
2009 static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2010 {
2011 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2012 unsigned long irqflags;
2013 u32 imr;
2014
2015 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2016 i915_disable_pipestat(dev_priv, pipe,
2017 PIPE_START_VBLANK_INTERRUPT_ENABLE);
2018 imr = I915_READ(VLV_IMR);
2019 if (pipe == 0)
2020 imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
2021 else
2022 imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2023 I915_WRITE(VLV_IMR, imr);
2024 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2025 }
2026
2027 static u32
2028 ring_last_seqno(struct intel_ring_buffer *ring)
2029 {
2030 return list_entry(ring->request_list.prev,
2031 struct drm_i915_gem_request, list)->seqno;
2032 }
2033
2034 static bool
2035 ring_idle(struct intel_ring_buffer *ring, u32 seqno)
2036 {
2037 return (list_empty(&ring->request_list) ||
2038 i915_seqno_passed(seqno, ring_last_seqno(ring)));
2039 }
2040
2041 static struct intel_ring_buffer *
2042 semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
2043 {
2044 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2045 u32 cmd, ipehr, acthd, acthd_min;
2046
2047 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2048 if ((ipehr & ~(0x3 << 16)) !=
2049 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
2050 return NULL;
2051
2052 /* ACTHD is likely pointing to the dword after the actual command,
2053 * so scan backwards until we find the MBOX.
2054 */
2055 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
2056 acthd_min = max((int)acthd - 3 * 4, 0);
2057 do {
2058 cmd = ioread32(ring->virtual_start + acthd);
2059 if (cmd == ipehr)
2060 break;
2061
2062 acthd -= 4;
2063 if (acthd < acthd_min)
2064 return NULL;
2065 } while (1);
2066
2067 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2068 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
2069 }
2070
2071 static int semaphore_passed(struct intel_ring_buffer *ring)
2072 {
2073 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2074 struct intel_ring_buffer *signaller;
2075 u32 seqno, ctl;
2076
2077 ring->hangcheck.deadlock = true;
2078
2079 signaller = semaphore_waits_for(ring, &seqno);
2080 if (signaller == NULL || signaller->hangcheck.deadlock)
2081 return -1;
2082
2083 /* cursory check for an unkickable deadlock */
2084 ctl = I915_READ_CTL(signaller);
2085 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2086 return -1;
2087
2088 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2089 }
2090
2091 static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2092 {
2093 struct intel_ring_buffer *ring;
2094 int i;
2095
2096 for_each_ring(ring, dev_priv, i)
2097 ring->hangcheck.deadlock = false;
2098 }
2099
2100 static enum intel_ring_hangcheck_action
2101 ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
2102 {
2103 struct drm_device *dev = ring->dev;
2104 struct drm_i915_private *dev_priv = dev->dev_private;
2105 u32 tmp;
2106
2107 if (ring->hangcheck.acthd != acthd)
2108 return HANGCHECK_ACTIVE;
2109
2110 if (IS_GEN2(dev))
2111 return HANGCHECK_HUNG;
2112
2113 /* Is the chip hanging on a WAIT_FOR_EVENT?
2114 * If so we can simply poke the RB_WAIT bit
2115 * and break the hang. This should work on
2116 * all but the second generation chipsets.
2117 */
2118 tmp = I915_READ_CTL(ring);
2119 if (tmp & RING_WAIT) {
2120 DRM_ERROR("Kicking stuck wait on %s\n",
2121 ring->name);
2122 i915_handle_error(dev, false);
2123 I915_WRITE_CTL(ring, tmp);
2124 return HANGCHECK_KICK;
2125 }
2126
2127 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2128 switch (semaphore_passed(ring)) {
2129 default:
2130 return HANGCHECK_HUNG;
2131 case 1:
2132 DRM_ERROR("Kicking stuck semaphore on %s\n",
2133 ring->name);
2134 i915_handle_error(dev, false);
2135 I915_WRITE_CTL(ring, tmp);
2136 return HANGCHECK_KICK;
2137 case 0:
2138 return HANGCHECK_WAIT;
2139 }
2140 }
2141
2142 return HANGCHECK_HUNG;
2143 }
2144
2145 /**
2146 * This is called when the chip hasn't reported back with completed
2147 * batchbuffers in a long time. We keep track per ring seqno progress and
2148 * if there are no progress, hangcheck score for that ring is increased.
2149 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2150 * we kick the ring. If we see no progress on three subsequent calls
2151 * we assume chip is wedged and try to fix it by resetting the chip.
2152 */
2153 static void i915_hangcheck_elapsed(unsigned long data)
2154 {
2155 struct drm_device *dev = (struct drm_device *)data;
2156 drm_i915_private_t *dev_priv = dev->dev_private;
2157 struct intel_ring_buffer *ring;
2158 int i;
2159 int busy_count = 0, rings_hung = 0;
2160 bool stuck[I915_NUM_RINGS] = { 0 };
2161 #define BUSY 1
2162 #define KICK 5
2163 #define HUNG 20
2164 #define FIRE 30
2165
2166 if (!i915_enable_hangcheck)
2167 return;
2168
2169 for_each_ring(ring, dev_priv, i) {
2170 u32 seqno, acthd;
2171 bool busy = true;
2172
2173 semaphore_clear_deadlocks(dev_priv);
2174
2175 seqno = ring->get_seqno(ring, false);
2176 acthd = intel_ring_get_active_head(ring);
2177
2178 if (ring->hangcheck.seqno == seqno) {
2179 if (ring_idle(ring, seqno)) {
2180 ring->hangcheck.action = HANGCHECK_IDLE;
2181
2182 if (waitqueue_active(&ring->irq_queue)) {
2183 /* Issue a wake-up to catch stuck h/w. */
2184 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
2185 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2186 ring->name);
2187 wake_up_all(&ring->irq_queue);
2188 }
2189 /* Safeguard against driver failure */
2190 ring->hangcheck.score += BUSY;
2191 } else
2192 busy = false;
2193 } else {
2194 /* We always increment the hangcheck score
2195 * if the ring is busy and still processing
2196 * the same request, so that no single request
2197 * can run indefinitely (such as a chain of
2198 * batches). The only time we do not increment
2199 * the hangcheck score on this ring, if this
2200 * ring is in a legitimate wait for another
2201 * ring. In that case the waiting ring is a
2202 * victim and we want to be sure we catch the
2203 * right culprit. Then every time we do kick
2204 * the ring, add a small increment to the
2205 * score so that we can catch a batch that is
2206 * being repeatedly kicked and so responsible
2207 * for stalling the machine.
2208 */
2209 ring->hangcheck.action = ring_stuck(ring,
2210 acthd);
2211
2212 switch (ring->hangcheck.action) {
2213 case HANGCHECK_IDLE:
2214 case HANGCHECK_WAIT:
2215 break;
2216 case HANGCHECK_ACTIVE:
2217 ring->hangcheck.score += BUSY;
2218 break;
2219 case HANGCHECK_KICK:
2220 ring->hangcheck.score += KICK;
2221 break;
2222 case HANGCHECK_HUNG:
2223 ring->hangcheck.score += HUNG;
2224 stuck[i] = true;
2225 break;
2226 }
2227 }
2228 } else {
2229 ring->hangcheck.action = HANGCHECK_ACTIVE;
2230
2231 /* Gradually reduce the count so that we catch DoS
2232 * attempts across multiple batches.
2233 */
2234 if (ring->hangcheck.score > 0)
2235 ring->hangcheck.score--;
2236 }
2237
2238 ring->hangcheck.seqno = seqno;
2239 ring->hangcheck.acthd = acthd;
2240 busy_count += busy;
2241 }
2242
2243 for_each_ring(ring, dev_priv, i) {
2244 if (ring->hangcheck.score > FIRE) {
2245 DRM_INFO("%s on %s\n",
2246 stuck[i] ? "stuck" : "no progress",
2247 ring->name);
2248 rings_hung++;
2249 }
2250 }
2251
2252 if (rings_hung)
2253 return i915_handle_error(dev, true);
2254
2255 if (busy_count)
2256 /* Reset timer case chip hangs without another request
2257 * being added */
2258 i915_queue_hangcheck(dev);
2259 }
2260
2261 void i915_queue_hangcheck(struct drm_device *dev)
2262 {
2263 struct drm_i915_private *dev_priv = dev->dev_private;
2264 if (!i915_enable_hangcheck)
2265 return;
2266
2267 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2268 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
2269 }
2270
2271 static void ibx_irq_preinstall(struct drm_device *dev)
2272 {
2273 struct drm_i915_private *dev_priv = dev->dev_private;
2274
2275 if (HAS_PCH_NOP(dev))
2276 return;
2277
2278 /* south display irq */
2279 I915_WRITE(SDEIMR, 0xffffffff);
2280 /*
2281 * SDEIER is also touched by the interrupt handler to work around missed
2282 * PCH interrupts. Hence we can't update it after the interrupt handler
2283 * is enabled - instead we unconditionally enable all PCH interrupt
2284 * sources here, but then only unmask them as needed with SDEIMR.
2285 */
2286 I915_WRITE(SDEIER, 0xffffffff);
2287 POSTING_READ(SDEIER);
2288 }
2289
2290 static void gen5_gt_irq_preinstall(struct drm_device *dev)
2291 {
2292 struct drm_i915_private *dev_priv = dev->dev_private;
2293
2294 /* and GT */
2295 I915_WRITE(GTIMR, 0xffffffff);
2296 I915_WRITE(GTIER, 0x0);
2297 POSTING_READ(GTIER);
2298
2299 if (INTEL_INFO(dev)->gen >= 6) {
2300 /* and PM */
2301 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2302 I915_WRITE(GEN6_PMIER, 0x0);
2303 POSTING_READ(GEN6_PMIER);
2304 }
2305 }
2306
2307 /* drm_dma.h hooks
2308 */
2309 static void ironlake_irq_preinstall(struct drm_device *dev)
2310 {
2311 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2312
2313 atomic_set(&dev_priv->irq_received, 0);
2314
2315 I915_WRITE(HWSTAM, 0xeffe);
2316
2317 I915_WRITE(DEIMR, 0xffffffff);
2318 I915_WRITE(DEIER, 0x0);
2319 POSTING_READ(DEIER);
2320
2321 gen5_gt_irq_preinstall(dev);
2322
2323 ibx_irq_preinstall(dev);
2324 }
2325
2326 static void valleyview_irq_preinstall(struct drm_device *dev)
2327 {
2328 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2329 int pipe;
2330
2331 atomic_set(&dev_priv->irq_received, 0);
2332
2333 /* VLV magic */
2334 I915_WRITE(VLV_IMR, 0);
2335 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2336 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2337 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2338
2339 /* and GT */
2340 I915_WRITE(GTIIR, I915_READ(GTIIR));
2341 I915_WRITE(GTIIR, I915_READ(GTIIR));
2342
2343 gen5_gt_irq_preinstall(dev);
2344
2345 I915_WRITE(DPINVGTT, 0xff);
2346
2347 I915_WRITE(PORT_HOTPLUG_EN, 0);
2348 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2349 for_each_pipe(pipe)
2350 I915_WRITE(PIPESTAT(pipe), 0xffff);
2351 I915_WRITE(VLV_IIR, 0xffffffff);
2352 I915_WRITE(VLV_IMR, 0xffffffff);
2353 I915_WRITE(VLV_IER, 0x0);
2354 POSTING_READ(VLV_IER);
2355 }
2356
2357 static void ibx_hpd_irq_setup(struct drm_device *dev)
2358 {
2359 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2360 struct drm_mode_config *mode_config = &dev->mode_config;
2361 struct intel_encoder *intel_encoder;
2362 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
2363
2364 if (HAS_PCH_IBX(dev)) {
2365 hotplug_irqs = SDE_HOTPLUG_MASK;
2366 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
2367 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
2368 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
2369 } else {
2370 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
2371 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
2372 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
2373 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
2374 }
2375
2376 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
2377
2378 /*
2379 * Enable digital hotplug on the PCH, and configure the DP short pulse
2380 * duration to 2ms (which is the minimum in the Display Port spec)
2381 *
2382 * This register is the same on all known PCH chips.
2383 */
2384 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2385 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2386 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2387 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2388 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2389 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2390 }
2391
2392 static void ibx_irq_postinstall(struct drm_device *dev)
2393 {
2394 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2395 u32 mask;
2396
2397 if (HAS_PCH_NOP(dev))
2398 return;
2399
2400 if (HAS_PCH_IBX(dev)) {
2401 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
2402 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
2403 } else {
2404 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2405
2406 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2407 }
2408
2409 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2410 I915_WRITE(SDEIMR, ~mask);
2411 }
2412
2413 static void gen5_gt_irq_postinstall(struct drm_device *dev)
2414 {
2415 struct drm_i915_private *dev_priv = dev->dev_private;
2416 u32 pm_irqs, gt_irqs;
2417
2418 pm_irqs = gt_irqs = 0;
2419
2420 dev_priv->gt_irq_mask = ~0;
2421 if (HAS_L3_DPF(dev)) {
2422 /* L3 parity interrupt is always unmasked. */
2423 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2424 gt_irqs |= GT_PARITY_ERROR(dev);
2425 }
2426
2427 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2428 if (IS_GEN5(dev)) {
2429 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2430 ILK_BSD_USER_INTERRUPT;
2431 } else {
2432 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2433 }
2434
2435 I915_WRITE(GTIIR, I915_READ(GTIIR));
2436 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2437 I915_WRITE(GTIER, gt_irqs);
2438 POSTING_READ(GTIER);
2439
2440 if (INTEL_INFO(dev)->gen >= 6) {
2441 pm_irqs |= GEN6_PM_RPS_EVENTS;
2442
2443 if (HAS_VEBOX(dev))
2444 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2445
2446 dev_priv->pm_irq_mask = 0xffffffff;
2447 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
2448 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
2449 I915_WRITE(GEN6_PMIER, pm_irqs);
2450 POSTING_READ(GEN6_PMIER);
2451 }
2452 }
2453
2454 static int ironlake_irq_postinstall(struct drm_device *dev)
2455 {
2456 unsigned long irqflags;
2457 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2458 u32 display_mask, extra_mask;
2459
2460 if (INTEL_INFO(dev)->gen >= 7) {
2461 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2462 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2463 DE_PLANEB_FLIP_DONE_IVB |
2464 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2465 DE_ERR_INT_IVB);
2466 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2467 DE_PIPEA_VBLANK_IVB);
2468
2469 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2470 } else {
2471 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2472 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
2473 DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN |
2474 DE_PIPEA_FIFO_UNDERRUN | DE_POISON);
2475 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2476 }
2477
2478 dev_priv->irq_mask = ~display_mask;
2479
2480 /* should always can generate irq */
2481 I915_WRITE(DEIIR, I915_READ(DEIIR));
2482 I915_WRITE(DEIMR, dev_priv->irq_mask);
2483 I915_WRITE(DEIER, display_mask | extra_mask);
2484 POSTING_READ(DEIER);
2485
2486 gen5_gt_irq_postinstall(dev);
2487
2488 ibx_irq_postinstall(dev);
2489
2490 if (IS_IRONLAKE_M(dev)) {
2491 /* Enable PCU event interrupts
2492 *
2493 * spinlocking not required here for correctness since interrupt
2494 * setup is guaranteed to run in single-threaded context. But we
2495 * need it to make the assert_spin_locked happy. */
2496 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2497 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
2498 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2499 }
2500
2501 return 0;
2502 }
2503
2504 static int valleyview_irq_postinstall(struct drm_device *dev)
2505 {
2506 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2507 u32 enable_mask;
2508 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV;
2509 unsigned long irqflags;
2510
2511 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
2512 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2513 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2514 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2515 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2516
2517 /*
2518 *Leave vblank interrupts masked initially. enable/disable will
2519 * toggle them based on usage.
2520 */
2521 dev_priv->irq_mask = (~enable_mask) |
2522 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2523 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2524
2525 I915_WRITE(PORT_HOTPLUG_EN, 0);
2526 POSTING_READ(PORT_HOTPLUG_EN);
2527
2528 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2529 I915_WRITE(VLV_IER, enable_mask);
2530 I915_WRITE(VLV_IIR, 0xffffffff);
2531 I915_WRITE(PIPESTAT(0), 0xffff);
2532 I915_WRITE(PIPESTAT(1), 0xffff);
2533 POSTING_READ(VLV_IER);
2534
2535 /* Interrupt setup is already guaranteed to be single-threaded, this is
2536 * just to make the assert_spin_locked check happy. */
2537 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2538 i915_enable_pipestat(dev_priv, 0, pipestat_enable);
2539 i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
2540 i915_enable_pipestat(dev_priv, 1, pipestat_enable);
2541 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2542
2543 I915_WRITE(VLV_IIR, 0xffffffff);
2544 I915_WRITE(VLV_IIR, 0xffffffff);
2545
2546 gen5_gt_irq_postinstall(dev);
2547
2548 /* ack & enable invalid PTE error interrupts */
2549 #if 0 /* FIXME: add support to irq handler for checking these bits */
2550 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2551 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2552 #endif
2553
2554 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
2555
2556 return 0;
2557 }
2558
2559 static void valleyview_irq_uninstall(struct drm_device *dev)
2560 {
2561 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2562 int pipe;
2563
2564 if (!dev_priv)
2565 return;
2566
2567 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2568
2569 for_each_pipe(pipe)
2570 I915_WRITE(PIPESTAT(pipe), 0xffff);
2571
2572 I915_WRITE(HWSTAM, 0xffffffff);
2573 I915_WRITE(PORT_HOTPLUG_EN, 0);
2574 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2575 for_each_pipe(pipe)
2576 I915_WRITE(PIPESTAT(pipe), 0xffff);
2577 I915_WRITE(VLV_IIR, 0xffffffff);
2578 I915_WRITE(VLV_IMR, 0xffffffff);
2579 I915_WRITE(VLV_IER, 0x0);
2580 POSTING_READ(VLV_IER);
2581 }
2582
2583 static void ironlake_irq_uninstall(struct drm_device *dev)
2584 {
2585 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2586
2587 if (!dev_priv)
2588 return;
2589
2590 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2591
2592 I915_WRITE(HWSTAM, 0xffffffff);
2593
2594 I915_WRITE(DEIMR, 0xffffffff);
2595 I915_WRITE(DEIER, 0x0);
2596 I915_WRITE(DEIIR, I915_READ(DEIIR));
2597 if (IS_GEN7(dev))
2598 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2599
2600 I915_WRITE(GTIMR, 0xffffffff);
2601 I915_WRITE(GTIER, 0x0);
2602 I915_WRITE(GTIIR, I915_READ(GTIIR));
2603
2604 if (HAS_PCH_NOP(dev))
2605 return;
2606
2607 I915_WRITE(SDEIMR, 0xffffffff);
2608 I915_WRITE(SDEIER, 0x0);
2609 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2610 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
2611 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2612 }
2613
2614 static void i8xx_irq_preinstall(struct drm_device * dev)
2615 {
2616 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2617 int pipe;
2618
2619 atomic_set(&dev_priv->irq_received, 0);
2620
2621 for_each_pipe(pipe)
2622 I915_WRITE(PIPESTAT(pipe), 0);
2623 I915_WRITE16(IMR, 0xffff);
2624 I915_WRITE16(IER, 0x0);
2625 POSTING_READ16(IER);
2626 }
2627
2628 static int i8xx_irq_postinstall(struct drm_device *dev)
2629 {
2630 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2631
2632 I915_WRITE16(EMR,
2633 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2634
2635 /* Unmask the interrupts that we always want on. */
2636 dev_priv->irq_mask =
2637 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2638 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2639 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2640 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2641 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2642 I915_WRITE16(IMR, dev_priv->irq_mask);
2643
2644 I915_WRITE16(IER,
2645 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2646 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2647 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2648 I915_USER_INTERRUPT);
2649 POSTING_READ16(IER);
2650
2651 return 0;
2652 }
2653
2654 /*
2655 * Returns true when a page flip has completed.
2656 */
2657 static bool i8xx_handle_vblank(struct drm_device *dev,
2658 int pipe, u16 iir)
2659 {
2660 drm_i915_private_t *dev_priv = dev->dev_private;
2661 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
2662
2663 if (!drm_handle_vblank(dev, pipe))
2664 return false;
2665
2666 if ((iir & flip_pending) == 0)
2667 return false;
2668
2669 intel_prepare_page_flip(dev, pipe);
2670
2671 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2672 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2673 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2674 * the flip is completed (no longer pending). Since this doesn't raise
2675 * an interrupt per se, we watch for the change at vblank.
2676 */
2677 if (I915_READ16(ISR) & flip_pending)
2678 return false;
2679
2680 intel_finish_page_flip(dev, pipe);
2681
2682 return true;
2683 }
2684
2685 static irqreturn_t i8xx_irq_handler(int irq, void *arg)
2686 {
2687 struct drm_device *dev = (struct drm_device *) arg;
2688 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2689 u16 iir, new_iir;
2690 u32 pipe_stats[2];
2691 unsigned long irqflags;
2692 int pipe;
2693 u16 flip_mask =
2694 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2695 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
2696
2697 atomic_inc(&dev_priv->irq_received);
2698
2699 iir = I915_READ16(IIR);
2700 if (iir == 0)
2701 return IRQ_NONE;
2702
2703 while (iir & ~flip_mask) {
2704 /* Can't rely on pipestat interrupt bit in iir as it might
2705 * have been cleared after the pipestat interrupt was received.
2706 * It doesn't set the bit in iir again, but it still produces
2707 * interrupts (for non-MSI).
2708 */
2709 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2710 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2711 i915_handle_error(dev, false);
2712
2713 for_each_pipe(pipe) {
2714 int reg = PIPESTAT(pipe);
2715 pipe_stats[pipe] = I915_READ(reg);
2716
2717 /*
2718 * Clear the PIPE*STAT regs before the IIR
2719 */
2720 if (pipe_stats[pipe] & 0x8000ffff) {
2721 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2722 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2723 pipe_name(pipe));
2724 I915_WRITE(reg, pipe_stats[pipe]);
2725 }
2726 }
2727 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2728
2729 I915_WRITE16(IIR, iir & ~flip_mask);
2730 new_iir = I915_READ16(IIR); /* Flush posted writes */
2731
2732 i915_update_dri1_breadcrumb(dev);
2733
2734 if (iir & I915_USER_INTERRUPT)
2735 notify_ring(dev, &dev_priv->ring[RCS]);
2736
2737 if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS &&
2738 i8xx_handle_vblank(dev, 0, iir))
2739 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0);
2740
2741 if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
2742 i8xx_handle_vblank(dev, 1, iir))
2743 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1);
2744
2745 iir = new_iir;
2746 }
2747
2748 return IRQ_HANDLED;
2749 }
2750
2751 static void i8xx_irq_uninstall(struct drm_device * dev)
2752 {
2753 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2754 int pipe;
2755
2756 for_each_pipe(pipe) {
2757 /* Clear enable bits; then clear status bits */
2758 I915_WRITE(PIPESTAT(pipe), 0);
2759 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
2760 }
2761 I915_WRITE16(IMR, 0xffff);
2762 I915_WRITE16(IER, 0x0);
2763 I915_WRITE16(IIR, I915_READ16(IIR));
2764 }
2765
2766 static void i915_irq_preinstall(struct drm_device * dev)
2767 {
2768 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2769 int pipe;
2770
2771 atomic_set(&dev_priv->irq_received, 0);
2772
2773 if (I915_HAS_HOTPLUG(dev)) {
2774 I915_WRITE(PORT_HOTPLUG_EN, 0);
2775 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2776 }
2777
2778 I915_WRITE16(HWSTAM, 0xeffe);
2779 for_each_pipe(pipe)
2780 I915_WRITE(PIPESTAT(pipe), 0);
2781 I915_WRITE(IMR, 0xffffffff);
2782 I915_WRITE(IER, 0x0);
2783 POSTING_READ(IER);
2784 }
2785
2786 static int i915_irq_postinstall(struct drm_device *dev)
2787 {
2788 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2789 u32 enable_mask;
2790
2791 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2792
2793 /* Unmask the interrupts that we always want on. */
2794 dev_priv->irq_mask =
2795 ~(I915_ASLE_INTERRUPT |
2796 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2797 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2798 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2799 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2800 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2801
2802 enable_mask =
2803 I915_ASLE_INTERRUPT |
2804 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2805 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2806 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2807 I915_USER_INTERRUPT;
2808
2809 if (I915_HAS_HOTPLUG(dev)) {
2810 I915_WRITE(PORT_HOTPLUG_EN, 0);
2811 POSTING_READ(PORT_HOTPLUG_EN);
2812
2813 /* Enable in IER... */
2814 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
2815 /* and unmask in IMR */
2816 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
2817 }
2818
2819 I915_WRITE(IMR, dev_priv->irq_mask);
2820 I915_WRITE(IER, enable_mask);
2821 POSTING_READ(IER);
2822
2823 i915_enable_asle_pipestat(dev);
2824
2825 return 0;
2826 }
2827
2828 /*
2829 * Returns true when a page flip has completed.
2830 */
2831 static bool i915_handle_vblank(struct drm_device *dev,
2832 int plane, int pipe, u32 iir)
2833 {
2834 drm_i915_private_t *dev_priv = dev->dev_private;
2835 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
2836
2837 if (!drm_handle_vblank(dev, pipe))
2838 return false;
2839
2840 if ((iir & flip_pending) == 0)
2841 return false;
2842
2843 intel_prepare_page_flip(dev, plane);
2844
2845 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2846 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2847 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2848 * the flip is completed (no longer pending). Since this doesn't raise
2849 * an interrupt per se, we watch for the change at vblank.
2850 */
2851 if (I915_READ(ISR) & flip_pending)
2852 return false;
2853
2854 intel_finish_page_flip(dev, pipe);
2855
2856 return true;
2857 }
2858
2859 static irqreturn_t i915_irq_handler(int irq, void *arg)
2860 {
2861 struct drm_device *dev = (struct drm_device *) arg;
2862 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2863 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
2864 unsigned long irqflags;
2865 u32 flip_mask =
2866 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2867 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
2868 int pipe, ret = IRQ_NONE;
2869
2870 atomic_inc(&dev_priv->irq_received);
2871
2872 iir = I915_READ(IIR);
2873 do {
2874 bool irq_received = (iir & ~flip_mask) != 0;
2875 bool blc_event = false;
2876
2877 /* Can't rely on pipestat interrupt bit in iir as it might
2878 * have been cleared after the pipestat interrupt was received.
2879 * It doesn't set the bit in iir again, but it still produces
2880 * interrupts (for non-MSI).
2881 */
2882 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2883 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2884 i915_handle_error(dev, false);
2885
2886 for_each_pipe(pipe) {
2887 int reg = PIPESTAT(pipe);
2888 pipe_stats[pipe] = I915_READ(reg);
2889
2890 /* Clear the PIPE*STAT regs before the IIR */
2891 if (pipe_stats[pipe] & 0x8000ffff) {
2892 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2893 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2894 pipe_name(pipe));
2895 I915_WRITE(reg, pipe_stats[pipe]);
2896 irq_received = true;
2897 }
2898 }
2899 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2900
2901 if (!irq_received)
2902 break;
2903
2904 /* Consume port. Then clear IIR or we'll miss events */
2905 if ((I915_HAS_HOTPLUG(dev)) &&
2906 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
2907 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
2908 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
2909
2910 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
2911 hotplug_status);
2912
2913 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
2914
2915 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
2916 POSTING_READ(PORT_HOTPLUG_STAT);
2917 }
2918
2919 I915_WRITE(IIR, iir & ~flip_mask);
2920 new_iir = I915_READ(IIR); /* Flush posted writes */
2921
2922 if (iir & I915_USER_INTERRUPT)
2923 notify_ring(dev, &dev_priv->ring[RCS]);
2924
2925 for_each_pipe(pipe) {
2926 int plane = pipe;
2927 if (IS_MOBILE(dev))
2928 plane = !plane;
2929
2930 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
2931 i915_handle_vblank(dev, plane, pipe, iir))
2932 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
2933
2934 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2935 blc_event = true;
2936 }
2937
2938 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2939 intel_opregion_asle_intr(dev);
2940
2941 /* With MSI, interrupts are only generated when iir
2942 * transitions from zero to nonzero. If another bit got
2943 * set while we were handling the existing iir bits, then
2944 * we would never get another interrupt.
2945 *
2946 * This is fine on non-MSI as well, as if we hit this path
2947 * we avoid exiting the interrupt handler only to generate
2948 * another one.
2949 *
2950 * Note that for MSI this could cause a stray interrupt report
2951 * if an interrupt landed in the time between writing IIR and
2952 * the posting read. This should be rare enough to never
2953 * trigger the 99% of 100,000 interrupts test for disabling
2954 * stray interrupts.
2955 */
2956 ret = IRQ_HANDLED;
2957 iir = new_iir;
2958 } while (iir & ~flip_mask);
2959
2960 i915_update_dri1_breadcrumb(dev);
2961
2962 return ret;
2963 }
2964
2965 static void i915_irq_uninstall(struct drm_device * dev)
2966 {
2967 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2968 int pipe;
2969
2970 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2971
2972 if (I915_HAS_HOTPLUG(dev)) {
2973 I915_WRITE(PORT_HOTPLUG_EN, 0);
2974 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2975 }
2976
2977 I915_WRITE16(HWSTAM, 0xffff);
2978 for_each_pipe(pipe) {
2979 /* Clear enable bits; then clear status bits */
2980 I915_WRITE(PIPESTAT(pipe), 0);
2981 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
2982 }
2983 I915_WRITE(IMR, 0xffffffff);
2984 I915_WRITE(IER, 0x0);
2985
2986 I915_WRITE(IIR, I915_READ(IIR));
2987 }
2988
2989 static void i965_irq_preinstall(struct drm_device * dev)
2990 {
2991 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2992 int pipe;
2993
2994 atomic_set(&dev_priv->irq_received, 0);
2995
2996 I915_WRITE(PORT_HOTPLUG_EN, 0);
2997 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2998
2999 I915_WRITE(HWSTAM, 0xeffe);
3000 for_each_pipe(pipe)
3001 I915_WRITE(PIPESTAT(pipe), 0);
3002 I915_WRITE(IMR, 0xffffffff);
3003 I915_WRITE(IER, 0x0);
3004 POSTING_READ(IER);
3005 }
3006
3007 static int i965_irq_postinstall(struct drm_device *dev)
3008 {
3009 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3010 u32 enable_mask;
3011 u32 error_mask;
3012 unsigned long irqflags;
3013
3014 /* Unmask the interrupts that we always want on. */
3015 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
3016 I915_DISPLAY_PORT_INTERRUPT |
3017 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3018 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3019 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3020 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3021 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3022
3023 enable_mask = ~dev_priv->irq_mask;
3024 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3025 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
3026 enable_mask |= I915_USER_INTERRUPT;
3027
3028 if (IS_G4X(dev))
3029 enable_mask |= I915_BSD_USER_INTERRUPT;
3030
3031 /* Interrupt setup is already guaranteed to be single-threaded, this is
3032 * just to make the assert_spin_locked check happy. */
3033 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3034 i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
3035 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3036
3037 /*
3038 * Enable some error detection, note the instruction error mask
3039 * bit is reserved, so we leave it masked.
3040 */
3041 if (IS_G4X(dev)) {
3042 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3043 GM45_ERROR_MEM_PRIV |
3044 GM45_ERROR_CP_PRIV |
3045 I915_ERROR_MEMORY_REFRESH);
3046 } else {
3047 error_mask = ~(I915_ERROR_PAGE_TABLE |
3048 I915_ERROR_MEMORY_REFRESH);
3049 }
3050 I915_WRITE(EMR, error_mask);
3051
3052 I915_WRITE(IMR, dev_priv->irq_mask);
3053 I915_WRITE(IER, enable_mask);
3054 POSTING_READ(IER);
3055
3056 I915_WRITE(PORT_HOTPLUG_EN, 0);
3057 POSTING_READ(PORT_HOTPLUG_EN);
3058
3059 i915_enable_asle_pipestat(dev);
3060
3061 return 0;
3062 }
3063
3064 static void i915_hpd_irq_setup(struct drm_device *dev)
3065 {
3066 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3067 struct drm_mode_config *mode_config = &dev->mode_config;
3068 struct intel_encoder *intel_encoder;
3069 u32 hotplug_en;
3070
3071 assert_spin_locked(&dev_priv->irq_lock);
3072
3073 if (I915_HAS_HOTPLUG(dev)) {
3074 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3075 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3076 /* Note HDMI and DP share hotplug bits */
3077 /* enable bits are the same for all generations */
3078 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3079 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3080 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
3081 /* Programming the CRT detection parameters tends
3082 to generate a spurious hotplug event about three
3083 seconds later. So just do it once.
3084 */
3085 if (IS_G4X(dev))
3086 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
3087 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
3088 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
3089
3090 /* Ignore TV since it's buggy */
3091 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3092 }
3093 }
3094
3095 static irqreturn_t i965_irq_handler(int irq, void *arg)
3096 {
3097 struct drm_device *dev = (struct drm_device *) arg;
3098 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3099 u32 iir, new_iir;
3100 u32 pipe_stats[I915_MAX_PIPES];
3101 unsigned long irqflags;
3102 int irq_received;
3103 int ret = IRQ_NONE, pipe;
3104 u32 flip_mask =
3105 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3106 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3107
3108 atomic_inc(&dev_priv->irq_received);
3109
3110 iir = I915_READ(IIR);
3111
3112 for (;;) {
3113 bool blc_event = false;
3114
3115 irq_received = (iir & ~flip_mask) != 0;
3116
3117 /* Can't rely on pipestat interrupt bit in iir as it might
3118 * have been cleared after the pipestat interrupt was received.
3119 * It doesn't set the bit in iir again, but it still produces
3120 * interrupts (for non-MSI).
3121 */
3122 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3123 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3124 i915_handle_error(dev, false);
3125
3126 for_each_pipe(pipe) {
3127 int reg = PIPESTAT(pipe);
3128 pipe_stats[pipe] = I915_READ(reg);
3129
3130 /*
3131 * Clear the PIPE*STAT regs before the IIR
3132 */
3133 if (pipe_stats[pipe] & 0x8000ffff) {
3134 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3135 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3136 pipe_name(pipe));
3137 I915_WRITE(reg, pipe_stats[pipe]);
3138 irq_received = 1;
3139 }
3140 }
3141 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3142
3143 if (!irq_received)
3144 break;
3145
3146 ret = IRQ_HANDLED;
3147
3148 /* Consume port. Then clear IIR or we'll miss events */
3149 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
3150 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
3151 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3152 HOTPLUG_INT_STATUS_G4X :
3153 HOTPLUG_INT_STATUS_I915);
3154
3155 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3156 hotplug_status);
3157
3158 intel_hpd_irq_handler(dev, hotplug_trigger,
3159 IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
3160
3161 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3162 I915_READ(PORT_HOTPLUG_STAT);
3163 }
3164
3165 I915_WRITE(IIR, iir & ~flip_mask);
3166 new_iir = I915_READ(IIR); /* Flush posted writes */
3167
3168 if (iir & I915_USER_INTERRUPT)
3169 notify_ring(dev, &dev_priv->ring[RCS]);
3170 if (iir & I915_BSD_USER_INTERRUPT)
3171 notify_ring(dev, &dev_priv->ring[VCS]);
3172
3173 for_each_pipe(pipe) {
3174 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
3175 i915_handle_vblank(dev, pipe, pipe, iir))
3176 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
3177
3178 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3179 blc_event = true;
3180 }
3181
3182
3183 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3184 intel_opregion_asle_intr(dev);
3185
3186 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3187 gmbus_irq_handler(dev);
3188
3189 /* With MSI, interrupts are only generated when iir
3190 * transitions from zero to nonzero. If another bit got
3191 * set while we were handling the existing iir bits, then
3192 * we would never get another interrupt.
3193 *
3194 * This is fine on non-MSI as well, as if we hit this path
3195 * we avoid exiting the interrupt handler only to generate
3196 * another one.
3197 *
3198 * Note that for MSI this could cause a stray interrupt report
3199 * if an interrupt landed in the time between writing IIR and
3200 * the posting read. This should be rare enough to never
3201 * trigger the 99% of 100,000 interrupts test for disabling
3202 * stray interrupts.
3203 */
3204 iir = new_iir;
3205 }
3206
3207 i915_update_dri1_breadcrumb(dev);
3208
3209 return ret;
3210 }
3211
3212 static void i965_irq_uninstall(struct drm_device * dev)
3213 {
3214 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3215 int pipe;
3216
3217 if (!dev_priv)
3218 return;
3219
3220 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3221
3222 I915_WRITE(PORT_HOTPLUG_EN, 0);
3223 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3224
3225 I915_WRITE(HWSTAM, 0xffffffff);
3226 for_each_pipe(pipe)
3227 I915_WRITE(PIPESTAT(pipe), 0);
3228 I915_WRITE(IMR, 0xffffffff);
3229 I915_WRITE(IER, 0x0);
3230
3231 for_each_pipe(pipe)
3232 I915_WRITE(PIPESTAT(pipe),
3233 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3234 I915_WRITE(IIR, I915_READ(IIR));
3235 }
3236
3237 static void i915_reenable_hotplug_timer_func(unsigned long data)
3238 {
3239 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3240 struct drm_device *dev = dev_priv->dev;
3241 struct drm_mode_config *mode_config = &dev->mode_config;
3242 unsigned long irqflags;
3243 int i;
3244
3245 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3246 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3247 struct drm_connector *connector;
3248
3249 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3250 continue;
3251
3252 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3253
3254 list_for_each_entry(connector, &mode_config->connector_list, head) {
3255 struct intel_connector *intel_connector = to_intel_connector(connector);
3256
3257 if (intel_connector->encoder->hpd_pin == i) {
3258 if (connector->polled != intel_connector->polled)
3259 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3260 drm_get_connector_name(connector));
3261 connector->polled = intel_connector->polled;
3262 if (!connector->polled)
3263 connector->polled = DRM_CONNECTOR_POLL_HPD;
3264 }
3265 }
3266 }
3267 if (dev_priv->display.hpd_irq_setup)
3268 dev_priv->display.hpd_irq_setup(dev);
3269 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3270 }
3271
3272 void intel_irq_init(struct drm_device *dev)
3273 {
3274 struct drm_i915_private *dev_priv = dev->dev_private;
3275
3276 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
3277 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
3278 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
3279 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
3280
3281 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3282 i915_hangcheck_elapsed,
3283 (unsigned long) dev);
3284 setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
3285 (unsigned long) dev_priv);
3286
3287 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
3288
3289 if (IS_GEN2(dev)) {
3290 dev->max_vblank_count = 0;
3291 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3292 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
3293 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3294 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
3295 } else {
3296 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3297 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
3298 }
3299
3300 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
3301 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
3302 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3303 }
3304
3305 if (IS_VALLEYVIEW(dev)) {
3306 dev->driver->irq_handler = valleyview_irq_handler;
3307 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3308 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3309 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3310 dev->driver->enable_vblank = valleyview_enable_vblank;
3311 dev->driver->disable_vblank = valleyview_disable_vblank;
3312 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
3313 } else if (HAS_PCH_SPLIT(dev)) {
3314 dev->driver->irq_handler = ironlake_irq_handler;
3315 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3316 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3317 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3318 dev->driver->enable_vblank = ironlake_enable_vblank;
3319 dev->driver->disable_vblank = ironlake_disable_vblank;
3320 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
3321 } else {
3322 if (INTEL_INFO(dev)->gen == 2) {
3323 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3324 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3325 dev->driver->irq_handler = i8xx_irq_handler;
3326 dev->driver->irq_uninstall = i8xx_irq_uninstall;
3327 } else if (INTEL_INFO(dev)->gen == 3) {
3328 dev->driver->irq_preinstall = i915_irq_preinstall;
3329 dev->driver->irq_postinstall = i915_irq_postinstall;
3330 dev->driver->irq_uninstall = i915_irq_uninstall;
3331 dev->driver->irq_handler = i915_irq_handler;
3332 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
3333 } else {
3334 dev->driver->irq_preinstall = i965_irq_preinstall;
3335 dev->driver->irq_postinstall = i965_irq_postinstall;
3336 dev->driver->irq_uninstall = i965_irq_uninstall;
3337 dev->driver->irq_handler = i965_irq_handler;
3338 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
3339 }
3340 dev->driver->enable_vblank = i915_enable_vblank;
3341 dev->driver->disable_vblank = i915_disable_vblank;
3342 }
3343 }
3344
3345 void intel_hpd_init(struct drm_device *dev)
3346 {
3347 struct drm_i915_private *dev_priv = dev->dev_private;
3348 struct drm_mode_config *mode_config = &dev->mode_config;
3349 struct drm_connector *connector;
3350 unsigned long irqflags;
3351 int i;
3352
3353 for (i = 1; i < HPD_NUM_PINS; i++) {
3354 dev_priv->hpd_stats[i].hpd_cnt = 0;
3355 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3356 }
3357 list_for_each_entry(connector, &mode_config->connector_list, head) {
3358 struct intel_connector *intel_connector = to_intel_connector(connector);
3359 connector->polled = intel_connector->polled;
3360 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3361 connector->polled = DRM_CONNECTOR_POLL_HPD;
3362 }
3363
3364 /* Interrupt setup is already guaranteed to be single-threaded, this is
3365 * just to make the assert_spin_locked checks happy. */
3366 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3367 if (dev_priv->display.hpd_irq_setup)
3368 dev_priv->display.hpd_irq_setup(dev);
3369 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3370 }
3371
3372 /* Disable interrupts so we can allow Package C8+. */
3373 void hsw_pc8_disable_interrupts(struct drm_device *dev)
3374 {
3375 struct drm_i915_private *dev_priv = dev->dev_private;
3376 unsigned long irqflags;
3377
3378 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3379
3380 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3381 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3382 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3383 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3384 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3385
3386 ironlake_disable_display_irq(dev_priv, ~DE_PCH_EVENT_IVB);
3387 ibx_disable_display_interrupt(dev_priv, ~SDE_HOTPLUG_MASK_CPT);
3388 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3389 snb_disable_pm_irq(dev_priv, 0xffffffff);
3390
3391 dev_priv->pc8.irqs_disabled = true;
3392
3393 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3394 }
3395
3396 /* Restore interrupts so we can recover from Package C8+. */
3397 void hsw_pc8_restore_interrupts(struct drm_device *dev)
3398 {
3399 struct drm_i915_private *dev_priv = dev->dev_private;
3400 unsigned long irqflags;
3401 uint32_t val, expected;
3402
3403 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3404
3405 val = I915_READ(DEIMR);
3406 expected = ~DE_PCH_EVENT_IVB;
3407 WARN(val != expected, "DEIMR is 0x%08x, not 0x%08x\n", val, expected);
3408
3409 val = I915_READ(SDEIMR) & ~SDE_HOTPLUG_MASK_CPT;
3410 expected = ~SDE_HOTPLUG_MASK_CPT;
3411 WARN(val != expected, "SDEIMR non-HPD bits are 0x%08x, not 0x%08x\n",
3412 val, expected);
3413
3414 val = I915_READ(GTIMR);
3415 expected = 0xffffffff;
3416 WARN(val != expected, "GTIMR is 0x%08x, not 0x%08x\n", val, expected);
3417
3418 val = I915_READ(GEN6_PMIMR);
3419 expected = 0xffffffff;
3420 WARN(val != expected, "GEN6_PMIMR is 0x%08x, not 0x%08x\n", val,
3421 expected);
3422
3423 dev_priv->pc8.irqs_disabled = false;
3424
3425 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
3426 ibx_enable_display_interrupt(dev_priv,
3427 ~dev_priv->pc8.regsave.sdeimr &
3428 ~SDE_HOTPLUG_MASK_CPT);
3429 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
3430 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
3431 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
3432
3433 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3434 }
This page took 0.099255 seconds and 6 git commands to generate.