radeon_object.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #ifndef __RADEON_OBJECT_H__
  29. #define __RADEON_OBJECT_H__
  30. #include <drm/radeon_drm.h>
  31. #include "radeon.h"
  32. /**
  33. * radeon_mem_type_to_domain - return domain corresponding to mem_type
  34. * @mem_type: ttm memory type
  35. *
  36. * Returns corresponding domain of the ttm mem_type
  37. */
  38. static inline unsigned radeon_mem_type_to_domain(u32 mem_type)
  39. {
  40. switch (mem_type) {
  41. case TTM_PL_VRAM:
  42. return RADEON_GEM_DOMAIN_VRAM;
  43. case TTM_PL_TT:
  44. return RADEON_GEM_DOMAIN_GTT;
  45. case TTM_PL_SYSTEM:
  46. return RADEON_GEM_DOMAIN_CPU;
  47. default:
  48. break;
  49. }
  50. return 0;
  51. }
  52. /**
  53. * radeon_bo_reserve - reserve bo
  54. * @bo: bo structure
  55. * @no_intr: don't return -ERESTARTSYS on pending signal
  56. *
  57. * Returns:
  58. * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by
  59. * a signal. Release all buffer reservations and return to user-space.
  60. */
  61. static inline int radeon_bo_reserve(struct radeon_bo *bo, bool no_intr)
  62. {
  63. int r;
  64. r = ttm_bo_reserve(&bo->tbo, !no_intr, false, NULL);
  65. if (unlikely(r != 0)) {
  66. if (r != -ERESTARTSYS)
  67. dev_err(bo->rdev->dev, "%p reserve failed\n", bo);
  68. return r;
  69. }
  70. return 0;
  71. }
  72. static inline void radeon_bo_unreserve(struct radeon_bo *bo)
  73. {
  74. ttm_bo_unreserve(&bo->tbo);
  75. }
  76. /**
  77. * radeon_bo_gpu_offset - return GPU offset of bo
  78. * @bo: radeon object for which we query the offset
  79. *
  80. * Returns current GPU offset of the object.
  81. *
  82. * Note: object should either be pinned or reserved when calling this
  83. * function, it might be useful to add check for this for debugging.
  84. */
  85. static inline u64 radeon_bo_gpu_offset(struct radeon_bo *bo)
  86. {
  87. struct radeon_device *rdev;
  88. u64 start = 0;
  89. rdev = radeon_get_rdev(bo->tbo.bdev);
  90. switch (bo->tbo.resource->mem_type) {
  91. case TTM_PL_TT:
  92. start = rdev->mc.gtt_start;
  93. break;
  94. case TTM_PL_VRAM:
  95. start = rdev->mc.vram_start;
  96. break;
  97. }
  98. return (bo->tbo.resource->start << PAGE_SHIFT) + start;
  99. }
  100. static inline unsigned long radeon_bo_size(struct radeon_bo *bo)
  101. {
  102. return bo->tbo.base.size;
  103. }
  104. static inline unsigned radeon_bo_ngpu_pages(struct radeon_bo *bo)
  105. {
  106. return bo->tbo.base.size / RADEON_GPU_PAGE_SIZE;
  107. }
  108. static inline unsigned radeon_bo_gpu_page_alignment(struct radeon_bo *bo)
  109. {
  110. return (bo->tbo.page_alignment << PAGE_SHIFT) / RADEON_GPU_PAGE_SIZE;
  111. }
  112. /**
  113. * radeon_bo_mmap_offset - return mmap offset of bo
  114. * @bo: radeon object for which we query the offset
  115. *
  116. * Returns mmap offset of the object.
  117. */
  118. static inline u64 radeon_bo_mmap_offset(struct radeon_bo *bo)
  119. {
  120. return drm_vma_node_offset_addr(&bo->tbo.base.vma_node);
  121. }
  122. extern int radeon_bo_create(struct radeon_device *rdev,
  123. unsigned long size, int byte_align,
  124. bool kernel, u32 domain, u32 flags,
  125. struct sg_table *sg,
  126. struct dma_resv *resv,
  127. struct radeon_bo **bo_ptr);
  128. extern int radeon_bo_kmap(struct radeon_bo *bo, void **ptr);
  129. extern void radeon_bo_kunmap(struct radeon_bo *bo);
  130. extern struct radeon_bo *radeon_bo_ref(struct radeon_bo *bo);
  131. extern void radeon_bo_unref(struct radeon_bo **bo);
  132. extern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr);
  133. extern int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain,
  134. u64 max_offset, u64 *gpu_addr);
  135. extern void radeon_bo_unpin(struct radeon_bo *bo);
  136. extern int radeon_bo_evict_vram(struct radeon_device *rdev);
  137. extern void radeon_bo_force_delete(struct radeon_device *rdev);
  138. extern int radeon_bo_init(struct radeon_device *rdev);
  139. extern void radeon_bo_fini(struct radeon_device *rdev);
  140. extern int radeon_bo_list_validate(struct radeon_device *rdev,
  141. struct ww_acquire_ctx *ticket,
  142. struct list_head *head, int ring);
  143. extern int radeon_bo_set_tiling_flags(struct radeon_bo *bo,
  144. u32 tiling_flags, u32 pitch);
  145. extern void radeon_bo_get_tiling_flags(struct radeon_bo *bo,
  146. u32 *tiling_flags, u32 *pitch);
  147. extern int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved,
  148. bool force_drop);
  149. extern void radeon_bo_move_notify(struct ttm_buffer_object *bo);
  150. extern vm_fault_t radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo);
  151. extern int radeon_bo_get_surface_reg(struct radeon_bo *bo);
  152. extern void radeon_bo_fence(struct radeon_bo *bo, struct radeon_fence *fence,
  153. bool shared);
  154. /*
  155. * sub allocation
  156. */
  157. static inline uint64_t radeon_sa_bo_gpu_addr(struct radeon_sa_bo *sa_bo)
  158. {
  159. return sa_bo->manager->gpu_addr + sa_bo->soffset;
  160. }
  161. static inline void * radeon_sa_bo_cpu_addr(struct radeon_sa_bo *sa_bo)
  162. {
  163. return sa_bo->manager->cpu_ptr + sa_bo->soffset;
  164. }
  165. extern int radeon_sa_bo_manager_init(struct radeon_device *rdev,
  166. struct radeon_sa_manager *sa_manager,
  167. unsigned size, u32 align, u32 domain,
  168. u32 flags);
  169. extern void radeon_sa_bo_manager_fini(struct radeon_device *rdev,
  170. struct radeon_sa_manager *sa_manager);
  171. extern int radeon_sa_bo_manager_start(struct radeon_device *rdev,
  172. struct radeon_sa_manager *sa_manager);
  173. extern int radeon_sa_bo_manager_suspend(struct radeon_device *rdev,
  174. struct radeon_sa_manager *sa_manager);
  175. extern int radeon_sa_bo_new(struct radeon_device *rdev,
  176. struct radeon_sa_manager *sa_manager,
  177. struct radeon_sa_bo **sa_bo,
  178. unsigned size, unsigned align);
  179. extern void radeon_sa_bo_free(struct radeon_device *rdev,
  180. struct radeon_sa_bo **sa_bo,
  181. struct radeon_fence *fence);
  182. #if defined(CONFIG_DEBUG_FS)
  183. extern void radeon_sa_bo_dump_debug_info(struct radeon_sa_manager *sa_manager,
  184. struct seq_file *m);
  185. #endif
  186. #endif