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