i915_irq.c 33 KB

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