i915_irq.c 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458
  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 ilk_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 ilk_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 snb_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 snb_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 bdw_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 bdw_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. /*
  916. * Handle hotplug events outside the interrupt handler proper.
  917. */
  918. #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
  919. static void i915_hotplug_work_func(struct work_struct *work)
  920. {
  921. struct drm_i915_private *dev_priv =
  922. container_of(work, struct drm_i915_private, hotplug_work);
  923. struct drm_device *dev = dev_priv->dev;
  924. struct drm_mode_config *mode_config = &dev->mode_config;
  925. struct intel_connector *intel_connector;
  926. struct intel_encoder *intel_encoder;
  927. struct drm_connector *connector;
  928. unsigned long irqflags;
  929. bool hpd_disabled = false;
  930. bool changed = false;
  931. u32 hpd_event_bits;
  932. /* HPD irq before everything is fully set up. */
  933. if (!dev_priv->enable_hotplug_processing)
  934. return;
  935. mutex_lock(&mode_config->mutex);
  936. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  937. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  938. hpd_event_bits = dev_priv->hpd_event_bits;
  939. dev_priv->hpd_event_bits = 0;
  940. list_for_each_entry(connector, &mode_config->connector_list, head) {
  941. intel_connector = to_intel_connector(connector);
  942. intel_encoder = intel_connector->encoder;
  943. if (intel_encoder->hpd_pin > HPD_NONE &&
  944. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
  945. connector->polled == DRM_CONNECTOR_POLL_HPD) {
  946. DRM_INFO("HPD interrupt storm detected on connector %s: "
  947. "switching from hotplug detection to polling\n",
  948. connector->name);
  949. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
  950. connector->polled = DRM_CONNECTOR_POLL_CONNECT
  951. | DRM_CONNECTOR_POLL_DISCONNECT;
  952. hpd_disabled = true;
  953. }
  954. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  955. DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
  956. connector->name, intel_encoder->hpd_pin);
  957. }
  958. }
  959. /* if there were no outputs to poll, poll was disabled,
  960. * therefore make sure it's enabled when disabling HPD on
  961. * some connectors */
  962. if (hpd_disabled) {
  963. drm_kms_helper_poll_enable(dev);
  964. mod_timer(&dev_priv->hotplug_reenable_timer,
  965. jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
  966. }
  967. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  968. list_for_each_entry(connector, &mode_config->connector_list, head) {
  969. intel_connector = to_intel_connector(connector);
  970. intel_encoder = intel_connector->encoder;
  971. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  972. if (intel_encoder->hot_plug)
  973. intel_encoder->hot_plug(intel_encoder);
  974. if (intel_hpd_irq_event(dev, connector))
  975. changed = true;
  976. }
  977. }
  978. mutex_unlock(&mode_config->mutex);
  979. if (changed)
  980. drm_kms_helper_hotplug_event(dev);
  981. }
  982. static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv)
  983. {
  984. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  985. }
  986. static void ironlake_rps_change_irq_handler(struct drm_device *dev)
  987. {
  988. struct drm_i915_private *dev_priv = dev->dev_private;
  989. u32 busy_up, busy_down, max_avg, min_avg;
  990. u8 new_delay;
  991. spin_lock(&mchdev_lock);
  992. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  993. new_delay = dev_priv->ips.cur_delay;
  994. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  995. busy_up = I915_READ(RCPREVBSYTUPAVG);
  996. busy_down = I915_READ(RCPREVBSYTDNAVG);
  997. max_avg = I915_READ(RCBMAXAVG);
  998. min_avg = I915_READ(RCBMINAVG);
  999. /* Handle RCS change request from hw */
  1000. if (busy_up > max_avg) {
  1001. if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
  1002. new_delay = dev_priv->ips.cur_delay - 1;
  1003. if (new_delay < dev_priv->ips.max_delay)
  1004. new_delay = dev_priv->ips.max_delay;
  1005. } else if (busy_down < min_avg) {
  1006. if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
  1007. new_delay = dev_priv->ips.cur_delay + 1;
  1008. if (new_delay > dev_priv->ips.min_delay)
  1009. new_delay = dev_priv->ips.min_delay;
  1010. }
  1011. if (ironlake_set_drps(dev, new_delay))
  1012. dev_priv->ips.cur_delay = new_delay;
  1013. spin_unlock(&mchdev_lock);
  1014. return;
  1015. }
  1016. static void notify_ring(struct drm_device *dev,
  1017. struct intel_engine_cs *ring)
  1018. {
  1019. if (!intel_ring_initialized(ring))
  1020. return;
  1021. trace_i915_gem_request_complete(ring);
  1022. wake_up_all(&ring->irq_queue);
  1023. i915_queue_hangcheck(dev);
  1024. }
  1025. static void gen6_pm_rps_work(struct work_struct *work)
  1026. {
  1027. struct drm_i915_private *dev_priv =
  1028. container_of(work, struct drm_i915_private, rps.work);
  1029. u32 pm_iir;
  1030. int new_delay, adj;
  1031. spin_lock_irq(&dev_priv->irq_lock);
  1032. pm_iir = dev_priv->rps.pm_iir;
  1033. dev_priv->rps.pm_iir = 0;
  1034. if (IS_BROADWELL(dev_priv->dev))
  1035. bdw_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
  1036. else {
  1037. /* Make sure not to corrupt PMIMR state used by ringbuffer */
  1038. snb_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
  1039. }
  1040. spin_unlock_irq(&dev_priv->irq_lock);
  1041. /* Make sure we didn't queue anything we're not going to process. */
  1042. WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
  1043. if ((pm_iir & dev_priv->pm_rps_events) == 0)
  1044. return;
  1045. mutex_lock(&dev_priv->rps.hw_lock);
  1046. adj = dev_priv->rps.last_adj;
  1047. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
  1048. if (adj > 0)
  1049. adj *= 2;
  1050. else
  1051. adj = 1;
  1052. new_delay = dev_priv->rps.cur_freq + adj;
  1053. /*
  1054. * For better performance, jump directly
  1055. * to RPe if we're below it.
  1056. */
  1057. if (new_delay < dev_priv->rps.efficient_freq)
  1058. new_delay = dev_priv->rps.efficient_freq;
  1059. } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
  1060. if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
  1061. new_delay = dev_priv->rps.efficient_freq;
  1062. else
  1063. new_delay = dev_priv->rps.min_freq_softlimit;
  1064. adj = 0;
  1065. } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
  1066. if (adj < 0)
  1067. adj *= 2;
  1068. else
  1069. adj = -1;
  1070. new_delay = dev_priv->rps.cur_freq + adj;
  1071. } else { /* unknown event */
  1072. new_delay = dev_priv->rps.cur_freq;
  1073. }
  1074. /* sysfs frequency interfaces may have snuck in while servicing the
  1075. * interrupt
  1076. */
  1077. new_delay = clamp_t(int, new_delay,
  1078. dev_priv->rps.min_freq_softlimit,
  1079. dev_priv->rps.max_freq_softlimit);
  1080. dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
  1081. if (IS_VALLEYVIEW(dev_priv->dev))
  1082. valleyview_set_rps(dev_priv->dev, new_delay);
  1083. else
  1084. gen6_set_rps(dev_priv->dev, new_delay);
  1085. mutex_unlock(&dev_priv->rps.hw_lock);
  1086. }
  1087. /**
  1088. * ivybridge_parity_work - Workqueue called when a parity error interrupt
  1089. * occurred.
  1090. * @work: workqueue struct
  1091. *
  1092. * Doesn't actually do anything except notify userspace. As a consequence of
  1093. * this event, userspace should try to remap the bad rows since statistically
  1094. * it is likely the same row is more likely to go bad again.
  1095. */
  1096. static void ivybridge_parity_work(struct work_struct *work)
  1097. {
  1098. struct drm_i915_private *dev_priv =
  1099. container_of(work, struct drm_i915_private, l3_parity.error_work);
  1100. u32 error_status, row, bank, subbank;
  1101. char *parity_event[6];
  1102. uint32_t misccpctl;
  1103. unsigned long flags;
  1104. uint8_t slice = 0;
  1105. /* We must turn off DOP level clock gating to access the L3 registers.
  1106. * In order to prevent a get/put style interface, acquire struct mutex
  1107. * any time we access those registers.
  1108. */
  1109. mutex_lock(&dev_priv->dev->struct_mutex);
  1110. /* If we've screwed up tracking, just let the interrupt fire again */
  1111. if (WARN_ON(!dev_priv->l3_parity.which_slice))
  1112. goto out;
  1113. misccpctl = I915_READ(GEN7_MISCCPCTL);
  1114. I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  1115. POSTING_READ(GEN7_MISCCPCTL);
  1116. while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
  1117. u32 reg;
  1118. slice--;
  1119. if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
  1120. break;
  1121. dev_priv->l3_parity.which_slice &= ~(1<<slice);
  1122. reg = GEN7_L3CDERRST1 + (slice * 0x200);
  1123. error_status = I915_READ(reg);
  1124. row = GEN7_PARITY_ERROR_ROW(error_status);
  1125. bank = GEN7_PARITY_ERROR_BANK(error_status);
  1126. subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
  1127. I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
  1128. POSTING_READ(reg);
  1129. parity_event[0] = I915_L3_PARITY_UEVENT "=1";
  1130. parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
  1131. parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
  1132. parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
  1133. parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
  1134. parity_event[5] = NULL;
  1135. kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
  1136. KOBJ_CHANGE, parity_event);
  1137. DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
  1138. slice, row, bank, subbank);
  1139. kfree(parity_event[4]);
  1140. kfree(parity_event[3]);
  1141. kfree(parity_event[2]);
  1142. kfree(parity_event[1]);
  1143. }
  1144. I915_WRITE(GEN7_MISCCPCTL, misccpctl);
  1145. out:
  1146. WARN_ON(dev_priv->l3_parity.which_slice);
  1147. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  1148. ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
  1149. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  1150. mutex_unlock(&dev_priv->dev->struct_mutex);
  1151. }
  1152. static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
  1153. {
  1154. struct drm_i915_private *dev_priv = dev->dev_private;
  1155. if (!HAS_L3_DPF(dev))
  1156. return;
  1157. spin_lock(&dev_priv->irq_lock);
  1158. ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
  1159. spin_unlock(&dev_priv->irq_lock);
  1160. iir &= GT_PARITY_ERROR(dev);
  1161. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
  1162. dev_priv->l3_parity.which_slice |= 1 << 1;
  1163. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
  1164. dev_priv->l3_parity.which_slice |= 1 << 0;
  1165. queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
  1166. }
  1167. static void ilk_gt_irq_handler(struct drm_device *dev,
  1168. struct drm_i915_private *dev_priv,
  1169. u32 gt_iir)
  1170. {
  1171. if (gt_iir &
  1172. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  1173. notify_ring(dev, &dev_priv->ring[RCS]);
  1174. if (gt_iir & ILK_BSD_USER_INTERRUPT)
  1175. notify_ring(dev, &dev_priv->ring[VCS]);
  1176. }
  1177. static void snb_gt_irq_handler(struct drm_device *dev,
  1178. struct drm_i915_private *dev_priv,
  1179. u32 gt_iir)
  1180. {
  1181. if (gt_iir &
  1182. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  1183. notify_ring(dev, &dev_priv->ring[RCS]);
  1184. if (gt_iir & GT_BSD_USER_INTERRUPT)
  1185. notify_ring(dev, &dev_priv->ring[VCS]);
  1186. if (gt_iir & GT_BLT_USER_INTERRUPT)
  1187. notify_ring(dev, &dev_priv->ring[BCS]);
  1188. if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
  1189. GT_BSD_CS_ERROR_INTERRUPT |
  1190. GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
  1191. i915_handle_error(dev, false, "GT error interrupt 0x%08x",
  1192. gt_iir);
  1193. }
  1194. if (gt_iir & GT_PARITY_ERROR(dev))
  1195. ivybridge_parity_error_irq_handler(dev, gt_iir);
  1196. }
  1197. static void gen8_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
  1198. {
  1199. if ((pm_iir & dev_priv->pm_rps_events) == 0)
  1200. return;
  1201. spin_lock(&dev_priv->irq_lock);
  1202. dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
  1203. bdw_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
  1204. spin_unlock(&dev_priv->irq_lock);
  1205. queue_work(dev_priv->wq, &dev_priv->rps.work);
  1206. }
  1207. static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
  1208. struct drm_i915_private *dev_priv,
  1209. u32 master_ctl)
  1210. {
  1211. u32 rcs, bcs, vcs;
  1212. uint32_t tmp = 0;
  1213. irqreturn_t ret = IRQ_NONE;
  1214. if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
  1215. tmp = I915_READ(GEN8_GT_IIR(0));
  1216. if (tmp) {
  1217. ret = IRQ_HANDLED;
  1218. rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
  1219. bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
  1220. if (rcs & GT_RENDER_USER_INTERRUPT)
  1221. notify_ring(dev, &dev_priv->ring[RCS]);
  1222. if (bcs & GT_RENDER_USER_INTERRUPT)
  1223. notify_ring(dev, &dev_priv->ring[BCS]);
  1224. I915_WRITE(GEN8_GT_IIR(0), tmp);
  1225. } else
  1226. DRM_ERROR("The master control interrupt lied (GT0)!\n");
  1227. }
  1228. if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
  1229. tmp = I915_READ(GEN8_GT_IIR(1));
  1230. if (tmp) {
  1231. ret = IRQ_HANDLED;
  1232. vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
  1233. if (vcs & GT_RENDER_USER_INTERRUPT)
  1234. notify_ring(dev, &dev_priv->ring[VCS]);
  1235. vcs = tmp >> GEN8_VCS2_IRQ_SHIFT;
  1236. if (vcs & GT_RENDER_USER_INTERRUPT)
  1237. notify_ring(dev, &dev_priv->ring[VCS2]);
  1238. I915_WRITE(GEN8_GT_IIR(1), tmp);
  1239. } else
  1240. DRM_ERROR("The master control interrupt lied (GT1)!\n");
  1241. }
  1242. if (master_ctl & GEN8_GT_PM_IRQ) {
  1243. tmp = I915_READ(GEN8_GT_IIR(2));
  1244. if (tmp & dev_priv->pm_rps_events) {
  1245. ret = IRQ_HANDLED;
  1246. gen8_rps_irq_handler(dev_priv, tmp);
  1247. I915_WRITE(GEN8_GT_IIR(2),
  1248. tmp & dev_priv->pm_rps_events);
  1249. } else
  1250. DRM_ERROR("The master control interrupt lied (PM)!\n");
  1251. }
  1252. if (master_ctl & GEN8_GT_VECS_IRQ) {
  1253. tmp = I915_READ(GEN8_GT_IIR(3));
  1254. if (tmp) {
  1255. ret = IRQ_HANDLED;
  1256. vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
  1257. if (vcs & GT_RENDER_USER_INTERRUPT)
  1258. notify_ring(dev, &dev_priv->ring[VECS]);
  1259. I915_WRITE(GEN8_GT_IIR(3), tmp);
  1260. } else
  1261. DRM_ERROR("The master control interrupt lied (GT3)!\n");
  1262. }
  1263. return ret;
  1264. }
  1265. #define HPD_STORM_DETECT_PERIOD 1000
  1266. #define HPD_STORM_THRESHOLD 5
  1267. static inline void intel_hpd_irq_handler(struct drm_device *dev,
  1268. u32 hotplug_trigger,
  1269. const u32 *hpd)
  1270. {
  1271. struct drm_i915_private *dev_priv = dev->dev_private;
  1272. int i;
  1273. bool storm_detected = false;
  1274. if (!hotplug_trigger)
  1275. return;
  1276. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  1277. hotplug_trigger);
  1278. spin_lock(&dev_priv->irq_lock);
  1279. for (i = 1; i < HPD_NUM_PINS; i++) {
  1280. if (hpd[i] & hotplug_trigger &&
  1281. dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) {
  1282. /*
  1283. * On GMCH platforms the interrupt mask bits only
  1284. * prevent irq generation, not the setting of the
  1285. * hotplug bits itself. So only WARN about unexpected
  1286. * interrupts on saner platforms.
  1287. */
  1288. WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev),
  1289. "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
  1290. hotplug_trigger, i, hpd[i]);
  1291. continue;
  1292. }
  1293. if (!(hpd[i] & hotplug_trigger) ||
  1294. dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
  1295. continue;
  1296. dev_priv->hpd_event_bits |= (1 << i);
  1297. if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
  1298. dev_priv->hpd_stats[i].hpd_last_jiffies
  1299. + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
  1300. dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
  1301. dev_priv->hpd_stats[i].hpd_cnt = 0;
  1302. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
  1303. } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
  1304. dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
  1305. dev_priv->hpd_event_bits &= ~(1 << i);
  1306. DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
  1307. storm_detected = true;
  1308. } else {
  1309. dev_priv->hpd_stats[i].hpd_cnt++;
  1310. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
  1311. dev_priv->hpd_stats[i].hpd_cnt);
  1312. }
  1313. }
  1314. if (storm_detected)
  1315. dev_priv->display.hpd_irq_setup(dev);
  1316. spin_unlock(&dev_priv->irq_lock);
  1317. /*
  1318. * Our hotplug handler can grab modeset locks (by calling down into the
  1319. * fb helpers). Hence it must not be run on our own dev-priv->wq work
  1320. * queue for otherwise the flush_work in the pageflip code will
  1321. * deadlock.
  1322. */
  1323. schedule_work(&dev_priv->hotplug_work);
  1324. }
  1325. static void gmbus_irq_handler(struct drm_device *dev)
  1326. {
  1327. struct drm_i915_private *dev_priv = dev->dev_private;
  1328. wake_up_all(&dev_priv->gmbus_wait_queue);
  1329. }
  1330. static void dp_aux_irq_handler(struct drm_device *dev)
  1331. {
  1332. struct drm_i915_private *dev_priv = dev->dev_private;
  1333. wake_up_all(&dev_priv->gmbus_wait_queue);
  1334. }
  1335. #if defined(CONFIG_DEBUG_FS)
  1336. static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1337. uint32_t crc0, uint32_t crc1,
  1338. uint32_t crc2, uint32_t crc3,
  1339. uint32_t crc4)
  1340. {
  1341. struct drm_i915_private *dev_priv = dev->dev_private;
  1342. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
  1343. struct intel_pipe_crc_entry *entry;
  1344. int head, tail;
  1345. spin_lock(&pipe_crc->lock);
  1346. if (!pipe_crc->entries) {
  1347. spin_unlock(&pipe_crc->lock);
  1348. DRM_ERROR("spurious interrupt\n");
  1349. return;
  1350. }
  1351. head = pipe_crc->head;
  1352. tail = pipe_crc->tail;
  1353. if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
  1354. spin_unlock(&pipe_crc->lock);
  1355. DRM_ERROR("CRC buffer overflowing\n");
  1356. return;
  1357. }
  1358. entry = &pipe_crc->entries[head];
  1359. entry->frame = dev->driver->get_vblank_counter(dev, pipe);
  1360. entry->crc[0] = crc0;
  1361. entry->crc[1] = crc1;
  1362. entry->crc[2] = crc2;
  1363. entry->crc[3] = crc3;
  1364. entry->crc[4] = crc4;
  1365. head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
  1366. pipe_crc->head = head;
  1367. spin_unlock(&pipe_crc->lock);
  1368. wake_up_interruptible(&pipe_crc->wq);
  1369. }
  1370. #else
  1371. static inline void
  1372. display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1373. uint32_t crc0, uint32_t crc1,
  1374. uint32_t crc2, uint32_t crc3,
  1375. uint32_t crc4) {}
  1376. #endif
  1377. static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1378. {
  1379. struct drm_i915_private *dev_priv = dev->dev_private;
  1380. display_pipe_crc_irq_handler(dev, pipe,
  1381. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1382. 0, 0, 0, 0);
  1383. }
  1384. static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1385. {
  1386. struct drm_i915_private *dev_priv = dev->dev_private;
  1387. display_pipe_crc_irq_handler(dev, pipe,
  1388. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1389. I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
  1390. I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
  1391. I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
  1392. I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
  1393. }
  1394. static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1395. {
  1396. struct drm_i915_private *dev_priv = dev->dev_private;
  1397. uint32_t res1, res2;
  1398. if (INTEL_INFO(dev)->gen >= 3)
  1399. res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
  1400. else
  1401. res1 = 0;
  1402. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  1403. res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
  1404. else
  1405. res2 = 0;
  1406. display_pipe_crc_irq_handler(dev, pipe,
  1407. I915_READ(PIPE_CRC_RES_RED(pipe)),
  1408. I915_READ(PIPE_CRC_RES_GREEN(pipe)),
  1409. I915_READ(PIPE_CRC_RES_BLUE(pipe)),
  1410. res1, res2);
  1411. }
  1412. /* The RPS events need forcewake, so we add them to a work queue and mask their
  1413. * IMR bits until the work is done. Other interrupts can be processed without
  1414. * the work queue. */
  1415. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
  1416. {
  1417. if (pm_iir & dev_priv->pm_rps_events) {
  1418. spin_lock(&dev_priv->irq_lock);
  1419. dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
  1420. snb_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
  1421. spin_unlock(&dev_priv->irq_lock);
  1422. queue_work(dev_priv->wq, &dev_priv->rps.work);
  1423. }
  1424. if (HAS_VEBOX(dev_priv->dev)) {
  1425. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  1426. notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
  1427. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
  1428. i915_handle_error(dev_priv->dev, false,
  1429. "VEBOX CS error interrupt 0x%08x",
  1430. pm_iir);
  1431. }
  1432. }
  1433. }
  1434. static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
  1435. {
  1436. struct intel_crtc *crtc;
  1437. if (!drm_handle_vblank(dev, pipe))
  1438. return false;
  1439. crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
  1440. wake_up(&crtc->vbl_wait);
  1441. return true;
  1442. }
  1443. static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
  1444. {
  1445. struct drm_i915_private *dev_priv = dev->dev_private;
  1446. u32 pipe_stats[I915_MAX_PIPES] = { };
  1447. int pipe;
  1448. spin_lock(&dev_priv->irq_lock);
  1449. for_each_pipe(pipe) {
  1450. int reg;
  1451. u32 mask, iir_bit = 0;
  1452. /*
  1453. * PIPESTAT bits get signalled even when the interrupt is
  1454. * disabled with the mask bits, and some of the status bits do
  1455. * not generate interrupts at all (like the underrun bit). Hence
  1456. * we need to be careful that we only handle what we want to
  1457. * handle.
  1458. */
  1459. mask = 0;
  1460. if (__cpu_fifo_underrun_reporting_enabled(dev, pipe))
  1461. mask |= PIPE_FIFO_UNDERRUN_STATUS;
  1462. switch (pipe) {
  1463. case PIPE_A:
  1464. iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
  1465. break;
  1466. case PIPE_B:
  1467. iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  1468. break;
  1469. case PIPE_C:
  1470. iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  1471. break;
  1472. }
  1473. if (iir & iir_bit)
  1474. mask |= dev_priv->pipestat_irq_mask[pipe];
  1475. if (!mask)
  1476. continue;
  1477. reg = PIPESTAT(pipe);
  1478. mask |= PIPESTAT_INT_ENABLE_MASK;
  1479. pipe_stats[pipe] = I915_READ(reg) & mask;
  1480. /*
  1481. * Clear the PIPE*STAT regs before the IIR
  1482. */
  1483. if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
  1484. PIPESTAT_INT_STATUS_MASK))
  1485. I915_WRITE(reg, pipe_stats[pipe]);
  1486. }
  1487. spin_unlock(&dev_priv->irq_lock);
  1488. for_each_pipe(pipe) {
  1489. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
  1490. intel_pipe_handle_vblank(dev, pipe);
  1491. if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
  1492. intel_prepare_page_flip(dev, pipe);
  1493. intel_finish_page_flip(dev, pipe);
  1494. }
  1495. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1496. i9xx_pipe_crc_irq_handler(dev, pipe);
  1497. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
  1498. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  1499. DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
  1500. }
  1501. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  1502. gmbus_irq_handler(dev);
  1503. }
  1504. static void i9xx_hpd_irq_handler(struct drm_device *dev)
  1505. {
  1506. struct drm_i915_private *dev_priv = dev->dev_private;
  1507. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1508. if (IS_G4X(dev)) {
  1509. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
  1510. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_g4x);
  1511. } else {
  1512. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  1513. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  1514. }
  1515. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
  1516. hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
  1517. dp_aux_irq_handler(dev);
  1518. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1519. /*
  1520. * Make sure hotplug status is cleared before we clear IIR, or else we
  1521. * may miss hotplug events.
  1522. */
  1523. POSTING_READ(PORT_HOTPLUG_STAT);
  1524. }
  1525. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  1526. {
  1527. struct drm_device *dev = arg;
  1528. struct drm_i915_private *dev_priv = dev->dev_private;
  1529. u32 iir, gt_iir, pm_iir;
  1530. irqreturn_t ret = IRQ_NONE;
  1531. while (true) {
  1532. iir = I915_READ(VLV_IIR);
  1533. gt_iir = I915_READ(GTIIR);
  1534. pm_iir = I915_READ(GEN6_PMIIR);
  1535. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  1536. goto out;
  1537. ret = IRQ_HANDLED;
  1538. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1539. valleyview_pipestat_irq_handler(dev, iir);
  1540. /* Consume port. Then clear IIR or we'll miss events */
  1541. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  1542. i9xx_hpd_irq_handler(dev);
  1543. if (pm_iir)
  1544. gen6_rps_irq_handler(dev_priv, pm_iir);
  1545. I915_WRITE(GTIIR, gt_iir);
  1546. I915_WRITE(GEN6_PMIIR, pm_iir);
  1547. I915_WRITE(VLV_IIR, iir);
  1548. }
  1549. out:
  1550. return ret;
  1551. }
  1552. static irqreturn_t cherryview_irq_handler(int irq, void *arg)
  1553. {
  1554. struct drm_device *dev = arg;
  1555. struct drm_i915_private *dev_priv = dev->dev_private;
  1556. u32 master_ctl, iir;
  1557. irqreturn_t ret = IRQ_NONE;
  1558. for (;;) {
  1559. master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
  1560. iir = I915_READ(VLV_IIR);
  1561. if (master_ctl == 0 && iir == 0)
  1562. break;
  1563. I915_WRITE(GEN8_MASTER_IRQ, 0);
  1564. gen8_gt_irq_handler(dev, dev_priv, master_ctl);
  1565. valleyview_pipestat_irq_handler(dev, iir);
  1566. /* Consume port. Then clear IIR or we'll miss events */
  1567. i9xx_hpd_irq_handler(dev);
  1568. I915_WRITE(VLV_IIR, iir);
  1569. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  1570. POSTING_READ(GEN8_MASTER_IRQ);
  1571. ret = IRQ_HANDLED;
  1572. }
  1573. return ret;
  1574. }
  1575. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  1576. {
  1577. struct drm_i915_private *dev_priv = dev->dev_private;
  1578. int pipe;
  1579. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  1580. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
  1581. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  1582. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  1583. SDE_AUDIO_POWER_SHIFT);
  1584. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  1585. port_name(port));
  1586. }
  1587. if (pch_iir & SDE_AUX_MASK)
  1588. dp_aux_irq_handler(dev);
  1589. if (pch_iir & SDE_GMBUS)
  1590. gmbus_irq_handler(dev);
  1591. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  1592. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  1593. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  1594. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  1595. if (pch_iir & SDE_POISON)
  1596. DRM_ERROR("PCH poison interrupt\n");
  1597. if (pch_iir & SDE_FDI_MASK)
  1598. for_each_pipe(pipe)
  1599. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1600. pipe_name(pipe),
  1601. I915_READ(FDI_RX_IIR(pipe)));
  1602. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  1603. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  1604. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  1605. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  1606. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  1607. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  1608. false))
  1609. DRM_ERROR("PCH transcoder A FIFO underrun\n");
  1610. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  1611. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  1612. false))
  1613. DRM_ERROR("PCH transcoder B FIFO underrun\n");
  1614. }
  1615. static void ivb_err_int_handler(struct drm_device *dev)
  1616. {
  1617. struct drm_i915_private *dev_priv = dev->dev_private;
  1618. u32 err_int = I915_READ(GEN7_ERR_INT);
  1619. enum pipe pipe;
  1620. if (err_int & ERR_INT_POISON)
  1621. DRM_ERROR("Poison interrupt\n");
  1622. for_each_pipe(pipe) {
  1623. if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
  1624. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
  1625. false))
  1626. DRM_ERROR("Pipe %c FIFO underrun\n",
  1627. pipe_name(pipe));
  1628. }
  1629. if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
  1630. if (IS_IVYBRIDGE(dev))
  1631. ivb_pipe_crc_irq_handler(dev, pipe);
  1632. else
  1633. hsw_pipe_crc_irq_handler(dev, pipe);
  1634. }
  1635. }
  1636. I915_WRITE(GEN7_ERR_INT, err_int);
  1637. }
  1638. static void cpt_serr_int_handler(struct drm_device *dev)
  1639. {
  1640. struct drm_i915_private *dev_priv = dev->dev_private;
  1641. u32 serr_int = I915_READ(SERR_INT);
  1642. if (serr_int & SERR_INT_POISON)
  1643. DRM_ERROR("PCH poison interrupt\n");
  1644. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  1645. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  1646. false))
  1647. DRM_ERROR("PCH transcoder A FIFO underrun\n");
  1648. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  1649. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  1650. false))
  1651. DRM_ERROR("PCH transcoder B FIFO underrun\n");
  1652. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  1653. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
  1654. false))
  1655. DRM_ERROR("PCH transcoder C FIFO underrun\n");
  1656. I915_WRITE(SERR_INT, serr_int);
  1657. }
  1658. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  1659. {
  1660. struct drm_i915_private *dev_priv = dev->dev_private;
  1661. int pipe;
  1662. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  1663. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
  1664. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  1665. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  1666. SDE_AUDIO_POWER_SHIFT_CPT);
  1667. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  1668. port_name(port));
  1669. }
  1670. if (pch_iir & SDE_AUX_MASK_CPT)
  1671. dp_aux_irq_handler(dev);
  1672. if (pch_iir & SDE_GMBUS_CPT)
  1673. gmbus_irq_handler(dev);
  1674. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  1675. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  1676. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  1677. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  1678. if (pch_iir & SDE_FDI_MASK_CPT)
  1679. for_each_pipe(pipe)
  1680. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1681. pipe_name(pipe),
  1682. I915_READ(FDI_RX_IIR(pipe)));
  1683. if (pch_iir & SDE_ERROR_CPT)
  1684. cpt_serr_int_handler(dev);
  1685. }
  1686. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1687. {
  1688. struct drm_i915_private *dev_priv = dev->dev_private;
  1689. enum pipe pipe;
  1690. if (de_iir & DE_AUX_CHANNEL_A)
  1691. dp_aux_irq_handler(dev);
  1692. if (de_iir & DE_GSE)
  1693. intel_opregion_asle_intr(dev);
  1694. if (de_iir & DE_POISON)
  1695. DRM_ERROR("Poison interrupt\n");
  1696. for_each_pipe(pipe) {
  1697. if (de_iir & DE_PIPE_VBLANK(pipe))
  1698. intel_pipe_handle_vblank(dev, pipe);
  1699. if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
  1700. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  1701. DRM_ERROR("Pipe %c FIFO underrun\n",
  1702. pipe_name(pipe));
  1703. if (de_iir & DE_PIPE_CRC_DONE(pipe))
  1704. i9xx_pipe_crc_irq_handler(dev, pipe);
  1705. /* plane/pipes map 1:1 on ilk+ */
  1706. if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
  1707. intel_prepare_page_flip(dev, pipe);
  1708. intel_finish_page_flip_plane(dev, pipe);
  1709. }
  1710. }
  1711. /* check event from PCH */
  1712. if (de_iir & DE_PCH_EVENT) {
  1713. u32 pch_iir = I915_READ(SDEIIR);
  1714. if (HAS_PCH_CPT(dev))
  1715. cpt_irq_handler(dev, pch_iir);
  1716. else
  1717. ibx_irq_handler(dev, pch_iir);
  1718. /* should clear PCH hotplug event before clear CPU irq */
  1719. I915_WRITE(SDEIIR, pch_iir);
  1720. }
  1721. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1722. ironlake_rps_change_irq_handler(dev);
  1723. }
  1724. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1725. {
  1726. struct drm_i915_private *dev_priv = dev->dev_private;
  1727. enum pipe pipe;
  1728. if (de_iir & DE_ERR_INT_IVB)
  1729. ivb_err_int_handler(dev);
  1730. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1731. dp_aux_irq_handler(dev);
  1732. if (de_iir & DE_GSE_IVB)
  1733. intel_opregion_asle_intr(dev);
  1734. for_each_pipe(pipe) {
  1735. if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
  1736. intel_pipe_handle_vblank(dev, pipe);
  1737. /* plane/pipes map 1:1 on ilk+ */
  1738. if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
  1739. intel_prepare_page_flip(dev, pipe);
  1740. intel_finish_page_flip_plane(dev, pipe);
  1741. }
  1742. }
  1743. /* check event from PCH */
  1744. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1745. u32 pch_iir = I915_READ(SDEIIR);
  1746. cpt_irq_handler(dev, pch_iir);
  1747. /* clear PCH hotplug event before clear CPU irq */
  1748. I915_WRITE(SDEIIR, pch_iir);
  1749. }
  1750. }
  1751. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1752. {
  1753. struct drm_device *dev = arg;
  1754. struct drm_i915_private *dev_priv = dev->dev_private;
  1755. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1756. irqreturn_t ret = IRQ_NONE;
  1757. /* We get interrupts on unclaimed registers, so check for this before we
  1758. * do any I915_{READ,WRITE}. */
  1759. intel_uncore_check_errors(dev);
  1760. /* disable master interrupt before clearing iir */
  1761. de_ier = I915_READ(DEIER);
  1762. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1763. POSTING_READ(DEIER);
  1764. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1765. * interrupts will will be stored on its back queue, and then we'll be
  1766. * able to process them after we restore SDEIER (as soon as we restore
  1767. * it, we'll get an interrupt if SDEIIR still has something to process
  1768. * due to its back queue). */
  1769. if (!HAS_PCH_NOP(dev)) {
  1770. sde_ier = I915_READ(SDEIER);
  1771. I915_WRITE(SDEIER, 0);
  1772. POSTING_READ(SDEIER);
  1773. }
  1774. gt_iir = I915_READ(GTIIR);
  1775. if (gt_iir) {
  1776. if (INTEL_INFO(dev)->gen >= 6)
  1777. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1778. else
  1779. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1780. I915_WRITE(GTIIR, gt_iir);
  1781. ret = IRQ_HANDLED;
  1782. }
  1783. de_iir = I915_READ(DEIIR);
  1784. if (de_iir) {
  1785. if (INTEL_INFO(dev)->gen >= 7)
  1786. ivb_display_irq_handler(dev, de_iir);
  1787. else
  1788. ilk_display_irq_handler(dev, de_iir);
  1789. I915_WRITE(DEIIR, de_iir);
  1790. ret = IRQ_HANDLED;
  1791. }
  1792. if (INTEL_INFO(dev)->gen >= 6) {
  1793. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1794. if (pm_iir) {
  1795. gen6_rps_irq_handler(dev_priv, pm_iir);
  1796. I915_WRITE(GEN6_PMIIR, pm_iir);
  1797. ret = IRQ_HANDLED;
  1798. }
  1799. }
  1800. I915_WRITE(DEIER, de_ier);
  1801. POSTING_READ(DEIER);
  1802. if (!HAS_PCH_NOP(dev)) {
  1803. I915_WRITE(SDEIER, sde_ier);
  1804. POSTING_READ(SDEIER);
  1805. }
  1806. return ret;
  1807. }
  1808. static irqreturn_t gen8_irq_handler(int irq, void *arg)
  1809. {
  1810. struct drm_device *dev = arg;
  1811. struct drm_i915_private *dev_priv = dev->dev_private;
  1812. u32 master_ctl;
  1813. irqreturn_t ret = IRQ_NONE;
  1814. uint32_t tmp = 0;
  1815. enum pipe pipe;
  1816. master_ctl = I915_READ(GEN8_MASTER_IRQ);
  1817. master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
  1818. if (!master_ctl)
  1819. return IRQ_NONE;
  1820. I915_WRITE(GEN8_MASTER_IRQ, 0);
  1821. POSTING_READ(GEN8_MASTER_IRQ);
  1822. ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
  1823. if (master_ctl & GEN8_DE_MISC_IRQ) {
  1824. tmp = I915_READ(GEN8_DE_MISC_IIR);
  1825. if (tmp & GEN8_DE_MISC_GSE)
  1826. intel_opregion_asle_intr(dev);
  1827. else if (tmp)
  1828. DRM_ERROR("Unexpected DE Misc interrupt\n");
  1829. else
  1830. DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
  1831. if (tmp) {
  1832. I915_WRITE(GEN8_DE_MISC_IIR, tmp);
  1833. ret = IRQ_HANDLED;
  1834. }
  1835. }
  1836. if (master_ctl & GEN8_DE_PORT_IRQ) {
  1837. tmp = I915_READ(GEN8_DE_PORT_IIR);
  1838. if (tmp & GEN8_AUX_CHANNEL_A)
  1839. dp_aux_irq_handler(dev);
  1840. else if (tmp)
  1841. DRM_ERROR("Unexpected DE Port interrupt\n");
  1842. else
  1843. DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
  1844. if (tmp) {
  1845. I915_WRITE(GEN8_DE_PORT_IIR, tmp);
  1846. ret = IRQ_HANDLED;
  1847. }
  1848. }
  1849. for_each_pipe(pipe) {
  1850. uint32_t pipe_iir;
  1851. if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
  1852. continue;
  1853. pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
  1854. if (pipe_iir & GEN8_PIPE_VBLANK)
  1855. intel_pipe_handle_vblank(dev, pipe);
  1856. if (pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE) {
  1857. intel_prepare_page_flip(dev, pipe);
  1858. intel_finish_page_flip_plane(dev, pipe);
  1859. }
  1860. if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
  1861. hsw_pipe_crc_irq_handler(dev, pipe);
  1862. if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
  1863. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
  1864. false))
  1865. DRM_ERROR("Pipe %c FIFO underrun\n",
  1866. pipe_name(pipe));
  1867. }
  1868. if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
  1869. DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
  1870. pipe_name(pipe),
  1871. pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
  1872. }
  1873. if (pipe_iir) {
  1874. ret = IRQ_HANDLED;
  1875. I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
  1876. } else
  1877. DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
  1878. }
  1879. if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
  1880. /*
  1881. * FIXME(BDW): Assume for now that the new interrupt handling
  1882. * scheme also closed the SDE interrupt handling race we've seen
  1883. * on older pch-split platforms. But this needs testing.
  1884. */
  1885. u32 pch_iir = I915_READ(SDEIIR);
  1886. cpt_irq_handler(dev, pch_iir);
  1887. if (pch_iir) {
  1888. I915_WRITE(SDEIIR, pch_iir);
  1889. ret = IRQ_HANDLED;
  1890. }
  1891. }
  1892. I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
  1893. POSTING_READ(GEN8_MASTER_IRQ);
  1894. return ret;
  1895. }
  1896. static void i915_error_wake_up(struct drm_i915_private *dev_priv,
  1897. bool reset_completed)
  1898. {
  1899. struct intel_engine_cs *ring;
  1900. int i;
  1901. /*
  1902. * Notify all waiters for GPU completion events that reset state has
  1903. * been changed, and that they need to restart their wait after
  1904. * checking for potential errors (and bail out to drop locks if there is
  1905. * a gpu reset pending so that i915_error_work_func can acquire them).
  1906. */
  1907. /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
  1908. for_each_ring(ring, dev_priv, i)
  1909. wake_up_all(&ring->irq_queue);
  1910. /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
  1911. wake_up_all(&dev_priv->pending_flip_queue);
  1912. /*
  1913. * Signal tasks blocked in i915_gem_wait_for_error that the pending
  1914. * reset state is cleared.
  1915. */
  1916. if (reset_completed)
  1917. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1918. }
  1919. /**
  1920. * i915_error_work_func - do process context error handling work
  1921. * @work: work struct
  1922. *
  1923. * Fire an error uevent so userspace can see that a hang or error
  1924. * was detected.
  1925. */
  1926. static void i915_error_work_func(struct work_struct *work)
  1927. {
  1928. struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
  1929. work);
  1930. struct drm_i915_private *dev_priv =
  1931. container_of(error, struct drm_i915_private, gpu_error);
  1932. struct drm_device *dev = dev_priv->dev;
  1933. char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
  1934. char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
  1935. char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
  1936. int ret;
  1937. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
  1938. /*
  1939. * Note that there's only one work item which does gpu resets, so we
  1940. * need not worry about concurrent gpu resets potentially incrementing
  1941. * error->reset_counter twice. We only need to take care of another
  1942. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1943. * quick check for that is good enough: schedule_work ensures the
  1944. * correct ordering between hang detection and this work item, and since
  1945. * the reset in-progress bit is only ever set by code outside of this
  1946. * work we don't need to worry about any other races.
  1947. */
  1948. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1949. DRM_DEBUG_DRIVER("resetting chip\n");
  1950. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
  1951. reset_event);
  1952. /*
  1953. * In most cases it's guaranteed that we get here with an RPM
  1954. * reference held, for example because there is a pending GPU
  1955. * request that won't finish until the reset is done. This
  1956. * isn't the case at least when we get here by doing a
  1957. * simulated reset via debugs, so get an RPM reference.
  1958. */
  1959. intel_runtime_pm_get(dev_priv);
  1960. /*
  1961. * All state reset _must_ be completed before we update the
  1962. * reset counter, for otherwise waiters might miss the reset
  1963. * pending state and not properly drop locks, resulting in
  1964. * deadlocks with the reset work.
  1965. */
  1966. ret = i915_reset(dev);
  1967. intel_display_handle_reset(dev);
  1968. intel_runtime_pm_put(dev_priv);
  1969. if (ret == 0) {
  1970. /*
  1971. * After all the gem state is reset, increment the reset
  1972. * counter and wake up everyone waiting for the reset to
  1973. * complete.
  1974. *
  1975. * Since unlock operations are a one-sided barrier only,
  1976. * we need to insert a barrier here to order any seqno
  1977. * updates before
  1978. * the counter increment.
  1979. */
  1980. smp_mb__before_atomic();
  1981. atomic_inc(&dev_priv->gpu_error.reset_counter);
  1982. kobject_uevent_env(&dev->primary->kdev->kobj,
  1983. KOBJ_CHANGE, reset_done_event);
  1984. } else {
  1985. atomic_set_mask(I915_WEDGED, &error->reset_counter);
  1986. }
  1987. /*
  1988. * Note: The wake_up also serves as a memory barrier so that
  1989. * waiters see the update value of the reset counter atomic_t.
  1990. */
  1991. i915_error_wake_up(dev_priv, true);
  1992. }
  1993. }
  1994. static void i915_report_and_clear_eir(struct drm_device *dev)
  1995. {
  1996. struct drm_i915_private *dev_priv = dev->dev_private;
  1997. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1998. u32 eir = I915_READ(EIR);
  1999. int pipe, i;
  2000. if (!eir)
  2001. return;
  2002. pr_err("render error detected, EIR: 0x%08x\n", eir);
  2003. i915_get_extra_instdone(dev, instdone);
  2004. if (IS_G4X(dev)) {
  2005. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  2006. u32 ipeir = I915_READ(IPEIR_I965);
  2007. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  2008. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  2009. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  2010. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  2011. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  2012. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  2013. I915_WRITE(IPEIR_I965, ipeir);
  2014. POSTING_READ(IPEIR_I965);
  2015. }
  2016. if (eir & GM45_ERROR_PAGE_TABLE) {
  2017. u32 pgtbl_err = I915_READ(PGTBL_ER);
  2018. pr_err("page table error\n");
  2019. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  2020. I915_WRITE(PGTBL_ER, pgtbl_err);
  2021. POSTING_READ(PGTBL_ER);
  2022. }
  2023. }
  2024. if (!IS_GEN2(dev)) {
  2025. if (eir & I915_ERROR_PAGE_TABLE) {
  2026. u32 pgtbl_err = I915_READ(PGTBL_ER);
  2027. pr_err("page table error\n");
  2028. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  2029. I915_WRITE(PGTBL_ER, pgtbl_err);
  2030. POSTING_READ(PGTBL_ER);
  2031. }
  2032. }
  2033. if (eir & I915_ERROR_MEMORY_REFRESH) {
  2034. pr_err("memory refresh error:\n");
  2035. for_each_pipe(pipe)
  2036. pr_err("pipe %c stat: 0x%08x\n",
  2037. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  2038. /* pipestat has already been acked */
  2039. }
  2040. if (eir & I915_ERROR_INSTRUCTION) {
  2041. pr_err("instruction error\n");
  2042. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  2043. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  2044. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  2045. if (INTEL_INFO(dev)->gen < 4) {
  2046. u32 ipeir = I915_READ(IPEIR);
  2047. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  2048. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  2049. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  2050. I915_WRITE(IPEIR, ipeir);
  2051. POSTING_READ(IPEIR);
  2052. } else {
  2053. u32 ipeir = I915_READ(IPEIR_I965);
  2054. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  2055. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  2056. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  2057. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  2058. I915_WRITE(IPEIR_I965, ipeir);
  2059. POSTING_READ(IPEIR_I965);
  2060. }
  2061. }
  2062. I915_WRITE(EIR, eir);
  2063. POSTING_READ(EIR);
  2064. eir = I915_READ(EIR);
  2065. if (eir) {
  2066. /*
  2067. * some errors might have become stuck,
  2068. * mask them.
  2069. */
  2070. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  2071. I915_WRITE(EMR, I915_READ(EMR) | eir);
  2072. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2073. }
  2074. }
  2075. /**
  2076. * i915_handle_error - handle an error interrupt
  2077. * @dev: drm device
  2078. *
  2079. * Do some basic checking of regsiter state at error interrupt time and
  2080. * dump it to the syslog. Also call i915_capture_error_state() to make
  2081. * sure we get a record and make it available in debugfs. Fire a uevent
  2082. * so userspace knows something bad happened (should trigger collection
  2083. * of a ring dump etc.).
  2084. */
  2085. void i915_handle_error(struct drm_device *dev, bool wedged,
  2086. const char *fmt, ...)
  2087. {
  2088. struct drm_i915_private *dev_priv = dev->dev_private;
  2089. va_list args;
  2090. char error_msg[80];
  2091. va_start(args, fmt);
  2092. vscnprintf(error_msg, sizeof(error_msg), fmt, args);
  2093. va_end(args);
  2094. i915_capture_error_state(dev, wedged, error_msg);
  2095. i915_report_and_clear_eir(dev);
  2096. if (wedged) {
  2097. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  2098. &dev_priv->gpu_error.reset_counter);
  2099. /*
  2100. * Wakeup waiting processes so that the reset work function
  2101. * i915_error_work_func doesn't deadlock trying to grab various
  2102. * locks. By bumping the reset counter first, the woken
  2103. * processes will see a reset in progress and back off,
  2104. * releasing their locks and then wait for the reset completion.
  2105. * We must do this for _all_ gpu waiters that might hold locks
  2106. * that the reset work needs to acquire.
  2107. *
  2108. * Note: The wake_up serves as the required memory barrier to
  2109. * ensure that the waiters see the updated value of the reset
  2110. * counter atomic_t.
  2111. */
  2112. i915_error_wake_up(dev_priv, false);
  2113. }
  2114. /*
  2115. * Our reset work can grab modeset locks (since it needs to reset the
  2116. * state of outstanding pagelips). Hence it must not be run on our own
  2117. * dev-priv->wq work queue for otherwise the flush_work in the pageflip
  2118. * code will deadlock.
  2119. */
  2120. schedule_work(&dev_priv->gpu_error.work);
  2121. }
  2122. static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  2123. {
  2124. struct drm_i915_private *dev_priv = dev->dev_private;
  2125. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  2126. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2127. struct drm_i915_gem_object *obj;
  2128. struct intel_unpin_work *work;
  2129. unsigned long flags;
  2130. bool stall_detected;
  2131. /* Ignore early vblank irqs */
  2132. if (intel_crtc == NULL)
  2133. return;
  2134. spin_lock_irqsave(&dev->event_lock, flags);
  2135. work = intel_crtc->unpin_work;
  2136. if (work == NULL ||
  2137. atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
  2138. !work->enable_stall_check) {
  2139. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  2140. spin_unlock_irqrestore(&dev->event_lock, flags);
  2141. return;
  2142. }
  2143. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  2144. obj = work->pending_flip_obj;
  2145. if (INTEL_INFO(dev)->gen >= 4) {
  2146. int dspsurf = DSPSURF(intel_crtc->plane);
  2147. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  2148. i915_gem_obj_ggtt_offset(obj);
  2149. } else {
  2150. int dspaddr = DSPADDR(intel_crtc->plane);
  2151. stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
  2152. crtc->y * crtc->primary->fb->pitches[0] +
  2153. crtc->x * crtc->primary->fb->bits_per_pixel/8);
  2154. }
  2155. spin_unlock_irqrestore(&dev->event_lock, flags);
  2156. if (stall_detected) {
  2157. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  2158. intel_prepare_page_flip(dev, intel_crtc->plane);
  2159. }
  2160. }
  2161. /* Called from drm generic code, passed 'crtc' which
  2162. * we use as a pipe index
  2163. */
  2164. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  2165. {
  2166. struct drm_i915_private *dev_priv = dev->dev_private;
  2167. unsigned long irqflags;
  2168. if (!i915_pipe_enabled(dev, pipe))
  2169. return -EINVAL;
  2170. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2171. if (INTEL_INFO(dev)->gen >= 4)
  2172. i915_enable_pipestat(dev_priv, pipe,
  2173. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2174. else
  2175. i915_enable_pipestat(dev_priv, pipe,
  2176. PIPE_VBLANK_INTERRUPT_STATUS);
  2177. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2178. return 0;
  2179. }
  2180. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  2181. {
  2182. struct drm_i915_private *dev_priv = dev->dev_private;
  2183. unsigned long irqflags;
  2184. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2185. DE_PIPE_VBLANK(pipe);
  2186. if (!i915_pipe_enabled(dev, pipe))
  2187. return -EINVAL;
  2188. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2189. ironlake_enable_display_irq(dev_priv, bit);
  2190. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2191. return 0;
  2192. }
  2193. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  2194. {
  2195. struct drm_i915_private *dev_priv = dev->dev_private;
  2196. unsigned long irqflags;
  2197. if (!i915_pipe_enabled(dev, pipe))
  2198. return -EINVAL;
  2199. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2200. i915_enable_pipestat(dev_priv, pipe,
  2201. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2202. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2203. return 0;
  2204. }
  2205. static int gen8_enable_vblank(struct drm_device *dev, int pipe)
  2206. {
  2207. struct drm_i915_private *dev_priv = dev->dev_private;
  2208. unsigned long irqflags;
  2209. if (!i915_pipe_enabled(dev, pipe))
  2210. return -EINVAL;
  2211. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2212. dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
  2213. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2214. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2215. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2216. return 0;
  2217. }
  2218. /* Called from drm generic code, passed 'crtc' which
  2219. * we use as a pipe index
  2220. */
  2221. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  2222. {
  2223. struct drm_i915_private *dev_priv = dev->dev_private;
  2224. unsigned long irqflags;
  2225. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2226. i915_disable_pipestat(dev_priv, pipe,
  2227. PIPE_VBLANK_INTERRUPT_STATUS |
  2228. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2229. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2230. }
  2231. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  2232. {
  2233. struct drm_i915_private *dev_priv = dev->dev_private;
  2234. unsigned long irqflags;
  2235. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2236. DE_PIPE_VBLANK(pipe);
  2237. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2238. ironlake_disable_display_irq(dev_priv, bit);
  2239. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2240. }
  2241. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  2242. {
  2243. struct drm_i915_private *dev_priv = dev->dev_private;
  2244. unsigned long irqflags;
  2245. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2246. i915_disable_pipestat(dev_priv, pipe,
  2247. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2248. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2249. }
  2250. static void gen8_disable_vblank(struct drm_device *dev, int pipe)
  2251. {
  2252. struct drm_i915_private *dev_priv = dev->dev_private;
  2253. unsigned long irqflags;
  2254. if (!i915_pipe_enabled(dev, pipe))
  2255. return;
  2256. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2257. dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
  2258. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2259. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2260. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2261. }
  2262. static u32
  2263. ring_last_seqno(struct intel_engine_cs *ring)
  2264. {
  2265. return list_entry(ring->request_list.prev,
  2266. struct drm_i915_gem_request, list)->seqno;
  2267. }
  2268. static bool
  2269. ring_idle(struct intel_engine_cs *ring, u32 seqno)
  2270. {
  2271. return (list_empty(&ring->request_list) ||
  2272. i915_seqno_passed(seqno, ring_last_seqno(ring)));
  2273. }
  2274. static bool
  2275. ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
  2276. {
  2277. if (INTEL_INFO(dev)->gen >= 8) {
  2278. /*
  2279. * FIXME: gen8 semaphore support - currently we don't emit
  2280. * semaphores on bdw anyway, but this needs to be addressed when
  2281. * we merge that code.
  2282. */
  2283. return false;
  2284. } else {
  2285. ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
  2286. return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
  2287. MI_SEMAPHORE_REGISTER);
  2288. }
  2289. }
  2290. static struct intel_engine_cs *
  2291. semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr)
  2292. {
  2293. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2294. struct intel_engine_cs *signaller;
  2295. int i;
  2296. if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
  2297. /*
  2298. * FIXME: gen8 semaphore support - currently we don't emit
  2299. * semaphores on bdw anyway, but this needs to be addressed when
  2300. * we merge that code.
  2301. */
  2302. return NULL;
  2303. } else {
  2304. u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
  2305. for_each_ring(signaller, dev_priv, i) {
  2306. if(ring == signaller)
  2307. continue;
  2308. if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
  2309. return signaller;
  2310. }
  2311. }
  2312. DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x\n",
  2313. ring->id, ipehr);
  2314. return NULL;
  2315. }
  2316. static struct intel_engine_cs *
  2317. semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
  2318. {
  2319. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2320. u32 cmd, ipehr, head;
  2321. int i;
  2322. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  2323. if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
  2324. return NULL;
  2325. /*
  2326. * HEAD is likely pointing to the dword after the actual command,
  2327. * so scan backwards until we find the MBOX. But limit it to just 3
  2328. * dwords. Note that we don't care about ACTHD here since that might
  2329. * point at at batch, and semaphores are always emitted into the
  2330. * ringbuffer itself.
  2331. */
  2332. head = I915_READ_HEAD(ring) & HEAD_ADDR;
  2333. for (i = 4; i; --i) {
  2334. /*
  2335. * Be paranoid and presume the hw has gone off into the wild -
  2336. * our ring is smaller than what the hardware (and hence
  2337. * HEAD_ADDR) allows. Also handles wrap-around.
  2338. */
  2339. head &= ring->buffer->size - 1;
  2340. /* This here seems to blow up */
  2341. cmd = ioread32(ring->buffer->virtual_start + head);
  2342. if (cmd == ipehr)
  2343. break;
  2344. head -= 4;
  2345. }
  2346. if (!i)
  2347. return NULL;
  2348. *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
  2349. return semaphore_wait_to_signaller_ring(ring, ipehr);
  2350. }
  2351. static int semaphore_passed(struct intel_engine_cs *ring)
  2352. {
  2353. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2354. struct intel_engine_cs *signaller;
  2355. u32 seqno;
  2356. ring->hangcheck.deadlock++;
  2357. signaller = semaphore_waits_for(ring, &seqno);
  2358. if (signaller == NULL)
  2359. return -1;
  2360. /* Prevent pathological recursion due to driver bugs */
  2361. if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
  2362. return -1;
  2363. if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
  2364. return 1;
  2365. /* cursory check for an unkickable deadlock */
  2366. if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
  2367. semaphore_passed(signaller) < 0)
  2368. return -1;
  2369. return 0;
  2370. }
  2371. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  2372. {
  2373. struct intel_engine_cs *ring;
  2374. int i;
  2375. for_each_ring(ring, dev_priv, i)
  2376. ring->hangcheck.deadlock = 0;
  2377. }
  2378. static enum intel_ring_hangcheck_action
  2379. ring_stuck(struct intel_engine_cs *ring, u64 acthd)
  2380. {
  2381. struct drm_device *dev = ring->dev;
  2382. struct drm_i915_private *dev_priv = dev->dev_private;
  2383. u32 tmp;
  2384. if (ring->hangcheck.acthd != acthd)
  2385. return HANGCHECK_ACTIVE;
  2386. if (IS_GEN2(dev))
  2387. return HANGCHECK_HUNG;
  2388. /* Is the chip hanging on a WAIT_FOR_EVENT?
  2389. * If so we can simply poke the RB_WAIT bit
  2390. * and break the hang. This should work on
  2391. * all but the second generation chipsets.
  2392. */
  2393. tmp = I915_READ_CTL(ring);
  2394. if (tmp & RING_WAIT) {
  2395. i915_handle_error(dev, false,
  2396. "Kicking stuck wait on %s",
  2397. ring->name);
  2398. I915_WRITE_CTL(ring, tmp);
  2399. return HANGCHECK_KICK;
  2400. }
  2401. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  2402. switch (semaphore_passed(ring)) {
  2403. default:
  2404. return HANGCHECK_HUNG;
  2405. case 1:
  2406. i915_handle_error(dev, false,
  2407. "Kicking stuck semaphore on %s",
  2408. ring->name);
  2409. I915_WRITE_CTL(ring, tmp);
  2410. return HANGCHECK_KICK;
  2411. case 0:
  2412. return HANGCHECK_WAIT;
  2413. }
  2414. }
  2415. return HANGCHECK_HUNG;
  2416. }
  2417. /**
  2418. * This is called when the chip hasn't reported back with completed
  2419. * batchbuffers in a long time. We keep track per ring seqno progress and
  2420. * if there are no progress, hangcheck score for that ring is increased.
  2421. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  2422. * we kick the ring. If we see no progress on three subsequent calls
  2423. * we assume chip is wedged and try to fix it by resetting the chip.
  2424. */
  2425. static void i915_hangcheck_elapsed(unsigned long data)
  2426. {
  2427. struct drm_device *dev = (struct drm_device *)data;
  2428. struct drm_i915_private *dev_priv = dev->dev_private;
  2429. struct intel_engine_cs *ring;
  2430. int i;
  2431. int busy_count = 0, rings_hung = 0;
  2432. bool stuck[I915_NUM_RINGS] = { 0 };
  2433. #define BUSY 1
  2434. #define KICK 5
  2435. #define HUNG 20
  2436. if (!i915.enable_hangcheck)
  2437. return;
  2438. for_each_ring(ring, dev_priv, i) {
  2439. u64 acthd;
  2440. u32 seqno;
  2441. bool busy = true;
  2442. semaphore_clear_deadlocks(dev_priv);
  2443. seqno = ring->get_seqno(ring, false);
  2444. acthd = intel_ring_get_active_head(ring);
  2445. if (ring->hangcheck.seqno == seqno) {
  2446. if (ring_idle(ring, seqno)) {
  2447. ring->hangcheck.action = HANGCHECK_IDLE;
  2448. if (waitqueue_active(&ring->irq_queue)) {
  2449. /* Issue a wake-up to catch stuck h/w. */
  2450. if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
  2451. if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
  2452. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  2453. ring->name);
  2454. else
  2455. DRM_INFO("Fake missed irq on %s\n",
  2456. ring->name);
  2457. wake_up_all(&ring->irq_queue);
  2458. }
  2459. /* Safeguard against driver failure */
  2460. ring->hangcheck.score += BUSY;
  2461. } else
  2462. busy = false;
  2463. } else {
  2464. /* We always increment the hangcheck score
  2465. * if the ring is busy and still processing
  2466. * the same request, so that no single request
  2467. * can run indefinitely (such as a chain of
  2468. * batches). The only time we do not increment
  2469. * the hangcheck score on this ring, if this
  2470. * ring is in a legitimate wait for another
  2471. * ring. In that case the waiting ring is a
  2472. * victim and we want to be sure we catch the
  2473. * right culprit. Then every time we do kick
  2474. * the ring, add a small increment to the
  2475. * score so that we can catch a batch that is
  2476. * being repeatedly kicked and so responsible
  2477. * for stalling the machine.
  2478. */
  2479. ring->hangcheck.action = ring_stuck(ring,
  2480. acthd);
  2481. switch (ring->hangcheck.action) {
  2482. case HANGCHECK_IDLE:
  2483. case HANGCHECK_WAIT:
  2484. break;
  2485. case HANGCHECK_ACTIVE:
  2486. ring->hangcheck.score += BUSY;
  2487. break;
  2488. case HANGCHECK_KICK:
  2489. ring->hangcheck.score += KICK;
  2490. break;
  2491. case HANGCHECK_HUNG:
  2492. ring->hangcheck.score += HUNG;
  2493. stuck[i] = true;
  2494. break;
  2495. }
  2496. }
  2497. } else {
  2498. ring->hangcheck.action = HANGCHECK_ACTIVE;
  2499. /* Gradually reduce the count so that we catch DoS
  2500. * attempts across multiple batches.
  2501. */
  2502. if (ring->hangcheck.score > 0)
  2503. ring->hangcheck.score--;
  2504. }
  2505. ring->hangcheck.seqno = seqno;
  2506. ring->hangcheck.acthd = acthd;
  2507. busy_count += busy;
  2508. }
  2509. for_each_ring(ring, dev_priv, i) {
  2510. if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
  2511. DRM_INFO("%s on %s\n",
  2512. stuck[i] ? "stuck" : "no progress",
  2513. ring->name);
  2514. rings_hung++;
  2515. }
  2516. }
  2517. if (rings_hung)
  2518. return i915_handle_error(dev, true, "Ring hung");
  2519. if (busy_count)
  2520. /* Reset timer case chip hangs without another request
  2521. * being added */
  2522. i915_queue_hangcheck(dev);
  2523. }
  2524. void i915_queue_hangcheck(struct drm_device *dev)
  2525. {
  2526. struct drm_i915_private *dev_priv = dev->dev_private;
  2527. if (!i915.enable_hangcheck)
  2528. return;
  2529. mod_timer(&dev_priv->gpu_error.hangcheck_timer,
  2530. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  2531. }
  2532. static void ibx_irq_reset(struct drm_device *dev)
  2533. {
  2534. struct drm_i915_private *dev_priv = dev->dev_private;
  2535. if (HAS_PCH_NOP(dev))
  2536. return;
  2537. GEN5_IRQ_RESET(SDE);
  2538. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  2539. I915_WRITE(SERR_INT, 0xffffffff);
  2540. }
  2541. /*
  2542. * SDEIER is also touched by the interrupt handler to work around missed PCH
  2543. * interrupts. Hence we can't update it after the interrupt handler is enabled -
  2544. * instead we unconditionally enable all PCH interrupt sources here, but then
  2545. * only unmask them as needed with SDEIMR.
  2546. *
  2547. * This function needs to be called before interrupts are enabled.
  2548. */
  2549. static void ibx_irq_pre_postinstall(struct drm_device *dev)
  2550. {
  2551. struct drm_i915_private *dev_priv = dev->dev_private;
  2552. if (HAS_PCH_NOP(dev))
  2553. return;
  2554. WARN_ON(I915_READ(SDEIER) != 0);
  2555. I915_WRITE(SDEIER, 0xffffffff);
  2556. POSTING_READ(SDEIER);
  2557. }
  2558. static void gen5_gt_irq_reset(struct drm_device *dev)
  2559. {
  2560. struct drm_i915_private *dev_priv = dev->dev_private;
  2561. GEN5_IRQ_RESET(GT);
  2562. if (INTEL_INFO(dev)->gen >= 6)
  2563. GEN5_IRQ_RESET(GEN6_PM);
  2564. }
  2565. /* drm_dma.h hooks
  2566. */
  2567. static void ironlake_irq_reset(struct drm_device *dev)
  2568. {
  2569. struct drm_i915_private *dev_priv = dev->dev_private;
  2570. I915_WRITE(HWSTAM, 0xffffffff);
  2571. GEN5_IRQ_RESET(DE);
  2572. if (IS_GEN7(dev))
  2573. I915_WRITE(GEN7_ERR_INT, 0xffffffff);
  2574. gen5_gt_irq_reset(dev);
  2575. ibx_irq_reset(dev);
  2576. }
  2577. static void valleyview_irq_preinstall(struct drm_device *dev)
  2578. {
  2579. struct drm_i915_private *dev_priv = dev->dev_private;
  2580. int pipe;
  2581. /* VLV magic */
  2582. I915_WRITE(VLV_IMR, 0);
  2583. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  2584. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  2585. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  2586. /* and GT */
  2587. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2588. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2589. gen5_gt_irq_reset(dev);
  2590. I915_WRITE(DPINVGTT, 0xff);
  2591. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2592. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2593. for_each_pipe(pipe)
  2594. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2595. I915_WRITE(VLV_IIR, 0xffffffff);
  2596. I915_WRITE(VLV_IMR, 0xffffffff);
  2597. I915_WRITE(VLV_IER, 0x0);
  2598. POSTING_READ(VLV_IER);
  2599. }
  2600. static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
  2601. {
  2602. GEN8_IRQ_RESET_NDX(GT, 0);
  2603. GEN8_IRQ_RESET_NDX(GT, 1);
  2604. GEN8_IRQ_RESET_NDX(GT, 2);
  2605. GEN8_IRQ_RESET_NDX(GT, 3);
  2606. }
  2607. static void gen8_irq_reset(struct drm_device *dev)
  2608. {
  2609. struct drm_i915_private *dev_priv = dev->dev_private;
  2610. int pipe;
  2611. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2612. POSTING_READ(GEN8_MASTER_IRQ);
  2613. gen8_gt_irq_reset(dev_priv);
  2614. for_each_pipe(pipe)
  2615. GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
  2616. GEN5_IRQ_RESET(GEN8_DE_PORT_);
  2617. GEN5_IRQ_RESET(GEN8_DE_MISC_);
  2618. GEN5_IRQ_RESET(GEN8_PCU_);
  2619. ibx_irq_reset(dev);
  2620. }
  2621. static void cherryview_irq_preinstall(struct drm_device *dev)
  2622. {
  2623. struct drm_i915_private *dev_priv = dev->dev_private;
  2624. int pipe;
  2625. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2626. POSTING_READ(GEN8_MASTER_IRQ);
  2627. gen8_gt_irq_reset(dev_priv);
  2628. GEN5_IRQ_RESET(GEN8_PCU_);
  2629. POSTING_READ(GEN8_PCU_IIR);
  2630. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
  2631. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2632. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2633. for_each_pipe(pipe)
  2634. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2635. I915_WRITE(VLV_IMR, 0xffffffff);
  2636. I915_WRITE(VLV_IER, 0x0);
  2637. I915_WRITE(VLV_IIR, 0xffffffff);
  2638. POSTING_READ(VLV_IIR);
  2639. }
  2640. static void ibx_hpd_irq_setup(struct drm_device *dev)
  2641. {
  2642. struct drm_i915_private *dev_priv = dev->dev_private;
  2643. struct drm_mode_config *mode_config = &dev->mode_config;
  2644. struct intel_encoder *intel_encoder;
  2645. u32 hotplug_irqs, hotplug, enabled_irqs = 0;
  2646. if (HAS_PCH_IBX(dev)) {
  2647. hotplug_irqs = SDE_HOTPLUG_MASK;
  2648. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2649. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2650. enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
  2651. } else {
  2652. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  2653. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2654. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2655. enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
  2656. }
  2657. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2658. /*
  2659. * Enable digital hotplug on the PCH, and configure the DP short pulse
  2660. * duration to 2ms (which is the minimum in the Display Port spec)
  2661. *
  2662. * This register is the same on all known PCH chips.
  2663. */
  2664. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  2665. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  2666. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  2667. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  2668. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  2669. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  2670. }
  2671. static void ibx_irq_postinstall(struct drm_device *dev)
  2672. {
  2673. struct drm_i915_private *dev_priv = dev->dev_private;
  2674. u32 mask;
  2675. if (HAS_PCH_NOP(dev))
  2676. return;
  2677. if (HAS_PCH_IBX(dev))
  2678. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
  2679. else
  2680. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
  2681. GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
  2682. I915_WRITE(SDEIMR, ~mask);
  2683. }
  2684. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  2685. {
  2686. struct drm_i915_private *dev_priv = dev->dev_private;
  2687. u32 pm_irqs, gt_irqs;
  2688. pm_irqs = gt_irqs = 0;
  2689. dev_priv->gt_irq_mask = ~0;
  2690. if (HAS_L3_DPF(dev)) {
  2691. /* L3 parity interrupt is always unmasked. */
  2692. dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
  2693. gt_irqs |= GT_PARITY_ERROR(dev);
  2694. }
  2695. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  2696. if (IS_GEN5(dev)) {
  2697. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  2698. ILK_BSD_USER_INTERRUPT;
  2699. } else {
  2700. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  2701. }
  2702. GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
  2703. if (INTEL_INFO(dev)->gen >= 6) {
  2704. pm_irqs |= dev_priv->pm_rps_events;
  2705. if (HAS_VEBOX(dev))
  2706. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  2707. dev_priv->pm_irq_mask = 0xffffffff;
  2708. GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
  2709. }
  2710. }
  2711. static int ironlake_irq_postinstall(struct drm_device *dev)
  2712. {
  2713. unsigned long irqflags;
  2714. struct drm_i915_private *dev_priv = dev->dev_private;
  2715. u32 display_mask, extra_mask;
  2716. if (INTEL_INFO(dev)->gen >= 7) {
  2717. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  2718. DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
  2719. DE_PLANEB_FLIP_DONE_IVB |
  2720. DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
  2721. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  2722. DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
  2723. } else {
  2724. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  2725. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  2726. DE_AUX_CHANNEL_A |
  2727. DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
  2728. DE_POISON);
  2729. extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
  2730. DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
  2731. }
  2732. dev_priv->irq_mask = ~display_mask;
  2733. I915_WRITE(HWSTAM, 0xeffe);
  2734. ibx_irq_pre_postinstall(dev);
  2735. GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
  2736. gen5_gt_irq_postinstall(dev);
  2737. ibx_irq_postinstall(dev);
  2738. if (IS_IRONLAKE_M(dev)) {
  2739. /* Enable PCU event interrupts
  2740. *
  2741. * spinlocking not required here for correctness since interrupt
  2742. * setup is guaranteed to run in single-threaded context. But we
  2743. * need it to make the assert_spin_locked happy. */
  2744. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2745. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  2746. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2747. }
  2748. return 0;
  2749. }
  2750. static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
  2751. {
  2752. u32 pipestat_mask;
  2753. u32 iir_mask;
  2754. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2755. PIPE_FIFO_UNDERRUN_STATUS;
  2756. I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
  2757. I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
  2758. POSTING_READ(PIPESTAT(PIPE_A));
  2759. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2760. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2761. i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask |
  2762. PIPE_GMBUS_INTERRUPT_STATUS);
  2763. i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask);
  2764. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2765. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2766. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2767. dev_priv->irq_mask &= ~iir_mask;
  2768. I915_WRITE(VLV_IIR, iir_mask);
  2769. I915_WRITE(VLV_IIR, iir_mask);
  2770. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2771. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2772. POSTING_READ(VLV_IER);
  2773. }
  2774. static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
  2775. {
  2776. u32 pipestat_mask;
  2777. u32 iir_mask;
  2778. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2779. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2780. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2781. dev_priv->irq_mask |= iir_mask;
  2782. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2783. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2784. I915_WRITE(VLV_IIR, iir_mask);
  2785. I915_WRITE(VLV_IIR, iir_mask);
  2786. POSTING_READ(VLV_IIR);
  2787. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2788. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2789. i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask |
  2790. PIPE_GMBUS_INTERRUPT_STATUS);
  2791. i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask);
  2792. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2793. PIPE_FIFO_UNDERRUN_STATUS;
  2794. I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
  2795. I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
  2796. POSTING_READ(PIPESTAT(PIPE_A));
  2797. }
  2798. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
  2799. {
  2800. assert_spin_locked(&dev_priv->irq_lock);
  2801. if (dev_priv->display_irqs_enabled)
  2802. return;
  2803. dev_priv->display_irqs_enabled = true;
  2804. if (dev_priv->dev->irq_enabled)
  2805. valleyview_display_irqs_install(dev_priv);
  2806. }
  2807. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
  2808. {
  2809. assert_spin_locked(&dev_priv->irq_lock);
  2810. if (!dev_priv->display_irqs_enabled)
  2811. return;
  2812. dev_priv->display_irqs_enabled = false;
  2813. if (dev_priv->dev->irq_enabled)
  2814. valleyview_display_irqs_uninstall(dev_priv);
  2815. }
  2816. static int valleyview_irq_postinstall(struct drm_device *dev)
  2817. {
  2818. struct drm_i915_private *dev_priv = dev->dev_private;
  2819. unsigned long irqflags;
  2820. dev_priv->irq_mask = ~0;
  2821. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2822. POSTING_READ(PORT_HOTPLUG_EN);
  2823. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2824. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2825. I915_WRITE(VLV_IIR, 0xffffffff);
  2826. POSTING_READ(VLV_IER);
  2827. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2828. * just to make the assert_spin_locked check happy. */
  2829. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2830. if (dev_priv->display_irqs_enabled)
  2831. valleyview_display_irqs_install(dev_priv);
  2832. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2833. I915_WRITE(VLV_IIR, 0xffffffff);
  2834. I915_WRITE(VLV_IIR, 0xffffffff);
  2835. gen5_gt_irq_postinstall(dev);
  2836. /* ack & enable invalid PTE error interrupts */
  2837. #if 0 /* FIXME: add support to irq handler for checking these bits */
  2838. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2839. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  2840. #endif
  2841. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  2842. return 0;
  2843. }
  2844. static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
  2845. {
  2846. int i;
  2847. /* These are interrupts we'll toggle with the ring mask register */
  2848. uint32_t gt_interrupts[] = {
  2849. GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  2850. GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
  2851. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
  2852. GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
  2853. GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
  2854. 0,
  2855. GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
  2856. };
  2857. for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++)
  2858. GEN8_IRQ_INIT_NDX(GT, i, ~gt_interrupts[i], gt_interrupts[i]);
  2859. dev_priv->pm_irq_mask = 0xffffffff;
  2860. }
  2861. static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
  2862. {
  2863. struct drm_device *dev = dev_priv->dev;
  2864. uint32_t de_pipe_masked = GEN8_PIPE_PRIMARY_FLIP_DONE |
  2865. GEN8_PIPE_CDCLK_CRC_DONE |
  2866. GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  2867. uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
  2868. GEN8_PIPE_FIFO_UNDERRUN;
  2869. int pipe;
  2870. dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
  2871. dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
  2872. dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
  2873. for_each_pipe(pipe)
  2874. GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, dev_priv->de_irq_mask[pipe],
  2875. de_pipe_enables);
  2876. GEN5_IRQ_INIT(GEN8_DE_PORT_, ~GEN8_AUX_CHANNEL_A, GEN8_AUX_CHANNEL_A);
  2877. }
  2878. static int gen8_irq_postinstall(struct drm_device *dev)
  2879. {
  2880. struct drm_i915_private *dev_priv = dev->dev_private;
  2881. ibx_irq_pre_postinstall(dev);
  2882. gen8_gt_irq_postinstall(dev_priv);
  2883. gen8_de_irq_postinstall(dev_priv);
  2884. ibx_irq_postinstall(dev);
  2885. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  2886. POSTING_READ(GEN8_MASTER_IRQ);
  2887. return 0;
  2888. }
  2889. static int cherryview_irq_postinstall(struct drm_device *dev)
  2890. {
  2891. struct drm_i915_private *dev_priv = dev->dev_private;
  2892. u32 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
  2893. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2894. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2895. I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  2896. u32 pipestat_enable = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2897. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2898. unsigned long irqflags;
  2899. int pipe;
  2900. /*
  2901. * Leave vblank interrupts masked initially. enable/disable will
  2902. * toggle them based on usage.
  2903. */
  2904. dev_priv->irq_mask = ~enable_mask;
  2905. for_each_pipe(pipe)
  2906. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2907. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2908. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  2909. for_each_pipe(pipe)
  2910. i915_enable_pipestat(dev_priv, pipe, pipestat_enable);
  2911. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2912. I915_WRITE(VLV_IIR, 0xffffffff);
  2913. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2914. I915_WRITE(VLV_IER, enable_mask);
  2915. gen8_gt_irq_postinstall(dev_priv);
  2916. I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
  2917. POSTING_READ(GEN8_MASTER_IRQ);
  2918. return 0;
  2919. }
  2920. static void gen8_irq_uninstall(struct drm_device *dev)
  2921. {
  2922. struct drm_i915_private *dev_priv = dev->dev_private;
  2923. if (!dev_priv)
  2924. return;
  2925. intel_hpd_irq_uninstall(dev_priv);
  2926. gen8_irq_reset(dev);
  2927. }
  2928. static void valleyview_irq_uninstall(struct drm_device *dev)
  2929. {
  2930. struct drm_i915_private *dev_priv = dev->dev_private;
  2931. unsigned long irqflags;
  2932. int pipe;
  2933. if (!dev_priv)
  2934. return;
  2935. I915_WRITE(VLV_MASTER_IER, 0);
  2936. intel_hpd_irq_uninstall(dev_priv);
  2937. for_each_pipe(pipe)
  2938. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2939. I915_WRITE(HWSTAM, 0xffffffff);
  2940. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2941. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2942. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2943. if (dev_priv->display_irqs_enabled)
  2944. valleyview_display_irqs_uninstall(dev_priv);
  2945. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2946. dev_priv->irq_mask = 0;
  2947. I915_WRITE(VLV_IIR, 0xffffffff);
  2948. I915_WRITE(VLV_IMR, 0xffffffff);
  2949. I915_WRITE(VLV_IER, 0x0);
  2950. POSTING_READ(VLV_IER);
  2951. }
  2952. static void cherryview_irq_uninstall(struct drm_device *dev)
  2953. {
  2954. struct drm_i915_private *dev_priv = dev->dev_private;
  2955. int pipe;
  2956. if (!dev_priv)
  2957. return;
  2958. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2959. POSTING_READ(GEN8_MASTER_IRQ);
  2960. #define GEN8_IRQ_FINI_NDX(type, which) \
  2961. do { \
  2962. I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
  2963. I915_WRITE(GEN8_##type##_IER(which), 0); \
  2964. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  2965. POSTING_READ(GEN8_##type##_IIR(which)); \
  2966. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  2967. } while (0)
  2968. #define GEN8_IRQ_FINI(type) \
  2969. do { \
  2970. I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
  2971. I915_WRITE(GEN8_##type##_IER, 0); \
  2972. I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
  2973. POSTING_READ(GEN8_##type##_IIR); \
  2974. I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
  2975. } while (0)
  2976. GEN8_IRQ_FINI_NDX(GT, 0);
  2977. GEN8_IRQ_FINI_NDX(GT, 1);
  2978. GEN8_IRQ_FINI_NDX(GT, 2);
  2979. GEN8_IRQ_FINI_NDX(GT, 3);
  2980. GEN8_IRQ_FINI(PCU);
  2981. #undef GEN8_IRQ_FINI
  2982. #undef GEN8_IRQ_FINI_NDX
  2983. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2984. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2985. for_each_pipe(pipe)
  2986. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2987. I915_WRITE(VLV_IMR, 0xffffffff);
  2988. I915_WRITE(VLV_IER, 0x0);
  2989. I915_WRITE(VLV_IIR, 0xffffffff);
  2990. POSTING_READ(VLV_IIR);
  2991. }
  2992. static void ironlake_irq_uninstall(struct drm_device *dev)
  2993. {
  2994. struct drm_i915_private *dev_priv = dev->dev_private;
  2995. if (!dev_priv)
  2996. return;
  2997. intel_hpd_irq_uninstall(dev_priv);
  2998. ironlake_irq_reset(dev);
  2999. }
  3000. static void i8xx_irq_preinstall(struct drm_device * dev)
  3001. {
  3002. struct drm_i915_private *dev_priv = dev->dev_private;
  3003. int pipe;
  3004. for_each_pipe(pipe)
  3005. I915_WRITE(PIPESTAT(pipe), 0);
  3006. I915_WRITE16(IMR, 0xffff);
  3007. I915_WRITE16(IER, 0x0);
  3008. POSTING_READ16(IER);
  3009. }
  3010. static int i8xx_irq_postinstall(struct drm_device *dev)
  3011. {
  3012. struct drm_i915_private *dev_priv = dev->dev_private;
  3013. unsigned long irqflags;
  3014. I915_WRITE16(EMR,
  3015. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  3016. /* Unmask the interrupts that we always want on. */
  3017. dev_priv->irq_mask =
  3018. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3019. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3020. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3021. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  3022. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  3023. I915_WRITE16(IMR, dev_priv->irq_mask);
  3024. I915_WRITE16(IER,
  3025. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3026. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3027. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  3028. I915_USER_INTERRUPT);
  3029. POSTING_READ16(IER);
  3030. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3031. * just to make the assert_spin_locked check happy. */
  3032. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3033. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3034. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3035. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3036. return 0;
  3037. }
  3038. /*
  3039. * Returns true when a page flip has completed.
  3040. */
  3041. static bool i8xx_handle_vblank(struct drm_device *dev,
  3042. int plane, int pipe, u32 iir)
  3043. {
  3044. struct drm_i915_private *dev_priv = dev->dev_private;
  3045. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  3046. if (!intel_pipe_handle_vblank(dev, pipe))
  3047. return false;
  3048. if ((iir & flip_pending) == 0)
  3049. return false;
  3050. intel_prepare_page_flip(dev, plane);
  3051. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  3052. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  3053. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  3054. * the flip is completed (no longer pending). Since this doesn't raise
  3055. * an interrupt per se, we watch for the change at vblank.
  3056. */
  3057. if (I915_READ16(ISR) & flip_pending)
  3058. return false;
  3059. intel_finish_page_flip(dev, pipe);
  3060. return true;
  3061. }
  3062. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  3063. {
  3064. struct drm_device *dev = arg;
  3065. struct drm_i915_private *dev_priv = dev->dev_private;
  3066. u16 iir, new_iir;
  3067. u32 pipe_stats[2];
  3068. unsigned long irqflags;
  3069. int pipe;
  3070. u16 flip_mask =
  3071. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3072. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3073. iir = I915_READ16(IIR);
  3074. if (iir == 0)
  3075. return IRQ_NONE;
  3076. while (iir & ~flip_mask) {
  3077. /* Can't rely on pipestat interrupt bit in iir as it might
  3078. * have been cleared after the pipestat interrupt was received.
  3079. * It doesn't set the bit in iir again, but it still produces
  3080. * interrupts (for non-MSI).
  3081. */
  3082. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3083. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3084. i915_handle_error(dev, false,
  3085. "Command parser error, iir 0x%08x",
  3086. iir);
  3087. for_each_pipe(pipe) {
  3088. int reg = PIPESTAT(pipe);
  3089. pipe_stats[pipe] = I915_READ(reg);
  3090. /*
  3091. * Clear the PIPE*STAT regs before the IIR
  3092. */
  3093. if (pipe_stats[pipe] & 0x8000ffff)
  3094. I915_WRITE(reg, pipe_stats[pipe]);
  3095. }
  3096. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3097. I915_WRITE16(IIR, iir & ~flip_mask);
  3098. new_iir = I915_READ16(IIR); /* Flush posted writes */
  3099. i915_update_dri1_breadcrumb(dev);
  3100. if (iir & I915_USER_INTERRUPT)
  3101. notify_ring(dev, &dev_priv->ring[RCS]);
  3102. for_each_pipe(pipe) {
  3103. int plane = pipe;
  3104. if (HAS_FBC(dev))
  3105. plane = !plane;
  3106. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  3107. i8xx_handle_vblank(dev, plane, pipe, iir))
  3108. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  3109. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3110. i9xx_pipe_crc_irq_handler(dev, pipe);
  3111. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
  3112. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  3113. DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
  3114. }
  3115. iir = new_iir;
  3116. }
  3117. return IRQ_HANDLED;
  3118. }
  3119. static void i8xx_irq_uninstall(struct drm_device * dev)
  3120. {
  3121. struct drm_i915_private *dev_priv = dev->dev_private;
  3122. int pipe;
  3123. for_each_pipe(pipe) {
  3124. /* Clear enable bits; then clear status bits */
  3125. I915_WRITE(PIPESTAT(pipe), 0);
  3126. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  3127. }
  3128. I915_WRITE16(IMR, 0xffff);
  3129. I915_WRITE16(IER, 0x0);
  3130. I915_WRITE16(IIR, I915_READ16(IIR));
  3131. }
  3132. static void i915_irq_preinstall(struct drm_device * dev)
  3133. {
  3134. struct drm_i915_private *dev_priv = dev->dev_private;
  3135. int pipe;
  3136. if (I915_HAS_HOTPLUG(dev)) {
  3137. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3138. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3139. }
  3140. I915_WRITE16(HWSTAM, 0xeffe);
  3141. for_each_pipe(pipe)
  3142. I915_WRITE(PIPESTAT(pipe), 0);
  3143. I915_WRITE(IMR, 0xffffffff);
  3144. I915_WRITE(IER, 0x0);
  3145. POSTING_READ(IER);
  3146. }
  3147. static int i915_irq_postinstall(struct drm_device *dev)
  3148. {
  3149. struct drm_i915_private *dev_priv = dev->dev_private;
  3150. u32 enable_mask;
  3151. unsigned long irqflags;
  3152. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  3153. /* Unmask the interrupts that we always want on. */
  3154. dev_priv->irq_mask =
  3155. ~(I915_ASLE_INTERRUPT |
  3156. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3157. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3158. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3159. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  3160. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  3161. enable_mask =
  3162. I915_ASLE_INTERRUPT |
  3163. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3164. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3165. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  3166. I915_USER_INTERRUPT;
  3167. if (I915_HAS_HOTPLUG(dev)) {
  3168. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3169. POSTING_READ(PORT_HOTPLUG_EN);
  3170. /* Enable in IER... */
  3171. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  3172. /* and unmask in IMR */
  3173. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  3174. }
  3175. I915_WRITE(IMR, dev_priv->irq_mask);
  3176. I915_WRITE(IER, enable_mask);
  3177. POSTING_READ(IER);
  3178. i915_enable_asle_pipestat(dev);
  3179. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3180. * just to make the assert_spin_locked check happy. */
  3181. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3182. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3183. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3184. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3185. return 0;
  3186. }
  3187. /*
  3188. * Returns true when a page flip has completed.
  3189. */
  3190. static bool i915_handle_vblank(struct drm_device *dev,
  3191. int plane, int pipe, u32 iir)
  3192. {
  3193. struct drm_i915_private *dev_priv = dev->dev_private;
  3194. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  3195. if (!intel_pipe_handle_vblank(dev, pipe))
  3196. return false;
  3197. if ((iir & flip_pending) == 0)
  3198. return false;
  3199. intel_prepare_page_flip(dev, plane);
  3200. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  3201. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  3202. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  3203. * the flip is completed (no longer pending). Since this doesn't raise
  3204. * an interrupt per se, we watch for the change at vblank.
  3205. */
  3206. if (I915_READ(ISR) & flip_pending)
  3207. return false;
  3208. intel_finish_page_flip(dev, pipe);
  3209. return true;
  3210. }
  3211. static irqreturn_t i915_irq_handler(int irq, void *arg)
  3212. {
  3213. struct drm_device *dev = arg;
  3214. struct drm_i915_private *dev_priv = dev->dev_private;
  3215. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  3216. unsigned long irqflags;
  3217. u32 flip_mask =
  3218. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3219. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3220. int pipe, ret = IRQ_NONE;
  3221. iir = I915_READ(IIR);
  3222. do {
  3223. bool irq_received = (iir & ~flip_mask) != 0;
  3224. bool blc_event = false;
  3225. /* Can't rely on pipestat interrupt bit in iir as it might
  3226. * have been cleared after the pipestat interrupt was received.
  3227. * It doesn't set the bit in iir again, but it still produces
  3228. * interrupts (for non-MSI).
  3229. */
  3230. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3231. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3232. i915_handle_error(dev, false,
  3233. "Command parser error, iir 0x%08x",
  3234. iir);
  3235. for_each_pipe(pipe) {
  3236. int reg = PIPESTAT(pipe);
  3237. pipe_stats[pipe] = I915_READ(reg);
  3238. /* Clear the PIPE*STAT regs before the IIR */
  3239. if (pipe_stats[pipe] & 0x8000ffff) {
  3240. I915_WRITE(reg, pipe_stats[pipe]);
  3241. irq_received = true;
  3242. }
  3243. }
  3244. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3245. if (!irq_received)
  3246. break;
  3247. /* Consume port. Then clear IIR or we'll miss events */
  3248. if (I915_HAS_HOTPLUG(dev) &&
  3249. iir & I915_DISPLAY_PORT_INTERRUPT)
  3250. i9xx_hpd_irq_handler(dev);
  3251. I915_WRITE(IIR, iir & ~flip_mask);
  3252. new_iir = I915_READ(IIR); /* Flush posted writes */
  3253. if (iir & I915_USER_INTERRUPT)
  3254. notify_ring(dev, &dev_priv->ring[RCS]);
  3255. for_each_pipe(pipe) {
  3256. int plane = pipe;
  3257. if (HAS_FBC(dev))
  3258. plane = !plane;
  3259. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  3260. i915_handle_vblank(dev, plane, pipe, iir))
  3261. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  3262. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3263. blc_event = true;
  3264. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3265. i9xx_pipe_crc_irq_handler(dev, pipe);
  3266. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
  3267. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  3268. DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
  3269. }
  3270. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3271. intel_opregion_asle_intr(dev);
  3272. /* With MSI, interrupts are only generated when iir
  3273. * transitions from zero to nonzero. If another bit got
  3274. * set while we were handling the existing iir bits, then
  3275. * we would never get another interrupt.
  3276. *
  3277. * This is fine on non-MSI as well, as if we hit this path
  3278. * we avoid exiting the interrupt handler only to generate
  3279. * another one.
  3280. *
  3281. * Note that for MSI this could cause a stray interrupt report
  3282. * if an interrupt landed in the time between writing IIR and
  3283. * the posting read. This should be rare enough to never
  3284. * trigger the 99% of 100,000 interrupts test for disabling
  3285. * stray interrupts.
  3286. */
  3287. ret = IRQ_HANDLED;
  3288. iir = new_iir;
  3289. } while (iir & ~flip_mask);
  3290. i915_update_dri1_breadcrumb(dev);
  3291. return ret;
  3292. }
  3293. static void i915_irq_uninstall(struct drm_device * dev)
  3294. {
  3295. struct drm_i915_private *dev_priv = dev->dev_private;
  3296. int pipe;
  3297. intel_hpd_irq_uninstall(dev_priv);
  3298. if (I915_HAS_HOTPLUG(dev)) {
  3299. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3300. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3301. }
  3302. I915_WRITE16(HWSTAM, 0xffff);
  3303. for_each_pipe(pipe) {
  3304. /* Clear enable bits; then clear status bits */
  3305. I915_WRITE(PIPESTAT(pipe), 0);
  3306. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  3307. }
  3308. I915_WRITE(IMR, 0xffffffff);
  3309. I915_WRITE(IER, 0x0);
  3310. I915_WRITE(IIR, I915_READ(IIR));
  3311. }
  3312. static void i965_irq_preinstall(struct drm_device * dev)
  3313. {
  3314. struct drm_i915_private *dev_priv = dev->dev_private;
  3315. int pipe;
  3316. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3317. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3318. I915_WRITE(HWSTAM, 0xeffe);
  3319. for_each_pipe(pipe)
  3320. I915_WRITE(PIPESTAT(pipe), 0);
  3321. I915_WRITE(IMR, 0xffffffff);
  3322. I915_WRITE(IER, 0x0);
  3323. POSTING_READ(IER);
  3324. }
  3325. static int i965_irq_postinstall(struct drm_device *dev)
  3326. {
  3327. struct drm_i915_private *dev_priv = dev->dev_private;
  3328. u32 enable_mask;
  3329. u32 error_mask;
  3330. unsigned long irqflags;
  3331. /* Unmask the interrupts that we always want on. */
  3332. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  3333. I915_DISPLAY_PORT_INTERRUPT |
  3334. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3335. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3336. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3337. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  3338. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  3339. enable_mask = ~dev_priv->irq_mask;
  3340. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3341. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3342. enable_mask |= I915_USER_INTERRUPT;
  3343. if (IS_G4X(dev))
  3344. enable_mask |= I915_BSD_USER_INTERRUPT;
  3345. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3346. * just to make the assert_spin_locked check happy. */
  3347. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3348. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  3349. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3350. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3351. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3352. /*
  3353. * Enable some error detection, note the instruction error mask
  3354. * bit is reserved, so we leave it masked.
  3355. */
  3356. if (IS_G4X(dev)) {
  3357. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  3358. GM45_ERROR_MEM_PRIV |
  3359. GM45_ERROR_CP_PRIV |
  3360. I915_ERROR_MEMORY_REFRESH);
  3361. } else {
  3362. error_mask = ~(I915_ERROR_PAGE_TABLE |
  3363. I915_ERROR_MEMORY_REFRESH);
  3364. }
  3365. I915_WRITE(EMR, error_mask);
  3366. I915_WRITE(IMR, dev_priv->irq_mask);
  3367. I915_WRITE(IER, enable_mask);
  3368. POSTING_READ(IER);
  3369. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3370. POSTING_READ(PORT_HOTPLUG_EN);
  3371. i915_enable_asle_pipestat(dev);
  3372. return 0;
  3373. }
  3374. static void i915_hpd_irq_setup(struct drm_device *dev)
  3375. {
  3376. struct drm_i915_private *dev_priv = dev->dev_private;
  3377. struct drm_mode_config *mode_config = &dev->mode_config;
  3378. struct intel_encoder *intel_encoder;
  3379. u32 hotplug_en;
  3380. assert_spin_locked(&dev_priv->irq_lock);
  3381. if (I915_HAS_HOTPLUG(dev)) {
  3382. hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  3383. hotplug_en &= ~HOTPLUG_INT_EN_MASK;
  3384. /* Note HDMI and DP share hotplug bits */
  3385. /* enable bits are the same for all generations */
  3386. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  3387. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  3388. hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
  3389. /* Programming the CRT detection parameters tends
  3390. to generate a spurious hotplug event about three
  3391. seconds later. So just do it once.
  3392. */
  3393. if (IS_G4X(dev))
  3394. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  3395. hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
  3396. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  3397. /* Ignore TV since it's buggy */
  3398. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  3399. }
  3400. }
  3401. static irqreturn_t i965_irq_handler(int irq, void *arg)
  3402. {
  3403. struct drm_device *dev = arg;
  3404. struct drm_i915_private *dev_priv = dev->dev_private;
  3405. u32 iir, new_iir;
  3406. u32 pipe_stats[I915_MAX_PIPES];
  3407. unsigned long irqflags;
  3408. int ret = IRQ_NONE, pipe;
  3409. u32 flip_mask =
  3410. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3411. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3412. iir = I915_READ(IIR);
  3413. for (;;) {
  3414. bool irq_received = (iir & ~flip_mask) != 0;
  3415. bool blc_event = false;
  3416. /* Can't rely on pipestat interrupt bit in iir as it might
  3417. * have been cleared after the pipestat interrupt was received.
  3418. * It doesn't set the bit in iir again, but it still produces
  3419. * interrupts (for non-MSI).
  3420. */
  3421. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3422. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3423. i915_handle_error(dev, false,
  3424. "Command parser error, iir 0x%08x",
  3425. iir);
  3426. for_each_pipe(pipe) {
  3427. int reg = PIPESTAT(pipe);
  3428. pipe_stats[pipe] = I915_READ(reg);
  3429. /*
  3430. * Clear the PIPE*STAT regs before the IIR
  3431. */
  3432. if (pipe_stats[pipe] & 0x8000ffff) {
  3433. I915_WRITE(reg, pipe_stats[pipe]);
  3434. irq_received = true;
  3435. }
  3436. }
  3437. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3438. if (!irq_received)
  3439. break;
  3440. ret = IRQ_HANDLED;
  3441. /* Consume port. Then clear IIR or we'll miss events */
  3442. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  3443. i9xx_hpd_irq_handler(dev);
  3444. I915_WRITE(IIR, iir & ~flip_mask);
  3445. new_iir = I915_READ(IIR); /* Flush posted writes */
  3446. if (iir & I915_USER_INTERRUPT)
  3447. notify_ring(dev, &dev_priv->ring[RCS]);
  3448. if (iir & I915_BSD_USER_INTERRUPT)
  3449. notify_ring(dev, &dev_priv->ring[VCS]);
  3450. for_each_pipe(pipe) {
  3451. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  3452. i915_handle_vblank(dev, pipe, pipe, iir))
  3453. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  3454. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3455. blc_event = true;
  3456. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3457. i9xx_pipe_crc_irq_handler(dev, pipe);
  3458. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
  3459. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  3460. DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
  3461. }
  3462. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3463. intel_opregion_asle_intr(dev);
  3464. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  3465. gmbus_irq_handler(dev);
  3466. /* With MSI, interrupts are only generated when iir
  3467. * transitions from zero to nonzero. If another bit got
  3468. * set while we were handling the existing iir bits, then
  3469. * we would never get another interrupt.
  3470. *
  3471. * This is fine on non-MSI as well, as if we hit this path
  3472. * we avoid exiting the interrupt handler only to generate
  3473. * another one.
  3474. *
  3475. * Note that for MSI this could cause a stray interrupt report
  3476. * if an interrupt landed in the time between writing IIR and
  3477. * the posting read. This should be rare enough to never
  3478. * trigger the 99% of 100,000 interrupts test for disabling
  3479. * stray interrupts.
  3480. */
  3481. iir = new_iir;
  3482. }
  3483. i915_update_dri1_breadcrumb(dev);
  3484. return ret;
  3485. }
  3486. static void i965_irq_uninstall(struct drm_device * dev)
  3487. {
  3488. struct drm_i915_private *dev_priv = dev->dev_private;
  3489. int pipe;
  3490. if (!dev_priv)
  3491. return;
  3492. intel_hpd_irq_uninstall(dev_priv);
  3493. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3494. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3495. I915_WRITE(HWSTAM, 0xffffffff);
  3496. for_each_pipe(pipe)
  3497. I915_WRITE(PIPESTAT(pipe), 0);
  3498. I915_WRITE(IMR, 0xffffffff);
  3499. I915_WRITE(IER, 0x0);
  3500. for_each_pipe(pipe)
  3501. I915_WRITE(PIPESTAT(pipe),
  3502. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  3503. I915_WRITE(IIR, I915_READ(IIR));
  3504. }
  3505. static void intel_hpd_irq_reenable(unsigned long data)
  3506. {
  3507. struct drm_i915_private *dev_priv = (struct drm_i915_private *)data;
  3508. struct drm_device *dev = dev_priv->dev;
  3509. struct drm_mode_config *mode_config = &dev->mode_config;
  3510. unsigned long irqflags;
  3511. int i;
  3512. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3513. for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
  3514. struct drm_connector *connector;
  3515. if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
  3516. continue;
  3517. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  3518. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3519. struct intel_connector *intel_connector = to_intel_connector(connector);
  3520. if (intel_connector->encoder->hpd_pin == i) {
  3521. if (connector->polled != intel_connector->polled)
  3522. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  3523. connector->name);
  3524. connector->polled = intel_connector->polled;
  3525. if (!connector->polled)
  3526. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3527. }
  3528. }
  3529. }
  3530. if (dev_priv->display.hpd_irq_setup)
  3531. dev_priv->display.hpd_irq_setup(dev);
  3532. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3533. }
  3534. void intel_irq_init(struct drm_device *dev)
  3535. {
  3536. struct drm_i915_private *dev_priv = dev->dev_private;
  3537. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  3538. INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
  3539. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  3540. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  3541. /* Let's track the enabled rps events */
  3542. dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
  3543. setup_timer(&dev_priv->gpu_error.hangcheck_timer,
  3544. i915_hangcheck_elapsed,
  3545. (unsigned long) dev);
  3546. setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable,
  3547. (unsigned long) dev_priv);
  3548. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  3549. if (IS_GEN2(dev)) {
  3550. dev->max_vblank_count = 0;
  3551. dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
  3552. } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  3553. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  3554. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  3555. } else {
  3556. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  3557. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  3558. }
  3559. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  3560. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  3561. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  3562. }
  3563. if (IS_CHERRYVIEW(dev)) {
  3564. dev->driver->irq_handler = cherryview_irq_handler;
  3565. dev->driver->irq_preinstall = cherryview_irq_preinstall;
  3566. dev->driver->irq_postinstall = cherryview_irq_postinstall;
  3567. dev->driver->irq_uninstall = cherryview_irq_uninstall;
  3568. dev->driver->enable_vblank = valleyview_enable_vblank;
  3569. dev->driver->disable_vblank = valleyview_disable_vblank;
  3570. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3571. } else if (IS_VALLEYVIEW(dev)) {
  3572. dev->driver->irq_handler = valleyview_irq_handler;
  3573. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  3574. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  3575. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  3576. dev->driver->enable_vblank = valleyview_enable_vblank;
  3577. dev->driver->disable_vblank = valleyview_disable_vblank;
  3578. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3579. } else if (IS_GEN8(dev)) {
  3580. dev->driver->irq_handler = gen8_irq_handler;
  3581. dev->driver->irq_preinstall = gen8_irq_reset;
  3582. dev->driver->irq_postinstall = gen8_irq_postinstall;
  3583. dev->driver->irq_uninstall = gen8_irq_uninstall;
  3584. dev->driver->enable_vblank = gen8_enable_vblank;
  3585. dev->driver->disable_vblank = gen8_disable_vblank;
  3586. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3587. } else if (HAS_PCH_SPLIT(dev)) {
  3588. dev->driver->irq_handler = ironlake_irq_handler;
  3589. dev->driver->irq_preinstall = ironlake_irq_reset;
  3590. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  3591. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  3592. dev->driver->enable_vblank = ironlake_enable_vblank;
  3593. dev->driver->disable_vblank = ironlake_disable_vblank;
  3594. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3595. } else {
  3596. if (INTEL_INFO(dev)->gen == 2) {
  3597. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  3598. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  3599. dev->driver->irq_handler = i8xx_irq_handler;
  3600. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  3601. } else if (INTEL_INFO(dev)->gen == 3) {
  3602. dev->driver->irq_preinstall = i915_irq_preinstall;
  3603. dev->driver->irq_postinstall = i915_irq_postinstall;
  3604. dev->driver->irq_uninstall = i915_irq_uninstall;
  3605. dev->driver->irq_handler = i915_irq_handler;
  3606. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3607. } else {
  3608. dev->driver->irq_preinstall = i965_irq_preinstall;
  3609. dev->driver->irq_postinstall = i965_irq_postinstall;
  3610. dev->driver->irq_uninstall = i965_irq_uninstall;
  3611. dev->driver->irq_handler = i965_irq_handler;
  3612. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3613. }
  3614. dev->driver->enable_vblank = i915_enable_vblank;
  3615. dev->driver->disable_vblank = i915_disable_vblank;
  3616. }
  3617. }
  3618. void intel_hpd_init(struct drm_device *dev)
  3619. {
  3620. struct drm_i915_private *dev_priv = dev->dev_private;
  3621. struct drm_mode_config *mode_config = &dev->mode_config;
  3622. struct drm_connector *connector;
  3623. unsigned long irqflags;
  3624. int i;
  3625. for (i = 1; i < HPD_NUM_PINS; i++) {
  3626. dev_priv->hpd_stats[i].hpd_cnt = 0;
  3627. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  3628. }
  3629. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3630. struct intel_connector *intel_connector = to_intel_connector(connector);
  3631. connector->polled = intel_connector->polled;
  3632. if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
  3633. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3634. }
  3635. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3636. * just to make the assert_spin_locked checks happy. */
  3637. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3638. if (dev_priv->display.hpd_irq_setup)
  3639. dev_priv->display.hpd_irq_setup(dev);
  3640. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3641. }
  3642. /* Disable interrupts so we can allow runtime PM. */
  3643. void intel_runtime_pm_disable_interrupts(struct drm_device *dev)
  3644. {
  3645. struct drm_i915_private *dev_priv = dev->dev_private;
  3646. dev->driver->irq_uninstall(dev);
  3647. dev_priv->pm.irqs_disabled = true;
  3648. }
  3649. /* Restore interrupts so we can recover from runtime PM. */
  3650. void intel_runtime_pm_restore_interrupts(struct drm_device *dev)
  3651. {
  3652. struct drm_i915_private *dev_priv = dev->dev_private;
  3653. dev_priv->pm.irqs_disabled = false;
  3654. dev->driver->irq_preinstall(dev);
  3655. dev->driver->irq_postinstall(dev);
  3656. }