1
0

intel_bufmgr_priv.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Copyright © 2008 Intel Corporation
  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, sublicense,
  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 next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * 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 NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. *
  26. */
  27. /**
  28. * @file intel_bufmgr_priv.h
  29. *
  30. * Private definitions of Intel-specific bufmgr functions and structures.
  31. */
  32. #ifndef INTEL_BUFMGR_PRIV_H
  33. #define INTEL_BUFMGR_PRIV_H
  34. /**
  35. * Context for a buffer manager instance.
  36. *
  37. * Contains public methods followed by private storage for the buffer manager.
  38. */
  39. struct _drm_intel_bufmgr {
  40. /**
  41. * Allocate a buffer object.
  42. *
  43. * Buffer objects are not necessarily initially mapped into CPU virtual
  44. * address space or graphics device aperture. They must be mapped
  45. * using bo_map() or drm_intel_gem_bo_map_gtt() to be used by the CPU.
  46. */
  47. drm_intel_bo *(*bo_alloc) (drm_intel_bufmgr *bufmgr, const char *name,
  48. unsigned long size, unsigned int alignment);
  49. /**
  50. * Allocate a buffer object, hinting that it will be used as a
  51. * render target.
  52. *
  53. * This is otherwise the same as bo_alloc.
  54. */
  55. drm_intel_bo *(*bo_alloc_for_render) (drm_intel_bufmgr *bufmgr,
  56. const char *name,
  57. unsigned long size,
  58. unsigned int alignment);
  59. /**
  60. * Allocate a buffer object from an existing user accessible
  61. * address malloc'd with the provided size.
  62. * Alignment is used when mapping to the gtt.
  63. * Flags may be I915_VMAP_READ_ONLY or I915_USERPTR_UNSYNCHRONIZED
  64. */
  65. drm_intel_bo *(*bo_alloc_userptr)(drm_intel_bufmgr *bufmgr,
  66. const char *name, void *addr,
  67. uint32_t tiling_mode, uint32_t stride,
  68. unsigned long size,
  69. unsigned long flags);
  70. /**
  71. * Allocate a tiled buffer object.
  72. *
  73. * Alignment for tiled objects is set automatically; the 'flags'
  74. * argument provides a hint about how the object will be used initially.
  75. *
  76. * Valid tiling formats are:
  77. * I915_TILING_NONE
  78. * I915_TILING_X
  79. * I915_TILING_Y
  80. *
  81. * Note the tiling format may be rejected; callers should check the
  82. * 'tiling_mode' field on return, as well as the pitch value, which
  83. * may have been rounded up to accommodate for tiling restrictions.
  84. */
  85. drm_intel_bo *(*bo_alloc_tiled) (drm_intel_bufmgr *bufmgr,
  86. const char *name,
  87. int x, int y, int cpp,
  88. uint32_t *tiling_mode,
  89. unsigned long *pitch,
  90. unsigned long flags);
  91. /** Takes a reference on a buffer object */
  92. void (*bo_reference) (drm_intel_bo *bo);
  93. /**
  94. * Releases a reference on a buffer object, freeing the data if
  95. * no references remain.
  96. */
  97. void (*bo_unreference) (drm_intel_bo *bo);
  98. /**
  99. * Maps the buffer into userspace.
  100. *
  101. * This function will block waiting for any existing execution on the
  102. * buffer to complete, first. The resulting mapping is available at
  103. * buf->virtual.
  104. */
  105. int (*bo_map) (drm_intel_bo *bo, int write_enable);
  106. /**
  107. * Reduces the refcount on the userspace mapping of the buffer
  108. * object.
  109. */
  110. int (*bo_unmap) (drm_intel_bo *bo);
  111. /**
  112. * Write data into an object.
  113. *
  114. * This is an optional function, if missing,
  115. * drm_intel_bo will map/memcpy/unmap.
  116. */
  117. int (*bo_subdata) (drm_intel_bo *bo, unsigned long offset,
  118. unsigned long size, const void *data);
  119. /**
  120. * Read data from an object
  121. *
  122. * This is an optional function, if missing,
  123. * drm_intel_bo will map/memcpy/unmap.
  124. */
  125. int (*bo_get_subdata) (drm_intel_bo *bo, unsigned long offset,
  126. unsigned long size, void *data);
  127. /**
  128. * Waits for rendering to an object by the GPU to have completed.
  129. *
  130. * This is not required for any access to the BO by bo_map,
  131. * bo_subdata, etc. It is merely a way for the driver to implement
  132. * glFinish.
  133. */
  134. void (*bo_wait_rendering) (drm_intel_bo *bo);
  135. /**
  136. * Tears down the buffer manager instance.
  137. */
  138. void (*destroy) (drm_intel_bufmgr *bufmgr);
  139. /**
  140. * Indicate if the buffer can be placed anywhere in the full ppgtt
  141. * address range (2^48).
  142. *
  143. * Any resource used with flat/heapless (0x00000000-0xfffff000)
  144. * General State Heap (GSH) or Instructions State Heap (ISH) must
  145. * be in a 32-bit range. 48-bit range will only be used when explicitly
  146. * requested.
  147. *
  148. * \param bo Buffer to set the use_48b_address_range flag.
  149. * \param enable The flag value.
  150. */
  151. void (*bo_use_48b_address_range) (drm_intel_bo *bo, uint32_t enable);
  152. /**
  153. * Add relocation entry in reloc_buf, which will be updated with the
  154. * target buffer's real offset on on command submission.
  155. *
  156. * Relocations remain in place for the lifetime of the buffer object.
  157. *
  158. * \param bo Buffer to write the relocation into.
  159. * \param offset Byte offset within reloc_bo of the pointer to
  160. * target_bo.
  161. * \param target_bo Buffer whose offset should be written into the
  162. * relocation entry.
  163. * \param target_offset Constant value to be added to target_bo's
  164. * offset in relocation entry.
  165. * \param read_domains GEM read domains which the buffer will be
  166. * read into by the command that this relocation
  167. * is part of.
  168. * \param write_domains GEM read domains which the buffer will be
  169. * dirtied in by the command that this
  170. * relocation is part of.
  171. */
  172. int (*bo_emit_reloc) (drm_intel_bo *bo, uint32_t offset,
  173. drm_intel_bo *target_bo, uint32_t target_offset,
  174. uint32_t read_domains, uint32_t write_domain);
  175. int (*bo_emit_reloc_fence)(drm_intel_bo *bo, uint32_t offset,
  176. drm_intel_bo *target_bo,
  177. uint32_t target_offset,
  178. uint32_t read_domains,
  179. uint32_t write_domain);
  180. /** Executes the command buffer pointed to by bo. */
  181. int (*bo_exec) (drm_intel_bo *bo, int used,
  182. drm_clip_rect_t *cliprects, int num_cliprects,
  183. int DR4);
  184. /** Executes the command buffer pointed to by bo on the selected
  185. * ring buffer
  186. */
  187. int (*bo_mrb_exec) (drm_intel_bo *bo, int used,
  188. drm_clip_rect_t *cliprects, int num_cliprects,
  189. int DR4, unsigned flags);
  190. /**
  191. * Pin a buffer to the aperture and fix the offset until unpinned
  192. *
  193. * \param buf Buffer to pin
  194. * \param alignment Required alignment for aperture, in bytes
  195. */
  196. int (*bo_pin) (drm_intel_bo *bo, uint32_t alignment);
  197. /**
  198. * Unpin a buffer from the aperture, allowing it to be removed
  199. *
  200. * \param buf Buffer to unpin
  201. */
  202. int (*bo_unpin) (drm_intel_bo *bo);
  203. /**
  204. * Ask that the buffer be placed in tiling mode
  205. *
  206. * \param buf Buffer to set tiling mode for
  207. * \param tiling_mode desired, and returned tiling mode
  208. */
  209. int (*bo_set_tiling) (drm_intel_bo *bo, uint32_t * tiling_mode,
  210. uint32_t stride);
  211. /**
  212. * Get the current tiling (and resulting swizzling) mode for the bo.
  213. *
  214. * \param buf Buffer to get tiling mode for
  215. * \param tiling_mode returned tiling mode
  216. * \param swizzle_mode returned swizzling mode
  217. */
  218. int (*bo_get_tiling) (drm_intel_bo *bo, uint32_t * tiling_mode,
  219. uint32_t * swizzle_mode);
  220. /**
  221. * Set the offset at which this buffer will be softpinned
  222. * \param bo Buffer to set the softpin offset for
  223. * \param offset Softpin offset
  224. */
  225. int (*bo_set_softpin_offset) (drm_intel_bo *bo, uint64_t offset);
  226. /**
  227. * Create a visible name for a buffer which can be used by other apps
  228. *
  229. * \param buf Buffer to create a name for
  230. * \param name Returned name
  231. */
  232. int (*bo_flink) (drm_intel_bo *bo, uint32_t * name);
  233. /**
  234. * Returns 1 if mapping the buffer for write could cause the process
  235. * to block, due to the object being active in the GPU.
  236. */
  237. int (*bo_busy) (drm_intel_bo *bo);
  238. /**
  239. * Specify the volatility of the buffer.
  240. * \param bo Buffer to create a name for
  241. * \param madv The purgeable status
  242. *
  243. * Use I915_MADV_DONTNEED to mark the buffer as purgeable, and it will be
  244. * reclaimed under memory pressure. If you subsequently require the buffer,
  245. * then you must pass I915_MADV_WILLNEED to mark the buffer as required.
  246. *
  247. * Returns 1 if the buffer was retained, or 0 if it was discarded whilst
  248. * marked as I915_MADV_DONTNEED.
  249. */
  250. int (*bo_madvise) (drm_intel_bo *bo, int madv);
  251. int (*check_aperture_space) (drm_intel_bo ** bo_array, int count);
  252. /**
  253. * Disable buffer reuse for buffers which will be shared in some way,
  254. * as with scanout buffers. When the buffer reference count goes to
  255. * zero, it will be freed and not placed in the reuse list.
  256. *
  257. * \param bo Buffer to disable reuse for
  258. */
  259. int (*bo_disable_reuse) (drm_intel_bo *bo);
  260. /**
  261. * Query whether a buffer is reusable.
  262. *
  263. * \param bo Buffer to query
  264. */
  265. int (*bo_is_reusable) (drm_intel_bo *bo);
  266. /**
  267. *
  268. * Return the pipe associated with a crtc_id so that vblank
  269. * synchronization can use the correct data in the request.
  270. * This is only supported for KMS and gem at this point, when
  271. * unsupported, this function returns -1 and leaves the decision
  272. * of what to do in that case to the caller
  273. *
  274. * \param bufmgr the associated buffer manager
  275. * \param crtc_id the crtc identifier
  276. */
  277. int (*get_pipe_from_crtc_id) (drm_intel_bufmgr *bufmgr, int crtc_id);
  278. /** Returns true if target_bo is in the relocation tree rooted at bo. */
  279. int (*bo_references) (drm_intel_bo *bo, drm_intel_bo *target_bo);
  280. /**< Enables verbose debugging printouts */
  281. int debug;
  282. };
  283. struct _drm_intel_context {
  284. unsigned int ctx_id;
  285. struct _drm_intel_bufmgr *bufmgr;
  286. };
  287. #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1))
  288. #define ROUND_UP_TO(x, y) (((x) + (y) - 1) / (y) * (y))
  289. #define ROUND_UP_TO_MB(x) ROUND_UP_TO((x), 1024*1024)
  290. #endif /* INTEL_BUFMGR_PRIV_H */