1 /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
29 #include <linux/sysrq.h>
34 #include "i915_trace.h"
35 #include "intel_drv.h"
37 #define MAX_NOPID ((u32)~0)
40 * Interrupts that are always left unmasked.
42 * Since pipe events are edge-triggered from the PIPESTAT register to IIR,
43 * we leave them always unmasked in IMR and then control enabling them through
46 #define I915_INTERRUPT_ENABLE_FIX (I915_ASLE_INTERRUPT | \
47 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \
48 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \
49 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
51 /** Interrupts that we mask and unmask at runtime. */
52 #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT)
54 #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\
55 PIPE_VBLANK_INTERRUPT_STATUS)
57 #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\
58 PIPE_VBLANK_INTERRUPT_ENABLE)
60 #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \
61 DRM_I915_VBLANK_PIPE_B)
64 igdng_enable_graphics_irq(drm_i915_private_t
*dev_priv
, u32 mask
)
66 if ((dev_priv
->gt_irq_mask_reg
& mask
) != 0) {
67 dev_priv
->gt_irq_mask_reg
&= ~mask
;
68 I915_WRITE(GTIMR
, dev_priv
->gt_irq_mask_reg
);
69 (void) I915_READ(GTIMR
);
74 igdng_disable_graphics_irq(drm_i915_private_t
*dev_priv
, u32 mask
)
76 if ((dev_priv
->gt_irq_mask_reg
& mask
) != mask
) {
77 dev_priv
->gt_irq_mask_reg
|= mask
;
78 I915_WRITE(GTIMR
, dev_priv
->gt_irq_mask_reg
);
79 (void) I915_READ(GTIMR
);
83 /* For display hotplug interrupt */
85 igdng_enable_display_irq(drm_i915_private_t
*dev_priv
, u32 mask
)
87 if ((dev_priv
->irq_mask_reg
& mask
) != 0) {
88 dev_priv
->irq_mask_reg
&= ~mask
;
89 I915_WRITE(DEIMR
, dev_priv
->irq_mask_reg
);
90 (void) I915_READ(DEIMR
);
95 igdng_disable_display_irq(drm_i915_private_t
*dev_priv
, u32 mask
)
97 if ((dev_priv
->irq_mask_reg
& mask
) != mask
) {
98 dev_priv
->irq_mask_reg
|= mask
;
99 I915_WRITE(DEIMR
, dev_priv
->irq_mask_reg
);
100 (void) I915_READ(DEIMR
);
105 i915_enable_irq(drm_i915_private_t
*dev_priv
, u32 mask
)
107 if ((dev_priv
->irq_mask_reg
& mask
) != 0) {
108 dev_priv
->irq_mask_reg
&= ~mask
;
109 I915_WRITE(IMR
, dev_priv
->irq_mask_reg
);
110 (void) I915_READ(IMR
);
115 i915_disable_irq(drm_i915_private_t
*dev_priv
, u32 mask
)
117 if ((dev_priv
->irq_mask_reg
& mask
) != mask
) {
118 dev_priv
->irq_mask_reg
|= mask
;
119 I915_WRITE(IMR
, dev_priv
->irq_mask_reg
);
120 (void) I915_READ(IMR
);
125 i915_pipestat(int pipe
)
135 i915_enable_pipestat(drm_i915_private_t
*dev_priv
, int pipe
, u32 mask
)
137 if ((dev_priv
->pipestat
[pipe
] & mask
) != mask
) {
138 u32 reg
= i915_pipestat(pipe
);
140 dev_priv
->pipestat
[pipe
] |= mask
;
141 /* Enable the interrupt, clear any pending status */
142 I915_WRITE(reg
, dev_priv
->pipestat
[pipe
] | (mask
>> 16));
143 (void) I915_READ(reg
);
148 i915_disable_pipestat(drm_i915_private_t
*dev_priv
, int pipe
, u32 mask
)
150 if ((dev_priv
->pipestat
[pipe
] & mask
) != 0) {
151 u32 reg
= i915_pipestat(pipe
);
153 dev_priv
->pipestat
[pipe
] &= ~mask
;
154 I915_WRITE(reg
, dev_priv
->pipestat
[pipe
]);
155 (void) I915_READ(reg
);
160 * i915_pipe_enabled - check if a pipe is enabled
162 * @pipe: pipe to check
164 * Reading certain registers when the pipe is disabled can hang the chip.
165 * Use this routine to make sure the PLL is running and the pipe is active
166 * before reading such registers if unsure.
169 i915_pipe_enabled(struct drm_device
*dev
, int pipe
)
171 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
172 unsigned long pipeconf
= pipe
? PIPEBCONF
: PIPEACONF
;
174 if (I915_READ(pipeconf
) & PIPEACONF_ENABLE
)
180 /* Called from drm generic code, passed a 'crtc', which
181 * we use as a pipe index
183 u32
i915_get_vblank_counter(struct drm_device
*dev
, int pipe
)
185 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
186 unsigned long high_frame
;
187 unsigned long low_frame
;
188 u32 high1
, high2
, low
, count
;
190 high_frame
= pipe
? PIPEBFRAMEHIGH
: PIPEAFRAMEHIGH
;
191 low_frame
= pipe
? PIPEBFRAMEPIXEL
: PIPEAFRAMEPIXEL
;
193 if (!i915_pipe_enabled(dev
, pipe
)) {
194 DRM_DEBUG("trying to get vblank count for disabled pipe %d\n", pipe
);
199 * High & low register fields aren't synchronized, so make sure
200 * we get a low value that's stable across two reads of the high
204 high1
= ((I915_READ(high_frame
) & PIPE_FRAME_HIGH_MASK
) >>
205 PIPE_FRAME_HIGH_SHIFT
);
206 low
= ((I915_READ(low_frame
) & PIPE_FRAME_LOW_MASK
) >>
207 PIPE_FRAME_LOW_SHIFT
);
208 high2
= ((I915_READ(high_frame
) & PIPE_FRAME_HIGH_MASK
) >>
209 PIPE_FRAME_HIGH_SHIFT
);
210 } while (high1
!= high2
);
212 count
= (high1
<< 8) | low
;
217 u32
gm45_get_vblank_counter(struct drm_device
*dev
, int pipe
)
219 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
220 int reg
= pipe
? PIPEB_FRMCOUNT_GM45
: PIPEA_FRMCOUNT_GM45
;
222 if (!i915_pipe_enabled(dev
, pipe
)) {
223 DRM_DEBUG("trying to get vblank count for disabled pipe %d\n", pipe
);
227 return I915_READ(reg
);
231 * Handle hotplug events outside the interrupt handler proper.
233 static void i915_hotplug_work_func(struct work_struct
*work
)
235 drm_i915_private_t
*dev_priv
= container_of(work
, drm_i915_private_t
,
237 struct drm_device
*dev
= dev_priv
->dev
;
238 struct drm_mode_config
*mode_config
= &dev
->mode_config
;
239 struct drm_connector
*connector
;
241 if (mode_config
->num_connector
) {
242 list_for_each_entry(connector
, &mode_config
->connector_list
, head
) {
243 struct intel_output
*intel_output
= to_intel_output(connector
);
245 if (intel_output
->hot_plug
)
246 (*intel_output
->hot_plug
) (intel_output
);
249 /* Just fire off a uevent and let userspace tell us what to do */
250 drm_sysfs_hotplug_event(dev
);
253 irqreturn_t
igdng_irq_handler(struct drm_device
*dev
)
255 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
257 u32 de_iir
, gt_iir
, de_ier
;
258 struct drm_i915_master_private
*master_priv
;
260 /* disable master interrupt before clearing iir */
261 de_ier
= I915_READ(DEIER
);
262 I915_WRITE(DEIER
, de_ier
& ~DE_MASTER_IRQ_CONTROL
);
263 (void)I915_READ(DEIER
);
265 de_iir
= I915_READ(DEIIR
);
266 gt_iir
= I915_READ(GTIIR
);
268 if (de_iir
== 0 && gt_iir
== 0)
273 if (dev
->primary
->master
) {
274 master_priv
= dev
->primary
->master
->driver_priv
;
275 if (master_priv
->sarea_priv
)
276 master_priv
->sarea_priv
->last_dispatch
=
277 READ_BREADCRUMB(dev_priv
);
280 if (gt_iir
& GT_USER_INTERRUPT
) {
281 u32 seqno
= i915_get_gem_seqno(dev
);
282 dev_priv
->mm
.irq_gem_seqno
= seqno
;
283 trace_i915_gem_request_complete(dev
, seqno
);
284 DRM_WAKEUP(&dev_priv
->irq_queue
);
285 dev_priv
->hangcheck_count
= 0;
286 mod_timer(&dev_priv
->hangcheck_timer
, jiffies
+ DRM_I915_HANGCHECK_PERIOD
);
289 I915_WRITE(GTIIR
, gt_iir
);
290 I915_WRITE(DEIIR
, de_iir
);
293 I915_WRITE(DEIER
, de_ier
);
294 (void)I915_READ(DEIER
);
300 * i915_error_work_func - do process context error handling work
303 * Fire an error uevent so userspace can see that a hang or error
306 static void i915_error_work_func(struct work_struct
*work
)
308 drm_i915_private_t
*dev_priv
= container_of(work
, drm_i915_private_t
,
310 struct drm_device
*dev
= dev_priv
->dev
;
311 char *error_event
[] = { "ERROR=1", NULL
};
312 char *reset_event
[] = { "RESET=1", NULL
};
313 char *reset_done_event
[] = { "ERROR=0", NULL
};
315 DRM_DEBUG("generating error event\n");
316 kobject_uevent_env(&dev
->primary
->kdev
.kobj
, KOBJ_CHANGE
, error_event
);
318 if (atomic_read(&dev_priv
->mm
.wedged
)) {
320 DRM_DEBUG("resetting chip\n");
321 kobject_uevent_env(&dev
->primary
->kdev
.kobj
, KOBJ_CHANGE
, reset_event
);
322 if (!i965_reset(dev
, GDRST_RENDER
)) {
323 atomic_set(&dev_priv
->mm
.wedged
, 0);
324 kobject_uevent_env(&dev
->primary
->kdev
.kobj
, KOBJ_CHANGE
, reset_done_event
);
327 printk("reboot required\n");
333 * i915_capture_error_state - capture an error record for later analysis
336 * Should be called when an error is detected (either a hang or an error
337 * interrupt) to capture error state from the time of the error. Fills
338 * out a structure which becomes available in debugfs for user level tools
341 static void i915_capture_error_state(struct drm_device
*dev
)
343 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
344 struct drm_i915_error_state
*error
;
347 spin_lock_irqsave(&dev_priv
->error_lock
, flags
);
348 if (dev_priv
->first_error
)
351 error
= kmalloc(sizeof(*error
), GFP_ATOMIC
);
353 DRM_DEBUG("out ot memory, not capturing error state\n");
357 error
->eir
= I915_READ(EIR
);
358 error
->pgtbl_er
= I915_READ(PGTBL_ER
);
359 error
->pipeastat
= I915_READ(PIPEASTAT
);
360 error
->pipebstat
= I915_READ(PIPEBSTAT
);
361 error
->instpm
= I915_READ(INSTPM
);
362 if (!IS_I965G(dev
)) {
363 error
->ipeir
= I915_READ(IPEIR
);
364 error
->ipehr
= I915_READ(IPEHR
);
365 error
->instdone
= I915_READ(INSTDONE
);
366 error
->acthd
= I915_READ(ACTHD
);
368 error
->ipeir
= I915_READ(IPEIR_I965
);
369 error
->ipehr
= I915_READ(IPEHR_I965
);
370 error
->instdone
= I915_READ(INSTDONE_I965
);
371 error
->instps
= I915_READ(INSTPS
);
372 error
->instdone1
= I915_READ(INSTDONE1
);
373 error
->acthd
= I915_READ(ACTHD_I965
);
376 do_gettimeofday(&error
->time
);
378 dev_priv
->first_error
= error
;
381 spin_unlock_irqrestore(&dev_priv
->error_lock
, flags
);
385 * i915_handle_error - handle an error interrupt
388 * Do some basic checking of regsiter state at error interrupt time and
389 * dump it to the syslog. Also call i915_capture_error_state() to make
390 * sure we get a record and make it available in debugfs. Fire a uevent
391 * so userspace knows something bad happened (should trigger collection
392 * of a ring dump etc.).
394 static void i915_handle_error(struct drm_device
*dev
, bool wedged
)
396 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
397 u32 eir
= I915_READ(EIR
);
398 u32 pipea_stats
= I915_READ(PIPEASTAT
);
399 u32 pipeb_stats
= I915_READ(PIPEBSTAT
);
401 i915_capture_error_state(dev
);
403 printk(KERN_ERR
"render error detected, EIR: 0x%08x\n",
407 if (eir
& (GM45_ERROR_MEM_PRIV
| GM45_ERROR_CP_PRIV
)) {
408 u32 ipeir
= I915_READ(IPEIR_I965
);
410 printk(KERN_ERR
" IPEIR: 0x%08x\n",
411 I915_READ(IPEIR_I965
));
412 printk(KERN_ERR
" IPEHR: 0x%08x\n",
413 I915_READ(IPEHR_I965
));
414 printk(KERN_ERR
" INSTDONE: 0x%08x\n",
415 I915_READ(INSTDONE_I965
));
416 printk(KERN_ERR
" INSTPS: 0x%08x\n",
418 printk(KERN_ERR
" INSTDONE1: 0x%08x\n",
419 I915_READ(INSTDONE1
));
420 printk(KERN_ERR
" ACTHD: 0x%08x\n",
421 I915_READ(ACTHD_I965
));
422 I915_WRITE(IPEIR_I965
, ipeir
);
423 (void)I915_READ(IPEIR_I965
);
425 if (eir
& GM45_ERROR_PAGE_TABLE
) {
426 u32 pgtbl_err
= I915_READ(PGTBL_ER
);
427 printk(KERN_ERR
"page table error\n");
428 printk(KERN_ERR
" PGTBL_ER: 0x%08x\n",
430 I915_WRITE(PGTBL_ER
, pgtbl_err
);
431 (void)I915_READ(PGTBL_ER
);
436 if (eir
& I915_ERROR_PAGE_TABLE
) {
437 u32 pgtbl_err
= I915_READ(PGTBL_ER
);
438 printk(KERN_ERR
"page table error\n");
439 printk(KERN_ERR
" PGTBL_ER: 0x%08x\n",
441 I915_WRITE(PGTBL_ER
, pgtbl_err
);
442 (void)I915_READ(PGTBL_ER
);
446 if (eir
& I915_ERROR_MEMORY_REFRESH
) {
447 printk(KERN_ERR
"memory refresh error\n");
448 printk(KERN_ERR
"PIPEASTAT: 0x%08x\n",
450 printk(KERN_ERR
"PIPEBSTAT: 0x%08x\n",
452 /* pipestat has already been acked */
454 if (eir
& I915_ERROR_INSTRUCTION
) {
455 printk(KERN_ERR
"instruction error\n");
456 printk(KERN_ERR
" INSTPM: 0x%08x\n",
458 if (!IS_I965G(dev
)) {
459 u32 ipeir
= I915_READ(IPEIR
);
461 printk(KERN_ERR
" IPEIR: 0x%08x\n",
463 printk(KERN_ERR
" IPEHR: 0x%08x\n",
465 printk(KERN_ERR
" INSTDONE: 0x%08x\n",
466 I915_READ(INSTDONE
));
467 printk(KERN_ERR
" ACTHD: 0x%08x\n",
469 I915_WRITE(IPEIR
, ipeir
);
470 (void)I915_READ(IPEIR
);
472 u32 ipeir
= I915_READ(IPEIR_I965
);
474 printk(KERN_ERR
" IPEIR: 0x%08x\n",
475 I915_READ(IPEIR_I965
));
476 printk(KERN_ERR
" IPEHR: 0x%08x\n",
477 I915_READ(IPEHR_I965
));
478 printk(KERN_ERR
" INSTDONE: 0x%08x\n",
479 I915_READ(INSTDONE_I965
));
480 printk(KERN_ERR
" INSTPS: 0x%08x\n",
482 printk(KERN_ERR
" INSTDONE1: 0x%08x\n",
483 I915_READ(INSTDONE1
));
484 printk(KERN_ERR
" ACTHD: 0x%08x\n",
485 I915_READ(ACTHD_I965
));
486 I915_WRITE(IPEIR_I965
, ipeir
);
487 (void)I915_READ(IPEIR_I965
);
491 I915_WRITE(EIR
, eir
);
492 (void)I915_READ(EIR
);
493 eir
= I915_READ(EIR
);
496 * some errors might have become stuck,
499 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir
);
500 I915_WRITE(EMR
, I915_READ(EMR
) | eir
);
501 I915_WRITE(IIR
, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
);
505 atomic_set(&dev_priv
->mm
.wedged
, 1);
508 * Wakeup waiting processes so they don't hang
510 printk("i915: Waking up sleeping processes\n");
511 DRM_WAKEUP(&dev_priv
->irq_queue
);
514 queue_work(dev_priv
->wq
, &dev_priv
->error_work
);
517 irqreturn_t
i915_driver_irq_handler(DRM_IRQ_ARGS
)
519 struct drm_device
*dev
= (struct drm_device
*) arg
;
520 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
521 struct drm_i915_master_private
*master_priv
;
523 u32 pipea_stats
, pipeb_stats
;
527 unsigned long irqflags
;
531 atomic_inc(&dev_priv
->irq_received
);
534 return igdng_irq_handler(dev
);
536 iir
= I915_READ(IIR
);
539 vblank_status
= I915_START_VBLANK_INTERRUPT_STATUS
;
540 vblank_enable
= PIPE_START_VBLANK_INTERRUPT_ENABLE
;
542 vblank_status
= I915_VBLANK_INTERRUPT_STATUS
;
543 vblank_enable
= I915_VBLANK_INTERRUPT_ENABLE
;
547 irq_received
= iir
!= 0;
549 /* Can't rely on pipestat interrupt bit in iir as it might
550 * have been cleared after the pipestat interrupt was received.
551 * It doesn't set the bit in iir again, but it still produces
552 * interrupts (for non-MSI).
554 spin_lock_irqsave(&dev_priv
->user_irq_lock
, irqflags
);
555 pipea_stats
= I915_READ(PIPEASTAT
);
556 pipeb_stats
= I915_READ(PIPEBSTAT
);
558 if (iir
& I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT
)
559 i915_handle_error(dev
, false);
562 * Clear the PIPE(A|B)STAT regs before the IIR
564 if (pipea_stats
& 0x8000ffff) {
565 if (pipea_stats
& PIPE_FIFO_UNDERRUN_STATUS
)
566 DRM_DEBUG("pipe a underrun\n");
567 I915_WRITE(PIPEASTAT
, pipea_stats
);
571 if (pipeb_stats
& 0x8000ffff) {
572 if (pipeb_stats
& PIPE_FIFO_UNDERRUN_STATUS
)
573 DRM_DEBUG("pipe b underrun\n");
574 I915_WRITE(PIPEBSTAT
, pipeb_stats
);
577 spin_unlock_irqrestore(&dev_priv
->user_irq_lock
, irqflags
);
584 /* Consume port. Then clear IIR or we'll miss events */
585 if ((I915_HAS_HOTPLUG(dev
)) &&
586 (iir
& I915_DISPLAY_PORT_INTERRUPT
)) {
587 u32 hotplug_status
= I915_READ(PORT_HOTPLUG_STAT
);
589 DRM_DEBUG("hotplug event received, stat 0x%08x\n",
591 if (hotplug_status
& dev_priv
->hotplug_supported_mask
)
592 queue_work(dev_priv
->wq
,
593 &dev_priv
->hotplug_work
);
595 I915_WRITE(PORT_HOTPLUG_STAT
, hotplug_status
);
596 I915_READ(PORT_HOTPLUG_STAT
);
598 /* EOS interrupts occurs */
600 (hotplug_status
& CRT_EOS_INT_STATUS
)) {
603 DRM_DEBUG("EOS interrupt occurs\n");
604 /* status is already cleared */
605 temp
= I915_READ(ADPA
);
606 temp
&= ~ADPA_DAC_ENABLE
;
607 I915_WRITE(ADPA
, temp
);
609 temp
= I915_READ(PORT_HOTPLUG_EN
);
610 temp
&= ~CRT_EOS_INT_EN
;
611 I915_WRITE(PORT_HOTPLUG_EN
, temp
);
613 temp
= I915_READ(PORT_HOTPLUG_STAT
);
614 if (temp
& CRT_EOS_INT_STATUS
)
615 I915_WRITE(PORT_HOTPLUG_STAT
,
620 I915_WRITE(IIR
, iir
);
621 new_iir
= I915_READ(IIR
); /* Flush posted writes */
623 if (dev
->primary
->master
) {
624 master_priv
= dev
->primary
->master
->driver_priv
;
625 if (master_priv
->sarea_priv
)
626 master_priv
->sarea_priv
->last_dispatch
=
627 READ_BREADCRUMB(dev_priv
);
630 if (iir
& I915_USER_INTERRUPT
) {
631 u32 seqno
= i915_get_gem_seqno(dev
);
632 dev_priv
->mm
.irq_gem_seqno
= seqno
;
633 trace_i915_gem_request_complete(dev
, seqno
);
634 DRM_WAKEUP(&dev_priv
->irq_queue
);
635 dev_priv
->hangcheck_count
= 0;
636 mod_timer(&dev_priv
->hangcheck_timer
, jiffies
+ DRM_I915_HANGCHECK_PERIOD
);
639 if (pipea_stats
& vblank_status
) {
641 drm_handle_vblank(dev
, 0);
644 if (pipeb_stats
& vblank_status
) {
646 drm_handle_vblank(dev
, 1);
649 if ((pipeb_stats
& I915_LEGACY_BLC_EVENT_STATUS
) ||
650 (iir
& I915_ASLE_INTERRUPT
))
651 opregion_asle_intr(dev
);
653 /* With MSI, interrupts are only generated when iir
654 * transitions from zero to nonzero. If another bit got
655 * set while we were handling the existing iir bits, then
656 * we would never get another interrupt.
658 * This is fine on non-MSI as well, as if we hit this path
659 * we avoid exiting the interrupt handler only to generate
662 * Note that for MSI this could cause a stray interrupt report
663 * if an interrupt landed in the time between writing IIR and
664 * the posting read. This should be rare enough to never
665 * trigger the 99% of 100,000 interrupts test for disabling
674 static int i915_emit_irq(struct drm_device
* dev
)
676 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
677 struct drm_i915_master_private
*master_priv
= dev
->primary
->master
->driver_priv
;
680 i915_kernel_lost_context(dev
);
685 if (dev_priv
->counter
> 0x7FFFFFFFUL
)
686 dev_priv
->counter
= 1;
687 if (master_priv
->sarea_priv
)
688 master_priv
->sarea_priv
->last_enqueue
= dev_priv
->counter
;
691 OUT_RING(MI_STORE_DWORD_INDEX
);
692 OUT_RING(I915_BREADCRUMB_INDEX
<< MI_STORE_DWORD_INDEX_SHIFT
);
693 OUT_RING(dev_priv
->counter
);
694 OUT_RING(MI_USER_INTERRUPT
);
697 return dev_priv
->counter
;
700 void i915_user_irq_get(struct drm_device
*dev
)
702 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
703 unsigned long irqflags
;
705 spin_lock_irqsave(&dev_priv
->user_irq_lock
, irqflags
);
706 if (dev
->irq_enabled
&& (++dev_priv
->user_irq_refcount
== 1)) {
708 igdng_enable_graphics_irq(dev_priv
, GT_USER_INTERRUPT
);
710 i915_enable_irq(dev_priv
, I915_USER_INTERRUPT
);
712 spin_unlock_irqrestore(&dev_priv
->user_irq_lock
, irqflags
);
715 void i915_user_irq_put(struct drm_device
*dev
)
717 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
718 unsigned long irqflags
;
720 spin_lock_irqsave(&dev_priv
->user_irq_lock
, irqflags
);
721 BUG_ON(dev
->irq_enabled
&& dev_priv
->user_irq_refcount
<= 0);
722 if (dev
->irq_enabled
&& (--dev_priv
->user_irq_refcount
== 0)) {
724 igdng_disable_graphics_irq(dev_priv
, GT_USER_INTERRUPT
);
726 i915_disable_irq(dev_priv
, I915_USER_INTERRUPT
);
728 spin_unlock_irqrestore(&dev_priv
->user_irq_lock
, irqflags
);
731 void i915_trace_irq_get(struct drm_device
*dev
, u32 seqno
)
733 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
735 if (dev_priv
->trace_irq_seqno
== 0)
736 i915_user_irq_get(dev
);
738 dev_priv
->trace_irq_seqno
= seqno
;
741 static int i915_wait_irq(struct drm_device
* dev
, int irq_nr
)
743 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
744 struct drm_i915_master_private
*master_priv
= dev
->primary
->master
->driver_priv
;
747 DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr
,
748 READ_BREADCRUMB(dev_priv
));
750 if (READ_BREADCRUMB(dev_priv
) >= irq_nr
) {
751 if (master_priv
->sarea_priv
)
752 master_priv
->sarea_priv
->last_dispatch
= READ_BREADCRUMB(dev_priv
);
756 if (master_priv
->sarea_priv
)
757 master_priv
->sarea_priv
->perf_boxes
|= I915_BOX_WAIT
;
759 i915_user_irq_get(dev
);
760 DRM_WAIT_ON(ret
, dev_priv
->irq_queue
, 3 * DRM_HZ
,
761 READ_BREADCRUMB(dev_priv
) >= irq_nr
);
762 i915_user_irq_put(dev
);
765 DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
766 READ_BREADCRUMB(dev_priv
), (int)dev_priv
->counter
);
772 /* Needs the lock as it touches the ring.
774 int i915_irq_emit(struct drm_device
*dev
, void *data
,
775 struct drm_file
*file_priv
)
777 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
778 drm_i915_irq_emit_t
*emit
= data
;
781 if (!dev_priv
|| !dev_priv
->ring
.virtual_start
) {
782 DRM_ERROR("called with no initialization\n");
786 RING_LOCK_TEST_WITH_RETURN(dev
, file_priv
);
788 mutex_lock(&dev
->struct_mutex
);
789 result
= i915_emit_irq(dev
);
790 mutex_unlock(&dev
->struct_mutex
);
792 if (DRM_COPY_TO_USER(emit
->irq_seq
, &result
, sizeof(int))) {
793 DRM_ERROR("copy_to_user\n");
800 /* Doesn't need the hardware lock.
802 int i915_irq_wait(struct drm_device
*dev
, void *data
,
803 struct drm_file
*file_priv
)
805 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
806 drm_i915_irq_wait_t
*irqwait
= data
;
809 DRM_ERROR("called with no initialization\n");
813 return i915_wait_irq(dev
, irqwait
->irq_seq
);
816 /* Called from drm generic code, passed 'crtc' which
817 * we use as a pipe index
819 int i915_enable_vblank(struct drm_device
*dev
, int pipe
)
821 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
822 unsigned long irqflags
;
823 int pipeconf_reg
= (pipe
== 0) ? PIPEACONF
: PIPEBCONF
;
826 pipeconf
= I915_READ(pipeconf_reg
);
827 if (!(pipeconf
& PIPEACONF_ENABLE
))
833 spin_lock_irqsave(&dev_priv
->user_irq_lock
, irqflags
);
835 i915_enable_pipestat(dev_priv
, pipe
,
836 PIPE_START_VBLANK_INTERRUPT_ENABLE
);
838 i915_enable_pipestat(dev_priv
, pipe
,
839 PIPE_VBLANK_INTERRUPT_ENABLE
);
840 spin_unlock_irqrestore(&dev_priv
->user_irq_lock
, irqflags
);
844 /* Called from drm generic code, passed 'crtc' which
845 * we use as a pipe index
847 void i915_disable_vblank(struct drm_device
*dev
, int pipe
)
849 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
850 unsigned long irqflags
;
855 spin_lock_irqsave(&dev_priv
->user_irq_lock
, irqflags
);
856 i915_disable_pipestat(dev_priv
, pipe
,
857 PIPE_VBLANK_INTERRUPT_ENABLE
|
858 PIPE_START_VBLANK_INTERRUPT_ENABLE
);
859 spin_unlock_irqrestore(&dev_priv
->user_irq_lock
, irqflags
);
862 void i915_enable_interrupt (struct drm_device
*dev
)
864 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
867 opregion_enable_asle(dev
);
868 dev_priv
->irq_enabled
= 1;
872 /* Set the vblank monitor pipe
874 int i915_vblank_pipe_set(struct drm_device
*dev
, void *data
,
875 struct drm_file
*file_priv
)
877 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
880 DRM_ERROR("called with no initialization\n");
887 int i915_vblank_pipe_get(struct drm_device
*dev
, void *data
,
888 struct drm_file
*file_priv
)
890 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
891 drm_i915_vblank_pipe_t
*pipe
= data
;
894 DRM_ERROR("called with no initialization\n");
898 pipe
->pipe
= DRM_I915_VBLANK_PIPE_A
| DRM_I915_VBLANK_PIPE_B
;
904 * Schedule buffer swap at given vertical blank.
906 int i915_vblank_swap(struct drm_device
*dev
, void *data
,
907 struct drm_file
*file_priv
)
909 /* The delayed swap mechanism was fundamentally racy, and has been
910 * removed. The model was that the client requested a delayed flip/swap
911 * from the kernel, then waited for vblank before continuing to perform
912 * rendering. The problem was that the kernel might wake the client
913 * up before it dispatched the vblank swap (since the lock has to be
914 * held while touching the ringbuffer), in which case the client would
915 * clear and start the next frame before the swap occurred, and
916 * flicker would occur in addition to likely missing the vblank.
918 * In the absence of this ioctl, userland falls back to a correct path
919 * of waiting for a vblank, then dispatching the swap on its own.
920 * Context switching to userland and back is plenty fast enough for
921 * meeting the requirements of vblank swapping.
926 struct drm_i915_gem_request
*i915_get_tail_request(struct drm_device
*dev
) {
927 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
928 return list_entry(dev_priv
->mm
.request_list
.prev
, struct drm_i915_gem_request
, list
);
932 * This is called when the chip hasn't reported back with completed
933 * batchbuffers in a long time. The first time this is called we simply record
934 * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
935 * again, we assume the chip is wedged and try to fix it.
937 void i915_hangcheck_elapsed(unsigned long data
)
939 struct drm_device
*dev
= (struct drm_device
*)data
;
940 drm_i915_private_t
*dev_priv
= dev
->dev_private
;
944 acthd
= I915_READ(ACTHD
);
946 acthd
= I915_READ(ACTHD_I965
);
948 /* If all work is done then ACTHD clearly hasn't advanced. */
949 if (list_empty(&dev_priv
->mm
.request_list
) ||
950 i915_seqno_passed(i915_get_gem_seqno(dev
), i915_get_tail_request(dev
)->seqno
)) {
951 dev_priv
->hangcheck_count
= 0;
955 if (dev_priv
->last_acthd
== acthd
&& dev_priv
->hangcheck_count
> 0) {
956 DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
957 i915_handle_error(dev
, true);
961 /* Reset timer case chip hangs without another request being added */
962 mod_timer(&dev_priv
->hangcheck_timer
, jiffies
+ DRM_I915_HANGCHECK_PERIOD
);
964 if (acthd
!= dev_priv
->last_acthd
)
965 dev_priv
->hangcheck_count
= 0;
967 dev_priv
->hangcheck_count
++;
969 dev_priv
->last_acthd
= acthd
;
974 static void igdng_irq_preinstall(struct drm_device
*dev
)
976 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
978 I915_WRITE(HWSTAM
, 0xeffe);
980 /* XXX hotplug from PCH */
982 I915_WRITE(DEIMR
, 0xffffffff);
983 I915_WRITE(DEIER
, 0x0);
984 (void) I915_READ(DEIER
);
987 I915_WRITE(GTIMR
, 0xffffffff);
988 I915_WRITE(GTIER
, 0x0);
989 (void) I915_READ(GTIER
);
992 static int igdng_irq_postinstall(struct drm_device
*dev
)
994 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
995 /* enable kind of interrupts always enabled */
996 u32 display_mask
= DE_MASTER_IRQ_CONTROL
/*| DE_PCH_EVENT */;
997 u32 render_mask
= GT_USER_INTERRUPT
;
999 dev_priv
->irq_mask_reg
= ~display_mask
;
1000 dev_priv
->de_irq_enable_reg
= display_mask
;
1002 /* should always can generate irq */
1003 I915_WRITE(DEIIR
, I915_READ(DEIIR
));
1004 I915_WRITE(DEIMR
, dev_priv
->irq_mask_reg
);
1005 I915_WRITE(DEIER
, dev_priv
->de_irq_enable_reg
);
1006 (void) I915_READ(DEIER
);
1008 /* user interrupt should be enabled, but masked initial */
1009 dev_priv
->gt_irq_mask_reg
= 0xffffffff;
1010 dev_priv
->gt_irq_enable_reg
= render_mask
;
1012 I915_WRITE(GTIIR
, I915_READ(GTIIR
));
1013 I915_WRITE(GTIMR
, dev_priv
->gt_irq_mask_reg
);
1014 I915_WRITE(GTIER
, dev_priv
->gt_irq_enable_reg
);
1015 (void) I915_READ(GTIER
);
1020 void i915_driver_irq_preinstall(struct drm_device
* dev
)
1022 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1024 atomic_set(&dev_priv
->irq_received
, 0);
1026 INIT_WORK(&dev_priv
->hotplug_work
, i915_hotplug_work_func
);
1027 INIT_WORK(&dev_priv
->error_work
, i915_error_work_func
);
1029 if (IS_IGDNG(dev
)) {
1030 igdng_irq_preinstall(dev
);
1034 if (I915_HAS_HOTPLUG(dev
)) {
1035 I915_WRITE(PORT_HOTPLUG_EN
, 0);
1036 I915_WRITE(PORT_HOTPLUG_STAT
, I915_READ(PORT_HOTPLUG_STAT
));
1039 I915_WRITE(HWSTAM
, 0xeffe);
1040 I915_WRITE(PIPEASTAT
, 0);
1041 I915_WRITE(PIPEBSTAT
, 0);
1042 I915_WRITE(IMR
, 0xffffffff);
1043 I915_WRITE(IER
, 0x0);
1044 (void) I915_READ(IER
);
1048 * Must be called after intel_modeset_init or hotplug interrupts won't be
1049 * enabled correctly.
1051 int i915_driver_irq_postinstall(struct drm_device
*dev
)
1053 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1054 u32 enable_mask
= I915_INTERRUPT_ENABLE_FIX
| I915_INTERRUPT_ENABLE_VAR
;
1057 DRM_INIT_WAITQUEUE(&dev_priv
->irq_queue
);
1059 dev_priv
->vblank_pipe
= DRM_I915_VBLANK_PIPE_A
| DRM_I915_VBLANK_PIPE_B
;
1062 return igdng_irq_postinstall(dev
);
1064 /* Unmask the interrupts that we always want on. */
1065 dev_priv
->irq_mask_reg
= ~I915_INTERRUPT_ENABLE_FIX
;
1067 dev_priv
->pipestat
[0] = 0;
1068 dev_priv
->pipestat
[1] = 0;
1070 if (I915_HAS_HOTPLUG(dev
)) {
1071 u32 hotplug_en
= I915_READ(PORT_HOTPLUG_EN
);
1073 /* Note HDMI and DP share bits */
1074 if (dev_priv
->hotplug_supported_mask
& HDMIB_HOTPLUG_INT_STATUS
)
1075 hotplug_en
|= HDMIB_HOTPLUG_INT_EN
;
1076 if (dev_priv
->hotplug_supported_mask
& HDMIC_HOTPLUG_INT_STATUS
)
1077 hotplug_en
|= HDMIC_HOTPLUG_INT_EN
;
1078 if (dev_priv
->hotplug_supported_mask
& HDMID_HOTPLUG_INT_STATUS
)
1079 hotplug_en
|= HDMID_HOTPLUG_INT_EN
;
1080 if (dev_priv
->hotplug_supported_mask
& SDVOC_HOTPLUG_INT_STATUS
)
1081 hotplug_en
|= SDVOC_HOTPLUG_INT_EN
;
1082 if (dev_priv
->hotplug_supported_mask
& SDVOB_HOTPLUG_INT_STATUS
)
1083 hotplug_en
|= SDVOB_HOTPLUG_INT_EN
;
1084 if (dev_priv
->hotplug_supported_mask
& CRT_HOTPLUG_INT_STATUS
)
1085 hotplug_en
|= CRT_HOTPLUG_INT_EN
;
1086 /* Ignore TV since it's buggy */
1088 I915_WRITE(PORT_HOTPLUG_EN
, hotplug_en
);
1090 /* Enable in IER... */
1091 enable_mask
|= I915_DISPLAY_PORT_INTERRUPT
;
1092 /* and unmask in IMR */
1093 i915_enable_irq(dev_priv
, I915_DISPLAY_PORT_INTERRUPT
);
1097 * Enable some error detection, note the instruction error mask
1098 * bit is reserved, so we leave it masked.
1101 error_mask
= ~(GM45_ERROR_PAGE_TABLE
|
1102 GM45_ERROR_MEM_PRIV
|
1103 GM45_ERROR_CP_PRIV
|
1104 I915_ERROR_MEMORY_REFRESH
);
1106 error_mask
= ~(I915_ERROR_PAGE_TABLE
|
1107 I915_ERROR_MEMORY_REFRESH
);
1109 I915_WRITE(EMR
, error_mask
);
1111 /* Disable pipe interrupt enables, clear pending pipe status */
1112 I915_WRITE(PIPEASTAT
, I915_READ(PIPEASTAT
) & 0x8000ffff);
1113 I915_WRITE(PIPEBSTAT
, I915_READ(PIPEBSTAT
) & 0x8000ffff);
1114 /* Clear pending interrupt status */
1115 I915_WRITE(IIR
, I915_READ(IIR
));
1117 I915_WRITE(IER
, enable_mask
);
1118 I915_WRITE(IMR
, dev_priv
->irq_mask_reg
);
1119 (void) I915_READ(IER
);
1121 opregion_enable_asle(dev
);
1126 static void igdng_irq_uninstall(struct drm_device
*dev
)
1128 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1129 I915_WRITE(HWSTAM
, 0xffffffff);
1131 I915_WRITE(DEIMR
, 0xffffffff);
1132 I915_WRITE(DEIER
, 0x0);
1133 I915_WRITE(DEIIR
, I915_READ(DEIIR
));
1135 I915_WRITE(GTIMR
, 0xffffffff);
1136 I915_WRITE(GTIER
, 0x0);
1137 I915_WRITE(GTIIR
, I915_READ(GTIIR
));
1140 void i915_driver_irq_uninstall(struct drm_device
* dev
)
1142 drm_i915_private_t
*dev_priv
= (drm_i915_private_t
*) dev
->dev_private
;
1147 dev_priv
->vblank_pipe
= 0;
1149 if (IS_IGDNG(dev
)) {
1150 igdng_irq_uninstall(dev
);
1154 if (I915_HAS_HOTPLUG(dev
)) {
1155 I915_WRITE(PORT_HOTPLUG_EN
, 0);
1156 I915_WRITE(PORT_HOTPLUG_STAT
, I915_READ(PORT_HOTPLUG_STAT
));
1159 I915_WRITE(HWSTAM
, 0xffffffff);
1160 I915_WRITE(PIPEASTAT
, 0);
1161 I915_WRITE(PIPEBSTAT
, 0);
1162 I915_WRITE(IMR
, 0xffffffff);
1163 I915_WRITE(IER
, 0x0);
1165 I915_WRITE(PIPEASTAT
, I915_READ(PIPEASTAT
) & 0x8000ffff);
1166 I915_WRITE(PIPEBSTAT
, I915_READ(PIPEBSTAT
) & 0x8000ffff);
1167 I915_WRITE(IIR
, I915_READ(IIR
));