Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1 | /* via_irq.c |
| 2 | * |
| 3 | * Copyright 2004 BEAM Ltd. |
| 4 | * Copyright 2002 Tungsten Graphics, Inc. |
| 5 | * Copyright 2005 Thomas Hellstrom. |
| 6 | * All Rights Reserved. |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the "Software"), |
| 10 | * to deal in the Software without restriction, including without limitation |
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 12 | * and/or sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice (including the next |
| 16 | * paragraph) shall be included in all copies or substantial portions of the |
| 17 | * Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BEAM LTD, TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 23 | * 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 | * Terry Barnaby <terry1@beam.ltd.uk> |
| 30 | * Keith Whitwell <keith@tungstengraphics.com> |
| 31 | * Thomas Hellstrom <unichrome@shipmail.org> |
| 32 | * |
| 33 | * This code provides standard DRM access to the Via Unichrome / Pro Vertical blank |
| 34 | * interrupt, as well as an infrastructure to handle other interrupts of the chip. |
| 35 | * The refresh rate is also calculated for video playback sync purposes. |
| 36 | */ |
| 37 | |
| 38 | #include "drmP.h" |
| 39 | #include "drm.h" |
| 40 | #include "via_drm.h" |
| 41 | #include "via_drv.h" |
| 42 | |
| 43 | #define VIA_REG_INTERRUPT 0x200 |
| 44 | |
| 45 | /* VIA_REG_INTERRUPT */ |
| 46 | #define VIA_IRQ_GLOBAL (1 << 31) |
| 47 | #define VIA_IRQ_VBLANK_ENABLE (1 << 19) |
| 48 | #define VIA_IRQ_VBLANK_PENDING (1 << 3) |
| 49 | #define VIA_IRQ_HQV0_ENABLE (1 << 11) |
| 50 | #define VIA_IRQ_HQV1_ENABLE (1 << 25) |
| 51 | #define VIA_IRQ_HQV0_PENDING (1 << 9) |
| 52 | #define VIA_IRQ_HQV1_PENDING (1 << 10) |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 53 | #define VIA_IRQ_DMA0_DD_ENABLE (1 << 20) |
| 54 | #define VIA_IRQ_DMA0_TD_ENABLE (1 << 21) |
| 55 | #define VIA_IRQ_DMA1_DD_ENABLE (1 << 22) |
| 56 | #define VIA_IRQ_DMA1_TD_ENABLE (1 << 23) |
| 57 | #define VIA_IRQ_DMA0_DD_PENDING (1 << 4) |
| 58 | #define VIA_IRQ_DMA0_TD_PENDING (1 << 5) |
| 59 | #define VIA_IRQ_DMA1_DD_PENDING (1 << 6) |
| 60 | #define VIA_IRQ_DMA1_TD_PENDING (1 << 7) |
| 61 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 62 | |
| 63 | /* |
| 64 | * Device-specific IRQs go here. This type might need to be extended with |
| 65 | * the register if there are multiple IRQ control registers. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 66 | * Currently we activate the HQV interrupts of Unichrome Pro group A. |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 67 | */ |
| 68 | |
| 69 | static maskarray_t via_pro_group_a_irqs[] = { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 70 | {VIA_IRQ_HQV0_ENABLE, VIA_IRQ_HQV0_PENDING, 0x000003D0, 0x00008010, |
| 71 | 0x00000000}, |
| 72 | {VIA_IRQ_HQV1_ENABLE, VIA_IRQ_HQV1_PENDING, 0x000013D0, 0x00008010, |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 73 | 0x00000000}, |
| 74 | {VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0, |
| 75 | VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008}, |
| 76 | {VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1, |
| 77 | VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008}, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 78 | }; |
| 79 | static int via_num_pro_group_a = |
| 80 | sizeof(via_pro_group_a_irqs) / sizeof(maskarray_t); |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 81 | static int via_irqmap_pro_group_a[] = {0, 1, -1, 2, -1, 3}; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 82 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 83 | static maskarray_t via_unichrome_irqs[] = { |
| 84 | {VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0, |
| 85 | VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008}, |
| 86 | {VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1, |
| 87 | VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008} |
| 88 | }; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 89 | static int via_num_unichrome = sizeof(via_unichrome_irqs) / sizeof(maskarray_t); |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 90 | static int via_irqmap_unichrome[] = {-1, -1, -1, 0, -1, 1}; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 91 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 92 | static unsigned time_diff(struct timeval *now, struct timeval *then) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 93 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 94 | return (now->tv_usec >= then->tv_usec) ? |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 95 | now->tv_usec - then->tv_usec : |
| 96 | 1000000 - (then->tv_usec - now->tv_usec); |
| 97 | } |
| 98 | |
| 99 | u32 via_get_vblank_counter(struct drm_device *dev, int crtc) |
| 100 | { |
| 101 | drm_via_private_t *dev_priv = dev->dev_private; |
| 102 | if (crtc != 0) |
| 103 | return 0; |
| 104 | |
| 105 | return atomic_read(&dev_priv->vbl_received); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS) |
| 109 | { |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 110 | struct drm_device *dev = (struct drm_device *) arg; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 111 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 112 | u32 status; |
| 113 | int handled = 0; |
| 114 | struct timeval cur_vblank; |
| 115 | drm_via_irq_t *cur_irq = dev_priv->via_irqs; |
| 116 | int i; |
| 117 | |
| 118 | status = VIA_READ(VIA_REG_INTERRUPT); |
| 119 | if (status & VIA_IRQ_VBLANK_PENDING) { |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 120 | atomic_inc(&dev_priv->vbl_received); |
| 121 | if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 122 | do_gettimeofday(&cur_vblank); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 123 | if (dev_priv->last_vblank_valid) { |
| 124 | dev_priv->usec_per_vblank = |
| 125 | time_diff(&cur_vblank, |
| 126 | &dev_priv->last_vblank) >> 4; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 127 | } |
| 128 | dev_priv->last_vblank = cur_vblank; |
| 129 | dev_priv->last_vblank_valid = 1; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 130 | } |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 131 | if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 132 | DRM_DEBUG("US per vblank is: %u\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 133 | dev_priv->usec_per_vblank); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 134 | } |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 135 | drm_handle_vblank(dev, 0); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 136 | handled = 1; |
| 137 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 138 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 139 | for (i = 0; i < dev_priv->num_irqs; ++i) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 140 | if (status & cur_irq->pending_mask) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 141 | atomic_inc(&cur_irq->irq_received); |
| 142 | DRM_WAKEUP(&cur_irq->irq_queue); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 143 | handled = 1; |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 144 | if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) { |
| 145 | via_dmablit_handler(dev, 0, 1); |
| 146 | } else if (dev_priv->irq_map[drm_via_irq_dma1_td] == i) { |
| 147 | via_dmablit_handler(dev, 1, 1); |
| 148 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 149 | } |
| 150 | cur_irq++; |
| 151 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 152 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 153 | /* Acknowlege interrupts */ |
| 154 | VIA_WRITE(VIA_REG_INTERRUPT, status); |
| 155 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 156 | if (handled) |
| 157 | return IRQ_HANDLED; |
| 158 | else |
| 159 | return IRQ_NONE; |
| 160 | } |
| 161 | |
| 162 | static __inline__ void viadrv_acknowledge_irqs(drm_via_private_t * dev_priv) |
| 163 | { |
| 164 | u32 status; |
| 165 | |
| 166 | if (dev_priv) { |
| 167 | /* Acknowlege interrupts */ |
| 168 | status = VIA_READ(VIA_REG_INTERRUPT); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 169 | VIA_WRITE(VIA_REG_INTERRUPT, status | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 170 | dev_priv->irq_pending_mask); |
| 171 | } |
| 172 | } |
| 173 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 174 | int via_enable_vblank(struct drm_device *dev, int crtc) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 175 | { |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 176 | drm_via_private_t *dev_priv = dev->dev_private; |
| 177 | u32 status; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 178 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 179 | if (crtc != 0) { |
| 180 | DRM_ERROR("%s: bad crtc %d\n", __FUNCTION__, crtc); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 181 | return -EINVAL; |
| 182 | } |
| 183 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 184 | status = VIA_READ(VIA_REG_INTERRUPT); |
| 185 | VIA_WRITE(VIA_REG_INTERRUPT, status & VIA_IRQ_VBLANK_ENABLE); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 186 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 187 | VIA_WRITE8(0x83d4, 0x11); |
| 188 | VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) | 0x30); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 189 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 190 | return 0; |
| 191 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 192 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 193 | void via_disable_vblank(struct drm_device *dev, int crtc) |
| 194 | { |
| 195 | drm_via_private_t *dev_priv = dev->dev_private; |
| 196 | |
| 197 | VIA_WRITE8(0x83d4, 0x11); |
| 198 | VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) & ~0x30); |
| 199 | |
| 200 | if (crtc != 0) |
| 201 | DRM_ERROR("%s: bad crtc %d\n", __FUNCTION__, crtc); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 202 | } |
| 203 | |
Dave Airlie | ce60fe0 | 2006-02-02 19:21:38 +1100 | [diff] [blame] | 204 | static int |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 205 | via_driver_irq_wait(struct drm_device * dev, unsigned int irq, int force_sequence, |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 206 | unsigned int *sequence) |
| 207 | { |
| 208 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 209 | unsigned int cur_irq_sequence; |
Jayachandran C | d253258 | 2006-04-10 23:18:28 -0700 | [diff] [blame] | 210 | drm_via_irq_t *cur_irq; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 211 | int ret = 0; |
Dave Airlie | 86678df | 2006-04-05 18:10:11 +1000 | [diff] [blame] | 212 | maskarray_t *masks; |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 213 | int real_irq; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 214 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 215 | DRM_DEBUG("\n"); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 216 | |
| 217 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 218 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 219 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 220 | } |
| 221 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 222 | if (irq >= drm_via_irq_num) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 223 | DRM_ERROR("Trying to wait on unknown irq %d\n", irq); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 224 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 225 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 226 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 227 | real_irq = dev_priv->irq_map[irq]; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 228 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 229 | if (real_irq < 0) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 230 | DRM_ERROR("Video IRQ %d not available on this hardware.\n", |
| 231 | irq); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 232 | return -EINVAL; |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 233 | } |
Dave Airlie | 86678df | 2006-04-05 18:10:11 +1000 | [diff] [blame] | 234 | |
| 235 | masks = dev_priv->irq_masks; |
Jayachandran C | d253258 | 2006-04-10 23:18:28 -0700 | [diff] [blame] | 236 | cur_irq = dev_priv->via_irqs + real_irq; |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 237 | |
| 238 | if (masks[real_irq][2] && !force_sequence) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 239 | DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 240 | ((VIA_READ(masks[irq][2]) & masks[irq][3]) == |
| 241 | masks[irq][4])); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 242 | cur_irq_sequence = atomic_read(&cur_irq->irq_received); |
| 243 | } else { |
| 244 | DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 245 | (((cur_irq_sequence = |
| 246 | atomic_read(&cur_irq->irq_received)) - |
| 247 | *sequence) <= (1 << 23))); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 248 | } |
| 249 | *sequence = cur_irq_sequence; |
| 250 | return ret; |
| 251 | } |
| 252 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 253 | /* |
| 254 | * drm_dma.h hooks |
| 255 | */ |
| 256 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 257 | void via_driver_irq_preinstall(struct drm_device * dev) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 258 | { |
| 259 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 260 | u32 status; |
Jayachandran C | d253258 | 2006-04-10 23:18:28 -0700 | [diff] [blame] | 261 | drm_via_irq_t *cur_irq; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 262 | int i; |
| 263 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 264 | DRM_DEBUG("dev_priv: %p\n", dev_priv); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 265 | if (dev_priv) { |
Jayachandran C | d253258 | 2006-04-10 23:18:28 -0700 | [diff] [blame] | 266 | cur_irq = dev_priv->via_irqs; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 267 | |
| 268 | dev_priv->irq_enable_mask = VIA_IRQ_VBLANK_ENABLE; |
| 269 | dev_priv->irq_pending_mask = VIA_IRQ_VBLANK_PENDING; |
| 270 | |
Thomas Hellstrom | 689692e | 2007-01-08 21:19:57 +1100 | [diff] [blame] | 271 | if (dev_priv->chipset == VIA_PRO_GROUP_A || |
| 272 | dev_priv->chipset == VIA_DX9_0) { |
| 273 | dev_priv->irq_masks = via_pro_group_a_irqs; |
| 274 | dev_priv->num_irqs = via_num_pro_group_a; |
| 275 | dev_priv->irq_map = via_irqmap_pro_group_a; |
| 276 | } else { |
| 277 | dev_priv->irq_masks = via_unichrome_irqs; |
| 278 | dev_priv->num_irqs = via_num_unichrome; |
| 279 | dev_priv->irq_map = via_irqmap_unichrome; |
| 280 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 281 | |
| 282 | for (i = 0; i < dev_priv->num_irqs; ++i) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 283 | atomic_set(&cur_irq->irq_received, 0); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 284 | cur_irq->enable_mask = dev_priv->irq_masks[i][0]; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 285 | cur_irq->pending_mask = dev_priv->irq_masks[i][1]; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 286 | DRM_INIT_WAITQUEUE(&cur_irq->irq_queue); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 287 | dev_priv->irq_enable_mask |= cur_irq->enable_mask; |
| 288 | dev_priv->irq_pending_mask |= cur_irq->pending_mask; |
| 289 | cur_irq++; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 290 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 291 | DRM_DEBUG("Initializing IRQ %d\n", i); |
| 292 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 293 | |
| 294 | dev_priv->last_vblank_valid = 0; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 295 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 296 | /* Clear VSync interrupt regs */ |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 297 | status = VIA_READ(VIA_REG_INTERRUPT); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 298 | VIA_WRITE(VIA_REG_INTERRUPT, status & |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 299 | ~(dev_priv->irq_enable_mask)); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 300 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 301 | /* Clear bits if they're already high */ |
| 302 | viadrv_acknowledge_irqs(dev_priv); |
| 303 | } |
| 304 | } |
| 305 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 306 | int via_driver_irq_postinstall(struct drm_device * dev) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 307 | { |
| 308 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 309 | u32 status; |
| 310 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 311 | DRM_DEBUG("via_driver_irq_postinstall\n"); |
| 312 | if (!dev_priv) |
| 313 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 314 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 315 | drm_vblank_init(dev, 1); |
| 316 | status = VIA_READ(VIA_REG_INTERRUPT); |
| 317 | VIA_WRITE(VIA_REG_INTERRUPT, status | VIA_IRQ_GLOBAL |
| 318 | | dev_priv->irq_enable_mask); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 319 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 320 | /* Some magic, oh for some data sheets ! */ |
| 321 | VIA_WRITE8(0x83d4, 0x11); |
| 322 | VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) | 0x30); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 323 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 324 | return 0; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 325 | } |
| 326 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 327 | void via_driver_irq_uninstall(struct drm_device * dev) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 328 | { |
| 329 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 330 | u32 status; |
| 331 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 332 | DRM_DEBUG("\n"); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 333 | if (dev_priv) { |
| 334 | |
| 335 | /* Some more magic, oh for some data sheets ! */ |
| 336 | |
| 337 | VIA_WRITE8(0x83d4, 0x11); |
| 338 | VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) & ~0x30); |
| 339 | |
| 340 | status = VIA_READ(VIA_REG_INTERRUPT); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 341 | VIA_WRITE(VIA_REG_INTERRUPT, status & |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 342 | ~(VIA_IRQ_VBLANK_ENABLE | dev_priv->irq_enable_mask)); |
| 343 | } |
| 344 | } |
| 345 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 346 | int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 347 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 348 | drm_via_irqwait_t *irqwait = data; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 349 | struct timeval now; |
| 350 | int ret = 0; |
| 351 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 352 | drm_via_irq_t *cur_irq = dev_priv->via_irqs; |
| 353 | int force_sequence; |
| 354 | |
| 355 | if (!dev->irq) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 356 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 357 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 358 | if (irqwait->request.irq >= dev_priv->num_irqs) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 359 | DRM_ERROR("Trying to wait on unknown irq %d\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 360 | irqwait->request.irq); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 361 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 362 | } |
| 363 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 364 | cur_irq += irqwait->request.irq; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 365 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 366 | switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 367 | case VIA_IRQ_RELATIVE: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 368 | irqwait->request.sequence += atomic_read(&cur_irq->irq_received); |
| 369 | irqwait->request.type &= ~_DRM_VBLANK_RELATIVE; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 370 | case VIA_IRQ_ABSOLUTE: |
| 371 | break; |
| 372 | default: |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 373 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 374 | } |
| 375 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 376 | if (irqwait->request.type & VIA_IRQ_SIGNAL) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 377 | DRM_ERROR("Signals on Via IRQs not implemented yet.\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 378 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 379 | } |
| 380 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 381 | force_sequence = (irqwait->request.type & VIA_IRQ_FORCE_SEQUENCE); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 382 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 383 | ret = via_driver_irq_wait(dev, irqwait->request.irq, force_sequence, |
| 384 | &irqwait->request.sequence); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 385 | do_gettimeofday(&now); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 386 | irqwait->reply.tval_sec = now.tv_sec; |
| 387 | irqwait->reply.tval_usec = now.tv_usec; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 388 | |
| 389 | return ret; |
| 390 | } |