1 /* SPDX-License-Identifier: GPL-2.0 */
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 struct list_head vma_list
;
30 struct nouveau_cli
*cli
;
34 struct nouveau_drm_tile
*tile
;
36 /* Only valid if allocated via nouveau_gem_new() and iff you hold a
37 * gem reference to it! For debugging, use gem.filp != NULL to test
38 * whether it is valid. */
39 struct drm_gem_object gem
;
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
;
62 *pnvbo
= ref
? nouveau_bo(ttm_bo_reference(&ref
->bo
)) : NULL
;
64 struct ttm_buffer_object
*bo
= &prev
->bo
;
72 extern struct ttm_bo_driver nouveau_bo_driver
;
74 void nouveau_bo_move_init(struct nouveau_drm
*);
75 int nouveau_bo_new(struct nouveau_cli
*, u64 size
, int align
, u32 flags
,
76 u32 tile_mode
, u32 tile_flags
, struct sg_table
*sg
,
77 struct reservation_object
*robj
,
78 struct nouveau_bo
**);
79 int nouveau_bo_pin(struct nouveau_bo
*, u32 flags
, bool contig
);
80 int nouveau_bo_unpin(struct nouveau_bo
*);
81 int nouveau_bo_map(struct nouveau_bo
*);
82 void nouveau_bo_unmap(struct nouveau_bo
*);
83 void nouveau_bo_placement_set(struct nouveau_bo
*, u32 type
, u32 busy
);
84 void nouveau_bo_wr16(struct nouveau_bo
*, unsigned index
, u16 val
);
85 u32
nouveau_bo_rd32(struct nouveau_bo
*, unsigned index
);
86 void nouveau_bo_wr32(struct nouveau_bo
*, unsigned index
, u32 val
);
87 void nouveau_bo_fence(struct nouveau_bo
*, struct nouveau_fence
*, bool exclusive
);
88 int nouveau_bo_validate(struct nouveau_bo
*, bool interruptible
,
90 void nouveau_bo_sync_for_device(struct nouveau_bo
*nvbo
);
91 void nouveau_bo_sync_for_cpu(struct nouveau_bo
*nvbo
);
94 nouveau_bo_vma_find(struct nouveau_bo
*, struct nvkm_vm
*);
96 int nouveau_bo_vma_add(struct nouveau_bo
*, struct nvkm_vm
*,
98 void nouveau_bo_vma_del(struct nouveau_bo
*, struct nvkm_vma
*);
100 /* TODO: submit equivalent to TTM generic API upstream? */
101 static inline void __iomem
*
102 nvbo_kmap_obj_iovirtual(struct nouveau_bo
*nvbo
)
105 void __iomem
*ioptr
= (void __force __iomem
*)ttm_kmap_obj_virtual(
106 &nvbo
->kmap
, &is_iomem
);
107 WARN_ON_ONCE(ioptr
&& !is_iomem
);