nouveau_irq.c 36 KB

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