i915_gpu_error.c 33 KB

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