blob: a9ffbad1cfdd87fe9d4c4bf14ce8902ca07f4f50 [file] [log] [blame]
Dave Airlie22f579c2005-06-28 22:48:56 +10001/*
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
David Howells760285e2012-10-02 18:01:07 +010028#include <drm/drmP.h>
29#include <drm/via_drm.h>
Dave Airlie22f579c2005-06-28 22:48:56 +100030#include "via_drv.h"
31
Nicolas Kaiser58c1e852010-07-11 15:32:42 +020032void via_init_futex(drm_via_private_t *dev_priv)
Dave Airlie22f579c2005-06-28 22:48:56 +100033{
34 unsigned int i;
35
Márton Németh3e684ea2008-01-24 15:58:57 +100036 DRM_DEBUG("\n");
Dave Airlie22f579c2005-06-28 22:48:56 +100037
38 for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
Daniel Vetter57ed0f72013-12-11 11:34:43 +010039 init_waitqueue_head(&(dev_priv->decoder_queue[i]));
Dave Airlie22f579c2005-06-28 22:48:56 +100040 XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0;
41 }
42}
43
Nicolas Kaiser58c1e852010-07-11 15:32:42 +020044void via_cleanup_futex(drm_via_private_t *dev_priv)
Dave Airlie22f579c2005-06-28 22:48:56 +100045{
Dave Airlieb5e89ed2005-09-25 14:28:13 +100046}
Dave Airlie22f579c2005-06-28 22:48:56 +100047
Nicolas Kaiser58c1e852010-07-11 15:32:42 +020048void via_release_futex(drm_via_private_t *dev_priv, int context)
Dave Airlie22f579c2005-06-28 22:48:56 +100049{
50 unsigned int i;
51 volatile int *lock;
52
Dave Airlie92514242005-11-12 21:52:46 +110053 if (!dev_priv->sarea_priv)
54 return;
55
Dave Airlieb5e89ed2005-09-25 14:28:13 +100056 for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
Dave Airlie92514242005-11-12 21:52:46 +110057 lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i);
Dave Airlieb5e89ed2005-09-25 14:28:13 +100058 if ((_DRM_LOCKING_CONTEXT(*lock) == context)) {
59 if (_DRM_LOCK_IS_HELD(*lock)
60 && (*lock & _DRM_LOCK_CONT)) {
Daniel Vetter57ed0f72013-12-11 11:34:43 +010061 wake_up(&(dev_priv->decoder_queue[i]));
Dave Airlie22f579c2005-06-28 22:48:56 +100062 }
63 *lock = 0;
64 }
Dave Airlieb5e89ed2005-09-25 14:28:13 +100065 }
66}
Dave Airlie22f579c2005-06-28 22:48:56 +100067
Eric Anholtc153f452007-09-03 12:06:45 +100068int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv)
Dave Airlie22f579c2005-06-28 22:48:56 +100069{
Eric Anholtc153f452007-09-03 12:06:45 +100070 drm_via_futex_t *fx = data;
Dave Airlie22f579c2005-06-28 22:48:56 +100071 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
Márton Németh3e684ea2008-01-24 15:58:57 +100076 DRM_DEBUG("\n");
Dave Airlie22f579c2005-06-28 22:48:56 +100077
Dan Carpenter22fb5732010-04-27 14:11:03 -070078 if (fx->lock >= VIA_NR_XVMC_LOCKS)
Dave Airlie22f579c2005-06-28 22:48:56 +100079 return -EFAULT;
80
Eric Anholtc153f452007-09-03 12:06:45 +100081 lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock);
Dave Airlie22f579c2005-06-28 22:48:56 +100082
Eric Anholtc153f452007-09-03 12:06:45 +100083 switch (fx->func) {
Dave Airlie22f579c2005-06-28 22:48:56 +100084 case VIA_FUTEX_WAIT:
Eric Anholtc153f452007-09-03 12:06:45 +100085 DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock],
Daniel Vetterbfd83032013-12-11 11:34:41 +010086 (fx->ms / 10) * (HZ / 100), *lock != fx->val);
Dave Airlie22f579c2005-06-28 22:48:56 +100087 return ret;
88 case VIA_FUTEX_WAKE:
Daniel Vetter57ed0f72013-12-11 11:34:43 +010089 wake_up(&(dev_priv->decoder_queue[fx->lock]));
Dave Airlie22f579c2005-06-28 22:48:56 +100090 return 0;
91 }
92 return 0;
93}