blob: 868c7fd74854dae082581177858a48fe847b1ff1 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright (C) 2006 Ben Skeggs.
3 *
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 */
27
28/*
29 * Authors:
30 * Ben Skeggs <darktama@iinet.net.au>
31 */
32
33#include "drmP.h"
34#include "drm.h"
35#include "nouveau_drm.h"
36#include "nouveau_drv.h"
37#include "nouveau_reg.h"
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100038#include "nouveau_ramht.h"
Ben Skeggsd7facf92010-11-03 10:06:43 +100039#include "nouveau_util.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100040
Ben Skeggs6ee73862009-12-11 19:24:15 +100041void
42nouveau_irq_preinstall(struct drm_device *dev)
43{
44 struct drm_nouveau_private *dev_priv = dev->dev_private;
45
46 /* Master disable */
47 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
48
Ben Skeggs19b7fc72010-11-03 10:27:27 +100049 INIT_LIST_HEAD(&dev_priv->vbl_waiting);
Ben Skeggs6ee73862009-12-11 19:24:15 +100050}
51
52int
53nouveau_irq_postinstall(struct drm_device *dev)
54{
Ben Skeggs35fa2f22010-10-21 14:07:03 +100055 struct drm_nouveau_private *dev_priv = dev->dev_private;
56
Ben Skeggs6ee73862009-12-11 19:24:15 +100057 /* Master enable */
58 nv_wr32(dev, NV03_PMC_INTR_EN_0, NV_PMC_INTR_EN_0_MASTER_ENABLE);
Ben Skeggs35fa2f22010-10-21 14:07:03 +100059 if (dev_priv->msi_enabled)
60 nv_wr08(dev, 0x00088068, 0xff);
61
Ben Skeggs6ee73862009-12-11 19:24:15 +100062 return 0;
63}
64
65void
66nouveau_irq_uninstall(struct drm_device *dev)
67{
68 /* Master disable */
69 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
70}
71
Ben Skeggs6ee73862009-12-11 19:24:15 +100072irqreturn_t
73nouveau_irq_handler(DRM_IRQ_ARGS)
74{
75 struct drm_device *dev = (struct drm_device *)arg;
76 struct drm_nouveau_private *dev_priv = dev->dev_private;
Maarten Maathuisff9e5272010-02-01 20:58:27 +010077 unsigned long flags;
Ben Skeggs274fec92010-11-03 13:16:18 +100078 u32 stat;
Ben Skeggs8f8a5442010-11-03 09:57:28 +100079 int i;
Ben Skeggs6ee73862009-12-11 19:24:15 +100080
Ben Skeggs274fec92010-11-03 13:16:18 +100081 stat = nv_rd32(dev, NV03_PMC_INTR_0);
Ben Skeggs9717f3d2011-07-12 15:42:45 +100082 if (stat == 0 || stat == ~0)
Ben Skeggs6ee73862009-12-11 19:24:15 +100083 return IRQ_NONE;
84
Maarten Maathuisff9e5272010-02-01 20:58:27 +010085 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
Ben Skeggs274fec92010-11-03 13:16:18 +100086 for (i = 0; i < 32 && stat; i++) {
87 if (!(stat & (1 << i)) || !dev_priv->irq_handler[i])
Ben Skeggs8f8a5442010-11-03 09:57:28 +100088 continue;
89
90 dev_priv->irq_handler[i](dev);
Ben Skeggs274fec92010-11-03 13:16:18 +100091 stat &= ~(1 << i);
Ben Skeggs8f8a5442010-11-03 09:57:28 +100092 }
93
Ben Skeggs35fa2f22010-10-21 14:07:03 +100094 if (dev_priv->msi_enabled)
95 nv_wr08(dev, 0x00088068, 0xff);
Ben Skeggs274fec92010-11-03 13:16:18 +100096 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
Ben Skeggs35fa2f22010-10-21 14:07:03 +100097
Ben Skeggs274fec92010-11-03 13:16:18 +100098 if (stat && nouveau_ratelimit())
99 NV_ERROR(dev, "PMC - unhandled INTR 0x%08x\n", stat);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000100 return IRQ_HANDLED;
101}
Ben Skeggs35fa2f22010-10-21 14:07:03 +1000102
103int
104nouveau_irq_init(struct drm_device *dev)
105{
106 struct drm_nouveau_private *dev_priv = dev->dev_private;
107 int ret;
108
109 if (nouveau_msi != 0 && dev_priv->card_type >= NV_50) {
110 ret = pci_enable_msi(dev->pdev);
111 if (ret == 0) {
112 NV_INFO(dev, "enabled MSI\n");
113 dev_priv->msi_enabled = true;
114 }
115 }
116
117 return drm_irq_install(dev);
118}
119
120void
121nouveau_irq_fini(struct drm_device *dev)
122{
123 struct drm_nouveau_private *dev_priv = dev->dev_private;
124
125 drm_irq_uninstall(dev);
126 if (dev_priv->msi_enabled)
127 pci_disable_msi(dev->pdev);
128}
Ben Skeggs8f8a5442010-11-03 09:57:28 +1000129
130void
131nouveau_irq_register(struct drm_device *dev, int status_bit,
132 void (*handler)(struct drm_device *))
133{
134 struct drm_nouveau_private *dev_priv = dev->dev_private;
135 unsigned long flags;
136
137 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
138 dev_priv->irq_handler[status_bit] = handler;
139 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
140}
141
142void
143nouveau_irq_unregister(struct drm_device *dev, int status_bit)
144{
145 struct drm_nouveau_private *dev_priv = dev->dev_private;
146 unsigned long flags;
147
148 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
149 dev_priv->irq_handler[status_bit] = NULL;
150 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
151}