drm/nouveau/fifo: add common runlist control
[linux-block.git] / drivers / gpu / drm / nouveau / nvkm / engine / fifo / gk110.c
CommitLineData
63f8c9b7
BS
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 */
8c4e9f9d 24#include "cgrp.h"
f5e45689 25#include "chan.h"
800ac1f8 26#include "chid.h"
d94470e9 27#include "runl.h"
f5e45689
BS
28
29#include "gk104.h"
63f8c9b7
BS
30#include "changk104.h"
31
8c4e9f9d 32#include <core/memory.h>
acff9415 33#include <subdev/timer.h>
8c4e9f9d 34
f9360c3a
BS
35#include <nvif/class.h>
36
acff9415
BS
37void
38gk110_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
f5e45689
BS
50const struct nvkm_chan_func
51gk110_chan = {
62742b5e
BS
52 .bind = gk104_chan_bind,
53 .unbind = gk104_chan_unbind,
67059b9f
BS
54 .start = gk104_chan_start,
55 .stop = gk104_chan_stop,
acff9415 56 .preempt = gk110_chan_preempt,
f5e45689
BS
57};
58
acff9415
BS
59static void
60gk110_cgrp_preempt(struct nvkm_cgrp *cgrp)
61{
62 nvkm_wr32(cgrp->runl->fifo->engine.subdev.device, 0x002634, 0x01000000 | cgrp->id);
63}
64
f5e45689
BS
65const struct nvkm_cgrp_func
66gk110_cgrp = {
acff9415 67 .preempt = gk110_cgrp_preempt,
f5e45689
BS
68};
69
8c4e9f9d 70void
b084fff2 71gk110_runl_insert_cgrp(struct nvkm_cgrp *cgrp, struct nvkm_memory *memory, u64 offset)
8c4e9f9d
BS
72{
73 nvkm_wo32(memory, offset + 0, (cgrp->chan_nr << 26) | (128 << 18) |
74 (3 << 14) | 0x00002000 | cgrp->id);
75 nvkm_wo32(memory, offset + 4, 0x00000000);
76}
77
d94470e9
BS
78const struct nvkm_runl_func
79gk110_runl = {
b084fff2
BS
80 .size = 8,
81 .update = nv50_runl_update,
82 .insert_cgrp = gk110_runl_insert_cgrp,
83 .insert_chan = gk104_runl_insert_chan,
84 .commit = gk104_runl_commit,
4a492fd5
BS
85 .wait = nv50_runl_wait,
86 .pending = gk104_runl_pending,
3a6bc9c2
BS
87 .block = gk104_runl_block,
88 .allow = gk104_runl_allow,
4d60100a 89 .fault_clear = gk104_runl_fault_clear,
acff9415 90 .preempt_pending = gf100_runl_preempt_pending,
d94470e9
BS
91};
92
800ac1f8
BS
93int
94gk110_fifo_chid_ctor(struct nvkm_fifo *fifo, int nr)
95{
96 int ret;
97
98 ret = nvkm_chid_new(&nvkm_chan_event, &fifo->engine.subdev, nr, 0, nr, &fifo->cgid);
99 if (ret)
100 return ret;
101
102 return gf100_fifo_chid_ctor(fifo, nr);
103}
104
9be9c606 105static const struct nvkm_fifo_func
63f8c9b7 106gk110_fifo = {
9be9c606
BS
107 .dtor = gk104_fifo_dtor,
108 .oneinit = gk104_fifo_oneinit,
8c18138c 109 .chid_nr = gk104_fifo_chid_nr,
800ac1f8 110 .chid_ctor = gk110_fifo_chid_ctor,
1c488ba9 111 .runq_nr = gf100_fifo_runq_nr,
d94470e9 112 .runl_ctor = gk104_fifo_runl_ctor,
9be9c606 113 .init = gk104_fifo_init,
965c41d9 114 .init_pbdmas = gk104_fifo_init_pbdmas,
9be9c606
BS
115 .intr = gk104_fifo_intr,
116 .intr_mmu_fault_unit = gf100_fifo_intr_mmu_fault_unit,
4d60100a 117 .intr_ctxsw_timeout = gf100_fifo_intr_ctxsw_timeout,
9be9c606 118 .mmu_fault = &gk104_fifo_mmu_fault,
9be9c606 119 .engine_id = gk104_fifo_engine_id,
d67f3b96 120 .nonstall = &gf100_fifo_nonstall,
d94470e9 121 .runl = &gk110_runl,
1c488ba9 122 .runq = &gk104_runq,
d94470e9
BS
123 .engn = &gk104_engn,
124 .engn_ce = &gk104_engn_ce,
f5e45689
BS
125 .cgrp = {{ 0, 0, KEPLER_CHANNEL_GROUP_A }, &gk110_cgrp },
126 .chan = {{ 0, 0, KEPLER_CHANNEL_GPFIFO_B }, &gk110_chan, .ctor = &gk104_fifo_gpfifo_new },
63f8c9b7
BS
127};
128
129int
ab0db2bd
BS
130gk110_fifo_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
131 struct nvkm_fifo **pfifo)
63f8c9b7 132{
8c18138c 133 return gk104_fifo_new_(&gk110_fifo, device, type, inst, 0, pfifo);
63f8c9b7 134}