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 | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 31 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 32 | static int nv40_graph_register(struct drm_device *); |
| 33 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 34 | struct nouveau_channel * |
| 35 | nv40_graph_channel(struct drm_device *dev) |
| 36 | { |
| 37 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 38 | uint32_t inst; |
| 39 | int i; |
| 40 | |
| 41 | inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR); |
| 42 | if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED)) |
| 43 | return NULL; |
| 44 | inst = (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) << 4; |
| 45 | |
| 46 | for (i = 0; i < dev_priv->engine.fifo.channels; i++) { |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 47 | struct nouveau_channel *chan = dev_priv->channels.ptr[i]; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 48 | |
| 49 | if (chan && chan->ramin_grctx && |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 50 | chan->ramin_grctx->pinst == inst) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 51 | return chan; |
| 52 | } |
| 53 | |
| 54 | return NULL; |
| 55 | } |
| 56 | |
| 57 | int |
| 58 | nv40_graph_create_context(struct nouveau_channel *chan) |
| 59 | { |
| 60 | struct drm_device *dev = chan->dev; |
| 61 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 054b93e | 2009-12-15 22:02:47 +1000 | [diff] [blame] | 62 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 63 | struct nouveau_grctx ctx = {}; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 64 | int ret; |
| 65 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 66 | ret = nouveau_gpuobj_new(dev, chan, pgraph->grctx_size, 16, |
| 67 | NVOBJ_FLAG_ZERO_ALLOC, &chan->ramin_grctx); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 68 | if (ret) |
| 69 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 70 | |
| 71 | /* Initialise default context values */ |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 72 | ctx.dev = chan->dev; |
| 73 | ctx.mode = NOUVEAU_GRCTX_VALS; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 74 | ctx.data = chan->ramin_grctx; |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 75 | nv40_grctx_init(&ctx); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 76 | |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 77 | nv_wo32(chan->ramin_grctx, 0, chan->ramin_grctx->pinst); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | nv40_graph_destroy_context(struct nouveau_channel *chan) |
| 83 | { |
Francisco Jerez | 3945e47 | 2010-10-18 03:53:39 +0200 | [diff] [blame] | 84 | struct drm_device *dev = chan->dev; |
| 85 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 86 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; |
| 87 | unsigned long flags; |
| 88 | |
| 89 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 90 | pgraph->fifo_access(dev, false); |
| 91 | |
| 92 | /* Unload the context if it's the currently active one */ |
| 93 | if (pgraph->channel(dev) == chan) |
| 94 | pgraph->unload_context(dev); |
| 95 | |
| 96 | pgraph->fifo_access(dev, true); |
| 97 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
| 98 | |
| 99 | /* Free the context resources */ |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 100 | nouveau_gpuobj_ref(NULL, &chan->ramin_grctx); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static int |
| 104 | nv40_graph_transfer_context(struct drm_device *dev, uint32_t inst, int save) |
| 105 | { |
| 106 | uint32_t old_cp, tv = 1000, tmp; |
| 107 | int i; |
| 108 | |
| 109 | old_cp = nv_rd32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER); |
| 110 | nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst); |
| 111 | |
| 112 | tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0310); |
| 113 | tmp |= save ? NV40_PGRAPH_CTXCTL_0310_XFER_SAVE : |
| 114 | NV40_PGRAPH_CTXCTL_0310_XFER_LOAD; |
| 115 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_0310, tmp); |
| 116 | |
| 117 | tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0304); |
| 118 | tmp |= NV40_PGRAPH_CTXCTL_0304_XFER_CTX; |
| 119 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_0304, tmp); |
| 120 | |
| 121 | nouveau_wait_for_idle(dev); |
| 122 | |
| 123 | for (i = 0; i < tv; i++) { |
| 124 | if (nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C) == 0) |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, old_cp); |
| 129 | |
| 130 | if (i == tv) { |
| 131 | uint32_t ucstat = nv_rd32(dev, NV40_PGRAPH_CTXCTL_UCODE_STAT); |
| 132 | NV_ERROR(dev, "Failed: Instance=0x%08x Save=%d\n", inst, save); |
| 133 | NV_ERROR(dev, "IP: 0x%02x, Opcode: 0x%08x\n", |
| 134 | ucstat >> NV40_PGRAPH_CTXCTL_UCODE_STAT_IP_SHIFT, |
| 135 | ucstat & NV40_PGRAPH_CTXCTL_UCODE_STAT_OP_MASK); |
| 136 | NV_ERROR(dev, "0x40030C = 0x%08x\n", |
| 137 | nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C)); |
| 138 | return -EBUSY; |
| 139 | } |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | /* Restore the context for a specific channel into PGRAPH */ |
| 145 | int |
| 146 | nv40_graph_load_context(struct nouveau_channel *chan) |
| 147 | { |
| 148 | struct drm_device *dev = chan->dev; |
| 149 | uint32_t inst; |
| 150 | int ret; |
| 151 | |
| 152 | if (!chan->ramin_grctx) |
| 153 | return -EINVAL; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 154 | inst = chan->ramin_grctx->pinst >> 4; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 155 | |
| 156 | ret = nv40_graph_transfer_context(dev, inst, 0); |
| 157 | if (ret) |
| 158 | return ret; |
| 159 | |
| 160 | /* 0x40032C, no idea of it's exact function. Could simply be a |
| 161 | * record of the currently active PGRAPH context. It's currently |
| 162 | * unknown as to what bit 24 does. The nv ddx has it set, so we will |
| 163 | * set it here too. |
| 164 | */ |
| 165 | nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst); |
| 166 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, |
| 167 | (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) | |
| 168 | NV40_PGRAPH_CTXCTL_CUR_LOADED); |
| 169 | /* 0x32E0 records the instance address of the active FIFO's PGRAPH |
| 170 | * context. If at any time this doesn't match 0x40032C, you will |
| 171 | * recieve PGRAPH_INTR_CONTEXT_SWITCH |
| 172 | */ |
| 173 | nv_wr32(dev, NV40_PFIFO_GRCTX_INSTANCE, inst); |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | int |
| 178 | nv40_graph_unload_context(struct drm_device *dev) |
| 179 | { |
| 180 | uint32_t inst; |
| 181 | int ret; |
| 182 | |
| 183 | inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR); |
| 184 | if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED)) |
| 185 | return 0; |
| 186 | inst &= NV40_PGRAPH_CTXCTL_CUR_INSTANCE; |
| 187 | |
| 188 | ret = nv40_graph_transfer_context(dev, inst, 1); |
| 189 | |
| 190 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, inst); |
| 191 | return ret; |
| 192 | } |
| 193 | |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 194 | void |
| 195 | nv40_graph_set_region_tiling(struct drm_device *dev, int i, uint32_t addr, |
| 196 | uint32_t size, uint32_t pitch) |
| 197 | { |
| 198 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 199 | uint32_t limit = max(1u, addr + size) - 1; |
| 200 | |
| 201 | if (pitch) |
| 202 | addr |= 1; |
| 203 | |
| 204 | switch (dev_priv->chipset) { |
| 205 | case 0x44: |
| 206 | case 0x4a: |
| 207 | case 0x4e: |
| 208 | nv_wr32(dev, NV20_PGRAPH_TSIZE(i), pitch); |
| 209 | nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), limit); |
| 210 | nv_wr32(dev, NV20_PGRAPH_TILE(i), addr); |
| 211 | break; |
| 212 | |
| 213 | case 0x46: |
| 214 | case 0x47: |
| 215 | case 0x49: |
| 216 | case 0x4b: |
| 217 | nv_wr32(dev, NV47_PGRAPH_TSIZE(i), pitch); |
| 218 | nv_wr32(dev, NV47_PGRAPH_TLIMIT(i), limit); |
| 219 | nv_wr32(dev, NV47_PGRAPH_TILE(i), addr); |
| 220 | nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), pitch); |
| 221 | nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), limit); |
| 222 | nv_wr32(dev, NV40_PGRAPH_TILE1(i), addr); |
| 223 | break; |
| 224 | |
| 225 | default: |
| 226 | nv_wr32(dev, NV20_PGRAPH_TSIZE(i), pitch); |
| 227 | nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), limit); |
| 228 | nv_wr32(dev, NV20_PGRAPH_TILE(i), addr); |
| 229 | nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), pitch); |
| 230 | nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), limit); |
| 231 | nv_wr32(dev, NV40_PGRAPH_TILE1(i), addr); |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 236 | /* |
| 237 | * G70 0x47 |
| 238 | * G71 0x49 |
| 239 | * NV45 0x48 |
| 240 | * G72[M] 0x46 |
| 241 | * G73 0x4b |
| 242 | * C51_G7X 0x4c |
| 243 | * C51 0x4e |
| 244 | */ |
| 245 | int |
| 246 | nv40_graph_init(struct drm_device *dev) |
| 247 | { |
| 248 | struct drm_nouveau_private *dev_priv = |
| 249 | (struct drm_nouveau_private *)dev->dev_private; |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 250 | struct nouveau_fb_engine *pfb = &dev_priv->engine.fb; |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 251 | struct nouveau_grctx ctx = {}; |
| 252 | uint32_t vramsz, *cp; |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 253 | int ret, i, j; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 254 | |
| 255 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & |
| 256 | ~NV_PMC_ENABLE_PGRAPH); |
| 257 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | |
| 258 | NV_PMC_ENABLE_PGRAPH); |
| 259 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 260 | cp = kmalloc(sizeof(*cp) * 256, GFP_KERNEL); |
| 261 | if (!cp) |
| 262 | return -ENOMEM; |
Ben Skeggs | 054b93e | 2009-12-15 22:02:47 +1000 | [diff] [blame] | 263 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 264 | ctx.dev = dev; |
| 265 | ctx.mode = NOUVEAU_GRCTX_PROG; |
| 266 | ctx.data = cp; |
| 267 | ctx.ctxprog_max = 256; |
| 268 | nv40_grctx_init(&ctx); |
| 269 | dev_priv->engine.graph.grctx_size = ctx.ctxvals_pos * 4; |
Prarit Bhargava | f49d273 | 2010-05-24 10:24:07 +1000 | [diff] [blame] | 270 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 271 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0); |
| 272 | for (i = 0; i < ctx.ctxprog_len; i++) |
| 273 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]); |
Ben Skeggs | 054b93e | 2009-12-15 22:02:47 +1000 | [diff] [blame] | 274 | |
Ben Skeggs | ec91db2 | 2010-07-08 11:53:19 +1000 | [diff] [blame] | 275 | kfree(cp); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 276 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 277 | ret = nv40_graph_register(dev); |
| 278 | if (ret) |
| 279 | return ret; |
| 280 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 281 | /* No context present currently */ |
| 282 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0x00000000); |
| 283 | |
| 284 | nv_wr32(dev, NV03_PGRAPH_INTR , 0xFFFFFFFF); |
| 285 | nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xFFFFFFFF); |
| 286 | |
| 287 | nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF); |
| 288 | nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x00000000); |
| 289 | nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x401287c0); |
| 290 | nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xe0de8055); |
| 291 | nv_wr32(dev, NV10_PGRAPH_DEBUG_4, 0x00008000); |
| 292 | nv_wr32(dev, NV04_PGRAPH_LIMIT_VIOL_PIX, 0x00be3c5f); |
| 293 | |
| 294 | nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100); |
| 295 | nv_wr32(dev, NV10_PGRAPH_STATE , 0xFFFFFFFF); |
| 296 | |
| 297 | j = nv_rd32(dev, 0x1540) & 0xff; |
| 298 | if (j) { |
| 299 | for (i = 0; !(j & 1); j >>= 1, i++) |
| 300 | ; |
| 301 | nv_wr32(dev, 0x405000, i); |
| 302 | } |
| 303 | |
| 304 | if (dev_priv->chipset == 0x40) { |
| 305 | nv_wr32(dev, 0x4009b0, 0x83280fff); |
| 306 | nv_wr32(dev, 0x4009b4, 0x000000a0); |
| 307 | } else { |
| 308 | nv_wr32(dev, 0x400820, 0x83280eff); |
| 309 | nv_wr32(dev, 0x400824, 0x000000a0); |
| 310 | } |
| 311 | |
| 312 | switch (dev_priv->chipset) { |
| 313 | case 0x40: |
| 314 | case 0x45: |
| 315 | nv_wr32(dev, 0x4009b8, 0x0078e366); |
| 316 | nv_wr32(dev, 0x4009bc, 0x0000014c); |
| 317 | break; |
| 318 | case 0x41: |
| 319 | case 0x42: /* pciid also 0x00Cx */ |
| 320 | /* case 0x0120: XXX (pciid) */ |
| 321 | nv_wr32(dev, 0x400828, 0x007596ff); |
| 322 | nv_wr32(dev, 0x40082c, 0x00000108); |
| 323 | break; |
| 324 | case 0x43: |
| 325 | nv_wr32(dev, 0x400828, 0x0072cb77); |
| 326 | nv_wr32(dev, 0x40082c, 0x00000108); |
| 327 | break; |
| 328 | case 0x44: |
| 329 | case 0x46: /* G72 */ |
| 330 | case 0x4a: |
| 331 | case 0x4c: /* G7x-based C51 */ |
| 332 | case 0x4e: |
| 333 | nv_wr32(dev, 0x400860, 0); |
| 334 | nv_wr32(dev, 0x400864, 0); |
| 335 | break; |
| 336 | case 0x47: /* G70 */ |
| 337 | case 0x49: /* G71 */ |
| 338 | case 0x4b: /* G73 */ |
| 339 | nv_wr32(dev, 0x400828, 0x07830610); |
| 340 | nv_wr32(dev, 0x40082c, 0x0000016A); |
| 341 | break; |
| 342 | default: |
| 343 | break; |
| 344 | } |
| 345 | |
| 346 | nv_wr32(dev, 0x400b38, 0x2ffff800); |
| 347 | nv_wr32(dev, 0x400b3c, 0x00006000); |
| 348 | |
Francisco Jerez | 2295e17 | 2010-04-06 21:11:58 +0200 | [diff] [blame] | 349 | /* Tiling related stuff. */ |
| 350 | switch (dev_priv->chipset) { |
| 351 | case 0x44: |
| 352 | case 0x4a: |
| 353 | nv_wr32(dev, 0x400bc4, 0x1003d888); |
| 354 | nv_wr32(dev, 0x400bbc, 0xb7a7b500); |
| 355 | break; |
| 356 | case 0x46: |
| 357 | nv_wr32(dev, 0x400bc4, 0x0000e024); |
| 358 | nv_wr32(dev, 0x400bbc, 0xb7a7b520); |
| 359 | break; |
| 360 | case 0x4c: |
| 361 | case 0x4e: |
| 362 | case 0x67: |
| 363 | nv_wr32(dev, 0x400bc4, 0x1003d888); |
| 364 | nv_wr32(dev, 0x400bbc, 0xb7a7b540); |
| 365 | break; |
| 366 | default: |
| 367 | break; |
| 368 | } |
| 369 | |
Francisco Jerez | 0d87c10 | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 370 | /* Turn all the tiling regions off. */ |
| 371 | for (i = 0; i < pfb->num_tiles; i++) |
| 372 | nv40_graph_set_region_tiling(dev, i, 0, 0, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 373 | |
| 374 | /* begin RAM config */ |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 375 | vramsz = pci_resource_len(dev->pdev, 0) - 1; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 376 | switch (dev_priv->chipset) { |
| 377 | case 0x40: |
| 378 | nv_wr32(dev, 0x4009A4, nv_rd32(dev, NV04_PFB_CFG0)); |
| 379 | nv_wr32(dev, 0x4009A8, nv_rd32(dev, NV04_PFB_CFG1)); |
| 380 | nv_wr32(dev, 0x4069A4, nv_rd32(dev, NV04_PFB_CFG0)); |
| 381 | nv_wr32(dev, 0x4069A8, nv_rd32(dev, NV04_PFB_CFG1)); |
| 382 | nv_wr32(dev, 0x400820, 0); |
| 383 | nv_wr32(dev, 0x400824, 0); |
| 384 | nv_wr32(dev, 0x400864, vramsz); |
| 385 | nv_wr32(dev, 0x400868, vramsz); |
| 386 | break; |
| 387 | default: |
| 388 | switch (dev_priv->chipset) { |
| 389 | case 0x46: |
| 390 | case 0x47: |
| 391 | case 0x49: |
| 392 | case 0x4b: |
| 393 | nv_wr32(dev, 0x400DF0, nv_rd32(dev, NV04_PFB_CFG0)); |
| 394 | nv_wr32(dev, 0x400DF4, nv_rd32(dev, NV04_PFB_CFG1)); |
| 395 | break; |
| 396 | default: |
| 397 | nv_wr32(dev, 0x4009F0, nv_rd32(dev, NV04_PFB_CFG0)); |
| 398 | nv_wr32(dev, 0x4009F4, nv_rd32(dev, NV04_PFB_CFG1)); |
| 399 | break; |
| 400 | } |
| 401 | nv_wr32(dev, 0x4069F0, nv_rd32(dev, NV04_PFB_CFG0)); |
| 402 | nv_wr32(dev, 0x4069F4, nv_rd32(dev, NV04_PFB_CFG1)); |
| 403 | nv_wr32(dev, 0x400840, 0); |
| 404 | nv_wr32(dev, 0x400844, 0); |
| 405 | nv_wr32(dev, 0x4008A0, vramsz); |
| 406 | nv_wr32(dev, 0x4008A4, vramsz); |
| 407 | break; |
| 408 | } |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | void nv40_graph_takedown(struct drm_device *dev) |
| 414 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 415 | } |
| 416 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 417 | static int |
| 418 | nv40_graph_register(struct drm_device *dev) |
| 419 | { |
| 420 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 421 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 422 | if (dev_priv->engine.graph.registered) |
| 423 | return 0; |
| 424 | |
| 425 | NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */ |
| 426 | NVOBJ_CLASS(dev, 0x0030, GR); /* null */ |
| 427 | NVOBJ_CLASS(dev, 0x0039, GR); /* m2mf */ |
| 428 | NVOBJ_CLASS(dev, 0x004a, GR); /* gdirect */ |
| 429 | NVOBJ_CLASS(dev, 0x009f, GR); /* imageblit (nv12) */ |
| 430 | NVOBJ_CLASS(dev, 0x008a, GR); /* ifc */ |
| 431 | NVOBJ_CLASS(dev, 0x0089, GR); /* sifm */ |
| 432 | NVOBJ_CLASS(dev, 0x3089, GR); /* sifm (nv40) */ |
| 433 | NVOBJ_CLASS(dev, 0x0062, GR); /* surf2d */ |
| 434 | NVOBJ_CLASS(dev, 0x3062, GR); /* surf2d (nv40) */ |
| 435 | NVOBJ_CLASS(dev, 0x0043, GR); /* rop */ |
| 436 | NVOBJ_CLASS(dev, 0x0012, GR); /* beta1 */ |
| 437 | NVOBJ_CLASS(dev, 0x0072, GR); /* beta4 */ |
| 438 | NVOBJ_CLASS(dev, 0x0019, GR); /* cliprect */ |
| 439 | NVOBJ_CLASS(dev, 0x0044, GR); /* pattern */ |
| 440 | NVOBJ_CLASS(dev, 0x309e, GR); /* swzsurf */ |
| 441 | |
| 442 | /* curie */ |
| 443 | if (dev_priv->chipset >= 0x60 || |
| 444 | 0x00005450 & (1 << (dev_priv->chipset & 0x0f))) |
| 445 | NVOBJ_CLASS(dev, 0x4497, GR); |
| 446 | else |
| 447 | NVOBJ_CLASS(dev, 0x4097, GR); |
| 448 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame^] | 449 | /* nvsw */ |
| 450 | NVOBJ_CLASS(dev, 0x506e, SW); |
| 451 | NVOBJ_MTHD (dev, 0x506e, 0x0500, nv04_graph_mthd_page_flip); |
| 452 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 453 | dev_priv->engine.graph.registered = true; |
| 454 | return 0; |
| 455 | } |