i915_irq.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  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 <linux/slab.h>
  30. #include "drmP.h"
  31. #include "drm.h"
  32. #include "i915_drm.h"
  33. #include "i915_drv.h"
  34. #include "i915_trace.h"
  35. #include "intel_drv.h"
  36. #define MAX_NOPID ((u32)~0)
  37. /**
  38. * Interrupts that are always left unmasked.
  39. *
  40. * Since pipe events are edge-triggered from the PIPESTAT register to IIR,
  41. * we leave them always unmasked in IMR and then control enabling them through
  42. * PIPESTAT alone.
  43. */
  44. #define I915_INTERRUPT_ENABLE_FIX \
  45. (I915_ASLE_INTERRUPT | \
  46. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \
  47. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \
  48. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | \
  49. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | \
  50. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  51. /** Interrupts that we mask and unmask at runtime. */
  52. #define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT | I915_BSD_USER_INTERRUPT)
  53. #define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\
  54. PIPE_VBLANK_INTERRUPT_STATUS)
  55. #define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\
  56. PIPE_VBLANK_INTERRUPT_ENABLE)
  57. #define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \
  58. DRM_I915_VBLANK_PIPE_B)
  59. /* For display hotplug interrupt */
  60. static void
  61. ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  62. {
  63. if ((dev_priv->irq_mask & mask) != 0) {
  64. dev_priv->irq_mask &= ~mask;
  65. I915_WRITE(DEIMR, dev_priv->irq_mask);
  66. POSTING_READ(DEIMR);
  67. }
  68. }
  69. static inline void
  70. ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  71. {
  72. if ((dev_priv->irq_mask & mask) != mask) {
  73. dev_priv->irq_mask |= mask;
  74. I915_WRITE(DEIMR, dev_priv->irq_mask);
  75. POSTING_READ(DEIMR);
  76. }
  77. }
  78. void
  79. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  80. {
  81. if ((dev_priv->pipestat[pipe] & mask) != mask) {
  82. u32 reg = PIPESTAT(pipe);
  83. dev_priv->pipestat[pipe] |= mask;
  84. /* Enable the interrupt, clear any pending status */
  85. I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16));
  86. POSTING_READ(reg);
  87. }
  88. }
  89. void
  90. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  91. {
  92. if ((dev_priv->pipestat[pipe] & mask) != 0) {
  93. u32 reg = PIPESTAT(pipe);
  94. dev_priv->pipestat[pipe] &= ~mask;
  95. I915_WRITE(reg, dev_priv->pipestat[pipe]);
  96. POSTING_READ(reg);
  97. }
  98. }
  99. /**
  100. * intel_enable_asle - enable ASLE interrupt for OpRegion
  101. */
  102. void intel_enable_asle(struct drm_device *dev)
  103. {
  104. drm_i915_private_t *dev_priv = dev->dev_private;
  105. unsigned long irqflags;
  106. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  107. if (HAS_PCH_SPLIT(dev))
  108. ironlake_enable_display_irq(dev_priv, DE_GSE);
  109. else {
  110. i915_enable_pipestat(dev_priv, 1,
  111. PIPE_LEGACY_BLC_EVENT_ENABLE);
  112. if (INTEL_INFO(dev)->gen >= 4)
  113. i915_enable_pipestat(dev_priv, 0,
  114. PIPE_LEGACY_BLC_EVENT_ENABLE);
  115. }
  116. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  117. }
  118. /**
  119. * i915_pipe_enabled - check if a pipe is enabled
  120. * @dev: DRM device
  121. * @pipe: pipe to check
  122. *
  123. * Reading certain registers when the pipe is disabled can hang the chip.
  124. * Use this routine to make sure the PLL is running and the pipe is active
  125. * before reading such registers if unsure.
  126. */
  127. static int
  128. i915_pipe_enabled(struct drm_device *dev, int pipe)
  129. {
  130. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  131. return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
  132. }
  133. /* Called from drm generic code, passed a 'crtc', which
  134. * we use as a pipe index
  135. */
  136. u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  137. {
  138. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  139. unsigned long high_frame;
  140. unsigned long low_frame;
  141. u32 high1, high2, low;
  142. if (!i915_pipe_enabled(dev, pipe)) {
  143. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  144. "pipe %c\n", pipe_name(pipe));
  145. return 0;
  146. }
  147. high_frame = PIPEFRAME(pipe);
  148. low_frame = PIPEFRAMEPIXEL(pipe);
  149. /*
  150. * High & low register fields aren't synchronized, so make sure
  151. * we get a low value that's stable across two reads of the high
  152. * register.
  153. */
  154. do {
  155. high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  156. low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK;
  157. high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  158. } while (high1 != high2);
  159. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  160. low >>= PIPE_FRAME_LOW_SHIFT;
  161. return (high1 << 8) | low;
  162. }
  163. u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  164. {
  165. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  166. int reg = PIPE_FRMCOUNT_GM45(pipe);
  167. if (!i915_pipe_enabled(dev, pipe)) {
  168. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  169. "pipe %c\n", pipe_name(pipe));
  170. return 0;
  171. }
  172. return I915_READ(reg);
  173. }
  174. int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
  175. int *vpos, int *hpos)
  176. {
  177. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  178. u32 vbl = 0, position = 0;
  179. int vbl_start, vbl_end, htotal, vtotal;
  180. bool in_vbl = true;
  181. int ret = 0;
  182. if (!i915_pipe_enabled(dev, pipe)) {
  183. DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
  184. "pipe %c\n", pipe_name(pipe));
  185. return 0;
  186. }
  187. /* Get vtotal. */
  188. vtotal = 1 + ((I915_READ(VTOTAL(pipe)) >> 16) & 0x1fff);
  189. if (INTEL_INFO(dev)->gen >= 4) {
  190. /* No obvious pixelcount register. Only query vertical
  191. * scanout position from Display scan line register.
  192. */
  193. position = I915_READ(PIPEDSL(pipe));
  194. /* Decode into vertical scanout position. Don't have
  195. * horizontal scanout position.
  196. */
  197. *vpos = position & 0x1fff;
  198. *hpos = 0;
  199. } else {
  200. /* Have access to pixelcount since start of frame.
  201. * We can split this into vertical and horizontal
  202. * scanout position.
  203. */
  204. position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  205. htotal = 1 + ((I915_READ(HTOTAL(pipe)) >> 16) & 0x1fff);
  206. *vpos = position / htotal;
  207. *hpos = position - (*vpos * htotal);
  208. }
  209. /* Query vblank area. */
  210. vbl = I915_READ(VBLANK(pipe));
  211. /* Test position against vblank region. */
  212. vbl_start = vbl & 0x1fff;
  213. vbl_end = (vbl >> 16) & 0x1fff;
  214. if ((*vpos < vbl_start) || (*vpos > vbl_end))
  215. in_vbl = false;
  216. /* Inside "upper part" of vblank area? Apply corrective offset: */
  217. if (in_vbl && (*vpos >= vbl_start))
  218. *vpos = *vpos - vtotal;
  219. /* Readouts valid? */
  220. if (vbl > 0)
  221. ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
  222. /* In vblank? */
  223. if (in_vbl)
  224. ret |= DRM_SCANOUTPOS_INVBL;
  225. return ret;
  226. }
  227. int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
  228. int *max_error,
  229. struct timeval *vblank_time,
  230. unsigned flags)
  231. {
  232. struct drm_i915_private *dev_priv = dev->dev_private;
  233. struct drm_crtc *crtc;
  234. if (pipe < 0 || pipe >= dev_priv->num_pipe) {
  235. DRM_ERROR("Invalid crtc %d\n", pipe);
  236. return -EINVAL;
  237. }
  238. /* Get drm_crtc to timestamp: */
  239. crtc = intel_get_crtc_for_pipe(dev, pipe);
  240. if (crtc == NULL) {
  241. DRM_ERROR("Invalid crtc %d\n", pipe);
  242. return -EINVAL;
  243. }
  244. if (!crtc->enabled) {
  245. DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
  246. return -EBUSY;
  247. }
  248. /* Helper routine in DRM core does all the work: */
  249. return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
  250. vblank_time, flags,
  251. crtc);
  252. }
  253. /*
  254. * Handle hotplug events outside the interrupt handler proper.
  255. */
  256. static void i915_hotplug_work_func(struct work_struct *work)
  257. {
  258. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  259. hotplug_work);
  260. struct drm_device *dev = dev_priv->dev;
  261. struct drm_mode_config *mode_config = &dev->mode_config;
  262. struct intel_encoder *encoder;
  263. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  264. list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
  265. if (encoder->hot_plug)
  266. encoder->hot_plug(encoder);
  267. /* Just fire off a uevent and let userspace tell us what to do */
  268. drm_helper_hpd_irq_event(dev);
  269. }
  270. static void i915_handle_rps_change(struct drm_device *dev)
  271. {
  272. drm_i915_private_t *dev_priv = dev->dev_private;
  273. u32 busy_up, busy_down, max_avg, min_avg;
  274. u8 new_delay = dev_priv->cur_delay;
  275. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  276. busy_up = I915_READ(RCPREVBSYTUPAVG);
  277. busy_down = I915_READ(RCPREVBSYTDNAVG);
  278. max_avg = I915_READ(RCBMAXAVG);
  279. min_avg = I915_READ(RCBMINAVG);
  280. /* Handle RCS change request from hw */
  281. if (busy_up > max_avg) {
  282. if (dev_priv->cur_delay != dev_priv->max_delay)
  283. new_delay = dev_priv->cur_delay - 1;
  284. if (new_delay < dev_priv->max_delay)
  285. new_delay = dev_priv->max_delay;
  286. } else if (busy_down < min_avg) {
  287. if (dev_priv->cur_delay != dev_priv->min_delay)
  288. new_delay = dev_priv->cur_delay + 1;
  289. if (new_delay > dev_priv->min_delay)
  290. new_delay = dev_priv->min_delay;
  291. }
  292. if (ironlake_set_drps(dev, new_delay))
  293. dev_priv->cur_delay = new_delay;
  294. return;
  295. }
  296. static void notify_ring(struct drm_device *dev,
  297. struct intel_ring_buffer *ring)
  298. {
  299. struct drm_i915_private *dev_priv = dev->dev_private;
  300. u32 seqno;
  301. if (ring->obj == NULL)
  302. return;
  303. seqno = ring->get_seqno(ring);
  304. trace_i915_gem_request_complete(ring, seqno);
  305. ring->irq_seqno = seqno;
  306. wake_up_all(&ring->irq_queue);
  307. dev_priv->hangcheck_count = 0;
  308. mod_timer(&dev_priv->hangcheck_timer,
  309. jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
  310. }
  311. static void gen6_pm_rps_work(struct work_struct *work)
  312. {
  313. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  314. rps_work);
  315. u8 new_delay = dev_priv->cur_delay;
  316. u32 pm_iir, pm_imr;
  317. spin_lock_irq(&dev_priv->rps_lock);
  318. pm_iir = dev_priv->pm_iir;
  319. dev_priv->pm_iir = 0;
  320. pm_imr = I915_READ(GEN6_PMIMR);
  321. spin_unlock_irq(&dev_priv->rps_lock);
  322. if (!pm_iir)
  323. return;
  324. mutex_lock(&dev_priv->dev->struct_mutex);
  325. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
  326. if (dev_priv->cur_delay != dev_priv->max_delay)
  327. new_delay = dev_priv->cur_delay + 1;
  328. if (new_delay > dev_priv->max_delay)
  329. new_delay = dev_priv->max_delay;
  330. } else if (pm_iir & (GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT)) {
  331. gen6_gt_force_wake_get(dev_priv);
  332. if (dev_priv->cur_delay != dev_priv->min_delay)
  333. new_delay = dev_priv->cur_delay - 1;
  334. if (new_delay < dev_priv->min_delay) {
  335. new_delay = dev_priv->min_delay;
  336. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  337. I915_READ(GEN6_RP_INTERRUPT_LIMITS) |
  338. ((new_delay << 16) & 0x3f0000));
  339. } else {
  340. /* Make sure we continue to get down interrupts
  341. * until we hit the minimum frequency */
  342. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  343. I915_READ(GEN6_RP_INTERRUPT_LIMITS) & ~0x3f0000);
  344. }
  345. gen6_gt_force_wake_put(dev_priv);
  346. }
  347. gen6_set_rps(dev_priv->dev, new_delay);
  348. dev_priv->cur_delay = new_delay;
  349. /*
  350. * rps_lock not held here because clearing is non-destructive. There is
  351. * an *extremely* unlikely race with gen6_rps_enable() that is prevented
  352. * by holding struct_mutex for the duration of the write.
  353. */
  354. I915_WRITE(GEN6_PMIMR, pm_imr & ~pm_iir);
  355. mutex_unlock(&dev_priv->dev->struct_mutex);
  356. }
  357. static void pch_irq_handler(struct drm_device *dev)
  358. {
  359. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  360. u32 pch_iir;
  361. int pipe;
  362. pch_iir = I915_READ(SDEIIR);
  363. if (pch_iir & SDE_AUDIO_POWER_MASK)
  364. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  365. (pch_iir & SDE_AUDIO_POWER_MASK) >>
  366. SDE_AUDIO_POWER_SHIFT);
  367. if (pch_iir & SDE_GMBUS)
  368. DRM_DEBUG_DRIVER("PCH GMBUS interrupt\n");
  369. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  370. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  371. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  372. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  373. if (pch_iir & SDE_POISON)
  374. DRM_ERROR("PCH poison interrupt\n");
  375. if (pch_iir & SDE_FDI_MASK)
  376. for_each_pipe(pipe)
  377. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  378. pipe_name(pipe),
  379. I915_READ(FDI_RX_IIR(pipe)));
  380. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  381. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  382. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  383. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  384. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  385. DRM_DEBUG_DRIVER("PCH transcoder B underrun interrupt\n");
  386. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  387. DRM_DEBUG_DRIVER("PCH transcoder A underrun interrupt\n");
  388. }
  389. irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
  390. {
  391. struct drm_device *dev = (struct drm_device *) arg;
  392. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  393. int ret = IRQ_NONE;
  394. u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
  395. u32 hotplug_mask;
  396. struct drm_i915_master_private *master_priv;
  397. u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
  398. atomic_inc(&dev_priv->irq_received);
  399. if (IS_GEN6(dev))
  400. bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
  401. /* disable master interrupt before clearing iir */
  402. de_ier = I915_READ(DEIER);
  403. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  404. POSTING_READ(DEIER);
  405. de_iir = I915_READ(DEIIR);
  406. gt_iir = I915_READ(GTIIR);
  407. pch_iir = I915_READ(SDEIIR);
  408. pm_iir = I915_READ(GEN6_PMIIR);
  409. if (de_iir == 0 && gt_iir == 0 && pch_iir == 0 &&
  410. (!IS_GEN6(dev) || pm_iir == 0))
  411. goto done;
  412. if (HAS_PCH_CPT(dev))
  413. hotplug_mask = SDE_HOTPLUG_MASK_CPT;
  414. else
  415. hotplug_mask = SDE_HOTPLUG_MASK;
  416. ret = IRQ_HANDLED;
  417. if (dev->primary->master) {
  418. master_priv = dev->primary->master->driver_priv;
  419. if (master_priv->sarea_priv)
  420. master_priv->sarea_priv->last_dispatch =
  421. READ_BREADCRUMB(dev_priv);
  422. }
  423. if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY))
  424. notify_ring(dev, &dev_priv->ring[RCS]);
  425. if (gt_iir & bsd_usr_interrupt)
  426. notify_ring(dev, &dev_priv->ring[VCS]);
  427. if (gt_iir & GT_BLT_USER_INTERRUPT)
  428. notify_ring(dev, &dev_priv->ring[BCS]);
  429. if (de_iir & DE_GSE)
  430. intel_opregion_gse_intr(dev);
  431. if (de_iir & DE_PLANEA_FLIP_DONE) {
  432. intel_prepare_page_flip(dev, 0);
  433. intel_finish_page_flip_plane(dev, 0);
  434. }
  435. if (de_iir & DE_PLANEB_FLIP_DONE) {
  436. intel_prepare_page_flip(dev, 1);
  437. intel_finish_page_flip_plane(dev, 1);
  438. }
  439. if (de_iir & DE_PIPEA_VBLANK)
  440. drm_handle_vblank(dev, 0);
  441. if (de_iir & DE_PIPEB_VBLANK)
  442. drm_handle_vblank(dev, 1);
  443. /* check event from PCH */
  444. if (de_iir & DE_PCH_EVENT) {
  445. if (pch_iir & hotplug_mask)
  446. queue_work(dev_priv->wq, &dev_priv->hotplug_work);
  447. pch_irq_handler(dev);
  448. }
  449. if (de_iir & DE_PCU_EVENT) {
  450. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  451. i915_handle_rps_change(dev);
  452. }
  453. if (IS_GEN6(dev) && pm_iir & GEN6_PM_DEFERRED_EVENTS) {
  454. /*
  455. * IIR bits should never already be set because IMR should
  456. * prevent an interrupt from being shown in IIR. The warning
  457. * displays a case where we've unsafely cleared
  458. * dev_priv->pm_iir. Although missing an interrupt of the same
  459. * type is not a problem, it displays a problem in the logic.
  460. *
  461. * The mask bit in IMR is cleared by rps_work.
  462. */
  463. unsigned long flags;
  464. spin_lock_irqsave(&dev_priv->rps_lock, flags);
  465. WARN(dev_priv->pm_iir & pm_iir, "Missed a PM interrupt\n");
  466. I915_WRITE(GEN6_PMIMR, pm_iir);
  467. dev_priv->pm_iir |= pm_iir;
  468. spin_unlock_irqrestore(&dev_priv->rps_lock, flags);
  469. queue_work(dev_priv->wq, &dev_priv->rps_work);
  470. }
  471. /* should clear PCH hotplug event before clear CPU irq */
  472. I915_WRITE(SDEIIR, pch_iir);
  473. I915_WRITE(GTIIR, gt_iir);
  474. I915_WRITE(DEIIR, de_iir);
  475. I915_WRITE(GEN6_PMIIR, pm_iir);
  476. done:
  477. I915_WRITE(DEIER, de_ier);
  478. POSTING_READ(DEIER);
  479. return ret;
  480. }
  481. /**
  482. * i915_error_work_func - do process context error handling work
  483. * @work: work struct
  484. *
  485. * Fire an error uevent so userspace can see that a hang or error
  486. * was detected.
  487. */
  488. static void i915_error_work_func(struct work_struct *work)
  489. {
  490. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  491. error_work);
  492. struct drm_device *dev = dev_priv->dev;
  493. char *error_event[] = { "ERROR=1", NULL };
  494. char *reset_event[] = { "RESET=1", NULL };
  495. char *reset_done_event[] = { "ERROR=0", NULL };
  496. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  497. if (atomic_read(&dev_priv->mm.wedged)) {
  498. DRM_DEBUG_DRIVER("resetting chip\n");
  499. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event);
  500. if (!i915_reset(dev, GRDOM_RENDER)) {
  501. atomic_set(&dev_priv->mm.wedged, 0);
  502. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event);
  503. }
  504. complete_all(&dev_priv->error_completion);
  505. }
  506. }
  507. #ifdef CONFIG_DEBUG_FS
  508. static struct drm_i915_error_object *
  509. i915_error_object_create(struct drm_i915_private *dev_priv,
  510. struct drm_i915_gem_object *src)
  511. {
  512. struct drm_i915_error_object *dst;
  513. int page, page_count;
  514. u32 reloc_offset;
  515. if (src == NULL || src->pages == NULL)
  516. return NULL;
  517. page_count = src->base.size / PAGE_SIZE;
  518. dst = kmalloc(sizeof(*dst) + page_count * sizeof (u32 *), GFP_ATOMIC);
  519. if (dst == NULL)
  520. return NULL;
  521. reloc_offset = src->gtt_offset;
  522. for (page = 0; page < page_count; page++) {
  523. unsigned long flags;
  524. void __iomem *s;
  525. void *d;
  526. d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
  527. if (d == NULL)
  528. goto unwind;
  529. local_irq_save(flags);
  530. s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
  531. reloc_offset);
  532. memcpy_fromio(d, s, PAGE_SIZE);
  533. io_mapping_unmap_atomic(s);
  534. local_irq_restore(flags);
  535. dst->pages[page] = d;
  536. reloc_offset += PAGE_SIZE;
  537. }
  538. dst->page_count = page_count;
  539. dst->gtt_offset = src->gtt_offset;
  540. return dst;
  541. unwind:
  542. while (page--)
  543. kfree(dst->pages[page]);
  544. kfree(dst);
  545. return NULL;
  546. }
  547. static void
  548. i915_error_object_free(struct drm_i915_error_object *obj)
  549. {
  550. int page;
  551. if (obj == NULL)
  552. return;
  553. for (page = 0; page < obj->page_count; page++)
  554. kfree(obj->pages[page]);
  555. kfree(obj);
  556. }
  557. static void
  558. i915_error_state_free(struct drm_device *dev,
  559. struct drm_i915_error_state *error)
  560. {
  561. int i;
  562. for (i = 0; i < ARRAY_SIZE(error->batchbuffer); i++)
  563. i915_error_object_free(error->batchbuffer[i]);
  564. for (i = 0; i < ARRAY_SIZE(error->ringbuffer); i++)
  565. i915_error_object_free(error->ringbuffer[i]);
  566. kfree(error->active_bo);
  567. kfree(error->overlay);
  568. kfree(error);
  569. }
  570. static u32 capture_bo_list(struct drm_i915_error_buffer *err,
  571. int count,
  572. struct list_head *head)
  573. {
  574. struct drm_i915_gem_object *obj;
  575. int i = 0;
  576. list_for_each_entry(obj, head, mm_list) {
  577. err->size = obj->base.size;
  578. err->name = obj->base.name;
  579. err->seqno = obj->last_rendering_seqno;
  580. err->gtt_offset = obj->gtt_offset;
  581. err->read_domains = obj->base.read_domains;
  582. err->write_domain = obj->base.write_domain;
  583. err->fence_reg = obj->fence_reg;
  584. err->pinned = 0;
  585. if (obj->pin_count > 0)
  586. err->pinned = 1;
  587. if (obj->user_pin_count > 0)
  588. err->pinned = -1;
  589. err->tiling = obj->tiling_mode;
  590. err->dirty = obj->dirty;
  591. err->purgeable = obj->madv != I915_MADV_WILLNEED;
  592. err->ring = obj->ring ? obj->ring->id : 0;
  593. err->cache_level = obj->cache_level;
  594. if (++i == count)
  595. break;
  596. err++;
  597. }
  598. return i;
  599. }
  600. static void i915_gem_record_fences(struct drm_device *dev,
  601. struct drm_i915_error_state *error)
  602. {
  603. struct drm_i915_private *dev_priv = dev->dev_private;
  604. int i;
  605. /* Fences */
  606. switch (INTEL_INFO(dev)->gen) {
  607. case 6:
  608. for (i = 0; i < 16; i++)
  609. error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
  610. break;
  611. case 5:
  612. case 4:
  613. for (i = 0; i < 16; i++)
  614. error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
  615. break;
  616. case 3:
  617. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  618. for (i = 0; i < 8; i++)
  619. error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
  620. case 2:
  621. for (i = 0; i < 8; i++)
  622. error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
  623. break;
  624. }
  625. }
  626. static struct drm_i915_error_object *
  627. i915_error_first_batchbuffer(struct drm_i915_private *dev_priv,
  628. struct intel_ring_buffer *ring)
  629. {
  630. struct drm_i915_gem_object *obj;
  631. u32 seqno;
  632. if (!ring->get_seqno)
  633. return NULL;
  634. seqno = ring->get_seqno(ring);
  635. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
  636. if (obj->ring != ring)
  637. continue;
  638. if (i915_seqno_passed(seqno, obj->last_rendering_seqno))
  639. continue;
  640. if ((obj->base.read_domains & I915_GEM_DOMAIN_COMMAND) == 0)
  641. continue;
  642. /* We need to copy these to an anonymous buffer as the simplest
  643. * method to avoid being overwritten by userspace.
  644. */
  645. return i915_error_object_create(dev_priv, obj);
  646. }
  647. return NULL;
  648. }
  649. /**
  650. * i915_capture_error_state - capture an error record for later analysis
  651. * @dev: drm device
  652. *
  653. * Should be called when an error is detected (either a hang or an error
  654. * interrupt) to capture error state from the time of the error. Fills
  655. * out a structure which becomes available in debugfs for user level tools
  656. * to pick up.
  657. */
  658. static void i915_capture_error_state(struct drm_device *dev)
  659. {
  660. struct drm_i915_private *dev_priv = dev->dev_private;
  661. struct drm_i915_gem_object *obj;
  662. struct drm_i915_error_state *error;
  663. unsigned long flags;
  664. int i, pipe;
  665. spin_lock_irqsave(&dev_priv->error_lock, flags);
  666. error = dev_priv->first_error;
  667. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  668. if (error)
  669. return;
  670. /* Account for pipe specific data like PIPE*STAT */
  671. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  672. if (!error) {
  673. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  674. return;
  675. }
  676. DRM_INFO("capturing error event; look for more information in /debug/dri/%d/i915_error_state\n",
  677. dev->primary->index);
  678. error->seqno = dev_priv->ring[RCS].get_seqno(&dev_priv->ring[RCS]);
  679. error->eir = I915_READ(EIR);
  680. error->pgtbl_er = I915_READ(PGTBL_ER);
  681. for_each_pipe(pipe)
  682. error->pipestat[pipe] = I915_READ(PIPESTAT(pipe));
  683. error->instpm = I915_READ(INSTPM);
  684. error->error = 0;
  685. if (INTEL_INFO(dev)->gen >= 6) {
  686. error->error = I915_READ(ERROR_GEN6);
  687. error->bcs_acthd = I915_READ(BCS_ACTHD);
  688. error->bcs_ipehr = I915_READ(BCS_IPEHR);
  689. error->bcs_ipeir = I915_READ(BCS_IPEIR);
  690. error->bcs_instdone = I915_READ(BCS_INSTDONE);
  691. error->bcs_seqno = 0;
  692. if (dev_priv->ring[BCS].get_seqno)
  693. error->bcs_seqno = dev_priv->ring[BCS].get_seqno(&dev_priv->ring[BCS]);
  694. error->vcs_acthd = I915_READ(VCS_ACTHD);
  695. error->vcs_ipehr = I915_READ(VCS_IPEHR);
  696. error->vcs_ipeir = I915_READ(VCS_IPEIR);
  697. error->vcs_instdone = I915_READ(VCS_INSTDONE);
  698. error->vcs_seqno = 0;
  699. if (dev_priv->ring[VCS].get_seqno)
  700. error->vcs_seqno = dev_priv->ring[VCS].get_seqno(&dev_priv->ring[VCS]);
  701. }
  702. if (INTEL_INFO(dev)->gen >= 4) {
  703. error->ipeir = I915_READ(IPEIR_I965);
  704. error->ipehr = I915_READ(IPEHR_I965);
  705. error->instdone = I915_READ(INSTDONE_I965);
  706. error->instps = I915_READ(INSTPS);
  707. error->instdone1 = I915_READ(INSTDONE1);
  708. error->acthd = I915_READ(ACTHD_I965);
  709. error->bbaddr = I915_READ64(BB_ADDR);
  710. } else {
  711. error->ipeir = I915_READ(IPEIR);
  712. error->ipehr = I915_READ(IPEHR);
  713. error->instdone = I915_READ(INSTDONE);
  714. error->acthd = I915_READ(ACTHD);
  715. error->bbaddr = 0;
  716. }
  717. i915_gem_record_fences(dev, error);
  718. /* Record the active batch and ring buffers */
  719. for (i = 0; i < I915_NUM_RINGS; i++) {
  720. error->batchbuffer[i] =
  721. i915_error_first_batchbuffer(dev_priv,
  722. &dev_priv->ring[i]);
  723. error->ringbuffer[i] =
  724. i915_error_object_create(dev_priv,
  725. dev_priv->ring[i].obj);
  726. }
  727. /* Record buffers on the active and pinned lists. */
  728. error->active_bo = NULL;
  729. error->pinned_bo = NULL;
  730. i = 0;
  731. list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list)
  732. i++;
  733. error->active_bo_count = i;
  734. list_for_each_entry(obj, &dev_priv->mm.pinned_list, mm_list)
  735. i++;
  736. error->pinned_bo_count = i - error->active_bo_count;
  737. error->active_bo = NULL;
  738. error->pinned_bo = NULL;
  739. if (i) {
  740. error->active_bo = kmalloc(sizeof(*error->active_bo)*i,
  741. GFP_ATOMIC);
  742. if (error->active_bo)
  743. error->pinned_bo =
  744. error->active_bo + error->active_bo_count;
  745. }
  746. if (error->active_bo)
  747. error->active_bo_count =
  748. capture_bo_list(error->active_bo,
  749. error->active_bo_count,
  750. &dev_priv->mm.active_list);
  751. if (error->pinned_bo)
  752. error->pinned_bo_count =
  753. capture_bo_list(error->pinned_bo,
  754. error->pinned_bo_count,
  755. &dev_priv->mm.pinned_list);
  756. do_gettimeofday(&error->time);
  757. error->overlay = intel_overlay_capture_error_state(dev);
  758. error->display = intel_display_capture_error_state(dev);
  759. spin_lock_irqsave(&dev_priv->error_lock, flags);
  760. if (dev_priv->first_error == NULL) {
  761. dev_priv->first_error = error;
  762. error = NULL;
  763. }
  764. spin_unlock_irqrestore(&dev_priv->error_lock, flags);
  765. if (error)
  766. i915_error_state_free(dev, error);
  767. }
  768. void i915_destroy_error_state(struct drm_device *dev)
  769. {
  770. struct drm_i915_private *dev_priv = dev->dev_private;
  771. struct drm_i915_error_state *error;
  772. spin_lock(&dev_priv->error_lock);
  773. error = dev_priv->first_error;
  774. dev_priv->first_error = NULL;
  775. spin_unlock(&dev_priv->error_lock);
  776. if (error)
  777. i915_error_state_free(dev, error);
  778. }
  779. #else
  780. #define i915_capture_error_state(x)
  781. #endif
  782. static void i915_report_and_clear_eir(struct drm_device *dev)
  783. {
  784. struct drm_i915_private *dev_priv = dev->dev_private;
  785. u32 eir = I915_READ(EIR);
  786. int pipe;
  787. if (!eir)
  788. return;
  789. printk(KERN_ERR "render error detected, EIR: 0x%08x\n",
  790. eir);
  791. if (IS_G4X(dev)) {
  792. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  793. u32 ipeir = I915_READ(IPEIR_I965);
  794. printk(KERN_ERR " IPEIR: 0x%08x\n",
  795. I915_READ(IPEIR_I965));
  796. printk(KERN_ERR " IPEHR: 0x%08x\n",
  797. I915_READ(IPEHR_I965));
  798. printk(KERN_ERR " INSTDONE: 0x%08x\n",
  799. I915_READ(INSTDONE_I965));
  800. printk(KERN_ERR " INSTPS: 0x%08x\n",
  801. I915_READ(INSTPS));
  802. printk(KERN_ERR " INSTDONE1: 0x%08x\n",
  803. I915_READ(INSTDONE1));
  804. printk(KERN_ERR " ACTHD: 0x%08x\n",
  805. I915_READ(ACTHD_I965));
  806. I915_WRITE(IPEIR_I965, ipeir);
  807. POSTING_READ(IPEIR_I965);
  808. }
  809. if (eir & GM45_ERROR_PAGE_TABLE) {
  810. u32 pgtbl_err = I915_READ(PGTBL_ER);
  811. printk(KERN_ERR "page table error\n");
  812. printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
  813. pgtbl_err);
  814. I915_WRITE(PGTBL_ER, pgtbl_err);
  815. POSTING_READ(PGTBL_ER);
  816. }
  817. }
  818. if (!IS_GEN2(dev)) {
  819. if (eir & I915_ERROR_PAGE_TABLE) {
  820. u32 pgtbl_err = I915_READ(PGTBL_ER);
  821. printk(KERN_ERR "page table error\n");
  822. printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
  823. pgtbl_err);
  824. I915_WRITE(PGTBL_ER, pgtbl_err);
  825. POSTING_READ(PGTBL_ER);
  826. }
  827. }
  828. if (eir & I915_ERROR_MEMORY_REFRESH) {
  829. printk(KERN_ERR "memory refresh error:\n");
  830. for_each_pipe(pipe)
  831. printk(KERN_ERR "pipe %c stat: 0x%08x\n",
  832. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  833. /* pipestat has already been acked */
  834. }
  835. if (eir & I915_ERROR_INSTRUCTION) {
  836. printk(KERN_ERR "instruction error\n");
  837. printk(KERN_ERR " INSTPM: 0x%08x\n",
  838. I915_READ(INSTPM));
  839. if (INTEL_INFO(dev)->gen < 4) {
  840. u32 ipeir = I915_READ(IPEIR);
  841. printk(KERN_ERR " IPEIR: 0x%08x\n",
  842. I915_READ(IPEIR));
  843. printk(KERN_ERR " IPEHR: 0x%08x\n",
  844. I915_READ(IPEHR));
  845. printk(KERN_ERR " INSTDONE: 0x%08x\n",
  846. I915_READ(INSTDONE));
  847. printk(KERN_ERR " ACTHD: 0x%08x\n",
  848. I915_READ(ACTHD));
  849. I915_WRITE(IPEIR, ipeir);
  850. POSTING_READ(IPEIR);
  851. } else {
  852. u32 ipeir = I915_READ(IPEIR_I965);
  853. printk(KERN_ERR " IPEIR: 0x%08x\n",
  854. I915_READ(IPEIR_I965));
  855. printk(KERN_ERR " IPEHR: 0x%08x\n",
  856. I915_READ(IPEHR_I965));
  857. printk(KERN_ERR " INSTDONE: 0x%08x\n",
  858. I915_READ(INSTDONE_I965));
  859. printk(KERN_ERR " INSTPS: 0x%08x\n",
  860. I915_READ(INSTPS));
  861. printk(KERN_ERR " INSTDONE1: 0x%08x\n",
  862. I915_READ(INSTDONE1));
  863. printk(KERN_ERR " ACTHD: 0x%08x\n",
  864. I915_READ(ACTHD_I965));
  865. I915_WRITE(IPEIR_I965, ipeir);
  866. POSTING_READ(IPEIR_I965);
  867. }
  868. }
  869. I915_WRITE(EIR, eir);
  870. POSTING_READ(EIR);
  871. eir = I915_READ(EIR);
  872. if (eir) {
  873. /*
  874. * some errors might have become stuck,
  875. * mask them.
  876. */
  877. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  878. I915_WRITE(EMR, I915_READ(EMR) | eir);
  879. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  880. }
  881. }
  882. /**
  883. * i915_handle_error - handle an error interrupt
  884. * @dev: drm device
  885. *
  886. * Do some basic checking of regsiter state at error interrupt time and
  887. * dump it to the syslog. Also call i915_capture_error_state() to make
  888. * sure we get a record and make it available in debugfs. Fire a uevent
  889. * so userspace knows something bad happened (should trigger collection
  890. * of a ring dump etc.).
  891. */
  892. void i915_handle_error(struct drm_device *dev, bool wedged)
  893. {
  894. struct drm_i915_private *dev_priv = dev->dev_private;
  895. i915_capture_error_state(dev);
  896. i915_report_and_clear_eir(dev);
  897. if (wedged) {
  898. INIT_COMPLETION(dev_priv->error_completion);
  899. atomic_set(&dev_priv->mm.wedged, 1);
  900. /*
  901. * Wakeup waiting processes so they don't hang
  902. */
  903. wake_up_all(&dev_priv->ring[RCS].irq_queue);
  904. if (HAS_BSD(dev))
  905. wake_up_all(&dev_priv->ring[VCS].irq_queue);
  906. if (HAS_BLT(dev))
  907. wake_up_all(&dev_priv->ring[BCS].irq_queue);
  908. }
  909. queue_work(dev_priv->wq, &dev_priv->error_work);
  910. }
  911. static void i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  912. {
  913. drm_i915_private_t *dev_priv = dev->dev_private;
  914. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  915. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  916. struct drm_i915_gem_object *obj;
  917. struct intel_unpin_work *work;
  918. unsigned long flags;
  919. bool stall_detected;
  920. /* Ignore early vblank irqs */
  921. if (intel_crtc == NULL)
  922. return;
  923. spin_lock_irqsave(&dev->event_lock, flags);
  924. work = intel_crtc->unpin_work;
  925. if (work == NULL || work->pending || !work->enable_stall_check) {
  926. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  927. spin_unlock_irqrestore(&dev->event_lock, flags);
  928. return;
  929. }
  930. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  931. obj = work->pending_flip_obj;
  932. if (INTEL_INFO(dev)->gen >= 4) {
  933. int dspsurf = DSPSURF(intel_crtc->plane);
  934. stall_detected = I915_READ(dspsurf) == obj->gtt_offset;
  935. } else {
  936. int dspaddr = DSPADDR(intel_crtc->plane);
  937. stall_detected = I915_READ(dspaddr) == (obj->gtt_offset +
  938. crtc->y * crtc->fb->pitch +
  939. crtc->x * crtc->fb->bits_per_pixel/8);
  940. }
  941. spin_unlock_irqrestore(&dev->event_lock, flags);
  942. if (stall_detected) {
  943. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  944. intel_prepare_page_flip(dev, intel_crtc->plane);
  945. }
  946. }
  947. irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
  948. {
  949. struct drm_device *dev = (struct drm_device *) arg;
  950. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  951. struct drm_i915_master_private *master_priv;
  952. u32 iir, new_iir;
  953. u32 pipe_stats[I915_MAX_PIPES];
  954. u32 vblank_status;
  955. int vblank = 0;
  956. unsigned long irqflags;
  957. int irq_received;
  958. int ret = IRQ_NONE, pipe;
  959. bool blc_event = false;
  960. atomic_inc(&dev_priv->irq_received);
  961. iir = I915_READ(IIR);
  962. if (INTEL_INFO(dev)->gen >= 4)
  963. vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS;
  964. else
  965. vblank_status = PIPE_VBLANK_INTERRUPT_STATUS;
  966. for (;;) {
  967. irq_received = iir != 0;
  968. /* Can't rely on pipestat interrupt bit in iir as it might
  969. * have been cleared after the pipestat interrupt was received.
  970. * It doesn't set the bit in iir again, but it still produces
  971. * interrupts (for non-MSI).
  972. */
  973. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  974. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  975. i915_handle_error(dev, false);
  976. for_each_pipe(pipe) {
  977. int reg = PIPESTAT(pipe);
  978. pipe_stats[pipe] = I915_READ(reg);
  979. /*
  980. * Clear the PIPE*STAT regs before the IIR
  981. */
  982. if (pipe_stats[pipe] & 0x8000ffff) {
  983. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  984. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  985. pipe_name(pipe));
  986. I915_WRITE(reg, pipe_stats[pipe]);
  987. irq_received = 1;
  988. }
  989. }
  990. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  991. if (!irq_received)
  992. break;
  993. ret = IRQ_HANDLED;
  994. /* Consume port. Then clear IIR or we'll miss events */
  995. if ((I915_HAS_HOTPLUG(dev)) &&
  996. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  997. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  998. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  999. hotplug_status);
  1000. if (hotplug_status & dev_priv->hotplug_supported_mask)
  1001. queue_work(dev_priv->wq,
  1002. &dev_priv->hotplug_work);
  1003. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1004. I915_READ(PORT_HOTPLUG_STAT);
  1005. }
  1006. I915_WRITE(IIR, iir);
  1007. new_iir = I915_READ(IIR); /* Flush posted writes */
  1008. if (dev->primary->master) {
  1009. master_priv = dev->primary->master->driver_priv;
  1010. if (master_priv->sarea_priv)
  1011. master_priv->sarea_priv->last_dispatch =
  1012. READ_BREADCRUMB(dev_priv);
  1013. }
  1014. if (iir & I915_USER_INTERRUPT)
  1015. notify_ring(dev, &dev_priv->ring[RCS]);
  1016. if (iir & I915_BSD_USER_INTERRUPT)
  1017. notify_ring(dev, &dev_priv->ring[VCS]);
  1018. if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) {
  1019. intel_prepare_page_flip(dev, 0);
  1020. if (dev_priv->flip_pending_is_done)
  1021. intel_finish_page_flip_plane(dev, 0);
  1022. }
  1023. if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) {
  1024. intel_prepare_page_flip(dev, 1);
  1025. if (dev_priv->flip_pending_is_done)
  1026. intel_finish_page_flip_plane(dev, 1);
  1027. }
  1028. for_each_pipe(pipe) {
  1029. if (pipe_stats[pipe] & vblank_status &&
  1030. drm_handle_vblank(dev, pipe)) {
  1031. vblank++;
  1032. if (!dev_priv->flip_pending_is_done) {
  1033. i915_pageflip_stall_check(dev, pipe);
  1034. intel_finish_page_flip(dev, pipe);
  1035. }
  1036. }
  1037. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  1038. blc_event = true;
  1039. }
  1040. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  1041. intel_opregion_asle_intr(dev);
  1042. /* With MSI, interrupts are only generated when iir
  1043. * transitions from zero to nonzero. If another bit got
  1044. * set while we were handling the existing iir bits, then
  1045. * we would never get another interrupt.
  1046. *
  1047. * This is fine on non-MSI as well, as if we hit this path
  1048. * we avoid exiting the interrupt handler only to generate
  1049. * another one.
  1050. *
  1051. * Note that for MSI this could cause a stray interrupt report
  1052. * if an interrupt landed in the time between writing IIR and
  1053. * the posting read. This should be rare enough to never
  1054. * trigger the 99% of 100,000 interrupts test for disabling
  1055. * stray interrupts.
  1056. */
  1057. iir = new_iir;
  1058. }
  1059. return ret;
  1060. }
  1061. static int i915_emit_irq(struct drm_device * dev)
  1062. {
  1063. drm_i915_private_t *dev_priv = dev->dev_private;
  1064. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  1065. i915_kernel_lost_context(dev);
  1066. DRM_DEBUG_DRIVER("\n");
  1067. dev_priv->counter++;
  1068. if (dev_priv->counter > 0x7FFFFFFFUL)
  1069. dev_priv->counter = 1;
  1070. if (master_priv->sarea_priv)
  1071. master_priv->sarea_priv->last_enqueue = dev_priv->counter;
  1072. if (BEGIN_LP_RING(4) == 0) {
  1073. OUT_RING(MI_STORE_DWORD_INDEX);
  1074. OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
  1075. OUT_RING(dev_priv->counter);
  1076. OUT_RING(MI_USER_INTERRUPT);
  1077. ADVANCE_LP_RING();
  1078. }
  1079. return dev_priv->counter;
  1080. }
  1081. static int i915_wait_irq(struct drm_device * dev, int irq_nr)
  1082. {
  1083. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1084. struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
  1085. int ret = 0;
  1086. struct intel_ring_buffer *ring = LP_RING(dev_priv);
  1087. DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr,
  1088. READ_BREADCRUMB(dev_priv));
  1089. if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
  1090. if (master_priv->sarea_priv)
  1091. master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
  1092. return 0;
  1093. }
  1094. if (master_priv->sarea_priv)
  1095. master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
  1096. if (ring->irq_get(ring)) {
  1097. DRM_WAIT_ON(ret, ring->irq_queue, 3 * DRM_HZ,
  1098. READ_BREADCRUMB(dev_priv) >= irq_nr);
  1099. ring->irq_put(ring);
  1100. } else if (wait_for(READ_BREADCRUMB(dev_priv) >= irq_nr, 3000))
  1101. ret = -EBUSY;
  1102. if (ret == -EBUSY) {
  1103. DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
  1104. READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
  1105. }
  1106. return ret;
  1107. }
  1108. /* Needs the lock as it touches the ring.
  1109. */
  1110. int i915_irq_emit(struct drm_device *dev, void *data,
  1111. struct drm_file *file_priv)
  1112. {
  1113. drm_i915_private_t *dev_priv = dev->dev_private;
  1114. drm_i915_irq_emit_t *emit = data;
  1115. int result;
  1116. if (!dev_priv || !LP_RING(dev_priv)->virtual_start) {
  1117. DRM_ERROR("called with no initialization\n");
  1118. return -EINVAL;
  1119. }
  1120. RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
  1121. mutex_lock(&dev->struct_mutex);
  1122. result = i915_emit_irq(dev);
  1123. mutex_unlock(&dev->struct_mutex);
  1124. if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
  1125. DRM_ERROR("copy_to_user\n");
  1126. return -EFAULT;
  1127. }
  1128. return 0;
  1129. }
  1130. /* Doesn't need the hardware lock.
  1131. */
  1132. int i915_irq_wait(struct drm_device *dev, void *data,
  1133. struct drm_file *file_priv)
  1134. {
  1135. drm_i915_private_t *dev_priv = dev->dev_private;
  1136. drm_i915_irq_wait_t *irqwait = data;
  1137. if (!dev_priv) {
  1138. DRM_ERROR("called with no initialization\n");
  1139. return -EINVAL;
  1140. }
  1141. return i915_wait_irq(dev, irqwait->irq_seq);
  1142. }
  1143. /* Called from drm generic code, passed 'crtc' which
  1144. * we use as a pipe index
  1145. */
  1146. int i915_enable_vblank(struct drm_device *dev, int pipe)
  1147. {
  1148. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1149. unsigned long irqflags;
  1150. if (!i915_pipe_enabled(dev, pipe))
  1151. return -EINVAL;
  1152. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1153. if (INTEL_INFO(dev)->gen >= 4)
  1154. i915_enable_pipestat(dev_priv, pipe,
  1155. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1156. else
  1157. i915_enable_pipestat(dev_priv, pipe,
  1158. PIPE_VBLANK_INTERRUPT_ENABLE);
  1159. /* maintain vblank delivery even in deep C-states */
  1160. if (dev_priv->info->gen == 3)
  1161. I915_WRITE(INSTPM, INSTPM_AGPBUSY_DIS << 16);
  1162. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1163. return 0;
  1164. }
  1165. int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1166. {
  1167. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1168. unsigned long irqflags;
  1169. if (!i915_pipe_enabled(dev, pipe))
  1170. return -EINVAL;
  1171. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1172. ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
  1173. DE_PIPEA_VBLANK: DE_PIPEB_VBLANK);
  1174. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1175. return 0;
  1176. }
  1177. /* Called from drm generic code, passed 'crtc' which
  1178. * we use as a pipe index
  1179. */
  1180. void i915_disable_vblank(struct drm_device *dev, int pipe)
  1181. {
  1182. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1183. unsigned long irqflags;
  1184. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1185. if (dev_priv->info->gen == 3)
  1186. I915_WRITE(INSTPM,
  1187. INSTPM_AGPBUSY_DIS << 16 | INSTPM_AGPBUSY_DIS);
  1188. i915_disable_pipestat(dev_priv, pipe,
  1189. PIPE_VBLANK_INTERRUPT_ENABLE |
  1190. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1191. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1192. }
  1193. void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  1194. {
  1195. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1196. unsigned long irqflags;
  1197. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1198. ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
  1199. DE_PIPEA_VBLANK: DE_PIPEB_VBLANK);
  1200. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1201. }
  1202. /* Set the vblank monitor pipe
  1203. */
  1204. int i915_vblank_pipe_set(struct drm_device *dev, void *data,
  1205. struct drm_file *file_priv)
  1206. {
  1207. drm_i915_private_t *dev_priv = dev->dev_private;
  1208. if (!dev_priv) {
  1209. DRM_ERROR("called with no initialization\n");
  1210. return -EINVAL;
  1211. }
  1212. return 0;
  1213. }
  1214. int i915_vblank_pipe_get(struct drm_device *dev, void *data,
  1215. struct drm_file *file_priv)
  1216. {
  1217. drm_i915_private_t *dev_priv = dev->dev_private;
  1218. drm_i915_vblank_pipe_t *pipe = data;
  1219. if (!dev_priv) {
  1220. DRM_ERROR("called with no initialization\n");
  1221. return -EINVAL;
  1222. }
  1223. pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  1224. return 0;
  1225. }
  1226. /**
  1227. * Schedule buffer swap at given vertical blank.
  1228. */
  1229. int i915_vblank_swap(struct drm_device *dev, void *data,
  1230. struct drm_file *file_priv)
  1231. {
  1232. /* The delayed swap mechanism was fundamentally racy, and has been
  1233. * removed. The model was that the client requested a delayed flip/swap
  1234. * from the kernel, then waited for vblank before continuing to perform
  1235. * rendering. The problem was that the kernel might wake the client
  1236. * up before it dispatched the vblank swap (since the lock has to be
  1237. * held while touching the ringbuffer), in which case the client would
  1238. * clear and start the next frame before the swap occurred, and
  1239. * flicker would occur in addition to likely missing the vblank.
  1240. *
  1241. * In the absence of this ioctl, userland falls back to a correct path
  1242. * of waiting for a vblank, then dispatching the swap on its own.
  1243. * Context switching to userland and back is plenty fast enough for
  1244. * meeting the requirements of vblank swapping.
  1245. */
  1246. return -EINVAL;
  1247. }
  1248. static u32
  1249. ring_last_seqno(struct intel_ring_buffer *ring)
  1250. {
  1251. return list_entry(ring->request_list.prev,
  1252. struct drm_i915_gem_request, list)->seqno;
  1253. }
  1254. static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err)
  1255. {
  1256. if (list_empty(&ring->request_list) ||
  1257. i915_seqno_passed(ring->get_seqno(ring), ring_last_seqno(ring))) {
  1258. /* Issue a wake-up to catch stuck h/w. */
  1259. if (ring->waiting_seqno && waitqueue_active(&ring->irq_queue)) {
  1260. DRM_ERROR("Hangcheck timer elapsed... %s idle [waiting on %d, at %d], missed IRQ?\n",
  1261. ring->name,
  1262. ring->waiting_seqno,
  1263. ring->get_seqno(ring));
  1264. wake_up_all(&ring->irq_queue);
  1265. *err = true;
  1266. }
  1267. return true;
  1268. }
  1269. return false;
  1270. }
  1271. static bool kick_ring(struct intel_ring_buffer *ring)
  1272. {
  1273. struct drm_device *dev = ring->dev;
  1274. struct drm_i915_private *dev_priv = dev->dev_private;
  1275. u32 tmp = I915_READ_CTL(ring);
  1276. if (tmp & RING_WAIT) {
  1277. DRM_ERROR("Kicking stuck wait on %s\n",
  1278. ring->name);
  1279. I915_WRITE_CTL(ring, tmp);
  1280. return true;
  1281. }
  1282. if (IS_GEN6(dev) &&
  1283. (tmp & RING_WAIT_SEMAPHORE)) {
  1284. DRM_ERROR("Kicking stuck semaphore on %s\n",
  1285. ring->name);
  1286. I915_WRITE_CTL(ring, tmp);
  1287. return true;
  1288. }
  1289. return false;
  1290. }
  1291. /**
  1292. * This is called when the chip hasn't reported back with completed
  1293. * batchbuffers in a long time. The first time this is called we simply record
  1294. * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
  1295. * again, we assume the chip is wedged and try to fix it.
  1296. */
  1297. void i915_hangcheck_elapsed(unsigned long data)
  1298. {
  1299. struct drm_device *dev = (struct drm_device *)data;
  1300. drm_i915_private_t *dev_priv = dev->dev_private;
  1301. uint32_t acthd, instdone, instdone1;
  1302. bool err = false;
  1303. /* If all work is done then ACTHD clearly hasn't advanced. */
  1304. if (i915_hangcheck_ring_idle(&dev_priv->ring[RCS], &err) &&
  1305. i915_hangcheck_ring_idle(&dev_priv->ring[VCS], &err) &&
  1306. i915_hangcheck_ring_idle(&dev_priv->ring[BCS], &err)) {
  1307. dev_priv->hangcheck_count = 0;
  1308. if (err)
  1309. goto repeat;
  1310. return;
  1311. }
  1312. if (INTEL_INFO(dev)->gen < 4) {
  1313. acthd = I915_READ(ACTHD);
  1314. instdone = I915_READ(INSTDONE);
  1315. instdone1 = 0;
  1316. } else {
  1317. acthd = I915_READ(ACTHD_I965);
  1318. instdone = I915_READ(INSTDONE_I965);
  1319. instdone1 = I915_READ(INSTDONE1);
  1320. }
  1321. if (dev_priv->last_acthd == acthd &&
  1322. dev_priv->last_instdone == instdone &&
  1323. dev_priv->last_instdone1 == instdone1) {
  1324. if (dev_priv->hangcheck_count++ > 1) {
  1325. DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
  1326. if (!IS_GEN2(dev)) {
  1327. /* Is the chip hanging on a WAIT_FOR_EVENT?
  1328. * If so we can simply poke the RB_WAIT bit
  1329. * and break the hang. This should work on
  1330. * all but the second generation chipsets.
  1331. */
  1332. if (kick_ring(&dev_priv->ring[RCS]))
  1333. goto repeat;
  1334. if (HAS_BSD(dev) &&
  1335. kick_ring(&dev_priv->ring[VCS]))
  1336. goto repeat;
  1337. if (HAS_BLT(dev) &&
  1338. kick_ring(&dev_priv->ring[BCS]))
  1339. goto repeat;
  1340. }
  1341. i915_handle_error(dev, true);
  1342. return;
  1343. }
  1344. } else {
  1345. dev_priv->hangcheck_count = 0;
  1346. dev_priv->last_acthd = acthd;
  1347. dev_priv->last_instdone = instdone;
  1348. dev_priv->last_instdone1 = instdone1;
  1349. }
  1350. repeat:
  1351. /* Reset timer case chip hangs without another request being added */
  1352. mod_timer(&dev_priv->hangcheck_timer,
  1353. jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
  1354. }
  1355. /* drm_dma.h hooks
  1356. */
  1357. void ironlake_irq_preinstall(struct drm_device *dev)
  1358. {
  1359. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1360. atomic_set(&dev_priv->irq_received, 0);
  1361. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  1362. INIT_WORK(&dev_priv->error_work, i915_error_work_func);
  1363. I915_WRITE(HWSTAM, 0xeffe);
  1364. /* XXX hotplug from PCH */
  1365. I915_WRITE(DEIMR, 0xffffffff);
  1366. I915_WRITE(DEIER, 0x0);
  1367. POSTING_READ(DEIER);
  1368. /* and GT */
  1369. I915_WRITE(GTIMR, 0xffffffff);
  1370. I915_WRITE(GTIER, 0x0);
  1371. POSTING_READ(GTIER);
  1372. /* south display irq */
  1373. I915_WRITE(SDEIMR, 0xffffffff);
  1374. I915_WRITE(SDEIER, 0x0);
  1375. POSTING_READ(SDEIER);
  1376. }
  1377. int ironlake_irq_postinstall(struct drm_device *dev)
  1378. {
  1379. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1380. /* enable kind of interrupts always enabled */
  1381. u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  1382. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE;
  1383. u32 render_irqs;
  1384. u32 hotplug_mask;
  1385. DRM_INIT_WAITQUEUE(&dev_priv->ring[RCS].irq_queue);
  1386. if (HAS_BSD(dev))
  1387. DRM_INIT_WAITQUEUE(&dev_priv->ring[VCS].irq_queue);
  1388. if (HAS_BLT(dev))
  1389. DRM_INIT_WAITQUEUE(&dev_priv->ring[BCS].irq_queue);
  1390. dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  1391. dev_priv->irq_mask = ~display_mask;
  1392. /* should always can generate irq */
  1393. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1394. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1395. I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK);
  1396. POSTING_READ(DEIER);
  1397. dev_priv->gt_irq_mask = ~0;
  1398. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1399. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1400. if (IS_GEN6(dev))
  1401. render_irqs =
  1402. GT_USER_INTERRUPT |
  1403. GT_GEN6_BSD_USER_INTERRUPT |
  1404. GT_BLT_USER_INTERRUPT;
  1405. else
  1406. render_irqs =
  1407. GT_USER_INTERRUPT |
  1408. GT_PIPE_NOTIFY |
  1409. GT_BSD_USER_INTERRUPT;
  1410. I915_WRITE(GTIER, render_irqs);
  1411. POSTING_READ(GTIER);
  1412. if (HAS_PCH_CPT(dev)) {
  1413. hotplug_mask = (SDE_CRT_HOTPLUG_CPT |
  1414. SDE_PORTB_HOTPLUG_CPT |
  1415. SDE_PORTC_HOTPLUG_CPT |
  1416. SDE_PORTD_HOTPLUG_CPT);
  1417. } else {
  1418. hotplug_mask = (SDE_CRT_HOTPLUG |
  1419. SDE_PORTB_HOTPLUG |
  1420. SDE_PORTC_HOTPLUG |
  1421. SDE_PORTD_HOTPLUG |
  1422. SDE_AUX_MASK);
  1423. }
  1424. dev_priv->pch_irq_mask = ~hotplug_mask;
  1425. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1426. I915_WRITE(SDEIMR, dev_priv->pch_irq_mask);
  1427. I915_WRITE(SDEIER, hotplug_mask);
  1428. POSTING_READ(SDEIER);
  1429. if (IS_IRONLAKE_M(dev)) {
  1430. /* Clear & enable PCU event interrupts */
  1431. I915_WRITE(DEIIR, DE_PCU_EVENT);
  1432. I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT);
  1433. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  1434. }
  1435. return 0;
  1436. }
  1437. void i915_driver_irq_preinstall(struct drm_device * dev)
  1438. {
  1439. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1440. int pipe;
  1441. atomic_set(&dev_priv->irq_received, 0);
  1442. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  1443. INIT_WORK(&dev_priv->error_work, i915_error_work_func);
  1444. INIT_WORK(&dev_priv->rps_work, gen6_pm_rps_work);
  1445. if (I915_HAS_HOTPLUG(dev)) {
  1446. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1447. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1448. }
  1449. I915_WRITE(HWSTAM, 0xeffe);
  1450. for_each_pipe(pipe)
  1451. I915_WRITE(PIPESTAT(pipe), 0);
  1452. I915_WRITE(IMR, 0xffffffff);
  1453. I915_WRITE(IER, 0x0);
  1454. POSTING_READ(IER);
  1455. }
  1456. /*
  1457. * Must be called after intel_modeset_init or hotplug interrupts won't be
  1458. * enabled correctly.
  1459. */
  1460. int i915_driver_irq_postinstall(struct drm_device *dev)
  1461. {
  1462. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1463. u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR;
  1464. u32 error_mask;
  1465. dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
  1466. /* Unmask the interrupts that we always want on. */
  1467. dev_priv->irq_mask = ~I915_INTERRUPT_ENABLE_FIX;
  1468. dev_priv->pipestat[0] = 0;
  1469. dev_priv->pipestat[1] = 0;
  1470. if (I915_HAS_HOTPLUG(dev)) {
  1471. /* Enable in IER... */
  1472. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  1473. /* and unmask in IMR */
  1474. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  1475. }
  1476. /*
  1477. * Enable some error detection, note the instruction error mask
  1478. * bit is reserved, so we leave it masked.
  1479. */
  1480. if (IS_G4X(dev)) {
  1481. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  1482. GM45_ERROR_MEM_PRIV |
  1483. GM45_ERROR_CP_PRIV |
  1484. I915_ERROR_MEMORY_REFRESH);
  1485. } else {
  1486. error_mask = ~(I915_ERROR_PAGE_TABLE |
  1487. I915_ERROR_MEMORY_REFRESH);
  1488. }
  1489. I915_WRITE(EMR, error_mask);
  1490. I915_WRITE(IMR, dev_priv->irq_mask);
  1491. I915_WRITE(IER, enable_mask);
  1492. POSTING_READ(IER);
  1493. if (I915_HAS_HOTPLUG(dev)) {
  1494. u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  1495. /* Note HDMI and DP share bits */
  1496. if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
  1497. hotplug_en |= HDMIB_HOTPLUG_INT_EN;
  1498. if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
  1499. hotplug_en |= HDMIC_HOTPLUG_INT_EN;
  1500. if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
  1501. hotplug_en |= HDMID_HOTPLUG_INT_EN;
  1502. if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS)
  1503. hotplug_en |= SDVOC_HOTPLUG_INT_EN;
  1504. if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS)
  1505. hotplug_en |= SDVOB_HOTPLUG_INT_EN;
  1506. if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
  1507. hotplug_en |= CRT_HOTPLUG_INT_EN;
  1508. /* Programming the CRT detection parameters tends
  1509. to generate a spurious hotplug event about three
  1510. seconds later. So just do it once.
  1511. */
  1512. if (IS_G4X(dev))
  1513. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  1514. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  1515. }
  1516. /* Ignore TV since it's buggy */
  1517. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  1518. }
  1519. intel_opregion_enable_asle(dev);
  1520. return 0;
  1521. }
  1522. void ironlake_irq_uninstall(struct drm_device *dev)
  1523. {
  1524. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1525. if (!dev_priv)
  1526. return;
  1527. dev_priv->vblank_pipe = 0;
  1528. I915_WRITE(HWSTAM, 0xffffffff);
  1529. I915_WRITE(DEIMR, 0xffffffff);
  1530. I915_WRITE(DEIER, 0x0);
  1531. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1532. I915_WRITE(GTIMR, 0xffffffff);
  1533. I915_WRITE(GTIER, 0x0);
  1534. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1535. }
  1536. void i915_driver_irq_uninstall(struct drm_device * dev)
  1537. {
  1538. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1539. int pipe;
  1540. if (!dev_priv)
  1541. return;
  1542. dev_priv->vblank_pipe = 0;
  1543. if (I915_HAS_HOTPLUG(dev)) {
  1544. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1545. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1546. }
  1547. I915_WRITE(HWSTAM, 0xffffffff);
  1548. for_each_pipe(pipe)
  1549. I915_WRITE(PIPESTAT(pipe), 0);
  1550. I915_WRITE(IMR, 0xffffffff);
  1551. I915_WRITE(IER, 0x0);
  1552. for_each_pipe(pipe)
  1553. I915_WRITE(PIPESTAT(pipe),
  1554. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  1555. I915_WRITE(IIR, I915_READ(IIR));
  1556. }