i915_irq.c 135 KB

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