vmwgfx_resource_priv.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /**************************************************************************
  3. *
  4. * Copyright 2012-2014 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. #ifndef _VMWGFX_RESOURCE_PRIV_H_
  28. #define _VMWGFX_RESOURCE_PRIV_H_
  29. #include "vmwgfx_drv.h"
  30. /*
  31. * Extra memory required by the resource id's ida storage, which is allocated
  32. * separately from the base object itself. We estimate an on-average 128 bytes
  33. * per ida.
  34. */
  35. #define VMW_IDA_ACC_SIZE 128
  36. enum vmw_cmdbuf_res_state {
  37. VMW_CMDBUF_RES_COMMITTED,
  38. VMW_CMDBUF_RES_ADD,
  39. VMW_CMDBUF_RES_DEL
  40. };
  41. /**
  42. * struct vmw_user_resource_conv - Identify a derived user-exported resource
  43. * type and provide a function to convert its ttm_base_object pointer to
  44. * a struct vmw_resource
  45. */
  46. struct vmw_user_resource_conv {
  47. enum ttm_object_type object_type;
  48. struct vmw_resource *(*base_obj_to_res)(struct ttm_base_object *base);
  49. void (*res_free) (struct vmw_resource *res);
  50. };
  51. /**
  52. * struct vmw_res_func - members and functions common for a resource type
  53. *
  54. * @res_type: Enum that identifies the lru list to use for eviction.
  55. * @needs_guest_memory:Whether the resource is guest-backed and needs
  56. * persistent buffer storage.
  57. * @type_name: String that identifies the resource type.
  58. * @domain: TTM placement for guest memory buffers.
  59. * @busy_domain: TTM busy placement for guest memory buffers.
  60. * @may_evict Whether the resource may be evicted.
  61. * @create: Create a hardware resource.
  62. * @destroy: Destroy a hardware resource.
  63. * @bind: Bind a hardware resource to persistent buffer storage.
  64. * @unbind: Unbind a hardware resource from persistent
  65. * buffer storage.
  66. * @commit_notify: If the resource is a command buffer managed resource,
  67. * callback to notify that a define or remove command
  68. * has been committed to the device.
  69. * @dirty_alloc: Allocate a dirty tracker. NULL if dirty-tracking is not
  70. * supported.
  71. * @dirty_free: Free the dirty tracker.
  72. * @dirty_sync: Upload the dirty mob contents to the resource.
  73. * @dirty_add_range: Add a sequential dirty range to the resource
  74. * dirty tracker.
  75. * @clean: Clean the resource.
  76. */
  77. struct vmw_res_func {
  78. enum vmw_res_type res_type;
  79. bool needs_guest_memory;
  80. const char *type_name;
  81. u32 domain;
  82. u32 busy_domain;
  83. bool may_evict;
  84. u32 prio;
  85. u32 dirty_prio;
  86. int (*create) (struct vmw_resource *res);
  87. int (*destroy) (struct vmw_resource *res);
  88. int (*bind) (struct vmw_resource *res,
  89. struct ttm_validate_buffer *val_buf);
  90. int (*unbind) (struct vmw_resource *res,
  91. bool readback,
  92. struct ttm_validate_buffer *val_buf);
  93. void (*commit_notify)(struct vmw_resource *res,
  94. enum vmw_cmdbuf_res_state state);
  95. int (*dirty_alloc)(struct vmw_resource *res);
  96. void (*dirty_free)(struct vmw_resource *res);
  97. int (*dirty_sync)(struct vmw_resource *res);
  98. void (*dirty_range_add)(struct vmw_resource *res, size_t start,
  99. size_t end);
  100. int (*clean)(struct vmw_resource *res);
  101. };
  102. /**
  103. * struct vmw_simple_resource_func - members and functions common for the
  104. * simple resource helpers.
  105. * @res_func: struct vmw_res_func as described above.
  106. * @ttm_res_type: TTM resource type used for handle recognition.
  107. * @size: Size of the simple resource information struct.
  108. * @init: Initialize the simple resource information.
  109. * @hw_destroy: A resource hw_destroy function.
  110. * @set_arg_handle: Set the handle output argument of the ioctl create struct.
  111. */
  112. struct vmw_simple_resource_func {
  113. const struct vmw_res_func res_func;
  114. int ttm_res_type;
  115. size_t size;
  116. int (*init)(struct vmw_resource *res, void *data);
  117. void (*hw_destroy)(struct vmw_resource *res);
  118. void (*set_arg_handle)(void *data, u32 handle);
  119. };
  120. /**
  121. * struct vmw_simple_resource - Kernel only side simple resource
  122. * @res: The resource we derive from.
  123. * @func: The method and member virtual table.
  124. */
  125. struct vmw_simple_resource {
  126. struct vmw_resource res;
  127. const struct vmw_simple_resource_func *func;
  128. };
  129. int vmw_resource_alloc_id(struct vmw_resource *res);
  130. void vmw_resource_release_id(struct vmw_resource *res);
  131. int vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res,
  132. bool delay_id,
  133. void (*res_free) (struct vmw_resource *res),
  134. const struct vmw_res_func *func);
  135. int
  136. vmw_simple_resource_create_ioctl(struct drm_device *dev,
  137. void *data,
  138. struct drm_file *file_priv,
  139. const struct vmw_simple_resource_func *func);
  140. struct vmw_resource *
  141. vmw_simple_resource_lookup(struct ttm_object_file *tfile,
  142. uint32_t handle,
  143. const struct vmw_simple_resource_func *func);
  144. #endif