mesa-drm/linux-core/openchrome/via_video.c
2009-01-17 12:57:04 +01:00

105 lines
3.1 KiB
C

/*
* Copyright 2005 Thomas Hellstrom. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sub license,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Author: Thomas Hellstrom 2005.
*
* Video and XvMC related functions.
*/
#include "drmP.h"
#include "ochr_drm.h"
#include "via_drv.h"
#include "drm_sarea.h"
void via_init_futex(struct drm_via_private *dev_priv)
{
unsigned int i;
volatile struct via_sarea *sa_priv = dev_priv->sarea_priv;
DRM_DEBUG("\n");
for (i = 0; i < DRM_VIA_NR_XVMC_LOCKS; ++i) {
DRM_INIT_WAITQUEUE(&(dev_priv->decoder_queue[i]));
DRM_VIA_XVMCLOCKPTR(&sa_priv->sa_xvmc, i)->lock = 0;
}
}
void via_release_futex(struct drm_via_private *dev_priv, int context)
{
unsigned int i;
volatile int *lock;
volatile struct via_sarea *sa_priv = dev_priv->sarea_priv;
if (!dev_priv->sarea_priv)
return;
for (i = 0; i < DRM_VIA_NR_XVMC_LOCKS; ++i) {
lock =
(volatile int *)DRM_VIA_XVMCLOCKPTR(&sa_priv->sa_xvmc, i);
if ((_DRM_LOCKING_CONTEXT(*lock) == context)) {
if (_DRM_LOCK_IS_HELD(*lock)
&& (*lock & _DRM_LOCK_CONT)) {
DRM_WAKEUP(&(dev_priv->decoder_queue[i]));
}
*lock = 0;
}
}
}
int via_decoder_futex(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_via_futex *fx = data;
volatile int *lock;
struct drm_via_private *dev_priv = via_priv(dev);
struct via_sarea *sa_priv = dev_priv->sarea_priv;
int ret = 0;
DRM_DEBUG("\n");
if (unlikely(sa_priv == NULL)) {
dev_priv->sarea = drm_getsarea(dev);
if (!dev_priv->sarea) {
DRM_ERROR("Could not find sarea.\n");
return -EINVAL;
}
dev_priv->sarea_priv =
(struct via_sarea *)((u8 *) dev_priv->sarea->handle +
sizeof(struct drm_sarea));
sa_priv = dev_priv->sarea_priv;
}
if (fx->lock > DRM_VIA_NR_XVMC_LOCKS)
return -EFAULT;
lock = (volatile int *)DRM_VIA_XVMCLOCKPTR(&sa_priv->sa_xvmc, fx->lock);
switch (fx->op) {
case VIA_FUTEX_WAIT:
DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock],
(fx->ms / 10) * (DRM_HZ / 100), *lock != fx->val);
return ret;
case VIA_FUTEX_WAKE:
DRM_WAKEUP(&(dev_priv->decoder_queue[fx->lock]));
return 0;
}
return 0;
}