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 "priv.h" 25 #include "cgrp.h" 26 #include "chan.h" 27 #include "chid.h" 28 #include "runl.h" 29 30 #include <core/memory.h> 31 #include <subdev/timer.h> 32 33 #include <nvif/class.h> 34 35 void 36 gk110_chan_preempt(struct nvkm_chan *chan) 37 { 38 struct nvkm_cgrp *cgrp = chan->cgrp; 39 40 if (cgrp->hw) { 41 cgrp->func->preempt(cgrp); 42 return; 43 } 44 45 gf100_chan_preempt(chan); 46 } 47 48 const struct nvkm_chan_func 49 gk110_chan = { 50 .inst = &gf100_chan_inst, 51 .userd = &gk104_chan_userd, 52 .ramfc = &gk104_chan_ramfc, 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 .chid_nr = gk104_fifo_chid_nr, 109 .chid_ctor = gk110_fifo_chid_ctor, 110 .runq_nr = gf100_fifo_runq_nr, 111 .runl_ctor = gk104_fifo_runl_ctor, 112 .init = gk104_fifo_init, 113 .init_pbdmas = gk104_fifo_init_pbdmas, 114 .intr = gk104_fifo_intr, 115 .intr_mmu_fault_unit = gf100_fifo_intr_mmu_fault_unit, 116 .intr_ctxsw_timeout = gf100_fifo_intr_ctxsw_timeout, 117 .mmu_fault = &gk104_fifo_mmu_fault, 118 .nonstall = &gf100_fifo_nonstall, 119 .runl = &gk110_runl, 120 .runq = &gk104_runq, 121 .engn = &gk104_engn, 122 .engn_ce = &gk104_engn_ce, 123 .cgrp = {{ 0, 0, KEPLER_CHANNEL_GROUP_A }, &gk110_cgrp }, 124 .chan = {{ 0, 0, KEPLER_CHANNEL_GPFIFO_B }, &gk110_chan }, 125 }; 126 127 int 128 gk110_fifo_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, 129 struct nvkm_fifo **pfifo) 130 { 131 return nvkm_fifo_new_(&gk110_fifo, device, type, inst, pfifo); 132 } 133