nouveau_bo.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef __NOUVEAU_BO_H__
  2. #define __NOUVEAU_BO_H__
  3. #include <drm/drm_gem.h>
  4. struct nouveau_channel;
  5. struct nouveau_fence;
  6. struct nvkm_vma;
  7. struct nouveau_bo {
  8. struct ttm_buffer_object bo;
  9. struct ttm_placement placement;
  10. u32 valid_domains;
  11. struct ttm_place placements[3];
  12. struct ttm_place busy_placements[3];
  13. bool force_coherent;
  14. struct ttm_bo_kmap_obj kmap;
  15. struct list_head head;
  16. /* protected by ttm_bo_reserve() */
  17. struct drm_file *reserved_by;
  18. struct list_head entry;
  19. int pbbo_index;
  20. bool validate_mapped;
  21. struct list_head vma_list;
  22. unsigned page_shift;
  23. struct nouveau_cli *cli;
  24. u32 tile_mode;
  25. u32 tile_flags;
  26. struct nouveau_drm_tile *tile;
  27. /* Only valid if allocated via nouveau_gem_new() and iff you hold a
  28. * gem reference to it! For debugging, use gem.filp != NULL to test
  29. * whether it is valid. */
  30. struct drm_gem_object gem;
  31. /* protect by the ttm reservation lock */
  32. int pin_refcnt;
  33. struct ttm_bo_kmap_obj dma_buf_vmap;
  34. };
  35. static inline struct nouveau_bo *
  36. nouveau_bo(struct ttm_buffer_object *bo)
  37. {
  38. return container_of(bo, struct nouveau_bo, bo);
  39. }
  40. static inline int
  41. nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
  42. {
  43. struct nouveau_bo *prev;
  44. if (!pnvbo)
  45. return -EINVAL;
  46. prev = *pnvbo;
  47. *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
  48. if (prev) {
  49. struct ttm_buffer_object *bo = &prev->bo;
  50. ttm_bo_unref(&bo);
  51. }
  52. return 0;
  53. }
  54. extern struct ttm_bo_driver nouveau_bo_driver;
  55. void nouveau_bo_move_init(struct nouveau_drm *);
  56. int nouveau_bo_new(struct nouveau_cli *, u64 size, int align, u32 flags,
  57. u32 tile_mode, u32 tile_flags, struct sg_table *sg,
  58. struct reservation_object *robj,
  59. struct nouveau_bo **);
  60. int nouveau_bo_pin(struct nouveau_bo *, u32 flags, bool contig);
  61. int nouveau_bo_unpin(struct nouveau_bo *);
  62. int nouveau_bo_map(struct nouveau_bo *);
  63. void nouveau_bo_unmap(struct nouveau_bo *);
  64. void nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy);
  65. void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val);
  66. u32 nouveau_bo_rd32(struct nouveau_bo *, unsigned index);
  67. void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
  68. void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive);
  69. int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
  70. bool no_wait_gpu);
  71. void nouveau_bo_sync_for_device(struct nouveau_bo *nvbo);
  72. void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo);
  73. struct nvkm_vma *
  74. nouveau_bo_vma_find(struct nouveau_bo *, struct nvkm_vm *);
  75. int nouveau_bo_vma_add(struct nouveau_bo *, struct nvkm_vm *,
  76. struct nvkm_vma *);
  77. void nouveau_bo_vma_del(struct nouveau_bo *, struct nvkm_vma *);
  78. /* TODO: submit equivalent to TTM generic API upstream? */
  79. static inline void __iomem *
  80. nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
  81. {
  82. bool is_iomem;
  83. void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
  84. &nvbo->kmap, &is_iomem);
  85. WARN_ON_ONCE(ioptr && !is_iomem);
  86. return ioptr;
  87. }
  88. #endif