via_video.c revision 1.5 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 <drm/drmP.h>
29 #include <drm/via_drm.h>
30 #include "via_drv.h"
31
32 void via_init_futex(drm_via_private_t *dev_priv)
33 {
34 unsigned int i;
35
36 DRM_DEBUG("\n");
37
38 for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
39 #ifdef __NetBSD__
40 spin_lock_init(&dev_priv->decoder_lock[i]);
41 DRM_INIT_WAITQUEUE(&dev_priv->decoder_queue[i], "viadec");
42 #else
43 init_waitqueue_head(&(dev_priv->decoder_queue[i]));
44 #endif
45 XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0;
46 }
47 }
48
49 void via_cleanup_futex(drm_via_private_t *dev_priv)
50 {
51 #ifdef __NetBSD__
52 unsigned i;
53
54 for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
55 DRM_DESTROY_WAITQUEUE(&dev_priv->decoder_queue[i]);
56 spin_lock_destroy(&dev_priv->decoder_lock[i]);
57 }
58 #endif
59 }
60
61 void via_release_futex(drm_via_private_t *dev_priv, int context)
62 {
63 unsigned int i;
64 volatile int *lock;
65
66 if (!dev_priv->sarea_priv)
67 return;
68
69 for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
70 lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i);
71 if ((_DRM_LOCKING_CONTEXT(*lock) == context)) {
72 if (_DRM_LOCK_IS_HELD(*lock)
73 && (*lock & _DRM_LOCK_CONT)) {
74 #ifdef __NetBSD__
75 spin_lock(&dev_priv->decoder_lock[i]);
76 DRM_SPIN_WAKEUP_ALL(&dev_priv->decoder_queue[i],
77 &dev_priv->decoder_lock[i]);
78 spin_unlock(&dev_priv->decoder_lock[i]);
79 #else
80 wake_up(&(dev_priv->decoder_queue[i]));
81 #endif
82 }
83 *lock = 0;
84 }
85 }
86 }
87
88 int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv)
89 {
90 drm_via_futex_t *fx = data;
91 volatile int *lock;
92 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
93 drm_via_sarea_t *sAPriv = dev_priv->sarea_priv;
94 int ret = 0;
95
96 DRM_DEBUG("\n");
97
98 if (fx->lock >= VIA_NR_XVMC_LOCKS)
99 return -EFAULT;
100
101 lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock);
102
103 switch (fx->func) {
104 case VIA_FUTEX_WAIT:
105 #ifdef __NetBSD__
106 spin_lock(&dev_priv->decoder_lock[fx->lock]);
107 DRM_SPIN_WAIT_ON(ret, &dev_priv->decoder_queue[fx->lock],
108 &dev_priv->decoder_lock[fx->lock],
109 (fx->ms / 10) * (DRM_HZ / 100),
110 *lock != fx->val);
111 spin_unlock(&dev_priv->decoder_lock[fx->lock]);
112 #else
113 DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock],
114 (fx->ms / 10) * (HZ / 100), *lock != fx->val);
115 #endif
116 return ret;
117 case VIA_FUTEX_WAKE:
118 #ifdef __NetBSD__
119 spin_lock(&dev_priv->decoder_lock[fx->lock]);
120 DRM_SPIN_WAKEUP_ALL(&dev_priv->decoder_queue[fx->lock],
121 &dev_priv->decoder_lock[fx->lock]);
122 spin_unlock(&dev_priv->decoder_lock[fx->lock]);
123 #else
124 wake_up(&(dev_priv->decoder_queue[fx->lock]));
125 #endif
126 return 0;
127 }
128 return 0;
129 }
130