1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_FIFO_H__
3 #define __NVKM_FIFO_H__
4 #include <core/engine.h>
5 #include <core/object.h>
6 #include <core/event.h>
7 #include <subdev/gsp.h>
8 struct nvkm_fault_data;
9 
10 #define NVKM_FIFO_ENGN_NR 16
11 
12 struct nvkm_chan {
13 	const struct nvkm_chan_func *func;
14 	char name[64];
15 	struct nvkm_cgrp *cgrp;
16 	int runq;
17 
18 	struct nvkm_gpuobj *inst;
19 	struct nvkm_vmm *vmm;
20 	struct nvkm_gpuobj *push;
21 	int id;
22 
23 	struct {
24 		struct nvkm_memory *mem;
25 		u32 base;
26 	} userd;
27 
28 	u32 ramfc_offset;
29 	struct nvkm_gpuobj *ramfc;
30 	struct nvkm_gpuobj *cache;
31 	struct nvkm_gpuobj *eng;
32 	struct nvkm_gpuobj *pgd;
33 	struct nvkm_ramht *ramht;
34 
35 	spinlock_t lock;
36 	atomic_t blocked;
37 	atomic_t errored;
38 
39 	struct {
40 		struct nvkm_gsp_object object;
41 		struct {
42 			dma_addr_t addr;
43 			void *ptr;
44 		} mthdbuf;
45 		struct nvkm_vctx *grctx;
46 	} rm;
47 
48 	struct list_head cctxs;
49 	struct list_head head;
50 };
51 
52 struct nvkm_chan *nvkm_chan_get_chid(struct nvkm_engine *, int id, unsigned long *irqflags);
53 struct nvkm_chan *nvkm_chan_get_inst(struct nvkm_engine *, u64 inst, unsigned long *irqflags);
54 void nvkm_chan_put(struct nvkm_chan **, unsigned long irqflags);
55 
56 struct nvkm_chan *nvkm_uchan_chan(struct nvkm_object *);
57 
58 struct nvkm_fifo {
59 	const struct nvkm_fifo_func *func;
60 	struct nvkm_engine engine;
61 
62 	struct nvkm_chid *chid;
63 	struct nvkm_chid *cgid;
64 
65 	struct list_head runqs;
66 	struct list_head runls;
67 
68 	struct {
69 #define NVKM_FIFO_NONSTALL_EVENT BIT(0)
70 		struct nvkm_event event;
71 		struct nvkm_inth intr;
72 	} nonstall;
73 
74 	struct {
75 		u32 chan_msec;
76 	} timeout;
77 
78 	struct {
79 		struct nvkm_memory *mem;
80 		struct nvkm_vma *bar1;
81 
82 		struct mutex mutex;
83 		struct list_head list;
84 	} userd;
85 
86 	struct {
87 		u32 mthdbuf_size;
88 	} rm;
89 
90 	spinlock_t lock;
91 	struct mutex mutex;
92 };
93 
94 void nvkm_fifo_fault(struct nvkm_fifo *, struct nvkm_fault_data *);
95 void nvkm_fifo_pause(struct nvkm_fifo *, unsigned long *);
96 void nvkm_fifo_start(struct nvkm_fifo *, unsigned long *);
97 bool nvkm_fifo_ctxsw_in_progress(struct nvkm_engine *);
98 
99 int nv04_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
100 int nv10_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
101 int nv17_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
102 int nv40_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
103 int nv50_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
104 int g84_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
105 int g98_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
106 int gf100_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
107 int gk104_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
108 int gk110_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
109 int gk208_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
110 int gk20a_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
111 int gm107_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
112 int gm200_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
113 int gp100_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
114 int gv100_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
115 int tu102_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
116 int ga100_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
117 int ga102_fifo_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fifo **);
118 #endif
119