i915_irq.c 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205
  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 <linux/circ_buf.h>
  32. #include <drm/drmP.h>
  33. #include <drm/i915_drm.h>
  34. #include "i915_drv.h"
  35. #include "i915_trace.h"
  36. #include "intel_drv.h"
  37. static const u32 hpd_ibx[] = {
  38. [HPD_CRT] = SDE_CRT_HOTPLUG,
  39. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
  40. [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
  41. [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
  42. [HPD_PORT_D] = SDE_PORTD_HOTPLUG
  43. };
  44. static const u32 hpd_cpt[] = {
  45. [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
  46. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
  47. [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
  48. [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
  49. [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
  50. };
  51. static const u32 hpd_mask_i915[] = {
  52. [HPD_CRT] = CRT_HOTPLUG_INT_EN,
  53. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
  54. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
  55. [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
  56. [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
  57. [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
  58. };
  59. static const u32 hpd_status_g4x[] = {
  60. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  61. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
  62. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
  63. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  64. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  65. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
  66. };
  67. static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
  68. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  69. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
  70. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
  71. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  72. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  73. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
  74. };
  75. /* For display hotplug interrupt */
  76. static void
  77. ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  78. {
  79. assert_spin_locked(&dev_priv->irq_lock);
  80. if (dev_priv->pm.irqs_disabled) {
  81. WARN(1, "IRQs disabled\n");
  82. dev_priv->pm.regsave.deimr &= ~mask;
  83. return;
  84. }
  85. if ((dev_priv->irq_mask & mask) != 0) {
  86. dev_priv->irq_mask &= ~mask;
  87. I915_WRITE(DEIMR, dev_priv->irq_mask);
  88. POSTING_READ(DEIMR);
  89. }
  90. }
  91. static void
  92. ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  93. {
  94. assert_spin_locked(&dev_priv->irq_lock);
  95. if (dev_priv->pm.irqs_disabled) {
  96. WARN(1, "IRQs disabled\n");
  97. dev_priv->pm.regsave.deimr |= mask;
  98. return;
  99. }
  100. if ((dev_priv->irq_mask & mask) != mask) {
  101. dev_priv->irq_mask |= mask;
  102. I915_WRITE(DEIMR, dev_priv->irq_mask);
  103. POSTING_READ(DEIMR);
  104. }
  105. }
  106. /**
  107. * ilk_update_gt_irq - update GTIMR
  108. * @dev_priv: driver private
  109. * @interrupt_mask: mask of interrupt bits to update
  110. * @enabled_irq_mask: mask of interrupt bits to enable
  111. */
  112. static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
  113. uint32_t interrupt_mask,
  114. uint32_t enabled_irq_mask)
  115. {
  116. assert_spin_locked(&dev_priv->irq_lock);
  117. if (dev_priv->pm.irqs_disabled) {
  118. WARN(1, "IRQs disabled\n");
  119. dev_priv->pm.regsave.gtimr &= ~interrupt_mask;
  120. dev_priv->pm.regsave.gtimr |= (~enabled_irq_mask &
  121. interrupt_mask);
  122. return;
  123. }
  124. dev_priv->gt_irq_mask &= ~interrupt_mask;
  125. dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
  126. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  127. POSTING_READ(GTIMR);
  128. }
  129. void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  130. {
  131. ilk_update_gt_irq(dev_priv, mask, mask);
  132. }
  133. void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  134. {
  135. ilk_update_gt_irq(dev_priv, mask, 0);
  136. }
  137. /**
  138. * snb_update_pm_irq - update GEN6_PMIMR
  139. * @dev_priv: driver private
  140. * @interrupt_mask: mask of interrupt bits to update
  141. * @enabled_irq_mask: mask of interrupt bits to enable
  142. */
  143. static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
  144. uint32_t interrupt_mask,
  145. uint32_t enabled_irq_mask)
  146. {
  147. uint32_t new_val;
  148. assert_spin_locked(&dev_priv->irq_lock);
  149. if (dev_priv->pm.irqs_disabled) {
  150. WARN(1, "IRQs disabled\n");
  151. dev_priv->pm.regsave.gen6_pmimr &= ~interrupt_mask;
  152. dev_priv->pm.regsave.gen6_pmimr |= (~enabled_irq_mask &
  153. interrupt_mask);
  154. return;
  155. }
  156. new_val = dev_priv->pm_irq_mask;
  157. new_val &= ~interrupt_mask;
  158. new_val |= (~enabled_irq_mask & interrupt_mask);
  159. if (new_val != dev_priv->pm_irq_mask) {
  160. dev_priv->pm_irq_mask = new_val;
  161. I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
  162. POSTING_READ(GEN6_PMIMR);
  163. }
  164. }
  165. void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  166. {
  167. snb_update_pm_irq(dev_priv, mask, mask);
  168. }
  169. void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  170. {
  171. snb_update_pm_irq(dev_priv, mask, 0);
  172. }
  173. static bool ivb_can_enable_err_int(struct drm_device *dev)
  174. {
  175. struct drm_i915_private *dev_priv = dev->dev_private;
  176. struct intel_crtc *crtc;
  177. enum pipe pipe;
  178. assert_spin_locked(&dev_priv->irq_lock);
  179. for_each_pipe(pipe) {
  180. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  181. if (crtc->cpu_fifo_underrun_disabled)
  182. return false;
  183. }
  184. return true;
  185. }
  186. static bool cpt_can_enable_serr_int(struct drm_device *dev)
  187. {
  188. struct drm_i915_private *dev_priv = dev->dev_private;
  189. enum pipe pipe;
  190. struct intel_crtc *crtc;
  191. assert_spin_locked(&dev_priv->irq_lock);
  192. for_each_pipe(pipe) {
  193. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  194. if (crtc->pch_fifo_underrun_disabled)
  195. return false;
  196. }
  197. return true;
  198. }
  199. static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe)
  200. {
  201. struct drm_i915_private *dev_priv = dev->dev_private;
  202. u32 reg = PIPESTAT(pipe);
  203. u32 pipestat = I915_READ(reg) & 0x7fff0000;
  204. assert_spin_locked(&dev_priv->irq_lock);
  205. I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
  206. POSTING_READ(reg);
  207. }
  208. static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
  209. enum pipe pipe, bool enable)
  210. {
  211. struct drm_i915_private *dev_priv = dev->dev_private;
  212. uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
  213. DE_PIPEB_FIFO_UNDERRUN;
  214. if (enable)
  215. ironlake_enable_display_irq(dev_priv, bit);
  216. else
  217. ironlake_disable_display_irq(dev_priv, bit);
  218. }
  219. static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
  220. enum pipe pipe, bool enable)
  221. {
  222. struct drm_i915_private *dev_priv = dev->dev_private;
  223. if (enable) {
  224. I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
  225. if (!ivb_can_enable_err_int(dev))
  226. return;
  227. ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
  228. } else {
  229. bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
  230. /* Change the state _after_ we've read out the current one. */
  231. ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
  232. if (!was_enabled &&
  233. (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
  234. DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
  235. pipe_name(pipe));
  236. }
  237. }
  238. }
  239. static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
  240. enum pipe pipe, bool enable)
  241. {
  242. struct drm_i915_private *dev_priv = dev->dev_private;
  243. assert_spin_locked(&dev_priv->irq_lock);
  244. if (enable)
  245. dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
  246. else
  247. dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
  248. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  249. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  250. }
  251. /**
  252. * ibx_display_interrupt_update - update SDEIMR
  253. * @dev_priv: driver private
  254. * @interrupt_mask: mask of interrupt bits to update
  255. * @enabled_irq_mask: mask of interrupt bits to enable
  256. */
  257. static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  258. uint32_t interrupt_mask,
  259. uint32_t enabled_irq_mask)
  260. {
  261. uint32_t sdeimr = I915_READ(SDEIMR);
  262. sdeimr &= ~interrupt_mask;
  263. sdeimr |= (~enabled_irq_mask & interrupt_mask);
  264. assert_spin_locked(&dev_priv->irq_lock);
  265. if (dev_priv->pm.irqs_disabled &&
  266. (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
  267. WARN(1, "IRQs disabled\n");
  268. dev_priv->pm.regsave.sdeimr &= ~interrupt_mask;
  269. dev_priv->pm.regsave.sdeimr |= (~enabled_irq_mask &
  270. interrupt_mask);
  271. return;
  272. }
  273. I915_WRITE(SDEIMR, sdeimr);
  274. POSTING_READ(SDEIMR);
  275. }
  276. #define ibx_enable_display_interrupt(dev_priv, bits) \
  277. ibx_display_interrupt_update((dev_priv), (bits), (bits))
  278. #define ibx_disable_display_interrupt(dev_priv, bits) \
  279. ibx_display_interrupt_update((dev_priv), (bits), 0)
  280. static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
  281. enum transcoder pch_transcoder,
  282. bool enable)
  283. {
  284. struct drm_i915_private *dev_priv = dev->dev_private;
  285. uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
  286. SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
  287. if (enable)
  288. ibx_enable_display_interrupt(dev_priv, bit);
  289. else
  290. ibx_disable_display_interrupt(dev_priv, bit);
  291. }
  292. static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
  293. enum transcoder pch_transcoder,
  294. bool enable)
  295. {
  296. struct drm_i915_private *dev_priv = dev->dev_private;
  297. if (enable) {
  298. I915_WRITE(SERR_INT,
  299. SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
  300. if (!cpt_can_enable_serr_int(dev))
  301. return;
  302. ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
  303. } else {
  304. uint32_t tmp = I915_READ(SERR_INT);
  305. bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
  306. /* Change the state _after_ we've read out the current one. */
  307. ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
  308. if (!was_enabled &&
  309. (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
  310. DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
  311. transcoder_name(pch_transcoder));
  312. }
  313. }
  314. }
  315. /**
  316. * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
  317. * @dev: drm device
  318. * @pipe: pipe
  319. * @enable: true if we want to report FIFO underrun errors, false otherwise
  320. *
  321. * This function makes us disable or enable CPU fifo underruns for a specific
  322. * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
  323. * reporting for one pipe may also disable all the other CPU error interruts for
  324. * the other pipes, due to the fact that there's just one interrupt mask/enable
  325. * bit for all the pipes.
  326. *
  327. * Returns the previous state of underrun reporting.
  328. */
  329. bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
  330. enum pipe pipe, bool enable)
  331. {
  332. struct drm_i915_private *dev_priv = dev->dev_private;
  333. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  334. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  335. bool ret;
  336. assert_spin_locked(&dev_priv->irq_lock);
  337. ret = !intel_crtc->cpu_fifo_underrun_disabled;
  338. if (enable == ret)
  339. goto done;
  340. intel_crtc->cpu_fifo_underrun_disabled = !enable;
  341. if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev)))
  342. i9xx_clear_fifo_underrun(dev, pipe);
  343. else if (IS_GEN5(dev) || IS_GEN6(dev))
  344. ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
  345. else if (IS_GEN7(dev))
  346. ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
  347. else if (IS_GEN8(dev))
  348. broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
  349. done:
  350. return ret;
  351. }
  352. bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
  353. enum pipe pipe, bool enable)
  354. {
  355. struct drm_i915_private *dev_priv = dev->dev_private;
  356. unsigned long flags;
  357. bool ret;
  358. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  359. ret = __intel_set_cpu_fifo_underrun_reporting(dev, pipe, enable);
  360. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  361. return ret;
  362. }
  363. static bool __cpu_fifo_underrun_reporting_enabled(struct drm_device *dev,
  364. enum pipe pipe)
  365. {
  366. struct drm_i915_private *dev_priv = dev->dev_private;
  367. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  368. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  369. return !intel_crtc->cpu_fifo_underrun_disabled;
  370. }
  371. /**
  372. * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
  373. * @dev: drm device
  374. * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
  375. * @enable: true if we want to report FIFO underrun errors, false otherwise
  376. *
  377. * This function makes us disable or enable PCH fifo underruns for a specific
  378. * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
  379. * underrun reporting for one transcoder may also disable all the other PCH
  380. * error interruts for the other transcoders, due to the fact that there's just
  381. * one interrupt mask/enable bit for all the transcoders.
  382. *
  383. * Returns the previous state of underrun reporting.
  384. */
  385. bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
  386. enum transcoder pch_transcoder,
  387. bool enable)
  388. {
  389. struct drm_i915_private *dev_priv = dev->dev_private;
  390. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
  391. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  392. unsigned long flags;
  393. bool ret;
  394. /*
  395. * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
  396. * has only one pch transcoder A that all pipes can use. To avoid racy
  397. * pch transcoder -> pipe lookups from interrupt code simply store the
  398. * underrun statistics in crtc A. Since we never expose this anywhere
  399. * nor use it outside of the fifo underrun code here using the "wrong"
  400. * crtc on LPT won't cause issues.
  401. */
  402. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  403. ret = !intel_crtc->pch_fifo_underrun_disabled;
  404. if (enable == ret)
  405. goto done;
  406. intel_crtc->pch_fifo_underrun_disabled = !enable;
  407. if (HAS_PCH_IBX(dev))
  408. ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
  409. else
  410. cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
  411. done:
  412. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  413. return ret;
  414. }
  415. static void
  416. __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  417. u32 enable_mask, u32 status_mask)
  418. {
  419. u32 reg = PIPESTAT(pipe);
  420. u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
  421. assert_spin_locked(&dev_priv->irq_lock);
  422. if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
  423. status_mask & ~PIPESTAT_INT_STATUS_MASK))
  424. return;
  425. if ((pipestat & enable_mask) == enable_mask)
  426. return;
  427. dev_priv->pipestat_irq_mask[pipe] |= status_mask;
  428. /* Enable the interrupt, clear any pending status */
  429. pipestat |= enable_mask | status_mask;
  430. I915_WRITE(reg, pipestat);
  431. POSTING_READ(reg);
  432. }
  433. static void
  434. __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  435. u32 enable_mask, u32 status_mask)
  436. {
  437. u32 reg = PIPESTAT(pipe);
  438. u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
  439. assert_spin_locked(&dev_priv->irq_lock);
  440. if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
  441. status_mask & ~PIPESTAT_INT_STATUS_MASK))
  442. return;
  443. if ((pipestat & enable_mask) == 0)
  444. return;
  445. dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
  446. pipestat &= ~enable_mask;
  447. I915_WRITE(reg, pipestat);
  448. POSTING_READ(reg);
  449. }
  450. static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
  451. {
  452. u32 enable_mask = status_mask << 16;
  453. /*
  454. * On pipe A we don't support the PSR interrupt yet, on pipe B the
  455. * same bit MBZ.
  456. */
  457. if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
  458. return 0;
  459. enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
  460. SPRITE0_FLIP_DONE_INT_EN_VLV |
  461. SPRITE1_FLIP_DONE_INT_EN_VLV);
  462. if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
  463. enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
  464. if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
  465. enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
  466. return enable_mask;
  467. }
  468. void
  469. i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  470. u32 status_mask)
  471. {
  472. u32 enable_mask;
  473. if (IS_VALLEYVIEW(dev_priv->dev))
  474. enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
  475. status_mask);
  476. else
  477. enable_mask = status_mask << 16;
  478. __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
  479. }
  480. void
  481. i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  482. u32 status_mask)
  483. {
  484. u32 enable_mask;
  485. if (IS_VALLEYVIEW(dev_priv->dev))
  486. enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
  487. status_mask);
  488. else
  489. enable_mask = status_mask << 16;
  490. __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
  491. }
  492. /**
  493. * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
  494. */
  495. static void i915_enable_asle_pipestat(struct drm_device *dev)
  496. {
  497. drm_i915_private_t *dev_priv = dev->dev_private;
  498. unsigned long irqflags;
  499. if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
  500. return;
  501. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  502. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
  503. if (INTEL_INFO(dev)->gen >= 4)
  504. i915_enable_pipestat(dev_priv, PIPE_A,
  505. PIPE_LEGACY_BLC_EVENT_STATUS);
  506. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  507. }
  508. /**
  509. * i915_pipe_enabled - check if a pipe is enabled
  510. * @dev: DRM device
  511. * @pipe: pipe to check
  512. *
  513. * Reading certain registers when the pipe is disabled can hang the chip.
  514. * Use this routine to make sure the PLL is running and the pipe is active
  515. * before reading such registers if unsure.
  516. */
  517. static int
  518. i915_pipe_enabled(struct drm_device *dev, int pipe)
  519. {
  520. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  521. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  522. /* Locking is horribly broken here, but whatever. */
  523. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  524. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  525. return intel_crtc->active;
  526. } else {
  527. return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
  528. }
  529. }
  530. static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
  531. {
  532. /* Gen2 doesn't have a hardware frame counter */
  533. return 0;
  534. }
  535. /* Called from drm generic code, passed a 'crtc', which
  536. * we use as a pipe index
  537. */
  538. static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  539. {
  540. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  541. unsigned long high_frame;
  542. unsigned long low_frame;
  543. u32 high1, high2, low, pixel, vbl_start;
  544. if (!i915_pipe_enabled(dev, pipe)) {
  545. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  546. "pipe %c\n", pipe_name(pipe));
  547. return 0;
  548. }
  549. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  550. struct intel_crtc *intel_crtc =
  551. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  552. const struct drm_display_mode *mode =
  553. &intel_crtc->config.adjusted_mode;
  554. vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
  555. } else {
  556. enum transcoder cpu_transcoder = (enum transcoder) pipe;
  557. u32 htotal;
  558. htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
  559. vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
  560. vbl_start *= htotal;
  561. }
  562. high_frame = PIPEFRAME(pipe);
  563. low_frame = PIPEFRAMEPIXEL(pipe);
  564. /*
  565. * High & low register fields aren't synchronized, so make sure
  566. * we get a low value that's stable across two reads of the high
  567. * register.
  568. */
  569. do {
  570. high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  571. low = I915_READ(low_frame);
  572. high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  573. } while (high1 != high2);
  574. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  575. pixel = low & PIPE_PIXEL_MASK;
  576. low >>= PIPE_FRAME_LOW_SHIFT;
  577. /*
  578. * The frame counter increments at beginning of active.
  579. * Cook up a vblank counter by also checking the pixel
  580. * counter against vblank start.
  581. */
  582. return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
  583. }
  584. static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  585. {
  586. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  587. int reg = PIPE_FRMCOUNT_GM45(pipe);
  588. if (!i915_pipe_enabled(dev, pipe)) {
  589. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  590. "pipe %c\n", pipe_name(pipe));
  591. return 0;
  592. }
  593. return I915_READ(reg);
  594. }
  595. /* raw reads, only for fast reads of display block, no need for forcewake etc. */
  596. #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
  597. static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
  598. {
  599. struct drm_i915_private *dev_priv = dev->dev_private;
  600. uint32_t status;
  601. int reg;
  602. if (INTEL_INFO(dev)->gen >= 8) {
  603. status = GEN8_PIPE_VBLANK;
  604. reg = GEN8_DE_PIPE_ISR(pipe);
  605. } else if (INTEL_INFO(dev)->gen >= 7) {
  606. status = DE_PIPE_VBLANK_IVB(pipe);
  607. reg = DEISR;
  608. } else {
  609. status = DE_PIPE_VBLANK(pipe);
  610. reg = DEISR;
  611. }
  612. return __raw_i915_read32(dev_priv, reg) & status;
  613. }
  614. static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
  615. unsigned int flags, int *vpos, int *hpos,
  616. ktime_t *stime, ktime_t *etime)
  617. {
  618. struct drm_i915_private *dev_priv = dev->dev_private;
  619. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  620. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  621. const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
  622. int position;
  623. int vbl_start, vbl_end, htotal, vtotal;
  624. bool in_vbl = true;
  625. int ret = 0;
  626. unsigned long irqflags;
  627. if (!intel_crtc->active) {
  628. DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
  629. "pipe %c\n", pipe_name(pipe));
  630. return 0;
  631. }
  632. htotal = mode->crtc_htotal;
  633. vtotal = mode->crtc_vtotal;
  634. vbl_start = mode->crtc_vblank_start;
  635. vbl_end = mode->crtc_vblank_end;
  636. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  637. vbl_start = DIV_ROUND_UP(vbl_start, 2);
  638. vbl_end /= 2;
  639. vtotal /= 2;
  640. }
  641. ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
  642. /*
  643. * Lock uncore.lock, as we will do multiple timing critical raw
  644. * register reads, potentially with preemption disabled, so the
  645. * following code must not block on uncore.lock.
  646. */
  647. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  648. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  649. /* Get optional system timestamp before query. */
  650. if (stime)
  651. *stime = ktime_get();
  652. if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  653. /* No obvious pixelcount register. Only query vertical
  654. * scanout position from Display scan line register.
  655. */
  656. if (IS_GEN2(dev))
  657. position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
  658. else
  659. position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
  660. if (HAS_DDI(dev)) {
  661. /*
  662. * On HSW HDMI outputs there seems to be a 2 line
  663. * difference, whereas eDP has the normal 1 line
  664. * difference that earlier platforms have. External
  665. * DP is unknown. For now just check for the 2 line
  666. * difference case on all output types on HSW+.
  667. *
  668. * This might misinterpret the scanline counter being
  669. * one line too far along on eDP, but that's less
  670. * dangerous than the alternative since that would lead
  671. * the vblank timestamp code astray when it sees a
  672. * scanline count before vblank_start during a vblank
  673. * interrupt.
  674. */
  675. in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
  676. if ((in_vbl && (position == vbl_start - 2 ||
  677. position == vbl_start - 1)) ||
  678. (!in_vbl && (position == vbl_end - 2 ||
  679. position == vbl_end - 1)))
  680. position = (position + 2) % vtotal;
  681. } else if (HAS_PCH_SPLIT(dev)) {
  682. /*
  683. * The scanline counter increments at the leading edge
  684. * of hsync, ie. it completely misses the active portion
  685. * of the line. Fix up the counter at both edges of vblank
  686. * to get a more accurate picture whether we're in vblank
  687. * or not.
  688. */
  689. in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
  690. if ((in_vbl && position == vbl_start - 1) ||
  691. (!in_vbl && position == vbl_end - 1))
  692. position = (position + 1) % vtotal;
  693. } else {
  694. /*
  695. * ISR vblank status bits don't work the way we'd want
  696. * them to work on non-PCH platforms (for
  697. * ilk_pipe_in_vblank_locked()), and there doesn't
  698. * appear any other way to determine if we're currently
  699. * in vblank.
  700. *
  701. * Instead let's assume that we're already in vblank if
  702. * we got called from the vblank interrupt and the
  703. * scanline counter value indicates that we're on the
  704. * line just prior to vblank start. This should result
  705. * in the correct answer, unless the vblank interrupt
  706. * delivery really got delayed for almost exactly one
  707. * full frame/field.
  708. */
  709. if (flags & DRM_CALLED_FROM_VBLIRQ &&
  710. position == vbl_start - 1) {
  711. position = (position + 1) % vtotal;
  712. /* Signal this correction as "applied". */
  713. ret |= 0x8;
  714. }
  715. }
  716. } else {
  717. /* Have access to pixelcount since start of frame.
  718. * We can split this into vertical and horizontal
  719. * scanout position.
  720. */
  721. position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  722. /* convert to pixel counts */
  723. vbl_start *= htotal;
  724. vbl_end *= htotal;
  725. vtotal *= htotal;
  726. }
  727. /* Get optional system timestamp after query. */
  728. if (etime)
  729. *etime = ktime_get();
  730. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  731. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  732. in_vbl = position >= vbl_start && position < vbl_end;
  733. /*
  734. * While in vblank, position will be negative
  735. * counting up towards 0 at vbl_end. And outside
  736. * vblank, position will be positive counting
  737. * up since vbl_end.
  738. */
  739. if (position >= vbl_start)
  740. position -= vbl_end;
  741. else
  742. position += vtotal - vbl_end;
  743. if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  744. *vpos = position;
  745. *hpos = 0;
  746. } else {
  747. *vpos = position / htotal;
  748. *hpos = position - (*vpos * htotal);
  749. }
  750. /* In vblank? */
  751. if (in_vbl)
  752. ret |= DRM_SCANOUTPOS_INVBL;
  753. return ret;
  754. }
  755. static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
  756. int *max_error,
  757. struct timeval *vblank_time,
  758. unsigned flags)
  759. {
  760. struct drm_crtc *crtc;
  761. if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
  762. DRM_ERROR("Invalid crtc %d\n", pipe);
  763. return -EINVAL;
  764. }
  765. /* Get drm_crtc to timestamp: */
  766. crtc = intel_get_crtc_for_pipe(dev, pipe);
  767. if (crtc == NULL) {
  768. DRM_ERROR("Invalid crtc %d\n", pipe);
  769. return -EINVAL;
  770. }
  771. if (!crtc->enabled) {
  772. DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
  773. return -EBUSY;
  774. }
  775. /* Helper routine in DRM core does all the work: */
  776. return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
  777. vblank_time, flags,
  778. crtc,
  779. &to_intel_crtc(crtc)->config.adjusted_mode);
  780. }
  781. static bool intel_hpd_irq_event(struct drm_device *dev,
  782. struct drm_connector *connector)
  783. {
  784. enum drm_connector_status old_status;
  785. WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
  786. old_status = connector->status;
  787. connector->status = connector->funcs->detect(connector, false);
  788. if (old_status == connector->status)
  789. return false;
  790. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
  791. connector->base.id,
  792. drm_get_connector_name(connector),
  793. drm_get_connector_status_name(old_status),
  794. drm_get_connector_status_name(connector->status));
  795. return true;
  796. }
  797. /*
  798. * Handle hotplug events outside the interrupt handler proper.
  799. */
  800. #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
  801. static void i915_hotplug_work_func(struct work_struct *work)
  802. {
  803. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  804. hotplug_work);
  805. struct drm_device *dev = dev_priv->dev;
  806. struct drm_mode_config *mode_config = &dev->mode_config;
  807. struct intel_connector *intel_connector;
  808. struct intel_encoder *intel_encoder;
  809. struct drm_connector *connector;
  810. unsigned long irqflags;
  811. bool hpd_disabled = false;
  812. bool changed = false;
  813. u32 hpd_event_bits;
  814. /* HPD irq before everything is fully set up. */
  815. if (!dev_priv->enable_hotplug_processing)
  816. return;
  817. mutex_lock(&mode_config->mutex);
  818. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  819. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  820. hpd_event_bits = dev_priv->hpd_event_bits;
  821. dev_priv->hpd_event_bits = 0;
  822. list_for_each_entry(connector, &mode_config->connector_list, head) {
  823. intel_connector = to_intel_connector(connector);
  824. intel_encoder = intel_connector->encoder;
  825. if (intel_encoder->hpd_pin > HPD_NONE &&
  826. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
  827. connector->polled == DRM_CONNECTOR_POLL_HPD) {
  828. DRM_INFO("HPD interrupt storm detected on connector %s: "
  829. "switching from hotplug detection to polling\n",
  830. drm_get_connector_name(connector));
  831. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
  832. connector->polled = DRM_CONNECTOR_POLL_CONNECT
  833. | DRM_CONNECTOR_POLL_DISCONNECT;
  834. hpd_disabled = true;
  835. }
  836. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  837. DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
  838. drm_get_connector_name(connector), intel_encoder->hpd_pin);
  839. }
  840. }
  841. /* if there were no outputs to poll, poll was disabled,
  842. * therefore make sure it's enabled when disabling HPD on
  843. * some connectors */
  844. if (hpd_disabled) {
  845. drm_kms_helper_poll_enable(dev);
  846. mod_timer(&dev_priv->hotplug_reenable_timer,
  847. jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
  848. }
  849. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  850. list_for_each_entry(connector, &mode_config->connector_list, head) {
  851. intel_connector = to_intel_connector(connector);
  852. intel_encoder = intel_connector->encoder;
  853. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  854. if (intel_encoder->hot_plug)
  855. intel_encoder->hot_plug(intel_encoder);
  856. if (intel_hpd_irq_event(dev, connector))
  857. changed = true;
  858. }
  859. }
  860. mutex_unlock(&mode_config->mutex);
  861. if (changed)
  862. drm_kms_helper_hotplug_event(dev);
  863. }
  864. static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv)
  865. {
  866. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  867. }
  868. static void ironlake_rps_change_irq_handler(struct drm_device *dev)
  869. {
  870. drm_i915_private_t *dev_priv = dev->dev_private;
  871. u32 busy_up, busy_down, max_avg, min_avg;
  872. u8 new_delay;
  873. spin_lock(&mchdev_lock);
  874. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  875. new_delay = dev_priv->ips.cur_delay;
  876. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  877. busy_up = I915_READ(RCPREVBSYTUPAVG);
  878. busy_down = I915_READ(RCPREVBSYTDNAVG);
  879. max_avg = I915_READ(RCBMAXAVG);
  880. min_avg = I915_READ(RCBMINAVG);
  881. /* Handle RCS change request from hw */
  882. if (busy_up > max_avg) {
  883. if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
  884. new_delay = dev_priv->ips.cur_delay - 1;
  885. if (new_delay < dev_priv->ips.max_delay)
  886. new_delay = dev_priv->ips.max_delay;
  887. } else if (busy_down < min_avg) {
  888. if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
  889. new_delay = dev_priv->ips.cur_delay + 1;
  890. if (new_delay > dev_priv->ips.min_delay)
  891. new_delay = dev_priv->ips.min_delay;
  892. }
  893. if (ironlake_set_drps(dev, new_delay))
  894. dev_priv->ips.cur_delay = new_delay;
  895. spin_unlock(&mchdev_lock);
  896. return;
  897. }
  898. static void notify_ring(struct drm_device *dev,
  899. struct intel_ring_buffer *ring)
  900. {
  901. if (ring->obj == NULL)
  902. return;
  903. trace_i915_gem_request_complete(ring);
  904. wake_up_all(&ring->irq_queue);
  905. i915_queue_hangcheck(dev);
  906. }
  907. void gen6_set_pm_mask(struct drm_i915_private *dev_priv,
  908. u32 pm_iir, int new_delay)
  909. {
  910. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
  911. if (new_delay >= dev_priv->rps.max_freq_softlimit) {
  912. /* Mask UP THRESHOLD Interrupts */
  913. I915_WRITE(GEN6_PMINTRMSK,
  914. I915_READ(GEN6_PMINTRMSK) |
  915. GEN6_PM_RP_UP_THRESHOLD);
  916. dev_priv->rps.rp_up_masked = true;
  917. }
  918. if (dev_priv->rps.rp_down_masked) {
  919. /* UnMask DOWN THRESHOLD Interrupts */
  920. I915_WRITE(GEN6_PMINTRMSK,
  921. I915_READ(GEN6_PMINTRMSK) &
  922. ~GEN6_PM_RP_DOWN_THRESHOLD);
  923. dev_priv->rps.rp_down_masked = false;
  924. }
  925. } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
  926. if (new_delay <= dev_priv->rps.min_freq_softlimit) {
  927. /* Mask DOWN THRESHOLD Interrupts */
  928. I915_WRITE(GEN6_PMINTRMSK,
  929. I915_READ(GEN6_PMINTRMSK) |
  930. GEN6_PM_RP_DOWN_THRESHOLD);
  931. dev_priv->rps.rp_down_masked = true;
  932. }
  933. if (dev_priv->rps.rp_up_masked) {
  934. /* UnMask UP THRESHOLD Interrupts */
  935. I915_WRITE(GEN6_PMINTRMSK,
  936. I915_READ(GEN6_PMINTRMSK) &
  937. ~GEN6_PM_RP_UP_THRESHOLD);
  938. dev_priv->rps.rp_up_masked = false;
  939. }
  940. }
  941. }
  942. static void gen6_pm_rps_work(struct work_struct *work)
  943. {
  944. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  945. rps.work);
  946. u32 pm_iir;
  947. int new_delay, adj;
  948. spin_lock_irq(&dev_priv->irq_lock);
  949. pm_iir = dev_priv->rps.pm_iir;
  950. dev_priv->rps.pm_iir = 0;
  951. /* Make sure not to corrupt PMIMR state used by ringbuffer code */
  952. snb_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
  953. spin_unlock_irq(&dev_priv->irq_lock);
  954. /* Make sure we didn't queue anything we're not going to process. */
  955. WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
  956. if ((pm_iir & dev_priv->pm_rps_events) == 0)
  957. return;
  958. mutex_lock(&dev_priv->rps.hw_lock);
  959. adj = dev_priv->rps.last_adj;
  960. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
  961. if (adj > 0)
  962. adj *= 2;
  963. else
  964. adj = 1;
  965. new_delay = dev_priv->rps.cur_freq + adj;
  966. /*
  967. * For better performance, jump directly
  968. * to RPe if we're below it.
  969. */
  970. if (new_delay < dev_priv->rps.efficient_freq)
  971. new_delay = dev_priv->rps.efficient_freq;
  972. } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
  973. if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
  974. new_delay = dev_priv->rps.efficient_freq;
  975. else
  976. new_delay = dev_priv->rps.min_freq_softlimit;
  977. adj = 0;
  978. } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
  979. if (adj < 0)
  980. adj *= 2;
  981. else
  982. adj = -1;
  983. new_delay = dev_priv->rps.cur_freq + adj;
  984. } else { /* unknown event */
  985. new_delay = dev_priv->rps.cur_freq;
  986. }
  987. /* sysfs frequency interfaces may have snuck in while servicing the
  988. * interrupt
  989. */
  990. new_delay = clamp_t(int, new_delay,
  991. dev_priv->rps.min_freq_softlimit,
  992. dev_priv->rps.max_freq_softlimit);
  993. gen6_set_pm_mask(dev_priv, pm_iir, new_delay);
  994. dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
  995. if (IS_VALLEYVIEW(dev_priv->dev))
  996. valleyview_set_rps(dev_priv->dev, new_delay);
  997. else
  998. gen6_set_rps(dev_priv->dev, new_delay);
  999. mutex_unlock(&dev_priv->rps.hw_lock);
  1000. }
  1001. /**
  1002. * ivybridge_parity_work - Workqueue called when a parity error interrupt
  1003. * occurred.
  1004. * @work: workqueue struct
  1005. *
  1006. * Doesn't actually do anything except notify userspace. As a consequence of
  1007. * this event, userspace should try to remap the bad rows since statistically
  1008. * it is likely the same row is more likely to go bad again.
  1009. */
  1010. static void ivybridge_parity_work(struct work_struct *work)
  1011. {
  1012. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  1013. l3_parity.error_work);
  1014. u32 error_status, row, bank, subbank;
  1015. char *parity_event[6];
  1016. uint32_t misccpctl;
  1017. unsigned long flags;
  1018. uint8_t slice = 0;
  1019. /* We must turn off DOP level clock gating to access the L3 registers.
  1020. * In order to prevent a get/put style interface, acquire struct mutex
  1021. * any time we access those registers.
  1022. */
  1023. mutex_lock(&dev_priv->dev->struct_mutex);
  1024. /* If we've screwed up tracking, just let the interrupt fire again */
  1025. if (WARN_ON(!dev_priv->l3_parity.which_slice))
  1026. goto out;
  1027. misccpctl = I915_READ(GEN7_MISCCPCTL);
  1028. I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  1029. POSTING_READ(GEN7_MISCCPCTL);
  1030. while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
  1031. u32 reg;
  1032. slice--;
  1033. if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
  1034. break;
  1035. dev_priv->l3_parity.which_slice &= ~(1<<slice);
  1036. reg = GEN7_L3CDERRST1 + (slice * 0x200);
  1037. error_status = I915_READ(reg);
  1038. row = GEN7_PARITY_ERROR_ROW(error_status);
  1039. bank = GEN7_PARITY_ERROR_BANK(error_status);
  1040. subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
  1041. I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
  1042. POSTING_READ(reg);
  1043. parity_event[0] = I915_L3_PARITY_UEVENT "=1";
  1044. parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
  1045. parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
  1046. parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
  1047. parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
  1048. parity_event[5] = NULL;
  1049. kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
  1050. KOBJ_CHANGE, parity_event);
  1051. DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
  1052. slice, row, bank, subbank);
  1053. kfree(parity_event[4]);
  1054. kfree(parity_event[3]);
  1055. kfree(parity_event[2]);
  1056. kfree(parity_event[1]);
  1057. }
  1058. I915_WRITE(GEN7_MISCCPCTL, misccpctl);
  1059. out:
  1060. WARN_ON(dev_priv->l3_parity.which_slice);
  1061. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  1062. ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
  1063. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  1064. mutex_unlock(&dev_priv->dev->struct_mutex);
  1065. }
  1066. static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
  1067. {
  1068. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1069. if (!HAS_L3_DPF(dev))
  1070. return;
  1071. spin_lock(&dev_priv->irq_lock);
  1072. ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
  1073. spin_unlock(&dev_priv->irq_lock);
  1074. iir &= GT_PARITY_ERROR(dev);
  1075. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
  1076. dev_priv->l3_parity.which_slice |= 1 << 1;
  1077. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
  1078. dev_priv->l3_parity.which_slice |= 1 << 0;
  1079. queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
  1080. }
  1081. static void ilk_gt_irq_handler(struct drm_device *dev,
  1082. struct drm_i915_private *dev_priv,
  1083. u32 gt_iir)
  1084. {
  1085. if (gt_iir &
  1086. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  1087. notify_ring(dev, &dev_priv->ring[RCS]);
  1088. if (gt_iir & ILK_BSD_USER_INTERRUPT)
  1089. notify_ring(dev, &dev_priv->ring[VCS]);
  1090. }
  1091. static void snb_gt_irq_handler(struct drm_device *dev,
  1092. struct drm_i915_private *dev_priv,
  1093. u32 gt_iir)
  1094. {
  1095. if (gt_iir &
  1096. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  1097. notify_ring(dev, &dev_priv->ring[RCS]);
  1098. if (gt_iir & GT_BSD_USER_INTERRUPT)
  1099. notify_ring(dev, &dev_priv->ring[VCS]);
  1100. if (gt_iir & GT_BLT_USER_INTERRUPT)
  1101. notify_ring(dev, &dev_priv->ring[BCS]);
  1102. if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
  1103. GT_BSD_CS_ERROR_INTERRUPT |
  1104. GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
  1105. i915_handle_error(dev, false, "GT error interrupt 0x%08x",
  1106. gt_iir);
  1107. }
  1108. if (gt_iir & GT_PARITY_ERROR(dev))
  1109. ivybridge_parity_error_irq_handler(dev, gt_iir);
  1110. }
  1111. static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
  1112. struct drm_i915_private *dev_priv,
  1113. u32 master_ctl)
  1114. {
  1115. u32 rcs, bcs, vcs;
  1116. uint32_t tmp = 0;
  1117. irqreturn_t ret = IRQ_NONE;
  1118. if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
  1119. tmp = I915_READ(GEN8_GT_IIR(0));
  1120. if (tmp) {
  1121. ret = IRQ_HANDLED;
  1122. rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
  1123. bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
  1124. if (rcs & GT_RENDER_USER_INTERRUPT)
  1125. notify_ring(dev, &dev_priv->ring[RCS]);
  1126. if (bcs & GT_RENDER_USER_INTERRUPT)
  1127. notify_ring(dev, &dev_priv->ring[BCS]);
  1128. I915_WRITE(GEN8_GT_IIR(0), tmp);
  1129. } else
  1130. DRM_ERROR("The master control interrupt lied (GT0)!\n");
  1131. }
  1132. if (master_ctl & GEN8_GT_VCS1_IRQ) {
  1133. tmp = I915_READ(GEN8_GT_IIR(1));
  1134. if (tmp) {
  1135. ret = IRQ_HANDLED;
  1136. vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
  1137. if (vcs & GT_RENDER_USER_INTERRUPT)
  1138. notify_ring(dev, &dev_priv->ring[VCS]);
  1139. I915_WRITE(GEN8_GT_IIR(1), tmp);
  1140. } else
  1141. DRM_ERROR("The master control interrupt lied (GT1)!\n");
  1142. }
  1143. if (master_ctl & GEN8_GT_VECS_IRQ) {
  1144. tmp = I915_READ(GEN8_GT_IIR(3));
  1145. if (tmp) {
  1146. ret = IRQ_HANDLED;
  1147. vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
  1148. if (vcs & GT_RENDER_USER_INTERRUPT)
  1149. notify_ring(dev, &dev_priv->ring[VECS]);
  1150. I915_WRITE(GEN8_GT_IIR(3), tmp);
  1151. } else
  1152. DRM_ERROR("The master control interrupt lied (GT3)!\n");
  1153. }
  1154. return ret;
  1155. }
  1156. #define HPD_STORM_DETECT_PERIOD 1000
  1157. #define HPD_STORM_THRESHOLD 5
  1158. static inline void intel_hpd_irq_handler(struct drm_device *dev,
  1159. u32 hotplug_trigger,
  1160. const u32 *hpd)
  1161. {
  1162. drm_i915_private_t *dev_priv = dev->dev_private;
  1163. int i;
  1164. bool storm_detected = false;
  1165. if (!hotplug_trigger)
  1166. return;
  1167. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  1168. hotplug_trigger);
  1169. spin_lock(&dev_priv->irq_lock);
  1170. for (i = 1; i < HPD_NUM_PINS; i++) {
  1171. WARN_ONCE(hpd[i] & hotplug_trigger &&
  1172. dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
  1173. "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
  1174. hotplug_trigger, i, hpd[i]);
  1175. if (!(hpd[i] & hotplug_trigger) ||
  1176. dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
  1177. continue;
  1178. dev_priv->hpd_event_bits |= (1 << i);
  1179. if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
  1180. dev_priv->hpd_stats[i].hpd_last_jiffies
  1181. + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
  1182. dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
  1183. dev_priv->hpd_stats[i].hpd_cnt = 0;
  1184. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
  1185. } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
  1186. dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
  1187. dev_priv->hpd_event_bits &= ~(1 << i);
  1188. DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
  1189. storm_detected = true;
  1190. } else {
  1191. dev_priv->hpd_stats[i].hpd_cnt++;
  1192. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
  1193. dev_priv->hpd_stats[i].hpd_cnt);
  1194. }
  1195. }
  1196. if (storm_detected)
  1197. dev_priv->display.hpd_irq_setup(dev);
  1198. spin_unlock(&dev_priv->irq_lock);
  1199. /*
  1200. * Our hotplug handler can grab modeset locks (by calling down into the
  1201. * fb helpers). Hence it must not be run on our own dev-priv->wq work
  1202. * queue for otherwise the flush_work in the pageflip code will
  1203. * deadlock.
  1204. */
  1205. schedule_work(&dev_priv->hotplug_work);
  1206. }
  1207. static void gmbus_irq_handler(struct drm_device *dev)
  1208. {
  1209. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1210. wake_up_all(&dev_priv->gmbus_wait_queue);
  1211. }
  1212. static void dp_aux_irq_handler(struct drm_device *dev)
  1213. {
  1214. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1215. wake_up_all(&dev_priv->gmbus_wait_queue);
  1216. }
  1217. #if defined(CONFIG_DEBUG_FS)
  1218. static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1219. uint32_t crc0, uint32_t crc1,
  1220. uint32_t crc2, uint32_t crc3,
  1221. uint32_t crc4)
  1222. {
  1223. struct drm_i915_private *dev_priv = dev->dev_private;
  1224. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
  1225. struct intel_pipe_crc_entry *entry;
  1226. int head, tail;
  1227. spin_lock(&pipe_crc->lock);
  1228. if (!pipe_crc->entries) {
  1229. spin_unlock(&pipe_crc->lock);
  1230. DRM_ERROR("spurious interrupt\n");
  1231. return;
  1232. }
  1233. head = pipe_crc->head;
  1234. tail = pipe_crc->tail;
  1235. if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
  1236. spin_unlock(&pipe_crc->lock);
  1237. DRM_ERROR("CRC buffer overflowing\n");
  1238. return;
  1239. }
  1240. entry = &pipe_crc->entries[head];
  1241. entry->frame = dev->driver->get_vblank_counter(dev, pipe);
  1242. entry->crc[0] = crc0;
  1243. entry->crc[1] = crc1;
  1244. entry->crc[2] = crc2;
  1245. entry->crc[3] = crc3;
  1246. entry->crc[4] = crc4;
  1247. head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
  1248. pipe_crc->head = head;
  1249. spin_unlock(&pipe_crc->lock);
  1250. wake_up_interruptible(&pipe_crc->wq);
  1251. }
  1252. #else
  1253. static inline void
  1254. display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1255. uint32_t crc0, uint32_t crc1,
  1256. uint32_t crc2, uint32_t crc3,
  1257. uint32_t crc4) {}
  1258. #endif
  1259. static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1260. {
  1261. struct drm_i915_private *dev_priv = dev->dev_private;
  1262. display_pipe_crc_irq_handler(dev, pipe,
  1263. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1264. 0, 0, 0, 0);
  1265. }
  1266. static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1267. {
  1268. struct drm_i915_private *dev_priv = dev->dev_private;
  1269. display_pipe_crc_irq_handler(dev, pipe,
  1270. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1271. I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
  1272. I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
  1273. I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
  1274. I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
  1275. }
  1276. static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1277. {
  1278. struct drm_i915_private *dev_priv = dev->dev_private;
  1279. uint32_t res1, res2;
  1280. if (INTEL_INFO(dev)->gen >= 3)
  1281. res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
  1282. else
  1283. res1 = 0;
  1284. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  1285. res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
  1286. else
  1287. res2 = 0;
  1288. display_pipe_crc_irq_handler(dev, pipe,
  1289. I915_READ(PIPE_CRC_RES_RED(pipe)),
  1290. I915_READ(PIPE_CRC_RES_GREEN(pipe)),
  1291. I915_READ(PIPE_CRC_RES_BLUE(pipe)),
  1292. res1, res2);
  1293. }
  1294. /* The RPS events need forcewake, so we add them to a work queue and mask their
  1295. * IMR bits until the work is done. Other interrupts can be processed without
  1296. * the work queue. */
  1297. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
  1298. {
  1299. if (pm_iir & dev_priv->pm_rps_events) {
  1300. spin_lock(&dev_priv->irq_lock);
  1301. dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
  1302. snb_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
  1303. spin_unlock(&dev_priv->irq_lock);
  1304. queue_work(dev_priv->wq, &dev_priv->rps.work);
  1305. }
  1306. if (HAS_VEBOX(dev_priv->dev)) {
  1307. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  1308. notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
  1309. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
  1310. i915_handle_error(dev_priv->dev, false,
  1311. "VEBOX CS error interrupt 0x%08x",
  1312. pm_iir);
  1313. }
  1314. }
  1315. }
  1316. static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
  1317. {
  1318. struct drm_i915_private *dev_priv = dev->dev_private;
  1319. u32 pipe_stats[I915_MAX_PIPES] = { };
  1320. int pipe;
  1321. spin_lock(&dev_priv->irq_lock);
  1322. for_each_pipe(pipe) {
  1323. int reg;
  1324. u32 mask, iir_bit = 0;
  1325. /*
  1326. * PIPESTAT bits get signalled even when the interrupt is
  1327. * disabled with the mask bits, and some of the status bits do
  1328. * not generate interrupts at all (like the underrun bit). Hence
  1329. * we need to be careful that we only handle what we want to
  1330. * handle.
  1331. */
  1332. mask = 0;
  1333. if (__cpu_fifo_underrun_reporting_enabled(dev, pipe))
  1334. mask |= PIPE_FIFO_UNDERRUN_STATUS;
  1335. switch (pipe) {
  1336. case PIPE_A:
  1337. iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
  1338. break;
  1339. case PIPE_B:
  1340. iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  1341. break;
  1342. }
  1343. if (iir & iir_bit)
  1344. mask |= dev_priv->pipestat_irq_mask[pipe];
  1345. if (!mask)
  1346. continue;
  1347. reg = PIPESTAT(pipe);
  1348. mask |= PIPESTAT_INT_ENABLE_MASK;
  1349. pipe_stats[pipe] = I915_READ(reg) & mask;
  1350. /*
  1351. * Clear the PIPE*STAT regs before the IIR
  1352. */
  1353. if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
  1354. PIPESTAT_INT_STATUS_MASK))
  1355. I915_WRITE(reg, pipe_stats[pipe]);
  1356. }
  1357. spin_unlock(&dev_priv->irq_lock);
  1358. for_each_pipe(pipe) {
  1359. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
  1360. drm_handle_vblank(dev, pipe);
  1361. if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
  1362. intel_prepare_page_flip(dev, pipe);
  1363. intel_finish_page_flip(dev, pipe);
  1364. }
  1365. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1366. i9xx_pipe_crc_irq_handler(dev, pipe);
  1367. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
  1368. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  1369. DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
  1370. }
  1371. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  1372. gmbus_irq_handler(dev);
  1373. }
  1374. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  1375. {
  1376. struct drm_device *dev = (struct drm_device *) arg;
  1377. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1378. u32 iir, gt_iir, pm_iir;
  1379. irqreturn_t ret = IRQ_NONE;
  1380. while (true) {
  1381. iir = I915_READ(VLV_IIR);
  1382. gt_iir = I915_READ(GTIIR);
  1383. pm_iir = I915_READ(GEN6_PMIIR);
  1384. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  1385. goto out;
  1386. ret = IRQ_HANDLED;
  1387. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1388. valleyview_pipestat_irq_handler(dev, iir);
  1389. /* Consume port. Then clear IIR or we'll miss events */
  1390. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  1391. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1392. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  1393. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  1394. if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
  1395. dp_aux_irq_handler(dev);
  1396. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1397. I915_READ(PORT_HOTPLUG_STAT);
  1398. }
  1399. if (pm_iir)
  1400. gen6_rps_irq_handler(dev_priv, pm_iir);
  1401. I915_WRITE(GTIIR, gt_iir);
  1402. I915_WRITE(GEN6_PMIIR, pm_iir);
  1403. I915_WRITE(VLV_IIR, iir);
  1404. }
  1405. out:
  1406. return ret;
  1407. }
  1408. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  1409. {
  1410. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1411. int pipe;
  1412. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  1413. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
  1414. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  1415. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  1416. SDE_AUDIO_POWER_SHIFT);
  1417. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  1418. port_name(port));
  1419. }
  1420. if (pch_iir & SDE_AUX_MASK)
  1421. dp_aux_irq_handler(dev);
  1422. if (pch_iir & SDE_GMBUS)
  1423. gmbus_irq_handler(dev);
  1424. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  1425. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  1426. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  1427. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  1428. if (pch_iir & SDE_POISON)
  1429. DRM_ERROR("PCH poison interrupt\n");
  1430. if (pch_iir & SDE_FDI_MASK)
  1431. for_each_pipe(pipe)
  1432. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1433. pipe_name(pipe),
  1434. I915_READ(FDI_RX_IIR(pipe)));
  1435. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  1436. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  1437. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  1438. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  1439. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  1440. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  1441. false))
  1442. DRM_ERROR("PCH transcoder A FIFO underrun\n");
  1443. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  1444. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  1445. false))
  1446. DRM_ERROR("PCH transcoder B FIFO underrun\n");
  1447. }
  1448. static void ivb_err_int_handler(struct drm_device *dev)
  1449. {
  1450. struct drm_i915_private *dev_priv = dev->dev_private;
  1451. u32 err_int = I915_READ(GEN7_ERR_INT);
  1452. enum pipe pipe;
  1453. if (err_int & ERR_INT_POISON)
  1454. DRM_ERROR("Poison interrupt\n");
  1455. for_each_pipe(pipe) {
  1456. if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
  1457. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
  1458. false))
  1459. DRM_ERROR("Pipe %c FIFO underrun\n",
  1460. pipe_name(pipe));
  1461. }
  1462. if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
  1463. if (IS_IVYBRIDGE(dev))
  1464. ivb_pipe_crc_irq_handler(dev, pipe);
  1465. else
  1466. hsw_pipe_crc_irq_handler(dev, pipe);
  1467. }
  1468. }
  1469. I915_WRITE(GEN7_ERR_INT, err_int);
  1470. }
  1471. static void cpt_serr_int_handler(struct drm_device *dev)
  1472. {
  1473. struct drm_i915_private *dev_priv = dev->dev_private;
  1474. u32 serr_int = I915_READ(SERR_INT);
  1475. if (serr_int & SERR_INT_POISON)
  1476. DRM_ERROR("PCH poison interrupt\n");
  1477. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  1478. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  1479. false))
  1480. DRM_ERROR("PCH transcoder A FIFO underrun\n");
  1481. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  1482. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  1483. false))
  1484. DRM_ERROR("PCH transcoder B FIFO underrun\n");
  1485. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  1486. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
  1487. false))
  1488. DRM_ERROR("PCH transcoder C FIFO underrun\n");
  1489. I915_WRITE(SERR_INT, serr_int);
  1490. }
  1491. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  1492. {
  1493. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1494. int pipe;
  1495. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  1496. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
  1497. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  1498. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  1499. SDE_AUDIO_POWER_SHIFT_CPT);
  1500. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  1501. port_name(port));
  1502. }
  1503. if (pch_iir & SDE_AUX_MASK_CPT)
  1504. dp_aux_irq_handler(dev);
  1505. if (pch_iir & SDE_GMBUS_CPT)
  1506. gmbus_irq_handler(dev);
  1507. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  1508. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  1509. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  1510. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  1511. if (pch_iir & SDE_FDI_MASK_CPT)
  1512. for_each_pipe(pipe)
  1513. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1514. pipe_name(pipe),
  1515. I915_READ(FDI_RX_IIR(pipe)));
  1516. if (pch_iir & SDE_ERROR_CPT)
  1517. cpt_serr_int_handler(dev);
  1518. }
  1519. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1520. {
  1521. struct drm_i915_private *dev_priv = dev->dev_private;
  1522. enum pipe pipe;
  1523. if (de_iir & DE_AUX_CHANNEL_A)
  1524. dp_aux_irq_handler(dev);
  1525. if (de_iir & DE_GSE)
  1526. intel_opregion_asle_intr(dev);
  1527. if (de_iir & DE_POISON)
  1528. DRM_ERROR("Poison interrupt\n");
  1529. for_each_pipe(pipe) {
  1530. if (de_iir & DE_PIPE_VBLANK(pipe))
  1531. drm_handle_vblank(dev, pipe);
  1532. if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
  1533. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  1534. DRM_ERROR("Pipe %c FIFO underrun\n",
  1535. pipe_name(pipe));
  1536. if (de_iir & DE_PIPE_CRC_DONE(pipe))
  1537. i9xx_pipe_crc_irq_handler(dev, pipe);
  1538. /* plane/pipes map 1:1 on ilk+ */
  1539. if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
  1540. intel_prepare_page_flip(dev, pipe);
  1541. intel_finish_page_flip_plane(dev, pipe);
  1542. }
  1543. }
  1544. /* check event from PCH */
  1545. if (de_iir & DE_PCH_EVENT) {
  1546. u32 pch_iir = I915_READ(SDEIIR);
  1547. if (HAS_PCH_CPT(dev))
  1548. cpt_irq_handler(dev, pch_iir);
  1549. else
  1550. ibx_irq_handler(dev, pch_iir);
  1551. /* should clear PCH hotplug event before clear CPU irq */
  1552. I915_WRITE(SDEIIR, pch_iir);
  1553. }
  1554. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1555. ironlake_rps_change_irq_handler(dev);
  1556. }
  1557. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1558. {
  1559. struct drm_i915_private *dev_priv = dev->dev_private;
  1560. enum pipe pipe;
  1561. if (de_iir & DE_ERR_INT_IVB)
  1562. ivb_err_int_handler(dev);
  1563. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1564. dp_aux_irq_handler(dev);
  1565. if (de_iir & DE_GSE_IVB)
  1566. intel_opregion_asle_intr(dev);
  1567. for_each_pipe(pipe) {
  1568. if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
  1569. drm_handle_vblank(dev, pipe);
  1570. /* plane/pipes map 1:1 on ilk+ */
  1571. if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
  1572. intel_prepare_page_flip(dev, pipe);
  1573. intel_finish_page_flip_plane(dev, pipe);
  1574. }
  1575. }
  1576. /* check event from PCH */
  1577. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1578. u32 pch_iir = I915_READ(SDEIIR);
  1579. cpt_irq_handler(dev, pch_iir);
  1580. /* clear PCH hotplug event before clear CPU irq */
  1581. I915_WRITE(SDEIIR, pch_iir);
  1582. }
  1583. }
  1584. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1585. {
  1586. struct drm_device *dev = (struct drm_device *) arg;
  1587. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1588. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1589. irqreturn_t ret = IRQ_NONE;
  1590. /* We get interrupts on unclaimed registers, so check for this before we
  1591. * do any I915_{READ,WRITE}. */
  1592. intel_uncore_check_errors(dev);
  1593. /* disable master interrupt before clearing iir */
  1594. de_ier = I915_READ(DEIER);
  1595. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1596. POSTING_READ(DEIER);
  1597. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1598. * interrupts will will be stored on its back queue, and then we'll be
  1599. * able to process them after we restore SDEIER (as soon as we restore
  1600. * it, we'll get an interrupt if SDEIIR still has something to process
  1601. * due to its back queue). */
  1602. if (!HAS_PCH_NOP(dev)) {
  1603. sde_ier = I915_READ(SDEIER);
  1604. I915_WRITE(SDEIER, 0);
  1605. POSTING_READ(SDEIER);
  1606. }
  1607. gt_iir = I915_READ(GTIIR);
  1608. if (gt_iir) {
  1609. if (INTEL_INFO(dev)->gen >= 6)
  1610. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1611. else
  1612. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1613. I915_WRITE(GTIIR, gt_iir);
  1614. ret = IRQ_HANDLED;
  1615. }
  1616. de_iir = I915_READ(DEIIR);
  1617. if (de_iir) {
  1618. if (INTEL_INFO(dev)->gen >= 7)
  1619. ivb_display_irq_handler(dev, de_iir);
  1620. else
  1621. ilk_display_irq_handler(dev, de_iir);
  1622. I915_WRITE(DEIIR, de_iir);
  1623. ret = IRQ_HANDLED;
  1624. }
  1625. if (INTEL_INFO(dev)->gen >= 6) {
  1626. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1627. if (pm_iir) {
  1628. gen6_rps_irq_handler(dev_priv, pm_iir);
  1629. I915_WRITE(GEN6_PMIIR, pm_iir);
  1630. ret = IRQ_HANDLED;
  1631. }
  1632. }
  1633. I915_WRITE(DEIER, de_ier);
  1634. POSTING_READ(DEIER);
  1635. if (!HAS_PCH_NOP(dev)) {
  1636. I915_WRITE(SDEIER, sde_ier);
  1637. POSTING_READ(SDEIER);
  1638. }
  1639. return ret;
  1640. }
  1641. static irqreturn_t gen8_irq_handler(int irq, void *arg)
  1642. {
  1643. struct drm_device *dev = arg;
  1644. struct drm_i915_private *dev_priv = dev->dev_private;
  1645. u32 master_ctl;
  1646. irqreturn_t ret = IRQ_NONE;
  1647. uint32_t tmp = 0;
  1648. enum pipe pipe;
  1649. master_ctl = I915_READ(GEN8_MASTER_IRQ);
  1650. master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
  1651. if (!master_ctl)
  1652. return IRQ_NONE;
  1653. I915_WRITE(GEN8_MASTER_IRQ, 0);
  1654. POSTING_READ(GEN8_MASTER_IRQ);
  1655. ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
  1656. if (master_ctl & GEN8_DE_MISC_IRQ) {
  1657. tmp = I915_READ(GEN8_DE_MISC_IIR);
  1658. if (tmp & GEN8_DE_MISC_GSE)
  1659. intel_opregion_asle_intr(dev);
  1660. else if (tmp)
  1661. DRM_ERROR("Unexpected DE Misc interrupt\n");
  1662. else
  1663. DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
  1664. if (tmp) {
  1665. I915_WRITE(GEN8_DE_MISC_IIR, tmp);
  1666. ret = IRQ_HANDLED;
  1667. }
  1668. }
  1669. if (master_ctl & GEN8_DE_PORT_IRQ) {
  1670. tmp = I915_READ(GEN8_DE_PORT_IIR);
  1671. if (tmp & GEN8_AUX_CHANNEL_A)
  1672. dp_aux_irq_handler(dev);
  1673. else if (tmp)
  1674. DRM_ERROR("Unexpected DE Port interrupt\n");
  1675. else
  1676. DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
  1677. if (tmp) {
  1678. I915_WRITE(GEN8_DE_PORT_IIR, tmp);
  1679. ret = IRQ_HANDLED;
  1680. }
  1681. }
  1682. for_each_pipe(pipe) {
  1683. uint32_t pipe_iir;
  1684. if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
  1685. continue;
  1686. pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
  1687. if (pipe_iir & GEN8_PIPE_VBLANK)
  1688. drm_handle_vblank(dev, pipe);
  1689. if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
  1690. intel_prepare_page_flip(dev, pipe);
  1691. intel_finish_page_flip_plane(dev, pipe);
  1692. }
  1693. if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
  1694. hsw_pipe_crc_irq_handler(dev, pipe);
  1695. if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
  1696. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
  1697. false))
  1698. DRM_ERROR("Pipe %c FIFO underrun\n",
  1699. pipe_name(pipe));
  1700. }
  1701. if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
  1702. DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
  1703. pipe_name(pipe),
  1704. pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
  1705. }
  1706. if (pipe_iir) {
  1707. ret = IRQ_HANDLED;
  1708. I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
  1709. } else
  1710. DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
  1711. }
  1712. if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
  1713. /*
  1714. * FIXME(BDW): Assume for now that the new interrupt handling
  1715. * scheme also closed the SDE interrupt handling race we've seen
  1716. * on older pch-split platforms. But this needs testing.
  1717. */
  1718. u32 pch_iir = I915_READ(SDEIIR);
  1719. cpt_irq_handler(dev, pch_iir);
  1720. if (pch_iir) {
  1721. I915_WRITE(SDEIIR, pch_iir);
  1722. ret = IRQ_HANDLED;
  1723. }
  1724. }
  1725. I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
  1726. POSTING_READ(GEN8_MASTER_IRQ);
  1727. return ret;
  1728. }
  1729. static void i915_error_wake_up(struct drm_i915_private *dev_priv,
  1730. bool reset_completed)
  1731. {
  1732. struct intel_ring_buffer *ring;
  1733. int i;
  1734. /*
  1735. * Notify all waiters for GPU completion events that reset state has
  1736. * been changed, and that they need to restart their wait after
  1737. * checking for potential errors (and bail out to drop locks if there is
  1738. * a gpu reset pending so that i915_error_work_func can acquire them).
  1739. */
  1740. /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
  1741. for_each_ring(ring, dev_priv, i)
  1742. wake_up_all(&ring->irq_queue);
  1743. /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
  1744. wake_up_all(&dev_priv->pending_flip_queue);
  1745. /*
  1746. * Signal tasks blocked in i915_gem_wait_for_error that the pending
  1747. * reset state is cleared.
  1748. */
  1749. if (reset_completed)
  1750. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1751. }
  1752. /**
  1753. * i915_error_work_func - do process context error handling work
  1754. * @work: work struct
  1755. *
  1756. * Fire an error uevent so userspace can see that a hang or error
  1757. * was detected.
  1758. */
  1759. static void i915_error_work_func(struct work_struct *work)
  1760. {
  1761. struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
  1762. work);
  1763. drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
  1764. gpu_error);
  1765. struct drm_device *dev = dev_priv->dev;
  1766. char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
  1767. char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
  1768. char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
  1769. int ret;
  1770. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
  1771. /*
  1772. * Note that there's only one work item which does gpu resets, so we
  1773. * need not worry about concurrent gpu resets potentially incrementing
  1774. * error->reset_counter twice. We only need to take care of another
  1775. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1776. * quick check for that is good enough: schedule_work ensures the
  1777. * correct ordering between hang detection and this work item, and since
  1778. * the reset in-progress bit is only ever set by code outside of this
  1779. * work we don't need to worry about any other races.
  1780. */
  1781. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1782. DRM_DEBUG_DRIVER("resetting chip\n");
  1783. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
  1784. reset_event);
  1785. /*
  1786. * All state reset _must_ be completed before we update the
  1787. * reset counter, for otherwise waiters might miss the reset
  1788. * pending state and not properly drop locks, resulting in
  1789. * deadlocks with the reset work.
  1790. */
  1791. ret = i915_reset(dev);
  1792. intel_display_handle_reset(dev);
  1793. if (ret == 0) {
  1794. /*
  1795. * After all the gem state is reset, increment the reset
  1796. * counter and wake up everyone waiting for the reset to
  1797. * complete.
  1798. *
  1799. * Since unlock operations are a one-sided barrier only,
  1800. * we need to insert a barrier here to order any seqno
  1801. * updates before
  1802. * the counter increment.
  1803. */
  1804. smp_mb__before_atomic_inc();
  1805. atomic_inc(&dev_priv->gpu_error.reset_counter);
  1806. kobject_uevent_env(&dev->primary->kdev->kobj,
  1807. KOBJ_CHANGE, reset_done_event);
  1808. } else {
  1809. atomic_set_mask(I915_WEDGED, &error->reset_counter);
  1810. }
  1811. /*
  1812. * Note: The wake_up also serves as a memory barrier so that
  1813. * waiters see the update value of the reset counter atomic_t.
  1814. */
  1815. i915_error_wake_up(dev_priv, true);
  1816. }
  1817. }
  1818. static void i915_report_and_clear_eir(struct drm_device *dev)
  1819. {
  1820. struct drm_i915_private *dev_priv = dev->dev_private;
  1821. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1822. u32 eir = I915_READ(EIR);
  1823. int pipe, i;
  1824. if (!eir)
  1825. return;
  1826. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1827. i915_get_extra_instdone(dev, instdone);
  1828. if (IS_G4X(dev)) {
  1829. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1830. u32 ipeir = I915_READ(IPEIR_I965);
  1831. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1832. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1833. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1834. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1835. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1836. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1837. I915_WRITE(IPEIR_I965, ipeir);
  1838. POSTING_READ(IPEIR_I965);
  1839. }
  1840. if (eir & GM45_ERROR_PAGE_TABLE) {
  1841. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1842. pr_err("page table error\n");
  1843. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1844. I915_WRITE(PGTBL_ER, pgtbl_err);
  1845. POSTING_READ(PGTBL_ER);
  1846. }
  1847. }
  1848. if (!IS_GEN2(dev)) {
  1849. if (eir & I915_ERROR_PAGE_TABLE) {
  1850. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1851. pr_err("page table error\n");
  1852. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1853. I915_WRITE(PGTBL_ER, pgtbl_err);
  1854. POSTING_READ(PGTBL_ER);
  1855. }
  1856. }
  1857. if (eir & I915_ERROR_MEMORY_REFRESH) {
  1858. pr_err("memory refresh error:\n");
  1859. for_each_pipe(pipe)
  1860. pr_err("pipe %c stat: 0x%08x\n",
  1861. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  1862. /* pipestat has already been acked */
  1863. }
  1864. if (eir & I915_ERROR_INSTRUCTION) {
  1865. pr_err("instruction error\n");
  1866. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  1867. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1868. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1869. if (INTEL_INFO(dev)->gen < 4) {
  1870. u32 ipeir = I915_READ(IPEIR);
  1871. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  1872. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  1873. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  1874. I915_WRITE(IPEIR, ipeir);
  1875. POSTING_READ(IPEIR);
  1876. } else {
  1877. u32 ipeir = I915_READ(IPEIR_I965);
  1878. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1879. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1880. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1881. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1882. I915_WRITE(IPEIR_I965, ipeir);
  1883. POSTING_READ(IPEIR_I965);
  1884. }
  1885. }
  1886. I915_WRITE(EIR, eir);
  1887. POSTING_READ(EIR);
  1888. eir = I915_READ(EIR);
  1889. if (eir) {
  1890. /*
  1891. * some errors might have become stuck,
  1892. * mask them.
  1893. */
  1894. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1895. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1896. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1897. }
  1898. }
  1899. /**
  1900. * i915_handle_error - handle an error interrupt
  1901. * @dev: drm device
  1902. *
  1903. * Do some basic checking of regsiter state at error interrupt time and
  1904. * dump it to the syslog. Also call i915_capture_error_state() to make
  1905. * sure we get a record and make it available in debugfs. Fire a uevent
  1906. * so userspace knows something bad happened (should trigger collection
  1907. * of a ring dump etc.).
  1908. */
  1909. void i915_handle_error(struct drm_device *dev, bool wedged,
  1910. const char *fmt, ...)
  1911. {
  1912. struct drm_i915_private *dev_priv = dev->dev_private;
  1913. va_list args;
  1914. char error_msg[80];
  1915. va_start(args, fmt);
  1916. vscnprintf(error_msg, sizeof(error_msg), fmt, args);
  1917. va_end(args);
  1918. i915_capture_error_state(dev, wedged, error_msg);
  1919. i915_report_and_clear_eir(dev);
  1920. if (wedged) {
  1921. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  1922. &dev_priv->gpu_error.reset_counter);
  1923. /*
  1924. * Wakeup waiting processes so that the reset work function
  1925. * i915_error_work_func doesn't deadlock trying to grab various
  1926. * locks. By bumping the reset counter first, the woken
  1927. * processes will see a reset in progress and back off,
  1928. * releasing their locks and then wait for the reset completion.
  1929. * We must do this for _all_ gpu waiters that might hold locks
  1930. * that the reset work needs to acquire.
  1931. *
  1932. * Note: The wake_up serves as the required memory barrier to
  1933. * ensure that the waiters see the updated value of the reset
  1934. * counter atomic_t.
  1935. */
  1936. i915_error_wake_up(dev_priv, false);
  1937. }
  1938. /*
  1939. * Our reset work can grab modeset locks (since it needs to reset the
  1940. * state of outstanding pagelips). Hence it must not be run on our own
  1941. * dev-priv->wq work queue for otherwise the flush_work in the pageflip
  1942. * code will deadlock.
  1943. */
  1944. schedule_work(&dev_priv->gpu_error.work);
  1945. }
  1946. static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1947. {
  1948. drm_i915_private_t *dev_priv = dev->dev_private;
  1949. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1950. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1951. struct drm_i915_gem_object *obj;
  1952. struct intel_unpin_work *work;
  1953. unsigned long flags;
  1954. bool stall_detected;
  1955. /* Ignore early vblank irqs */
  1956. if (intel_crtc == NULL)
  1957. return;
  1958. spin_lock_irqsave(&dev->event_lock, flags);
  1959. work = intel_crtc->unpin_work;
  1960. if (work == NULL ||
  1961. atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
  1962. !work->enable_stall_check) {
  1963. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1964. spin_unlock_irqrestore(&dev->event_lock, flags);
  1965. return;
  1966. }
  1967. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1968. obj = work->pending_flip_obj;
  1969. if (INTEL_INFO(dev)->gen >= 4) {
  1970. int dspsurf = DSPSURF(intel_crtc->plane);
  1971. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  1972. i915_gem_obj_ggtt_offset(obj);
  1973. } else {
  1974. int dspaddr = DSPADDR(intel_crtc->plane);
  1975. stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
  1976. crtc->y * crtc->fb->pitches[0] +
  1977. crtc->x * crtc->fb->bits_per_pixel/8);
  1978. }
  1979. spin_unlock_irqrestore(&dev->event_lock, flags);
  1980. if (stall_detected) {
  1981. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1982. intel_prepare_page_flip(dev, intel_crtc->plane);
  1983. }
  1984. }
  1985. /* Called from drm generic code, passed 'crtc' which
  1986. * we use as a pipe index
  1987. */
  1988. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1989. {
  1990. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1991. unsigned long irqflags;
  1992. if (!i915_pipe_enabled(dev, pipe))
  1993. return -EINVAL;
  1994. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1995. if (INTEL_INFO(dev)->gen >= 4)
  1996. i915_enable_pipestat(dev_priv, pipe,
  1997. PIPE_START_VBLANK_INTERRUPT_STATUS);
  1998. else
  1999. i915_enable_pipestat(dev_priv, pipe,
  2000. PIPE_VBLANK_INTERRUPT_STATUS);
  2001. /* maintain vblank delivery even in deep C-states */
  2002. if (INTEL_INFO(dev)->gen == 3)
  2003. I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
  2004. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2005. return 0;
  2006. }
  2007. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  2008. {
  2009. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2010. unsigned long irqflags;
  2011. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2012. DE_PIPE_VBLANK(pipe);
  2013. if (!i915_pipe_enabled(dev, pipe))
  2014. return -EINVAL;
  2015. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2016. ironlake_enable_display_irq(dev_priv, bit);
  2017. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2018. return 0;
  2019. }
  2020. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  2021. {
  2022. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2023. unsigned long irqflags;
  2024. if (!i915_pipe_enabled(dev, pipe))
  2025. return -EINVAL;
  2026. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2027. i915_enable_pipestat(dev_priv, pipe,
  2028. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2029. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2030. return 0;
  2031. }
  2032. static int gen8_enable_vblank(struct drm_device *dev, int pipe)
  2033. {
  2034. struct drm_i915_private *dev_priv = dev->dev_private;
  2035. unsigned long irqflags;
  2036. if (!i915_pipe_enabled(dev, pipe))
  2037. return -EINVAL;
  2038. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2039. dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
  2040. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2041. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2042. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2043. return 0;
  2044. }
  2045. /* Called from drm generic code, passed 'crtc' which
  2046. * we use as a pipe index
  2047. */
  2048. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  2049. {
  2050. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2051. unsigned long irqflags;
  2052. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2053. if (INTEL_INFO(dev)->gen == 3)
  2054. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
  2055. i915_disable_pipestat(dev_priv, pipe,
  2056. PIPE_VBLANK_INTERRUPT_STATUS |
  2057. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2058. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2059. }
  2060. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  2061. {
  2062. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2063. unsigned long irqflags;
  2064. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2065. DE_PIPE_VBLANK(pipe);
  2066. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2067. ironlake_disable_display_irq(dev_priv, bit);
  2068. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2069. }
  2070. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  2071. {
  2072. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2073. unsigned long irqflags;
  2074. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2075. i915_disable_pipestat(dev_priv, pipe,
  2076. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2077. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2078. }
  2079. static void gen8_disable_vblank(struct drm_device *dev, int pipe)
  2080. {
  2081. struct drm_i915_private *dev_priv = dev->dev_private;
  2082. unsigned long irqflags;
  2083. if (!i915_pipe_enabled(dev, pipe))
  2084. return;
  2085. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2086. dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
  2087. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2088. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2089. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2090. }
  2091. static u32
  2092. ring_last_seqno(struct intel_ring_buffer *ring)
  2093. {
  2094. return list_entry(ring->request_list.prev,
  2095. struct drm_i915_gem_request, list)->seqno;
  2096. }
  2097. static bool
  2098. ring_idle(struct intel_ring_buffer *ring, u32 seqno)
  2099. {
  2100. return (list_empty(&ring->request_list) ||
  2101. i915_seqno_passed(seqno, ring_last_seqno(ring)));
  2102. }
  2103. static struct intel_ring_buffer *
  2104. semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
  2105. {
  2106. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2107. u32 cmd, ipehr, head;
  2108. int i;
  2109. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  2110. if ((ipehr & ~(0x3 << 16)) !=
  2111. (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
  2112. return NULL;
  2113. /*
  2114. * HEAD is likely pointing to the dword after the actual command,
  2115. * so scan backwards until we find the MBOX. But limit it to just 3
  2116. * dwords. Note that we don't care about ACTHD here since that might
  2117. * point at at batch, and semaphores are always emitted into the
  2118. * ringbuffer itself.
  2119. */
  2120. head = I915_READ_HEAD(ring) & HEAD_ADDR;
  2121. for (i = 4; i; --i) {
  2122. /*
  2123. * Be paranoid and presume the hw has gone off into the wild -
  2124. * our ring is smaller than what the hardware (and hence
  2125. * HEAD_ADDR) allows. Also handles wrap-around.
  2126. */
  2127. head &= ring->size - 1;
  2128. /* This here seems to blow up */
  2129. cmd = ioread32(ring->virtual_start + head);
  2130. if (cmd == ipehr)
  2131. break;
  2132. head -= 4;
  2133. }
  2134. if (!i)
  2135. return NULL;
  2136. *seqno = ioread32(ring->virtual_start + head + 4) + 1;
  2137. return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
  2138. }
  2139. static int semaphore_passed(struct intel_ring_buffer *ring)
  2140. {
  2141. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2142. struct intel_ring_buffer *signaller;
  2143. u32 seqno, ctl;
  2144. ring->hangcheck.deadlock = true;
  2145. signaller = semaphore_waits_for(ring, &seqno);
  2146. if (signaller == NULL || signaller->hangcheck.deadlock)
  2147. return -1;
  2148. /* cursory check for an unkickable deadlock */
  2149. ctl = I915_READ_CTL(signaller);
  2150. if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
  2151. return -1;
  2152. return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
  2153. }
  2154. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  2155. {
  2156. struct intel_ring_buffer *ring;
  2157. int i;
  2158. for_each_ring(ring, dev_priv, i)
  2159. ring->hangcheck.deadlock = false;
  2160. }
  2161. static enum intel_ring_hangcheck_action
  2162. ring_stuck(struct intel_ring_buffer *ring, u64 acthd)
  2163. {
  2164. struct drm_device *dev = ring->dev;
  2165. struct drm_i915_private *dev_priv = dev->dev_private;
  2166. u32 tmp;
  2167. if (ring->hangcheck.acthd != acthd)
  2168. return HANGCHECK_ACTIVE;
  2169. if (IS_GEN2(dev))
  2170. return HANGCHECK_HUNG;
  2171. /* Is the chip hanging on a WAIT_FOR_EVENT?
  2172. * If so we can simply poke the RB_WAIT bit
  2173. * and break the hang. This should work on
  2174. * all but the second generation chipsets.
  2175. */
  2176. tmp = I915_READ_CTL(ring);
  2177. if (tmp & RING_WAIT) {
  2178. i915_handle_error(dev, false,
  2179. "Kicking stuck wait on %s",
  2180. ring->name);
  2181. I915_WRITE_CTL(ring, tmp);
  2182. return HANGCHECK_KICK;
  2183. }
  2184. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  2185. switch (semaphore_passed(ring)) {
  2186. default:
  2187. return HANGCHECK_HUNG;
  2188. case 1:
  2189. i915_handle_error(dev, false,
  2190. "Kicking stuck semaphore on %s",
  2191. ring->name);
  2192. I915_WRITE_CTL(ring, tmp);
  2193. return HANGCHECK_KICK;
  2194. case 0:
  2195. return HANGCHECK_WAIT;
  2196. }
  2197. }
  2198. return HANGCHECK_HUNG;
  2199. }
  2200. /**
  2201. * This is called when the chip hasn't reported back with completed
  2202. * batchbuffers in a long time. We keep track per ring seqno progress and
  2203. * if there are no progress, hangcheck score for that ring is increased.
  2204. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  2205. * we kick the ring. If we see no progress on three subsequent calls
  2206. * we assume chip is wedged and try to fix it by resetting the chip.
  2207. */
  2208. static void i915_hangcheck_elapsed(unsigned long data)
  2209. {
  2210. struct drm_device *dev = (struct drm_device *)data;
  2211. drm_i915_private_t *dev_priv = dev->dev_private;
  2212. struct intel_ring_buffer *ring;
  2213. int i;
  2214. int busy_count = 0, rings_hung = 0;
  2215. bool stuck[I915_NUM_RINGS] = { 0 };
  2216. #define BUSY 1
  2217. #define KICK 5
  2218. #define HUNG 20
  2219. if (!i915.enable_hangcheck)
  2220. return;
  2221. for_each_ring(ring, dev_priv, i) {
  2222. u64 acthd;
  2223. u32 seqno;
  2224. bool busy = true;
  2225. semaphore_clear_deadlocks(dev_priv);
  2226. seqno = ring->get_seqno(ring, false);
  2227. acthd = intel_ring_get_active_head(ring);
  2228. if (ring->hangcheck.seqno == seqno) {
  2229. if (ring_idle(ring, seqno)) {
  2230. ring->hangcheck.action = HANGCHECK_IDLE;
  2231. if (waitqueue_active(&ring->irq_queue)) {
  2232. /* Issue a wake-up to catch stuck h/w. */
  2233. if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
  2234. if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
  2235. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  2236. ring->name);
  2237. else
  2238. DRM_INFO("Fake missed irq on %s\n",
  2239. ring->name);
  2240. wake_up_all(&ring->irq_queue);
  2241. }
  2242. /* Safeguard against driver failure */
  2243. ring->hangcheck.score += BUSY;
  2244. } else
  2245. busy = false;
  2246. } else {
  2247. /* We always increment the hangcheck score
  2248. * if the ring is busy and still processing
  2249. * the same request, so that no single request
  2250. * can run indefinitely (such as a chain of
  2251. * batches). The only time we do not increment
  2252. * the hangcheck score on this ring, if this
  2253. * ring is in a legitimate wait for another
  2254. * ring. In that case the waiting ring is a
  2255. * victim and we want to be sure we catch the
  2256. * right culprit. Then every time we do kick
  2257. * the ring, add a small increment to the
  2258. * score so that we can catch a batch that is
  2259. * being repeatedly kicked and so responsible
  2260. * for stalling the machine.
  2261. */
  2262. ring->hangcheck.action = ring_stuck(ring,
  2263. acthd);
  2264. switch (ring->hangcheck.action) {
  2265. case HANGCHECK_IDLE:
  2266. case HANGCHECK_WAIT:
  2267. break;
  2268. case HANGCHECK_ACTIVE:
  2269. ring->hangcheck.score += BUSY;
  2270. break;
  2271. case HANGCHECK_KICK:
  2272. ring->hangcheck.score += KICK;
  2273. break;
  2274. case HANGCHECK_HUNG:
  2275. ring->hangcheck.score += HUNG;
  2276. stuck[i] = true;
  2277. break;
  2278. }
  2279. }
  2280. } else {
  2281. ring->hangcheck.action = HANGCHECK_ACTIVE;
  2282. /* Gradually reduce the count so that we catch DoS
  2283. * attempts across multiple batches.
  2284. */
  2285. if (ring->hangcheck.score > 0)
  2286. ring->hangcheck.score--;
  2287. }
  2288. ring->hangcheck.seqno = seqno;
  2289. ring->hangcheck.acthd = acthd;
  2290. busy_count += busy;
  2291. }
  2292. for_each_ring(ring, dev_priv, i) {
  2293. if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
  2294. DRM_INFO("%s on %s\n",
  2295. stuck[i] ? "stuck" : "no progress",
  2296. ring->name);
  2297. rings_hung++;
  2298. }
  2299. }
  2300. if (rings_hung)
  2301. return i915_handle_error(dev, true, "Ring hung");
  2302. if (busy_count)
  2303. /* Reset timer case chip hangs without another request
  2304. * being added */
  2305. i915_queue_hangcheck(dev);
  2306. }
  2307. void i915_queue_hangcheck(struct drm_device *dev)
  2308. {
  2309. struct drm_i915_private *dev_priv = dev->dev_private;
  2310. if (!i915.enable_hangcheck)
  2311. return;
  2312. mod_timer(&dev_priv->gpu_error.hangcheck_timer,
  2313. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  2314. }
  2315. static void ibx_irq_preinstall(struct drm_device *dev)
  2316. {
  2317. struct drm_i915_private *dev_priv = dev->dev_private;
  2318. if (HAS_PCH_NOP(dev))
  2319. return;
  2320. /* south display irq */
  2321. I915_WRITE(SDEIMR, 0xffffffff);
  2322. /*
  2323. * SDEIER is also touched by the interrupt handler to work around missed
  2324. * PCH interrupts. Hence we can't update it after the interrupt handler
  2325. * is enabled - instead we unconditionally enable all PCH interrupt
  2326. * sources here, but then only unmask them as needed with SDEIMR.
  2327. */
  2328. I915_WRITE(SDEIER, 0xffffffff);
  2329. POSTING_READ(SDEIER);
  2330. }
  2331. static void gen5_gt_irq_preinstall(struct drm_device *dev)
  2332. {
  2333. struct drm_i915_private *dev_priv = dev->dev_private;
  2334. /* and GT */
  2335. I915_WRITE(GTIMR, 0xffffffff);
  2336. I915_WRITE(GTIER, 0x0);
  2337. POSTING_READ(GTIER);
  2338. if (INTEL_INFO(dev)->gen >= 6) {
  2339. /* and PM */
  2340. I915_WRITE(GEN6_PMIMR, 0xffffffff);
  2341. I915_WRITE(GEN6_PMIER, 0x0);
  2342. POSTING_READ(GEN6_PMIER);
  2343. }
  2344. }
  2345. /* drm_dma.h hooks
  2346. */
  2347. static void ironlake_irq_preinstall(struct drm_device *dev)
  2348. {
  2349. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2350. I915_WRITE(HWSTAM, 0xeffe);
  2351. I915_WRITE(DEIMR, 0xffffffff);
  2352. I915_WRITE(DEIER, 0x0);
  2353. POSTING_READ(DEIER);
  2354. gen5_gt_irq_preinstall(dev);
  2355. ibx_irq_preinstall(dev);
  2356. }
  2357. static void valleyview_irq_preinstall(struct drm_device *dev)
  2358. {
  2359. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2360. int pipe;
  2361. /* VLV magic */
  2362. I915_WRITE(VLV_IMR, 0);
  2363. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  2364. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  2365. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  2366. /* and GT */
  2367. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2368. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2369. gen5_gt_irq_preinstall(dev);
  2370. I915_WRITE(DPINVGTT, 0xff);
  2371. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2372. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2373. for_each_pipe(pipe)
  2374. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2375. I915_WRITE(VLV_IIR, 0xffffffff);
  2376. I915_WRITE(VLV_IMR, 0xffffffff);
  2377. I915_WRITE(VLV_IER, 0x0);
  2378. POSTING_READ(VLV_IER);
  2379. }
  2380. static void gen8_irq_preinstall(struct drm_device *dev)
  2381. {
  2382. struct drm_i915_private *dev_priv = dev->dev_private;
  2383. int pipe;
  2384. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2385. POSTING_READ(GEN8_MASTER_IRQ);
  2386. /* IIR can theoretically queue up two events. Be paranoid */
  2387. #define GEN8_IRQ_INIT_NDX(type, which) do { \
  2388. I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
  2389. POSTING_READ(GEN8_##type##_IMR(which)); \
  2390. I915_WRITE(GEN8_##type##_IER(which), 0); \
  2391. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  2392. POSTING_READ(GEN8_##type##_IIR(which)); \
  2393. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  2394. } while (0)
  2395. #define GEN8_IRQ_INIT(type) do { \
  2396. I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
  2397. POSTING_READ(GEN8_##type##_IMR); \
  2398. I915_WRITE(GEN8_##type##_IER, 0); \
  2399. I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
  2400. POSTING_READ(GEN8_##type##_IIR); \
  2401. I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
  2402. } while (0)
  2403. GEN8_IRQ_INIT_NDX(GT, 0);
  2404. GEN8_IRQ_INIT_NDX(GT, 1);
  2405. GEN8_IRQ_INIT_NDX(GT, 2);
  2406. GEN8_IRQ_INIT_NDX(GT, 3);
  2407. for_each_pipe(pipe) {
  2408. GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
  2409. }
  2410. GEN8_IRQ_INIT(DE_PORT);
  2411. GEN8_IRQ_INIT(DE_MISC);
  2412. GEN8_IRQ_INIT(PCU);
  2413. #undef GEN8_IRQ_INIT
  2414. #undef GEN8_IRQ_INIT_NDX
  2415. POSTING_READ(GEN8_PCU_IIR);
  2416. ibx_irq_preinstall(dev);
  2417. }
  2418. static void ibx_hpd_irq_setup(struct drm_device *dev)
  2419. {
  2420. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2421. struct drm_mode_config *mode_config = &dev->mode_config;
  2422. struct intel_encoder *intel_encoder;
  2423. u32 hotplug_irqs, hotplug, enabled_irqs = 0;
  2424. if (HAS_PCH_IBX(dev)) {
  2425. hotplug_irqs = SDE_HOTPLUG_MASK;
  2426. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2427. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2428. enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
  2429. } else {
  2430. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  2431. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2432. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2433. enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
  2434. }
  2435. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2436. /*
  2437. * Enable digital hotplug on the PCH, and configure the DP short pulse
  2438. * duration to 2ms (which is the minimum in the Display Port spec)
  2439. *
  2440. * This register is the same on all known PCH chips.
  2441. */
  2442. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  2443. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  2444. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  2445. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  2446. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  2447. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  2448. }
  2449. static void ibx_irq_postinstall(struct drm_device *dev)
  2450. {
  2451. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2452. u32 mask;
  2453. if (HAS_PCH_NOP(dev))
  2454. return;
  2455. if (HAS_PCH_IBX(dev)) {
  2456. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
  2457. } else {
  2458. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
  2459. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  2460. }
  2461. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  2462. I915_WRITE(SDEIMR, ~mask);
  2463. }
  2464. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  2465. {
  2466. struct drm_i915_private *dev_priv = dev->dev_private;
  2467. u32 pm_irqs, gt_irqs;
  2468. pm_irqs = gt_irqs = 0;
  2469. dev_priv->gt_irq_mask = ~0;
  2470. if (HAS_L3_DPF(dev)) {
  2471. /* L3 parity interrupt is always unmasked. */
  2472. dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
  2473. gt_irqs |= GT_PARITY_ERROR(dev);
  2474. }
  2475. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  2476. if (IS_GEN5(dev)) {
  2477. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  2478. ILK_BSD_USER_INTERRUPT;
  2479. } else {
  2480. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  2481. }
  2482. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2483. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  2484. I915_WRITE(GTIER, gt_irqs);
  2485. POSTING_READ(GTIER);
  2486. if (INTEL_INFO(dev)->gen >= 6) {
  2487. pm_irqs |= dev_priv->pm_rps_events;
  2488. if (HAS_VEBOX(dev))
  2489. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  2490. dev_priv->pm_irq_mask = 0xffffffff;
  2491. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  2492. I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
  2493. I915_WRITE(GEN6_PMIER, pm_irqs);
  2494. POSTING_READ(GEN6_PMIER);
  2495. }
  2496. }
  2497. static int ironlake_irq_postinstall(struct drm_device *dev)
  2498. {
  2499. unsigned long irqflags;
  2500. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2501. u32 display_mask, extra_mask;
  2502. if (INTEL_INFO(dev)->gen >= 7) {
  2503. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  2504. DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
  2505. DE_PLANEB_FLIP_DONE_IVB |
  2506. DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
  2507. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  2508. DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
  2509. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  2510. } else {
  2511. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  2512. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  2513. DE_AUX_CHANNEL_A |
  2514. DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
  2515. DE_POISON);
  2516. extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
  2517. DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
  2518. }
  2519. dev_priv->irq_mask = ~display_mask;
  2520. /* should always can generate irq */
  2521. I915_WRITE(DEIIR, I915_READ(DEIIR));
  2522. I915_WRITE(DEIMR, dev_priv->irq_mask);
  2523. I915_WRITE(DEIER, display_mask | extra_mask);
  2524. POSTING_READ(DEIER);
  2525. gen5_gt_irq_postinstall(dev);
  2526. ibx_irq_postinstall(dev);
  2527. if (IS_IRONLAKE_M(dev)) {
  2528. /* Enable PCU event interrupts
  2529. *
  2530. * spinlocking not required here for correctness since interrupt
  2531. * setup is guaranteed to run in single-threaded context. But we
  2532. * need it to make the assert_spin_locked happy. */
  2533. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2534. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  2535. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2536. }
  2537. return 0;
  2538. }
  2539. static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
  2540. {
  2541. u32 pipestat_mask;
  2542. u32 iir_mask;
  2543. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2544. PIPE_FIFO_UNDERRUN_STATUS;
  2545. I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
  2546. I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
  2547. POSTING_READ(PIPESTAT(PIPE_A));
  2548. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2549. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2550. i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask |
  2551. PIPE_GMBUS_INTERRUPT_STATUS);
  2552. i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask);
  2553. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2554. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2555. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2556. dev_priv->irq_mask &= ~iir_mask;
  2557. I915_WRITE(VLV_IIR, iir_mask);
  2558. I915_WRITE(VLV_IIR, iir_mask);
  2559. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2560. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2561. POSTING_READ(VLV_IER);
  2562. }
  2563. static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
  2564. {
  2565. u32 pipestat_mask;
  2566. u32 iir_mask;
  2567. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2568. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2569. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2570. dev_priv->irq_mask |= iir_mask;
  2571. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2572. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2573. I915_WRITE(VLV_IIR, iir_mask);
  2574. I915_WRITE(VLV_IIR, iir_mask);
  2575. POSTING_READ(VLV_IIR);
  2576. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2577. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2578. i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask |
  2579. PIPE_GMBUS_INTERRUPT_STATUS);
  2580. i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask);
  2581. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2582. PIPE_FIFO_UNDERRUN_STATUS;
  2583. I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
  2584. I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
  2585. POSTING_READ(PIPESTAT(PIPE_A));
  2586. }
  2587. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
  2588. {
  2589. assert_spin_locked(&dev_priv->irq_lock);
  2590. if (dev_priv->display_irqs_enabled)
  2591. return;
  2592. dev_priv->display_irqs_enabled = true;
  2593. if (dev_priv->dev->irq_enabled)
  2594. valleyview_display_irqs_install(dev_priv);
  2595. }
  2596. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
  2597. {
  2598. assert_spin_locked(&dev_priv->irq_lock);
  2599. if (!dev_priv->display_irqs_enabled)
  2600. return;
  2601. dev_priv->display_irqs_enabled = false;
  2602. if (dev_priv->dev->irq_enabled)
  2603. valleyview_display_irqs_uninstall(dev_priv);
  2604. }
  2605. static int valleyview_irq_postinstall(struct drm_device *dev)
  2606. {
  2607. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2608. unsigned long irqflags;
  2609. dev_priv->irq_mask = ~0;
  2610. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2611. POSTING_READ(PORT_HOTPLUG_EN);
  2612. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2613. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2614. I915_WRITE(VLV_IIR, 0xffffffff);
  2615. POSTING_READ(VLV_IER);
  2616. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2617. * just to make the assert_spin_locked check happy. */
  2618. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2619. if (dev_priv->display_irqs_enabled)
  2620. valleyview_display_irqs_install(dev_priv);
  2621. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2622. I915_WRITE(VLV_IIR, 0xffffffff);
  2623. I915_WRITE(VLV_IIR, 0xffffffff);
  2624. gen5_gt_irq_postinstall(dev);
  2625. /* ack & enable invalid PTE error interrupts */
  2626. #if 0 /* FIXME: add support to irq handler for checking these bits */
  2627. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2628. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  2629. #endif
  2630. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  2631. return 0;
  2632. }
  2633. static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
  2634. {
  2635. int i;
  2636. /* These are interrupts we'll toggle with the ring mask register */
  2637. uint32_t gt_interrupts[] = {
  2638. GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  2639. GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
  2640. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
  2641. GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
  2642. GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
  2643. 0,
  2644. GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
  2645. };
  2646. for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
  2647. u32 tmp = I915_READ(GEN8_GT_IIR(i));
  2648. if (tmp)
  2649. DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
  2650. i, tmp);
  2651. I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
  2652. I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
  2653. }
  2654. POSTING_READ(GEN8_GT_IER(0));
  2655. }
  2656. static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
  2657. {
  2658. struct drm_device *dev = dev_priv->dev;
  2659. uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
  2660. GEN8_PIPE_CDCLK_CRC_DONE |
  2661. GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  2662. uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
  2663. GEN8_PIPE_FIFO_UNDERRUN;
  2664. int pipe;
  2665. dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
  2666. dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
  2667. dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
  2668. for_each_pipe(pipe) {
  2669. u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
  2670. if (tmp)
  2671. DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
  2672. pipe, tmp);
  2673. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2674. I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
  2675. }
  2676. POSTING_READ(GEN8_DE_PIPE_ISR(0));
  2677. I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
  2678. I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
  2679. POSTING_READ(GEN8_DE_PORT_IER);
  2680. }
  2681. static int gen8_irq_postinstall(struct drm_device *dev)
  2682. {
  2683. struct drm_i915_private *dev_priv = dev->dev_private;
  2684. gen8_gt_irq_postinstall(dev_priv);
  2685. gen8_de_irq_postinstall(dev_priv);
  2686. ibx_irq_postinstall(dev);
  2687. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  2688. POSTING_READ(GEN8_MASTER_IRQ);
  2689. return 0;
  2690. }
  2691. static void gen8_irq_uninstall(struct drm_device *dev)
  2692. {
  2693. struct drm_i915_private *dev_priv = dev->dev_private;
  2694. int pipe;
  2695. if (!dev_priv)
  2696. return;
  2697. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2698. #define GEN8_IRQ_FINI_NDX(type, which) do { \
  2699. I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
  2700. I915_WRITE(GEN8_##type##_IER(which), 0); \
  2701. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  2702. } while (0)
  2703. #define GEN8_IRQ_FINI(type) do { \
  2704. I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
  2705. I915_WRITE(GEN8_##type##_IER, 0); \
  2706. I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
  2707. } while (0)
  2708. GEN8_IRQ_FINI_NDX(GT, 0);
  2709. GEN8_IRQ_FINI_NDX(GT, 1);
  2710. GEN8_IRQ_FINI_NDX(GT, 2);
  2711. GEN8_IRQ_FINI_NDX(GT, 3);
  2712. for_each_pipe(pipe) {
  2713. GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
  2714. }
  2715. GEN8_IRQ_FINI(DE_PORT);
  2716. GEN8_IRQ_FINI(DE_MISC);
  2717. GEN8_IRQ_FINI(PCU);
  2718. #undef GEN8_IRQ_FINI
  2719. #undef GEN8_IRQ_FINI_NDX
  2720. POSTING_READ(GEN8_PCU_IIR);
  2721. }
  2722. static void valleyview_irq_uninstall(struct drm_device *dev)
  2723. {
  2724. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2725. unsigned long irqflags;
  2726. int pipe;
  2727. if (!dev_priv)
  2728. return;
  2729. intel_hpd_irq_uninstall(dev_priv);
  2730. for_each_pipe(pipe)
  2731. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2732. I915_WRITE(HWSTAM, 0xffffffff);
  2733. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2734. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2735. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2736. if (dev_priv->display_irqs_enabled)
  2737. valleyview_display_irqs_uninstall(dev_priv);
  2738. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2739. dev_priv->irq_mask = 0;
  2740. I915_WRITE(VLV_IIR, 0xffffffff);
  2741. I915_WRITE(VLV_IMR, 0xffffffff);
  2742. I915_WRITE(VLV_IER, 0x0);
  2743. POSTING_READ(VLV_IER);
  2744. }
  2745. static void ironlake_irq_uninstall(struct drm_device *dev)
  2746. {
  2747. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2748. if (!dev_priv)
  2749. return;
  2750. intel_hpd_irq_uninstall(dev_priv);
  2751. I915_WRITE(HWSTAM, 0xffffffff);
  2752. I915_WRITE(DEIMR, 0xffffffff);
  2753. I915_WRITE(DEIER, 0x0);
  2754. I915_WRITE(DEIIR, I915_READ(DEIIR));
  2755. if (IS_GEN7(dev))
  2756. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  2757. I915_WRITE(GTIMR, 0xffffffff);
  2758. I915_WRITE(GTIER, 0x0);
  2759. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2760. if (HAS_PCH_NOP(dev))
  2761. return;
  2762. I915_WRITE(SDEIMR, 0xffffffff);
  2763. I915_WRITE(SDEIER, 0x0);
  2764. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  2765. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  2766. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  2767. }
  2768. static void i8xx_irq_preinstall(struct drm_device * dev)
  2769. {
  2770. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2771. int pipe;
  2772. for_each_pipe(pipe)
  2773. I915_WRITE(PIPESTAT(pipe), 0);
  2774. I915_WRITE16(IMR, 0xffff);
  2775. I915_WRITE16(IER, 0x0);
  2776. POSTING_READ16(IER);
  2777. }
  2778. static int i8xx_irq_postinstall(struct drm_device *dev)
  2779. {
  2780. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2781. unsigned long irqflags;
  2782. I915_WRITE16(EMR,
  2783. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2784. /* Unmask the interrupts that we always want on. */
  2785. dev_priv->irq_mask =
  2786. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2787. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2788. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2789. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2790. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2791. I915_WRITE16(IMR, dev_priv->irq_mask);
  2792. I915_WRITE16(IER,
  2793. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2794. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2795. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2796. I915_USER_INTERRUPT);
  2797. POSTING_READ16(IER);
  2798. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2799. * just to make the assert_spin_locked check happy. */
  2800. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2801. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  2802. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  2803. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2804. return 0;
  2805. }
  2806. /*
  2807. * Returns true when a page flip has completed.
  2808. */
  2809. static bool i8xx_handle_vblank(struct drm_device *dev,
  2810. int plane, int pipe, u32 iir)
  2811. {
  2812. drm_i915_private_t *dev_priv = dev->dev_private;
  2813. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  2814. if (!drm_handle_vblank(dev, pipe))
  2815. return false;
  2816. if ((iir & flip_pending) == 0)
  2817. return false;
  2818. intel_prepare_page_flip(dev, plane);
  2819. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2820. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2821. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2822. * the flip is completed (no longer pending). Since this doesn't raise
  2823. * an interrupt per se, we watch for the change at vblank.
  2824. */
  2825. if (I915_READ16(ISR) & flip_pending)
  2826. return false;
  2827. intel_finish_page_flip(dev, pipe);
  2828. return true;
  2829. }
  2830. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  2831. {
  2832. struct drm_device *dev = (struct drm_device *) arg;
  2833. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2834. u16 iir, new_iir;
  2835. u32 pipe_stats[2];
  2836. unsigned long irqflags;
  2837. int pipe;
  2838. u16 flip_mask =
  2839. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2840. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2841. iir = I915_READ16(IIR);
  2842. if (iir == 0)
  2843. return IRQ_NONE;
  2844. while (iir & ~flip_mask) {
  2845. /* Can't rely on pipestat interrupt bit in iir as it might
  2846. * have been cleared after the pipestat interrupt was received.
  2847. * It doesn't set the bit in iir again, but it still produces
  2848. * interrupts (for non-MSI).
  2849. */
  2850. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2851. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2852. i915_handle_error(dev, false,
  2853. "Command parser error, iir 0x%08x",
  2854. iir);
  2855. for_each_pipe(pipe) {
  2856. int reg = PIPESTAT(pipe);
  2857. pipe_stats[pipe] = I915_READ(reg);
  2858. /*
  2859. * Clear the PIPE*STAT regs before the IIR
  2860. */
  2861. if (pipe_stats[pipe] & 0x8000ffff)
  2862. I915_WRITE(reg, pipe_stats[pipe]);
  2863. }
  2864. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2865. I915_WRITE16(IIR, iir & ~flip_mask);
  2866. new_iir = I915_READ16(IIR); /* Flush posted writes */
  2867. i915_update_dri1_breadcrumb(dev);
  2868. if (iir & I915_USER_INTERRUPT)
  2869. notify_ring(dev, &dev_priv->ring[RCS]);
  2870. for_each_pipe(pipe) {
  2871. int plane = pipe;
  2872. if (HAS_FBC(dev))
  2873. plane = !plane;
  2874. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2875. i8xx_handle_vblank(dev, plane, pipe, iir))
  2876. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  2877. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  2878. i9xx_pipe_crc_irq_handler(dev, pipe);
  2879. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
  2880. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  2881. DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
  2882. }
  2883. iir = new_iir;
  2884. }
  2885. return IRQ_HANDLED;
  2886. }
  2887. static void i8xx_irq_uninstall(struct drm_device * dev)
  2888. {
  2889. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2890. int pipe;
  2891. for_each_pipe(pipe) {
  2892. /* Clear enable bits; then clear status bits */
  2893. I915_WRITE(PIPESTAT(pipe), 0);
  2894. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2895. }
  2896. I915_WRITE16(IMR, 0xffff);
  2897. I915_WRITE16(IER, 0x0);
  2898. I915_WRITE16(IIR, I915_READ16(IIR));
  2899. }
  2900. static void i915_irq_preinstall(struct drm_device * dev)
  2901. {
  2902. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2903. int pipe;
  2904. if (I915_HAS_HOTPLUG(dev)) {
  2905. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2906. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2907. }
  2908. I915_WRITE16(HWSTAM, 0xeffe);
  2909. for_each_pipe(pipe)
  2910. I915_WRITE(PIPESTAT(pipe), 0);
  2911. I915_WRITE(IMR, 0xffffffff);
  2912. I915_WRITE(IER, 0x0);
  2913. POSTING_READ(IER);
  2914. }
  2915. static int i915_irq_postinstall(struct drm_device *dev)
  2916. {
  2917. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2918. u32 enable_mask;
  2919. unsigned long irqflags;
  2920. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2921. /* Unmask the interrupts that we always want on. */
  2922. dev_priv->irq_mask =
  2923. ~(I915_ASLE_INTERRUPT |
  2924. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2925. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2926. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2927. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2928. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2929. enable_mask =
  2930. I915_ASLE_INTERRUPT |
  2931. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2932. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2933. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2934. I915_USER_INTERRUPT;
  2935. if (I915_HAS_HOTPLUG(dev)) {
  2936. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2937. POSTING_READ(PORT_HOTPLUG_EN);
  2938. /* Enable in IER... */
  2939. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  2940. /* and unmask in IMR */
  2941. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  2942. }
  2943. I915_WRITE(IMR, dev_priv->irq_mask);
  2944. I915_WRITE(IER, enable_mask);
  2945. POSTING_READ(IER);
  2946. i915_enable_asle_pipestat(dev);
  2947. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2948. * just to make the assert_spin_locked check happy. */
  2949. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2950. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  2951. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  2952. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2953. return 0;
  2954. }
  2955. /*
  2956. * Returns true when a page flip has completed.
  2957. */
  2958. static bool i915_handle_vblank(struct drm_device *dev,
  2959. int plane, int pipe, u32 iir)
  2960. {
  2961. drm_i915_private_t *dev_priv = dev->dev_private;
  2962. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  2963. if (!drm_handle_vblank(dev, pipe))
  2964. return false;
  2965. if ((iir & flip_pending) == 0)
  2966. return false;
  2967. intel_prepare_page_flip(dev, plane);
  2968. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2969. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2970. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2971. * the flip is completed (no longer pending). Since this doesn't raise
  2972. * an interrupt per se, we watch for the change at vblank.
  2973. */
  2974. if (I915_READ(ISR) & flip_pending)
  2975. return false;
  2976. intel_finish_page_flip(dev, pipe);
  2977. return true;
  2978. }
  2979. static irqreturn_t i915_irq_handler(int irq, void *arg)
  2980. {
  2981. struct drm_device *dev = (struct drm_device *) arg;
  2982. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2983. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  2984. unsigned long irqflags;
  2985. u32 flip_mask =
  2986. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2987. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2988. int pipe, ret = IRQ_NONE;
  2989. iir = I915_READ(IIR);
  2990. do {
  2991. bool irq_received = (iir & ~flip_mask) != 0;
  2992. bool blc_event = false;
  2993. /* Can't rely on pipestat interrupt bit in iir as it might
  2994. * have been cleared after the pipestat interrupt was received.
  2995. * It doesn't set the bit in iir again, but it still produces
  2996. * interrupts (for non-MSI).
  2997. */
  2998. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2999. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3000. i915_handle_error(dev, false,
  3001. "Command parser error, iir 0x%08x",
  3002. iir);
  3003. for_each_pipe(pipe) {
  3004. int reg = PIPESTAT(pipe);
  3005. pipe_stats[pipe] = I915_READ(reg);
  3006. /* Clear the PIPE*STAT regs before the IIR */
  3007. if (pipe_stats[pipe] & 0x8000ffff) {
  3008. I915_WRITE(reg, pipe_stats[pipe]);
  3009. irq_received = true;
  3010. }
  3011. }
  3012. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3013. if (!irq_received)
  3014. break;
  3015. /* Consume port. Then clear IIR or we'll miss events */
  3016. if ((I915_HAS_HOTPLUG(dev)) &&
  3017. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  3018. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  3019. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  3020. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  3021. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  3022. POSTING_READ(PORT_HOTPLUG_STAT);
  3023. }
  3024. I915_WRITE(IIR, iir & ~flip_mask);
  3025. new_iir = I915_READ(IIR); /* Flush posted writes */
  3026. if (iir & I915_USER_INTERRUPT)
  3027. notify_ring(dev, &dev_priv->ring[RCS]);
  3028. for_each_pipe(pipe) {
  3029. int plane = pipe;
  3030. if (HAS_FBC(dev))
  3031. plane = !plane;
  3032. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  3033. i915_handle_vblank(dev, plane, pipe, iir))
  3034. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  3035. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3036. blc_event = true;
  3037. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3038. i9xx_pipe_crc_irq_handler(dev, pipe);
  3039. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
  3040. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  3041. DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
  3042. }
  3043. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3044. intel_opregion_asle_intr(dev);
  3045. /* With MSI, interrupts are only generated when iir
  3046. * transitions from zero to nonzero. If another bit got
  3047. * set while we were handling the existing iir bits, then
  3048. * we would never get another interrupt.
  3049. *
  3050. * This is fine on non-MSI as well, as if we hit this path
  3051. * we avoid exiting the interrupt handler only to generate
  3052. * another one.
  3053. *
  3054. * Note that for MSI this could cause a stray interrupt report
  3055. * if an interrupt landed in the time between writing IIR and
  3056. * the posting read. This should be rare enough to never
  3057. * trigger the 99% of 100,000 interrupts test for disabling
  3058. * stray interrupts.
  3059. */
  3060. ret = IRQ_HANDLED;
  3061. iir = new_iir;
  3062. } while (iir & ~flip_mask);
  3063. i915_update_dri1_breadcrumb(dev);
  3064. return ret;
  3065. }
  3066. static void i915_irq_uninstall(struct drm_device * dev)
  3067. {
  3068. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  3069. int pipe;
  3070. intel_hpd_irq_uninstall(dev_priv);
  3071. if (I915_HAS_HOTPLUG(dev)) {
  3072. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3073. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3074. }
  3075. I915_WRITE16(HWSTAM, 0xffff);
  3076. for_each_pipe(pipe) {
  3077. /* Clear enable bits; then clear status bits */
  3078. I915_WRITE(PIPESTAT(pipe), 0);
  3079. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  3080. }
  3081. I915_WRITE(IMR, 0xffffffff);
  3082. I915_WRITE(IER, 0x0);
  3083. I915_WRITE(IIR, I915_READ(IIR));
  3084. }
  3085. static void i965_irq_preinstall(struct drm_device * dev)
  3086. {
  3087. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  3088. int pipe;
  3089. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3090. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3091. I915_WRITE(HWSTAM, 0xeffe);
  3092. for_each_pipe(pipe)
  3093. I915_WRITE(PIPESTAT(pipe), 0);
  3094. I915_WRITE(IMR, 0xffffffff);
  3095. I915_WRITE(IER, 0x0);
  3096. POSTING_READ(IER);
  3097. }
  3098. static int i965_irq_postinstall(struct drm_device *dev)
  3099. {
  3100. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  3101. u32 enable_mask;
  3102. u32 error_mask;
  3103. unsigned long irqflags;
  3104. /* Unmask the interrupts that we always want on. */
  3105. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  3106. I915_DISPLAY_PORT_INTERRUPT |
  3107. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3108. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3109. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3110. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  3111. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  3112. enable_mask = ~dev_priv->irq_mask;
  3113. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3114. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3115. enable_mask |= I915_USER_INTERRUPT;
  3116. if (IS_G4X(dev))
  3117. enable_mask |= I915_BSD_USER_INTERRUPT;
  3118. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3119. * just to make the assert_spin_locked check happy. */
  3120. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3121. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  3122. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3123. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3124. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3125. /*
  3126. * Enable some error detection, note the instruction error mask
  3127. * bit is reserved, so we leave it masked.
  3128. */
  3129. if (IS_G4X(dev)) {
  3130. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  3131. GM45_ERROR_MEM_PRIV |
  3132. GM45_ERROR_CP_PRIV |
  3133. I915_ERROR_MEMORY_REFRESH);
  3134. } else {
  3135. error_mask = ~(I915_ERROR_PAGE_TABLE |
  3136. I915_ERROR_MEMORY_REFRESH);
  3137. }
  3138. I915_WRITE(EMR, error_mask);
  3139. I915_WRITE(IMR, dev_priv->irq_mask);
  3140. I915_WRITE(IER, enable_mask);
  3141. POSTING_READ(IER);
  3142. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3143. POSTING_READ(PORT_HOTPLUG_EN);
  3144. i915_enable_asle_pipestat(dev);
  3145. return 0;
  3146. }
  3147. static void i915_hpd_irq_setup(struct drm_device *dev)
  3148. {
  3149. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  3150. struct drm_mode_config *mode_config = &dev->mode_config;
  3151. struct intel_encoder *intel_encoder;
  3152. u32 hotplug_en;
  3153. assert_spin_locked(&dev_priv->irq_lock);
  3154. if (I915_HAS_HOTPLUG(dev)) {
  3155. hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  3156. hotplug_en &= ~HOTPLUG_INT_EN_MASK;
  3157. /* Note HDMI and DP share hotplug bits */
  3158. /* enable bits are the same for all generations */
  3159. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  3160. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  3161. hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
  3162. /* Programming the CRT detection parameters tends
  3163. to generate a spurious hotplug event about three
  3164. seconds later. So just do it once.
  3165. */
  3166. if (IS_G4X(dev))
  3167. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  3168. hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
  3169. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  3170. /* Ignore TV since it's buggy */
  3171. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  3172. }
  3173. }
  3174. static irqreturn_t i965_irq_handler(int irq, void *arg)
  3175. {
  3176. struct drm_device *dev = (struct drm_device *) arg;
  3177. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  3178. u32 iir, new_iir;
  3179. u32 pipe_stats[I915_MAX_PIPES];
  3180. unsigned long irqflags;
  3181. int ret = IRQ_NONE, pipe;
  3182. u32 flip_mask =
  3183. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3184. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3185. iir = I915_READ(IIR);
  3186. for (;;) {
  3187. bool irq_received = (iir & ~flip_mask) != 0;
  3188. bool blc_event = false;
  3189. /* Can't rely on pipestat interrupt bit in iir as it might
  3190. * have been cleared after the pipestat interrupt was received.
  3191. * It doesn't set the bit in iir again, but it still produces
  3192. * interrupts (for non-MSI).
  3193. */
  3194. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3195. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3196. i915_handle_error(dev, false,
  3197. "Command parser error, iir 0x%08x",
  3198. iir);
  3199. for_each_pipe(pipe) {
  3200. int reg = PIPESTAT(pipe);
  3201. pipe_stats[pipe] = I915_READ(reg);
  3202. /*
  3203. * Clear the PIPE*STAT regs before the IIR
  3204. */
  3205. if (pipe_stats[pipe] & 0x8000ffff) {
  3206. I915_WRITE(reg, pipe_stats[pipe]);
  3207. irq_received = true;
  3208. }
  3209. }
  3210. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3211. if (!irq_received)
  3212. break;
  3213. ret = IRQ_HANDLED;
  3214. /* Consume port. Then clear IIR or we'll miss events */
  3215. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  3216. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  3217. u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
  3218. HOTPLUG_INT_STATUS_G4X :
  3219. HOTPLUG_INT_STATUS_I915);
  3220. intel_hpd_irq_handler(dev, hotplug_trigger,
  3221. IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915);
  3222. if (IS_G4X(dev) &&
  3223. (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X))
  3224. dp_aux_irq_handler(dev);
  3225. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  3226. I915_READ(PORT_HOTPLUG_STAT);
  3227. }
  3228. I915_WRITE(IIR, iir & ~flip_mask);
  3229. new_iir = I915_READ(IIR); /* Flush posted writes */
  3230. if (iir & I915_USER_INTERRUPT)
  3231. notify_ring(dev, &dev_priv->ring[RCS]);
  3232. if (iir & I915_BSD_USER_INTERRUPT)
  3233. notify_ring(dev, &dev_priv->ring[VCS]);
  3234. for_each_pipe(pipe) {
  3235. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  3236. i915_handle_vblank(dev, pipe, pipe, iir))
  3237. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  3238. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3239. blc_event = true;
  3240. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3241. i9xx_pipe_crc_irq_handler(dev, pipe);
  3242. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
  3243. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  3244. DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
  3245. }
  3246. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3247. intel_opregion_asle_intr(dev);
  3248. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  3249. gmbus_irq_handler(dev);
  3250. /* With MSI, interrupts are only generated when iir
  3251. * transitions from zero to nonzero. If another bit got
  3252. * set while we were handling the existing iir bits, then
  3253. * we would never get another interrupt.
  3254. *
  3255. * This is fine on non-MSI as well, as if we hit this path
  3256. * we avoid exiting the interrupt handler only to generate
  3257. * another one.
  3258. *
  3259. * Note that for MSI this could cause a stray interrupt report
  3260. * if an interrupt landed in the time between writing IIR and
  3261. * the posting read. This should be rare enough to never
  3262. * trigger the 99% of 100,000 interrupts test for disabling
  3263. * stray interrupts.
  3264. */
  3265. iir = new_iir;
  3266. }
  3267. i915_update_dri1_breadcrumb(dev);
  3268. return ret;
  3269. }
  3270. static void i965_irq_uninstall(struct drm_device * dev)
  3271. {
  3272. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  3273. int pipe;
  3274. if (!dev_priv)
  3275. return;
  3276. intel_hpd_irq_uninstall(dev_priv);
  3277. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3278. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3279. I915_WRITE(HWSTAM, 0xffffffff);
  3280. for_each_pipe(pipe)
  3281. I915_WRITE(PIPESTAT(pipe), 0);
  3282. I915_WRITE(IMR, 0xffffffff);
  3283. I915_WRITE(IER, 0x0);
  3284. for_each_pipe(pipe)
  3285. I915_WRITE(PIPESTAT(pipe),
  3286. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  3287. I915_WRITE(IIR, I915_READ(IIR));
  3288. }
  3289. static void intel_hpd_irq_reenable(unsigned long data)
  3290. {
  3291. drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
  3292. struct drm_device *dev = dev_priv->dev;
  3293. struct drm_mode_config *mode_config = &dev->mode_config;
  3294. unsigned long irqflags;
  3295. int i;
  3296. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3297. for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
  3298. struct drm_connector *connector;
  3299. if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
  3300. continue;
  3301. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  3302. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3303. struct intel_connector *intel_connector = to_intel_connector(connector);
  3304. if (intel_connector->encoder->hpd_pin == i) {
  3305. if (connector->polled != intel_connector->polled)
  3306. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  3307. drm_get_connector_name(connector));
  3308. connector->polled = intel_connector->polled;
  3309. if (!connector->polled)
  3310. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3311. }
  3312. }
  3313. }
  3314. if (dev_priv->display.hpd_irq_setup)
  3315. dev_priv->display.hpd_irq_setup(dev);
  3316. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3317. }
  3318. void intel_irq_init(struct drm_device *dev)
  3319. {
  3320. struct drm_i915_private *dev_priv = dev->dev_private;
  3321. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  3322. INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
  3323. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  3324. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  3325. /* Let's track the enabled rps events */
  3326. dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
  3327. setup_timer(&dev_priv->gpu_error.hangcheck_timer,
  3328. i915_hangcheck_elapsed,
  3329. (unsigned long) dev);
  3330. setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable,
  3331. (unsigned long) dev_priv);
  3332. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  3333. if (IS_GEN2(dev)) {
  3334. dev->max_vblank_count = 0;
  3335. dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
  3336. } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  3337. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  3338. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  3339. } else {
  3340. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  3341. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  3342. }
  3343. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  3344. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  3345. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  3346. }
  3347. if (IS_VALLEYVIEW(dev)) {
  3348. dev->driver->irq_handler = valleyview_irq_handler;
  3349. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  3350. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  3351. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  3352. dev->driver->enable_vblank = valleyview_enable_vblank;
  3353. dev->driver->disable_vblank = valleyview_disable_vblank;
  3354. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3355. } else if (IS_GEN8(dev)) {
  3356. dev->driver->irq_handler = gen8_irq_handler;
  3357. dev->driver->irq_preinstall = gen8_irq_preinstall;
  3358. dev->driver->irq_postinstall = gen8_irq_postinstall;
  3359. dev->driver->irq_uninstall = gen8_irq_uninstall;
  3360. dev->driver->enable_vblank = gen8_enable_vblank;
  3361. dev->driver->disable_vblank = gen8_disable_vblank;
  3362. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3363. } else if (HAS_PCH_SPLIT(dev)) {
  3364. dev->driver->irq_handler = ironlake_irq_handler;
  3365. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  3366. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  3367. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  3368. dev->driver->enable_vblank = ironlake_enable_vblank;
  3369. dev->driver->disable_vblank = ironlake_disable_vblank;
  3370. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3371. } else {
  3372. if (INTEL_INFO(dev)->gen == 2) {
  3373. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  3374. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  3375. dev->driver->irq_handler = i8xx_irq_handler;
  3376. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  3377. } else if (INTEL_INFO(dev)->gen == 3) {
  3378. dev->driver->irq_preinstall = i915_irq_preinstall;
  3379. dev->driver->irq_postinstall = i915_irq_postinstall;
  3380. dev->driver->irq_uninstall = i915_irq_uninstall;
  3381. dev->driver->irq_handler = i915_irq_handler;
  3382. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3383. } else {
  3384. dev->driver->irq_preinstall = i965_irq_preinstall;
  3385. dev->driver->irq_postinstall = i965_irq_postinstall;
  3386. dev->driver->irq_uninstall = i965_irq_uninstall;
  3387. dev->driver->irq_handler = i965_irq_handler;
  3388. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3389. }
  3390. dev->driver->enable_vblank = i915_enable_vblank;
  3391. dev->driver->disable_vblank = i915_disable_vblank;
  3392. }
  3393. }
  3394. void intel_hpd_init(struct drm_device *dev)
  3395. {
  3396. struct drm_i915_private *dev_priv = dev->dev_private;
  3397. struct drm_mode_config *mode_config = &dev->mode_config;
  3398. struct drm_connector *connector;
  3399. unsigned long irqflags;
  3400. int i;
  3401. for (i = 1; i < HPD_NUM_PINS; i++) {
  3402. dev_priv->hpd_stats[i].hpd_cnt = 0;
  3403. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  3404. }
  3405. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3406. struct intel_connector *intel_connector = to_intel_connector(connector);
  3407. connector->polled = intel_connector->polled;
  3408. if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
  3409. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3410. }
  3411. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3412. * just to make the assert_spin_locked checks happy. */
  3413. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3414. if (dev_priv->display.hpd_irq_setup)
  3415. dev_priv->display.hpd_irq_setup(dev);
  3416. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3417. }
  3418. /* Disable interrupts so we can allow runtime PM. */
  3419. void hsw_runtime_pm_disable_interrupts(struct drm_device *dev)
  3420. {
  3421. struct drm_i915_private *dev_priv = dev->dev_private;
  3422. unsigned long irqflags;
  3423. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3424. dev_priv->pm.regsave.deimr = I915_READ(DEIMR);
  3425. dev_priv->pm.regsave.sdeimr = I915_READ(SDEIMR);
  3426. dev_priv->pm.regsave.gtimr = I915_READ(GTIMR);
  3427. dev_priv->pm.regsave.gtier = I915_READ(GTIER);
  3428. dev_priv->pm.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
  3429. ironlake_disable_display_irq(dev_priv, 0xffffffff);
  3430. ibx_disable_display_interrupt(dev_priv, 0xffffffff);
  3431. ilk_disable_gt_irq(dev_priv, 0xffffffff);
  3432. snb_disable_pm_irq(dev_priv, 0xffffffff);
  3433. dev_priv->pm.irqs_disabled = true;
  3434. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3435. }
  3436. /* Restore interrupts so we can recover from runtime PM. */
  3437. void hsw_runtime_pm_restore_interrupts(struct drm_device *dev)
  3438. {
  3439. struct drm_i915_private *dev_priv = dev->dev_private;
  3440. unsigned long irqflags;
  3441. uint32_t val;
  3442. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3443. val = I915_READ(DEIMR);
  3444. WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
  3445. val = I915_READ(SDEIMR);
  3446. WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
  3447. val = I915_READ(GTIMR);
  3448. WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
  3449. val = I915_READ(GEN6_PMIMR);
  3450. WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
  3451. dev_priv->pm.irqs_disabled = false;
  3452. ironlake_enable_display_irq(dev_priv, ~dev_priv->pm.regsave.deimr);
  3453. ibx_enable_display_interrupt(dev_priv, ~dev_priv->pm.regsave.sdeimr);
  3454. ilk_enable_gt_irq(dev_priv, ~dev_priv->pm.regsave.gtimr);
  3455. snb_enable_pm_irq(dev_priv, ~dev_priv->pm.regsave.gen6_pmimr);
  3456. I915_WRITE(GTIER, dev_priv->pm.regsave.gtier);
  3457. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3458. }