nouveau_bo.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. struct drm_gem_object *gem;
  25. int pin_refcnt;
  26. struct ttm_bo_kmap_obj dma_buf_vmap;
  27. int vmapping_count;
  28. };
  29. static inline struct nouveau_bo *
  30. nouveau_bo(struct ttm_buffer_object *bo)
  31. {
  32. return container_of(bo, struct nouveau_bo, bo);
  33. }
  34. static inline int
  35. nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
  36. {
  37. struct nouveau_bo *prev;
  38. if (!pnvbo)
  39. return -EINVAL;
  40. prev = *pnvbo;
  41. *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
  42. if (prev) {
  43. struct ttm_buffer_object *bo = &prev->bo;
  44. ttm_bo_unref(&bo);
  45. }
  46. return 0;
  47. }
  48. extern struct ttm_bo_driver nouveau_bo_driver;
  49. void nouveau_bo_move_init(struct nouveau_drm *);
  50. int nouveau_bo_new(struct drm_device *, int size, int align, u32 flags,
  51. u32 tile_mode, u32 tile_flags, struct sg_table *sg,
  52. struct nouveau_bo **);
  53. int nouveau_bo_pin(struct nouveau_bo *, u32 flags);
  54. int nouveau_bo_unpin(struct nouveau_bo *);
  55. int nouveau_bo_map(struct nouveau_bo *);
  56. void nouveau_bo_unmap(struct nouveau_bo *);
  57. void nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy);
  58. u16 nouveau_bo_rd16(struct nouveau_bo *, unsigned index);
  59. void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val);
  60. u32 nouveau_bo_rd32(struct nouveau_bo *, unsigned index);
  61. void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
  62. void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *);
  63. int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
  64. bool no_wait_gpu);
  65. struct nouveau_vma *
  66. nouveau_bo_vma_find(struct nouveau_bo *, struct nouveau_vm *);
  67. int nouveau_bo_vma_add(struct nouveau_bo *, struct nouveau_vm *,
  68. struct nouveau_vma *);
  69. void nouveau_bo_vma_del(struct nouveau_bo *, struct nouveau_vma *);
  70. /* TODO: submit equivalent to TTM generic API upstream? */
  71. static inline void __iomem *
  72. nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
  73. {
  74. bool is_iomem;
  75. void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
  76. &nvbo->kmap, &is_iomem);
  77. WARN_ON_ONCE(ioptr && !is_iomem);
  78. return ioptr;
  79. }
  80. #endif