blob: e42360983229960162d057f1e03422616f75a55f [file] [log] [blame]
Ben Skeggs8be21a62012-07-18 17:17:09 +10001#ifndef __NOUVEAU_BO_H__
2#define __NOUVEAU_BO_H__
3
Daniel Vetterd9fc9412014-09-23 15:46:53 +02004#include <drm/drm_gem.h>
5
Ben Skeggs8be21a62012-07-18 17:17:09 +10006struct nouveau_channel;
Ben Skeggsebb945a2012-07-20 08:17:34 +10007struct nouveau_fence;
Ben Skeggsbe83cd42015-01-14 15:36:34 +10008struct nvkm_vma;
Ben Skeggs8be21a62012-07-18 17:17:09 +10009
Ben Skeggs8be21a62012-07-18 17:17:09 +100010struct nouveau_bo {
11 struct ttm_buffer_object bo;
12 struct ttm_placement placement;
13 u32 valid_domains;
Christian Königf1217ed2014-08-27 13:16:04 +020014 struct ttm_place placements[3];
15 struct ttm_place busy_placements[3];
Alexandre Courbotc3a0c772014-10-27 18:49:17 +090016 bool force_coherent;
Ben Skeggs8be21a62012-07-18 17:17:09 +100017 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;
Ben Skeggsebb945a2012-07-20 08:17:34 +100031 struct nouveau_drm_tile *tile;
Ben Skeggs8be21a62012-07-18 17:17:09 +100032
David Herrmann55fb74a2013-10-02 10:15:17 +020033 /* 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;
Daniel Vetter0ae6d7b2012-12-11 21:52:30 +010037
38 /* protect by the ttm reservation lock */
Ben Skeggs8be21a62012-07-18 17:17:09 +100039 int pin_refcnt;
40
41 struct ttm_bo_kmap_obj dma_buf_vmap;
Ben Skeggs8be21a62012-07-18 17:17:09 +100042};
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
Ben Skeggs49981042012-08-06 19:38:25 +100071void nouveau_bo_move_init(struct nouveau_drm *);
Ben Skeggs8be21a62012-07-18 17:17:09 +100072int nouveau_bo_new(struct drm_device *, int size, int align, u32 flags,
73 u32 tile_mode, u32 tile_flags, struct sg_table *sg,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +010074 struct reservation_object *robj,
Ben Skeggs8be21a62012-07-18 17:17:09 +100075 struct nouveau_bo **);
Ben Skeggsad76b3f2014-11-10 11:24:27 +100076int nouveau_bo_pin(struct nouveau_bo *, u32 flags, bool contig);
Ben Skeggs8be21a62012-07-18 17:17:09 +100077int 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);
Ben Skeggs8be21a62012-07-18 17:17:09 +100081void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val);
82u32 nouveau_bo_rd32(struct nouveau_bo *, unsigned index);
83void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
Maarten Lankhorst809e9442014-04-09 16:19:30 +020084void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive);
Ben Skeggs8be21a62012-07-18 17:17:09 +100085int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
Maarten Lankhorst97a875c2012-11-28 11:25:44 +000086 bool no_wait_gpu);
Alexandre Courbotb22870b2014-10-27 18:49:19 +090087void nouveau_bo_sync_for_device(struct nouveau_bo *nvbo);
88void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo);
Ben Skeggs8be21a62012-07-18 17:17:09 +100089
Ben Skeggsbe83cd42015-01-14 15:36:34 +100090struct nvkm_vma *
91nouveau_bo_vma_find(struct nouveau_bo *, struct nvkm_vm *);
Ben Skeggs8be21a62012-07-18 17:17:09 +100092
Ben Skeggsbe83cd42015-01-14 15:36:34 +100093int nouveau_bo_vma_add(struct nouveau_bo *, struct nvkm_vm *,
94 struct nvkm_vma *);
95void nouveau_bo_vma_del(struct nouveau_bo *, struct nvkm_vma *);
Ben Skeggs8be21a62012-07-18 17:17:09 +100096
Ben Skeggsebb945a2012-07-20 08:17:34 +100097/* TODO: submit equivalent to TTM generic API upstream? */
98static inline void __iomem *
99nvbo_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
Ben Skeggs8be21a62012-07-18 17:17:09 +1000108#endif