i915_irq.c 32 KB

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