i915_irq.c 135 KB

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