blob: ae7d3a82a6d1279e726d603a3e739ce4e1e504b5 [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
29#include "drmP.h"
30#include "drm.h"
31#include "i915_drm.h"
32#include "i915_drv.h"
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#define MAX_NOPID ((u32)~0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Eric Anholted4cb412008-07-29 12:10:39 -070036/** These are the interrupts used by the driver */
37#define I915_INTERRUPT_ENABLE_MASK (I915_USER_INTERRUPT | \
38 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | \
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +010039 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT | \
40 I915_ASLE_INTERRUPT | \
41 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT)
Eric Anholted4cb412008-07-29 12:10:39 -070042
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +010043void
Eric Anholted4cb412008-07-29 12:10:39 -070044i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask)
45{
46 if ((dev_priv->irq_mask_reg & mask) != 0) {
47 dev_priv->irq_mask_reg &= ~mask;
48 I915_WRITE(IMR, dev_priv->irq_mask_reg);
49 (void) I915_READ(IMR);
50 }
51}
52
53static inline void
54i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask)
55{
56 if ((dev_priv->irq_mask_reg & mask) != mask) {
57 dev_priv->irq_mask_reg |= mask;
58 I915_WRITE(IMR, dev_priv->irq_mask_reg);
59 (void) I915_READ(IMR);
60 }
61}
62
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +100063/**
64 * Emit blits for scheduled buffer swaps.
65 *
66 * This function will be called with the HW lock held.
67 */
Dave Airlie84b1fd12007-07-11 15:53:27 +100068static void i915_vblank_tasklet(struct drm_device *dev)
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +100069{
70 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlieaf6061a2008-05-07 12:15:39 +100071 unsigned long irqflags;
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +110072 struct list_head *list, *tmp, hits, *hit;
Dave Airlieaf6061a2008-05-07 12:15:39 +100073 int nhits, nrects, slice[2], upper[2], lower[2], i;
74 unsigned counter[2] = { atomic_read(&dev->vbl_received),
75 atomic_read(&dev->vbl_received2) };
Dave Airliec60ce622007-07-11 15:27:12 +100076 struct drm_drawable_info *drw;
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +110077 drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv;
Dave Airlieaf6061a2008-05-07 12:15:39 +100078 u32 cpp = dev_priv->cpp;
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +110079 u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
80 XY_SRC_COPY_BLT_WRITE_ALPHA |
81 XY_SRC_COPY_BLT_WRITE_RGB)
82 : XY_SRC_COPY_BLT_CMD;
Keith Packard7b832b52008-04-21 16:31:10 +100083 u32 src_pitch = sarea_priv->pitch * cpp;
84 u32 dst_pitch = sarea_priv->pitch * cpp;
85 u32 ropcpp = (0xcc << 16) | ((cpp - 1) << 24);
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +110086 RING_LOCALS;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +100087
Jesse Barnes3d258022008-07-01 12:32:52 -070088 if (IS_I965G(dev) && sarea_priv->front_tiled) {
Keith Packard7b832b52008-04-21 16:31:10 +100089 cmd |= XY_SRC_COPY_BLT_DST_TILED;
90 dst_pitch >>= 2;
91 }
Jesse Barnes3d258022008-07-01 12:32:52 -070092 if (IS_I965G(dev) && sarea_priv->back_tiled) {
Keith Packard7b832b52008-04-21 16:31:10 +100093 cmd |= XY_SRC_COPY_BLT_SRC_TILED;
94 src_pitch >>= 2;
95 }
96
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +100097 DRM_DEBUG("\n");
98
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +110099 INIT_LIST_HEAD(&hits);
100
101 nhits = nrects = 0;
102
Dave Airlieaf6061a2008-05-07 12:15:39 +1000103 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000104
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100105 /* Find buffer swaps scheduled for this vertical blank */
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000106 list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
107 drm_i915_vbl_swap_t *vbl_swap =
108 list_entry(list, drm_i915_vbl_swap_t, head);
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000109
Dave Airlieaf6061a2008-05-07 12:15:39 +1000110 if ((counter[vbl_swap->pipe] - vbl_swap->sequence) > (1<<23))
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100111 continue;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000112
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100113 list_del(list);
114 dev_priv->swaps_pending--;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000115
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100116 spin_unlock(&dev_priv->swaps_lock);
117 spin_lock(&dev->drw_lock);
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000118
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100119 drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000120
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100121 if (!drw) {
122 spin_unlock(&dev->drw_lock);
123 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
124 spin_lock(&dev_priv->swaps_lock);
125 continue;
126 }
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000127
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100128 list_for_each(hit, &hits) {
129 drm_i915_vbl_swap_t *swap_cmp =
130 list_entry(hit, drm_i915_vbl_swap_t, head);
Dave Airliec60ce622007-07-11 15:27:12 +1000131 struct drm_drawable_info *drw_cmp =
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100132 drm_get_drawable_info(dev, swap_cmp->drw_id);
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000133
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100134 if (drw_cmp &&
135 drw_cmp->rects[0].y1 > drw->rects[0].y1) {
136 list_add_tail(list, hit);
137 break;
138 }
139 }
140
141 spin_unlock(&dev->drw_lock);
142
143 /* List of hits was empty, or we reached the end of it */
144 if (hit == &hits)
145 list_add_tail(list, hits.prev);
146
147 nhits++;
148
149 spin_lock(&dev_priv->swaps_lock);
150 }
151
Dave Airlieaf6061a2008-05-07 12:15:39 +1000152 if (nhits == 0) {
153 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
Jesse Barnesac741ab2008-04-22 16:03:07 +1000154 return;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000155 }
156
157 spin_unlock(&dev_priv->swaps_lock);
Jesse Barnesac741ab2008-04-22 16:03:07 +1000158
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100159 i915_kernel_lost_context(dev);
160
Dave Airlieaf6061a2008-05-07 12:15:39 +1000161 if (IS_I965G(dev)) {
162 BEGIN_LP_RING(4);
Jesse Barnesac741ab2008-04-22 16:03:07 +1000163
Dave Airlieaf6061a2008-05-07 12:15:39 +1000164 OUT_RING(GFX_OP_DRAWRECT_INFO_I965);
165 OUT_RING(0);
166 OUT_RING(((sarea_priv->width - 1) & 0xffff) | ((sarea_priv->height - 1) << 16));
167 OUT_RING(0);
168 ADVANCE_LP_RING();
169 } else {
170 BEGIN_LP_RING(6);
171
172 OUT_RING(GFX_OP_DRAWRECT_INFO);
173 OUT_RING(0);
174 OUT_RING(0);
175 OUT_RING(sarea_priv->width | sarea_priv->height << 16);
176 OUT_RING(sarea_priv->width | sarea_priv->height << 16);
177 OUT_RING(0);
178
179 ADVANCE_LP_RING();
180 }
181
182 sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
183
184 upper[0] = upper[1] = 0;
185 slice[0] = max(sarea_priv->pipeA_h / nhits, 1);
186 slice[1] = max(sarea_priv->pipeB_h / nhits, 1);
187 lower[0] = sarea_priv->pipeA_y + slice[0];
188 lower[1] = sarea_priv->pipeB_y + slice[0];
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100189
190 spin_lock(&dev->drw_lock);
191
192 /* Emit blits for buffer swaps, partitioning both outputs into as many
193 * slices as there are buffer swaps scheduled in order to avoid tearing
194 * (based on the assumption that a single buffer swap would always
195 * complete before scanout starts).
196 */
197 for (i = 0; i++ < nhits;
198 upper[0] = lower[0], lower[0] += slice[0],
199 upper[1] = lower[1], lower[1] += slice[1]) {
200 if (i == nhits)
201 lower[0] = lower[1] = sarea_priv->height;
202
203 list_for_each(hit, &hits) {
204 drm_i915_vbl_swap_t *swap_hit =
205 list_entry(hit, drm_i915_vbl_swap_t, head);
Dave Airliec60ce622007-07-11 15:27:12 +1000206 struct drm_clip_rect *rect;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000207 int num_rects, pipe;
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100208 unsigned short top, bottom;
209
210 drw = drm_get_drawable_info(dev, swap_hit->drw_id);
211
212 if (!drw)
213 continue;
214
215 rect = drw->rects;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000216 pipe = swap_hit->pipe;
217 top = upper[pipe];
218 bottom = lower[pipe];
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100219
220 for (num_rects = drw->num_rects; num_rects--; rect++) {
221 int y1 = max(rect->y1, top);
222 int y2 = min(rect->y2, bottom);
223
224 if (y1 >= y2)
225 continue;
226
227 BEGIN_LP_RING(8);
228
229 OUT_RING(cmd);
Keith Packard7b832b52008-04-21 16:31:10 +1000230 OUT_RING(ropcpp | dst_pitch);
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100231 OUT_RING((y1 << 16) | rect->x1);
232 OUT_RING((y2 << 16) | rect->x2);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000233 OUT_RING(sarea_priv->front_offset);
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100234 OUT_RING((y1 << 16) | rect->x1);
Keith Packard7b832b52008-04-21 16:31:10 +1000235 OUT_RING(src_pitch);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000236 OUT_RING(sarea_priv->back_offset);
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000237
238 ADVANCE_LP_RING();
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000239 }
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000240 }
241 }
242
Dave Airlieaf6061a2008-05-07 12:15:39 +1000243 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
=?utf-8?q?Michel_D=C3=A4nzer?=3188a242006-12-11 18:32:27 +1100244
245 list_for_each_safe(hit, tmp, &hits) {
246 drm_i915_vbl_swap_t *swap_hit =
247 list_entry(hit, drm_i915_vbl_swap_t, head);
248
249 list_del(hit);
250
251 drm_free(swap_hit, sizeof(*swap_hit), DRM_MEM_DRIVER);
252 }
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000253}
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
256{
Dave Airlie84b1fd12007-07-11 15:53:27 +1000257 struct drm_device *dev = (struct drm_device *) arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airliee4a7b1d2007-09-28 11:46:28 +1000259 u32 pipea_stats, pipeb_stats;
Eric Anholted4cb412008-07-29 12:10:39 -0700260 u32 iir;
Dave Airliee4a7b1d2007-09-28 11:46:28 +1000261
Jesse Barnes585fb112008-07-29 11:54:06 -0700262 pipea_stats = I915_READ(PIPEASTAT);
263 pipeb_stats = I915_READ(PIPEBSTAT);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000264
Eric Anholted4cb412008-07-29 12:10:39 -0700265 if (dev->pdev->msi_enabled)
266 I915_WRITE(IMR, ~0);
267 iir = I915_READ(IIR);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000268
Eric Anholted4cb412008-07-29 12:10:39 -0700269 DRM_DEBUG("iir=%08x\n", iir);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000270
Eric Anholted4cb412008-07-29 12:10:39 -0700271 if (iir == 0) {
272 if (dev->pdev->msi_enabled) {
273 I915_WRITE(IMR, dev_priv->irq_mask_reg);
274 (void) I915_READ(IMR);
275 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return IRQ_NONE;
Eric Anholted4cb412008-07-29 12:10:39 -0700277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +0100279 I915_WRITE(PIPEASTAT, pipea_stats);
280 I915_WRITE(PIPEBSTAT, pipeb_stats);
281
Eric Anholted4cb412008-07-29 12:10:39 -0700282 I915_WRITE(IIR, iir);
283 if (dev->pdev->msi_enabled)
284 I915_WRITE(IMR, dev_priv->irq_mask_reg);
285 (void) I915_READ(IIR); /* Flush posted writes */
Dave Airlie0d6aa602006-01-02 20:14:23 +1100286
Dave Airlieaf6061a2008-05-07 12:15:39 +1000287 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
Dave Airlie6e5fca52006-03-20 18:34:29 +1100288
Eric Anholted4cb412008-07-29 12:10:39 -0700289 if (iir & I915_USER_INTERRUPT)
Dave Airlie0d6aa602006-01-02 20:14:23 +1100290 DRM_WAKEUP(&dev_priv->irq_queue);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000291
Eric Anholted4cb412008-07-29 12:10:39 -0700292 if (iir & (I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
293 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT)) {
Dave Airlieaf6061a2008-05-07 12:15:39 +1000294 int vblank_pipe = dev_priv->vblank_pipe;
295
296 if ((vblank_pipe &
297 (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B))
298 == (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B)) {
Eric Anholted4cb412008-07-29 12:10:39 -0700299 if (iir & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT)
Dave Airlieaf6061a2008-05-07 12:15:39 +1000300 atomic_inc(&dev->vbl_received);
Eric Anholted4cb412008-07-29 12:10:39 -0700301 if (iir & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT)
Dave Airlieaf6061a2008-05-07 12:15:39 +1000302 atomic_inc(&dev->vbl_received2);
Eric Anholted4cb412008-07-29 12:10:39 -0700303 } else if (((iir & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT) &&
Dave Airlieaf6061a2008-05-07 12:15:39 +1000304 (vblank_pipe & DRM_I915_VBLANK_PIPE_A)) ||
Eric Anholted4cb412008-07-29 12:10:39 -0700305 ((iir & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT) &&
Dave Airlieaf6061a2008-05-07 12:15:39 +1000306 (vblank_pipe & DRM_I915_VBLANK_PIPE_B)))
307 atomic_inc(&dev->vbl_received);
308
309 DRM_WAKEUP(&dev->vbl_queue);
310 drm_vbl_send_signals(dev);
311
=?utf-8?q?Michel_D=C3=A4nzer?=2228ed62006-10-25 01:05:09 +1000312 if (dev_priv->swaps_pending > 0)
313 drm_locked_tasklet(dev, i915_vblank_tasklet);
Dave Airlie0d6aa602006-01-02 20:14:23 +1100314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +0100316 if (iir & I915_ASLE_INTERRUPT)
317 opregion_asle_intr(dev);
318
319 if (iir & I915_DISPLAY_PIPE_B_EVENT_INTERRUPT)
320 opregion_asle_intr(dev);
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 return IRQ_HANDLED;
323}
324
Dave Airlieaf6061a2008-05-07 12:15:39 +1000325static int i915_emit_irq(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
327 drm_i915_private_t *dev_priv = dev->dev_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 RING_LOCALS;
329
330 i915_kernel_lost_context(dev);
331
Márton Németh3e684ea2008-01-24 15:58:57 +1000332 DRM_DEBUG("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Alan Hourihanec29b6692006-08-12 16:29:24 +1000334 dev_priv->sarea_priv->last_enqueue = ++dev_priv->counter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Alan Hourihanec29b6692006-08-12 16:29:24 +1000336 if (dev_priv->counter > 0x7FFFFFFFUL)
337 dev_priv->sarea_priv->last_enqueue = dev_priv->counter = 1;
338
339 BEGIN_LP_RING(6);
Jesse Barnes585fb112008-07-29 11:54:06 -0700340 OUT_RING(MI_STORE_DWORD_INDEX);
341 OUT_RING(5 << MI_STORE_DWORD_INDEX_SHIFT);
Alan Hourihanec29b6692006-08-12 16:29:24 +1000342 OUT_RING(dev_priv->counter);
343 OUT_RING(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 OUT_RING(0);
Jesse Barnes585fb112008-07-29 11:54:06 -0700345 OUT_RING(MI_USER_INTERRUPT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 ADVANCE_LP_RING();
Dave Airliebc5f4522007-11-05 12:50:58 +1000347
Alan Hourihanec29b6692006-08-12 16:29:24 +1000348 return dev_priv->counter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Eric Anholted4cb412008-07-29 12:10:39 -0700351static void i915_user_irq_get(struct drm_device *dev)
352{
353 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
354
355 spin_lock(&dev_priv->user_irq_lock);
356 if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1))
357 i915_enable_irq(dev_priv, I915_USER_INTERRUPT);
358 spin_unlock(&dev_priv->user_irq_lock);
359}
360
361static void i915_user_irq_put(struct drm_device *dev)
362{
363 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
364
365 spin_lock(&dev_priv->user_irq_lock);
366 BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0);
367 if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0))
368 i915_disable_irq(dev_priv, I915_USER_INTERRUPT);
369 spin_unlock(&dev_priv->user_irq_lock);
370}
371
Dave Airlie84b1fd12007-07-11 15:53:27 +1000372static int i915_wait_irq(struct drm_device * dev, int irq_nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
375 int ret = 0;
376
Márton Németh3e684ea2008-01-24 15:58:57 +1000377 DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 READ_BREADCRUMB(dev_priv));
379
Eric Anholted4cb412008-07-29 12:10:39 -0700380 if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
381 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return 0;
Eric Anholted4cb412008-07-29 12:10:39 -0700383 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
386
Eric Anholted4cb412008-07-29 12:10:39 -0700387 i915_user_irq_get(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
389 READ_BREADCRUMB(dev_priv) >= irq_nr);
Eric Anholted4cb412008-07-29 12:10:39 -0700390 i915_user_irq_put(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Eric Anholt20caafa2007-08-25 19:22:43 +1000392 if (ret == -EBUSY) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000393 DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
395 }
396
Dave Airlieaf6061a2008-05-07 12:15:39 +1000397 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return ret;
399}
400
Dave Airlieaf6061a2008-05-07 12:15:39 +1000401static int i915_driver_vblank_do_wait(struct drm_device *dev, unsigned int *sequence,
402 atomic_t *counter)
403{
404 drm_i915_private_t *dev_priv = dev->dev_private;
405 unsigned int cur_vblank;
406 int ret = 0;
407
408 if (!dev_priv) {
409 DRM_ERROR("called with no initialization\n");
410 return -EINVAL;
411 }
412
413 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
414 (((cur_vblank = atomic_read(counter))
415 - *sequence) <= (1<<23)));
416
417 *sequence = cur_vblank;
418
419 return ret;
420}
421
422
423int i915_driver_vblank_wait(struct drm_device *dev, unsigned int *sequence)
424{
425 return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received);
426}
427
428int i915_driver_vblank_wait2(struct drm_device *dev, unsigned int *sequence)
429{
430 return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received2);
431}
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433/* Needs the lock as it touches the ring.
434 */
Eric Anholtc153f452007-09-03 12:06:45 +1000435int i915_irq_emit(struct drm_device *dev, void *data,
436 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000439 drm_i915_irq_emit_t *emit = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 int result;
441
Eric Anholt6c340ea2007-08-25 20:23:09 +1000442 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000445 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000446 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 result = i915_emit_irq(dev);
450
Eric Anholtc153f452007-09-03 12:06:45 +1000451 if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 DRM_ERROR("copy_to_user\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000453 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
456 return 0;
457}
458
459/* Doesn't need the hardware lock.
460 */
Eric Anholtc153f452007-09-03 12:06:45 +1000461int i915_irq_wait(struct drm_device *dev, void *data,
462 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000465 drm_i915_irq_wait_t *irqwait = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000468 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000469 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 }
471
Eric Anholtc153f452007-09-03 12:06:45 +1000472 return i915_wait_irq(dev, irqwait->irq_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
Dave Airlie702880f2006-06-24 17:07:34 +1000475/* Set the vblank monitor pipe
476 */
Eric Anholtc153f452007-09-03 12:06:45 +1000477int i915_vblank_pipe_set(struct drm_device *dev, void *data,
478 struct drm_file *file_priv)
Dave Airlie702880f2006-06-24 17:07:34 +1000479{
Dave Airlie702880f2006-06-24 17:07:34 +1000480 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000481 drm_i915_vblank_pipe_t *pipe = data;
Eric Anholted4cb412008-07-29 12:10:39 -0700482 u32 enable_mask = 0, disable_mask = 0;
Dave Airlie702880f2006-06-24 17:07:34 +1000483
484 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000485 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000486 return -EINVAL;
Dave Airlie702880f2006-06-24 17:07:34 +1000487 }
488
Eric Anholtc153f452007-09-03 12:06:45 +1000489 if (pipe->pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000490 DRM_ERROR("called with invalid pipe 0x%x\n", pipe->pipe);
Eric Anholt20caafa2007-08-25 19:22:43 +1000491 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=5b516942006-10-25 00:08:23 +1000492 }
493
Eric Anholted4cb412008-07-29 12:10:39 -0700494 if (pipe->pipe & DRM_I915_VBLANK_PIPE_A)
495 enable_mask |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
496 else
497 disable_mask |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
=?utf-8?q?Michel_D=C3=A4nzer?=5b516942006-10-25 00:08:23 +1000498
Eric Anholted4cb412008-07-29 12:10:39 -0700499 if (pipe->pipe & DRM_I915_VBLANK_PIPE_B)
500 enable_mask |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
501 else
502 disable_mask |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
503
504 i915_enable_irq(dev_priv, enable_mask);
505 i915_disable_irq(dev_priv, disable_mask);
506
507 dev_priv->vblank_pipe = pipe->pipe;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000508
=?utf-8?q?Michel_D=C3=A4nzer?=5b516942006-10-25 00:08:23 +1000509 return 0;
Dave Airlie702880f2006-06-24 17:07:34 +1000510}
511
Eric Anholtc153f452007-09-03 12:06:45 +1000512int i915_vblank_pipe_get(struct drm_device *dev, void *data,
513 struct drm_file *file_priv)
Dave Airlie702880f2006-06-24 17:07:34 +1000514{
Dave Airlie702880f2006-06-24 17:07:34 +1000515 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000516 drm_i915_vblank_pipe_t *pipe = data;
Dave Airlie702880f2006-06-24 17:07:34 +1000517 u16 flag;
518
519 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +1000520 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000521 return -EINVAL;
Dave Airlie702880f2006-06-24 17:07:34 +1000522 }
523
Eric Anholted4cb412008-07-29 12:10:39 -0700524 flag = I915_READ(IMR);
Eric Anholtc153f452007-09-03 12:06:45 +1000525 pipe->pipe = 0;
Jesse Barnes585fb112008-07-29 11:54:06 -0700526 if (flag & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT)
Eric Anholtc153f452007-09-03 12:06:45 +1000527 pipe->pipe |= DRM_I915_VBLANK_PIPE_A;
Jesse Barnes585fb112008-07-29 11:54:06 -0700528 if (flag & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT)
Eric Anholtc153f452007-09-03 12:06:45 +1000529 pipe->pipe |= DRM_I915_VBLANK_PIPE_B;
530
Dave Airlie702880f2006-06-24 17:07:34 +1000531 return 0;
532}
533
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000534/**
535 * Schedule buffer swap at given vertical blank.
536 */
Eric Anholtc153f452007-09-03 12:06:45 +1000537int i915_vblank_swap(struct drm_device *dev, void *data,
538 struct drm_file *file_priv)
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000539{
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000540 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +1000541 drm_i915_vblank_swap_t *swap = data;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000542 drm_i915_vbl_swap_t *vbl_swap;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000543 unsigned int pipe, seqtype, curseq;
=?utf-8?q?Michel_D=C3=A4nzer?=a0b136b2006-10-25 00:12:52 +1000544 unsigned long irqflags;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000545 struct list_head *list;
546
547 if (!dev_priv) {
548 DRM_ERROR("%s called with no initialization\n", __func__);
Eric Anholt20caafa2007-08-25 19:22:43 +1000549 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000550 }
551
Dave Airlieaf6061a2008-05-07 12:15:39 +1000552 if (dev_priv->sarea_priv->rotation) {
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000553 DRM_DEBUG("Rotation not supported\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000554 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000555 }
556
Eric Anholtc153f452007-09-03 12:06:45 +1000557 if (swap->seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE |
Dave Airlieaf6061a2008-05-07 12:15:39 +1000558 _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS)) {
Eric Anholtc153f452007-09-03 12:06:45 +1000559 DRM_ERROR("Invalid sequence type 0x%x\n", swap->seqtype);
Eric Anholt20caafa2007-08-25 19:22:43 +1000560 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=541f29a2006-10-24 23:38:54 +1000561 }
562
Dave Airlieaf6061a2008-05-07 12:15:39 +1000563 pipe = (swap->seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0;
=?utf-8?q?Michel_D=C3=A4nzer?=541f29a2006-10-24 23:38:54 +1000564
Eric Anholtc153f452007-09-03 12:06:45 +1000565 seqtype = swap->seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE);
=?utf-8?q?Michel_D=C3=A4nzer?=541f29a2006-10-24 23:38:54 +1000566
=?utf-8?q?Michel_D=C3=A4nzer?=541f29a2006-10-24 23:38:54 +1000567 if (!(dev_priv->vblank_pipe & (1 << pipe))) {
568 DRM_ERROR("Invalid pipe %d\n", pipe);
Eric Anholt20caafa2007-08-25 19:22:43 +1000569 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000570 }
571
572 spin_lock_irqsave(&dev->drw_lock, irqflags);
573
Eric Anholtc153f452007-09-03 12:06:45 +1000574 if (!drm_get_drawable_info(dev, swap->drawable)) {
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000575 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
Eric Anholtc153f452007-09-03 12:06:45 +1000576 DRM_DEBUG("Invalid drawable ID %d\n", swap->drawable);
Eric Anholt20caafa2007-08-25 19:22:43 +1000577 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000578 }
579
580 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
581
Dave Airlieaf6061a2008-05-07 12:15:39 +1000582 curseq = atomic_read(pipe ? &dev->vbl_received2 : &dev->vbl_received);
=?utf-8?q?Michel_D=C3=A4nzer?=541f29a2006-10-24 23:38:54 +1000583
=?utf-8?q?Michel_D=C3=A4nzer?=2228ed62006-10-25 01:05:09 +1000584 if (seqtype == _DRM_VBLANK_RELATIVE)
Eric Anholtc153f452007-09-03 12:06:45 +1000585 swap->sequence += curseq;
=?utf-8?q?Michel_D=C3=A4nzer?=2228ed62006-10-25 01:05:09 +1000586
Eric Anholtc153f452007-09-03 12:06:45 +1000587 if ((curseq - swap->sequence) <= (1<<23)) {
588 if (swap->seqtype & _DRM_VBLANK_NEXTONMISS) {
589 swap->sequence = curseq + 1;
=?utf-8?q?Michel_D=C3=A4nzer?=2228ed62006-10-25 01:05:09 +1000590 } else {
=?utf-8?q?Michel_D=C3=A4nzer?=541f29a2006-10-24 23:38:54 +1000591 DRM_DEBUG("Missed target sequence\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000592 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=541f29a2006-10-24 23:38:54 +1000593 }
=?utf-8?q?Michel_D=C3=A4nzer?=541f29a2006-10-24 23:38:54 +1000594 }
595
=?utf-8?q?Michel_D=C3=A4nzer?=2228ed62006-10-25 01:05:09 +1000596 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
597
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000598 list_for_each(list, &dev_priv->vbl_swaps.head) {
599 vbl_swap = list_entry(list, drm_i915_vbl_swap_t, head);
600
Eric Anholtc153f452007-09-03 12:06:45 +1000601 if (vbl_swap->drw_id == swap->drawable &&
Dave Airlieaf6061a2008-05-07 12:15:39 +1000602 vbl_swap->pipe == pipe &&
Eric Anholtc153f452007-09-03 12:06:45 +1000603 vbl_swap->sequence == swap->sequence) {
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000604 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
605 DRM_DEBUG("Already scheduled\n");
606 return 0;
607 }
608 }
609
610 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
611
=?utf-8?q?Michel_D=C3=A4nzer?=21fa60e2006-10-25 00:10:59 +1000612 if (dev_priv->swaps_pending >= 100) {
613 DRM_DEBUG("Too many swaps queued\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000614 return -EBUSY;
=?utf-8?q?Michel_D=C3=A4nzer?=21fa60e2006-10-25 00:10:59 +1000615 }
616
Dave Airlie54583bf2007-10-14 21:21:30 +1000617 vbl_swap = drm_calloc(1, sizeof(*vbl_swap), DRM_MEM_DRIVER);
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000618
619 if (!vbl_swap) {
620 DRM_ERROR("Failed to allocate memory to queue swap\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000621 return -ENOMEM;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000622 }
623
624 DRM_DEBUG("\n");
625
Eric Anholtc153f452007-09-03 12:06:45 +1000626 vbl_swap->drw_id = swap->drawable;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000627 vbl_swap->pipe = pipe;
Eric Anholtc153f452007-09-03 12:06:45 +1000628 vbl_swap->sequence = swap->sequence;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000629
630 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
631
Li Zefand5b0d1b2007-12-17 09:47:19 +1000632 list_add_tail(&vbl_swap->head, &dev_priv->vbl_swaps.head);
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000633 dev_priv->swaps_pending++;
634
635 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
636
637 return 0;
638}
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640/* drm_dma.h hooks
641*/
Dave Airlie84b1fd12007-07-11 15:53:27 +1000642void i915_driver_irq_preinstall(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
644 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
645
Eric Anholted4cb412008-07-29 12:10:39 -0700646 I915_WRITE(HWSTAM, 0xfffe);
647 I915_WRITE(IMR, 0x0);
648 I915_WRITE(IER, 0x0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649}
650
Dave Airlieaf6061a2008-05-07 12:15:39 +1000651void i915_driver_irq_postinstall(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
653 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
654
Thomas Gleixnera6399bd2007-05-26 05:56:14 +1000655 spin_lock_init(&dev_priv->swaps_lock);
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000656 INIT_LIST_HEAD(&dev_priv->vbl_swaps.head);
657 dev_priv->swaps_pending = 0;
658
Dave Airlieaf6061a2008-05-07 12:15:39 +1000659 if (!dev_priv->vblank_pipe)
660 dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A;
Eric Anholted4cb412008-07-29 12:10:39 -0700661
662 /* Set initial unmasked IRQs to just the selected vblank pipes. */
663 dev_priv->irq_mask_reg = ~0;
664 if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A)
665 dev_priv->irq_mask_reg &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
666 if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
667 dev_priv->irq_mask_reg &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
668
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +0100669 dev_priv->irq_mask_reg &= I915_INTERRUPT_ENABLE_MASK;
670
Eric Anholted4cb412008-07-29 12:10:39 -0700671 I915_WRITE(IMR, dev_priv->irq_mask_reg);
672 I915_WRITE(IER, I915_INTERRUPT_ENABLE_MASK);
673 (void) I915_READ(IER);
674
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +0100675 opregion_enable_asle(dev);
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
678}
679
Dave Airlie84b1fd12007-07-11 15:53:27 +1000680void i915_driver_irq_uninstall(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
682 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlieaf6061a2008-05-07 12:15:39 +1000683 u16 temp;
Dave Airlie91e37382006-02-18 15:17:04 +1100684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 if (!dev_priv)
686 return;
687
Eric Anholted4cb412008-07-29 12:10:39 -0700688 I915_WRITE(HWSTAM, 0xffff);
689 I915_WRITE(IMR, 0xffff);
690 I915_WRITE(IER, 0x0);
Dave Airlie91e37382006-02-18 15:17:04 +1100691
Eric Anholted4cb412008-07-29 12:10:39 -0700692 temp = I915_READ(IIR);
693 I915_WRITE(IIR, temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}