]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/nouveau/nouveau_bo.h
UBUNTU: Ubuntu-4.15.0-96.97
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / nouveau / nouveau_bo.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
8be21a64
BS
2#ifndef __NOUVEAU_BO_H__
3#define __NOUVEAU_BO_H__
4
d9fc9413
DV
5#include <drm/drm_gem.h>
6
8be21a64 7struct nouveau_channel;
ebb945a9 8struct nouveau_fence;
be83cd4e 9struct nvkm_vma;
8be21a64 10
8be21a64
BS
11struct nouveau_bo {
12 struct ttm_buffer_object bo;
13 struct ttm_placement placement;
14 u32 valid_domains;
f1217ed0
CK
15 struct ttm_place placements[3];
16 struct ttm_place busy_placements[3];
c3a0c771 17 bool force_coherent;
8be21a64
BS
18 struct ttm_bo_kmap_obj kmap;
19 struct list_head head;
20
21 /* protected by ttm_bo_reserve() */
22 struct drm_file *reserved_by;
23 struct list_head entry;
24 int pbbo_index;
25 bool validate_mapped;
26
27 struct list_head vma_list;
8be21a64 28
7760a2e3
BS
29 unsigned contig:1;
30 unsigned page:5;
31 unsigned kind:8;
32 unsigned comp:3;
33 unsigned zeta:3;
34 unsigned mode;
35
ebb945a9 36 struct nouveau_drm_tile *tile;
8be21a64 37
55fb74ad
DH
38 /* Only valid if allocated via nouveau_gem_new() and iff you hold a
39 * gem reference to it! For debugging, use gem.filp != NULL to test
40 * whether it is valid. */
41 struct drm_gem_object gem;
0ae6d7bc
DV
42
43 /* protect by the ttm reservation lock */
8be21a64
BS
44 int pin_refcnt;
45
46 struct ttm_bo_kmap_obj dma_buf_vmap;
8be21a64
BS
47};
48
49static inline struct nouveau_bo *
50nouveau_bo(struct ttm_buffer_object *bo)
51{
52 return container_of(bo, struct nouveau_bo, bo);
53}
54
55static inline int
56nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
57{
58 struct nouveau_bo *prev;
59
60 if (!pnvbo)
61 return -EINVAL;
62 prev = *pnvbo;
63
64 *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
65 if (prev) {
66 struct ttm_buffer_object *bo = &prev->bo;
67
68 ttm_bo_unref(&bo);
69 }
70
71 return 0;
72}
73
74extern struct ttm_bo_driver nouveau_bo_driver;
75
49981046 76void nouveau_bo_move_init(struct nouveau_drm *);
4d8b3d34 77int nouveau_bo_new(struct nouveau_cli *, u64 size, int align, u32 flags,
8be21a64 78 u32 tile_mode, u32 tile_flags, struct sg_table *sg,
bb6178b0 79 struct reservation_object *robj,
8be21a64 80 struct nouveau_bo **);
ad76b3f7 81int nouveau_bo_pin(struct nouveau_bo *, u32 flags, bool contig);
8be21a64
BS
82int nouveau_bo_unpin(struct nouveau_bo *);
83int nouveau_bo_map(struct nouveau_bo *);
84void nouveau_bo_unmap(struct nouveau_bo *);
85void nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy);
8be21a64
BS
86void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val);
87u32 nouveau_bo_rd32(struct nouveau_bo *, unsigned index);
88void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
809e9447 89void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive);
8be21a64 90int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
97a875cb 91 bool no_wait_gpu);
b22870ba
AC
92void nouveau_bo_sync_for_device(struct nouveau_bo *nvbo);
93void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo);
8be21a64 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