i915_gpu_error.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. /*
  2. * Copyright (c) 2008 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. * Keith Packard <keithp@keithp.com>
  26. * Mika Kuoppala <mika.kuoppala@intel.com>
  27. *
  28. */
  29. #include <generated/utsrelease.h>
  30. #include "i915_drv.h"
  31. static const char *yesno(int v)
  32. {
  33. return v ? "yes" : "no";
  34. }
  35. static const char *ring_str(int ring)
  36. {
  37. switch (ring) {
  38. case RCS: return "render";
  39. case VCS: return "bsd";
  40. case BCS: return "blt";
  41. case VECS: return "vebox";
  42. case VCS2: return "bsd2";
  43. default: return "";
  44. }
  45. }
  46. static const char *pin_flag(int pinned)
  47. {
  48. if (pinned > 0)
  49. return " P";
  50. else if (pinned < 0)
  51. return " p";
  52. else
  53. return "";
  54. }
  55. static const char *tiling_flag(int tiling)
  56. {
  57. switch (tiling) {
  58. default:
  59. case I915_TILING_NONE: return "";
  60. case I915_TILING_X: return " X";
  61. case I915_TILING_Y: return " Y";
  62. }
  63. }
  64. static const char *dirty_flag(int dirty)
  65. {
  66. return dirty ? " dirty" : "";
  67. }
  68. static const char *purgeable_flag(int purgeable)
  69. {
  70. return purgeable ? " purgeable" : "";
  71. }
  72. static bool __i915_error_ok(struct drm_i915_error_state_buf *e)
  73. {
  74. if (!e->err && WARN(e->bytes > (e->size - 1), "overflow")) {
  75. e->err = -ENOSPC;
  76. return false;
  77. }
  78. if (e->bytes == e->size - 1 || e->err)
  79. return false;
  80. return true;
  81. }
  82. static bool __i915_error_seek(struct drm_i915_error_state_buf *e,
  83. unsigned len)
  84. {
  85. if (e->pos + len <= e->start) {
  86. e->pos += len;
  87. return false;
  88. }
  89. /* First vsnprintf needs to fit in its entirety for memmove */
  90. if (len >= e->size) {
  91. e->err = -EIO;
  92. return false;
  93. }
  94. return true;
  95. }
  96. static void __i915_error_advance(struct drm_i915_error_state_buf *e,
  97. unsigned len)
  98. {
  99. /* If this is first printf in this window, adjust it so that
  100. * start position matches start of the buffer
  101. */
  102. if (e->pos < e->start) {
  103. const size_t off = e->start - e->pos;
  104. /* Should not happen but be paranoid */
  105. if (off > len || e->bytes) {
  106. e->err = -EIO;
  107. return;
  108. }
  109. memmove(e->buf, e->buf + off, len - off);
  110. e->bytes = len - off;
  111. e->pos = e->start;
  112. return;
  113. }
  114. e->bytes += len;
  115. e->pos += len;
  116. }
  117. static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
  118. const char *f, va_list args)
  119. {
  120. unsigned len;
  121. if (!__i915_error_ok(e))
  122. return;
  123. /* Seek the first printf which is hits start position */
  124. if (e->pos < e->start) {
  125. va_list tmp;
  126. va_copy(tmp, args);
  127. len = vsnprintf(NULL, 0, f, tmp);
  128. va_end(tmp);
  129. if (!__i915_error_seek(e, len))
  130. return;
  131. }
  132. len = vsnprintf(e->buf + e->bytes, e->size - e->bytes, f, args);
  133. if (len >= e->size - e->bytes)
  134. len = e->size - e->bytes - 1;
  135. __i915_error_advance(e, len);
  136. }
  137. static void i915_error_puts(struct drm_i915_error_state_buf *e,
  138. const char *str)
  139. {
  140. unsigned len;
  141. if (!__i915_error_ok(e))
  142. return;
  143. len = strlen(str);
  144. /* Seek the first printf which is hits start position */
  145. if (e->pos < e->start) {
  146. if (!__i915_error_seek(e, len))
  147. return;
  148. }
  149. if (len >= e->size - e->bytes)
  150. len = e->size - e->bytes - 1;
  151. memcpy(e->buf + e->bytes, str, len);
  152. __i915_error_advance(e, len);
  153. }
  154. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  155. #define err_puts(e, s) i915_error_puts(e, s)
  156. static void print_error_buffers(struct drm_i915_error_state_buf *m,
  157. const char *name,
  158. struct drm_i915_error_buffer *err,
  159. int count)
  160. {
  161. err_printf(m, " %s [%d]:\n", name, count);
  162. while (count--) {
  163. err_printf(m, " %08x %8u %02x %02x %x %x",
  164. err->gtt_offset,
  165. err->size,
  166. err->read_domains,
  167. err->write_domain,
  168. err->rseqno, err->wseqno);
  169. err_puts(m, pin_flag(err->pinned));
  170. err_puts(m, tiling_flag(err->tiling));
  171. err_puts(m, dirty_flag(err->dirty));
  172. err_puts(m, purgeable_flag(err->purgeable));
  173. err_puts(m, err->userptr ? " userptr" : "");
  174. err_puts(m, err->ring != -1 ? " " : "");
  175. err_puts(m, ring_str(err->ring));
  176. err_puts(m, i915_cache_level_str(m->i915, err->cache_level));
  177. if (err->name)
  178. err_printf(m, " (name: %d)", err->name);
  179. if (err->fence_reg != I915_FENCE_REG_NONE)
  180. err_printf(m, " (fence: %d)", err->fence_reg);
  181. err_puts(m, "\n");
  182. err++;
  183. }
  184. }
  185. static const char *hangcheck_action_to_str(enum intel_ring_hangcheck_action a)
  186. {
  187. switch (a) {
  188. case HANGCHECK_IDLE:
  189. return "idle";
  190. case HANGCHECK_WAIT:
  191. return "wait";
  192. case HANGCHECK_ACTIVE:
  193. return "active";
  194. case HANGCHECK_ACTIVE_LOOP:
  195. return "active (loop)";
  196. case HANGCHECK_KICK:
  197. return "kick";
  198. case HANGCHECK_HUNG:
  199. return "hung";
  200. }
  201. return "unknown";
  202. }
  203. static void i915_ring_error_state(struct drm_i915_error_state_buf *m,
  204. struct drm_device *dev,
  205. struct drm_i915_error_state *error,
  206. int ring_idx)
  207. {
  208. struct drm_i915_error_ring *ring = &error->ring[ring_idx];
  209. if (!ring->valid)
  210. return;
  211. err_printf(m, "%s command stream:\n", ring_str(ring_idx));
  212. err_printf(m, " HEAD: 0x%08x\n", ring->head);
  213. err_printf(m, " TAIL: 0x%08x\n", ring->tail);
  214. err_printf(m, " CTL: 0x%08x\n", ring->ctl);
  215. err_printf(m, " HWS: 0x%08x\n", ring->hws);
  216. err_printf(m, " ACTHD: 0x%08x %08x\n", (u32)(ring->acthd>>32), (u32)ring->acthd);
  217. err_printf(m, " IPEIR: 0x%08x\n", ring->ipeir);
  218. err_printf(m, " IPEHR: 0x%08x\n", ring->ipehr);
  219. err_printf(m, " INSTDONE: 0x%08x\n", ring->instdone);
  220. if (INTEL_INFO(dev)->gen >= 4) {
  221. err_printf(m, " BBADDR: 0x%08x %08x\n", (u32)(ring->bbaddr>>32), (u32)ring->bbaddr);
  222. err_printf(m, " BB_STATE: 0x%08x\n", ring->bbstate);
  223. err_printf(m, " INSTPS: 0x%08x\n", ring->instps);
  224. }
  225. err_printf(m, " INSTPM: 0x%08x\n", ring->instpm);
  226. err_printf(m, " FADDR: 0x%08x %08x\n", upper_32_bits(ring->faddr),
  227. lower_32_bits(ring->faddr));
  228. if (INTEL_INFO(dev)->gen >= 6) {
  229. err_printf(m, " RC PSMI: 0x%08x\n", ring->rc_psmi);
  230. err_printf(m, " FAULT_REG: 0x%08x\n", ring->fault_reg);
  231. err_printf(m, " SYNC_0: 0x%08x [last synced 0x%08x]\n",
  232. ring->semaphore_mboxes[0],
  233. ring->semaphore_seqno[0]);
  234. err_printf(m, " SYNC_1: 0x%08x [last synced 0x%08x]\n",
  235. ring->semaphore_mboxes[1],
  236. ring->semaphore_seqno[1]);
  237. if (HAS_VEBOX(dev)) {
  238. err_printf(m, " SYNC_2: 0x%08x [last synced 0x%08x]\n",
  239. ring->semaphore_mboxes[2],
  240. ring->semaphore_seqno[2]);
  241. }
  242. }
  243. if (USES_PPGTT(dev)) {
  244. err_printf(m, " GFX_MODE: 0x%08x\n", ring->vm_info.gfx_mode);
  245. if (INTEL_INFO(dev)->gen >= 8) {
  246. int i;
  247. for (i = 0; i < 4; i++)
  248. err_printf(m, " PDP%d: 0x%016llx\n",
  249. i, ring->vm_info.pdp[i]);
  250. } else {
  251. err_printf(m, " PP_DIR_BASE: 0x%08x\n",
  252. ring->vm_info.pp_dir_base);
  253. }
  254. }
  255. err_printf(m, " seqno: 0x%08x\n", ring->seqno);
  256. err_printf(m, " waiting: %s\n", yesno(ring->waiting));
  257. err_printf(m, " ring->head: 0x%08x\n", ring->cpu_ring_head);
  258. err_printf(m, " ring->tail: 0x%08x\n", ring->cpu_ring_tail);
  259. err_printf(m, " hangcheck: %s [%d]\n",
  260. hangcheck_action_to_str(ring->hangcheck_action),
  261. ring->hangcheck_score);
  262. }
  263. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...)
  264. {
  265. va_list args;
  266. va_start(args, f);
  267. i915_error_vprintf(e, f, args);
  268. va_end(args);
  269. }
  270. static void print_error_obj(struct drm_i915_error_state_buf *m,
  271. struct drm_i915_error_object *obj)
  272. {
  273. int page, offset, elt;
  274. for (page = offset = 0; page < obj->page_count; page++) {
  275. for (elt = 0; elt < PAGE_SIZE/4; elt++) {
  276. err_printf(m, "%08x : %08x\n", offset,
  277. obj->pages[page][elt]);
  278. offset += 4;
  279. }
  280. }
  281. }
  282. int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
  283. const struct i915_error_state_file_priv *error_priv)
  284. {
  285. struct drm_device *dev = error_priv->dev;
  286. struct drm_i915_private *dev_priv = dev->dev_private;
  287. struct drm_i915_error_state *error = error_priv->error;
  288. struct drm_i915_error_object *obj;
  289. int i, j, offset, elt;
  290. int max_hangcheck_score;
  291. if (!error) {
  292. err_printf(m, "no error state collected\n");
  293. goto out;
  294. }
  295. err_printf(m, "%s\n", error->error_msg);
  296. err_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
  297. error->time.tv_usec);
  298. err_printf(m, "Kernel: " UTS_RELEASE "\n");
  299. max_hangcheck_score = 0;
  300. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  301. if (error->ring[i].hangcheck_score > max_hangcheck_score)
  302. max_hangcheck_score = error->ring[i].hangcheck_score;
  303. }
  304. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  305. if (error->ring[i].hangcheck_score == max_hangcheck_score &&
  306. error->ring[i].pid != -1) {
  307. err_printf(m, "Active process (on ring %s): %s [%d]\n",
  308. ring_str(i),
  309. error->ring[i].comm,
  310. error->ring[i].pid);
  311. }
  312. }
  313. err_printf(m, "Reset count: %u\n", error->reset_count);
  314. err_printf(m, "Suspend count: %u\n", error->suspend_count);
  315. err_printf(m, "PCI ID: 0x%04x\n", dev->pdev->device);
  316. err_printf(m, "EIR: 0x%08x\n", error->eir);
  317. err_printf(m, "IER: 0x%08x\n", error->ier);
  318. if (INTEL_INFO(dev)->gen >= 8) {
  319. for (i = 0; i < 4; i++)
  320. err_printf(m, "GTIER gt %d: 0x%08x\n", i,
  321. error->gtier[i]);
  322. } else if (HAS_PCH_SPLIT(dev) || IS_VALLEYVIEW(dev))
  323. err_printf(m, "GTIER: 0x%08x\n", error->gtier[0]);
  324. err_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
  325. err_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
  326. err_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
  327. err_printf(m, "CCID: 0x%08x\n", error->ccid);
  328. err_printf(m, "Missed interrupts: 0x%08lx\n", dev_priv->gpu_error.missed_irq_rings);
  329. for (i = 0; i < dev_priv->num_fence_regs; i++)
  330. err_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
  331. for (i = 0; i < ARRAY_SIZE(error->extra_instdone); i++)
  332. err_printf(m, " INSTDONE_%d: 0x%08x\n", i,
  333. error->extra_instdone[i]);
  334. if (INTEL_INFO(dev)->gen >= 6) {
  335. err_printf(m, "ERROR: 0x%08x\n", error->error);
  336. err_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
  337. }
  338. if (INTEL_INFO(dev)->gen == 7)
  339. err_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
  340. for (i = 0; i < ARRAY_SIZE(error->ring); i++)
  341. i915_ring_error_state(m, dev, error, i);
  342. for (i = 0; i < error->vm_count; i++) {
  343. err_printf(m, "vm[%d]\n", i);
  344. print_error_buffers(m, "Active",
  345. error->active_bo[i],
  346. error->active_bo_count[i]);
  347. print_error_buffers(m, "Pinned",
  348. error->pinned_bo[i],
  349. error->pinned_bo_count[i]);
  350. }
  351. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  352. obj = error->ring[i].batchbuffer;
  353. if (obj) {
  354. err_puts(m, dev_priv->ring[i].name);
  355. if (error->ring[i].pid != -1)
  356. err_printf(m, " (submitted by %s [%d])",
  357. error->ring[i].comm,
  358. error->ring[i].pid);
  359. err_printf(m, " --- gtt_offset = 0x%08x\n",
  360. obj->gtt_offset);
  361. print_error_obj(m, obj);
  362. }
  363. obj = error->ring[i].wa_batchbuffer;
  364. if (obj) {
  365. err_printf(m, "%s (w/a) --- gtt_offset = 0x%08x\n",
  366. dev_priv->ring[i].name, obj->gtt_offset);
  367. print_error_obj(m, obj);
  368. }
  369. if (error->ring[i].num_requests) {
  370. err_printf(m, "%s --- %d requests\n",
  371. dev_priv->ring[i].name,
  372. error->ring[i].num_requests);
  373. for (j = 0; j < error->ring[i].num_requests; j++) {
  374. err_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
  375. error->ring[i].requests[j].seqno,
  376. error->ring[i].requests[j].jiffies,
  377. error->ring[i].requests[j].tail);
  378. }
  379. }
  380. if ((obj = error->ring[i].ringbuffer)) {
  381. err_printf(m, "%s --- ringbuffer = 0x%08x\n",
  382. dev_priv->ring[i].name,
  383. obj->gtt_offset);
  384. print_error_obj(m, obj);
  385. }
  386. if ((obj = error->ring[i].hws_page)) {
  387. err_printf(m, "%s --- HW Status = 0x%08x\n",
  388. dev_priv->ring[i].name,
  389. obj->gtt_offset);
  390. offset = 0;
  391. for (elt = 0; elt < PAGE_SIZE/16; elt += 4) {
  392. err_printf(m, "[%04x] %08x %08x %08x %08x\n",
  393. offset,
  394. obj->pages[0][elt],
  395. obj->pages[0][elt+1],
  396. obj->pages[0][elt+2],
  397. obj->pages[0][elt+3]);
  398. offset += 16;
  399. }
  400. }
  401. if ((obj = error->ring[i].ctx)) {
  402. err_printf(m, "%s --- HW Context = 0x%08x\n",
  403. dev_priv->ring[i].name,
  404. obj->gtt_offset);
  405. print_error_obj(m, obj);
  406. }
  407. }
  408. if ((obj = error->semaphore_obj)) {
  409. err_printf(m, "Semaphore page = 0x%08x\n", obj->gtt_offset);
  410. for (elt = 0; elt < PAGE_SIZE/16; elt += 4) {
  411. err_printf(m, "[%04x] %08x %08x %08x %08x\n",
  412. elt * 4,
  413. obj->pages[0][elt],
  414. obj->pages[0][elt+1],
  415. obj->pages[0][elt+2],
  416. obj->pages[0][elt+3]);
  417. }
  418. }
  419. if (error->overlay)
  420. intel_overlay_print_error_state(m, error->overlay);
  421. if (error->display)
  422. intel_display_print_error_state(m, dev, error->display);
  423. out:
  424. if (m->bytes == 0 && m->err)
  425. return m->err;
  426. return 0;
  427. }
  428. int i915_error_state_buf_init(struct drm_i915_error_state_buf *ebuf,
  429. struct drm_i915_private *i915,
  430. size_t count, loff_t pos)
  431. {
  432. memset(ebuf, 0, sizeof(*ebuf));
  433. ebuf->i915 = i915;
  434. /* We need to have enough room to store any i915_error_state printf
  435. * so that we can move it to start position.
  436. */
  437. ebuf->size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
  438. ebuf->buf = kmalloc(ebuf->size,
  439. GFP_TEMPORARY | __GFP_NORETRY | __GFP_NOWARN);
  440. if (ebuf->buf == NULL) {
  441. ebuf->size = PAGE_SIZE;
  442. ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
  443. }
  444. if (ebuf->buf == NULL) {
  445. ebuf->size = 128;
  446. ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
  447. }
  448. if (ebuf->buf == NULL)
  449. return -ENOMEM;
  450. ebuf->start = pos;
  451. return 0;
  452. }
  453. static void i915_error_object_free(struct drm_i915_error_object *obj)
  454. {
  455. int page;
  456. if (obj == NULL)
  457. return;
  458. for (page = 0; page < obj->page_count; page++)
  459. kfree(obj->pages[page]);
  460. kfree(obj);
  461. }
  462. static void i915_error_state_free(struct kref *error_ref)
  463. {
  464. struct drm_i915_error_state *error = container_of(error_ref,
  465. typeof(*error), ref);
  466. int i;
  467. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  468. i915_error_object_free(error->ring[i].batchbuffer);
  469. i915_error_object_free(error->ring[i].ringbuffer);
  470. i915_error_object_free(error->ring[i].hws_page);
  471. i915_error_object_free(error->ring[i].ctx);
  472. kfree(error->ring[i].requests);
  473. }
  474. i915_error_object_free(error->semaphore_obj);
  475. for (i = 0; i < error->vm_count; i++)
  476. kfree(error->active_bo[i]);
  477. kfree(error->active_bo);
  478. kfree(error->active_bo_count);
  479. kfree(error->pinned_bo);
  480. kfree(error->pinned_bo_count);
  481. kfree(error->overlay);
  482. kfree(error->display);
  483. kfree(error);
  484. }
  485. static struct drm_i915_error_object *
  486. i915_error_object_create(struct drm_i915_private *dev_priv,
  487. struct drm_i915_gem_object *src,
  488. struct i915_address_space *vm)
  489. {
  490. struct drm_i915_error_object *dst;
  491. struct i915_vma *vma = NULL;
  492. int num_pages;
  493. bool use_ggtt;
  494. int i = 0;
  495. u32 reloc_offset;
  496. if (src == NULL || src->pages == NULL)
  497. return NULL;
  498. num_pages = src->base.size >> PAGE_SHIFT;
  499. dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *), GFP_ATOMIC);
  500. if (dst == NULL)
  501. return NULL;
  502. if (i915_gem_obj_bound(src, vm))
  503. dst->gtt_offset = i915_gem_obj_offset(src, vm);
  504. else
  505. dst->gtt_offset = -1;
  506. reloc_offset = dst->gtt_offset;
  507. if (i915_is_ggtt(vm))
  508. vma = i915_gem_obj_to_ggtt(src);
  509. use_ggtt = (src->cache_level == I915_CACHE_NONE &&
  510. vma && (vma->bound & GLOBAL_BIND) &&
  511. reloc_offset + num_pages * PAGE_SIZE <= dev_priv->gtt.mappable_end);
  512. /* Cannot access stolen address directly, try to use the aperture */
  513. if (src->stolen) {
  514. use_ggtt = true;
  515. if (!(vma && vma->bound & GLOBAL_BIND))
  516. goto unwind;
  517. reloc_offset = i915_gem_obj_ggtt_offset(src);
  518. if (reloc_offset + num_pages * PAGE_SIZE > dev_priv->gtt.mappable_end)
  519. goto unwind;
  520. }
  521. /* Cannot access snooped pages through the aperture */
  522. if (use_ggtt && src->cache_level != I915_CACHE_NONE && !HAS_LLC(dev_priv->dev))
  523. goto unwind;
  524. dst->page_count = num_pages;
  525. while (num_pages--) {
  526. unsigned long flags;
  527. void *d;
  528. d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
  529. if (d == NULL)
  530. goto unwind;
  531. local_irq_save(flags);
  532. if (use_ggtt) {
  533. void __iomem *s;
  534. /* Simply ignore tiling or any overlapping fence.
  535. * It's part of the error state, and this hopefully
  536. * captures what the GPU read.
  537. */
  538. s = io_mapping_map_atomic_wc(dev_priv->gtt.mappable,
  539. reloc_offset);
  540. memcpy_fromio(d, s, PAGE_SIZE);
  541. io_mapping_unmap_atomic(s);
  542. } else {
  543. struct page *page;
  544. void *s;
  545. page = i915_gem_object_get_page(src, i);
  546. drm_clflush_pages(&page, 1);
  547. s = kmap_atomic(page);
  548. memcpy(d, s, PAGE_SIZE);
  549. kunmap_atomic(s);
  550. drm_clflush_pages(&page, 1);
  551. }
  552. local_irq_restore(flags);
  553. dst->pages[i++] = d;
  554. reloc_offset += PAGE_SIZE;
  555. }
  556. return dst;
  557. unwind:
  558. while (i--)
  559. kfree(dst->pages[i]);
  560. kfree(dst);
  561. return NULL;
  562. }
  563. #define i915_error_ggtt_object_create(dev_priv, src) \
  564. i915_error_object_create((dev_priv), (src), &(dev_priv)->gtt.base)
  565. static void capture_bo(struct drm_i915_error_buffer *err,
  566. struct i915_vma *vma)
  567. {
  568. struct drm_i915_gem_object *obj = vma->obj;
  569. err->size = obj->base.size;
  570. err->name = obj->base.name;
  571. err->rseqno = i915_gem_request_get_seqno(obj->last_read_req);
  572. err->wseqno = i915_gem_request_get_seqno(obj->last_write_req);
  573. err->gtt_offset = vma->node.start;
  574. err->read_domains = obj->base.read_domains;
  575. err->write_domain = obj->base.write_domain;
  576. err->fence_reg = obj->fence_reg;
  577. err->pinned = 0;
  578. if (i915_gem_obj_is_pinned(obj))
  579. err->pinned = 1;
  580. err->tiling = obj->tiling_mode;
  581. err->dirty = obj->dirty;
  582. err->purgeable = obj->madv != I915_MADV_WILLNEED;
  583. err->userptr = obj->userptr.mm != NULL;
  584. err->ring = obj->last_read_req ?
  585. i915_gem_request_get_ring(obj->last_read_req)->id : -1;
  586. err->cache_level = obj->cache_level;
  587. }
  588. static u32 capture_active_bo(struct drm_i915_error_buffer *err,
  589. int count, struct list_head *head)
  590. {
  591. struct i915_vma *vma;
  592. int i = 0;
  593. list_for_each_entry(vma, head, mm_list) {
  594. capture_bo(err++, vma);
  595. if (++i == count)
  596. break;
  597. }
  598. return i;
  599. }
  600. static u32 capture_pinned_bo(struct drm_i915_error_buffer *err,
  601. int count, struct list_head *head,
  602. struct i915_address_space *vm)
  603. {
  604. struct drm_i915_gem_object *obj;
  605. struct drm_i915_error_buffer * const first = err;
  606. struct drm_i915_error_buffer * const last = err + count;
  607. list_for_each_entry(obj, head, global_list) {
  608. struct i915_vma *vma;
  609. if (err == last)
  610. break;
  611. list_for_each_entry(vma, &obj->vma_list, vma_link)
  612. if (vma->vm == vm && vma->pin_count > 0)
  613. capture_bo(err++, vma);
  614. }
  615. return err - first;
  616. }
  617. /* Generate a semi-unique error code. The code is not meant to have meaning, The
  618. * code's only purpose is to try to prevent false duplicated bug reports by
  619. * grossly estimating a GPU error state.
  620. *
  621. * TODO Ideally, hashing the batchbuffer would be a very nice way to determine
  622. * the hang if we could strip the GTT offset information from it.
  623. *
  624. * It's only a small step better than a random number in its current form.
  625. */
  626. static uint32_t i915_error_generate_code(struct drm_i915_private *dev_priv,
  627. struct drm_i915_error_state *error,
  628. int *ring_id)
  629. {
  630. uint32_t error_code = 0;
  631. int i;
  632. /* IPEHR would be an ideal way to detect errors, as it's the gross
  633. * measure of "the command that hung." However, has some very common
  634. * synchronization commands which almost always appear in the case
  635. * strictly a client bug. Use instdone to differentiate those some.
  636. */
  637. for (i = 0; i < I915_NUM_RINGS; i++) {
  638. if (error->ring[i].hangcheck_action == HANGCHECK_HUNG) {
  639. if (ring_id)
  640. *ring_id = i;
  641. return error->ring[i].ipehr ^ error->ring[i].instdone;
  642. }
  643. }
  644. return error_code;
  645. }
  646. static void i915_gem_record_fences(struct drm_device *dev,
  647. struct drm_i915_error_state *error)
  648. {
  649. struct drm_i915_private *dev_priv = dev->dev_private;
  650. int i;
  651. if (IS_GEN3(dev) || IS_GEN2(dev)) {
  652. for (i = 0; i < 8; i++)
  653. error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
  654. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  655. for (i = 0; i < 8; i++)
  656. error->fence[i+8] = I915_READ(FENCE_REG_945_8 +
  657. (i * 4));
  658. } else if (IS_GEN5(dev) || IS_GEN4(dev))
  659. for (i = 0; i < 16; i++)
  660. error->fence[i] = I915_READ64(FENCE_REG_965_0 +
  661. (i * 8));
  662. else if (INTEL_INFO(dev)->gen >= 6)
  663. for (i = 0; i < dev_priv->num_fence_regs; i++)
  664. error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 +
  665. (i * 8));
  666. }
  667. static void gen8_record_semaphore_state(struct drm_i915_private *dev_priv,
  668. struct drm_i915_error_state *error,
  669. struct intel_engine_cs *ring,
  670. struct drm_i915_error_ring *ering)
  671. {
  672. struct intel_engine_cs *to;
  673. int i;
  674. if (!i915_semaphore_is_enabled(dev_priv->dev))
  675. return;
  676. if (!error->semaphore_obj)
  677. error->semaphore_obj =
  678. i915_error_ggtt_object_create(dev_priv,
  679. dev_priv->semaphore_obj);
  680. for_each_ring(to, dev_priv, i) {
  681. int idx;
  682. u16 signal_offset;
  683. u32 *tmp;
  684. if (ring == to)
  685. continue;
  686. signal_offset = (GEN8_SIGNAL_OFFSET(ring, i) & (PAGE_SIZE - 1))
  687. / 4;
  688. tmp = error->semaphore_obj->pages[0];
  689. idx = intel_ring_sync_index(ring, to);
  690. ering->semaphore_mboxes[idx] = tmp[signal_offset];
  691. ering->semaphore_seqno[idx] = ring->semaphore.sync_seqno[idx];
  692. }
  693. }
  694. static void gen6_record_semaphore_state(struct drm_i915_private *dev_priv,
  695. struct intel_engine_cs *ring,
  696. struct drm_i915_error_ring *ering)
  697. {
  698. ering->semaphore_mboxes[0] = I915_READ(RING_SYNC_0(ring->mmio_base));
  699. ering->semaphore_mboxes[1] = I915_READ(RING_SYNC_1(ring->mmio_base));
  700. ering->semaphore_seqno[0] = ring->semaphore.sync_seqno[0];
  701. ering->semaphore_seqno[1] = ring->semaphore.sync_seqno[1];
  702. if (HAS_VEBOX(dev_priv->dev)) {
  703. ering->semaphore_mboxes[2] =
  704. I915_READ(RING_SYNC_2(ring->mmio_base));
  705. ering->semaphore_seqno[2] = ring->semaphore.sync_seqno[2];
  706. }
  707. }
  708. static void i915_record_ring_state(struct drm_device *dev,
  709. struct drm_i915_error_state *error,
  710. struct intel_engine_cs *ring,
  711. struct drm_i915_error_ring *ering)
  712. {
  713. struct drm_i915_private *dev_priv = dev->dev_private;
  714. if (INTEL_INFO(dev)->gen >= 6) {
  715. ering->rc_psmi = I915_READ(ring->mmio_base + 0x50);
  716. ering->fault_reg = I915_READ(RING_FAULT_REG(ring));
  717. if (INTEL_INFO(dev)->gen >= 8)
  718. gen8_record_semaphore_state(dev_priv, error, ring, ering);
  719. else
  720. gen6_record_semaphore_state(dev_priv, ring, ering);
  721. }
  722. if (INTEL_INFO(dev)->gen >= 4) {
  723. ering->faddr = I915_READ(RING_DMA_FADD(ring->mmio_base));
  724. ering->ipeir = I915_READ(RING_IPEIR(ring->mmio_base));
  725. ering->ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  726. ering->instdone = I915_READ(RING_INSTDONE(ring->mmio_base));
  727. ering->instps = I915_READ(RING_INSTPS(ring->mmio_base));
  728. ering->bbaddr = I915_READ(RING_BBADDR(ring->mmio_base));
  729. if (INTEL_INFO(dev)->gen >= 8) {
  730. ering->faddr |= (u64) I915_READ(RING_DMA_FADD_UDW(ring->mmio_base)) << 32;
  731. ering->bbaddr |= (u64) I915_READ(RING_BBADDR_UDW(ring->mmio_base)) << 32;
  732. }
  733. ering->bbstate = I915_READ(RING_BBSTATE(ring->mmio_base));
  734. } else {
  735. ering->faddr = I915_READ(DMA_FADD_I8XX);
  736. ering->ipeir = I915_READ(IPEIR);
  737. ering->ipehr = I915_READ(IPEHR);
  738. ering->instdone = I915_READ(INSTDONE);
  739. }
  740. ering->waiting = waitqueue_active(&ring->irq_queue);
  741. ering->instpm = I915_READ(RING_INSTPM(ring->mmio_base));
  742. ering->seqno = ring->get_seqno(ring, false);
  743. ering->acthd = intel_ring_get_active_head(ring);
  744. ering->head = I915_READ_HEAD(ring);
  745. ering->tail = I915_READ_TAIL(ring);
  746. ering->ctl = I915_READ_CTL(ring);
  747. if (I915_NEED_GFX_HWS(dev)) {
  748. int mmio;
  749. if (IS_GEN7(dev)) {
  750. switch (ring->id) {
  751. default:
  752. case RCS:
  753. mmio = RENDER_HWS_PGA_GEN7;
  754. break;
  755. case BCS:
  756. mmio = BLT_HWS_PGA_GEN7;
  757. break;
  758. case VCS:
  759. mmio = BSD_HWS_PGA_GEN7;
  760. break;
  761. case VECS:
  762. mmio = VEBOX_HWS_PGA_GEN7;
  763. break;
  764. }
  765. } else if (IS_GEN6(ring->dev)) {
  766. mmio = RING_HWS_PGA_GEN6(ring->mmio_base);
  767. } else {
  768. /* XXX: gen8 returns to sanity */
  769. mmio = RING_HWS_PGA(ring->mmio_base);
  770. }
  771. ering->hws = I915_READ(mmio);
  772. }
  773. ering->hangcheck_score = ring->hangcheck.score;
  774. ering->hangcheck_action = ring->hangcheck.action;
  775. if (USES_PPGTT(dev)) {
  776. int i;
  777. ering->vm_info.gfx_mode = I915_READ(RING_MODE_GEN7(ring));
  778. if (IS_GEN6(dev))
  779. ering->vm_info.pp_dir_base =
  780. I915_READ(RING_PP_DIR_BASE_READ(ring));
  781. else if (IS_GEN7(dev))
  782. ering->vm_info.pp_dir_base =
  783. I915_READ(RING_PP_DIR_BASE(ring));
  784. else if (INTEL_INFO(dev)->gen >= 8)
  785. for (i = 0; i < 4; i++) {
  786. ering->vm_info.pdp[i] =
  787. I915_READ(GEN8_RING_PDP_UDW(ring, i));
  788. ering->vm_info.pdp[i] <<= 32;
  789. ering->vm_info.pdp[i] |=
  790. I915_READ(GEN8_RING_PDP_LDW(ring, i));
  791. }
  792. }
  793. }
  794. static void i915_gem_record_active_context(struct intel_engine_cs *ring,
  795. struct drm_i915_error_state *error,
  796. struct drm_i915_error_ring *ering)
  797. {
  798. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  799. struct drm_i915_gem_object *obj;
  800. /* Currently render ring is the only HW context user */
  801. if (ring->id != RCS || !error->ccid)
  802. return;
  803. list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
  804. if (!i915_gem_obj_ggtt_bound(obj))
  805. continue;
  806. if ((error->ccid & PAGE_MASK) == i915_gem_obj_ggtt_offset(obj)) {
  807. ering->ctx = i915_error_ggtt_object_create(dev_priv, obj);
  808. break;
  809. }
  810. }
  811. }
  812. static void i915_gem_record_rings(struct drm_device *dev,
  813. struct drm_i915_error_state *error)
  814. {
  815. struct drm_i915_private *dev_priv = dev->dev_private;
  816. struct drm_i915_gem_request *request;
  817. int i, count;
  818. for (i = 0; i < I915_NUM_RINGS; i++) {
  819. struct intel_engine_cs *ring = &dev_priv->ring[i];
  820. struct intel_ringbuffer *rbuf;
  821. error->ring[i].pid = -1;
  822. if (ring->dev == NULL)
  823. continue;
  824. error->ring[i].valid = true;
  825. i915_record_ring_state(dev, error, ring, &error->ring[i]);
  826. request = i915_gem_find_active_request(ring);
  827. if (request) {
  828. struct i915_address_space *vm;
  829. vm = request->ctx && request->ctx->ppgtt ?
  830. &request->ctx->ppgtt->base :
  831. &dev_priv->gtt.base;
  832. /* We need to copy these to an anonymous buffer
  833. * as the simplest method to avoid being overwritten
  834. * by userspace.
  835. */
  836. error->ring[i].batchbuffer =
  837. i915_error_object_create(dev_priv,
  838. request->batch_obj,
  839. vm);
  840. if (HAS_BROKEN_CS_TLB(dev_priv->dev))
  841. error->ring[i].wa_batchbuffer =
  842. i915_error_ggtt_object_create(dev_priv,
  843. ring->scratch.obj);
  844. if (request->pid) {
  845. struct task_struct *task;
  846. rcu_read_lock();
  847. task = pid_task(request->pid, PIDTYPE_PID);
  848. if (task) {
  849. strcpy(error->ring[i].comm, task->comm);
  850. error->ring[i].pid = task->pid;
  851. }
  852. rcu_read_unlock();
  853. }
  854. }
  855. if (i915.enable_execlists) {
  856. /* TODO: This is only a small fix to keep basic error
  857. * capture working, but we need to add more information
  858. * for it to be useful (e.g. dump the context being
  859. * executed).
  860. */
  861. if (request)
  862. rbuf = request->ctx->engine[ring->id].ringbuf;
  863. else
  864. rbuf = ring->default_context->engine[ring->id].ringbuf;
  865. } else
  866. rbuf = ring->buffer;
  867. error->ring[i].cpu_ring_head = rbuf->head;
  868. error->ring[i].cpu_ring_tail = rbuf->tail;
  869. error->ring[i].ringbuffer =
  870. i915_error_ggtt_object_create(dev_priv, rbuf->obj);
  871. error->ring[i].hws_page =
  872. i915_error_ggtt_object_create(dev_priv, ring->status_page.obj);
  873. i915_gem_record_active_context(ring, error, &error->ring[i]);
  874. count = 0;
  875. list_for_each_entry(request, &ring->request_list, list)
  876. count++;
  877. error->ring[i].num_requests = count;
  878. error->ring[i].requests =
  879. kcalloc(count, sizeof(*error->ring[i].requests),
  880. GFP_ATOMIC);
  881. if (error->ring[i].requests == NULL) {
  882. error->ring[i].num_requests = 0;
  883. continue;
  884. }
  885. count = 0;
  886. list_for_each_entry(request, &ring->request_list, list) {
  887. struct drm_i915_error_request *erq;
  888. erq = &error->ring[i].requests[count++];
  889. erq->seqno = request->seqno;
  890. erq->jiffies = request->emitted_jiffies;
  891. erq->tail = request->postfix;
  892. }
  893. }
  894. }
  895. /* FIXME: Since pin count/bound list is global, we duplicate what we capture per
  896. * VM.
  897. */
  898. static void i915_gem_capture_vm(struct drm_i915_private *dev_priv,
  899. struct drm_i915_error_state *error,
  900. struct i915_address_space *vm,
  901. const int ndx)
  902. {
  903. struct drm_i915_error_buffer *active_bo = NULL, *pinned_bo = NULL;
  904. struct drm_i915_gem_object *obj;
  905. struct i915_vma *vma;
  906. int i;
  907. i = 0;
  908. list_for_each_entry(vma, &vm->active_list, mm_list)
  909. i++;
  910. error->active_bo_count[ndx] = i;
  911. list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
  912. list_for_each_entry(vma, &obj->vma_list, vma_link)
  913. if (vma->vm == vm && vma->pin_count > 0)
  914. i++;
  915. }
  916. error->pinned_bo_count[ndx] = i - error->active_bo_count[ndx];
  917. if (i) {
  918. active_bo = kcalloc(i, sizeof(*active_bo), GFP_ATOMIC);
  919. if (active_bo)
  920. pinned_bo = active_bo + error->active_bo_count[ndx];
  921. }
  922. if (active_bo)
  923. error->active_bo_count[ndx] =
  924. capture_active_bo(active_bo,
  925. error->active_bo_count[ndx],
  926. &vm->active_list);
  927. if (pinned_bo)
  928. error->pinned_bo_count[ndx] =
  929. capture_pinned_bo(pinned_bo,
  930. error->pinned_bo_count[ndx],
  931. &dev_priv->mm.bound_list, vm);
  932. error->active_bo[ndx] = active_bo;
  933. error->pinned_bo[ndx] = pinned_bo;
  934. }
  935. static void i915_gem_capture_buffers(struct drm_i915_private *dev_priv,
  936. struct drm_i915_error_state *error)
  937. {
  938. struct i915_address_space *vm;
  939. int cnt = 0, i = 0;
  940. list_for_each_entry(vm, &dev_priv->vm_list, global_link)
  941. cnt++;
  942. error->active_bo = kcalloc(cnt, sizeof(*error->active_bo), GFP_ATOMIC);
  943. error->pinned_bo = kcalloc(cnt, sizeof(*error->pinned_bo), GFP_ATOMIC);
  944. error->active_bo_count = kcalloc(cnt, sizeof(*error->active_bo_count),
  945. GFP_ATOMIC);
  946. error->pinned_bo_count = kcalloc(cnt, sizeof(*error->pinned_bo_count),
  947. GFP_ATOMIC);
  948. if (error->active_bo == NULL ||
  949. error->pinned_bo == NULL ||
  950. error->active_bo_count == NULL ||
  951. error->pinned_bo_count == NULL) {
  952. kfree(error->active_bo);
  953. kfree(error->active_bo_count);
  954. kfree(error->pinned_bo);
  955. kfree(error->pinned_bo_count);
  956. error->active_bo = NULL;
  957. error->active_bo_count = NULL;
  958. error->pinned_bo = NULL;
  959. error->pinned_bo_count = NULL;
  960. } else {
  961. list_for_each_entry(vm, &dev_priv->vm_list, global_link)
  962. i915_gem_capture_vm(dev_priv, error, vm, i++);
  963. error->vm_count = cnt;
  964. }
  965. }
  966. /* Capture all registers which don't fit into another category. */
  967. static void i915_capture_reg_state(struct drm_i915_private *dev_priv,
  968. struct drm_i915_error_state *error)
  969. {
  970. struct drm_device *dev = dev_priv->dev;
  971. int i;
  972. /* General organization
  973. * 1. Registers specific to a single generation
  974. * 2. Registers which belong to multiple generations
  975. * 3. Feature specific registers.
  976. * 4. Everything else
  977. * Please try to follow the order.
  978. */
  979. /* 1: Registers specific to a single generation */
  980. if (IS_VALLEYVIEW(dev)) {
  981. error->gtier[0] = I915_READ(GTIER);
  982. error->ier = I915_READ(VLV_IER);
  983. error->forcewake = I915_READ(FORCEWAKE_VLV);
  984. }
  985. if (IS_GEN7(dev))
  986. error->err_int = I915_READ(GEN7_ERR_INT);
  987. if (IS_GEN6(dev)) {
  988. error->forcewake = I915_READ(FORCEWAKE);
  989. error->gab_ctl = I915_READ(GAB_CTL);
  990. error->gfx_mode = I915_READ(GFX_MODE);
  991. }
  992. /* 2: Registers which belong to multiple generations */
  993. if (INTEL_INFO(dev)->gen >= 7)
  994. error->forcewake = I915_READ(FORCEWAKE_MT);
  995. if (INTEL_INFO(dev)->gen >= 6) {
  996. error->derrmr = I915_READ(DERRMR);
  997. error->error = I915_READ(ERROR_GEN6);
  998. error->done_reg = I915_READ(DONE_REG);
  999. }
  1000. /* 3: Feature specific registers */
  1001. if (IS_GEN6(dev) || IS_GEN7(dev)) {
  1002. error->gam_ecochk = I915_READ(GAM_ECOCHK);
  1003. error->gac_eco = I915_READ(GAC_ECO_BITS);
  1004. }
  1005. /* 4: Everything else */
  1006. if (HAS_HW_CONTEXTS(dev))
  1007. error->ccid = I915_READ(CCID);
  1008. if (INTEL_INFO(dev)->gen >= 8) {
  1009. error->ier = I915_READ(GEN8_DE_MISC_IER);
  1010. for (i = 0; i < 4; i++)
  1011. error->gtier[i] = I915_READ(GEN8_GT_IER(i));
  1012. } else if (HAS_PCH_SPLIT(dev)) {
  1013. error->ier = I915_READ(DEIER);
  1014. error->gtier[0] = I915_READ(GTIER);
  1015. } else if (IS_GEN2(dev)) {
  1016. error->ier = I915_READ16(IER);
  1017. } else if (!IS_VALLEYVIEW(dev)) {
  1018. error->ier = I915_READ(IER);
  1019. }
  1020. error->eir = I915_READ(EIR);
  1021. error->pgtbl_er = I915_READ(PGTBL_ER);
  1022. i915_get_extra_instdone(dev, error->extra_instdone);
  1023. }
  1024. static void i915_error_capture_msg(struct drm_device *dev,
  1025. struct drm_i915_error_state *error,
  1026. bool wedged,
  1027. const char *error_msg)
  1028. {
  1029. struct drm_i915_private *dev_priv = dev->dev_private;
  1030. u32 ecode;
  1031. int ring_id = -1, len;
  1032. ecode = i915_error_generate_code(dev_priv, error, &ring_id);
  1033. len = scnprintf(error->error_msg, sizeof(error->error_msg),
  1034. "GPU HANG: ecode %d:%d:0x%08x",
  1035. INTEL_INFO(dev)->gen, ring_id, ecode);
  1036. if (ring_id != -1 && error->ring[ring_id].pid != -1)
  1037. len += scnprintf(error->error_msg + len,
  1038. sizeof(error->error_msg) - len,
  1039. ", in %s [%d]",
  1040. error->ring[ring_id].comm,
  1041. error->ring[ring_id].pid);
  1042. scnprintf(error->error_msg + len, sizeof(error->error_msg) - len,
  1043. ", reason: %s, action: %s",
  1044. error_msg,
  1045. wedged ? "reset" : "continue");
  1046. }
  1047. static void i915_capture_gen_state(struct drm_i915_private *dev_priv,
  1048. struct drm_i915_error_state *error)
  1049. {
  1050. error->reset_count = i915_reset_count(&dev_priv->gpu_error);
  1051. error->suspend_count = dev_priv->suspend_count;
  1052. }
  1053. /**
  1054. * i915_capture_error_state - capture an error record for later analysis
  1055. * @dev: drm device
  1056. *
  1057. * Should be called when an error is detected (either a hang or an error
  1058. * interrupt) to capture error state from the time of the error. Fills
  1059. * out a structure which becomes available in debugfs for user level tools
  1060. * to pick up.
  1061. */
  1062. void i915_capture_error_state(struct drm_device *dev, bool wedged,
  1063. const char *error_msg)
  1064. {
  1065. static bool warned;
  1066. struct drm_i915_private *dev_priv = dev->dev_private;
  1067. struct drm_i915_error_state *error;
  1068. unsigned long flags;
  1069. /* Account for pipe specific data like PIPE*STAT */
  1070. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  1071. if (!error) {
  1072. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  1073. return;
  1074. }
  1075. kref_init(&error->ref);
  1076. i915_capture_gen_state(dev_priv, error);
  1077. i915_capture_reg_state(dev_priv, error);
  1078. i915_gem_capture_buffers(dev_priv, error);
  1079. i915_gem_record_fences(dev, error);
  1080. i915_gem_record_rings(dev, error);
  1081. do_gettimeofday(&error->time);
  1082. error->overlay = intel_overlay_capture_error_state(dev);
  1083. error->display = intel_display_capture_error_state(dev);
  1084. i915_error_capture_msg(dev, error, wedged, error_msg);
  1085. DRM_INFO("%s\n", error->error_msg);
  1086. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  1087. if (dev_priv->gpu_error.first_error == NULL) {
  1088. dev_priv->gpu_error.first_error = error;
  1089. error = NULL;
  1090. }
  1091. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  1092. if (error) {
  1093. i915_error_state_free(&error->ref);
  1094. return;
  1095. }
  1096. if (!warned) {
  1097. DRM_INFO("GPU hangs can indicate a bug anywhere in the entire gfx stack, including userspace.\n");
  1098. DRM_INFO("Please file a _new_ bug report on bugs.freedesktop.org against DRI -> DRM/Intel\n");
  1099. DRM_INFO("drm/i915 developers can then reassign to the right component if it's not a kernel issue.\n");
  1100. DRM_INFO("The gpu crash dump is required to analyze gpu hangs, so please always attach it.\n");
  1101. DRM_INFO("GPU crash dump saved to /sys/class/drm/card%d/error\n", dev->primary->index);
  1102. warned = true;
  1103. }
  1104. }
  1105. void i915_error_state_get(struct drm_device *dev,
  1106. struct i915_error_state_file_priv *error_priv)
  1107. {
  1108. struct drm_i915_private *dev_priv = dev->dev_private;
  1109. spin_lock_irq(&dev_priv->gpu_error.lock);
  1110. error_priv->error = dev_priv->gpu_error.first_error;
  1111. if (error_priv->error)
  1112. kref_get(&error_priv->error->ref);
  1113. spin_unlock_irq(&dev_priv->gpu_error.lock);
  1114. }
  1115. void i915_error_state_put(struct i915_error_state_file_priv *error_priv)
  1116. {
  1117. if (error_priv->error)
  1118. kref_put(&error_priv->error->ref, i915_error_state_free);
  1119. }
  1120. void i915_destroy_error_state(struct drm_device *dev)
  1121. {
  1122. struct drm_i915_private *dev_priv = dev->dev_private;
  1123. struct drm_i915_error_state *error;
  1124. spin_lock_irq(&dev_priv->gpu_error.lock);
  1125. error = dev_priv->gpu_error.first_error;
  1126. dev_priv->gpu_error.first_error = NULL;
  1127. spin_unlock_irq(&dev_priv->gpu_error.lock);
  1128. if (error)
  1129. kref_put(&error->ref, i915_error_state_free);
  1130. }
  1131. const char *i915_cache_level_str(struct drm_i915_private *i915, int type)
  1132. {
  1133. switch (type) {
  1134. case I915_CACHE_NONE: return " uncached";
  1135. case I915_CACHE_LLC: return HAS_LLC(i915) ? " LLC" : " snooped";
  1136. case I915_CACHE_L3_LLC: return " L3+LLC";
  1137. case I915_CACHE_WT: return " WT";
  1138. default: return "";
  1139. }
  1140. }
  1141. /* NB: please notice the memset */
  1142. void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone)
  1143. {
  1144. struct drm_i915_private *dev_priv = dev->dev_private;
  1145. memset(instdone, 0, sizeof(*instdone) * I915_NUM_INSTDONE_REG);
  1146. if (IS_GEN2(dev) || IS_GEN3(dev))
  1147. instdone[0] = I915_READ(INSTDONE);
  1148. else if (IS_GEN4(dev) || IS_GEN5(dev) || IS_GEN6(dev)) {
  1149. instdone[0] = I915_READ(INSTDONE_I965);
  1150. instdone[1] = I915_READ(INSTDONE1);
  1151. } else if (INTEL_INFO(dev)->gen >= 7) {
  1152. instdone[0] = I915_READ(GEN7_INSTDONE_1);
  1153. instdone[1] = I915_READ(GEN7_SC_INSTDONE);
  1154. instdone[2] = I915_READ(GEN7_SAMPLER_INSTDONE);
  1155. instdone[3] = I915_READ(GEN7_ROW_INSTDONE);
  1156. }
  1157. }