i915_irq.c 33 KB

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