i915_irq.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  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. #include <linux/sysrq.h>
  29. #include "drmP.h"
  30. #include "drm.h"
  31. #include "i915_drm.h"
  32. #include "i915_drv.h"
  33. #include "i915_trace.h"
  34. #include "intel_drv.h"
  35. #define MAX_NOPID ((u32)~0)
  36. /**
  37. * Interrupts that are always left unmasked.
  38. *
  39. * Since pipe events are edge-triggered from the PIPESTAT register to IIR,
  40. * we leave them always unmasked in IMR and then control enabling them through
  41. * PIPESTAT alone.
  42. */
  43. #define I915_INTERRUPT_ENABLE_FIX (I915_ASLE_INTERRUPT | \
  44. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \
  45. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \
  46. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  47. /** Interrupts that we mask and unmask at runtime. */
  48. #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT)
  49. #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\
  50. PIPE_VBLANK_INTERRUPT_STATUS)
  51. #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\
  52. PIPE_VBLANK_INTERRUPT_ENABLE)
  53. #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \
  54. DRM_I915_VBLANK_PIPE_B)
  55. void
  56. igdng_enable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask)
  57. {
  58. if ((dev_priv->gt_irq_mask_reg & mask) != 0) {
  59. dev_priv->gt_irq_mask_reg &= ~mask;
  60. I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg);
  61. (void) I915_READ(GTIMR);
  62. }
  63. }
  64. static inline void
  65. igdng_disable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask)
  66. {
  67. if ((dev_priv->gt_irq_mask_reg & mask) != mask) {
  68. dev_priv->gt_irq_mask_reg |= mask;
  69. I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg);
  70. (void) I915_READ(GTIMR);
  71. }
  72. }
  73. /* For display hotplug interrupt */
  74. void
  75. igdng_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  76. {
  77. if ((dev_priv->irq_mask_reg & mask) != 0) {
  78. dev_priv->irq_mask_reg &= ~mask;
  79. I915_WRITE(DEIMR, dev_priv->irq_mask_reg);
  80. (void) I915_READ(DEIMR);
  81. }
  82. }
  83. static inline void
  84. igdng_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  85. {
  86. if ((dev_priv->irq_mask_reg & mask) != mask) {
  87. dev_priv->irq_mask_reg |= mask;
  88. I915_WRITE(DEIMR, dev_priv->irq_mask_reg);
  89. (void) I915_READ(DEIMR);
  90. }
  91. }
  92. void
  93. i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask)
  94. {
  95. if ((dev_priv->irq_mask_reg & mask) != 0) {
  96. dev_priv->irq_mask_reg &= ~mask;
  97. I915_WRITE(IMR, dev_priv->irq_mask_reg);
  98. (void) I915_READ(IMR);
  99. }
  100. }
  101. static inline void
  102. i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask)
  103. {
  104. if ((dev_priv->irq_mask_reg & mask) != mask) {
  105. dev_priv->irq_mask_reg |= mask;
  106. I915_WRITE(IMR, dev_priv->irq_mask_reg);
  107. (void) I915_READ(IMR);
  108. }
  109. }
  110. static inline u32
  111. i915_pipestat(int pipe)
  112. {
  113. if (pipe == 0)
  114. return PIPEASTAT;
  115. if (pipe == 1)
  116. return PIPEBSTAT;
  117. BUG();
  118. }
  119. void
  120. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  121. {
  122. if ((dev_priv->pipestat[pipe] & mask) != mask) {
  123. u32 reg = i915_pipestat(pipe);
  124. dev_priv->pipestat[pipe] |= mask;
  125. /* Enable the interrupt, clear any pending status */
  126. I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16));
  127. (void) I915_READ(reg);
  128. }
  129. }
  130. void
  131. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  132. {
  133. if ((dev_priv->pipestat[pipe] & mask) != 0) {
  134. u32 reg = i915_pipestat(pipe);
  135. dev_priv->pipestat[pipe] &= ~mask;
  136. I915_WRITE(reg, dev_priv->pipestat[pipe]);
  137. (void) I915_READ(reg);
  138. }
  139. }
  140. /**
  141. * i915_pipe_enabled - check if a pipe is enabled
  142. * @dev: DRM device
  143. * @pipe: pipe to check
  144. *
  145. * Reading certain registers when the pipe is disabled can hang the chip.
  146. * Use this routine to make sure the PLL is running and the pipe is active
  147. * before reading such registers if unsure.
  148. */
  149. static int
  150. i915_pipe_enabled(struct drm_device *dev, int pipe)
  151. {
  152. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  153. unsigned long pipeconf = pipe ? PIPEBCONF : PIPEACONF;
  154. if (I915_READ(pipeconf) & PIPEACONF_ENABLE)
  155. return 1;
  156. return 0;
  157. }
  158. /* Called from drm generic code, passed a 'crtc', which
  159. * we use as a pipe index
  160. */
  161. u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  162. {
  163. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  164. unsigned long high_frame;
  165. unsigned long low_frame;
  166. u32 high1, high2, low, count;
  167. high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH;
  168. low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL;
  169. if (!i915_pipe_enabled(dev, pipe)) {
  170. DRM_DEBUG("trying to get vblank count for disabled pipe %d\n", pipe);
  171. return 0;
  172. }
  173. /*
  174. * High & low register fields aren't synchronized, so make sure
  175. * we get a low value that's stable across two reads of the high
  176. * register.
  177. */
  178. do {
  179. high1 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  180. PIPE_FRAME_HIGH_SHIFT);
  181. low = ((I915_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
  182. PIPE_FRAME_LOW_SHIFT);
  183. high2 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  184. PIPE_FRAME_HIGH_SHIFT);
  185. } while (high1 != high2);
  186. count = (high1 << 8) | low;
  187. return count;
  188. }
  189. u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  190. {
  191. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  192. int reg = pipe ? PIPEB_FRMCOUNT_GM45 : PIPEA_FRMCOUNT_GM45;
  193. if (!i915_pipe_enabled(dev, pipe)) {
  194. DRM_DEBUG("trying to get vblank count for disabled pipe %d\n", pipe);
  195. return 0;
  196. }
  197. return I915_READ(reg);
  198. }
  199. /*
  200. * Handle hotplug events outside the interrupt handler proper.
  201. */
  202. static void i915_hotplug_work_func(struct work_struct *work)
  203. {
  204. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  205. hotplug_work);
  206. struct drm_device *dev = dev_priv->dev;
  207. struct drm_mode_config *mode_config = &dev->mode_config;
  208. struct drm_connector *connector;
  209. if (mode_config->num_connector) {
  210. list_for_each_entry(connector, &mode_config->connector_list, head) {
  211. struct intel_output *intel_output = to_intel_output(connector);
  212. if (intel_output->hot_plug)
  213. (*intel_output->hot_plug) (intel_output);
  214. }
  215. }
  216. /* Just fire off a uevent and let userspace tell us what to do */
  217. drm_sysfs_hotplug_event(dev);
  218. }
  219. irqreturn_t igdng_irq_handler(struct drm_device *dev)
  220. {
  221. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  222. int ret = IRQ_NONE;
  223. u32 de_iir, gt_iir, de_ier;
  224. u32 new_de_iir, new_gt_iir;
  225. struct drm_i915_master_private *master_priv;
  226. /* disable master interrupt before clearing iir */
  227. de_ier = I915_READ(DEIER);
  228. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  229. (void)I915_READ(DEIER);
  230. de_iir = I915_READ(DEIIR);
  231. gt_iir = I915_READ(GTIIR);
  232. for (;;) {
  233. if (de_iir == 0 && gt_iir == 0)
  234. break;
  235. ret = IRQ_HANDLED;
  236. I915_WRITE(DEIIR, de_iir);
  237. new_de_iir = I915_READ(DEIIR);
  238. I915_WRITE(GTIIR, gt_iir);
  239. new_gt_iir = I915_READ(GTIIR);
  240. if (dev->primary->master) {
  241. master_priv = dev->primary->master->driver_priv;
  242. if (master_priv->sarea_priv)
  243. master_priv->sarea_priv->last_dispatch =
  244. READ_BREADCRUMB(dev_priv);
  245. }
  246. if (gt_iir & GT_USER_INTERRUPT) {
  247. u32 seqno = i915_get_gem_seqno(dev);
  248. dev_priv->mm.irq_gem_seqno = seqno;
  249. trace_i915_gem_request_complete(dev, seqno);
  250. DRM_WAKEUP(&dev_priv->irq_queue);
  251. }
  252. de_iir = new_de_iir;
  253. gt_iir = new_gt_iir;
  254. }
  255. I915_WRITE(DEIER, de_ier);
  256. (void)I915_READ(DEIER);
  257. return ret;
  258. }
  259. /**
  260. * i915_error_work_func - do process context error handling work
  261. * @work: work struct
  262. *
  263. * Fire an error uevent so userspace can see that a hang or error
  264. * was detected.
  265. */
  266. static void i915_error_work_func(struct work_struct *work)
  267. {
  268. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  269. error_work);
  270. struct drm_device *dev = dev_priv->dev;
  271. char *error_event[] = { "ERROR=1", NULL };
  272. char *reset_event[] = { "RESET=1", NULL };
  273. char *reset_done_event[] = { "ERROR=0", NULL };
  274. DRM_DEBUG("generating error event\n");
  275. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  276. if (atomic_read(&dev_priv->mm.wedged)) {
  277. if (IS_I965G(dev)) {
  278. DRM_DEBUG("resetting chip\n");
  279. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event);
  280. if (!i965_reset(dev, GDRST_RENDER)) {
  281. atomic_set(&dev_priv->mm.wedged, 0);
  282. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event);
  283. }
  284. } else {
  285. printk("reboot required\n");
  286. }
  287. }
  288. }
  289. /**
  290. * i915_capture_error_state - capture an error record for later analysis
  291. * @dev: drm device
  292. *
  293. * Should be called when an error is detected (either a hang or an error
  294. * interrupt) to capture error state from the time of the error. Fills
  295. * out a structure which becomes available in debugfs for user level tools
  296. * to pick up.
  297. */
  298. static void i915_capture_error_state(struct drm_device *dev)
  299. {
  300. struct drm_i915_private *dev_priv = dev->dev_private;
  301. struct drm_i915_error_state *error;
  302. unsigned long flags;
  303. spin_lock_irqsave(&dev_priv->error_lock, flags);
  304. if (dev_priv->first_error)
  305. goto out;
  306. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  307. if (!error) {
  308. DRM_DEBUG("out ot memory, not capturing error state\n");
  309. goto out;
  310. }
  311. error->eir = I915_READ(EIR);
  312. error->pgtbl_er = I915_READ(PGTBL_ER);
  313. error->pipeastat = I915_READ(PIPEASTAT);
  314. error->pipebstat = I915_READ(PIPEBSTAT);
  315. error->instpm = I915_READ(INSTPM);
  316. if (!IS_I965G(dev)) {
  317. error->ipeir = I915_READ(IPEIR);
  318. error->ipehr = I915_READ(IPEHR);
  319. error->instdone = I915_READ(INSTDONE);
  320. error->acthd = I915_READ(ACTHD);
  321. } else {
  322. error->ipeir = I915_READ(IPEIR_I965);
  323. error->ipehr = I915_READ(IPEHR_I965);
  324. error->instdone = I915_READ(INSTDONE_I965);
  325. error->instps = I915_READ(INSTPS);
  326. error->instdone1 = I915_READ(INSTDONE1);
  327. error->acthd = I915_READ(ACTHD_I965);
  328. }
  329. do_gettimeofday(&error->time);
  330. dev_priv->first_error = error;
  331. out:
  332. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  333. }
  334. /**
  335. * i915_handle_error - handle an error interrupt
  336. * @dev: drm device
  337. *
  338. * Do some basic checking of regsiter state at error interrupt time and
  339. * dump it to the syslog. Also call i915_capture_error_state() to make
  340. * sure we get a record and make it available in debugfs. Fire a uevent
  341. * so userspace knows something bad happened (should trigger collection
  342. * of a ring dump etc.).
  343. */
  344. static void i915_handle_error(struct drm_device *dev, bool wedged)
  345. {
  346. struct drm_i915_private *dev_priv = dev->dev_private;
  347. u32 eir = I915_READ(EIR);
  348. u32 pipea_stats = I915_READ(PIPEASTAT);
  349. u32 pipeb_stats = I915_READ(PIPEBSTAT);
  350. i915_capture_error_state(dev);
  351. printk(KERN_ERR "render error detected, EIR: 0x%08x\n",
  352. eir);
  353. if (IS_G4X(dev)) {
  354. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  355. u32 ipeir = I915_READ(IPEIR_I965);
  356. printk(KERN_ERR " IPEIR: 0x%08x\n",
  357. I915_READ(IPEIR_I965));
  358. printk(KERN_ERR " IPEHR: 0x%08x\n",
  359. I915_READ(IPEHR_I965));
  360. printk(KERN_ERR " INSTDONE: 0x%08x\n",
  361. I915_READ(INSTDONE_I965));
  362. printk(KERN_ERR " INSTPS: 0x%08x\n",
  363. I915_READ(INSTPS));
  364. printk(KERN_ERR " INSTDONE1: 0x%08x\n",
  365. I915_READ(INSTDONE1));
  366. printk(KERN_ERR " ACTHD: 0x%08x\n",
  367. I915_READ(ACTHD_I965));
  368. I915_WRITE(IPEIR_I965, ipeir);
  369. (void)I915_READ(IPEIR_I965);
  370. }
  371. if (eir & GM45_ERROR_PAGE_TABLE) {
  372. u32 pgtbl_err = I915_READ(PGTBL_ER);
  373. printk(KERN_ERR "page table error\n");
  374. printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
  375. pgtbl_err);
  376. I915_WRITE(PGTBL_ER, pgtbl_err);
  377. (void)I915_READ(PGTBL_ER);
  378. }
  379. }
  380. if (IS_I9XX(dev)) {
  381. if (eir & I915_ERROR_PAGE_TABLE) {
  382. u32 pgtbl_err = I915_READ(PGTBL_ER);
  383. printk(KERN_ERR "page table error\n");
  384. printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
  385. pgtbl_err);
  386. I915_WRITE(PGTBL_ER, pgtbl_err);
  387. (void)I915_READ(PGTBL_ER);
  388. }
  389. }
  390. if (eir & I915_ERROR_MEMORY_REFRESH) {
  391. printk(KERN_ERR "memory refresh error\n");
  392. printk(KERN_ERR "PIPEASTAT: 0x%08x\n",
  393. pipea_stats);
  394. printk(KERN_ERR "PIPEBSTAT: 0x%08x\n",
  395. pipeb_stats);
  396. /* pipestat has already been acked */
  397. }
  398. if (eir & I915_ERROR_INSTRUCTION) {
  399. printk(KERN_ERR "instruction error\n");
  400. printk(KERN_ERR " INSTPM: 0x%08x\n",
  401. I915_READ(INSTPM));
  402. if (!IS_I965G(dev)) {
  403. u32 ipeir = I915_READ(IPEIR);
  404. printk(KERN_ERR " IPEIR: 0x%08x\n",
  405. I915_READ(IPEIR));
  406. printk(KERN_ERR " IPEHR: 0x%08x\n",
  407. I915_READ(IPEHR));
  408. printk(KERN_ERR " INSTDONE: 0x%08x\n",
  409. I915_READ(INSTDONE));
  410. printk(KERN_ERR " ACTHD: 0x%08x\n",
  411. I915_READ(ACTHD));
  412. I915_WRITE(IPEIR, ipeir);
  413. (void)I915_READ(IPEIR);
  414. } else {
  415. u32 ipeir = I915_READ(IPEIR_I965);
  416. printk(KERN_ERR " IPEIR: 0x%08x\n",
  417. I915_READ(IPEIR_I965));
  418. printk(KERN_ERR " IPEHR: 0x%08x\n",
  419. I915_READ(IPEHR_I965));
  420. printk(KERN_ERR " INSTDONE: 0x%08x\n",
  421. I915_READ(INSTDONE_I965));
  422. printk(KERN_ERR " INSTPS: 0x%08x\n",
  423. I915_READ(INSTPS));
  424. printk(KERN_ERR " INSTDONE1: 0x%08x\n",
  425. I915_READ(INSTDONE1));
  426. printk(KERN_ERR " ACTHD: 0x%08x\n",
  427. I915_READ(ACTHD_I965));
  428. I915_WRITE(IPEIR_I965, ipeir);
  429. (void)I915_READ(IPEIR_I965);
  430. }
  431. }
  432. I915_WRITE(EIR, eir);
  433. (void)I915_READ(EIR);
  434. eir = I915_READ(EIR);
  435. if (eir) {
  436. /*
  437. * some errors might have become stuck,
  438. * mask them.
  439. */
  440. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  441. I915_WRITE(EMR, I915_READ(EMR) | eir);
  442. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  443. }
  444. if (wedged) {
  445. atomic_set(&dev_priv->mm.wedged, 1);
  446. /*
  447. * Wakeup waiting processes so they don't hang
  448. */
  449. printk("i915: Waking up sleeping processes\n");
  450. DRM_WAKEUP(&dev_priv->irq_queue);
  451. }
  452. queue_work(dev_priv->wq, &dev_priv->error_work);
  453. }
  454. irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
  455. {
  456. struct drm_device *dev = (struct drm_device *) arg;
  457. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  458. struct drm_i915_master_private *master_priv;
  459. u32 iir, new_iir;
  460. u32 pipea_stats, pipeb_stats;
  461. u32 vblank_status;
  462. u32 vblank_enable;
  463. int vblank = 0;
  464. unsigned long irqflags;
  465. int irq_received;
  466. int ret = IRQ_NONE;
  467. atomic_inc(&dev_priv->irq_received);
  468. if (IS_IGDNG(dev))
  469. return igdng_irq_handler(dev);
  470. iir = I915_READ(IIR);
  471. if (IS_I965G(dev)) {
  472. vblank_status = I915_START_VBLANK_INTERRUPT_STATUS;
  473. vblank_enable = PIPE_START_VBLANK_INTERRUPT_ENABLE;
  474. } else {
  475. vblank_status = I915_VBLANK_INTERRUPT_STATUS;
  476. vblank_enable = I915_VBLANK_INTERRUPT_ENABLE;
  477. }
  478. for (;;) {
  479. irq_received = iir != 0;
  480. /* Can't rely on pipestat interrupt bit in iir as it might
  481. * have been cleared after the pipestat interrupt was received.
  482. * It doesn't set the bit in iir again, but it still produces
  483. * interrupts (for non-MSI).
  484. */
  485. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  486. pipea_stats = I915_READ(PIPEASTAT);
  487. pipeb_stats = I915_READ(PIPEBSTAT);
  488. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  489. i915_handle_error(dev, false);
  490. /*
  491. * Clear the PIPE(A|B)STAT regs before the IIR
  492. */
  493. if (pipea_stats & 0x8000ffff) {
  494. if (pipea_stats & PIPE_FIFO_UNDERRUN_STATUS)
  495. DRM_DEBUG("pipe a underrun\n");
  496. I915_WRITE(PIPEASTAT, pipea_stats);
  497. irq_received = 1;
  498. }
  499. if (pipeb_stats & 0x8000ffff) {
  500. if (pipeb_stats & PIPE_FIFO_UNDERRUN_STATUS)
  501. DRM_DEBUG("pipe b underrun\n");
  502. I915_WRITE(PIPEBSTAT, pipeb_stats);
  503. irq_received = 1;
  504. }
  505. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  506. if (!irq_received)
  507. break;
  508. ret = IRQ_HANDLED;
  509. /* Consume port. Then clear IIR or we'll miss events */
  510. if ((I915_HAS_HOTPLUG(dev)) &&
  511. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  512. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  513. DRM_DEBUG("hotplug event received, stat 0x%08x\n",
  514. hotplug_status);
  515. if (hotplug_status & dev_priv->hotplug_supported_mask)
  516. queue_work(dev_priv->wq,
  517. &dev_priv->hotplug_work);
  518. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  519. I915_READ(PORT_HOTPLUG_STAT);
  520. /* EOS interrupts occurs */
  521. if (IS_IGD(dev) &&
  522. (hotplug_status & CRT_EOS_INT_STATUS)) {
  523. u32 temp;
  524. DRM_DEBUG("EOS interrupt occurs\n");
  525. /* status is already cleared */
  526. temp = I915_READ(ADPA);
  527. temp &= ~ADPA_DAC_ENABLE;
  528. I915_WRITE(ADPA, temp);
  529. temp = I915_READ(PORT_HOTPLUG_EN);
  530. temp &= ~CRT_EOS_INT_EN;
  531. I915_WRITE(PORT_HOTPLUG_EN, temp);
  532. temp = I915_READ(PORT_HOTPLUG_STAT);
  533. if (temp & CRT_EOS_INT_STATUS)
  534. I915_WRITE(PORT_HOTPLUG_STAT,
  535. CRT_EOS_INT_STATUS);
  536. }
  537. }
  538. I915_WRITE(IIR, iir);
  539. new_iir = I915_READ(IIR); /* Flush posted writes */
  540. if (dev->primary->master) {
  541. master_priv = dev->primary->master->driver_priv;
  542. if (master_priv->sarea_priv)
  543. master_priv->sarea_priv->last_dispatch =
  544. READ_BREADCRUMB(dev_priv);
  545. }
  546. if (iir & I915_USER_INTERRUPT) {
  547. u32 seqno = i915_get_gem_seqno(dev);
  548. dev_priv->mm.irq_gem_seqno = seqno;
  549. trace_i915_gem_request_complete(dev, seqno);
  550. DRM_WAKEUP(&dev_priv->irq_queue);
  551. dev_priv->hangcheck_count = 0;
  552. mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD);
  553. }
  554. if (pipea_stats & vblank_status) {
  555. vblank++;
  556. drm_handle_vblank(dev, 0);
  557. }
  558. if (pipeb_stats & vblank_status) {
  559. vblank++;
  560. drm_handle_vblank(dev, 1);
  561. }
  562. if ((pipeb_stats & I915_LEGACY_BLC_EVENT_STATUS) ||
  563. (iir & I915_ASLE_INTERRUPT))
  564. opregion_asle_intr(dev);
  565. /* With MSI, interrupts are only generated when iir
  566. * transitions from zero to nonzero. If another bit got
  567. * set while we were handling the existing iir bits, then
  568. * we would never get another interrupt.
  569. *
  570. * This is fine on non-MSI as well, as if we hit this path
  571. * we avoid exiting the interrupt handler only to generate
  572. * another one.
  573. *
  574. * Note that for MSI this could cause a stray interrupt report
  575. * if an interrupt landed in the time between writing IIR and
  576. * the posting read. This should be rare enough to never
  577. * trigger the 99% of 100,000 interrupts test for disabling
  578. * stray interrupts.
  579. */
  580. iir = new_iir;
  581. }
  582. return ret;
  583. }
  584. static int i915_emit_irq(struct drm_device * dev)
  585. {
  586. drm_i915_private_t *dev_priv = dev->dev_private;
  587. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  588. RING_LOCALS;
  589. i915_kernel_lost_context(dev);
  590. DRM_DEBUG("\n");
  591. dev_priv->counter++;
  592. if (dev_priv->counter > 0x7FFFFFFFUL)
  593. dev_priv->counter = 1;
  594. if (master_priv->sarea_priv)
  595. master_priv->sarea_priv->last_enqueue = dev_priv->counter;
  596. BEGIN_LP_RING(4);
  597. OUT_RING(MI_STORE_DWORD_INDEX);
  598. OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
  599. OUT_RING(dev_priv->counter);
  600. OUT_RING(MI_USER_INTERRUPT);
  601. ADVANCE_LP_RING();
  602. return dev_priv->counter;
  603. }
  604. void i915_user_irq_get(struct drm_device *dev)
  605. {
  606. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  607. unsigned long irqflags;
  608. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  609. if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) {
  610. if (IS_IGDNG(dev))
  611. igdng_enable_graphics_irq(dev_priv, GT_USER_INTERRUPT);
  612. else
  613. i915_enable_irq(dev_priv, I915_USER_INTERRUPT);
  614. }
  615. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  616. }
  617. void i915_user_irq_put(struct drm_device *dev)
  618. {
  619. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  620. unsigned long irqflags;
  621. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  622. BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0);
  623. if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) {
  624. if (IS_IGDNG(dev))
  625. igdng_disable_graphics_irq(dev_priv, GT_USER_INTERRUPT);
  626. else
  627. i915_disable_irq(dev_priv, I915_USER_INTERRUPT);
  628. }
  629. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  630. }
  631. void i915_trace_irq_get(struct drm_device *dev, u32 seqno)
  632. {
  633. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  634. if (dev_priv->trace_irq_seqno == 0)
  635. i915_user_irq_get(dev);
  636. dev_priv->trace_irq_seqno = seqno;
  637. }
  638. static int i915_wait_irq(struct drm_device * dev, int irq_nr)
  639. {
  640. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  641. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  642. int ret = 0;
  643. DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
  644. READ_BREADCRUMB(dev_priv));
  645. if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
  646. if (master_priv->sarea_priv)
  647. master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  648. return 0;
  649. }
  650. if (master_priv->sarea_priv)
  651. master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
  652. i915_user_irq_get(dev);
  653. DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
  654. READ_BREADCRUMB(dev_priv) >= irq_nr);
  655. i915_user_irq_put(dev);
  656. if (ret == -EBUSY) {
  657. DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
  658. READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
  659. }
  660. return ret;
  661. }
  662. /* Needs the lock as it touches the ring.
  663. */
  664. int i915_irq_emit(struct drm_device *dev, void *data,
  665. struct drm_file *file_priv)
  666. {
  667. drm_i915_private_t *dev_priv = dev->dev_private;
  668. drm_i915_irq_emit_t *emit = data;
  669. int result;
  670. if (!dev_priv || !dev_priv->ring.virtual_start) {
  671. DRM_ERROR("called with no initialization\n");
  672. return -EINVAL;
  673. }
  674. RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
  675. mutex_lock(&dev->struct_mutex);
  676. result = i915_emit_irq(dev);
  677. mutex_unlock(&dev->struct_mutex);
  678. if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
  679. DRM_ERROR("copy_to_user\n");
  680. return -EFAULT;
  681. }
  682. return 0;
  683. }
  684. /* Doesn't need the hardware lock.
  685. */
  686. int i915_irq_wait(struct drm_device *dev, void *data,
  687. struct drm_file *file_priv)
  688. {
  689. drm_i915_private_t *dev_priv = dev->dev_private;
  690. drm_i915_irq_wait_t *irqwait = data;
  691. if (!dev_priv) {
  692. DRM_ERROR("called with no initialization\n");
  693. return -EINVAL;
  694. }
  695. return i915_wait_irq(dev, irqwait->irq_seq);
  696. }
  697. /* Called from drm generic code, passed 'crtc' which
  698. * we use as a pipe index
  699. */
  700. int i915_enable_vblank(struct drm_device *dev, int pipe)
  701. {
  702. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  703. unsigned long irqflags;
  704. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  705. u32 pipeconf;
  706. pipeconf = I915_READ(pipeconf_reg);
  707. if (!(pipeconf & PIPEACONF_ENABLE))
  708. return -EINVAL;
  709. if (IS_IGDNG(dev))
  710. return 0;
  711. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  712. if (IS_I965G(dev))
  713. i915_enable_pipestat(dev_priv, pipe,
  714. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  715. else
  716. i915_enable_pipestat(dev_priv, pipe,
  717. PIPE_VBLANK_INTERRUPT_ENABLE);
  718. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  719. return 0;
  720. }
  721. /* Called from drm generic code, passed 'crtc' which
  722. * we use as a pipe index
  723. */
  724. void i915_disable_vblank(struct drm_device *dev, int pipe)
  725. {
  726. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  727. unsigned long irqflags;
  728. if (IS_IGDNG(dev))
  729. return;
  730. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  731. i915_disable_pipestat(dev_priv, pipe,
  732. PIPE_VBLANK_INTERRUPT_ENABLE |
  733. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  734. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  735. }
  736. void i915_enable_interrupt (struct drm_device *dev)
  737. {
  738. struct drm_i915_private *dev_priv = dev->dev_private;
  739. if (!IS_IGDNG(dev))
  740. opregion_enable_asle(dev);
  741. dev_priv->irq_enabled = 1;
  742. }
  743. /* Set the vblank monitor pipe
  744. */
  745. int i915_vblank_pipe_set(struct drm_device *dev, void *data,
  746. struct drm_file *file_priv)
  747. {
  748. drm_i915_private_t *dev_priv = dev->dev_private;
  749. if (!dev_priv) {
  750. DRM_ERROR("called with no initialization\n");
  751. return -EINVAL;
  752. }
  753. return 0;
  754. }
  755. int i915_vblank_pipe_get(struct drm_device *dev, void *data,
  756. struct drm_file *file_priv)
  757. {
  758. drm_i915_private_t *dev_priv = dev->dev_private;
  759. drm_i915_vblank_pipe_t *pipe = data;
  760. if (!dev_priv) {
  761. DRM_ERROR("called with no initialization\n");
  762. return -EINVAL;
  763. }
  764. pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  765. return 0;
  766. }
  767. /**
  768. * Schedule buffer swap at given vertical blank.
  769. */
  770. int i915_vblank_swap(struct drm_device *dev, void *data,
  771. struct drm_file *file_priv)
  772. {
  773. /* The delayed swap mechanism was fundamentally racy, and has been
  774. * removed. The model was that the client requested a delayed flip/swap
  775. * from the kernel, then waited for vblank before continuing to perform
  776. * rendering. The problem was that the kernel might wake the client
  777. * up before it dispatched the vblank swap (since the lock has to be
  778. * held while touching the ringbuffer), in which case the client would
  779. * clear and start the next frame before the swap occurred, and
  780. * flicker would occur in addition to likely missing the vblank.
  781. *
  782. * In the absence of this ioctl, userland falls back to a correct path
  783. * of waiting for a vblank, then dispatching the swap on its own.
  784. * Context switching to userland and back is plenty fast enough for
  785. * meeting the requirements of vblank swapping.
  786. */
  787. return -EINVAL;
  788. }
  789. struct drm_i915_gem_request *i915_get_tail_request(struct drm_device *dev) {
  790. drm_i915_private_t *dev_priv = dev->dev_private;
  791. return list_entry(dev_priv->mm.request_list.prev, struct drm_i915_gem_request, list);
  792. }
  793. /**
  794. * This is called when the chip hasn't reported back with completed
  795. * batchbuffers in a long time. The first time this is called we simply record
  796. * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
  797. * again, we assume the chip is wedged and try to fix it.
  798. */
  799. void i915_hangcheck_elapsed(unsigned long data)
  800. {
  801. struct drm_device *dev = (struct drm_device *)data;
  802. drm_i915_private_t *dev_priv = dev->dev_private;
  803. uint32_t acthd;
  804. if (!IS_I965G(dev))
  805. acthd = I915_READ(ACTHD);
  806. else
  807. acthd = I915_READ(ACTHD_I965);
  808. /* If all work is done then ACTHD clearly hasn't advanced. */
  809. if (list_empty(&dev_priv->mm.request_list) ||
  810. i915_seqno_passed(i915_get_gem_seqno(dev), i915_get_tail_request(dev)->seqno)) {
  811. dev_priv->hangcheck_count = 0;
  812. return;
  813. }
  814. if (dev_priv->last_acthd == acthd && dev_priv->hangcheck_count > 0) {
  815. DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
  816. i915_handle_error(dev, true);
  817. return;
  818. }
  819. /* Reset timer case chip hangs without another request being added */
  820. mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD);
  821. if (acthd != dev_priv->last_acthd)
  822. dev_priv->hangcheck_count = 0;
  823. else
  824. dev_priv->hangcheck_count++;
  825. dev_priv->last_acthd = acthd;
  826. }
  827. /* drm_dma.h hooks
  828. */
  829. static void igdng_irq_preinstall(struct drm_device *dev)
  830. {
  831. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  832. I915_WRITE(HWSTAM, 0xeffe);
  833. /* XXX hotplug from PCH */
  834. I915_WRITE(DEIMR, 0xffffffff);
  835. I915_WRITE(DEIER, 0x0);
  836. (void) I915_READ(DEIER);
  837. /* and GT */
  838. I915_WRITE(GTIMR, 0xffffffff);
  839. I915_WRITE(GTIER, 0x0);
  840. (void) I915_READ(GTIER);
  841. }
  842. static int igdng_irq_postinstall(struct drm_device *dev)
  843. {
  844. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  845. /* enable kind of interrupts always enabled */
  846. u32 display_mask = DE_MASTER_IRQ_CONTROL /*| DE_PCH_EVENT */;
  847. u32 render_mask = GT_USER_INTERRUPT;
  848. dev_priv->irq_mask_reg = ~display_mask;
  849. dev_priv->de_irq_enable_reg = display_mask;
  850. /* should always can generate irq */
  851. I915_WRITE(DEIIR, I915_READ(DEIIR));
  852. I915_WRITE(DEIMR, dev_priv->irq_mask_reg);
  853. I915_WRITE(DEIER, dev_priv->de_irq_enable_reg);
  854. (void) I915_READ(DEIER);
  855. /* user interrupt should be enabled, but masked initial */
  856. dev_priv->gt_irq_mask_reg = 0xffffffff;
  857. dev_priv->gt_irq_enable_reg = render_mask;
  858. I915_WRITE(GTIIR, I915_READ(GTIIR));
  859. I915_WRITE(GTIMR, dev_priv->gt_irq_mask_reg);
  860. I915_WRITE(GTIER, dev_priv->gt_irq_enable_reg);
  861. (void) I915_READ(GTIER);
  862. return 0;
  863. }
  864. void i915_driver_irq_preinstall(struct drm_device * dev)
  865. {
  866. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  867. atomic_set(&dev_priv->irq_received, 0);
  868. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  869. INIT_WORK(&dev_priv->error_work, i915_error_work_func);
  870. if (IS_IGDNG(dev)) {
  871. igdng_irq_preinstall(dev);
  872. return;
  873. }
  874. if (I915_HAS_HOTPLUG(dev)) {
  875. I915_WRITE(PORT_HOTPLUG_EN, 0);
  876. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  877. }
  878. I915_WRITE(HWSTAM, 0xeffe);
  879. I915_WRITE(PIPEASTAT, 0);
  880. I915_WRITE(PIPEBSTAT, 0);
  881. I915_WRITE(IMR, 0xffffffff);
  882. I915_WRITE(IER, 0x0);
  883. (void) I915_READ(IER);
  884. }
  885. int i915_driver_irq_postinstall(struct drm_device *dev)
  886. {
  887. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  888. u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR;
  889. u32 error_mask;
  890. DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
  891. dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  892. if (IS_IGDNG(dev))
  893. return igdng_irq_postinstall(dev);
  894. /* Unmask the interrupts that we always want on. */
  895. dev_priv->irq_mask_reg = ~I915_INTERRUPT_ENABLE_FIX;
  896. dev_priv->pipestat[0] = 0;
  897. dev_priv->pipestat[1] = 0;
  898. if (I915_HAS_HOTPLUG(dev)) {
  899. u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  900. /* Leave other bits alone */
  901. hotplug_en |= HOTPLUG_EN_MASK;
  902. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  903. dev_priv->hotplug_supported_mask = CRT_HOTPLUG_INT_STATUS |
  904. TV_HOTPLUG_INT_STATUS | SDVOC_HOTPLUG_INT_STATUS |
  905. SDVOB_HOTPLUG_INT_STATUS;
  906. if (IS_G4X(dev)) {
  907. dev_priv->hotplug_supported_mask |=
  908. HDMIB_HOTPLUG_INT_STATUS |
  909. HDMIC_HOTPLUG_INT_STATUS |
  910. HDMID_HOTPLUG_INT_STATUS;
  911. }
  912. /* Enable in IER... */
  913. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  914. /* and unmask in IMR */
  915. i915_enable_irq(dev_priv, I915_DISPLAY_PORT_INTERRUPT);
  916. }
  917. /*
  918. * Enable some error detection, note the instruction error mask
  919. * bit is reserved, so we leave it masked.
  920. */
  921. if (IS_G4X(dev)) {
  922. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  923. GM45_ERROR_MEM_PRIV |
  924. GM45_ERROR_CP_PRIV |
  925. I915_ERROR_MEMORY_REFRESH);
  926. } else {
  927. error_mask = ~(I915_ERROR_PAGE_TABLE |
  928. I915_ERROR_MEMORY_REFRESH);
  929. }
  930. I915_WRITE(EMR, error_mask);
  931. /* Disable pipe interrupt enables, clear pending pipe status */
  932. I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff);
  933. I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff);
  934. /* Clear pending interrupt status */
  935. I915_WRITE(IIR, I915_READ(IIR));
  936. I915_WRITE(IER, enable_mask);
  937. I915_WRITE(IMR, dev_priv->irq_mask_reg);
  938. (void) I915_READ(IER);
  939. opregion_enable_asle(dev);
  940. return 0;
  941. }
  942. static void igdng_irq_uninstall(struct drm_device *dev)
  943. {
  944. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  945. I915_WRITE(HWSTAM, 0xffffffff);
  946. I915_WRITE(DEIMR, 0xffffffff);
  947. I915_WRITE(DEIER, 0x0);
  948. I915_WRITE(DEIIR, I915_READ(DEIIR));
  949. I915_WRITE(GTIMR, 0xffffffff);
  950. I915_WRITE(GTIER, 0x0);
  951. I915_WRITE(GTIIR, I915_READ(GTIIR));
  952. }
  953. void i915_driver_irq_uninstall(struct drm_device * dev)
  954. {
  955. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  956. if (!dev_priv)
  957. return;
  958. dev_priv->vblank_pipe = 0;
  959. if (IS_IGDNG(dev)) {
  960. igdng_irq_uninstall(dev);
  961. return;
  962. }
  963. if (I915_HAS_HOTPLUG(dev)) {
  964. I915_WRITE(PORT_HOTPLUG_EN, 0);
  965. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  966. }
  967. I915_WRITE(HWSTAM, 0xffffffff);
  968. I915_WRITE(PIPEASTAT, 0);
  969. I915_WRITE(PIPEBSTAT, 0);
  970. I915_WRITE(IMR, 0xffffffff);
  971. I915_WRITE(IER, 0x0);
  972. I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff);
  973. I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff);
  974. I915_WRITE(IIR, I915_READ(IIR));
  975. }