xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvkm/engine/fifo/gv100.c (revision 3647c53bd7dada9053b46a5ca27eb3f7c5472416)
1 /*
2  * Copyright 2018 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #include "chan.h"
23 #include "chid.h"
24 #include "cgrp.h"
25 #include "runl.h"
26 #include "runq.h"
27 
28 #include "gk104.h"
29 #include "changk104.h"
30 
31 #include <core/gpuobj.h>
32 
33 #include <nvif/class.h>
34 
35 static u32
36 gv100_chan_doorbell_handle(struct nvkm_chan *chan)
37 {
38 	return chan->id;
39 }
40 
41 static int
42 gv100_chan_ramfc_write(struct nvkm_chan *chan, u64 offset, u64 length, u32 devm, bool priv)
43 {
44 	const u64 userd = nvkm_memory_addr(chan->userd.mem) + chan->userd.base;
45 	const u32 limit2 = ilog2(length / 8);
46 
47 	nvkm_kmap(chan->inst);
48 	nvkm_wo32(chan->inst, 0x008, lower_32_bits(userd));
49 	nvkm_wo32(chan->inst, 0x00c, upper_32_bits(userd));
50 	nvkm_wo32(chan->inst, 0x010, 0x0000face);
51 	nvkm_wo32(chan->inst, 0x030, 0x7ffff902);
52 	nvkm_wo32(chan->inst, 0x048, lower_32_bits(offset));
53 	nvkm_wo32(chan->inst, 0x04c, upper_32_bits(offset) | (limit2 << 16));
54 	nvkm_wo32(chan->inst, 0x084, 0x20400000);
55 	nvkm_wo32(chan->inst, 0x094, 0x30000000 | devm);
56 	nvkm_wo32(chan->inst, 0x0e4, priv ? 0x00000020 : 0x00000000);
57 	nvkm_wo32(chan->inst, 0x0e8, chan->id);
58 	nvkm_wo32(chan->inst, 0x0f4, 0x00001000 | (priv ? 0x00000100 : 0x00000000));
59 	nvkm_wo32(chan->inst, 0x0f8, 0x10003080);
60 	nvkm_mo32(chan->inst, 0x218, 0x00000000, 0x00000000);
61 	nvkm_done(chan->inst);
62 	return 0;
63 }
64 
65 const struct nvkm_chan_func_ramfc
66 gv100_chan_ramfc = {
67 	.write = gv100_chan_ramfc_write,
68 	.devm = 0xfff,
69 	.priv = true,
70 };
71 
72 const struct nvkm_chan_func_userd
73 gv100_chan_userd = {
74 	.bar = 1, /*FIXME: hw doesn't have poller, flip to user-allocated in uapi commit. */
75 	.size = 0x200,
76 	.clear = gf100_chan_userd_clear,
77 };
78 
79 static const struct nvkm_chan_func
80 gv100_chan = {
81 	.inst = &gf100_chan_inst,
82 	.userd = &gv100_chan_userd,
83 	.ramfc = &gv100_chan_ramfc,
84 	.bind = gk104_chan_bind_inst,
85 	.unbind = gk104_chan_unbind,
86 	.start = gk104_chan_start,
87 	.stop = gk104_chan_stop,
88 	.preempt = gk110_chan_preempt,
89 	.doorbell_handle = gv100_chan_doorbell_handle,
90 };
91 
92 const struct nvkm_engn_func
93 gv100_engn = {
94 	.chsw = gk104_engn_chsw,
95 	.cxid = gk104_engn_cxid,
96 };
97 
98 const struct nvkm_engn_func
99 gv100_engn_ce = {
100 	.chsw = gk104_engn_chsw,
101 	.cxid = gk104_engn_cxid,
102 };
103 
104 static bool
105 gv100_runq_intr_1_ctxnotvalid(struct nvkm_runq *runq, int chid)
106 {
107 	struct nvkm_fifo *fifo = runq->fifo;
108 	struct nvkm_device *device = fifo->engine.subdev.device;
109 	struct nvkm_chan *chan;
110 	unsigned long flags;
111 
112 	RUNQ_ERROR(runq, "CTXNOTVALID chid:%d", chid);
113 
114 	chan = nvkm_chan_get_chid(&fifo->engine, chid, &flags);
115 	if (WARN_ON_ONCE(!chan))
116 		return false;
117 
118 	nvkm_chan_error(chan, true);
119 	nvkm_chan_put(&chan, flags);
120 
121 	nvkm_mask(device, 0x0400ac + (runq->id * 0x2000), 0x00030000, 0x00030000);
122 	nvkm_wr32(device, 0x040148 + (runq->id * 0x2000), 0x80000000);
123 	return true;
124 }
125 
126 const struct nvkm_runq_func
127 gv100_runq = {
128 	.init = gk208_runq_init,
129 	.intr = gk104_runq_intr,
130 	.intr_0_names = gk104_runq_intr_0_names,
131 	.intr_1_ctxnotvalid = gv100_runq_intr_1_ctxnotvalid,
132 	.idle = gk104_runq_idle,
133 };
134 
135 void
136 gv100_runl_preempt(struct nvkm_runl *runl)
137 {
138 	nvkm_wr32(runl->fifo->engine.subdev.device, 0x002638, BIT(runl->id));
139 }
140 
141 void
142 gv100_runl_insert_chan(struct nvkm_chan *chan, struct nvkm_memory *memory, u64 offset)
143 {
144 	const u64 user = nvkm_memory_addr(chan->userd.mem) + chan->userd.base;
145 	const u64 inst = chan->inst->addr;
146 
147 	nvkm_wo32(memory, offset + 0x0, lower_32_bits(user) | chan->runq << 1);
148 	nvkm_wo32(memory, offset + 0x4, upper_32_bits(user));
149 	nvkm_wo32(memory, offset + 0x8, lower_32_bits(inst) | chan->id);
150 	nvkm_wo32(memory, offset + 0xc, upper_32_bits(inst));
151 }
152 
153 void
154 gv100_runl_insert_cgrp(struct nvkm_cgrp *cgrp, struct nvkm_memory *memory, u64 offset)
155 {
156 	nvkm_wo32(memory, offset + 0x0, (128 << 24) | (3 << 16) | 0x00000001);
157 	nvkm_wo32(memory, offset + 0x4, cgrp->chan_nr);
158 	nvkm_wo32(memory, offset + 0x8, cgrp->id);
159 	nvkm_wo32(memory, offset + 0xc, 0x00000000);
160 }
161 
162 static const struct nvkm_runl_func
163 gv100_runl = {
164 	.runqs = 2,
165 	.size = 16,
166 	.update = nv50_runl_update,
167 	.insert_cgrp = gv100_runl_insert_cgrp,
168 	.insert_chan = gv100_runl_insert_chan,
169 	.commit = gk104_runl_commit,
170 	.wait = nv50_runl_wait,
171 	.pending = gk104_runl_pending,
172 	.block = gk104_runl_block,
173 	.allow = gk104_runl_allow,
174 	.preempt = gv100_runl_preempt,
175 	.preempt_pending = gf100_runl_preempt_pending,
176 };
177 
178 const struct nvkm_enum
179 gv100_fifo_mmu_fault_gpcclient[] = {
180 	{ 0x00, "T1_0" },
181 	{ 0x01, "T1_1" },
182 	{ 0x02, "T1_2" },
183 	{ 0x03, "T1_3" },
184 	{ 0x04, "T1_4" },
185 	{ 0x05, "T1_5" },
186 	{ 0x06, "T1_6" },
187 	{ 0x07, "T1_7" },
188 	{ 0x08, "PE_0" },
189 	{ 0x09, "PE_1" },
190 	{ 0x0a, "PE_2" },
191 	{ 0x0b, "PE_3" },
192 	{ 0x0c, "PE_4" },
193 	{ 0x0d, "PE_5" },
194 	{ 0x0e, "PE_6" },
195 	{ 0x0f, "PE_7" },
196 	{ 0x10, "RAST" },
197 	{ 0x11, "GCC" },
198 	{ 0x12, "GPCCS" },
199 	{ 0x13, "PROP_0" },
200 	{ 0x14, "PROP_1" },
201 	{ 0x15, "PROP_2" },
202 	{ 0x16, "PROP_3" },
203 	{ 0x17, "GPM" },
204 	{ 0x18, "LTP_UTLB_0" },
205 	{ 0x19, "LTP_UTLB_1" },
206 	{ 0x1a, "LTP_UTLB_2" },
207 	{ 0x1b, "LTP_UTLB_3" },
208 	{ 0x1c, "LTP_UTLB_4" },
209 	{ 0x1d, "LTP_UTLB_5" },
210 	{ 0x1e, "LTP_UTLB_6" },
211 	{ 0x1f, "LTP_UTLB_7" },
212 	{ 0x20, "RGG_UTLB" },
213 	{ 0x21, "T1_8" },
214 	{ 0x22, "T1_9" },
215 	{ 0x23, "T1_10" },
216 	{ 0x24, "T1_11" },
217 	{ 0x25, "T1_12" },
218 	{ 0x26, "T1_13" },
219 	{ 0x27, "T1_14" },
220 	{ 0x28, "T1_15" },
221 	{ 0x29, "TPCCS_0" },
222 	{ 0x2a, "TPCCS_1" },
223 	{ 0x2b, "TPCCS_2" },
224 	{ 0x2c, "TPCCS_3" },
225 	{ 0x2d, "TPCCS_4" },
226 	{ 0x2e, "TPCCS_5" },
227 	{ 0x2f, "TPCCS_6" },
228 	{ 0x30, "TPCCS_7" },
229 	{ 0x31, "PE_8" },
230 	{ 0x32, "PE_9" },
231 	{ 0x33, "TPCCS_8" },
232 	{ 0x34, "TPCCS_9" },
233 	{ 0x35, "T1_16" },
234 	{ 0x36, "T1_17" },
235 	{ 0x37, "T1_18" },
236 	{ 0x38, "T1_19" },
237 	{ 0x39, "PE_10" },
238 	{ 0x3a, "PE_11" },
239 	{ 0x3b, "TPCCS_10" },
240 	{ 0x3c, "TPCCS_11" },
241 	{ 0x3d, "T1_20" },
242 	{ 0x3e, "T1_21" },
243 	{ 0x3f, "T1_22" },
244 	{ 0x40, "T1_23" },
245 	{ 0x41, "PE_12" },
246 	{ 0x42, "PE_13" },
247 	{ 0x43, "TPCCS_12" },
248 	{ 0x44, "TPCCS_13" },
249 	{ 0x45, "T1_24" },
250 	{ 0x46, "T1_25" },
251 	{ 0x47, "T1_26" },
252 	{ 0x48, "T1_27" },
253 	{ 0x49, "PE_14" },
254 	{ 0x4a, "PE_15" },
255 	{ 0x4b, "TPCCS_14" },
256 	{ 0x4c, "TPCCS_15" },
257 	{ 0x4d, "T1_28" },
258 	{ 0x4e, "T1_29" },
259 	{ 0x4f, "T1_30" },
260 	{ 0x50, "T1_31" },
261 	{ 0x51, "PE_16" },
262 	{ 0x52, "PE_17" },
263 	{ 0x53, "TPCCS_16" },
264 	{ 0x54, "TPCCS_17" },
265 	{ 0x55, "T1_32" },
266 	{ 0x56, "T1_33" },
267 	{ 0x57, "T1_34" },
268 	{ 0x58, "T1_35" },
269 	{ 0x59, "PE_18" },
270 	{ 0x5a, "PE_19" },
271 	{ 0x5b, "TPCCS_18" },
272 	{ 0x5c, "TPCCS_19" },
273 	{ 0x5d, "T1_36" },
274 	{ 0x5e, "T1_37" },
275 	{ 0x5f, "T1_38" },
276 	{ 0x60, "T1_39" },
277 	{}
278 };
279 
280 const struct nvkm_enum
281 gv100_fifo_mmu_fault_hubclient[] = {
282 	{ 0x00, "VIP" },
283 	{ 0x01, "CE0" },
284 	{ 0x02, "CE1" },
285 	{ 0x03, "DNISO" },
286 	{ 0x04, "FE" },
287 	{ 0x05, "FECS" },
288 	{ 0x06, "HOST" },
289 	{ 0x07, "HOST_CPU" },
290 	{ 0x08, "HOST_CPU_NB" },
291 	{ 0x09, "ISO" },
292 	{ 0x0a, "MMU" },
293 	{ 0x0b, "NVDEC" },
294 	{ 0x0d, "NVENC1" },
295 	{ 0x0e, "NISO" },
296 	{ 0x0f, "P2P" },
297 	{ 0x10, "PD" },
298 	{ 0x11, "PERF" },
299 	{ 0x12, "PMU" },
300 	{ 0x13, "RASTERTWOD" },
301 	{ 0x14, "SCC" },
302 	{ 0x15, "SCC_NB" },
303 	{ 0x16, "SEC" },
304 	{ 0x17, "SSYNC" },
305 	{ 0x18, "CE2" },
306 	{ 0x19, "XV" },
307 	{ 0x1a, "MMU_NB" },
308 	{ 0x1b, "NVENC0" },
309 	{ 0x1c, "DFALCON" },
310 	{ 0x1d, "SKED" },
311 	{ 0x1e, "AFALCON" },
312 	{ 0x1f, "DONT_CARE" },
313 	{ 0x20, "HSCE0" },
314 	{ 0x21, "HSCE1" },
315 	{ 0x22, "HSCE2" },
316 	{ 0x23, "HSCE3" },
317 	{ 0x24, "HSCE4" },
318 	{ 0x25, "HSCE5" },
319 	{ 0x26, "HSCE6" },
320 	{ 0x27, "HSCE7" },
321 	{ 0x28, "HSCE8" },
322 	{ 0x29, "HSCE9" },
323 	{ 0x2a, "HSHUB" },
324 	{ 0x2b, "PTP_X0" },
325 	{ 0x2c, "PTP_X1" },
326 	{ 0x2d, "PTP_X2" },
327 	{ 0x2e, "PTP_X3" },
328 	{ 0x2f, "PTP_X4" },
329 	{ 0x30, "PTP_X5" },
330 	{ 0x31, "PTP_X6" },
331 	{ 0x32, "PTP_X7" },
332 	{ 0x33, "NVENC2" },
333 	{ 0x34, "VPR_SCRUBBER0" },
334 	{ 0x35, "VPR_SCRUBBER1" },
335 	{ 0x36, "DWBIF" },
336 	{ 0x37, "FBFALCON" },
337 	{ 0x38, "CE_SHIM" },
338 	{ 0x39, "GSP" },
339 	{}
340 };
341 
342 const struct nvkm_enum
343 gv100_fifo_mmu_fault_reason[] = {
344 	{ 0x00, "PDE" },
345 	{ 0x01, "PDE_SIZE" },
346 	{ 0x02, "PTE" },
347 	{ 0x03, "VA_LIMIT_VIOLATION" },
348 	{ 0x04, "UNBOUND_INST_BLOCK" },
349 	{ 0x05, "PRIV_VIOLATION" },
350 	{ 0x06, "RO_VIOLATION" },
351 	{ 0x07, "WO_VIOLATION" },
352 	{ 0x08, "PITCH_MASK_VIOLATION" },
353 	{ 0x09, "WORK_CREATION" },
354 	{ 0x0a, "UNSUPPORTED_APERTURE" },
355 	{ 0x0b, "COMPRESSION_FAILURE" },
356 	{ 0x0c, "UNSUPPORTED_KIND" },
357 	{ 0x0d, "REGION_VIOLATION" },
358 	{ 0x0e, "POISONED" },
359 	{ 0x0f, "ATOMIC_VIOLATION" },
360 	{}
361 };
362 
363 static const struct nvkm_enum
364 gv100_fifo_mmu_fault_engine[] = {
365 	{ 0x01, "DISPLAY" },
366 	{ 0x03, "PTP" },
367 	{ 0x04, "BAR1", NULL, NVKM_SUBDEV_BAR },
368 	{ 0x05, "BAR2", NULL, NVKM_SUBDEV_INSTMEM },
369 	{ 0x06, "PWR_PMU" },
370 	{ 0x08, "IFB", NULL, NVKM_ENGINE_IFB },
371 	{ 0x09, "PERF" },
372 	{ 0x1f, "PHYSICAL" },
373 	{ 0x20, "HOST0" },
374 	{ 0x21, "HOST1" },
375 	{ 0x22, "HOST2" },
376 	{ 0x23, "HOST3" },
377 	{ 0x24, "HOST4" },
378 	{ 0x25, "HOST5" },
379 	{ 0x26, "HOST6" },
380 	{ 0x27, "HOST7" },
381 	{ 0x28, "HOST8" },
382 	{ 0x29, "HOST9" },
383 	{ 0x2a, "HOST10" },
384 	{ 0x2b, "HOST11" },
385 	{ 0x2c, "HOST12" },
386 	{ 0x2d, "HOST13" },
387 	{}
388 };
389 
390 const struct nvkm_enum
391 gv100_fifo_mmu_fault_access[] = {
392 	{ 0x0, "VIRT_READ" },
393 	{ 0x1, "VIRT_WRITE" },
394 	{ 0x2, "VIRT_ATOMIC" },
395 	{ 0x3, "VIRT_PREFETCH" },
396 	{ 0x4, "VIRT_ATOMIC_WEAK" },
397 	{ 0x8, "PHYS_READ" },
398 	{ 0x9, "PHYS_WRITE" },
399 	{ 0xa, "PHYS_ATOMIC" },
400 	{ 0xb, "PHYS_PREFETCH" },
401 	{}
402 };
403 
404 static const struct nvkm_fifo_func_mmu_fault
405 gv100_fifo_mmu_fault = {
406 	.recover = gf100_fifo_mmu_fault_recover,
407 	.access = gv100_fifo_mmu_fault_access,
408 	.engine = gv100_fifo_mmu_fault_engine,
409 	.reason = gv100_fifo_mmu_fault_reason,
410 	.hubclient = gv100_fifo_mmu_fault_hubclient,
411 	.gpcclient = gv100_fifo_mmu_fault_gpcclient,
412 };
413 
414 static void
415 gv100_fifo_intr_ctxsw_timeout(struct nvkm_fifo *fifo, u32 engm)
416 {
417 	struct nvkm_runl *runl;
418 	struct nvkm_engn *engn;
419 
420 	nvkm_runl_foreach(runl, fifo) {
421 		nvkm_runl_foreach_engn_cond(engn, runl, engm & BIT(engn->id))
422 			nvkm_runl_rc_engn(runl, engn);
423 	}
424 }
425 
426 static const struct nvkm_fifo_func
427 gv100_fifo = {
428 	.dtor = gk104_fifo_dtor,
429 	.oneinit = gk104_fifo_oneinit,
430 	.chid_nr = gm200_fifo_chid_nr,
431 	.chid_ctor = gk110_fifo_chid_ctor,
432 	.runq_nr = gm200_fifo_runq_nr,
433 	.runl_ctor = gk104_fifo_runl_ctor,
434 	.init = gk104_fifo_init,
435 	.init_pbdmas = gk104_fifo_init_pbdmas,
436 	.intr = gk104_fifo_intr,
437 	.intr_ctxsw_timeout = gv100_fifo_intr_ctxsw_timeout,
438 	.mmu_fault = &gv100_fifo_mmu_fault,
439 	.engine_id = gk104_fifo_engine_id,
440 	.nonstall = &gf100_fifo_nonstall,
441 	.runl = &gv100_runl,
442 	.runq = &gv100_runq,
443 	.engn = &gv100_engn,
444 	.engn_ce = &gv100_engn_ce,
445 	.cgrp = {{ 0, 0, KEPLER_CHANNEL_GROUP_A  }, &gk110_cgrp, .force = true },
446 	.chan = {{ 0, 0,  VOLTA_CHANNEL_GPFIFO_A }, &gv100_chan, .ctor = gv100_fifo_gpfifo_new },
447 };
448 
449 int
450 gv100_fifo_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
451 	       struct nvkm_fifo **pfifo)
452 {
453 	return gk104_fifo_new_(&gv100_fifo, device, type, inst, 0, pfifo);
454 }
455