i915_irq.c 123 KB

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