i915_irq.c 127 KB

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