summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nouveau/nouveau_uvmm.h
blob: fc7f6fd2a4e1be843309e89e62bcb0c30261978e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* SPDX-License-Identifier: MIT */

#ifndef __NOUVEAU_UVMM_H__
#define __NOUVEAU_UVMM_H__

#include <drm/drm_gpuva_mgr.h>

#include "nouveau_drv.h"

struct nouveau_uvmm {
	struct nouveau_vmm vmm;
	struct drm_gpuva_manager umgr;
	struct maple_tree region_mt;
	struct mutex mutex;
	struct dma_resv resv;

	u64 kernel_managed_addr;
	u64 kernel_managed_size;

	bool disabled;
};

struct nouveau_uvma_region {
	struct nouveau_uvmm *uvmm;

	struct {
		u64 addr;
		u64 range;
	} va;

	struct kref kref;

	struct completion complete;
	bool dirty;
};

struct nouveau_uvma {
	struct drm_gpuva va;

	struct nouveau_uvma_region *region;
	u8 kind;
};

#define uvmm_from_mgr(x) container_of((x), struct nouveau_uvmm, umgr)
#define uvma_from_va(x) container_of((x), struct nouveau_uvma, va)

#define to_uvmm(x) uvmm_from_mgr((x)->va.mgr)

struct nouveau_uvmm_bind_job {
	struct nouveau_job base;

	struct kref kref;
	struct list_head entry;
	struct work_struct work;
	struct completion complete;

	/* struct bind_job_op */
	struct list_head ops;
};

struct nouveau_uvmm_bind_job_args {
	struct drm_file *file_priv;
	struct nouveau_sched_entity *sched_entity;

	unsigned int flags;

	struct {
		struct drm_nouveau_sync *s;
		u32 count;
	} in_sync;

	struct {
		struct drm_nouveau_sync *s;
		u32 count;
	} out_sync;

	struct {
		struct drm_nouveau_vm_bind_op *s;
		u32 count;
	} op;
};

#define to_uvmm_bind_job(job) container_of((job), struct nouveau_uvmm_bind_job, base)

int nouveau_uvmm_init(struct nouveau_uvmm *uvmm, struct nouveau_cli *cli,
		      u64 kernel_managed_addr, u64 kernel_managed_size);
void nouveau_uvmm_fini(struct nouveau_uvmm *uvmm);

void nouveau_uvmm_bo_map_all(struct nouveau_bo *nvbov, struct nouveau_mem *mem);
void nouveau_uvmm_bo_unmap_all(struct nouveau_bo *nvbo);

int nouveau_uvmm_ioctl_vm_init(struct drm_device *dev, void *data,
			       struct drm_file *file_priv);

int nouveau_uvmm_ioctl_vm_bind(struct drm_device *dev, void *data,
			       struct drm_file *file_priv);

static inline void nouveau_uvmm_lock(struct nouveau_uvmm *uvmm)
{
	mutex_lock(&uvmm->mutex);
}

static inline void nouveau_uvmm_unlock(struct nouveau_uvmm *uvmm)
{
	mutex_unlock(&uvmm->mutex);
}

#endif