i915_irq.c 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538
  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. bool long_hpd;
  1206. if (!(hpd[i] & hotplug_trigger))
  1207. continue;
  1208. port = get_port_from_pin(i);
  1209. if (!port || !dev_priv->hotplug.irq_port[port])
  1210. continue;
  1211. if (!HAS_GMCH_DISPLAY(dev_priv)) {
  1212. dig_shift = pch_port_to_hotplug_shift(port);
  1213. long_hpd = (dig_hotplug_reg >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
  1214. } else {
  1215. dig_shift = i915_port_to_hotplug_shift(port);
  1216. long_hpd = (hotplug_trigger >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
  1217. }
  1218. DRM_DEBUG_DRIVER("digital hpd port %c - %s\n", port_name(port),
  1219. long_hpd ? "long" : "short");
  1220. /*
  1221. * For long HPD pulses we want to have the digital queue happen,
  1222. * but we still want HPD storm detection to function.
  1223. */
  1224. if (long_hpd) {
  1225. dev_priv->hotplug.long_port_mask |= (1 << port);
  1226. dig_port_mask |= hpd[i];
  1227. } else {
  1228. /* for short HPD just trigger the digital queue */
  1229. dev_priv->hotplug.short_port_mask |= (1 << port);
  1230. hotplug_trigger &= ~hpd[i];
  1231. }
  1232. queue_dig = true;
  1233. }
  1234. for_each_hpd_pin(i) {
  1235. if (!(hpd[i] & hotplug_trigger))
  1236. continue;
  1237. if (dev_priv->hotplug.stats[i].state == HPD_DISABLED) {
  1238. /*
  1239. * On GMCH platforms the interrupt mask bits only
  1240. * prevent irq generation, not the setting of the
  1241. * hotplug bits itself. So only WARN about unexpected
  1242. * interrupts on saner platforms.
  1243. */
  1244. WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev),
  1245. "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
  1246. hotplug_trigger, i, hpd[i]);
  1247. continue;
  1248. }
  1249. if (dev_priv->hotplug.stats[i].state != HPD_ENABLED)
  1250. continue;
  1251. if (!(dig_port_mask & hpd[i])) {
  1252. dev_priv->hotplug.event_bits |= (1 << i);
  1253. queue_hp = true;
  1254. }
  1255. if (!time_in_range(jiffies, dev_priv->hotplug.stats[i].last_jiffies,
  1256. dev_priv->hotplug.stats[i].last_jiffies
  1257. + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
  1258. dev_priv->hotplug.stats[i].last_jiffies = jiffies;
  1259. dev_priv->hotplug.stats[i].count = 0;
  1260. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
  1261. } else if (dev_priv->hotplug.stats[i].count > HPD_STORM_THRESHOLD) {
  1262. dev_priv->hotplug.stats[i].state = HPD_MARK_DISABLED;
  1263. dev_priv->hotplug.event_bits &= ~(1 << i);
  1264. DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
  1265. storm_detected = true;
  1266. } else {
  1267. dev_priv->hotplug.stats[i].count++;
  1268. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
  1269. dev_priv->hotplug.stats[i].count);
  1270. }
  1271. }
  1272. if (storm_detected)
  1273. dev_priv->display.hpd_irq_setup(dev);
  1274. spin_unlock(&dev_priv->irq_lock);
  1275. /*
  1276. * Our hotplug handler can grab modeset locks (by calling down into the
  1277. * fb helpers). Hence it must not be run on our own dev-priv->wq work
  1278. * queue for otherwise the flush_work in the pageflip code will
  1279. * deadlock.
  1280. */
  1281. if (queue_dig)
  1282. queue_work(dev_priv->hotplug.dp_wq, &dev_priv->hotplug.dig_port_work);
  1283. if (queue_hp)
  1284. schedule_work(&dev_priv->hotplug.hotplug_work);
  1285. }
  1286. static void gmbus_irq_handler(struct drm_device *dev)
  1287. {
  1288. struct drm_i915_private *dev_priv = dev->dev_private;
  1289. wake_up_all(&dev_priv->gmbus_wait_queue);
  1290. }
  1291. static void dp_aux_irq_handler(struct drm_device *dev)
  1292. {
  1293. struct drm_i915_private *dev_priv = dev->dev_private;
  1294. wake_up_all(&dev_priv->gmbus_wait_queue);
  1295. }
  1296. #if defined(CONFIG_DEBUG_FS)
  1297. static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1298. uint32_t crc0, uint32_t crc1,
  1299. uint32_t crc2, uint32_t crc3,
  1300. uint32_t crc4)
  1301. {
  1302. struct drm_i915_private *dev_priv = dev->dev_private;
  1303. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
  1304. struct intel_pipe_crc_entry *entry;
  1305. int head, tail;
  1306. spin_lock(&pipe_crc->lock);
  1307. if (!pipe_crc->entries) {
  1308. spin_unlock(&pipe_crc->lock);
  1309. DRM_DEBUG_KMS("spurious interrupt\n");
  1310. return;
  1311. }
  1312. head = pipe_crc->head;
  1313. tail = pipe_crc->tail;
  1314. if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
  1315. spin_unlock(&pipe_crc->lock);
  1316. DRM_ERROR("CRC buffer overflowing\n");
  1317. return;
  1318. }
  1319. entry = &pipe_crc->entries[head];
  1320. entry->frame = dev->driver->get_vblank_counter(dev, pipe);
  1321. entry->crc[0] = crc0;
  1322. entry->crc[1] = crc1;
  1323. entry->crc[2] = crc2;
  1324. entry->crc[3] = crc3;
  1325. entry->crc[4] = crc4;
  1326. head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
  1327. pipe_crc->head = head;
  1328. spin_unlock(&pipe_crc->lock);
  1329. wake_up_interruptible(&pipe_crc->wq);
  1330. }
  1331. #else
  1332. static inline void
  1333. display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1334. uint32_t crc0, uint32_t crc1,
  1335. uint32_t crc2, uint32_t crc3,
  1336. uint32_t crc4) {}
  1337. #endif
  1338. static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1339. {
  1340. struct drm_i915_private *dev_priv = dev->dev_private;
  1341. display_pipe_crc_irq_handler(dev, pipe,
  1342. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1343. 0, 0, 0, 0);
  1344. }
  1345. static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1346. {
  1347. struct drm_i915_private *dev_priv = dev->dev_private;
  1348. display_pipe_crc_irq_handler(dev, pipe,
  1349. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1350. I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
  1351. I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
  1352. I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
  1353. I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
  1354. }
  1355. static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1356. {
  1357. struct drm_i915_private *dev_priv = dev->dev_private;
  1358. uint32_t res1, res2;
  1359. if (INTEL_INFO(dev)->gen >= 3)
  1360. res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
  1361. else
  1362. res1 = 0;
  1363. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  1364. res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
  1365. else
  1366. res2 = 0;
  1367. display_pipe_crc_irq_handler(dev, pipe,
  1368. I915_READ(PIPE_CRC_RES_RED(pipe)),
  1369. I915_READ(PIPE_CRC_RES_GREEN(pipe)),
  1370. I915_READ(PIPE_CRC_RES_BLUE(pipe)),
  1371. res1, res2);
  1372. }
  1373. /* The RPS events need forcewake, so we add them to a work queue and mask their
  1374. * IMR bits until the work is done. Other interrupts can be processed without
  1375. * the work queue. */
  1376. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
  1377. {
  1378. if (pm_iir & dev_priv->pm_rps_events) {
  1379. spin_lock(&dev_priv->irq_lock);
  1380. gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
  1381. if (dev_priv->rps.interrupts_enabled) {
  1382. dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
  1383. queue_work(dev_priv->wq, &dev_priv->rps.work);
  1384. }
  1385. spin_unlock(&dev_priv->irq_lock);
  1386. }
  1387. if (INTEL_INFO(dev_priv)->gen >= 8)
  1388. return;
  1389. if (HAS_VEBOX(dev_priv->dev)) {
  1390. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  1391. notify_ring(&dev_priv->ring[VECS]);
  1392. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
  1393. DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
  1394. }
  1395. }
  1396. static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
  1397. {
  1398. if (!drm_handle_vblank(dev, pipe))
  1399. return false;
  1400. return true;
  1401. }
  1402. static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
  1403. {
  1404. struct drm_i915_private *dev_priv = dev->dev_private;
  1405. u32 pipe_stats[I915_MAX_PIPES] = { };
  1406. int pipe;
  1407. spin_lock(&dev_priv->irq_lock);
  1408. for_each_pipe(dev_priv, pipe) {
  1409. int reg;
  1410. u32 mask, iir_bit = 0;
  1411. /*
  1412. * PIPESTAT bits get signalled even when the interrupt is
  1413. * disabled with the mask bits, and some of the status bits do
  1414. * not generate interrupts at all (like the underrun bit). Hence
  1415. * we need to be careful that we only handle what we want to
  1416. * handle.
  1417. */
  1418. /* fifo underruns are filterered in the underrun handler. */
  1419. mask = PIPE_FIFO_UNDERRUN_STATUS;
  1420. switch (pipe) {
  1421. case PIPE_A:
  1422. iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
  1423. break;
  1424. case PIPE_B:
  1425. iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  1426. break;
  1427. case PIPE_C:
  1428. iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  1429. break;
  1430. }
  1431. if (iir & iir_bit)
  1432. mask |= dev_priv->pipestat_irq_mask[pipe];
  1433. if (!mask)
  1434. continue;
  1435. reg = PIPESTAT(pipe);
  1436. mask |= PIPESTAT_INT_ENABLE_MASK;
  1437. pipe_stats[pipe] = I915_READ(reg) & mask;
  1438. /*
  1439. * Clear the PIPE*STAT regs before the IIR
  1440. */
  1441. if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
  1442. PIPESTAT_INT_STATUS_MASK))
  1443. I915_WRITE(reg, pipe_stats[pipe]);
  1444. }
  1445. spin_unlock(&dev_priv->irq_lock);
  1446. for_each_pipe(dev_priv, pipe) {
  1447. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  1448. intel_pipe_handle_vblank(dev, pipe))
  1449. intel_check_page_flip(dev, pipe);
  1450. if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
  1451. intel_prepare_page_flip(dev, pipe);
  1452. intel_finish_page_flip(dev, pipe);
  1453. }
  1454. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1455. i9xx_pipe_crc_irq_handler(dev, pipe);
  1456. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1457. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1458. }
  1459. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  1460. gmbus_irq_handler(dev);
  1461. }
  1462. static void i9xx_hpd_irq_handler(struct drm_device *dev)
  1463. {
  1464. struct drm_i915_private *dev_priv = dev->dev_private;
  1465. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1466. if (!hotplug_status)
  1467. return;
  1468. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1469. /*
  1470. * Make sure hotplug status is cleared before we clear IIR, or else we
  1471. * may miss hotplug events.
  1472. */
  1473. POSTING_READ(PORT_HOTPLUG_STAT);
  1474. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  1475. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
  1476. intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_g4x);
  1477. if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
  1478. dp_aux_irq_handler(dev);
  1479. } else {
  1480. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  1481. intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_i915);
  1482. }
  1483. }
  1484. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  1485. {
  1486. struct drm_device *dev = arg;
  1487. struct drm_i915_private *dev_priv = dev->dev_private;
  1488. u32 iir, gt_iir, pm_iir;
  1489. irqreturn_t ret = IRQ_NONE;
  1490. if (!intel_irqs_enabled(dev_priv))
  1491. return IRQ_NONE;
  1492. while (true) {
  1493. /* Find, clear, then process each source of interrupt */
  1494. gt_iir = I915_READ(GTIIR);
  1495. if (gt_iir)
  1496. I915_WRITE(GTIIR, gt_iir);
  1497. pm_iir = I915_READ(GEN6_PMIIR);
  1498. if (pm_iir)
  1499. I915_WRITE(GEN6_PMIIR, pm_iir);
  1500. iir = I915_READ(VLV_IIR);
  1501. if (iir) {
  1502. /* Consume port before clearing IIR or we'll miss events */
  1503. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  1504. i9xx_hpd_irq_handler(dev);
  1505. I915_WRITE(VLV_IIR, iir);
  1506. }
  1507. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  1508. goto out;
  1509. ret = IRQ_HANDLED;
  1510. if (gt_iir)
  1511. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1512. if (pm_iir)
  1513. gen6_rps_irq_handler(dev_priv, pm_iir);
  1514. /* Call regardless, as some status bits might not be
  1515. * signalled in iir */
  1516. valleyview_pipestat_irq_handler(dev, iir);
  1517. }
  1518. out:
  1519. return ret;
  1520. }
  1521. static irqreturn_t cherryview_irq_handler(int irq, void *arg)
  1522. {
  1523. struct drm_device *dev = arg;
  1524. struct drm_i915_private *dev_priv = dev->dev_private;
  1525. u32 master_ctl, iir;
  1526. irqreturn_t ret = IRQ_NONE;
  1527. if (!intel_irqs_enabled(dev_priv))
  1528. return IRQ_NONE;
  1529. for (;;) {
  1530. master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
  1531. iir = I915_READ(VLV_IIR);
  1532. if (master_ctl == 0 && iir == 0)
  1533. break;
  1534. ret = IRQ_HANDLED;
  1535. I915_WRITE(GEN8_MASTER_IRQ, 0);
  1536. /* Find, clear, then process each source of interrupt */
  1537. if (iir) {
  1538. /* Consume port before clearing IIR or we'll miss events */
  1539. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  1540. i9xx_hpd_irq_handler(dev);
  1541. I915_WRITE(VLV_IIR, iir);
  1542. }
  1543. gen8_gt_irq_handler(dev_priv, master_ctl);
  1544. /* Call regardless, as some status bits might not be
  1545. * signalled in iir */
  1546. valleyview_pipestat_irq_handler(dev, iir);
  1547. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  1548. POSTING_READ(GEN8_MASTER_IRQ);
  1549. }
  1550. return ret;
  1551. }
  1552. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  1553. {
  1554. struct drm_i915_private *dev_priv = dev->dev_private;
  1555. int pipe;
  1556. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  1557. u32 dig_hotplug_reg;
  1558. dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
  1559. I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1560. intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_ibx);
  1561. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  1562. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  1563. SDE_AUDIO_POWER_SHIFT);
  1564. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  1565. port_name(port));
  1566. }
  1567. if (pch_iir & SDE_AUX_MASK)
  1568. dp_aux_irq_handler(dev);
  1569. if (pch_iir & SDE_GMBUS)
  1570. gmbus_irq_handler(dev);
  1571. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  1572. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  1573. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  1574. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  1575. if (pch_iir & SDE_POISON)
  1576. DRM_ERROR("PCH poison interrupt\n");
  1577. if (pch_iir & SDE_FDI_MASK)
  1578. for_each_pipe(dev_priv, pipe)
  1579. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1580. pipe_name(pipe),
  1581. I915_READ(FDI_RX_IIR(pipe)));
  1582. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  1583. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  1584. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  1585. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  1586. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  1587. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
  1588. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  1589. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
  1590. }
  1591. static void ivb_err_int_handler(struct drm_device *dev)
  1592. {
  1593. struct drm_i915_private *dev_priv = dev->dev_private;
  1594. u32 err_int = I915_READ(GEN7_ERR_INT);
  1595. enum pipe pipe;
  1596. if (err_int & ERR_INT_POISON)
  1597. DRM_ERROR("Poison interrupt\n");
  1598. for_each_pipe(dev_priv, pipe) {
  1599. if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
  1600. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1601. if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
  1602. if (IS_IVYBRIDGE(dev))
  1603. ivb_pipe_crc_irq_handler(dev, pipe);
  1604. else
  1605. hsw_pipe_crc_irq_handler(dev, pipe);
  1606. }
  1607. }
  1608. I915_WRITE(GEN7_ERR_INT, err_int);
  1609. }
  1610. static void cpt_serr_int_handler(struct drm_device *dev)
  1611. {
  1612. struct drm_i915_private *dev_priv = dev->dev_private;
  1613. u32 serr_int = I915_READ(SERR_INT);
  1614. if (serr_int & SERR_INT_POISON)
  1615. DRM_ERROR("PCH poison interrupt\n");
  1616. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  1617. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
  1618. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  1619. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
  1620. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  1621. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
  1622. I915_WRITE(SERR_INT, serr_int);
  1623. }
  1624. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  1625. {
  1626. struct drm_i915_private *dev_priv = dev->dev_private;
  1627. int pipe;
  1628. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  1629. u32 dig_hotplug_reg;
  1630. dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
  1631. I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1632. intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_cpt);
  1633. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  1634. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  1635. SDE_AUDIO_POWER_SHIFT_CPT);
  1636. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  1637. port_name(port));
  1638. }
  1639. if (pch_iir & SDE_AUX_MASK_CPT)
  1640. dp_aux_irq_handler(dev);
  1641. if (pch_iir & SDE_GMBUS_CPT)
  1642. gmbus_irq_handler(dev);
  1643. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  1644. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  1645. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  1646. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  1647. if (pch_iir & SDE_FDI_MASK_CPT)
  1648. for_each_pipe(dev_priv, pipe)
  1649. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1650. pipe_name(pipe),
  1651. I915_READ(FDI_RX_IIR(pipe)));
  1652. if (pch_iir & SDE_ERROR_CPT)
  1653. cpt_serr_int_handler(dev);
  1654. }
  1655. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1656. {
  1657. struct drm_i915_private *dev_priv = dev->dev_private;
  1658. enum pipe pipe;
  1659. if (de_iir & DE_AUX_CHANNEL_A)
  1660. dp_aux_irq_handler(dev);
  1661. if (de_iir & DE_GSE)
  1662. intel_opregion_asle_intr(dev);
  1663. if (de_iir & DE_POISON)
  1664. DRM_ERROR("Poison interrupt\n");
  1665. for_each_pipe(dev_priv, pipe) {
  1666. if (de_iir & DE_PIPE_VBLANK(pipe) &&
  1667. intel_pipe_handle_vblank(dev, pipe))
  1668. intel_check_page_flip(dev, pipe);
  1669. if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
  1670. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1671. if (de_iir & DE_PIPE_CRC_DONE(pipe))
  1672. i9xx_pipe_crc_irq_handler(dev, pipe);
  1673. /* plane/pipes map 1:1 on ilk+ */
  1674. if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
  1675. intel_prepare_page_flip(dev, pipe);
  1676. intel_finish_page_flip_plane(dev, pipe);
  1677. }
  1678. }
  1679. /* check event from PCH */
  1680. if (de_iir & DE_PCH_EVENT) {
  1681. u32 pch_iir = I915_READ(SDEIIR);
  1682. if (HAS_PCH_CPT(dev))
  1683. cpt_irq_handler(dev, pch_iir);
  1684. else
  1685. ibx_irq_handler(dev, pch_iir);
  1686. /* should clear PCH hotplug event before clear CPU irq */
  1687. I915_WRITE(SDEIIR, pch_iir);
  1688. }
  1689. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1690. ironlake_rps_change_irq_handler(dev);
  1691. }
  1692. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1693. {
  1694. struct drm_i915_private *dev_priv = dev->dev_private;
  1695. enum pipe pipe;
  1696. if (de_iir & DE_ERR_INT_IVB)
  1697. ivb_err_int_handler(dev);
  1698. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1699. dp_aux_irq_handler(dev);
  1700. if (de_iir & DE_GSE_IVB)
  1701. intel_opregion_asle_intr(dev);
  1702. for_each_pipe(dev_priv, pipe) {
  1703. if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
  1704. intel_pipe_handle_vblank(dev, pipe))
  1705. intel_check_page_flip(dev, pipe);
  1706. /* plane/pipes map 1:1 on ilk+ */
  1707. if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
  1708. intel_prepare_page_flip(dev, pipe);
  1709. intel_finish_page_flip_plane(dev, pipe);
  1710. }
  1711. }
  1712. /* check event from PCH */
  1713. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1714. u32 pch_iir = I915_READ(SDEIIR);
  1715. cpt_irq_handler(dev, pch_iir);
  1716. /* clear PCH hotplug event before clear CPU irq */
  1717. I915_WRITE(SDEIIR, pch_iir);
  1718. }
  1719. }
  1720. /*
  1721. * To handle irqs with the minimum potential races with fresh interrupts, we:
  1722. * 1 - Disable Master Interrupt Control.
  1723. * 2 - Find the source(s) of the interrupt.
  1724. * 3 - Clear the Interrupt Identity bits (IIR).
  1725. * 4 - Process the interrupt(s) that had bits set in the IIRs.
  1726. * 5 - Re-enable Master Interrupt Control.
  1727. */
  1728. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1729. {
  1730. struct drm_device *dev = arg;
  1731. struct drm_i915_private *dev_priv = dev->dev_private;
  1732. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1733. irqreturn_t ret = IRQ_NONE;
  1734. if (!intel_irqs_enabled(dev_priv))
  1735. return IRQ_NONE;
  1736. /* We get interrupts on unclaimed registers, so check for this before we
  1737. * do any I915_{READ,WRITE}. */
  1738. intel_uncore_check_errors(dev);
  1739. /* disable master interrupt before clearing iir */
  1740. de_ier = I915_READ(DEIER);
  1741. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1742. POSTING_READ(DEIER);
  1743. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1744. * interrupts will will be stored on its back queue, and then we'll be
  1745. * able to process them after we restore SDEIER (as soon as we restore
  1746. * it, we'll get an interrupt if SDEIIR still has something to process
  1747. * due to its back queue). */
  1748. if (!HAS_PCH_NOP(dev)) {
  1749. sde_ier = I915_READ(SDEIER);
  1750. I915_WRITE(SDEIER, 0);
  1751. POSTING_READ(SDEIER);
  1752. }
  1753. /* Find, clear, then process each source of interrupt */
  1754. gt_iir = I915_READ(GTIIR);
  1755. if (gt_iir) {
  1756. I915_WRITE(GTIIR, gt_iir);
  1757. ret = IRQ_HANDLED;
  1758. if (INTEL_INFO(dev)->gen >= 6)
  1759. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1760. else
  1761. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1762. }
  1763. de_iir = I915_READ(DEIIR);
  1764. if (de_iir) {
  1765. I915_WRITE(DEIIR, de_iir);
  1766. ret = IRQ_HANDLED;
  1767. if (INTEL_INFO(dev)->gen >= 7)
  1768. ivb_display_irq_handler(dev, de_iir);
  1769. else
  1770. ilk_display_irq_handler(dev, de_iir);
  1771. }
  1772. if (INTEL_INFO(dev)->gen >= 6) {
  1773. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1774. if (pm_iir) {
  1775. I915_WRITE(GEN6_PMIIR, pm_iir);
  1776. ret = IRQ_HANDLED;
  1777. gen6_rps_irq_handler(dev_priv, pm_iir);
  1778. }
  1779. }
  1780. I915_WRITE(DEIER, de_ier);
  1781. POSTING_READ(DEIER);
  1782. if (!HAS_PCH_NOP(dev)) {
  1783. I915_WRITE(SDEIER, sde_ier);
  1784. POSTING_READ(SDEIER);
  1785. }
  1786. return ret;
  1787. }
  1788. static void bxt_hpd_handler(struct drm_device *dev, uint32_t iir_status)
  1789. {
  1790. struct drm_i915_private *dev_priv = dev->dev_private;
  1791. uint32_t hp_control;
  1792. uint32_t hp_trigger;
  1793. /* Get the status */
  1794. hp_trigger = iir_status & BXT_DE_PORT_HOTPLUG_MASK;
  1795. hp_control = I915_READ(BXT_HOTPLUG_CTL);
  1796. /* Hotplug not enabled ? */
  1797. if (!(hp_control & BXT_HOTPLUG_CTL_MASK)) {
  1798. DRM_ERROR("Interrupt when HPD disabled\n");
  1799. return;
  1800. }
  1801. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  1802. hp_control & BXT_HOTPLUG_CTL_MASK);
  1803. /* Check for HPD storm and schedule bottom half */
  1804. intel_hpd_irq_handler(dev, hp_trigger, hp_control, hpd_bxt);
  1805. /*
  1806. * FIXME: Save the hot plug status for bottom half before
  1807. * clearing the sticky status bits, else the status will be
  1808. * lost.
  1809. */
  1810. /* Clear sticky bits in hpd status */
  1811. I915_WRITE(BXT_HOTPLUG_CTL, hp_control);
  1812. }
  1813. static irqreturn_t gen8_irq_handler(int irq, void *arg)
  1814. {
  1815. struct drm_device *dev = arg;
  1816. struct drm_i915_private *dev_priv = dev->dev_private;
  1817. u32 master_ctl;
  1818. irqreturn_t ret = IRQ_NONE;
  1819. uint32_t tmp = 0;
  1820. enum pipe pipe;
  1821. u32 aux_mask = GEN8_AUX_CHANNEL_A;
  1822. if (!intel_irqs_enabled(dev_priv))
  1823. return IRQ_NONE;
  1824. if (IS_GEN9(dev))
  1825. aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
  1826. GEN9_AUX_CHANNEL_D;
  1827. master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
  1828. master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
  1829. if (!master_ctl)
  1830. return IRQ_NONE;
  1831. I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
  1832. /* Find, clear, then process each source of interrupt */
  1833. ret = gen8_gt_irq_handler(dev_priv, master_ctl);
  1834. if (master_ctl & GEN8_DE_MISC_IRQ) {
  1835. tmp = I915_READ(GEN8_DE_MISC_IIR);
  1836. if (tmp) {
  1837. I915_WRITE(GEN8_DE_MISC_IIR, tmp);
  1838. ret = IRQ_HANDLED;
  1839. if (tmp & GEN8_DE_MISC_GSE)
  1840. intel_opregion_asle_intr(dev);
  1841. else
  1842. DRM_ERROR("Unexpected DE Misc interrupt\n");
  1843. }
  1844. else
  1845. DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
  1846. }
  1847. if (master_ctl & GEN8_DE_PORT_IRQ) {
  1848. tmp = I915_READ(GEN8_DE_PORT_IIR);
  1849. if (tmp) {
  1850. bool found = false;
  1851. I915_WRITE(GEN8_DE_PORT_IIR, tmp);
  1852. ret = IRQ_HANDLED;
  1853. if (tmp & aux_mask) {
  1854. dp_aux_irq_handler(dev);
  1855. found = true;
  1856. }
  1857. if (IS_BROXTON(dev) && tmp & BXT_DE_PORT_HOTPLUG_MASK) {
  1858. bxt_hpd_handler(dev, tmp);
  1859. found = true;
  1860. }
  1861. if (IS_BROXTON(dev) && (tmp & BXT_DE_PORT_GMBUS)) {
  1862. gmbus_irq_handler(dev);
  1863. found = true;
  1864. }
  1865. if (!found)
  1866. DRM_ERROR("Unexpected DE Port interrupt\n");
  1867. }
  1868. else
  1869. DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
  1870. }
  1871. for_each_pipe(dev_priv, pipe) {
  1872. uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
  1873. if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
  1874. continue;
  1875. pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
  1876. if (pipe_iir) {
  1877. ret = IRQ_HANDLED;
  1878. I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
  1879. if (pipe_iir & GEN8_PIPE_VBLANK &&
  1880. intel_pipe_handle_vblank(dev, pipe))
  1881. intel_check_page_flip(dev, pipe);
  1882. if (IS_GEN9(dev))
  1883. flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
  1884. else
  1885. flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
  1886. if (flip_done) {
  1887. intel_prepare_page_flip(dev, pipe);
  1888. intel_finish_page_flip_plane(dev, pipe);
  1889. }
  1890. if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
  1891. hsw_pipe_crc_irq_handler(dev, pipe);
  1892. if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN)
  1893. intel_cpu_fifo_underrun_irq_handler(dev_priv,
  1894. pipe);
  1895. if (IS_GEN9(dev))
  1896. fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
  1897. else
  1898. fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  1899. if (fault_errors)
  1900. DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
  1901. pipe_name(pipe),
  1902. pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
  1903. } else
  1904. DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
  1905. }
  1906. if (HAS_PCH_SPLIT(dev) && !HAS_PCH_NOP(dev) &&
  1907. master_ctl & GEN8_DE_PCH_IRQ) {
  1908. /*
  1909. * FIXME(BDW): Assume for now that the new interrupt handling
  1910. * scheme also closed the SDE interrupt handling race we've seen
  1911. * on older pch-split platforms. But this needs testing.
  1912. */
  1913. u32 pch_iir = I915_READ(SDEIIR);
  1914. if (pch_iir) {
  1915. I915_WRITE(SDEIIR, pch_iir);
  1916. ret = IRQ_HANDLED;
  1917. cpt_irq_handler(dev, pch_iir);
  1918. } else
  1919. DRM_ERROR("The master control interrupt lied (SDE)!\n");
  1920. }
  1921. I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
  1922. POSTING_READ_FW(GEN8_MASTER_IRQ);
  1923. return ret;
  1924. }
  1925. static void i915_error_wake_up(struct drm_i915_private *dev_priv,
  1926. bool reset_completed)
  1927. {
  1928. struct intel_engine_cs *ring;
  1929. int i;
  1930. /*
  1931. * Notify all waiters for GPU completion events that reset state has
  1932. * been changed, and that they need to restart their wait after
  1933. * checking for potential errors (and bail out to drop locks if there is
  1934. * a gpu reset pending so that i915_error_work_func can acquire them).
  1935. */
  1936. /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
  1937. for_each_ring(ring, dev_priv, i)
  1938. wake_up_all(&ring->irq_queue);
  1939. /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
  1940. wake_up_all(&dev_priv->pending_flip_queue);
  1941. /*
  1942. * Signal tasks blocked in i915_gem_wait_for_error that the pending
  1943. * reset state is cleared.
  1944. */
  1945. if (reset_completed)
  1946. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1947. }
  1948. /**
  1949. * i915_reset_and_wakeup - do process context error handling work
  1950. *
  1951. * Fire an error uevent so userspace can see that a hang or error
  1952. * was detected.
  1953. */
  1954. static void i915_reset_and_wakeup(struct drm_device *dev)
  1955. {
  1956. struct drm_i915_private *dev_priv = to_i915(dev);
  1957. struct i915_gpu_error *error = &dev_priv->gpu_error;
  1958. char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
  1959. char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
  1960. char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
  1961. int ret;
  1962. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
  1963. /*
  1964. * Note that there's only one work item which does gpu resets, so we
  1965. * need not worry about concurrent gpu resets potentially incrementing
  1966. * error->reset_counter twice. We only need to take care of another
  1967. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1968. * quick check for that is good enough: schedule_work ensures the
  1969. * correct ordering between hang detection and this work item, and since
  1970. * the reset in-progress bit is only ever set by code outside of this
  1971. * work we don't need to worry about any other races.
  1972. */
  1973. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1974. DRM_DEBUG_DRIVER("resetting chip\n");
  1975. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
  1976. reset_event);
  1977. /*
  1978. * In most cases it's guaranteed that we get here with an RPM
  1979. * reference held, for example because there is a pending GPU
  1980. * request that won't finish until the reset is done. This
  1981. * isn't the case at least when we get here by doing a
  1982. * simulated reset via debugs, so get an RPM reference.
  1983. */
  1984. intel_runtime_pm_get(dev_priv);
  1985. intel_prepare_reset(dev);
  1986. /*
  1987. * All state reset _must_ be completed before we update the
  1988. * reset counter, for otherwise waiters might miss the reset
  1989. * pending state and not properly drop locks, resulting in
  1990. * deadlocks with the reset work.
  1991. */
  1992. ret = i915_reset(dev);
  1993. intel_finish_reset(dev);
  1994. intel_runtime_pm_put(dev_priv);
  1995. if (ret == 0) {
  1996. /*
  1997. * After all the gem state is reset, increment the reset
  1998. * counter and wake up everyone waiting for the reset to
  1999. * complete.
  2000. *
  2001. * Since unlock operations are a one-sided barrier only,
  2002. * we need to insert a barrier here to order any seqno
  2003. * updates before
  2004. * the counter increment.
  2005. */
  2006. smp_mb__before_atomic();
  2007. atomic_inc(&dev_priv->gpu_error.reset_counter);
  2008. kobject_uevent_env(&dev->primary->kdev->kobj,
  2009. KOBJ_CHANGE, reset_done_event);
  2010. } else {
  2011. atomic_set_mask(I915_WEDGED, &error->reset_counter);
  2012. }
  2013. /*
  2014. * Note: The wake_up also serves as a memory barrier so that
  2015. * waiters see the update value of the reset counter atomic_t.
  2016. */
  2017. i915_error_wake_up(dev_priv, true);
  2018. }
  2019. }
  2020. static void i915_report_and_clear_eir(struct drm_device *dev)
  2021. {
  2022. struct drm_i915_private *dev_priv = dev->dev_private;
  2023. uint32_t instdone[I915_NUM_INSTDONE_REG];
  2024. u32 eir = I915_READ(EIR);
  2025. int pipe, i;
  2026. if (!eir)
  2027. return;
  2028. pr_err("render error detected, EIR: 0x%08x\n", eir);
  2029. i915_get_extra_instdone(dev, instdone);
  2030. if (IS_G4X(dev)) {
  2031. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  2032. u32 ipeir = I915_READ(IPEIR_I965);
  2033. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  2034. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  2035. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  2036. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  2037. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  2038. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  2039. I915_WRITE(IPEIR_I965, ipeir);
  2040. POSTING_READ(IPEIR_I965);
  2041. }
  2042. if (eir & GM45_ERROR_PAGE_TABLE) {
  2043. u32 pgtbl_err = I915_READ(PGTBL_ER);
  2044. pr_err("page table error\n");
  2045. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  2046. I915_WRITE(PGTBL_ER, pgtbl_err);
  2047. POSTING_READ(PGTBL_ER);
  2048. }
  2049. }
  2050. if (!IS_GEN2(dev)) {
  2051. if (eir & I915_ERROR_PAGE_TABLE) {
  2052. u32 pgtbl_err = I915_READ(PGTBL_ER);
  2053. pr_err("page table error\n");
  2054. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  2055. I915_WRITE(PGTBL_ER, pgtbl_err);
  2056. POSTING_READ(PGTBL_ER);
  2057. }
  2058. }
  2059. if (eir & I915_ERROR_MEMORY_REFRESH) {
  2060. pr_err("memory refresh error:\n");
  2061. for_each_pipe(dev_priv, pipe)
  2062. pr_err("pipe %c stat: 0x%08x\n",
  2063. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  2064. /* pipestat has already been acked */
  2065. }
  2066. if (eir & I915_ERROR_INSTRUCTION) {
  2067. pr_err("instruction error\n");
  2068. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  2069. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  2070. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  2071. if (INTEL_INFO(dev)->gen < 4) {
  2072. u32 ipeir = I915_READ(IPEIR);
  2073. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  2074. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  2075. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  2076. I915_WRITE(IPEIR, ipeir);
  2077. POSTING_READ(IPEIR);
  2078. } else {
  2079. u32 ipeir = I915_READ(IPEIR_I965);
  2080. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  2081. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  2082. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  2083. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  2084. I915_WRITE(IPEIR_I965, ipeir);
  2085. POSTING_READ(IPEIR_I965);
  2086. }
  2087. }
  2088. I915_WRITE(EIR, eir);
  2089. POSTING_READ(EIR);
  2090. eir = I915_READ(EIR);
  2091. if (eir) {
  2092. /*
  2093. * some errors might have become stuck,
  2094. * mask them.
  2095. */
  2096. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  2097. I915_WRITE(EMR, I915_READ(EMR) | eir);
  2098. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2099. }
  2100. }
  2101. /**
  2102. * i915_handle_error - handle a gpu error
  2103. * @dev: drm device
  2104. *
  2105. * Do some basic checking of regsiter state at error time and
  2106. * dump it to the syslog. Also call i915_capture_error_state() to make
  2107. * sure we get a record and make it available in debugfs. Fire a uevent
  2108. * so userspace knows something bad happened (should trigger collection
  2109. * of a ring dump etc.).
  2110. */
  2111. void i915_handle_error(struct drm_device *dev, bool wedged,
  2112. const char *fmt, ...)
  2113. {
  2114. struct drm_i915_private *dev_priv = dev->dev_private;
  2115. va_list args;
  2116. char error_msg[80];
  2117. va_start(args, fmt);
  2118. vscnprintf(error_msg, sizeof(error_msg), fmt, args);
  2119. va_end(args);
  2120. i915_capture_error_state(dev, wedged, error_msg);
  2121. i915_report_and_clear_eir(dev);
  2122. if (wedged) {
  2123. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  2124. &dev_priv->gpu_error.reset_counter);
  2125. /*
  2126. * Wakeup waiting processes so that the reset function
  2127. * i915_reset_and_wakeup doesn't deadlock trying to grab
  2128. * various locks. By bumping the reset counter first, the woken
  2129. * processes will see a reset in progress and back off,
  2130. * releasing their locks and then wait for the reset completion.
  2131. * We must do this for _all_ gpu waiters that might hold locks
  2132. * that the reset work needs to acquire.
  2133. *
  2134. * Note: The wake_up serves as the required memory barrier to
  2135. * ensure that the waiters see the updated value of the reset
  2136. * counter atomic_t.
  2137. */
  2138. i915_error_wake_up(dev_priv, false);
  2139. }
  2140. i915_reset_and_wakeup(dev);
  2141. }
  2142. /* Called from drm generic code, passed 'crtc' which
  2143. * we use as a pipe index
  2144. */
  2145. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  2146. {
  2147. struct drm_i915_private *dev_priv = dev->dev_private;
  2148. unsigned long irqflags;
  2149. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2150. if (INTEL_INFO(dev)->gen >= 4)
  2151. i915_enable_pipestat(dev_priv, pipe,
  2152. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2153. else
  2154. i915_enable_pipestat(dev_priv, pipe,
  2155. PIPE_VBLANK_INTERRUPT_STATUS);
  2156. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2157. return 0;
  2158. }
  2159. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  2160. {
  2161. struct drm_i915_private *dev_priv = dev->dev_private;
  2162. unsigned long irqflags;
  2163. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2164. DE_PIPE_VBLANK(pipe);
  2165. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2166. ironlake_enable_display_irq(dev_priv, bit);
  2167. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2168. return 0;
  2169. }
  2170. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  2171. {
  2172. struct drm_i915_private *dev_priv = dev->dev_private;
  2173. unsigned long irqflags;
  2174. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2175. i915_enable_pipestat(dev_priv, pipe,
  2176. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2177. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2178. return 0;
  2179. }
  2180. static int gen8_enable_vblank(struct drm_device *dev, int pipe)
  2181. {
  2182. struct drm_i915_private *dev_priv = dev->dev_private;
  2183. unsigned long irqflags;
  2184. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2185. dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
  2186. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2187. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2188. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2189. return 0;
  2190. }
  2191. /* Called from drm generic code, passed 'crtc' which
  2192. * we use as a pipe index
  2193. */
  2194. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  2195. {
  2196. struct drm_i915_private *dev_priv = dev->dev_private;
  2197. unsigned long irqflags;
  2198. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2199. i915_disable_pipestat(dev_priv, pipe,
  2200. PIPE_VBLANK_INTERRUPT_STATUS |
  2201. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2202. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2203. }
  2204. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  2205. {
  2206. struct drm_i915_private *dev_priv = dev->dev_private;
  2207. unsigned long irqflags;
  2208. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2209. DE_PIPE_VBLANK(pipe);
  2210. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2211. ironlake_disable_display_irq(dev_priv, bit);
  2212. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2213. }
  2214. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  2215. {
  2216. struct drm_i915_private *dev_priv = dev->dev_private;
  2217. unsigned long irqflags;
  2218. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2219. i915_disable_pipestat(dev_priv, pipe,
  2220. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2221. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2222. }
  2223. static void gen8_disable_vblank(struct drm_device *dev, int pipe)
  2224. {
  2225. struct drm_i915_private *dev_priv = dev->dev_private;
  2226. unsigned long irqflags;
  2227. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2228. dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
  2229. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2230. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2231. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2232. }
  2233. static struct drm_i915_gem_request *
  2234. ring_last_request(struct intel_engine_cs *ring)
  2235. {
  2236. return list_entry(ring->request_list.prev,
  2237. struct drm_i915_gem_request, list);
  2238. }
  2239. static bool
  2240. ring_idle(struct intel_engine_cs *ring)
  2241. {
  2242. return (list_empty(&ring->request_list) ||
  2243. i915_gem_request_completed(ring_last_request(ring), false));
  2244. }
  2245. static bool
  2246. ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
  2247. {
  2248. if (INTEL_INFO(dev)->gen >= 8) {
  2249. return (ipehr >> 23) == 0x1c;
  2250. } else {
  2251. ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
  2252. return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
  2253. MI_SEMAPHORE_REGISTER);
  2254. }
  2255. }
  2256. static struct intel_engine_cs *
  2257. semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
  2258. {
  2259. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2260. struct intel_engine_cs *signaller;
  2261. int i;
  2262. if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
  2263. for_each_ring(signaller, dev_priv, i) {
  2264. if (ring == signaller)
  2265. continue;
  2266. if (offset == signaller->semaphore.signal_ggtt[ring->id])
  2267. return signaller;
  2268. }
  2269. } else {
  2270. u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
  2271. for_each_ring(signaller, dev_priv, i) {
  2272. if(ring == signaller)
  2273. continue;
  2274. if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
  2275. return signaller;
  2276. }
  2277. }
  2278. DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
  2279. ring->id, ipehr, offset);
  2280. return NULL;
  2281. }
  2282. static struct intel_engine_cs *
  2283. semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
  2284. {
  2285. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2286. u32 cmd, ipehr, head;
  2287. u64 offset = 0;
  2288. int i, backwards;
  2289. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  2290. if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
  2291. return NULL;
  2292. /*
  2293. * HEAD is likely pointing to the dword after the actual command,
  2294. * so scan backwards until we find the MBOX. But limit it to just 3
  2295. * or 4 dwords depending on the semaphore wait command size.
  2296. * Note that we don't care about ACTHD here since that might
  2297. * point at at batch, and semaphores are always emitted into the
  2298. * ringbuffer itself.
  2299. */
  2300. head = I915_READ_HEAD(ring) & HEAD_ADDR;
  2301. backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
  2302. for (i = backwards; i; --i) {
  2303. /*
  2304. * Be paranoid and presume the hw has gone off into the wild -
  2305. * our ring is smaller than what the hardware (and hence
  2306. * HEAD_ADDR) allows. Also handles wrap-around.
  2307. */
  2308. head &= ring->buffer->size - 1;
  2309. /* This here seems to blow up */
  2310. cmd = ioread32(ring->buffer->virtual_start + head);
  2311. if (cmd == ipehr)
  2312. break;
  2313. head -= 4;
  2314. }
  2315. if (!i)
  2316. return NULL;
  2317. *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
  2318. if (INTEL_INFO(ring->dev)->gen >= 8) {
  2319. offset = ioread32(ring->buffer->virtual_start + head + 12);
  2320. offset <<= 32;
  2321. offset = ioread32(ring->buffer->virtual_start + head + 8);
  2322. }
  2323. return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
  2324. }
  2325. static int semaphore_passed(struct intel_engine_cs *ring)
  2326. {
  2327. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2328. struct intel_engine_cs *signaller;
  2329. u32 seqno;
  2330. ring->hangcheck.deadlock++;
  2331. signaller = semaphore_waits_for(ring, &seqno);
  2332. if (signaller == NULL)
  2333. return -1;
  2334. /* Prevent pathological recursion due to driver bugs */
  2335. if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
  2336. return -1;
  2337. if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
  2338. return 1;
  2339. /* cursory check for an unkickable deadlock */
  2340. if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
  2341. semaphore_passed(signaller) < 0)
  2342. return -1;
  2343. return 0;
  2344. }
  2345. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  2346. {
  2347. struct intel_engine_cs *ring;
  2348. int i;
  2349. for_each_ring(ring, dev_priv, i)
  2350. ring->hangcheck.deadlock = 0;
  2351. }
  2352. static enum intel_ring_hangcheck_action
  2353. ring_stuck(struct intel_engine_cs *ring, u64 acthd)
  2354. {
  2355. struct drm_device *dev = ring->dev;
  2356. struct drm_i915_private *dev_priv = dev->dev_private;
  2357. u32 tmp;
  2358. if (acthd != ring->hangcheck.acthd) {
  2359. if (acthd > ring->hangcheck.max_acthd) {
  2360. ring->hangcheck.max_acthd = acthd;
  2361. return HANGCHECK_ACTIVE;
  2362. }
  2363. return HANGCHECK_ACTIVE_LOOP;
  2364. }
  2365. if (IS_GEN2(dev))
  2366. return HANGCHECK_HUNG;
  2367. /* Is the chip hanging on a WAIT_FOR_EVENT?
  2368. * If so we can simply poke the RB_WAIT bit
  2369. * and break the hang. This should work on
  2370. * all but the second generation chipsets.
  2371. */
  2372. tmp = I915_READ_CTL(ring);
  2373. if (tmp & RING_WAIT) {
  2374. i915_handle_error(dev, false,
  2375. "Kicking stuck wait on %s",
  2376. ring->name);
  2377. I915_WRITE_CTL(ring, tmp);
  2378. return HANGCHECK_KICK;
  2379. }
  2380. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  2381. switch (semaphore_passed(ring)) {
  2382. default:
  2383. return HANGCHECK_HUNG;
  2384. case 1:
  2385. i915_handle_error(dev, false,
  2386. "Kicking stuck semaphore on %s",
  2387. ring->name);
  2388. I915_WRITE_CTL(ring, tmp);
  2389. return HANGCHECK_KICK;
  2390. case 0:
  2391. return HANGCHECK_WAIT;
  2392. }
  2393. }
  2394. return HANGCHECK_HUNG;
  2395. }
  2396. /*
  2397. * This is called when the chip hasn't reported back with completed
  2398. * batchbuffers in a long time. We keep track per ring seqno progress and
  2399. * if there are no progress, hangcheck score for that ring is increased.
  2400. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  2401. * we kick the ring. If we see no progress on three subsequent calls
  2402. * we assume chip is wedged and try to fix it by resetting the chip.
  2403. */
  2404. static void i915_hangcheck_elapsed(struct work_struct *work)
  2405. {
  2406. struct drm_i915_private *dev_priv =
  2407. container_of(work, typeof(*dev_priv),
  2408. gpu_error.hangcheck_work.work);
  2409. struct drm_device *dev = dev_priv->dev;
  2410. struct intel_engine_cs *ring;
  2411. int i;
  2412. int busy_count = 0, rings_hung = 0;
  2413. bool stuck[I915_NUM_RINGS] = { 0 };
  2414. #define BUSY 1
  2415. #define KICK 5
  2416. #define HUNG 20
  2417. if (!i915.enable_hangcheck)
  2418. return;
  2419. for_each_ring(ring, dev_priv, i) {
  2420. u64 acthd;
  2421. u32 seqno;
  2422. bool busy = true;
  2423. semaphore_clear_deadlocks(dev_priv);
  2424. seqno = ring->get_seqno(ring, false);
  2425. acthd = intel_ring_get_active_head(ring);
  2426. if (ring->hangcheck.seqno == seqno) {
  2427. if (ring_idle(ring)) {
  2428. ring->hangcheck.action = HANGCHECK_IDLE;
  2429. if (waitqueue_active(&ring->irq_queue)) {
  2430. /* Issue a wake-up to catch stuck h/w. */
  2431. if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
  2432. if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
  2433. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  2434. ring->name);
  2435. else
  2436. DRM_INFO("Fake missed irq on %s\n",
  2437. ring->name);
  2438. wake_up_all(&ring->irq_queue);
  2439. }
  2440. /* Safeguard against driver failure */
  2441. ring->hangcheck.score += BUSY;
  2442. } else
  2443. busy = false;
  2444. } else {
  2445. /* We always increment the hangcheck score
  2446. * if the ring is busy and still processing
  2447. * the same request, so that no single request
  2448. * can run indefinitely (such as a chain of
  2449. * batches). The only time we do not increment
  2450. * the hangcheck score on this ring, if this
  2451. * ring is in a legitimate wait for another
  2452. * ring. In that case the waiting ring is a
  2453. * victim and we want to be sure we catch the
  2454. * right culprit. Then every time we do kick
  2455. * the ring, add a small increment to the
  2456. * score so that we can catch a batch that is
  2457. * being repeatedly kicked and so responsible
  2458. * for stalling the machine.
  2459. */
  2460. ring->hangcheck.action = ring_stuck(ring,
  2461. acthd);
  2462. switch (ring->hangcheck.action) {
  2463. case HANGCHECK_IDLE:
  2464. case HANGCHECK_WAIT:
  2465. case HANGCHECK_ACTIVE:
  2466. break;
  2467. case HANGCHECK_ACTIVE_LOOP:
  2468. ring->hangcheck.score += BUSY;
  2469. break;
  2470. case HANGCHECK_KICK:
  2471. ring->hangcheck.score += KICK;
  2472. break;
  2473. case HANGCHECK_HUNG:
  2474. ring->hangcheck.score += HUNG;
  2475. stuck[i] = true;
  2476. break;
  2477. }
  2478. }
  2479. } else {
  2480. ring->hangcheck.action = HANGCHECK_ACTIVE;
  2481. /* Gradually reduce the count so that we catch DoS
  2482. * attempts across multiple batches.
  2483. */
  2484. if (ring->hangcheck.score > 0)
  2485. ring->hangcheck.score--;
  2486. ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
  2487. }
  2488. ring->hangcheck.seqno = seqno;
  2489. ring->hangcheck.acthd = acthd;
  2490. busy_count += busy;
  2491. }
  2492. for_each_ring(ring, dev_priv, i) {
  2493. if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
  2494. DRM_INFO("%s on %s\n",
  2495. stuck[i] ? "stuck" : "no progress",
  2496. ring->name);
  2497. rings_hung++;
  2498. }
  2499. }
  2500. if (rings_hung)
  2501. return i915_handle_error(dev, true, "Ring hung");
  2502. if (busy_count)
  2503. /* Reset timer case chip hangs without another request
  2504. * being added */
  2505. i915_queue_hangcheck(dev);
  2506. }
  2507. void i915_queue_hangcheck(struct drm_device *dev)
  2508. {
  2509. struct i915_gpu_error *e = &to_i915(dev)->gpu_error;
  2510. if (!i915.enable_hangcheck)
  2511. return;
  2512. /* Don't continually defer the hangcheck so that it is always run at
  2513. * least once after work has been scheduled on any ring. Otherwise,
  2514. * we will ignore a hung ring if a second ring is kept busy.
  2515. */
  2516. queue_delayed_work(e->hangcheck_wq, &e->hangcheck_work,
  2517. round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES));
  2518. }
  2519. static void ibx_irq_reset(struct drm_device *dev)
  2520. {
  2521. struct drm_i915_private *dev_priv = dev->dev_private;
  2522. if (HAS_PCH_NOP(dev))
  2523. return;
  2524. GEN5_IRQ_RESET(SDE);
  2525. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  2526. I915_WRITE(SERR_INT, 0xffffffff);
  2527. }
  2528. /*
  2529. * SDEIER is also touched by the interrupt handler to work around missed PCH
  2530. * interrupts. Hence we can't update it after the interrupt handler is enabled -
  2531. * instead we unconditionally enable all PCH interrupt sources here, but then
  2532. * only unmask them as needed with SDEIMR.
  2533. *
  2534. * This function needs to be called before interrupts are enabled.
  2535. */
  2536. static void ibx_irq_pre_postinstall(struct drm_device *dev)
  2537. {
  2538. struct drm_i915_private *dev_priv = dev->dev_private;
  2539. if (HAS_PCH_NOP(dev))
  2540. return;
  2541. WARN_ON(I915_READ(SDEIER) != 0);
  2542. I915_WRITE(SDEIER, 0xffffffff);
  2543. POSTING_READ(SDEIER);
  2544. }
  2545. static void gen5_gt_irq_reset(struct drm_device *dev)
  2546. {
  2547. struct drm_i915_private *dev_priv = dev->dev_private;
  2548. GEN5_IRQ_RESET(GT);
  2549. if (INTEL_INFO(dev)->gen >= 6)
  2550. GEN5_IRQ_RESET(GEN6_PM);
  2551. }
  2552. /* drm_dma.h hooks
  2553. */
  2554. static void ironlake_irq_reset(struct drm_device *dev)
  2555. {
  2556. struct drm_i915_private *dev_priv = dev->dev_private;
  2557. I915_WRITE(HWSTAM, 0xffffffff);
  2558. GEN5_IRQ_RESET(DE);
  2559. if (IS_GEN7(dev))
  2560. I915_WRITE(GEN7_ERR_INT, 0xffffffff);
  2561. gen5_gt_irq_reset(dev);
  2562. ibx_irq_reset(dev);
  2563. }
  2564. static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
  2565. {
  2566. enum pipe pipe;
  2567. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2568. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2569. for_each_pipe(dev_priv, pipe)
  2570. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2571. GEN5_IRQ_RESET(VLV_);
  2572. }
  2573. static void valleyview_irq_preinstall(struct drm_device *dev)
  2574. {
  2575. struct drm_i915_private *dev_priv = dev->dev_private;
  2576. /* VLV magic */
  2577. I915_WRITE(VLV_IMR, 0);
  2578. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  2579. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  2580. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  2581. gen5_gt_irq_reset(dev);
  2582. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2583. vlv_display_irq_reset(dev_priv);
  2584. }
  2585. static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
  2586. {
  2587. GEN8_IRQ_RESET_NDX(GT, 0);
  2588. GEN8_IRQ_RESET_NDX(GT, 1);
  2589. GEN8_IRQ_RESET_NDX(GT, 2);
  2590. GEN8_IRQ_RESET_NDX(GT, 3);
  2591. }
  2592. static void gen8_irq_reset(struct drm_device *dev)
  2593. {
  2594. struct drm_i915_private *dev_priv = dev->dev_private;
  2595. int pipe;
  2596. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2597. POSTING_READ(GEN8_MASTER_IRQ);
  2598. gen8_gt_irq_reset(dev_priv);
  2599. for_each_pipe(dev_priv, pipe)
  2600. if (intel_display_power_is_enabled(dev_priv,
  2601. POWER_DOMAIN_PIPE(pipe)))
  2602. GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
  2603. GEN5_IRQ_RESET(GEN8_DE_PORT_);
  2604. GEN5_IRQ_RESET(GEN8_DE_MISC_);
  2605. GEN5_IRQ_RESET(GEN8_PCU_);
  2606. if (HAS_PCH_SPLIT(dev))
  2607. ibx_irq_reset(dev);
  2608. }
  2609. void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
  2610. unsigned int pipe_mask)
  2611. {
  2612. uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
  2613. spin_lock_irq(&dev_priv->irq_lock);
  2614. if (pipe_mask & 1 << PIPE_A)
  2615. GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_A,
  2616. dev_priv->de_irq_mask[PIPE_A],
  2617. ~dev_priv->de_irq_mask[PIPE_A] | extra_ier);
  2618. if (pipe_mask & 1 << PIPE_B)
  2619. GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B,
  2620. dev_priv->de_irq_mask[PIPE_B],
  2621. ~dev_priv->de_irq_mask[PIPE_B] | extra_ier);
  2622. if (pipe_mask & 1 << PIPE_C)
  2623. GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C,
  2624. dev_priv->de_irq_mask[PIPE_C],
  2625. ~dev_priv->de_irq_mask[PIPE_C] | extra_ier);
  2626. spin_unlock_irq(&dev_priv->irq_lock);
  2627. }
  2628. static void cherryview_irq_preinstall(struct drm_device *dev)
  2629. {
  2630. struct drm_i915_private *dev_priv = dev->dev_private;
  2631. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2632. POSTING_READ(GEN8_MASTER_IRQ);
  2633. gen8_gt_irq_reset(dev_priv);
  2634. GEN5_IRQ_RESET(GEN8_PCU_);
  2635. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
  2636. vlv_display_irq_reset(dev_priv);
  2637. }
  2638. static void ibx_hpd_irq_setup(struct drm_device *dev)
  2639. {
  2640. struct drm_i915_private *dev_priv = dev->dev_private;
  2641. struct intel_encoder *intel_encoder;
  2642. u32 hotplug_irqs, hotplug, enabled_irqs = 0;
  2643. if (HAS_PCH_IBX(dev)) {
  2644. hotplug_irqs = SDE_HOTPLUG_MASK;
  2645. for_each_intel_encoder(dev, intel_encoder)
  2646. if (dev_priv->hotplug.stats[intel_encoder->hpd_pin].state == HPD_ENABLED)
  2647. enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
  2648. } else {
  2649. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  2650. for_each_intel_encoder(dev, intel_encoder)
  2651. if (dev_priv->hotplug.stats[intel_encoder->hpd_pin].state == HPD_ENABLED)
  2652. enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
  2653. }
  2654. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2655. /*
  2656. * Enable digital hotplug on the PCH, and configure the DP short pulse
  2657. * duration to 2ms (which is the minimum in the Display Port spec)
  2658. *
  2659. * This register is the same on all known PCH chips.
  2660. */
  2661. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  2662. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  2663. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  2664. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  2665. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  2666. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  2667. }
  2668. static void bxt_hpd_irq_setup(struct drm_device *dev)
  2669. {
  2670. struct drm_i915_private *dev_priv = dev->dev_private;
  2671. struct intel_encoder *intel_encoder;
  2672. u32 hotplug_port = 0;
  2673. u32 hotplug_ctrl;
  2674. /* Now, enable HPD */
  2675. for_each_intel_encoder(dev, intel_encoder) {
  2676. if (dev_priv->hotplug.stats[intel_encoder->hpd_pin].state
  2677. == HPD_ENABLED)
  2678. hotplug_port |= hpd_bxt[intel_encoder->hpd_pin];
  2679. }
  2680. /* Mask all HPD control bits */
  2681. hotplug_ctrl = I915_READ(BXT_HOTPLUG_CTL) & ~BXT_HOTPLUG_CTL_MASK;
  2682. /* Enable requested port in hotplug control */
  2683. /* TODO: implement (short) HPD support on port A */
  2684. WARN_ON_ONCE(hotplug_port & BXT_DE_PORT_HP_DDIA);
  2685. if (hotplug_port & BXT_DE_PORT_HP_DDIB)
  2686. hotplug_ctrl |= BXT_DDIB_HPD_ENABLE;
  2687. if (hotplug_port & BXT_DE_PORT_HP_DDIC)
  2688. hotplug_ctrl |= BXT_DDIC_HPD_ENABLE;
  2689. I915_WRITE(BXT_HOTPLUG_CTL, hotplug_ctrl);
  2690. /* Unmask DDI hotplug in IMR */
  2691. hotplug_ctrl = I915_READ(GEN8_DE_PORT_IMR) & ~hotplug_port;
  2692. I915_WRITE(GEN8_DE_PORT_IMR, hotplug_ctrl);
  2693. /* Enable DDI hotplug in IER */
  2694. hotplug_ctrl = I915_READ(GEN8_DE_PORT_IER) | hotplug_port;
  2695. I915_WRITE(GEN8_DE_PORT_IER, hotplug_ctrl);
  2696. POSTING_READ(GEN8_DE_PORT_IER);
  2697. }
  2698. static void ibx_irq_postinstall(struct drm_device *dev)
  2699. {
  2700. struct drm_i915_private *dev_priv = dev->dev_private;
  2701. u32 mask;
  2702. if (HAS_PCH_NOP(dev))
  2703. return;
  2704. if (HAS_PCH_IBX(dev))
  2705. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
  2706. else
  2707. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
  2708. GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
  2709. I915_WRITE(SDEIMR, ~mask);
  2710. }
  2711. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  2712. {
  2713. struct drm_i915_private *dev_priv = dev->dev_private;
  2714. u32 pm_irqs, gt_irqs;
  2715. pm_irqs = gt_irqs = 0;
  2716. dev_priv->gt_irq_mask = ~0;
  2717. if (HAS_L3_DPF(dev)) {
  2718. /* L3 parity interrupt is always unmasked. */
  2719. dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
  2720. gt_irqs |= GT_PARITY_ERROR(dev);
  2721. }
  2722. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  2723. if (IS_GEN5(dev)) {
  2724. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  2725. ILK_BSD_USER_INTERRUPT;
  2726. } else {
  2727. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  2728. }
  2729. GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
  2730. if (INTEL_INFO(dev)->gen >= 6) {
  2731. /*
  2732. * RPS interrupts will get enabled/disabled on demand when RPS
  2733. * itself is enabled/disabled.
  2734. */
  2735. if (HAS_VEBOX(dev))
  2736. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  2737. dev_priv->pm_irq_mask = 0xffffffff;
  2738. GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
  2739. }
  2740. }
  2741. static int ironlake_irq_postinstall(struct drm_device *dev)
  2742. {
  2743. struct drm_i915_private *dev_priv = dev->dev_private;
  2744. u32 display_mask, extra_mask;
  2745. if (INTEL_INFO(dev)->gen >= 7) {
  2746. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  2747. DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
  2748. DE_PLANEB_FLIP_DONE_IVB |
  2749. DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
  2750. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  2751. DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
  2752. } else {
  2753. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  2754. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  2755. DE_AUX_CHANNEL_A |
  2756. DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
  2757. DE_POISON);
  2758. extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
  2759. DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
  2760. }
  2761. dev_priv->irq_mask = ~display_mask;
  2762. I915_WRITE(HWSTAM, 0xeffe);
  2763. ibx_irq_pre_postinstall(dev);
  2764. GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
  2765. gen5_gt_irq_postinstall(dev);
  2766. ibx_irq_postinstall(dev);
  2767. if (IS_IRONLAKE_M(dev)) {
  2768. /* Enable PCU event interrupts
  2769. *
  2770. * spinlocking not required here for correctness since interrupt
  2771. * setup is guaranteed to run in single-threaded context. But we
  2772. * need it to make the assert_spin_locked happy. */
  2773. spin_lock_irq(&dev_priv->irq_lock);
  2774. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  2775. spin_unlock_irq(&dev_priv->irq_lock);
  2776. }
  2777. return 0;
  2778. }
  2779. static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
  2780. {
  2781. u32 pipestat_mask;
  2782. u32 iir_mask;
  2783. enum pipe pipe;
  2784. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2785. PIPE_FIFO_UNDERRUN_STATUS;
  2786. for_each_pipe(dev_priv, pipe)
  2787. I915_WRITE(PIPESTAT(pipe), pipestat_mask);
  2788. POSTING_READ(PIPESTAT(PIPE_A));
  2789. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2790. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2791. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  2792. for_each_pipe(dev_priv, pipe)
  2793. i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
  2794. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2795. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2796. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2797. if (IS_CHERRYVIEW(dev_priv))
  2798. iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  2799. dev_priv->irq_mask &= ~iir_mask;
  2800. I915_WRITE(VLV_IIR, iir_mask);
  2801. I915_WRITE(VLV_IIR, iir_mask);
  2802. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2803. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2804. POSTING_READ(VLV_IMR);
  2805. }
  2806. static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
  2807. {
  2808. u32 pipestat_mask;
  2809. u32 iir_mask;
  2810. enum pipe pipe;
  2811. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2812. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2813. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2814. if (IS_CHERRYVIEW(dev_priv))
  2815. iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  2816. dev_priv->irq_mask |= iir_mask;
  2817. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2818. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2819. I915_WRITE(VLV_IIR, iir_mask);
  2820. I915_WRITE(VLV_IIR, iir_mask);
  2821. POSTING_READ(VLV_IIR);
  2822. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2823. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2824. i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  2825. for_each_pipe(dev_priv, pipe)
  2826. i915_disable_pipestat(dev_priv, pipe, pipestat_mask);
  2827. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2828. PIPE_FIFO_UNDERRUN_STATUS;
  2829. for_each_pipe(dev_priv, pipe)
  2830. I915_WRITE(PIPESTAT(pipe), pipestat_mask);
  2831. POSTING_READ(PIPESTAT(PIPE_A));
  2832. }
  2833. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
  2834. {
  2835. assert_spin_locked(&dev_priv->irq_lock);
  2836. if (dev_priv->display_irqs_enabled)
  2837. return;
  2838. dev_priv->display_irqs_enabled = true;
  2839. if (intel_irqs_enabled(dev_priv))
  2840. valleyview_display_irqs_install(dev_priv);
  2841. }
  2842. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
  2843. {
  2844. assert_spin_locked(&dev_priv->irq_lock);
  2845. if (!dev_priv->display_irqs_enabled)
  2846. return;
  2847. dev_priv->display_irqs_enabled = false;
  2848. if (intel_irqs_enabled(dev_priv))
  2849. valleyview_display_irqs_uninstall(dev_priv);
  2850. }
  2851. static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
  2852. {
  2853. dev_priv->irq_mask = ~0;
  2854. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2855. POSTING_READ(PORT_HOTPLUG_EN);
  2856. I915_WRITE(VLV_IIR, 0xffffffff);
  2857. I915_WRITE(VLV_IIR, 0xffffffff);
  2858. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2859. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2860. POSTING_READ(VLV_IMR);
  2861. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2862. * just to make the assert_spin_locked check happy. */
  2863. spin_lock_irq(&dev_priv->irq_lock);
  2864. if (dev_priv->display_irqs_enabled)
  2865. valleyview_display_irqs_install(dev_priv);
  2866. spin_unlock_irq(&dev_priv->irq_lock);
  2867. }
  2868. static int valleyview_irq_postinstall(struct drm_device *dev)
  2869. {
  2870. struct drm_i915_private *dev_priv = dev->dev_private;
  2871. vlv_display_irq_postinstall(dev_priv);
  2872. gen5_gt_irq_postinstall(dev);
  2873. /* ack & enable invalid PTE error interrupts */
  2874. #if 0 /* FIXME: add support to irq handler for checking these bits */
  2875. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2876. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  2877. #endif
  2878. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  2879. return 0;
  2880. }
  2881. static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
  2882. {
  2883. /* These are interrupts we'll toggle with the ring mask register */
  2884. uint32_t gt_interrupts[] = {
  2885. GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  2886. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  2887. GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
  2888. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
  2889. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
  2890. GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
  2891. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
  2892. GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
  2893. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
  2894. 0,
  2895. GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
  2896. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
  2897. };
  2898. dev_priv->pm_irq_mask = 0xffffffff;
  2899. GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
  2900. GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
  2901. /*
  2902. * RPS interrupts will get enabled/disabled on demand when RPS itself
  2903. * is enabled/disabled.
  2904. */
  2905. GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
  2906. GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
  2907. }
  2908. static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
  2909. {
  2910. uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
  2911. uint32_t de_pipe_enables;
  2912. int pipe;
  2913. u32 de_port_en = GEN8_AUX_CHANNEL_A;
  2914. if (IS_GEN9(dev_priv)) {
  2915. de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
  2916. GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
  2917. de_port_en |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
  2918. GEN9_AUX_CHANNEL_D;
  2919. if (IS_BROXTON(dev_priv))
  2920. de_port_en |= BXT_DE_PORT_GMBUS;
  2921. } else
  2922. de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
  2923. GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  2924. de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
  2925. GEN8_PIPE_FIFO_UNDERRUN;
  2926. dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
  2927. dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
  2928. dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
  2929. for_each_pipe(dev_priv, pipe)
  2930. if (intel_display_power_is_enabled(dev_priv,
  2931. POWER_DOMAIN_PIPE(pipe)))
  2932. GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
  2933. dev_priv->de_irq_mask[pipe],
  2934. de_pipe_enables);
  2935. GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_en, de_port_en);
  2936. }
  2937. static int gen8_irq_postinstall(struct drm_device *dev)
  2938. {
  2939. struct drm_i915_private *dev_priv = dev->dev_private;
  2940. if (HAS_PCH_SPLIT(dev))
  2941. ibx_irq_pre_postinstall(dev);
  2942. gen8_gt_irq_postinstall(dev_priv);
  2943. gen8_de_irq_postinstall(dev_priv);
  2944. if (HAS_PCH_SPLIT(dev))
  2945. ibx_irq_postinstall(dev);
  2946. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  2947. POSTING_READ(GEN8_MASTER_IRQ);
  2948. return 0;
  2949. }
  2950. static int cherryview_irq_postinstall(struct drm_device *dev)
  2951. {
  2952. struct drm_i915_private *dev_priv = dev->dev_private;
  2953. vlv_display_irq_postinstall(dev_priv);
  2954. gen8_gt_irq_postinstall(dev_priv);
  2955. I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
  2956. POSTING_READ(GEN8_MASTER_IRQ);
  2957. return 0;
  2958. }
  2959. static void gen8_irq_uninstall(struct drm_device *dev)
  2960. {
  2961. struct drm_i915_private *dev_priv = dev->dev_private;
  2962. if (!dev_priv)
  2963. return;
  2964. gen8_irq_reset(dev);
  2965. }
  2966. static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv)
  2967. {
  2968. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2969. * just to make the assert_spin_locked check happy. */
  2970. spin_lock_irq(&dev_priv->irq_lock);
  2971. if (dev_priv->display_irqs_enabled)
  2972. valleyview_display_irqs_uninstall(dev_priv);
  2973. spin_unlock_irq(&dev_priv->irq_lock);
  2974. vlv_display_irq_reset(dev_priv);
  2975. dev_priv->irq_mask = ~0;
  2976. }
  2977. static void valleyview_irq_uninstall(struct drm_device *dev)
  2978. {
  2979. struct drm_i915_private *dev_priv = dev->dev_private;
  2980. if (!dev_priv)
  2981. return;
  2982. I915_WRITE(VLV_MASTER_IER, 0);
  2983. gen5_gt_irq_reset(dev);
  2984. I915_WRITE(HWSTAM, 0xffffffff);
  2985. vlv_display_irq_uninstall(dev_priv);
  2986. }
  2987. static void cherryview_irq_uninstall(struct drm_device *dev)
  2988. {
  2989. struct drm_i915_private *dev_priv = dev->dev_private;
  2990. if (!dev_priv)
  2991. return;
  2992. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2993. POSTING_READ(GEN8_MASTER_IRQ);
  2994. gen8_gt_irq_reset(dev_priv);
  2995. GEN5_IRQ_RESET(GEN8_PCU_);
  2996. vlv_display_irq_uninstall(dev_priv);
  2997. }
  2998. static void ironlake_irq_uninstall(struct drm_device *dev)
  2999. {
  3000. struct drm_i915_private *dev_priv = dev->dev_private;
  3001. if (!dev_priv)
  3002. return;
  3003. ironlake_irq_reset(dev);
  3004. }
  3005. static void i8xx_irq_preinstall(struct drm_device * dev)
  3006. {
  3007. struct drm_i915_private *dev_priv = dev->dev_private;
  3008. int pipe;
  3009. for_each_pipe(dev_priv, pipe)
  3010. I915_WRITE(PIPESTAT(pipe), 0);
  3011. I915_WRITE16(IMR, 0xffff);
  3012. I915_WRITE16(IER, 0x0);
  3013. POSTING_READ16(IER);
  3014. }
  3015. static int i8xx_irq_postinstall(struct drm_device *dev)
  3016. {
  3017. struct drm_i915_private *dev_priv = dev->dev_private;
  3018. I915_WRITE16(EMR,
  3019. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  3020. /* Unmask the interrupts that we always want on. */
  3021. dev_priv->irq_mask =
  3022. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3023. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3024. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3025. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3026. I915_WRITE16(IMR, dev_priv->irq_mask);
  3027. I915_WRITE16(IER,
  3028. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3029. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3030. I915_USER_INTERRUPT);
  3031. POSTING_READ16(IER);
  3032. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3033. * just to make the assert_spin_locked check happy. */
  3034. spin_lock_irq(&dev_priv->irq_lock);
  3035. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3036. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3037. spin_unlock_irq(&dev_priv->irq_lock);
  3038. return 0;
  3039. }
  3040. /*
  3041. * Returns true when a page flip has completed.
  3042. */
  3043. static bool i8xx_handle_vblank(struct drm_device *dev,
  3044. int plane, int pipe, u32 iir)
  3045. {
  3046. struct drm_i915_private *dev_priv = dev->dev_private;
  3047. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  3048. if (!intel_pipe_handle_vblank(dev, pipe))
  3049. return false;
  3050. if ((iir & flip_pending) == 0)
  3051. goto check_page_flip;
  3052. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  3053. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  3054. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  3055. * the flip is completed (no longer pending). Since this doesn't raise
  3056. * an interrupt per se, we watch for the change at vblank.
  3057. */
  3058. if (I915_READ16(ISR) & flip_pending)
  3059. goto check_page_flip;
  3060. intel_prepare_page_flip(dev, plane);
  3061. intel_finish_page_flip(dev, pipe);
  3062. return true;
  3063. check_page_flip:
  3064. intel_check_page_flip(dev, pipe);
  3065. return false;
  3066. }
  3067. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  3068. {
  3069. struct drm_device *dev = arg;
  3070. struct drm_i915_private *dev_priv = dev->dev_private;
  3071. u16 iir, new_iir;
  3072. u32 pipe_stats[2];
  3073. int pipe;
  3074. u16 flip_mask =
  3075. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3076. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3077. if (!intel_irqs_enabled(dev_priv))
  3078. return IRQ_NONE;
  3079. iir = I915_READ16(IIR);
  3080. if (iir == 0)
  3081. return IRQ_NONE;
  3082. while (iir & ~flip_mask) {
  3083. /* Can't rely on pipestat interrupt bit in iir as it might
  3084. * have been cleared after the pipestat interrupt was received.
  3085. * It doesn't set the bit in iir again, but it still produces
  3086. * interrupts (for non-MSI).
  3087. */
  3088. spin_lock(&dev_priv->irq_lock);
  3089. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3090. DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
  3091. for_each_pipe(dev_priv, pipe) {
  3092. int reg = PIPESTAT(pipe);
  3093. pipe_stats[pipe] = I915_READ(reg);
  3094. /*
  3095. * Clear the PIPE*STAT regs before the IIR
  3096. */
  3097. if (pipe_stats[pipe] & 0x8000ffff)
  3098. I915_WRITE(reg, pipe_stats[pipe]);
  3099. }
  3100. spin_unlock(&dev_priv->irq_lock);
  3101. I915_WRITE16(IIR, iir & ~flip_mask);
  3102. new_iir = I915_READ16(IIR); /* Flush posted writes */
  3103. if (iir & I915_USER_INTERRUPT)
  3104. notify_ring(&dev_priv->ring[RCS]);
  3105. for_each_pipe(dev_priv, pipe) {
  3106. int plane = pipe;
  3107. if (HAS_FBC(dev))
  3108. plane = !plane;
  3109. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  3110. i8xx_handle_vblank(dev, plane, pipe, iir))
  3111. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  3112. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3113. i9xx_pipe_crc_irq_handler(dev, pipe);
  3114. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3115. intel_cpu_fifo_underrun_irq_handler(dev_priv,
  3116. pipe);
  3117. }
  3118. iir = new_iir;
  3119. }
  3120. return IRQ_HANDLED;
  3121. }
  3122. static void i8xx_irq_uninstall(struct drm_device * dev)
  3123. {
  3124. struct drm_i915_private *dev_priv = dev->dev_private;
  3125. int pipe;
  3126. for_each_pipe(dev_priv, pipe) {
  3127. /* Clear enable bits; then clear status bits */
  3128. I915_WRITE(PIPESTAT(pipe), 0);
  3129. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  3130. }
  3131. I915_WRITE16(IMR, 0xffff);
  3132. I915_WRITE16(IER, 0x0);
  3133. I915_WRITE16(IIR, I915_READ16(IIR));
  3134. }
  3135. static void i915_irq_preinstall(struct drm_device * dev)
  3136. {
  3137. struct drm_i915_private *dev_priv = dev->dev_private;
  3138. int pipe;
  3139. if (I915_HAS_HOTPLUG(dev)) {
  3140. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3141. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3142. }
  3143. I915_WRITE16(HWSTAM, 0xeffe);
  3144. for_each_pipe(dev_priv, pipe)
  3145. I915_WRITE(PIPESTAT(pipe), 0);
  3146. I915_WRITE(IMR, 0xffffffff);
  3147. I915_WRITE(IER, 0x0);
  3148. POSTING_READ(IER);
  3149. }
  3150. static int i915_irq_postinstall(struct drm_device *dev)
  3151. {
  3152. struct drm_i915_private *dev_priv = dev->dev_private;
  3153. u32 enable_mask;
  3154. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  3155. /* Unmask the interrupts that we always want on. */
  3156. dev_priv->irq_mask =
  3157. ~(I915_ASLE_INTERRUPT |
  3158. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3159. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3160. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3161. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3162. enable_mask =
  3163. I915_ASLE_INTERRUPT |
  3164. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3165. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3166. I915_USER_INTERRUPT;
  3167. if (I915_HAS_HOTPLUG(dev)) {
  3168. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3169. POSTING_READ(PORT_HOTPLUG_EN);
  3170. /* Enable in IER... */
  3171. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  3172. /* and unmask in IMR */
  3173. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  3174. }
  3175. I915_WRITE(IMR, dev_priv->irq_mask);
  3176. I915_WRITE(IER, enable_mask);
  3177. POSTING_READ(IER);
  3178. i915_enable_asle_pipestat(dev);
  3179. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3180. * just to make the assert_spin_locked check happy. */
  3181. spin_lock_irq(&dev_priv->irq_lock);
  3182. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3183. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3184. spin_unlock_irq(&dev_priv->irq_lock);
  3185. return 0;
  3186. }
  3187. /*
  3188. * Returns true when a page flip has completed.
  3189. */
  3190. static bool i915_handle_vblank(struct drm_device *dev,
  3191. int plane, int pipe, u32 iir)
  3192. {
  3193. struct drm_i915_private *dev_priv = dev->dev_private;
  3194. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  3195. if (!intel_pipe_handle_vblank(dev, pipe))
  3196. return false;
  3197. if ((iir & flip_pending) == 0)
  3198. goto check_page_flip;
  3199. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  3200. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  3201. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  3202. * the flip is completed (no longer pending). Since this doesn't raise
  3203. * an interrupt per se, we watch for the change at vblank.
  3204. */
  3205. if (I915_READ(ISR) & flip_pending)
  3206. goto check_page_flip;
  3207. intel_prepare_page_flip(dev, plane);
  3208. intel_finish_page_flip(dev, pipe);
  3209. return true;
  3210. check_page_flip:
  3211. intel_check_page_flip(dev, pipe);
  3212. return false;
  3213. }
  3214. static irqreturn_t i915_irq_handler(int irq, void *arg)
  3215. {
  3216. struct drm_device *dev = arg;
  3217. struct drm_i915_private *dev_priv = dev->dev_private;
  3218. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  3219. u32 flip_mask =
  3220. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3221. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3222. int pipe, ret = IRQ_NONE;
  3223. if (!intel_irqs_enabled(dev_priv))
  3224. return IRQ_NONE;
  3225. iir = I915_READ(IIR);
  3226. do {
  3227. bool irq_received = (iir & ~flip_mask) != 0;
  3228. bool blc_event = false;
  3229. /* Can't rely on pipestat interrupt bit in iir as it might
  3230. * have been cleared after the pipestat interrupt was received.
  3231. * It doesn't set the bit in iir again, but it still produces
  3232. * interrupts (for non-MSI).
  3233. */
  3234. spin_lock(&dev_priv->irq_lock);
  3235. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3236. DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
  3237. for_each_pipe(dev_priv, pipe) {
  3238. int reg = PIPESTAT(pipe);
  3239. pipe_stats[pipe] = I915_READ(reg);
  3240. /* Clear the PIPE*STAT regs before the IIR */
  3241. if (pipe_stats[pipe] & 0x8000ffff) {
  3242. I915_WRITE(reg, pipe_stats[pipe]);
  3243. irq_received = true;
  3244. }
  3245. }
  3246. spin_unlock(&dev_priv->irq_lock);
  3247. if (!irq_received)
  3248. break;
  3249. /* Consume port. Then clear IIR or we'll miss events */
  3250. if (I915_HAS_HOTPLUG(dev) &&
  3251. iir & I915_DISPLAY_PORT_INTERRUPT)
  3252. i9xx_hpd_irq_handler(dev);
  3253. I915_WRITE(IIR, iir & ~flip_mask);
  3254. new_iir = I915_READ(IIR); /* Flush posted writes */
  3255. if (iir & I915_USER_INTERRUPT)
  3256. notify_ring(&dev_priv->ring[RCS]);
  3257. for_each_pipe(dev_priv, pipe) {
  3258. int plane = pipe;
  3259. if (HAS_FBC(dev))
  3260. plane = !plane;
  3261. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  3262. i915_handle_vblank(dev, plane, pipe, iir))
  3263. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  3264. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3265. blc_event = true;
  3266. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3267. i9xx_pipe_crc_irq_handler(dev, pipe);
  3268. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3269. intel_cpu_fifo_underrun_irq_handler(dev_priv,
  3270. pipe);
  3271. }
  3272. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3273. intel_opregion_asle_intr(dev);
  3274. /* With MSI, interrupts are only generated when iir
  3275. * transitions from zero to nonzero. If another bit got
  3276. * set while we were handling the existing iir bits, then
  3277. * we would never get another interrupt.
  3278. *
  3279. * This is fine on non-MSI as well, as if we hit this path
  3280. * we avoid exiting the interrupt handler only to generate
  3281. * another one.
  3282. *
  3283. * Note that for MSI this could cause a stray interrupt report
  3284. * if an interrupt landed in the time between writing IIR and
  3285. * the posting read. This should be rare enough to never
  3286. * trigger the 99% of 100,000 interrupts test for disabling
  3287. * stray interrupts.
  3288. */
  3289. ret = IRQ_HANDLED;
  3290. iir = new_iir;
  3291. } while (iir & ~flip_mask);
  3292. return ret;
  3293. }
  3294. static void i915_irq_uninstall(struct drm_device * dev)
  3295. {
  3296. struct drm_i915_private *dev_priv = dev->dev_private;
  3297. int pipe;
  3298. if (I915_HAS_HOTPLUG(dev)) {
  3299. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3300. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3301. }
  3302. I915_WRITE16(HWSTAM, 0xffff);
  3303. for_each_pipe(dev_priv, pipe) {
  3304. /* Clear enable bits; then clear status bits */
  3305. I915_WRITE(PIPESTAT(pipe), 0);
  3306. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  3307. }
  3308. I915_WRITE(IMR, 0xffffffff);
  3309. I915_WRITE(IER, 0x0);
  3310. I915_WRITE(IIR, I915_READ(IIR));
  3311. }
  3312. static void i965_irq_preinstall(struct drm_device * dev)
  3313. {
  3314. struct drm_i915_private *dev_priv = dev->dev_private;
  3315. int pipe;
  3316. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3317. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3318. I915_WRITE(HWSTAM, 0xeffe);
  3319. for_each_pipe(dev_priv, pipe)
  3320. I915_WRITE(PIPESTAT(pipe), 0);
  3321. I915_WRITE(IMR, 0xffffffff);
  3322. I915_WRITE(IER, 0x0);
  3323. POSTING_READ(IER);
  3324. }
  3325. static int i965_irq_postinstall(struct drm_device *dev)
  3326. {
  3327. struct drm_i915_private *dev_priv = dev->dev_private;
  3328. u32 enable_mask;
  3329. u32 error_mask;
  3330. /* Unmask the interrupts that we always want on. */
  3331. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  3332. I915_DISPLAY_PORT_INTERRUPT |
  3333. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3334. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3335. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3336. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  3337. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  3338. enable_mask = ~dev_priv->irq_mask;
  3339. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3340. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3341. enable_mask |= I915_USER_INTERRUPT;
  3342. if (IS_G4X(dev))
  3343. enable_mask |= I915_BSD_USER_INTERRUPT;
  3344. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3345. * just to make the assert_spin_locked check happy. */
  3346. spin_lock_irq(&dev_priv->irq_lock);
  3347. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  3348. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3349. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3350. spin_unlock_irq(&dev_priv->irq_lock);
  3351. /*
  3352. * Enable some error detection, note the instruction error mask
  3353. * bit is reserved, so we leave it masked.
  3354. */
  3355. if (IS_G4X(dev)) {
  3356. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  3357. GM45_ERROR_MEM_PRIV |
  3358. GM45_ERROR_CP_PRIV |
  3359. I915_ERROR_MEMORY_REFRESH);
  3360. } else {
  3361. error_mask = ~(I915_ERROR_PAGE_TABLE |
  3362. I915_ERROR_MEMORY_REFRESH);
  3363. }
  3364. I915_WRITE(EMR, error_mask);
  3365. I915_WRITE(IMR, dev_priv->irq_mask);
  3366. I915_WRITE(IER, enable_mask);
  3367. POSTING_READ(IER);
  3368. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3369. POSTING_READ(PORT_HOTPLUG_EN);
  3370. i915_enable_asle_pipestat(dev);
  3371. return 0;
  3372. }
  3373. static void i915_hpd_irq_setup(struct drm_device *dev)
  3374. {
  3375. struct drm_i915_private *dev_priv = dev->dev_private;
  3376. struct intel_encoder *intel_encoder;
  3377. u32 hotplug_en;
  3378. assert_spin_locked(&dev_priv->irq_lock);
  3379. hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  3380. hotplug_en &= ~HOTPLUG_INT_EN_MASK;
  3381. /* Note HDMI and DP share hotplug bits */
  3382. /* enable bits are the same for all generations */
  3383. for_each_intel_encoder(dev, intel_encoder)
  3384. if (dev_priv->hotplug.stats[intel_encoder->hpd_pin].state == HPD_ENABLED)
  3385. hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
  3386. /* Programming the CRT detection parameters tends
  3387. to generate a spurious hotplug event about three
  3388. seconds later. So just do it once.
  3389. */
  3390. if (IS_G4X(dev))
  3391. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  3392. hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
  3393. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  3394. /* Ignore TV since it's buggy */
  3395. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  3396. }
  3397. static irqreturn_t i965_irq_handler(int irq, void *arg)
  3398. {
  3399. struct drm_device *dev = arg;
  3400. struct drm_i915_private *dev_priv = dev->dev_private;
  3401. u32 iir, new_iir;
  3402. u32 pipe_stats[I915_MAX_PIPES];
  3403. int ret = IRQ_NONE, pipe;
  3404. u32 flip_mask =
  3405. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3406. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3407. if (!intel_irqs_enabled(dev_priv))
  3408. return IRQ_NONE;
  3409. iir = I915_READ(IIR);
  3410. for (;;) {
  3411. bool irq_received = (iir & ~flip_mask) != 0;
  3412. bool blc_event = false;
  3413. /* Can't rely on pipestat interrupt bit in iir as it might
  3414. * have been cleared after the pipestat interrupt was received.
  3415. * It doesn't set the bit in iir again, but it still produces
  3416. * interrupts (for non-MSI).
  3417. */
  3418. spin_lock(&dev_priv->irq_lock);
  3419. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3420. DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
  3421. for_each_pipe(dev_priv, pipe) {
  3422. int reg = PIPESTAT(pipe);
  3423. pipe_stats[pipe] = I915_READ(reg);
  3424. /*
  3425. * Clear the PIPE*STAT regs before the IIR
  3426. */
  3427. if (pipe_stats[pipe] & 0x8000ffff) {
  3428. I915_WRITE(reg, pipe_stats[pipe]);
  3429. irq_received = true;
  3430. }
  3431. }
  3432. spin_unlock(&dev_priv->irq_lock);
  3433. if (!irq_received)
  3434. break;
  3435. ret = IRQ_HANDLED;
  3436. /* Consume port. Then clear IIR or we'll miss events */
  3437. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  3438. i9xx_hpd_irq_handler(dev);
  3439. I915_WRITE(IIR, iir & ~flip_mask);
  3440. new_iir = I915_READ(IIR); /* Flush posted writes */
  3441. if (iir & I915_USER_INTERRUPT)
  3442. notify_ring(&dev_priv->ring[RCS]);
  3443. if (iir & I915_BSD_USER_INTERRUPT)
  3444. notify_ring(&dev_priv->ring[VCS]);
  3445. for_each_pipe(dev_priv, pipe) {
  3446. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  3447. i915_handle_vblank(dev, pipe, pipe, iir))
  3448. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  3449. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3450. blc_event = true;
  3451. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3452. i9xx_pipe_crc_irq_handler(dev, pipe);
  3453. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3454. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  3455. }
  3456. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3457. intel_opregion_asle_intr(dev);
  3458. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  3459. gmbus_irq_handler(dev);
  3460. /* With MSI, interrupts are only generated when iir
  3461. * transitions from zero to nonzero. If another bit got
  3462. * set while we were handling the existing iir bits, then
  3463. * we would never get another interrupt.
  3464. *
  3465. * This is fine on non-MSI as well, as if we hit this path
  3466. * we avoid exiting the interrupt handler only to generate
  3467. * another one.
  3468. *
  3469. * Note that for MSI this could cause a stray interrupt report
  3470. * if an interrupt landed in the time between writing IIR and
  3471. * the posting read. This should be rare enough to never
  3472. * trigger the 99% of 100,000 interrupts test for disabling
  3473. * stray interrupts.
  3474. */
  3475. iir = new_iir;
  3476. }
  3477. return ret;
  3478. }
  3479. static void i965_irq_uninstall(struct drm_device * dev)
  3480. {
  3481. struct drm_i915_private *dev_priv = dev->dev_private;
  3482. int pipe;
  3483. if (!dev_priv)
  3484. return;
  3485. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3486. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3487. I915_WRITE(HWSTAM, 0xffffffff);
  3488. for_each_pipe(dev_priv, pipe)
  3489. I915_WRITE(PIPESTAT(pipe), 0);
  3490. I915_WRITE(IMR, 0xffffffff);
  3491. I915_WRITE(IER, 0x0);
  3492. for_each_pipe(dev_priv, pipe)
  3493. I915_WRITE(PIPESTAT(pipe),
  3494. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  3495. I915_WRITE(IIR, I915_READ(IIR));
  3496. }
  3497. static void intel_hpd_irq_reenable_work(struct work_struct *work)
  3498. {
  3499. struct drm_i915_private *dev_priv =
  3500. container_of(work, typeof(*dev_priv),
  3501. hotplug.reenable_work.work);
  3502. struct drm_device *dev = dev_priv->dev;
  3503. struct drm_mode_config *mode_config = &dev->mode_config;
  3504. int i;
  3505. intel_runtime_pm_get(dev_priv);
  3506. spin_lock_irq(&dev_priv->irq_lock);
  3507. for_each_hpd_pin(i) {
  3508. struct drm_connector *connector;
  3509. if (dev_priv->hotplug.stats[i].state != HPD_DISABLED)
  3510. continue;
  3511. dev_priv->hotplug.stats[i].state = HPD_ENABLED;
  3512. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3513. struct intel_connector *intel_connector = to_intel_connector(connector);
  3514. if (intel_connector->encoder->hpd_pin == i) {
  3515. if (connector->polled != intel_connector->polled)
  3516. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  3517. connector->name);
  3518. connector->polled = intel_connector->polled;
  3519. if (!connector->polled)
  3520. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3521. }
  3522. }
  3523. }
  3524. if (dev_priv->display.hpd_irq_setup)
  3525. dev_priv->display.hpd_irq_setup(dev);
  3526. spin_unlock_irq(&dev_priv->irq_lock);
  3527. intel_runtime_pm_put(dev_priv);
  3528. }
  3529. /**
  3530. * intel_irq_init - initializes irq support
  3531. * @dev_priv: i915 device instance
  3532. *
  3533. * This function initializes all the irq support including work items, timers
  3534. * and all the vtables. It does not setup the interrupt itself though.
  3535. */
  3536. void intel_irq_init(struct drm_i915_private *dev_priv)
  3537. {
  3538. struct drm_device *dev = dev_priv->dev;
  3539. INIT_WORK(&dev_priv->hotplug.hotplug_work, i915_hotplug_work_func);
  3540. INIT_WORK(&dev_priv->hotplug.dig_port_work, i915_digport_work_func);
  3541. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  3542. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  3543. /* Let's track the enabled rps events */
  3544. if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
  3545. /* WaGsvRC0ResidencyMethod:vlv */
  3546. dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
  3547. else
  3548. dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
  3549. INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
  3550. i915_hangcheck_elapsed);
  3551. INIT_DELAYED_WORK(&dev_priv->hotplug.reenable_work,
  3552. intel_hpd_irq_reenable_work);
  3553. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  3554. if (IS_GEN2(dev_priv)) {
  3555. dev->max_vblank_count = 0;
  3556. dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
  3557. } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
  3558. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  3559. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  3560. } else {
  3561. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  3562. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  3563. }
  3564. /*
  3565. * Opt out of the vblank disable timer on everything except gen2.
  3566. * Gen2 doesn't have a hardware frame counter and so depends on
  3567. * vblank interrupts to produce sane vblank seuquence numbers.
  3568. */
  3569. if (!IS_GEN2(dev_priv))
  3570. dev->vblank_disable_immediate = true;
  3571. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  3572. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  3573. if (IS_CHERRYVIEW(dev_priv)) {
  3574. dev->driver->irq_handler = cherryview_irq_handler;
  3575. dev->driver->irq_preinstall = cherryview_irq_preinstall;
  3576. dev->driver->irq_postinstall = cherryview_irq_postinstall;
  3577. dev->driver->irq_uninstall = cherryview_irq_uninstall;
  3578. dev->driver->enable_vblank = valleyview_enable_vblank;
  3579. dev->driver->disable_vblank = valleyview_disable_vblank;
  3580. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3581. } else if (IS_VALLEYVIEW(dev_priv)) {
  3582. dev->driver->irq_handler = valleyview_irq_handler;
  3583. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  3584. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  3585. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  3586. dev->driver->enable_vblank = valleyview_enable_vblank;
  3587. dev->driver->disable_vblank = valleyview_disable_vblank;
  3588. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3589. } else if (INTEL_INFO(dev_priv)->gen >= 8) {
  3590. dev->driver->irq_handler = gen8_irq_handler;
  3591. dev->driver->irq_preinstall = gen8_irq_reset;
  3592. dev->driver->irq_postinstall = gen8_irq_postinstall;
  3593. dev->driver->irq_uninstall = gen8_irq_uninstall;
  3594. dev->driver->enable_vblank = gen8_enable_vblank;
  3595. dev->driver->disable_vblank = gen8_disable_vblank;
  3596. if (HAS_PCH_SPLIT(dev))
  3597. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3598. else
  3599. dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
  3600. } else if (HAS_PCH_SPLIT(dev)) {
  3601. dev->driver->irq_handler = ironlake_irq_handler;
  3602. dev->driver->irq_preinstall = ironlake_irq_reset;
  3603. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  3604. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  3605. dev->driver->enable_vblank = ironlake_enable_vblank;
  3606. dev->driver->disable_vblank = ironlake_disable_vblank;
  3607. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3608. } else {
  3609. if (INTEL_INFO(dev_priv)->gen == 2) {
  3610. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  3611. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  3612. dev->driver->irq_handler = i8xx_irq_handler;
  3613. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  3614. } else if (INTEL_INFO(dev_priv)->gen == 3) {
  3615. dev->driver->irq_preinstall = i915_irq_preinstall;
  3616. dev->driver->irq_postinstall = i915_irq_postinstall;
  3617. dev->driver->irq_uninstall = i915_irq_uninstall;
  3618. dev->driver->irq_handler = i915_irq_handler;
  3619. } else {
  3620. dev->driver->irq_preinstall = i965_irq_preinstall;
  3621. dev->driver->irq_postinstall = i965_irq_postinstall;
  3622. dev->driver->irq_uninstall = i965_irq_uninstall;
  3623. dev->driver->irq_handler = i965_irq_handler;
  3624. }
  3625. if (I915_HAS_HOTPLUG(dev_priv))
  3626. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3627. dev->driver->enable_vblank = i915_enable_vblank;
  3628. dev->driver->disable_vblank = i915_disable_vblank;
  3629. }
  3630. }
  3631. /**
  3632. * intel_hpd_init - initializes and enables hpd support
  3633. * @dev_priv: i915 device instance
  3634. *
  3635. * This function enables the hotplug support. It requires that interrupts have
  3636. * already been enabled with intel_irq_init_hw(). From this point on hotplug and
  3637. * poll request can run concurrently to other code, so locking rules must be
  3638. * obeyed.
  3639. *
  3640. * This is a separate step from interrupt enabling to simplify the locking rules
  3641. * in the driver load and resume code.
  3642. */
  3643. void intel_hpd_init(struct drm_i915_private *dev_priv)
  3644. {
  3645. struct drm_device *dev = dev_priv->dev;
  3646. struct drm_mode_config *mode_config = &dev->mode_config;
  3647. struct drm_connector *connector;
  3648. int i;
  3649. for_each_hpd_pin(i) {
  3650. dev_priv->hotplug.stats[i].count = 0;
  3651. dev_priv->hotplug.stats[i].state = HPD_ENABLED;
  3652. }
  3653. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3654. struct intel_connector *intel_connector = to_intel_connector(connector);
  3655. connector->polled = intel_connector->polled;
  3656. if (connector->encoder && !connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
  3657. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3658. if (intel_connector->mst_port)
  3659. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3660. }
  3661. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3662. * just to make the assert_spin_locked checks happy. */
  3663. spin_lock_irq(&dev_priv->irq_lock);
  3664. if (dev_priv->display.hpd_irq_setup)
  3665. dev_priv->display.hpd_irq_setup(dev);
  3666. spin_unlock_irq(&dev_priv->irq_lock);
  3667. }
  3668. /**
  3669. * intel_irq_install - enables the hardware interrupt
  3670. * @dev_priv: i915 device instance
  3671. *
  3672. * This function enables the hardware interrupt handling, but leaves the hotplug
  3673. * handling still disabled. It is called after intel_irq_init().
  3674. *
  3675. * In the driver load and resume code we need working interrupts in a few places
  3676. * but don't want to deal with the hassle of concurrent probe and hotplug
  3677. * workers. Hence the split into this two-stage approach.
  3678. */
  3679. int intel_irq_install(struct drm_i915_private *dev_priv)
  3680. {
  3681. /*
  3682. * We enable some interrupt sources in our postinstall hooks, so mark
  3683. * interrupts as enabled _before_ actually enabling them to avoid
  3684. * special cases in our ordering checks.
  3685. */
  3686. dev_priv->pm.irqs_enabled = true;
  3687. return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
  3688. }
  3689. /**
  3690. * intel_irq_uninstall - finilizes all irq handling
  3691. * @dev_priv: i915 device instance
  3692. *
  3693. * This stops interrupt and hotplug handling and unregisters and frees all
  3694. * resources acquired in the init functions.
  3695. */
  3696. void intel_irq_uninstall(struct drm_i915_private *dev_priv)
  3697. {
  3698. drm_irq_uninstall(dev_priv->dev);
  3699. intel_hpd_cancel_work(dev_priv);
  3700. dev_priv->pm.irqs_enabled = false;
  3701. }
  3702. /**
  3703. * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
  3704. * @dev_priv: i915 device instance
  3705. *
  3706. * This function is used to disable interrupts at runtime, both in the runtime
  3707. * pm and the system suspend/resume code.
  3708. */
  3709. void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
  3710. {
  3711. dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
  3712. dev_priv->pm.irqs_enabled = false;
  3713. synchronize_irq(dev_priv->dev->irq);
  3714. }
  3715. /**
  3716. * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
  3717. * @dev_priv: i915 device instance
  3718. *
  3719. * This function is used to enable interrupts at runtime, both in the runtime
  3720. * pm and the system suspend/resume code.
  3721. */
  3722. void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
  3723. {
  3724. dev_priv->pm.irqs_enabled = true;
  3725. dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
  3726. dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
  3727. }