nouveau_bo.h 2.7 KB

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