Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Ben Skeggs. |
| 3 | * |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | * a copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial |
| 16 | * portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 21 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * Authors: |
| 30 | * Ben Skeggs <darktama@iinet.net.au> |
| 31 | */ |
| 32 | |
| 33 | #include "drmP.h" |
| 34 | #include "drm.h" |
| 35 | #include "nouveau_drm.h" |
| 36 | #include "nouveau_drv.h" |
| 37 | #include "nouveau_reg.h" |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame^] | 38 | #include "nouveau_ramht.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 39 | #include <linux/ratelimit.h> |
| 40 | |
| 41 | /* needed for hotplug irq */ |
| 42 | #include "nouveau_connector.h" |
| 43 | #include "nv50_display.h" |
| 44 | |
| 45 | void |
| 46 | nouveau_irq_preinstall(struct drm_device *dev) |
| 47 | { |
| 48 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 49 | |
| 50 | /* Master disable */ |
| 51 | nv_wr32(dev, NV03_PMC_INTR_EN_0, 0); |
| 52 | |
Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 53 | if (dev_priv->card_type >= NV_50) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 54 | INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh); |
Ben Skeggs | a5acac6 | 2010-03-30 15:14:41 +1000 | [diff] [blame] | 55 | INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 56 | INIT_LIST_HEAD(&dev_priv->vbl_waiting); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | int |
| 61 | nouveau_irq_postinstall(struct drm_device *dev) |
| 62 | { |
| 63 | /* Master enable */ |
| 64 | nv_wr32(dev, NV03_PMC_INTR_EN_0, NV_PMC_INTR_EN_0_MASTER_ENABLE); |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | nouveau_irq_uninstall(struct drm_device *dev) |
| 70 | { |
| 71 | /* Master disable */ |
| 72 | nv_wr32(dev, NV03_PMC_INTR_EN_0, 0); |
| 73 | } |
| 74 | |
| 75 | static int |
| 76 | nouveau_call_method(struct nouveau_channel *chan, int class, int mthd, int data) |
| 77 | { |
| 78 | struct drm_nouveau_private *dev_priv = chan->dev->dev_private; |
| 79 | struct nouveau_pgraph_object_method *grm; |
| 80 | struct nouveau_pgraph_object_class *grc; |
| 81 | |
| 82 | grc = dev_priv->engine.graph.grclass; |
| 83 | while (grc->id) { |
| 84 | if (grc->id == class) |
| 85 | break; |
| 86 | grc++; |
| 87 | } |
| 88 | |
| 89 | if (grc->id != class || !grc->methods) |
| 90 | return -ENOENT; |
| 91 | |
| 92 | grm = grc->methods; |
| 93 | while (grm->id) { |
| 94 | if (grm->id == mthd) |
| 95 | return grm->exec(chan, class, mthd, data); |
| 96 | grm++; |
| 97 | } |
| 98 | |
| 99 | return -ENOENT; |
| 100 | } |
| 101 | |
| 102 | static bool |
| 103 | nouveau_fifo_swmthd(struct nouveau_channel *chan, uint32_t addr, uint32_t data) |
| 104 | { |
| 105 | struct drm_device *dev = chan->dev; |
| 106 | const int subc = (addr >> 13) & 0x7; |
| 107 | const int mthd = addr & 0x1ffc; |
| 108 | |
| 109 | if (mthd == 0x0000) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame^] | 110 | struct nouveau_gpuobj *gpuobj; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 111 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame^] | 112 | gpuobj = nouveau_ramht_find(chan, data); |
| 113 | if (!gpuobj) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 114 | return false; |
| 115 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame^] | 116 | if (gpuobj->engine != NVOBJ_ENGINE_SW) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 117 | return false; |
| 118 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame^] | 119 | chan->sw_subchannel[subc] = gpuobj->class; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 120 | nv_wr32(dev, NV04_PFIFO_CACHE1_ENGINE, nv_rd32(dev, |
| 121 | NV04_PFIFO_CACHE1_ENGINE) & ~(0xf << subc * 4)); |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | /* hw object */ |
| 126 | if (nv_rd32(dev, NV04_PFIFO_CACHE1_ENGINE) & (1 << (subc*4))) |
| 127 | return false; |
| 128 | |
| 129 | if (nouveau_call_method(chan, chan->sw_subchannel[subc], mthd, data)) |
| 130 | return false; |
| 131 | |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | static void |
| 136 | nouveau_fifo_irq_handler(struct drm_device *dev) |
| 137 | { |
| 138 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 139 | struct nouveau_engine *engine = &dev_priv->engine; |
| 140 | uint32_t status, reassign; |
| 141 | int cnt = 0; |
| 142 | |
| 143 | reassign = nv_rd32(dev, NV03_PFIFO_CACHES) & 1; |
| 144 | while ((status = nv_rd32(dev, NV03_PFIFO_INTR_0)) && (cnt++ < 100)) { |
| 145 | struct nouveau_channel *chan = NULL; |
| 146 | uint32_t chid, get; |
| 147 | |
| 148 | nv_wr32(dev, NV03_PFIFO_CACHES, 0); |
| 149 | |
| 150 | chid = engine->fifo.channel_id(dev); |
| 151 | if (chid >= 0 && chid < engine->fifo.channels) |
| 152 | chan = dev_priv->fifos[chid]; |
| 153 | get = nv_rd32(dev, NV03_PFIFO_CACHE1_GET); |
| 154 | |
| 155 | if (status & NV_PFIFO_INTR_CACHE_ERROR) { |
| 156 | uint32_t mthd, data; |
| 157 | int ptr; |
| 158 | |
| 159 | /* NV_PFIFO_CACHE1_GET actually goes to 0xffc before |
| 160 | * wrapping on my G80 chips, but CACHE1 isn't big |
| 161 | * enough for this much data.. Tests show that it |
| 162 | * wraps around to the start at GET=0x800.. No clue |
| 163 | * as to why.. |
| 164 | */ |
| 165 | ptr = (get & 0x7ff) >> 2; |
| 166 | |
| 167 | if (dev_priv->card_type < NV_40) { |
| 168 | mthd = nv_rd32(dev, |
| 169 | NV04_PFIFO_CACHE1_METHOD(ptr)); |
| 170 | data = nv_rd32(dev, |
| 171 | NV04_PFIFO_CACHE1_DATA(ptr)); |
| 172 | } else { |
| 173 | mthd = nv_rd32(dev, |
| 174 | NV40_PFIFO_CACHE1_METHOD(ptr)); |
| 175 | data = nv_rd32(dev, |
| 176 | NV40_PFIFO_CACHE1_DATA(ptr)); |
| 177 | } |
| 178 | |
| 179 | if (!chan || !nouveau_fifo_swmthd(chan, mthd, data)) { |
| 180 | NV_INFO(dev, "PFIFO_CACHE_ERROR - Ch %d/%d " |
| 181 | "Mthd 0x%04x Data 0x%08x\n", |
| 182 | chid, (mthd >> 13) & 7, mthd & 0x1ffc, |
| 183 | data); |
| 184 | } |
| 185 | |
| 186 | nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, 0); |
| 187 | nv_wr32(dev, NV03_PFIFO_INTR_0, |
| 188 | NV_PFIFO_INTR_CACHE_ERROR); |
| 189 | |
| 190 | nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0, |
| 191 | nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH0) & ~1); |
| 192 | nv_wr32(dev, NV03_PFIFO_CACHE1_GET, get + 4); |
| 193 | nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0, |
| 194 | nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH0) | 1); |
| 195 | nv_wr32(dev, NV04_PFIFO_CACHE1_HASH, 0); |
| 196 | |
| 197 | nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, |
| 198 | nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUSH) | 1); |
| 199 | nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1); |
| 200 | |
| 201 | status &= ~NV_PFIFO_INTR_CACHE_ERROR; |
| 202 | } |
| 203 | |
| 204 | if (status & NV_PFIFO_INTR_DMA_PUSHER) { |
| 205 | NV_INFO(dev, "PFIFO_DMA_PUSHER - Ch %d\n", chid); |
| 206 | |
| 207 | status &= ~NV_PFIFO_INTR_DMA_PUSHER; |
| 208 | nv_wr32(dev, NV03_PFIFO_INTR_0, |
| 209 | NV_PFIFO_INTR_DMA_PUSHER); |
| 210 | |
| 211 | nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_STATE, 0x00000000); |
| 212 | if (nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUT) != get) |
| 213 | nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_GET, |
| 214 | get + 4); |
| 215 | } |
| 216 | |
Francisco Jerez | 139295b | 2010-01-30 18:28:00 +0100 | [diff] [blame] | 217 | if (status & NV_PFIFO_INTR_SEMAPHORE) { |
| 218 | uint32_t sem; |
| 219 | |
| 220 | status &= ~NV_PFIFO_INTR_SEMAPHORE; |
| 221 | nv_wr32(dev, NV03_PFIFO_INTR_0, |
| 222 | NV_PFIFO_INTR_SEMAPHORE); |
| 223 | |
| 224 | sem = nv_rd32(dev, NV10_PFIFO_CACHE1_SEMAPHORE); |
| 225 | nv_wr32(dev, NV10_PFIFO_CACHE1_SEMAPHORE, sem | 0x1); |
| 226 | |
| 227 | nv_wr32(dev, NV03_PFIFO_CACHE1_GET, get + 4); |
| 228 | nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1); |
| 229 | } |
| 230 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 231 | if (status) { |
| 232 | NV_INFO(dev, "PFIFO_INTR 0x%08x - Ch %d\n", |
| 233 | status, chid); |
| 234 | nv_wr32(dev, NV03_PFIFO_INTR_0, status); |
| 235 | status = 0; |
| 236 | } |
| 237 | |
| 238 | nv_wr32(dev, NV03_PFIFO_CACHES, reassign); |
| 239 | } |
| 240 | |
| 241 | if (status) { |
| 242 | NV_INFO(dev, "PFIFO still angry after %d spins, halt\n", cnt); |
| 243 | nv_wr32(dev, 0x2140, 0); |
| 244 | nv_wr32(dev, 0x140, 0); |
| 245 | } |
| 246 | |
| 247 | nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PFIFO_PENDING); |
| 248 | } |
| 249 | |
| 250 | struct nouveau_bitfield_names { |
| 251 | uint32_t mask; |
| 252 | const char *name; |
| 253 | }; |
| 254 | |
| 255 | static struct nouveau_bitfield_names nstatus_names[] = |
| 256 | { |
| 257 | { NV04_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" }, |
| 258 | { NV04_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" }, |
| 259 | { NV04_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" }, |
| 260 | { NV04_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" } |
| 261 | }; |
| 262 | |
| 263 | static struct nouveau_bitfield_names nstatus_names_nv10[] = |
| 264 | { |
| 265 | { NV10_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" }, |
| 266 | { NV10_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" }, |
| 267 | { NV10_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" }, |
| 268 | { NV10_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" } |
| 269 | }; |
| 270 | |
| 271 | static struct nouveau_bitfield_names nsource_names[] = |
| 272 | { |
| 273 | { NV03_PGRAPH_NSOURCE_NOTIFICATION, "NOTIFICATION" }, |
| 274 | { NV03_PGRAPH_NSOURCE_DATA_ERROR, "DATA_ERROR" }, |
| 275 | { NV03_PGRAPH_NSOURCE_PROTECTION_ERROR, "PROTECTION_ERROR" }, |
| 276 | { NV03_PGRAPH_NSOURCE_RANGE_EXCEPTION, "RANGE_EXCEPTION" }, |
| 277 | { NV03_PGRAPH_NSOURCE_LIMIT_COLOR, "LIMIT_COLOR" }, |
| 278 | { NV03_PGRAPH_NSOURCE_LIMIT_ZETA, "LIMIT_ZETA" }, |
| 279 | { NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD, "ILLEGAL_MTHD" }, |
| 280 | { NV03_PGRAPH_NSOURCE_DMA_R_PROTECTION, "DMA_R_PROTECTION" }, |
| 281 | { NV03_PGRAPH_NSOURCE_DMA_W_PROTECTION, "DMA_W_PROTECTION" }, |
| 282 | { NV03_PGRAPH_NSOURCE_FORMAT_EXCEPTION, "FORMAT_EXCEPTION" }, |
| 283 | { NV03_PGRAPH_NSOURCE_PATCH_EXCEPTION, "PATCH_EXCEPTION" }, |
| 284 | { NV03_PGRAPH_NSOURCE_STATE_INVALID, "STATE_INVALID" }, |
| 285 | { NV03_PGRAPH_NSOURCE_DOUBLE_NOTIFY, "DOUBLE_NOTIFY" }, |
| 286 | { NV03_PGRAPH_NSOURCE_NOTIFY_IN_USE, "NOTIFY_IN_USE" }, |
| 287 | { NV03_PGRAPH_NSOURCE_METHOD_CNT, "METHOD_CNT" }, |
| 288 | { NV03_PGRAPH_NSOURCE_BFR_NOTIFICATION, "BFR_NOTIFICATION" }, |
| 289 | { NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION, "DMA_VTX_PROTECTION" }, |
| 290 | { NV03_PGRAPH_NSOURCE_DMA_WIDTH_A, "DMA_WIDTH_A" }, |
| 291 | { NV03_PGRAPH_NSOURCE_DMA_WIDTH_B, "DMA_WIDTH_B" }, |
| 292 | }; |
| 293 | |
| 294 | static void |
| 295 | nouveau_print_bitfield_names_(uint32_t value, |
| 296 | const struct nouveau_bitfield_names *namelist, |
| 297 | const int namelist_len) |
| 298 | { |
| 299 | /* |
| 300 | * Caller must have already printed the KERN_* log level for us. |
| 301 | * Also the caller is responsible for adding the newline. |
| 302 | */ |
| 303 | int i; |
| 304 | for (i = 0; i < namelist_len; ++i) { |
| 305 | uint32_t mask = namelist[i].mask; |
| 306 | if (value & mask) { |
| 307 | printk(" %s", namelist[i].name); |
| 308 | value &= ~mask; |
| 309 | } |
| 310 | } |
| 311 | if (value) |
| 312 | printk(" (unknown bits 0x%08x)", value); |
| 313 | } |
| 314 | #define nouveau_print_bitfield_names(val, namelist) \ |
| 315 | nouveau_print_bitfield_names_((val), (namelist), ARRAY_SIZE(namelist)) |
| 316 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 317 | struct nouveau_enum_names { |
| 318 | uint32_t value; |
| 319 | const char *name; |
| 320 | }; |
| 321 | |
| 322 | static void |
| 323 | nouveau_print_enum_names_(uint32_t value, |
| 324 | const struct nouveau_enum_names *namelist, |
| 325 | const int namelist_len) |
| 326 | { |
| 327 | /* |
| 328 | * Caller must have already printed the KERN_* log level for us. |
| 329 | * Also the caller is responsible for adding the newline. |
| 330 | */ |
| 331 | int i; |
| 332 | for (i = 0; i < namelist_len; ++i) { |
| 333 | if (value == namelist[i].value) { |
| 334 | printk("%s", namelist[i].name); |
| 335 | return; |
| 336 | } |
| 337 | } |
| 338 | printk("unknown value 0x%08x", value); |
| 339 | } |
| 340 | #define nouveau_print_enum_names(val, namelist) \ |
| 341 | nouveau_print_enum_names_((val), (namelist), ARRAY_SIZE(namelist)) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 342 | |
| 343 | static int |
| 344 | nouveau_graph_chid_from_grctx(struct drm_device *dev) |
| 345 | { |
| 346 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 347 | uint32_t inst; |
| 348 | int i; |
| 349 | |
| 350 | if (dev_priv->card_type < NV_40) |
| 351 | return dev_priv->engine.fifo.channels; |
| 352 | else |
| 353 | if (dev_priv->card_type < NV_50) { |
| 354 | inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 4; |
| 355 | |
| 356 | for (i = 0; i < dev_priv->engine.fifo.channels; i++) { |
| 357 | struct nouveau_channel *chan = dev_priv->fifos[i]; |
| 358 | |
| 359 | if (!chan || !chan->ramin_grctx) |
| 360 | continue; |
| 361 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame^] | 362 | if (inst == chan->ramin_grctx->pinst) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | } else { |
| 366 | inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 12; |
| 367 | |
| 368 | for (i = 0; i < dev_priv->engine.fifo.channels; i++) { |
| 369 | struct nouveau_channel *chan = dev_priv->fifos[i]; |
| 370 | |
| 371 | if (!chan || !chan->ramin) |
| 372 | continue; |
| 373 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame^] | 374 | if (inst == chan->ramin->vinst) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 375 | break; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | |
| 380 | return i; |
| 381 | } |
| 382 | |
| 383 | static int |
| 384 | nouveau_graph_trapped_channel(struct drm_device *dev, int *channel_ret) |
| 385 | { |
| 386 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 387 | struct nouveau_engine *engine = &dev_priv->engine; |
| 388 | int channel; |
| 389 | |
| 390 | if (dev_priv->card_type < NV_10) |
| 391 | channel = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 24) & 0xf; |
| 392 | else |
| 393 | if (dev_priv->card_type < NV_40) |
| 394 | channel = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 20) & 0x1f; |
| 395 | else |
| 396 | channel = nouveau_graph_chid_from_grctx(dev); |
| 397 | |
| 398 | if (channel >= engine->fifo.channels || !dev_priv->fifos[channel]) { |
| 399 | NV_ERROR(dev, "AIII, invalid/inactive channel id %d\n", channel); |
| 400 | return -EINVAL; |
| 401 | } |
| 402 | |
| 403 | *channel_ret = channel; |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | struct nouveau_pgraph_trap { |
| 408 | int channel; |
| 409 | int class; |
| 410 | int subc, mthd, size; |
| 411 | uint32_t data, data2; |
| 412 | uint32_t nsource, nstatus; |
| 413 | }; |
| 414 | |
| 415 | static void |
| 416 | nouveau_graph_trap_info(struct drm_device *dev, |
| 417 | struct nouveau_pgraph_trap *trap) |
| 418 | { |
| 419 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 420 | uint32_t address; |
| 421 | |
| 422 | trap->nsource = trap->nstatus = 0; |
| 423 | if (dev_priv->card_type < NV_50) { |
| 424 | trap->nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE); |
| 425 | trap->nstatus = nv_rd32(dev, NV03_PGRAPH_NSTATUS); |
| 426 | } |
| 427 | |
| 428 | if (nouveau_graph_trapped_channel(dev, &trap->channel)) |
| 429 | trap->channel = -1; |
| 430 | address = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR); |
| 431 | |
| 432 | trap->mthd = address & 0x1FFC; |
| 433 | trap->data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA); |
| 434 | if (dev_priv->card_type < NV_10) { |
| 435 | trap->subc = (address >> 13) & 0x7; |
| 436 | } else { |
| 437 | trap->subc = (address >> 16) & 0x7; |
| 438 | trap->data2 = nv_rd32(dev, NV10_PGRAPH_TRAPPED_DATA_HIGH); |
| 439 | } |
| 440 | |
| 441 | if (dev_priv->card_type < NV_10) |
| 442 | trap->class = nv_rd32(dev, 0x400180 + trap->subc*4) & 0xFF; |
| 443 | else if (dev_priv->card_type < NV_40) |
| 444 | trap->class = nv_rd32(dev, 0x400160 + trap->subc*4) & 0xFFF; |
| 445 | else if (dev_priv->card_type < NV_50) |
| 446 | trap->class = nv_rd32(dev, 0x400160 + trap->subc*4) & 0xFFFF; |
| 447 | else |
| 448 | trap->class = nv_rd32(dev, 0x400814); |
| 449 | } |
| 450 | |
| 451 | static void |
| 452 | nouveau_graph_dump_trap_info(struct drm_device *dev, const char *id, |
| 453 | struct nouveau_pgraph_trap *trap) |
| 454 | { |
| 455 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 456 | uint32_t nsource = trap->nsource, nstatus = trap->nstatus; |
| 457 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 458 | if (dev_priv->card_type < NV_50) { |
| 459 | NV_INFO(dev, "%s - nSource:", id); |
| 460 | nouveau_print_bitfield_names(nsource, nsource_names); |
| 461 | printk(", nStatus:"); |
| 462 | if (dev_priv->card_type < NV_10) |
| 463 | nouveau_print_bitfield_names(nstatus, nstatus_names); |
| 464 | else |
| 465 | nouveau_print_bitfield_names(nstatus, nstatus_names_nv10); |
| 466 | printk("\n"); |
| 467 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 468 | |
| 469 | NV_INFO(dev, "%s - Ch %d/%d Class 0x%04x Mthd 0x%04x " |
| 470 | "Data 0x%08x:0x%08x\n", |
| 471 | id, trap->channel, trap->subc, |
| 472 | trap->class, trap->mthd, |
| 473 | trap->data2, trap->data); |
| 474 | } |
| 475 | |
| 476 | static int |
| 477 | nouveau_pgraph_intr_swmthd(struct drm_device *dev, |
| 478 | struct nouveau_pgraph_trap *trap) |
| 479 | { |
| 480 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 481 | |
| 482 | if (trap->channel < 0 || |
| 483 | trap->channel >= dev_priv->engine.fifo.channels || |
| 484 | !dev_priv->fifos[trap->channel]) |
| 485 | return -ENODEV; |
| 486 | |
| 487 | return nouveau_call_method(dev_priv->fifos[trap->channel], |
| 488 | trap->class, trap->mthd, trap->data); |
| 489 | } |
| 490 | |
| 491 | static inline void |
| 492 | nouveau_pgraph_intr_notify(struct drm_device *dev, uint32_t nsource) |
| 493 | { |
| 494 | struct nouveau_pgraph_trap trap; |
| 495 | int unhandled = 0; |
| 496 | |
| 497 | nouveau_graph_trap_info(dev, &trap); |
| 498 | |
| 499 | if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) { |
| 500 | if (nouveau_pgraph_intr_swmthd(dev, &trap)) |
| 501 | unhandled = 1; |
| 502 | } else { |
| 503 | unhandled = 1; |
| 504 | } |
| 505 | |
| 506 | if (unhandled) |
| 507 | nouveau_graph_dump_trap_info(dev, "PGRAPH_NOTIFY", &trap); |
| 508 | } |
| 509 | |
| 510 | static DEFINE_RATELIMIT_STATE(nouveau_ratelimit_state, 3 * HZ, 20); |
| 511 | |
| 512 | static int nouveau_ratelimit(void) |
| 513 | { |
| 514 | return __ratelimit(&nouveau_ratelimit_state); |
| 515 | } |
| 516 | |
| 517 | |
| 518 | static inline void |
| 519 | nouveau_pgraph_intr_error(struct drm_device *dev, uint32_t nsource) |
| 520 | { |
| 521 | struct nouveau_pgraph_trap trap; |
| 522 | int unhandled = 0; |
| 523 | |
| 524 | nouveau_graph_trap_info(dev, &trap); |
| 525 | trap.nsource = nsource; |
| 526 | |
| 527 | if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) { |
| 528 | if (nouveau_pgraph_intr_swmthd(dev, &trap)) |
| 529 | unhandled = 1; |
Luca Barbieri | d051bbb | 2010-01-16 15:27:51 +0100 | [diff] [blame] | 530 | } else if (nsource & NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION) { |
| 531 | uint32_t v = nv_rd32(dev, 0x402000); |
| 532 | nv_wr32(dev, 0x402000, v); |
| 533 | |
| 534 | /* dump the error anyway for now: it's useful for |
| 535 | Gallium development */ |
| 536 | unhandled = 1; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 537 | } else { |
| 538 | unhandled = 1; |
| 539 | } |
| 540 | |
| 541 | if (unhandled && nouveau_ratelimit()) |
| 542 | nouveau_graph_dump_trap_info(dev, "PGRAPH_ERROR", &trap); |
| 543 | } |
| 544 | |
| 545 | static inline void |
| 546 | nouveau_pgraph_intr_context_switch(struct drm_device *dev) |
| 547 | { |
| 548 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 549 | struct nouveau_engine *engine = &dev_priv->engine; |
| 550 | uint32_t chid; |
| 551 | |
| 552 | chid = engine->fifo.channel_id(dev); |
| 553 | NV_DEBUG(dev, "PGRAPH context switch interrupt channel %x\n", chid); |
| 554 | |
| 555 | switch (dev_priv->card_type) { |
| 556 | case NV_04: |
| 557 | nv04_graph_context_switch(dev); |
| 558 | break; |
| 559 | case NV_10: |
| 560 | nv10_graph_context_switch(dev); |
| 561 | break; |
| 562 | default: |
| 563 | NV_ERROR(dev, "Context switch not implemented\n"); |
| 564 | break; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | static void |
| 569 | nouveau_pgraph_irq_handler(struct drm_device *dev) |
| 570 | { |
| 571 | uint32_t status; |
| 572 | |
| 573 | while ((status = nv_rd32(dev, NV03_PGRAPH_INTR))) { |
| 574 | uint32_t nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE); |
| 575 | |
| 576 | if (status & NV_PGRAPH_INTR_NOTIFY) { |
| 577 | nouveau_pgraph_intr_notify(dev, nsource); |
| 578 | |
| 579 | status &= ~NV_PGRAPH_INTR_NOTIFY; |
| 580 | nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_NOTIFY); |
| 581 | } |
| 582 | |
| 583 | if (status & NV_PGRAPH_INTR_ERROR) { |
| 584 | nouveau_pgraph_intr_error(dev, nsource); |
| 585 | |
| 586 | status &= ~NV_PGRAPH_INTR_ERROR; |
| 587 | nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_ERROR); |
| 588 | } |
| 589 | |
| 590 | if (status & NV_PGRAPH_INTR_CONTEXT_SWITCH) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 591 | status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH; |
| 592 | nv_wr32(dev, NV03_PGRAPH_INTR, |
| 593 | NV_PGRAPH_INTR_CONTEXT_SWITCH); |
Francisco Jerez | 308dceb | 2010-08-04 04:41:55 +0200 | [diff] [blame] | 594 | |
| 595 | nouveau_pgraph_intr_context_switch(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | if (status) { |
| 599 | NV_INFO(dev, "Unhandled PGRAPH_INTR - 0x%08x\n", status); |
| 600 | nv_wr32(dev, NV03_PGRAPH_INTR, status); |
| 601 | } |
| 602 | |
| 603 | if ((nv_rd32(dev, NV04_PGRAPH_FIFO) & (1 << 0)) == 0) |
| 604 | nv_wr32(dev, NV04_PGRAPH_FIFO, 1); |
| 605 | } |
| 606 | |
| 607 | nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING); |
| 608 | } |
| 609 | |
| 610 | static void |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 611 | nv50_pfb_vm_trap(struct drm_device *dev, int display, const char *name) |
| 612 | { |
| 613 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 614 | uint32_t trap[6]; |
| 615 | int i, ch; |
| 616 | uint32_t idx = nv_rd32(dev, 0x100c90); |
| 617 | if (idx & 0x80000000) { |
| 618 | idx &= 0xffffff; |
| 619 | if (display) { |
| 620 | for (i = 0; i < 6; i++) { |
| 621 | nv_wr32(dev, 0x100c90, idx | i << 24); |
| 622 | trap[i] = nv_rd32(dev, 0x100c94); |
| 623 | } |
| 624 | for (ch = 0; ch < dev_priv->engine.fifo.channels; ch++) { |
| 625 | struct nouveau_channel *chan = dev_priv->fifos[ch]; |
| 626 | |
| 627 | if (!chan || !chan->ramin) |
| 628 | continue; |
| 629 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame^] | 630 | if (trap[1] == chan->ramin->vinst >> 12) |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 631 | break; |
| 632 | } |
| 633 | NV_INFO(dev, "%s - VM: Trapped %s at %02x%04x%04x status %08x %08x channel %d\n", |
| 634 | name, (trap[5]&0x100?"read":"write"), |
| 635 | trap[5]&0xff, trap[4]&0xffff, |
| 636 | trap[3]&0xffff, trap[0], trap[2], ch); |
| 637 | } |
| 638 | nv_wr32(dev, 0x100c90, idx | 0x80000000); |
| 639 | } else if (display) { |
| 640 | NV_INFO(dev, "%s - no VM fault?\n", name); |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | static struct nouveau_enum_names nv50_mp_exec_error_names[] = |
| 645 | { |
| 646 | { 3, "STACK_UNDERFLOW" }, |
| 647 | { 4, "QUADON_ACTIVE" }, |
| 648 | { 8, "TIMEOUT" }, |
| 649 | { 0x10, "INVALID_OPCODE" }, |
| 650 | { 0x40, "BREAKPOINT" }, |
| 651 | }; |
| 652 | |
| 653 | static void |
| 654 | nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display) |
| 655 | { |
| 656 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 657 | uint32_t units = nv_rd32(dev, 0x1540); |
| 658 | uint32_t addr, mp10, status, pc, oplow, ophigh; |
| 659 | int i; |
| 660 | int mps = 0; |
| 661 | for (i = 0; i < 4; i++) { |
| 662 | if (!(units & 1 << (i+24))) |
| 663 | continue; |
| 664 | if (dev_priv->chipset < 0xa0) |
| 665 | addr = 0x408200 + (tpid << 12) + (i << 7); |
| 666 | else |
| 667 | addr = 0x408100 + (tpid << 11) + (i << 7); |
| 668 | mp10 = nv_rd32(dev, addr + 0x10); |
| 669 | status = nv_rd32(dev, addr + 0x14); |
| 670 | if (!status) |
| 671 | continue; |
| 672 | if (display) { |
| 673 | nv_rd32(dev, addr + 0x20); |
| 674 | pc = nv_rd32(dev, addr + 0x24); |
| 675 | oplow = nv_rd32(dev, addr + 0x70); |
| 676 | ophigh= nv_rd32(dev, addr + 0x74); |
| 677 | NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - " |
| 678 | "TP %d MP %d: ", tpid, i); |
| 679 | nouveau_print_enum_names(status, |
| 680 | nv50_mp_exec_error_names); |
| 681 | printk(" at %06x warp %d, opcode %08x %08x\n", |
| 682 | pc&0xffffff, pc >> 24, |
| 683 | oplow, ophigh); |
| 684 | } |
| 685 | nv_wr32(dev, addr + 0x10, mp10); |
| 686 | nv_wr32(dev, addr + 0x14, 0); |
| 687 | mps++; |
| 688 | } |
| 689 | if (!mps && display) |
| 690 | NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: " |
| 691 | "No MPs claiming errors?\n", tpid); |
| 692 | } |
| 693 | |
| 694 | static void |
| 695 | nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old, |
| 696 | uint32_t ustatus_new, int display, const char *name) |
| 697 | { |
| 698 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 699 | int tps = 0; |
| 700 | uint32_t units = nv_rd32(dev, 0x1540); |
| 701 | int i, r; |
| 702 | uint32_t ustatus_addr, ustatus; |
| 703 | for (i = 0; i < 16; i++) { |
| 704 | if (!(units & (1 << i))) |
| 705 | continue; |
| 706 | if (dev_priv->chipset < 0xa0) |
| 707 | ustatus_addr = ustatus_old + (i << 12); |
| 708 | else |
| 709 | ustatus_addr = ustatus_new + (i << 11); |
| 710 | ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff; |
| 711 | if (!ustatus) |
| 712 | continue; |
| 713 | tps++; |
| 714 | switch (type) { |
| 715 | case 6: /* texture error... unknown for now */ |
| 716 | nv50_pfb_vm_trap(dev, display, name); |
| 717 | if (display) { |
| 718 | NV_ERROR(dev, "magic set %d:\n", i); |
| 719 | for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4) |
| 720 | NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, |
| 721 | nv_rd32(dev, r)); |
| 722 | } |
| 723 | break; |
| 724 | case 7: /* MP error */ |
| 725 | if (ustatus & 0x00010000) { |
| 726 | nv50_pgraph_mp_trap(dev, i, display); |
| 727 | ustatus &= ~0x00010000; |
| 728 | } |
| 729 | break; |
| 730 | case 8: /* TPDMA error */ |
| 731 | { |
| 732 | uint32_t e0c = nv_rd32(dev, ustatus_addr + 4); |
| 733 | uint32_t e10 = nv_rd32(dev, ustatus_addr + 8); |
| 734 | uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc); |
| 735 | uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10); |
| 736 | uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14); |
| 737 | uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18); |
| 738 | uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c); |
| 739 | nv50_pfb_vm_trap(dev, display, name); |
| 740 | /* 2d engine destination */ |
| 741 | if (ustatus & 0x00000010) { |
| 742 | if (display) { |
| 743 | NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n", |
| 744 | i, e14, e10); |
| 745 | NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n", |
| 746 | i, e0c, e18, e1c, e20, e24); |
| 747 | } |
| 748 | ustatus &= ~0x00000010; |
| 749 | } |
| 750 | /* Render target */ |
| 751 | if (ustatus & 0x00000040) { |
| 752 | if (display) { |
| 753 | NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n", |
| 754 | i, e14, e10); |
| 755 | NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n", |
| 756 | i, e0c, e18, e1c, e20, e24); |
| 757 | } |
| 758 | ustatus &= ~0x00000040; |
| 759 | } |
| 760 | /* CUDA memory: l[], g[] or stack. */ |
| 761 | if (ustatus & 0x00000080) { |
| 762 | if (display) { |
| 763 | if (e18 & 0x80000000) { |
| 764 | /* g[] read fault? */ |
| 765 | NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n", |
| 766 | i, e14, e10 | ((e18 >> 24) & 0x1f)); |
| 767 | e18 &= ~0x1f000000; |
| 768 | } else if (e18 & 0xc) { |
| 769 | /* g[] write fault? */ |
| 770 | NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n", |
| 771 | i, e14, e10 | ((e18 >> 7) & 0x1f)); |
| 772 | e18 &= ~0x00000f80; |
| 773 | } else { |
| 774 | NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n", |
| 775 | i, e14, e10); |
| 776 | } |
| 777 | NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n", |
| 778 | i, e0c, e18, e1c, e20, e24); |
| 779 | } |
| 780 | ustatus &= ~0x00000080; |
| 781 | } |
| 782 | } |
| 783 | break; |
| 784 | } |
| 785 | if (ustatus) { |
| 786 | if (display) |
| 787 | NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus); |
| 788 | } |
| 789 | nv_wr32(dev, ustatus_addr, 0xc0000000); |
| 790 | } |
| 791 | |
| 792 | if (!tps && display) |
| 793 | NV_INFO(dev, "%s - No TPs claiming errors?\n", name); |
| 794 | } |
| 795 | |
| 796 | static void |
| 797 | nv50_pgraph_trap_handler(struct drm_device *dev) |
| 798 | { |
| 799 | struct nouveau_pgraph_trap trap; |
| 800 | uint32_t status = nv_rd32(dev, 0x400108); |
| 801 | uint32_t ustatus; |
| 802 | int display = nouveau_ratelimit(); |
| 803 | |
| 804 | |
| 805 | if (!status && display) { |
| 806 | nouveau_graph_trap_info(dev, &trap); |
| 807 | nouveau_graph_dump_trap_info(dev, "PGRAPH_TRAP", &trap); |
| 808 | NV_INFO(dev, "PGRAPH_TRAP - no units reporting traps?\n"); |
| 809 | } |
| 810 | |
| 811 | /* DISPATCH: Relays commands to other units and handles NOTIFY, |
| 812 | * COND, QUERY. If you get a trap from it, the command is still stuck |
| 813 | * in DISPATCH and you need to do something about it. */ |
| 814 | if (status & 0x001) { |
| 815 | ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff; |
| 816 | if (!ustatus && display) { |
| 817 | NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n"); |
| 818 | } |
| 819 | |
| 820 | /* Known to be triggered by screwed up NOTIFY and COND... */ |
| 821 | if (ustatus & 0x00000001) { |
| 822 | nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_DISPATCH_FAULT"); |
| 823 | nv_wr32(dev, 0x400500, 0); |
| 824 | if (nv_rd32(dev, 0x400808) & 0x80000000) { |
| 825 | if (display) { |
| 826 | if (nouveau_graph_trapped_channel(dev, &trap.channel)) |
| 827 | trap.channel = -1; |
| 828 | trap.class = nv_rd32(dev, 0x400814); |
| 829 | trap.mthd = nv_rd32(dev, 0x400808) & 0x1ffc; |
| 830 | trap.subc = (nv_rd32(dev, 0x400808) >> 16) & 0x7; |
| 831 | trap.data = nv_rd32(dev, 0x40080c); |
| 832 | trap.data2 = nv_rd32(dev, 0x400810); |
| 833 | nouveau_graph_dump_trap_info(dev, |
| 834 | "PGRAPH_TRAP_DISPATCH_FAULT", &trap); |
| 835 | NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - 400808: %08x\n", nv_rd32(dev, 0x400808)); |
| 836 | NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - 400848: %08x\n", nv_rd32(dev, 0x400848)); |
| 837 | } |
| 838 | nv_wr32(dev, 0x400808, 0); |
| 839 | } else if (display) { |
| 840 | NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - No stuck command?\n"); |
| 841 | } |
| 842 | nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3); |
| 843 | nv_wr32(dev, 0x400848, 0); |
| 844 | ustatus &= ~0x00000001; |
| 845 | } |
| 846 | if (ustatus & 0x00000002) { |
| 847 | nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_DISPATCH_QUERY"); |
| 848 | nv_wr32(dev, 0x400500, 0); |
| 849 | if (nv_rd32(dev, 0x40084c) & 0x80000000) { |
| 850 | if (display) { |
| 851 | if (nouveau_graph_trapped_channel(dev, &trap.channel)) |
| 852 | trap.channel = -1; |
| 853 | trap.class = nv_rd32(dev, 0x400814); |
| 854 | trap.mthd = nv_rd32(dev, 0x40084c) & 0x1ffc; |
| 855 | trap.subc = (nv_rd32(dev, 0x40084c) >> 16) & 0x7; |
| 856 | trap.data = nv_rd32(dev, 0x40085c); |
| 857 | trap.data2 = 0; |
| 858 | nouveau_graph_dump_trap_info(dev, |
| 859 | "PGRAPH_TRAP_DISPATCH_QUERY", &trap); |
| 860 | NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_QUERY - 40084c: %08x\n", nv_rd32(dev, 0x40084c)); |
| 861 | } |
| 862 | nv_wr32(dev, 0x40084c, 0); |
| 863 | } else if (display) { |
| 864 | NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_QUERY - No stuck command?\n"); |
| 865 | } |
| 866 | ustatus &= ~0x00000002; |
| 867 | } |
| 868 | if (ustatus && display) |
| 869 | NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - Unhandled ustatus 0x%08x\n", ustatus); |
| 870 | nv_wr32(dev, 0x400804, 0xc0000000); |
| 871 | nv_wr32(dev, 0x400108, 0x001); |
| 872 | status &= ~0x001; |
| 873 | } |
| 874 | |
| 875 | /* TRAPs other than dispatch use the "normal" trap regs. */ |
| 876 | if (status && display) { |
| 877 | nouveau_graph_trap_info(dev, &trap); |
| 878 | nouveau_graph_dump_trap_info(dev, |
| 879 | "PGRAPH_TRAP", &trap); |
| 880 | } |
| 881 | |
| 882 | /* M2MF: Memory to memory copy engine. */ |
| 883 | if (status & 0x002) { |
| 884 | ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff; |
| 885 | if (!ustatus && display) { |
| 886 | NV_INFO(dev, "PGRAPH_TRAP_M2MF - no ustatus?\n"); |
| 887 | } |
| 888 | if (ustatus & 0x00000001) { |
| 889 | nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_NOTIFY"); |
| 890 | ustatus &= ~0x00000001; |
| 891 | } |
| 892 | if (ustatus & 0x00000002) { |
| 893 | nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_IN"); |
| 894 | ustatus &= ~0x00000002; |
| 895 | } |
| 896 | if (ustatus & 0x00000004) { |
| 897 | nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_OUT"); |
| 898 | ustatus &= ~0x00000004; |
| 899 | } |
| 900 | NV_INFO (dev, "PGRAPH_TRAP_M2MF - %08x %08x %08x %08x\n", |
| 901 | nv_rd32(dev, 0x406804), |
| 902 | nv_rd32(dev, 0x406808), |
| 903 | nv_rd32(dev, 0x40680c), |
| 904 | nv_rd32(dev, 0x406810)); |
| 905 | if (ustatus && display) |
| 906 | NV_INFO(dev, "PGRAPH_TRAP_M2MF - Unhandled ustatus 0x%08x\n", ustatus); |
| 907 | /* No sane way found yet -- just reset the bugger. */ |
| 908 | nv_wr32(dev, 0x400040, 2); |
| 909 | nv_wr32(dev, 0x400040, 0); |
| 910 | nv_wr32(dev, 0x406800, 0xc0000000); |
| 911 | nv_wr32(dev, 0x400108, 0x002); |
| 912 | status &= ~0x002; |
| 913 | } |
| 914 | |
| 915 | /* VFETCH: Fetches data from vertex buffers. */ |
| 916 | if (status & 0x004) { |
| 917 | ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff; |
| 918 | if (!ustatus && display) { |
| 919 | NV_INFO(dev, "PGRAPH_TRAP_VFETCH - no ustatus?\n"); |
| 920 | } |
| 921 | if (ustatus & 0x00000001) { |
| 922 | nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_VFETCH_FAULT"); |
| 923 | NV_INFO (dev, "PGRAPH_TRAP_VFETCH_FAULT - %08x %08x %08x %08x\n", |
| 924 | nv_rd32(dev, 0x400c00), |
| 925 | nv_rd32(dev, 0x400c08), |
| 926 | nv_rd32(dev, 0x400c0c), |
| 927 | nv_rd32(dev, 0x400c10)); |
| 928 | ustatus &= ~0x00000001; |
| 929 | } |
| 930 | if (ustatus && display) |
| 931 | NV_INFO(dev, "PGRAPH_TRAP_VFETCH - Unhandled ustatus 0x%08x\n", ustatus); |
| 932 | nv_wr32(dev, 0x400c04, 0xc0000000); |
| 933 | nv_wr32(dev, 0x400108, 0x004); |
| 934 | status &= ~0x004; |
| 935 | } |
| 936 | |
| 937 | /* STRMOUT: DirectX streamout / OpenGL transform feedback. */ |
| 938 | if (status & 0x008) { |
| 939 | ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff; |
| 940 | if (!ustatus && display) { |
| 941 | NV_INFO(dev, "PGRAPH_TRAP_STRMOUT - no ustatus?\n"); |
| 942 | } |
| 943 | if (ustatus & 0x00000001) { |
| 944 | nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_STRMOUT_FAULT"); |
| 945 | NV_INFO (dev, "PGRAPH_TRAP_STRMOUT_FAULT - %08x %08x %08x %08x\n", |
| 946 | nv_rd32(dev, 0x401804), |
| 947 | nv_rd32(dev, 0x401808), |
| 948 | nv_rd32(dev, 0x40180c), |
| 949 | nv_rd32(dev, 0x401810)); |
| 950 | ustatus &= ~0x00000001; |
| 951 | } |
| 952 | if (ustatus && display) |
| 953 | NV_INFO(dev, "PGRAPH_TRAP_STRMOUT - Unhandled ustatus 0x%08x\n", ustatus); |
| 954 | /* No sane way found yet -- just reset the bugger. */ |
| 955 | nv_wr32(dev, 0x400040, 0x80); |
| 956 | nv_wr32(dev, 0x400040, 0); |
| 957 | nv_wr32(dev, 0x401800, 0xc0000000); |
| 958 | nv_wr32(dev, 0x400108, 0x008); |
| 959 | status &= ~0x008; |
| 960 | } |
| 961 | |
| 962 | /* CCACHE: Handles code and c[] caches and fills them. */ |
| 963 | if (status & 0x010) { |
| 964 | ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff; |
| 965 | if (!ustatus && display) { |
| 966 | NV_INFO(dev, "PGRAPH_TRAP_CCACHE - no ustatus?\n"); |
| 967 | } |
| 968 | if (ustatus & 0x00000001) { |
| 969 | nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_CCACHE_FAULT"); |
| 970 | NV_INFO (dev, "PGRAPH_TRAP_CCACHE_FAULT - %08x %08x %08x %08x %08x %08x %08x\n", |
| 971 | nv_rd32(dev, 0x405800), |
| 972 | nv_rd32(dev, 0x405804), |
| 973 | nv_rd32(dev, 0x405808), |
| 974 | nv_rd32(dev, 0x40580c), |
| 975 | nv_rd32(dev, 0x405810), |
| 976 | nv_rd32(dev, 0x405814), |
| 977 | nv_rd32(dev, 0x40581c)); |
| 978 | ustatus &= ~0x00000001; |
| 979 | } |
| 980 | if (ustatus && display) |
| 981 | NV_INFO(dev, "PGRAPH_TRAP_CCACHE - Unhandled ustatus 0x%08x\n", ustatus); |
| 982 | nv_wr32(dev, 0x405018, 0xc0000000); |
| 983 | nv_wr32(dev, 0x400108, 0x010); |
| 984 | status &= ~0x010; |
| 985 | } |
| 986 | |
| 987 | /* Unknown, not seen yet... 0x402000 is the only trap status reg |
| 988 | * remaining, so try to handle it anyway. Perhaps related to that |
| 989 | * unknown DMA slot on tesla? */ |
| 990 | if (status & 0x20) { |
| 991 | nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_UNKC04"); |
| 992 | ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff; |
| 993 | if (display) |
| 994 | NV_INFO(dev, "PGRAPH_TRAP_UNKC04 - Unhandled ustatus 0x%08x\n", ustatus); |
| 995 | nv_wr32(dev, 0x402000, 0xc0000000); |
| 996 | /* no status modifiction on purpose */ |
| 997 | } |
| 998 | |
| 999 | /* TEXTURE: CUDA texturing units */ |
| 1000 | if (status & 0x040) { |
| 1001 | nv50_pgraph_tp_trap (dev, 6, 0x408900, 0x408600, display, |
| 1002 | "PGRAPH_TRAP_TEXTURE"); |
| 1003 | nv_wr32(dev, 0x400108, 0x040); |
| 1004 | status &= ~0x040; |
| 1005 | } |
| 1006 | |
| 1007 | /* MP: CUDA execution engines. */ |
| 1008 | if (status & 0x080) { |
| 1009 | nv50_pgraph_tp_trap (dev, 7, 0x408314, 0x40831c, display, |
| 1010 | "PGRAPH_TRAP_MP"); |
| 1011 | nv_wr32(dev, 0x400108, 0x080); |
| 1012 | status &= ~0x080; |
| 1013 | } |
| 1014 | |
| 1015 | /* TPDMA: Handles TP-initiated uncached memory accesses: |
| 1016 | * l[], g[], stack, 2d surfaces, render targets. */ |
| 1017 | if (status & 0x100) { |
| 1018 | nv50_pgraph_tp_trap (dev, 8, 0x408e08, 0x408708, display, |
| 1019 | "PGRAPH_TRAP_TPDMA"); |
| 1020 | nv_wr32(dev, 0x400108, 0x100); |
| 1021 | status &= ~0x100; |
| 1022 | } |
| 1023 | |
| 1024 | if (status) { |
| 1025 | if (display) |
| 1026 | NV_INFO(dev, "PGRAPH_TRAP - Unknown trap 0x%08x\n", |
| 1027 | status); |
| 1028 | nv_wr32(dev, 0x400108, status); |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | /* There must be a *lot* of these. Will take some time to gather them up. */ |
| 1033 | static struct nouveau_enum_names nv50_data_error_names[] = |
| 1034 | { |
| 1035 | { 4, "INVALID_VALUE" }, |
| 1036 | { 5, "INVALID_ENUM" }, |
| 1037 | { 8, "INVALID_OBJECT" }, |
| 1038 | { 0xc, "INVALID_BITFIELD" }, |
| 1039 | { 0x28, "MP_NO_REG_SPACE" }, |
| 1040 | { 0x2b, "MP_BLOCK_SIZE_MISMATCH" }, |
| 1041 | }; |
| 1042 | |
| 1043 | static void |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1044 | nv50_pgraph_irq_handler(struct drm_device *dev) |
| 1045 | { |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1046 | struct nouveau_pgraph_trap trap; |
| 1047 | int unhandled = 0; |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1048 | uint32_t status; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1049 | |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1050 | while ((status = nv_rd32(dev, NV03_PGRAPH_INTR))) { |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1051 | /* NOTIFY: You've set a NOTIFY an a command and it's done. */ |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1052 | if (status & 0x00000001) { |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1053 | nouveau_graph_trap_info(dev, &trap); |
| 1054 | if (nouveau_ratelimit()) |
| 1055 | nouveau_graph_dump_trap_info(dev, |
| 1056 | "PGRAPH_NOTIFY", &trap); |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1057 | status &= ~0x00000001; |
| 1058 | nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000001); |
| 1059 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1060 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1061 | /* COMPUTE_QUERY: Purpose and exact cause unknown, happens |
| 1062 | * when you write 0x200 to 0x50c0 method 0x31c. */ |
| 1063 | if (status & 0x00000002) { |
| 1064 | nouveau_graph_trap_info(dev, &trap); |
| 1065 | if (nouveau_ratelimit()) |
| 1066 | nouveau_graph_dump_trap_info(dev, |
| 1067 | "PGRAPH_COMPUTE_QUERY", &trap); |
| 1068 | status &= ~0x00000002; |
| 1069 | nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000002); |
| 1070 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1071 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1072 | /* Unknown, never seen: 0x4 */ |
| 1073 | |
| 1074 | /* ILLEGAL_MTHD: You used a wrong method for this class. */ |
| 1075 | if (status & 0x00000010) { |
| 1076 | nouveau_graph_trap_info(dev, &trap); |
| 1077 | if (nouveau_pgraph_intr_swmthd(dev, &trap)) |
| 1078 | unhandled = 1; |
| 1079 | if (unhandled && nouveau_ratelimit()) |
| 1080 | nouveau_graph_dump_trap_info(dev, |
| 1081 | "PGRAPH_ILLEGAL_MTHD", &trap); |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1082 | status &= ~0x00000010; |
| 1083 | nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000010); |
| 1084 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1085 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1086 | /* ILLEGAL_CLASS: You used a wrong class. */ |
| 1087 | if (status & 0x00000020) { |
| 1088 | nouveau_graph_trap_info(dev, &trap); |
| 1089 | if (nouveau_ratelimit()) |
| 1090 | nouveau_graph_dump_trap_info(dev, |
| 1091 | "PGRAPH_ILLEGAL_CLASS", &trap); |
| 1092 | status &= ~0x00000020; |
| 1093 | nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000020); |
| 1094 | } |
| 1095 | |
| 1096 | /* DOUBLE_NOTIFY: You tried to set a NOTIFY on another NOTIFY. */ |
| 1097 | if (status & 0x00000040) { |
| 1098 | nouveau_graph_trap_info(dev, &trap); |
| 1099 | if (nouveau_ratelimit()) |
| 1100 | nouveau_graph_dump_trap_info(dev, |
| 1101 | "PGRAPH_DOUBLE_NOTIFY", &trap); |
| 1102 | status &= ~0x00000040; |
| 1103 | nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000040); |
| 1104 | } |
| 1105 | |
| 1106 | /* CONTEXT_SWITCH: PGRAPH needs us to load a new context */ |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1107 | if (status & 0x00001000) { |
| 1108 | nv_wr32(dev, 0x400500, 0x00000000); |
| 1109 | nv_wr32(dev, NV03_PGRAPH_INTR, |
| 1110 | NV_PGRAPH_INTR_CONTEXT_SWITCH); |
| 1111 | nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev, |
| 1112 | NV40_PGRAPH_INTR_EN) & |
| 1113 | ~NV_PGRAPH_INTR_CONTEXT_SWITCH); |
| 1114 | nv_wr32(dev, 0x400500, 0x00010001); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1115 | |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1116 | nv50_graph_context_switch(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1117 | |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1118 | status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH; |
| 1119 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1120 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1121 | /* BUFFER_NOTIFY: Your m2mf transfer finished */ |
| 1122 | if (status & 0x00010000) { |
| 1123 | nouveau_graph_trap_info(dev, &trap); |
| 1124 | if (nouveau_ratelimit()) |
| 1125 | nouveau_graph_dump_trap_info(dev, |
| 1126 | "PGRAPH_BUFFER_NOTIFY", &trap); |
| 1127 | status &= ~0x00010000; |
| 1128 | nv_wr32(dev, NV03_PGRAPH_INTR, 0x00010000); |
| 1129 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1130 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1131 | /* DATA_ERROR: Invalid value for this method, or invalid |
| 1132 | * state in current PGRAPH context for this operation */ |
| 1133 | if (status & 0x00100000) { |
| 1134 | nouveau_graph_trap_info(dev, &trap); |
| 1135 | if (nouveau_ratelimit()) { |
| 1136 | nouveau_graph_dump_trap_info(dev, |
| 1137 | "PGRAPH_DATA_ERROR", &trap); |
| 1138 | NV_INFO (dev, "PGRAPH_DATA_ERROR - "); |
| 1139 | nouveau_print_enum_names(nv_rd32(dev, 0x400110), |
| 1140 | nv50_data_error_names); |
| 1141 | printk("\n"); |
| 1142 | } |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1143 | status &= ~0x00100000; |
| 1144 | nv_wr32(dev, NV03_PGRAPH_INTR, 0x00100000); |
| 1145 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1146 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1147 | /* TRAP: Something bad happened in the middle of command |
| 1148 | * execution. Has a billion types, subtypes, and even |
| 1149 | * subsubtypes. */ |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1150 | if (status & 0x00200000) { |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1151 | nv50_pgraph_trap_handler(dev); |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1152 | status &= ~0x00200000; |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1153 | nv_wr32(dev, NV03_PGRAPH_INTR, 0x00200000); |
| 1154 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1155 | |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1156 | /* Unknown, never seen: 0x00400000 */ |
| 1157 | |
| 1158 | /* SINGLE_STEP: Happens on every method if you turned on |
| 1159 | * single stepping in 40008c */ |
| 1160 | if (status & 0x01000000) { |
| 1161 | nouveau_graph_trap_info(dev, &trap); |
| 1162 | if (nouveau_ratelimit()) |
| 1163 | nouveau_graph_dump_trap_info(dev, |
| 1164 | "PGRAPH_SINGLE_STEP", &trap); |
| 1165 | status &= ~0x01000000; |
| 1166 | nv_wr32(dev, NV03_PGRAPH_INTR, 0x01000000); |
| 1167 | } |
| 1168 | |
| 1169 | /* 0x02000000 happens when you pause a ctxprog... |
| 1170 | * but the only way this can happen that I know is by |
| 1171 | * poking the relevant MMIO register, and we don't |
| 1172 | * do that. */ |
| 1173 | |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1174 | if (status) { |
| 1175 | NV_INFO(dev, "Unhandled PGRAPH_INTR - 0x%08x\n", |
| 1176 | status); |
| 1177 | nv_wr32(dev, NV03_PGRAPH_INTR, status); |
| 1178 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1179 | |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1180 | { |
| 1181 | const int isb = (1 << 16) | (1 << 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1182 | |
Maarten Maathuis | b1d37aa | 2010-01-20 19:54:34 +0100 | [diff] [blame] | 1183 | if ((nv_rd32(dev, 0x400500) & isb) != isb) |
| 1184 | nv_wr32(dev, 0x400500, |
| 1185 | nv_rd32(dev, 0x400500) | isb); |
| 1186 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING); |
Marcin Kościelnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 1190 | if (nv_rd32(dev, 0x400824) & (1 << 31)) |
| 1191 | nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | static void |
| 1195 | nouveau_crtc_irq_handler(struct drm_device *dev, int crtc) |
| 1196 | { |
| 1197 | if (crtc & 1) |
| 1198 | nv_wr32(dev, NV_CRTC0_INTSTAT, NV_CRTC_INTR_VBLANK); |
| 1199 | |
| 1200 | if (crtc & 2) |
| 1201 | nv_wr32(dev, NV_CRTC1_INTSTAT, NV_CRTC_INTR_VBLANK); |
| 1202 | } |
| 1203 | |
| 1204 | irqreturn_t |
| 1205 | nouveau_irq_handler(DRM_IRQ_ARGS) |
| 1206 | { |
| 1207 | struct drm_device *dev = (struct drm_device *)arg; |
| 1208 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1209 | uint32_t status; |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 1210 | unsigned long flags; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1211 | |
| 1212 | status = nv_rd32(dev, NV03_PMC_INTR_0); |
| 1213 | if (!status) |
| 1214 | return IRQ_NONE; |
| 1215 | |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 1216 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 1217 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1218 | if (status & NV_PMC_INTR_0_PFIFO_PENDING) { |
| 1219 | nouveau_fifo_irq_handler(dev); |
| 1220 | status &= ~NV_PMC_INTR_0_PFIFO_PENDING; |
| 1221 | } |
| 1222 | |
| 1223 | if (status & NV_PMC_INTR_0_PGRAPH_PENDING) { |
| 1224 | if (dev_priv->card_type >= NV_50) |
| 1225 | nv50_pgraph_irq_handler(dev); |
| 1226 | else |
| 1227 | nouveau_pgraph_irq_handler(dev); |
| 1228 | |
| 1229 | status &= ~NV_PMC_INTR_0_PGRAPH_PENDING; |
| 1230 | } |
| 1231 | |
| 1232 | if (status & NV_PMC_INTR_0_CRTCn_PENDING) { |
| 1233 | nouveau_crtc_irq_handler(dev, (status>>24)&3); |
| 1234 | status &= ~NV_PMC_INTR_0_CRTCn_PENDING; |
| 1235 | } |
| 1236 | |
| 1237 | if (status & (NV_PMC_INTR_0_NV50_DISPLAY_PENDING | |
| 1238 | NV_PMC_INTR_0_NV50_I2C_PENDING)) { |
| 1239 | nv50_display_irq_handler(dev); |
| 1240 | status &= ~(NV_PMC_INTR_0_NV50_DISPLAY_PENDING | |
| 1241 | NV_PMC_INTR_0_NV50_I2C_PENDING); |
| 1242 | } |
| 1243 | |
| 1244 | if (status) |
| 1245 | NV_ERROR(dev, "Unhandled PMC INTR status bits 0x%08x\n", status); |
| 1246 | |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 1247 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
| 1248 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1249 | return IRQ_HANDLED; |
| 1250 | } |