i915_gpu_error.c 33 KB

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