summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
blob: 6f5d376d8fcc1ecb6d9faa80b4b06ba4cd1b21e4 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#ifndef __NVKM_GSP_H__
#define __NVKM_GSP_H__
#define nvkm_gsp(p) container_of((p), struct nvkm_gsp, subdev)
#include <core/subdev.h>
#include <core/falcon.h>
#include <core/firmware.h>

#define GSP_PAGE_SHIFT 12
#define GSP_PAGE_SIZE  BIT(GSP_PAGE_SHIFT)

struct nvkm_gsp_mem {
	size_t size;
	void *data;
	dma_addr_t addr;
};

struct nvkm_gsp_radix3 {
	struct nvkm_gsp_mem mem[3];
};

int nvkm_gsp_sg(struct nvkm_device *, u64 size, struct sg_table *);
void nvkm_gsp_sg_free(struct nvkm_device *, struct sg_table *);

typedef int (*nvkm_gsp_msg_ntfy_func)(void *priv, u32 fn, void *repv, u32 repc);

struct nvkm_gsp_event;
typedef void (*nvkm_gsp_event_func)(struct nvkm_gsp_event *, void *repv, u32 repc);

struct nvkm_gsp {
	const struct nvkm_gsp_func *func;
	struct nvkm_subdev subdev;

	struct nvkm_falcon falcon;

	struct {
		struct {
			const struct firmware *load;
			const struct firmware *unload;
		} booter;
		const struct firmware *bl;
		const struct firmware *rm;
	} fws;

	struct nvkm_firmware fw;
	struct nvkm_gsp_mem sig;
	struct nvkm_gsp_radix3 radix3;

	struct {
		struct {
			struct {
				u64 addr;
				u64 size;
			} vga_workspace;
			u64 addr;
			u64 size;
		} bios;
		struct {
			struct {
				u64 addr;
				u64 size;
			} frts, boot, elf, heap;
			u64 addr;
			u64 size;
		} wpr2;
		struct {
			u64 addr;
			u64 size;
		} heap;
		u64 addr;
		u64 size;

		struct {
			u64 addr;
			u64 size;
		} region[16];
		int region_nr;
		u32 rsvd_size;
	} fb;

	struct {
		struct nvkm_falcon_fw load;
		struct nvkm_falcon_fw unload;
	} booter;

	struct {
		struct nvkm_gsp_mem fw;
		u32 code_offset;
		u32 data_offset;
		u32 manifest_offset;
		u32 app_version;
	} boot;

	struct nvkm_gsp_mem libos;
	struct nvkm_gsp_mem loginit;
	struct nvkm_gsp_mem logintr;
	struct nvkm_gsp_mem logrm;
	struct nvkm_gsp_mem rmargs;

	struct nvkm_gsp_mem wpr_meta;

	struct {
		struct sg_table sgt;
		struct nvkm_gsp_radix3 radix3;
		struct nvkm_gsp_mem meta;
	} sr;

	struct {
		struct nvkm_gsp_mem mem;

		struct {
			int   nr;
			u32 size;
			u64 *ptr;
		} ptes;

		struct {
			u32  size;
			void *ptr;
		} cmdq, msgq;
	} shm;

	struct nvkm_gsp_cmdq {
		struct mutex mutex;
		u32 cnt;
		u32 seq;
		u32 *wptr;
		u32 *rptr;
	} cmdq;

	struct nvkm_gsp_msgq {
		struct mutex mutex;
		u32 cnt;
		u32 *wptr;
		u32 *rptr;
		struct nvkm_gsp_msgq_ntfy {
			u32 fn;
			nvkm_gsp_msg_ntfy_func func;
			void *priv;
		} ntfy[16];
		int ntfy_nr;
		struct work_struct work;
	} msgq;

	bool running;

	/* Internal GSP-RM control handles. */
	struct {
		struct nvkm_gsp_client {
			struct nvkm_gsp_object {
				struct nvkm_gsp_client *client;
				struct nvkm_gsp_object *parent;
				u32 handle;
			} object;

			struct nvkm_gsp *gsp;

			struct list_head events;
		} client;

		struct nvkm_gsp_device {
			struct nvkm_gsp_object object;
			struct nvkm_gsp_object subdevice;
		} device;
	} internal;

	struct {
		enum nvkm_subdev_type type;
		int inst;
		u32 stall;
		u32 nonstall;
	} intr[32];
	int intr_nr;

	struct {
		u64 rm_bar1_pdb;
		u64 rm_bar2_pdb;
	} bar;

	struct {
		u8 gpcs;
		u8 tpcs;
	} gr;

	const struct nvkm_gsp_rm {
		void *(*rpc_get)(struct nvkm_gsp *, u32 fn, u32 argc);
		void *(*rpc_push)(struct nvkm_gsp *, void *argv, bool wait, u32 repc);
		void (*rpc_done)(struct nvkm_gsp *gsp, void *repv);

		void *(*rm_ctrl_get)(struct nvkm_gsp_object *, u32 cmd, u32 argc);
		int (*rm_ctrl_push)(struct nvkm_gsp_object *, void **argv, u32 repc);
		void (*rm_ctrl_done)(struct nvkm_gsp_object *, void *repv);

		void *(*rm_alloc_get)(struct nvkm_gsp_object *, u32 oclass, u32 argc);
		void *(*rm_alloc_push)(struct nvkm_gsp_object *, void *argv, u32 repc);
		void (*rm_alloc_done)(struct nvkm_gsp_object *, void *repv);

		int (*rm_free)(struct nvkm_gsp_object *);

		int (*client_ctor)(struct nvkm_gsp *, struct nvkm_gsp_client *);
		void (*client_dtor)(struct nvkm_gsp_client *);

		int (*device_ctor)(struct nvkm_gsp_client *, struct nvkm_gsp_device *);
		void (*device_dtor)(struct nvkm_gsp_device *);

		int (*event_ctor)(struct nvkm_gsp_device *, u32 handle, u32 id,
				  nvkm_gsp_event_func, struct nvkm_gsp_event *);
		void (*event_dtor)(struct nvkm_gsp_event *);
	} *rm;

	struct {
		struct mutex mutex;;
		struct idr idr;
	} client_id;
};

static inline bool
nvkm_gsp_rm(struct nvkm_gsp *gsp)
{
	return gsp && (gsp->fws.rm || gsp->fw.img);
}

static inline void *
nvkm_gsp_rpc_get(struct nvkm_gsp *gsp, u32 fn, u32 argc)
{
	return gsp->rm->rpc_get(gsp, fn, argc);
}

static inline void *
nvkm_gsp_rpc_push(struct nvkm_gsp *gsp, void *argv, bool wait, u32 repc)
{
	return gsp->rm->rpc_push(gsp, argv, wait, repc);
}

static inline void *
nvkm_gsp_rpc_rd(struct nvkm_gsp *gsp, u32 fn, u32 argc)
{
	void *argv = nvkm_gsp_rpc_get(gsp, fn, argc);

	if (IS_ERR_OR_NULL(argv))
		return argv;

	return nvkm_gsp_rpc_push(gsp, argv, true, argc);
}

static inline int
nvkm_gsp_rpc_wr(struct nvkm_gsp *gsp, void *argv, bool wait)
{
	void *repv = nvkm_gsp_rpc_push(gsp, argv, wait, 0);

	if (IS_ERR(repv))
		return PTR_ERR(repv);

	return 0;
}

static inline void
nvkm_gsp_rpc_done(struct nvkm_gsp *gsp, void *repv)
{
	gsp->rm->rpc_done(gsp, repv);
}

static inline void *
nvkm_gsp_rm_ctrl_get(struct nvkm_gsp_object *object, u32 cmd, u32 argc)
{
	return object->client->gsp->rm->rm_ctrl_get(object, cmd, argc);
}

static inline int
nvkm_gsp_rm_ctrl_push(struct nvkm_gsp_object *object, void *argv, u32 repc)
{
	return object->client->gsp->rm->rm_ctrl_push(object, argv, repc);
}

static inline void *
nvkm_gsp_rm_ctrl_rd(struct nvkm_gsp_object *object, u32 cmd, u32 repc)
{
	void *argv = nvkm_gsp_rm_ctrl_get(object, cmd, repc);
	int ret;

	if (IS_ERR(argv))
		return argv;

	ret = nvkm_gsp_rm_ctrl_push(object, &argv, repc);
	if (ret)
		return ERR_PTR(ret);
	return argv;
}

static inline int
nvkm_gsp_rm_ctrl_wr(struct nvkm_gsp_object *object, void *argv)
{
	int ret = nvkm_gsp_rm_ctrl_push(object, &argv, 0);

	if (ret)
		return ret;
	return 0;
}

static inline void
nvkm_gsp_rm_ctrl_done(struct nvkm_gsp_object *object, void *repv)
{
	object->client->gsp->rm->rm_ctrl_done(object, repv);
}

static inline void *
nvkm_gsp_rm_alloc_get(struct nvkm_gsp_object *parent, u32 handle, u32 oclass, u32 argc,
		      struct nvkm_gsp_object *object)
{
	struct nvkm_gsp_client *client = parent->client;
	struct nvkm_gsp *gsp = client->gsp;
	void *argv;

	object->client = parent->client;
	object->parent = parent;
	object->handle = handle;

	argv = gsp->rm->rm_alloc_get(object, oclass, argc);
	if (IS_ERR_OR_NULL(argv)) {
		object->client = NULL;
		return argv;
	}

	return argv;
}

static inline void *
nvkm_gsp_rm_alloc_push(struct nvkm_gsp_object *object, void *argv, u32 repc)
{
	void *repv = object->client->gsp->rm->rm_alloc_push(object, argv, repc);

	if (IS_ERR(repv))
		object->client = NULL;

	return repv;
}

static inline int
nvkm_gsp_rm_alloc_wr(struct nvkm_gsp_object *object, void *argv)
{
	void *repv = nvkm_gsp_rm_alloc_push(object, argv, 0);

	if (IS_ERR(repv))
		return PTR_ERR(repv);

	return 0;
}

static inline void
nvkm_gsp_rm_alloc_done(struct nvkm_gsp_object *object, void *repv)
{
	object->client->gsp->rm->rm_alloc_done(object, repv);
}

static inline int
nvkm_gsp_rm_alloc(struct nvkm_gsp_object *parent, u32 handle, u32 oclass, u32 argc,
		  struct nvkm_gsp_object *object)
{
	void *argv = nvkm_gsp_rm_alloc_get(parent, handle, oclass, argc, object);

	if (IS_ERR_OR_NULL(argv))
		return argv ? PTR_ERR(argv) : -EIO;

	return nvkm_gsp_rm_alloc_wr(object, argv);
}

static inline int
nvkm_gsp_rm_free(struct nvkm_gsp_object *object)
{
	if (object->client)
		return object->client->gsp->rm->rm_free(object);

	return 0;
}

static inline int
nvkm_gsp_client_ctor(struct nvkm_gsp *gsp, struct nvkm_gsp_client *client)
{
	if (WARN_ON(!gsp->rm))
		return -ENOSYS;

	return gsp->rm->client_ctor(gsp, client);
}

static inline void
nvkm_gsp_client_dtor(struct nvkm_gsp_client *client)
{
	if (client->gsp)
		client->gsp->rm->client_dtor(client);
}

static inline int
nvkm_gsp_device_ctor(struct nvkm_gsp_client *client, struct nvkm_gsp_device *device)
{
	return client->gsp->rm->device_ctor(client, device);
}

static inline void
nvkm_gsp_device_dtor(struct nvkm_gsp_device *device)
{
	if (device->object.client)
		device->object.client->gsp->rm->device_dtor(device);
}

static inline int
nvkm_gsp_client_device_ctor(struct nvkm_gsp *gsp,
			    struct nvkm_gsp_client *client, struct nvkm_gsp_device *device)
{
	int ret = nvkm_gsp_client_ctor(gsp, client);

	if (ret == 0) {
		ret = nvkm_gsp_device_ctor(client, device);
		if (ret)
			nvkm_gsp_client_dtor(client);
	}

	return ret;
}

struct nvkm_gsp_event {
	struct nvkm_gsp_device *device;
	u32 id;
	nvkm_gsp_event_func func;

	struct nvkm_gsp_object object;

	struct list_head head;
};

static inline int
nvkm_gsp_device_event_ctor(struct nvkm_gsp_device *device, u32 handle, u32 id,
			   nvkm_gsp_event_func func, struct nvkm_gsp_event *event)
{
	return device->object.client->gsp->rm->event_ctor(device, handle, id, func, event);
}

static inline void
nvkm_gsp_event_dtor(struct nvkm_gsp_event *event)
{
	struct nvkm_gsp_device *device = event->device;

	if (device)
		device->object.client->gsp->rm->event_dtor(event);
}

int nvkm_gsp_intr_stall(struct nvkm_gsp *, enum nvkm_subdev_type, int);
int nvkm_gsp_intr_nonstall(struct nvkm_gsp *, enum nvkm_subdev_type, int);

int gv100_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **);
int tu102_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **);
int tu116_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **);
int ga100_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **);
int ga102_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **);
int ad102_gsp_new(struct nvkm_device *, enum nvkm_subdev_type, int, struct nvkm_gsp **);
#endif