Commit | Line | Data |
---|---|---|
8be21a64 BS |
1 | #ifndef __NOUVEAU_BO_H__ |
2 | #define __NOUVEAU_BO_H__ | |
3 | ||
d9fc9413 DV |
4 | #include <drm/drm_gem.h> |
5 | ||
8be21a64 | 6 | struct nouveau_channel; |
ebb945a9 | 7 | struct nouveau_fence; |
be83cd4e | 8 | struct nvkm_vma; |
8be21a64 | 9 | |
8be21a64 BS |
10 | struct nouveau_bo { |
11 | struct ttm_buffer_object bo; | |
12 | struct ttm_placement placement; | |
13 | u32 valid_domains; | |
f1217ed0 CK |
14 | struct ttm_place placements[3]; |
15 | struct ttm_place busy_placements[3]; | |
c3a0c771 | 16 | bool force_coherent; |
8be21a64 BS |
17 | struct ttm_bo_kmap_obj kmap; |
18 | struct list_head head; | |
19 | ||
20 | /* protected by ttm_bo_reserve() */ | |
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; | |
ebb945a9 | 31 | struct nouveau_drm_tile *tile; |
8be21a64 | 32 | |
55fb74ad DH |
33 | /* Only valid if allocated via nouveau_gem_new() and iff you hold a |
34 | * gem reference to it! For debugging, use gem.filp != NULL to test | |
35 | * whether it is valid. */ | |
36 | struct drm_gem_object gem; | |
0ae6d7bc DV |
37 | |
38 | /* protect by the ttm reservation lock */ | |
8be21a64 BS |
39 | int pin_refcnt; |
40 | ||
41 | struct ttm_bo_kmap_obj dma_buf_vmap; | |
8be21a64 BS |
42 | }; |
43 | ||
44 | static inline struct nouveau_bo * | |
45 | nouveau_bo(struct ttm_buffer_object *bo) | |
46 | { | |
47 | return container_of(bo, struct nouveau_bo, bo); | |
48 | } | |
49 | ||
50 | static inline int | |
51 | nouveau_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 | ||
69 | extern struct ttm_bo_driver nouveau_bo_driver; | |
70 | ||
49981046 | 71 | void nouveau_bo_move_init(struct nouveau_drm *); |
8be21a64 BS |
72 | int nouveau_bo_new(struct drm_device *, int size, int align, u32 flags, |
73 | u32 tile_mode, u32 tile_flags, struct sg_table *sg, | |
bb6178b0 | 74 | struct reservation_object *robj, |
8be21a64 | 75 | struct nouveau_bo **); |
ad76b3f7 | 76 | int nouveau_bo_pin(struct nouveau_bo *, u32 flags, bool contig); |
8be21a64 BS |
77 | int nouveau_bo_unpin(struct nouveau_bo *); |
78 | int nouveau_bo_map(struct nouveau_bo *); | |
79 | void nouveau_bo_unmap(struct nouveau_bo *); | |
80 | void nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy); | |
8be21a64 BS |
81 | void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val); |
82 | u32 nouveau_bo_rd32(struct nouveau_bo *, unsigned index); | |
83 | void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val); | |
809e9447 | 84 | void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive); |
8be21a64 | 85 | int nouveau_bo_validate(struct nouveau_bo *, bool interruptible, |
97a875cb | 86 | bool no_wait_gpu); |
b22870ba AC |
87 | void nouveau_bo_sync_for_device(struct nouveau_bo *nvbo); |
88 | void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo); | |
8be21a64 | 89 | |
be83cd4e BS |
90 | struct nvkm_vma * |
91 | nouveau_bo_vma_find(struct nouveau_bo *, struct nvkm_vm *); | |
8be21a64 | 92 | |
be83cd4e BS |
93 | int nouveau_bo_vma_add(struct nouveau_bo *, struct nvkm_vm *, |
94 | struct nvkm_vma *); | |
95 | void nouveau_bo_vma_del(struct nouveau_bo *, struct nvkm_vma *); | |
8be21a64 | 96 | |
ebb945a9 BS |
97 | /* TODO: submit equivalent to TTM generic API upstream? */ |
98 | static inline void __iomem * | |
99 | nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo) | |
100 | { | |
101 | bool is_iomem; | |
102 | void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual( | |
103 | &nvbo->kmap, &is_iomem); | |
104 | WARN_ON_ONCE(ioptr && !is_iomem); | |
105 | return ioptr; | |
106 | } | |
107 | ||
8be21a64 | 108 | #endif |