nouveau_bo.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* SPDX-License-Identifier: MIT */
  2. #ifndef __NOUVEAU_BO_H__
  3. #define __NOUVEAU_BO_H__
  4. #include <drm/ttm/ttm_bo_driver.h>
  5. #include <drm/drm_gem.h>
  6. struct nouveau_channel;
  7. struct nouveau_cli;
  8. struct nouveau_drm;
  9. struct nouveau_fence;
  10. struct nouveau_bo {
  11. struct ttm_buffer_object bo;
  12. struct ttm_placement placement;
  13. u32 valid_domains;
  14. struct ttm_place placements[3];
  15. struct ttm_place busy_placements[3];
  16. bool force_coherent;
  17. struct ttm_bo_kmap_obj kmap;
  18. struct list_head head;
  19. struct list_head io_reserve_lru;
  20. /* protected by ttm_bo_reserve() */
  21. struct drm_file *reserved_by;
  22. struct list_head entry;
  23. int pbbo_index;
  24. bool validate_mapped;
  25. /* GPU address space is independent of CPU word size */
  26. uint64_t offset;
  27. struct list_head vma_list;
  28. unsigned contig:1;
  29. unsigned page:5;
  30. unsigned kind:8;
  31. unsigned comp:3;
  32. unsigned zeta:3;
  33. unsigned mode;
  34. struct nouveau_drm_tile *tile;
  35. };
  36. static inline struct nouveau_bo *
  37. nouveau_bo(struct ttm_buffer_object *bo)
  38. {
  39. return container_of(bo, struct nouveau_bo, bo);
  40. }
  41. static inline int
  42. nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
  43. {
  44. struct nouveau_bo *prev;
  45. if (!pnvbo)
  46. return -EINVAL;
  47. prev = *pnvbo;
  48. if (ref) {
  49. ttm_bo_get(&ref->bo);
  50. *pnvbo = nouveau_bo(&ref->bo);
  51. } else {
  52. *pnvbo = NULL;
  53. }
  54. if (prev)
  55. ttm_bo_put(&prev->bo);
  56. return 0;
  57. }
  58. extern struct ttm_device_funcs nouveau_bo_driver;
  59. void nouveau_bo_move_init(struct nouveau_drm *);
  60. struct nouveau_bo *nouveau_bo_alloc(struct nouveau_cli *, u64 *size, int *align,
  61. u32 domain, u32 tile_mode, u32 tile_flags);
  62. int nouveau_bo_init(struct nouveau_bo *, u64 size, int align, u32 domain,
  63. struct sg_table *sg, struct dma_resv *robj);
  64. int nouveau_bo_new(struct nouveau_cli *, u64 size, int align, u32 domain,
  65. u32 tile_mode, u32 tile_flags, struct sg_table *sg,
  66. struct dma_resv *robj,
  67. struct nouveau_bo **);
  68. int nouveau_bo_pin(struct nouveau_bo *, u32 flags, bool contig);
  69. int nouveau_bo_unpin(struct nouveau_bo *);
  70. int nouveau_bo_map(struct nouveau_bo *);
  71. void nouveau_bo_unmap(struct nouveau_bo *);
  72. void nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy);
  73. void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val);
  74. u32 nouveau_bo_rd32(struct nouveau_bo *, unsigned index);
  75. void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
  76. vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo);
  77. void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive);
  78. int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
  79. bool no_wait_gpu);
  80. void nouveau_bo_sync_for_device(struct nouveau_bo *nvbo);
  81. void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo);
  82. void nouveau_bo_add_io_reserve_lru(struct ttm_buffer_object *bo);
  83. void nouveau_bo_del_io_reserve_lru(struct ttm_buffer_object *bo);
  84. /* TODO: submit equivalent to TTM generic API upstream? */
  85. static inline void __iomem *
  86. nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
  87. {
  88. bool is_iomem;
  89. void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
  90. &nvbo->kmap, &is_iomem);
  91. WARN_ON_ONCE(ioptr && !is_iomem);
  92. return ioptr;
  93. }
  94. static inline void
  95. nouveau_bo_unmap_unpin_unref(struct nouveau_bo **pnvbo)
  96. {
  97. if (*pnvbo) {
  98. nouveau_bo_unmap(*pnvbo);
  99. nouveau_bo_unpin(*pnvbo);
  100. nouveau_bo_ref(NULL, pnvbo);
  101. }
  102. }
  103. static inline int
  104. nouveau_bo_new_pin_map(struct nouveau_cli *cli, u64 size, int align, u32 domain,
  105. struct nouveau_bo **pnvbo)
  106. {
  107. int ret = nouveau_bo_new(cli, size, align, domain,
  108. 0, 0, NULL, NULL, pnvbo);
  109. if (ret == 0) {
  110. ret = nouveau_bo_pin(*pnvbo, domain, true);
  111. if (ret == 0) {
  112. ret = nouveau_bo_map(*pnvbo);
  113. if (ret == 0)
  114. return ret;
  115. nouveau_bo_unpin(*pnvbo);
  116. }
  117. nouveau_bo_ref(NULL, pnvbo);
  118. }
  119. return ret;
  120. }
  121. int nv04_bo_move_init(struct nouveau_channel *, u32);
  122. int nv04_bo_move_m2mf(struct nouveau_channel *, struct ttm_buffer_object *,
  123. struct ttm_resource *, struct ttm_resource *);
  124. int nv50_bo_move_init(struct nouveau_channel *, u32);
  125. int nv50_bo_move_m2mf(struct nouveau_channel *, struct ttm_buffer_object *,
  126. struct ttm_resource *, struct ttm_resource *);
  127. int nv84_bo_move_exec(struct nouveau_channel *, struct ttm_buffer_object *,
  128. struct ttm_resource *, struct ttm_resource *);
  129. int nva3_bo_move_copy(struct nouveau_channel *, struct ttm_buffer_object *,
  130. struct ttm_resource *, struct ttm_resource *);
  131. int nvc0_bo_move_init(struct nouveau_channel *, u32);
  132. int nvc0_bo_move_m2mf(struct nouveau_channel *, struct ttm_buffer_object *,
  133. struct ttm_resource *, struct ttm_resource *);
  134. int nvc0_bo_move_copy(struct nouveau_channel *, struct ttm_buffer_object *,
  135. struct ttm_resource *, struct ttm_resource *);
  136. int nve0_bo_move_init(struct nouveau_channel *, u32);
  137. int nve0_bo_move_copy(struct nouveau_channel *, struct ttm_buffer_object *,
  138. struct ttm_resource *, struct ttm_resource *);
  139. #define NVBO_WR32_(b,o,dr,f) nouveau_bo_wr32((b), (o)/4 + (dr), (f))
  140. #define NVBO_RD32_(b,o,dr) nouveau_bo_rd32((b), (o)/4 + (dr))
  141. #define NVBO_RD32(A...) DRF_RD(NVBO_RD32_, ##A)
  142. #define NVBO_RV32(A...) DRF_RV(NVBO_RD32_, ##A)
  143. #define NVBO_TV32(A...) DRF_TV(NVBO_RD32_, ##A)
  144. #define NVBO_TD32(A...) DRF_TD(NVBO_RD32_, ##A)
  145. #define NVBO_WR32(A...) DRF_WR( NVBO_WR32_, ##A)
  146. #define NVBO_WV32(A...) DRF_WV( NVBO_WR32_, ##A)
  147. #define NVBO_WD32(A...) DRF_WD( NVBO_WR32_, ##A)
  148. #define NVBO_MR32(A...) DRF_MR(NVBO_RD32_, NVBO_WR32_, u32, ##A)
  149. #define NVBO_MV32(A...) DRF_MV(NVBO_RD32_, NVBO_WR32_, u32, ##A)
  150. #define NVBO_MD32(A...) DRF_MD(NVBO_RD32_, NVBO_WR32_, u32, ##A)
  151. #endif