i915_irq.c 135 KB

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