i915_irq.c 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134
  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] = "L3_PARITY_ERROR=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. if (!(hpd[i] & hotplug_trigger) ||
  763. dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
  764. continue;
  765. dev_priv->hpd_event_bits |= (1 << i);
  766. if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
  767. dev_priv->hpd_stats[i].hpd_last_jiffies
  768. + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
  769. dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
  770. dev_priv->hpd_stats[i].hpd_cnt = 0;
  771. } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
  772. dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
  773. dev_priv->hpd_event_bits &= ~(1 << i);
  774. DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
  775. storm_detected = true;
  776. } else {
  777. dev_priv->hpd_stats[i].hpd_cnt++;
  778. }
  779. }
  780. if (storm_detected)
  781. dev_priv->display.hpd_irq_setup(dev);
  782. spin_unlock(&dev_priv->irq_lock);
  783. queue_work(dev_priv->wq,
  784. &dev_priv->hotplug_work);
  785. }
  786. static void gmbus_irq_handler(struct drm_device *dev)
  787. {
  788. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  789. wake_up_all(&dev_priv->gmbus_wait_queue);
  790. }
  791. static void dp_aux_irq_handler(struct drm_device *dev)
  792. {
  793. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  794. wake_up_all(&dev_priv->gmbus_wait_queue);
  795. }
  796. /* Unlike gen6_rps_irq_handler() from which this function is originally derived,
  797. * we must be able to deal with other PM interrupts. This is complicated because
  798. * of the way in which we use the masks to defer the RPS work (which for
  799. * posterity is necessary because of forcewake).
  800. */
  801. static void hsw_pm_irq_handler(struct drm_i915_private *dev_priv,
  802. u32 pm_iir)
  803. {
  804. if (pm_iir & GEN6_PM_RPS_EVENTS) {
  805. spin_lock(&dev_priv->irq_lock);
  806. dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
  807. I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
  808. /* never want to mask useful interrupts. (also posting read) */
  809. WARN_ON(I915_READ_NOTRACE(GEN6_PMIMR) & ~GEN6_PM_RPS_EVENTS);
  810. spin_unlock(&dev_priv->irq_lock);
  811. queue_work(dev_priv->wq, &dev_priv->rps.work);
  812. }
  813. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  814. notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
  815. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
  816. DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
  817. i915_handle_error(dev_priv->dev, false);
  818. }
  819. }
  820. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  821. {
  822. struct drm_device *dev = (struct drm_device *) arg;
  823. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  824. u32 iir, gt_iir, pm_iir;
  825. irqreturn_t ret = IRQ_NONE;
  826. unsigned long irqflags;
  827. int pipe;
  828. u32 pipe_stats[I915_MAX_PIPES];
  829. atomic_inc(&dev_priv->irq_received);
  830. while (true) {
  831. iir = I915_READ(VLV_IIR);
  832. gt_iir = I915_READ(GTIIR);
  833. pm_iir = I915_READ(GEN6_PMIIR);
  834. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  835. goto out;
  836. ret = IRQ_HANDLED;
  837. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  838. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  839. for_each_pipe(pipe) {
  840. int reg = PIPESTAT(pipe);
  841. pipe_stats[pipe] = I915_READ(reg);
  842. /*
  843. * Clear the PIPE*STAT regs before the IIR
  844. */
  845. if (pipe_stats[pipe] & 0x8000ffff) {
  846. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  847. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  848. pipe_name(pipe));
  849. I915_WRITE(reg, pipe_stats[pipe]);
  850. }
  851. }
  852. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  853. for_each_pipe(pipe) {
  854. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
  855. drm_handle_vblank(dev, pipe);
  856. if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
  857. intel_prepare_page_flip(dev, pipe);
  858. intel_finish_page_flip(dev, pipe);
  859. }
  860. }
  861. /* Consume port. Then clear IIR or we'll miss events */
  862. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  863. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  864. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  865. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  866. hotplug_status);
  867. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  868. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  869. I915_READ(PORT_HOTPLUG_STAT);
  870. }
  871. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  872. gmbus_irq_handler(dev);
  873. if (pm_iir & GEN6_PM_RPS_EVENTS)
  874. gen6_rps_irq_handler(dev_priv, pm_iir);
  875. I915_WRITE(GTIIR, gt_iir);
  876. I915_WRITE(GEN6_PMIIR, pm_iir);
  877. I915_WRITE(VLV_IIR, iir);
  878. }
  879. out:
  880. return ret;
  881. }
  882. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  883. {
  884. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  885. int pipe;
  886. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  887. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
  888. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  889. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  890. SDE_AUDIO_POWER_SHIFT);
  891. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  892. port_name(port));
  893. }
  894. if (pch_iir & SDE_AUX_MASK)
  895. dp_aux_irq_handler(dev);
  896. if (pch_iir & SDE_GMBUS)
  897. gmbus_irq_handler(dev);
  898. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  899. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  900. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  901. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  902. if (pch_iir & SDE_POISON)
  903. DRM_ERROR("PCH poison interrupt\n");
  904. if (pch_iir & SDE_FDI_MASK)
  905. for_each_pipe(pipe)
  906. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  907. pipe_name(pipe),
  908. I915_READ(FDI_RX_IIR(pipe)));
  909. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  910. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  911. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  912. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  913. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  914. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  915. false))
  916. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  917. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  918. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  919. false))
  920. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  921. }
  922. static void ivb_err_int_handler(struct drm_device *dev)
  923. {
  924. struct drm_i915_private *dev_priv = dev->dev_private;
  925. u32 err_int = I915_READ(GEN7_ERR_INT);
  926. if (err_int & ERR_INT_POISON)
  927. DRM_ERROR("Poison interrupt\n");
  928. if (err_int & ERR_INT_FIFO_UNDERRUN_A)
  929. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
  930. DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
  931. if (err_int & ERR_INT_FIFO_UNDERRUN_B)
  932. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
  933. DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
  934. if (err_int & ERR_INT_FIFO_UNDERRUN_C)
  935. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false))
  936. DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n");
  937. I915_WRITE(GEN7_ERR_INT, err_int);
  938. }
  939. static void cpt_serr_int_handler(struct drm_device *dev)
  940. {
  941. struct drm_i915_private *dev_priv = dev->dev_private;
  942. u32 serr_int = I915_READ(SERR_INT);
  943. if (serr_int & SERR_INT_POISON)
  944. DRM_ERROR("PCH poison interrupt\n");
  945. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  946. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  947. false))
  948. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  949. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  950. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  951. false))
  952. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  953. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  954. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
  955. false))
  956. DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
  957. I915_WRITE(SERR_INT, serr_int);
  958. }
  959. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  960. {
  961. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  962. int pipe;
  963. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  964. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
  965. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  966. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  967. SDE_AUDIO_POWER_SHIFT_CPT);
  968. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  969. port_name(port));
  970. }
  971. if (pch_iir & SDE_AUX_MASK_CPT)
  972. dp_aux_irq_handler(dev);
  973. if (pch_iir & SDE_GMBUS_CPT)
  974. gmbus_irq_handler(dev);
  975. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  976. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  977. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  978. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  979. if (pch_iir & SDE_FDI_MASK_CPT)
  980. for_each_pipe(pipe)
  981. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  982. pipe_name(pipe),
  983. I915_READ(FDI_RX_IIR(pipe)));
  984. if (pch_iir & SDE_ERROR_CPT)
  985. cpt_serr_int_handler(dev);
  986. }
  987. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  988. {
  989. struct drm_i915_private *dev_priv = dev->dev_private;
  990. if (de_iir & DE_AUX_CHANNEL_A)
  991. dp_aux_irq_handler(dev);
  992. if (de_iir & DE_GSE)
  993. intel_opregion_asle_intr(dev);
  994. if (de_iir & DE_PIPEA_VBLANK)
  995. drm_handle_vblank(dev, 0);
  996. if (de_iir & DE_PIPEB_VBLANK)
  997. drm_handle_vblank(dev, 1);
  998. if (de_iir & DE_POISON)
  999. DRM_ERROR("Poison interrupt\n");
  1000. if (de_iir & DE_PIPEA_FIFO_UNDERRUN)
  1001. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
  1002. DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
  1003. if (de_iir & DE_PIPEB_FIFO_UNDERRUN)
  1004. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
  1005. DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
  1006. if (de_iir & DE_PLANEA_FLIP_DONE) {
  1007. intel_prepare_page_flip(dev, 0);
  1008. intel_finish_page_flip_plane(dev, 0);
  1009. }
  1010. if (de_iir & DE_PLANEB_FLIP_DONE) {
  1011. intel_prepare_page_flip(dev, 1);
  1012. intel_finish_page_flip_plane(dev, 1);
  1013. }
  1014. /* check event from PCH */
  1015. if (de_iir & DE_PCH_EVENT) {
  1016. u32 pch_iir = I915_READ(SDEIIR);
  1017. if (HAS_PCH_CPT(dev))
  1018. cpt_irq_handler(dev, pch_iir);
  1019. else
  1020. ibx_irq_handler(dev, pch_iir);
  1021. /* should clear PCH hotplug event before clear CPU irq */
  1022. I915_WRITE(SDEIIR, pch_iir);
  1023. }
  1024. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1025. ironlake_rps_change_irq_handler(dev);
  1026. }
  1027. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1028. {
  1029. struct drm_i915_private *dev_priv = dev->dev_private;
  1030. int i;
  1031. if (de_iir & DE_ERR_INT_IVB)
  1032. ivb_err_int_handler(dev);
  1033. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1034. dp_aux_irq_handler(dev);
  1035. if (de_iir & DE_GSE_IVB)
  1036. intel_opregion_asle_intr(dev);
  1037. for (i = 0; i < 3; i++) {
  1038. if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
  1039. drm_handle_vblank(dev, i);
  1040. if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
  1041. intel_prepare_page_flip(dev, i);
  1042. intel_finish_page_flip_plane(dev, i);
  1043. }
  1044. }
  1045. /* check event from PCH */
  1046. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1047. u32 pch_iir = I915_READ(SDEIIR);
  1048. cpt_irq_handler(dev, pch_iir);
  1049. /* clear PCH hotplug event before clear CPU irq */
  1050. I915_WRITE(SDEIIR, pch_iir);
  1051. }
  1052. }
  1053. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1054. {
  1055. struct drm_device *dev = (struct drm_device *) arg;
  1056. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1057. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1058. irqreturn_t ret = IRQ_NONE;
  1059. atomic_inc(&dev_priv->irq_received);
  1060. /* We get interrupts on unclaimed registers, so check for this before we
  1061. * do any I915_{READ,WRITE}. */
  1062. if (IS_HASWELL(dev) &&
  1063. (I915_READ_NOTRACE(FPGA_DBG) & FPGA_DBG_RM_NOCLAIM)) {
  1064. DRM_ERROR("Unclaimed register before interrupt\n");
  1065. I915_WRITE_NOTRACE(FPGA_DBG, FPGA_DBG_RM_NOCLAIM);
  1066. }
  1067. /* disable master interrupt before clearing iir */
  1068. de_ier = I915_READ(DEIER);
  1069. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1070. POSTING_READ(DEIER);
  1071. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1072. * interrupts will will be stored on its back queue, and then we'll be
  1073. * able to process them after we restore SDEIER (as soon as we restore
  1074. * it, we'll get an interrupt if SDEIIR still has something to process
  1075. * due to its back queue). */
  1076. if (!HAS_PCH_NOP(dev)) {
  1077. sde_ier = I915_READ(SDEIER);
  1078. I915_WRITE(SDEIER, 0);
  1079. POSTING_READ(SDEIER);
  1080. }
  1081. /* On Haswell, also mask ERR_INT because we don't want to risk
  1082. * generating "unclaimed register" interrupts from inside the interrupt
  1083. * handler. */
  1084. if (IS_HASWELL(dev)) {
  1085. spin_lock(&dev_priv->irq_lock);
  1086. ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
  1087. spin_unlock(&dev_priv->irq_lock);
  1088. }
  1089. gt_iir = I915_READ(GTIIR);
  1090. if (gt_iir) {
  1091. if (IS_GEN5(dev))
  1092. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1093. else
  1094. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1095. I915_WRITE(GTIIR, gt_iir);
  1096. ret = IRQ_HANDLED;
  1097. }
  1098. de_iir = I915_READ(DEIIR);
  1099. if (de_iir) {
  1100. if (INTEL_INFO(dev)->gen >= 7)
  1101. ivb_display_irq_handler(dev, de_iir);
  1102. else
  1103. ilk_display_irq_handler(dev, de_iir);
  1104. I915_WRITE(DEIIR, de_iir);
  1105. ret = IRQ_HANDLED;
  1106. }
  1107. if (INTEL_INFO(dev)->gen >= 6) {
  1108. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1109. if (pm_iir) {
  1110. if (IS_HASWELL(dev))
  1111. hsw_pm_irq_handler(dev_priv, pm_iir);
  1112. else if (pm_iir & GEN6_PM_RPS_EVENTS)
  1113. gen6_rps_irq_handler(dev_priv, pm_iir);
  1114. I915_WRITE(GEN6_PMIIR, pm_iir);
  1115. ret = IRQ_HANDLED;
  1116. }
  1117. }
  1118. if (IS_HASWELL(dev)) {
  1119. spin_lock(&dev_priv->irq_lock);
  1120. if (ivb_can_enable_err_int(dev))
  1121. ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
  1122. spin_unlock(&dev_priv->irq_lock);
  1123. }
  1124. I915_WRITE(DEIER, de_ier);
  1125. POSTING_READ(DEIER);
  1126. if (!HAS_PCH_NOP(dev)) {
  1127. I915_WRITE(SDEIER, sde_ier);
  1128. POSTING_READ(SDEIER);
  1129. }
  1130. return ret;
  1131. }
  1132. /**
  1133. * i915_error_work_func - do process context error handling work
  1134. * @work: work struct
  1135. *
  1136. * Fire an error uevent so userspace can see that a hang or error
  1137. * was detected.
  1138. */
  1139. static void i915_error_work_func(struct work_struct *work)
  1140. {
  1141. struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
  1142. work);
  1143. drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
  1144. gpu_error);
  1145. struct drm_device *dev = dev_priv->dev;
  1146. struct intel_ring_buffer *ring;
  1147. char *error_event[] = { "ERROR=1", NULL };
  1148. char *reset_event[] = { "RESET=1", NULL };
  1149. char *reset_done_event[] = { "ERROR=0", NULL };
  1150. int i, ret;
  1151. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  1152. /*
  1153. * Note that there's only one work item which does gpu resets, so we
  1154. * need not worry about concurrent gpu resets potentially incrementing
  1155. * error->reset_counter twice. We only need to take care of another
  1156. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1157. * quick check for that is good enough: schedule_work ensures the
  1158. * correct ordering between hang detection and this work item, and since
  1159. * the reset in-progress bit is only ever set by code outside of this
  1160. * work we don't need to worry about any other races.
  1161. */
  1162. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1163. DRM_DEBUG_DRIVER("resetting chip\n");
  1164. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
  1165. reset_event);
  1166. ret = i915_reset(dev);
  1167. if (ret == 0) {
  1168. /*
  1169. * After all the gem state is reset, increment the reset
  1170. * counter and wake up everyone waiting for the reset to
  1171. * complete.
  1172. *
  1173. * Since unlock operations are a one-sided barrier only,
  1174. * we need to insert a barrier here to order any seqno
  1175. * updates before
  1176. * the counter increment.
  1177. */
  1178. smp_mb__before_atomic_inc();
  1179. atomic_inc(&dev_priv->gpu_error.reset_counter);
  1180. kobject_uevent_env(&dev->primary->kdev.kobj,
  1181. KOBJ_CHANGE, reset_done_event);
  1182. } else {
  1183. atomic_set(&error->reset_counter, I915_WEDGED);
  1184. }
  1185. for_each_ring(ring, dev_priv, i)
  1186. wake_up_all(&ring->irq_queue);
  1187. intel_display_handle_reset(dev);
  1188. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1189. }
  1190. }
  1191. static void i915_report_and_clear_eir(struct drm_device *dev)
  1192. {
  1193. struct drm_i915_private *dev_priv = dev->dev_private;
  1194. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1195. u32 eir = I915_READ(EIR);
  1196. int pipe, i;
  1197. if (!eir)
  1198. return;
  1199. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1200. i915_get_extra_instdone(dev, instdone);
  1201. if (IS_G4X(dev)) {
  1202. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1203. u32 ipeir = I915_READ(IPEIR_I965);
  1204. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1205. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1206. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1207. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1208. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1209. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1210. I915_WRITE(IPEIR_I965, ipeir);
  1211. POSTING_READ(IPEIR_I965);
  1212. }
  1213. if (eir & GM45_ERROR_PAGE_TABLE) {
  1214. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1215. pr_err("page table error\n");
  1216. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1217. I915_WRITE(PGTBL_ER, pgtbl_err);
  1218. POSTING_READ(PGTBL_ER);
  1219. }
  1220. }
  1221. if (!IS_GEN2(dev)) {
  1222. if (eir & I915_ERROR_PAGE_TABLE) {
  1223. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1224. pr_err("page table error\n");
  1225. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1226. I915_WRITE(PGTBL_ER, pgtbl_err);
  1227. POSTING_READ(PGTBL_ER);
  1228. }
  1229. }
  1230. if (eir & I915_ERROR_MEMORY_REFRESH) {
  1231. pr_err("memory refresh error:\n");
  1232. for_each_pipe(pipe)
  1233. pr_err("pipe %c stat: 0x%08x\n",
  1234. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  1235. /* pipestat has already been acked */
  1236. }
  1237. if (eir & I915_ERROR_INSTRUCTION) {
  1238. pr_err("instruction error\n");
  1239. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  1240. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1241. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1242. if (INTEL_INFO(dev)->gen < 4) {
  1243. u32 ipeir = I915_READ(IPEIR);
  1244. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  1245. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  1246. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  1247. I915_WRITE(IPEIR, ipeir);
  1248. POSTING_READ(IPEIR);
  1249. } else {
  1250. u32 ipeir = I915_READ(IPEIR_I965);
  1251. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1252. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1253. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1254. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1255. I915_WRITE(IPEIR_I965, ipeir);
  1256. POSTING_READ(IPEIR_I965);
  1257. }
  1258. }
  1259. I915_WRITE(EIR, eir);
  1260. POSTING_READ(EIR);
  1261. eir = I915_READ(EIR);
  1262. if (eir) {
  1263. /*
  1264. * some errors might have become stuck,
  1265. * mask them.
  1266. */
  1267. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1268. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1269. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1270. }
  1271. }
  1272. /**
  1273. * i915_handle_error - handle an error interrupt
  1274. * @dev: drm device
  1275. *
  1276. * Do some basic checking of regsiter state at error interrupt time and
  1277. * dump it to the syslog. Also call i915_capture_error_state() to make
  1278. * sure we get a record and make it available in debugfs. Fire a uevent
  1279. * so userspace knows something bad happened (should trigger collection
  1280. * of a ring dump etc.).
  1281. */
  1282. void i915_handle_error(struct drm_device *dev, bool wedged)
  1283. {
  1284. struct drm_i915_private *dev_priv = dev->dev_private;
  1285. struct intel_ring_buffer *ring;
  1286. int i;
  1287. i915_capture_error_state(dev);
  1288. i915_report_and_clear_eir(dev);
  1289. if (wedged) {
  1290. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  1291. &dev_priv->gpu_error.reset_counter);
  1292. /*
  1293. * Wakeup waiting processes so that the reset work item
  1294. * doesn't deadlock trying to grab various locks.
  1295. */
  1296. for_each_ring(ring, dev_priv, i)
  1297. wake_up_all(&ring->irq_queue);
  1298. }
  1299. queue_work(dev_priv->wq, &dev_priv->gpu_error.work);
  1300. }
  1301. static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1302. {
  1303. drm_i915_private_t *dev_priv = dev->dev_private;
  1304. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1305. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1306. struct drm_i915_gem_object *obj;
  1307. struct intel_unpin_work *work;
  1308. unsigned long flags;
  1309. bool stall_detected;
  1310. /* Ignore early vblank irqs */
  1311. if (intel_crtc == NULL)
  1312. return;
  1313. spin_lock_irqsave(&dev->event_lock, flags);
  1314. work = intel_crtc->unpin_work;
  1315. if (work == NULL ||
  1316. atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
  1317. !work->enable_stall_check) {
  1318. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1319. spin_unlock_irqrestore(&dev->event_lock, flags);
  1320. return;
  1321. }
  1322. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1323. obj = work->pending_flip_obj;
  1324. if (INTEL_INFO(dev)->gen >= 4) {
  1325. int dspsurf = DSPSURF(intel_crtc->plane);
  1326. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  1327. i915_gem_obj_ggtt_offset(obj);
  1328. } else {
  1329. int dspaddr = DSPADDR(intel_crtc->plane);
  1330. stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
  1331. crtc->y * crtc->fb->pitches[0] +
  1332. crtc->x * crtc->fb->bits_per_pixel/8);
  1333. }
  1334. spin_unlock_irqrestore(&dev->event_lock, flags);
  1335. if (stall_detected) {
  1336. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1337. intel_prepare_page_flip(dev, intel_crtc->plane);
  1338. }
  1339. }
  1340. /* Called from drm generic code, passed 'crtc' which
  1341. * we use as a pipe index
  1342. */
  1343. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1344. {
  1345. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1346. unsigned long irqflags;
  1347. if (!i915_pipe_enabled(dev, pipe))
  1348. return -EINVAL;
  1349. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1350. if (INTEL_INFO(dev)->gen >= 4)
  1351. i915_enable_pipestat(dev_priv, pipe,
  1352. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1353. else
  1354. i915_enable_pipestat(dev_priv, pipe,
  1355. PIPE_VBLANK_INTERRUPT_ENABLE);
  1356. /* maintain vblank delivery even in deep C-states */
  1357. if (dev_priv->info->gen == 3)
  1358. I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
  1359. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1360. return 0;
  1361. }
  1362. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1363. {
  1364. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1365. unsigned long irqflags;
  1366. if (!i915_pipe_enabled(dev, pipe))
  1367. return -EINVAL;
  1368. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1369. ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
  1370. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1371. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1372. return 0;
  1373. }
  1374. static int ivybridge_enable_vblank(struct drm_device *dev, int pipe)
  1375. {
  1376. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1377. unsigned long irqflags;
  1378. if (!i915_pipe_enabled(dev, pipe))
  1379. return -EINVAL;
  1380. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1381. ironlake_enable_display_irq(dev_priv,
  1382. DE_PIPEA_VBLANK_IVB << (5 * pipe));
  1383. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1384. return 0;
  1385. }
  1386. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  1387. {
  1388. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1389. unsigned long irqflags;
  1390. u32 imr;
  1391. if (!i915_pipe_enabled(dev, pipe))
  1392. return -EINVAL;
  1393. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1394. imr = I915_READ(VLV_IMR);
  1395. if (pipe == 0)
  1396. imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1397. else
  1398. imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1399. I915_WRITE(VLV_IMR, imr);
  1400. i915_enable_pipestat(dev_priv, pipe,
  1401. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1402. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1403. return 0;
  1404. }
  1405. /* Called from drm generic code, passed 'crtc' which
  1406. * we use as a pipe index
  1407. */
  1408. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  1409. {
  1410. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1411. unsigned long irqflags;
  1412. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1413. if (dev_priv->info->gen == 3)
  1414. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
  1415. i915_disable_pipestat(dev_priv, pipe,
  1416. PIPE_VBLANK_INTERRUPT_ENABLE |
  1417. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1418. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1419. }
  1420. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  1421. {
  1422. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1423. unsigned long irqflags;
  1424. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1425. ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
  1426. DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
  1427. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1428. }
  1429. static void ivybridge_disable_vblank(struct drm_device *dev, int pipe)
  1430. {
  1431. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1432. unsigned long irqflags;
  1433. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1434. ironlake_disable_display_irq(dev_priv,
  1435. DE_PIPEA_VBLANK_IVB << (pipe * 5));
  1436. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1437. }
  1438. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  1439. {
  1440. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1441. unsigned long irqflags;
  1442. u32 imr;
  1443. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1444. i915_disable_pipestat(dev_priv, pipe,
  1445. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1446. imr = I915_READ(VLV_IMR);
  1447. if (pipe == 0)
  1448. imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1449. else
  1450. imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1451. I915_WRITE(VLV_IMR, imr);
  1452. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1453. }
  1454. static u32
  1455. ring_last_seqno(struct intel_ring_buffer *ring)
  1456. {
  1457. return list_entry(ring->request_list.prev,
  1458. struct drm_i915_gem_request, list)->seqno;
  1459. }
  1460. static bool
  1461. ring_idle(struct intel_ring_buffer *ring, u32 seqno)
  1462. {
  1463. return (list_empty(&ring->request_list) ||
  1464. i915_seqno_passed(seqno, ring_last_seqno(ring)));
  1465. }
  1466. static struct intel_ring_buffer *
  1467. semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
  1468. {
  1469. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1470. u32 cmd, ipehr, acthd, acthd_min;
  1471. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  1472. if ((ipehr & ~(0x3 << 16)) !=
  1473. (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
  1474. return NULL;
  1475. /* ACTHD is likely pointing to the dword after the actual command,
  1476. * so scan backwards until we find the MBOX.
  1477. */
  1478. acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
  1479. acthd_min = max((int)acthd - 3 * 4, 0);
  1480. do {
  1481. cmd = ioread32(ring->virtual_start + acthd);
  1482. if (cmd == ipehr)
  1483. break;
  1484. acthd -= 4;
  1485. if (acthd < acthd_min)
  1486. return NULL;
  1487. } while (1);
  1488. *seqno = ioread32(ring->virtual_start+acthd+4)+1;
  1489. return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
  1490. }
  1491. static int semaphore_passed(struct intel_ring_buffer *ring)
  1492. {
  1493. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1494. struct intel_ring_buffer *signaller;
  1495. u32 seqno, ctl;
  1496. ring->hangcheck.deadlock = true;
  1497. signaller = semaphore_waits_for(ring, &seqno);
  1498. if (signaller == NULL || signaller->hangcheck.deadlock)
  1499. return -1;
  1500. /* cursory check for an unkickable deadlock */
  1501. ctl = I915_READ_CTL(signaller);
  1502. if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
  1503. return -1;
  1504. return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
  1505. }
  1506. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  1507. {
  1508. struct intel_ring_buffer *ring;
  1509. int i;
  1510. for_each_ring(ring, dev_priv, i)
  1511. ring->hangcheck.deadlock = false;
  1512. }
  1513. static enum intel_ring_hangcheck_action
  1514. ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
  1515. {
  1516. struct drm_device *dev = ring->dev;
  1517. struct drm_i915_private *dev_priv = dev->dev_private;
  1518. u32 tmp;
  1519. if (ring->hangcheck.acthd != acthd)
  1520. return active;
  1521. if (IS_GEN2(dev))
  1522. return hung;
  1523. /* Is the chip hanging on a WAIT_FOR_EVENT?
  1524. * If so we can simply poke the RB_WAIT bit
  1525. * and break the hang. This should work on
  1526. * all but the second generation chipsets.
  1527. */
  1528. tmp = I915_READ_CTL(ring);
  1529. if (tmp & RING_WAIT) {
  1530. DRM_ERROR("Kicking stuck wait on %s\n",
  1531. ring->name);
  1532. I915_WRITE_CTL(ring, tmp);
  1533. return kick;
  1534. }
  1535. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  1536. switch (semaphore_passed(ring)) {
  1537. default:
  1538. return hung;
  1539. case 1:
  1540. DRM_ERROR("Kicking stuck semaphore on %s\n",
  1541. ring->name);
  1542. I915_WRITE_CTL(ring, tmp);
  1543. return kick;
  1544. case 0:
  1545. return wait;
  1546. }
  1547. }
  1548. return hung;
  1549. }
  1550. /**
  1551. * This is called when the chip hasn't reported back with completed
  1552. * batchbuffers in a long time. We keep track per ring seqno progress and
  1553. * if there are no progress, hangcheck score for that ring is increased.
  1554. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  1555. * we kick the ring. If we see no progress on three subsequent calls
  1556. * we assume chip is wedged and try to fix it by resetting the chip.
  1557. */
  1558. void i915_hangcheck_elapsed(unsigned long data)
  1559. {
  1560. struct drm_device *dev = (struct drm_device *)data;
  1561. drm_i915_private_t *dev_priv = dev->dev_private;
  1562. struct intel_ring_buffer *ring;
  1563. int i;
  1564. int busy_count = 0, rings_hung = 0;
  1565. bool stuck[I915_NUM_RINGS] = { 0 };
  1566. #define BUSY 1
  1567. #define KICK 5
  1568. #define HUNG 20
  1569. #define FIRE 30
  1570. if (!i915_enable_hangcheck)
  1571. return;
  1572. for_each_ring(ring, dev_priv, i) {
  1573. u32 seqno, acthd;
  1574. bool busy = true;
  1575. semaphore_clear_deadlocks(dev_priv);
  1576. seqno = ring->get_seqno(ring, false);
  1577. acthd = intel_ring_get_active_head(ring);
  1578. if (ring->hangcheck.seqno == seqno) {
  1579. if (ring_idle(ring, seqno)) {
  1580. if (waitqueue_active(&ring->irq_queue)) {
  1581. /* Issue a wake-up to catch stuck h/w. */
  1582. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  1583. ring->name);
  1584. wake_up_all(&ring->irq_queue);
  1585. ring->hangcheck.score += HUNG;
  1586. } else
  1587. busy = false;
  1588. } else {
  1589. int score;
  1590. /* We always increment the hangcheck score
  1591. * if the ring is busy and still processing
  1592. * the same request, so that no single request
  1593. * can run indefinitely (such as a chain of
  1594. * batches). The only time we do not increment
  1595. * the hangcheck score on this ring, if this
  1596. * ring is in a legitimate wait for another
  1597. * ring. In that case the waiting ring is a
  1598. * victim and we want to be sure we catch the
  1599. * right culprit. Then every time we do kick
  1600. * the ring, add a small increment to the
  1601. * score so that we can catch a batch that is
  1602. * being repeatedly kicked and so responsible
  1603. * for stalling the machine.
  1604. */
  1605. ring->hangcheck.action = ring_stuck(ring,
  1606. acthd);
  1607. switch (ring->hangcheck.action) {
  1608. case wait:
  1609. score = 0;
  1610. break;
  1611. case active:
  1612. score = BUSY;
  1613. break;
  1614. case kick:
  1615. score = KICK;
  1616. break;
  1617. case hung:
  1618. score = HUNG;
  1619. stuck[i] = true;
  1620. break;
  1621. }
  1622. ring->hangcheck.score += score;
  1623. }
  1624. } else {
  1625. /* Gradually reduce the count so that we catch DoS
  1626. * attempts across multiple batches.
  1627. */
  1628. if (ring->hangcheck.score > 0)
  1629. ring->hangcheck.score--;
  1630. }
  1631. ring->hangcheck.seqno = seqno;
  1632. ring->hangcheck.acthd = acthd;
  1633. busy_count += busy;
  1634. }
  1635. for_each_ring(ring, dev_priv, i) {
  1636. if (ring->hangcheck.score > FIRE) {
  1637. DRM_ERROR("%s on %s\n",
  1638. stuck[i] ? "stuck" : "no progress",
  1639. ring->name);
  1640. rings_hung++;
  1641. }
  1642. }
  1643. if (rings_hung)
  1644. return i915_handle_error(dev, true);
  1645. if (busy_count)
  1646. /* Reset timer case chip hangs without another request
  1647. * being added */
  1648. i915_queue_hangcheck(dev);
  1649. }
  1650. void i915_queue_hangcheck(struct drm_device *dev)
  1651. {
  1652. struct drm_i915_private *dev_priv = dev->dev_private;
  1653. if (!i915_enable_hangcheck)
  1654. return;
  1655. mod_timer(&dev_priv->gpu_error.hangcheck_timer,
  1656. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  1657. }
  1658. static void ibx_irq_preinstall(struct drm_device *dev)
  1659. {
  1660. struct drm_i915_private *dev_priv = dev->dev_private;
  1661. if (HAS_PCH_NOP(dev))
  1662. return;
  1663. /* south display irq */
  1664. I915_WRITE(SDEIMR, 0xffffffff);
  1665. /*
  1666. * SDEIER is also touched by the interrupt handler to work around missed
  1667. * PCH interrupts. Hence we can't update it after the interrupt handler
  1668. * is enabled - instead we unconditionally enable all PCH interrupt
  1669. * sources here, but then only unmask them as needed with SDEIMR.
  1670. */
  1671. I915_WRITE(SDEIER, 0xffffffff);
  1672. POSTING_READ(SDEIER);
  1673. }
  1674. static void gen5_gt_irq_preinstall(struct drm_device *dev)
  1675. {
  1676. struct drm_i915_private *dev_priv = dev->dev_private;
  1677. /* and GT */
  1678. I915_WRITE(GTIMR, 0xffffffff);
  1679. I915_WRITE(GTIER, 0x0);
  1680. POSTING_READ(GTIER);
  1681. if (INTEL_INFO(dev)->gen >= 6) {
  1682. /* and PM */
  1683. I915_WRITE(GEN6_PMIMR, 0xffffffff);
  1684. I915_WRITE(GEN6_PMIER, 0x0);
  1685. POSTING_READ(GEN6_PMIER);
  1686. }
  1687. }
  1688. /* drm_dma.h hooks
  1689. */
  1690. static void ironlake_irq_preinstall(struct drm_device *dev)
  1691. {
  1692. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1693. atomic_set(&dev_priv->irq_received, 0);
  1694. I915_WRITE(HWSTAM, 0xeffe);
  1695. I915_WRITE(DEIMR, 0xffffffff);
  1696. I915_WRITE(DEIER, 0x0);
  1697. POSTING_READ(DEIER);
  1698. gen5_gt_irq_preinstall(dev);
  1699. ibx_irq_preinstall(dev);
  1700. }
  1701. static void valleyview_irq_preinstall(struct drm_device *dev)
  1702. {
  1703. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1704. int pipe;
  1705. atomic_set(&dev_priv->irq_received, 0);
  1706. /* VLV magic */
  1707. I915_WRITE(VLV_IMR, 0);
  1708. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  1709. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  1710. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  1711. /* and GT */
  1712. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1713. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1714. gen5_gt_irq_preinstall(dev);
  1715. I915_WRITE(DPINVGTT, 0xff);
  1716. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1717. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1718. for_each_pipe(pipe)
  1719. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1720. I915_WRITE(VLV_IIR, 0xffffffff);
  1721. I915_WRITE(VLV_IMR, 0xffffffff);
  1722. I915_WRITE(VLV_IER, 0x0);
  1723. POSTING_READ(VLV_IER);
  1724. }
  1725. static void ibx_hpd_irq_setup(struct drm_device *dev)
  1726. {
  1727. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1728. struct drm_mode_config *mode_config = &dev->mode_config;
  1729. struct intel_encoder *intel_encoder;
  1730. u32 hotplug_irqs, hotplug, enabled_irqs = 0;
  1731. if (HAS_PCH_IBX(dev)) {
  1732. hotplug_irqs = SDE_HOTPLUG_MASK;
  1733. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  1734. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  1735. enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
  1736. } else {
  1737. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  1738. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  1739. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  1740. enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
  1741. }
  1742. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  1743. /*
  1744. * Enable digital hotplug on the PCH, and configure the DP short pulse
  1745. * duration to 2ms (which is the minimum in the Display Port spec)
  1746. *
  1747. * This register is the same on all known PCH chips.
  1748. */
  1749. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  1750. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  1751. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  1752. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  1753. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  1754. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  1755. }
  1756. static void ibx_irq_postinstall(struct drm_device *dev)
  1757. {
  1758. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1759. u32 mask;
  1760. if (HAS_PCH_NOP(dev))
  1761. return;
  1762. if (HAS_PCH_IBX(dev)) {
  1763. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
  1764. SDE_TRANSA_FIFO_UNDER | SDE_POISON;
  1765. } else {
  1766. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
  1767. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  1768. }
  1769. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1770. I915_WRITE(SDEIMR, ~mask);
  1771. }
  1772. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  1773. {
  1774. struct drm_i915_private *dev_priv = dev->dev_private;
  1775. u32 pm_irqs, gt_irqs;
  1776. pm_irqs = gt_irqs = 0;
  1777. dev_priv->gt_irq_mask = ~0;
  1778. if (HAS_L3_GPU_CACHE(dev)) {
  1779. /* L3 parity interrupt is always unmasked. */
  1780. dev_priv->gt_irq_mask = ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  1781. gt_irqs |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  1782. }
  1783. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  1784. if (IS_GEN5(dev)) {
  1785. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  1786. ILK_BSD_USER_INTERRUPT;
  1787. } else {
  1788. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  1789. }
  1790. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1791. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1792. I915_WRITE(GTIER, gt_irqs);
  1793. POSTING_READ(GTIER);
  1794. if (INTEL_INFO(dev)->gen >= 6) {
  1795. pm_irqs |= GEN6_PM_RPS_EVENTS;
  1796. if (HAS_VEBOX(dev))
  1797. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  1798. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  1799. I915_WRITE(GEN6_PMIMR, 0xffffffff);
  1800. I915_WRITE(GEN6_PMIER, pm_irqs);
  1801. POSTING_READ(GEN6_PMIER);
  1802. }
  1803. }
  1804. static int ironlake_irq_postinstall(struct drm_device *dev)
  1805. {
  1806. unsigned long irqflags;
  1807. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1808. /* enable kind of interrupts always enabled */
  1809. u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  1810. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  1811. DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN |
  1812. DE_PIPEA_FIFO_UNDERRUN | DE_POISON;
  1813. dev_priv->irq_mask = ~display_mask;
  1814. /* should always can generate irq */
  1815. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1816. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1817. I915_WRITE(DEIER, display_mask |
  1818. DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT);
  1819. POSTING_READ(DEIER);
  1820. gen5_gt_irq_postinstall(dev);
  1821. ibx_irq_postinstall(dev);
  1822. if (IS_IRONLAKE_M(dev)) {
  1823. /* Enable PCU event interrupts
  1824. *
  1825. * spinlocking not required here for correctness since interrupt
  1826. * setup is guaranteed to run in single-threaded context. But we
  1827. * need it to make the assert_spin_locked happy. */
  1828. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1829. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  1830. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1831. }
  1832. return 0;
  1833. }
  1834. static int ivybridge_irq_postinstall(struct drm_device *dev)
  1835. {
  1836. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1837. /* enable kind of interrupts always enabled */
  1838. u32 display_mask =
  1839. DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | DE_PCH_EVENT_IVB |
  1840. DE_PLANEC_FLIP_DONE_IVB |
  1841. DE_PLANEB_FLIP_DONE_IVB |
  1842. DE_PLANEA_FLIP_DONE_IVB |
  1843. DE_AUX_CHANNEL_A_IVB |
  1844. DE_ERR_INT_IVB;
  1845. dev_priv->irq_mask = ~display_mask;
  1846. /* should always can generate irq */
  1847. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  1848. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1849. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1850. I915_WRITE(DEIER,
  1851. display_mask |
  1852. DE_PIPEC_VBLANK_IVB |
  1853. DE_PIPEB_VBLANK_IVB |
  1854. DE_PIPEA_VBLANK_IVB);
  1855. POSTING_READ(DEIER);
  1856. gen5_gt_irq_postinstall(dev);
  1857. ibx_irq_postinstall(dev);
  1858. return 0;
  1859. }
  1860. static int valleyview_irq_postinstall(struct drm_device *dev)
  1861. {
  1862. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1863. u32 enable_mask;
  1864. u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV;
  1865. unsigned long irqflags;
  1866. enable_mask = I915_DISPLAY_PORT_INTERRUPT;
  1867. enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1868. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1869. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1870. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1871. /*
  1872. *Leave vblank interrupts masked initially. enable/disable will
  1873. * toggle them based on usage.
  1874. */
  1875. dev_priv->irq_mask = (~enable_mask) |
  1876. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1877. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1878. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1879. POSTING_READ(PORT_HOTPLUG_EN);
  1880. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  1881. I915_WRITE(VLV_IER, enable_mask);
  1882. I915_WRITE(VLV_IIR, 0xffffffff);
  1883. I915_WRITE(PIPESTAT(0), 0xffff);
  1884. I915_WRITE(PIPESTAT(1), 0xffff);
  1885. POSTING_READ(VLV_IER);
  1886. /* Interrupt setup is already guaranteed to be single-threaded, this is
  1887. * just to make the assert_spin_locked check happy. */
  1888. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1889. i915_enable_pipestat(dev_priv, 0, pipestat_enable);
  1890. i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
  1891. i915_enable_pipestat(dev_priv, 1, pipestat_enable);
  1892. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1893. I915_WRITE(VLV_IIR, 0xffffffff);
  1894. I915_WRITE(VLV_IIR, 0xffffffff);
  1895. gen5_gt_irq_postinstall(dev);
  1896. /* ack & enable invalid PTE error interrupts */
  1897. #if 0 /* FIXME: add support to irq handler for checking these bits */
  1898. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  1899. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  1900. #endif
  1901. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  1902. return 0;
  1903. }
  1904. static void valleyview_irq_uninstall(struct drm_device *dev)
  1905. {
  1906. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1907. int pipe;
  1908. if (!dev_priv)
  1909. return;
  1910. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  1911. for_each_pipe(pipe)
  1912. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1913. I915_WRITE(HWSTAM, 0xffffffff);
  1914. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1915. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1916. for_each_pipe(pipe)
  1917. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1918. I915_WRITE(VLV_IIR, 0xffffffff);
  1919. I915_WRITE(VLV_IMR, 0xffffffff);
  1920. I915_WRITE(VLV_IER, 0x0);
  1921. POSTING_READ(VLV_IER);
  1922. }
  1923. static void ironlake_irq_uninstall(struct drm_device *dev)
  1924. {
  1925. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1926. if (!dev_priv)
  1927. return;
  1928. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  1929. I915_WRITE(HWSTAM, 0xffffffff);
  1930. I915_WRITE(DEIMR, 0xffffffff);
  1931. I915_WRITE(DEIER, 0x0);
  1932. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1933. if (IS_GEN7(dev))
  1934. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  1935. I915_WRITE(GTIMR, 0xffffffff);
  1936. I915_WRITE(GTIER, 0x0);
  1937. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1938. if (HAS_PCH_NOP(dev))
  1939. return;
  1940. I915_WRITE(SDEIMR, 0xffffffff);
  1941. I915_WRITE(SDEIER, 0x0);
  1942. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1943. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  1944. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  1945. }
  1946. static void i8xx_irq_preinstall(struct drm_device * dev)
  1947. {
  1948. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1949. int pipe;
  1950. atomic_set(&dev_priv->irq_received, 0);
  1951. for_each_pipe(pipe)
  1952. I915_WRITE(PIPESTAT(pipe), 0);
  1953. I915_WRITE16(IMR, 0xffff);
  1954. I915_WRITE16(IER, 0x0);
  1955. POSTING_READ16(IER);
  1956. }
  1957. static int i8xx_irq_postinstall(struct drm_device *dev)
  1958. {
  1959. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1960. I915_WRITE16(EMR,
  1961. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  1962. /* Unmask the interrupts that we always want on. */
  1963. dev_priv->irq_mask =
  1964. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1965. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1966. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1967. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  1968. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1969. I915_WRITE16(IMR, dev_priv->irq_mask);
  1970. I915_WRITE16(IER,
  1971. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1972. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1973. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  1974. I915_USER_INTERRUPT);
  1975. POSTING_READ16(IER);
  1976. return 0;
  1977. }
  1978. /*
  1979. * Returns true when a page flip has completed.
  1980. */
  1981. static bool i8xx_handle_vblank(struct drm_device *dev,
  1982. int pipe, u16 iir)
  1983. {
  1984. drm_i915_private_t *dev_priv = dev->dev_private;
  1985. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
  1986. if (!drm_handle_vblank(dev, pipe))
  1987. return false;
  1988. if ((iir & flip_pending) == 0)
  1989. return false;
  1990. intel_prepare_page_flip(dev, pipe);
  1991. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  1992. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  1993. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  1994. * the flip is completed (no longer pending). Since this doesn't raise
  1995. * an interrupt per se, we watch for the change at vblank.
  1996. */
  1997. if (I915_READ16(ISR) & flip_pending)
  1998. return false;
  1999. intel_finish_page_flip(dev, pipe);
  2000. return true;
  2001. }
  2002. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  2003. {
  2004. struct drm_device *dev = (struct drm_device *) arg;
  2005. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2006. u16 iir, new_iir;
  2007. u32 pipe_stats[2];
  2008. unsigned long irqflags;
  2009. int irq_received;
  2010. int pipe;
  2011. u16 flip_mask =
  2012. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2013. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2014. atomic_inc(&dev_priv->irq_received);
  2015. iir = I915_READ16(IIR);
  2016. if (iir == 0)
  2017. return IRQ_NONE;
  2018. while (iir & ~flip_mask) {
  2019. /* Can't rely on pipestat interrupt bit in iir as it might
  2020. * have been cleared after the pipestat interrupt was received.
  2021. * It doesn't set the bit in iir again, but it still produces
  2022. * interrupts (for non-MSI).
  2023. */
  2024. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2025. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2026. i915_handle_error(dev, false);
  2027. for_each_pipe(pipe) {
  2028. int reg = PIPESTAT(pipe);
  2029. pipe_stats[pipe] = I915_READ(reg);
  2030. /*
  2031. * Clear the PIPE*STAT regs before the IIR
  2032. */
  2033. if (pipe_stats[pipe] & 0x8000ffff) {
  2034. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2035. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2036. pipe_name(pipe));
  2037. I915_WRITE(reg, pipe_stats[pipe]);
  2038. irq_received = 1;
  2039. }
  2040. }
  2041. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2042. I915_WRITE16(IIR, iir & ~flip_mask);
  2043. new_iir = I915_READ16(IIR); /* Flush posted writes */
  2044. i915_update_dri1_breadcrumb(dev);
  2045. if (iir & I915_USER_INTERRUPT)
  2046. notify_ring(dev, &dev_priv->ring[RCS]);
  2047. if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2048. i8xx_handle_vblank(dev, 0, iir))
  2049. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0);
  2050. if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2051. i8xx_handle_vblank(dev, 1, iir))
  2052. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1);
  2053. iir = new_iir;
  2054. }
  2055. return IRQ_HANDLED;
  2056. }
  2057. static void i8xx_irq_uninstall(struct drm_device * dev)
  2058. {
  2059. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2060. int pipe;
  2061. for_each_pipe(pipe) {
  2062. /* Clear enable bits; then clear status bits */
  2063. I915_WRITE(PIPESTAT(pipe), 0);
  2064. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2065. }
  2066. I915_WRITE16(IMR, 0xffff);
  2067. I915_WRITE16(IER, 0x0);
  2068. I915_WRITE16(IIR, I915_READ16(IIR));
  2069. }
  2070. static void i915_irq_preinstall(struct drm_device * dev)
  2071. {
  2072. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2073. int pipe;
  2074. atomic_set(&dev_priv->irq_received, 0);
  2075. if (I915_HAS_HOTPLUG(dev)) {
  2076. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2077. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2078. }
  2079. I915_WRITE16(HWSTAM, 0xeffe);
  2080. for_each_pipe(pipe)
  2081. I915_WRITE(PIPESTAT(pipe), 0);
  2082. I915_WRITE(IMR, 0xffffffff);
  2083. I915_WRITE(IER, 0x0);
  2084. POSTING_READ(IER);
  2085. }
  2086. static int i915_irq_postinstall(struct drm_device *dev)
  2087. {
  2088. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2089. u32 enable_mask;
  2090. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2091. /* Unmask the interrupts that we always want on. */
  2092. dev_priv->irq_mask =
  2093. ~(I915_ASLE_INTERRUPT |
  2094. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2095. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2096. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2097. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2098. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2099. enable_mask =
  2100. I915_ASLE_INTERRUPT |
  2101. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2102. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2103. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2104. I915_USER_INTERRUPT;
  2105. if (I915_HAS_HOTPLUG(dev)) {
  2106. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2107. POSTING_READ(PORT_HOTPLUG_EN);
  2108. /* Enable in IER... */
  2109. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  2110. /* and unmask in IMR */
  2111. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  2112. }
  2113. I915_WRITE(IMR, dev_priv->irq_mask);
  2114. I915_WRITE(IER, enable_mask);
  2115. POSTING_READ(IER);
  2116. i915_enable_asle_pipestat(dev);
  2117. return 0;
  2118. }
  2119. /*
  2120. * Returns true when a page flip has completed.
  2121. */
  2122. static bool i915_handle_vblank(struct drm_device *dev,
  2123. int plane, int pipe, u32 iir)
  2124. {
  2125. drm_i915_private_t *dev_priv = dev->dev_private;
  2126. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  2127. if (!drm_handle_vblank(dev, pipe))
  2128. return false;
  2129. if ((iir & flip_pending) == 0)
  2130. return false;
  2131. intel_prepare_page_flip(dev, plane);
  2132. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2133. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2134. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2135. * the flip is completed (no longer pending). Since this doesn't raise
  2136. * an interrupt per se, we watch for the change at vblank.
  2137. */
  2138. if (I915_READ(ISR) & flip_pending)
  2139. return false;
  2140. intel_finish_page_flip(dev, pipe);
  2141. return true;
  2142. }
  2143. static irqreturn_t i915_irq_handler(int irq, void *arg)
  2144. {
  2145. struct drm_device *dev = (struct drm_device *) arg;
  2146. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2147. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  2148. unsigned long irqflags;
  2149. u32 flip_mask =
  2150. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2151. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2152. int pipe, ret = IRQ_NONE;
  2153. atomic_inc(&dev_priv->irq_received);
  2154. iir = I915_READ(IIR);
  2155. do {
  2156. bool irq_received = (iir & ~flip_mask) != 0;
  2157. bool blc_event = false;
  2158. /* Can't rely on pipestat interrupt bit in iir as it might
  2159. * have been cleared after the pipestat interrupt was received.
  2160. * It doesn't set the bit in iir again, but it still produces
  2161. * interrupts (for non-MSI).
  2162. */
  2163. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2164. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2165. i915_handle_error(dev, false);
  2166. for_each_pipe(pipe) {
  2167. int reg = PIPESTAT(pipe);
  2168. pipe_stats[pipe] = I915_READ(reg);
  2169. /* Clear the PIPE*STAT regs before the IIR */
  2170. if (pipe_stats[pipe] & 0x8000ffff) {
  2171. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2172. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2173. pipe_name(pipe));
  2174. I915_WRITE(reg, pipe_stats[pipe]);
  2175. irq_received = true;
  2176. }
  2177. }
  2178. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2179. if (!irq_received)
  2180. break;
  2181. /* Consume port. Then clear IIR or we'll miss events */
  2182. if ((I915_HAS_HOTPLUG(dev)) &&
  2183. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  2184. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2185. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  2186. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2187. hotplug_status);
  2188. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  2189. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2190. POSTING_READ(PORT_HOTPLUG_STAT);
  2191. }
  2192. I915_WRITE(IIR, iir & ~flip_mask);
  2193. new_iir = I915_READ(IIR); /* Flush posted writes */
  2194. if (iir & I915_USER_INTERRUPT)
  2195. notify_ring(dev, &dev_priv->ring[RCS]);
  2196. for_each_pipe(pipe) {
  2197. int plane = pipe;
  2198. if (IS_MOBILE(dev))
  2199. plane = !plane;
  2200. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2201. i915_handle_vblank(dev, plane, pipe, iir))
  2202. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  2203. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2204. blc_event = true;
  2205. }
  2206. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2207. intel_opregion_asle_intr(dev);
  2208. /* With MSI, interrupts are only generated when iir
  2209. * transitions from zero to nonzero. If another bit got
  2210. * set while we were handling the existing iir bits, then
  2211. * we would never get another interrupt.
  2212. *
  2213. * This is fine on non-MSI as well, as if we hit this path
  2214. * we avoid exiting the interrupt handler only to generate
  2215. * another one.
  2216. *
  2217. * Note that for MSI this could cause a stray interrupt report
  2218. * if an interrupt landed in the time between writing IIR and
  2219. * the posting read. This should be rare enough to never
  2220. * trigger the 99% of 100,000 interrupts test for disabling
  2221. * stray interrupts.
  2222. */
  2223. ret = IRQ_HANDLED;
  2224. iir = new_iir;
  2225. } while (iir & ~flip_mask);
  2226. i915_update_dri1_breadcrumb(dev);
  2227. return ret;
  2228. }
  2229. static void i915_irq_uninstall(struct drm_device * dev)
  2230. {
  2231. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2232. int pipe;
  2233. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2234. if (I915_HAS_HOTPLUG(dev)) {
  2235. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2236. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2237. }
  2238. I915_WRITE16(HWSTAM, 0xffff);
  2239. for_each_pipe(pipe) {
  2240. /* Clear enable bits; then clear status bits */
  2241. I915_WRITE(PIPESTAT(pipe), 0);
  2242. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2243. }
  2244. I915_WRITE(IMR, 0xffffffff);
  2245. I915_WRITE(IER, 0x0);
  2246. I915_WRITE(IIR, I915_READ(IIR));
  2247. }
  2248. static void i965_irq_preinstall(struct drm_device * dev)
  2249. {
  2250. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2251. int pipe;
  2252. atomic_set(&dev_priv->irq_received, 0);
  2253. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2254. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2255. I915_WRITE(HWSTAM, 0xeffe);
  2256. for_each_pipe(pipe)
  2257. I915_WRITE(PIPESTAT(pipe), 0);
  2258. I915_WRITE(IMR, 0xffffffff);
  2259. I915_WRITE(IER, 0x0);
  2260. POSTING_READ(IER);
  2261. }
  2262. static int i965_irq_postinstall(struct drm_device *dev)
  2263. {
  2264. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2265. u32 enable_mask;
  2266. u32 error_mask;
  2267. unsigned long irqflags;
  2268. /* Unmask the interrupts that we always want on. */
  2269. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  2270. I915_DISPLAY_PORT_INTERRUPT |
  2271. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2272. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2273. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2274. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2275. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2276. enable_mask = ~dev_priv->irq_mask;
  2277. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2278. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  2279. enable_mask |= I915_USER_INTERRUPT;
  2280. if (IS_G4X(dev))
  2281. enable_mask |= I915_BSD_USER_INTERRUPT;
  2282. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2283. * just to make the assert_spin_locked check happy. */
  2284. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2285. i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
  2286. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2287. /*
  2288. * Enable some error detection, note the instruction error mask
  2289. * bit is reserved, so we leave it masked.
  2290. */
  2291. if (IS_G4X(dev)) {
  2292. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  2293. GM45_ERROR_MEM_PRIV |
  2294. GM45_ERROR_CP_PRIV |
  2295. I915_ERROR_MEMORY_REFRESH);
  2296. } else {
  2297. error_mask = ~(I915_ERROR_PAGE_TABLE |
  2298. I915_ERROR_MEMORY_REFRESH);
  2299. }
  2300. I915_WRITE(EMR, error_mask);
  2301. I915_WRITE(IMR, dev_priv->irq_mask);
  2302. I915_WRITE(IER, enable_mask);
  2303. POSTING_READ(IER);
  2304. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2305. POSTING_READ(PORT_HOTPLUG_EN);
  2306. i915_enable_asle_pipestat(dev);
  2307. return 0;
  2308. }
  2309. static void i915_hpd_irq_setup(struct drm_device *dev)
  2310. {
  2311. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2312. struct drm_mode_config *mode_config = &dev->mode_config;
  2313. struct intel_encoder *intel_encoder;
  2314. u32 hotplug_en;
  2315. assert_spin_locked(&dev_priv->irq_lock);
  2316. if (I915_HAS_HOTPLUG(dev)) {
  2317. hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  2318. hotplug_en &= ~HOTPLUG_INT_EN_MASK;
  2319. /* Note HDMI and DP share hotplug bits */
  2320. /* enable bits are the same for all generations */
  2321. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2322. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2323. hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
  2324. /* Programming the CRT detection parameters tends
  2325. to generate a spurious hotplug event about three
  2326. seconds later. So just do it once.
  2327. */
  2328. if (IS_G4X(dev))
  2329. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  2330. hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
  2331. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  2332. /* Ignore TV since it's buggy */
  2333. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  2334. }
  2335. }
  2336. static irqreturn_t i965_irq_handler(int irq, void *arg)
  2337. {
  2338. struct drm_device *dev = (struct drm_device *) arg;
  2339. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2340. u32 iir, new_iir;
  2341. u32 pipe_stats[I915_MAX_PIPES];
  2342. unsigned long irqflags;
  2343. int irq_received;
  2344. int ret = IRQ_NONE, pipe;
  2345. u32 flip_mask =
  2346. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2347. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2348. atomic_inc(&dev_priv->irq_received);
  2349. iir = I915_READ(IIR);
  2350. for (;;) {
  2351. bool blc_event = false;
  2352. irq_received = (iir & ~flip_mask) != 0;
  2353. /* Can't rely on pipestat interrupt bit in iir as it might
  2354. * have been cleared after the pipestat interrupt was received.
  2355. * It doesn't set the bit in iir again, but it still produces
  2356. * interrupts (for non-MSI).
  2357. */
  2358. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2359. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2360. i915_handle_error(dev, false);
  2361. for_each_pipe(pipe) {
  2362. int reg = PIPESTAT(pipe);
  2363. pipe_stats[pipe] = I915_READ(reg);
  2364. /*
  2365. * Clear the PIPE*STAT regs before the IIR
  2366. */
  2367. if (pipe_stats[pipe] & 0x8000ffff) {
  2368. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2369. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2370. pipe_name(pipe));
  2371. I915_WRITE(reg, pipe_stats[pipe]);
  2372. irq_received = 1;
  2373. }
  2374. }
  2375. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2376. if (!irq_received)
  2377. break;
  2378. ret = IRQ_HANDLED;
  2379. /* Consume port. Then clear IIR or we'll miss events */
  2380. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  2381. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2382. u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
  2383. HOTPLUG_INT_STATUS_G4X :
  2384. HOTPLUG_INT_STATUS_I915);
  2385. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2386. hotplug_status);
  2387. intel_hpd_irq_handler(dev, hotplug_trigger,
  2388. IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
  2389. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2390. I915_READ(PORT_HOTPLUG_STAT);
  2391. }
  2392. I915_WRITE(IIR, iir & ~flip_mask);
  2393. new_iir = I915_READ(IIR); /* Flush posted writes */
  2394. if (iir & I915_USER_INTERRUPT)
  2395. notify_ring(dev, &dev_priv->ring[RCS]);
  2396. if (iir & I915_BSD_USER_INTERRUPT)
  2397. notify_ring(dev, &dev_priv->ring[VCS]);
  2398. for_each_pipe(pipe) {
  2399. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  2400. i915_handle_vblank(dev, pipe, pipe, iir))
  2401. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  2402. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2403. blc_event = true;
  2404. }
  2405. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2406. intel_opregion_asle_intr(dev);
  2407. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  2408. gmbus_irq_handler(dev);
  2409. /* With MSI, interrupts are only generated when iir
  2410. * transitions from zero to nonzero. If another bit got
  2411. * set while we were handling the existing iir bits, then
  2412. * we would never get another interrupt.
  2413. *
  2414. * This is fine on non-MSI as well, as if we hit this path
  2415. * we avoid exiting the interrupt handler only to generate
  2416. * another one.
  2417. *
  2418. * Note that for MSI this could cause a stray interrupt report
  2419. * if an interrupt landed in the time between writing IIR and
  2420. * the posting read. This should be rare enough to never
  2421. * trigger the 99% of 100,000 interrupts test for disabling
  2422. * stray interrupts.
  2423. */
  2424. iir = new_iir;
  2425. }
  2426. i915_update_dri1_breadcrumb(dev);
  2427. return ret;
  2428. }
  2429. static void i965_irq_uninstall(struct drm_device * dev)
  2430. {
  2431. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2432. int pipe;
  2433. if (!dev_priv)
  2434. return;
  2435. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2436. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2437. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2438. I915_WRITE(HWSTAM, 0xffffffff);
  2439. for_each_pipe(pipe)
  2440. I915_WRITE(PIPESTAT(pipe), 0);
  2441. I915_WRITE(IMR, 0xffffffff);
  2442. I915_WRITE(IER, 0x0);
  2443. for_each_pipe(pipe)
  2444. I915_WRITE(PIPESTAT(pipe),
  2445. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  2446. I915_WRITE(IIR, I915_READ(IIR));
  2447. }
  2448. static void i915_reenable_hotplug_timer_func(unsigned long data)
  2449. {
  2450. drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
  2451. struct drm_device *dev = dev_priv->dev;
  2452. struct drm_mode_config *mode_config = &dev->mode_config;
  2453. unsigned long irqflags;
  2454. int i;
  2455. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2456. for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
  2457. struct drm_connector *connector;
  2458. if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
  2459. continue;
  2460. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  2461. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2462. struct intel_connector *intel_connector = to_intel_connector(connector);
  2463. if (intel_connector->encoder->hpd_pin == i) {
  2464. if (connector->polled != intel_connector->polled)
  2465. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  2466. drm_get_connector_name(connector));
  2467. connector->polled = intel_connector->polled;
  2468. if (!connector->polled)
  2469. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2470. }
  2471. }
  2472. }
  2473. if (dev_priv->display.hpd_irq_setup)
  2474. dev_priv->display.hpd_irq_setup(dev);
  2475. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2476. }
  2477. void intel_irq_init(struct drm_device *dev)
  2478. {
  2479. struct drm_i915_private *dev_priv = dev->dev_private;
  2480. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  2481. INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
  2482. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  2483. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  2484. setup_timer(&dev_priv->gpu_error.hangcheck_timer,
  2485. i915_hangcheck_elapsed,
  2486. (unsigned long) dev);
  2487. setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
  2488. (unsigned long) dev_priv);
  2489. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  2490. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  2491. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  2492. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  2493. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  2494. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  2495. }
  2496. if (drm_core_check_feature(dev, DRIVER_MODESET))
  2497. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  2498. else
  2499. dev->driver->get_vblank_timestamp = NULL;
  2500. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  2501. if (IS_VALLEYVIEW(dev)) {
  2502. dev->driver->irq_handler = valleyview_irq_handler;
  2503. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  2504. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  2505. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  2506. dev->driver->enable_vblank = valleyview_enable_vblank;
  2507. dev->driver->disable_vblank = valleyview_disable_vblank;
  2508. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2509. } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
  2510. /* Share uninstall handlers with ILK/SNB */
  2511. dev->driver->irq_handler = ironlake_irq_handler;
  2512. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2513. dev->driver->irq_postinstall = ivybridge_irq_postinstall;
  2514. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2515. dev->driver->enable_vblank = ivybridge_enable_vblank;
  2516. dev->driver->disable_vblank = ivybridge_disable_vblank;
  2517. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  2518. } else if (HAS_PCH_SPLIT(dev)) {
  2519. dev->driver->irq_handler = ironlake_irq_handler;
  2520. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2521. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  2522. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2523. dev->driver->enable_vblank = ironlake_enable_vblank;
  2524. dev->driver->disable_vblank = ironlake_disable_vblank;
  2525. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  2526. } else {
  2527. if (INTEL_INFO(dev)->gen == 2) {
  2528. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  2529. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  2530. dev->driver->irq_handler = i8xx_irq_handler;
  2531. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  2532. } else if (INTEL_INFO(dev)->gen == 3) {
  2533. dev->driver->irq_preinstall = i915_irq_preinstall;
  2534. dev->driver->irq_postinstall = i915_irq_postinstall;
  2535. dev->driver->irq_uninstall = i915_irq_uninstall;
  2536. dev->driver->irq_handler = i915_irq_handler;
  2537. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2538. } else {
  2539. dev->driver->irq_preinstall = i965_irq_preinstall;
  2540. dev->driver->irq_postinstall = i965_irq_postinstall;
  2541. dev->driver->irq_uninstall = i965_irq_uninstall;
  2542. dev->driver->irq_handler = i965_irq_handler;
  2543. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2544. }
  2545. dev->driver->enable_vblank = i915_enable_vblank;
  2546. dev->driver->disable_vblank = i915_disable_vblank;
  2547. }
  2548. }
  2549. void intel_hpd_init(struct drm_device *dev)
  2550. {
  2551. struct drm_i915_private *dev_priv = dev->dev_private;
  2552. struct drm_mode_config *mode_config = &dev->mode_config;
  2553. struct drm_connector *connector;
  2554. unsigned long irqflags;
  2555. int i;
  2556. for (i = 1; i < HPD_NUM_PINS; i++) {
  2557. dev_priv->hpd_stats[i].hpd_cnt = 0;
  2558. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  2559. }
  2560. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2561. struct intel_connector *intel_connector = to_intel_connector(connector);
  2562. connector->polled = intel_connector->polled;
  2563. if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
  2564. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2565. }
  2566. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2567. * just to make the assert_spin_locked checks happy. */
  2568. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2569. if (dev_priv->display.hpd_irq_setup)
  2570. dev_priv->display.hpd_irq_setup(dev);
  2571. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2572. }