1203288Srnoland/*- 2203288Srnoland * Copyright 2005 Thomas Hellstrom. All Rights Reserved. 3203288Srnoland * 4203288Srnoland * Permission is hereby granted, free of charge, to any person obtaining a 5203288Srnoland * copy of this software and associated documentation files (the "Software"), 6203288Srnoland * to deal in the Software without restriction, including without limitation 7203288Srnoland * the rights to use, copy, modify, merge, publish, distribute, sub license, 8203288Srnoland * and/or sell copies of the Software, and to permit persons to whom the 9203288Srnoland * Software is furnished to do so, subject to the following conditions: 10203288Srnoland * 11203288Srnoland * The above copyright notice and this permission notice (including the 12203288Srnoland * next paragraph) shall be included in all copies or substantial portions 13203288Srnoland * of the Software. 14203288Srnoland * 15203288Srnoland * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16203288Srnoland * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17203288Srnoland * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18203288Srnoland * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19203288Srnoland * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20203288Srnoland * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21203288Srnoland * DEALINGS IN THE SOFTWARE. 22203288Srnoland * 23203288Srnoland * Author: Thomas Hellstrom 2005. 24203288Srnoland * 25203288Srnoland * Video and XvMC related functions. 26203288Srnoland */ 27203288Srnoland 28203288Srnoland#include <sys/cdefs.h> 29203288Srnoland__FBSDID("$FreeBSD$"); 30203288Srnoland 31203288Srnoland#include "dev/drm/drmP.h" 32203288Srnoland#include "dev/drm/via_drm.h" 33203288Srnoland#include "dev/drm/via_drv.h" 34203288Srnoland 35203288Srnolandvoid via_init_futex(drm_via_private_t * dev_priv) 36203288Srnoland{ 37203288Srnoland unsigned int i; 38203288Srnoland 39203288Srnoland DRM_DEBUG("\n"); 40203288Srnoland 41203288Srnoland for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) { 42203288Srnoland DRM_INIT_WAITQUEUE(&(dev_priv->decoder_queue[i])); 43203288Srnoland XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0; 44203288Srnoland } 45203288Srnoland} 46203288Srnoland 47203288Srnolandvoid via_cleanup_futex(drm_via_private_t * dev_priv) 48203288Srnoland{ 49203288Srnoland} 50203288Srnoland 51203288Srnolandvoid via_release_futex(drm_via_private_t * dev_priv, int context) 52203288Srnoland{ 53203288Srnoland unsigned int i; 54203288Srnoland volatile int *lock; 55203288Srnoland 56203288Srnoland if (!dev_priv->sarea_priv) 57203288Srnoland return; 58203288Srnoland 59203288Srnoland for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) { 60203288Srnoland lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i); 61203288Srnoland if ((_DRM_LOCKING_CONTEXT(*lock) == context)) { 62203288Srnoland if (_DRM_LOCK_IS_HELD(*lock) 63203288Srnoland && (*lock & _DRM_LOCK_CONT)) { 64203288Srnoland DRM_WAKEUP(&(dev_priv->decoder_queue[i])); 65203288Srnoland } 66203288Srnoland *lock = 0; 67203288Srnoland } 68203288Srnoland } 69203288Srnoland} 70203288Srnoland 71203288Srnolandint via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv) 72203288Srnoland{ 73203288Srnoland drm_via_futex_t *fx = data; 74203288Srnoland volatile int *lock; 75203288Srnoland drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; 76203288Srnoland drm_via_sarea_t *sAPriv = dev_priv->sarea_priv; 77203288Srnoland int ret = 0; 78203288Srnoland 79203288Srnoland DRM_DEBUG("\n"); 80203288Srnoland 81207318Srnoland if (fx->lock >= VIA_NR_XVMC_LOCKS) 82203288Srnoland return -EFAULT; 83203288Srnoland 84203288Srnoland lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock); 85203288Srnoland 86203288Srnoland switch (fx->func) { 87203288Srnoland case VIA_FUTEX_WAIT: 88203288Srnoland DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock], 89203288Srnoland (fx->ms / 10) * (DRM_HZ / 100), *lock != fx->val); 90203288Srnoland return ret; 91203288Srnoland case VIA_FUTEX_WAKE: 92203288Srnoland DRM_WAKEUP(&(dev_priv->decoder_queue[fx->lock])); 93203288Srnoland return 0; 94203288Srnoland } 95203288Srnoland return 0; 96203288Srnoland} 97