Merge tag 'for-linus-20141015' of git://git.infradead.org/linux-mtd
[linux-2.6-block.git] / drivers / gpu / drm / nouveau / nouveau_bo.h
CommitLineData
8be21a64
BS
1#ifndef __NOUVEAU_BO_H__
2#define __NOUVEAU_BO_H__
3
d9fc9413
DV
4#include <drm/drm_gem.h>
5
8be21a64 6struct nouveau_channel;
ebb945a9 7struct nouveau_fence;
8be21a64
BS
8struct nouveau_vma;
9
8be21a64
BS
10struct 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];
8be21a64
BS
16 struct ttm_bo_kmap_obj kmap;
17 struct list_head head;
18
19 /* protected by ttm_bo_reserve() */
20 struct drm_file *reserved_by;
21 struct list_head entry;
22 int pbbo_index;
23 bool validate_mapped;
24
25 struct list_head vma_list;
26 unsigned page_shift;
27
28 u32 tile_mode;
29 u32 tile_flags;
ebb945a9 30 struct nouveau_drm_tile *tile;
8be21a64 31
55fb74ad
DH
32 /* Only valid if allocated via nouveau_gem_new() and iff you hold a
33 * gem reference to it! For debugging, use gem.filp != NULL to test
34 * whether it is valid. */
35 struct drm_gem_object gem;
0ae6d7bc
DV
36
37 /* protect by the ttm reservation lock */
8be21a64
BS
38 int pin_refcnt;
39
40 struct ttm_bo_kmap_obj dma_buf_vmap;
8be21a64
BS
41};
42
43static inline struct nouveau_bo *
44nouveau_bo(struct ttm_buffer_object *bo)
45{
46 return container_of(bo, struct nouveau_bo, bo);
47}
48
49static inline int
50nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
51{
52 struct nouveau_bo *prev;
53
54 if (!pnvbo)
55 return -EINVAL;
56 prev = *pnvbo;
57
58 *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
59 if (prev) {
60 struct ttm_buffer_object *bo = &prev->bo;
61
62 ttm_bo_unref(&bo);
63 }
64
65 return 0;
66}
67
68extern struct ttm_bo_driver nouveau_bo_driver;
69
49981046 70void nouveau_bo_move_init(struct nouveau_drm *);
8be21a64
BS
71int nouveau_bo_new(struct drm_device *, int size, int align, u32 flags,
72 u32 tile_mode, u32 tile_flags, struct sg_table *sg,
bb6178b0 73 struct reservation_object *robj,
8be21a64
BS
74 struct nouveau_bo **);
75int nouveau_bo_pin(struct nouveau_bo *, u32 flags);
76int nouveau_bo_unpin(struct nouveau_bo *);
77int nouveau_bo_map(struct nouveau_bo *);
78void nouveau_bo_unmap(struct nouveau_bo *);
79void nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy);
80u16 nouveau_bo_rd16(struct nouveau_bo *, unsigned index);
81void 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);
809e9447 84void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive);
8be21a64 85int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
97a875cb 86 bool no_wait_gpu);
8be21a64
BS
87
88struct nouveau_vma *
89nouveau_bo_vma_find(struct nouveau_bo *, struct nouveau_vm *);
90
91int nouveau_bo_vma_add(struct nouveau_bo *, struct nouveau_vm *,
92 struct nouveau_vma *);
93void nouveau_bo_vma_del(struct nouveau_bo *, struct nouveau_vma *);
94
ebb945a9
BS
95/* TODO: submit equivalent to TTM generic API upstream? */
96static inline void __iomem *
97nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
98{
99 bool is_iomem;
100 void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
101 &nvbo->kmap, &is_iomem);
102 WARN_ON_ONCE(ioptr && !is_iomem);
103 return ioptr;
104}
105
8be21a64 106#endif