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