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