2 * Copyright (C) 2006 Ben Skeggs.
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:
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.
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.
30 * Ben Skeggs <darktama@iinet.net.au>
35 #include "nouveau_drm.h"
36 #include "nouveau_drv.h"
37 #include "nouveau_reg.h"
38 #include "nouveau_ramht.h"
39 #include "nouveau_util.h"
42 nouveau_irq_preinstall(struct drm_device
*dev
)
44 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
47 nv_wr32(dev
, NV03_PMC_INTR_EN_0
, 0);
49 INIT_LIST_HEAD(&dev_priv
->vbl_waiting
);
53 nouveau_irq_postinstall(struct drm_device
*dev
)
55 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
58 nv_wr32(dev
, NV03_PMC_INTR_EN_0
, NV_PMC_INTR_EN_0_MASTER_ENABLE
);
59 if (dev_priv
->msi_enabled
)
60 nv_wr08(dev
, 0x00088068, 0xff);
66 nouveau_irq_uninstall(struct drm_device
*dev
)
69 nv_wr32(dev
, NV03_PMC_INTR_EN_0
, 0);
73 nouveau_irq_handler(DRM_IRQ_ARGS
)
75 struct drm_device
*dev
= (struct drm_device
*)arg
;
76 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
81 stat
= nv_rd32(dev
, NV03_PMC_INTR_0
);
85 spin_lock_irqsave(&dev_priv
->context_switch_lock
, flags
);
86 for (i
= 0; i
< 32 && stat
; i
++) {
87 if (!(stat
& (1 << i
)) || !dev_priv
->irq_handler
[i
])
90 dev_priv
->irq_handler
[i
](dev
);
94 if (dev_priv
->msi_enabled
)
95 nv_wr08(dev
, 0x00088068, 0xff);
96 spin_unlock_irqrestore(&dev_priv
->context_switch_lock
, flags
);
98 if (stat
&& nouveau_ratelimit())
99 NV_ERROR(dev
, "PMC - unhandled INTR 0x%08x\n", stat
);
104 nouveau_irq_init(struct drm_device
*dev
)
106 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
109 if (nouveau_msi
!= 0 && dev_priv
->card_type
>= NV_50
) {
110 ret
= pci_enable_msi(dev
->pdev
);
112 NV_INFO(dev
, "enabled MSI\n");
113 dev_priv
->msi_enabled
= true;
117 return drm_irq_install(dev
);
121 nouveau_irq_fini(struct drm_device
*dev
)
123 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
125 drm_irq_uninstall(dev
);
126 if (dev_priv
->msi_enabled
)
127 pci_disable_msi(dev
->pdev
);
131 nouveau_irq_register(struct drm_device
*dev
, int status_bit
,
132 void (*handler
)(struct drm_device
*))
134 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
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
);
143 nouveau_irq_unregister(struct drm_device
*dev
, int status_bit
)
145 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
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
);