via_video.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include "drmP.h"
  28. #include "via_drm.h"
  29. #include "via_drv.h"
  30. void
  31. via_init_futex(drm_via_private_t *dev_priv)
  32. {
  33. unsigned int i;
  34. DRM_DEBUG("%s\n", __FUNCTION__);
  35. for (i = 0; i < VIA_NR_XVMC_LOCKS; ++i) {
  36. DRM_INIT_WAITQUEUE(&(dev_priv->decoder_queue[i]));
  37. XVMCLOCKPTR(dev_priv->sarea_priv, i)->lock = 0;
  38. }
  39. }
  40. void
  41. via_cleanup_futex(drm_via_private_t *dev_priv)
  42. {
  43. }
  44. void
  45. via_release_futex(drm_via_private_t *dev_priv, int context)
  46. {
  47. unsigned int i;
  48. volatile int *lock;
  49. for (i=0; i < VIA_NR_XVMC_LOCKS; ++i) {
  50. lock = (int *) XVMCLOCKPTR(dev_priv->sarea_priv, i);
  51. if ( (_DRM_LOCKING_CONTEXT( *lock ) == context)) {
  52. if (_DRM_LOCK_IS_HELD( *lock ) && (*lock & _DRM_LOCK_CONT)) {
  53. DRM_WAKEUP( &(dev_priv->decoder_queue[i]));
  54. }
  55. *lock = 0;
  56. }
  57. }
  58. }
  59. int
  60. via_decoder_futex(DRM_IOCTL_ARGS)
  61. {
  62. DRM_DEVICE;
  63. drm_via_futex_t fx;
  64. volatile int *lock;
  65. drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
  66. drm_via_sarea_t *sAPriv = dev_priv->sarea_priv;
  67. int ret = 0;
  68. DRM_DEBUG("%s\n", __FUNCTION__);
  69. DRM_COPY_FROM_USER_IOCTL(fx, (drm_via_futex_t __user *) data,
  70. sizeof(fx));
  71. if (fx.lock > VIA_NR_XVMC_LOCKS)
  72. return -EFAULT;
  73. lock = (int *)XVMCLOCKPTR(sAPriv, fx.lock);
  74. switch (fx.func) {
  75. case VIA_FUTEX_WAIT:
  76. DRM_WAIT_ON(ret, dev_priv->decoder_queue[fx.lock],
  77. (fx.ms / 10) * (DRM_HZ / 100), *lock != fx.val);
  78. return ret;
  79. case VIA_FUTEX_WAKE:
  80. DRM_WAKEUP(&(dev_priv->decoder_queue[fx.lock]));
  81. return 0;
  82. }
  83. return 0;
  84. }