nouveau_irq.c 36 KB

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