Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Ben Skeggs. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include "drmP.h" |
| 28 | #include "drm.h" |
| 29 | #include "nouveau_drv.h" |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 30 | #include "nouveau_ramht.h" |
Marcin Kościelnicki | d5f3c90 | 2010-02-25 00:54:02 +0000 | [diff] [blame] | 31 | #include "nouveau_grctx.h" |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame^] | 32 | #include "nouveau_dma.h" |
| 33 | #include "nv50_evo.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 34 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 35 | static int nv50_graph_register(struct drm_device *); |
| 36 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 37 | static void |
| 38 | nv50_graph_init_reset(struct drm_device *dev) |
| 39 | { |
| 40 | uint32_t pmc_e = NV_PMC_ENABLE_PGRAPH | (1 << 21); |
| 41 | |
| 42 | NV_DEBUG(dev, "\n"); |
| 43 | |
| 44 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e); |
| 45 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e); |
| 46 | } |
| 47 | |
| 48 | static void |
| 49 | nv50_graph_init_intr(struct drm_device *dev) |
| 50 | { |
| 51 | NV_DEBUG(dev, "\n"); |
| 52 | |
| 53 | nv_wr32(dev, NV03_PGRAPH_INTR, 0xffffffff); |
| 54 | nv_wr32(dev, 0x400138, 0xffffffff); |
| 55 | nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xffffffff); |
| 56 | } |
| 57 | |
| 58 | static void |
| 59 | nv50_graph_init_regs__nv(struct drm_device *dev) |
| 60 | { |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 61 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 62 | uint32_t units = nv_rd32(dev, 0x1540); |
| 63 | int i; |
| 64 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 65 | NV_DEBUG(dev, "\n"); |
| 66 | |
| 67 | nv_wr32(dev, 0x400804, 0xc0000000); |
| 68 | nv_wr32(dev, 0x406800, 0xc0000000); |
| 69 | nv_wr32(dev, 0x400c04, 0xc0000000); |
Marcin Kościelnicki | 716abaa | 2010-01-12 18:21:56 +0000 | [diff] [blame] | 70 | nv_wr32(dev, 0x401800, 0xc0000000); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 71 | nv_wr32(dev, 0x405018, 0xc0000000); |
| 72 | nv_wr32(dev, 0x402000, 0xc0000000); |
| 73 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 74 | for (i = 0; i < 16; i++) { |
| 75 | if (units & 1 << i) { |
| 76 | if (dev_priv->chipset < 0xa0) { |
| 77 | nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000); |
| 78 | nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000); |
| 79 | nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000); |
| 80 | } else { |
| 81 | nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000); |
| 82 | nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000); |
| 83 | nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 88 | nv_wr32(dev, 0x400108, 0xffffffff); |
| 89 | |
| 90 | nv_wr32(dev, 0x400824, 0x00004000); |
| 91 | nv_wr32(dev, 0x400500, 0x00010001); |
| 92 | } |
| 93 | |
| 94 | static void |
| 95 | nv50_graph_init_regs(struct drm_device *dev) |
| 96 | { |
| 97 | NV_DEBUG(dev, "\n"); |
| 98 | |
| 99 | nv_wr32(dev, NV04_PGRAPH_DEBUG_3, |
| 100 | (1 << 2) /* HW_CONTEXT_SWITCH_ENABLED */); |
| 101 | nv_wr32(dev, 0x402ca8, 0x800); |
| 102 | } |
| 103 | |
| 104 | static int |
| 105 | nv50_graph_init_ctxctl(struct drm_device *dev) |
| 106 | { |
Ben Skeggs | 054b93e | 2009-12-15 22:02:47 +1000 | [diff] [blame] | 107 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 108 | struct nouveau_grctx ctx = {}; |
| 109 | uint32_t *cp; |
| 110 | int i; |
Ben Skeggs | 054b93e | 2009-12-15 22:02:47 +1000 | [diff] [blame] | 111 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 112 | NV_DEBUG(dev, "\n"); |
| 113 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 114 | cp = kmalloc(512 * 4, GFP_KERNEL); |
| 115 | if (!cp) { |
| 116 | NV_ERROR(dev, "failed to allocate ctxprog\n"); |
| 117 | dev_priv->engine.graph.accel_blocked = true; |
| 118 | return 0; |
Marcin Kościelnicki | d5f3c90 | 2010-02-25 00:54:02 +0000 | [diff] [blame] | 119 | } |
Marcin Kościelnicki | d5f3c90 | 2010-02-25 00:54:02 +0000 | [diff] [blame] | 120 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 121 | ctx.dev = dev; |
| 122 | ctx.mode = NOUVEAU_GRCTX_PROG; |
| 123 | ctx.data = cp; |
| 124 | ctx.ctxprog_max = 512; |
| 125 | if (!nv50_grctx_init(&ctx)) { |
| 126 | dev_priv->engine.graph.grctx_size = ctx.ctxvals_pos * 4; |
| 127 | |
| 128 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0); |
| 129 | for (i = 0; i < ctx.ctxprog_len; i++) |
| 130 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]); |
| 131 | } else { |
| 132 | dev_priv->engine.graph.accel_blocked = true; |
Marcin Kościelnicki | d5f3c90 | 2010-02-25 00:54:02 +0000 | [diff] [blame] | 133 | } |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 134 | kfree(cp); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 135 | |
| 136 | nv_wr32(dev, 0x400320, 4); |
| 137 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0); |
| 138 | nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, 0); |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | int |
| 143 | nv50_graph_init(struct drm_device *dev) |
| 144 | { |
| 145 | int ret; |
| 146 | |
| 147 | NV_DEBUG(dev, "\n"); |
| 148 | |
| 149 | nv50_graph_init_reset(dev); |
| 150 | nv50_graph_init_regs__nv(dev); |
| 151 | nv50_graph_init_regs(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 152 | |
| 153 | ret = nv50_graph_init_ctxctl(dev); |
| 154 | if (ret) |
| 155 | return ret; |
| 156 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 157 | ret = nv50_graph_register(dev); |
| 158 | if (ret) |
| 159 | return ret; |
| 160 | nv50_graph_init_intr(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | void |
| 165 | nv50_graph_takedown(struct drm_device *dev) |
| 166 | { |
| 167 | NV_DEBUG(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void |
| 171 | nv50_graph_fifo_access(struct drm_device *dev, bool enabled) |
| 172 | { |
| 173 | const uint32_t mask = 0x00010001; |
| 174 | |
| 175 | if (enabled) |
| 176 | nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) | mask); |
| 177 | else |
| 178 | nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) & ~mask); |
| 179 | } |
| 180 | |
| 181 | struct nouveau_channel * |
| 182 | nv50_graph_channel(struct drm_device *dev) |
| 183 | { |
| 184 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 185 | uint32_t inst; |
| 186 | int i; |
| 187 | |
Maarten Maathuis | a51a3bf | 2010-02-01 18:32:09 +0100 | [diff] [blame] | 188 | /* Be sure we're not in the middle of a context switch or bad things |
| 189 | * will happen, such as unloading the wrong pgraph context. |
| 190 | */ |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 191 | if (!nv_wait(dev, 0x400300, 0x00000001, 0x00000000)) |
Maarten Maathuis | a51a3bf | 2010-02-01 18:32:09 +0100 | [diff] [blame] | 192 | NV_ERROR(dev, "Ctxprog is still running\n"); |
| 193 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 194 | inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR); |
| 195 | if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED)) |
| 196 | return NULL; |
| 197 | inst = (inst & NV50_PGRAPH_CTXCTL_CUR_INSTANCE) << 12; |
| 198 | |
| 199 | for (i = 0; i < dev_priv->engine.fifo.channels; i++) { |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 200 | struct nouveau_channel *chan = dev_priv->channels.ptr[i]; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 201 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 202 | if (chan && chan->ramin && chan->ramin->vinst == inst) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 203 | return chan; |
| 204 | } |
| 205 | |
| 206 | return NULL; |
| 207 | } |
| 208 | |
| 209 | int |
| 210 | nv50_graph_create_context(struct nouveau_channel *chan) |
| 211 | { |
| 212 | struct drm_device *dev = chan->dev; |
| 213 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 214 | struct nouveau_gpuobj *ramin = chan->ramin; |
Marcin Kościelnicki | d5f3c90 | 2010-02-25 00:54:02 +0000 | [diff] [blame] | 215 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 216 | struct nouveau_grctx ctx = {}; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 217 | int hdr, ret; |
| 218 | |
| 219 | NV_DEBUG(dev, "ch%d\n", chan->id); |
| 220 | |
Ben Skeggs | 3052be2 | 2010-10-20 11:46:38 +1000 | [diff] [blame] | 221 | ret = nouveau_gpuobj_new(dev, chan, pgraph->grctx_size, 0, |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 222 | NVOBJ_FLAG_ZERO_ALLOC | |
| 223 | NVOBJ_FLAG_ZERO_FREE, &chan->ramin_grctx); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 224 | if (ret) |
| 225 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 226 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 227 | hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20; |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 228 | nv_wo32(ramin, hdr + 0x00, 0x00190002); |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 229 | nv_wo32(ramin, hdr + 0x04, chan->ramin_grctx->vinst + |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 230 | pgraph->grctx_size - 1); |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 231 | nv_wo32(ramin, hdr + 0x08, chan->ramin_grctx->vinst); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 232 | nv_wo32(ramin, hdr + 0x0c, 0); |
| 233 | nv_wo32(ramin, hdr + 0x10, 0); |
| 234 | nv_wo32(ramin, hdr + 0x14, 0x00010000); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 235 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 236 | ctx.dev = chan->dev; |
| 237 | ctx.mode = NOUVEAU_GRCTX_VALS; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 238 | ctx.data = chan->ramin_grctx; |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 239 | nv50_grctx_init(&ctx); |
| 240 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 241 | nv_wo32(chan->ramin_grctx, 0x00000, chan->ramin->vinst >> 12); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 242 | |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 243 | dev_priv->engine.instmem.flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | void |
| 248 | nv50_graph_destroy_context(struct nouveau_channel *chan) |
| 249 | { |
| 250 | struct drm_device *dev = chan->dev; |
| 251 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Francisco Jerez | 3945e47 | 2010-10-18 03:53:39 +0200 | [diff] [blame] | 252 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 253 | int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20; |
Francisco Jerez | 3945e47 | 2010-10-18 03:53:39 +0200 | [diff] [blame] | 254 | unsigned long flags; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 255 | |
| 256 | NV_DEBUG(dev, "ch%d\n", chan->id); |
| 257 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 258 | if (!chan->ramin) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 259 | return; |
| 260 | |
Francisco Jerez | 3945e47 | 2010-10-18 03:53:39 +0200 | [diff] [blame] | 261 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 262 | pgraph->fifo_access(dev, false); |
| 263 | |
| 264 | if (pgraph->channel(dev) == chan) |
| 265 | pgraph->unload_context(dev); |
| 266 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 267 | for (i = hdr; i < hdr + 24; i += 4) |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 268 | nv_wo32(chan->ramin, i, 0); |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 269 | dev_priv->engine.instmem.flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 270 | |
Francisco Jerez | 3945e47 | 2010-10-18 03:53:39 +0200 | [diff] [blame] | 271 | pgraph->fifo_access(dev, true); |
| 272 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
| 273 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 274 | nouveau_gpuobj_ref(NULL, &chan->ramin_grctx); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static int |
| 278 | nv50_graph_do_load_context(struct drm_device *dev, uint32_t inst) |
| 279 | { |
| 280 | uint32_t fifo = nv_rd32(dev, 0x400500); |
| 281 | |
| 282 | nv_wr32(dev, 0x400500, fifo & ~1); |
| 283 | nv_wr32(dev, 0x400784, inst); |
| 284 | nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x40); |
| 285 | nv_wr32(dev, 0x400320, nv_rd32(dev, 0x400320) | 0x11); |
| 286 | nv_wr32(dev, 0x400040, 0xffffffff); |
| 287 | (void)nv_rd32(dev, 0x400040); |
| 288 | nv_wr32(dev, 0x400040, 0x00000000); |
| 289 | nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 1); |
| 290 | |
| 291 | if (nouveau_wait_for_idle(dev)) |
| 292 | nv_wr32(dev, 0x40032c, inst | (1<<31)); |
| 293 | nv_wr32(dev, 0x400500, fifo); |
| 294 | |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | int |
| 299 | nv50_graph_load_context(struct nouveau_channel *chan) |
| 300 | { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 301 | uint32_t inst = chan->ramin->vinst >> 12; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 302 | |
| 303 | NV_DEBUG(chan->dev, "ch%d\n", chan->id); |
| 304 | return nv50_graph_do_load_context(chan->dev, inst); |
| 305 | } |
| 306 | |
| 307 | int |
| 308 | nv50_graph_unload_context(struct drm_device *dev) |
| 309 | { |
Maarten Maathuis | a51a3bf | 2010-02-01 18:32:09 +0100 | [diff] [blame] | 310 | uint32_t inst; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 311 | |
| 312 | inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR); |
| 313 | if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED)) |
| 314 | return 0; |
| 315 | inst &= NV50_PGRAPH_CTXCTL_CUR_INSTANCE; |
| 316 | |
Maarten Maathuis | 0a90dc5 | 2010-01-11 21:18:53 +0100 | [diff] [blame] | 317 | nouveau_wait_for_idle(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 318 | nv_wr32(dev, 0x400784, inst); |
| 319 | nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x20); |
| 320 | nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 0x01); |
| 321 | nouveau_wait_for_idle(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 322 | |
| 323 | nv_wr32(dev, NV50_PGRAPH_CTXCTL_CUR, inst); |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | void |
| 328 | nv50_graph_context_switch(struct drm_device *dev) |
| 329 | { |
| 330 | uint32_t inst; |
| 331 | |
| 332 | nv50_graph_unload_context(dev); |
| 333 | |
| 334 | inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_NEXT); |
| 335 | inst &= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE; |
| 336 | nv50_graph_do_load_context(dev, inst); |
| 337 | |
| 338 | nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev, |
| 339 | NV40_PGRAPH_INTR_EN) | NV_PGRAPH_INTR_CONTEXT_SWITCH); |
| 340 | } |
| 341 | |
| 342 | static int |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 343 | nv50_graph_nvsw_dma_vblsem(struct nouveau_channel *chan, |
| 344 | u32 class, u32 mthd, u32 data) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 345 | { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 346 | struct nouveau_gpuobj *gpuobj; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 347 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 348 | gpuobj = nouveau_ramht_find(chan, data); |
| 349 | if (!gpuobj) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 350 | return -ENOENT; |
| 351 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 352 | if (nouveau_notifier_offset(gpuobj, NULL)) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 353 | return -EINVAL; |
| 354 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 355 | chan->nvsw.vblsem = gpuobj; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 356 | chan->nvsw.vblsem_offset = ~0; |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | static int |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 361 | nv50_graph_nvsw_vblsem_offset(struct nouveau_channel *chan, |
| 362 | u32 class, u32 mthd, u32 data) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 363 | { |
| 364 | if (nouveau_notifier_offset(chan->nvsw.vblsem, &data)) |
| 365 | return -ERANGE; |
| 366 | |
| 367 | chan->nvsw.vblsem_offset = data >> 2; |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | static int |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 372 | nv50_graph_nvsw_vblsem_release_val(struct nouveau_channel *chan, |
| 373 | u32 class, u32 mthd, u32 data) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 374 | { |
| 375 | chan->nvsw.vblsem_rval = data; |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static int |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 380 | nv50_graph_nvsw_vblsem_release(struct nouveau_channel *chan, |
| 381 | u32 class, u32 mthd, u32 data) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 382 | { |
| 383 | struct drm_device *dev = chan->dev; |
| 384 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 385 | |
| 386 | if (!chan->nvsw.vblsem || chan->nvsw.vblsem_offset == ~0 || data > 1) |
| 387 | return -EINVAL; |
| 388 | |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 389 | drm_vblank_get(dev, data); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 390 | list_add(&chan->nvsw.vbl_wait, &dev_priv->vbl_waiting); |
| 391 | return 0; |
| 392 | } |
| 393 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 394 | static int |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame^] | 395 | nv50_graph_nvsw_mthd_page_flip(struct nouveau_channel *chan, |
| 396 | u32 class, u32 mthd, u32 data) |
| 397 | { |
| 398 | struct nouveau_page_flip_state s; |
| 399 | |
| 400 | if (!nouveau_finish_page_flip(chan, &s)) { |
| 401 | /* XXX - Do something here */ |
| 402 | } |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static int |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 408 | nv50_graph_register(struct drm_device *dev) |
| 409 | { |
| 410 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 411 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 412 | if (dev_priv->engine.graph.registered) |
| 413 | return 0; |
| 414 | |
| 415 | NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */ |
| 416 | NVOBJ_MTHD (dev, 0x506e, 0x018c, nv50_graph_nvsw_dma_vblsem); |
| 417 | NVOBJ_MTHD (dev, 0x506e, 0x0400, nv50_graph_nvsw_vblsem_offset); |
| 418 | NVOBJ_MTHD (dev, 0x506e, 0x0404, nv50_graph_nvsw_vblsem_release_val); |
| 419 | NVOBJ_MTHD (dev, 0x506e, 0x0408, nv50_graph_nvsw_vblsem_release); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame^] | 420 | NVOBJ_MTHD (dev, 0x506e, 0x0500, nv50_graph_nvsw_mthd_page_flip); |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 421 | |
| 422 | NVOBJ_CLASS(dev, 0x0030, GR); /* null */ |
| 423 | NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */ |
| 424 | NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */ |
| 425 | NVOBJ_CLASS(dev, 0x50c0, GR); /* compute */ |
| 426 | NVOBJ_CLASS(dev, 0x85c0, GR); /* compute (nva3, nva5, nva8) */ |
| 427 | |
| 428 | /* tesla */ |
| 429 | if (dev_priv->chipset == 0x50) |
| 430 | NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */ |
| 431 | else |
| 432 | if (dev_priv->chipset < 0xa0) |
| 433 | NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */ |
| 434 | else { |
| 435 | switch (dev_priv->chipset) { |
| 436 | case 0xa0: |
| 437 | case 0xaa: |
| 438 | case 0xac: |
| 439 | NVOBJ_CLASS(dev, 0x8397, GR); |
| 440 | break; |
| 441 | case 0xa3: |
| 442 | case 0xa5: |
| 443 | case 0xa8: |
| 444 | NVOBJ_CLASS(dev, 0x8597, GR); |
| 445 | break; |
| 446 | case 0xaf: |
| 447 | NVOBJ_CLASS(dev, 0x8697, GR); |
| 448 | break; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | dev_priv->engine.graph.registered = true; |
| 453 | return 0; |
| 454 | } |
Ben Skeggs | 56ac747 | 2010-10-22 10:26:24 +1000 | [diff] [blame] | 455 | |
| 456 | void |
| 457 | nv50_graph_tlb_flush(struct drm_device *dev) |
| 458 | { |
| 459 | nv50_vm_flush(dev, 0); |
| 460 | } |
| 461 | |
| 462 | void |
| 463 | nv86_graph_tlb_flush(struct drm_device *dev) |
| 464 | { |
| 465 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 466 | struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer; |
| 467 | bool idle, timeout = false; |
| 468 | unsigned long flags; |
| 469 | u64 start; |
| 470 | u32 tmp; |
| 471 | |
| 472 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 473 | nv_mask(dev, 0x400500, 0x00000001, 0x00000000); |
| 474 | |
| 475 | start = ptimer->read(dev); |
| 476 | do { |
| 477 | idle = true; |
| 478 | |
| 479 | for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) { |
| 480 | if ((tmp & 7) == 1) |
| 481 | idle = false; |
| 482 | } |
| 483 | |
| 484 | for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) { |
| 485 | if ((tmp & 7) == 1) |
| 486 | idle = false; |
| 487 | } |
| 488 | |
| 489 | for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) { |
| 490 | if ((tmp & 7) == 1) |
| 491 | idle = false; |
| 492 | } |
| 493 | } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000)); |
| 494 | |
| 495 | if (timeout) { |
| 496 | NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: " |
| 497 | "0x%08x 0x%08x 0x%08x 0x%08x\n", |
| 498 | nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380), |
| 499 | nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388)); |
| 500 | } |
| 501 | |
| 502 | nv50_vm_flush(dev, 0); |
| 503 | |
| 504 | nv_mask(dev, 0x400500, 0x00000001, 0x00000001); |
| 505 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
| 506 | } |