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 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 38 | #include <drm/drmP.h> |
| 39 | #include <drm/via_drm.h> |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 40 | #include "via_drv.h" |
| 41 | |
| 42 | #define VIA_REG_INTERRUPT 0x200 |
| 43 | |
| 44 | /* VIA_REG_INTERRUPT */ |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 45 | #define VIA_IRQ_GLOBAL (1 << 31) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 46 | #define VIA_IRQ_VBLANK_ENABLE (1 << 19) |
| 47 | #define VIA_IRQ_VBLANK_PENDING (1 << 3) |
| 48 | #define VIA_IRQ_HQV0_ENABLE (1 << 11) |
| 49 | #define VIA_IRQ_HQV1_ENABLE (1 << 25) |
| 50 | #define VIA_IRQ_HQV0_PENDING (1 << 9) |
| 51 | #define VIA_IRQ_HQV1_PENDING (1 << 10) |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 52 | #define VIA_IRQ_DMA0_DD_ENABLE (1 << 20) |
| 53 | #define VIA_IRQ_DMA0_TD_ENABLE (1 << 21) |
| 54 | #define VIA_IRQ_DMA1_DD_ENABLE (1 << 22) |
| 55 | #define VIA_IRQ_DMA1_TD_ENABLE (1 << 23) |
| 56 | #define VIA_IRQ_DMA0_DD_PENDING (1 << 4) |
| 57 | #define VIA_IRQ_DMA0_TD_PENDING (1 << 5) |
| 58 | #define VIA_IRQ_DMA1_DD_PENDING (1 << 6) |
| 59 | #define VIA_IRQ_DMA1_TD_PENDING (1 << 7) |
| 60 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * Device-specific IRQs go here. This type might need to be extended with |
| 64 | * the register if there are multiple IRQ control registers. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 65 | * Currently we activate the HQV interrupts of Unichrome Pro group A. |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 66 | */ |
| 67 | |
| 68 | static maskarray_t via_pro_group_a_irqs[] = { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 69 | {VIA_IRQ_HQV0_ENABLE, VIA_IRQ_HQV0_PENDING, 0x000003D0, 0x00008010, |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 70 | 0x00000000 }, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 71 | {VIA_IRQ_HQV1_ENABLE, VIA_IRQ_HQV1_PENDING, 0x000013D0, 0x00008010, |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 72 | 0x00000000 }, |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 73 | {VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0, |
| 74 | VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008}, |
| 75 | {VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1, |
| 76 | VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008}, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 77 | }; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 78 | static int via_num_pro_group_a = ARRAY_SIZE(via_pro_group_a_irqs); |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 79 | 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] | 80 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 81 | static maskarray_t via_unichrome_irqs[] = { |
| 82 | {VIA_IRQ_DMA0_TD_ENABLE, VIA_IRQ_DMA0_TD_PENDING, VIA_PCI_DMA_CSR0, |
| 83 | VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008}, |
| 84 | {VIA_IRQ_DMA1_TD_ENABLE, VIA_IRQ_DMA1_TD_PENDING, VIA_PCI_DMA_CSR1, |
| 85 | VIA_DMA_CSR_TA | VIA_DMA_CSR_TD, 0x00000008} |
| 86 | }; |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 87 | static int via_num_unichrome = ARRAY_SIZE(via_unichrome_irqs); |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 88 | static int via_irqmap_unichrome[] = {-1, -1, -1, 0, -1, 1}; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 89 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 90 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 91 | u32 via_get_vblank_counter(struct drm_device *dev, unsigned int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 92 | { |
| 93 | drm_via_private_t *dev_priv = dev->dev_private; |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 94 | |
| 95 | if (pipe != 0) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 96 | return 0; |
| 97 | |
| 98 | return atomic_read(&dev_priv->vbl_received); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 99 | } |
| 100 | |
Daniel Vetter | e9f0d76 | 2013-12-11 11:34:42 +0100 | [diff] [blame] | 101 | irqreturn_t via_driver_irq_handler(int irq, void *arg) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 102 | { |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 103 | struct drm_device *dev = (struct drm_device *) arg; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 104 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 105 | u32 status; |
| 106 | int handled = 0; |
Arnd Bergmann | de7e8bd | 2017-11-04 22:20:08 +0100 | [diff] [blame] | 107 | ktime_t cur_vblank; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 108 | drm_via_irq_t *cur_irq = dev_priv->via_irqs; |
| 109 | int i; |
| 110 | |
| 111 | status = VIA_READ(VIA_REG_INTERRUPT); |
| 112 | if (status & VIA_IRQ_VBLANK_PENDING) { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 113 | atomic_inc(&dev_priv->vbl_received); |
| 114 | if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) { |
Arnd Bergmann | de7e8bd | 2017-11-04 22:20:08 +0100 | [diff] [blame] | 115 | cur_vblank = ktime_get(); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 116 | if (dev_priv->last_vblank_valid) { |
Arnd Bergmann | de7e8bd | 2017-11-04 22:20:08 +0100 | [diff] [blame] | 117 | dev_priv->nsec_per_vblank = |
| 118 | ktime_sub(cur_vblank, |
| 119 | dev_priv->last_vblank) >> 4; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 120 | } |
| 121 | dev_priv->last_vblank = cur_vblank; |
| 122 | dev_priv->last_vblank_valid = 1; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 123 | } |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 124 | if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) { |
Arnd Bergmann | de7e8bd | 2017-11-04 22:20:08 +0100 | [diff] [blame] | 125 | DRM_DEBUG("nsec per vblank is: %llu\n", |
| 126 | ktime_to_ns(dev_priv->nsec_per_vblank)); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 127 | } |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 128 | drm_handle_vblank(dev, 0); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 129 | handled = 1; |
| 130 | } |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 131 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 132 | for (i = 0; i < dev_priv->num_irqs; ++i) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 133 | if (status & cur_irq->pending_mask) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 134 | atomic_inc(&cur_irq->irq_received); |
Daniel Vetter | 57ed0f7 | 2013-12-11 11:34:43 +0100 | [diff] [blame] | 135 | wake_up(&cur_irq->irq_queue); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 136 | handled = 1; |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 137 | if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 138 | via_dmablit_handler(dev, 0, 1); |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 139 | else if (dev_priv->irq_map[drm_via_irq_dma1_td] == i) |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 140 | via_dmablit_handler(dev, 1, 1); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 141 | } |
| 142 | cur_irq++; |
| 143 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 144 | |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 145 | /* Acknowledge interrupts */ |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 146 | VIA_WRITE(VIA_REG_INTERRUPT, status); |
| 147 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 148 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 149 | if (handled) |
| 150 | return IRQ_HANDLED; |
| 151 | else |
| 152 | return IRQ_NONE; |
| 153 | } |
| 154 | |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 155 | static __inline__ void viadrv_acknowledge_irqs(drm_via_private_t *dev_priv) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 156 | { |
| 157 | u32 status; |
| 158 | |
| 159 | if (dev_priv) { |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 160 | /* Acknowledge interrupts */ |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 161 | status = VIA_READ(VIA_REG_INTERRUPT); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 162 | VIA_WRITE(VIA_REG_INTERRUPT, status | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 163 | dev_priv->irq_pending_mask); |
| 164 | } |
| 165 | } |
| 166 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 167 | int via_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 168 | { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 169 | drm_via_private_t *dev_priv = dev->dev_private; |
| 170 | u32 status; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 171 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 172 | if (pipe != 0) { |
| 173 | DRM_ERROR("%s: bad crtc %u\n", __func__, pipe); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 174 | return -EINVAL; |
| 175 | } |
| 176 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 177 | status = VIA_READ(VIA_REG_INTERRUPT); |
Simon Farnsworth | 42dd861 | 2009-07-10 11:25:16 +0100 | [diff] [blame] | 178 | VIA_WRITE(VIA_REG_INTERRUPT, status | VIA_IRQ_VBLANK_ENABLE); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 179 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 180 | VIA_WRITE8(0x83d4, 0x11); |
| 181 | VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) | 0x30); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 182 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 183 | return 0; |
| 184 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 185 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 186 | void via_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 187 | { |
| 188 | drm_via_private_t *dev_priv = dev->dev_private; |
Simon Farnsworth | 42dd861 | 2009-07-10 11:25:16 +0100 | [diff] [blame] | 189 | u32 status; |
| 190 | |
| 191 | status = VIA_READ(VIA_REG_INTERRUPT); |
| 192 | VIA_WRITE(VIA_REG_INTERRUPT, status & ~VIA_IRQ_VBLANK_ENABLE); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 193 | |
| 194 | VIA_WRITE8(0x83d4, 0x11); |
| 195 | VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) & ~0x30); |
| 196 | |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 197 | if (pipe != 0) |
| 198 | DRM_ERROR("%s: bad crtc %u\n", __func__, pipe); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 199 | } |
| 200 | |
Dave Airlie | ce60fe0 | 2006-02-02 19:21:38 +1100 | [diff] [blame] | 201 | static int |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 202 | 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] | 203 | unsigned int *sequence) |
| 204 | { |
| 205 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 206 | unsigned int cur_irq_sequence; |
Jayachandran C | d253258 | 2006-04-10 23:18:28 -0700 | [diff] [blame] | 207 | drm_via_irq_t *cur_irq; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 208 | int ret = 0; |
Dave Airlie | 86678df | 2006-04-05 18:10:11 +1000 | [diff] [blame] | 209 | maskarray_t *masks; |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 210 | int real_irq; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 211 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 212 | DRM_DEBUG("\n"); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 213 | |
| 214 | if (!dev_priv) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 215 | DRM_ERROR("called with no initialization\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 216 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 217 | } |
| 218 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 219 | if (irq >= drm_via_irq_num) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 220 | DRM_ERROR("Trying to wait on unknown irq %d\n", irq); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 221 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 222 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 223 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 224 | real_irq = dev_priv->irq_map[irq]; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 225 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 226 | if (real_irq < 0) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 227 | DRM_ERROR("Video IRQ %d not available on this hardware.\n", |
| 228 | irq); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 229 | return -EINVAL; |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 230 | } |
Dave Airlie | 86678df | 2006-04-05 18:10:11 +1000 | [diff] [blame] | 231 | |
| 232 | masks = dev_priv->irq_masks; |
Jayachandran C | d253258 | 2006-04-10 23:18:28 -0700 | [diff] [blame] | 233 | cur_irq = dev_priv->via_irqs + real_irq; |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 234 | |
| 235 | if (masks[real_irq][2] && !force_sequence) { |
Daniel Vetter | bfd8303 | 2013-12-11 11:34:41 +0100 | [diff] [blame] | 236 | DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 237 | ((VIA_READ(masks[irq][2]) & masks[irq][3]) == |
| 238 | masks[irq][4])); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 239 | cur_irq_sequence = atomic_read(&cur_irq->irq_received); |
| 240 | } else { |
Daniel Vetter | bfd8303 | 2013-12-11 11:34:41 +0100 | [diff] [blame] | 241 | DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 242 | (((cur_irq_sequence = |
| 243 | atomic_read(&cur_irq->irq_received)) - |
| 244 | *sequence) <= (1 << 23))); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 245 | } |
| 246 | *sequence = cur_irq_sequence; |
| 247 | return ret; |
| 248 | } |
| 249 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 250 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 251 | /* |
| 252 | * drm_dma.h hooks |
| 253 | */ |
| 254 | |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 255 | void via_driver_irq_preinstall(struct drm_device *dev) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 256 | { |
| 257 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 258 | u32 status; |
Jayachandran C | d253258 | 2006-04-10 23:18:28 -0700 | [diff] [blame] | 259 | drm_via_irq_t *cur_irq; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 260 | int i; |
| 261 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 262 | DRM_DEBUG("dev_priv: %p\n", dev_priv); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 263 | if (dev_priv) { |
Jayachandran C | d253258 | 2006-04-10 23:18:28 -0700 | [diff] [blame] | 264 | cur_irq = dev_priv->via_irqs; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 265 | |
| 266 | dev_priv->irq_enable_mask = VIA_IRQ_VBLANK_ENABLE; |
| 267 | dev_priv->irq_pending_mask = VIA_IRQ_VBLANK_PENDING; |
| 268 | |
Thomas Hellstrom | 689692e | 2007-01-08 21:19:57 +1100 | [diff] [blame] | 269 | if (dev_priv->chipset == VIA_PRO_GROUP_A || |
| 270 | dev_priv->chipset == VIA_DX9_0) { |
| 271 | dev_priv->irq_masks = via_pro_group_a_irqs; |
| 272 | dev_priv->num_irqs = via_num_pro_group_a; |
| 273 | dev_priv->irq_map = via_irqmap_pro_group_a; |
| 274 | } else { |
| 275 | dev_priv->irq_masks = via_unichrome_irqs; |
| 276 | dev_priv->num_irqs = via_num_unichrome; |
| 277 | dev_priv->irq_map = via_irqmap_unichrome; |
| 278 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 279 | |
| 280 | for (i = 0; i < dev_priv->num_irqs; ++i) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 281 | atomic_set(&cur_irq->irq_received, 0); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 282 | cur_irq->enable_mask = dev_priv->irq_masks[i][0]; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 283 | cur_irq->pending_mask = dev_priv->irq_masks[i][1]; |
Daniel Vetter | 57ed0f7 | 2013-12-11 11:34:43 +0100 | [diff] [blame] | 284 | init_waitqueue_head(&cur_irq->irq_queue); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 285 | dev_priv->irq_enable_mask |= cur_irq->enable_mask; |
| 286 | dev_priv->irq_pending_mask |= cur_irq->pending_mask; |
| 287 | cur_irq++; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 288 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 289 | DRM_DEBUG("Initializing IRQ %d\n", i); |
| 290 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 291 | |
| 292 | dev_priv->last_vblank_valid = 0; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 293 | |
Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 294 | /* Clear VSync interrupt regs */ |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 295 | status = VIA_READ(VIA_REG_INTERRUPT); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 296 | VIA_WRITE(VIA_REG_INTERRUPT, status & |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 297 | ~(dev_priv->irq_enable_mask)); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 298 | |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 299 | /* Clear bits if they're already high */ |
| 300 | viadrv_acknowledge_irqs(dev_priv); |
| 301 | } |
| 302 | } |
| 303 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 304 | int via_driver_irq_postinstall(struct drm_device *dev) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 305 | { |
| 306 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 307 | u32 status; |
| 308 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 309 | DRM_DEBUG("via_driver_irq_postinstall\n"); |
| 310 | if (!dev_priv) |
| 311 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 312 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 313 | status = VIA_READ(VIA_REG_INTERRUPT); |
| 314 | VIA_WRITE(VIA_REG_INTERRUPT, status | VIA_IRQ_GLOBAL |
| 315 | | dev_priv->irq_enable_mask); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 316 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 317 | /* Some magic, oh for some data sheets ! */ |
| 318 | VIA_WRITE8(0x83d4, 0x11); |
| 319 | VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) | 0x30); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 320 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 321 | return 0; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 322 | } |
| 323 | |
Nicolas Kaiser | 58c1e85 | 2010-07-11 15:32:42 +0200 | [diff] [blame] | 324 | void via_driver_irq_uninstall(struct drm_device *dev) |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 325 | { |
| 326 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 327 | u32 status; |
| 328 | |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 329 | DRM_DEBUG("\n"); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 330 | if (dev_priv) { |
| 331 | |
| 332 | /* Some more magic, oh for some data sheets ! */ |
| 333 | |
| 334 | VIA_WRITE8(0x83d4, 0x11); |
| 335 | VIA_WRITE8(0x83d5, VIA_READ8(0x83d5) & ~0x30); |
| 336 | |
| 337 | status = VIA_READ(VIA_REG_INTERRUPT); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 338 | VIA_WRITE(VIA_REG_INTERRUPT, status & |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 339 | ~(VIA_IRQ_VBLANK_ENABLE | dev_priv->irq_enable_mask)); |
| 340 | } |
| 341 | } |
| 342 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 343 | 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] | 344 | { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 345 | drm_via_irqwait_t *irqwait = data; |
Arnd Bergmann | 44a2d56 | 2017-11-27 12:17:03 +0100 | [diff] [blame] | 346 | struct timespec64 now; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 347 | int ret = 0; |
| 348 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; |
| 349 | drm_via_irq_t *cur_irq = dev_priv->via_irqs; |
| 350 | int force_sequence; |
| 351 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 352 | if (irqwait->request.irq >= dev_priv->num_irqs) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 353 | DRM_ERROR("Trying to wait on unknown irq %d\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 354 | irqwait->request.irq); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 355 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 356 | } |
| 357 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 358 | cur_irq += irqwait->request.irq; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 359 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 360 | switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) { |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 361 | case VIA_IRQ_RELATIVE: |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 362 | irqwait->request.sequence += |
| 363 | atomic_read(&cur_irq->irq_received); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 364 | irqwait->request.type &= ~_DRM_VBLANK_RELATIVE; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 365 | case VIA_IRQ_ABSOLUTE: |
| 366 | break; |
| 367 | default: |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 368 | return -EINVAL; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 369 | } |
| 370 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 371 | if (irqwait->request.type & VIA_IRQ_SIGNAL) { |
Márton Németh | 3e684ea | 2008-01-24 15:58:57 +1000 | [diff] [blame] | 372 | DRM_ERROR("Signals on Via IRQs not implemented yet.\n"); |
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 | force_sequence = (irqwait->request.type & VIA_IRQ_FORCE_SEQUENCE); |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 377 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 378 | ret = via_driver_irq_wait(dev, irqwait->request.irq, force_sequence, |
| 379 | &irqwait->request.sequence); |
Arnd Bergmann | 44a2d56 | 2017-11-27 12:17:03 +0100 | [diff] [blame] | 380 | ktime_get_ts64(&now); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 381 | irqwait->reply.tval_sec = now.tv_sec; |
Arnd Bergmann | 44a2d56 | 2017-11-27 12:17:03 +0100 | [diff] [blame] | 382 | irqwait->reply.tval_usec = now.tv_nsec / NSEC_PER_USEC; |
Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 383 | |
| 384 | return ret; |
| 385 | } |