Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* mga_irq.c -- IRQ handling for radeon -*- linux-c -*- |
| 2 | * |
| 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> |
| 30 | * Eric Anholt <anholt@FreeBSD.org> |
| 31 | */ |
| 32 | |
| 33 | #include "drmP.h" |
| 34 | #include "drm.h" |
| 35 | #include "mga_drm.h" |
| 36 | #include "mga_drv.h" |
| 37 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 38 | u32 mga_get_vblank_counter(struct drm_device *dev, int crtc) |
| 39 | { |
| 40 | const drm_mga_private_t *const dev_priv = |
| 41 | (drm_mga_private_t *) dev->dev_private; |
| 42 | |
| 43 | if (crtc != 0) { |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | return atomic_read(&dev_priv->vbl_received); |
| 49 | } |
| 50 | |
| 51 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 52 | irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 54 | struct drm_device *dev = (struct drm_device *) arg; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 55 | 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] | 56 | int status; |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 57 | int handled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 59 | status = MGA_READ(MGA_STATUS); |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* VBLANK interrupt */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 62 | if (status & MGA_VLINEPEN) { |
| 63 | MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR); |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 64 | atomic_inc(&dev_priv->vbl_received); |
| 65 | drm_handle_vblank(dev, 0); |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 66 | handled = 1; |
| 67 | } |
| 68 | |
| 69 | /* SOFTRAP interrupt */ |
| 70 | if (status & MGA_SOFTRAPEN) { |
| 71 | const u32 prim_start = MGA_READ(MGA_PRIMADDRESS); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 72 | const u32 prim_end = MGA_READ(MGA_PRIMEND); |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 73 | |
| 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 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [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); |
| 81 | } |
| 82 | |
| 83 | atomic_inc(&dev_priv->last_fence_retired); |
| 84 | DRM_WAKEUP(&dev_priv->fence_queue); |
| 85 | handled = 1; |
| 86 | } |
| 87 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 88 | if (handled) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | return IRQ_HANDLED; |
| 90 | } |
| 91 | return IRQ_NONE; |
| 92 | } |
| 93 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 94 | int mga_enable_vblank(struct drm_device *dev, int crtc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 96 | 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] | 97 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 98 | if (crtc != 0) { |
| 99 | DRM_ERROR("tried to enable vblank on non-existent crtc %d\n", |
| 100 | crtc); |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | MGA_WRITE(MGA_IEN, MGA_VLINEIEN | MGA_SOFTRAPEN); |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void mga_disable_vblank(struct drm_device *dev, int crtc) |
| 110 | { |
| 111 | if (crtc != 0) { |
| 112 | DRM_ERROR("tried to disable vblank on non-existent crtc %d\n", |
| 113 | crtc); |
| 114 | } |
| 115 | |
| 116 | /* Do *NOT* disable the vertical refresh interrupt. MGA doesn't have |
| 117 | * a nice hardware counter that tracks the number of refreshes when |
| 118 | * the interrupt is disabled, and the kernel doesn't know the refresh |
| 119 | * rate to calculate an estimate. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | */ |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 121 | /* MGA_WRITE(MGA_IEN, MGA_VLINEIEN | MGA_SOFTRAPEN); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 124 | int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence) |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 125 | { |
| 126 | drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private; |
| 127 | unsigned int cur_fence; |
| 128 | int ret = 0; |
| 129 | |
| 130 | /* Assume that the user has missed the current sequence number |
| 131 | * by about a day rather than she wants to wait for years |
| 132 | * using fences. |
| 133 | */ |
| 134 | DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ, |
| 135 | (((cur_fence = atomic_read(&dev_priv->last_fence_retired)) |
| 136 | - *sequence) <= (1 << 23))); |
| 137 | |
| 138 | *sequence = cur_fence; |
| 139 | |
| 140 | return ret; |
| 141 | } |
| 142 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 143 | void mga_driver_irq_preinstall(struct drm_device * dev) |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 144 | { |
| 145 | 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] | 146 | |
| 147 | /* Disable *all* interrupts */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 148 | MGA_WRITE(MGA_IEN, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /* Clear bits if they're already high */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 150 | MGA_WRITE(MGA_ICLEAR, ~0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 153 | int mga_driver_irq_postinstall(struct drm_device * dev) |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 154 | { |
| 155 | drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private; |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 156 | int ret; |
| 157 | |
| 158 | ret = drm_vblank_init(dev, 1); |
| 159 | if (ret) |
| 160 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 162 | DRM_INIT_WAITQUEUE(&dev_priv->fence_queue); |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 163 | |
Jesse Barnes | ac741ab | 2008-04-22 16:03:07 +1000 | [diff] [blame] | 164 | /* Turn on soft trap interrupt. Vertical blank interrupts are enabled |
| 165 | * in mga_enable_vblank. |
| 166 | */ |
| 167 | MGA_WRITE(MGA_IEN, MGA_SOFTRAPEN); |
| 168 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 171 | void mga_driver_irq_uninstall(struct drm_device * dev) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 172 | { |
| 173 | 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] | 174 | if (!dev_priv) |
| 175 | return; |
| 176 | |
| 177 | /* Disable *all* interrupts */ |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 178 | MGA_WRITE(MGA_IEN, 0); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 179 | |
Dave Airlie | 6795c98 | 2005-07-10 18:20:09 +1000 | [diff] [blame] | 180 | dev->irq_enabled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |