vmwgfx_va.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**************************************************************************
  2. *
  3. * Copyright © 2012-2016 VMware, Inc., Palo Alto, CA., USA
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #include "vmwgfx_drv.h"
  28. #include "vmwgfx_resource_priv.h"
  29. /**
  30. * struct vmw_stream - Overlay stream simple resource.
  31. * @sres: The simple resource we derive from.
  32. * @stream_id: The overlay stream id.
  33. */
  34. struct vmw_stream {
  35. struct vmw_simple_resource sres;
  36. u32 stream_id;
  37. };
  38. /**
  39. * vmw_stream - Typecast a struct vmw_resource to a struct vmw_stream.
  40. * @res: Pointer to the struct vmw_resource.
  41. *
  42. * Returns: Returns a pointer to the struct vmw_stream.
  43. */
  44. static struct vmw_stream *
  45. vmw_stream(struct vmw_resource *res)
  46. {
  47. return container_of(res, struct vmw_stream, sres.res);
  48. }
  49. /***************************************************************************
  50. * Simple resource callbacks for struct vmw_stream
  51. **************************************************************************/
  52. static void vmw_stream_hw_destroy(struct vmw_resource *res)
  53. {
  54. struct vmw_private *dev_priv = res->dev_priv;
  55. struct vmw_stream *stream = vmw_stream(res);
  56. int ret;
  57. ret = vmw_overlay_unref(dev_priv, stream->stream_id);
  58. WARN_ON_ONCE(ret != 0);
  59. }
  60. static int vmw_stream_init(struct vmw_resource *res, void *data)
  61. {
  62. struct vmw_stream *stream = vmw_stream(res);
  63. return vmw_overlay_claim(res->dev_priv, &stream->stream_id);
  64. }
  65. static void vmw_stream_set_arg_handle(void *data, u32 handle)
  66. {
  67. struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data;
  68. arg->stream_id = handle;
  69. }
  70. static const struct vmw_simple_resource_func va_stream_func = {
  71. .res_func = {
  72. .res_type = vmw_res_stream,
  73. .needs_backup = false,
  74. .may_evict = false,
  75. .type_name = "overlay stream",
  76. .backup_placement = NULL,
  77. .create = NULL,
  78. .destroy = NULL,
  79. .bind = NULL,
  80. .unbind = NULL
  81. },
  82. .ttm_res_type = VMW_RES_STREAM,
  83. .size = sizeof(struct vmw_stream),
  84. .init = vmw_stream_init,
  85. .hw_destroy = vmw_stream_hw_destroy,
  86. .set_arg_handle = vmw_stream_set_arg_handle,
  87. };
  88. /***************************************************************************
  89. * End simple resource callbacks for struct vmw_stream
  90. **************************************************************************/
  91. /**
  92. * vmw_stream_unref_ioctl - Ioctl to unreference a user-space handle to
  93. * a struct vmw_stream.
  94. * @dev: Pointer to the drm device.
  95. * @data: The ioctl argument
  96. * @file_priv: Pointer to a struct drm_file identifying the caller.
  97. *
  98. * Return:
  99. * 0 if successful.
  100. * Negative error value on failure.
  101. */
  102. int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
  103. struct drm_file *file_priv)
  104. {
  105. struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data;
  106. return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile,
  107. arg->stream_id, TTM_REF_USAGE);
  108. }
  109. /**
  110. * vmw_stream_claim_ioctl - Ioctl to claim a struct vmw_stream overlay.
  111. * @dev: Pointer to the drm device.
  112. * @data: The ioctl argument
  113. * @file_priv: Pointer to a struct drm_file identifying the caller.
  114. *
  115. * Return:
  116. * 0 if successful.
  117. * Negative error value on failure.
  118. */
  119. int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  120. struct drm_file *file_priv)
  121. {
  122. return vmw_simple_resource_create_ioctl(dev, data, file_priv,
  123. &va_stream_func);
  124. }
  125. /**
  126. * vmw_user_stream_lookup - Look up a struct vmw_user_stream from a handle.
  127. * @dev_priv: Pointer to a struct vmw_private.
  128. * @tfile: struct ttm_object_file identifying the caller.
  129. * @inout_id: In: The user-space handle. Out: The stream id.
  130. * @out: On output contains a refcounted pointer to the embedded
  131. * struct vmw_resource.
  132. *
  133. * Return:
  134. * 0 if successful.
  135. * Negative error value on failure.
  136. */
  137. int vmw_user_stream_lookup(struct vmw_private *dev_priv,
  138. struct ttm_object_file *tfile,
  139. uint32_t *inout_id, struct vmw_resource **out)
  140. {
  141. struct vmw_stream *stream;
  142. struct vmw_resource *res =
  143. vmw_simple_resource_lookup(tfile, *inout_id, &va_stream_func);
  144. if (IS_ERR(res))
  145. return PTR_ERR(res);
  146. stream = vmw_stream(res);
  147. *inout_id = stream->stream_id;
  148. *out = res;
  149. return 0;
  150. }