i915_irq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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 "drmP.h"
  29. #include "drm.h"
  30. #include "i915_drm.h"
  31. #include "i915_drv.h"
  32. #include "intel_drv.h"
  33. #define MAX_NOPID ((u32)~0)
  34. /**
  35. * Interrupts that are always left unmasked.
  36. *
  37. * Since pipe events are edge-triggered from the PIPESTAT register to IIR,
  38. * we leave them always unmasked in IMR and then control enabling them through
  39. * PIPESTAT alone.
  40. */
  41. #define I915_INTERRUPT_ENABLE_FIX (I915_ASLE_INTERRUPT | \
  42. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \
  43. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT)
  44. /** Interrupts that we mask and unmask at runtime. */
  45. #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT)
  46. #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\
  47. PIPE_VBLANK_INTERRUPT_STATUS)
  48. #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\
  49. PIPE_VBLANK_INTERRUPT_ENABLE)
  50. #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \
  51. DRM_I915_VBLANK_PIPE_B)
  52. void
  53. i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask)
  54. {
  55. if ((dev_priv->irq_mask_reg & mask) != 0) {
  56. dev_priv->irq_mask_reg &= ~mask;
  57. I915_WRITE(IMR, dev_priv->irq_mask_reg);
  58. (void) I915_READ(IMR);
  59. }
  60. }
  61. static inline void
  62. i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask)
  63. {
  64. if ((dev_priv->irq_mask_reg & mask) != mask) {
  65. dev_priv->irq_mask_reg |= mask;
  66. I915_WRITE(IMR, dev_priv->irq_mask_reg);
  67. (void) I915_READ(IMR);
  68. }
  69. }
  70. static inline u32
  71. i915_pipestat(int pipe)
  72. {
  73. if (pipe == 0)
  74. return PIPEASTAT;
  75. if (pipe == 1)
  76. return PIPEBSTAT;
  77. BUG();
  78. }
  79. void
  80. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  81. {
  82. if ((dev_priv->pipestat[pipe] & mask) != mask) {
  83. u32 reg = i915_pipestat(pipe);
  84. dev_priv->pipestat[pipe] |= mask;
  85. /* Enable the interrupt, clear any pending status */
  86. I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16));
  87. (void) I915_READ(reg);
  88. }
  89. }
  90. void
  91. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  92. {
  93. if ((dev_priv->pipestat[pipe] & mask) != 0) {
  94. u32 reg = i915_pipestat(pipe);
  95. dev_priv->pipestat[pipe] &= ~mask;
  96. I915_WRITE(reg, dev_priv->pipestat[pipe]);
  97. (void) I915_READ(reg);
  98. }
  99. }
  100. /**
  101. * i915_pipe_enabled - check if a pipe is enabled
  102. * @dev: DRM device
  103. * @pipe: pipe to check
  104. *
  105. * Reading certain registers when the pipe is disabled can hang the chip.
  106. * Use this routine to make sure the PLL is running and the pipe is active
  107. * before reading such registers if unsure.
  108. */
  109. static int
  110. i915_pipe_enabled(struct drm_device *dev, int pipe)
  111. {
  112. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  113. unsigned long pipeconf = pipe ? PIPEBCONF : PIPEACONF;
  114. if (I915_READ(pipeconf) & PIPEACONF_ENABLE)
  115. return 1;
  116. return 0;
  117. }
  118. /* Called from drm generic code, passed a 'crtc', which
  119. * we use as a pipe index
  120. */
  121. u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  122. {
  123. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  124. unsigned long high_frame;
  125. unsigned long low_frame;
  126. u32 high1, high2, low, count;
  127. high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH;
  128. low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL;
  129. if (!i915_pipe_enabled(dev, pipe)) {
  130. DRM_ERROR("trying to get vblank count for disabled pipe %d\n", pipe);
  131. return 0;
  132. }
  133. /*
  134. * High & low register fields aren't synchronized, so make sure
  135. * we get a low value that's stable across two reads of the high
  136. * register.
  137. */
  138. do {
  139. high1 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  140. PIPE_FRAME_HIGH_SHIFT);
  141. low = ((I915_READ(low_frame) & PIPE_FRAME_LOW_MASK) >>
  142. PIPE_FRAME_LOW_SHIFT);
  143. high2 = ((I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK) >>
  144. PIPE_FRAME_HIGH_SHIFT);
  145. } while (high1 != high2);
  146. count = (high1 << 8) | low;
  147. return count;
  148. }
  149. u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  150. {
  151. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  152. int reg = pipe ? PIPEB_FRMCOUNT_GM45 : PIPEA_FRMCOUNT_GM45;
  153. if (!i915_pipe_enabled(dev, pipe)) {
  154. DRM_ERROR("trying to get vblank count for disabled pipe %d\n", pipe);
  155. return 0;
  156. }
  157. return I915_READ(reg);
  158. }
  159. /*
  160. * Handle hotplug events outside the interrupt handler proper.
  161. */
  162. static void i915_hotplug_work_func(struct work_struct *work)
  163. {
  164. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  165. hotplug_work);
  166. struct drm_device *dev = dev_priv->dev;
  167. /* Just fire off a uevent and let userspace tell us what to do */
  168. drm_sysfs_hotplug_event(dev);
  169. }
  170. irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
  171. {
  172. struct drm_device *dev = (struct drm_device *) arg;
  173. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  174. struct drm_i915_master_private *master_priv;
  175. u32 iir, new_iir;
  176. u32 pipea_stats, pipeb_stats;
  177. u32 vblank_status;
  178. u32 vblank_enable;
  179. int vblank = 0;
  180. unsigned long irqflags;
  181. int irq_received;
  182. int ret = IRQ_NONE;
  183. atomic_inc(&dev_priv->irq_received);
  184. iir = I915_READ(IIR);
  185. if (IS_I965G(dev)) {
  186. vblank_status = I915_START_VBLANK_INTERRUPT_STATUS;
  187. vblank_enable = PIPE_START_VBLANK_INTERRUPT_ENABLE;
  188. } else {
  189. vblank_status = I915_VBLANK_INTERRUPT_STATUS;
  190. vblank_enable = I915_VBLANK_INTERRUPT_ENABLE;
  191. }
  192. for (;;) {
  193. irq_received = iir != 0;
  194. /* Can't rely on pipestat interrupt bit in iir as it might
  195. * have been cleared after the pipestat interrupt was received.
  196. * It doesn't set the bit in iir again, but it still produces
  197. * interrupts (for non-MSI).
  198. */
  199. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  200. pipea_stats = I915_READ(PIPEASTAT);
  201. pipeb_stats = I915_READ(PIPEBSTAT);
  202. /*
  203. * Clear the PIPE(A|B)STAT regs before the IIR
  204. */
  205. if (pipea_stats & 0x8000ffff) {
  206. I915_WRITE(PIPEASTAT, pipea_stats);
  207. irq_received = 1;
  208. }
  209. if (pipeb_stats & 0x8000ffff) {
  210. I915_WRITE(PIPEBSTAT, pipeb_stats);
  211. irq_received = 1;
  212. }
  213. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  214. if (!irq_received)
  215. break;
  216. ret = IRQ_HANDLED;
  217. /* Consume port. Then clear IIR or we'll miss events */
  218. if ((I915_HAS_HOTPLUG(dev)) &&
  219. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  220. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  221. DRM_DEBUG("hotplug event received, stat 0x%08x\n",
  222. hotplug_status);
  223. if (hotplug_status & dev_priv->hotplug_supported_mask)
  224. schedule_work(&dev_priv->hotplug_work);
  225. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  226. I915_READ(PORT_HOTPLUG_STAT);
  227. }
  228. I915_WRITE(IIR, iir);
  229. new_iir = I915_READ(IIR); /* Flush posted writes */
  230. if (dev->primary->master) {
  231. master_priv = dev->primary->master->driver_priv;
  232. if (master_priv->sarea_priv)
  233. master_priv->sarea_priv->last_dispatch =
  234. READ_BREADCRUMB(dev_priv);
  235. }
  236. if (iir & I915_USER_INTERRUPT) {
  237. dev_priv->mm.irq_gem_seqno = i915_get_gem_seqno(dev);
  238. DRM_WAKEUP(&dev_priv->irq_queue);
  239. }
  240. if (pipea_stats & vblank_status) {
  241. vblank++;
  242. drm_handle_vblank(dev, 0);
  243. }
  244. if (pipeb_stats & vblank_status) {
  245. vblank++;
  246. drm_handle_vblank(dev, 1);
  247. }
  248. if ((pipeb_stats & I915_LEGACY_BLC_EVENT_STATUS) ||
  249. (iir & I915_ASLE_INTERRUPT))
  250. opregion_asle_intr(dev);
  251. /* With MSI, interrupts are only generated when iir
  252. * transitions from zero to nonzero. If another bit got
  253. * set while we were handling the existing iir bits, then
  254. * we would never get another interrupt.
  255. *
  256. * This is fine on non-MSI as well, as if we hit this path
  257. * we avoid exiting the interrupt handler only to generate
  258. * another one.
  259. *
  260. * Note that for MSI this could cause a stray interrupt report
  261. * if an interrupt landed in the time between writing IIR and
  262. * the posting read. This should be rare enough to never
  263. * trigger the 99% of 100,000 interrupts test for disabling
  264. * stray interrupts.
  265. */
  266. iir = new_iir;
  267. }
  268. return ret;
  269. }
  270. static int i915_emit_irq(struct drm_device * dev)
  271. {
  272. drm_i915_private_t *dev_priv = dev->dev_private;
  273. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  274. RING_LOCALS;
  275. i915_kernel_lost_context(dev);
  276. DRM_DEBUG("\n");
  277. dev_priv->counter++;
  278. if (dev_priv->counter > 0x7FFFFFFFUL)
  279. dev_priv->counter = 1;
  280. if (master_priv->sarea_priv)
  281. master_priv->sarea_priv->last_enqueue = dev_priv->counter;
  282. BEGIN_LP_RING(4);
  283. OUT_RING(MI_STORE_DWORD_INDEX);
  284. OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
  285. OUT_RING(dev_priv->counter);
  286. OUT_RING(MI_USER_INTERRUPT);
  287. ADVANCE_LP_RING();
  288. return dev_priv->counter;
  289. }
  290. void i915_user_irq_get(struct drm_device *dev)
  291. {
  292. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  293. unsigned long irqflags;
  294. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  295. if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1))
  296. i915_enable_irq(dev_priv, I915_USER_INTERRUPT);
  297. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  298. }
  299. void i915_user_irq_put(struct drm_device *dev)
  300. {
  301. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  302. unsigned long irqflags;
  303. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  304. BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0);
  305. if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0))
  306. i915_disable_irq(dev_priv, I915_USER_INTERRUPT);
  307. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  308. }
  309. static int i915_wait_irq(struct drm_device * dev, int irq_nr)
  310. {
  311. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  312. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  313. int ret = 0;
  314. DRM_DEBUG("irq_nr=%d breadcrumb=%d\n", irq_nr,
  315. READ_BREADCRUMB(dev_priv));
  316. if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
  317. if (master_priv->sarea_priv)
  318. master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  319. return 0;
  320. }
  321. if (master_priv->sarea_priv)
  322. master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
  323. i915_user_irq_get(dev);
  324. DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
  325. READ_BREADCRUMB(dev_priv) >= irq_nr);
  326. i915_user_irq_put(dev);
  327. if (ret == -EBUSY) {
  328. DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
  329. READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
  330. }
  331. return ret;
  332. }
  333. /* Needs the lock as it touches the ring.
  334. */
  335. int i915_irq_emit(struct drm_device *dev, void *data,
  336. struct drm_file *file_priv)
  337. {
  338. drm_i915_private_t *dev_priv = dev->dev_private;
  339. drm_i915_irq_emit_t *emit = data;
  340. int result;
  341. if (!dev_priv) {
  342. DRM_ERROR("called with no initialization\n");
  343. return -EINVAL;
  344. }
  345. RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
  346. mutex_lock(&dev->struct_mutex);
  347. result = i915_emit_irq(dev);
  348. mutex_unlock(&dev->struct_mutex);
  349. if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
  350. DRM_ERROR("copy_to_user\n");
  351. return -EFAULT;
  352. }
  353. return 0;
  354. }
  355. /* Doesn't need the hardware lock.
  356. */
  357. int i915_irq_wait(struct drm_device *dev, void *data,
  358. struct drm_file *file_priv)
  359. {
  360. drm_i915_private_t *dev_priv = dev->dev_private;
  361. drm_i915_irq_wait_t *irqwait = data;
  362. if (!dev_priv) {
  363. DRM_ERROR("called with no initialization\n");
  364. return -EINVAL;
  365. }
  366. return i915_wait_irq(dev, irqwait->irq_seq);
  367. }
  368. /* Called from drm generic code, passed 'crtc' which
  369. * we use as a pipe index
  370. */
  371. int i915_enable_vblank(struct drm_device *dev, int pipe)
  372. {
  373. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  374. unsigned long irqflags;
  375. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  376. u32 pipeconf;
  377. pipeconf = I915_READ(pipeconf_reg);
  378. if (!(pipeconf & PIPEACONF_ENABLE))
  379. return -EINVAL;
  380. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  381. if (IS_I965G(dev))
  382. i915_enable_pipestat(dev_priv, pipe,
  383. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  384. else
  385. i915_enable_pipestat(dev_priv, pipe,
  386. PIPE_VBLANK_INTERRUPT_ENABLE);
  387. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  388. return 0;
  389. }
  390. /* Called from drm generic code, passed 'crtc' which
  391. * we use as a pipe index
  392. */
  393. void i915_disable_vblank(struct drm_device *dev, int pipe)
  394. {
  395. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  396. unsigned long irqflags;
  397. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  398. i915_disable_pipestat(dev_priv, pipe,
  399. PIPE_VBLANK_INTERRUPT_ENABLE |
  400. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  401. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  402. }
  403. void i915_enable_interrupt (struct drm_device *dev)
  404. {
  405. struct drm_i915_private *dev_priv = dev->dev_private;
  406. opregion_enable_asle(dev);
  407. dev_priv->irq_enabled = 1;
  408. }
  409. /* Set the vblank monitor pipe
  410. */
  411. int i915_vblank_pipe_set(struct drm_device *dev, void *data,
  412. struct drm_file *file_priv)
  413. {
  414. drm_i915_private_t *dev_priv = dev->dev_private;
  415. if (!dev_priv) {
  416. DRM_ERROR("called with no initialization\n");
  417. return -EINVAL;
  418. }
  419. return 0;
  420. }
  421. int i915_vblank_pipe_get(struct drm_device *dev, void *data,
  422. struct drm_file *file_priv)
  423. {
  424. drm_i915_private_t *dev_priv = dev->dev_private;
  425. drm_i915_vblank_pipe_t *pipe = data;
  426. if (!dev_priv) {
  427. DRM_ERROR("called with no initialization\n");
  428. return -EINVAL;
  429. }
  430. pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  431. return 0;
  432. }
  433. /**
  434. * Schedule buffer swap at given vertical blank.
  435. */
  436. int i915_vblank_swap(struct drm_device *dev, void *data,
  437. struct drm_file *file_priv)
  438. {
  439. /* The delayed swap mechanism was fundamentally racy, and has been
  440. * removed. The model was that the client requested a delayed flip/swap
  441. * from the kernel, then waited for vblank before continuing to perform
  442. * rendering. The problem was that the kernel might wake the client
  443. * up before it dispatched the vblank swap (since the lock has to be
  444. * held while touching the ringbuffer), in which case the client would
  445. * clear and start the next frame before the swap occurred, and
  446. * flicker would occur in addition to likely missing the vblank.
  447. *
  448. * In the absence of this ioctl, userland falls back to a correct path
  449. * of waiting for a vblank, then dispatching the swap on its own.
  450. * Context switching to userland and back is plenty fast enough for
  451. * meeting the requirements of vblank swapping.
  452. */
  453. return -EINVAL;
  454. }
  455. /* drm_dma.h hooks
  456. */
  457. void i915_driver_irq_preinstall(struct drm_device * dev)
  458. {
  459. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  460. atomic_set(&dev_priv->irq_received, 0);
  461. if (I915_HAS_HOTPLUG(dev)) {
  462. I915_WRITE(PORT_HOTPLUG_EN, 0);
  463. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  464. }
  465. I915_WRITE(HWSTAM, 0xeffe);
  466. I915_WRITE(PIPEASTAT, 0);
  467. I915_WRITE(PIPEBSTAT, 0);
  468. I915_WRITE(IMR, 0xffffffff);
  469. I915_WRITE(IER, 0x0);
  470. (void) I915_READ(IER);
  471. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  472. }
  473. int i915_driver_irq_postinstall(struct drm_device *dev)
  474. {
  475. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  476. u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR;
  477. dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  478. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  479. /* Unmask the interrupts that we always want on. */
  480. dev_priv->irq_mask_reg = ~I915_INTERRUPT_ENABLE_FIX;
  481. dev_priv->pipestat[0] = 0;
  482. dev_priv->pipestat[1] = 0;
  483. if (I915_HAS_HOTPLUG(dev)) {
  484. u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  485. /* Leave other bits alone */
  486. hotplug_en |= HOTPLUG_EN_MASK;
  487. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  488. dev_priv->hotplug_supported_mask = CRT_HOTPLUG_INT_STATUS |
  489. TV_HOTPLUG_INT_STATUS | SDVOC_HOTPLUG_INT_STATUS |
  490. SDVOB_HOTPLUG_INT_STATUS;
  491. if (IS_G4X(dev)) {
  492. dev_priv->hotplug_supported_mask |=
  493. HDMIB_HOTPLUG_INT_STATUS |
  494. HDMIC_HOTPLUG_INT_STATUS |
  495. HDMID_HOTPLUG_INT_STATUS;
  496. }
  497. /* Enable in IER... */
  498. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  499. /* and unmask in IMR */
  500. i915_enable_irq(dev_priv, I915_DISPLAY_PORT_INTERRUPT);
  501. }
  502. /* Disable pipe interrupt enables, clear pending pipe status */
  503. I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff);
  504. I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff);
  505. /* Clear pending interrupt status */
  506. I915_WRITE(IIR, I915_READ(IIR));
  507. I915_WRITE(IER, enable_mask);
  508. I915_WRITE(IMR, dev_priv->irq_mask_reg);
  509. (void) I915_READ(IER);
  510. opregion_enable_asle(dev);
  511. DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
  512. return 0;
  513. }
  514. void i915_driver_irq_uninstall(struct drm_device * dev)
  515. {
  516. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  517. if (!dev_priv)
  518. return;
  519. dev_priv->vblank_pipe = 0;
  520. if (I915_HAS_HOTPLUG(dev)) {
  521. I915_WRITE(PORT_HOTPLUG_EN, 0);
  522. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  523. }
  524. I915_WRITE(HWSTAM, 0xffffffff);
  525. I915_WRITE(PIPEASTAT, 0);
  526. I915_WRITE(PIPEBSTAT, 0);
  527. I915_WRITE(IMR, 0xffffffff);
  528. I915_WRITE(IER, 0x0);
  529. I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff);
  530. I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff);
  531. I915_WRITE(IIR, I915_READ(IIR));
  532. }