i915_irq.c 35 KB

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