i915_gpu_error.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  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(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_KICK:
  195. return "kick";
  196. case HANGCHECK_HUNG:
  197. return "hung";
  198. }
  199. return "unknown";
  200. }
  201. static void i915_ring_error_state(struct drm_i915_error_state_buf *m,
  202. struct drm_device *dev,
  203. struct drm_i915_error_ring *ring)
  204. {
  205. if (!ring->valid)
  206. return;
  207. err_printf(m, " HEAD: 0x%08x\n", ring->head);
  208. err_printf(m, " TAIL: 0x%08x\n", ring->tail);
  209. err_printf(m, " CTL: 0x%08x\n", ring->ctl);
  210. err_printf(m, " HWS: 0x%08x\n", ring->hws);
  211. err_printf(m, " ACTHD: 0x%08x %08x\n", (u32)(ring->acthd>>32), (u32)ring->acthd);
  212. err_printf(m, " IPEIR: 0x%08x\n", ring->ipeir);
  213. err_printf(m, " IPEHR: 0x%08x\n", ring->ipehr);
  214. err_printf(m, " INSTDONE: 0x%08x\n", ring->instdone);
  215. if (INTEL_INFO(dev)->gen >= 4) {
  216. err_printf(m, " BBADDR: 0x%08x %08x\n", (u32)(ring->bbaddr>>32), (u32)ring->bbaddr);
  217. err_printf(m, " BB_STATE: 0x%08x\n", ring->bbstate);
  218. err_printf(m, " INSTPS: 0x%08x\n", ring->instps);
  219. }
  220. err_printf(m, " INSTPM: 0x%08x\n", ring->instpm);
  221. err_printf(m, " FADDR: 0x%08x %08x\n", upper_32_bits(ring->faddr),
  222. lower_32_bits(ring->faddr));
  223. if (INTEL_INFO(dev)->gen >= 6) {
  224. err_printf(m, " RC PSMI: 0x%08x\n", ring->rc_psmi);
  225. err_printf(m, " FAULT_REG: 0x%08x\n", ring->fault_reg);
  226. err_printf(m, " SYNC_0: 0x%08x [last synced 0x%08x]\n",
  227. ring->semaphore_mboxes[0],
  228. ring->semaphore_seqno[0]);
  229. err_printf(m, " SYNC_1: 0x%08x [last synced 0x%08x]\n",
  230. ring->semaphore_mboxes[1],
  231. ring->semaphore_seqno[1]);
  232. if (HAS_VEBOX(dev)) {
  233. err_printf(m, " SYNC_2: 0x%08x [last synced 0x%08x]\n",
  234. ring->semaphore_mboxes[2],
  235. ring->semaphore_seqno[2]);
  236. }
  237. }
  238. if (USES_PPGTT(dev)) {
  239. err_printf(m, " GFX_MODE: 0x%08x\n", ring->vm_info.gfx_mode);
  240. if (INTEL_INFO(dev)->gen >= 8) {
  241. int i;
  242. for (i = 0; i < 4; i++)
  243. err_printf(m, " PDP%d: 0x%016llx\n",
  244. i, ring->vm_info.pdp[i]);
  245. } else {
  246. err_printf(m, " PP_DIR_BASE: 0x%08x\n",
  247. ring->vm_info.pp_dir_base);
  248. }
  249. }
  250. err_printf(m, " seqno: 0x%08x\n", ring->seqno);
  251. err_printf(m, " waiting: %s\n", yesno(ring->waiting));
  252. err_printf(m, " ring->head: 0x%08x\n", ring->cpu_ring_head);
  253. err_printf(m, " ring->tail: 0x%08x\n", ring->cpu_ring_tail);
  254. err_printf(m, " hangcheck: %s [%d]\n",
  255. hangcheck_action_to_str(ring->hangcheck_action),
  256. ring->hangcheck_score);
  257. }
  258. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...)
  259. {
  260. va_list args;
  261. va_start(args, f);
  262. i915_error_vprintf(e, f, args);
  263. va_end(args);
  264. }
  265. static void print_error_obj(struct drm_i915_error_state_buf *m,
  266. struct drm_i915_error_object *obj)
  267. {
  268. int page, offset, elt;
  269. for (page = offset = 0; page < obj->page_count; page++) {
  270. for (elt = 0; elt < PAGE_SIZE/4; elt++) {
  271. err_printf(m, "%08x : %08x\n", offset,
  272. obj->pages[page][elt]);
  273. offset += 4;
  274. }
  275. }
  276. }
  277. int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
  278. const struct i915_error_state_file_priv *error_priv)
  279. {
  280. struct drm_device *dev = error_priv->dev;
  281. struct drm_i915_private *dev_priv = dev->dev_private;
  282. struct drm_i915_error_state *error = error_priv->error;
  283. int i, j, offset, elt;
  284. int max_hangcheck_score;
  285. if (!error) {
  286. err_printf(m, "no error state collected\n");
  287. goto out;
  288. }
  289. err_printf(m, "%s\n", error->error_msg);
  290. err_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
  291. error->time.tv_usec);
  292. err_printf(m, "Kernel: " UTS_RELEASE "\n");
  293. max_hangcheck_score = 0;
  294. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  295. if (error->ring[i].hangcheck_score > max_hangcheck_score)
  296. max_hangcheck_score = error->ring[i].hangcheck_score;
  297. }
  298. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  299. if (error->ring[i].hangcheck_score == max_hangcheck_score &&
  300. error->ring[i].pid != -1) {
  301. err_printf(m, "Active process (on ring %s): %s [%d]\n",
  302. ring_str(i),
  303. error->ring[i].comm,
  304. error->ring[i].pid);
  305. }
  306. }
  307. err_printf(m, "Reset count: %u\n", error->reset_count);
  308. err_printf(m, "Suspend count: %u\n", error->suspend_count);
  309. err_printf(m, "PCI ID: 0x%04x\n", dev->pdev->device);
  310. err_printf(m, "EIR: 0x%08x\n", error->eir);
  311. err_printf(m, "IER: 0x%08x\n", error->ier);
  312. err_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
  313. err_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
  314. err_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
  315. err_printf(m, "CCID: 0x%08x\n", error->ccid);
  316. err_printf(m, "Missed interrupts: 0x%08lx\n", dev_priv->gpu_error.missed_irq_rings);
  317. for (i = 0; i < dev_priv->num_fence_regs; i++)
  318. err_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
  319. for (i = 0; i < ARRAY_SIZE(error->extra_instdone); i++)
  320. err_printf(m, " INSTDONE_%d: 0x%08x\n", i,
  321. error->extra_instdone[i]);
  322. if (INTEL_INFO(dev)->gen >= 6) {
  323. err_printf(m, "ERROR: 0x%08x\n", error->error);
  324. err_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
  325. }
  326. if (INTEL_INFO(dev)->gen == 7)
  327. err_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
  328. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  329. err_printf(m, "%s command stream:\n", ring_str(i));
  330. i915_ring_error_state(m, dev, &error->ring[i]);
  331. }
  332. if (error->active_bo)
  333. print_error_buffers(m, "Active",
  334. error->active_bo[0],
  335. error->active_bo_count[0]);
  336. if (error->pinned_bo)
  337. print_error_buffers(m, "Pinned",
  338. error->pinned_bo[0],
  339. error->pinned_bo_count[0]);
  340. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  341. struct drm_i915_error_object *obj;
  342. obj = error->ring[i].batchbuffer;
  343. if (obj) {
  344. err_puts(m, dev_priv->ring[i].name);
  345. if (error->ring[i].pid != -1)
  346. err_printf(m, " (submitted by %s [%d])",
  347. error->ring[i].comm,
  348. error->ring[i].pid);
  349. err_printf(m, " --- gtt_offset = 0x%08x\n",
  350. obj->gtt_offset);
  351. print_error_obj(m, obj);
  352. }
  353. obj = error->ring[i].wa_batchbuffer;
  354. if (obj) {
  355. err_printf(m, "%s (w/a) --- gtt_offset = 0x%08x\n",
  356. dev_priv->ring[i].name, obj->gtt_offset);
  357. print_error_obj(m, obj);
  358. }
  359. if (error->ring[i].num_requests) {
  360. err_printf(m, "%s --- %d requests\n",
  361. dev_priv->ring[i].name,
  362. error->ring[i].num_requests);
  363. for (j = 0; j < error->ring[i].num_requests; j++) {
  364. err_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
  365. error->ring[i].requests[j].seqno,
  366. error->ring[i].requests[j].jiffies,
  367. error->ring[i].requests[j].tail);
  368. }
  369. }
  370. if ((obj = error->ring[i].ringbuffer)) {
  371. err_printf(m, "%s --- ringbuffer = 0x%08x\n",
  372. dev_priv->ring[i].name,
  373. obj->gtt_offset);
  374. print_error_obj(m, obj);
  375. }
  376. if ((obj = error->ring[i].hws_page)) {
  377. err_printf(m, "%s --- HW Status = 0x%08x\n",
  378. dev_priv->ring[i].name,
  379. obj->gtt_offset);
  380. offset = 0;
  381. for (elt = 0; elt < PAGE_SIZE/16; elt += 4) {
  382. err_printf(m, "[%04x] %08x %08x %08x %08x\n",
  383. offset,
  384. obj->pages[0][elt],
  385. obj->pages[0][elt+1],
  386. obj->pages[0][elt+2],
  387. obj->pages[0][elt+3]);
  388. offset += 16;
  389. }
  390. }
  391. if ((obj = error->ring[i].ctx)) {
  392. err_printf(m, "%s --- HW Context = 0x%08x\n",
  393. dev_priv->ring[i].name,
  394. obj->gtt_offset);
  395. print_error_obj(m, obj);
  396. }
  397. }
  398. if (error->overlay)
  399. intel_overlay_print_error_state(m, error->overlay);
  400. if (error->display)
  401. intel_display_print_error_state(m, dev, error->display);
  402. out:
  403. if (m->bytes == 0 && m->err)
  404. return m->err;
  405. return 0;
  406. }
  407. int i915_error_state_buf_init(struct drm_i915_error_state_buf *ebuf,
  408. size_t count, loff_t pos)
  409. {
  410. memset(ebuf, 0, sizeof(*ebuf));
  411. /* We need to have enough room to store any i915_error_state printf
  412. * so that we can move it to start position.
  413. */
  414. ebuf->size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
  415. ebuf->buf = kmalloc(ebuf->size,
  416. GFP_TEMPORARY | __GFP_NORETRY | __GFP_NOWARN);
  417. if (ebuf->buf == NULL) {
  418. ebuf->size = PAGE_SIZE;
  419. ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
  420. }
  421. if (ebuf->buf == NULL) {
  422. ebuf->size = 128;
  423. ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
  424. }
  425. if (ebuf->buf == NULL)
  426. return -ENOMEM;
  427. ebuf->start = pos;
  428. return 0;
  429. }
  430. static void i915_error_object_free(struct drm_i915_error_object *obj)
  431. {
  432. int page;
  433. if (obj == NULL)
  434. return;
  435. for (page = 0; page < obj->page_count; page++)
  436. kfree(obj->pages[page]);
  437. kfree(obj);
  438. }
  439. static void i915_error_state_free(struct kref *error_ref)
  440. {
  441. struct drm_i915_error_state *error = container_of(error_ref,
  442. typeof(*error), ref);
  443. int i;
  444. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  445. i915_error_object_free(error->ring[i].batchbuffer);
  446. i915_error_object_free(error->ring[i].ringbuffer);
  447. i915_error_object_free(error->ring[i].hws_page);
  448. i915_error_object_free(error->ring[i].ctx);
  449. kfree(error->ring[i].requests);
  450. }
  451. kfree(error->active_bo);
  452. kfree(error->overlay);
  453. kfree(error->display);
  454. kfree(error);
  455. }
  456. static struct drm_i915_error_object *
  457. i915_error_object_create_sized(struct drm_i915_private *dev_priv,
  458. struct drm_i915_gem_object *src,
  459. struct i915_address_space *vm,
  460. const int num_pages)
  461. {
  462. struct drm_i915_error_object *dst;
  463. int i;
  464. u32 reloc_offset;
  465. if (src == NULL || src->pages == NULL)
  466. return NULL;
  467. dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *), GFP_ATOMIC);
  468. if (dst == NULL)
  469. return NULL;
  470. reloc_offset = dst->gtt_offset = i915_gem_obj_offset(src, vm);
  471. for (i = 0; i < num_pages; i++) {
  472. unsigned long flags;
  473. void *d;
  474. d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
  475. if (d == NULL)
  476. goto unwind;
  477. local_irq_save(flags);
  478. if (src->cache_level == I915_CACHE_NONE &&
  479. reloc_offset < dev_priv->gtt.mappable_end &&
  480. src->has_global_gtt_mapping &&
  481. i915_is_ggtt(vm)) {
  482. void __iomem *s;
  483. /* Simply ignore tiling or any overlapping fence.
  484. * It's part of the error state, and this hopefully
  485. * captures what the GPU read.
  486. */
  487. s = io_mapping_map_atomic_wc(dev_priv->gtt.mappable,
  488. reloc_offset);
  489. memcpy_fromio(d, s, PAGE_SIZE);
  490. io_mapping_unmap_atomic(s);
  491. } else if (src->stolen) {
  492. unsigned long offset;
  493. offset = dev_priv->mm.stolen_base;
  494. offset += src->stolen->start;
  495. offset += i << PAGE_SHIFT;
  496. memcpy_fromio(d, (void __iomem *) offset, PAGE_SIZE);
  497. } else {
  498. struct page *page;
  499. void *s;
  500. page = i915_gem_object_get_page(src, i);
  501. drm_clflush_pages(&page, 1);
  502. s = kmap_atomic(page);
  503. memcpy(d, s, PAGE_SIZE);
  504. kunmap_atomic(s);
  505. drm_clflush_pages(&page, 1);
  506. }
  507. local_irq_restore(flags);
  508. dst->pages[i] = d;
  509. reloc_offset += PAGE_SIZE;
  510. }
  511. dst->page_count = num_pages;
  512. return dst;
  513. unwind:
  514. while (i--)
  515. kfree(dst->pages[i]);
  516. kfree(dst);
  517. return NULL;
  518. }
  519. #define i915_error_object_create(dev_priv, src, vm) \
  520. i915_error_object_create_sized((dev_priv), (src), (vm), \
  521. (src)->base.size>>PAGE_SHIFT)
  522. #define i915_error_ggtt_object_create(dev_priv, src) \
  523. i915_error_object_create_sized((dev_priv), (src), &(dev_priv)->gtt.base, \
  524. (src)->base.size>>PAGE_SHIFT)
  525. static void capture_bo(struct drm_i915_error_buffer *err,
  526. struct drm_i915_gem_object *obj)
  527. {
  528. err->size = obj->base.size;
  529. err->name = obj->base.name;
  530. err->rseqno = obj->last_read_seqno;
  531. err->wseqno = obj->last_write_seqno;
  532. err->gtt_offset = i915_gem_obj_ggtt_offset(obj);
  533. err->read_domains = obj->base.read_domains;
  534. err->write_domain = obj->base.write_domain;
  535. err->fence_reg = obj->fence_reg;
  536. err->pinned = 0;
  537. if (i915_gem_obj_is_pinned(obj))
  538. err->pinned = 1;
  539. if (obj->user_pin_count > 0)
  540. err->pinned = -1;
  541. err->tiling = obj->tiling_mode;
  542. err->dirty = obj->dirty;
  543. err->purgeable = obj->madv != I915_MADV_WILLNEED;
  544. err->userptr = obj->userptr.mm != NULL;
  545. err->ring = obj->ring ? obj->ring->id : -1;
  546. err->cache_level = obj->cache_level;
  547. }
  548. static u32 capture_active_bo(struct drm_i915_error_buffer *err,
  549. int count, struct list_head *head)
  550. {
  551. struct i915_vma *vma;
  552. int i = 0;
  553. list_for_each_entry(vma, head, mm_list) {
  554. capture_bo(err++, vma->obj);
  555. if (++i == count)
  556. break;
  557. }
  558. return i;
  559. }
  560. static u32 capture_pinned_bo(struct drm_i915_error_buffer *err,
  561. int count, struct list_head *head)
  562. {
  563. struct drm_i915_gem_object *obj;
  564. int i = 0;
  565. list_for_each_entry(obj, head, global_list) {
  566. if (!i915_gem_obj_is_pinned(obj))
  567. continue;
  568. capture_bo(err++, obj);
  569. if (++i == count)
  570. break;
  571. }
  572. return i;
  573. }
  574. /* Generate a semi-unique error code. The code is not meant to have meaning, The
  575. * code's only purpose is to try to prevent false duplicated bug reports by
  576. * grossly estimating a GPU error state.
  577. *
  578. * TODO Ideally, hashing the batchbuffer would be a very nice way to determine
  579. * the hang if we could strip the GTT offset information from it.
  580. *
  581. * It's only a small step better than a random number in its current form.
  582. */
  583. static uint32_t i915_error_generate_code(struct drm_i915_private *dev_priv,
  584. struct drm_i915_error_state *error,
  585. int *ring_id)
  586. {
  587. uint32_t error_code = 0;
  588. int i;
  589. /* IPEHR would be an ideal way to detect errors, as it's the gross
  590. * measure of "the command that hung." However, has some very common
  591. * synchronization commands which almost always appear in the case
  592. * strictly a client bug. Use instdone to differentiate those some.
  593. */
  594. for (i = 0; i < I915_NUM_RINGS; i++) {
  595. if (error->ring[i].hangcheck_action == HANGCHECK_HUNG) {
  596. if (ring_id)
  597. *ring_id = i;
  598. return error->ring[i].ipehr ^ error->ring[i].instdone;
  599. }
  600. }
  601. return error_code;
  602. }
  603. static void i915_gem_record_fences(struct drm_device *dev,
  604. struct drm_i915_error_state *error)
  605. {
  606. struct drm_i915_private *dev_priv = dev->dev_private;
  607. int i;
  608. /* Fences */
  609. switch (INTEL_INFO(dev)->gen) {
  610. case 8:
  611. case 7:
  612. case 6:
  613. for (i = 0; i < dev_priv->num_fence_regs; i++)
  614. error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
  615. break;
  616. case 5:
  617. case 4:
  618. for (i = 0; i < 16; i++)
  619. error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
  620. break;
  621. case 3:
  622. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  623. for (i = 0; i < 8; i++)
  624. error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
  625. case 2:
  626. for (i = 0; i < 8; i++)
  627. error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
  628. break;
  629. default:
  630. BUG();
  631. }
  632. }
  633. static void i915_record_ring_state(struct drm_device *dev,
  634. struct intel_engine_cs *ring,
  635. struct drm_i915_error_ring *ering)
  636. {
  637. struct drm_i915_private *dev_priv = dev->dev_private;
  638. if (INTEL_INFO(dev)->gen >= 6) {
  639. ering->rc_psmi = I915_READ(ring->mmio_base + 0x50);
  640. ering->fault_reg = I915_READ(RING_FAULT_REG(ring));
  641. ering->semaphore_mboxes[0]
  642. = I915_READ(RING_SYNC_0(ring->mmio_base));
  643. ering->semaphore_mboxes[1]
  644. = I915_READ(RING_SYNC_1(ring->mmio_base));
  645. ering->semaphore_seqno[0] = ring->semaphore.sync_seqno[0];
  646. ering->semaphore_seqno[1] = ring->semaphore.sync_seqno[1];
  647. }
  648. if (HAS_VEBOX(dev)) {
  649. ering->semaphore_mboxes[2] =
  650. I915_READ(RING_SYNC_2(ring->mmio_base));
  651. ering->semaphore_seqno[2] = ring->semaphore.sync_seqno[2];
  652. }
  653. if (INTEL_INFO(dev)->gen >= 4) {
  654. ering->faddr = I915_READ(RING_DMA_FADD(ring->mmio_base));
  655. ering->ipeir = I915_READ(RING_IPEIR(ring->mmio_base));
  656. ering->ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  657. ering->instdone = I915_READ(RING_INSTDONE(ring->mmio_base));
  658. ering->instps = I915_READ(RING_INSTPS(ring->mmio_base));
  659. ering->bbaddr = I915_READ(RING_BBADDR(ring->mmio_base));
  660. if (INTEL_INFO(dev)->gen >= 8) {
  661. ering->faddr |= (u64) I915_READ(RING_DMA_FADD_UDW(ring->mmio_base)) << 32;
  662. ering->bbaddr |= (u64) I915_READ(RING_BBADDR_UDW(ring->mmio_base)) << 32;
  663. }
  664. ering->bbstate = I915_READ(RING_BBSTATE(ring->mmio_base));
  665. } else {
  666. ering->faddr = I915_READ(DMA_FADD_I8XX);
  667. ering->ipeir = I915_READ(IPEIR);
  668. ering->ipehr = I915_READ(IPEHR);
  669. ering->instdone = I915_READ(INSTDONE);
  670. }
  671. ering->waiting = waitqueue_active(&ring->irq_queue);
  672. ering->instpm = I915_READ(RING_INSTPM(ring->mmio_base));
  673. ering->seqno = ring->get_seqno(ring, false);
  674. ering->acthd = intel_ring_get_active_head(ring);
  675. ering->head = I915_READ_HEAD(ring);
  676. ering->tail = I915_READ_TAIL(ring);
  677. ering->ctl = I915_READ_CTL(ring);
  678. if (I915_NEED_GFX_HWS(dev)) {
  679. int mmio;
  680. if (IS_GEN7(dev)) {
  681. switch (ring->id) {
  682. default:
  683. case RCS:
  684. mmio = RENDER_HWS_PGA_GEN7;
  685. break;
  686. case BCS:
  687. mmio = BLT_HWS_PGA_GEN7;
  688. break;
  689. case VCS:
  690. mmio = BSD_HWS_PGA_GEN7;
  691. break;
  692. case VECS:
  693. mmio = VEBOX_HWS_PGA_GEN7;
  694. break;
  695. }
  696. } else if (IS_GEN6(ring->dev)) {
  697. mmio = RING_HWS_PGA_GEN6(ring->mmio_base);
  698. } else {
  699. /* XXX: gen8 returns to sanity */
  700. mmio = RING_HWS_PGA(ring->mmio_base);
  701. }
  702. ering->hws = I915_READ(mmio);
  703. }
  704. ering->cpu_ring_head = ring->buffer->head;
  705. ering->cpu_ring_tail = ring->buffer->tail;
  706. ering->hangcheck_score = ring->hangcheck.score;
  707. ering->hangcheck_action = ring->hangcheck.action;
  708. if (USES_PPGTT(dev)) {
  709. int i;
  710. ering->vm_info.gfx_mode = I915_READ(RING_MODE_GEN7(ring));
  711. switch (INTEL_INFO(dev)->gen) {
  712. case 8:
  713. for (i = 0; i < 4; i++) {
  714. ering->vm_info.pdp[i] =
  715. I915_READ(GEN8_RING_PDP_UDW(ring, i));
  716. ering->vm_info.pdp[i] <<= 32;
  717. ering->vm_info.pdp[i] |=
  718. I915_READ(GEN8_RING_PDP_LDW(ring, i));
  719. }
  720. break;
  721. case 7:
  722. ering->vm_info.pp_dir_base =
  723. I915_READ(RING_PP_DIR_BASE(ring));
  724. break;
  725. case 6:
  726. ering->vm_info.pp_dir_base =
  727. I915_READ(RING_PP_DIR_BASE_READ(ring));
  728. break;
  729. }
  730. }
  731. }
  732. static void i915_gem_record_active_context(struct intel_engine_cs *ring,
  733. struct drm_i915_error_state *error,
  734. struct drm_i915_error_ring *ering)
  735. {
  736. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  737. struct drm_i915_gem_object *obj;
  738. /* Currently render ring is the only HW context user */
  739. if (ring->id != RCS || !error->ccid)
  740. return;
  741. list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
  742. if ((error->ccid & PAGE_MASK) == i915_gem_obj_ggtt_offset(obj)) {
  743. ering->ctx = i915_error_ggtt_object_create(dev_priv, obj);
  744. break;
  745. }
  746. }
  747. }
  748. static void i915_gem_record_rings(struct drm_device *dev,
  749. struct drm_i915_error_state *error)
  750. {
  751. struct drm_i915_private *dev_priv = dev->dev_private;
  752. struct drm_i915_gem_request *request;
  753. int i, count;
  754. for (i = 0; i < I915_NUM_RINGS; i++) {
  755. struct intel_engine_cs *ring = &dev_priv->ring[i];
  756. error->ring[i].pid = -1;
  757. if (ring->dev == NULL)
  758. continue;
  759. error->ring[i].valid = true;
  760. i915_record_ring_state(dev, ring, &error->ring[i]);
  761. request = i915_gem_find_active_request(ring);
  762. if (request) {
  763. /* We need to copy these to an anonymous buffer
  764. * as the simplest method to avoid being overwritten
  765. * by userspace.
  766. */
  767. error->ring[i].batchbuffer =
  768. i915_error_object_create(dev_priv,
  769. request->batch_obj,
  770. request->ctx ?
  771. request->ctx->vm :
  772. &dev_priv->gtt.base);
  773. if (HAS_BROKEN_CS_TLB(dev_priv->dev) &&
  774. ring->scratch.obj)
  775. error->ring[i].wa_batchbuffer =
  776. i915_error_ggtt_object_create(dev_priv,
  777. ring->scratch.obj);
  778. if (request->file_priv) {
  779. struct task_struct *task;
  780. rcu_read_lock();
  781. task = pid_task(request->file_priv->file->pid,
  782. PIDTYPE_PID);
  783. if (task) {
  784. strcpy(error->ring[i].comm, task->comm);
  785. error->ring[i].pid = task->pid;
  786. }
  787. rcu_read_unlock();
  788. }
  789. }
  790. error->ring[i].ringbuffer =
  791. i915_error_ggtt_object_create(dev_priv, ring->buffer->obj);
  792. if (ring->status_page.obj)
  793. error->ring[i].hws_page =
  794. i915_error_ggtt_object_create(dev_priv, ring->status_page.obj);
  795. i915_gem_record_active_context(ring, error, &error->ring[i]);
  796. count = 0;
  797. list_for_each_entry(request, &ring->request_list, list)
  798. count++;
  799. error->ring[i].num_requests = count;
  800. error->ring[i].requests =
  801. kcalloc(count, sizeof(*error->ring[i].requests),
  802. GFP_ATOMIC);
  803. if (error->ring[i].requests == NULL) {
  804. error->ring[i].num_requests = 0;
  805. continue;
  806. }
  807. count = 0;
  808. list_for_each_entry(request, &ring->request_list, list) {
  809. struct drm_i915_error_request *erq;
  810. erq = &error->ring[i].requests[count++];
  811. erq->seqno = request->seqno;
  812. erq->jiffies = request->emitted_jiffies;
  813. erq->tail = request->tail;
  814. }
  815. }
  816. }
  817. /* FIXME: Since pin count/bound list is global, we duplicate what we capture per
  818. * VM.
  819. */
  820. static void i915_gem_capture_vm(struct drm_i915_private *dev_priv,
  821. struct drm_i915_error_state *error,
  822. struct i915_address_space *vm,
  823. const int ndx)
  824. {
  825. struct drm_i915_error_buffer *active_bo = NULL, *pinned_bo = NULL;
  826. struct drm_i915_gem_object *obj;
  827. struct i915_vma *vma;
  828. int i;
  829. i = 0;
  830. list_for_each_entry(vma, &vm->active_list, mm_list)
  831. i++;
  832. error->active_bo_count[ndx] = i;
  833. list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
  834. if (i915_gem_obj_is_pinned(obj))
  835. i++;
  836. error->pinned_bo_count[ndx] = i - error->active_bo_count[ndx];
  837. if (i) {
  838. active_bo = kcalloc(i, sizeof(*active_bo), GFP_ATOMIC);
  839. if (active_bo)
  840. pinned_bo = active_bo + error->active_bo_count[ndx];
  841. }
  842. if (active_bo)
  843. error->active_bo_count[ndx] =
  844. capture_active_bo(active_bo,
  845. error->active_bo_count[ndx],
  846. &vm->active_list);
  847. if (pinned_bo)
  848. error->pinned_bo_count[ndx] =
  849. capture_pinned_bo(pinned_bo,
  850. error->pinned_bo_count[ndx],
  851. &dev_priv->mm.bound_list);
  852. error->active_bo[ndx] = active_bo;
  853. error->pinned_bo[ndx] = pinned_bo;
  854. }
  855. static void i915_gem_capture_buffers(struct drm_i915_private *dev_priv,
  856. struct drm_i915_error_state *error)
  857. {
  858. struct i915_address_space *vm;
  859. int cnt = 0, i = 0;
  860. list_for_each_entry(vm, &dev_priv->vm_list, global_link)
  861. cnt++;
  862. error->active_bo = kcalloc(cnt, sizeof(*error->active_bo), GFP_ATOMIC);
  863. error->pinned_bo = kcalloc(cnt, sizeof(*error->pinned_bo), GFP_ATOMIC);
  864. error->active_bo_count = kcalloc(cnt, sizeof(*error->active_bo_count),
  865. GFP_ATOMIC);
  866. error->pinned_bo_count = kcalloc(cnt, sizeof(*error->pinned_bo_count),
  867. GFP_ATOMIC);
  868. list_for_each_entry(vm, &dev_priv->vm_list, global_link)
  869. i915_gem_capture_vm(dev_priv, error, vm, i++);
  870. }
  871. /* Capture all registers which don't fit into another category. */
  872. static void i915_capture_reg_state(struct drm_i915_private *dev_priv,
  873. struct drm_i915_error_state *error)
  874. {
  875. struct drm_device *dev = dev_priv->dev;
  876. /* General organization
  877. * 1. Registers specific to a single generation
  878. * 2. Registers which belong to multiple generations
  879. * 3. Feature specific registers.
  880. * 4. Everything else
  881. * Please try to follow the order.
  882. */
  883. /* 1: Registers specific to a single generation */
  884. if (IS_VALLEYVIEW(dev)) {
  885. error->ier = I915_READ(GTIER) | I915_READ(VLV_IER);
  886. error->forcewake = I915_READ(FORCEWAKE_VLV);
  887. }
  888. if (IS_GEN7(dev))
  889. error->err_int = I915_READ(GEN7_ERR_INT);
  890. if (IS_GEN6(dev)) {
  891. error->forcewake = I915_READ(FORCEWAKE);
  892. error->gab_ctl = I915_READ(GAB_CTL);
  893. error->gfx_mode = I915_READ(GFX_MODE);
  894. }
  895. /* 2: Registers which belong to multiple generations */
  896. if (INTEL_INFO(dev)->gen >= 7)
  897. error->forcewake = I915_READ(FORCEWAKE_MT);
  898. if (INTEL_INFO(dev)->gen >= 6) {
  899. error->derrmr = I915_READ(DERRMR);
  900. error->error = I915_READ(ERROR_GEN6);
  901. error->done_reg = I915_READ(DONE_REG);
  902. }
  903. /* 3: Feature specific registers */
  904. if (IS_GEN6(dev) || IS_GEN7(dev)) {
  905. error->gam_ecochk = I915_READ(GAM_ECOCHK);
  906. error->gac_eco = I915_READ(GAC_ECO_BITS);
  907. }
  908. /* 4: Everything else */
  909. if (HAS_HW_CONTEXTS(dev))
  910. error->ccid = I915_READ(CCID);
  911. if (HAS_PCH_SPLIT(dev))
  912. error->ier = I915_READ(DEIER) | I915_READ(GTIER);
  913. else {
  914. if (IS_GEN2(dev))
  915. error->ier = I915_READ16(IER);
  916. else
  917. error->ier = I915_READ(IER);
  918. }
  919. /* 4: Everything else */
  920. error->eir = I915_READ(EIR);
  921. error->pgtbl_er = I915_READ(PGTBL_ER);
  922. i915_get_extra_instdone(dev, error->extra_instdone);
  923. }
  924. static void i915_error_capture_msg(struct drm_device *dev,
  925. struct drm_i915_error_state *error,
  926. bool wedged,
  927. const char *error_msg)
  928. {
  929. struct drm_i915_private *dev_priv = dev->dev_private;
  930. u32 ecode;
  931. int ring_id = -1, len;
  932. ecode = i915_error_generate_code(dev_priv, error, &ring_id);
  933. len = scnprintf(error->error_msg, sizeof(error->error_msg),
  934. "GPU HANG: ecode %d:0x%08x", ring_id, ecode);
  935. if (ring_id != -1 && error->ring[ring_id].pid != -1)
  936. len += scnprintf(error->error_msg + len,
  937. sizeof(error->error_msg) - len,
  938. ", in %s [%d]",
  939. error->ring[ring_id].comm,
  940. error->ring[ring_id].pid);
  941. scnprintf(error->error_msg + len, sizeof(error->error_msg) - len,
  942. ", reason: %s, action: %s",
  943. error_msg,
  944. wedged ? "reset" : "continue");
  945. }
  946. static void i915_capture_gen_state(struct drm_i915_private *dev_priv,
  947. struct drm_i915_error_state *error)
  948. {
  949. error->reset_count = i915_reset_count(&dev_priv->gpu_error);
  950. error->suspend_count = dev_priv->suspend_count;
  951. }
  952. /**
  953. * i915_capture_error_state - capture an error record for later analysis
  954. * @dev: drm device
  955. *
  956. * Should be called when an error is detected (either a hang or an error
  957. * interrupt) to capture error state from the time of the error. Fills
  958. * out a structure which becomes available in debugfs for user level tools
  959. * to pick up.
  960. */
  961. void i915_capture_error_state(struct drm_device *dev, bool wedged,
  962. const char *error_msg)
  963. {
  964. static bool warned;
  965. struct drm_i915_private *dev_priv = dev->dev_private;
  966. struct drm_i915_error_state *error;
  967. unsigned long flags;
  968. /* Account for pipe specific data like PIPE*STAT */
  969. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  970. if (!error) {
  971. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  972. return;
  973. }
  974. kref_init(&error->ref);
  975. i915_capture_gen_state(dev_priv, error);
  976. i915_capture_reg_state(dev_priv, error);
  977. i915_gem_capture_buffers(dev_priv, error);
  978. i915_gem_record_fences(dev, error);
  979. i915_gem_record_rings(dev, error);
  980. do_gettimeofday(&error->time);
  981. error->overlay = intel_overlay_capture_error_state(dev);
  982. error->display = intel_display_capture_error_state(dev);
  983. i915_error_capture_msg(dev, error, wedged, error_msg);
  984. DRM_INFO("%s\n", error->error_msg);
  985. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  986. if (dev_priv->gpu_error.first_error == NULL) {
  987. dev_priv->gpu_error.first_error = error;
  988. error = NULL;
  989. }
  990. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  991. if (error) {
  992. i915_error_state_free(&error->ref);
  993. return;
  994. }
  995. if (!warned) {
  996. DRM_INFO("GPU hangs can indicate a bug anywhere in the entire gfx stack, including userspace.\n");
  997. DRM_INFO("Please file a _new_ bug report on bugs.freedesktop.org against DRI -> DRM/Intel\n");
  998. DRM_INFO("drm/i915 developers can then reassign to the right component if it's not a kernel issue.\n");
  999. DRM_INFO("The gpu crash dump is required to analyze gpu hangs, so please always attach it.\n");
  1000. DRM_INFO("GPU crash dump saved to /sys/class/drm/card%d/error\n", dev->primary->index);
  1001. warned = true;
  1002. }
  1003. }
  1004. void i915_error_state_get(struct drm_device *dev,
  1005. struct i915_error_state_file_priv *error_priv)
  1006. {
  1007. struct drm_i915_private *dev_priv = dev->dev_private;
  1008. unsigned long flags;
  1009. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  1010. error_priv->error = dev_priv->gpu_error.first_error;
  1011. if (error_priv->error)
  1012. kref_get(&error_priv->error->ref);
  1013. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  1014. }
  1015. void i915_error_state_put(struct i915_error_state_file_priv *error_priv)
  1016. {
  1017. if (error_priv->error)
  1018. kref_put(&error_priv->error->ref, i915_error_state_free);
  1019. }
  1020. void i915_destroy_error_state(struct drm_device *dev)
  1021. {
  1022. struct drm_i915_private *dev_priv = dev->dev_private;
  1023. struct drm_i915_error_state *error;
  1024. unsigned long flags;
  1025. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  1026. error = dev_priv->gpu_error.first_error;
  1027. dev_priv->gpu_error.first_error = NULL;
  1028. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  1029. if (error)
  1030. kref_put(&error->ref, i915_error_state_free);
  1031. }
  1032. const char *i915_cache_level_str(int type)
  1033. {
  1034. switch (type) {
  1035. case I915_CACHE_NONE: return " uncached";
  1036. case I915_CACHE_LLC: return " snooped or LLC";
  1037. case I915_CACHE_L3_LLC: return " L3+LLC";
  1038. case I915_CACHE_WT: return " WT";
  1039. default: return "";
  1040. }
  1041. }
  1042. /* NB: please notice the memset */
  1043. void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone)
  1044. {
  1045. struct drm_i915_private *dev_priv = dev->dev_private;
  1046. memset(instdone, 0, sizeof(*instdone) * I915_NUM_INSTDONE_REG);
  1047. switch (INTEL_INFO(dev)->gen) {
  1048. case 2:
  1049. case 3:
  1050. instdone[0] = I915_READ(INSTDONE);
  1051. break;
  1052. case 4:
  1053. case 5:
  1054. case 6:
  1055. instdone[0] = I915_READ(INSTDONE_I965);
  1056. instdone[1] = I915_READ(INSTDONE1);
  1057. break;
  1058. default:
  1059. WARN_ONCE(1, "Unsupported platform\n");
  1060. case 7:
  1061. case 8:
  1062. instdone[0] = I915_READ(GEN7_INSTDONE_1);
  1063. instdone[1] = I915_READ(GEN7_SC_INSTDONE);
  1064. instdone[2] = I915_READ(GEN7_SAMPLER_INSTDONE);
  1065. instdone[3] = I915_READ(GEN7_ROW_INSTDONE);
  1066. break;
  1067. }
  1068. }