i915_irq.c 91 KB

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