nouveau_irq.c 36 KB

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