vmwgfx_resource_priv.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #define VMW_IDA_ACC_SIZE 128
  31. enum vmw_cmdbuf_res_state {
  32. VMW_CMDBUF_RES_COMMITTED,
  33. VMW_CMDBUF_RES_ADD,
  34. VMW_CMDBUF_RES_DEL
  35. };
  36. /**
  37. * struct vmw_user_resource_conv - Identify a derived user-exported resource
  38. * type and provide a function to convert its ttm_base_object pointer to
  39. * a struct vmw_resource
  40. */
  41. struct vmw_user_resource_conv {
  42. enum ttm_object_type object_type;
  43. struct vmw_resource *(*base_obj_to_res)(struct ttm_base_object *base);
  44. void (*res_free) (struct vmw_resource *res);
  45. };
  46. /**
  47. * struct vmw_res_func - members and functions common for a resource type
  48. *
  49. * @res_type: Enum that identifies the lru list to use for eviction.
  50. * @needs_backup: Whether the resource is guest-backed and needs
  51. * persistent buffer storage.
  52. * @type_name: String that identifies the resource type.
  53. * @backup_placement: TTM placement for backup buffers.
  54. * @may_evict Whether the resource may be evicted.
  55. * @create: Create a hardware resource.
  56. * @destroy: Destroy a hardware resource.
  57. * @bind: Bind a hardware resource to persistent buffer storage.
  58. * @unbind: Unbind a hardware resource from persistent
  59. * buffer storage.
  60. * @commit_notify: If the resource is a command buffer managed resource,
  61. * callback to notify that a define or remove command
  62. * has been committed to the device.
  63. */
  64. struct vmw_res_func {
  65. enum vmw_res_type res_type;
  66. bool needs_backup;
  67. const char *type_name;
  68. struct ttm_placement *backup_placement;
  69. bool may_evict;
  70. int (*create) (struct vmw_resource *res);
  71. int (*destroy) (struct vmw_resource *res);
  72. int (*bind) (struct vmw_resource *res,
  73. struct ttm_validate_buffer *val_buf);
  74. int (*unbind) (struct vmw_resource *res,
  75. bool readback,
  76. struct ttm_validate_buffer *val_buf);
  77. void (*commit_notify)(struct vmw_resource *res,
  78. enum vmw_cmdbuf_res_state state);
  79. };
  80. /**
  81. * struct vmw_simple_resource_func - members and functions common for the
  82. * simple resource helpers.
  83. * @res_func: struct vmw_res_func as described above.
  84. * @ttm_res_type: TTM resource type used for handle recognition.
  85. * @size: Size of the simple resource information struct.
  86. * @init: Initialize the simple resource information.
  87. * @hw_destroy: A resource hw_destroy function.
  88. * @set_arg_handle: Set the handle output argument of the ioctl create struct.
  89. */
  90. struct vmw_simple_resource_func {
  91. const struct vmw_res_func res_func;
  92. int ttm_res_type;
  93. size_t size;
  94. int (*init)(struct vmw_resource *res, void *data);
  95. void (*hw_destroy)(struct vmw_resource *res);
  96. void (*set_arg_handle)(void *data, u32 handle);
  97. };
  98. /**
  99. * struct vmw_simple_resource - Kernel only side simple resource
  100. * @res: The resource we derive from.
  101. * @func: The method and member virtual table.
  102. */
  103. struct vmw_simple_resource {
  104. struct vmw_resource res;
  105. const struct vmw_simple_resource_func *func;
  106. };
  107. int vmw_resource_alloc_id(struct vmw_resource *res);
  108. void vmw_resource_release_id(struct vmw_resource *res);
  109. int vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res,
  110. bool delay_id,
  111. void (*res_free) (struct vmw_resource *res),
  112. const struct vmw_res_func *func);
  113. void vmw_resource_activate(struct vmw_resource *res,
  114. void (*hw_destroy) (struct vmw_resource *));
  115. int
  116. vmw_simple_resource_create_ioctl(struct drm_device *dev,
  117. void *data,
  118. struct drm_file *file_priv,
  119. const struct vmw_simple_resource_func *func);
  120. struct vmw_resource *
  121. vmw_simple_resource_lookup(struct ttm_object_file *tfile,
  122. uint32_t handle,
  123. const struct vmw_simple_resource_func *func);
  124. #endif