Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /** |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 2 | * \file drm_irq.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * IRQ support |
| 4 | * |
| 5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> |
| 6 | * \author Gareth Hughes <gareth@valinux.com> |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com |
| 11 | * |
| 12 | * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas. |
| 13 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
| 14 | * All Rights Reserved. |
| 15 | * |
| 16 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 17 | * copy of this software and associated documentation files (the "Software"), |
| 18 | * to deal in the Software without restriction, including without limitation |
| 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 20 | * and/or sell copies of the Software, and to permit persons to whom the |
| 21 | * Software is furnished to do so, subject to the following conditions: |
| 22 | * |
| 23 | * The above copyright notice and this permission notice (including the next |
| 24 | * paragraph) shall be included in all copies or substantial portions of the |
| 25 | * Software. |
| 26 | * |
| 27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 30 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 31 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 32 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 33 | * OTHER DEALINGS IN THE SOFTWARE. |
| 34 | */ |
| 35 | |
| 36 | #include "drmP.h" |
| 37 | |
| 38 | #include <linux/interrupt.h> /* For task queue support */ |
| 39 | |
| 40 | /** |
| 41 | * Get interrupt from bus id. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 42 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | * \param inode device inode. |
| 44 | * \param filp file pointer. |
| 45 | * \param cmd command. |
| 46 | * \param arg user argument, pointing to a drm_irq_busid structure. |
| 47 | * \return zero on success or a negative number on failure. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 48 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | * Finds the PCI device with the specified bus id and gets its IRQ number. |
| 50 | * This IOCTL is deprecated, and will now return EINVAL for any busid not equal |
| 51 | * to that of the device that this DRM instance attached to. |
| 52 | */ |
| 53 | int drm_irq_by_busid(struct inode *inode, struct file *filp, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 54 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
| 56 | drm_file_t *priv = filp->private_data; |
| 57 | drm_device_t *dev = priv->head->dev; |
| 58 | drm_irq_busid_t __user *argp = (void __user *)arg; |
| 59 | drm_irq_busid_t p; |
| 60 | |
| 61 | if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) |
| 62 | return -EINVAL; |
| 63 | |
| 64 | if (copy_from_user(&p, argp, sizeof(p))) |
| 65 | return -EFAULT; |
| 66 | |
Dave Airlie | 33229601 | 2006-08-07 20:23:42 +1000 | [diff] [blame] | 67 | if ((p.busnum >> 8) != drm_get_pci_domain(dev) || |
Dave | 242ef0e | 2006-07-18 04:01:01 +1000 | [diff] [blame] | 68 | (p.busnum & 0xff) != dev->pdev->bus->number || |
| 69 | p.devnum != PCI_SLOT(dev->pdev->devfn) || p.funcnum != PCI_FUNC(dev->pdev->devfn)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | return -EINVAL; |
| 71 | |
| 72 | p.irq = dev->irq; |
| 73 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 74 | DRM_DEBUG("%d:%d:%d => IRQ %d\n", p.busnum, p.devnum, p.funcnum, p.irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | if (copy_to_user(argp, &p, sizeof(p))) |
| 76 | return -EFAULT; |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Install IRQ handler. |
| 82 | * |
| 83 | * \param dev DRM device. |
| 84 | * \param irq IRQ number. |
| 85 | * |
| 86 | * Initializes the IRQ related data, and setups drm_device::vbl_queue. Installs the handler, calling the driver |
| 87 | * \c drm_driver_irq_preinstall() and \c drm_driver_irq_postinstall() functions |
| 88 | * before and after the installation. |
| 89 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 90 | static int drm_irq_install(drm_device_t * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | int ret; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 93 | unsigned long sh_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) |
| 96 | return -EINVAL; |
| 97 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 98 | if (dev->irq == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | return -EINVAL; |
| 100 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 101 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | /* Driver must have been initialized */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 104 | if (!dev->dev_private) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 105 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | return -EINVAL; |
| 107 | } |
| 108 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 109 | if (dev->irq_enabled) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 110 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | return -EBUSY; |
| 112 | } |
| 113 | dev->irq_enabled = 1; |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 114 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 116 | DRM_DEBUG("%s: irq=%d\n", __FUNCTION__, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | if (drm_core_check_feature(dev, DRIVER_IRQ_VBL)) { |
| 119 | init_waitqueue_head(&dev->vbl_queue); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 120 | |
| 121 | spin_lock_init(&dev->vbl_lock); |
| 122 | |
| 123 | INIT_LIST_HEAD(&dev->vbl_sigs.head); |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 124 | INIT_LIST_HEAD(&dev->vbl_sigs2.head); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | dev->vbl_pending = 0; |
| 127 | } |
| 128 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 129 | /* Before installing handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | dev->driver->irq_preinstall(dev); |
| 131 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 132 | /* Install handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | if (drm_core_check_feature(dev, DRIVER_IRQ_SHARED)) |
Thomas Gleixner | 935f6e3 | 2006-07-01 19:29:34 -0700 | [diff] [blame] | 134 | sh_flags = IRQF_SHARED; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 135 | |
| 136 | ret = request_irq(dev->irq, dev->driver->irq_handler, |
| 137 | sh_flags, dev->devname, dev); |
| 138 | if (ret < 0) { |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 139 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | dev->irq_enabled = 0; |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 141 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | return ret; |
| 143 | } |
| 144 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 145 | /* After installing handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | dev->driver->irq_postinstall(dev); |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Uninstall the IRQ handler. |
| 153 | * |
| 154 | * \param dev DRM device. |
| 155 | * |
| 156 | * Calls the driver's \c drm_driver_irq_uninstall() function, and stops the irq. |
| 157 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 158 | int drm_irq_uninstall(drm_device_t * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
| 160 | int irq_enabled; |
| 161 | |
| 162 | if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) |
| 163 | return -EINVAL; |
| 164 | |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 165 | mutex_lock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | irq_enabled = dev->irq_enabled; |
| 167 | dev->irq_enabled = 0; |
Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 168 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 170 | if (!irq_enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | return -EINVAL; |
| 172 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 173 | DRM_DEBUG("%s: irq=%d\n", __FUNCTION__, dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | dev->driver->irq_uninstall(dev); |
| 176 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 177 | free_irq(dev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | return 0; |
| 180 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | EXPORT_SYMBOL(drm_irq_uninstall); |
| 183 | |
| 184 | /** |
| 185 | * IRQ control ioctl. |
| 186 | * |
| 187 | * \param inode device inode. |
| 188 | * \param filp file pointer. |
| 189 | * \param cmd command. |
| 190 | * \param arg user argument, pointing to a drm_control structure. |
| 191 | * \return zero on success or a negative number on failure. |
| 192 | * |
| 193 | * Calls irq_install() or irq_uninstall() according to \p arg. |
| 194 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 195 | int drm_control(struct inode *inode, struct file *filp, |
| 196 | unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { |
| 198 | drm_file_t *priv = filp->private_data; |
| 199 | drm_device_t *dev = priv->head->dev; |
| 200 | drm_control_t ctl; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | /* if we haven't irq we fallback for compatibility reasons - this used to be a separate function in drm_dma.h */ |
| 203 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 204 | if (copy_from_user(&ctl, (drm_control_t __user *) arg, sizeof(ctl))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return -EFAULT; |
| 206 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 207 | switch (ctl.func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | case DRM_INST_HANDLER: |
| 209 | if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) |
| 210 | return 0; |
| 211 | if (dev->if_version < DRM_IF_VERSION(1, 2) && |
| 212 | ctl.irq != dev->irq) |
| 213 | return -EINVAL; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 214 | return drm_irq_install(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | case DRM_UNINST_HANDLER: |
| 216 | if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) |
| 217 | return 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 218 | return drm_irq_uninstall(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | default: |
| 220 | return -EINVAL; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Wait for VBLANK. |
| 226 | * |
| 227 | * \param inode device inode. |
| 228 | * \param filp file pointer. |
| 229 | * \param cmd command. |
| 230 | * \param data user argument, pointing to a drm_wait_vblank structure. |
| 231 | * \return zero on success or a negative number on failure. |
| 232 | * |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 233 | * Verifies the IRQ is installed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | * |
| 235 | * If a signal is requested checks if this task has already scheduled the same signal |
| 236 | * for the same vblank sequence number - nothing to be done in |
| 237 | * that case. If the number of tasks waiting for the interrupt exceeds 100 the |
| 238 | * function fails. Otherwise adds a new entry to drm_device::vbl_sigs for this |
| 239 | * task. |
| 240 | * |
| 241 | * If a signal is not requested, then calls vblank_wait(). |
| 242 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 243 | int drm_wait_vblank(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | drm_file_t *priv = filp->private_data; |
| 246 | drm_device_t *dev = priv->head->dev; |
| 247 | drm_wait_vblank_t __user *argp = (void __user *)data; |
| 248 | drm_wait_vblank_t vblwait; |
| 249 | struct timeval now; |
| 250 | int ret = 0; |
| 251 | unsigned int flags; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 252 | atomic_t *seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | if (!dev->irq) |
| 255 | return -EINVAL; |
| 256 | |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 257 | if (copy_from_user(&vblwait, argp, sizeof(vblwait))) |
| 258 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 260 | if (vblwait.request.type & |
| 261 | ~(_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK)) { |
| 262 | DRM_ERROR("Unsupported type value 0x%x, supported mask 0x%x\n", |
| 263 | vblwait.request.type, |
| 264 | (_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK)); |
| 265 | return -EINVAL; |
| 266 | } |
| 267 | |
| 268 | flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK; |
| 269 | |
| 270 | if (!drm_core_check_feature(dev, (flags & _DRM_VBLANK_SECONDARY) ? |
| 271 | DRIVER_IRQ_VBL2 : DRIVER_IRQ_VBL)) |
| 272 | return -EINVAL; |
| 273 | |
| 274 | seq = (flags & _DRM_VBLANK_SECONDARY) ? &dev->vbl_received2 : |
| 275 | &dev->vbl_received; |
| 276 | |
| 277 | switch (vblwait.request.type & _DRM_VBLANK_TYPES_MASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | case _DRM_VBLANK_RELATIVE: |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 279 | vblwait.request.sequence += atomic_read(seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | vblwait.request.type &= ~_DRM_VBLANK_RELATIVE; |
| 281 | case _DRM_VBLANK_ABSOLUTE: |
| 282 | break; |
| 283 | default: |
| 284 | return -EINVAL; |
| 285 | } |
| 286 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 287 | if (flags & _DRM_VBLANK_SIGNAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | unsigned long irqflags; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 289 | drm_vbl_sig_t *vbl_sigs = (flags & _DRM_VBLANK_SECONDARY) |
| 290 | ? &dev->vbl_sigs2 : &dev->vbl_sigs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | drm_vbl_sig_t *vbl_sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 293 | vblwait.reply.sequence = atomic_read(seq); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 294 | |
| 295 | spin_lock_irqsave(&dev->vbl_lock, irqflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | /* Check if this task has already scheduled the same signal |
| 298 | * for the same vblank sequence number; nothing to be done in |
| 299 | * that case |
| 300 | */ |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 301 | list_for_each_entry(vbl_sig, &vbl_sigs->head, head) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | if (vbl_sig->sequence == vblwait.request.sequence |
| 303 | && vbl_sig->info.si_signo == vblwait.request.signal |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 304 | && vbl_sig->task == current) { |
| 305 | spin_unlock_irqrestore(&dev->vbl_lock, |
| 306 | irqflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | goto done; |
| 308 | } |
| 309 | } |
| 310 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 311 | if (dev->vbl_pending >= 100) { |
| 312 | spin_unlock_irqrestore(&dev->vbl_lock, irqflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | return -EBUSY; |
| 314 | } |
| 315 | |
| 316 | dev->vbl_pending++; |
| 317 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 318 | spin_unlock_irqrestore(&dev->vbl_lock, irqflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 320 | if (! |
| 321 | (vbl_sig = |
| 322 | drm_alloc(sizeof(drm_vbl_sig_t), DRM_MEM_DRIVER))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | return -ENOMEM; |
| 324 | } |
| 325 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 326 | memset((void *)vbl_sig, 0, sizeof(*vbl_sig)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | vbl_sig->sequence = vblwait.request.sequence; |
| 329 | vbl_sig->info.si_signo = vblwait.request.signal; |
| 330 | vbl_sig->task = current; |
| 331 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 332 | spin_lock_irqsave(&dev->vbl_lock, irqflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 334 | list_add_tail((struct list_head *)vbl_sig, &vbl_sigs->head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 336 | spin_unlock_irqrestore(&dev->vbl_lock, irqflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } else { |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 338 | if (flags & _DRM_VBLANK_SECONDARY) { |
| 339 | if (dev->driver->vblank_wait2) |
| 340 | ret = dev->driver->vblank_wait2(dev, &vblwait.request.sequence); |
| 341 | } else if (dev->driver->vblank_wait) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 342 | ret = |
| 343 | dev->driver->vblank_wait(dev, |
| 344 | &vblwait.request.sequence); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 346 | do_gettimeofday(&now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | vblwait.reply.tval_sec = now.tv_sec; |
| 348 | vblwait.reply.tval_usec = now.tv_usec; |
| 349 | } |
| 350 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 351 | done: |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 352 | if (copy_to_user(argp, &vblwait, sizeof(vblwait))) |
| 353 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | return ret; |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Send the VBLANK signals. |
| 360 | * |
| 361 | * \param dev DRM device. |
| 362 | * |
| 363 | * Sends a signal for each task in drm_device::vbl_sigs and empties the list. |
| 364 | * |
| 365 | * If a signal is not requested, then calls vblank_wait(). |
| 366 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 367 | void drm_vbl_send_signals(drm_device_t * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | unsigned long flags; |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 370 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 372 | spin_lock_irqsave(&dev->vbl_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 374 | for (i = 0; i < 2; i++) { |
| 375 | struct list_head *list, *tmp; |
| 376 | drm_vbl_sig_t *vbl_sig; |
| 377 | drm_vbl_sig_t *vbl_sigs = i ? &dev->vbl_sigs2 : &dev->vbl_sigs; |
| 378 | unsigned int vbl_seq = atomic_read(i ? &dev->vbl_received2 : |
| 379 | &dev->vbl_received); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 381 | list_for_each_safe(list, tmp, &vbl_sigs->head) { |
| 382 | vbl_sig = list_entry(list, drm_vbl_sig_t, head); |
| 383 | if ((vbl_seq - vbl_sig->sequence) <= (1 << 23)) { |
| 384 | vbl_sig->info.si_code = vbl_seq; |
| 385 | send_sig_info(vbl_sig->info.si_signo, |
| 386 | &vbl_sig->info, vbl_sig->task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 388 | list_del(list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
=?utf-8?q?Michel_D=C3=A4nzer?= | 776c944 | 2006-10-24 22:24:38 +1000 | [diff] [blame] | 390 | drm_free(vbl_sig, sizeof(*vbl_sig), |
| 391 | DRM_MEM_DRIVER); |
| 392 | |
| 393 | dev->vbl_pending--; |
| 394 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 398 | spin_unlock_irqrestore(&dev->vbl_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | EXPORT_SYMBOL(drm_vbl_send_signals); |