i915_irq.c 34 KB

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