1#ifndef __NOUVEAU_BO_H__
2#define __NOUVEAU_BO_H__
3
4#include <drm/drm_gem.h>
5
6struct nouveau_channel;
7struct nouveau_fence;
8struct nouveau_vma;
9
10struct 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
20
21 struct drm_file *reserved_by;
22 struct list_head entry;
23 int pbbo_index;
24 bool validate_mapped;
25
26 struct list_head vma_list;
27 unsigned page_shift;
28
29 u32 tile_mode;
30 u32 tile_flags;
31 struct nouveau_drm_tile *tile;
32
33
34
35
36 struct drm_gem_object gem;
37
38
39 int pin_refcnt;
40
41 struct ttm_bo_kmap_obj dma_buf_vmap;
42};
43
44static inline struct nouveau_bo *
45nouveau_bo(struct ttm_buffer_object *bo)
46{
47 return container_of(bo, struct nouveau_bo, bo);
48}
49
50static inline int
51nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
52{
53 struct nouveau_bo *prev;
54
55 if (!pnvbo)
56 return -EINVAL;
57 prev = *pnvbo;
58
59 *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
60 if (prev) {
61 struct ttm_buffer_object *bo = &prev->bo;
62
63 ttm_bo_unref(&bo);
64 }
65
66 return 0;
67}
68
69extern struct ttm_bo_driver nouveau_bo_driver;
70
71void nouveau_bo_move_init(struct nouveau_drm *);
72int nouveau_bo_new(struct drm_device *, int size, int align, u32 flags,
73 u32 tile_mode, u32 tile_flags, struct sg_table *sg,
74 struct reservation_object *robj,
75 struct nouveau_bo **);
76int nouveau_bo_pin(struct nouveau_bo *, u32 flags, bool contig);
77int nouveau_bo_unpin(struct nouveau_bo *);
78int nouveau_bo_map(struct nouveau_bo *);
79void nouveau_bo_unmap(struct nouveau_bo *);
80void nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy);
81u16 nouveau_bo_rd16(struct nouveau_bo *, unsigned index);
82void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val);
83u32 nouveau_bo_rd32(struct nouveau_bo *, unsigned index);
84void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
85void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive);
86int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
87 bool no_wait_gpu);
88void nouveau_bo_sync_for_device(struct nouveau_bo *nvbo);
89void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo);
90
91struct nouveau_vma *
92nouveau_bo_vma_find(struct nouveau_bo *, struct nouveau_vm *);
93
94int nouveau_bo_vma_add(struct nouveau_bo *, struct nouveau_vm *,
95 struct nouveau_vma *);
96void nouveau_bo_vma_del(struct nouveau_bo *, struct nouveau_vma *);
97
98
99static inline void __iomem *
100nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
101{
102 bool is_iomem;
103 void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
104 &nvbo->kmap, &is_iomem);
105 WARN_ON_ONCE(ioptr && !is_iomem);
106 return ioptr;
107}
108
109#endif
110