i915_irq.c 135 KB

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