18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2005 Thomas Hellstrom. All Rights Reserved. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the 128c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 138c2ecf20Sopenharmony_ci * of the Software. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 188c2ecf20Sopenharmony_ci * THE AUTHOR(S), AND/OR THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 198c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 208c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 218c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Author: Thomas Hellstrom 2005. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * Video and XvMC related functions. 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include <drm/drm_device.h> 298c2ecf20Sopenharmony_ci#include <drm/via_drm.h> 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#include "via_drv.h" 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_civoid via_init_futex(drm_via_private_t *dev_priv) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci unsigned int i; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci DRM_DEBUG("\n"); 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) { 408c2ecf20Sopenharmony_ci init_waitqueue_head(&(dev_priv->decoder_queue[i])); 418c2ecf20Sopenharmony_ci XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0; 428c2ecf20Sopenharmony_ci } 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_civoid via_cleanup_futex(drm_via_private_t *dev_priv) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_civoid via_release_futex(drm_via_private_t *dev_priv, int context) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci unsigned int i; 528c2ecf20Sopenharmony_ci volatile int *lock; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci if (!dev_priv->sarea_priv) 558c2ecf20Sopenharmony_ci return; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) { 588c2ecf20Sopenharmony_ci lock = (volatile int *)XVMCLOCKPTR(dev_priv->sarea_priv, i); 598c2ecf20Sopenharmony_ci if ((_DRM_LOCKING_CONTEXT(*lock) == context)) { 608c2ecf20Sopenharmony_ci if (_DRM_LOCK_IS_HELD(*lock) 618c2ecf20Sopenharmony_ci && (*lock & _DRM_LOCK_CONT)) { 628c2ecf20Sopenharmony_ci wake_up(&(dev_priv->decoder_queue[i])); 638c2ecf20Sopenharmony_ci } 648c2ecf20Sopenharmony_ci *lock = 0; 658c2ecf20Sopenharmony_ci } 668c2ecf20Sopenharmony_ci } 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciint via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci drm_via_futex_t *fx = data; 728c2ecf20Sopenharmony_ci volatile int *lock; 738c2ecf20Sopenharmony_ci drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; 748c2ecf20Sopenharmony_ci drm_via_sarea_t *sAPriv = dev_priv->sarea_priv; 758c2ecf20Sopenharmony_ci int ret = 0; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci DRM_DEBUG("\n"); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci if (fx->lock >= VIA_NR_XVMC_LOCKS) 808c2ecf20Sopenharmony_ci return -EFAULT; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci lock = (volatile int *)XVMCLOCKPTR(sAPriv, fx->lock); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci switch (fx->func) { 858c2ecf20Sopenharmony_ci case VIA_FUTEX_WAIT: 868c2ecf20Sopenharmony_ci VIA_WAIT_ON(ret, dev_priv->decoder_queue[fx->lock], 878c2ecf20Sopenharmony_ci (fx->ms / 10) * (HZ / 100), *lock != fx->val); 888c2ecf20Sopenharmony_ci return ret; 898c2ecf20Sopenharmony_ci case VIA_FUTEX_WAKE: 908c2ecf20Sopenharmony_ci wake_up(&(dev_priv->decoder_queue[fx->lock])); 918c2ecf20Sopenharmony_ci return 0; 928c2ecf20Sopenharmony_ci } 938c2ecf20Sopenharmony_ci return 0; 948c2ecf20Sopenharmony_ci} 95