via_video.c 2.7 KB

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