xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drv.h (revision 770c9d53527f316421c021ddaa11b2f94d5fbbc7)
1 /*	$NetBSD: nouveau_drv.h,v 1.5 2024/04/16 14:34:02 riastradh Exp $	*/
2 
3 /* SPDX-License-Identifier: MIT */
4 #ifndef __NOUVEAU_DRV_H__
5 #define __NOUVEAU_DRV_H__
6 
7 #define DRIVER_AUTHOR		"Nouveau Project"
8 #define DRIVER_EMAIL		"nouveau@lists.freedesktop.org"
9 
10 #define DRIVER_NAME		"nouveau"
11 #define DRIVER_DESC		"nVidia Riva/TNT/GeForce/Quadro/Tesla/Tegra K1+"
12 #define DRIVER_DATE		"20120801"
13 
14 #define DRIVER_MAJOR		1
15 #define DRIVER_MINOR		3
16 #define DRIVER_PATCHLEVEL	1
17 
18 /*
19  * 1.1.1:
20  * 	- added support for tiled system memory buffer objects
21  *      - added support for NOUVEAU_GETPARAM_GRAPH_UNITS on [nvc0,nve0].
22  *      - added support for compressed memory storage types on [nvc0,nve0].
23  *      - added support for software methods 0x600,0x644,0x6ac on nvc0
24  *        to control registers on the MPs to enable performance counters,
25  *        and to control the warp error enable mask (OpenGL requires out of
26  *        bounds access to local memory to be silently ignored / return 0).
27  * 1.1.2:
28  *      - fixes multiple bugs in flip completion events and timestamping
29  * 1.2.0:
30  * 	- object api exposed to userspace
31  * 	- fermi,kepler,maxwell zbc
32  * 1.2.1:
33  *      - allow concurrent access to bo's mapped read/write.
34  * 1.2.2:
35  *      - add NOUVEAU_GEM_DOMAIN_COHERENT flag
36  * 1.3.0:
37  *      - NVIF ABI modified, safe because only (current) users are test
38  *        programs that get directly linked with NVKM.
39  * 1.3.1:
40  *      - implemented limited ABI16/NVIF interop
41  */
42 
43 #include <linux/acpi.h>
44 #include <linux/notifier.h>
45 
46 #include <nvif/client.h>
47 #include <nvif/device.h>
48 #include <nvif/ioctl.h>
49 #include <nvif/mmu.h>
50 #include <nvif/vmm.h>
51 
52 #include <drm/drm_connector.h>
53 #include <drm/drm_device.h>
54 #include <drm/drm_drv.h>
55 #include <drm/drm_file.h>
56 
57 #include <drm/ttm/ttm_bo_api.h>
58 #include <drm/ttm/ttm_bo_driver.h>
59 #include <drm/ttm/ttm_placement.h>
60 #include <drm/ttm/ttm_memory.h>
61 #include <drm/ttm/ttm_module.h>
62 #include <drm/ttm/ttm_page_alloc.h>
63 
64 #include <drm/drm_audio_component.h>
65 
66 #include "uapi/drm/nouveau_drm.h"
67 
68 struct nouveau_channel;
69 struct platform_device;
70 
71 #include "nouveau_fence.h"
72 #include "nouveau_bios.h"
73 #include "nouveau_vmm.h"
74 
75 struct nouveau_drm_tile {
76 	struct nouveau_fence *fence;
77 	bool used;
78 };
79 
80 enum nouveau_drm_object_route {
81 	NVDRM_OBJECT_NVIF = NVIF_IOCTL_V0_OWNER_NVIF,
82 	NVDRM_OBJECT_USIF,
83 	NVDRM_OBJECT_ABI16,
84 	NVDRM_OBJECT_ANY = NVIF_IOCTL_V0_OWNER_ANY,
85 };
86 
87 enum nouveau_drm_notify_route {
88 	NVDRM_NOTIFY_NVIF = 0,
89 	NVDRM_NOTIFY_USIF
90 };
91 
92 enum nouveau_drm_handle {
93 	NVDRM_CHAN    = 0xcccc0000, /* |= client chid */
94 	NVDRM_NVSW    = 0x55550000,
95 };
96 
97 struct nouveau_cli {
98 	struct nvif_client base;
99 	struct nouveau_drm *drm;
100 	struct mutex mutex;
101 
102 	struct nvif_device device;
103 	struct nvif_mmu mmu;
104 	struct nouveau_vmm vmm;
105 	struct nouveau_vmm svm;
106 	const struct nvif_mclass *mem;
107 
108 	struct list_head head;
109 	void *abi16;
110 	struct list_head objects;
111 	struct list_head notifys;
112 	char name[32];
113 
114 	struct work_struct work;
115 	struct list_head worker;
116 	struct mutex lock;
117 };
118 
119 struct nouveau_cli_work {
120 	void (*func)(struct nouveau_cli_work *);
121 	struct nouveau_cli *cli;
122 	struct list_head head;
123 
124 	struct dma_fence *fence;
125 	struct dma_fence_cb cb;
126 };
127 
128 void nouveau_cli_work_queue(struct nouveau_cli *, struct dma_fence *,
129 			    struct nouveau_cli_work *);
130 
131 static inline struct nouveau_cli *
nouveau_cli(struct drm_file * fpriv)132 nouveau_cli(struct drm_file *fpriv)
133 {
134 	return fpriv ? fpriv->driver_priv : NULL;
135 }
136 
137 #include <nvif/object.h>
138 
139 struct nouveau_drm {
140 	struct nouveau_cli master;
141 	struct nouveau_cli client;
142 	struct drm_device *dev;
143 
144 	struct list_head clients;
145 
146 	struct {
147 		struct agp_bridge_data *bridge;
148 		u32 base;
149 		u32 size;
150 		bool cma;
151 	} agp;
152 
153 	/* TTM interface support */
154 	struct {
155 		struct ttm_bo_device bdev;
156 		atomic_t validate_sequence;
157 		int (*move)(struct nouveau_channel *,
158 			    struct ttm_buffer_object *,
159 			    struct ttm_mem_reg *, struct ttm_mem_reg *);
160 		struct nouveau_channel *chan;
161 		struct nvif_object copy;
162 		int mtrr;
163 		int type_vram;
164 		int type_host[2];
165 		int type_ncoh[2];
166 	} ttm;
167 
168 	/* GEM interface support */
169 	struct {
170 		u64 vram_available;
171 		u64 gart_available;
172 	} gem;
173 
174 	/* synchronisation */
175 	void *fence;
176 
177 	/* Global channel management. */
178 	struct {
179 		int nr;
180 		u64 context_base;
181 	} chan;
182 
183 	/* context for accelerated drm-internal operations */
184 	struct nouveau_channel *cechan;
185 	struct nouveau_channel *channel;
186 	struct nvkm_gpuobj *notify;
187 	struct nouveau_fbdev *fbcon;
188 	struct nvif_object nvsw;
189 	struct nvif_object ntfy;
190 
191 	/* nv10-nv40 tiling regions */
192 	struct {
193 		struct nouveau_drm_tile reg[15];
194 		spinlock_t lock;
195 	} tile;
196 
197 	/* modesetting */
198 	struct nvbios vbios;
199 	struct nouveau_display *display;
200 	struct work_struct hpd_work;
201 	struct work_struct fbcon_work;
202 	int fbcon_new_state;
203 #ifdef CONFIG_ACPI
204 	struct notifier_block acpi_nb;
205 #endif
206 
207 	/* power management */
208 	struct nouveau_hwmon *hwmon;
209 	struct nouveau_debugfs *debugfs;
210 
211 	/* led management */
212 	struct nouveau_led *led;
213 
214 	struct dev_pm_domain vga_pm_domain;
215 
216 	struct nouveau_svm *svm;
217 
218 	struct nouveau_dmem *dmem;
219 
220 	struct {
221 		struct drm_audio_component *component;
222 		bool component_registered;
223 	} audio;
224 };
225 
226 static inline struct nouveau_drm *
nouveau_drm(struct drm_device * dev)227 nouveau_drm(struct drm_device *dev)
228 {
229 	return dev->dev_private;
230 }
231 
232 static inline bool
nouveau_drm_use_coherent_gpu_mapping(struct nouveau_drm * drm)233 nouveau_drm_use_coherent_gpu_mapping(struct nouveau_drm *drm)
234 {
235 	struct nvif_mmu *mmu = &drm->client.mmu;
236 	return !(mmu->type[drm->ttm.type_host[0]].type & NVIF_MEM_UNCACHED);
237 }
238 
239 #ifdef __NetBSD__
240 int nouveau_drm_device_init(struct drm_device *);
241 void nouveau_drm_device_fini(struct drm_device *);
242 int nouveau_pmops_suspend(struct drm_device *);
243 int nouveau_pmops_resume(struct drm_device *);
244 #else
245 int nouveau_pmops_suspend(struct device *);
246 int nouveau_pmops_resume(struct device *);
247 #endif
248 bool nouveau_pmops_runtime(void);
249 
250 #include <nvkm/core/tegra.h>
251 
252 struct drm_device *
253 nouveau_platform_device_create(const struct nvkm_device_tegra_func *,
254 			       struct platform_device *, struct nvkm_device **);
255 void nouveau_drm_device_remove(struct drm_device *dev);
256 
257 #define NV_PRINTK(l,c,f,a...) do {                                             \
258 	struct nouveau_cli *_cli = (c);                                        \
259 	dev_##l(_cli->drm->dev->dev, "%s: "f, _cli->name, ##a);                \
260 } while(0)
261 
262 #define NV_FATAL(drm,f,a...) NV_PRINTK(crit, &(drm)->client, f, ##a)
263 #define NV_ERROR(drm,f,a...) NV_PRINTK(err, &(drm)->client, f, ##a)
264 #define NV_WARN(drm,f,a...) NV_PRINTK(warn, &(drm)->client, f, ##a)
265 #define NV_INFO(drm,f,a...) NV_PRINTK(info, &(drm)->client, f, ##a)
266 
267 #define NV_DEBUG(drm,f,a...) do {                                              \
268 	if (drm_debug_enabled(DRM_UT_DRIVER))                                  \
269 		NV_PRINTK(info, &(drm)->client, f, ##a);                       \
270 } while(0)
271 #define NV_ATOMIC(drm,f,a...) do {                                             \
272 	if (drm_debug_enabled(DRM_UT_ATOMIC))                                  \
273 		NV_PRINTK(info, &(drm)->client, f, ##a);                       \
274 } while(0)
275 
276 #define NV_PRINTK_ONCE(l,c,f,a...) NV_PRINTK(l##_once,c,f, ##a)
277 
278 #define NV_ERROR_ONCE(drm,f,a...) NV_PRINTK_ONCE(err, &(drm)->client, f, ##a)
279 #define NV_WARN_ONCE(drm,f,a...) NV_PRINTK_ONCE(warn, &(drm)->client, f, ##a)
280 #define NV_INFO_ONCE(drm,f,a...) NV_PRINTK_ONCE(info, &(drm)->client, f, ##a)
281 
282 extern int nouveau_modeset;
283 
284 #endif
285