PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/gpu/drm/i915/i915_irq.c

https://bitbucket.org/olivier_pitton/linux-3.8
C | 2884 lines | 2069 code | 518 blank | 297 comment | 351 complexity | ff3c660d5ab32dbf46996a4c893614ea MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
  2. */
  3. /*
  4. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  5. * All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sub license, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the
  16. * next paragraph) shall be included in all copies or substantial portions
  17. * of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  22. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  23. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  24. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  25. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. */
  28. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  29. #include <linux/sysrq.h>
  30. #include <linux/slab.h>
  31. #include <drm/drmP.h>
  32. #include <drm/i915_drm.h>
  33. #include "i915_drv.h"
  34. #include "i915_trace.h"
  35. #include "intel_drv.h"
  36. /* For display hotplug interrupt */
  37. static void
  38. ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  39. {
  40. if ((dev_priv->irq_mask & mask) != 0) {
  41. dev_priv->irq_mask &= ~mask;
  42. I915_WRITE(DEIMR, dev_priv->irq_mask);
  43. POSTING_READ(DEIMR);
  44. }
  45. }
  46. static inline void
  47. ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  48. {
  49. if ((dev_priv->irq_mask & mask) != mask) {
  50. dev_priv->irq_mask |= mask;
  51. I915_WRITE(DEIMR, dev_priv->irq_mask);
  52. POSTING_READ(DEIMR);
  53. }
  54. }
  55. void
  56. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  57. {
  58. if ((dev_priv->pipestat[pipe] & mask) != mask) {
  59. u32 reg = PIPESTAT(pipe);
  60. dev_priv->pipestat[pipe] |= mask;
  61. /* Enable the interrupt, clear any pending status */
  62. I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16));
  63. POSTING_READ(reg);
  64. }
  65. }
  66. void
  67. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  68. {
  69. if ((dev_priv->pipestat[pipe] & mask) != 0) {
  70. u32 reg = PIPESTAT(pipe);
  71. dev_priv->pipestat[pipe] &= ~mask;
  72. I915_WRITE(reg, dev_priv->pipestat[pipe]);
  73. POSTING_READ(reg);
  74. }
  75. }
  76. /**
  77. * intel_enable_asle - enable ASLE interrupt for OpRegion
  78. */
  79. void intel_enable_asle(struct drm_device *dev)
  80. {
  81. drm_i915_private_t *dev_priv = dev->dev_private;
  82. unsigned long irqflags;
  83. /* FIXME: opregion/asle for VLV */
  84. if (IS_VALLEYVIEW(dev))
  85. return;
  86. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  87. if (HAS_PCH_SPLIT(dev))
  88. ironlake_enable_display_irq(dev_priv, DE_GSE);
  89. else {
  90. i915_enable_pipestat(dev_priv, 1,
  91. PIPE_LEGACY_BLC_EVENT_ENABLE);
  92. if (INTEL_INFO(dev)->gen >= 4)
  93. i915_enable_pipestat(dev_priv, 0,
  94. PIPE_LEGACY_BLC_EVENT_ENABLE);
  95. }
  96. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  97. }
  98. /**
  99. * i915_pipe_enabled - check if a pipe is enabled
  100. * @dev: DRM device
  101. * @pipe: pipe to check
  102. *
  103. * Reading certain registers when the pipe is disabled can hang the chip.
  104. * Use this routine to make sure the PLL is running and the pipe is active
  105. * before reading such registers if unsure.
  106. */
  107. static int
  108. i915_pipe_enabled(struct drm_device *dev, int pipe)
  109. {
  110. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  111. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  112. pipe);
  113. return I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_ENABLE;
  114. }
  115. /* Called from drm generic code, passed a 'crtc', which
  116. * we use as a pipe index
  117. */
  118. static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  119. {
  120. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  121. unsigned long high_frame;
  122. unsigned long low_frame;
  123. u32 high1, high2, low;
  124. if (!i915_pipe_enabled(dev, pipe)) {
  125. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  126. "pipe %c\n", pipe_name(pipe));
  127. return 0;
  128. }
  129. high_frame = PIPEFRAME(pipe);
  130. low_frame = PIPEFRAMEPIXEL(pipe);
  131. /*
  132. * High & low register fields aren't synchronized, so make sure
  133. * we get a low value that's stable across two reads of the high
  134. * register.
  135. */
  136. do {
  137. high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  138. low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK;
  139. high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  140. } while (high1 != high2);
  141. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  142. low >>= PIPE_FRAME_LOW_SHIFT;
  143. return (high1 << 8) | low;
  144. }
  145. static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  146. {
  147. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  148. int reg = PIPE_FRMCOUNT_GM45(pipe);
  149. if (!i915_pipe_enabled(dev, pipe)) {
  150. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  151. "pipe %c\n", pipe_name(pipe));
  152. return 0;
  153. }
  154. return I915_READ(reg);
  155. }
  156. static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
  157. int *vpos, int *hpos)
  158. {
  159. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  160. u32 vbl = 0, position = 0;
  161. int vbl_start, vbl_end, htotal, vtotal;
  162. bool in_vbl = true;
  163. int ret = 0;
  164. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  165. pipe);
  166. if (!i915_pipe_enabled(dev, pipe)) {
  167. DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
  168. "pipe %c\n", pipe_name(pipe));
  169. return 0;
  170. }
  171. /* Get vtotal. */
  172. vtotal = 1 + ((I915_READ(VTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
  173. if (INTEL_INFO(dev)->gen >= 4) {
  174. /* No obvious pixelcount register. Only query vertical
  175. * scanout position from Display scan line register.
  176. */
  177. position = I915_READ(PIPEDSL(pipe));
  178. /* Decode into vertical scanout position. Don't have
  179. * horizontal scanout position.
  180. */
  181. *vpos = position & 0x1fff;
  182. *hpos = 0;
  183. } else {
  184. /* Have access to pixelcount since start of frame.
  185. * We can split this into vertical and horizontal
  186. * scanout position.
  187. */
  188. position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  189. htotal = 1 + ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
  190. *vpos = position / htotal;
  191. *hpos = position - (*vpos * htotal);
  192. }
  193. /* Query vblank area. */
  194. vbl = I915_READ(VBLANK(cpu_transcoder));
  195. /* Test position against vblank region. */
  196. vbl_start = vbl & 0x1fff;
  197. vbl_end = (vbl >> 16) & 0x1fff;
  198. if ((*vpos < vbl_start) || (*vpos > vbl_end))
  199. in_vbl = false;
  200. /* Inside "upper part" of vblank area? Apply corrective offset: */
  201. if (in_vbl && (*vpos >= vbl_start))
  202. *vpos = *vpos - vtotal;
  203. /* Readouts valid? */
  204. if (vbl > 0)
  205. ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
  206. /* In vblank? */
  207. if (in_vbl)
  208. ret |= DRM_SCANOUTPOS_INVBL;
  209. return ret;
  210. }
  211. static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
  212. int *max_error,
  213. struct timeval *vblank_time,
  214. unsigned flags)
  215. {
  216. struct drm_i915_private *dev_priv = dev->dev_private;
  217. struct drm_crtc *crtc;
  218. if (pipe < 0 || pipe >= dev_priv->num_pipe) {
  219. DRM_ERROR("Invalid crtc %d\n", pipe);
  220. return -EINVAL;
  221. }
  222. /* Get drm_crtc to timestamp: */
  223. crtc = intel_get_crtc_for_pipe(dev, pipe);
  224. if (crtc == NULL) {
  225. DRM_ERROR("Invalid crtc %d\n", pipe);
  226. return -EINVAL;
  227. }
  228. if (!crtc->enabled) {
  229. DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
  230. return -EBUSY;
  231. }
  232. /* Helper routine in DRM core does all the work: */
  233. return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
  234. vblank_time, flags,
  235. crtc);
  236. }
  237. /*
  238. * Handle hotplug events outside the interrupt handler proper.
  239. */
  240. static void i915_hotplug_work_func(struct work_struct *work)
  241. {
  242. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  243. hotplug_work);
  244. struct drm_device *dev = dev_priv->dev;
  245. struct drm_mode_config *mode_config = &dev->mode_config;
  246. struct intel_encoder *encoder;
  247. /* HPD irq before everything is fully set up. */
  248. if (!dev_priv->enable_hotplug_processing)
  249. return;
  250. mutex_lock(&mode_config->mutex);
  251. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  252. list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
  253. if (encoder->hot_plug)
  254. encoder->hot_plug(encoder);
  255. mutex_unlock(&mode_config->mutex);
  256. /* Just fire off a uevent and let userspace tell us what to do */
  257. drm_helper_hpd_irq_event(dev);
  258. }
  259. static void ironlake_handle_rps_change(struct drm_device *dev)
  260. {
  261. drm_i915_private_t *dev_priv = dev->dev_private;
  262. u32 busy_up, busy_down, max_avg, min_avg;
  263. u8 new_delay;
  264. unsigned long flags;
  265. spin_lock_irqsave(&mchdev_lock, flags);
  266. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  267. new_delay = dev_priv->ips.cur_delay;
  268. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  269. busy_up = I915_READ(RCPREVBSYTUPAVG);
  270. busy_down = I915_READ(RCPREVBSYTDNAVG);
  271. max_avg = I915_READ(RCBMAXAVG);
  272. min_avg = I915_READ(RCBMINAVG);
  273. /* Handle RCS change request from hw */
  274. if (busy_up > max_avg) {
  275. if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
  276. new_delay = dev_priv->ips.cur_delay - 1;
  277. if (new_delay < dev_priv->ips.max_delay)
  278. new_delay = dev_priv->ips.max_delay;
  279. } else if (busy_down < min_avg) {
  280. if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
  281. new_delay = dev_priv->ips.cur_delay + 1;
  282. if (new_delay > dev_priv->ips.min_delay)
  283. new_delay = dev_priv->ips.min_delay;
  284. }
  285. if (ironlake_set_drps(dev, new_delay))
  286. dev_priv->ips.cur_delay = new_delay;
  287. spin_unlock_irqrestore(&mchdev_lock, flags);
  288. return;
  289. }
  290. static void notify_ring(struct drm_device *dev,
  291. struct intel_ring_buffer *ring)
  292. {
  293. struct drm_i915_private *dev_priv = dev->dev_private;
  294. if (ring->obj == NULL)
  295. return;
  296. trace_i915_gem_request_complete(ring, ring->get_seqno(ring, false));
  297. wake_up_all(&ring->irq_queue);
  298. if (i915_enable_hangcheck) {
  299. dev_priv->gpu_error.hangcheck_count = 0;
  300. mod_timer(&dev_priv->gpu_error.hangcheck_timer,
  301. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  302. }
  303. }
  304. static void gen6_pm_rps_work(struct work_struct *work)
  305. {
  306. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  307. rps.work);
  308. u32 pm_iir, pm_imr;
  309. u8 new_delay;
  310. spin_lock_irq(&dev_priv->rps.lock);
  311. pm_iir = dev_priv->rps.pm_iir;
  312. dev_priv->rps.pm_iir = 0;
  313. pm_imr = I915_READ(GEN6_PMIMR);
  314. I915_WRITE(GEN6_PMIMR, 0);
  315. spin_unlock_irq(&dev_priv->rps.lock);
  316. if ((pm_iir & GEN6_PM_DEFERRED_EVENTS) == 0)
  317. return;
  318. mutex_lock(&dev_priv->rps.hw_lock);
  319. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD)
  320. new_delay = dev_priv->rps.cur_delay + 1;
  321. else
  322. new_delay = dev_priv->rps.cur_delay - 1;
  323. /* sysfs frequency interfaces may have snuck in while servicing the
  324. * interrupt
  325. */
  326. if (!(new_delay > dev_priv->rps.max_delay ||
  327. new_delay < dev_priv->rps.min_delay)) {
  328. gen6_set_rps(dev_priv->dev, new_delay);
  329. }
  330. mutex_unlock(&dev_priv->rps.hw_lock);
  331. }
  332. /**
  333. * ivybridge_parity_work - Workqueue called when a parity error interrupt
  334. * occurred.
  335. * @work: workqueue struct
  336. *
  337. * Doesn't actually do anything except notify userspace. As a consequence of
  338. * this event, userspace should try to remap the bad rows since statistically
  339. * it is likely the same row is more likely to go bad again.
  340. */
  341. static void ivybridge_parity_work(struct work_struct *work)
  342. {
  343. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  344. l3_parity.error_work);
  345. u32 error_status, row, bank, subbank;
  346. char *parity_event[5];
  347. uint32_t misccpctl;
  348. unsigned long flags;
  349. /* We must turn off DOP level clock gating to access the L3 registers.
  350. * In order to prevent a get/put style interface, acquire struct mutex
  351. * any time we access those registers.
  352. */
  353. mutex_lock(&dev_priv->dev->struct_mutex);
  354. misccpctl = I915_READ(GEN7_MISCCPCTL);
  355. I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  356. POSTING_READ(GEN7_MISCCPCTL);
  357. error_status = I915_READ(GEN7_L3CDERRST1);
  358. row = GEN7_PARITY_ERROR_ROW(error_status);
  359. bank = GEN7_PARITY_ERROR_BANK(error_status);
  360. subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
  361. I915_WRITE(GEN7_L3CDERRST1, GEN7_PARITY_ERROR_VALID |
  362. GEN7_L3CDERRST1_ENABLE);
  363. POSTING_READ(GEN7_L3CDERRST1);
  364. I915_WRITE(GEN7_MISCCPCTL, misccpctl);
  365. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  366. dev_priv->gt_irq_mask &= ~GT_GEN7_L3_PARITY_ERROR_INTERRUPT;
  367. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  368. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  369. mutex_unlock(&dev_priv->dev->struct_mutex);
  370. parity_event[0] = "L3_PARITY_ERROR=1";
  371. parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
  372. parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
  373. parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
  374. parity_event[4] = NULL;
  375. kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj,
  376. KOBJ_CHANGE, parity_event);
  377. DRM_DEBUG("Parity error: Row = %d, Bank = %d, Sub bank = %d.\n",
  378. row, bank, subbank);
  379. kfree(parity_event[3]);
  380. kfree(parity_event[2]);
  381. kfree(parity_event[1]);
  382. }
  383. static void ivybridge_handle_parity_error(struct drm_device *dev)
  384. {
  385. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  386. unsigned long flags;
  387. if (!HAS_L3_GPU_CACHE(dev))
  388. return;
  389. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  390. dev_priv->gt_irq_mask |= GT_GEN7_L3_PARITY_ERROR_INTERRUPT;
  391. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  392. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  393. queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
  394. }
  395. static void snb_gt_irq_handler(struct drm_device *dev,
  396. struct drm_i915_private *dev_priv,
  397. u32 gt_iir)
  398. {
  399. if (gt_iir & (GEN6_RENDER_USER_INTERRUPT |
  400. GEN6_RENDER_PIPE_CONTROL_NOTIFY_INTERRUPT))
  401. notify_ring(dev, &dev_priv->ring[RCS]);
  402. if (gt_iir & GEN6_BSD_USER_INTERRUPT)
  403. notify_ring(dev, &dev_priv->ring[VCS]);
  404. if (gt_iir & GEN6_BLITTER_USER_INTERRUPT)
  405. notify_ring(dev, &dev_priv->ring[BCS]);
  406. if (gt_iir & (GT_GEN6_BLT_CS_ERROR_INTERRUPT |
  407. GT_GEN6_BSD_CS_ERROR_INTERRUPT |
  408. GT_RENDER_CS_ERROR_INTERRUPT)) {
  409. DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
  410. i915_handle_error(dev, false);
  411. }
  412. if (gt_iir & GT_GEN7_L3_PARITY_ERROR_INTERRUPT)
  413. ivybridge_handle_parity_error(dev);
  414. }
  415. static void gen6_queue_rps_work(struct drm_i915_private *dev_priv,
  416. u32 pm_iir)
  417. {
  418. unsigned long flags;
  419. /*
  420. * IIR bits should never already be set because IMR should
  421. * prevent an interrupt from being shown in IIR. The warning
  422. * displays a case where we've unsafely cleared
  423. * dev_priv->rps.pm_iir. Although missing an interrupt of the same
  424. * type is not a problem, it displays a problem in the logic.
  425. *
  426. * The mask bit in IMR is cleared by dev_priv->rps.work.
  427. */
  428. spin_lock_irqsave(&dev_priv->rps.lock, flags);
  429. dev_priv->rps.pm_iir |= pm_iir;
  430. I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
  431. POSTING_READ(GEN6_PMIMR);
  432. spin_unlock_irqrestore(&dev_priv->rps.lock, flags);
  433. queue_work(dev_priv->wq, &dev_priv->rps.work);
  434. }
  435. static void gmbus_irq_handler(struct drm_device *dev)
  436. {
  437. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  438. wake_up_all(&dev_priv->gmbus_wait_queue);
  439. }
  440. static void dp_aux_irq_handler(struct drm_device *dev)
  441. {
  442. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  443. wake_up_all(&dev_priv->gmbus_wait_queue);
  444. }
  445. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  446. {
  447. struct drm_device *dev = (struct drm_device *) arg;
  448. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  449. u32 iir, gt_iir, pm_iir;
  450. irqreturn_t ret = IRQ_NONE;
  451. unsigned long irqflags;
  452. int pipe;
  453. u32 pipe_stats[I915_MAX_PIPES];
  454. atomic_inc(&dev_priv->irq_received);
  455. while (true) {
  456. iir = I915_READ(VLV_IIR);
  457. gt_iir = I915_READ(GTIIR);
  458. pm_iir = I915_READ(GEN6_PMIIR);
  459. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  460. goto out;
  461. ret = IRQ_HANDLED;
  462. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  463. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  464. for_each_pipe(pipe) {
  465. int reg = PIPESTAT(pipe);
  466. pipe_stats[pipe] = I915_READ(reg);
  467. /*
  468. * Clear the PIPE*STAT regs before the IIR
  469. */
  470. if (pipe_stats[pipe] & 0x8000ffff) {
  471. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  472. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  473. pipe_name(pipe));
  474. I915_WRITE(reg, pipe_stats[pipe]);
  475. }
  476. }
  477. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  478. for_each_pipe(pipe) {
  479. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
  480. drm_handle_vblank(dev, pipe);
  481. if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
  482. intel_prepare_page_flip(dev, pipe);
  483. intel_finish_page_flip(dev, pipe);
  484. }
  485. }
  486. /* Consume port. Then clear IIR or we'll miss events */
  487. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  488. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  489. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  490. hotplug_status);
  491. if (hotplug_status & dev_priv->hotplug_supported_mask)
  492. queue_work(dev_priv->wq,
  493. &dev_priv->hotplug_work);
  494. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  495. I915_READ(PORT_HOTPLUG_STAT);
  496. }
  497. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  498. gmbus_irq_handler(dev);
  499. if (pm_iir & GEN6_PM_DEFERRED_EVENTS)
  500. gen6_queue_rps_work(dev_priv, pm_iir);
  501. I915_WRITE(GTIIR, gt_iir);
  502. I915_WRITE(GEN6_PMIIR, pm_iir);
  503. I915_WRITE(VLV_IIR, iir);
  504. }
  505. out:
  506. return ret;
  507. }
  508. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  509. {
  510. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  511. int pipe;
  512. if (pch_iir & SDE_HOTPLUG_MASK)
  513. queue_work(dev_priv->wq, &dev_priv->hotplug_work);
  514. if (pch_iir & SDE_AUDIO_POWER_MASK)
  515. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  516. (pch_iir & SDE_AUDIO_POWER_MASK) >>
  517. SDE_AUDIO_POWER_SHIFT);
  518. if (pch_iir & SDE_AUX_MASK)
  519. dp_aux_irq_handler(dev);
  520. if (pch_iir & SDE_GMBUS)
  521. gmbus_irq_handler(dev);
  522. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  523. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  524. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  525. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  526. if (pch_iir & SDE_POISON)
  527. DRM_ERROR("PCH poison interrupt\n");
  528. if (pch_iir & SDE_FDI_MASK)
  529. for_each_pipe(pipe)
  530. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  531. pipe_name(pipe),
  532. I915_READ(FDI_RX_IIR(pipe)));
  533. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  534. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  535. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  536. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  537. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  538. DRM_DEBUG_DRIVER("PCH transcoder B underrun interrupt\n");
  539. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  540. DRM_DEBUG_DRIVER("PCH transcoder A underrun interrupt\n");
  541. }
  542. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  543. {
  544. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  545. int pipe;
  546. if (pch_iir & SDE_HOTPLUG_MASK_CPT)
  547. queue_work(dev_priv->wq, &dev_priv->hotplug_work);
  548. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT)
  549. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  550. (pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  551. SDE_AUDIO_POWER_SHIFT_CPT);
  552. if (pch_iir & SDE_AUX_MASK_CPT)
  553. dp_aux_irq_handler(dev);
  554. if (pch_iir & SDE_GMBUS_CPT)
  555. gmbus_irq_handler(dev);
  556. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  557. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  558. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  559. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  560. if (pch_iir & SDE_FDI_MASK_CPT)
  561. for_each_pipe(pipe)
  562. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  563. pipe_name(pipe),
  564. I915_READ(FDI_RX_IIR(pipe)));
  565. }
  566. static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
  567. {
  568. struct drm_device *dev = (struct drm_device *) arg;
  569. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  570. u32 de_iir, gt_iir, de_ier, pm_iir;
  571. irqreturn_t ret = IRQ_NONE;
  572. int i;
  573. atomic_inc(&dev_priv->irq_received);
  574. /* disable master interrupt before clearing iir */
  575. de_ier = I915_READ(DEIER);
  576. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  577. gt_iir = I915_READ(GTIIR);
  578. if (gt_iir) {
  579. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  580. I915_WRITE(GTIIR, gt_iir);
  581. ret = IRQ_HANDLED;
  582. }
  583. de_iir = I915_READ(DEIIR);
  584. if (de_iir) {
  585. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  586. dp_aux_irq_handler(dev);
  587. if (de_iir & DE_GSE_IVB)
  588. intel_opregion_gse_intr(dev);
  589. for (i = 0; i < 3; i++) {
  590. if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
  591. drm_handle_vblank(dev, i);
  592. if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
  593. intel_prepare_page_flip(dev, i);
  594. intel_finish_page_flip_plane(dev, i);
  595. }
  596. }
  597. /* check event from PCH */
  598. if (de_iir & DE_PCH_EVENT_IVB) {
  599. u32 pch_iir = I915_READ(SDEIIR);
  600. cpt_irq_handler(dev, pch_iir);
  601. /* clear PCH hotplug event before clear CPU irq */
  602. I915_WRITE(SDEIIR, pch_iir);
  603. }
  604. I915_WRITE(DEIIR, de_iir);
  605. ret = IRQ_HANDLED;
  606. }
  607. pm_iir = I915_READ(GEN6_PMIIR);
  608. if (pm_iir) {
  609. if (pm_iir & GEN6_PM_DEFERRED_EVENTS)
  610. gen6_queue_rps_work(dev_priv, pm_iir);
  611. I915_WRITE(GEN6_PMIIR, pm_iir);
  612. ret = IRQ_HANDLED;
  613. }
  614. I915_WRITE(DEIER, de_ier);
  615. POSTING_READ(DEIER);
  616. return ret;
  617. }
  618. static void ilk_gt_irq_handler(struct drm_device *dev,
  619. struct drm_i915_private *dev_priv,
  620. u32 gt_iir)
  621. {
  622. if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY))
  623. notify_ring(dev, &dev_priv->ring[RCS]);
  624. if (gt_iir & GT_BSD_USER_INTERRUPT)
  625. notify_ring(dev, &dev_priv->ring[VCS]);
  626. }
  627. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  628. {
  629. struct drm_device *dev = (struct drm_device *) arg;
  630. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  631. int ret = IRQ_NONE;
  632. u32 de_iir, gt_iir, de_ier, pm_iir;
  633. atomic_inc(&dev_priv->irq_received);
  634. /* disable master interrupt before clearing iir */
  635. de_ier = I915_READ(DEIER);
  636. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  637. POSTING_READ(DEIER);
  638. de_iir = I915_READ(DEIIR);
  639. gt_iir = I915_READ(GTIIR);
  640. pm_iir = I915_READ(GEN6_PMIIR);
  641. if (de_iir == 0 && gt_iir == 0 && (!IS_GEN6(dev) || pm_iir == 0))
  642. goto done;
  643. ret = IRQ_HANDLED;
  644. if (IS_GEN5(dev))
  645. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  646. else
  647. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  648. if (de_iir & DE_AUX_CHANNEL_A)
  649. dp_aux_irq_handler(dev);
  650. if (de_iir & DE_GSE)
  651. intel_opregion_gse_intr(dev);
  652. if (de_iir & DE_PIPEA_VBLANK)
  653. drm_handle_vblank(dev, 0);
  654. if (de_iir & DE_PIPEB_VBLANK)
  655. drm_handle_vblank(dev, 1);
  656. if (de_iir & DE_PLANEA_FLIP_DONE) {
  657. intel_prepare_page_flip(dev, 0);
  658. intel_finish_page_flip_plane(dev, 0);
  659. }
  660. if (de_iir & DE_PLANEB_FLIP_DONE) {
  661. intel_prepare_page_flip(dev, 1);
  662. intel_finish_page_flip_plane(dev, 1);
  663. }
  664. /* check event from PCH */
  665. if (de_iir & DE_PCH_EVENT) {
  666. u32 pch_iir = I915_READ(SDEIIR);
  667. if (HAS_PCH_CPT(dev))
  668. cpt_irq_handler(dev, pch_iir);
  669. else
  670. ibx_irq_handler(dev, pch_iir);
  671. /* should clear PCH hotplug event before clear CPU irq */
  672. I915_WRITE(SDEIIR, pch_iir);
  673. }
  674. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  675. ironlake_handle_rps_change(dev);
  676. if (IS_GEN6(dev) && pm_iir & GEN6_PM_DEFERRED_EVENTS)
  677. gen6_queue_rps_work(dev_priv, pm_iir);
  678. I915_WRITE(GTIIR, gt_iir);
  679. I915_WRITE(DEIIR, de_iir);
  680. I915_WRITE(GEN6_PMIIR, pm_iir);
  681. done:
  682. I915_WRITE(DEIER, de_ier);
  683. POSTING_READ(DEIER);
  684. return ret;
  685. }
  686. /**
  687. * i915_error_work_func - do process context error handling work
  688. * @work: work struct
  689. *
  690. * Fire an error uevent so userspace can see that a hang or error
  691. * was detected.
  692. */
  693. static void i915_error_work_func(struct work_struct *work)
  694. {
  695. struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
  696. work);
  697. drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
  698. gpu_error);
  699. struct drm_device *dev = dev_priv->dev;
  700. struct intel_ring_buffer *ring;
  701. char *error_event[] = { "ERROR=1", NULL };
  702. char *reset_event[] = { "RESET=1", NULL };
  703. char *reset_done_event[] = { "ERROR=0", NULL };
  704. int i, ret;
  705. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  706. /*
  707. * Note that there's only one work item which does gpu resets, so we
  708. * need not worry about concurrent gpu resets potentially incrementing
  709. * error->reset_counter twice. We only need to take care of another
  710. * racing irq/hangcheck declaring the gpu dead for a second time. A
  711. * quick check for that is good enough: schedule_work ensures the
  712. * correct ordering between hang detection and this work item, and since
  713. * the reset in-progress bit is only ever set by code outside of this
  714. * work we don't need to worry about any other races.
  715. */
  716. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  717. DRM_DEBUG_DRIVER("resetting chip\n");
  718. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
  719. reset_event);
  720. ret = i915_reset(dev);
  721. if (ret == 0) {
  722. /*
  723. * After all the gem state is reset, increment the reset
  724. * counter and wake up everyone waiting for the reset to
  725. * complete.
  726. *
  727. * Since unlock operations are a one-sided barrier only,
  728. * we need to insert a barrier here to order any seqno
  729. * updates before
  730. * the counter increment.
  731. */
  732. smp_mb__before_atomic_inc();
  733. atomic_inc(&dev_priv->gpu_error.reset_counter);
  734. kobject_uevent_env(&dev->primary->kdev.kobj,
  735. KOBJ_CHANGE, reset_done_event);
  736. } else {
  737. atomic_set(&error->reset_counter, I915_WEDGED);
  738. }
  739. for_each_ring(ring, dev_priv, i)
  740. wake_up_all(&ring->irq_queue);
  741. wake_up_all(&dev_priv->gpu_error.reset_queue);
  742. }
  743. }
  744. /* NB: please notice the memset */
  745. static void i915_get_extra_instdone(struct drm_device *dev,
  746. uint32_t *instdone)
  747. {
  748. struct drm_i915_private *dev_priv = dev->dev_private;
  749. memset(instdone, 0, sizeof(*instdone) * I915_NUM_INSTDONE_REG);
  750. switch(INTEL_INFO(dev)->gen) {
  751. case 2:
  752. case 3:
  753. instdone[0] = I915_READ(INSTDONE);
  754. break;
  755. case 4:
  756. case 5:
  757. case 6:
  758. instdone[0] = I915_READ(INSTDONE_I965);
  759. instdone[1] = I915_READ(INSTDONE1);
  760. break;
  761. default:
  762. WARN_ONCE(1, "Unsupported platform\n");
  763. case 7:
  764. instdone[0] = I915_READ(GEN7_INSTDONE_1);
  765. instdone[1] = I915_READ(GEN7_SC_INSTDONE);
  766. instdone[2] = I915_READ(GEN7_SAMPLER_INSTDONE);
  767. instdone[3] = I915_READ(GEN7_ROW_INSTDONE);
  768. break;
  769. }
  770. }
  771. #ifdef CONFIG_DEBUG_FS
  772. static struct drm_i915_error_object *
  773. i915_error_object_create(struct drm_i915_private *dev_priv,
  774. struct drm_i915_gem_object *src)
  775. {
  776. struct drm_i915_error_object *dst;
  777. int i, count;
  778. u32 reloc_offset;
  779. if (src == NULL || src->pages == NULL)
  780. return NULL;
  781. count = src->base.size / PAGE_SIZE;
  782. dst = kmalloc(sizeof(*dst) + count * sizeof(u32 *), GFP_ATOMIC);
  783. if (dst == NULL)
  784. return NULL;
  785. reloc_offset = src->gtt_offset;
  786. for (i = 0; i < count; i++) {
  787. unsigned long flags;
  788. void *d;
  789. d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
  790. if (d == NULL)
  791. goto unwind;
  792. local_irq_save(flags);
  793. if (reloc_offset < dev_priv->gtt.mappable_end &&
  794. src->has_global_gtt_mapping) {
  795. void __iomem *s;
  796. /* Simply ignore tiling or any overlapping fence.
  797. * It's part of the error state, and this hopefully
  798. * captures what the GPU read.
  799. */
  800. s = io_mapping_map_atomic_wc(dev_priv->gtt.mappable,
  801. reloc_offset);
  802. memcpy_fromio(d, s, PAGE_SIZE);
  803. io_mapping_unmap_atomic(s);
  804. } else if (src->stolen) {
  805. unsigned long offset;
  806. offset = dev_priv->mm.stolen_base;
  807. offset += src->stolen->start;
  808. offset += i << PAGE_SHIFT;
  809. memcpy_fromio(d, (void __iomem *) offset, PAGE_SIZE);
  810. } else {
  811. struct page *page;
  812. void *s;
  813. page = i915_gem_object_get_page(src, i);
  814. drm_clflush_pages(&page, 1);
  815. s = kmap_atomic(page);
  816. memcpy(d, s, PAGE_SIZE);
  817. kunmap_atomic(s);
  818. drm_clflush_pages(&page, 1);
  819. }
  820. local_irq_restore(flags);
  821. dst->pages[i] = d;
  822. reloc_offset += PAGE_SIZE;
  823. }
  824. dst->page_count = count;
  825. dst->gtt_offset = src->gtt_offset;
  826. return dst;
  827. unwind:
  828. while (i--)
  829. kfree(dst->pages[i]);
  830. kfree(dst);
  831. return NULL;
  832. }
  833. static void
  834. i915_error_object_free(struct drm_i915_error_object *obj)
  835. {
  836. int page;
  837. if (obj == NULL)
  838. return;
  839. for (page = 0; page < obj->page_count; page++)
  840. kfree(obj->pages[page]);
  841. kfree(obj);
  842. }
  843. void
  844. i915_error_state_free(struct kref *error_ref)
  845. {
  846. struct drm_i915_error_state *error = container_of(error_ref,
  847. typeof(*error), ref);
  848. int i;
  849. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  850. i915_error_object_free(error->ring[i].batchbuffer);
  851. i915_error_object_free(error->ring[i].ringbuffer);
  852. kfree(error->ring[i].requests);
  853. }
  854. kfree(error->active_bo);
  855. kfree(error->overlay);
  856. kfree(error);
  857. }
  858. static void capture_bo(struct drm_i915_error_buffer *err,
  859. struct drm_i915_gem_object *obj)
  860. {
  861. err->size = obj->base.size;
  862. err->name = obj->base.name;
  863. err->rseqno = obj->last_read_seqno;
  864. err->wseqno = obj->last_write_seqno;
  865. err->gtt_offset = obj->gtt_offset;
  866. err->read_domains = obj->base.read_domains;
  867. err->write_domain = obj->base.write_domain;
  868. err->fence_reg = obj->fence_reg;
  869. err->pinned = 0;
  870. if (obj->pin_count > 0)
  871. err->pinned = 1;
  872. if (obj->user_pin_count > 0)
  873. err->pinned = -1;
  874. err->tiling = obj->tiling_mode;
  875. err->dirty = obj->dirty;
  876. err->purgeable = obj->madv != I915_MADV_WILLNEED;
  877. err->ring = obj->ring ? obj->ring->id : -1;
  878. err->cache_level = obj->cache_level;
  879. }
  880. static u32 capture_active_bo(struct drm_i915_error_buffer *err,
  881. int count, struct list_head *head)
  882. {
  883. struct drm_i915_gem_object *obj;
  884. int i = 0;
  885. list_for_each_entry(obj, head, mm_list) {
  886. capture_bo(err++, obj);
  887. if (++i == count)
  888. break;
  889. }
  890. return i;
  891. }
  892. static u32 capture_pinned_bo(struct drm_i915_error_buffer *err,
  893. int count, struct list_head *head)
  894. {
  895. struct drm_i915_gem_object *obj;
  896. int i = 0;
  897. list_for_each_entry(obj, head, gtt_list) {
  898. if (obj->pin_count == 0)
  899. continue;
  900. capture_bo(err++, obj);
  901. if (++i == count)
  902. break;
  903. }
  904. return i;
  905. }
  906. static void i915_gem_record_fences(struct drm_device *dev,
  907. struct drm_i915_error_state *error)
  908. {
  909. struct drm_i915_private *dev_priv = dev->dev_private;
  910. int i;
  911. /* Fences */
  912. switch (INTEL_INFO(dev)->gen) {
  913. case 7:
  914. case 6:
  915. for (i = 0; i < 16; i++)
  916. error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
  917. break;
  918. case 5:
  919. case 4:
  920. for (i = 0; i < 16; i++)
  921. error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
  922. break;
  923. case 3:
  924. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  925. for (i = 0; i < 8; i++)
  926. error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
  927. case 2:
  928. for (i = 0; i < 8; i++)
  929. error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
  930. break;
  931. default:
  932. BUG();
  933. }
  934. }
  935. static struct drm_i915_error_object *
  936. i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
  937. struct intel_ring_buffer *ring)
  938. {
  939. struct drm_i915_gem_object *obj;
  940. u32 seqno;
  941. if (!ring->get_seqno)
  942. return NULL;
  943. if (HAS_BROKEN_CS_TLB(dev_priv->dev)) {
  944. u32 acthd = I915_READ(ACTHD);
  945. if (WARN_ON(ring->id != RCS))
  946. return NULL;
  947. obj = ring->private;
  948. if (acthd >= obj->gtt_offset &&
  949. acthd < obj->gtt_offset + obj->base.size)
  950. return i915_error_object_create(dev_priv, obj);
  951. }
  952. seqno = ring->get_seqno(ring, false);
  953. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
  954. if (obj->ring != ring)
  955. continue;
  956. if (i915_seqno_passed(seqno, obj->last_read_seqno))
  957. continue;
  958. if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
  959. continue;
  960. /* We need to copy these to an anonymous buffer as the simplest
  961. * method to avoid being overwritten by userspace.
  962. */
  963. return i915_error_object_create(dev_priv, obj);
  964. }
  965. return NULL;
  966. }
  967. static void i915_record_ring_state(struct drm_device *dev,
  968. struct drm_i915_error_state *error,
  969. struct intel_ring_buffer *ring)
  970. {
  971. struct drm_i915_private *dev_priv = dev->dev_private;
  972. if (INTEL_INFO(dev)->gen >= 6) {
  973. error->rc_psmi[ring->id] = I915_READ(ring->mmio_base + 0x50);
  974. error->fault_reg[ring->id] = I915_READ(RING_FAULT_REG(ring));
  975. error->semaphore_mboxes[ring->id][0]
  976. = I915_READ(RING_SYNC_0(ring->mmio_base));
  977. error->semaphore_mboxes[ring->id][1]
  978. = I915_READ(RING_SYNC_1(ring->mmio_base));
  979. error->semaphore_seqno[ring->id][0] = ring->sync_seqno[0];
  980. error->semaphore_seqno[ring->id][1] = ring->sync_seqno[1];
  981. }
  982. if (INTEL_INFO(dev)->gen >= 4) {
  983. error->faddr[ring->id] = I915_READ(RING_DMA_FADD(ring->mmio_base));
  984. error->ipeir[ring->id] = I915_READ(RING_IPEIR(ring->mmio_base));
  985. error->ipehr[ring->id] = I915_READ(RING_IPEHR(ring->mmio_base));
  986. error->instdone[ring->id] = I915_READ(RING_INSTDONE(ring->mmio_base));
  987. error->instps[ring->id] = I915_READ(RING_INSTPS(ring->mmio_base));
  988. if (ring->id == RCS)
  989. error->bbaddr = I915_READ64(BB_ADDR);
  990. } else {
  991. error->faddr[ring->id] = I915_READ(DMA_FADD_I8XX);
  992. error->ipeir[ring->id] = I915_READ(IPEIR);
  993. error->ipehr[ring->id] = I915_READ(IPEHR);
  994. error->instdone[ring->id] = I915_READ(INSTDONE);
  995. }
  996. error->waiting[ring->id] = waitqueue_active(&ring->irq_queue);
  997. error->instpm[ring->id] = I915_READ(RING_INSTPM(ring->mmio_base));
  998. error->seqno[ring->id] = ring->get_seqno(ring, false);
  999. error->acthd[ring->id] = intel_ring_get_active_head(ring);
  1000. error->head[ring->id] = I915_READ_HEAD(ring);
  1001. error->tail[ring->id] = I915_READ_TAIL(ring);
  1002. error->ctl[ring->id] = I915_READ_CTL(ring);
  1003. error->cpu_ring_head[ring->id] = ring->head;
  1004. error->cpu_ring_tail[ring->id] = ring->tail;
  1005. }
  1006. static void i915_gem_record_rings(struct drm_device *dev,
  1007. struct drm_i915_error_state *error)
  1008. {
  1009. struct drm_i915_private *dev_priv = dev->dev_private;
  1010. struct intel_ring_buffer *ring;
  1011. struct drm_i915_gem_request *request;
  1012. int i, count;
  1013. for_each_ring(ring, dev_priv, i) {
  1014. i915_record_ring_state(dev, error, ring);
  1015. error->ring[i].batchbuffer =
  1016. i915_error_first_batchbuffer(dev_priv, ring);
  1017. error->ring[i].ringbuffer =
  1018. i915_error_object_create(dev_priv, ring->obj);
  1019. count = 0;
  1020. list_for_each_entry(request, &ring->request_list, list)
  1021. count++;
  1022. error->ring[i].num_requests = count;
  1023. error->ring[i].requests =
  1024. kmalloc(count*sizeof(struct drm_i915_error_request),
  1025. GFP_ATOMIC);
  1026. if (error->ring[i].requests == NULL) {
  1027. error->ring[i].num_requests = 0;
  1028. continue;
  1029. }
  1030. count = 0;
  1031. list_for_each_entry(request, &ring->request_list, list) {
  1032. struct drm_i915_error_request *erq;
  1033. erq = &error->ring[i].requests[count++];
  1034. erq->seqno = request->seqno;
  1035. erq->jiffies = request->emitted_jiffies;
  1036. erq->tail = request->tail;
  1037. }
  1038. }
  1039. }
  1040. /**
  1041. * i915_capture_error_state - capture an error record for later analysis
  1042. * @dev: drm device
  1043. *
  1044. * Should be called when an error is detected (either a hang or an error
  1045. * interrupt) to capture error state from the time of the error. Fills
  1046. * out a structure which becomes available in debugfs for user level tools
  1047. * to pick up.
  1048. */
  1049. static void i915_capture_error_state(struct drm_device *dev)
  1050. {
  1051. struct drm_i915_private *dev_priv = dev->dev_private;
  1052. struct drm_i915_gem_object *obj;
  1053. struct drm_i915_error_state *error;
  1054. unsigned long flags;
  1055. int i, pipe;
  1056. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  1057. error = dev_priv->gpu_error.first_error;
  1058. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  1059. if (error)
  1060. return;
  1061. /* Account for pipe specific data like PIPE*STAT */
  1062. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  1063. if (!error) {
  1064. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  1065. return;
  1066. }
  1067. DRM_INFO("capturing error event; look for more information in"
  1068. "/sys/kernel/debug/dri/%d/i915_error_state\n",
  1069. dev->primary->index);
  1070. kref_init(&error->ref);
  1071. error->eir = I915_READ(EIR);
  1072. error->pgtbl_er = I915_READ(PGTBL_ER);
  1073. error->ccid = I915_READ(CCID);
  1074. if (HAS_PCH_SPLIT(dev))
  1075. error->ier = I915_READ(DEIER) | I915_READ(GTIER);
  1076. else if (IS_VALLEYVIEW(dev))
  1077. error->ier = I915_READ(GTIER) | I915_READ(VLV_IER);
  1078. else if (IS_GEN2(dev))
  1079. error->ier = I915_READ16(IER);
  1080. else
  1081. error->ier = I915_READ(IER);
  1082. if (INTEL_INFO(dev)->gen >= 6)
  1083. error->derrmr = I915_READ(DERRMR);
  1084. if (IS_VALLEYVIEW(dev))
  1085. error->forcewake = I915_READ(FORCEWAKE_VLV);
  1086. else if (INTEL_INFO(dev)->gen >= 7)
  1087. error->forcewake = I915_READ(FORCEWAKE_MT);
  1088. else if (INTEL_INFO(dev)->gen == 6)
  1089. error->forcewake = I915_READ(FORCEWAKE);
  1090. for_each_pipe(pipe)
  1091. error->pipestat[pipe] = I915_READ(PIPESTAT(pipe));
  1092. if (INTEL_INFO(dev)->gen >= 6) {
  1093. error->error = I915_READ(ERROR_GEN6);
  1094. error->done_reg = I915_READ(DONE_REG);
  1095. }
  1096. if (INTEL_INFO(dev)->gen == 7)
  1097. error->err_int = I915_READ(GEN7_ERR_INT);
  1098. i915_get_extra_instdone(dev, error->extra_instdone);
  1099. i915_gem_record_fences(dev, error);
  1100. i915_gem_record_rings(dev, error);
  1101. /* Record buffers on the active and pinned lists. */
  1102. error->active_bo = NULL;
  1103. error->pinned_bo = NULL;
  1104. i = 0;
  1105. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list)
  1106. i++;
  1107. error->active_bo_count = i;
  1108. list_for_each_entry(obj, &dev_priv->mm.bound_list, gtt_list)
  1109. if (obj->pin_count)
  1110. i++;
  1111. error->pinned_bo_count = i - error->active_bo_count;
  1112. error->active_bo = NULL;
  1113. error->pinned_bo = NULL;
  1114. if (i) {
  1115. error->active_bo = kmalloc(sizeof(*error->active_bo)*i,
  1116. GFP_ATOMIC);
  1117. if (error->active_bo)
  1118. error->pinned_bo =
  1119. error->active_bo + error->active_bo_count;
  1120. }
  1121. if (error->active_bo)
  1122. error->active_bo_count =
  1123. capture_active_bo(error->active_bo,
  1124. error->active_bo_count,
  1125. &dev_priv->mm.active_list);
  1126. if (error->pinned_bo)
  1127. error->pinned_bo_count =
  1128. capture_pinned_bo(error->pinned_bo,
  1129. error->pinned_bo_count,
  1130. &dev_priv->mm.bound_list);
  1131. do_gettimeofday(&error->time);
  1132. error->overlay = intel_overlay_capture_error_state(dev);
  1133. error->display = intel_display_capture_error_state(dev);
  1134. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  1135. if (dev_priv->gpu_error.first_error == NULL) {
  1136. dev_priv->gpu_error.first_error = error;
  1137. error = NULL;
  1138. }
  1139. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  1140. if (error)
  1141. i915_error_state_free(&error->ref);
  1142. }
  1143. void i915_destroy_error_state(struct drm_device *dev)
  1144. {
  1145. struct drm_i915_private *dev_priv = dev->dev_private;
  1146. struct drm_i915_error_state *error;
  1147. unsigned long flags;
  1148. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  1149. error = dev_priv->gpu_error.first_error;
  1150. dev_priv->gpu_error.first_error = NULL;
  1151. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  1152. if (error)
  1153. kref_put(&error->ref, i915_error_state_free);
  1154. }
  1155. #else
  1156. #define i915_capture_error_state(x)
  1157. #endif
  1158. static void i915_report_and_clear_eir(struct drm_device *dev)
  1159. {
  1160. struct drm_i915_private *dev_priv = dev->dev_private;
  1161. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1162. u32 eir = I915_READ(EIR);
  1163. int pipe, i;
  1164. if (!eir)
  1165. return;
  1166. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1167. i915_get_extra_instdone(dev, instdone);
  1168. if (IS_G4X(dev)) {
  1169. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1170. u32 ipeir = I915_READ(IPEIR_I965);
  1171. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1172. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1173. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1174. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1175. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1176. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1177. I915_WRITE(IPEIR_I965, ipeir);
  1178. POSTING_READ(IPEIR_I965);
  1179. }
  1180. if (eir & GM45_ERROR_PAGE_TABLE) {
  1181. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1182. pr_err("page table error\n");
  1183. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1184. I915_WRITE(PGTBL_ER, pgtbl_err);
  1185. POSTING_READ(PGTBL_ER);
  1186. }
  1187. }
  1188. if (!IS_GEN2(dev)) {
  1189. if (eir & I915_ERROR_PAGE_TABLE) {
  1190. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1191. pr_err("page table error\n");
  1192. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1193. I915_WRITE(PGTBL_ER, pgtbl_err);
  1194. POSTING_READ(PGTBL_ER);
  1195. }
  1196. }
  1197. if (eir & I915_ERROR_MEMORY_REFRESH) {
  1198. pr_err("memory refresh error:\n");
  1199. for_each_pipe(pipe)
  1200. pr_err("pipe %c stat: 0x%08x\n",
  1201. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  1202. /* pipestat has already been acked */
  1203. }
  1204. if (eir & I915_ERROR_INSTRUCTION) {
  1205. pr_err("instruction error\n");
  1206. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  1207. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1208. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1209. if (INTEL_INFO(dev)->gen < 4) {
  1210. u32 ipeir = I915_READ(IPEIR);
  1211. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  1212. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  1213. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  1214. I915_WRITE(IPEIR, ipeir);
  1215. POSTING_READ(IPEIR);
  1216. } else {
  1217. u32 ipeir = I915_READ(IPEIR_I965);
  1218. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1219. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1220. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1221. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1222. I915_WRITE(IPEIR_I965, ipeir);
  1223. POSTING_READ(IPEIR_I965);
  1224. }
  1225. }
  1226. I915_WRITE(EIR, eir);
  1227. POSTING_READ(EIR);
  1228. eir = I915_READ(EIR);
  1229. if (eir) {
  1230. /*
  1231. * some errors might have become stuck,
  1232. * mask them.
  1233. */
  1234. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1235. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1236. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1237. }
  1238. }
  1239. /**
  1240. * i915_handle_error - handle an error interrupt
  1241. * @dev: drm device
  1242. *
  1243. * Do some basic checking of regsiter state at error interrupt time and
  1244. * dump it to the syslog. Also call i915_capture_error_state() to make
  1245. * sure we get a record and make it available in debugfs. Fire a uevent
  1246. * so userspace knows something bad happened (should trigger collection
  1247. * of a ring dump etc.).
  1248. */
  1249. void i915_handle_error(struct drm_device *dev, bool wedged)
  1250. {
  1251. struct drm_i915_private *dev_priv = dev->dev_private;
  1252. struct intel_ring_buffer *ring;
  1253. int i;
  1254. i915_capture_error_state(dev);
  1255. i915_report_and_clear_eir(dev);
  1256. if (wedged) {
  1257. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  1258. &dev_priv->gpu_error.reset_counter);
  1259. /*
  1260. * Wakeup waiting processes so that the reset work item
  1261. * doesn't deadlock trying to grab various locks.
  1262. */
  1263. for_each_ring(ring, dev_priv, i)
  1264. wake_up_all(&ring->irq_queue);
  1265. }
  1266. queue_work(dev_priv->wq, &dev_priv->gpu_error.work);
  1267. }
  1268. static void i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1269. {
  1270. drm_i915_private_t *dev_priv = dev->dev_private;
  1271. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1272. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1273. struct drm_i915_gem_object *obj;
  1274. struct intel_unpin_work *work;
  1275. unsigned long flags;
  1276. bool stall_detected;
  1277. /* Ignore early vblank irqs */
  1278. if (intel_crtc == NULL)
  1279. return;
  1280. spin_lock_irqsave(&dev->event_lock, flags);
  1281. work = intel_crtc->unpin_work;
  1282. if (work == NULL ||
  1283. atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
  1284. !work->enable_stall_check) {
  1285. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1286. spin_unlock_irqrestore(&dev->event_lock, flags);
  1287. return;
  1288. }
  1289. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1290. obj = work->pending_flip_obj;
  1291. if (INTEL_INFO(dev)->gen >= 4) {
  1292. int dspsurf = DSPSURF(intel_crtc->plane);
  1293. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  1294. obj->gtt_offset;
  1295. } else {
  1296. int dspaddr = DSPADDR(intel_crtc->plane);
  1297. stall_detected = I915_READ(dspaddr) == (obj->gtt_offset +
  1298. crtc->y * crtc->fb->pitches[0] +
  1299. crtc->x * crtc->fb->bits_per_pixel/8);
  1300. }
  1301. spin_unlock_irqrestore(&dev->event_lock, flags);
  1302. if (stall_detected) {
  1303. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1304. intel_prepare_page_flip(dev, intel_crtc->plane);
  1305. }
  1306. }
  1307. /* Called from drm generic code, passed 'crtc' which
  1308. * we use as a pipe index
  1309. */
  1310. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1311. {
  1312. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1313. unsigned long irqflags;
  1314. if (!i915_pipe_enabled(dev, pipe))
  1315. return -EINVAL;
  1316. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1317. if (INTEL_INFO(dev)->gen >= 4)
  1318. i915_enable_pipestat(dev_priv, pipe,
  1319. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1320. else
  1321. i915_enable_pipestat(dev_priv, pipe,
  1322. PIPE_VBLANK_INTERRUPT_ENABLE);
  1323. /* maintain vblank delivery even in deep C-states */
  1324. if (dev_priv->info->gen == 3)
  1325. I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
  1326. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1327. return 0;
  1328. }
  1329. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1330. {
  1331. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1332. unsigned long irqflags;
  1333. if (!i915_pipe_enabled(dev, pipe))
  1334. return -EINVAL;
  1335. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1336. ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
  1337. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1338. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1339. return 0;
  1340. }
  1341. static int ivybridge_enable_vblank(struct drm_device *dev, int pipe)
  1342. {
  1343. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1344. unsigned long irqflags;
  1345. if (!i915_pipe_enabled(dev, pipe))
  1346. return -EINVAL;
  1347. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1348. ironlake_enable_display_irq(dev_priv,
  1349. DE_PIPEA_VBLANK_IVB << (5 * pipe));
  1350. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1351. return 0;
  1352. }
  1353. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  1354. {
  1355. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1356. unsigned long irqflags;
  1357. u32 imr;
  1358. if (!i915_pipe_enabled(dev, pipe))
  1359. return -EINVAL;
  1360. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1361. imr = I915_READ(VLV_IMR);
  1362. if (pipe == 0)
  1363. imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1364. else
  1365. imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1366. I915_WRITE(VLV_IMR, imr);
  1367. i915_enable_pipestat(dev_priv, pipe,
  1368. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1369. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1370. return 0;
  1371. }
  1372. /* Called from drm generic code, passed 'crtc' which
  1373. * we use as a pipe index
  1374. */
  1375. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  1376. {
  1377. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1378. unsigned long irqflags;
  1379. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1380. if (dev_priv->info->gen == 3)
  1381. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
  1382. i915_disable_pipestat(dev_priv, pipe,
  1383. PIPE_VBLANK_INTERRUPT_ENABLE |
  1384. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1385. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1386. }
  1387. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  1388. {
  1389. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1390. unsigned long irqflags;
  1391. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1392. ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
  1393. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1394. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1395. }
  1396. static void ivybridge_disable_vblank(struct drm_device *dev, int pipe)
  1397. {
  1398. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1399. unsigned long irqflags;
  1400. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1401. ironlake_disable_display_irq(dev_priv,
  1402. DE_PIPEA_VBLANK_IVB << (pipe * 5));
  1403. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1404. }
  1405. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  1406. {
  1407. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1408. unsigned long irqflags;
  1409. u32 imr;
  1410. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1411. i915_disable_pipestat(dev_priv, pipe,
  1412. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1413. imr = I915_READ(VLV_IMR);
  1414. if (pipe == 0)
  1415. imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1416. else
  1417. imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1418. I915_WRITE(VLV_IMR, imr);
  1419. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1420. }
  1421. static u32
  1422. ring_last_seqno(struct intel_ring_buffer *ring)
  1423. {
  1424. return list_entry(ring->request_list.prev,
  1425. struct drm_i915_gem_request, list)->seqno;
  1426. }
  1427. static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err)
  1428. {
  1429. if (list_empty(&ring->request_list) ||
  1430. i915_seqno_passed(ring->get_seqno(ring, false),
  1431. ring_last_seqno(ring))) {
  1432. /* Issue a wake-up to catch stuck h/w. */
  1433. if (waitqueue_active(&ring->irq_queue)) {
  1434. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  1435. ring->name);
  1436. wake_up_all(&ring->irq_queue);
  1437. *err = true;
  1438. }
  1439. return true;
  1440. }
  1441. return false;
  1442. }
  1443. static bool kick_ring(struct intel_ring_buffer *ring)
  1444. {
  1445. struct drm_device *dev = ring->dev;
  1446. struct drm_i915_private *dev_priv = dev->dev_private;
  1447. u32 tmp = I915_READ_CTL(ring);
  1448. if (tmp & RING_WAIT) {
  1449. DRM_ERROR("Kicking stuck wait on %s\n",
  1450. ring->name);
  1451. I915_WRITE_CTL(ring, tmp);
  1452. return true;
  1453. }
  1454. return false;
  1455. }
  1456. static bool i915_hangcheck_hung(struct drm_device *dev)
  1457. {
  1458. drm_i915_private_t *dev_priv = dev->dev_private;
  1459. if (dev_priv->gpu_error.hangcheck_count++ > 1) {
  1460. bool hung = true;
  1461. DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
  1462. i915_handle_error(dev, true);
  1463. if (!IS_GEN2(dev)) {
  1464. struct intel_ring_buffer *ring;
  1465. int i;
  1466. /* Is the chip hanging on a WAIT_FOR_EVENT?
  1467. * If so we can simply poke the RB_WAIT bit
  1468. * and break the hang. This should work on
  1469. * all but the second generation chipsets.
  1470. */
  1471. for_each_ring(ring, dev_priv, i)
  1472. hung &= !kick_ring(ring);
  1473. }
  1474. return hung;
  1475. }
  1476. return false;
  1477. }
  1478. /**
  1479. * This is called when the chip hasn't reported back with completed
  1480. * batchbuffers in a long time. The first time this is called we simply record
  1481. * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
  1482. * again, we assume the chip is wedged and try to fix it.
  1483. */
  1484. void i915_hangcheck_elapsed(unsigned long data)
  1485. {
  1486. struct drm_device *dev = (struct drm_device *)data;
  1487. drm_i915_private_t *dev_priv = dev->dev_private;
  1488. uint32_t acthd[I915_NUM_RINGS], instdone[I915_NUM_INSTDONE_REG];
  1489. struct intel_ring_buffer *ring;
  1490. bool err = false, idle;
  1491. int

Large files files are truncated, but you can click here to view the full file