xref: /linux/drivers/gpu/drm/nouveau/nouveau_uvmm.h (revision ab779466166348eecf17d20f620aa9a47965c934)
1 /* SPDX-License-Identifier: MIT */
2 
3 #ifndef __NOUVEAU_UVMM_H__
4 #define __NOUVEAU_UVMM_H__
5 
6 #include <drm/drm_gpuvm.h>
7 
8 #include "nouveau_drv.h"
9 
10 struct nouveau_uvmm {
11 	struct drm_gpuvm base;
12 	struct nouveau_vmm vmm;
13 	struct maple_tree region_mt;
14 	struct mutex mutex;
15 };
16 
17 struct nouveau_uvma_region {
18 	struct nouveau_uvmm *uvmm;
19 
20 	struct {
21 		u64 addr;
22 		u64 range;
23 	} va;
24 
25 	struct kref kref;
26 
27 	struct completion complete;
28 	bool dirty;
29 };
30 
31 struct nouveau_uvma {
32 	struct drm_gpuva va;
33 
34 	struct nouveau_uvma_region *region;
35 	u8 kind;
36 };
37 
38 #define uvmm_from_gpuvm(x) container_of((x), struct nouveau_uvmm, base)
39 #define uvma_from_va(x) container_of((x), struct nouveau_uvma, va)
40 
41 #define to_uvmm(x) uvmm_from_gpuvm((x)->va.vm)
42 
43 struct nouveau_uvmm_bind_job {
44 	struct nouveau_job base;
45 
46 	struct kref kref;
47 	struct list_head entry;
48 	struct work_struct work;
49 	struct completion complete;
50 
51 	/* struct bind_job_op */
52 	struct list_head ops;
53 };
54 
55 struct nouveau_uvmm_bind_job_args {
56 	struct drm_file *file_priv;
57 	struct nouveau_sched_entity *sched_entity;
58 
59 	unsigned int flags;
60 
61 	struct {
62 		struct drm_nouveau_sync *s;
63 		u32 count;
64 	} in_sync;
65 
66 	struct {
67 		struct drm_nouveau_sync *s;
68 		u32 count;
69 	} out_sync;
70 
71 	struct {
72 		struct drm_nouveau_vm_bind_op *s;
73 		u32 count;
74 	} op;
75 };
76 
77 #define to_uvmm_bind_job(job) container_of((job), struct nouveau_uvmm_bind_job, base)
78 
79 void nouveau_uvmm_fini(struct nouveau_uvmm *uvmm);
80 
81 void nouveau_uvmm_bo_map_all(struct nouveau_bo *nvbov, struct nouveau_mem *mem);
82 void nouveau_uvmm_bo_unmap_all(struct nouveau_bo *nvbo);
83 
84 int nouveau_uvmm_ioctl_vm_init(struct drm_device *dev, void *data,
85 			       struct drm_file *file_priv);
86 
87 int nouveau_uvmm_ioctl_vm_bind(struct drm_device *dev, void *data,
88 			       struct drm_file *file_priv);
89 
90 static inline void nouveau_uvmm_lock(struct nouveau_uvmm *uvmm)
91 {
92 	mutex_lock(&uvmm->mutex);
93 }
94 
95 static inline void nouveau_uvmm_unlock(struct nouveau_uvmm *uvmm)
96 {
97 	mutex_unlock(&uvmm->mutex);
98 }
99 
100 #endif
101