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
10struct nouveau_uvmm {
11 struct drm_gpuvm base;
12 struct nouveau_vmm vmm;
13 struct maple_tree region_mt;
14 struct mutex mutex;
15 struct dma_resv resv;
16
17 u64 kernel_managed_addr;
18 u64 kernel_managed_size;
19
20 bool disabled;
21};
22
23struct nouveau_uvma_region {
24 struct nouveau_uvmm *uvmm;
25
26 struct {
27 u64 addr;
28 u64 range;
29 } va;
30
31 struct kref kref;
32
33 struct completion complete;
34 bool dirty;
35};
36
37struct nouveau_uvma {
38 struct drm_gpuva va;
39
40 struct nouveau_uvma_region *region;
41 u8 kind;
42};
43
44#define uvmm_from_gpuvm(x) container_of((x), struct nouveau_uvmm, base)
45#define uvma_from_va(x) container_of((x), struct nouveau_uvma, va)
46
47#define to_uvmm(x) uvmm_from_gpuvm((x)->va.vm)
48
49struct nouveau_uvmm_bind_job {
50 struct nouveau_job base;
51
52 struct kref kref;
53 struct list_head entry;
54 struct work_struct work;
55 struct completion complete;
56
57 /* struct bind_job_op */
58 struct list_head ops;
59};
60
61struct nouveau_uvmm_bind_job_args {
62 struct drm_file *file_priv;
63 struct nouveau_sched_entity *sched_entity;
64
65 unsigned int flags;
66
67 struct {
68 struct drm_nouveau_sync *s;
69 u32 count;
70 } in_sync;
71
72 struct {
73 struct drm_nouveau_sync *s;
74 u32 count;
75 } out_sync;
76
77 struct {
78 struct drm_nouveau_vm_bind_op *s;
79 u32 count;
80 } op;
81};
82
83#define to_uvmm_bind_job(job) container_of((job), struct nouveau_uvmm_bind_job, base)
84
85int nouveau_uvmm_init(struct nouveau_uvmm *uvmm, struct nouveau_cli *cli,
86 u64 kernel_managed_addr, u64 kernel_managed_size);
87void nouveau_uvmm_fini(struct nouveau_uvmm *uvmm);
88
89void nouveau_uvmm_bo_map_all(struct nouveau_bo *nvbov, struct nouveau_mem *mem);
90void nouveau_uvmm_bo_unmap_all(struct nouveau_bo *nvbo);
91
92int nouveau_uvmm_ioctl_vm_init(struct drm_device *dev, void *data,
93 struct drm_file *file_priv);
94
95int nouveau_uvmm_ioctl_vm_bind(struct drm_device *dev, void *data,
96 struct drm_file *file_priv);
97
98static inline void nouveau_uvmm_lock(struct nouveau_uvmm *uvmm)
99{
100 mutex_lock(&uvmm->mutex);
101}
102
103static inline void nouveau_uvmm_unlock(struct nouveau_uvmm *uvmm)
104{
105 mutex_unlock(lock: &uvmm->mutex);
106}
107
108#endif
109

source code of linux/drivers/gpu/drm/nouveau/nouveau_uvmm.h