vmwgfx_va.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // SPDX-License-Identifier: GPL-2.0 OR MIT
  2. /**************************************************************************
  3. *
  4. * Copyright 2012-2016 VMware, Inc., Palo Alto, CA., USA
  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_bo.h"
  28. #include "vmwgfx_drv.h"
  29. #include "vmwgfx_resource_priv.h"
  30. /**
  31. * struct vmw_stream - Overlay stream simple resource.
  32. * @sres: The simple resource we derive from.
  33. * @stream_id: The overlay stream id.
  34. */
  35. struct vmw_stream {
  36. struct vmw_simple_resource sres;
  37. u32 stream_id;
  38. };
  39. /**
  40. * vmw_stream - Typecast a struct vmw_resource to a struct vmw_stream.
  41. * @res: Pointer to the struct vmw_resource.
  42. *
  43. * Returns: Returns a pointer to the struct vmw_stream.
  44. */
  45. static struct vmw_stream *
  46. vmw_stream(struct vmw_resource *res)
  47. {
  48. return container_of(res, struct vmw_stream, sres.res);
  49. }
  50. /***************************************************************************
  51. * Simple resource callbacks for struct vmw_stream
  52. **************************************************************************/
  53. static void vmw_stream_hw_destroy(struct vmw_resource *res)
  54. {
  55. struct vmw_private *dev_priv = res->dev_priv;
  56. struct vmw_stream *stream = vmw_stream(res);
  57. int ret;
  58. ret = vmw_overlay_unref(dev_priv, stream->stream_id);
  59. WARN_ON_ONCE(ret != 0);
  60. }
  61. static int vmw_stream_init(struct vmw_resource *res, void *data)
  62. {
  63. struct vmw_stream *stream = vmw_stream(res);
  64. return vmw_overlay_claim(res->dev_priv, &stream->stream_id);
  65. }
  66. static void vmw_stream_set_arg_handle(void *data, u32 handle)
  67. {
  68. struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data;
  69. arg->stream_id = handle;
  70. }
  71. static const struct vmw_simple_resource_func va_stream_func = {
  72. .res_func = {
  73. .res_type = vmw_res_stream,
  74. .needs_guest_memory = false,
  75. .may_evict = false,
  76. .type_name = "overlay stream",
  77. .domain = VMW_BO_DOMAIN_SYS,
  78. .busy_domain = VMW_BO_DOMAIN_SYS,
  79. .create = NULL,
  80. .destroy = NULL,
  81. .bind = NULL,
  82. .unbind = NULL
  83. },
  84. .ttm_res_type = VMW_RES_STREAM,
  85. .size = sizeof(struct vmw_stream),
  86. .init = vmw_stream_init,
  87. .hw_destroy = vmw_stream_hw_destroy,
  88. .set_arg_handle = vmw_stream_set_arg_handle,
  89. };
  90. /***************************************************************************
  91. * End simple resource callbacks for struct vmw_stream
  92. **************************************************************************/
  93. /**
  94. * vmw_stream_unref_ioctl - Ioctl to unreference a user-space handle to
  95. * a struct vmw_stream.
  96. * @dev: Pointer to the drm device.
  97. * @data: The ioctl argument
  98. * @file_priv: Pointer to a struct drm_file identifying the caller.
  99. *
  100. * Return:
  101. * 0 if successful.
  102. * Negative error value on failure.
  103. */
  104. int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
  105. struct drm_file *file_priv)
  106. {
  107. struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data;
  108. return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile,
  109. arg->stream_id);
  110. }
  111. /**
  112. * vmw_stream_claim_ioctl - Ioctl to claim a struct vmw_stream overlay.
  113. * @dev: Pointer to the drm device.
  114. * @data: The ioctl argument
  115. * @file_priv: Pointer to a struct drm_file identifying the caller.
  116. *
  117. * Return:
  118. * 0 if successful.
  119. * Negative error value on failure.
  120. */
  121. int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  122. struct drm_file *file_priv)
  123. {
  124. return vmw_simple_resource_create_ioctl(dev, data, file_priv,
  125. &va_stream_func);
  126. }
  127. /**
  128. * vmw_user_stream_lookup - Look up a struct vmw_user_stream from a handle.
  129. * @dev_priv: Pointer to a struct vmw_private.
  130. * @tfile: struct ttm_object_file identifying the caller.
  131. * @inout_id: In: The user-space handle. Out: The stream id.
  132. * @out: On output contains a refcounted pointer to the embedded
  133. * struct vmw_resource.
  134. *
  135. * Return:
  136. * 0 if successful.
  137. * Negative error value on failure.
  138. */
  139. int vmw_user_stream_lookup(struct vmw_private *dev_priv,
  140. struct ttm_object_file *tfile,
  141. uint32_t *inout_id, struct vmw_resource **out)
  142. {
  143. struct vmw_stream *stream;
  144. struct vmw_resource *res =
  145. vmw_simple_resource_lookup(tfile, *inout_id, &va_stream_func);
  146. if (IS_ERR(res))
  147. return PTR_ERR(res);
  148. stream = vmw_stream(res);
  149. *inout_id = stream->stream_id;
  150. *out = res;
  151. return 0;
  152. }