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 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 27 | #include "drmP.h" |
| 28 | #include "drm.h" |
| 29 | #include "nouveau_drv.h" |
Ben Skeggs | 054b93e | 2009-12-15 22:02:47 +1000 | [diff] [blame] | 30 | #include "nouveau_grctx.h" |
Ben Skeggs | 4ea52f8 | 2011-03-31 13:44:16 +1000 | [diff] [blame] | 31 | #include "nouveau_ramht.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 32 | |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 33 | struct nv40_graph_engine { |
| 34 | struct nouveau_exec_engine base; |
| 35 | u32 grctx_size; |
| 36 | }; |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 37 | |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 38 | static struct nouveau_channel * |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 39 | nv40_graph_channel(struct drm_device *dev) |
| 40 | { |
| 41 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 42 | struct nouveau_gpuobj *grctx; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 43 | uint32_t inst; |
| 44 | int i; |
| 45 | |
| 46 | inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR); |
| 47 | if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED)) |
| 48 | return NULL; |
| 49 | inst = (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) << 4; |
| 50 | |
| 51 | for (i = 0; i < dev_priv->engine.fifo.channels; i++) { |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 52 | if (!dev_priv->channels.ptr[i]) |
| 53 | continue; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 54 | |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 55 | grctx = dev_priv->channels.ptr[i]->engctx[NVOBJ_ENGINE_GR]; |
| 56 | if (grctx && grctx->pinst == inst) |
| 57 | return dev_priv->channels.ptr[i]; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | return NULL; |
| 61 | } |
| 62 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 63 | static int |
| 64 | nv40_graph_transfer_context(struct drm_device *dev, uint32_t inst, int save) |
| 65 | { |
| 66 | uint32_t old_cp, tv = 1000, tmp; |
| 67 | int i; |
| 68 | |
| 69 | old_cp = nv_rd32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER); |
| 70 | nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst); |
| 71 | |
| 72 | tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0310); |
| 73 | tmp |= save ? NV40_PGRAPH_CTXCTL_0310_XFER_SAVE : |
| 74 | NV40_PGRAPH_CTXCTL_0310_XFER_LOAD; |
| 75 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_0310, tmp); |
| 76 | |
| 77 | tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0304); |
| 78 | tmp |= NV40_PGRAPH_CTXCTL_0304_XFER_CTX; |
| 79 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_0304, tmp); |
| 80 | |
| 81 | nouveau_wait_for_idle(dev); |
| 82 | |
| 83 | for (i = 0; i < tv; i++) { |
| 84 | if (nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C) == 0) |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, old_cp); |
| 89 | |
| 90 | if (i == tv) { |
| 91 | uint32_t ucstat = nv_rd32(dev, NV40_PGRAPH_CTXCTL_UCODE_STAT); |
| 92 | NV_ERROR(dev, "Failed: Instance=0x%08x Save=%d\n", inst, save); |
| 93 | NV_ERROR(dev, "IP: 0x%02x, Opcode: 0x%08x\n", |
| 94 | ucstat >> NV40_PGRAPH_CTXCTL_UCODE_STAT_IP_SHIFT, |
| 95 | ucstat & NV40_PGRAPH_CTXCTL_UCODE_STAT_OP_MASK); |
| 96 | NV_ERROR(dev, "0x40030C = 0x%08x\n", |
| 97 | nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C)); |
| 98 | return -EBUSY; |
| 99 | } |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 104 | static int |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 105 | nv40_graph_unload_context(struct drm_device *dev) |
| 106 | { |
| 107 | uint32_t inst; |
| 108 | int ret; |
| 109 | |
| 110 | inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR); |
| 111 | if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED)) |
| 112 | return 0; |
| 113 | inst &= NV40_PGRAPH_CTXCTL_CUR_INSTANCE; |
| 114 | |
| 115 | ret = nv40_graph_transfer_context(dev, inst, 1); |
| 116 | |
| 117 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, inst); |
| 118 | return ret; |
| 119 | } |
| 120 | |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 121 | static int |
| 122 | nv40_graph_context_new(struct nouveau_channel *chan, int engine) |
| 123 | { |
| 124 | struct nv40_graph_engine *pgraph = nv_engine(chan->dev, engine); |
| 125 | struct drm_device *dev = chan->dev; |
| 126 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 127 | struct nouveau_gpuobj *grctx = NULL; |
| 128 | struct nouveau_grctx ctx = {}; |
| 129 | unsigned long flags; |
| 130 | int ret; |
| 131 | |
| 132 | ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 16, |
| 133 | NVOBJ_FLAG_ZERO_ALLOC, &grctx); |
| 134 | if (ret) |
| 135 | return ret; |
| 136 | |
| 137 | /* Initialise default context values */ |
| 138 | ctx.dev = chan->dev; |
| 139 | ctx.mode = NOUVEAU_GRCTX_VALS; |
| 140 | ctx.data = grctx; |
| 141 | nv40_grctx_init(&ctx); |
| 142 | |
| 143 | nv_wo32(grctx, 0, grctx->vinst); |
| 144 | |
| 145 | /* init grctx pointer in ramfc, and on PFIFO if channel is |
| 146 | * already active there |
| 147 | */ |
| 148 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 149 | nv_wo32(chan->ramfc, 0x38, grctx->vinst >> 4); |
| 150 | nv_mask(dev, 0x002500, 0x00000001, 0x00000000); |
| 151 | if ((nv_rd32(dev, 0x003204) & 0x0000001f) == chan->id) |
| 152 | nv_wr32(dev, 0x0032e0, grctx->vinst >> 4); |
| 153 | nv_mask(dev, 0x002500, 0x00000001, 0x00000001); |
| 154 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
| 155 | |
| 156 | chan->engctx[engine] = grctx; |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | static void |
| 161 | nv40_graph_context_del(struct nouveau_channel *chan, int engine) |
| 162 | { |
| 163 | struct nouveau_gpuobj *grctx = chan->engctx[engine]; |
| 164 | struct drm_device *dev = chan->dev; |
| 165 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 166 | unsigned long flags; |
| 167 | |
| 168 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 169 | nv04_graph_fifo_access(dev, false); |
| 170 | |
| 171 | /* Unload the context if it's the currently active one */ |
| 172 | if (nv40_graph_channel(dev) == chan) |
| 173 | nv40_graph_unload_context(dev); |
| 174 | |
| 175 | nv04_graph_fifo_access(dev, true); |
| 176 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
| 177 | |
| 178 | /* Free the context resources */ |
| 179 | nouveau_gpuobj_ref(NULL, &grctx); |
| 180 | chan->engctx[engine] = NULL; |
| 181 | } |
| 182 | |
Ben Skeggs | 4ea52f8 | 2011-03-31 13:44:16 +1000 | [diff] [blame] | 183 | int |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 184 | nv40_graph_object_new(struct nouveau_channel *chan, int engine, |
| 185 | u32 handle, u16 class) |
Ben Skeggs | 4ea52f8 | 2011-03-31 13:44:16 +1000 | [diff] [blame] | 186 | { |
| 187 | struct drm_device *dev = chan->dev; |
| 188 | struct nouveau_gpuobj *obj = NULL; |
| 189 | int ret; |
| 190 | |
| 191 | ret = nouveau_gpuobj_new(dev, chan, 20, 16, NVOBJ_FLAG_ZERO_FREE, &obj); |
| 192 | if (ret) |
| 193 | return ret; |
| 194 | obj->engine = 1; |
| 195 | obj->class = class; |
| 196 | |
| 197 | nv_wo32(obj, 0x00, class); |
| 198 | nv_wo32(obj, 0x04, 0x00000000); |
| 199 | #ifdef __BIG_ENDIAN |
| 200 | nv_wo32(obj, 0x08, 0x01000000); |
| 201 | #endif |
| 202 | nv_wo32(obj, 0x0c, 0x00000000); |
| 203 | nv_wo32(obj, 0x10, 0x00000000); |
| 204 | |
| 205 | ret = nouveau_ramht_insert(chan, handle, obj); |
| 206 | nouveau_gpuobj_ref(NULL, &obj); |
| 207 | return ret; |
| 208 | } |
| 209 | |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 210 | void |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 211 | nv40_graph_set_tile_region(struct drm_device *dev, int i) |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 212 | { |
| 213 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 214 | struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i]; |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 215 | |
| 216 | switch (dev_priv->chipset) { |
Ben Skeggs | 1dc3267 | 2011-02-07 10:49:39 +1000 | [diff] [blame] | 217 | case 0x40: |
| 218 | case 0x41: /* guess */ |
| 219 | case 0x42: |
| 220 | case 0x43: |
| 221 | case 0x45: /* guess */ |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 222 | case 0x4e: |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 223 | nv_wr32(dev, NV20_PGRAPH_TSIZE(i), tile->pitch); |
| 224 | nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), tile->limit); |
| 225 | nv_wr32(dev, NV20_PGRAPH_TILE(i), tile->addr); |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 226 | nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), tile->pitch); |
| 227 | nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), tile->limit); |
| 228 | nv_wr32(dev, NV40_PGRAPH_TILE1(i), tile->addr); |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 229 | break; |
Ben Skeggs | 1dc3267 | 2011-02-07 10:49:39 +1000 | [diff] [blame] | 230 | case 0x44: |
| 231 | case 0x4a: |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 232 | nv_wr32(dev, NV20_PGRAPH_TSIZE(i), tile->pitch); |
| 233 | nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), tile->limit); |
| 234 | nv_wr32(dev, NV20_PGRAPH_TILE(i), tile->addr); |
Ben Skeggs | 1dc3267 | 2011-02-07 10:49:39 +1000 | [diff] [blame] | 235 | break; |
| 236 | case 0x46: |
| 237 | case 0x47: |
| 238 | case 0x49: |
| 239 | case 0x4b: |
| 240 | case 0x4c: |
| 241 | case 0x67: |
| 242 | default: |
| 243 | nv_wr32(dev, NV47_PGRAPH_TSIZE(i), tile->pitch); |
| 244 | nv_wr32(dev, NV47_PGRAPH_TLIMIT(i), tile->limit); |
| 245 | nv_wr32(dev, NV47_PGRAPH_TILE(i), tile->addr); |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 246 | nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), tile->pitch); |
| 247 | nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), tile->limit); |
| 248 | nv_wr32(dev, NV40_PGRAPH_TILE1(i), tile->addr); |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 249 | break; |
| 250 | } |
| 251 | } |
| 252 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 253 | /* |
| 254 | * G70 0x47 |
| 255 | * G71 0x49 |
| 256 | * NV45 0x48 |
| 257 | * G72[M] 0x46 |
| 258 | * G73 0x4b |
| 259 | * C51_G7X 0x4c |
| 260 | * C51 0x4e |
| 261 | */ |
| 262 | int |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 263 | nv40_graph_init(struct drm_device *dev, int engine) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 264 | { |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 265 | struct nv40_graph_engine *pgraph = nv_engine(dev, engine); |
| 266 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 267 | struct nouveau_fb_engine *pfb = &dev_priv->engine.fb; |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 268 | struct nouveau_grctx ctx = {}; |
| 269 | uint32_t vramsz, *cp; |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 270 | int i, j; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 271 | |
| 272 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & |
| 273 | ~NV_PMC_ENABLE_PGRAPH); |
| 274 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | |
| 275 | NV_PMC_ENABLE_PGRAPH); |
| 276 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 277 | cp = kmalloc(sizeof(*cp) * 256, GFP_KERNEL); |
| 278 | if (!cp) |
| 279 | return -ENOMEM; |
Ben Skeggs | 054b93e | 2009-12-15 22:02:47 +1000 | [diff] [blame] | 280 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 281 | ctx.dev = dev; |
| 282 | ctx.mode = NOUVEAU_GRCTX_PROG; |
| 283 | ctx.data = cp; |
| 284 | ctx.ctxprog_max = 256; |
| 285 | nv40_grctx_init(&ctx); |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 286 | pgraph->grctx_size = ctx.ctxvals_pos * 4; |
Prarit Bhargava | f49d273 | 2010-05-24 10:24:07 +1000 | [diff] [blame] | 287 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 288 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0); |
| 289 | for (i = 0; i < ctx.ctxprog_len; i++) |
| 290 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]); |
Ben Skeggs | 054b93e | 2009-12-15 22:02:47 +1000 | [diff] [blame] | 291 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 292 | kfree(cp); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 293 | |
| 294 | /* No context present currently */ |
| 295 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0x00000000); |
| 296 | |
| 297 | nv_wr32(dev, NV03_PGRAPH_INTR , 0xFFFFFFFF); |
| 298 | nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xFFFFFFFF); |
| 299 | |
| 300 | nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF); |
| 301 | nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x00000000); |
| 302 | nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x401287c0); |
| 303 | nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xe0de8055); |
| 304 | nv_wr32(dev, NV10_PGRAPH_DEBUG_4, 0x00008000); |
| 305 | nv_wr32(dev, NV04_PGRAPH_LIMIT_VIOL_PIX, 0x00be3c5f); |
| 306 | |
| 307 | nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100); |
| 308 | nv_wr32(dev, NV10_PGRAPH_STATE , 0xFFFFFFFF); |
| 309 | |
| 310 | j = nv_rd32(dev, 0x1540) & 0xff; |
| 311 | if (j) { |
| 312 | for (i = 0; !(j & 1); j >>= 1, i++) |
| 313 | ; |
| 314 | nv_wr32(dev, 0x405000, i); |
| 315 | } |
| 316 | |
| 317 | if (dev_priv->chipset == 0x40) { |
| 318 | nv_wr32(dev, 0x4009b0, 0x83280fff); |
| 319 | nv_wr32(dev, 0x4009b4, 0x000000a0); |
| 320 | } else { |
| 321 | nv_wr32(dev, 0x400820, 0x83280eff); |
| 322 | nv_wr32(dev, 0x400824, 0x000000a0); |
| 323 | } |
| 324 | |
| 325 | switch (dev_priv->chipset) { |
| 326 | case 0x40: |
| 327 | case 0x45: |
| 328 | nv_wr32(dev, 0x4009b8, 0x0078e366); |
| 329 | nv_wr32(dev, 0x4009bc, 0x0000014c); |
| 330 | break; |
| 331 | case 0x41: |
| 332 | case 0x42: /* pciid also 0x00Cx */ |
| 333 | /* case 0x0120: XXX (pciid) */ |
| 334 | nv_wr32(dev, 0x400828, 0x007596ff); |
| 335 | nv_wr32(dev, 0x40082c, 0x00000108); |
| 336 | break; |
| 337 | case 0x43: |
| 338 | nv_wr32(dev, 0x400828, 0x0072cb77); |
| 339 | nv_wr32(dev, 0x40082c, 0x00000108); |
| 340 | break; |
| 341 | case 0x44: |
| 342 | case 0x46: /* G72 */ |
| 343 | case 0x4a: |
| 344 | case 0x4c: /* G7x-based C51 */ |
| 345 | case 0x4e: |
| 346 | nv_wr32(dev, 0x400860, 0); |
| 347 | nv_wr32(dev, 0x400864, 0); |
| 348 | break; |
| 349 | case 0x47: /* G70 */ |
| 350 | case 0x49: /* G71 */ |
| 351 | case 0x4b: /* G73 */ |
| 352 | nv_wr32(dev, 0x400828, 0x07830610); |
| 353 | nv_wr32(dev, 0x40082c, 0x0000016A); |
| 354 | break; |
| 355 | default: |
| 356 | break; |
| 357 | } |
| 358 | |
| 359 | nv_wr32(dev, 0x400b38, 0x2ffff800); |
| 360 | nv_wr32(dev, 0x400b3c, 0x00006000); |
| 361 | |
Francisco Jerez | 2295e17 | 2010-04-06 21:11:58 +0200 | [diff] [blame] | 362 | /* Tiling related stuff. */ |
| 363 | switch (dev_priv->chipset) { |
| 364 | case 0x44: |
| 365 | case 0x4a: |
| 366 | nv_wr32(dev, 0x400bc4, 0x1003d888); |
| 367 | nv_wr32(dev, 0x400bbc, 0xb7a7b500); |
| 368 | break; |
| 369 | case 0x46: |
| 370 | nv_wr32(dev, 0x400bc4, 0x0000e024); |
| 371 | nv_wr32(dev, 0x400bbc, 0xb7a7b520); |
| 372 | break; |
| 373 | case 0x4c: |
| 374 | case 0x4e: |
| 375 | case 0x67: |
| 376 | nv_wr32(dev, 0x400bc4, 0x1003d888); |
| 377 | nv_wr32(dev, 0x400bbc, 0xb7a7b540); |
| 378 | break; |
| 379 | default: |
| 380 | break; |
| 381 | } |
| 382 | |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 383 | /* Turn all the tiling regions off. */ |
| 384 | for (i = 0; i < pfb->num_tiles; i++) |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 385 | nv40_graph_set_tile_region(dev, i); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 386 | |
| 387 | /* begin RAM config */ |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 388 | vramsz = pci_resource_len(dev->pdev, 0) - 1; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 389 | switch (dev_priv->chipset) { |
| 390 | case 0x40: |
| 391 | nv_wr32(dev, 0x4009A4, nv_rd32(dev, NV04_PFB_CFG0)); |
| 392 | nv_wr32(dev, 0x4009A8, nv_rd32(dev, NV04_PFB_CFG1)); |
| 393 | nv_wr32(dev, 0x4069A4, nv_rd32(dev, NV04_PFB_CFG0)); |
| 394 | nv_wr32(dev, 0x4069A8, nv_rd32(dev, NV04_PFB_CFG1)); |
| 395 | nv_wr32(dev, 0x400820, 0); |
| 396 | nv_wr32(dev, 0x400824, 0); |
| 397 | nv_wr32(dev, 0x400864, vramsz); |
| 398 | nv_wr32(dev, 0x400868, vramsz); |
| 399 | break; |
| 400 | default: |
| 401 | switch (dev_priv->chipset) { |
Ben Skeggs | 1dc3267 | 2011-02-07 10:49:39 +1000 | [diff] [blame] | 402 | case 0x41: |
| 403 | case 0x42: |
| 404 | case 0x43: |
| 405 | case 0x45: |
| 406 | case 0x4e: |
| 407 | case 0x44: |
| 408 | case 0x4a: |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 409 | nv_wr32(dev, 0x4009F0, nv_rd32(dev, NV04_PFB_CFG0)); |
| 410 | nv_wr32(dev, 0x4009F4, nv_rd32(dev, NV04_PFB_CFG1)); |
| 411 | break; |
Ben Skeggs | 1dc3267 | 2011-02-07 10:49:39 +1000 | [diff] [blame] | 412 | default: |
| 413 | nv_wr32(dev, 0x400DF0, nv_rd32(dev, NV04_PFB_CFG0)); |
| 414 | nv_wr32(dev, 0x400DF4, nv_rd32(dev, NV04_PFB_CFG1)); |
| 415 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 416 | } |
| 417 | nv_wr32(dev, 0x4069F0, nv_rd32(dev, NV04_PFB_CFG0)); |
| 418 | nv_wr32(dev, 0x4069F4, nv_rd32(dev, NV04_PFB_CFG1)); |
| 419 | nv_wr32(dev, 0x400840, 0); |
| 420 | nv_wr32(dev, 0x400844, 0); |
| 421 | nv_wr32(dev, 0x4008A0, vramsz); |
| 422 | nv_wr32(dev, 0x4008A4, vramsz); |
| 423 | break; |
| 424 | } |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 429 | static int |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 430 | nv40_graph_fini(struct drm_device *dev, int engine) |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 431 | { |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 432 | nv40_graph_unload_context(dev); |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 433 | return 0; |
| 434 | } |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 435 | |
| 436 | static int |
| 437 | nv40_graph_isr_chid(struct drm_device *dev, u32 inst) |
| 438 | { |
| 439 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 440 | struct nouveau_gpuobj *grctx; |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 441 | unsigned long flags; |
| 442 | int i; |
| 443 | |
| 444 | spin_lock_irqsave(&dev_priv->channels.lock, flags); |
| 445 | for (i = 0; i < dev_priv->engine.fifo.channels; i++) { |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 446 | if (!dev_priv->channels.ptr[i]) |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 447 | continue; |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 448 | grctx = dev_priv->channels.ptr[i]->engctx[NVOBJ_ENGINE_GR]; |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 449 | |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 450 | if (grctx && grctx->pinst == inst) |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 451 | break; |
| 452 | } |
| 453 | spin_unlock_irqrestore(&dev_priv->channels.lock, flags); |
| 454 | return i; |
| 455 | } |
| 456 | |
| 457 | static void |
| 458 | nv40_graph_isr(struct drm_device *dev) |
| 459 | { |
| 460 | u32 stat; |
| 461 | |
| 462 | while ((stat = nv_rd32(dev, NV03_PGRAPH_INTR))) { |
| 463 | u32 nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE); |
| 464 | u32 nstatus = nv_rd32(dev, NV03_PGRAPH_NSTATUS); |
| 465 | u32 inst = (nv_rd32(dev, 0x40032c) & 0x000fffff) << 4; |
| 466 | u32 chid = nv40_graph_isr_chid(dev, inst); |
| 467 | u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR); |
| 468 | u32 subc = (addr & 0x00070000) >> 16; |
| 469 | u32 mthd = (addr & 0x00001ffc); |
| 470 | u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA); |
| 471 | u32 class = nv_rd32(dev, 0x400160 + subc * 4) & 0xffff; |
| 472 | u32 show = stat; |
| 473 | |
| 474 | if (stat & NV_PGRAPH_INTR_ERROR) { |
| 475 | if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) { |
| 476 | if (!nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data)) |
| 477 | show &= ~NV_PGRAPH_INTR_ERROR; |
| 478 | } else |
| 479 | if (nsource & NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION) { |
| 480 | nv_mask(dev, 0x402000, 0, 0); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | nv_wr32(dev, NV03_PGRAPH_INTR, stat); |
| 485 | nv_wr32(dev, NV04_PGRAPH_FIFO, 0x00000001); |
| 486 | |
| 487 | if (show && nouveau_ratelimit()) { |
| 488 | NV_INFO(dev, "PGRAPH -"); |
| 489 | nouveau_bitfield_print(nv10_graph_intr, show); |
| 490 | printk(" nsource:"); |
| 491 | nouveau_bitfield_print(nv04_graph_nsource, nsource); |
| 492 | printk(" nstatus:"); |
| 493 | nouveau_bitfield_print(nv10_graph_nstatus, nstatus); |
| 494 | printk("\n"); |
| 495 | NV_INFO(dev, "PGRAPH - ch %d (0x%08x) subc %d " |
| 496 | "class 0x%04x mthd 0x%04x data 0x%08x\n", |
| 497 | chid, inst, subc, class, mthd, data); |
| 498 | } |
| 499 | } |
| 500 | } |
Ben Skeggs | 39c8d36 | 2011-04-01 11:33:21 +1000 | [diff] [blame^] | 501 | |
| 502 | static void |
| 503 | nv40_graph_destroy(struct drm_device *dev, int engine) |
| 504 | { |
| 505 | struct nv40_graph_engine *pgraph = nv_engine(dev, engine); |
| 506 | |
| 507 | nouveau_irq_unregister(dev, 12); |
| 508 | |
| 509 | NVOBJ_ENGINE_DEL(dev, GR); |
| 510 | kfree(pgraph); |
| 511 | } |
| 512 | |
| 513 | int |
| 514 | nv40_graph_create(struct drm_device *dev) |
| 515 | { |
| 516 | struct nv40_graph_engine *pgraph; |
| 517 | |
| 518 | pgraph = kzalloc(sizeof(*pgraph), GFP_KERNEL); |
| 519 | if (!pgraph) |
| 520 | return -ENOMEM; |
| 521 | |
| 522 | pgraph->base.destroy = nv40_graph_destroy; |
| 523 | pgraph->base.init = nv40_graph_init; |
| 524 | pgraph->base.fini = nv40_graph_fini; |
| 525 | pgraph->base.context_new = nv40_graph_context_new; |
| 526 | pgraph->base.context_del = nv40_graph_context_del; |
| 527 | pgraph->base.object_new = nv40_graph_object_new; |
| 528 | |
| 529 | NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base); |
| 530 | nouveau_irq_register(dev, 12, nv40_graph_isr); |
| 531 | |
| 532 | NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */ |
| 533 | NVOBJ_CLASS(dev, 0x0030, GR); /* null */ |
| 534 | NVOBJ_CLASS(dev, 0x0039, GR); /* m2mf */ |
| 535 | NVOBJ_CLASS(dev, 0x004a, GR); /* gdirect */ |
| 536 | NVOBJ_CLASS(dev, 0x009f, GR); /* imageblit (nv12) */ |
| 537 | NVOBJ_CLASS(dev, 0x008a, GR); /* ifc */ |
| 538 | NVOBJ_CLASS(dev, 0x0089, GR); /* sifm */ |
| 539 | NVOBJ_CLASS(dev, 0x3089, GR); /* sifm (nv40) */ |
| 540 | NVOBJ_CLASS(dev, 0x0062, GR); /* surf2d */ |
| 541 | NVOBJ_CLASS(dev, 0x3062, GR); /* surf2d (nv40) */ |
| 542 | NVOBJ_CLASS(dev, 0x0043, GR); /* rop */ |
| 543 | NVOBJ_CLASS(dev, 0x0012, GR); /* beta1 */ |
| 544 | NVOBJ_CLASS(dev, 0x0072, GR); /* beta4 */ |
| 545 | NVOBJ_CLASS(dev, 0x0019, GR); /* cliprect */ |
| 546 | NVOBJ_CLASS(dev, 0x0044, GR); /* pattern */ |
| 547 | NVOBJ_CLASS(dev, 0x309e, GR); /* swzsurf */ |
| 548 | |
| 549 | /* curie */ |
| 550 | if (nv44_graph_class(dev)) |
| 551 | NVOBJ_CLASS(dev, 0x4497, GR); |
| 552 | else |
| 553 | NVOBJ_CLASS(dev, 0x4097, GR); |
| 554 | |
| 555 | /* nvsw */ |
| 556 | NVOBJ_CLASS(dev, 0x506e, SW); |
| 557 | NVOBJ_MTHD (dev, 0x506e, 0x0500, nv04_graph_mthd_page_flip); |
| 558 | return 0; |
| 559 | } |