Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 1 | /* |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 2 | * Copyright 2012 Red Hat Inc. |
Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 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 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 25 | #include <core/client.h> |
| 26 | #include <core/handle.h> |
| 27 | #include <core/namedb.h> |
| 28 | #include <core/gpuobj.h> |
| 29 | #include <core/engctx.h> |
Ben Skeggs | 9bd2ddb | 2013-01-31 13:51:20 +1000 | [diff] [blame] | 30 | #include <core/event.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 31 | #include <core/class.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 32 | #include <core/enum.h> |
Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 33 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 34 | #include <subdev/timer.h> |
| 35 | #include <subdev/bar.h> |
Ben Skeggs | 5222555 | 2013-12-23 01:51:16 +1000 | [diff] [blame] | 36 | #include <subdev/fb.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 37 | #include <subdev/vm.h> |
| 38 | |
| 39 | #include <engine/dmaobj.h> |
Ben Skeggs | 02a841d | 2012-07-04 23:44:54 +1000 | [diff] [blame] | 40 | #include <engine/fifo.h> |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 41 | |
| 42 | struct nvc0_fifo_priv { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 43 | struct nouveau_fifo base; |
Ben Skeggs | a07d0e7 | 2014-02-22 00:28:47 +1000 | [diff] [blame^] | 44 | struct { |
| 45 | struct nouveau_gpuobj *mem[2]; |
| 46 | int active; |
| 47 | wait_queue_head_t wait; |
| 48 | } runlist; |
Ben Skeggs | 9da226f | 2012-07-13 16:54:45 +1000 | [diff] [blame] | 49 | struct { |
| 50 | struct nouveau_gpuobj *mem; |
| 51 | struct nouveau_vma bar; |
| 52 | } user; |
Ben Skeggs | ec9c088 | 2010-12-31 12:10:49 +1000 | [diff] [blame] | 53 | int spoon_nr; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 54 | }; |
| 55 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 56 | struct nvc0_fifo_base { |
| 57 | struct nouveau_fifo_base base; |
| 58 | struct nouveau_gpuobj *pgd; |
| 59 | struct nouveau_vm *vm; |
| 60 | }; |
| 61 | |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 62 | struct nvc0_fifo_chan { |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 63 | struct nouveau_fifo_chan base; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 64 | }; |
| 65 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 66 | /******************************************************************************* |
| 67 | * FIFO channel objects |
| 68 | ******************************************************************************/ |
| 69 | |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 70 | static void |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 71 | nvc0_fifo_runlist_update(struct nvc0_fifo_priv *priv) |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 72 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 73 | struct nouveau_bar *bar = nouveau_bar(priv); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 74 | struct nouveau_gpuobj *cur; |
| 75 | int i, p; |
| 76 | |
Ben Skeggs | fadb171 | 2013-05-13 10:02:11 +1000 | [diff] [blame] | 77 | mutex_lock(&nv_subdev(priv)->mutex); |
Ben Skeggs | a07d0e7 | 2014-02-22 00:28:47 +1000 | [diff] [blame^] | 78 | cur = priv->runlist.mem[priv->runlist.active]; |
| 79 | priv->runlist.active = !priv->runlist.active; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 80 | |
| 81 | for (i = 0, p = 0; i < 128; i++) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 82 | if (!(nv_rd32(priv, 0x003004 + (i * 8)) & 1)) |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 83 | continue; |
| 84 | nv_wo32(cur, p + 0, i); |
| 85 | nv_wo32(cur, p + 4, 0x00000004); |
| 86 | p += 8; |
| 87 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 88 | bar->flush(bar); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 89 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 90 | nv_wr32(priv, 0x002270, cur->addr >> 12); |
| 91 | nv_wr32(priv, 0x002274, 0x01f00000 | (p >> 3)); |
| 92 | if (!nv_wait(priv, 0x00227c, 0x00100000, 0x00000000)) |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 93 | nv_error(priv, "runlist update failed\n"); |
Ben Skeggs | fadb171 | 2013-05-13 10:02:11 +1000 | [diff] [blame] | 94 | mutex_unlock(&nv_subdev(priv)->mutex); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 95 | } |
Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 96 | |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 97 | static int |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 98 | nvc0_fifo_context_attach(struct nouveau_object *parent, |
| 99 | struct nouveau_object *object) |
Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 100 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 101 | struct nouveau_bar *bar = nouveau_bar(parent); |
| 102 | struct nvc0_fifo_base *base = (void *)parent->parent; |
| 103 | struct nouveau_engctx *ectx = (void *)object; |
| 104 | u32 addr; |
| 105 | int ret; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 106 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 107 | switch (nv_engidx(object->engine)) { |
| 108 | case NVDEV_ENGINE_SW : return 0; |
| 109 | case NVDEV_ENGINE_GR : addr = 0x0210; break; |
| 110 | case NVDEV_ENGINE_COPY0: addr = 0x0230; break; |
| 111 | case NVDEV_ENGINE_COPY1: addr = 0x0240; break; |
Maarten Lankhorst | 23c14ed | 2012-11-23 11:08:23 +1000 | [diff] [blame] | 112 | case NVDEV_ENGINE_BSP : addr = 0x0270; break; |
| 113 | case NVDEV_ENGINE_VP : addr = 0x0250; break; |
| 114 | case NVDEV_ENGINE_PPP : addr = 0x0260; break; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 115 | default: |
| 116 | return -EINVAL; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 117 | } |
| 118 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 119 | if (!ectx->vma.node) { |
| 120 | ret = nouveau_gpuobj_map_vm(nv_gpuobj(ectx), base->vm, |
| 121 | NV_MEM_ACCESS_RW, &ectx->vma); |
| 122 | if (ret) |
| 123 | return ret; |
Ben Skeggs | 4c2d422 | 2012-08-10 15:10:34 +1000 | [diff] [blame] | 124 | |
| 125 | nv_engctx(ectx)->addr = nv_gpuobj(base)->addr >> 12; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 126 | } |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 127 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 128 | nv_wo32(base, addr + 0x00, lower_32_bits(ectx->vma.offset) | 4); |
| 129 | nv_wo32(base, addr + 0x04, upper_32_bits(ectx->vma.offset)); |
| 130 | bar->flush(bar); |
| 131 | return 0; |
| 132 | } |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 133 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 134 | static int |
| 135 | nvc0_fifo_context_detach(struct nouveau_object *parent, bool suspend, |
| 136 | struct nouveau_object *object) |
| 137 | { |
| 138 | struct nouveau_bar *bar = nouveau_bar(parent); |
| 139 | struct nvc0_fifo_priv *priv = (void *)parent->engine; |
| 140 | struct nvc0_fifo_base *base = (void *)parent->parent; |
| 141 | struct nvc0_fifo_chan *chan = (void *)parent; |
| 142 | u32 addr; |
| 143 | |
| 144 | switch (nv_engidx(object->engine)) { |
| 145 | case NVDEV_ENGINE_SW : return 0; |
| 146 | case NVDEV_ENGINE_GR : addr = 0x0210; break; |
| 147 | case NVDEV_ENGINE_COPY0: addr = 0x0230; break; |
| 148 | case NVDEV_ENGINE_COPY1: addr = 0x0240; break; |
Maarten Lankhorst | 23c14ed | 2012-11-23 11:08:23 +1000 | [diff] [blame] | 149 | case NVDEV_ENGINE_BSP : addr = 0x0270; break; |
| 150 | case NVDEV_ENGINE_VP : addr = 0x0250; break; |
| 151 | case NVDEV_ENGINE_PPP : addr = 0x0260; break; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 152 | default: |
| 153 | return -EINVAL; |
| 154 | } |
| 155 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 156 | nv_wr32(priv, 0x002634, chan->base.chid); |
| 157 | if (!nv_wait(priv, 0x002634, 0xffffffff, chan->base.chid)) { |
Marcin Slusarz | 93260d3 | 2012-12-09 23:00:34 +0100 | [diff] [blame] | 158 | nv_error(priv, "channel %d [%s] kick timeout\n", |
| 159 | chan->base.chid, nouveau_client_name(chan)); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 160 | if (suspend) |
| 161 | return -EBUSY; |
| 162 | } |
| 163 | |
Ben Skeggs | edc260d | 2012-11-27 11:05:36 +1000 | [diff] [blame] | 164 | nv_wo32(base, addr + 0x00, 0x00000000); |
| 165 | nv_wo32(base, addr + 0x04, 0x00000000); |
| 166 | bar->flush(bar); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static int |
| 171 | nvc0_fifo_chan_ctor(struct nouveau_object *parent, |
| 172 | struct nouveau_object *engine, |
| 173 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 174 | struct nouveau_object **pobject) |
| 175 | { |
| 176 | struct nouveau_bar *bar = nouveau_bar(parent); |
| 177 | struct nvc0_fifo_priv *priv = (void *)engine; |
| 178 | struct nvc0_fifo_base *base = (void *)parent; |
| 179 | struct nvc0_fifo_chan *chan; |
Ben Skeggs | dbff2de | 2012-08-06 18:16:37 +1000 | [diff] [blame] | 180 | struct nv50_channel_ind_class *args = data; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 181 | u64 usermem, ioffset, ilength; |
| 182 | int ret, i; |
| 183 | |
| 184 | if (size < sizeof(*args)) |
| 185 | return -EINVAL; |
| 186 | |
| 187 | ret = nouveau_fifo_channel_create(parent, engine, oclass, 1, |
| 188 | priv->user.bar.offset, 0x1000, |
| 189 | args->pushbuf, |
Martin Peres | 507ceb1 | 2012-11-27 00:30:32 +0100 | [diff] [blame] | 190 | (1ULL << NVDEV_ENGINE_SW) | |
| 191 | (1ULL << NVDEV_ENGINE_GR) | |
| 192 | (1ULL << NVDEV_ENGINE_COPY0) | |
| 193 | (1ULL << NVDEV_ENGINE_COPY1) | |
| 194 | (1ULL << NVDEV_ENGINE_BSP) | |
| 195 | (1ULL << NVDEV_ENGINE_VP) | |
| 196 | (1ULL << NVDEV_ENGINE_PPP), &chan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 197 | *pobject = nv_object(chan); |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 198 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 199 | return ret; |
| 200 | |
| 201 | nv_parent(chan)->context_attach = nvc0_fifo_context_attach; |
| 202 | nv_parent(chan)->context_detach = nvc0_fifo_context_detach; |
| 203 | |
| 204 | usermem = chan->base.chid * 0x1000; |
| 205 | ioffset = args->ioffset; |
Ilia Mirkin | 57be046 | 2013-07-27 00:27:00 -0400 | [diff] [blame] | 206 | ilength = order_base_2(args->ilength / 8); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 207 | |
| 208 | for (i = 0; i < 0x1000; i += 4) |
| 209 | nv_wo32(priv->user.mem, usermem + i, 0x00000000); |
| 210 | |
| 211 | nv_wo32(base, 0x08, lower_32_bits(priv->user.mem->addr + usermem)); |
| 212 | nv_wo32(base, 0x0c, upper_32_bits(priv->user.mem->addr + usermem)); |
| 213 | nv_wo32(base, 0x10, 0x0000face); |
| 214 | nv_wo32(base, 0x30, 0xfffff902); |
| 215 | nv_wo32(base, 0x48, lower_32_bits(ioffset)); |
| 216 | nv_wo32(base, 0x4c, upper_32_bits(ioffset) | (ilength << 16)); |
| 217 | nv_wo32(base, 0x54, 0x00000002); |
| 218 | nv_wo32(base, 0x84, 0x20400000); |
| 219 | nv_wo32(base, 0x94, 0x30000001); |
| 220 | nv_wo32(base, 0x9c, 0x00000100); |
| 221 | nv_wo32(base, 0xa4, 0x1f1f1f1f); |
| 222 | nv_wo32(base, 0xa8, 0x1f1f1f1f); |
| 223 | nv_wo32(base, 0xac, 0x0000001f); |
| 224 | nv_wo32(base, 0xb8, 0xf8000000); |
| 225 | nv_wo32(base, 0xf8, 0x10003080); /* 0x002310 */ |
| 226 | nv_wo32(base, 0xfc, 0x10000010); /* 0x002350 */ |
| 227 | bar->flush(bar); |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int |
| 232 | nvc0_fifo_chan_init(struct nouveau_object *object) |
| 233 | { |
| 234 | struct nouveau_gpuobj *base = nv_gpuobj(object->parent); |
| 235 | struct nvc0_fifo_priv *priv = (void *)object->engine; |
| 236 | struct nvc0_fifo_chan *chan = (void *)object; |
| 237 | u32 chid = chan->base.chid; |
| 238 | int ret; |
| 239 | |
| 240 | ret = nouveau_fifo_channel_init(&chan->base); |
| 241 | if (ret) |
| 242 | return ret; |
| 243 | |
| 244 | nv_wr32(priv, 0x003000 + (chid * 8), 0xc0000000 | base->addr >> 12); |
| 245 | nv_wr32(priv, 0x003004 + (chid * 8), 0x001f0001); |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 246 | nvc0_fifo_runlist_update(priv); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 247 | return 0; |
| 248 | } |
| 249 | |
Ben Skeggs | e99bf01 | 2014-02-22 00:18:17 +1000 | [diff] [blame] | 250 | static void nvc0_fifo_intr_engine(struct nvc0_fifo_priv *priv); |
| 251 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 252 | static int |
| 253 | nvc0_fifo_chan_fini(struct nouveau_object *object, bool suspend) |
| 254 | { |
| 255 | struct nvc0_fifo_priv *priv = (void *)object->engine; |
| 256 | struct nvc0_fifo_chan *chan = (void *)object; |
| 257 | u32 chid = chan->base.chid; |
| 258 | |
| 259 | nv_mask(priv, 0x003004 + (chid * 8), 0x00000001, 0x00000000); |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 260 | nvc0_fifo_runlist_update(priv); |
Ben Skeggs | e99bf01 | 2014-02-22 00:18:17 +1000 | [diff] [blame] | 261 | |
| 262 | nvc0_fifo_intr_engine(priv); |
| 263 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 264 | nv_wr32(priv, 0x003000 + (chid * 8), 0x00000000); |
| 265 | |
| 266 | return nouveau_fifo_channel_fini(&chan->base, suspend); |
| 267 | } |
| 268 | |
| 269 | static struct nouveau_ofuncs |
| 270 | nvc0_fifo_ofuncs = { |
| 271 | .ctor = nvc0_fifo_chan_ctor, |
| 272 | .dtor = _nouveau_fifo_channel_dtor, |
| 273 | .init = nvc0_fifo_chan_init, |
| 274 | .fini = nvc0_fifo_chan_fini, |
| 275 | .rd32 = _nouveau_fifo_channel_rd32, |
| 276 | .wr32 = _nouveau_fifo_channel_wr32, |
| 277 | }; |
| 278 | |
| 279 | static struct nouveau_oclass |
| 280 | nvc0_fifo_sclass[] = { |
Ben Skeggs | c97f8c9 | 2012-08-19 16:03:00 +1000 | [diff] [blame] | 281 | { NVC0_CHANNEL_IND_CLASS, &nvc0_fifo_ofuncs }, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 282 | {} |
| 283 | }; |
| 284 | |
| 285 | /******************************************************************************* |
| 286 | * FIFO context - instmem heap and vm setup |
| 287 | ******************************************************************************/ |
| 288 | |
| 289 | static int |
| 290 | nvc0_fifo_context_ctor(struct nouveau_object *parent, |
| 291 | struct nouveau_object *engine, |
| 292 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 293 | struct nouveau_object **pobject) |
| 294 | { |
| 295 | struct nvc0_fifo_base *base; |
| 296 | int ret; |
| 297 | |
| 298 | ret = nouveau_fifo_context_create(parent, engine, oclass, NULL, 0x1000, |
| 299 | 0x1000, NVOBJ_FLAG_ZERO_ALLOC | |
| 300 | NVOBJ_FLAG_HEAP, &base); |
| 301 | *pobject = nv_object(base); |
| 302 | if (ret) |
| 303 | return ret; |
| 304 | |
Ben Skeggs | f50c805 | 2013-04-24 18:02:35 +1000 | [diff] [blame] | 305 | ret = nouveau_gpuobj_new(nv_object(base), NULL, 0x10000, 0x1000, 0, |
| 306 | &base->pgd); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 307 | if (ret) |
| 308 | return ret; |
| 309 | |
| 310 | nv_wo32(base, 0x0200, lower_32_bits(base->pgd->addr)); |
| 311 | nv_wo32(base, 0x0204, upper_32_bits(base->pgd->addr)); |
| 312 | nv_wo32(base, 0x0208, 0xffffffff); |
| 313 | nv_wo32(base, 0x020c, 0x000000ff); |
| 314 | |
| 315 | ret = nouveau_vm_ref(nouveau_client(parent)->vm, &base->vm, base->pgd); |
| 316 | if (ret) |
| 317 | return ret; |
| 318 | |
| 319 | return 0; |
Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 320 | } |
| 321 | |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 322 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 323 | nvc0_fifo_context_dtor(struct nouveau_object *object) |
Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 324 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 325 | struct nvc0_fifo_base *base = (void *)object; |
| 326 | nouveau_vm_ref(NULL, &base->vm, base->pgd); |
| 327 | nouveau_gpuobj_ref(NULL, &base->pgd); |
| 328 | nouveau_fifo_context_destroy(&base->base); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 329 | } |
| 330 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 331 | static struct nouveau_oclass |
| 332 | nvc0_fifo_cclass = { |
| 333 | .handle = NV_ENGCTX(FIFO, 0xc0), |
| 334 | .ofuncs = &(struct nouveau_ofuncs) { |
| 335 | .ctor = nvc0_fifo_context_ctor, |
| 336 | .dtor = nvc0_fifo_context_dtor, |
| 337 | .init = _nouveau_fifo_context_init, |
| 338 | .fini = _nouveau_fifo_context_fini, |
| 339 | .rd32 = _nouveau_fifo_context_rd32, |
| 340 | .wr32 = _nouveau_fifo_context_wr32, |
| 341 | }, |
| 342 | }; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 343 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 344 | /******************************************************************************* |
| 345 | * PFIFO engine |
| 346 | ******************************************************************************/ |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 347 | |
Marcin Slusarz | e662625 | 2012-08-19 22:59:59 +0200 | [diff] [blame] | 348 | static const struct nouveau_enum nvc0_fifo_fault_unit[] = { |
Marcin Slusarz | 93260d3 | 2012-12-09 23:00:34 +0100 | [diff] [blame] | 349 | { 0x00, "PGRAPH", NULL, NVDEV_ENGINE_GR }, |
Ben Skeggs | 7a31347 | 2011-03-29 00:52:59 +1000 | [diff] [blame] | 350 | { 0x03, "PEEPHOLE" }, |
| 351 | { 0x04, "BAR1" }, |
| 352 | { 0x05, "BAR3" }, |
Marcin Slusarz | 93260d3 | 2012-12-09 23:00:34 +0100 | [diff] [blame] | 353 | { 0x07, "PFIFO", NULL, NVDEV_ENGINE_FIFO }, |
| 354 | { 0x10, "PBSP", NULL, NVDEV_ENGINE_BSP }, |
| 355 | { 0x11, "PPPP", NULL, NVDEV_ENGINE_PPP }, |
Ben Skeggs | 7a31347 | 2011-03-29 00:52:59 +1000 | [diff] [blame] | 356 | { 0x13, "PCOUNTER" }, |
Marcin Slusarz | 93260d3 | 2012-12-09 23:00:34 +0100 | [diff] [blame] | 357 | { 0x14, "PVP", NULL, NVDEV_ENGINE_VP }, |
| 358 | { 0x15, "PCOPY0", NULL, NVDEV_ENGINE_COPY0 }, |
| 359 | { 0x16, "PCOPY1", NULL, NVDEV_ENGINE_COPY1 }, |
Ben Skeggs | 7a31347 | 2011-03-29 00:52:59 +1000 | [diff] [blame] | 360 | { 0x17, "PDAEMON" }, |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 361 | {} |
| 362 | }; |
| 363 | |
Marcin Slusarz | e662625 | 2012-08-19 22:59:59 +0200 | [diff] [blame] | 364 | static const struct nouveau_enum nvc0_fifo_fault_reason[] = { |
Ben Skeggs | e296663 | 2011-03-29 08:57:34 +1000 | [diff] [blame] | 365 | { 0x00, "PT_NOT_PRESENT" }, |
| 366 | { 0x01, "PT_TOO_SHORT" }, |
| 367 | { 0x02, "PAGE_NOT_PRESENT" }, |
| 368 | { 0x03, "VM_LIMIT_EXCEEDED" }, |
| 369 | { 0x04, "NO_CHANNEL" }, |
| 370 | { 0x05, "PAGE_SYSTEM_ONLY" }, |
| 371 | { 0x06, "PAGE_READ_ONLY" }, |
| 372 | { 0x0a, "COMPRESSED_SYSRAM" }, |
| 373 | { 0x0c, "INVALID_STORAGE_TYPE" }, |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 374 | {} |
| 375 | }; |
| 376 | |
Marcin Slusarz | e662625 | 2012-08-19 22:59:59 +0200 | [diff] [blame] | 377 | static const struct nouveau_enum nvc0_fifo_fault_hubclient[] = { |
Ben Skeggs | 7795bee | 2011-03-29 09:28:24 +1000 | [diff] [blame] | 378 | { 0x01, "PCOPY0" }, |
| 379 | { 0x02, "PCOPY1" }, |
| 380 | { 0x04, "DISPATCH" }, |
| 381 | { 0x05, "CTXCTL" }, |
| 382 | { 0x06, "PFIFO" }, |
| 383 | { 0x07, "BAR_READ" }, |
| 384 | { 0x08, "BAR_WRITE" }, |
| 385 | { 0x0b, "PVP" }, |
| 386 | { 0x0c, "PPPP" }, |
| 387 | { 0x0d, "PBSP" }, |
| 388 | { 0x11, "PCOUNTER" }, |
| 389 | { 0x12, "PDAEMON" }, |
| 390 | { 0x14, "CCACHE" }, |
| 391 | { 0x15, "CCACHE_POST" }, |
| 392 | {} |
| 393 | }; |
| 394 | |
Marcin Slusarz | e662625 | 2012-08-19 22:59:59 +0200 | [diff] [blame] | 395 | static const struct nouveau_enum nvc0_fifo_fault_gpcclient[] = { |
Ben Skeggs | 7795bee | 2011-03-29 09:28:24 +1000 | [diff] [blame] | 396 | { 0x01, "TEX" }, |
| 397 | { 0x0c, "ESETUP" }, |
| 398 | { 0x0e, "CTXCTL" }, |
| 399 | { 0x0f, "PROP" }, |
| 400 | {} |
| 401 | }; |
| 402 | |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 403 | static const struct nouveau_bitfield nvc0_fifo_pbdma_intr[] = { |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 404 | /* { 0x00008000, "" } seen with null ib push */ |
| 405 | { 0x00200000, "ILLEGAL_MTHD" }, |
| 406 | { 0x00800000, "EMPTY_SUBC" }, |
| 407 | {} |
| 408 | }; |
| 409 | |
| 410 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 411 | nvc0_fifo_isr_vm_fault(struct nvc0_fifo_priv *priv, int unit) |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 412 | { |
Ben Skeggs | b3ccd34 | 2012-09-06 20:26:38 -0400 | [diff] [blame] | 413 | u32 inst = nv_rd32(priv, 0x002800 + (unit * 0x10)); |
| 414 | u32 valo = nv_rd32(priv, 0x002804 + (unit * 0x10)); |
| 415 | u32 vahi = nv_rd32(priv, 0x002808 + (unit * 0x10)); |
| 416 | u32 stat = nv_rd32(priv, 0x00280c + (unit * 0x10)); |
Ben Skeggs | 7795bee | 2011-03-29 09:28:24 +1000 | [diff] [blame] | 417 | u32 client = (stat & 0x00001f00) >> 8; |
Marcin Slusarz | 93260d3 | 2012-12-09 23:00:34 +0100 | [diff] [blame] | 418 | const struct nouveau_enum *en; |
| 419 | struct nouveau_engine *engine; |
| 420 | struct nouveau_object *engctx = NULL; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 421 | |
Ben Skeggs | b3ccd34 | 2012-09-06 20:26:38 -0400 | [diff] [blame] | 422 | switch (unit) { |
| 423 | case 3: /* PEEPHOLE */ |
| 424 | nv_mask(priv, 0x001718, 0x00000000, 0x00000000); |
| 425 | break; |
| 426 | case 4: /* BAR1 */ |
| 427 | nv_mask(priv, 0x001704, 0x00000000, 0x00000000); |
| 428 | break; |
| 429 | case 5: /* BAR3 */ |
| 430 | nv_mask(priv, 0x001714, 0x00000000, 0x00000000); |
| 431 | break; |
| 432 | default: |
| 433 | break; |
| 434 | } |
| 435 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 436 | nv_error(priv, "%s fault at 0x%010llx [", (stat & 0x00000080) ? |
| 437 | "write" : "read", (u64)vahi << 32 | valo); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 438 | nouveau_enum_print(nvc0_fifo_fault_reason, stat & 0x0000000f); |
Marcin Slusarz | f533da1 | 2012-12-09 15:45:20 +0100 | [diff] [blame] | 439 | pr_cont("] from "); |
Marcin Slusarz | 93260d3 | 2012-12-09 23:00:34 +0100 | [diff] [blame] | 440 | en = nouveau_enum_print(nvc0_fifo_fault_unit, unit); |
Ben Skeggs | 7795bee | 2011-03-29 09:28:24 +1000 | [diff] [blame] | 441 | if (stat & 0x00000040) { |
Marcin Slusarz | f533da1 | 2012-12-09 15:45:20 +0100 | [diff] [blame] | 442 | pr_cont("/"); |
Ben Skeggs | 7795bee | 2011-03-29 09:28:24 +1000 | [diff] [blame] | 443 | nouveau_enum_print(nvc0_fifo_fault_hubclient, client); |
| 444 | } else { |
Marcin Slusarz | f533da1 | 2012-12-09 15:45:20 +0100 | [diff] [blame] | 445 | pr_cont("/GPC%d/", (stat & 0x1f000000) >> 24); |
Ben Skeggs | 7795bee | 2011-03-29 09:28:24 +1000 | [diff] [blame] | 446 | nouveau_enum_print(nvc0_fifo_fault_gpcclient, client); |
| 447 | } |
Marcin Slusarz | 93260d3 | 2012-12-09 23:00:34 +0100 | [diff] [blame] | 448 | |
| 449 | if (en && en->data2) { |
| 450 | engine = nouveau_engine(priv, en->data2); |
| 451 | if (engine) |
| 452 | engctx = nouveau_engctx_get(engine, inst); |
| 453 | |
| 454 | } |
| 455 | pr_cont(" on channel 0x%010llx [%s]\n", (u64)inst << 12, |
| 456 | nouveau_client_name(engctx)); |
| 457 | |
| 458 | nouveau_engctx_put(engctx); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 459 | } |
| 460 | |
Ben Skeggs | d5316e2 | 2012-03-21 13:53:49 +1000 | [diff] [blame] | 461 | static int |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 462 | nvc0_fifo_swmthd(struct nvc0_fifo_priv *priv, u32 chid, u32 mthd, u32 data) |
Ben Skeggs | d5316e2 | 2012-03-21 13:53:49 +1000 | [diff] [blame] | 463 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 464 | struct nvc0_fifo_chan *chan = NULL; |
| 465 | struct nouveau_handle *bind; |
Ben Skeggs | d5316e2 | 2012-03-21 13:53:49 +1000 | [diff] [blame] | 466 | unsigned long flags; |
| 467 | int ret = -EINVAL; |
| 468 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 469 | spin_lock_irqsave(&priv->base.lock, flags); |
| 470 | if (likely(chid >= priv->base.min && chid <= priv->base.max)) |
| 471 | chan = (void *)priv->base.channel[chid]; |
| 472 | if (unlikely(!chan)) |
| 473 | goto out; |
| 474 | |
| 475 | bind = nouveau_namedb_get_class(nv_namedb(chan), 0x906e); |
| 476 | if (likely(bind)) { |
| 477 | if (!mthd || !nv_call(bind->object, mthd, data)) |
| 478 | ret = 0; |
| 479 | nouveau_namedb_put(bind); |
Ben Skeggs | d5316e2 | 2012-03-21 13:53:49 +1000 | [diff] [blame] | 480 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 481 | |
| 482 | out: |
| 483 | spin_unlock_irqrestore(&priv->base.lock, flags); |
Ben Skeggs | d5316e2 | 2012-03-21 13:53:49 +1000 | [diff] [blame] | 484 | return ret; |
| 485 | } |
| 486 | |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 487 | static void |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 488 | nvc0_fifo_isr_pbdma_intr(struct nvc0_fifo_priv *priv, int unit) |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 489 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 490 | u32 stat = nv_rd32(priv, 0x040108 + (unit * 0x2000)); |
| 491 | u32 addr = nv_rd32(priv, 0x0400c0 + (unit * 0x2000)); |
| 492 | u32 data = nv_rd32(priv, 0x0400c4 + (unit * 0x2000)); |
| 493 | u32 chid = nv_rd32(priv, 0x040120 + (unit * 0x2000)) & 0x7f; |
| 494 | u32 subc = (addr & 0x00070000) >> 16; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 495 | u32 mthd = (addr & 0x00003ffc); |
Ben Skeggs | d5316e2 | 2012-03-21 13:53:49 +1000 | [diff] [blame] | 496 | u32 show = stat; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 497 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 498 | if (stat & 0x00800000) { |
| 499 | if (!nvc0_fifo_swmthd(priv, chid, mthd, data)) |
| 500 | show &= ~0x00800000; |
Ben Skeggs | d5316e2 | 2012-03-21 13:53:49 +1000 | [diff] [blame] | 501 | } |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 502 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 503 | if (show) { |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 504 | nv_error(priv, "PBDMA%d:", unit); |
| 505 | nouveau_bitfield_print(nvc0_fifo_pbdma_intr, show); |
Marcin Slusarz | f533da1 | 2012-12-09 15:45:20 +0100 | [diff] [blame] | 506 | pr_cont("\n"); |
Marcin Slusarz | 93260d3 | 2012-12-09 23:00:34 +0100 | [diff] [blame] | 507 | nv_error(priv, |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 508 | "PBDMA%d: ch %d [%s] subc %d mthd 0x%04x data 0x%08x\n", |
Marcin Slusarz | 93260d3 | 2012-12-09 23:00:34 +0100 | [diff] [blame] | 509 | unit, chid, |
| 510 | nouveau_client_name_for_fifo_chid(&priv->base, chid), |
| 511 | subc, mthd, data); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | nv_wr32(priv, 0x0400c0 + (unit * 0x2000), 0x80600008); |
| 515 | nv_wr32(priv, 0x040108 + (unit * 0x2000), stat); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void |
Ben Skeggs | a07d0e7 | 2014-02-22 00:28:47 +1000 | [diff] [blame^] | 519 | nvc0_fifo_intr_runlist(struct nvc0_fifo_priv *priv) |
| 520 | { |
| 521 | u32 intr = nv_rd32(priv, 0x002a00); |
| 522 | |
| 523 | if (intr & 0x10000000) { |
| 524 | wake_up(&priv->runlist.wait); |
| 525 | nv_wr32(priv, 0x002a00, 0x10000000); |
| 526 | intr &= ~0x10000000; |
| 527 | } |
| 528 | |
| 529 | if (intr) { |
| 530 | nv_error(priv, "RUNLIST 0x%08x\n", intr); |
| 531 | nv_wr32(priv, 0x002a00, intr); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | static void |
Ben Skeggs | e99bf01 | 2014-02-22 00:18:17 +1000 | [diff] [blame] | 536 | nvc0_fifo_intr_engine_unit(struct nvc0_fifo_priv *priv, int engn) |
| 537 | { |
| 538 | u32 intr = nv_rd32(priv, 0x0025a8 + (engn * 0x04)); |
| 539 | u32 inte = nv_rd32(priv, 0x002628); |
| 540 | u32 unkn; |
| 541 | |
| 542 | for (unkn = 0; unkn < 8; unkn++) { |
| 543 | u32 ints = (intr >> (unkn * 0x04)) & inte; |
| 544 | if (ints & 0x1) { |
| 545 | nouveau_event_trigger(priv->base.uevent, 0); |
| 546 | ints &= ~1; |
| 547 | } |
| 548 | if (ints) { |
| 549 | nv_error(priv, "ENGINE %d %d %01x", engn, unkn, ints); |
| 550 | nv_mask(priv, 0x002628, ints, 0); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | nv_wr32(priv, 0x0025a8 + (engn * 0x04), intr); |
| 555 | } |
| 556 | |
| 557 | static void |
| 558 | nvc0_fifo_intr_engine(struct nvc0_fifo_priv *priv) |
| 559 | { |
| 560 | u32 mask = nv_rd32(priv, 0x0025a4); |
| 561 | while (mask) { |
| 562 | u32 unit = __ffs(mask); |
| 563 | nvc0_fifo_intr_engine_unit(priv, unit); |
| 564 | mask &= ~(1 << unit); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 569 | nvc0_fifo_intr(struct nouveau_subdev *subdev) |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 570 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 571 | struct nvc0_fifo_priv *priv = (void *)subdev; |
| 572 | u32 mask = nv_rd32(priv, 0x002140); |
| 573 | u32 stat = nv_rd32(priv, 0x002100) & mask; |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 574 | |
Ben Skeggs | 32256c8 | 2013-01-31 19:49:33 -0500 | [diff] [blame] | 575 | if (stat & 0x00000001) { |
| 576 | u32 intr = nv_rd32(priv, 0x00252c); |
| 577 | nv_warn(priv, "INTR 0x00000001: 0x%08x\n", intr); |
| 578 | nv_wr32(priv, 0x002100, 0x00000001); |
| 579 | stat &= ~0x00000001; |
| 580 | } |
| 581 | |
Ben Skeggs | cc8cd64 | 2011-01-28 13:42:16 +1000 | [diff] [blame] | 582 | if (stat & 0x00000100) { |
Ben Skeggs | 32256c8 | 2013-01-31 19:49:33 -0500 | [diff] [blame] | 583 | u32 intr = nv_rd32(priv, 0x00254c); |
| 584 | nv_warn(priv, "INTR 0x00000100: 0x%08x\n", intr); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 585 | nv_wr32(priv, 0x002100, 0x00000100); |
Ben Skeggs | cc8cd64 | 2011-01-28 13:42:16 +1000 | [diff] [blame] | 586 | stat &= ~0x00000100; |
| 587 | } |
| 588 | |
Ben Skeggs | 32256c8 | 2013-01-31 19:49:33 -0500 | [diff] [blame] | 589 | if (stat & 0x00010000) { |
| 590 | u32 intr = nv_rd32(priv, 0x00256c); |
| 591 | nv_warn(priv, "INTR 0x00010000: 0x%08x\n", intr); |
| 592 | nv_wr32(priv, 0x002100, 0x00010000); |
| 593 | stat &= ~0x00010000; |
| 594 | } |
| 595 | |
| 596 | if (stat & 0x01000000) { |
| 597 | u32 intr = nv_rd32(priv, 0x00258c); |
| 598 | nv_warn(priv, "INTR 0x01000000: 0x%08x\n", intr); |
| 599 | nv_wr32(priv, 0x002100, 0x01000000); |
| 600 | stat &= ~0x01000000; |
| 601 | } |
| 602 | |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 603 | if (stat & 0x10000000) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 604 | u32 units = nv_rd32(priv, 0x00259c); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 605 | u32 u = units; |
| 606 | |
| 607 | while (u) { |
| 608 | int i = ffs(u) - 1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 609 | nvc0_fifo_isr_vm_fault(priv, i); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 610 | u &= ~(1 << i); |
| 611 | } |
| 612 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 613 | nv_wr32(priv, 0x00259c, units); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 614 | stat &= ~0x10000000; |
| 615 | } |
| 616 | |
| 617 | if (stat & 0x20000000) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 618 | u32 units = nv_rd32(priv, 0x0025a0); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 619 | u32 u = units; |
| 620 | |
| 621 | while (u) { |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 622 | int i = __ffs(u); |
| 623 | nvc0_fifo_isr_pbdma_intr(priv, i); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 624 | u &= ~(1 << i); |
| 625 | } |
| 626 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 627 | nv_wr32(priv, 0x0025a0, units); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 628 | stat &= ~0x20000000; |
| 629 | } |
| 630 | |
Ben Skeggs | cc8cd64 | 2011-01-28 13:42:16 +1000 | [diff] [blame] | 631 | if (stat & 0x40000000) { |
Ben Skeggs | a07d0e7 | 2014-02-22 00:28:47 +1000 | [diff] [blame^] | 632 | nvc0_fifo_intr_runlist(priv); |
Ben Skeggs | cc8cd64 | 2011-01-28 13:42:16 +1000 | [diff] [blame] | 633 | stat &= ~0x40000000; |
| 634 | } |
| 635 | |
Ben Skeggs | 32256c8 | 2013-01-31 19:49:33 -0500 | [diff] [blame] | 636 | if (stat & 0x80000000) { |
Ben Skeggs | e99bf01 | 2014-02-22 00:18:17 +1000 | [diff] [blame] | 637 | nvc0_fifo_intr_engine(priv); |
Ben Skeggs | 32256c8 | 2013-01-31 19:49:33 -0500 | [diff] [blame] | 638 | stat &= ~0x80000000; |
| 639 | } |
| 640 | |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 641 | if (stat) { |
Ben Skeggs | 22a7a27 | 2014-02-22 00:19:19 +1000 | [diff] [blame] | 642 | nv_error(priv, "INTR 0x%08x\n", stat); |
| 643 | nv_mask(priv, 0x002140, stat, 0x00000000); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 644 | nv_wr32(priv, 0x002100, stat); |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 645 | } |
Ben Skeggs | b2b0993 | 2010-11-24 10:47:15 +1000 | [diff] [blame] | 646 | } |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 647 | |
Ben Skeggs | 9bd2ddb | 2013-01-31 13:51:20 +1000 | [diff] [blame] | 648 | static void |
| 649 | nvc0_fifo_uevent_enable(struct nouveau_event *event, int index) |
| 650 | { |
| 651 | struct nvc0_fifo_priv *priv = event->priv; |
| 652 | nv_mask(priv, 0x002140, 0x80000000, 0x80000000); |
| 653 | } |
| 654 | |
| 655 | static void |
| 656 | nvc0_fifo_uevent_disable(struct nouveau_event *event, int index) |
| 657 | { |
| 658 | struct nvc0_fifo_priv *priv = event->priv; |
| 659 | nv_mask(priv, 0x002140, 0x80000000, 0x00000000); |
| 660 | } |
| 661 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 662 | static int |
| 663 | nvc0_fifo_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
| 664 | struct nouveau_oclass *oclass, void *data, u32 size, |
| 665 | struct nouveau_object **pobject) |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 666 | { |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 667 | struct nvc0_fifo_priv *priv; |
| 668 | int ret; |
| 669 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 670 | ret = nouveau_fifo_create(parent, engine, oclass, 0, 127, &priv); |
| 671 | *pobject = nv_object(priv); |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 672 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 673 | return ret; |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 674 | |
Ben Skeggs | f50c805 | 2013-04-24 18:02:35 +1000 | [diff] [blame] | 675 | ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0x1000, 0, |
Ben Skeggs | a07d0e7 | 2014-02-22 00:28:47 +1000 | [diff] [blame^] | 676 | &priv->runlist.mem[0]); |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 677 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 678 | return ret; |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 679 | |
Ben Skeggs | f50c805 | 2013-04-24 18:02:35 +1000 | [diff] [blame] | 680 | ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0x1000, 0, |
Ben Skeggs | a07d0e7 | 2014-02-22 00:28:47 +1000 | [diff] [blame^] | 681 | &priv->runlist.mem[1]); |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 682 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 683 | return ret; |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 684 | |
Ben Skeggs | a07d0e7 | 2014-02-22 00:28:47 +1000 | [diff] [blame^] | 685 | init_waitqueue_head(&priv->runlist.wait); |
| 686 | |
Ben Skeggs | f50c805 | 2013-04-24 18:02:35 +1000 | [diff] [blame] | 687 | ret = nouveau_gpuobj_new(nv_object(priv), NULL, 128 * 0x1000, 0x1000, 0, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 688 | &priv->user.mem); |
Ben Skeggs | 9da226f | 2012-07-13 16:54:45 +1000 | [diff] [blame] | 689 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 690 | return ret; |
Ben Skeggs | 9da226f | 2012-07-13 16:54:45 +1000 | [diff] [blame] | 691 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 692 | ret = nouveau_gpuobj_map(priv->user.mem, NV_MEM_ACCESS_RW, |
| 693 | &priv->user.bar); |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 694 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 695 | return ret; |
| 696 | |
Ben Skeggs | 9bd2ddb | 2013-01-31 13:51:20 +1000 | [diff] [blame] | 697 | priv->base.uevent->enable = nvc0_fifo_uevent_enable; |
| 698 | priv->base.uevent->disable = nvc0_fifo_uevent_disable; |
| 699 | priv->base.uevent->priv = priv; |
| 700 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 701 | nv_subdev(priv)->unit = 0x00000100; |
| 702 | nv_subdev(priv)->intr = nvc0_fifo_intr; |
| 703 | nv_engine(priv)->cclass = &nvc0_fifo_cclass; |
| 704 | nv_engine(priv)->sclass = nvc0_fifo_sclass; |
| 705 | return 0; |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 706 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 707 | |
| 708 | static void |
| 709 | nvc0_fifo_dtor(struct nouveau_object *object) |
| 710 | { |
| 711 | struct nvc0_fifo_priv *priv = (void *)object; |
| 712 | |
| 713 | nouveau_gpuobj_unmap(&priv->user.bar); |
| 714 | nouveau_gpuobj_ref(NULL, &priv->user.mem); |
Ben Skeggs | a07d0e7 | 2014-02-22 00:28:47 +1000 | [diff] [blame^] | 715 | nouveau_gpuobj_ref(NULL, &priv->runlist.mem[0]); |
| 716 | nouveau_gpuobj_ref(NULL, &priv->runlist.mem[1]); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 717 | |
| 718 | nouveau_fifo_destroy(&priv->base); |
| 719 | } |
| 720 | |
| 721 | static int |
| 722 | nvc0_fifo_init(struct nouveau_object *object) |
| 723 | { |
| 724 | struct nvc0_fifo_priv *priv = (void *)object; |
| 725 | int ret, i; |
| 726 | |
| 727 | ret = nouveau_fifo_init(&priv->base); |
| 728 | if (ret) |
| 729 | return ret; |
| 730 | |
| 731 | nv_wr32(priv, 0x000204, 0xffffffff); |
| 732 | nv_wr32(priv, 0x002204, 0xffffffff); |
| 733 | |
| 734 | priv->spoon_nr = hweight32(nv_rd32(priv, 0x002204)); |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 735 | nv_debug(priv, "%d PBDMA unit(s)\n", priv->spoon_nr); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 736 | |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 737 | /* assign engines to PBDMAs */ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 738 | if (priv->spoon_nr >= 3) { |
| 739 | nv_wr32(priv, 0x002208, ~(1 << 0)); /* PGRAPH */ |
| 740 | nv_wr32(priv, 0x00220c, ~(1 << 1)); /* PVP */ |
| 741 | nv_wr32(priv, 0x002210, ~(1 << 1)); /* PPP */ |
| 742 | nv_wr32(priv, 0x002214, ~(1 << 1)); /* PBSP */ |
| 743 | nv_wr32(priv, 0x002218, ~(1 << 2)); /* PCE0 */ |
| 744 | nv_wr32(priv, 0x00221c, ~(1 << 1)); /* PCE1 */ |
| 745 | } |
| 746 | |
Ben Skeggs | 0357466 | 2014-01-28 11:47:46 +1000 | [diff] [blame] | 747 | /* PBDMA[n] */ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 748 | for (i = 0; i < priv->spoon_nr; i++) { |
| 749 | nv_mask(priv, 0x04013c + (i * 0x2000), 0x10000100, 0x00000000); |
| 750 | nv_wr32(priv, 0x040108 + (i * 0x2000), 0xffffffff); /* INTR */ |
| 751 | nv_wr32(priv, 0x04010c + (i * 0x2000), 0xfffffeff); /* INTREN */ |
| 752 | } |
| 753 | |
| 754 | nv_mask(priv, 0x002200, 0x00000001, 0x00000001); |
| 755 | nv_wr32(priv, 0x002254, 0x10000000 | priv->user.bar.offset >> 12); |
| 756 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 757 | nv_wr32(priv, 0x002100, 0xffffffff); |
Ben Skeggs | a07d0e7 | 2014-02-22 00:28:47 +1000 | [diff] [blame^] | 758 | nv_wr32(priv, 0x002140, 0x7fffffff); |
Ben Skeggs | e99bf01 | 2014-02-22 00:18:17 +1000 | [diff] [blame] | 759 | nv_wr32(priv, 0x002628, 0x00000001); /* ENGINE_INTR_EN */ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 760 | return 0; |
| 761 | } |
| 762 | |
Ben Skeggs | 16c4f22 | 2013-11-05 14:26:58 +1000 | [diff] [blame] | 763 | struct nouveau_oclass * |
| 764 | nvc0_fifo_oclass = &(struct nouveau_oclass) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 765 | .handle = NV_ENGINE(FIFO, 0xc0), |
| 766 | .ofuncs = &(struct nouveau_ofuncs) { |
| 767 | .ctor = nvc0_fifo_ctor, |
| 768 | .dtor = nvc0_fifo_dtor, |
| 769 | .init = nvc0_fifo_init, |
| 770 | .fini = _nouveau_fifo_fini, |
| 771 | }, |
| 772 | }; |