Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* mga_irq.c -- IRQ handling for radeon -*- linux-c -*- |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 2 | */ |
| 3 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * The Weather Channel (TM) funded Tungsten Graphics to develop the |
| 7 | * initial release of the Radeon 8500 driver under the XFree86 license. |
| 8 | * This notice must be preserved. |
| 9 | * |
| 10 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 11 | * copy of this software and associated documentation files (the "Software"), |
| 12 | * to deal in the Software without restriction, including without limitation |
| 13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 14 | * and/or sell copies of the Software, and to permit persons to whom the |
| 15 | * Software is furnished to do so, subject to the following conditions: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice (including the next |
| 18 | * paragraph) shall be included in all copies or substantial portions of the |
| 19 | * Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 24 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 25 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 26 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 27 | * DEALINGS IN THE SOFTWARE. |
| 28 | * |
| 29 | * Authors: |
| 30 | * Keith Whitwell <keith@tungstengraphics.com> |
| 31 | * Eric Anholt <anholt@FreeBSD.org> |
| 32 | */ |
| 33 | |
| 34 | #include "drmP.h" |
| 35 | #include "drm.h" |
| 36 | #include "mga_drm.h" |
| 37 | #include "mga_drv.h" |
| 38 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 39 | u32 mga_get_vblank_counter(struct drm_device *dev, int crtc) |
| 40 | { |
| 41 | const drm_mga_private_t *const dev_priv = |
| 42 | (drm_mga_private_t *) dev->dev_private; |
| 43 | |
| 44 | if (crtc != 0) |
| 45 | return 0; |
| 46 | |
| 47 | return atomic_read(&dev_priv->vbl_received); |
| 48 | } |
| 49 | |
| 50 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 51 | irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 53 | struct drm_device *dev = (struct drm_device *) arg; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 54 | drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | int status; |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 56 | int handled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 58 | status = MGA_READ(MGA_STATUS); |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* VBLANK interrupt */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 61 | if (status & MGA_VLINEPEN) { |
| 62 | MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR); |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 63 | atomic_inc(&dev_priv->vbl_received); |
| 64 | drm_handle_vblank(dev, 0); |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 65 | handled = 1; |
| 66 | } |
| 67 | |
| 68 | /* SOFTRAP interrupt */ |
| 69 | if (status & MGA_SOFTRAPEN) { |
| 70 | const u32 prim_start = MGA_READ(MGA_PRIMADDRESS); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 71 | const u32 prim_end = MGA_READ(MGA_PRIMEND); |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 72 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 73 | |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 74 | MGA_WRITE(MGA_ICLEAR, MGA_SOFTRAPICLR); |
| 75 | |
| 76 | /* In addition to clearing the interrupt-pending bit, we |
| 77 | * have to write to MGA_PRIMEND to re-start the DMA operation. |
| 78 | */ |
Nicolas Kaiser | f2b2cb7 | 2010-07-12 01:46:57 +0200 | [diff] [blame^] | 79 | if ((prim_start & ~0x03) != (prim_end & ~0x03)) |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 80 | MGA_WRITE(MGA_PRIMEND, prim_end); |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 81 | |
| 82 | atomic_inc(&dev_priv->last_fence_retired); |
| 83 | DRM_WAKEUP(&dev_priv->fence_queue); |
| 84 | handled = 1; |
| 85 | } |
| 86 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 87 | if (handled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | return IRQ_NONE; |
| 90 | } |
| 91 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 92 | int mga_enable_vblank(struct drm_device *dev, int crtc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 94 | drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 96 | if (crtc != 0) { |
| 97 | DRM_ERROR("tried to enable vblank on non-existent crtc %d\n", |
| 98 | crtc); |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | MGA_WRITE(MGA_IEN, MGA_VLINEIEN | MGA_SOFTRAPEN); |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | void mga_disable_vblank(struct drm_device *dev, int crtc) |
| 108 | { |
| 109 | if (crtc != 0) { |
| 110 | DRM_ERROR("tried to disable vblank on non-existent crtc %d\n", |
| 111 | crtc); |
| 112 | } |
| 113 | |
| 114 | /* Do *NOT* disable the vertical refresh interrupt. MGA doesn't have |
| 115 | * a nice hardware counter that tracks the number of refreshes when |
| 116 | * the interrupt is disabled, and the kernel doesn't know the refresh |
| 117 | * rate to calculate an estimate. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | */ |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 119 | /* MGA_WRITE(MGA_IEN, MGA_VLINEIEN | MGA_SOFTRAPEN); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Nicolas Kaiser | f2b2cb7 | 2010-07-12 01:46:57 +0200 | [diff] [blame^] | 122 | int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence) |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 123 | { |
| 124 | drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private; |
| 125 | unsigned int cur_fence; |
| 126 | int ret = 0; |
| 127 | |
| 128 | /* Assume that the user has missed the current sequence number |
| 129 | * by about a day rather than she wants to wait for years |
| 130 | * using fences. |
| 131 | */ |
| 132 | DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ, |
| 133 | (((cur_fence = atomic_read(&dev_priv->last_fence_retired)) |
| 134 | - *sequence) <= (1 << 23))); |
| 135 | |
| 136 | *sequence = cur_fence; |
| 137 | |
| 138 | return ret; |
| 139 | } |
| 140 | |
Nicolas Kaiser | f2b2cb7 | 2010-07-12 01:46:57 +0200 | [diff] [blame^] | 141 | void mga_driver_irq_preinstall(struct drm_device *dev) |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 142 | { |
| 143 | drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | /* Disable *all* interrupts */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 146 | MGA_WRITE(MGA_IEN, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* Clear bits if they're already high */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 148 | MGA_WRITE(MGA_ICLEAR, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 151 | int mga_driver_irq_postinstall(struct drm_device *dev) |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 152 | { |
| 153 | drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 155 | DRM_INIT_WAITQUEUE(&dev_priv->fence_queue); |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 156 | |
Jesse Barnes | 0a3e67a | 2008-09-30 12:14:26 -0700 | [diff] [blame] | 157 | /* Turn on soft trap interrupt. Vertical blank interrupts are enabled |
| 158 | * in mga_enable_vblank. |
| 159 | */ |
| 160 | MGA_WRITE(MGA_IEN, MGA_SOFTRAPEN); |
| 161 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Nicolas Kaiser | f2b2cb7 | 2010-07-12 01:46:57 +0200 | [diff] [blame^] | 164 | void mga_driver_irq_uninstall(struct drm_device *dev) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 165 | { |
| 166 | drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | if (!dev_priv) |
| 168 | return; |
| 169 | |
| 170 | /* Disable *all* interrupts */ |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 171 | MGA_WRITE(MGA_IEN, 0); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 172 | |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 173 | dev->irq_enabled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |