i915_irq.c 127 KB

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