1 /* 2 * Copyright 2016 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 * Authors: Ben Skeggs 23 */ 24 #include "cgrp.h" 25 #include "chan.h" 26 #include "chid.h" 27 #include "runl.h" 28 29 #include "gk104.h" 30 #include "changk104.h" 31 32 #include <core/memory.h> 33 #include <subdev/timer.h> 34 35 #include <nvif/class.h> 36 37 void 38 gk110_chan_preempt(struct nvkm_chan *chan) 39 { 40 struct nvkm_cgrp *cgrp = chan->cgrp; 41 42 if (cgrp->hw) { 43 cgrp->func->preempt(cgrp); 44 return; 45 } 46 47 gf100_chan_preempt(chan); 48 } 49 50 const struct nvkm_chan_func 51 gk110_chan = { 52 .inst = &gf100_chan_inst, 53 .bind = gk104_chan_bind, 54 .unbind = gk104_chan_unbind, 55 .start = gk104_chan_start, 56 .stop = gk104_chan_stop, 57 .preempt = gk110_chan_preempt, 58 }; 59 60 static void 61 gk110_cgrp_preempt(struct nvkm_cgrp *cgrp) 62 { 63 nvkm_wr32(cgrp->runl->fifo->engine.subdev.device, 0x002634, 0x01000000 | cgrp->id); 64 } 65 66 const struct nvkm_cgrp_func 67 gk110_cgrp = { 68 .preempt = gk110_cgrp_preempt, 69 }; 70 71 void 72 gk110_runl_insert_cgrp(struct nvkm_cgrp *cgrp, struct nvkm_memory *memory, u64 offset) 73 { 74 nvkm_wo32(memory, offset + 0, (cgrp->chan_nr << 26) | (128 << 18) | 75 (3 << 14) | 0x00002000 | cgrp->id); 76 nvkm_wo32(memory, offset + 4, 0x00000000); 77 } 78 79 const struct nvkm_runl_func 80 gk110_runl = { 81 .size = 8, 82 .update = nv50_runl_update, 83 .insert_cgrp = gk110_runl_insert_cgrp, 84 .insert_chan = gk104_runl_insert_chan, 85 .commit = gk104_runl_commit, 86 .wait = nv50_runl_wait, 87 .pending = gk104_runl_pending, 88 .block = gk104_runl_block, 89 .allow = gk104_runl_allow, 90 .fault_clear = gk104_runl_fault_clear, 91 .preempt_pending = gf100_runl_preempt_pending, 92 }; 93 94 int 95 gk110_fifo_chid_ctor(struct nvkm_fifo *fifo, int nr) 96 { 97 int ret; 98 99 ret = nvkm_chid_new(&nvkm_chan_event, &fifo->engine.subdev, nr, 0, nr, &fifo->cgid); 100 if (ret) 101 return ret; 102 103 return gf100_fifo_chid_ctor(fifo, nr); 104 } 105 106 static const struct nvkm_fifo_func 107 gk110_fifo = { 108 .dtor = gk104_fifo_dtor, 109 .oneinit = gk104_fifo_oneinit, 110 .chid_nr = gk104_fifo_chid_nr, 111 .chid_ctor = gk110_fifo_chid_ctor, 112 .runq_nr = gf100_fifo_runq_nr, 113 .runl_ctor = gk104_fifo_runl_ctor, 114 .init = gk104_fifo_init, 115 .init_pbdmas = gk104_fifo_init_pbdmas, 116 .intr = gk104_fifo_intr, 117 .intr_mmu_fault_unit = gf100_fifo_intr_mmu_fault_unit, 118 .intr_ctxsw_timeout = gf100_fifo_intr_ctxsw_timeout, 119 .mmu_fault = &gk104_fifo_mmu_fault, 120 .engine_id = gk104_fifo_engine_id, 121 .nonstall = &gf100_fifo_nonstall, 122 .runl = &gk110_runl, 123 .runq = &gk104_runq, 124 .engn = &gk104_engn, 125 .engn_ce = &gk104_engn_ce, 126 .cgrp = {{ 0, 0, KEPLER_CHANNEL_GROUP_A }, &gk110_cgrp }, 127 .chan = {{ 0, 0, KEPLER_CHANNEL_GPFIFO_B }, &gk110_chan, .ctor = &gk104_fifo_gpfifo_new }, 128 }; 129 130 int 131 gk110_fifo_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, 132 struct nvkm_fifo **pfifo) 133 { 134 return gk104_fifo_new_(&gk110_fifo, device, type, inst, 0, pfifo); 135 } 136