nouveau_irq.c 35 KB

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