i915_irq.c 137 KB

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