1 /* radeon_irq.c -- IRQ handling for radeon -*- linux-c -*- */
3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
5 * The Weather Channel (TM) funded Tungsten Graphics to develop the
6 * initial release of the Radeon 8500 driver under the XFree86 license.
7 * This notice must be preserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
29 * Keith Whitwell <keith@tungstengraphics.com>
30 * Michel D�zer <michel@daenzer.net>
33 #include "dev/drm/drmP.h"
34 #include "dev/drm/drm.h"
35 #include "dev/drm/radeon_drm.h"
36 #include "dev/drm/radeon_drv.h"
38 void radeon_irq_set_state(struct drm_device
*dev
, u32 mask
, int state
)
40 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
43 dev_priv
->irq_enable_reg
|= mask
;
45 dev_priv
->irq_enable_reg
&= ~mask
;
48 RADEON_WRITE(RADEON_GEN_INT_CNTL
, dev_priv
->irq_enable_reg
);
51 static void r500_vbl_irq_set_state(struct drm_device
*dev
, u32 mask
, int state
)
53 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
56 dev_priv
->r500_disp_irq_reg
|= mask
;
58 dev_priv
->r500_disp_irq_reg
&= ~mask
;
61 RADEON_WRITE(R500_DxMODE_INT_MASK
, dev_priv
->r500_disp_irq_reg
);
64 int radeon_enable_vblank(struct drm_device
*dev
, int crtc
)
66 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
68 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RS600
) {
71 r500_vbl_irq_set_state(dev
, R500_D1MODE_INT_MASK
, 1);
74 r500_vbl_irq_set_state(dev
, R500_D2MODE_INT_MASK
, 1);
77 DRM_ERROR("tried to enable vblank on non-existent crtc %d\n",
84 radeon_irq_set_state(dev
, RADEON_CRTC_VBLANK_MASK
, 1);
87 radeon_irq_set_state(dev
, RADEON_CRTC2_VBLANK_MASK
, 1);
90 DRM_ERROR("tried to enable vblank on non-existent crtc %d\n",
99 void radeon_disable_vblank(struct drm_device
*dev
, int crtc
)
101 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
103 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RS600
) {
106 r500_vbl_irq_set_state(dev
, R500_D1MODE_INT_MASK
, 0);
109 r500_vbl_irq_set_state(dev
, R500_D2MODE_INT_MASK
, 0);
112 DRM_ERROR("tried to enable vblank on non-existent crtc %d\n",
119 radeon_irq_set_state(dev
, RADEON_CRTC_VBLANK_MASK
, 0);
122 radeon_irq_set_state(dev
, RADEON_CRTC2_VBLANK_MASK
, 0);
125 DRM_ERROR("tried to enable vblank on non-existent crtc %d\n",
132 static __inline__ u32
radeon_acknowledge_irqs(drm_radeon_private_t
* dev_priv
, u32
*r500_disp_int
)
134 u32 irqs
= RADEON_READ(RADEON_GEN_INT_STATUS
);
135 u32 irq_mask
= RADEON_SW_INT_TEST
;
138 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RS600
) {
139 /* vbl interrupts in a different place */
141 if (irqs
& R500_DISPLAY_INT_STATUS
) {
142 /* if a display interrupt */
145 disp_irq
= RADEON_READ(R500_DISP_INTERRUPT_STATUS
);
147 *r500_disp_int
= disp_irq
;
148 if (disp_irq
& R500_D1_VBLANK_INTERRUPT
) {
149 RADEON_WRITE(R500_D1MODE_VBLANK_STATUS
, R500_VBLANK_ACK
);
151 if (disp_irq
& R500_D2_VBLANK_INTERRUPT
) {
152 RADEON_WRITE(R500_D2MODE_VBLANK_STATUS
, R500_VBLANK_ACK
);
155 irq_mask
|= R500_DISPLAY_INT_STATUS
;
157 irq_mask
|= RADEON_CRTC_VBLANK_STAT
| RADEON_CRTC2_VBLANK_STAT
;
162 RADEON_WRITE(RADEON_GEN_INT_STATUS
, irqs
);
167 /* Interrupts - Used for device synchronization and flushing in the
168 * following circumstances:
170 * - Exclusive FB access with hw idle:
171 * - Wait for GUI Idle (?) interrupt, then do normal flush.
173 * - Frame throttling, NV_fence:
174 * - Drop marker irq's into command stream ahead of time.
175 * - Wait on irq's with lock *not held*
176 * - Check each for termination condition
178 * - Internally in cp_getbuffer, etc:
179 * - as above, but wait with lock held???
181 * NOTE: These functions are misleadingly named -- the irq's aren't
182 * tied to dma at all, this is just a hangover from dri prehistory.
185 irqreturn_t
radeon_driver_irq_handler(DRM_IRQ_ARGS
)
187 struct drm_device
*dev
= (struct drm_device
*) arg
;
188 drm_radeon_private_t
*dev_priv
=
189 (drm_radeon_private_t
*) dev
->dev_private
;
194 /* Only consider the bits we're interested in - others could be used
197 stat
= radeon_acknowledge_irqs(dev_priv
, &r500_disp_int
);
201 stat
&= dev_priv
->irq_enable_reg
;
204 if (stat
& RADEON_SW_INT_TEST
)
205 DRM_WAKEUP(&dev_priv
->swi_queue
);
207 /* VBLANK interrupt */
208 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RS600
) {
209 if (r500_disp_int
& R500_D1_VBLANK_INTERRUPT
)
210 drm_handle_vblank(dev
, 0);
211 if (r500_disp_int
& R500_D2_VBLANK_INTERRUPT
)
212 drm_handle_vblank(dev
, 1);
214 if (stat
& RADEON_CRTC_VBLANK_STAT
)
215 drm_handle_vblank(dev
, 0);
216 if (stat
& RADEON_CRTC2_VBLANK_STAT
)
217 drm_handle_vblank(dev
, 1);
219 if (dev
->msi_enabled
) {
220 switch(dev_priv
->flags
& RADEON_FAMILY_MASK
) {
223 tmp
= RADEON_READ(RADEON_AIC_CNTL
) &
225 RADEON_WRITE(RADEON_AIC_CNTL
, tmp
);
226 RADEON_WRITE(RADEON_AIC_CNTL
,
227 tmp
| RS400_MSI_REARM
);
232 tmp
= RADEON_READ(RADEON_BUS_CNTL
) &
234 RADEON_WRITE(RADEON_BUS_CNTL
, tmp
);
235 RADEON_WRITE(RADEON_BUS_CNTL
, tmp
|
239 tmp
= RADEON_READ(RADEON_MSI_REARM_EN
) &
241 RADEON_WRITE(RADEON_MSI_REARM_EN
, tmp
);
242 RADEON_WRITE(RADEON_MSI_REARM_EN
,
243 tmp
| RV370_MSI_REARM_EN
);
250 static int radeon_emit_irq(struct drm_device
* dev
)
252 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
256 atomic_inc(&dev_priv
->swi_emitted
);
257 ret
= atomic_read(&dev_priv
->swi_emitted
);
260 OUT_RING_REG(RADEON_LAST_SWI_REG
, ret
);
261 OUT_RING_REG(RADEON_GEN_INT_STATUS
, RADEON_SW_INT_FIRE
);
268 static int radeon_wait_irq(struct drm_device
* dev
, int swi_nr
)
270 drm_radeon_private_t
*dev_priv
=
271 (drm_radeon_private_t
*) dev
->dev_private
;
274 if (RADEON_READ(RADEON_LAST_SWI_REG
) >= swi_nr
)
277 dev_priv
->stats
.boxes
|= RADEON_BOX_WAIT_IDLE
;
279 DRM_WAIT_ON(ret
, dev_priv
->swi_queue
, 3 * DRM_HZ
,
280 RADEON_READ(RADEON_LAST_SWI_REG
) >= swi_nr
);
282 if (ret
== -ERESTART
)
283 DRM_DEBUG("restarting syscall");
288 u32
radeon_get_vblank_counter(struct drm_device
*dev
, int crtc
)
290 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
293 DRM_ERROR("called with no initialization\n");
297 if (crtc
< 0 || crtc
> 1) {
298 DRM_ERROR("Invalid crtc %d\n", crtc
);
302 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RS600
) {
304 return RADEON_READ(R500_D1CRTC_FRAME_COUNT
);
306 return RADEON_READ(R500_D2CRTC_FRAME_COUNT
);
309 return RADEON_READ(RADEON_CRTC_CRNT_FRAME
);
311 return RADEON_READ(RADEON_CRTC2_CRNT_FRAME
);
315 /* Needs the lock as it touches the ring.
317 int radeon_irq_emit(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
319 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
320 drm_radeon_irq_emit_t
*emit
= data
;
323 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
326 DRM_ERROR("called with no initialization\n");
330 result
= radeon_emit_irq(dev
);
332 if (DRM_COPY_TO_USER(emit
->irq_seq
, &result
, sizeof(int))) {
333 DRM_ERROR("copy_to_user\n");
340 /* Doesn't need the hardware lock.
342 int radeon_irq_wait(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
344 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
345 drm_radeon_irq_wait_t
*irqwait
= data
;
348 DRM_ERROR("called with no initialization\n");
352 return radeon_wait_irq(dev
, irqwait
->irq_seq
);
357 void radeon_driver_irq_preinstall(struct drm_device
* dev
)
359 drm_radeon_private_t
*dev_priv
=
360 (drm_radeon_private_t
*) dev
->dev_private
;
363 /* Disable *all* interrupts */
364 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RS600
)
365 RADEON_WRITE(R500_DxMODE_INT_MASK
, 0);
366 RADEON_WRITE(RADEON_GEN_INT_CNTL
, 0);
368 /* Clear bits if they're already high */
369 radeon_acknowledge_irqs(dev_priv
, &dummy
);
372 int radeon_driver_irq_postinstall(struct drm_device
* dev
)
374 drm_radeon_private_t
*dev_priv
=
375 (drm_radeon_private_t
*) dev
->dev_private
;
377 atomic_set(&dev_priv
->swi_emitted
, 0);
378 DRM_INIT_WAITQUEUE(&dev_priv
->swi_queue
);
380 radeon_irq_set_state(dev
, RADEON_SW_INT_ENABLE
, 1);
385 void radeon_driver_irq_uninstall(struct drm_device
* dev
)
387 drm_radeon_private_t
*dev_priv
=
388 (drm_radeon_private_t
*) dev
->dev_private
;
392 dev_priv
->irq_enabled
= 0;
394 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RS600
)
395 RADEON_WRITE(R500_DxMODE_INT_MASK
, 0);
396 /* Disable *all* interrupts */
397 RADEON_WRITE(RADEON_GEN_INT_CNTL
, 0);
401 int radeon_vblank_crtc_get(struct drm_device
*dev
)
403 drm_radeon_private_t
*dev_priv
= (drm_radeon_private_t
*) dev
->dev_private
;
405 return dev_priv
->vblank_crtc
;
408 int radeon_vblank_crtc_set(struct drm_device
*dev
, int64_t value
)
410 drm_radeon_private_t
*dev_priv
= (drm_radeon_private_t
*) dev
->dev_private
;
411 if (value
& ~(DRM_RADEON_VBLANK_CRTC1
| DRM_RADEON_VBLANK_CRTC2
)) {
412 DRM_ERROR("called with invalid crtc 0x%x\n", (unsigned int)value
);
415 dev_priv
->vblank_crtc
= (unsigned int)value
;