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 void 93 gv100_ectx_bind(struct nvkm_engn *engn, struct nvkm_cctx *cctx, struct nvkm_chan *chan) 94 { 95 u64 addr = 0ULL; 96 97 if (cctx) { 98 addr = cctx->vctx->vma->addr; 99 addr |= 4ULL; 100 } 101 102 nvkm_kmap(chan->inst); 103 nvkm_wo32(chan->inst, 0x210, lower_32_bits(addr)); 104 nvkm_wo32(chan->inst, 0x214, upper_32_bits(addr)); 105 nvkm_mo32(chan->inst, 0x0ac, 0x00010000, cctx ? 0x00010000 : 0x00000000); 106 nvkm_done(chan->inst); 107 } 108 109 const struct nvkm_engn_func 110 gv100_engn = { 111 .chsw = gk104_engn_chsw, 112 .cxid = gk104_engn_cxid, 113 .ctor = gk104_ectx_ctor, 114 .bind = gv100_ectx_bind, 115 }; 116 117 void 118 gv100_ectx_ce_bind(struct nvkm_engn *engn, struct nvkm_cctx *cctx, struct nvkm_chan *chan) 119 { 120 const u64 bar2 = cctx ? nvkm_memory_bar2(cctx->vctx->inst->memory) : 0ULL; 121 122 nvkm_kmap(chan->inst); 123 nvkm_wo32(chan->inst, 0x220, lower_32_bits(bar2)); 124 nvkm_wo32(chan->inst, 0x224, upper_32_bits(bar2)); 125 nvkm_mo32(chan->inst, 0x0ac, 0x00020000, cctx ? 0x00020000 : 0x00000000); 126 nvkm_done(chan->inst); 127 } 128 129 int 130 gv100_ectx_ce_ctor(struct nvkm_engn *engn, struct nvkm_vctx *vctx) 131 { 132 if (nvkm_memory_bar2(vctx->inst->memory) == ~0ULL) 133 return -EFAULT; 134 135 return 0; 136 } 137 138 const struct nvkm_engn_func 139 gv100_engn_ce = { 140 .chsw = gk104_engn_chsw, 141 .cxid = gk104_engn_cxid, 142 .ctor = gv100_ectx_ce_ctor, 143 .bind = gv100_ectx_ce_bind, 144 }; 145 146 static bool 147 gv100_runq_intr_1_ctxnotvalid(struct nvkm_runq *runq, int chid) 148 { 149 struct nvkm_fifo *fifo = runq->fifo; 150 struct nvkm_device *device = fifo->engine.subdev.device; 151 struct nvkm_chan *chan; 152 unsigned long flags; 153 154 RUNQ_ERROR(runq, "CTXNOTVALID chid:%d", chid); 155 156 chan = nvkm_chan_get_chid(&fifo->engine, chid, &flags); 157 if (WARN_ON_ONCE(!chan)) 158 return false; 159 160 nvkm_chan_error(chan, true); 161 nvkm_chan_put(&chan, flags); 162 163 nvkm_mask(device, 0x0400ac + (runq->id * 0x2000), 0x00030000, 0x00030000); 164 nvkm_wr32(device, 0x040148 + (runq->id * 0x2000), 0x80000000); 165 return true; 166 } 167 168 const struct nvkm_runq_func 169 gv100_runq = { 170 .init = gk208_runq_init, 171 .intr = gk104_runq_intr, 172 .intr_0_names = gk104_runq_intr_0_names, 173 .intr_1_ctxnotvalid = gv100_runq_intr_1_ctxnotvalid, 174 .idle = gk104_runq_idle, 175 }; 176 177 void 178 gv100_runl_preempt(struct nvkm_runl *runl) 179 { 180 nvkm_wr32(runl->fifo->engine.subdev.device, 0x002638, BIT(runl->id)); 181 } 182 183 void 184 gv100_runl_insert_chan(struct nvkm_chan *chan, struct nvkm_memory *memory, u64 offset) 185 { 186 const u64 user = nvkm_memory_addr(chan->userd.mem) + chan->userd.base; 187 const u64 inst = chan->inst->addr; 188 189 nvkm_wo32(memory, offset + 0x0, lower_32_bits(user) | chan->runq << 1); 190 nvkm_wo32(memory, offset + 0x4, upper_32_bits(user)); 191 nvkm_wo32(memory, offset + 0x8, lower_32_bits(inst) | chan->id); 192 nvkm_wo32(memory, offset + 0xc, upper_32_bits(inst)); 193 } 194 195 void 196 gv100_runl_insert_cgrp(struct nvkm_cgrp *cgrp, struct nvkm_memory *memory, u64 offset) 197 { 198 nvkm_wo32(memory, offset + 0x0, (128 << 24) | (3 << 16) | 0x00000001); 199 nvkm_wo32(memory, offset + 0x4, cgrp->chan_nr); 200 nvkm_wo32(memory, offset + 0x8, cgrp->id); 201 nvkm_wo32(memory, offset + 0xc, 0x00000000); 202 } 203 204 static const struct nvkm_runl_func 205 gv100_runl = { 206 .runqs = 2, 207 .size = 16, 208 .update = nv50_runl_update, 209 .insert_cgrp = gv100_runl_insert_cgrp, 210 .insert_chan = gv100_runl_insert_chan, 211 .commit = gk104_runl_commit, 212 .wait = nv50_runl_wait, 213 .pending = gk104_runl_pending, 214 .block = gk104_runl_block, 215 .allow = gk104_runl_allow, 216 .preempt = gv100_runl_preempt, 217 .preempt_pending = gf100_runl_preempt_pending, 218 }; 219 220 const struct nvkm_enum 221 gv100_fifo_mmu_fault_gpcclient[] = { 222 { 0x00, "T1_0" }, 223 { 0x01, "T1_1" }, 224 { 0x02, "T1_2" }, 225 { 0x03, "T1_3" }, 226 { 0x04, "T1_4" }, 227 { 0x05, "T1_5" }, 228 { 0x06, "T1_6" }, 229 { 0x07, "T1_7" }, 230 { 0x08, "PE_0" }, 231 { 0x09, "PE_1" }, 232 { 0x0a, "PE_2" }, 233 { 0x0b, "PE_3" }, 234 { 0x0c, "PE_4" }, 235 { 0x0d, "PE_5" }, 236 { 0x0e, "PE_6" }, 237 { 0x0f, "PE_7" }, 238 { 0x10, "RAST" }, 239 { 0x11, "GCC" }, 240 { 0x12, "GPCCS" }, 241 { 0x13, "PROP_0" }, 242 { 0x14, "PROP_1" }, 243 { 0x15, "PROP_2" }, 244 { 0x16, "PROP_3" }, 245 { 0x17, "GPM" }, 246 { 0x18, "LTP_UTLB_0" }, 247 { 0x19, "LTP_UTLB_1" }, 248 { 0x1a, "LTP_UTLB_2" }, 249 { 0x1b, "LTP_UTLB_3" }, 250 { 0x1c, "LTP_UTLB_4" }, 251 { 0x1d, "LTP_UTLB_5" }, 252 { 0x1e, "LTP_UTLB_6" }, 253 { 0x1f, "LTP_UTLB_7" }, 254 { 0x20, "RGG_UTLB" }, 255 { 0x21, "T1_8" }, 256 { 0x22, "T1_9" }, 257 { 0x23, "T1_10" }, 258 { 0x24, "T1_11" }, 259 { 0x25, "T1_12" }, 260 { 0x26, "T1_13" }, 261 { 0x27, "T1_14" }, 262 { 0x28, "T1_15" }, 263 { 0x29, "TPCCS_0" }, 264 { 0x2a, "TPCCS_1" }, 265 { 0x2b, "TPCCS_2" }, 266 { 0x2c, "TPCCS_3" }, 267 { 0x2d, "TPCCS_4" }, 268 { 0x2e, "TPCCS_5" }, 269 { 0x2f, "TPCCS_6" }, 270 { 0x30, "TPCCS_7" }, 271 { 0x31, "PE_8" }, 272 { 0x32, "PE_9" }, 273 { 0x33, "TPCCS_8" }, 274 { 0x34, "TPCCS_9" }, 275 { 0x35, "T1_16" }, 276 { 0x36, "T1_17" }, 277 { 0x37, "T1_18" }, 278 { 0x38, "T1_19" }, 279 { 0x39, "PE_10" }, 280 { 0x3a, "PE_11" }, 281 { 0x3b, "TPCCS_10" }, 282 { 0x3c, "TPCCS_11" }, 283 { 0x3d, "T1_20" }, 284 { 0x3e, "T1_21" }, 285 { 0x3f, "T1_22" }, 286 { 0x40, "T1_23" }, 287 { 0x41, "PE_12" }, 288 { 0x42, "PE_13" }, 289 { 0x43, "TPCCS_12" }, 290 { 0x44, "TPCCS_13" }, 291 { 0x45, "T1_24" }, 292 { 0x46, "T1_25" }, 293 { 0x47, "T1_26" }, 294 { 0x48, "T1_27" }, 295 { 0x49, "PE_14" }, 296 { 0x4a, "PE_15" }, 297 { 0x4b, "TPCCS_14" }, 298 { 0x4c, "TPCCS_15" }, 299 { 0x4d, "T1_28" }, 300 { 0x4e, "T1_29" }, 301 { 0x4f, "T1_30" }, 302 { 0x50, "T1_31" }, 303 { 0x51, "PE_16" }, 304 { 0x52, "PE_17" }, 305 { 0x53, "TPCCS_16" }, 306 { 0x54, "TPCCS_17" }, 307 { 0x55, "T1_32" }, 308 { 0x56, "T1_33" }, 309 { 0x57, "T1_34" }, 310 { 0x58, "T1_35" }, 311 { 0x59, "PE_18" }, 312 { 0x5a, "PE_19" }, 313 { 0x5b, "TPCCS_18" }, 314 { 0x5c, "TPCCS_19" }, 315 { 0x5d, "T1_36" }, 316 { 0x5e, "T1_37" }, 317 { 0x5f, "T1_38" }, 318 { 0x60, "T1_39" }, 319 {} 320 }; 321 322 const struct nvkm_enum 323 gv100_fifo_mmu_fault_hubclient[] = { 324 { 0x00, "VIP" }, 325 { 0x01, "CE0" }, 326 { 0x02, "CE1" }, 327 { 0x03, "DNISO" }, 328 { 0x04, "FE" }, 329 { 0x05, "FECS" }, 330 { 0x06, "HOST" }, 331 { 0x07, "HOST_CPU" }, 332 { 0x08, "HOST_CPU_NB" }, 333 { 0x09, "ISO" }, 334 { 0x0a, "MMU" }, 335 { 0x0b, "NVDEC" }, 336 { 0x0d, "NVENC1" }, 337 { 0x0e, "NISO" }, 338 { 0x0f, "P2P" }, 339 { 0x10, "PD" }, 340 { 0x11, "PERF" }, 341 { 0x12, "PMU" }, 342 { 0x13, "RASTERTWOD" }, 343 { 0x14, "SCC" }, 344 { 0x15, "SCC_NB" }, 345 { 0x16, "SEC" }, 346 { 0x17, "SSYNC" }, 347 { 0x18, "CE2" }, 348 { 0x19, "XV" }, 349 { 0x1a, "MMU_NB" }, 350 { 0x1b, "NVENC0" }, 351 { 0x1c, "DFALCON" }, 352 { 0x1d, "SKED" }, 353 { 0x1e, "AFALCON" }, 354 { 0x1f, "DONT_CARE" }, 355 { 0x20, "HSCE0" }, 356 { 0x21, "HSCE1" }, 357 { 0x22, "HSCE2" }, 358 { 0x23, "HSCE3" }, 359 { 0x24, "HSCE4" }, 360 { 0x25, "HSCE5" }, 361 { 0x26, "HSCE6" }, 362 { 0x27, "HSCE7" }, 363 { 0x28, "HSCE8" }, 364 { 0x29, "HSCE9" }, 365 { 0x2a, "HSHUB" }, 366 { 0x2b, "PTP_X0" }, 367 { 0x2c, "PTP_X1" }, 368 { 0x2d, "PTP_X2" }, 369 { 0x2e, "PTP_X3" }, 370 { 0x2f, "PTP_X4" }, 371 { 0x30, "PTP_X5" }, 372 { 0x31, "PTP_X6" }, 373 { 0x32, "PTP_X7" }, 374 { 0x33, "NVENC2" }, 375 { 0x34, "VPR_SCRUBBER0" }, 376 { 0x35, "VPR_SCRUBBER1" }, 377 { 0x36, "DWBIF" }, 378 { 0x37, "FBFALCON" }, 379 { 0x38, "CE_SHIM" }, 380 { 0x39, "GSP" }, 381 {} 382 }; 383 384 const struct nvkm_enum 385 gv100_fifo_mmu_fault_reason[] = { 386 { 0x00, "PDE" }, 387 { 0x01, "PDE_SIZE" }, 388 { 0x02, "PTE" }, 389 { 0x03, "VA_LIMIT_VIOLATION" }, 390 { 0x04, "UNBOUND_INST_BLOCK" }, 391 { 0x05, "PRIV_VIOLATION" }, 392 { 0x06, "RO_VIOLATION" }, 393 { 0x07, "WO_VIOLATION" }, 394 { 0x08, "PITCH_MASK_VIOLATION" }, 395 { 0x09, "WORK_CREATION" }, 396 { 0x0a, "UNSUPPORTED_APERTURE" }, 397 { 0x0b, "COMPRESSION_FAILURE" }, 398 { 0x0c, "UNSUPPORTED_KIND" }, 399 { 0x0d, "REGION_VIOLATION" }, 400 { 0x0e, "POISONED" }, 401 { 0x0f, "ATOMIC_VIOLATION" }, 402 {} 403 }; 404 405 static const struct nvkm_enum 406 gv100_fifo_mmu_fault_engine[] = { 407 { 0x01, "DISPLAY" }, 408 { 0x03, "PTP" }, 409 { 0x04, "BAR1", NULL, NVKM_SUBDEV_BAR }, 410 { 0x05, "BAR2", NULL, NVKM_SUBDEV_INSTMEM }, 411 { 0x06, "PWR_PMU" }, 412 { 0x08, "IFB", NULL, NVKM_ENGINE_IFB }, 413 { 0x09, "PERF" }, 414 { 0x1f, "PHYSICAL" }, 415 { 0x20, "HOST0" }, 416 { 0x21, "HOST1" }, 417 { 0x22, "HOST2" }, 418 { 0x23, "HOST3" }, 419 { 0x24, "HOST4" }, 420 { 0x25, "HOST5" }, 421 { 0x26, "HOST6" }, 422 { 0x27, "HOST7" }, 423 { 0x28, "HOST8" }, 424 { 0x29, "HOST9" }, 425 { 0x2a, "HOST10" }, 426 { 0x2b, "HOST11" }, 427 { 0x2c, "HOST12" }, 428 { 0x2d, "HOST13" }, 429 {} 430 }; 431 432 const struct nvkm_enum 433 gv100_fifo_mmu_fault_access[] = { 434 { 0x0, "VIRT_READ" }, 435 { 0x1, "VIRT_WRITE" }, 436 { 0x2, "VIRT_ATOMIC" }, 437 { 0x3, "VIRT_PREFETCH" }, 438 { 0x4, "VIRT_ATOMIC_WEAK" }, 439 { 0x8, "PHYS_READ" }, 440 { 0x9, "PHYS_WRITE" }, 441 { 0xa, "PHYS_ATOMIC" }, 442 { 0xb, "PHYS_PREFETCH" }, 443 {} 444 }; 445 446 static const struct nvkm_fifo_func_mmu_fault 447 gv100_fifo_mmu_fault = { 448 .recover = gf100_fifo_mmu_fault_recover, 449 .access = gv100_fifo_mmu_fault_access, 450 .engine = gv100_fifo_mmu_fault_engine, 451 .reason = gv100_fifo_mmu_fault_reason, 452 .hubclient = gv100_fifo_mmu_fault_hubclient, 453 .gpcclient = gv100_fifo_mmu_fault_gpcclient, 454 }; 455 456 static void 457 gv100_fifo_intr_ctxsw_timeout(struct nvkm_fifo *fifo, u32 engm) 458 { 459 struct nvkm_runl *runl; 460 struct nvkm_engn *engn; 461 462 nvkm_runl_foreach(runl, fifo) { 463 nvkm_runl_foreach_engn_cond(engn, runl, engm & BIT(engn->id)) 464 nvkm_runl_rc_engn(runl, engn); 465 } 466 } 467 468 static const struct nvkm_fifo_func 469 gv100_fifo = { 470 .dtor = gk104_fifo_dtor, 471 .oneinit = gk104_fifo_oneinit, 472 .chid_nr = gm200_fifo_chid_nr, 473 .chid_ctor = gk110_fifo_chid_ctor, 474 .runq_nr = gm200_fifo_runq_nr, 475 .runl_ctor = gk104_fifo_runl_ctor, 476 .init = gk104_fifo_init, 477 .init_pbdmas = gk104_fifo_init_pbdmas, 478 .intr = gk104_fifo_intr, 479 .intr_ctxsw_timeout = gv100_fifo_intr_ctxsw_timeout, 480 .mmu_fault = &gv100_fifo_mmu_fault, 481 .nonstall = &gf100_fifo_nonstall, 482 .runl = &gv100_runl, 483 .runq = &gv100_runq, 484 .engn = &gv100_engn, 485 .engn_ce = &gv100_engn_ce, 486 .cgrp = {{ 0, 0, KEPLER_CHANNEL_GROUP_A }, &gk110_cgrp, .force = true }, 487 .chan = {{ 0, 0, VOLTA_CHANNEL_GPFIFO_A }, &gv100_chan, .ctor = gv100_fifo_gpfifo_new }, 488 }; 489 490 int 491 gv100_fifo_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, 492 struct nvkm_fifo **pfifo) 493 { 494 return gk104_fifo_new_(&gv100_fifo, device, type, inst, 0, pfifo); 495 } 496