i915_irq.c 126 KB

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