| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2005 Thomas Hellstrom. All Rights Reserved. | 
|  | 3 | * | 
|  | 4 | * Permission is hereby granted, free of charge, to any person obtaining a | 
|  | 5 | * copy of this software and associated documentation files (the "Software"), | 
|  | 6 | * to deal in the Software without restriction, including without limitation | 
|  | 7 | * the rights to use, copy, modify, merge, publish, distribute, sub license, | 
|  | 8 | * and/or sell copies of the Software, and to permit persons to whom the | 
|  | 9 | * Software is furnished to do so, subject to the following conditions: | 
|  | 10 | * | 
|  | 11 | * The above copyright notice and this permission notice (including the | 
|  | 12 | * next paragraph) shall be included in all copies or substantial portions | 
|  | 13 | * of the Software. | 
|  | 14 | * | 
|  | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
|  | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
|  | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | 
|  | 18 | * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | 
|  | 19 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | 
|  | 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
|  | 21 | * DEALINGS IN THE SOFTWARE. | 
|  | 22 | * | 
|  | 23 | * Author: Thomas Hellstrom 2005. | 
|  | 24 | * | 
|  | 25 | * Video and XvMC related functions. | 
|  | 26 | */ | 
|  | 27 |  | 
|  | 28 | #include "drmP.h" | 
|  | 29 | #include "via_drm.h" | 
|  | 30 | #include "via_drv.h" | 
|  | 31 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 32 | void via_init_futex(drm_via_private_t * dev_priv) | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 33 | { | 
|  | 34 | unsigned int i; | 
|  | 35 |  | 
|  | 36 | DRM_DEBUG("%s\n", __FUNCTION__); | 
|  | 37 |  | 
|  | 38 | for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) { | 
|  | 39 | DRM_INIT_WAITQUEUE(&(dev_priv->decoder_queue[i])); | 
|  | 40 | XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0; | 
|  | 41 | } | 
|  | 42 | } | 
|  | 43 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 44 | void via_cleanup_futex(drm_via_private_t * dev_priv) | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 45 | { | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 46 | } | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 47 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 48 | void via_release_futex(drm_via_private_t * dev_priv, int context) | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 49 | { | 
|  | 50 | unsigned int i; | 
|  | 51 | volatile int *lock; | 
|  | 52 |  | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 53 | if (!dev_priv->sarea_priv) | 
|  | 54 | return; | 
|  | 55 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 56 | for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) { | 
| Dave Airlie | 9251424 | 2005-11-12 21:52:46 +1100 | [diff] [blame] | 57 | lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i); | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 58 | if ((_DRM_LOCKING_CONTEXT(*lock) == context)) { | 
|  | 59 | if (_DRM_LOCK_IS_HELD(*lock) | 
|  | 60 | && (*lock & _DRM_LOCK_CONT)) { | 
|  | 61 | DRM_WAKEUP(&(dev_priv->decoder_queue[i])); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 62 | } | 
|  | 63 | *lock = 0; | 
|  | 64 | } | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 65 | } | 
|  | 66 | } | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 67 |  | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 68 | int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv) | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 69 | { | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 70 | drm_via_futex_t *fx = data; | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 71 | volatile int *lock; | 
|  | 72 | drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; | 
|  | 73 | drm_via_sarea_t *sAPriv = dev_priv->sarea_priv; | 
|  | 74 | int ret = 0; | 
|  | 75 |  | 
|  | 76 | DRM_DEBUG("%s\n", __FUNCTION__); | 
|  | 77 |  | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 78 | if (fx->lock > VIA_NR_XVMC_LOCKS) | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 79 | return -EFAULT; | 
|  | 80 |  | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 81 | lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 82 |  | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 83 | switch (fx->func) { | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 84 | case VIA_FUTEX_WAIT: | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 85 | DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock], | 
|  | 86 | (fx->ms / 10) * (DRM_HZ / 100), *lock != fx->val); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 87 | return ret; | 
|  | 88 | case VIA_FUTEX_WAKE: | 
| Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 89 | DRM_WAKEUP(&(dev_priv->decoder_queue[fx->lock])); | 
| Dave Airlie | 22f579c | 2005-06-28 22:48:56 +1000 | [diff] [blame] | 90 | return 0; | 
|  | 91 | } | 
|  | 92 | return 0; | 
|  | 93 | } |