blob: e7472d82132ad868ddd77454514036ae360bf0ce [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
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 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Jesse Barnes63eeaf32009-06-18 16:56:52 -070029#include <linux/sysrq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include "drmP.h"
31#include "drm.h"
32#include "i915_drm.h"
33#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010034#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080035#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#define MAX_NOPID ((u32)~0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Keith Packard7c463582008-11-04 02:03:27 -080039/**
40 * Interrupts that are always left unmasked.
41 *
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
44 * PIPESTAT alone.
45 */
Kristian Høgsberg6b95a202009-11-18 11:25:18 -050046#define I915_INTERRUPT_ENABLE_FIX \
47 (I915_ASLE_INTERRUPT | \
48 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \
49 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \
50 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | \
51 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | \
52 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Keith Packard7c463582008-11-04 02:03:27 -080053
54/** Interrupts that we mask and unmask at runtime. */
55#define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT)
56
Jesse Barnes79e53942008-11-07 14:24:08 -080057#define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\
58 PIPE_VBLANK_INTERRUPT_STATUS)
59
60#define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\
61 PIPE_VBLANK_INTERRUPT_ENABLE)
62
63#define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \
64 DRM_I915_VBLANK_PIPE_B)
65
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +010066void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050067ironlake_enable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080068{
69 if ((dev_priv->gt_irq_mask_reg & mask) != 0) {
70 dev_priv->gt_irq_mask_reg &= ~mask;
71 I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg);
72 (void) I915_READ(GTIMR);
73 }
74}
75
76static inline void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050077ironlake_disable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080078{
79 if ((dev_priv->gt_irq_mask_reg & mask) != mask) {
80 dev_priv->gt_irq_mask_reg |= mask;
81 I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg);
82 (void) I915_READ(GTIMR);
83 }
84}
85
86/* For display hotplug interrupt */
87void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050088ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080089{
90 if ((dev_priv->irq_mask_reg & mask) != 0) {
91 dev_priv->irq_mask_reg &= ~mask;
92 I915_WRITE(DEIMR, dev_priv->irq_mask_reg);
93 (void) I915_READ(DEIMR);
94 }
95}
96
97static inline void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050098ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080099{
100 if ((dev_priv->irq_mask_reg & mask) != mask) {
101 dev_priv->irq_mask_reg |= mask;
102 I915_WRITE(DEIMR, dev_priv->irq_mask_reg);
103 (void) I915_READ(DEIMR);
104 }
105}
106
107void
Eric Anholted4cb412008-07-29 12:10:39 -0700108i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask)
109{
110 if ((dev_priv->irq_mask_reg & mask) != 0) {
111 dev_priv->irq_mask_reg &= ~mask;
112 I915_WRITE(IMR, dev_priv->irq_mask_reg);
113 (void) I915_READ(IMR);
114 }
115}
116
117static inline void
118i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask)
119{
120 if ((dev_priv->irq_mask_reg & mask) != mask) {
121 dev_priv->irq_mask_reg |= mask;
122 I915_WRITE(IMR, dev_priv->irq_mask_reg);
123 (void) I915_READ(IMR);
124 }
125}
126
Keith Packard7c463582008-11-04 02:03:27 -0800127static inline u32
128i915_pipestat(int pipe)
129{
130 if (pipe == 0)
131 return PIPEASTAT;
132 if (pipe == 1)
133 return PIPEBSTAT;
Andrew Morton9c84ba42008-12-01 13:14:08 -0800134 BUG();
Keith Packard7c463582008-11-04 02:03:27 -0800135}
136
137void
138i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
139{
140 if ((dev_priv->pipestat[pipe] & mask) != mask) {
141 u32 reg = i915_pipestat(pipe);
142
143 dev_priv->pipestat[pipe] |= mask;
144 /* Enable the interrupt, clear any pending status */
145 I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16));
146 (void) I915_READ(reg);
147 }
148}
149
150void
151i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
152{
153 if ((dev_priv->pipestat[pipe] & mask) != 0) {
154 u32 reg = i915_pipestat(pipe);
155
156 dev_priv->pipestat[pipe] &= ~mask;
157 I915_WRITE(reg, dev_priv->pipestat[pipe]);
158 (void) I915_READ(reg);
159 }
160}
161
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000162/**
Zhao Yakui01c66882009-10-28 05:10:00 +0000163 * intel_enable_asle - enable ASLE interrupt for OpRegion
164 */
165void intel_enable_asle (struct drm_device *dev)
166{
167 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
168
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500169 if (IS_IRONLAKE(dev))
170 ironlake_enable_display_irq(dev_priv, DE_GSE);
Zhao Yakui01c66882009-10-28 05:10:00 +0000171 else
172 i915_enable_pipestat(dev_priv, 1,
173 I915_LEGACY_BLC_EVENT_ENABLE);
174}
175
176/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700177 * i915_pipe_enabled - check if a pipe is enabled
178 * @dev: DRM device
179 * @pipe: pipe to check
180 *
181 * Reading certain registers when the pipe is disabled can hang the chip.
182 * Use this routine to make sure the PLL is running and the pipe is active
183 * before reading such registers if unsure.
184 */
185static int
186i915_pipe_enabled(struct drm_device *dev, int pipe)
187{
188 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
189 unsigned long pipeconf = pipe ? PIPEBCONF : PIPEACONF;
190
191 if (I915_READ(pipeconf) & PIPEACONF_ENABLE)
192 return 1;
193
194 return 0;
195}
196
Keith Packard42f52ef2008-10-18 19:39:29 -0700197/* Called from drm generic code, passed a 'crtc', which
198 * we use as a pipe index
199 */
200u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700201{
202 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
203 unsigned long high_frame;
204 unsigned long low_frame;
205 u32 high1, high2, low, count;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700206
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700207 high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH;
208 low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL;
209
210 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800211 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
212 "pipe %d\n", pipe);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700213 return 0;
214 }
215
216 /*
217 * High & low register fields aren't synchronized, so make sure
218 * we get a low value that's stable across two reads of the high
219 * register.
220 */
221 do {
222 high1 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
223 PIPE_FRAME_HIGH_SHIFT);
224 low = ((I915_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
225 PIPE_FRAME_LOW_SHIFT);
226 high2 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
227 PIPE_FRAME_HIGH_SHIFT);
228 } while (high1 != high2);
229
230 count = (high1 << 8) | low;
231
232 return count;
233}
234
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800235u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
236{
237 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
238 int reg = pipe ? PIPEB_FRMCOUNT_GM45 : PIPEA_FRMCOUNT_GM45;
239
240 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800241 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
242 "pipe %d\n", pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800243 return 0;
244 }
245
246 return I915_READ(reg);
247}
248
Jesse Barnes5ca58282009-03-31 14:11:15 -0700249/*
250 * Handle hotplug events outside the interrupt handler proper.
251 */
252static void i915_hotplug_work_func(struct work_struct *work)
253{
254 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
255 hotplug_work);
256 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700257 struct drm_mode_config *mode_config = &dev->mode_config;
258 struct drm_connector *connector;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700259
Keith Packardc31c4ba2009-05-06 11:48:58 -0700260 if (mode_config->num_connector) {
261 list_for_each_entry(connector, &mode_config->connector_list, head) {
262 struct intel_output *intel_output = to_intel_output(connector);
263
264 if (intel_output->hot_plug)
265 (*intel_output->hot_plug) (intel_output);
266 }
267 }
Jesse Barnes5ca58282009-03-31 14:11:15 -0700268 /* Just fire off a uevent and let userspace tell us what to do */
269 drm_sysfs_hotplug_event(dev);
270}
271
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500272irqreturn_t ironlake_irq_handler(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800273{
274 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
275 int ret = IRQ_NONE;
Dave Airlie3ff99162009-12-08 14:03:47 +1000276 u32 de_iir, gt_iir, de_ier, pch_iir;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800277 struct drm_i915_master_private *master_priv;
278
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000279 /* disable master interrupt before clearing iir */
280 de_ier = I915_READ(DEIER);
281 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
282 (void)I915_READ(DEIER);
283
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800284 de_iir = I915_READ(DEIIR);
285 gt_iir = I915_READ(GTIIR);
Zhenyu Wangc6501562009-11-03 18:57:21 +0000286 pch_iir = I915_READ(SDEIIR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800287
Zou Nan haic7c85102010-01-15 10:29:06 +0800288 if (de_iir == 0 && gt_iir == 0 && pch_iir == 0)
289 goto done;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800290
Zou Nan haic7c85102010-01-15 10:29:06 +0800291 ret = IRQ_HANDLED;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800292
Zou Nan haic7c85102010-01-15 10:29:06 +0800293 if (dev->primary->master) {
294 master_priv = dev->primary->master->driver_priv;
295 if (master_priv->sarea_priv)
296 master_priv->sarea_priv->last_dispatch =
297 READ_BREADCRUMB(dev_priv);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800298 }
299
Zou Nan haic7c85102010-01-15 10:29:06 +0800300 if (gt_iir & GT_USER_INTERRUPT) {
301 u32 seqno = i915_get_gem_seqno(dev);
302 dev_priv->mm.irq_gem_seqno = seqno;
303 trace_i915_gem_request_complete(dev, seqno);
304 DRM_WAKEUP(&dev_priv->irq_queue);
305 dev_priv->hangcheck_count = 0;
306 mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD);
307 }
308
309 if (de_iir & DE_GSE)
310 ironlake_opregion_gse_intr(dev);
311
Li Pengc062df62010-01-23 00:12:58 +0800312 if (de_iir & DE_PIPEA_VBLANK)
313 drm_handle_vblank(dev, 0);
314
315 if (de_iir & DE_PIPEB_VBLANK)
316 drm_handle_vblank(dev, 1);
317
Zou Nan haic7c85102010-01-15 10:29:06 +0800318 /* check event from PCH */
319 if ((de_iir & DE_PCH_EVENT) &&
320 (pch_iir & SDE_HOTPLUG_MASK)) {
321 queue_work(dev_priv->wq, &dev_priv->hotplug_work);
322 }
323
324 /* should clear PCH hotplug event before clear CPU irq */
325 I915_WRITE(SDEIIR, pch_iir);
326 I915_WRITE(GTIIR, gt_iir);
327 I915_WRITE(DEIIR, de_iir);
328
329done:
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000330 I915_WRITE(DEIER, de_ier);
331 (void)I915_READ(DEIER);
332
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800333 return ret;
334}
335
Jesse Barnes8a905232009-07-11 16:48:03 -0400336/**
337 * i915_error_work_func - do process context error handling work
338 * @work: work struct
339 *
340 * Fire an error uevent so userspace can see that a hang or error
341 * was detected.
342 */
343static void i915_error_work_func(struct work_struct *work)
344{
345 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
346 error_work);
347 struct drm_device *dev = dev_priv->dev;
Ben Gamarif316a422009-09-14 17:48:46 -0400348 char *error_event[] = { "ERROR=1", NULL };
349 char *reset_event[] = { "RESET=1", NULL };
350 char *reset_done_event[] = { "ERROR=0", NULL };
Jesse Barnes8a905232009-07-11 16:48:03 -0400351
Zhao Yakui44d98a62009-10-09 11:39:40 +0800352 DRM_DEBUG_DRIVER("generating error event\n");
Ben Gamarif316a422009-09-14 17:48:46 -0400353 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -0400354
Ben Gamariba1234d2009-09-14 17:48:47 -0400355 if (atomic_read(&dev_priv->mm.wedged)) {
Ben Gamarif316a422009-09-14 17:48:46 -0400356 if (IS_I965G(dev)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800357 DRM_DEBUG_DRIVER("resetting chip\n");
Ben Gamarif316a422009-09-14 17:48:46 -0400358 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event);
359 if (!i965_reset(dev, GDRST_RENDER)) {
Ben Gamariba1234d2009-09-14 17:48:47 -0400360 atomic_set(&dev_priv->mm.wedged, 0);
Ben Gamarif316a422009-09-14 17:48:46 -0400361 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event);
362 }
363 } else {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800364 DRM_DEBUG_DRIVER("reboot required\n");
Ben Gamarif316a422009-09-14 17:48:46 -0400365 }
366 }
Jesse Barnes8a905232009-07-11 16:48:03 -0400367}
368
369/**
370 * i915_capture_error_state - capture an error record for later analysis
371 * @dev: drm device
372 *
373 * Should be called when an error is detected (either a hang or an error
374 * interrupt) to capture error state from the time of the error. Fills
375 * out a structure which becomes available in debugfs for user level tools
376 * to pick up.
377 */
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700378static void i915_capture_error_state(struct drm_device *dev)
379{
380 struct drm_i915_private *dev_priv = dev->dev_private;
381 struct drm_i915_error_state *error;
382 unsigned long flags;
383
384 spin_lock_irqsave(&dev_priv->error_lock, flags);
385 if (dev_priv->first_error)
386 goto out;
387
388 error = kmalloc(sizeof(*error), GFP_ATOMIC);
389 if (!error) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800390 DRM_DEBUG_DRIVER("out ot memory, not capturing error state\n");
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700391 goto out;
392 }
393
394 error->eir = I915_READ(EIR);
395 error->pgtbl_er = I915_READ(PGTBL_ER);
396 error->pipeastat = I915_READ(PIPEASTAT);
397 error->pipebstat = I915_READ(PIPEBSTAT);
398 error->instpm = I915_READ(INSTPM);
399 if (!IS_I965G(dev)) {
400 error->ipeir = I915_READ(IPEIR);
401 error->ipehr = I915_READ(IPEHR);
402 error->instdone = I915_READ(INSTDONE);
403 error->acthd = I915_READ(ACTHD);
404 } else {
405 error->ipeir = I915_READ(IPEIR_I965);
406 error->ipehr = I915_READ(IPEHR_I965);
407 error->instdone = I915_READ(INSTDONE_I965);
408 error->instps = I915_READ(INSTPS);
409 error->instdone1 = I915_READ(INSTDONE1);
410 error->acthd = I915_READ(ACTHD_I965);
411 }
412
Jesse Barnes8a905232009-07-11 16:48:03 -0400413 do_gettimeofday(&error->time);
414
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700415 dev_priv->first_error = error;
416
417out:
418 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
419}
420
Jesse Barnes8a905232009-07-11 16:48:03 -0400421/**
422 * i915_handle_error - handle an error interrupt
423 * @dev: drm device
424 *
425 * Do some basic checking of regsiter state at error interrupt time and
426 * dump it to the syslog. Also call i915_capture_error_state() to make
427 * sure we get a record and make it available in debugfs. Fire a uevent
428 * so userspace knows something bad happened (should trigger collection
429 * of a ring dump etc.).
430 */
Ben Gamariba1234d2009-09-14 17:48:47 -0400431static void i915_handle_error(struct drm_device *dev, bool wedged)
Jesse Barnes8a905232009-07-11 16:48:03 -0400432{
433 struct drm_i915_private *dev_priv = dev->dev_private;
434 u32 eir = I915_READ(EIR);
435 u32 pipea_stats = I915_READ(PIPEASTAT);
436 u32 pipeb_stats = I915_READ(PIPEBSTAT);
437
438 i915_capture_error_state(dev);
439
440 printk(KERN_ERR "render error detected, EIR: 0x%08x\n",
441 eir);
442
443 if (IS_G4X(dev)) {
444 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
445 u32 ipeir = I915_READ(IPEIR_I965);
446
447 printk(KERN_ERR " IPEIR: 0x%08x\n",
448 I915_READ(IPEIR_I965));
449 printk(KERN_ERR " IPEHR: 0x%08x\n",
450 I915_READ(IPEHR_I965));
451 printk(KERN_ERR " INSTDONE: 0x%08x\n",
452 I915_READ(INSTDONE_I965));
453 printk(KERN_ERR " INSTPS: 0x%08x\n",
454 I915_READ(INSTPS));
455 printk(KERN_ERR " INSTDONE1: 0x%08x\n",
456 I915_READ(INSTDONE1));
457 printk(KERN_ERR " ACTHD: 0x%08x\n",
458 I915_READ(ACTHD_I965));
459 I915_WRITE(IPEIR_I965, ipeir);
460 (void)I915_READ(IPEIR_I965);
461 }
462 if (eir & GM45_ERROR_PAGE_TABLE) {
463 u32 pgtbl_err = I915_READ(PGTBL_ER);
464 printk(KERN_ERR "page table error\n");
465 printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
466 pgtbl_err);
467 I915_WRITE(PGTBL_ER, pgtbl_err);
468 (void)I915_READ(PGTBL_ER);
469 }
470 }
471
472 if (IS_I9XX(dev)) {
473 if (eir & I915_ERROR_PAGE_TABLE) {
474 u32 pgtbl_err = I915_READ(PGTBL_ER);
475 printk(KERN_ERR "page table error\n");
476 printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
477 pgtbl_err);
478 I915_WRITE(PGTBL_ER, pgtbl_err);
479 (void)I915_READ(PGTBL_ER);
480 }
481 }
482
483 if (eir & I915_ERROR_MEMORY_REFRESH) {
484 printk(KERN_ERR "memory refresh error\n");
485 printk(KERN_ERR "PIPEASTAT: 0x%08x\n",
486 pipea_stats);
487 printk(KERN_ERR "PIPEBSTAT: 0x%08x\n",
488 pipeb_stats);
489 /* pipestat has already been acked */
490 }
491 if (eir & I915_ERROR_INSTRUCTION) {
492 printk(KERN_ERR "instruction error\n");
493 printk(KERN_ERR " INSTPM: 0x%08x\n",
494 I915_READ(INSTPM));
495 if (!IS_I965G(dev)) {
496 u32 ipeir = I915_READ(IPEIR);
497
498 printk(KERN_ERR " IPEIR: 0x%08x\n",
499 I915_READ(IPEIR));
500 printk(KERN_ERR " IPEHR: 0x%08x\n",
501 I915_READ(IPEHR));
502 printk(KERN_ERR " INSTDONE: 0x%08x\n",
503 I915_READ(INSTDONE));
504 printk(KERN_ERR " ACTHD: 0x%08x\n",
505 I915_READ(ACTHD));
506 I915_WRITE(IPEIR, ipeir);
507 (void)I915_READ(IPEIR);
508 } else {
509 u32 ipeir = I915_READ(IPEIR_I965);
510
511 printk(KERN_ERR " IPEIR: 0x%08x\n",
512 I915_READ(IPEIR_I965));
513 printk(KERN_ERR " IPEHR: 0x%08x\n",
514 I915_READ(IPEHR_I965));
515 printk(KERN_ERR " INSTDONE: 0x%08x\n",
516 I915_READ(INSTDONE_I965));
517 printk(KERN_ERR " INSTPS: 0x%08x\n",
518 I915_READ(INSTPS));
519 printk(KERN_ERR " INSTDONE1: 0x%08x\n",
520 I915_READ(INSTDONE1));
521 printk(KERN_ERR " ACTHD: 0x%08x\n",
522 I915_READ(ACTHD_I965));
523 I915_WRITE(IPEIR_I965, ipeir);
524 (void)I915_READ(IPEIR_I965);
525 }
526 }
527
528 I915_WRITE(EIR, eir);
529 (void)I915_READ(EIR);
530 eir = I915_READ(EIR);
531 if (eir) {
532 /*
533 * some errors might have become stuck,
534 * mask them.
535 */
536 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
537 I915_WRITE(EMR, I915_READ(EMR) | eir);
538 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
539 }
540
Ben Gamariba1234d2009-09-14 17:48:47 -0400541 if (wedged) {
542 atomic_set(&dev_priv->mm.wedged, 1);
543
Ben Gamari11ed50e2009-09-14 17:48:45 -0400544 /*
545 * Wakeup waiting processes so they don't hang
546 */
Ben Gamari11ed50e2009-09-14 17:48:45 -0400547 DRM_WAKEUP(&dev_priv->irq_queue);
548 }
549
Eric Anholt9c9fe1f2009-08-03 16:09:16 -0700550 queue_work(dev_priv->wq, &dev_priv->error_work);
Jesse Barnes8a905232009-07-11 16:48:03 -0400551}
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
554{
Dave Airlie84b1fd12007-07-11 15:53:27 +1000555 struct drm_device *dev = (struct drm_device *) arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000557 struct drm_i915_master_private *master_priv;
Eric Anholtcdfbc412008-11-04 15:50:30 -0800558 u32 iir, new_iir;
559 u32 pipea_stats, pipeb_stats;
Keith Packard05eff842008-11-19 14:03:05 -0800560 u32 vblank_status;
561 u32 vblank_enable;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700562 int vblank = 0;
Keith Packard7c463582008-11-04 02:03:27 -0800563 unsigned long irqflags;
Keith Packard05eff842008-11-19 14:03:05 -0800564 int irq_received;
565 int ret = IRQ_NONE;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000566
Eric Anholt630681d2008-10-06 15:14:12 -0700567 atomic_inc(&dev_priv->irq_received);
568
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500569 if (IS_IRONLAKE(dev))
570 return ironlake_irq_handler(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800571
Eric Anholted4cb412008-07-29 12:10:39 -0700572 iir = I915_READ(IIR);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000573
Keith Packard05eff842008-11-19 14:03:05 -0800574 if (IS_I965G(dev)) {
575 vblank_status = I915_START_VBLANK_INTERRUPT_STATUS;
576 vblank_enable = PIPE_START_VBLANK_INTERRUPT_ENABLE;
577 } else {
578 vblank_status = I915_VBLANK_INTERRUPT_STATUS;
579 vblank_enable = I915_VBLANK_INTERRUPT_ENABLE;
580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Keith Packard05eff842008-11-19 14:03:05 -0800582 for (;;) {
583 irq_received = iir != 0;
584
585 /* Can't rely on pipestat interrupt bit in iir as it might
586 * have been cleared after the pipestat interrupt was received.
587 * It doesn't set the bit in iir again, but it still produces
588 * interrupts (for non-MSI).
589 */
590 spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
591 pipea_stats = I915_READ(PIPEASTAT);
592 pipeb_stats = I915_READ(PIPEBSTAT);
Jesse Barnes79e53942008-11-07 14:24:08 -0800593
Jesse Barnes8a905232009-07-11 16:48:03 -0400594 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Ben Gamariba1234d2009-09-14 17:48:47 -0400595 i915_handle_error(dev, false);
Jesse Barnes8a905232009-07-11 16:48:03 -0400596
Eric Anholtcdfbc412008-11-04 15:50:30 -0800597 /*
598 * Clear the PIPE(A|B)STAT regs before the IIR
599 */
Keith Packard05eff842008-11-19 14:03:05 -0800600 if (pipea_stats & 0x8000ffff) {
Shaohua Li7662c8b2009-06-26 11:23:55 +0800601 if (pipea_stats & PIPE_FIFO_UNDERRUN_STATUS)
Zhao Yakui44d98a62009-10-09 11:39:40 +0800602 DRM_DEBUG_DRIVER("pipe a underrun\n");
Eric Anholtcdfbc412008-11-04 15:50:30 -0800603 I915_WRITE(PIPEASTAT, pipea_stats);
Keith Packard05eff842008-11-19 14:03:05 -0800604 irq_received = 1;
Eric Anholtcdfbc412008-11-04 15:50:30 -0800605 }
Keith Packard7c463582008-11-04 02:03:27 -0800606
Keith Packard05eff842008-11-19 14:03:05 -0800607 if (pipeb_stats & 0x8000ffff) {
Shaohua Li7662c8b2009-06-26 11:23:55 +0800608 if (pipeb_stats & PIPE_FIFO_UNDERRUN_STATUS)
Zhao Yakui44d98a62009-10-09 11:39:40 +0800609 DRM_DEBUG_DRIVER("pipe b underrun\n");
Eric Anholtcdfbc412008-11-04 15:50:30 -0800610 I915_WRITE(PIPEBSTAT, pipeb_stats);
Keith Packard05eff842008-11-19 14:03:05 -0800611 irq_received = 1;
Eric Anholtcdfbc412008-11-04 15:50:30 -0800612 }
Keith Packard05eff842008-11-19 14:03:05 -0800613 spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
614
615 if (!irq_received)
616 break;
617
618 ret = IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Jesse Barnes5ca58282009-03-31 14:11:15 -0700620 /* Consume port. Then clear IIR or we'll miss events */
621 if ((I915_HAS_HOTPLUG(dev)) &&
622 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
623 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
624
Zhao Yakui44d98a62009-10-09 11:39:40 +0800625 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
Jesse Barnes5ca58282009-03-31 14:11:15 -0700626 hotplug_status);
627 if (hotplug_status & dev_priv->hotplug_supported_mask)
Eric Anholt9c9fe1f2009-08-03 16:09:16 -0700628 queue_work(dev_priv->wq,
629 &dev_priv->hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700630
631 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
632 I915_READ(PORT_HOTPLUG_STAT);
633 }
634
Eric Anholtcdfbc412008-11-04 15:50:30 -0800635 I915_WRITE(IIR, iir);
636 new_iir = I915_READ(IIR); /* Flush posted writes */
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +0100637
Dave Airlie7c1c2872008-11-28 14:22:24 +1000638 if (dev->primary->master) {
639 master_priv = dev->primary->master->driver_priv;
640 if (master_priv->sarea_priv)
641 master_priv->sarea_priv->last_dispatch =
642 READ_BREADCRUMB(dev_priv);
643 }
Keith Packard7c463582008-11-04 02:03:27 -0800644
Eric Anholtcdfbc412008-11-04 15:50:30 -0800645 if (iir & I915_USER_INTERRUPT) {
Chris Wilson1c5d22f2009-08-25 11:15:50 +0100646 u32 seqno = i915_get_gem_seqno(dev);
647 dev_priv->mm.irq_gem_seqno = seqno;
648 trace_i915_gem_request_complete(dev, seqno);
Eric Anholtcdfbc412008-11-04 15:50:30 -0800649 DRM_WAKEUP(&dev_priv->irq_queue);
Ben Gamarif65d9422009-09-14 17:48:44 -0400650 dev_priv->hangcheck_count = 0;
651 mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD);
Eric Anholtcdfbc412008-11-04 15:50:30 -0800652 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700653
Kristian Høgsberg6b95a202009-11-18 11:25:18 -0500654 if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT)
655 intel_prepare_page_flip(dev, 0);
656
657 if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT)
658 intel_prepare_page_flip(dev, 1);
659
Keith Packard05eff842008-11-19 14:03:05 -0800660 if (pipea_stats & vblank_status) {
Eric Anholtcdfbc412008-11-04 15:50:30 -0800661 vblank++;
662 drm_handle_vblank(dev, 0);
Kristian Høgsberg6b95a202009-11-18 11:25:18 -0500663 intel_finish_page_flip(dev, 0);
Eric Anholtcdfbc412008-11-04 15:50:30 -0800664 }
Eric Anholt673a3942008-07-30 12:06:12 -0700665
Keith Packard05eff842008-11-19 14:03:05 -0800666 if (pipeb_stats & vblank_status) {
Eric Anholtcdfbc412008-11-04 15:50:30 -0800667 vblank++;
668 drm_handle_vblank(dev, 1);
Kristian Høgsberg6b95a202009-11-18 11:25:18 -0500669 intel_finish_page_flip(dev, 1);
Eric Anholtcdfbc412008-11-04 15:50:30 -0800670 }
Keith Packard7c463582008-11-04 02:03:27 -0800671
Eric Anholtcdfbc412008-11-04 15:50:30 -0800672 if ((pipeb_stats & I915_LEGACY_BLC_EVENT_STATUS) ||
673 (iir & I915_ASLE_INTERRUPT))
674 opregion_asle_intr(dev);
Keith Packard7c463582008-11-04 02:03:27 -0800675
Eric Anholtcdfbc412008-11-04 15:50:30 -0800676 /* With MSI, interrupts are only generated when iir
677 * transitions from zero to nonzero. If another bit got
678 * set while we were handling the existing iir bits, then
679 * we would never get another interrupt.
680 *
681 * This is fine on non-MSI as well, as if we hit this path
682 * we avoid exiting the interrupt handler only to generate
683 * another one.
684 *
685 * Note that for MSI this could cause a stray interrupt report
686 * if an interrupt landed in the time between writing IIR and
687 * the posting read. This should be rare enough to never
688 * trigger the 99% of 100,000 interrupts test for disabling
689 * stray interrupts.
690 */
691 iir = new_iir;
Keith Packard05eff842008-11-19 14:03:05 -0800692 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700693
Keith Packard05eff842008-11-19 14:03:05 -0800694 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695}
696
Dave Airlieaf6061a2008-05-07 12:15:39 +1000697static int i915_emit_irq(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698{
699 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000700 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 RING_LOCALS;
702
703 i915_kernel_lost_context(dev);
704
Zhao Yakui44d98a62009-10-09 11:39:40 +0800705 DRM_DEBUG_DRIVER("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Kristian Høgsbergc99b0582008-08-20 11:20:13 -0400707 dev_priv->counter++;
Alan Hourihanec29b6692006-08-12 16:29:24 +1000708 if (dev_priv->counter > 0x7FFFFFFFUL)
Kristian Høgsbergc99b0582008-08-20 11:20:13 -0400709 dev_priv->counter = 1;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000710 if (master_priv->sarea_priv)
711 master_priv->sarea_priv->last_enqueue = dev_priv->counter;
Alan Hourihanec29b6692006-08-12 16:29:24 +1000712
Keith Packard0baf8232008-11-08 11:44:14 +1000713 BEGIN_LP_RING(4);
Jesse Barnes585fb112008-07-29 11:54:06 -0700714 OUT_RING(MI_STORE_DWORD_INDEX);
Keith Packard0baf8232008-11-08 11:44:14 +1000715 OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
Alan Hourihanec29b6692006-08-12 16:29:24 +1000716 OUT_RING(dev_priv->counter);
Jesse Barnes585fb112008-07-29 11:54:06 -0700717 OUT_RING(MI_USER_INTERRUPT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 ADVANCE_LP_RING();
Dave Airliebc5f4522007-11-05 12:50:58 +1000719
Alan Hourihanec29b6692006-08-12 16:29:24 +1000720 return dev_priv->counter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
Eric Anholt673a3942008-07-30 12:06:12 -0700723void i915_user_irq_get(struct drm_device *dev)
Eric Anholted4cb412008-07-29 12:10:39 -0700724{
725 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -0700726 unsigned long irqflags;
Eric Anholted4cb412008-07-29 12:10:39 -0700727
Keith Packarde9d21d72008-10-16 11:31:38 -0700728 spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800729 if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500730 if (IS_IRONLAKE(dev))
731 ironlake_enable_graphics_irq(dev_priv, GT_USER_INTERRUPT);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800732 else
733 i915_enable_irq(dev_priv, I915_USER_INTERRUPT);
734 }
Keith Packarde9d21d72008-10-16 11:31:38 -0700735 spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
Eric Anholted4cb412008-07-29 12:10:39 -0700736}
737
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700738void i915_user_irq_put(struct drm_device *dev)
Eric Anholted4cb412008-07-29 12:10:39 -0700739{
740 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -0700741 unsigned long irqflags;
Eric Anholted4cb412008-07-29 12:10:39 -0700742
Keith Packarde9d21d72008-10-16 11:31:38 -0700743 spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
Eric Anholted4cb412008-07-29 12:10:39 -0700744 BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800745 if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500746 if (IS_IRONLAKE(dev))
747 ironlake_disable_graphics_irq(dev_priv, GT_USER_INTERRUPT);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800748 else
749 i915_disable_irq(dev_priv, I915_USER_INTERRUPT);
750 }
Keith Packarde9d21d72008-10-16 11:31:38 -0700751 spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
Eric Anholted4cb412008-07-29 12:10:39 -0700752}
753
Chris Wilson9d34e5d2009-09-24 05:26:06 +0100754void i915_trace_irq_get(struct drm_device *dev, u32 seqno)
755{
756 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
757
758 if (dev_priv->trace_irq_seqno == 0)
759 i915_user_irq_get(dev);
760
761 dev_priv->trace_irq_seqno = seqno;
762}
763
Dave Airlie84b1fd12007-07-11 15:53:27 +1000764static int i915_wait_irq(struct drm_device * dev, int irq_nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765{
766 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlie7c1c2872008-11-28 14:22:24 +1000767 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 int ret = 0;
769
Zhao Yakui44d98a62009-10-09 11:39:40 +0800770 DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 READ_BREADCRUMB(dev_priv));
772
Eric Anholted4cb412008-07-29 12:10:39 -0700773 if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
Dave Airlie7c1c2872008-11-28 14:22:24 +1000774 if (master_priv->sarea_priv)
775 master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 return 0;
Eric Anholted4cb412008-07-29 12:10:39 -0700777 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Dave Airlie7c1c2872008-11-28 14:22:24 +1000779 if (master_priv->sarea_priv)
780 master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Eric Anholted4cb412008-07-29 12:10:39 -0700782 i915_user_irq_get(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
784 READ_BREADCRUMB(dev_priv) >= irq_nr);
Eric Anholted4cb412008-07-29 12:10:39 -0700785 i915_user_irq_put(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Eric Anholt20caafa2007-08-25 19:22:43 +1000787 if (ret == -EBUSY) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000788 DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
790 }
791
Dave Airlieaf6061a2008-05-07 12:15:39 +1000792 return ret;
793}
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795/* Needs the lock as it touches the ring.
796 */
Eric Anholtc153f452007-09-03 12:06:45 +1000797int i915_irq_emit(struct drm_device *dev, void *data,
798 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000801 drm_i915_irq_emit_t *emit = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 int result;
803
Eric Anholt07f4f8b2009-04-16 13:46:12 -0700804 if (!dev_priv || !dev_priv->ring.virtual_start) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000805 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000806 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
Eric Anholt299eb932009-02-24 22:14:12 -0800808
809 RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
810
Eric Anholt546b0972008-09-01 16:45:29 -0700811 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 result = i915_emit_irq(dev);
Eric Anholt546b0972008-09-01 16:45:29 -0700813 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Eric Anholtc153f452007-09-03 12:06:45 +1000815 if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 DRM_ERROR("copy_to_user\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000817 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 }
819
820 return 0;
821}
822
823/* Doesn't need the hardware lock.
824 */
Eric Anholtc153f452007-09-03 12:06:45 +1000825int i915_irq_wait(struct drm_device *dev, void *data,
826 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000829 drm_i915_irq_wait_t *irqwait = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000832 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000833 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835
Eric Anholtc153f452007-09-03 12:06:45 +1000836 return i915_wait_irq(dev, irqwait->irq_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837}
838
Keith Packard42f52ef2008-10-18 19:39:29 -0700839/* Called from drm generic code, passed 'crtc' which
840 * we use as a pipe index
841 */
842int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700843{
844 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -0700845 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -0800846 int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
847 u32 pipeconf;
848
849 pipeconf = I915_READ(pipeconf_reg);
850 if (!(pipeconf & PIPEACONF_ENABLE))
851 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700852
Keith Packarde9d21d72008-10-16 11:31:38 -0700853 spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
Li Pengc062df62010-01-23 00:12:58 +0800854 if (IS_IRONLAKE(dev))
855 ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
856 DE_PIPEA_VBLANK: DE_PIPEB_VBLANK);
857 else if (IS_I965G(dev))
Keith Packard7c463582008-11-04 02:03:27 -0800858 i915_enable_pipestat(dev_priv, pipe,
859 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -0700860 else
Keith Packard7c463582008-11-04 02:03:27 -0800861 i915_enable_pipestat(dev_priv, pipe,
862 PIPE_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -0700863 spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700864 return 0;
865}
866
Keith Packard42f52ef2008-10-18 19:39:29 -0700867/* Called from drm generic code, passed 'crtc' which
868 * we use as a pipe index
869 */
870void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700871{
872 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -0700873 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700874
Keith Packarde9d21d72008-10-16 11:31:38 -0700875 spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
Li Pengc062df62010-01-23 00:12:58 +0800876 if (IS_IRONLAKE(dev))
877 ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
878 DE_PIPEA_VBLANK: DE_PIPEB_VBLANK);
879 else
880 i915_disable_pipestat(dev_priv, pipe,
881 PIPE_VBLANK_INTERRUPT_ENABLE |
882 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -0700883 spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700884}
885
Jesse Barnes79e53942008-11-07 14:24:08 -0800886void i915_enable_interrupt (struct drm_device *dev)
887{
888 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wange170b032009-06-05 15:38:40 +0800889
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500890 if (!IS_IRONLAKE(dev))
Zhenyu Wange170b032009-06-05 15:38:40 +0800891 opregion_enable_asle(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -0800892 dev_priv->irq_enabled = 1;
893}
894
895
Dave Airlie702880f2006-06-24 17:07:34 +1000896/* Set the vblank monitor pipe
897 */
Eric Anholtc153f452007-09-03 12:06:45 +1000898int i915_vblank_pipe_set(struct drm_device *dev, void *data,
899 struct drm_file *file_priv)
Dave Airlie702880f2006-06-24 17:07:34 +1000900{
Dave Airlie702880f2006-06-24 17:07:34 +1000901 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airlie702880f2006-06-24 17:07:34 +1000902
903 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000904 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000905 return -EINVAL;
Dave Airlie702880f2006-06-24 17:07:34 +1000906 }
907
=?utf-8?q?Michel_D=C3=A4nzer?=5b516942006-10-25 00:08:23 +1000908 return 0;
Dave Airlie702880f2006-06-24 17:07:34 +1000909}
910
Eric Anholtc153f452007-09-03 12:06:45 +1000911int i915_vblank_pipe_get(struct drm_device *dev, void *data,
912 struct drm_file *file_priv)
Dave Airlie702880f2006-06-24 17:07:34 +1000913{
Dave Airlie702880f2006-06-24 17:07:34 +1000914 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000915 drm_i915_vblank_pipe_t *pipe = data;
Dave Airlie702880f2006-06-24 17:07:34 +1000916
917 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000918 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000919 return -EINVAL;
Dave Airlie702880f2006-06-24 17:07:34 +1000920 }
921
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700922 pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
Eric Anholtc153f452007-09-03 12:06:45 +1000923
Dave Airlie702880f2006-06-24 17:07:34 +1000924 return 0;
925}
926
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000927/**
928 * Schedule buffer swap at given vertical blank.
929 */
Eric Anholtc153f452007-09-03 12:06:45 +1000930int i915_vblank_swap(struct drm_device *dev, void *data,
931 struct drm_file *file_priv)
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000932{
Eric Anholtbd95e0a2008-11-04 12:01:24 -0800933 /* The delayed swap mechanism was fundamentally racy, and has been
934 * removed. The model was that the client requested a delayed flip/swap
935 * from the kernel, then waited for vblank before continuing to perform
936 * rendering. The problem was that the kernel might wake the client
937 * up before it dispatched the vblank swap (since the lock has to be
938 * held while touching the ringbuffer), in which case the client would
939 * clear and start the next frame before the swap occurred, and
940 * flicker would occur in addition to likely missing the vblank.
941 *
942 * In the absence of this ioctl, userland falls back to a correct path
943 * of waiting for a vblank, then dispatching the swap on its own.
944 * Context switching to userland and back is plenty fast enough for
945 * meeting the requirements of vblank swapping.
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700946 */
Eric Anholtbd95e0a2008-11-04 12:01:24 -0800947 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000948}
949
Ben Gamarif65d9422009-09-14 17:48:44 -0400950struct drm_i915_gem_request *i915_get_tail_request(struct drm_device *dev) {
951 drm_i915_private_t *dev_priv = dev->dev_private;
952 return list_entry(dev_priv->mm.request_list.prev, struct drm_i915_gem_request, list);
953}
954
955/**
956 * This is called when the chip hasn't reported back with completed
957 * batchbuffers in a long time. The first time this is called we simply record
958 * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
959 * again, we assume the chip is wedged and try to fix it.
960 */
961void i915_hangcheck_elapsed(unsigned long data)
962{
963 struct drm_device *dev = (struct drm_device *)data;
964 drm_i915_private_t *dev_priv = dev->dev_private;
965 uint32_t acthd;
966
967 if (!IS_I965G(dev))
968 acthd = I915_READ(ACTHD);
969 else
970 acthd = I915_READ(ACTHD_I965);
971
972 /* If all work is done then ACTHD clearly hasn't advanced. */
973 if (list_empty(&dev_priv->mm.request_list) ||
974 i915_seqno_passed(i915_get_gem_seqno(dev), i915_get_tail_request(dev)->seqno)) {
975 dev_priv->hangcheck_count = 0;
976 return;
977 }
978
979 if (dev_priv->last_acthd == acthd && dev_priv->hangcheck_count > 0) {
980 DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
Ben Gamariba1234d2009-09-14 17:48:47 -0400981 i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -0400982 return;
983 }
984
985 /* Reset timer case chip hangs without another request being added */
986 mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD);
987
988 if (acthd != dev_priv->last_acthd)
989 dev_priv->hangcheck_count = 0;
990 else
991 dev_priv->hangcheck_count++;
992
993 dev_priv->last_acthd = acthd;
994}
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996/* drm_dma.h hooks
997*/
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500998static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800999{
1000 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1001
1002 I915_WRITE(HWSTAM, 0xeffe);
1003
1004 /* XXX hotplug from PCH */
1005
1006 I915_WRITE(DEIMR, 0xffffffff);
1007 I915_WRITE(DEIER, 0x0);
1008 (void) I915_READ(DEIER);
1009
1010 /* and GT */
1011 I915_WRITE(GTIMR, 0xffffffff);
1012 I915_WRITE(GTIER, 0x0);
1013 (void) I915_READ(GTIER);
Zhenyu Wangc6501562009-11-03 18:57:21 +00001014
1015 /* south display irq */
1016 I915_WRITE(SDEIMR, 0xffffffff);
1017 I915_WRITE(SDEIER, 0x0);
1018 (void) I915_READ(SDEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001019}
1020
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001021static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001022{
1023 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1024 /* enable kind of interrupts always enabled */
Li Pengc062df62010-01-23 00:12:58 +08001025 u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
1026 DE_PIPEA_VBLANK | DE_PIPEB_VBLANK;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001027 u32 render_mask = GT_USER_INTERRUPT;
Zhenyu Wangc6501562009-11-03 18:57:21 +00001028 u32 hotplug_mask = SDE_CRT_HOTPLUG | SDE_PORTB_HOTPLUG |
1029 SDE_PORTC_HOTPLUG | SDE_PORTD_HOTPLUG;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001030
1031 dev_priv->irq_mask_reg = ~display_mask;
1032 dev_priv->de_irq_enable_reg = display_mask;
1033
1034 /* should always can generate irq */
1035 I915_WRITE(DEIIR, I915_READ(DEIIR));
1036 I915_WRITE(DEIMR, dev_priv->irq_mask_reg);
1037 I915_WRITE(DEIER, dev_priv->de_irq_enable_reg);
1038 (void) I915_READ(DEIER);
1039
1040 /* user interrupt should be enabled, but masked initial */
1041 dev_priv->gt_irq_mask_reg = 0xffffffff;
1042 dev_priv->gt_irq_enable_reg = render_mask;
1043
1044 I915_WRITE(GTIIR, I915_READ(GTIIR));
1045 I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg);
1046 I915_WRITE(GTIER, dev_priv->gt_irq_enable_reg);
1047 (void) I915_READ(GTIER);
1048
Zhenyu Wangc6501562009-11-03 18:57:21 +00001049 dev_priv->pch_irq_mask_reg = ~hotplug_mask;
1050 dev_priv->pch_irq_enable_reg = hotplug_mask;
1051
1052 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
1053 I915_WRITE(SDEIMR, dev_priv->pch_irq_mask_reg);
1054 I915_WRITE(SDEIER, dev_priv->pch_irq_enable_reg);
1055 (void) I915_READ(SDEIER);
1056
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001057 return 0;
1058}
1059
Dave Airlie84b1fd12007-07-11 15:53:27 +10001060void i915_driver_irq_preinstall(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
1062 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1063
Jesse Barnes79e53942008-11-07 14:24:08 -08001064 atomic_set(&dev_priv->irq_received, 0);
1065
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001066 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Jesse Barnes8a905232009-07-11 16:48:03 -04001067 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001068
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001069 if (IS_IRONLAKE(dev)) {
1070 ironlake_irq_preinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001071 return;
1072 }
1073
Jesse Barnes5ca58282009-03-31 14:11:15 -07001074 if (I915_HAS_HOTPLUG(dev)) {
1075 I915_WRITE(PORT_HOTPLUG_EN, 0);
1076 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1077 }
1078
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001079 I915_WRITE(HWSTAM, 0xeffe);
Keith Packard7c463582008-11-04 02:03:27 -08001080 I915_WRITE(PIPEASTAT, 0);
1081 I915_WRITE(PIPEBSTAT, 0);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001082 I915_WRITE(IMR, 0xffffffff);
Eric Anholted4cb412008-07-29 12:10:39 -07001083 I915_WRITE(IER, 0x0);
Keith Packard7c463582008-11-04 02:03:27 -08001084 (void) I915_READ(IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
1086
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001087/*
1088 * Must be called after intel_modeset_init or hotplug interrupts won't be
1089 * enabled correctly.
1090 */
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001091int i915_driver_irq_postinstall(struct drm_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092{
1093 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes5ca58282009-03-31 14:11:15 -07001094 u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR;
Jesse Barnes63eeaf32009-06-18 16:56:52 -07001095 u32 error_mask;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001096
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001097 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
1098
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001099 dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001100
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001101 if (IS_IRONLAKE(dev))
1102 return ironlake_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001103
Keith Packard7c463582008-11-04 02:03:27 -08001104 /* Unmask the interrupts that we always want on. */
1105 dev_priv->irq_mask_reg = ~I915_INTERRUPT_ENABLE_FIX;
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +01001106
Keith Packard7c463582008-11-04 02:03:27 -08001107 dev_priv->pipestat[0] = 0;
1108 dev_priv->pipestat[1] = 0;
1109
Jesse Barnes5ca58282009-03-31 14:11:15 -07001110 if (I915_HAS_HOTPLUG(dev)) {
1111 u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
1112
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001113 /* Note HDMI and DP share bits */
1114 if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
1115 hotplug_en |= HDMIB_HOTPLUG_INT_EN;
1116 if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
1117 hotplug_en |= HDMIC_HOTPLUG_INT_EN;
1118 if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
1119 hotplug_en |= HDMID_HOTPLUG_INT_EN;
1120 if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS)
1121 hotplug_en |= SDVOC_HOTPLUG_INT_EN;
1122 if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS)
1123 hotplug_en |= SDVOB_HOTPLUG_INT_EN;
1124 if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS)
1125 hotplug_en |= CRT_HOTPLUG_INT_EN;
1126 /* Ignore TV since it's buggy */
1127
Jesse Barnes5ca58282009-03-31 14:11:15 -07001128 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
1129
Jesse Barnes5ca58282009-03-31 14:11:15 -07001130 /* Enable in IER... */
1131 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
1132 /* and unmask in IMR */
1133 i915_enable_irq(dev_priv, I915_DISPLAY_PORT_INTERRUPT);
1134 }
1135
Jesse Barnes63eeaf32009-06-18 16:56:52 -07001136 /*
1137 * Enable some error detection, note the instruction error mask
1138 * bit is reserved, so we leave it masked.
1139 */
1140 if (IS_G4X(dev)) {
1141 error_mask = ~(GM45_ERROR_PAGE_TABLE |
1142 GM45_ERROR_MEM_PRIV |
1143 GM45_ERROR_CP_PRIV |
1144 I915_ERROR_MEMORY_REFRESH);
1145 } else {
1146 error_mask = ~(I915_ERROR_PAGE_TABLE |
1147 I915_ERROR_MEMORY_REFRESH);
1148 }
1149 I915_WRITE(EMR, error_mask);
1150
Keith Packard7c463582008-11-04 02:03:27 -08001151 /* Disable pipe interrupt enables, clear pending pipe status */
1152 I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff);
1153 I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff);
1154 /* Clear pending interrupt status */
1155 I915_WRITE(IIR, I915_READ(IIR));
1156
Jesse Barnes5ca58282009-03-31 14:11:15 -07001157 I915_WRITE(IER, enable_mask);
Keith Packard7c463582008-11-04 02:03:27 -08001158 I915_WRITE(IMR, dev_priv->irq_mask_reg);
Eric Anholted4cb412008-07-29 12:10:39 -07001159 (void) I915_READ(IER);
1160
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +01001161 opregion_enable_asle(dev);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001162
1163 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
1165
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001166static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001167{
1168 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1169 I915_WRITE(HWSTAM, 0xffffffff);
1170
1171 I915_WRITE(DEIMR, 0xffffffff);
1172 I915_WRITE(DEIER, 0x0);
1173 I915_WRITE(DEIIR, I915_READ(DEIIR));
1174
1175 I915_WRITE(GTIMR, 0xffffffff);
1176 I915_WRITE(GTIER, 0x0);
1177 I915_WRITE(GTIIR, I915_READ(GTIIR));
1178}
1179
Dave Airlie84b1fd12007-07-11 15:53:27 +10001180void i915_driver_irq_uninstall(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
1182 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlie91e37382006-02-18 15:17:04 +11001183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 if (!dev_priv)
1185 return;
1186
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001187 dev_priv->vblank_pipe = 0;
1188
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001189 if (IS_IRONLAKE(dev)) {
1190 ironlake_irq_uninstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001191 return;
1192 }
1193
Jesse Barnes5ca58282009-03-31 14:11:15 -07001194 if (I915_HAS_HOTPLUG(dev)) {
1195 I915_WRITE(PORT_HOTPLUG_EN, 0);
1196 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1197 }
1198
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001199 I915_WRITE(HWSTAM, 0xffffffff);
Keith Packard7c463582008-11-04 02:03:27 -08001200 I915_WRITE(PIPEASTAT, 0);
1201 I915_WRITE(PIPEBSTAT, 0);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001202 I915_WRITE(IMR, 0xffffffff);
Eric Anholted4cb412008-07-29 12:10:39 -07001203 I915_WRITE(IER, 0x0);
Dave Airlie91e37382006-02-18 15:17:04 +11001204
Keith Packard7c463582008-11-04 02:03:27 -08001205 I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff);
1206 I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff);
1207 I915_WRITE(IIR, I915_READ(IIR));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208}