1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NOUVEAU_BO_H__
3 #define __NOUVEAU_BO_H__
5 #include <drm/drm_gem.h>
7 struct nouveau_channel;
12 struct ttm_buffer_object bo;
13 struct ttm_placement placement;
15 struct ttm_place placements[3];
16 struct ttm_place busy_placements[3];
18 struct ttm_bo_kmap_obj kmap;
19 struct list_head head;
21 /* protected by ttm_bo_reserve() */
22 struct drm_file *reserved_by;
23 struct list_head entry;
27 /* GPU address space is independent of CPU word size */
30 struct list_head vma_list;
39 struct nouveau_drm_tile *tile;
41 /* protect by the ttm reservation lock */
44 struct ttm_bo_kmap_obj dma_buf_vmap;
47 static inline struct nouveau_bo *
48 nouveau_bo(struct ttm_buffer_object *bo)
50 return container_of(bo, struct nouveau_bo, bo);
54 nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
56 struct nouveau_bo *prev;
64 *pnvbo = nouveau_bo(&ref->bo);
69 ttm_bo_put(&prev->bo);
74 extern struct ttm_bo_driver nouveau_bo_driver;
76 void nouveau_bo_move_init(struct nouveau_drm *);
77 struct nouveau_bo *nouveau_bo_alloc(struct nouveau_cli *, u64 *size, int *align,
78 u32 flags, u32 tile_mode, u32 tile_flags);
79 int nouveau_bo_init(struct nouveau_bo *, u64 size, int align, u32 flags,
80 struct sg_table *sg, struct dma_resv *robj);
81 int nouveau_bo_new(struct nouveau_cli *, u64 size, int align, u32 flags,
82 u32 tile_mode, u32 tile_flags, struct sg_table *sg,
83 struct dma_resv *robj,
84 struct nouveau_bo **);
85 int nouveau_bo_pin(struct nouveau_bo *, u32 flags, bool contig);
86 int nouveau_bo_unpin(struct nouveau_bo *);
87 int nouveau_bo_map(struct nouveau_bo *);
88 void nouveau_bo_unmap(struct nouveau_bo *);
89 void nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy);
90 void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val);
91 u32 nouveau_bo_rd32(struct nouveau_bo *, unsigned index);
92 void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
93 void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive);
94 int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
96 void nouveau_bo_sync_for_device(struct nouveau_bo *nvbo);
97 void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo);
99 /* TODO: submit equivalent to TTM generic API upstream? */
100 static inline void __iomem *
101 nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
104 void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
105 &nvbo->kmap, &is_iomem);
106 WARN_ON_ONCE(ioptr && !is_iomem);
111 nouveau_bo_unmap_unpin_unref(struct nouveau_bo **pnvbo)
114 nouveau_bo_unmap(*pnvbo);
115 nouveau_bo_unpin(*pnvbo);
116 nouveau_bo_ref(NULL, pnvbo);
121 nouveau_bo_new_pin_map(struct nouveau_cli *cli, u64 size, int align, u32 flags,
122 struct nouveau_bo **pnvbo)
124 int ret = nouveau_bo_new(cli, size, align, flags,
125 0, 0, NULL, NULL, pnvbo);
127 ret = nouveau_bo_pin(*pnvbo, flags, true);
129 ret = nouveau_bo_map(*pnvbo);
132 nouveau_bo_unpin(*pnvbo);
134 nouveau_bo_ref(NULL, pnvbo);