Dave Airlie | 94bb598 | 2006-12-19 17:49:08 +1100 | [diff] [blame] | 1 | /* radeon_irq.c -- IRQ handling for radeon -*- linux-c -*- */ |
| 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 8 | * |
| 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: |
| 15 | * |
| 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 |
| 18 | * Software. |
| 19 | * |
| 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. |
| 27 | * |
| 28 | * Authors: |
| 29 | * Keith Whitwell <keith@tungstengraphics.com> |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 30 | * Michel D�zer <michel@daenzer.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include "drmP.h" |
| 34 | #include "drm.h" |
| 35 | #include "radeon_drm.h" |
| 36 | #include "radeon_drv.h" |
| 37 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 38 | void radeon_irq_set_state(struct drm_device *dev, u32 mask, int state) |
Dave Airlie | 6921e33 | 2005-06-26 21:05:59 +1000 | [diff] [blame] | 39 | { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 40 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 41 | |
| 42 | if (state) |
| 43 | dev_priv->irq_enable_reg |= mask; |
| 44 | else |
| 45 | dev_priv->irq_enable_reg &= ~mask; |
| 46 | |
Dave Airlie | 077ebed | 2008-12-22 17:11:02 +1000 | [diff] [blame] | 47 | if (dev->irq_enabled) |
Dave Airlie | fae7043 | 2008-12-09 15:30:50 +1000 | [diff] [blame] | 48 | RADEON_WRITE(RADEON_GEN_INT_CNTL, dev_priv->irq_enable_reg); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static void r500_vbl_irq_set_state(struct drm_device *dev, u32 mask, int state) |
| 52 | { |
| 53 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 54 | |
| 55 | if (state) |
| 56 | dev_priv->r500_disp_irq_reg |= mask; |
| 57 | else |
| 58 | dev_priv->r500_disp_irq_reg &= ~mask; |
| 59 | |
Dave Airlie | 077ebed | 2008-12-22 17:11:02 +1000 | [diff] [blame] | 60 | if (dev->irq_enabled) |
Dave Airlie | fae7043 | 2008-12-09 15:30:50 +1000 | [diff] [blame] | 61 | RADEON_WRITE(R500_DxMODE_INT_MASK, dev_priv->r500_disp_irq_reg); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | int radeon_enable_vblank(struct drm_device *dev, int crtc) |
| 65 | { |
| 66 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 67 | |
Alex Deucher | 800b699 | 2009-03-06 11:47:54 -0500 | [diff] [blame] | 68 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 69 | switch (crtc) { |
| 70 | case 0: |
| 71 | r500_vbl_irq_set_state(dev, R500_D1MODE_INT_MASK, 1); |
| 72 | break; |
| 73 | case 1: |
| 74 | r500_vbl_irq_set_state(dev, R500_D2MODE_INT_MASK, 1); |
| 75 | break; |
| 76 | default: |
| 77 | DRM_ERROR("tried to enable vblank on non-existent crtc %d\n", |
| 78 | crtc); |
Vasiliy Kulikov | 21e2eae | 2010-11-14 23:08:27 +0300 | [diff] [blame^] | 79 | return -EINVAL; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 80 | } |
| 81 | } else { |
| 82 | switch (crtc) { |
| 83 | case 0: |
| 84 | radeon_irq_set_state(dev, RADEON_CRTC_VBLANK_MASK, 1); |
| 85 | break; |
| 86 | case 1: |
| 87 | radeon_irq_set_state(dev, RADEON_CRTC2_VBLANK_MASK, 1); |
| 88 | break; |
| 89 | default: |
| 90 | DRM_ERROR("tried to enable vblank on non-existent crtc %d\n", |
| 91 | crtc); |
Vasiliy Kulikov | 21e2eae | 2010-11-14 23:08:27 +0300 | [diff] [blame^] | 92 | return -EINVAL; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | void radeon_disable_vblank(struct drm_device *dev, int crtc) |
| 100 | { |
| 101 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 102 | |
Alex Deucher | 800b699 | 2009-03-06 11:47:54 -0500 | [diff] [blame] | 103 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 104 | switch (crtc) { |
| 105 | case 0: |
| 106 | r500_vbl_irq_set_state(dev, R500_D1MODE_INT_MASK, 0); |
| 107 | break; |
| 108 | case 1: |
| 109 | r500_vbl_irq_set_state(dev, R500_D2MODE_INT_MASK, 0); |
| 110 | break; |
| 111 | default: |
| 112 | DRM_ERROR("tried to enable vblank on non-existent crtc %d\n", |
| 113 | crtc); |
| 114 | break; |
| 115 | } |
| 116 | } else { |
| 117 | switch (crtc) { |
| 118 | case 0: |
| 119 | radeon_irq_set_state(dev, RADEON_CRTC_VBLANK_MASK, 0); |
| 120 | break; |
| 121 | case 1: |
| 122 | radeon_irq_set_state(dev, RADEON_CRTC2_VBLANK_MASK, 0); |
| 123 | break; |
| 124 | default: |
| 125 | DRM_ERROR("tried to enable vblank on non-existent crtc %d\n", |
| 126 | crtc); |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | static inline u32 radeon_acknowledge_irqs(drm_radeon_private_t *dev_priv, u32 *r500_disp_int) |
| 133 | { |
| 134 | u32 irqs = RADEON_READ(RADEON_GEN_INT_STATUS); |
| 135 | u32 irq_mask = RADEON_SW_INT_TEST; |
| 136 | |
| 137 | *r500_disp_int = 0; |
Alex Deucher | 800b699 | 2009-03-06 11:47:54 -0500 | [diff] [blame] | 138 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 139 | /* vbl interrupts in a different place */ |
| 140 | |
| 141 | if (irqs & R500_DISPLAY_INT_STATUS) { |
| 142 | /* if a display interrupt */ |
| 143 | u32 disp_irq; |
| 144 | |
| 145 | disp_irq = RADEON_READ(R500_DISP_INTERRUPT_STATUS); |
| 146 | |
| 147 | *r500_disp_int = disp_irq; |
| 148 | if (disp_irq & R500_D1_VBLANK_INTERRUPT) |
| 149 | RADEON_WRITE(R500_D1MODE_VBLANK_STATUS, R500_VBLANK_ACK); |
| 150 | if (disp_irq & R500_D2_VBLANK_INTERRUPT) |
| 151 | RADEON_WRITE(R500_D2MODE_VBLANK_STATUS, R500_VBLANK_ACK); |
| 152 | } |
| 153 | irq_mask |= R500_DISPLAY_INT_STATUS; |
| 154 | } else |
| 155 | irq_mask |= RADEON_CRTC_VBLANK_STAT | RADEON_CRTC2_VBLANK_STAT; |
| 156 | |
| 157 | irqs &= irq_mask; |
| 158 | |
Dave Airlie | 6921e33 | 2005-06-26 21:05:59 +1000 | [diff] [blame] | 159 | if (irqs) |
| 160 | RADEON_WRITE(RADEON_GEN_INT_STATUS, irqs); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 161 | |
Dave Airlie | 6921e33 | 2005-06-26 21:05:59 +1000 | [diff] [blame] | 162 | return irqs; |
| 163 | } |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /* Interrupts - Used for device synchronization and flushing in the |
| 166 | * following circumstances: |
| 167 | * |
| 168 | * - Exclusive FB access with hw idle: |
| 169 | * - Wait for GUI Idle (?) interrupt, then do normal flush. |
| 170 | * |
| 171 | * - Frame throttling, NV_fence: |
| 172 | * - Drop marker irq's into command stream ahead of time. |
| 173 | * - Wait on irq's with lock *not held* |
| 174 | * - Check each for termination condition |
| 175 | * |
| 176 | * - Internally in cp_getbuffer, etc: |
| 177 | * - as above, but wait with lock held??? |
| 178 | * |
| 179 | * NOTE: These functions are misleadingly named -- the irq's aren't |
| 180 | * tied to dma at all, this is just a hangover from dri prehistory. |
| 181 | */ |
| 182 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 183 | irqreturn_t radeon_driver_irq_handler(DRM_IRQ_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 185 | struct drm_device *dev = (struct drm_device *) arg; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 186 | drm_radeon_private_t *dev_priv = |
| 187 | (drm_radeon_private_t *) dev->dev_private; |
| 188 | u32 stat; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 189 | u32 r500_disp_int; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Alex Deucher | b15591f | 2009-09-17 14:25:12 -0400 | [diff] [blame] | 191 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 192 | return IRQ_NONE; |
| 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | /* Only consider the bits we're interested in - others could be used |
| 195 | * outside the DRM |
| 196 | */ |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 197 | stat = radeon_acknowledge_irqs(dev_priv, &r500_disp_int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (!stat) |
| 199 | return IRQ_NONE; |
| 200 | |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 201 | stat &= dev_priv->irq_enable_reg; |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /* SW interrupt */ |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 204 | if (stat & RADEON_SW_INT_TEST) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 205 | DRM_WAKEUP(&dev_priv->swi_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | /* VBLANK interrupt */ |
Alex Deucher | 800b699 | 2009-03-06 11:47:54 -0500 | [diff] [blame] | 208 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 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); |
| 213 | } else { |
| 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); |
Dave Airlie | af6061a | 2008-05-07 12:15:39 +1000 | [diff] [blame] | 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return IRQ_HANDLED; |
| 220 | } |
| 221 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 222 | static int radeon_emit_irq(struct drm_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { |
| 224 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 225 | unsigned int ret; |
| 226 | RING_LOCALS; |
| 227 | |
| 228 | atomic_inc(&dev_priv->swi_emitted); |
| 229 | ret = atomic_read(&dev_priv->swi_emitted); |
| 230 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 231 | BEGIN_RING(4); |
| 232 | OUT_RING_REG(RADEON_LAST_SWI_REG, ret); |
| 233 | OUT_RING_REG(RADEON_GEN_INT_STATUS, RADEON_SW_INT_FIRE); |
| 234 | ADVANCE_RING(); |
| 235 | COMMIT_RING(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | return ret; |
| 238 | } |
| 239 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 240 | static int radeon_wait_irq(struct drm_device * dev, int swi_nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 242 | drm_radeon_private_t *dev_priv = |
| 243 | (drm_radeon_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | int ret = 0; |
| 245 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 246 | if (RADEON_READ(RADEON_LAST_SWI_REG) >= swi_nr) |
| 247 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; |
| 250 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 251 | DRM_WAIT_ON(ret, dev_priv->swi_queue, 3 * DRM_HZ, |
| 252 | RADEON_READ(RADEON_LAST_SWI_REG) >= swi_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | return ret; |
| 255 | } |
| 256 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 257 | u32 radeon_get_vblank_counter(struct drm_device *dev, int crtc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 259 | drm_radeon_private_t *dev_priv = dev->dev_private; |
| 260 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 261 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 262 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 263 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 266 | if (crtc < 0 || crtc > 1) { |
| 267 | DRM_ERROR("Invalid crtc %d\n", crtc); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 268 | return -EINVAL; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 269 | } |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 270 | |
Alex Deucher | 800b699 | 2009-03-06 11:47:54 -0500 | [diff] [blame] | 271 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 272 | if (crtc == 0) |
| 273 | return RADEON_READ(R500_D1CRTC_FRAME_COUNT); |
| 274 | else |
| 275 | return RADEON_READ(R500_D2CRTC_FRAME_COUNT); |
| 276 | } else { |
| 277 | if (crtc == 0) |
| 278 | return RADEON_READ(RADEON_CRTC_CRNT_FRAME); |
| 279 | else |
| 280 | return RADEON_READ(RADEON_CRTC2_CRNT_FRAME); |
| 281 | } |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 282 | } |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /* Needs the lock as it touches the ring. |
| 285 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 286 | int radeon_irq_emit(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 289 | drm_radeon_irq_emit_t *emit = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | int result; |
| 291 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 292 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 293 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 294 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Darren Jenkins | 65aa2f4 | 2009-12-30 12:16:35 +1100 | [diff] [blame] | 297 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 298 | return -EINVAL; |
| 299 | |
| 300 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
| 301 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 302 | result = radeon_emit_irq(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 304 | if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 305 | DRM_ERROR("copy_to_user\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 306 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | /* Doesn't need the hardware lock. |
| 313 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 314 | int radeon_irq_wait(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | drm_radeon_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 317 | drm_radeon_irq_wait_t *irqwait = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 319 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 320 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 321 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Alex Deucher | b15591f | 2009-09-17 14:25:12 -0400 | [diff] [blame] | 324 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 325 | return -EINVAL; |
| 326 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 327 | return radeon_wait_irq(dev, irqwait->irq_seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | /* drm_dma.h hooks |
| 331 | */ |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 332 | void radeon_driver_irq_preinstall(struct drm_device * dev) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 333 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | drm_radeon_private_t *dev_priv = |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 335 | (drm_radeon_private_t *) dev->dev_private; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 336 | u32 dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Alex Deucher | b15591f | 2009-09-17 14:25:12 -0400 | [diff] [blame] | 338 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 339 | return; |
| 340 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 341 | /* Disable *all* interrupts */ |
Alex Deucher | 800b699 | 2009-03-06 11:47:54 -0500 | [diff] [blame] | 342 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 343 | RADEON_WRITE(R500_DxMODE_INT_MASK, 0); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 344 | RADEON_WRITE(RADEON_GEN_INT_CNTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | /* Clear bits if they're already high */ |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 347 | radeon_acknowledge_irqs(dev_priv, &dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 350 | int radeon_driver_irq_postinstall(struct drm_device *dev) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 351 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | drm_radeon_private_t *dev_priv = |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 353 | (drm_radeon_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 355 | atomic_set(&dev_priv->swi_emitted, 0); |
| 356 | DRM_INIT_WAITQUEUE(&dev_priv->swi_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 358 | dev->max_vblank_count = 0x001fffff; |
| 359 | |
Alex Deucher | b15591f | 2009-09-17 14:25:12 -0400 | [diff] [blame] | 360 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 361 | return 0; |
| 362 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 363 | radeon_irq_set_state(dev, RADEON_SW_INT_ENABLE, 1); |
| 364 | |
| 365 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 368 | void radeon_driver_irq_uninstall(struct drm_device * dev) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 369 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | drm_radeon_private_t *dev_priv = |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 371 | (drm_radeon_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | if (!dev_priv) |
| 373 | return; |
| 374 | |
Alex Deucher | b15591f | 2009-09-17 14:25:12 -0400 | [diff] [blame] | 375 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_R600) |
| 376 | return; |
| 377 | |
Alex Deucher | 800b699 | 2009-03-06 11:47:54 -0500 | [diff] [blame] | 378 | if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RS600) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 379 | RADEON_WRITE(R500_DxMODE_INT_MASK, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | /* Disable *all* interrupts */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 381 | RADEON_WRITE(RADEON_GEN_INT_CNTL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 383 | |
| 384 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 385 | int radeon_vblank_crtc_get(struct drm_device *dev) |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 386 | { |
| 387 | drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private; |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 388 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 389 | return dev_priv->vblank_crtc; |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 390 | } |
| 391 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 392 | int radeon_vblank_crtc_set(struct drm_device *dev, int64_t value) |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 393 | { |
| 394 | drm_radeon_private_t *dev_priv = (drm_radeon_private_t *) dev->dev_private; |
| 395 | if (value & ~(DRM_RADEON_VBLANK_CRTC1 | DRM_RADEON_VBLANK_CRTC2)) { |
| 396 | DRM_ERROR("called with invalid crtc 0x%x\n", (unsigned int)value); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 397 | return -EINVAL; |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 398 | } |
| 399 | dev_priv->vblank_crtc = (unsigned int)value; |
Dave Airlie | ddbee33 | 2007-07-11 12:16:01 +1000 | [diff] [blame] | 400 | return 0; |
| 401 | } |