1 commit 4f99970852559935b27bc634318f34c18c5fd143
2 Author: Eric Anholt <eric@anholt.net>
3 Date: Tue Jul 29 12:10:39 2008 -0700
5 i915: Add support for MSI and interrupt mitigation.
7 Previous attempts at interrupt mitigation had been foiled by i915_wait_irq's
8 failure to update the sarea seqno value when the status page indicated that
9 the seqno had already been passed. MSI support has been seen to cut CPU
10 costs by up to 40% in some workloads by avoiding other expensive interrupt
11 handlers for frequent graphics interrupts.
13 Signed-off-by: Eric Anholt <eric@anholt.net>
14 Signed-off-by: Dave Airlie <airlied@redhat.com>
16 diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
17 index 53f0e5a..61ed515 100644
18 --- a/drivers/gpu/drm/drm_irq.c
19 +++ b/drivers/gpu/drm/drm_irq.c
20 @@ -63,7 +63,7 @@ int drm_irq_by_busid(struct drm_device *dev, void *data,
21 p->devnum != PCI_SLOT(dev->pdev->devfn) || p->funcnum != PCI_FUNC(dev->pdev->devfn))
25 + p->irq = dev->pdev->irq;
27 DRM_DEBUG("%d:%d:%d => IRQ %d\n", p->busnum, p->devnum, p->funcnum,
29 @@ -89,7 +89,7 @@ static int drm_irq_install(struct drm_device * dev)
30 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
34 + if (dev->pdev->irq == 0)
37 mutex_lock(&dev->struct_mutex);
38 @@ -107,7 +107,7 @@ static int drm_irq_install(struct drm_device * dev)
40 mutex_unlock(&dev->struct_mutex);
42 - DRM_DEBUG("irq=%d\n", dev->irq);
43 + DRM_DEBUG("irq=%d\n", dev->pdev->irq);
45 if (drm_core_check_feature(dev, DRIVER_IRQ_VBL)) {
46 init_waitqueue_head(&dev->vbl_queue);
47 @@ -127,8 +127,12 @@ static int drm_irq_install(struct drm_device * dev)
48 if (drm_core_check_feature(dev, DRIVER_IRQ_SHARED))
49 sh_flags = IRQF_SHARED;
51 - ret = request_irq(dev->irq, dev->driver->irq_handler,
52 + ret = request_irq(dev->pdev->irq, dev->driver->irq_handler,
53 sh_flags, dev->devname, dev);
54 + /* Expose the device irq number to drivers that want to export it for
57 + dev->irq = dev->pdev->irq;
59 mutex_lock(&dev->struct_mutex);
61 @@ -164,11 +168,11 @@ int drm_irq_uninstall(struct drm_device * dev)
65 - DRM_DEBUG("irq=%d\n", dev->irq);
66 + DRM_DEBUG("irq=%d\n", dev->pdev->irq);
68 dev->driver->irq_uninstall(dev);
70 - free_irq(dev->irq, dev);
71 + free_irq(dev->pdev->irq, dev);
73 dev->locked_tasklet_func = NULL;
75 @@ -201,7 +205,7 @@ int drm_control(struct drm_device *dev, void *data,
76 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
78 if (dev->if_version < DRM_IF_VERSION(1, 2) &&
79 - ctl->irq != dev->irq)
80 + ctl->irq != dev->pdev->irq)
82 return drm_irq_install(dev);
83 case DRM_UNINST_HANDLER:
84 @@ -239,7 +243,7 @@ int drm_wait_vblank(struct drm_device *dev, void *data, struct drm_file *file_pr
86 unsigned int flags, seq;
88 - if ((!dev->irq) || (!dev->irq_enabled))
89 + if ((!dev->pdev->irq) || (!dev->irq_enabled))
92 if (vblwait->request.type &
93 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
94 index 7be580b..10bfb0c 100644
95 --- a/drivers/gpu/drm/i915/i915_dma.c
96 +++ b/drivers/gpu/drm/i915/i915_dma.c
97 @@ -84,7 +84,7 @@ static int i915_dma_cleanup(struct drm_device * dev)
98 * may not have been called from userspace and after dev_private
99 * is freed, it's too late.
102 + if (dev->irq_enabled)
103 drm_irq_uninstall(dev);
105 if (dev_priv->ring.virtual_start) {
106 @@ -644,7 +644,7 @@ static int i915_getparam(struct drm_device *dev, void *data,
108 switch (param->param) {
109 case I915_PARAM_IRQ_ACTIVE:
110 - value = dev->irq ? 1 : 0;
111 + value = dev->irq_enabled;
113 case I915_PARAM_ALLOW_BATCHBUFFER:
114 value = dev_priv->allow_batchbuffer ? 1 : 0;
115 @@ -763,6 +763,20 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
116 ret = drm_addmap(dev, base, size, _DRM_REGISTERS,
117 _DRM_KERNEL | _DRM_DRIVER,
118 &dev_priv->mmio_map);
121 + /* On the 945G/GM, the chipset reports the MSI capability on the
122 + * integrated graphics even though the support isn't actually there
123 + * according to the published specs. It doesn't appear to function
124 + * correctly in testing on 945G.
125 + * This may be a side effect of MSI having been made available for PEG
126 + * and the registers being closely associated.
128 + if (!IS_I945G(dev) && !IS_I945GM(dev))
129 + pci_enable_msi(dev->pdev);
131 + spin_lock_init(&dev_priv->user_irq_lock);
136 @@ -770,6 +784,9 @@ int i915_driver_unload(struct drm_device *dev)
138 struct drm_i915_private *dev_priv = dev->dev_private;
140 + if (dev->pdev->msi_enabled)
141 + pci_disable_msi(dev->pdev);
143 if (dev_priv->mmio_map)
144 drm_rmmap(dev, dev_priv->mmio_map);
146 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
147 index afb51a3..8daf0d8 100644
148 --- a/drivers/gpu/drm/i915/i915_drv.h
149 +++ b/drivers/gpu/drm/i915/i915_drv.h
150 @@ -105,6 +105,12 @@ typedef struct drm_i915_private {
151 wait_queue_head_t irq_queue;
152 atomic_t irq_received;
153 atomic_t irq_emitted;
154 + /** Protects user_irq_refcount and irq_mask_reg */
155 + spinlock_t user_irq_lock;
156 + /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
157 + int user_irq_refcount;
158 + /** Cached value of IMR to avoid reads in updating the bitfield */
161 int tex_lru_log_granularity;
162 int allow_batchbuffer;
163 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
164 index 4a2de78..24d11ed 100644
165 --- a/drivers/gpu/drm/i915/i915_irq.c
166 +++ b/drivers/gpu/drm/i915/i915_irq.c
169 #define MAX_NOPID ((u32)~0)
171 +/** These are the interrupts used by the driver */
172 +#define I915_INTERRUPT_ENABLE_MASK (I915_USER_INTERRUPT | \
173 + I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT | \
174 + I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT)
177 +i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask)
179 + if ((dev_priv->irq_mask_reg & mask) != 0) {
180 + dev_priv->irq_mask_reg &= ~mask;
181 + I915_WRITE(IMR, dev_priv->irq_mask_reg);
182 + (void) I915_READ(IMR);
187 +i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask)
189 + if ((dev_priv->irq_mask_reg & mask) != mask) {
190 + dev_priv->irq_mask_reg |= mask;
191 + I915_WRITE(IMR, dev_priv->irq_mask_reg);
192 + (void) I915_READ(IMR);
197 * Emit blits for scheduled buffer swaps.
199 @@ -229,46 +254,50 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
201 struct drm_device *dev = (struct drm_device *) arg;
202 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
204 u32 pipea_stats, pipeb_stats;
207 pipea_stats = I915_READ(PIPEASTAT);
208 pipeb_stats = I915_READ(PIPEBSTAT);
210 - temp = I915_READ16(IIR);
212 - temp &= (I915_USER_INTERRUPT |
213 - I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
214 - I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT);
215 + if (dev->pdev->msi_enabled)
216 + I915_WRITE(IMR, ~0);
217 + iir = I915_READ(IIR);
219 - DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
220 + DRM_DEBUG("iir=%08x\n", iir);
224 + if (dev->pdev->msi_enabled) {
225 + I915_WRITE(IMR, dev_priv->irq_mask_reg);
226 + (void) I915_READ(IMR);
231 - I915_WRITE16(IIR, temp);
232 - (void) I915_READ16(IIR);
233 - DRM_READMEMORYBARRIER();
234 + I915_WRITE(IIR, iir);
235 + if (dev->pdev->msi_enabled)
236 + I915_WRITE(IMR, dev_priv->irq_mask_reg);
237 + (void) I915_READ(IIR); /* Flush posted writes */
239 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
241 - if (temp & I915_USER_INTERRUPT)
242 + if (iir & I915_USER_INTERRUPT)
243 DRM_WAKEUP(&dev_priv->irq_queue);
245 - if (temp & (I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
246 - I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT)) {
247 + if (iir & (I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
248 + I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT)) {
249 int vblank_pipe = dev_priv->vblank_pipe;
252 (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B))
253 == (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B)) {
254 - if (temp & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT)
255 + if (iir & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT)
256 atomic_inc(&dev->vbl_received);
257 - if (temp & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT)
258 + if (iir & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT)
259 atomic_inc(&dev->vbl_received2);
260 - } else if (((temp & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT) &&
261 + } else if (((iir & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT) &&
262 (vblank_pipe & DRM_I915_VBLANK_PIPE_A)) ||
263 - ((temp & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT) &&
264 + ((iir & I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT) &&
265 (vblank_pipe & DRM_I915_VBLANK_PIPE_B)))
266 atomic_inc(&dev->vbl_received);
268 @@ -314,6 +343,27 @@ static int i915_emit_irq(struct drm_device * dev)
269 return dev_priv->counter;
272 +static void i915_user_irq_get(struct drm_device *dev)
274 + drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
276 + spin_lock(&dev_priv->user_irq_lock);
277 + if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1))
278 + i915_enable_irq(dev_priv, I915_USER_INTERRUPT);
279 + spin_unlock(&dev_priv->user_irq_lock);
282 +static void i915_user_irq_put(struct drm_device *dev)
284 + drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
286 + spin_lock(&dev_priv->user_irq_lock);
287 + BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0);
288 + if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0))
289 + i915_disable_irq(dev_priv, I915_USER_INTERRUPT);
290 + spin_unlock(&dev_priv->user_irq_lock);
293 static int i915_wait_irq(struct drm_device * dev, int irq_nr)
295 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
296 @@ -322,13 +372,17 @@ static int i915_wait_irq(struct drm_device * dev, int irq_nr)
297 DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
298 READ_BREADCRUMB(dev_priv));
300 - if (READ_BREADCRUMB(dev_priv) >= irq_nr)
301 + if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
302 + dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
306 dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
308 + i915_user_irq_get(dev);
309 DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
310 READ_BREADCRUMB(dev_priv) >= irq_nr);
311 + i915_user_irq_put(dev);
314 DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
315 @@ -413,20 +467,6 @@ int i915_irq_wait(struct drm_device *dev, void *data,
316 return i915_wait_irq(dev, irqwait->irq_seq);
319 -static void i915_enable_interrupt (struct drm_device *dev)
321 - drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
325 - if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A)
326 - flag |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
327 - if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
328 - flag |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
330 - I915_WRITE16(IER, I915_USER_INTERRUPT | flag);
333 /* Set the vblank monitor pipe
335 int i915_vblank_pipe_set(struct drm_device *dev, void *data,
336 @@ -434,6 +474,7 @@ int i915_vblank_pipe_set(struct drm_device *dev, void *data,
338 drm_i915_private_t *dev_priv = dev->dev_private;
339 drm_i915_vblank_pipe_t *pipe = data;
340 + u32 enable_mask = 0, disable_mask = 0;
343 DRM_ERROR("called with no initialization\n");
344 @@ -445,9 +486,20 @@ int i915_vblank_pipe_set(struct drm_device *dev, void *data,
348 - dev_priv->vblank_pipe = pipe->pipe;
349 + if (pipe->pipe & DRM_I915_VBLANK_PIPE_A)
350 + enable_mask |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
352 + disable_mask |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
354 + if (pipe->pipe & DRM_I915_VBLANK_PIPE_B)
355 + enable_mask |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
357 + disable_mask |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
359 - i915_enable_interrupt (dev);
360 + i915_enable_irq(dev_priv, enable_mask);
361 + i915_disable_irq(dev_priv, disable_mask);
363 + dev_priv->vblank_pipe = pipe->pipe;
367 @@ -464,7 +516,7 @@ int i915_vblank_pipe_get(struct drm_device *dev, void *data,
371 - flag = I915_READ(IER);
372 + flag = I915_READ(IMR);
374 if (flag & I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT)
375 pipe->pipe |= DRM_I915_VBLANK_PIPE_A;
376 @@ -586,9 +638,9 @@ void i915_driver_irq_preinstall(struct drm_device * dev)
378 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
380 - I915_WRITE16(HWSTAM, 0xfffe);
381 - I915_WRITE16(IMR, 0x0);
382 - I915_WRITE16(IER, 0x0);
383 + I915_WRITE(HWSTAM, 0xfffe);
384 + I915_WRITE(IMR, 0x0);
385 + I915_WRITE(IER, 0x0);
388 void i915_driver_irq_postinstall(struct drm_device * dev)
389 @@ -601,7 +653,18 @@ void i915_driver_irq_postinstall(struct drm_device * dev)
391 if (!dev_priv->vblank_pipe)
392 dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A;
393 - i915_enable_interrupt(dev);
395 + /* Set initial unmasked IRQs to just the selected vblank pipes. */
396 + dev_priv->irq_mask_reg = ~0;
397 + if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_A)
398 + dev_priv->irq_mask_reg &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
399 + if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
400 + dev_priv->irq_mask_reg &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
402 + I915_WRITE(IMR, dev_priv->irq_mask_reg);
403 + I915_WRITE(IER, I915_INTERRUPT_ENABLE_MASK);
404 + (void) I915_READ(IER);
406 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
409 @@ -613,10 +676,10 @@ void i915_driver_irq_uninstall(struct drm_device * dev)
413 - I915_WRITE16(HWSTAM, 0xffff);
414 - I915_WRITE16(IMR, 0xffff);
415 - I915_WRITE16(IER, 0x0);
416 + I915_WRITE(HWSTAM, 0xffff);
417 + I915_WRITE(IMR, 0xffff);
418 + I915_WRITE(IER, 0x0);
420 - temp = I915_READ16(IIR);
421 - I915_WRITE16(IIR, temp);
422 + temp = I915_READ(IIR);
423 + I915_WRITE(IIR, temp);