i915_irq.c 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  29. #include <linux/sysrq.h>
  30. #include <linux/slab.h>
  31. #include <drm/drmP.h>
  32. #include <drm/i915_drm.h>
  33. #include "i915_drv.h"
  34. #include "i915_trace.h"
  35. #include "intel_drv.h"
  36. static const u32 hpd_ibx[] = {
  37. [HPD_CRT] = SDE_CRT_HOTPLUG,
  38. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
  39. [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
  40. [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
  41. [HPD_PORT_D] = SDE_PORTD_HOTPLUG
  42. };
  43. static const u32 hpd_cpt[] = {
  44. [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
  45. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
  46. [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
  47. [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
  48. [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
  49. };
  50. static const u32 hpd_mask_i915[] = {
  51. [HPD_CRT] = CRT_HOTPLUG_INT_EN,
  52. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
  53. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
  54. [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
  55. [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
  56. [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
  57. };
  58. static const u32 hpd_status_gen4[] = {
  59. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  60. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
  61. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
  62. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  63. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  64. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
  65. };
  66. static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
  67. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  68. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
  69. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
  70. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  71. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  72. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
  73. };
  74. /* For display hotplug interrupt */
  75. static void
  76. ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  77. {
  78. assert_spin_locked(&dev_priv->irq_lock);
  79. if ((dev_priv->irq_mask & mask) != 0) {
  80. dev_priv->irq_mask &= ~mask;
  81. I915_WRITE(DEIMR, dev_priv->irq_mask);
  82. POSTING_READ(DEIMR);
  83. }
  84. }
  85. static void
  86. ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  87. {
  88. assert_spin_locked(&dev_priv->irq_lock);
  89. if ((dev_priv->irq_mask & mask) != mask) {
  90. dev_priv->irq_mask |= mask;
  91. I915_WRITE(DEIMR, dev_priv->irq_mask);
  92. POSTING_READ(DEIMR);
  93. }
  94. }
  95. static bool ivb_can_enable_err_int(struct drm_device *dev)
  96. {
  97. struct drm_i915_private *dev_priv = dev->dev_private;
  98. struct intel_crtc *crtc;
  99. enum pipe pipe;
  100. assert_spin_locked(&dev_priv->irq_lock);
  101. for_each_pipe(pipe) {
  102. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  103. if (crtc->cpu_fifo_underrun_disabled)
  104. return false;
  105. }
  106. return true;
  107. }
  108. static bool cpt_can_enable_serr_int(struct drm_device *dev)
  109. {
  110. struct drm_i915_private *dev_priv = dev->dev_private;
  111. enum pipe pipe;
  112. struct intel_crtc *crtc;
  113. assert_spin_locked(&dev_priv->irq_lock);
  114. for_each_pipe(pipe) {
  115. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  116. if (crtc->pch_fifo_underrun_disabled)
  117. return false;
  118. }
  119. return true;
  120. }
  121. static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
  122. enum pipe pipe, bool enable)
  123. {
  124. struct drm_i915_private *dev_priv = dev->dev_private;
  125. uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
  126. DE_PIPEB_FIFO_UNDERRUN;
  127. if (enable)
  128. ironlake_enable_display_irq(dev_priv, bit);
  129. else
  130. ironlake_disable_display_irq(dev_priv, bit);
  131. }
  132. static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
  133. enum pipe pipe, bool enable)
  134. {
  135. struct drm_i915_private *dev_priv = dev->dev_private;
  136. if (enable) {
  137. I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
  138. if (!ivb_can_enable_err_int(dev))
  139. return;
  140. ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
  141. } else {
  142. bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
  143. /* Change the state _after_ we've read out the current one. */
  144. ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
  145. if (!was_enabled &&
  146. (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
  147. DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
  148. pipe_name(pipe));
  149. }
  150. }
  151. }
  152. /**
  153. * ibx_display_interrupt_update - update SDEIMR
  154. * @dev_priv: driver private
  155. * @interrupt_mask: mask of interrupt bits to update
  156. * @enabled_irq_mask: mask of interrupt bits to enable
  157. */
  158. static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  159. uint32_t interrupt_mask,
  160. uint32_t enabled_irq_mask)
  161. {
  162. uint32_t sdeimr = I915_READ(SDEIMR);
  163. sdeimr &= ~interrupt_mask;
  164. sdeimr |= (~enabled_irq_mask & interrupt_mask);
  165. assert_spin_locked(&dev_priv->irq_lock);
  166. I915_WRITE(SDEIMR, sdeimr);
  167. POSTING_READ(SDEIMR);
  168. }
  169. #define ibx_enable_display_interrupt(dev_priv, bits) \
  170. ibx_display_interrupt_update((dev_priv), (bits), (bits))
  171. #define ibx_disable_display_interrupt(dev_priv, bits) \
  172. ibx_display_interrupt_update((dev_priv), (bits), 0)
  173. static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
  174. enum transcoder pch_transcoder,
  175. bool enable)
  176. {
  177. struct drm_i915_private *dev_priv = dev->dev_private;
  178. uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
  179. SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
  180. if (enable)
  181. ibx_enable_display_interrupt(dev_priv, bit);
  182. else
  183. ibx_disable_display_interrupt(dev_priv, bit);
  184. }
  185. static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
  186. enum transcoder pch_transcoder,
  187. bool enable)
  188. {
  189. struct drm_i915_private *dev_priv = dev->dev_private;
  190. if (enable) {
  191. I915_WRITE(SERR_INT,
  192. SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
  193. if (!cpt_can_enable_serr_int(dev))
  194. return;
  195. ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
  196. } else {
  197. uint32_t tmp = I915_READ(SERR_INT);
  198. bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
  199. /* Change the state _after_ we've read out the current one. */
  200. ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
  201. if (!was_enabled &&
  202. (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
  203. DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
  204. transcoder_name(pch_transcoder));
  205. }
  206. }
  207. }
  208. /**
  209. * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
  210. * @dev: drm device
  211. * @pipe: pipe
  212. * @enable: true if we want to report FIFO underrun errors, false otherwise
  213. *
  214. * This function makes us disable or enable CPU fifo underruns for a specific
  215. * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
  216. * reporting for one pipe may also disable all the other CPU error interruts for
  217. * the other pipes, due to the fact that there's just one interrupt mask/enable
  218. * bit for all the pipes.
  219. *
  220. * Returns the previous state of underrun reporting.
  221. */
  222. bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
  223. enum pipe pipe, bool enable)
  224. {
  225. struct drm_i915_private *dev_priv = dev->dev_private;
  226. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  227. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  228. unsigned long flags;
  229. bool ret;
  230. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  231. ret = !intel_crtc->cpu_fifo_underrun_disabled;
  232. if (enable == ret)
  233. goto done;
  234. intel_crtc->cpu_fifo_underrun_disabled = !enable;
  235. if (IS_GEN5(dev) || IS_GEN6(dev))
  236. ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
  237. else if (IS_GEN7(dev))
  238. ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
  239. done:
  240. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  241. return ret;
  242. }
  243. /**
  244. * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
  245. * @dev: drm device
  246. * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
  247. * @enable: true if we want to report FIFO underrun errors, false otherwise
  248. *
  249. * This function makes us disable or enable PCH fifo underruns for a specific
  250. * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
  251. * underrun reporting for one transcoder may also disable all the other PCH
  252. * error interruts for the other transcoders, due to the fact that there's just
  253. * one interrupt mask/enable bit for all the transcoders.
  254. *
  255. * Returns the previous state of underrun reporting.
  256. */
  257. bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
  258. enum transcoder pch_transcoder,
  259. bool enable)
  260. {
  261. struct drm_i915_private *dev_priv = dev->dev_private;
  262. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
  263. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  264. unsigned long flags;
  265. bool ret;
  266. /*
  267. * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
  268. * has only one pch transcoder A that all pipes can use. To avoid racy
  269. * pch transcoder -> pipe lookups from interrupt code simply store the
  270. * underrun statistics in crtc A. Since we never expose this anywhere
  271. * nor use it outside of the fifo underrun code here using the "wrong"
  272. * crtc on LPT won't cause issues.
  273. */
  274. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  275. ret = !intel_crtc->pch_fifo_underrun_disabled;
  276. if (enable == ret)
  277. goto done;
  278. intel_crtc->pch_fifo_underrun_disabled = !enable;
  279. if (HAS_PCH_IBX(dev))
  280. ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
  281. else
  282. cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
  283. done:
  284. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  285. return ret;
  286. }
  287. void
  288. i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  289. {
  290. u32 reg = PIPESTAT(pipe);
  291. u32 pipestat = I915_READ(reg) & 0x7fff0000;
  292. assert_spin_locked(&dev_priv->irq_lock);
  293. if ((pipestat & mask) == mask)
  294. return;
  295. /* Enable the interrupt, clear any pending status */
  296. pipestat |= mask | (mask >> 16);
  297. I915_WRITE(reg, pipestat);
  298. POSTING_READ(reg);
  299. }
  300. void
  301. i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
  302. {
  303. u32 reg = PIPESTAT(pipe);
  304. u32 pipestat = I915_READ(reg) & 0x7fff0000;
  305. assert_spin_locked(&dev_priv->irq_lock);
  306. if ((pipestat & mask) == 0)
  307. return;
  308. pipestat &= ~mask;
  309. I915_WRITE(reg, pipestat);
  310. POSTING_READ(reg);
  311. }
  312. /**
  313. * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
  314. */
  315. static void i915_enable_asle_pipestat(struct drm_device *dev)
  316. {
  317. drm_i915_private_t *dev_priv = dev->dev_private;
  318. unsigned long irqflags;
  319. if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
  320. return;
  321. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  322. i915_enable_pipestat(dev_priv, 1, PIPE_LEGACY_BLC_EVENT_ENABLE);
  323. if (INTEL_INFO(dev)->gen >= 4)
  324. i915_enable_pipestat(dev_priv, 0, PIPE_LEGACY_BLC_EVENT_ENABLE);
  325. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  326. }
  327. /**
  328. * i915_pipe_enabled - check if a pipe is enabled
  329. * @dev: DRM device
  330. * @pipe: pipe to check
  331. *
  332. * Reading certain registers when the pipe is disabled can hang the chip.
  333. * Use this routine to make sure the PLL is running and the pipe is active
  334. * before reading such registers if unsure.
  335. */
  336. static int
  337. i915_pipe_enabled(struct drm_device *dev, int pipe)
  338. {
  339. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  340. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  341. /* Locking is horribly broken here, but whatever. */
  342. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  343. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  344. return intel_crtc->active;
  345. } else {
  346. return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
  347. }
  348. }
  349. /* Called from drm generic code, passed a 'crtc', which
  350. * we use as a pipe index
  351. */
  352. static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  353. {
  354. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  355. unsigned long high_frame;
  356. unsigned long low_frame;
  357. u32 high1, high2, low;
  358. if (!i915_pipe_enabled(dev, pipe)) {
  359. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  360. "pipe %c\n", pipe_name(pipe));
  361. return 0;
  362. }
  363. high_frame = PIPEFRAME(pipe);
  364. low_frame = PIPEFRAMEPIXEL(pipe);
  365. /*
  366. * High & low register fields aren't synchronized, so make sure
  367. * we get a low value that's stable across two reads of the high
  368. * register.
  369. */
  370. do {
  371. high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  372. low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK;
  373. high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  374. } while (high1 != high2);
  375. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  376. low >>= PIPE_FRAME_LOW_SHIFT;
  377. return (high1 << 8) | low;
  378. }
  379. static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  380. {
  381. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  382. int reg = PIPE_FRMCOUNT_GM45(pipe);
  383. if (!i915_pipe_enabled(dev, pipe)) {
  384. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  385. "pipe %c\n", pipe_name(pipe));
  386. return 0;
  387. }
  388. return I915_READ(reg);
  389. }
  390. static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
  391. int *vpos, int *hpos)
  392. {
  393. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  394. u32 vbl = 0, position = 0;
  395. int vbl_start, vbl_end, htotal, vtotal;
  396. bool in_vbl = true;
  397. int ret = 0;
  398. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  399. pipe);
  400. if (!i915_pipe_enabled(dev, pipe)) {
  401. DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
  402. "pipe %c\n", pipe_name(pipe));
  403. return 0;
  404. }
  405. /* Get vtotal. */
  406. vtotal = 1 + ((I915_READ(VTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
  407. if (INTEL_INFO(dev)->gen >= 4) {
  408. /* No obvious pixelcount register. Only query vertical
  409. * scanout position from Display scan line register.
  410. */
  411. position = I915_READ(PIPEDSL(pipe));
  412. /* Decode into vertical scanout position. Don't have
  413. * horizontal scanout position.
  414. */
  415. *vpos = position & 0x1fff;
  416. *hpos = 0;
  417. } else {
  418. /* Have access to pixelcount since start of frame.
  419. * We can split this into vertical and horizontal
  420. * scanout position.
  421. */
  422. position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  423. htotal = 1 + ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
  424. *vpos = position / htotal;
  425. *hpos = position - (*vpos * htotal);
  426. }
  427. /* Query vblank area. */
  428. vbl = I915_READ(VBLANK(cpu_transcoder));
  429. /* Test position against vblank region. */
  430. vbl_start = vbl & 0x1fff;
  431. vbl_end = (vbl >> 16) & 0x1fff;
  432. if ((*vpos < vbl_start) || (*vpos > vbl_end))
  433. in_vbl = false;
  434. /* Inside "upper part" of vblank area? Apply corrective offset: */
  435. if (in_vbl && (*vpos >= vbl_start))
  436. *vpos = *vpos - vtotal;
  437. /* Readouts valid? */
  438. if (vbl > 0)
  439. ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
  440. /* In vblank? */
  441. if (in_vbl)
  442. ret |= DRM_SCANOUTPOS_INVBL;
  443. return ret;
  444. }
  445. static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
  446. int *max_error,
  447. struct timeval *vblank_time,
  448. unsigned flags)
  449. {
  450. struct drm_crtc *crtc;
  451. if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
  452. DRM_ERROR("Invalid crtc %d\n", pipe);
  453. return -EINVAL;
  454. }
  455. /* Get drm_crtc to timestamp: */
  456. crtc = intel_get_crtc_for_pipe(dev, pipe);
  457. if (crtc == NULL) {
  458. DRM_ERROR("Invalid crtc %d\n", pipe);
  459. return -EINVAL;
  460. }
  461. if (!crtc->enabled) {
  462. DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
  463. return -EBUSY;
  464. }
  465. /* Helper routine in DRM core does all the work: */
  466. return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
  467. vblank_time, flags,
  468. crtc);
  469. }
  470. static int intel_hpd_irq_event(struct drm_device *dev, struct drm_connector *connector)
  471. {
  472. enum drm_connector_status old_status;
  473. WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
  474. old_status = connector->status;
  475. connector->status = connector->funcs->detect(connector, false);
  476. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n",
  477. connector->base.id,
  478. drm_get_connector_name(connector),
  479. old_status, connector->status);
  480. return (old_status != connector->status);
  481. }
  482. /*
  483. * Handle hotplug events outside the interrupt handler proper.
  484. */
  485. #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
  486. static void i915_hotplug_work_func(struct work_struct *work)
  487. {
  488. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  489. hotplug_work);
  490. struct drm_device *dev = dev_priv->dev;
  491. struct drm_mode_config *mode_config = &dev->mode_config;
  492. struct intel_connector *intel_connector;
  493. struct intel_encoder *intel_encoder;
  494. struct drm_connector *connector;
  495. unsigned long irqflags;
  496. bool hpd_disabled = false;
  497. bool changed = false;
  498. u32 hpd_event_bits;
  499. /* HPD irq before everything is fully set up. */
  500. if (!dev_priv->enable_hotplug_processing)
  501. return;
  502. mutex_lock(&mode_config->mutex);
  503. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  504. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  505. hpd_event_bits = dev_priv->hpd_event_bits;
  506. dev_priv->hpd_event_bits = 0;
  507. list_for_each_entry(connector, &mode_config->connector_list, head) {
  508. intel_connector = to_intel_connector(connector);
  509. intel_encoder = intel_connector->encoder;
  510. if (intel_encoder->hpd_pin > HPD_NONE &&
  511. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
  512. connector->polled == DRM_CONNECTOR_POLL_HPD) {
  513. DRM_INFO("HPD interrupt storm detected on connector %s: "
  514. "switching from hotplug detection to polling\n",
  515. drm_get_connector_name(connector));
  516. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
  517. connector->polled = DRM_CONNECTOR_POLL_CONNECT
  518. | DRM_CONNECTOR_POLL_DISCONNECT;
  519. hpd_disabled = true;
  520. }
  521. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  522. DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
  523. drm_get_connector_name(connector), intel_encoder->hpd_pin);
  524. }
  525. }
  526. /* if there were no outputs to poll, poll was disabled,
  527. * therefore make sure it's enabled when disabling HPD on
  528. * some connectors */
  529. if (hpd_disabled) {
  530. drm_kms_helper_poll_enable(dev);
  531. mod_timer(&dev_priv->hotplug_reenable_timer,
  532. jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
  533. }
  534. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  535. list_for_each_entry(connector, &mode_config->connector_list, head) {
  536. intel_connector = to_intel_connector(connector);
  537. intel_encoder = intel_connector->encoder;
  538. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  539. if (intel_encoder->hot_plug)
  540. intel_encoder->hot_plug(intel_encoder);
  541. if (intel_hpd_irq_event(dev, connector))
  542. changed = true;
  543. }
  544. }
  545. mutex_unlock(&mode_config->mutex);
  546. if (changed)
  547. drm_kms_helper_hotplug_event(dev);
  548. }
  549. static void ironlake_rps_change_irq_handler(struct drm_device *dev)
  550. {
  551. drm_i915_private_t *dev_priv = dev->dev_private;
  552. u32 busy_up, busy_down, max_avg, min_avg;
  553. u8 new_delay;
  554. spin_lock(&mchdev_lock);
  555. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  556. new_delay = dev_priv->ips.cur_delay;
  557. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  558. busy_up = I915_READ(RCPREVBSYTUPAVG);
  559. busy_down = I915_READ(RCPREVBSYTDNAVG);
  560. max_avg = I915_READ(RCBMAXAVG);
  561. min_avg = I915_READ(RCBMINAVG);
  562. /* Handle RCS change request from hw */
  563. if (busy_up > max_avg) {
  564. if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
  565. new_delay = dev_priv->ips.cur_delay - 1;
  566. if (new_delay < dev_priv->ips.max_delay)
  567. new_delay = dev_priv->ips.max_delay;
  568. } else if (busy_down < min_avg) {
  569. if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
  570. new_delay = dev_priv->ips.cur_delay + 1;
  571. if (new_delay > dev_priv->ips.min_delay)
  572. new_delay = dev_priv->ips.min_delay;
  573. }
  574. if (ironlake_set_drps(dev, new_delay))
  575. dev_priv->ips.cur_delay = new_delay;
  576. spin_unlock(&mchdev_lock);
  577. return;
  578. }
  579. static void notify_ring(struct drm_device *dev,
  580. struct intel_ring_buffer *ring)
  581. {
  582. if (ring->obj == NULL)
  583. return;
  584. trace_i915_gem_request_complete(ring, ring->get_seqno(ring, false));
  585. wake_up_all(&ring->irq_queue);
  586. i915_queue_hangcheck(dev);
  587. }
  588. static void gen6_pm_rps_work(struct work_struct *work)
  589. {
  590. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  591. rps.work);
  592. u32 pm_iir, pm_imr;
  593. u8 new_delay;
  594. spin_lock_irq(&dev_priv->irq_lock);
  595. pm_iir = dev_priv->rps.pm_iir;
  596. dev_priv->rps.pm_iir = 0;
  597. pm_imr = I915_READ(GEN6_PMIMR);
  598. /* Make sure not to corrupt PMIMR state used by ringbuffer code */
  599. I915_WRITE(GEN6_PMIMR, pm_imr & ~GEN6_PM_RPS_EVENTS);
  600. spin_unlock_irq(&dev_priv->irq_lock);
  601. if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
  602. return;
  603. mutex_lock(&dev_priv->rps.hw_lock);
  604. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
  605. new_delay = dev_priv->rps.cur_delay + 1;
  606. /*
  607. * For better performance, jump directly
  608. * to RPe if we're below it.
  609. */
  610. if (IS_VALLEYVIEW(dev_priv->dev) &&
  611. dev_priv->rps.cur_delay < dev_priv->rps.rpe_delay)
  612. new_delay = dev_priv->rps.rpe_delay;
  613. } else
  614. new_delay = dev_priv->rps.cur_delay - 1;
  615. /* sysfs frequency interfaces may have snuck in while servicing the
  616. * interrupt
  617. */
  618. if (new_delay >= dev_priv->rps.min_delay &&
  619. new_delay <= dev_priv->rps.max_delay) {
  620. if (IS_VALLEYVIEW(dev_priv->dev))
  621. valleyview_set_rps(dev_priv->dev, new_delay);
  622. else
  623. gen6_set_rps(dev_priv->dev, new_delay);
  624. }
  625. if (IS_VALLEYVIEW(dev_priv->dev)) {
  626. /*
  627. * On VLV, when we enter RC6 we may not be at the minimum
  628. * voltage level, so arm a timer to check. It should only
  629. * fire when there's activity or once after we've entered
  630. * RC6, and then won't be re-armed until the next RPS interrupt.
  631. */
  632. mod_delayed_work(dev_priv->wq, &dev_priv->rps.vlv_work,
  633. msecs_to_jiffies(100));
  634. }
  635. mutex_unlock(&dev_priv->rps.hw_lock);
  636. }
  637. /**
  638. * ivybridge_parity_work - Workqueue called when a parity error interrupt
  639. * occurred.
  640. * @work: workqueue struct
  641. *
  642. * Doesn't actually do anything except notify userspace. As a consequence of
  643. * this event, userspace should try to remap the bad rows since statistically
  644. * it is likely the same row is more likely to go bad again.
  645. */
  646. static void ivybridge_parity_work(struct work_struct *work)
  647. {
  648. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  649. l3_parity.error_work);
  650. u32 error_status, row, bank, subbank;
  651. char *parity_event[5];
  652. uint32_t misccpctl;
  653. unsigned long flags;
  654. /* We must turn off DOP level clock gating to access the L3 registers.
  655. * In order to prevent a get/put style interface, acquire struct mutex
  656. * any time we access those registers.
  657. */
  658. mutex_lock(&dev_priv->dev->struct_mutex);
  659. misccpctl = I915_READ(GEN7_MISCCPCTL);
  660. I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  661. POSTING_READ(GEN7_MISCCPCTL);
  662. error_status = I915_READ(GEN7_L3CDERRST1);
  663. row = GEN7_PARITY_ERROR_ROW(error_status);
  664. bank = GEN7_PARITY_ERROR_BANK(error_status);
  665. subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
  666. I915_WRITE(GEN7_L3CDERRST1, GEN7_PARITY_ERROR_VALID |
  667. GEN7_L3CDERRST1_ENABLE);
  668. POSTING_READ(GEN7_L3CDERRST1);
  669. I915_WRITE(GEN7_MISCCPCTL, misccpctl);
  670. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  671. dev_priv->gt_irq_mask &= ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  672. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  673. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  674. mutex_unlock(&dev_priv->dev->struct_mutex);
  675. parity_event[0] = I915_L3_PARITY_UEVENT "=1";
  676. parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
  677. parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
  678. parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
  679. parity_event[4] = NULL;
  680. kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj,
  681. KOBJ_CHANGE, parity_event);
  682. DRM_DEBUG("Parity error: Row = %d, Bank = %d, Sub bank = %d.\n",
  683. row, bank, subbank);
  684. kfree(parity_event[3]);
  685. kfree(parity_event[2]);
  686. kfree(parity_event[1]);
  687. }
  688. static void ivybridge_parity_error_irq_handler(struct drm_device *dev)
  689. {
  690. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  691. if (!HAS_L3_GPU_CACHE(dev))
  692. return;
  693. spin_lock(&dev_priv->irq_lock);
  694. dev_priv->gt_irq_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  695. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  696. spin_unlock(&dev_priv->irq_lock);
  697. queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
  698. }
  699. static void ilk_gt_irq_handler(struct drm_device *dev,
  700. struct drm_i915_private *dev_priv,
  701. u32 gt_iir)
  702. {
  703. if (gt_iir &
  704. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  705. notify_ring(dev, &dev_priv->ring[RCS]);
  706. if (gt_iir & ILK_BSD_USER_INTERRUPT)
  707. notify_ring(dev, &dev_priv->ring[VCS]);
  708. }
  709. static void snb_gt_irq_handler(struct drm_device *dev,
  710. struct drm_i915_private *dev_priv,
  711. u32 gt_iir)
  712. {
  713. if (gt_iir &
  714. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  715. notify_ring(dev, &dev_priv->ring[RCS]);
  716. if (gt_iir & GT_BSD_USER_INTERRUPT)
  717. notify_ring(dev, &dev_priv->ring[VCS]);
  718. if (gt_iir & GT_BLT_USER_INTERRUPT)
  719. notify_ring(dev, &dev_priv->ring[BCS]);
  720. if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
  721. GT_BSD_CS_ERROR_INTERRUPT |
  722. GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
  723. DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
  724. i915_handle_error(dev, false);
  725. }
  726. if (gt_iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
  727. ivybridge_parity_error_irq_handler(dev);
  728. }
  729. /* Legacy way of handling PM interrupts */
  730. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv,
  731. u32 pm_iir)
  732. {
  733. /*
  734. * IIR bits should never already be set because IMR should
  735. * prevent an interrupt from being shown in IIR. The warning
  736. * displays a case where we've unsafely cleared
  737. * dev_priv->rps.pm_iir. Although missing an interrupt of the same
  738. * type is not a problem, it displays a problem in the logic.
  739. *
  740. * The mask bit in IMR is cleared by dev_priv->rps.work.
  741. */
  742. spin_lock(&dev_priv->irq_lock);
  743. dev_priv->rps.pm_iir |= pm_iir;
  744. I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
  745. POSTING_READ(GEN6_PMIMR);
  746. spin_unlock(&dev_priv->irq_lock);
  747. queue_work(dev_priv->wq, &dev_priv->rps.work);
  748. }
  749. #define HPD_STORM_DETECT_PERIOD 1000
  750. #define HPD_STORM_THRESHOLD 5
  751. static inline void intel_hpd_irq_handler(struct drm_device *dev,
  752. u32 hotplug_trigger,
  753. const u32 *hpd)
  754. {
  755. drm_i915_private_t *dev_priv = dev->dev_private;
  756. int i;
  757. bool storm_detected = false;
  758. if (!hotplug_trigger)
  759. return;
  760. spin_lock(&dev_priv->irq_lock);
  761. for (i = 1; i < HPD_NUM_PINS; i++) {
  762. WARN(((hpd[i] & hotplug_trigger) &&
  763. dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED),
  764. "Received HPD interrupt although disabled\n");
  765. if (!(hpd[i] & hotplug_trigger) ||
  766. dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
  767. continue;
  768. dev_priv->hpd_event_bits |= (1 << i);
  769. if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
  770. dev_priv->hpd_stats[i].hpd_last_jiffies
  771. + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
  772. dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
  773. dev_priv->hpd_stats[i].hpd_cnt = 0;
  774. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
  775. } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
  776. dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
  777. dev_priv->hpd_event_bits &= ~(1 << i);
  778. DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
  779. storm_detected = true;
  780. } else {
  781. dev_priv->hpd_stats[i].hpd_cnt++;
  782. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
  783. dev_priv->hpd_stats[i].hpd_cnt);
  784. }
  785. }
  786. if (storm_detected)
  787. dev_priv->display.hpd_irq_setup(dev);
  788. spin_unlock(&dev_priv->irq_lock);
  789. queue_work(dev_priv->wq,
  790. &dev_priv->hotplug_work);
  791. }
  792. static void gmbus_irq_handler(struct drm_device *dev)
  793. {
  794. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  795. wake_up_all(&dev_priv->gmbus_wait_queue);
  796. }
  797. static void dp_aux_irq_handler(struct drm_device *dev)
  798. {
  799. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  800. wake_up_all(&dev_priv->gmbus_wait_queue);
  801. }
  802. /* Unlike gen6_rps_irq_handler() from which this function is originally derived,
  803. * we must be able to deal with other PM interrupts. This is complicated because
  804. * of the way in which we use the masks to defer the RPS work (which for
  805. * posterity is necessary because of forcewake).
  806. */
  807. static void hsw_pm_irq_handler(struct drm_i915_private *dev_priv,
  808. u32 pm_iir)
  809. {
  810. if (pm_iir & GEN6_PM_RPS_EVENTS) {
  811. spin_lock(&dev_priv->irq_lock);
  812. dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
  813. I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
  814. /* never want to mask useful interrupts. (also posting read) */
  815. WARN_ON(I915_READ_NOTRACE(GEN6_PMIMR) & ~GEN6_PM_RPS_EVENTS);
  816. spin_unlock(&dev_priv->irq_lock);
  817. queue_work(dev_priv->wq, &dev_priv->rps.work);
  818. }
  819. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  820. notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
  821. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
  822. DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
  823. i915_handle_error(dev_priv->dev, false);
  824. }
  825. }
  826. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  827. {
  828. struct drm_device *dev = (struct drm_device *) arg;
  829. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  830. u32 iir, gt_iir, pm_iir;
  831. irqreturn_t ret = IRQ_NONE;
  832. unsigned long irqflags;
  833. int pipe;
  834. u32 pipe_stats[I915_MAX_PIPES];
  835. atomic_inc(&dev_priv->irq_received);
  836. while (true) {
  837. iir = I915_READ(VLV_IIR);
  838. gt_iir = I915_READ(GTIIR);
  839. pm_iir = I915_READ(GEN6_PMIIR);
  840. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  841. goto out;
  842. ret = IRQ_HANDLED;
  843. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  844. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  845. for_each_pipe(pipe) {
  846. int reg = PIPESTAT(pipe);
  847. pipe_stats[pipe] = I915_READ(reg);
  848. /*
  849. * Clear the PIPE*STAT regs before the IIR
  850. */
  851. if (pipe_stats[pipe] & 0x8000ffff) {
  852. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  853. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  854. pipe_name(pipe));
  855. I915_WRITE(reg, pipe_stats[pipe]);
  856. }
  857. }
  858. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  859. for_each_pipe(pipe) {
  860. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
  861. drm_handle_vblank(dev, pipe);
  862. if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
  863. intel_prepare_page_flip(dev, pipe);
  864. intel_finish_page_flip(dev, pipe);
  865. }
  866. }
  867. /* Consume port. Then clear IIR or we'll miss events */
  868. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  869. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  870. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  871. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  872. hotplug_status);
  873. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  874. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  875. I915_READ(PORT_HOTPLUG_STAT);
  876. }
  877. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  878. gmbus_irq_handler(dev);
  879. if (pm_iir & GEN6_PM_RPS_EVENTS)
  880. gen6_rps_irq_handler(dev_priv, pm_iir);
  881. I915_WRITE(GTIIR, gt_iir);
  882. I915_WRITE(GEN6_PMIIR, pm_iir);
  883. I915_WRITE(VLV_IIR, iir);
  884. }
  885. out:
  886. return ret;
  887. }
  888. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  889. {
  890. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  891. int pipe;
  892. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  893. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
  894. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  895. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  896. SDE_AUDIO_POWER_SHIFT);
  897. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  898. port_name(port));
  899. }
  900. if (pch_iir & SDE_AUX_MASK)
  901. dp_aux_irq_handler(dev);
  902. if (pch_iir & SDE_GMBUS)
  903. gmbus_irq_handler(dev);
  904. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  905. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  906. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  907. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  908. if (pch_iir & SDE_POISON)
  909. DRM_ERROR("PCH poison interrupt\n");
  910. if (pch_iir & SDE_FDI_MASK)
  911. for_each_pipe(pipe)
  912. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  913. pipe_name(pipe),
  914. I915_READ(FDI_RX_IIR(pipe)));
  915. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  916. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  917. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  918. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  919. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  920. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  921. false))
  922. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  923. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  924. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  925. false))
  926. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  927. }
  928. static void ivb_err_int_handler(struct drm_device *dev)
  929. {
  930. struct drm_i915_private *dev_priv = dev->dev_private;
  931. u32 err_int = I915_READ(GEN7_ERR_INT);
  932. if (err_int & ERR_INT_POISON)
  933. DRM_ERROR("Poison interrupt\n");
  934. if (err_int & ERR_INT_FIFO_UNDERRUN_A)
  935. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
  936. DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
  937. if (err_int & ERR_INT_FIFO_UNDERRUN_B)
  938. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
  939. DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
  940. if (err_int & ERR_INT_FIFO_UNDERRUN_C)
  941. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false))
  942. DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n");
  943. I915_WRITE(GEN7_ERR_INT, err_int);
  944. }
  945. static void cpt_serr_int_handler(struct drm_device *dev)
  946. {
  947. struct drm_i915_private *dev_priv = dev->dev_private;
  948. u32 serr_int = I915_READ(SERR_INT);
  949. if (serr_int & SERR_INT_POISON)
  950. DRM_ERROR("PCH poison interrupt\n");
  951. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  952. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  953. false))
  954. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  955. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  956. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  957. false))
  958. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  959. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  960. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
  961. false))
  962. DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
  963. I915_WRITE(SERR_INT, serr_int);
  964. }
  965. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  966. {
  967. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  968. int pipe;
  969. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  970. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
  971. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  972. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  973. SDE_AUDIO_POWER_SHIFT_CPT);
  974. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  975. port_name(port));
  976. }
  977. if (pch_iir & SDE_AUX_MASK_CPT)
  978. dp_aux_irq_handler(dev);
  979. if (pch_iir & SDE_GMBUS_CPT)
  980. gmbus_irq_handler(dev);
  981. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  982. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  983. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  984. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  985. if (pch_iir & SDE_FDI_MASK_CPT)
  986. for_each_pipe(pipe)
  987. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  988. pipe_name(pipe),
  989. I915_READ(FDI_RX_IIR(pipe)));
  990. if (pch_iir & SDE_ERROR_CPT)
  991. cpt_serr_int_handler(dev);
  992. }
  993. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  994. {
  995. struct drm_i915_private *dev_priv = dev->dev_private;
  996. if (de_iir & DE_AUX_CHANNEL_A)
  997. dp_aux_irq_handler(dev);
  998. if (de_iir & DE_GSE)
  999. intel_opregion_asle_intr(dev);
  1000. if (de_iir & DE_PIPEA_VBLANK)
  1001. drm_handle_vblank(dev, 0);
  1002. if (de_iir & DE_PIPEB_VBLANK)
  1003. drm_handle_vblank(dev, 1);
  1004. if (de_iir & DE_POISON)
  1005. DRM_ERROR("Poison interrupt\n");
  1006. if (de_iir & DE_PIPEA_FIFO_UNDERRUN)
  1007. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
  1008. DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
  1009. if (de_iir & DE_PIPEB_FIFO_UNDERRUN)
  1010. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
  1011. DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
  1012. if (de_iir & DE_PLANEA_FLIP_DONE) {
  1013. intel_prepare_page_flip(dev, 0);
  1014. intel_finish_page_flip_plane(dev, 0);
  1015. }
  1016. if (de_iir & DE_PLANEB_FLIP_DONE) {
  1017. intel_prepare_page_flip(dev, 1);
  1018. intel_finish_page_flip_plane(dev, 1);
  1019. }
  1020. /* check event from PCH */
  1021. if (de_iir & DE_PCH_EVENT) {
  1022. u32 pch_iir = I915_READ(SDEIIR);
  1023. if (HAS_PCH_CPT(dev))
  1024. cpt_irq_handler(dev, pch_iir);
  1025. else
  1026. ibx_irq_handler(dev, pch_iir);
  1027. /* should clear PCH hotplug event before clear CPU irq */
  1028. I915_WRITE(SDEIIR, pch_iir);
  1029. }
  1030. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1031. ironlake_rps_change_irq_handler(dev);
  1032. }
  1033. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1034. {
  1035. struct drm_i915_private *dev_priv = dev->dev_private;
  1036. int i;
  1037. if (de_iir & DE_ERR_INT_IVB)
  1038. ivb_err_int_handler(dev);
  1039. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1040. dp_aux_irq_handler(dev);
  1041. if (de_iir & DE_GSE_IVB)
  1042. intel_opregion_asle_intr(dev);
  1043. for (i = 0; i < 3; i++) {
  1044. if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
  1045. drm_handle_vblank(dev, i);
  1046. if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
  1047. intel_prepare_page_flip(dev, i);
  1048. intel_finish_page_flip_plane(dev, i);
  1049. }
  1050. }
  1051. /* check event from PCH */
  1052. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1053. u32 pch_iir = I915_READ(SDEIIR);
  1054. cpt_irq_handler(dev, pch_iir);
  1055. /* clear PCH hotplug event before clear CPU irq */
  1056. I915_WRITE(SDEIIR, pch_iir);
  1057. }
  1058. }
  1059. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1060. {
  1061. struct drm_device *dev = (struct drm_device *) arg;
  1062. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1063. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1064. irqreturn_t ret = IRQ_NONE;
  1065. atomic_inc(&dev_priv->irq_received);
  1066. /* We get interrupts on unclaimed registers, so check for this before we
  1067. * do any I915_{READ,WRITE}. */
  1068. intel_uncore_check_errors(dev);
  1069. /* disable master interrupt before clearing iir */
  1070. de_ier = I915_READ(DEIER);
  1071. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1072. POSTING_READ(DEIER);
  1073. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1074. * interrupts will will be stored on its back queue, and then we'll be
  1075. * able to process them after we restore SDEIER (as soon as we restore
  1076. * it, we'll get an interrupt if SDEIIR still has something to process
  1077. * due to its back queue). */
  1078. if (!HAS_PCH_NOP(dev)) {
  1079. sde_ier = I915_READ(SDEIER);
  1080. I915_WRITE(SDEIER, 0);
  1081. POSTING_READ(SDEIER);
  1082. }
  1083. /* On Haswell, also mask ERR_INT because we don't want to risk
  1084. * generating "unclaimed register" interrupts from inside the interrupt
  1085. * handler. */
  1086. if (IS_HASWELL(dev)) {
  1087. spin_lock(&dev_priv->irq_lock);
  1088. ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
  1089. spin_unlock(&dev_priv->irq_lock);
  1090. }
  1091. gt_iir = I915_READ(GTIIR);
  1092. if (gt_iir) {
  1093. if (INTEL_INFO(dev)->gen >= 6)
  1094. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1095. else
  1096. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1097. I915_WRITE(GTIIR, gt_iir);
  1098. ret = IRQ_HANDLED;
  1099. }
  1100. de_iir = I915_READ(DEIIR);
  1101. if (de_iir) {
  1102. if (INTEL_INFO(dev)->gen >= 7)
  1103. ivb_display_irq_handler(dev, de_iir);
  1104. else
  1105. ilk_display_irq_handler(dev, de_iir);
  1106. I915_WRITE(DEIIR, de_iir);
  1107. ret = IRQ_HANDLED;
  1108. }
  1109. if (INTEL_INFO(dev)->gen >= 6) {
  1110. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1111. if (pm_iir) {
  1112. if (IS_HASWELL(dev))
  1113. hsw_pm_irq_handler(dev_priv, pm_iir);
  1114. else if (pm_iir & GEN6_PM_RPS_EVENTS)
  1115. gen6_rps_irq_handler(dev_priv, pm_iir);
  1116. I915_WRITE(GEN6_PMIIR, pm_iir);
  1117. ret = IRQ_HANDLED;
  1118. }
  1119. }
  1120. if (IS_HASWELL(dev)) {
  1121. spin_lock(&dev_priv->irq_lock);
  1122. if (ivb_can_enable_err_int(dev))
  1123. ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
  1124. spin_unlock(&dev_priv->irq_lock);
  1125. }
  1126. I915_WRITE(DEIER, de_ier);
  1127. POSTING_READ(DEIER);
  1128. if (!HAS_PCH_NOP(dev)) {
  1129. I915_WRITE(SDEIER, sde_ier);
  1130. POSTING_READ(SDEIER);
  1131. }
  1132. return ret;
  1133. }
  1134. /**
  1135. * i915_error_work_func - do process context error handling work
  1136. * @work: work struct
  1137. *
  1138. * Fire an error uevent so userspace can see that a hang or error
  1139. * was detected.
  1140. */
  1141. static void i915_error_work_func(struct work_struct *work)
  1142. {
  1143. struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
  1144. work);
  1145. drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
  1146. gpu_error);
  1147. struct drm_device *dev = dev_priv->dev;
  1148. struct intel_ring_buffer *ring;
  1149. char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
  1150. char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
  1151. char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
  1152. int i, ret;
  1153. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  1154. /*
  1155. * Note that there's only one work item which does gpu resets, so we
  1156. * need not worry about concurrent gpu resets potentially incrementing
  1157. * error->reset_counter twice. We only need to take care of another
  1158. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1159. * quick check for that is good enough: schedule_work ensures the
  1160. * correct ordering between hang detection and this work item, and since
  1161. * the reset in-progress bit is only ever set by code outside of this
  1162. * work we don't need to worry about any other races.
  1163. */
  1164. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1165. DRM_DEBUG_DRIVER("resetting chip\n");
  1166. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
  1167. reset_event);
  1168. ret = i915_reset(dev);
  1169. if (ret == 0) {
  1170. /*
  1171. * After all the gem state is reset, increment the reset
  1172. * counter and wake up everyone waiting for the reset to
  1173. * complete.
  1174. *
  1175. * Since unlock operations are a one-sided barrier only,
  1176. * we need to insert a barrier here to order any seqno
  1177. * updates before
  1178. * the counter increment.
  1179. */
  1180. smp_mb__before_atomic_inc();
  1181. atomic_inc(&dev_priv->gpu_error.reset_counter);
  1182. kobject_uevent_env(&dev->primary->kdev.kobj,
  1183. KOBJ_CHANGE, reset_done_event);
  1184. } else {
  1185. atomic_set(&error->reset_counter, I915_WEDGED);
  1186. }
  1187. for_each_ring(ring, dev_priv, i)
  1188. wake_up_all(&ring->irq_queue);
  1189. intel_display_handle_reset(dev);
  1190. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1191. }
  1192. }
  1193. static void i915_report_and_clear_eir(struct drm_device *dev)
  1194. {
  1195. struct drm_i915_private *dev_priv = dev->dev_private;
  1196. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1197. u32 eir = I915_READ(EIR);
  1198. int pipe, i;
  1199. if (!eir)
  1200. return;
  1201. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1202. i915_get_extra_instdone(dev, instdone);
  1203. if (IS_G4X(dev)) {
  1204. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1205. u32 ipeir = I915_READ(IPEIR_I965);
  1206. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1207. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1208. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1209. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1210. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1211. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1212. I915_WRITE(IPEIR_I965, ipeir);
  1213. POSTING_READ(IPEIR_I965);
  1214. }
  1215. if (eir & GM45_ERROR_PAGE_TABLE) {
  1216. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1217. pr_err("page table error\n");
  1218. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1219. I915_WRITE(PGTBL_ER, pgtbl_err);
  1220. POSTING_READ(PGTBL_ER);
  1221. }
  1222. }
  1223. if (!IS_GEN2(dev)) {
  1224. if (eir & I915_ERROR_PAGE_TABLE) {
  1225. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1226. pr_err("page table error\n");
  1227. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1228. I915_WRITE(PGTBL_ER, pgtbl_err);
  1229. POSTING_READ(PGTBL_ER);
  1230. }
  1231. }
  1232. if (eir & I915_ERROR_MEMORY_REFRESH) {
  1233. pr_err("memory refresh error:\n");
  1234. for_each_pipe(pipe)
  1235. pr_err("pipe %c stat: 0x%08x\n",
  1236. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  1237. /* pipestat has already been acked */
  1238. }
  1239. if (eir & I915_ERROR_INSTRUCTION) {
  1240. pr_err("instruction error\n");
  1241. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  1242. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1243. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1244. if (INTEL_INFO(dev)->gen < 4) {
  1245. u32 ipeir = I915_READ(IPEIR);
  1246. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  1247. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  1248. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  1249. I915_WRITE(IPEIR, ipeir);
  1250. POSTING_READ(IPEIR);
  1251. } else {
  1252. u32 ipeir = I915_READ(IPEIR_I965);
  1253. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1254. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1255. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1256. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1257. I915_WRITE(IPEIR_I965, ipeir);
  1258. POSTING_READ(IPEIR_I965);
  1259. }
  1260. }
  1261. I915_WRITE(EIR, eir);
  1262. POSTING_READ(EIR);
  1263. eir = I915_READ(EIR);
  1264. if (eir) {
  1265. /*
  1266. * some errors might have become stuck,
  1267. * mask them.
  1268. */
  1269. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1270. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1271. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1272. }
  1273. }
  1274. /**
  1275. * i915_handle_error - handle an error interrupt
  1276. * @dev: drm device
  1277. *
  1278. * Do some basic checking of regsiter state at error interrupt time and
  1279. * dump it to the syslog. Also call i915_capture_error_state() to make
  1280. * sure we get a record and make it available in debugfs. Fire a uevent
  1281. * so userspace knows something bad happened (should trigger collection
  1282. * of a ring dump etc.).
  1283. */
  1284. void i915_handle_error(struct drm_device *dev, bool wedged)
  1285. {
  1286. struct drm_i915_private *dev_priv = dev->dev_private;
  1287. struct intel_ring_buffer *ring;
  1288. int i;
  1289. i915_capture_error_state(dev);
  1290. i915_report_and_clear_eir(dev);
  1291. if (wedged) {
  1292. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  1293. &dev_priv->gpu_error.reset_counter);
  1294. /*
  1295. * Wakeup waiting processes so that the reset work item
  1296. * doesn't deadlock trying to grab various locks.
  1297. */
  1298. for_each_ring(ring, dev_priv, i)
  1299. wake_up_all(&ring->irq_queue);
  1300. }
  1301. queue_work(dev_priv->wq, &dev_priv->gpu_error.work);
  1302. }
  1303. static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1304. {
  1305. drm_i915_private_t *dev_priv = dev->dev_private;
  1306. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1307. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1308. struct drm_i915_gem_object *obj;
  1309. struct intel_unpin_work *work;
  1310. unsigned long flags;
  1311. bool stall_detected;
  1312. /* Ignore early vblank irqs */
  1313. if (intel_crtc == NULL)
  1314. return;
  1315. spin_lock_irqsave(&dev->event_lock, flags);
  1316. work = intel_crtc->unpin_work;
  1317. if (work == NULL ||
  1318. atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
  1319. !work->enable_stall_check) {
  1320. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1321. spin_unlock_irqrestore(&dev->event_lock, flags);
  1322. return;
  1323. }
  1324. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1325. obj = work->pending_flip_obj;
  1326. if (INTEL_INFO(dev)->gen >= 4) {
  1327. int dspsurf = DSPSURF(intel_crtc->plane);
  1328. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  1329. i915_gem_obj_ggtt_offset(obj);
  1330. } else {
  1331. int dspaddr = DSPADDR(intel_crtc->plane);
  1332. stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
  1333. crtc->y * crtc->fb->pitches[0] +
  1334. crtc->x * crtc->fb->bits_per_pixel/8);
  1335. }
  1336. spin_unlock_irqrestore(&dev->event_lock, flags);
  1337. if (stall_detected) {
  1338. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1339. intel_prepare_page_flip(dev, intel_crtc->plane);
  1340. }
  1341. }
  1342. /* Called from drm generic code, passed 'crtc' which
  1343. * we use as a pipe index
  1344. */
  1345. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1346. {
  1347. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1348. unsigned long irqflags;
  1349. if (!i915_pipe_enabled(dev, pipe))
  1350. return -EINVAL;
  1351. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1352. if (INTEL_INFO(dev)->gen >= 4)
  1353. i915_enable_pipestat(dev_priv, pipe,
  1354. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1355. else
  1356. i915_enable_pipestat(dev_priv, pipe,
  1357. PIPE_VBLANK_INTERRUPT_ENABLE);
  1358. /* maintain vblank delivery even in deep C-states */
  1359. if (dev_priv->info->gen == 3)
  1360. I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
  1361. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1362. return 0;
  1363. }
  1364. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1365. {
  1366. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1367. unsigned long irqflags;
  1368. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  1369. DE_PIPE_VBLANK_ILK(pipe);
  1370. if (!i915_pipe_enabled(dev, pipe))
  1371. return -EINVAL;
  1372. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1373. ironlake_enable_display_irq(dev_priv, bit);
  1374. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1375. return 0;
  1376. }
  1377. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  1378. {
  1379. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1380. unsigned long irqflags;
  1381. u32 imr;
  1382. if (!i915_pipe_enabled(dev, pipe))
  1383. return -EINVAL;
  1384. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1385. imr = I915_READ(VLV_IMR);
  1386. if (pipe == 0)
  1387. imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1388. else
  1389. imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1390. I915_WRITE(VLV_IMR, imr);
  1391. i915_enable_pipestat(dev_priv, pipe,
  1392. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1393. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1394. return 0;
  1395. }
  1396. /* Called from drm generic code, passed 'crtc' which
  1397. * we use as a pipe index
  1398. */
  1399. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  1400. {
  1401. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1402. unsigned long irqflags;
  1403. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1404. if (dev_priv->info->gen == 3)
  1405. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
  1406. i915_disable_pipestat(dev_priv, pipe,
  1407. PIPE_VBLANK_INTERRUPT_ENABLE |
  1408. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1409. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1410. }
  1411. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  1412. {
  1413. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1414. unsigned long irqflags;
  1415. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  1416. DE_PIPE_VBLANK_ILK(pipe);
  1417. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1418. ironlake_disable_display_irq(dev_priv, bit);
  1419. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1420. }
  1421. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  1422. {
  1423. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1424. unsigned long irqflags;
  1425. u32 imr;
  1426. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1427. i915_disable_pipestat(dev_priv, pipe,
  1428. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1429. imr = I915_READ(VLV_IMR);
  1430. if (pipe == 0)
  1431. imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1432. else
  1433. imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1434. I915_WRITE(VLV_IMR, imr);
  1435. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1436. }
  1437. static u32
  1438. ring_last_seqno(struct intel_ring_buffer *ring)
  1439. {
  1440. return list_entry(ring->request_list.prev,
  1441. struct drm_i915_gem_request, list)->seqno;
  1442. }
  1443. static bool
  1444. ring_idle(struct intel_ring_buffer *ring, u32 seqno)
  1445. {
  1446. return (list_empty(&ring->request_list) ||
  1447. i915_seqno_passed(seqno, ring_last_seqno(ring)));
  1448. }
  1449. static struct intel_ring_buffer *
  1450. semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
  1451. {
  1452. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1453. u32 cmd, ipehr, acthd, acthd_min;
  1454. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  1455. if ((ipehr & ~(0x3 << 16)) !=
  1456. (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
  1457. return NULL;
  1458. /* ACTHD is likely pointing to the dword after the actual command,
  1459. * so scan backwards until we find the MBOX.
  1460. */
  1461. acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
  1462. acthd_min = max((int)acthd - 3 * 4, 0);
  1463. do {
  1464. cmd = ioread32(ring->virtual_start + acthd);
  1465. if (cmd == ipehr)
  1466. break;
  1467. acthd -= 4;
  1468. if (acthd < acthd_min)
  1469. return NULL;
  1470. } while (1);
  1471. *seqno = ioread32(ring->virtual_start+acthd+4)+1;
  1472. return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
  1473. }
  1474. static int semaphore_passed(struct intel_ring_buffer *ring)
  1475. {
  1476. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1477. struct intel_ring_buffer *signaller;
  1478. u32 seqno, ctl;
  1479. ring->hangcheck.deadlock = true;
  1480. signaller = semaphore_waits_for(ring, &seqno);
  1481. if (signaller == NULL || signaller->hangcheck.deadlock)
  1482. return -1;
  1483. /* cursory check for an unkickable deadlock */
  1484. ctl = I915_READ_CTL(signaller);
  1485. if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
  1486. return -1;
  1487. return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
  1488. }
  1489. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  1490. {
  1491. struct intel_ring_buffer *ring;
  1492. int i;
  1493. for_each_ring(ring, dev_priv, i)
  1494. ring->hangcheck.deadlock = false;
  1495. }
  1496. static enum intel_ring_hangcheck_action
  1497. ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
  1498. {
  1499. struct drm_device *dev = ring->dev;
  1500. struct drm_i915_private *dev_priv = dev->dev_private;
  1501. u32 tmp;
  1502. if (ring->hangcheck.acthd != acthd)
  1503. return HANGCHECK_ACTIVE;
  1504. if (IS_GEN2(dev))
  1505. return HANGCHECK_HUNG;
  1506. /* Is the chip hanging on a WAIT_FOR_EVENT?
  1507. * If so we can simply poke the RB_WAIT bit
  1508. * and break the hang. This should work on
  1509. * all but the second generation chipsets.
  1510. */
  1511. tmp = I915_READ_CTL(ring);
  1512. if (tmp & RING_WAIT) {
  1513. DRM_ERROR("Kicking stuck wait on %s\n",
  1514. ring->name);
  1515. I915_WRITE_CTL(ring, tmp);
  1516. return HANGCHECK_KICK;
  1517. }
  1518. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  1519. switch (semaphore_passed(ring)) {
  1520. default:
  1521. return HANGCHECK_HUNG;
  1522. case 1:
  1523. DRM_ERROR("Kicking stuck semaphore on %s\n",
  1524. ring->name);
  1525. I915_WRITE_CTL(ring, tmp);
  1526. return HANGCHECK_KICK;
  1527. case 0:
  1528. return HANGCHECK_WAIT;
  1529. }
  1530. }
  1531. return HANGCHECK_HUNG;
  1532. }
  1533. /**
  1534. * This is called when the chip hasn't reported back with completed
  1535. * batchbuffers in a long time. We keep track per ring seqno progress and
  1536. * if there are no progress, hangcheck score for that ring is increased.
  1537. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  1538. * we kick the ring. If we see no progress on three subsequent calls
  1539. * we assume chip is wedged and try to fix it by resetting the chip.
  1540. */
  1541. static void i915_hangcheck_elapsed(unsigned long data)
  1542. {
  1543. struct drm_device *dev = (struct drm_device *)data;
  1544. drm_i915_private_t *dev_priv = dev->dev_private;
  1545. struct intel_ring_buffer *ring;
  1546. int i;
  1547. int busy_count = 0, rings_hung = 0;
  1548. bool stuck[I915_NUM_RINGS] = { 0 };
  1549. #define BUSY 1
  1550. #define KICK 5
  1551. #define HUNG 20
  1552. #define FIRE 30
  1553. if (!i915_enable_hangcheck)
  1554. return;
  1555. for_each_ring(ring, dev_priv, i) {
  1556. u32 seqno, acthd;
  1557. bool busy = true;
  1558. semaphore_clear_deadlocks(dev_priv);
  1559. seqno = ring->get_seqno(ring, false);
  1560. acthd = intel_ring_get_active_head(ring);
  1561. if (ring->hangcheck.seqno == seqno) {
  1562. if (ring_idle(ring, seqno)) {
  1563. if (waitqueue_active(&ring->irq_queue)) {
  1564. /* Issue a wake-up to catch stuck h/w. */
  1565. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  1566. ring->name);
  1567. wake_up_all(&ring->irq_queue);
  1568. ring->hangcheck.score += HUNG;
  1569. } else
  1570. busy = false;
  1571. } else {
  1572. /* We always increment the hangcheck score
  1573. * if the ring is busy and still processing
  1574. * the same request, so that no single request
  1575. * can run indefinitely (such as a chain of
  1576. * batches). The only time we do not increment
  1577. * the hangcheck score on this ring, if this
  1578. * ring is in a legitimate wait for another
  1579. * ring. In that case the waiting ring is a
  1580. * victim and we want to be sure we catch the
  1581. * right culprit. Then every time we do kick
  1582. * the ring, add a small increment to the
  1583. * score so that we can catch a batch that is
  1584. * being repeatedly kicked and so responsible
  1585. * for stalling the machine.
  1586. */
  1587. ring->hangcheck.action = ring_stuck(ring,
  1588. acthd);
  1589. switch (ring->hangcheck.action) {
  1590. case HANGCHECK_WAIT:
  1591. break;
  1592. case HANGCHECK_ACTIVE:
  1593. ring->hangcheck.score += BUSY;
  1594. break;
  1595. case HANGCHECK_KICK:
  1596. ring->hangcheck.score += KICK;
  1597. break;
  1598. case HANGCHECK_HUNG:
  1599. ring->hangcheck.score += HUNG;
  1600. stuck[i] = true;
  1601. break;
  1602. }
  1603. }
  1604. } else {
  1605. /* Gradually reduce the count so that we catch DoS
  1606. * attempts across multiple batches.
  1607. */
  1608. if (ring->hangcheck.score > 0)
  1609. ring->hangcheck.score--;
  1610. }
  1611. ring->hangcheck.seqno = seqno;
  1612. ring->hangcheck.acthd = acthd;
  1613. busy_count += busy;
  1614. }
  1615. for_each_ring(ring, dev_priv, i) {
  1616. if (ring->hangcheck.score > FIRE) {
  1617. DRM_ERROR("%s on %s\n",
  1618. stuck[i] ? "stuck" : "no progress",
  1619. ring->name);
  1620. rings_hung++;
  1621. }
  1622. }
  1623. if (rings_hung)
  1624. return i915_handle_error(dev, true);
  1625. if (busy_count)
  1626. /* Reset timer case chip hangs without another request
  1627. * being added */
  1628. i915_queue_hangcheck(dev);
  1629. }
  1630. void i915_queue_hangcheck(struct drm_device *dev)
  1631. {
  1632. struct drm_i915_private *dev_priv = dev->dev_private;
  1633. if (!i915_enable_hangcheck)
  1634. return;
  1635. mod_timer(&dev_priv->gpu_error.hangcheck_timer,
  1636. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  1637. }
  1638. static void ibx_irq_preinstall(struct drm_device *dev)
  1639. {
  1640. struct drm_i915_private *dev_priv = dev->dev_private;
  1641. if (HAS_PCH_NOP(dev))
  1642. return;
  1643. /* south display irq */
  1644. I915_WRITE(SDEIMR, 0xffffffff);
  1645. /*
  1646. * SDEIER is also touched by the interrupt handler to work around missed
  1647. * PCH interrupts. Hence we can't update it after the interrupt handler
  1648. * is enabled - instead we unconditionally enable all PCH interrupt
  1649. * sources here, but then only unmask them as needed with SDEIMR.
  1650. */
  1651. I915_WRITE(SDEIER, 0xffffffff);
  1652. POSTING_READ(SDEIER);
  1653. }
  1654. static void gen5_gt_irq_preinstall(struct drm_device *dev)
  1655. {
  1656. struct drm_i915_private *dev_priv = dev->dev_private;
  1657. /* and GT */
  1658. I915_WRITE(GTIMR, 0xffffffff);
  1659. I915_WRITE(GTIER, 0x0);
  1660. POSTING_READ(GTIER);
  1661. if (INTEL_INFO(dev)->gen >= 6) {
  1662. /* and PM */
  1663. I915_WRITE(GEN6_PMIMR, 0xffffffff);
  1664. I915_WRITE(GEN6_PMIER, 0x0);
  1665. POSTING_READ(GEN6_PMIER);
  1666. }
  1667. }
  1668. /* drm_dma.h hooks
  1669. */
  1670. static void ironlake_irq_preinstall(struct drm_device *dev)
  1671. {
  1672. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1673. atomic_set(&dev_priv->irq_received, 0);
  1674. I915_WRITE(HWSTAM, 0xeffe);
  1675. I915_WRITE(DEIMR, 0xffffffff);
  1676. I915_WRITE(DEIER, 0x0);
  1677. POSTING_READ(DEIER);
  1678. gen5_gt_irq_preinstall(dev);
  1679. ibx_irq_preinstall(dev);
  1680. }
  1681. static void valleyview_irq_preinstall(struct drm_device *dev)
  1682. {
  1683. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1684. int pipe;
  1685. atomic_set(&dev_priv->irq_received, 0);
  1686. /* VLV magic */
  1687. I915_WRITE(VLV_IMR, 0);
  1688. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  1689. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  1690. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  1691. /* and GT */
  1692. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1693. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1694. gen5_gt_irq_preinstall(dev);
  1695. I915_WRITE(DPINVGTT, 0xff);
  1696. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1697. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1698. for_each_pipe(pipe)
  1699. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1700. I915_WRITE(VLV_IIR, 0xffffffff);
  1701. I915_WRITE(VLV_IMR, 0xffffffff);
  1702. I915_WRITE(VLV_IER, 0x0);
  1703. POSTING_READ(VLV_IER);
  1704. }
  1705. static void ibx_hpd_irq_setup(struct drm_device *dev)
  1706. {
  1707. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1708. struct drm_mode_config *mode_config = &dev->mode_config;
  1709. struct intel_encoder *intel_encoder;
  1710. u32 hotplug_irqs, hotplug, enabled_irqs = 0;
  1711. if (HAS_PCH_IBX(dev)) {
  1712. hotplug_irqs = SDE_HOTPLUG_MASK;
  1713. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  1714. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  1715. enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
  1716. } else {
  1717. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  1718. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  1719. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  1720. enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
  1721. }
  1722. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  1723. /*
  1724. * Enable digital hotplug on the PCH, and configure the DP short pulse
  1725. * duration to 2ms (which is the minimum in the Display Port spec)
  1726. *
  1727. * This register is the same on all known PCH chips.
  1728. */
  1729. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  1730. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  1731. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  1732. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  1733. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  1734. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  1735. }
  1736. static void ibx_irq_postinstall(struct drm_device *dev)
  1737. {
  1738. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1739. u32 mask;
  1740. if (HAS_PCH_NOP(dev))
  1741. return;
  1742. if (HAS_PCH_IBX(dev)) {
  1743. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
  1744. SDE_TRANSA_FIFO_UNDER | SDE_POISON;
  1745. } else {
  1746. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
  1747. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  1748. }
  1749. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1750. I915_WRITE(SDEIMR, ~mask);
  1751. }
  1752. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  1753. {
  1754. struct drm_i915_private *dev_priv = dev->dev_private;
  1755. u32 pm_irqs, gt_irqs;
  1756. pm_irqs = gt_irqs = 0;
  1757. dev_priv->gt_irq_mask = ~0;
  1758. if (HAS_L3_GPU_CACHE(dev)) {
  1759. /* L3 parity interrupt is always unmasked. */
  1760. dev_priv->gt_irq_mask = ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  1761. gt_irqs |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  1762. }
  1763. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  1764. if (IS_GEN5(dev)) {
  1765. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  1766. ILK_BSD_USER_INTERRUPT;
  1767. } else {
  1768. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  1769. }
  1770. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1771. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1772. I915_WRITE(GTIER, gt_irqs);
  1773. POSTING_READ(GTIER);
  1774. if (INTEL_INFO(dev)->gen >= 6) {
  1775. pm_irqs |= GEN6_PM_RPS_EVENTS;
  1776. if (HAS_VEBOX(dev))
  1777. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  1778. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  1779. I915_WRITE(GEN6_PMIMR, 0xffffffff);
  1780. I915_WRITE(GEN6_PMIER, pm_irqs);
  1781. POSTING_READ(GEN6_PMIER);
  1782. }
  1783. }
  1784. static int ironlake_irq_postinstall(struct drm_device *dev)
  1785. {
  1786. unsigned long irqflags;
  1787. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1788. u32 display_mask, extra_mask;
  1789. if (INTEL_INFO(dev)->gen >= 7) {
  1790. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  1791. DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
  1792. DE_PLANEB_FLIP_DONE_IVB |
  1793. DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
  1794. DE_ERR_INT_IVB);
  1795. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  1796. DE_PIPEA_VBLANK_IVB);
  1797. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  1798. } else {
  1799. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  1800. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  1801. DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN |
  1802. DE_PIPEA_FIFO_UNDERRUN | DE_POISON);
  1803. extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
  1804. }
  1805. dev_priv->irq_mask = ~display_mask;
  1806. /* should always can generate irq */
  1807. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1808. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1809. I915_WRITE(DEIER, display_mask | extra_mask);
  1810. POSTING_READ(DEIER);
  1811. gen5_gt_irq_postinstall(dev);
  1812. ibx_irq_postinstall(dev);
  1813. if (IS_IRONLAKE_M(dev)) {
  1814. /* Enable PCU event interrupts
  1815. *
  1816. * spinlocking not required here for correctness since interrupt
  1817. * setup is guaranteed to run in single-threaded context. But we
  1818. * need it to make the assert_spin_locked happy. */
  1819. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1820. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  1821. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1822. }
  1823. return 0;
  1824. }
  1825. static int valleyview_irq_postinstall(struct drm_device *dev)
  1826. {
  1827. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1828. u32 enable_mask;
  1829. u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV;
  1830. unsigned long irqflags;
  1831. enable_mask = I915_DISPLAY_PORT_INTERRUPT;
  1832. enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1833. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1834. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1835. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1836. /*
  1837. *Leave vblank interrupts masked initially. enable/disable will
  1838. * toggle them based on usage.
  1839. */
  1840. dev_priv->irq_mask = (~enable_mask) |
  1841. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1842. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1843. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1844. POSTING_READ(PORT_HOTPLUG_EN);
  1845. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  1846. I915_WRITE(VLV_IER, enable_mask);
  1847. I915_WRITE(VLV_IIR, 0xffffffff);
  1848. I915_WRITE(PIPESTAT(0), 0xffff);
  1849. I915_WRITE(PIPESTAT(1), 0xffff);
  1850. POSTING_READ(VLV_IER);
  1851. /* Interrupt setup is already guaranteed to be single-threaded, this is
  1852. * just to make the assert_spin_locked check happy. */
  1853. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1854. i915_enable_pipestat(dev_priv, 0, pipestat_enable);
  1855. i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
  1856. i915_enable_pipestat(dev_priv, 1, pipestat_enable);
  1857. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1858. I915_WRITE(VLV_IIR, 0xffffffff);
  1859. I915_WRITE(VLV_IIR, 0xffffffff);
  1860. gen5_gt_irq_postinstall(dev);
  1861. /* ack & enable invalid PTE error interrupts */
  1862. #if 0 /* FIXME: add support to irq handler for checking these bits */
  1863. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  1864. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  1865. #endif
  1866. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  1867. return 0;
  1868. }
  1869. static void valleyview_irq_uninstall(struct drm_device *dev)
  1870. {
  1871. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1872. int pipe;
  1873. if (!dev_priv)
  1874. return;
  1875. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  1876. for_each_pipe(pipe)
  1877. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1878. I915_WRITE(HWSTAM, 0xffffffff);
  1879. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1880. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1881. for_each_pipe(pipe)
  1882. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1883. I915_WRITE(VLV_IIR, 0xffffffff);
  1884. I915_WRITE(VLV_IMR, 0xffffffff);
  1885. I915_WRITE(VLV_IER, 0x0);
  1886. POSTING_READ(VLV_IER);
  1887. }
  1888. static void ironlake_irq_uninstall(struct drm_device *dev)
  1889. {
  1890. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1891. if (!dev_priv)
  1892. return;
  1893. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  1894. I915_WRITE(HWSTAM, 0xffffffff);
  1895. I915_WRITE(DEIMR, 0xffffffff);
  1896. I915_WRITE(DEIER, 0x0);
  1897. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1898. if (IS_GEN7(dev))
  1899. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  1900. I915_WRITE(GTIMR, 0xffffffff);
  1901. I915_WRITE(GTIER, 0x0);
  1902. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1903. if (HAS_PCH_NOP(dev))
  1904. return;
  1905. I915_WRITE(SDEIMR, 0xffffffff);
  1906. I915_WRITE(SDEIER, 0x0);
  1907. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1908. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  1909. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  1910. }
  1911. static void i8xx_irq_preinstall(struct drm_device * dev)
  1912. {
  1913. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1914. int pipe;
  1915. atomic_set(&dev_priv->irq_received, 0);
  1916. for_each_pipe(pipe)
  1917. I915_WRITE(PIPESTAT(pipe), 0);
  1918. I915_WRITE16(IMR, 0xffff);
  1919. I915_WRITE16(IER, 0x0);
  1920. POSTING_READ16(IER);
  1921. }
  1922. static int i8xx_irq_postinstall(struct drm_device *dev)
  1923. {
  1924. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1925. I915_WRITE16(EMR,
  1926. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  1927. /* Unmask the interrupts that we always want on. */
  1928. dev_priv->irq_mask =
  1929. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1930. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1931. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1932. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  1933. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1934. I915_WRITE16(IMR, dev_priv->irq_mask);
  1935. I915_WRITE16(IER,
  1936. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1937. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1938. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  1939. I915_USER_INTERRUPT);
  1940. POSTING_READ16(IER);
  1941. return 0;
  1942. }
  1943. /*
  1944. * Returns true when a page flip has completed.
  1945. */
  1946. static bool i8xx_handle_vblank(struct drm_device *dev,
  1947. int pipe, u16 iir)
  1948. {
  1949. drm_i915_private_t *dev_priv = dev->dev_private;
  1950. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
  1951. if (!drm_handle_vblank(dev, pipe))
  1952. return false;
  1953. if ((iir & flip_pending) == 0)
  1954. return false;
  1955. intel_prepare_page_flip(dev, pipe);
  1956. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  1957. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  1958. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  1959. * the flip is completed (no longer pending). Since this doesn't raise
  1960. * an interrupt per se, we watch for the change at vblank.
  1961. */
  1962. if (I915_READ16(ISR) & flip_pending)
  1963. return false;
  1964. intel_finish_page_flip(dev, pipe);
  1965. return true;
  1966. }
  1967. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  1968. {
  1969. struct drm_device *dev = (struct drm_device *) arg;
  1970. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1971. u16 iir, new_iir;
  1972. u32 pipe_stats[2];
  1973. unsigned long irqflags;
  1974. int pipe;
  1975. u16 flip_mask =
  1976. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1977. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  1978. atomic_inc(&dev_priv->irq_received);
  1979. iir = I915_READ16(IIR);
  1980. if (iir == 0)
  1981. return IRQ_NONE;
  1982. while (iir & ~flip_mask) {
  1983. /* Can't rely on pipestat interrupt bit in iir as it might
  1984. * have been cleared after the pipestat interrupt was received.
  1985. * It doesn't set the bit in iir again, but it still produces
  1986. * interrupts (for non-MSI).
  1987. */
  1988. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1989. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  1990. i915_handle_error(dev, false);
  1991. for_each_pipe(pipe) {
  1992. int reg = PIPESTAT(pipe);
  1993. pipe_stats[pipe] = I915_READ(reg);
  1994. /*
  1995. * Clear the PIPE*STAT regs before the IIR
  1996. */
  1997. if (pipe_stats[pipe] & 0x8000ffff) {
  1998. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1999. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2000. pipe_name(pipe));
  2001. I915_WRITE(reg, pipe_stats[pipe]);
  2002. }
  2003. }
  2004. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2005. I915_WRITE16(IIR, iir & ~flip_mask);
  2006. new_iir = I915_READ16(IIR); /* Flush posted writes */
  2007. i915_update_dri1_breadcrumb(dev);
  2008. if (iir & I915_USER_INTERRUPT)
  2009. notify_ring(dev, &dev_priv->ring[RCS]);
  2010. if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2011. i8xx_handle_vblank(dev, 0, iir))
  2012. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0);
  2013. if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2014. i8xx_handle_vblank(dev, 1, iir))
  2015. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1);
  2016. iir = new_iir;
  2017. }
  2018. return IRQ_HANDLED;
  2019. }
  2020. static void i8xx_irq_uninstall(struct drm_device * dev)
  2021. {
  2022. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2023. int pipe;
  2024. for_each_pipe(pipe) {
  2025. /* Clear enable bits; then clear status bits */
  2026. I915_WRITE(PIPESTAT(pipe), 0);
  2027. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2028. }
  2029. I915_WRITE16(IMR, 0xffff);
  2030. I915_WRITE16(IER, 0x0);
  2031. I915_WRITE16(IIR, I915_READ16(IIR));
  2032. }
  2033. static void i915_irq_preinstall(struct drm_device * dev)
  2034. {
  2035. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2036. int pipe;
  2037. atomic_set(&dev_priv->irq_received, 0);
  2038. if (I915_HAS_HOTPLUG(dev)) {
  2039. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2040. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2041. }
  2042. I915_WRITE16(HWSTAM, 0xeffe);
  2043. for_each_pipe(pipe)
  2044. I915_WRITE(PIPESTAT(pipe), 0);
  2045. I915_WRITE(IMR, 0xffffffff);
  2046. I915_WRITE(IER, 0x0);
  2047. POSTING_READ(IER);
  2048. }
  2049. static int i915_irq_postinstall(struct drm_device *dev)
  2050. {
  2051. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2052. u32 enable_mask;
  2053. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2054. /* Unmask the interrupts that we always want on. */
  2055. dev_priv->irq_mask =
  2056. ~(I915_ASLE_INTERRUPT |
  2057. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2058. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2059. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2060. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2061. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2062. enable_mask =
  2063. I915_ASLE_INTERRUPT |
  2064. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2065. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2066. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2067. I915_USER_INTERRUPT;
  2068. if (I915_HAS_HOTPLUG(dev)) {
  2069. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2070. POSTING_READ(PORT_HOTPLUG_EN);
  2071. /* Enable in IER... */
  2072. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  2073. /* and unmask in IMR */
  2074. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  2075. }
  2076. I915_WRITE(IMR, dev_priv->irq_mask);
  2077. I915_WRITE(IER, enable_mask);
  2078. POSTING_READ(IER);
  2079. i915_enable_asle_pipestat(dev);
  2080. return 0;
  2081. }
  2082. /*
  2083. * Returns true when a page flip has completed.
  2084. */
  2085. static bool i915_handle_vblank(struct drm_device *dev,
  2086. int plane, int pipe, u32 iir)
  2087. {
  2088. drm_i915_private_t *dev_priv = dev->dev_private;
  2089. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  2090. if (!drm_handle_vblank(dev, pipe))
  2091. return false;
  2092. if ((iir & flip_pending) == 0)
  2093. return false;
  2094. intel_prepare_page_flip(dev, plane);
  2095. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2096. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2097. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2098. * the flip is completed (no longer pending). Since this doesn't raise
  2099. * an interrupt per se, we watch for the change at vblank.
  2100. */
  2101. if (I915_READ(ISR) & flip_pending)
  2102. return false;
  2103. intel_finish_page_flip(dev, pipe);
  2104. return true;
  2105. }
  2106. static irqreturn_t i915_irq_handler(int irq, void *arg)
  2107. {
  2108. struct drm_device *dev = (struct drm_device *) arg;
  2109. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2110. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  2111. unsigned long irqflags;
  2112. u32 flip_mask =
  2113. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2114. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2115. int pipe, ret = IRQ_NONE;
  2116. atomic_inc(&dev_priv->irq_received);
  2117. iir = I915_READ(IIR);
  2118. do {
  2119. bool irq_received = (iir & ~flip_mask) != 0;
  2120. bool blc_event = false;
  2121. /* Can't rely on pipestat interrupt bit in iir as it might
  2122. * have been cleared after the pipestat interrupt was received.
  2123. * It doesn't set the bit in iir again, but it still produces
  2124. * interrupts (for non-MSI).
  2125. */
  2126. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2127. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2128. i915_handle_error(dev, false);
  2129. for_each_pipe(pipe) {
  2130. int reg = PIPESTAT(pipe);
  2131. pipe_stats[pipe] = I915_READ(reg);
  2132. /* Clear the PIPE*STAT regs before the IIR */
  2133. if (pipe_stats[pipe] & 0x8000ffff) {
  2134. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2135. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2136. pipe_name(pipe));
  2137. I915_WRITE(reg, pipe_stats[pipe]);
  2138. irq_received = true;
  2139. }
  2140. }
  2141. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2142. if (!irq_received)
  2143. break;
  2144. /* Consume port. Then clear IIR or we'll miss events */
  2145. if ((I915_HAS_HOTPLUG(dev)) &&
  2146. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  2147. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2148. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  2149. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2150. hotplug_status);
  2151. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  2152. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2153. POSTING_READ(PORT_HOTPLUG_STAT);
  2154. }
  2155. I915_WRITE(IIR, iir & ~flip_mask);
  2156. new_iir = I915_READ(IIR); /* Flush posted writes */
  2157. if (iir & I915_USER_INTERRUPT)
  2158. notify_ring(dev, &dev_priv->ring[RCS]);
  2159. for_each_pipe(pipe) {
  2160. int plane = pipe;
  2161. if (IS_MOBILE(dev))
  2162. plane = !plane;
  2163. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2164. i915_handle_vblank(dev, plane, pipe, iir))
  2165. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  2166. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2167. blc_event = true;
  2168. }
  2169. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2170. intel_opregion_asle_intr(dev);
  2171. /* With MSI, interrupts are only generated when iir
  2172. * transitions from zero to nonzero. If another bit got
  2173. * set while we were handling the existing iir bits, then
  2174. * we would never get another interrupt.
  2175. *
  2176. * This is fine on non-MSI as well, as if we hit this path
  2177. * we avoid exiting the interrupt handler only to generate
  2178. * another one.
  2179. *
  2180. * Note that for MSI this could cause a stray interrupt report
  2181. * if an interrupt landed in the time between writing IIR and
  2182. * the posting read. This should be rare enough to never
  2183. * trigger the 99% of 100,000 interrupts test for disabling
  2184. * stray interrupts.
  2185. */
  2186. ret = IRQ_HANDLED;
  2187. iir = new_iir;
  2188. } while (iir & ~flip_mask);
  2189. i915_update_dri1_breadcrumb(dev);
  2190. return ret;
  2191. }
  2192. static void i915_irq_uninstall(struct drm_device * dev)
  2193. {
  2194. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2195. int pipe;
  2196. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2197. if (I915_HAS_HOTPLUG(dev)) {
  2198. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2199. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2200. }
  2201. I915_WRITE16(HWSTAM, 0xffff);
  2202. for_each_pipe(pipe) {
  2203. /* Clear enable bits; then clear status bits */
  2204. I915_WRITE(PIPESTAT(pipe), 0);
  2205. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2206. }
  2207. I915_WRITE(IMR, 0xffffffff);
  2208. I915_WRITE(IER, 0x0);
  2209. I915_WRITE(IIR, I915_READ(IIR));
  2210. }
  2211. static void i965_irq_preinstall(struct drm_device * dev)
  2212. {
  2213. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2214. int pipe;
  2215. atomic_set(&dev_priv->irq_received, 0);
  2216. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2217. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2218. I915_WRITE(HWSTAM, 0xeffe);
  2219. for_each_pipe(pipe)
  2220. I915_WRITE(PIPESTAT(pipe), 0);
  2221. I915_WRITE(IMR, 0xffffffff);
  2222. I915_WRITE(IER, 0x0);
  2223. POSTING_READ(IER);
  2224. }
  2225. static int i965_irq_postinstall(struct drm_device *dev)
  2226. {
  2227. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2228. u32 enable_mask;
  2229. u32 error_mask;
  2230. unsigned long irqflags;
  2231. /* Unmask the interrupts that we always want on. */
  2232. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  2233. I915_DISPLAY_PORT_INTERRUPT |
  2234. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2235. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2236. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2237. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2238. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2239. enable_mask = ~dev_priv->irq_mask;
  2240. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2241. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  2242. enable_mask |= I915_USER_INTERRUPT;
  2243. if (IS_G4X(dev))
  2244. enable_mask |= I915_BSD_USER_INTERRUPT;
  2245. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2246. * just to make the assert_spin_locked check happy. */
  2247. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2248. i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
  2249. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2250. /*
  2251. * Enable some error detection, note the instruction error mask
  2252. * bit is reserved, so we leave it masked.
  2253. */
  2254. if (IS_G4X(dev)) {
  2255. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  2256. GM45_ERROR_MEM_PRIV |
  2257. GM45_ERROR_CP_PRIV |
  2258. I915_ERROR_MEMORY_REFRESH);
  2259. } else {
  2260. error_mask = ~(I915_ERROR_PAGE_TABLE |
  2261. I915_ERROR_MEMORY_REFRESH);
  2262. }
  2263. I915_WRITE(EMR, error_mask);
  2264. I915_WRITE(IMR, dev_priv->irq_mask);
  2265. I915_WRITE(IER, enable_mask);
  2266. POSTING_READ(IER);
  2267. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2268. POSTING_READ(PORT_HOTPLUG_EN);
  2269. i915_enable_asle_pipestat(dev);
  2270. return 0;
  2271. }
  2272. static void i915_hpd_irq_setup(struct drm_device *dev)
  2273. {
  2274. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2275. struct drm_mode_config *mode_config = &dev->mode_config;
  2276. struct intel_encoder *intel_encoder;
  2277. u32 hotplug_en;
  2278. assert_spin_locked(&dev_priv->irq_lock);
  2279. if (I915_HAS_HOTPLUG(dev)) {
  2280. hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  2281. hotplug_en &= ~HOTPLUG_INT_EN_MASK;
  2282. /* Note HDMI and DP share hotplug bits */
  2283. /* enable bits are the same for all generations */
  2284. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2285. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2286. hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
  2287. /* Programming the CRT detection parameters tends
  2288. to generate a spurious hotplug event about three
  2289. seconds later. So just do it once.
  2290. */
  2291. if (IS_G4X(dev))
  2292. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  2293. hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
  2294. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  2295. /* Ignore TV since it's buggy */
  2296. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  2297. }
  2298. }
  2299. static irqreturn_t i965_irq_handler(int irq, void *arg)
  2300. {
  2301. struct drm_device *dev = (struct drm_device *) arg;
  2302. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2303. u32 iir, new_iir;
  2304. u32 pipe_stats[I915_MAX_PIPES];
  2305. unsigned long irqflags;
  2306. int irq_received;
  2307. int ret = IRQ_NONE, pipe;
  2308. u32 flip_mask =
  2309. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2310. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2311. atomic_inc(&dev_priv->irq_received);
  2312. iir = I915_READ(IIR);
  2313. for (;;) {
  2314. bool blc_event = false;
  2315. irq_received = (iir & ~flip_mask) != 0;
  2316. /* Can't rely on pipestat interrupt bit in iir as it might
  2317. * have been cleared after the pipestat interrupt was received.
  2318. * It doesn't set the bit in iir again, but it still produces
  2319. * interrupts (for non-MSI).
  2320. */
  2321. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2322. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2323. i915_handle_error(dev, false);
  2324. for_each_pipe(pipe) {
  2325. int reg = PIPESTAT(pipe);
  2326. pipe_stats[pipe] = I915_READ(reg);
  2327. /*
  2328. * Clear the PIPE*STAT regs before the IIR
  2329. */
  2330. if (pipe_stats[pipe] & 0x8000ffff) {
  2331. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2332. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2333. pipe_name(pipe));
  2334. I915_WRITE(reg, pipe_stats[pipe]);
  2335. irq_received = 1;
  2336. }
  2337. }
  2338. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2339. if (!irq_received)
  2340. break;
  2341. ret = IRQ_HANDLED;
  2342. /* Consume port. Then clear IIR or we'll miss events */
  2343. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  2344. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2345. u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
  2346. HOTPLUG_INT_STATUS_G4X :
  2347. HOTPLUG_INT_STATUS_I915);
  2348. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2349. hotplug_status);
  2350. intel_hpd_irq_handler(dev, hotplug_trigger,
  2351. IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
  2352. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2353. I915_READ(PORT_HOTPLUG_STAT);
  2354. }
  2355. I915_WRITE(IIR, iir & ~flip_mask);
  2356. new_iir = I915_READ(IIR); /* Flush posted writes */
  2357. if (iir & I915_USER_INTERRUPT)
  2358. notify_ring(dev, &dev_priv->ring[RCS]);
  2359. if (iir & I915_BSD_USER_INTERRUPT)
  2360. notify_ring(dev, &dev_priv->ring[VCS]);
  2361. for_each_pipe(pipe) {
  2362. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  2363. i915_handle_vblank(dev, pipe, pipe, iir))
  2364. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  2365. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2366. blc_event = true;
  2367. }
  2368. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2369. intel_opregion_asle_intr(dev);
  2370. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  2371. gmbus_irq_handler(dev);
  2372. /* With MSI, interrupts are only generated when iir
  2373. * transitions from zero to nonzero. If another bit got
  2374. * set while we were handling the existing iir bits, then
  2375. * we would never get another interrupt.
  2376. *
  2377. * This is fine on non-MSI as well, as if we hit this path
  2378. * we avoid exiting the interrupt handler only to generate
  2379. * another one.
  2380. *
  2381. * Note that for MSI this could cause a stray interrupt report
  2382. * if an interrupt landed in the time between writing IIR and
  2383. * the posting read. This should be rare enough to never
  2384. * trigger the 99% of 100,000 interrupts test for disabling
  2385. * stray interrupts.
  2386. */
  2387. iir = new_iir;
  2388. }
  2389. i915_update_dri1_breadcrumb(dev);
  2390. return ret;
  2391. }
  2392. static void i965_irq_uninstall(struct drm_device * dev)
  2393. {
  2394. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2395. int pipe;
  2396. if (!dev_priv)
  2397. return;
  2398. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2399. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2400. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2401. I915_WRITE(HWSTAM, 0xffffffff);
  2402. for_each_pipe(pipe)
  2403. I915_WRITE(PIPESTAT(pipe), 0);
  2404. I915_WRITE(IMR, 0xffffffff);
  2405. I915_WRITE(IER, 0x0);
  2406. for_each_pipe(pipe)
  2407. I915_WRITE(PIPESTAT(pipe),
  2408. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  2409. I915_WRITE(IIR, I915_READ(IIR));
  2410. }
  2411. static void i915_reenable_hotplug_timer_func(unsigned long data)
  2412. {
  2413. drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
  2414. struct drm_device *dev = dev_priv->dev;
  2415. struct drm_mode_config *mode_config = &dev->mode_config;
  2416. unsigned long irqflags;
  2417. int i;
  2418. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2419. for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
  2420. struct drm_connector *connector;
  2421. if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
  2422. continue;
  2423. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  2424. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2425. struct intel_connector *intel_connector = to_intel_connector(connector);
  2426. if (intel_connector->encoder->hpd_pin == i) {
  2427. if (connector->polled != intel_connector->polled)
  2428. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  2429. drm_get_connector_name(connector));
  2430. connector->polled = intel_connector->polled;
  2431. if (!connector->polled)
  2432. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2433. }
  2434. }
  2435. }
  2436. if (dev_priv->display.hpd_irq_setup)
  2437. dev_priv->display.hpd_irq_setup(dev);
  2438. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2439. }
  2440. void intel_irq_init(struct drm_device *dev)
  2441. {
  2442. struct drm_i915_private *dev_priv = dev->dev_private;
  2443. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  2444. INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
  2445. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  2446. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  2447. setup_timer(&dev_priv->gpu_error.hangcheck_timer,
  2448. i915_hangcheck_elapsed,
  2449. (unsigned long) dev);
  2450. setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
  2451. (unsigned long) dev_priv);
  2452. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  2453. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  2454. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  2455. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  2456. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  2457. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  2458. }
  2459. if (drm_core_check_feature(dev, DRIVER_MODESET))
  2460. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  2461. else
  2462. dev->driver->get_vblank_timestamp = NULL;
  2463. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  2464. if (IS_VALLEYVIEW(dev)) {
  2465. dev->driver->irq_handler = valleyview_irq_handler;
  2466. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  2467. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  2468. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  2469. dev->driver->enable_vblank = valleyview_enable_vblank;
  2470. dev->driver->disable_vblank = valleyview_disable_vblank;
  2471. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2472. } else if (HAS_PCH_SPLIT(dev)) {
  2473. dev->driver->irq_handler = ironlake_irq_handler;
  2474. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2475. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  2476. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2477. dev->driver->enable_vblank = ironlake_enable_vblank;
  2478. dev->driver->disable_vblank = ironlake_disable_vblank;
  2479. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  2480. } else {
  2481. if (INTEL_INFO(dev)->gen == 2) {
  2482. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  2483. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  2484. dev->driver->irq_handler = i8xx_irq_handler;
  2485. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  2486. } else if (INTEL_INFO(dev)->gen == 3) {
  2487. dev->driver->irq_preinstall = i915_irq_preinstall;
  2488. dev->driver->irq_postinstall = i915_irq_postinstall;
  2489. dev->driver->irq_uninstall = i915_irq_uninstall;
  2490. dev->driver->irq_handler = i915_irq_handler;
  2491. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2492. } else {
  2493. dev->driver->irq_preinstall = i965_irq_preinstall;
  2494. dev->driver->irq_postinstall = i965_irq_postinstall;
  2495. dev->driver->irq_uninstall = i965_irq_uninstall;
  2496. dev->driver->irq_handler = i965_irq_handler;
  2497. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2498. }
  2499. dev->driver->enable_vblank = i915_enable_vblank;
  2500. dev->driver->disable_vblank = i915_disable_vblank;
  2501. }
  2502. }
  2503. void intel_hpd_init(struct drm_device *dev)
  2504. {
  2505. struct drm_i915_private *dev_priv = dev->dev_private;
  2506. struct drm_mode_config *mode_config = &dev->mode_config;
  2507. struct drm_connector *connector;
  2508. unsigned long irqflags;
  2509. int i;
  2510. for (i = 1; i < HPD_NUM_PINS; i++) {
  2511. dev_priv->hpd_stats[i].hpd_cnt = 0;
  2512. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  2513. }
  2514. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2515. struct intel_connector *intel_connector = to_intel_connector(connector);
  2516. connector->polled = intel_connector->polled;
  2517. if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
  2518. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2519. }
  2520. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2521. * just to make the assert_spin_locked checks happy. */
  2522. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2523. if (dev_priv->display.hpd_irq_setup)
  2524. dev_priv->display.hpd_irq_setup(dev);
  2525. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2526. }