i915_irq.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963
  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. /* For display hotplug interrupt */
  76. static void
  77. ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  78. {
  79. assert_spin_locked(&dev_priv->irq_lock);
  80. if (dev_priv->pc8.irqs_disabled) {
  81. WARN(1, "IRQs disabled\n");
  82. dev_priv->pc8.regsave.deimr &= ~mask;
  83. return;
  84. }
  85. if ((dev_priv->irq_mask & mask) != 0) {
  86. dev_priv->irq_mask &= ~mask;
  87. I915_WRITE(DEIMR, dev_priv->irq_mask);
  88. POSTING_READ(DEIMR);
  89. }
  90. }
  91. static void
  92. ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
  93. {
  94. assert_spin_locked(&dev_priv->irq_lock);
  95. if (dev_priv->pc8.irqs_disabled) {
  96. WARN(1, "IRQs disabled\n");
  97. dev_priv->pc8.regsave.deimr |= mask;
  98. return;
  99. }
  100. if ((dev_priv->irq_mask & mask) != mask) {
  101. dev_priv->irq_mask |= mask;
  102. I915_WRITE(DEIMR, dev_priv->irq_mask);
  103. POSTING_READ(DEIMR);
  104. }
  105. }
  106. /**
  107. * ilk_update_gt_irq - update GTIMR
  108. * @dev_priv: driver private
  109. * @interrupt_mask: mask of interrupt bits to update
  110. * @enabled_irq_mask: mask of interrupt bits to enable
  111. */
  112. static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
  113. uint32_t interrupt_mask,
  114. uint32_t enabled_irq_mask)
  115. {
  116. assert_spin_locked(&dev_priv->irq_lock);
  117. if (dev_priv->pc8.irqs_disabled) {
  118. WARN(1, "IRQs disabled\n");
  119. dev_priv->pc8.regsave.gtimr &= ~interrupt_mask;
  120. dev_priv->pc8.regsave.gtimr |= (~enabled_irq_mask &
  121. interrupt_mask);
  122. return;
  123. }
  124. dev_priv->gt_irq_mask &= ~interrupt_mask;
  125. dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
  126. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  127. POSTING_READ(GTIMR);
  128. }
  129. void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  130. {
  131. ilk_update_gt_irq(dev_priv, mask, mask);
  132. }
  133. void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  134. {
  135. ilk_update_gt_irq(dev_priv, mask, 0);
  136. }
  137. /**
  138. * snb_update_pm_irq - update GEN6_PMIMR
  139. * @dev_priv: driver private
  140. * @interrupt_mask: mask of interrupt bits to update
  141. * @enabled_irq_mask: mask of interrupt bits to enable
  142. */
  143. static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
  144. uint32_t interrupt_mask,
  145. uint32_t enabled_irq_mask)
  146. {
  147. uint32_t new_val;
  148. assert_spin_locked(&dev_priv->irq_lock);
  149. if (dev_priv->pc8.irqs_disabled) {
  150. WARN(1, "IRQs disabled\n");
  151. dev_priv->pc8.regsave.gen6_pmimr &= ~interrupt_mask;
  152. dev_priv->pc8.regsave.gen6_pmimr |= (~enabled_irq_mask &
  153. interrupt_mask);
  154. return;
  155. }
  156. new_val = dev_priv->pm_irq_mask;
  157. new_val &= ~interrupt_mask;
  158. new_val |= (~enabled_irq_mask & interrupt_mask);
  159. if (new_val != dev_priv->pm_irq_mask) {
  160. dev_priv->pm_irq_mask = new_val;
  161. I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
  162. POSTING_READ(GEN6_PMIMR);
  163. }
  164. }
  165. void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  166. {
  167. snb_update_pm_irq(dev_priv, mask, mask);
  168. }
  169. void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  170. {
  171. snb_update_pm_irq(dev_priv, mask, 0);
  172. }
  173. static bool ivb_can_enable_err_int(struct drm_device *dev)
  174. {
  175. struct drm_i915_private *dev_priv = dev->dev_private;
  176. struct intel_crtc *crtc;
  177. enum pipe pipe;
  178. assert_spin_locked(&dev_priv->irq_lock);
  179. for_each_pipe(pipe) {
  180. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  181. if (crtc->cpu_fifo_underrun_disabled)
  182. return false;
  183. }
  184. return true;
  185. }
  186. static bool cpt_can_enable_serr_int(struct drm_device *dev)
  187. {
  188. struct drm_i915_private *dev_priv = dev->dev_private;
  189. enum pipe pipe;
  190. struct intel_crtc *crtc;
  191. assert_spin_locked(&dev_priv->irq_lock);
  192. for_each_pipe(pipe) {
  193. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  194. if (crtc->pch_fifo_underrun_disabled)
  195. return false;
  196. }
  197. return true;
  198. }
  199. static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
  200. enum pipe pipe, bool enable)
  201. {
  202. struct drm_i915_private *dev_priv = dev->dev_private;
  203. uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
  204. DE_PIPEB_FIFO_UNDERRUN;
  205. if (enable)
  206. ironlake_enable_display_irq(dev_priv, bit);
  207. else
  208. ironlake_disable_display_irq(dev_priv, bit);
  209. }
  210. static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
  211. enum pipe pipe, bool enable)
  212. {
  213. struct drm_i915_private *dev_priv = dev->dev_private;
  214. if (enable) {
  215. I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
  216. if (!ivb_can_enable_err_int(dev))
  217. return;
  218. ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
  219. } else {
  220. bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
  221. /* Change the state _after_ we've read out the current one. */
  222. ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
  223. if (!was_enabled &&
  224. (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
  225. DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
  226. pipe_name(pipe));
  227. }
  228. }
  229. }
  230. static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
  231. enum pipe pipe, bool enable)
  232. {
  233. struct drm_i915_private *dev_priv = dev->dev_private;
  234. assert_spin_locked(&dev_priv->irq_lock);
  235. if (enable)
  236. dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
  237. else
  238. dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
  239. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  240. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  241. }
  242. /**
  243. * ibx_display_interrupt_update - update SDEIMR
  244. * @dev_priv: driver private
  245. * @interrupt_mask: mask of interrupt bits to update
  246. * @enabled_irq_mask: mask of interrupt bits to enable
  247. */
  248. static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  249. uint32_t interrupt_mask,
  250. uint32_t enabled_irq_mask)
  251. {
  252. uint32_t sdeimr = I915_READ(SDEIMR);
  253. sdeimr &= ~interrupt_mask;
  254. sdeimr |= (~enabled_irq_mask & interrupt_mask);
  255. assert_spin_locked(&dev_priv->irq_lock);
  256. if (dev_priv->pc8.irqs_disabled &&
  257. (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
  258. WARN(1, "IRQs disabled\n");
  259. dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
  260. dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
  261. interrupt_mask);
  262. return;
  263. }
  264. I915_WRITE(SDEIMR, sdeimr);
  265. POSTING_READ(SDEIMR);
  266. }
  267. #define ibx_enable_display_interrupt(dev_priv, bits) \
  268. ibx_display_interrupt_update((dev_priv), (bits), (bits))
  269. #define ibx_disable_display_interrupt(dev_priv, bits) \
  270. ibx_display_interrupt_update((dev_priv), (bits), 0)
  271. static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
  272. enum transcoder pch_transcoder,
  273. bool enable)
  274. {
  275. struct drm_i915_private *dev_priv = dev->dev_private;
  276. uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
  277. SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
  278. if (enable)
  279. ibx_enable_display_interrupt(dev_priv, bit);
  280. else
  281. ibx_disable_display_interrupt(dev_priv, bit);
  282. }
  283. static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
  284. enum transcoder pch_transcoder,
  285. bool enable)
  286. {
  287. struct drm_i915_private *dev_priv = dev->dev_private;
  288. if (enable) {
  289. I915_WRITE(SERR_INT,
  290. SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
  291. if (!cpt_can_enable_serr_int(dev))
  292. return;
  293. ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
  294. } else {
  295. uint32_t tmp = I915_READ(SERR_INT);
  296. bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
  297. /* Change the state _after_ we've read out the current one. */
  298. ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
  299. if (!was_enabled &&
  300. (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
  301. DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
  302. transcoder_name(pch_transcoder));
  303. }
  304. }
  305. }
  306. /**
  307. * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
  308. * @dev: drm device
  309. * @pipe: pipe
  310. * @enable: true if we want to report FIFO underrun errors, false otherwise
  311. *
  312. * This function makes us disable or enable CPU fifo underruns for a specific
  313. * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
  314. * reporting for one pipe may also disable all the other CPU error interruts for
  315. * the other pipes, due to the fact that there's just one interrupt mask/enable
  316. * bit for all the pipes.
  317. *
  318. * Returns the previous state of underrun reporting.
  319. */
  320. bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
  321. enum pipe pipe, bool enable)
  322. {
  323. struct drm_i915_private *dev_priv = dev->dev_private;
  324. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  325. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  326. unsigned long flags;
  327. bool ret;
  328. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  329. ret = !intel_crtc->cpu_fifo_underrun_disabled;
  330. if (enable == ret)
  331. goto done;
  332. intel_crtc->cpu_fifo_underrun_disabled = !enable;
  333. if (IS_GEN5(dev) || IS_GEN6(dev))
  334. ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
  335. else if (IS_GEN7(dev))
  336. ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
  337. else if (IS_GEN8(dev))
  338. broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
  339. done:
  340. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  341. return ret;
  342. }
  343. /**
  344. * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
  345. * @dev: drm device
  346. * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
  347. * @enable: true if we want to report FIFO underrun errors, false otherwise
  348. *
  349. * This function makes us disable or enable PCH fifo underruns for a specific
  350. * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
  351. * underrun reporting for one transcoder may also disable all the other PCH
  352. * error interruts for the other transcoders, due to the fact that there's just
  353. * one interrupt mask/enable bit for all the transcoders.
  354. *
  355. * Returns the previous state of underrun reporting.
  356. */
  357. bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
  358. enum transcoder pch_transcoder,
  359. bool enable)
  360. {
  361. struct drm_i915_private *dev_priv = dev->dev_private;
  362. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
  363. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  364. unsigned long flags;
  365. bool ret;
  366. /*
  367. * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
  368. * has only one pch transcoder A that all pipes can use. To avoid racy
  369. * pch transcoder -> pipe lookups from interrupt code simply store the
  370. * underrun statistics in crtc A. Since we never expose this anywhere
  371. * nor use it outside of the fifo underrun code here using the "wrong"
  372. * crtc on LPT won't cause issues.
  373. */
  374. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  375. ret = !intel_crtc->pch_fifo_underrun_disabled;
  376. if (enable == ret)
  377. goto done;
  378. intel_crtc->pch_fifo_underrun_disabled = !enable;
  379. if (HAS_PCH_IBX(dev))
  380. ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
  381. else
  382. cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
  383. done:
  384. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  385. return ret;
  386. }
  387. void
  388. i915_enable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
  389. {
  390. u32 reg = PIPESTAT(pipe);
  391. u32 pipestat = I915_READ(reg) & 0x7fff0000;
  392. assert_spin_locked(&dev_priv->irq_lock);
  393. if ((pipestat & mask) == mask)
  394. return;
  395. /* Enable the interrupt, clear any pending status */
  396. pipestat |= mask | (mask >> 16);
  397. I915_WRITE(reg, pipestat);
  398. POSTING_READ(reg);
  399. }
  400. void
  401. i915_disable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
  402. {
  403. u32 reg = PIPESTAT(pipe);
  404. u32 pipestat = I915_READ(reg) & 0x7fff0000;
  405. assert_spin_locked(&dev_priv->irq_lock);
  406. if ((pipestat & mask) == 0)
  407. return;
  408. pipestat &= ~mask;
  409. I915_WRITE(reg, pipestat);
  410. POSTING_READ(reg);
  411. }
  412. /**
  413. * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
  414. */
  415. static void i915_enable_asle_pipestat(struct drm_device *dev)
  416. {
  417. drm_i915_private_t *dev_priv = dev->dev_private;
  418. unsigned long irqflags;
  419. if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
  420. return;
  421. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  422. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_ENABLE);
  423. if (INTEL_INFO(dev)->gen >= 4)
  424. i915_enable_pipestat(dev_priv, PIPE_A,
  425. PIPE_LEGACY_BLC_EVENT_ENABLE);
  426. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  427. }
  428. /**
  429. * i915_pipe_enabled - check if a pipe is enabled
  430. * @dev: DRM device
  431. * @pipe: pipe to check
  432. *
  433. * Reading certain registers when the pipe is disabled can hang the chip.
  434. * Use this routine to make sure the PLL is running and the pipe is active
  435. * before reading such registers if unsure.
  436. */
  437. static int
  438. i915_pipe_enabled(struct drm_device *dev, int pipe)
  439. {
  440. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  441. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  442. /* Locking is horribly broken here, but whatever. */
  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->active;
  446. } else {
  447. return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
  448. }
  449. }
  450. static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
  451. {
  452. /* Gen2 doesn't have a hardware frame counter */
  453. return 0;
  454. }
  455. /* Called from drm generic code, passed a 'crtc', which
  456. * we use as a pipe index
  457. */
  458. static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  459. {
  460. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  461. unsigned long high_frame;
  462. unsigned long low_frame;
  463. u32 high1, high2, low, pixel, vbl_start;
  464. if (!i915_pipe_enabled(dev, pipe)) {
  465. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  466. "pipe %c\n", pipe_name(pipe));
  467. return 0;
  468. }
  469. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  470. struct intel_crtc *intel_crtc =
  471. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  472. const struct drm_display_mode *mode =
  473. &intel_crtc->config.adjusted_mode;
  474. vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
  475. } else {
  476. enum transcoder cpu_transcoder = (enum transcoder) pipe;
  477. u32 htotal;
  478. htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
  479. vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
  480. vbl_start *= htotal;
  481. }
  482. high_frame = PIPEFRAME(pipe);
  483. low_frame = PIPEFRAMEPIXEL(pipe);
  484. /*
  485. * High & low register fields aren't synchronized, so make sure
  486. * we get a low value that's stable across two reads of the high
  487. * register.
  488. */
  489. do {
  490. high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  491. low = I915_READ(low_frame);
  492. high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  493. } while (high1 != high2);
  494. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  495. pixel = low & PIPE_PIXEL_MASK;
  496. low >>= PIPE_FRAME_LOW_SHIFT;
  497. /*
  498. * The frame counter increments at beginning of active.
  499. * Cook up a vblank counter by also checking the pixel
  500. * counter against vblank start.
  501. */
  502. return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
  503. }
  504. static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  505. {
  506. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  507. int reg = PIPE_FRMCOUNT_GM45(pipe);
  508. if (!i915_pipe_enabled(dev, pipe)) {
  509. DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
  510. "pipe %c\n", pipe_name(pipe));
  511. return 0;
  512. }
  513. return I915_READ(reg);
  514. }
  515. /* raw reads, only for fast reads of display block, no need for forcewake etc. */
  516. #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
  517. static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
  518. {
  519. struct drm_i915_private *dev_priv = dev->dev_private;
  520. uint32_t status;
  521. int reg;
  522. if (INTEL_INFO(dev)->gen >= 8) {
  523. status = GEN8_PIPE_VBLANK;
  524. reg = GEN8_DE_PIPE_ISR(pipe);
  525. } else if (INTEL_INFO(dev)->gen >= 7) {
  526. status = DE_PIPE_VBLANK_IVB(pipe);
  527. reg = DEISR;
  528. } else {
  529. status = DE_PIPE_VBLANK(pipe);
  530. reg = DEISR;
  531. }
  532. return __raw_i915_read32(dev_priv, reg) & status;
  533. }
  534. static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
  535. unsigned int flags, int *vpos, int *hpos,
  536. ktime_t *stime, ktime_t *etime)
  537. {
  538. struct drm_i915_private *dev_priv = dev->dev_private;
  539. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  540. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  541. const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
  542. int position;
  543. int vbl_start, vbl_end, htotal, vtotal;
  544. bool in_vbl = true;
  545. int ret = 0;
  546. unsigned long irqflags;
  547. if (!intel_crtc->active) {
  548. DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
  549. "pipe %c\n", pipe_name(pipe));
  550. return 0;
  551. }
  552. htotal = mode->crtc_htotal;
  553. vtotal = mode->crtc_vtotal;
  554. vbl_start = mode->crtc_vblank_start;
  555. vbl_end = mode->crtc_vblank_end;
  556. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  557. vbl_start = DIV_ROUND_UP(vbl_start, 2);
  558. vbl_end /= 2;
  559. vtotal /= 2;
  560. }
  561. ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
  562. /*
  563. * Lock uncore.lock, as we will do multiple timing critical raw
  564. * register reads, potentially with preemption disabled, so the
  565. * following code must not block on uncore.lock.
  566. */
  567. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  568. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  569. /* Get optional system timestamp before query. */
  570. if (stime)
  571. *stime = ktime_get();
  572. if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  573. /* No obvious pixelcount register. Only query vertical
  574. * scanout position from Display scan line register.
  575. */
  576. if (IS_GEN2(dev))
  577. position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
  578. else
  579. position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
  580. if (HAS_DDI(dev)) {
  581. /*
  582. * On HSW HDMI outputs there seems to be a 2 line
  583. * difference, whereas eDP has the normal 1 line
  584. * difference that earlier platforms have. External
  585. * DP is unknown. For now just check for the 2 line
  586. * difference case on all output types on HSW+.
  587. *
  588. * This might misinterpret the scanline counter being
  589. * one line too far along on eDP, but that's less
  590. * dangerous than the alternative since that would lead
  591. * the vblank timestamp code astray when it sees a
  592. * scanline count before vblank_start during a vblank
  593. * interrupt.
  594. */
  595. in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
  596. if ((in_vbl && (position == vbl_start - 2 ||
  597. position == vbl_start - 1)) ||
  598. (!in_vbl && (position == vbl_end - 2 ||
  599. position == vbl_end - 1)))
  600. position = (position + 2) % vtotal;
  601. } else if (HAS_PCH_SPLIT(dev)) {
  602. /*
  603. * The scanline counter increments at the leading edge
  604. * of hsync, ie. it completely misses the active portion
  605. * of the line. Fix up the counter at both edges of vblank
  606. * to get a more accurate picture whether we're in vblank
  607. * or not.
  608. */
  609. in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
  610. if ((in_vbl && position == vbl_start - 1) ||
  611. (!in_vbl && position == vbl_end - 1))
  612. position = (position + 1) % vtotal;
  613. } else {
  614. /*
  615. * ISR vblank status bits don't work the way we'd want
  616. * them to work on non-PCH platforms (for
  617. * ilk_pipe_in_vblank_locked()), and there doesn't
  618. * appear any other way to determine if we're currently
  619. * in vblank.
  620. *
  621. * Instead let's assume that we're already in vblank if
  622. * we got called from the vblank interrupt and the
  623. * scanline counter value indicates that we're on the
  624. * line just prior to vblank start. This should result
  625. * in the correct answer, unless the vblank interrupt
  626. * delivery really got delayed for almost exactly one
  627. * full frame/field.
  628. */
  629. if (flags & DRM_CALLED_FROM_VBLIRQ &&
  630. position == vbl_start - 1) {
  631. position = (position + 1) % vtotal;
  632. /* Signal this correction as "applied". */
  633. ret |= 0x8;
  634. }
  635. }
  636. } else {
  637. /* Have access to pixelcount since start of frame.
  638. * We can split this into vertical and horizontal
  639. * scanout position.
  640. */
  641. position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  642. /* convert to pixel counts */
  643. vbl_start *= htotal;
  644. vbl_end *= htotal;
  645. vtotal *= htotal;
  646. }
  647. /* Get optional system timestamp after query. */
  648. if (etime)
  649. *etime = ktime_get();
  650. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  651. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  652. in_vbl = position >= vbl_start && position < vbl_end;
  653. /*
  654. * While in vblank, position will be negative
  655. * counting up towards 0 at vbl_end. And outside
  656. * vblank, position will be positive counting
  657. * up since vbl_end.
  658. */
  659. if (position >= vbl_start)
  660. position -= vbl_end;
  661. else
  662. position += vtotal - vbl_end;
  663. if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  664. *vpos = position;
  665. *hpos = 0;
  666. } else {
  667. *vpos = position / htotal;
  668. *hpos = position - (*vpos * htotal);
  669. }
  670. /* In vblank? */
  671. if (in_vbl)
  672. ret |= DRM_SCANOUTPOS_INVBL;
  673. return ret;
  674. }
  675. static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
  676. int *max_error,
  677. struct timeval *vblank_time,
  678. unsigned flags)
  679. {
  680. struct drm_crtc *crtc;
  681. if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
  682. DRM_ERROR("Invalid crtc %d\n", pipe);
  683. return -EINVAL;
  684. }
  685. /* Get drm_crtc to timestamp: */
  686. crtc = intel_get_crtc_for_pipe(dev, pipe);
  687. if (crtc == NULL) {
  688. DRM_ERROR("Invalid crtc %d\n", pipe);
  689. return -EINVAL;
  690. }
  691. if (!crtc->enabled) {
  692. DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
  693. return -EBUSY;
  694. }
  695. /* Helper routine in DRM core does all the work: */
  696. return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
  697. vblank_time, flags,
  698. crtc,
  699. &to_intel_crtc(crtc)->config.adjusted_mode);
  700. }
  701. static bool intel_hpd_irq_event(struct drm_device *dev,
  702. struct drm_connector *connector)
  703. {
  704. enum drm_connector_status old_status;
  705. WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
  706. old_status = connector->status;
  707. connector->status = connector->funcs->detect(connector, false);
  708. if (old_status == connector->status)
  709. return false;
  710. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
  711. connector->base.id,
  712. drm_get_connector_name(connector),
  713. drm_get_connector_status_name(old_status),
  714. drm_get_connector_status_name(connector->status));
  715. return true;
  716. }
  717. /*
  718. * Handle hotplug events outside the interrupt handler proper.
  719. */
  720. #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
  721. static void i915_hotplug_work_func(struct work_struct *work)
  722. {
  723. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  724. hotplug_work);
  725. struct drm_device *dev = dev_priv->dev;
  726. struct drm_mode_config *mode_config = &dev->mode_config;
  727. struct intel_connector *intel_connector;
  728. struct intel_encoder *intel_encoder;
  729. struct drm_connector *connector;
  730. unsigned long irqflags;
  731. bool hpd_disabled = false;
  732. bool changed = false;
  733. u32 hpd_event_bits;
  734. /* HPD irq before everything is fully set up. */
  735. if (!dev_priv->enable_hotplug_processing)
  736. return;
  737. mutex_lock(&mode_config->mutex);
  738. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  739. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  740. hpd_event_bits = dev_priv->hpd_event_bits;
  741. dev_priv->hpd_event_bits = 0;
  742. list_for_each_entry(connector, &mode_config->connector_list, head) {
  743. intel_connector = to_intel_connector(connector);
  744. intel_encoder = intel_connector->encoder;
  745. if (intel_encoder->hpd_pin > HPD_NONE &&
  746. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
  747. connector->polled == DRM_CONNECTOR_POLL_HPD) {
  748. DRM_INFO("HPD interrupt storm detected on connector %s: "
  749. "switching from hotplug detection to polling\n",
  750. drm_get_connector_name(connector));
  751. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
  752. connector->polled = DRM_CONNECTOR_POLL_CONNECT
  753. | DRM_CONNECTOR_POLL_DISCONNECT;
  754. hpd_disabled = true;
  755. }
  756. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  757. DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
  758. drm_get_connector_name(connector), intel_encoder->hpd_pin);
  759. }
  760. }
  761. /* if there were no outputs to poll, poll was disabled,
  762. * therefore make sure it's enabled when disabling HPD on
  763. * some connectors */
  764. if (hpd_disabled) {
  765. drm_kms_helper_poll_enable(dev);
  766. mod_timer(&dev_priv->hotplug_reenable_timer,
  767. jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
  768. }
  769. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  770. list_for_each_entry(connector, &mode_config->connector_list, head) {
  771. intel_connector = to_intel_connector(connector);
  772. intel_encoder = intel_connector->encoder;
  773. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  774. if (intel_encoder->hot_plug)
  775. intel_encoder->hot_plug(intel_encoder);
  776. if (intel_hpd_irq_event(dev, connector))
  777. changed = true;
  778. }
  779. }
  780. mutex_unlock(&mode_config->mutex);
  781. if (changed)
  782. drm_kms_helper_hotplug_event(dev);
  783. }
  784. static void ironlake_rps_change_irq_handler(struct drm_device *dev)
  785. {
  786. drm_i915_private_t *dev_priv = dev->dev_private;
  787. u32 busy_up, busy_down, max_avg, min_avg;
  788. u8 new_delay;
  789. spin_lock(&mchdev_lock);
  790. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  791. new_delay = dev_priv->ips.cur_delay;
  792. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  793. busy_up = I915_READ(RCPREVBSYTUPAVG);
  794. busy_down = I915_READ(RCPREVBSYTDNAVG);
  795. max_avg = I915_READ(RCBMAXAVG);
  796. min_avg = I915_READ(RCBMINAVG);
  797. /* Handle RCS change request from hw */
  798. if (busy_up > max_avg) {
  799. if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
  800. new_delay = dev_priv->ips.cur_delay - 1;
  801. if (new_delay < dev_priv->ips.max_delay)
  802. new_delay = dev_priv->ips.max_delay;
  803. } else if (busy_down < min_avg) {
  804. if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
  805. new_delay = dev_priv->ips.cur_delay + 1;
  806. if (new_delay > dev_priv->ips.min_delay)
  807. new_delay = dev_priv->ips.min_delay;
  808. }
  809. if (ironlake_set_drps(dev, new_delay))
  810. dev_priv->ips.cur_delay = new_delay;
  811. spin_unlock(&mchdev_lock);
  812. return;
  813. }
  814. static void notify_ring(struct drm_device *dev,
  815. struct intel_ring_buffer *ring)
  816. {
  817. if (ring->obj == NULL)
  818. return;
  819. trace_i915_gem_request_complete(ring);
  820. wake_up_all(&ring->irq_queue);
  821. i915_queue_hangcheck(dev);
  822. }
  823. static void gen6_pm_rps_work(struct work_struct *work)
  824. {
  825. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  826. rps.work);
  827. u32 pm_iir;
  828. int new_delay, adj;
  829. spin_lock_irq(&dev_priv->irq_lock);
  830. pm_iir = dev_priv->rps.pm_iir;
  831. dev_priv->rps.pm_iir = 0;
  832. /* Make sure not to corrupt PMIMR state used by ringbuffer code */
  833. snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
  834. spin_unlock_irq(&dev_priv->irq_lock);
  835. /* Make sure we didn't queue anything we're not going to process. */
  836. WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
  837. if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
  838. return;
  839. mutex_lock(&dev_priv->rps.hw_lock);
  840. adj = dev_priv->rps.last_adj;
  841. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
  842. if (adj > 0)
  843. adj *= 2;
  844. else
  845. adj = 1;
  846. new_delay = dev_priv->rps.cur_delay + adj;
  847. /*
  848. * For better performance, jump directly
  849. * to RPe if we're below it.
  850. */
  851. if (new_delay < dev_priv->rps.rpe_delay)
  852. new_delay = dev_priv->rps.rpe_delay;
  853. } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
  854. if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
  855. new_delay = dev_priv->rps.rpe_delay;
  856. else
  857. new_delay = dev_priv->rps.min_delay;
  858. adj = 0;
  859. } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
  860. if (adj < 0)
  861. adj *= 2;
  862. else
  863. adj = -1;
  864. new_delay = dev_priv->rps.cur_delay + adj;
  865. } else { /* unknown event */
  866. new_delay = dev_priv->rps.cur_delay;
  867. }
  868. /* sysfs frequency interfaces may have snuck in while servicing the
  869. * interrupt
  870. */
  871. new_delay = clamp_t(int, new_delay,
  872. dev_priv->rps.min_delay, dev_priv->rps.max_delay);
  873. dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
  874. if (IS_VALLEYVIEW(dev_priv->dev))
  875. valleyview_set_rps(dev_priv->dev, new_delay);
  876. else
  877. gen6_set_rps(dev_priv->dev, new_delay);
  878. mutex_unlock(&dev_priv->rps.hw_lock);
  879. }
  880. /**
  881. * ivybridge_parity_work - Workqueue called when a parity error interrupt
  882. * occurred.
  883. * @work: workqueue struct
  884. *
  885. * Doesn't actually do anything except notify userspace. As a consequence of
  886. * this event, userspace should try to remap the bad rows since statistically
  887. * it is likely the same row is more likely to go bad again.
  888. */
  889. static void ivybridge_parity_work(struct work_struct *work)
  890. {
  891. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  892. l3_parity.error_work);
  893. u32 error_status, row, bank, subbank;
  894. char *parity_event[6];
  895. uint32_t misccpctl;
  896. unsigned long flags;
  897. uint8_t slice = 0;
  898. /* We must turn off DOP level clock gating to access the L3 registers.
  899. * In order to prevent a get/put style interface, acquire struct mutex
  900. * any time we access those registers.
  901. */
  902. mutex_lock(&dev_priv->dev->struct_mutex);
  903. /* If we've screwed up tracking, just let the interrupt fire again */
  904. if (WARN_ON(!dev_priv->l3_parity.which_slice))
  905. goto out;
  906. misccpctl = I915_READ(GEN7_MISCCPCTL);
  907. I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  908. POSTING_READ(GEN7_MISCCPCTL);
  909. while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
  910. u32 reg;
  911. slice--;
  912. if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
  913. break;
  914. dev_priv->l3_parity.which_slice &= ~(1<<slice);
  915. reg = GEN7_L3CDERRST1 + (slice * 0x200);
  916. error_status = I915_READ(reg);
  917. row = GEN7_PARITY_ERROR_ROW(error_status);
  918. bank = GEN7_PARITY_ERROR_BANK(error_status);
  919. subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
  920. I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
  921. POSTING_READ(reg);
  922. parity_event[0] = I915_L3_PARITY_UEVENT "=1";
  923. parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
  924. parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
  925. parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
  926. parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
  927. parity_event[5] = NULL;
  928. kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
  929. KOBJ_CHANGE, parity_event);
  930. DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
  931. slice, row, bank, subbank);
  932. kfree(parity_event[4]);
  933. kfree(parity_event[3]);
  934. kfree(parity_event[2]);
  935. kfree(parity_event[1]);
  936. }
  937. I915_WRITE(GEN7_MISCCPCTL, misccpctl);
  938. out:
  939. WARN_ON(dev_priv->l3_parity.which_slice);
  940. spin_lock_irqsave(&dev_priv->irq_lock, flags);
  941. ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
  942. spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
  943. mutex_unlock(&dev_priv->dev->struct_mutex);
  944. }
  945. static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
  946. {
  947. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  948. if (!HAS_L3_DPF(dev))
  949. return;
  950. spin_lock(&dev_priv->irq_lock);
  951. ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
  952. spin_unlock(&dev_priv->irq_lock);
  953. iir &= GT_PARITY_ERROR(dev);
  954. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
  955. dev_priv->l3_parity.which_slice |= 1 << 1;
  956. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
  957. dev_priv->l3_parity.which_slice |= 1 << 0;
  958. queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
  959. }
  960. static void ilk_gt_irq_handler(struct drm_device *dev,
  961. struct drm_i915_private *dev_priv,
  962. u32 gt_iir)
  963. {
  964. if (gt_iir &
  965. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  966. notify_ring(dev, &dev_priv->ring[RCS]);
  967. if (gt_iir & ILK_BSD_USER_INTERRUPT)
  968. notify_ring(dev, &dev_priv->ring[VCS]);
  969. }
  970. static void snb_gt_irq_handler(struct drm_device *dev,
  971. struct drm_i915_private *dev_priv,
  972. u32 gt_iir)
  973. {
  974. if (gt_iir &
  975. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  976. notify_ring(dev, &dev_priv->ring[RCS]);
  977. if (gt_iir & GT_BSD_USER_INTERRUPT)
  978. notify_ring(dev, &dev_priv->ring[VCS]);
  979. if (gt_iir & GT_BLT_USER_INTERRUPT)
  980. notify_ring(dev, &dev_priv->ring[BCS]);
  981. if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
  982. GT_BSD_CS_ERROR_INTERRUPT |
  983. GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
  984. DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
  985. i915_handle_error(dev, false);
  986. }
  987. if (gt_iir & GT_PARITY_ERROR(dev))
  988. ivybridge_parity_error_irq_handler(dev, gt_iir);
  989. }
  990. static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
  991. struct drm_i915_private *dev_priv,
  992. u32 master_ctl)
  993. {
  994. u32 rcs, bcs, vcs;
  995. uint32_t tmp = 0;
  996. irqreturn_t ret = IRQ_NONE;
  997. if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
  998. tmp = I915_READ(GEN8_GT_IIR(0));
  999. if (tmp) {
  1000. ret = IRQ_HANDLED;
  1001. rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
  1002. bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
  1003. if (rcs & GT_RENDER_USER_INTERRUPT)
  1004. notify_ring(dev, &dev_priv->ring[RCS]);
  1005. if (bcs & GT_RENDER_USER_INTERRUPT)
  1006. notify_ring(dev, &dev_priv->ring[BCS]);
  1007. I915_WRITE(GEN8_GT_IIR(0), tmp);
  1008. } else
  1009. DRM_ERROR("The master control interrupt lied (GT0)!\n");
  1010. }
  1011. if (master_ctl & GEN8_GT_VCS1_IRQ) {
  1012. tmp = I915_READ(GEN8_GT_IIR(1));
  1013. if (tmp) {
  1014. ret = IRQ_HANDLED;
  1015. vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
  1016. if (vcs & GT_RENDER_USER_INTERRUPT)
  1017. notify_ring(dev, &dev_priv->ring[VCS]);
  1018. I915_WRITE(GEN8_GT_IIR(1), tmp);
  1019. } else
  1020. DRM_ERROR("The master control interrupt lied (GT1)!\n");
  1021. }
  1022. if (master_ctl & GEN8_GT_VECS_IRQ) {
  1023. tmp = I915_READ(GEN8_GT_IIR(3));
  1024. if (tmp) {
  1025. ret = IRQ_HANDLED;
  1026. vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
  1027. if (vcs & GT_RENDER_USER_INTERRUPT)
  1028. notify_ring(dev, &dev_priv->ring[VECS]);
  1029. I915_WRITE(GEN8_GT_IIR(3), tmp);
  1030. } else
  1031. DRM_ERROR("The master control interrupt lied (GT3)!\n");
  1032. }
  1033. return ret;
  1034. }
  1035. #define HPD_STORM_DETECT_PERIOD 1000
  1036. #define HPD_STORM_THRESHOLD 5
  1037. static inline void intel_hpd_irq_handler(struct drm_device *dev,
  1038. u32 hotplug_trigger,
  1039. const u32 *hpd)
  1040. {
  1041. drm_i915_private_t *dev_priv = dev->dev_private;
  1042. int i;
  1043. bool storm_detected = false;
  1044. if (!hotplug_trigger)
  1045. return;
  1046. spin_lock(&dev_priv->irq_lock);
  1047. for (i = 1; i < HPD_NUM_PINS; i++) {
  1048. WARN_ONCE(hpd[i] & hotplug_trigger &&
  1049. dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
  1050. "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
  1051. hotplug_trigger, i, hpd[i]);
  1052. if (!(hpd[i] & hotplug_trigger) ||
  1053. dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
  1054. continue;
  1055. dev_priv->hpd_event_bits |= (1 << i);
  1056. if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
  1057. dev_priv->hpd_stats[i].hpd_last_jiffies
  1058. + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
  1059. dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
  1060. dev_priv->hpd_stats[i].hpd_cnt = 0;
  1061. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
  1062. } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
  1063. dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
  1064. dev_priv->hpd_event_bits &= ~(1 << i);
  1065. DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
  1066. storm_detected = true;
  1067. } else {
  1068. dev_priv->hpd_stats[i].hpd_cnt++;
  1069. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
  1070. dev_priv->hpd_stats[i].hpd_cnt);
  1071. }
  1072. }
  1073. if (storm_detected)
  1074. dev_priv->display.hpd_irq_setup(dev);
  1075. spin_unlock(&dev_priv->irq_lock);
  1076. /*
  1077. * Our hotplug handler can grab modeset locks (by calling down into the
  1078. * fb helpers). Hence it must not be run on our own dev-priv->wq work
  1079. * queue for otherwise the flush_work in the pageflip code will
  1080. * deadlock.
  1081. */
  1082. schedule_work(&dev_priv->hotplug_work);
  1083. }
  1084. static void gmbus_irq_handler(struct drm_device *dev)
  1085. {
  1086. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1087. wake_up_all(&dev_priv->gmbus_wait_queue);
  1088. }
  1089. static void dp_aux_irq_handler(struct drm_device *dev)
  1090. {
  1091. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1092. wake_up_all(&dev_priv->gmbus_wait_queue);
  1093. }
  1094. #if defined(CONFIG_DEBUG_FS)
  1095. static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1096. uint32_t crc0, uint32_t crc1,
  1097. uint32_t crc2, uint32_t crc3,
  1098. uint32_t crc4)
  1099. {
  1100. struct drm_i915_private *dev_priv = dev->dev_private;
  1101. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
  1102. struct intel_pipe_crc_entry *entry;
  1103. int head, tail;
  1104. spin_lock(&pipe_crc->lock);
  1105. if (!pipe_crc->entries) {
  1106. spin_unlock(&pipe_crc->lock);
  1107. DRM_ERROR("spurious interrupt\n");
  1108. return;
  1109. }
  1110. head = pipe_crc->head;
  1111. tail = pipe_crc->tail;
  1112. if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
  1113. spin_unlock(&pipe_crc->lock);
  1114. DRM_ERROR("CRC buffer overflowing\n");
  1115. return;
  1116. }
  1117. entry = &pipe_crc->entries[head];
  1118. entry->frame = dev->driver->get_vblank_counter(dev, pipe);
  1119. entry->crc[0] = crc0;
  1120. entry->crc[1] = crc1;
  1121. entry->crc[2] = crc2;
  1122. entry->crc[3] = crc3;
  1123. entry->crc[4] = crc4;
  1124. head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
  1125. pipe_crc->head = head;
  1126. spin_unlock(&pipe_crc->lock);
  1127. wake_up_interruptible(&pipe_crc->wq);
  1128. }
  1129. #else
  1130. static inline void
  1131. display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1132. uint32_t crc0, uint32_t crc1,
  1133. uint32_t crc2, uint32_t crc3,
  1134. uint32_t crc4) {}
  1135. #endif
  1136. static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1137. {
  1138. struct drm_i915_private *dev_priv = dev->dev_private;
  1139. display_pipe_crc_irq_handler(dev, pipe,
  1140. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1141. 0, 0, 0, 0);
  1142. }
  1143. static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1144. {
  1145. struct drm_i915_private *dev_priv = dev->dev_private;
  1146. display_pipe_crc_irq_handler(dev, pipe,
  1147. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1148. I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
  1149. I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
  1150. I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
  1151. I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
  1152. }
  1153. static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1154. {
  1155. struct drm_i915_private *dev_priv = dev->dev_private;
  1156. uint32_t res1, res2;
  1157. if (INTEL_INFO(dev)->gen >= 3)
  1158. res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
  1159. else
  1160. res1 = 0;
  1161. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  1162. res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
  1163. else
  1164. res2 = 0;
  1165. display_pipe_crc_irq_handler(dev, pipe,
  1166. I915_READ(PIPE_CRC_RES_RED(pipe)),
  1167. I915_READ(PIPE_CRC_RES_GREEN(pipe)),
  1168. I915_READ(PIPE_CRC_RES_BLUE(pipe)),
  1169. res1, res2);
  1170. }
  1171. /* The RPS events need forcewake, so we add them to a work queue and mask their
  1172. * IMR bits until the work is done. Other interrupts can be processed without
  1173. * the work queue. */
  1174. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
  1175. {
  1176. if (pm_iir & GEN6_PM_RPS_EVENTS) {
  1177. spin_lock(&dev_priv->irq_lock);
  1178. dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
  1179. snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
  1180. spin_unlock(&dev_priv->irq_lock);
  1181. queue_work(dev_priv->wq, &dev_priv->rps.work);
  1182. }
  1183. if (HAS_VEBOX(dev_priv->dev)) {
  1184. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  1185. notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
  1186. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
  1187. DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
  1188. i915_handle_error(dev_priv->dev, false);
  1189. }
  1190. }
  1191. }
  1192. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  1193. {
  1194. struct drm_device *dev = (struct drm_device *) arg;
  1195. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1196. u32 iir, gt_iir, pm_iir;
  1197. irqreturn_t ret = IRQ_NONE;
  1198. unsigned long irqflags;
  1199. int pipe;
  1200. u32 pipe_stats[I915_MAX_PIPES];
  1201. atomic_inc(&dev_priv->irq_received);
  1202. while (true) {
  1203. iir = I915_READ(VLV_IIR);
  1204. gt_iir = I915_READ(GTIIR);
  1205. pm_iir = I915_READ(GEN6_PMIIR);
  1206. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  1207. goto out;
  1208. ret = IRQ_HANDLED;
  1209. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1210. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1211. for_each_pipe(pipe) {
  1212. int reg = PIPESTAT(pipe);
  1213. pipe_stats[pipe] = I915_READ(reg);
  1214. /*
  1215. * Clear the PIPE*STAT regs before the IIR
  1216. */
  1217. if (pipe_stats[pipe] & 0x8000ffff) {
  1218. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1219. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  1220. pipe_name(pipe));
  1221. I915_WRITE(reg, pipe_stats[pipe]);
  1222. }
  1223. }
  1224. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1225. for_each_pipe(pipe) {
  1226. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
  1227. drm_handle_vblank(dev, pipe);
  1228. if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
  1229. intel_prepare_page_flip(dev, pipe);
  1230. intel_finish_page_flip(dev, pipe);
  1231. }
  1232. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1233. i9xx_pipe_crc_irq_handler(dev, pipe);
  1234. }
  1235. /* Consume port. Then clear IIR or we'll miss events */
  1236. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  1237. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1238. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  1239. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  1240. hotplug_status);
  1241. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  1242. if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
  1243. dp_aux_irq_handler(dev);
  1244. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1245. I915_READ(PORT_HOTPLUG_STAT);
  1246. }
  1247. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  1248. gmbus_irq_handler(dev);
  1249. if (pm_iir)
  1250. gen6_rps_irq_handler(dev_priv, pm_iir);
  1251. I915_WRITE(GTIIR, gt_iir);
  1252. I915_WRITE(GEN6_PMIIR, pm_iir);
  1253. I915_WRITE(VLV_IIR, iir);
  1254. }
  1255. out:
  1256. return ret;
  1257. }
  1258. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  1259. {
  1260. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1261. int pipe;
  1262. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  1263. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
  1264. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  1265. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  1266. SDE_AUDIO_POWER_SHIFT);
  1267. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  1268. port_name(port));
  1269. }
  1270. if (pch_iir & SDE_AUX_MASK)
  1271. dp_aux_irq_handler(dev);
  1272. if (pch_iir & SDE_GMBUS)
  1273. gmbus_irq_handler(dev);
  1274. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  1275. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  1276. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  1277. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  1278. if (pch_iir & SDE_POISON)
  1279. DRM_ERROR("PCH poison interrupt\n");
  1280. if (pch_iir & SDE_FDI_MASK)
  1281. for_each_pipe(pipe)
  1282. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1283. pipe_name(pipe),
  1284. I915_READ(FDI_RX_IIR(pipe)));
  1285. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  1286. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  1287. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  1288. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  1289. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  1290. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  1291. false))
  1292. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  1293. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  1294. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  1295. false))
  1296. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  1297. }
  1298. static void ivb_err_int_handler(struct drm_device *dev)
  1299. {
  1300. struct drm_i915_private *dev_priv = dev->dev_private;
  1301. u32 err_int = I915_READ(GEN7_ERR_INT);
  1302. enum pipe pipe;
  1303. if (err_int & ERR_INT_POISON)
  1304. DRM_ERROR("Poison interrupt\n");
  1305. for_each_pipe(pipe) {
  1306. if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
  1307. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
  1308. false))
  1309. DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
  1310. pipe_name(pipe));
  1311. }
  1312. if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
  1313. if (IS_IVYBRIDGE(dev))
  1314. ivb_pipe_crc_irq_handler(dev, pipe);
  1315. else
  1316. hsw_pipe_crc_irq_handler(dev, pipe);
  1317. }
  1318. }
  1319. I915_WRITE(GEN7_ERR_INT, err_int);
  1320. }
  1321. static void cpt_serr_int_handler(struct drm_device *dev)
  1322. {
  1323. struct drm_i915_private *dev_priv = dev->dev_private;
  1324. u32 serr_int = I915_READ(SERR_INT);
  1325. if (serr_int & SERR_INT_POISON)
  1326. DRM_ERROR("PCH poison interrupt\n");
  1327. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  1328. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  1329. false))
  1330. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  1331. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  1332. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  1333. false))
  1334. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  1335. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  1336. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
  1337. false))
  1338. DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
  1339. I915_WRITE(SERR_INT, serr_int);
  1340. }
  1341. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  1342. {
  1343. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1344. int pipe;
  1345. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  1346. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
  1347. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  1348. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  1349. SDE_AUDIO_POWER_SHIFT_CPT);
  1350. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  1351. port_name(port));
  1352. }
  1353. if (pch_iir & SDE_AUX_MASK_CPT)
  1354. dp_aux_irq_handler(dev);
  1355. if (pch_iir & SDE_GMBUS_CPT)
  1356. gmbus_irq_handler(dev);
  1357. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  1358. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  1359. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  1360. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  1361. if (pch_iir & SDE_FDI_MASK_CPT)
  1362. for_each_pipe(pipe)
  1363. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1364. pipe_name(pipe),
  1365. I915_READ(FDI_RX_IIR(pipe)));
  1366. if (pch_iir & SDE_ERROR_CPT)
  1367. cpt_serr_int_handler(dev);
  1368. }
  1369. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1370. {
  1371. struct drm_i915_private *dev_priv = dev->dev_private;
  1372. enum pipe pipe;
  1373. if (de_iir & DE_AUX_CHANNEL_A)
  1374. dp_aux_irq_handler(dev);
  1375. if (de_iir & DE_GSE)
  1376. intel_opregion_asle_intr(dev);
  1377. if (de_iir & DE_POISON)
  1378. DRM_ERROR("Poison interrupt\n");
  1379. for_each_pipe(pipe) {
  1380. if (de_iir & DE_PIPE_VBLANK(pipe))
  1381. drm_handle_vblank(dev, pipe);
  1382. if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
  1383. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
  1384. DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
  1385. pipe_name(pipe));
  1386. if (de_iir & DE_PIPE_CRC_DONE(pipe))
  1387. i9xx_pipe_crc_irq_handler(dev, pipe);
  1388. /* plane/pipes map 1:1 on ilk+ */
  1389. if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
  1390. intel_prepare_page_flip(dev, pipe);
  1391. intel_finish_page_flip_plane(dev, pipe);
  1392. }
  1393. }
  1394. /* check event from PCH */
  1395. if (de_iir & DE_PCH_EVENT) {
  1396. u32 pch_iir = I915_READ(SDEIIR);
  1397. if (HAS_PCH_CPT(dev))
  1398. cpt_irq_handler(dev, pch_iir);
  1399. else
  1400. ibx_irq_handler(dev, pch_iir);
  1401. /* should clear PCH hotplug event before clear CPU irq */
  1402. I915_WRITE(SDEIIR, pch_iir);
  1403. }
  1404. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1405. ironlake_rps_change_irq_handler(dev);
  1406. }
  1407. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1408. {
  1409. struct drm_i915_private *dev_priv = dev->dev_private;
  1410. enum pipe i;
  1411. if (de_iir & DE_ERR_INT_IVB)
  1412. ivb_err_int_handler(dev);
  1413. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1414. dp_aux_irq_handler(dev);
  1415. if (de_iir & DE_GSE_IVB)
  1416. intel_opregion_asle_intr(dev);
  1417. for_each_pipe(i) {
  1418. if (de_iir & (DE_PIPE_VBLANK_IVB(i)))
  1419. drm_handle_vblank(dev, i);
  1420. /* plane/pipes map 1:1 on ilk+ */
  1421. if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) {
  1422. intel_prepare_page_flip(dev, i);
  1423. intel_finish_page_flip_plane(dev, i);
  1424. }
  1425. }
  1426. /* check event from PCH */
  1427. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1428. u32 pch_iir = I915_READ(SDEIIR);
  1429. cpt_irq_handler(dev, pch_iir);
  1430. /* clear PCH hotplug event before clear CPU irq */
  1431. I915_WRITE(SDEIIR, pch_iir);
  1432. }
  1433. }
  1434. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1435. {
  1436. struct drm_device *dev = (struct drm_device *) arg;
  1437. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1438. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1439. irqreturn_t ret = IRQ_NONE;
  1440. atomic_inc(&dev_priv->irq_received);
  1441. /* We get interrupts on unclaimed registers, so check for this before we
  1442. * do any I915_{READ,WRITE}. */
  1443. intel_uncore_check_errors(dev);
  1444. /* disable master interrupt before clearing iir */
  1445. de_ier = I915_READ(DEIER);
  1446. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1447. POSTING_READ(DEIER);
  1448. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1449. * interrupts will will be stored on its back queue, and then we'll be
  1450. * able to process them after we restore SDEIER (as soon as we restore
  1451. * it, we'll get an interrupt if SDEIIR still has something to process
  1452. * due to its back queue). */
  1453. if (!HAS_PCH_NOP(dev)) {
  1454. sde_ier = I915_READ(SDEIER);
  1455. I915_WRITE(SDEIER, 0);
  1456. POSTING_READ(SDEIER);
  1457. }
  1458. gt_iir = I915_READ(GTIIR);
  1459. if (gt_iir) {
  1460. if (INTEL_INFO(dev)->gen >= 6)
  1461. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1462. else
  1463. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1464. I915_WRITE(GTIIR, gt_iir);
  1465. ret = IRQ_HANDLED;
  1466. }
  1467. de_iir = I915_READ(DEIIR);
  1468. if (de_iir) {
  1469. if (INTEL_INFO(dev)->gen >= 7)
  1470. ivb_display_irq_handler(dev, de_iir);
  1471. else
  1472. ilk_display_irq_handler(dev, de_iir);
  1473. I915_WRITE(DEIIR, de_iir);
  1474. ret = IRQ_HANDLED;
  1475. }
  1476. if (INTEL_INFO(dev)->gen >= 6) {
  1477. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1478. if (pm_iir) {
  1479. gen6_rps_irq_handler(dev_priv, pm_iir);
  1480. I915_WRITE(GEN6_PMIIR, pm_iir);
  1481. ret = IRQ_HANDLED;
  1482. }
  1483. }
  1484. I915_WRITE(DEIER, de_ier);
  1485. POSTING_READ(DEIER);
  1486. if (!HAS_PCH_NOP(dev)) {
  1487. I915_WRITE(SDEIER, sde_ier);
  1488. POSTING_READ(SDEIER);
  1489. }
  1490. return ret;
  1491. }
  1492. static irqreturn_t gen8_irq_handler(int irq, void *arg)
  1493. {
  1494. struct drm_device *dev = arg;
  1495. struct drm_i915_private *dev_priv = dev->dev_private;
  1496. u32 master_ctl;
  1497. irqreturn_t ret = IRQ_NONE;
  1498. uint32_t tmp = 0;
  1499. enum pipe pipe;
  1500. atomic_inc(&dev_priv->irq_received);
  1501. master_ctl = I915_READ(GEN8_MASTER_IRQ);
  1502. master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
  1503. if (!master_ctl)
  1504. return IRQ_NONE;
  1505. I915_WRITE(GEN8_MASTER_IRQ, 0);
  1506. POSTING_READ(GEN8_MASTER_IRQ);
  1507. ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
  1508. if (master_ctl & GEN8_DE_MISC_IRQ) {
  1509. tmp = I915_READ(GEN8_DE_MISC_IIR);
  1510. if (tmp & GEN8_DE_MISC_GSE)
  1511. intel_opregion_asle_intr(dev);
  1512. else if (tmp)
  1513. DRM_ERROR("Unexpected DE Misc interrupt\n");
  1514. else
  1515. DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
  1516. if (tmp) {
  1517. I915_WRITE(GEN8_DE_MISC_IIR, tmp);
  1518. ret = IRQ_HANDLED;
  1519. }
  1520. }
  1521. if (master_ctl & GEN8_DE_PORT_IRQ) {
  1522. tmp = I915_READ(GEN8_DE_PORT_IIR);
  1523. if (tmp & GEN8_AUX_CHANNEL_A)
  1524. dp_aux_irq_handler(dev);
  1525. else if (tmp)
  1526. DRM_ERROR("Unexpected DE Port interrupt\n");
  1527. else
  1528. DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
  1529. if (tmp) {
  1530. I915_WRITE(GEN8_DE_PORT_IIR, tmp);
  1531. ret = IRQ_HANDLED;
  1532. }
  1533. }
  1534. for_each_pipe(pipe) {
  1535. uint32_t pipe_iir;
  1536. if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
  1537. continue;
  1538. pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
  1539. if (pipe_iir & GEN8_PIPE_VBLANK)
  1540. drm_handle_vblank(dev, pipe);
  1541. if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
  1542. intel_prepare_page_flip(dev, pipe);
  1543. intel_finish_page_flip_plane(dev, pipe);
  1544. }
  1545. if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
  1546. hsw_pipe_crc_irq_handler(dev, pipe);
  1547. if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
  1548. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
  1549. false))
  1550. DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
  1551. pipe_name(pipe));
  1552. }
  1553. if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
  1554. DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
  1555. pipe_name(pipe),
  1556. pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
  1557. }
  1558. if (pipe_iir) {
  1559. ret = IRQ_HANDLED;
  1560. I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
  1561. } else
  1562. DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
  1563. }
  1564. if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
  1565. /*
  1566. * FIXME(BDW): Assume for now that the new interrupt handling
  1567. * scheme also closed the SDE interrupt handling race we've seen
  1568. * on older pch-split platforms. But this needs testing.
  1569. */
  1570. u32 pch_iir = I915_READ(SDEIIR);
  1571. cpt_irq_handler(dev, pch_iir);
  1572. if (pch_iir) {
  1573. I915_WRITE(SDEIIR, pch_iir);
  1574. ret = IRQ_HANDLED;
  1575. }
  1576. }
  1577. I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
  1578. POSTING_READ(GEN8_MASTER_IRQ);
  1579. return ret;
  1580. }
  1581. static void i915_error_wake_up(struct drm_i915_private *dev_priv,
  1582. bool reset_completed)
  1583. {
  1584. struct intel_ring_buffer *ring;
  1585. int i;
  1586. /*
  1587. * Notify all waiters for GPU completion events that reset state has
  1588. * been changed, and that they need to restart their wait after
  1589. * checking for potential errors (and bail out to drop locks if there is
  1590. * a gpu reset pending so that i915_error_work_func can acquire them).
  1591. */
  1592. /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
  1593. for_each_ring(ring, dev_priv, i)
  1594. wake_up_all(&ring->irq_queue);
  1595. /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
  1596. wake_up_all(&dev_priv->pending_flip_queue);
  1597. /*
  1598. * Signal tasks blocked in i915_gem_wait_for_error that the pending
  1599. * reset state is cleared.
  1600. */
  1601. if (reset_completed)
  1602. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1603. }
  1604. /**
  1605. * i915_error_work_func - do process context error handling work
  1606. * @work: work struct
  1607. *
  1608. * Fire an error uevent so userspace can see that a hang or error
  1609. * was detected.
  1610. */
  1611. static void i915_error_work_func(struct work_struct *work)
  1612. {
  1613. struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
  1614. work);
  1615. drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
  1616. gpu_error);
  1617. struct drm_device *dev = dev_priv->dev;
  1618. char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
  1619. char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
  1620. char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
  1621. int ret;
  1622. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
  1623. /*
  1624. * Note that there's only one work item which does gpu resets, so we
  1625. * need not worry about concurrent gpu resets potentially incrementing
  1626. * error->reset_counter twice. We only need to take care of another
  1627. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1628. * quick check for that is good enough: schedule_work ensures the
  1629. * correct ordering between hang detection and this work item, and since
  1630. * the reset in-progress bit is only ever set by code outside of this
  1631. * work we don't need to worry about any other races.
  1632. */
  1633. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1634. DRM_DEBUG_DRIVER("resetting chip\n");
  1635. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
  1636. reset_event);
  1637. /*
  1638. * All state reset _must_ be completed before we update the
  1639. * reset counter, for otherwise waiters might miss the reset
  1640. * pending state and not properly drop locks, resulting in
  1641. * deadlocks with the reset work.
  1642. */
  1643. ret = i915_reset(dev);
  1644. intel_display_handle_reset(dev);
  1645. if (ret == 0) {
  1646. /*
  1647. * After all the gem state is reset, increment the reset
  1648. * counter and wake up everyone waiting for the reset to
  1649. * complete.
  1650. *
  1651. * Since unlock operations are a one-sided barrier only,
  1652. * we need to insert a barrier here to order any seqno
  1653. * updates before
  1654. * the counter increment.
  1655. */
  1656. smp_mb__before_atomic_inc();
  1657. atomic_inc(&dev_priv->gpu_error.reset_counter);
  1658. kobject_uevent_env(&dev->primary->kdev->kobj,
  1659. KOBJ_CHANGE, reset_done_event);
  1660. } else {
  1661. atomic_set_mask(I915_WEDGED, &error->reset_counter);
  1662. }
  1663. /*
  1664. * Note: The wake_up also serves as a memory barrier so that
  1665. * waiters see the update value of the reset counter atomic_t.
  1666. */
  1667. i915_error_wake_up(dev_priv, true);
  1668. }
  1669. }
  1670. static void i915_report_and_clear_eir(struct drm_device *dev)
  1671. {
  1672. struct drm_i915_private *dev_priv = dev->dev_private;
  1673. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1674. u32 eir = I915_READ(EIR);
  1675. int pipe, i;
  1676. if (!eir)
  1677. return;
  1678. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1679. i915_get_extra_instdone(dev, instdone);
  1680. if (IS_G4X(dev)) {
  1681. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1682. u32 ipeir = I915_READ(IPEIR_I965);
  1683. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1684. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1685. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1686. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1687. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1688. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1689. I915_WRITE(IPEIR_I965, ipeir);
  1690. POSTING_READ(IPEIR_I965);
  1691. }
  1692. if (eir & GM45_ERROR_PAGE_TABLE) {
  1693. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1694. pr_err("page table error\n");
  1695. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1696. I915_WRITE(PGTBL_ER, pgtbl_err);
  1697. POSTING_READ(PGTBL_ER);
  1698. }
  1699. }
  1700. if (!IS_GEN2(dev)) {
  1701. if (eir & I915_ERROR_PAGE_TABLE) {
  1702. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1703. pr_err("page table error\n");
  1704. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1705. I915_WRITE(PGTBL_ER, pgtbl_err);
  1706. POSTING_READ(PGTBL_ER);
  1707. }
  1708. }
  1709. if (eir & I915_ERROR_MEMORY_REFRESH) {
  1710. pr_err("memory refresh error:\n");
  1711. for_each_pipe(pipe)
  1712. pr_err("pipe %c stat: 0x%08x\n",
  1713. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  1714. /* pipestat has already been acked */
  1715. }
  1716. if (eir & I915_ERROR_INSTRUCTION) {
  1717. pr_err("instruction error\n");
  1718. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  1719. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1720. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1721. if (INTEL_INFO(dev)->gen < 4) {
  1722. u32 ipeir = I915_READ(IPEIR);
  1723. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  1724. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  1725. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  1726. I915_WRITE(IPEIR, ipeir);
  1727. POSTING_READ(IPEIR);
  1728. } else {
  1729. u32 ipeir = I915_READ(IPEIR_I965);
  1730. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1731. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1732. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1733. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1734. I915_WRITE(IPEIR_I965, ipeir);
  1735. POSTING_READ(IPEIR_I965);
  1736. }
  1737. }
  1738. I915_WRITE(EIR, eir);
  1739. POSTING_READ(EIR);
  1740. eir = I915_READ(EIR);
  1741. if (eir) {
  1742. /*
  1743. * some errors might have become stuck,
  1744. * mask them.
  1745. */
  1746. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1747. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1748. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1749. }
  1750. }
  1751. /**
  1752. * i915_handle_error - handle an error interrupt
  1753. * @dev: drm device
  1754. *
  1755. * Do some basic checking of regsiter state at error interrupt time and
  1756. * dump it to the syslog. Also call i915_capture_error_state() to make
  1757. * sure we get a record and make it available in debugfs. Fire a uevent
  1758. * so userspace knows something bad happened (should trigger collection
  1759. * of a ring dump etc.).
  1760. */
  1761. void i915_handle_error(struct drm_device *dev, bool wedged)
  1762. {
  1763. struct drm_i915_private *dev_priv = dev->dev_private;
  1764. i915_capture_error_state(dev);
  1765. i915_report_and_clear_eir(dev);
  1766. if (wedged) {
  1767. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  1768. &dev_priv->gpu_error.reset_counter);
  1769. /*
  1770. * Wakeup waiting processes so that the reset work function
  1771. * i915_error_work_func doesn't deadlock trying to grab various
  1772. * locks. By bumping the reset counter first, the woken
  1773. * processes will see a reset in progress and back off,
  1774. * releasing their locks and then wait for the reset completion.
  1775. * We must do this for _all_ gpu waiters that might hold locks
  1776. * that the reset work needs to acquire.
  1777. *
  1778. * Note: The wake_up serves as the required memory barrier to
  1779. * ensure that the waiters see the updated value of the reset
  1780. * counter atomic_t.
  1781. */
  1782. i915_error_wake_up(dev_priv, false);
  1783. }
  1784. /*
  1785. * Our reset work can grab modeset locks (since it needs to reset the
  1786. * state of outstanding pagelips). Hence it must not be run on our own
  1787. * dev-priv->wq work queue for otherwise the flush_work in the pageflip
  1788. * code will deadlock.
  1789. */
  1790. schedule_work(&dev_priv->gpu_error.work);
  1791. }
  1792. static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1793. {
  1794. drm_i915_private_t *dev_priv = dev->dev_private;
  1795. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1796. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1797. struct drm_i915_gem_object *obj;
  1798. struct intel_unpin_work *work;
  1799. unsigned long flags;
  1800. bool stall_detected;
  1801. /* Ignore early vblank irqs */
  1802. if (intel_crtc == NULL)
  1803. return;
  1804. spin_lock_irqsave(&dev->event_lock, flags);
  1805. work = intel_crtc->unpin_work;
  1806. if (work == NULL ||
  1807. atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
  1808. !work->enable_stall_check) {
  1809. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1810. spin_unlock_irqrestore(&dev->event_lock, flags);
  1811. return;
  1812. }
  1813. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1814. obj = work->pending_flip_obj;
  1815. if (INTEL_INFO(dev)->gen >= 4) {
  1816. int dspsurf = DSPSURF(intel_crtc->plane);
  1817. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  1818. i915_gem_obj_ggtt_offset(obj);
  1819. } else {
  1820. int dspaddr = DSPADDR(intel_crtc->plane);
  1821. stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
  1822. crtc->y * crtc->fb->pitches[0] +
  1823. crtc->x * crtc->fb->bits_per_pixel/8);
  1824. }
  1825. spin_unlock_irqrestore(&dev->event_lock, flags);
  1826. if (stall_detected) {
  1827. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1828. intel_prepare_page_flip(dev, intel_crtc->plane);
  1829. }
  1830. }
  1831. /* Called from drm generic code, passed 'crtc' which
  1832. * we use as a pipe index
  1833. */
  1834. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1835. {
  1836. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1837. unsigned long irqflags;
  1838. if (!i915_pipe_enabled(dev, pipe))
  1839. return -EINVAL;
  1840. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1841. if (INTEL_INFO(dev)->gen >= 4)
  1842. i915_enable_pipestat(dev_priv, pipe,
  1843. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1844. else
  1845. i915_enable_pipestat(dev_priv, pipe,
  1846. PIPE_VBLANK_INTERRUPT_ENABLE);
  1847. /* maintain vblank delivery even in deep C-states */
  1848. if (dev_priv->info->gen == 3)
  1849. I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
  1850. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1851. return 0;
  1852. }
  1853. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1854. {
  1855. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1856. unsigned long irqflags;
  1857. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  1858. DE_PIPE_VBLANK(pipe);
  1859. if (!i915_pipe_enabled(dev, pipe))
  1860. return -EINVAL;
  1861. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1862. ironlake_enable_display_irq(dev_priv, bit);
  1863. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1864. return 0;
  1865. }
  1866. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  1867. {
  1868. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1869. unsigned long irqflags;
  1870. u32 imr;
  1871. if (!i915_pipe_enabled(dev, pipe))
  1872. return -EINVAL;
  1873. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1874. imr = I915_READ(VLV_IMR);
  1875. if (pipe == PIPE_A)
  1876. imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1877. else
  1878. imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1879. I915_WRITE(VLV_IMR, imr);
  1880. i915_enable_pipestat(dev_priv, pipe,
  1881. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1882. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1883. return 0;
  1884. }
  1885. static int gen8_enable_vblank(struct drm_device *dev, int pipe)
  1886. {
  1887. struct drm_i915_private *dev_priv = dev->dev_private;
  1888. unsigned long irqflags;
  1889. if (!i915_pipe_enabled(dev, pipe))
  1890. return -EINVAL;
  1891. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1892. dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
  1893. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  1894. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  1895. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1896. return 0;
  1897. }
  1898. /* Called from drm generic code, passed 'crtc' which
  1899. * we use as a pipe index
  1900. */
  1901. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  1902. {
  1903. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1904. unsigned long irqflags;
  1905. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1906. if (dev_priv->info->gen == 3)
  1907. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
  1908. i915_disable_pipestat(dev_priv, pipe,
  1909. PIPE_VBLANK_INTERRUPT_ENABLE |
  1910. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1911. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1912. }
  1913. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  1914. {
  1915. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1916. unsigned long irqflags;
  1917. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  1918. DE_PIPE_VBLANK(pipe);
  1919. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1920. ironlake_disable_display_irq(dev_priv, bit);
  1921. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1922. }
  1923. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  1924. {
  1925. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1926. unsigned long irqflags;
  1927. u32 imr;
  1928. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1929. i915_disable_pipestat(dev_priv, pipe,
  1930. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1931. imr = I915_READ(VLV_IMR);
  1932. if (pipe == PIPE_A)
  1933. imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1934. else
  1935. imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1936. I915_WRITE(VLV_IMR, imr);
  1937. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1938. }
  1939. static void gen8_disable_vblank(struct drm_device *dev, int pipe)
  1940. {
  1941. struct drm_i915_private *dev_priv = dev->dev_private;
  1942. unsigned long irqflags;
  1943. if (!i915_pipe_enabled(dev, pipe))
  1944. return;
  1945. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1946. dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
  1947. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  1948. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  1949. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1950. }
  1951. static u32
  1952. ring_last_seqno(struct intel_ring_buffer *ring)
  1953. {
  1954. return list_entry(ring->request_list.prev,
  1955. struct drm_i915_gem_request, list)->seqno;
  1956. }
  1957. static bool
  1958. ring_idle(struct intel_ring_buffer *ring, u32 seqno)
  1959. {
  1960. return (list_empty(&ring->request_list) ||
  1961. i915_seqno_passed(seqno, ring_last_seqno(ring)));
  1962. }
  1963. static struct intel_ring_buffer *
  1964. semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
  1965. {
  1966. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1967. u32 cmd, ipehr, acthd, acthd_min;
  1968. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  1969. if ((ipehr & ~(0x3 << 16)) !=
  1970. (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
  1971. return NULL;
  1972. /* ACTHD is likely pointing to the dword after the actual command,
  1973. * so scan backwards until we find the MBOX.
  1974. */
  1975. acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
  1976. acthd_min = max((int)acthd - 3 * 4, 0);
  1977. do {
  1978. cmd = ioread32(ring->virtual_start + acthd);
  1979. if (cmd == ipehr)
  1980. break;
  1981. acthd -= 4;
  1982. if (acthd < acthd_min)
  1983. return NULL;
  1984. } while (1);
  1985. *seqno = ioread32(ring->virtual_start+acthd+4)+1;
  1986. return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
  1987. }
  1988. static int semaphore_passed(struct intel_ring_buffer *ring)
  1989. {
  1990. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1991. struct intel_ring_buffer *signaller;
  1992. u32 seqno, ctl;
  1993. ring->hangcheck.deadlock = true;
  1994. signaller = semaphore_waits_for(ring, &seqno);
  1995. if (signaller == NULL || signaller->hangcheck.deadlock)
  1996. return -1;
  1997. /* cursory check for an unkickable deadlock */
  1998. ctl = I915_READ_CTL(signaller);
  1999. if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
  2000. return -1;
  2001. return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
  2002. }
  2003. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  2004. {
  2005. struct intel_ring_buffer *ring;
  2006. int i;
  2007. for_each_ring(ring, dev_priv, i)
  2008. ring->hangcheck.deadlock = false;
  2009. }
  2010. static enum intel_ring_hangcheck_action
  2011. ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
  2012. {
  2013. struct drm_device *dev = ring->dev;
  2014. struct drm_i915_private *dev_priv = dev->dev_private;
  2015. u32 tmp;
  2016. if (ring->hangcheck.acthd != acthd)
  2017. return HANGCHECK_ACTIVE;
  2018. if (IS_GEN2(dev))
  2019. return HANGCHECK_HUNG;
  2020. /* Is the chip hanging on a WAIT_FOR_EVENT?
  2021. * If so we can simply poke the RB_WAIT bit
  2022. * and break the hang. This should work on
  2023. * all but the second generation chipsets.
  2024. */
  2025. tmp = I915_READ_CTL(ring);
  2026. if (tmp & RING_WAIT) {
  2027. DRM_ERROR("Kicking stuck wait on %s\n",
  2028. ring->name);
  2029. i915_handle_error(dev, false);
  2030. I915_WRITE_CTL(ring, tmp);
  2031. return HANGCHECK_KICK;
  2032. }
  2033. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  2034. switch (semaphore_passed(ring)) {
  2035. default:
  2036. return HANGCHECK_HUNG;
  2037. case 1:
  2038. DRM_ERROR("Kicking stuck semaphore on %s\n",
  2039. ring->name);
  2040. i915_handle_error(dev, false);
  2041. I915_WRITE_CTL(ring, tmp);
  2042. return HANGCHECK_KICK;
  2043. case 0:
  2044. return HANGCHECK_WAIT;
  2045. }
  2046. }
  2047. return HANGCHECK_HUNG;
  2048. }
  2049. /**
  2050. * This is called when the chip hasn't reported back with completed
  2051. * batchbuffers in a long time. We keep track per ring seqno progress and
  2052. * if there are no progress, hangcheck score for that ring is increased.
  2053. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  2054. * we kick the ring. If we see no progress on three subsequent calls
  2055. * we assume chip is wedged and try to fix it by resetting the chip.
  2056. */
  2057. static void i915_hangcheck_elapsed(unsigned long data)
  2058. {
  2059. struct drm_device *dev = (struct drm_device *)data;
  2060. drm_i915_private_t *dev_priv = dev->dev_private;
  2061. struct intel_ring_buffer *ring;
  2062. int i;
  2063. int busy_count = 0, rings_hung = 0;
  2064. bool stuck[I915_NUM_RINGS] = { 0 };
  2065. #define BUSY 1
  2066. #define KICK 5
  2067. #define HUNG 20
  2068. #define FIRE 30
  2069. if (!i915_enable_hangcheck)
  2070. return;
  2071. for_each_ring(ring, dev_priv, i) {
  2072. u32 seqno, acthd;
  2073. bool busy = true;
  2074. semaphore_clear_deadlocks(dev_priv);
  2075. seqno = ring->get_seqno(ring, false);
  2076. acthd = intel_ring_get_active_head(ring);
  2077. if (ring->hangcheck.seqno == seqno) {
  2078. if (ring_idle(ring, seqno)) {
  2079. ring->hangcheck.action = HANGCHECK_IDLE;
  2080. if (waitqueue_active(&ring->irq_queue)) {
  2081. /* Issue a wake-up to catch stuck h/w. */
  2082. if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
  2083. if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
  2084. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  2085. ring->name);
  2086. else
  2087. DRM_INFO("Fake missed irq on %s\n",
  2088. ring->name);
  2089. wake_up_all(&ring->irq_queue);
  2090. }
  2091. /* Safeguard against driver failure */
  2092. ring->hangcheck.score += BUSY;
  2093. } else
  2094. busy = false;
  2095. } else {
  2096. /* We always increment the hangcheck score
  2097. * if the ring is busy and still processing
  2098. * the same request, so that no single request
  2099. * can run indefinitely (such as a chain of
  2100. * batches). The only time we do not increment
  2101. * the hangcheck score on this ring, if this
  2102. * ring is in a legitimate wait for another
  2103. * ring. In that case the waiting ring is a
  2104. * victim and we want to be sure we catch the
  2105. * right culprit. Then every time we do kick
  2106. * the ring, add a small increment to the
  2107. * score so that we can catch a batch that is
  2108. * being repeatedly kicked and so responsible
  2109. * for stalling the machine.
  2110. */
  2111. ring->hangcheck.action = ring_stuck(ring,
  2112. acthd);
  2113. switch (ring->hangcheck.action) {
  2114. case HANGCHECK_IDLE:
  2115. case HANGCHECK_WAIT:
  2116. break;
  2117. case HANGCHECK_ACTIVE:
  2118. ring->hangcheck.score += BUSY;
  2119. break;
  2120. case HANGCHECK_KICK:
  2121. ring->hangcheck.score += KICK;
  2122. break;
  2123. case HANGCHECK_HUNG:
  2124. ring->hangcheck.score += HUNG;
  2125. stuck[i] = true;
  2126. break;
  2127. }
  2128. }
  2129. } else {
  2130. ring->hangcheck.action = HANGCHECK_ACTIVE;
  2131. /* Gradually reduce the count so that we catch DoS
  2132. * attempts across multiple batches.
  2133. */
  2134. if (ring->hangcheck.score > 0)
  2135. ring->hangcheck.score--;
  2136. }
  2137. ring->hangcheck.seqno = seqno;
  2138. ring->hangcheck.acthd = acthd;
  2139. busy_count += busy;
  2140. }
  2141. for_each_ring(ring, dev_priv, i) {
  2142. if (ring->hangcheck.score > FIRE) {
  2143. DRM_INFO("%s on %s\n",
  2144. stuck[i] ? "stuck" : "no progress",
  2145. ring->name);
  2146. rings_hung++;
  2147. }
  2148. }
  2149. if (rings_hung)
  2150. return i915_handle_error(dev, true);
  2151. if (busy_count)
  2152. /* Reset timer case chip hangs without another request
  2153. * being added */
  2154. i915_queue_hangcheck(dev);
  2155. }
  2156. void i915_queue_hangcheck(struct drm_device *dev)
  2157. {
  2158. struct drm_i915_private *dev_priv = dev->dev_private;
  2159. if (!i915_enable_hangcheck)
  2160. return;
  2161. mod_timer(&dev_priv->gpu_error.hangcheck_timer,
  2162. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  2163. }
  2164. static void ibx_irq_preinstall(struct drm_device *dev)
  2165. {
  2166. struct drm_i915_private *dev_priv = dev->dev_private;
  2167. if (HAS_PCH_NOP(dev))
  2168. return;
  2169. /* south display irq */
  2170. I915_WRITE(SDEIMR, 0xffffffff);
  2171. /*
  2172. * SDEIER is also touched by the interrupt handler to work around missed
  2173. * PCH interrupts. Hence we can't update it after the interrupt handler
  2174. * is enabled - instead we unconditionally enable all PCH interrupt
  2175. * sources here, but then only unmask them as needed with SDEIMR.
  2176. */
  2177. I915_WRITE(SDEIER, 0xffffffff);
  2178. POSTING_READ(SDEIER);
  2179. }
  2180. static void gen5_gt_irq_preinstall(struct drm_device *dev)
  2181. {
  2182. struct drm_i915_private *dev_priv = dev->dev_private;
  2183. /* and GT */
  2184. I915_WRITE(GTIMR, 0xffffffff);
  2185. I915_WRITE(GTIER, 0x0);
  2186. POSTING_READ(GTIER);
  2187. if (INTEL_INFO(dev)->gen >= 6) {
  2188. /* and PM */
  2189. I915_WRITE(GEN6_PMIMR, 0xffffffff);
  2190. I915_WRITE(GEN6_PMIER, 0x0);
  2191. POSTING_READ(GEN6_PMIER);
  2192. }
  2193. }
  2194. /* drm_dma.h hooks
  2195. */
  2196. static void ironlake_irq_preinstall(struct drm_device *dev)
  2197. {
  2198. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2199. atomic_set(&dev_priv->irq_received, 0);
  2200. I915_WRITE(HWSTAM, 0xeffe);
  2201. I915_WRITE(DEIMR, 0xffffffff);
  2202. I915_WRITE(DEIER, 0x0);
  2203. POSTING_READ(DEIER);
  2204. gen5_gt_irq_preinstall(dev);
  2205. ibx_irq_preinstall(dev);
  2206. }
  2207. static void valleyview_irq_preinstall(struct drm_device *dev)
  2208. {
  2209. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2210. int pipe;
  2211. atomic_set(&dev_priv->irq_received, 0);
  2212. /* VLV magic */
  2213. I915_WRITE(VLV_IMR, 0);
  2214. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  2215. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  2216. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  2217. /* and GT */
  2218. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2219. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2220. gen5_gt_irq_preinstall(dev);
  2221. I915_WRITE(DPINVGTT, 0xff);
  2222. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2223. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2224. for_each_pipe(pipe)
  2225. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2226. I915_WRITE(VLV_IIR, 0xffffffff);
  2227. I915_WRITE(VLV_IMR, 0xffffffff);
  2228. I915_WRITE(VLV_IER, 0x0);
  2229. POSTING_READ(VLV_IER);
  2230. }
  2231. static void gen8_irq_preinstall(struct drm_device *dev)
  2232. {
  2233. struct drm_i915_private *dev_priv = dev->dev_private;
  2234. int pipe;
  2235. atomic_set(&dev_priv->irq_received, 0);
  2236. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2237. POSTING_READ(GEN8_MASTER_IRQ);
  2238. /* IIR can theoretically queue up two events. Be paranoid */
  2239. #define GEN8_IRQ_INIT_NDX(type, which) do { \
  2240. I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
  2241. POSTING_READ(GEN8_##type##_IMR(which)); \
  2242. I915_WRITE(GEN8_##type##_IER(which), 0); \
  2243. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  2244. POSTING_READ(GEN8_##type##_IIR(which)); \
  2245. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  2246. } while (0)
  2247. #define GEN8_IRQ_INIT(type) do { \
  2248. I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
  2249. POSTING_READ(GEN8_##type##_IMR); \
  2250. I915_WRITE(GEN8_##type##_IER, 0); \
  2251. I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
  2252. POSTING_READ(GEN8_##type##_IIR); \
  2253. I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
  2254. } while (0)
  2255. GEN8_IRQ_INIT_NDX(GT, 0);
  2256. GEN8_IRQ_INIT_NDX(GT, 1);
  2257. GEN8_IRQ_INIT_NDX(GT, 2);
  2258. GEN8_IRQ_INIT_NDX(GT, 3);
  2259. for_each_pipe(pipe) {
  2260. GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
  2261. }
  2262. GEN8_IRQ_INIT(DE_PORT);
  2263. GEN8_IRQ_INIT(DE_MISC);
  2264. GEN8_IRQ_INIT(PCU);
  2265. #undef GEN8_IRQ_INIT
  2266. #undef GEN8_IRQ_INIT_NDX
  2267. POSTING_READ(GEN8_PCU_IIR);
  2268. ibx_irq_preinstall(dev);
  2269. }
  2270. static void ibx_hpd_irq_setup(struct drm_device *dev)
  2271. {
  2272. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2273. struct drm_mode_config *mode_config = &dev->mode_config;
  2274. struct intel_encoder *intel_encoder;
  2275. u32 hotplug_irqs, hotplug, enabled_irqs = 0;
  2276. if (HAS_PCH_IBX(dev)) {
  2277. hotplug_irqs = SDE_HOTPLUG_MASK;
  2278. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2279. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2280. enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
  2281. } else {
  2282. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  2283. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2284. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2285. enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
  2286. }
  2287. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2288. /*
  2289. * Enable digital hotplug on the PCH, and configure the DP short pulse
  2290. * duration to 2ms (which is the minimum in the Display Port spec)
  2291. *
  2292. * This register is the same on all known PCH chips.
  2293. */
  2294. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  2295. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  2296. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  2297. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  2298. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  2299. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  2300. }
  2301. static void ibx_irq_postinstall(struct drm_device *dev)
  2302. {
  2303. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2304. u32 mask;
  2305. if (HAS_PCH_NOP(dev))
  2306. return;
  2307. if (HAS_PCH_IBX(dev)) {
  2308. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
  2309. } else {
  2310. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
  2311. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  2312. }
  2313. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  2314. I915_WRITE(SDEIMR, ~mask);
  2315. }
  2316. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  2317. {
  2318. struct drm_i915_private *dev_priv = dev->dev_private;
  2319. u32 pm_irqs, gt_irqs;
  2320. pm_irqs = gt_irqs = 0;
  2321. dev_priv->gt_irq_mask = ~0;
  2322. if (HAS_L3_DPF(dev)) {
  2323. /* L3 parity interrupt is always unmasked. */
  2324. dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
  2325. gt_irqs |= GT_PARITY_ERROR(dev);
  2326. }
  2327. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  2328. if (IS_GEN5(dev)) {
  2329. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  2330. ILK_BSD_USER_INTERRUPT;
  2331. } else {
  2332. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  2333. }
  2334. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2335. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  2336. I915_WRITE(GTIER, gt_irqs);
  2337. POSTING_READ(GTIER);
  2338. if (INTEL_INFO(dev)->gen >= 6) {
  2339. pm_irqs |= GEN6_PM_RPS_EVENTS;
  2340. if (HAS_VEBOX(dev))
  2341. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  2342. dev_priv->pm_irq_mask = 0xffffffff;
  2343. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  2344. I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
  2345. I915_WRITE(GEN6_PMIER, pm_irqs);
  2346. POSTING_READ(GEN6_PMIER);
  2347. }
  2348. }
  2349. static int ironlake_irq_postinstall(struct drm_device *dev)
  2350. {
  2351. unsigned long irqflags;
  2352. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2353. u32 display_mask, extra_mask;
  2354. if (INTEL_INFO(dev)->gen >= 7) {
  2355. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  2356. DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
  2357. DE_PLANEB_FLIP_DONE_IVB |
  2358. DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
  2359. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  2360. DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
  2361. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  2362. } else {
  2363. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  2364. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  2365. DE_AUX_CHANNEL_A |
  2366. DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
  2367. DE_POISON);
  2368. extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
  2369. DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
  2370. }
  2371. dev_priv->irq_mask = ~display_mask;
  2372. /* should always can generate irq */
  2373. I915_WRITE(DEIIR, I915_READ(DEIIR));
  2374. I915_WRITE(DEIMR, dev_priv->irq_mask);
  2375. I915_WRITE(DEIER, display_mask | extra_mask);
  2376. POSTING_READ(DEIER);
  2377. gen5_gt_irq_postinstall(dev);
  2378. ibx_irq_postinstall(dev);
  2379. if (IS_IRONLAKE_M(dev)) {
  2380. /* Enable PCU event interrupts
  2381. *
  2382. * spinlocking not required here for correctness since interrupt
  2383. * setup is guaranteed to run in single-threaded context. But we
  2384. * need it to make the assert_spin_locked happy. */
  2385. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2386. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  2387. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2388. }
  2389. return 0;
  2390. }
  2391. static int valleyview_irq_postinstall(struct drm_device *dev)
  2392. {
  2393. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2394. u32 enable_mask;
  2395. u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV |
  2396. PIPE_CRC_DONE_ENABLE;
  2397. unsigned long irqflags;
  2398. enable_mask = I915_DISPLAY_PORT_INTERRUPT;
  2399. enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2400. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  2401. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2402. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  2403. /*
  2404. *Leave vblank interrupts masked initially. enable/disable will
  2405. * toggle them based on usage.
  2406. */
  2407. dev_priv->irq_mask = (~enable_mask) |
  2408. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  2409. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  2410. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2411. POSTING_READ(PORT_HOTPLUG_EN);
  2412. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2413. I915_WRITE(VLV_IER, enable_mask);
  2414. I915_WRITE(VLV_IIR, 0xffffffff);
  2415. I915_WRITE(PIPESTAT(0), 0xffff);
  2416. I915_WRITE(PIPESTAT(1), 0xffff);
  2417. POSTING_READ(VLV_IER);
  2418. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2419. * just to make the assert_spin_locked check happy. */
  2420. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2421. i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable);
  2422. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
  2423. i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable);
  2424. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2425. I915_WRITE(VLV_IIR, 0xffffffff);
  2426. I915_WRITE(VLV_IIR, 0xffffffff);
  2427. gen5_gt_irq_postinstall(dev);
  2428. /* ack & enable invalid PTE error interrupts */
  2429. #if 0 /* FIXME: add support to irq handler for checking these bits */
  2430. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2431. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  2432. #endif
  2433. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  2434. return 0;
  2435. }
  2436. static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
  2437. {
  2438. int i;
  2439. /* These are interrupts we'll toggle with the ring mask register */
  2440. uint32_t gt_interrupts[] = {
  2441. GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  2442. GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
  2443. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
  2444. GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
  2445. GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
  2446. 0,
  2447. GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
  2448. };
  2449. for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
  2450. u32 tmp = I915_READ(GEN8_GT_IIR(i));
  2451. if (tmp)
  2452. DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
  2453. i, tmp);
  2454. I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
  2455. I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
  2456. }
  2457. POSTING_READ(GEN8_GT_IER(0));
  2458. }
  2459. static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
  2460. {
  2461. struct drm_device *dev = dev_priv->dev;
  2462. uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
  2463. GEN8_PIPE_CDCLK_CRC_DONE |
  2464. GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  2465. uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
  2466. GEN8_PIPE_FIFO_UNDERRUN;
  2467. int pipe;
  2468. dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
  2469. dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
  2470. dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
  2471. for_each_pipe(pipe) {
  2472. u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
  2473. if (tmp)
  2474. DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
  2475. pipe, tmp);
  2476. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2477. I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
  2478. }
  2479. POSTING_READ(GEN8_DE_PIPE_ISR(0));
  2480. I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
  2481. I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
  2482. POSTING_READ(GEN8_DE_PORT_IER);
  2483. }
  2484. static int gen8_irq_postinstall(struct drm_device *dev)
  2485. {
  2486. struct drm_i915_private *dev_priv = dev->dev_private;
  2487. gen8_gt_irq_postinstall(dev_priv);
  2488. gen8_de_irq_postinstall(dev_priv);
  2489. ibx_irq_postinstall(dev);
  2490. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  2491. POSTING_READ(GEN8_MASTER_IRQ);
  2492. return 0;
  2493. }
  2494. static void gen8_irq_uninstall(struct drm_device *dev)
  2495. {
  2496. struct drm_i915_private *dev_priv = dev->dev_private;
  2497. int pipe;
  2498. if (!dev_priv)
  2499. return;
  2500. atomic_set(&dev_priv->irq_received, 0);
  2501. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2502. #define GEN8_IRQ_FINI_NDX(type, which) do { \
  2503. I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
  2504. I915_WRITE(GEN8_##type##_IER(which), 0); \
  2505. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  2506. } while (0)
  2507. #define GEN8_IRQ_FINI(type) do { \
  2508. I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
  2509. I915_WRITE(GEN8_##type##_IER, 0); \
  2510. I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
  2511. } while (0)
  2512. GEN8_IRQ_FINI_NDX(GT, 0);
  2513. GEN8_IRQ_FINI_NDX(GT, 1);
  2514. GEN8_IRQ_FINI_NDX(GT, 2);
  2515. GEN8_IRQ_FINI_NDX(GT, 3);
  2516. for_each_pipe(pipe) {
  2517. GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
  2518. }
  2519. GEN8_IRQ_FINI(DE_PORT);
  2520. GEN8_IRQ_FINI(DE_MISC);
  2521. GEN8_IRQ_FINI(PCU);
  2522. #undef GEN8_IRQ_FINI
  2523. #undef GEN8_IRQ_FINI_NDX
  2524. POSTING_READ(GEN8_PCU_IIR);
  2525. }
  2526. static void valleyview_irq_uninstall(struct drm_device *dev)
  2527. {
  2528. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2529. int pipe;
  2530. if (!dev_priv)
  2531. return;
  2532. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2533. for_each_pipe(pipe)
  2534. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2535. I915_WRITE(HWSTAM, 0xffffffff);
  2536. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2537. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2538. for_each_pipe(pipe)
  2539. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2540. I915_WRITE(VLV_IIR, 0xffffffff);
  2541. I915_WRITE(VLV_IMR, 0xffffffff);
  2542. I915_WRITE(VLV_IER, 0x0);
  2543. POSTING_READ(VLV_IER);
  2544. }
  2545. static void ironlake_irq_uninstall(struct drm_device *dev)
  2546. {
  2547. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2548. if (!dev_priv)
  2549. return;
  2550. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2551. I915_WRITE(HWSTAM, 0xffffffff);
  2552. I915_WRITE(DEIMR, 0xffffffff);
  2553. I915_WRITE(DEIER, 0x0);
  2554. I915_WRITE(DEIIR, I915_READ(DEIIR));
  2555. if (IS_GEN7(dev))
  2556. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  2557. I915_WRITE(GTIMR, 0xffffffff);
  2558. I915_WRITE(GTIER, 0x0);
  2559. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2560. if (HAS_PCH_NOP(dev))
  2561. return;
  2562. I915_WRITE(SDEIMR, 0xffffffff);
  2563. I915_WRITE(SDEIER, 0x0);
  2564. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  2565. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  2566. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  2567. }
  2568. static void i8xx_irq_preinstall(struct drm_device * dev)
  2569. {
  2570. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2571. int pipe;
  2572. atomic_set(&dev_priv->irq_received, 0);
  2573. for_each_pipe(pipe)
  2574. I915_WRITE(PIPESTAT(pipe), 0);
  2575. I915_WRITE16(IMR, 0xffff);
  2576. I915_WRITE16(IER, 0x0);
  2577. POSTING_READ16(IER);
  2578. }
  2579. static int i8xx_irq_postinstall(struct drm_device *dev)
  2580. {
  2581. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2582. unsigned long irqflags;
  2583. I915_WRITE16(EMR,
  2584. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2585. /* Unmask the interrupts that we always want on. */
  2586. dev_priv->irq_mask =
  2587. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2588. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2589. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2590. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2591. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2592. I915_WRITE16(IMR, dev_priv->irq_mask);
  2593. I915_WRITE16(IER,
  2594. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2595. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2596. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2597. I915_USER_INTERRUPT);
  2598. POSTING_READ16(IER);
  2599. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2600. * just to make the assert_spin_locked check happy. */
  2601. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2602. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
  2603. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
  2604. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2605. return 0;
  2606. }
  2607. /*
  2608. * Returns true when a page flip has completed.
  2609. */
  2610. static bool i8xx_handle_vblank(struct drm_device *dev,
  2611. int plane, int pipe, u32 iir)
  2612. {
  2613. drm_i915_private_t *dev_priv = dev->dev_private;
  2614. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  2615. if (!drm_handle_vblank(dev, pipe))
  2616. return false;
  2617. if ((iir & flip_pending) == 0)
  2618. return false;
  2619. intel_prepare_page_flip(dev, plane);
  2620. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2621. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2622. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2623. * the flip is completed (no longer pending). Since this doesn't raise
  2624. * an interrupt per se, we watch for the change at vblank.
  2625. */
  2626. if (I915_READ16(ISR) & flip_pending)
  2627. return false;
  2628. intel_finish_page_flip(dev, pipe);
  2629. return true;
  2630. }
  2631. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  2632. {
  2633. struct drm_device *dev = (struct drm_device *) arg;
  2634. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2635. u16 iir, new_iir;
  2636. u32 pipe_stats[2];
  2637. unsigned long irqflags;
  2638. int pipe;
  2639. u16 flip_mask =
  2640. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2641. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2642. atomic_inc(&dev_priv->irq_received);
  2643. iir = I915_READ16(IIR);
  2644. if (iir == 0)
  2645. return IRQ_NONE;
  2646. while (iir & ~flip_mask) {
  2647. /* Can't rely on pipestat interrupt bit in iir as it might
  2648. * have been cleared after the pipestat interrupt was received.
  2649. * It doesn't set the bit in iir again, but it still produces
  2650. * interrupts (for non-MSI).
  2651. */
  2652. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2653. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2654. i915_handle_error(dev, false);
  2655. for_each_pipe(pipe) {
  2656. int reg = PIPESTAT(pipe);
  2657. pipe_stats[pipe] = I915_READ(reg);
  2658. /*
  2659. * Clear the PIPE*STAT regs before the IIR
  2660. */
  2661. if (pipe_stats[pipe] & 0x8000ffff) {
  2662. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2663. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2664. pipe_name(pipe));
  2665. I915_WRITE(reg, pipe_stats[pipe]);
  2666. }
  2667. }
  2668. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2669. I915_WRITE16(IIR, iir & ~flip_mask);
  2670. new_iir = I915_READ16(IIR); /* Flush posted writes */
  2671. i915_update_dri1_breadcrumb(dev);
  2672. if (iir & I915_USER_INTERRUPT)
  2673. notify_ring(dev, &dev_priv->ring[RCS]);
  2674. for_each_pipe(pipe) {
  2675. int plane = pipe;
  2676. if (HAS_FBC(dev))
  2677. plane = !plane;
  2678. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2679. i8xx_handle_vblank(dev, plane, pipe, iir))
  2680. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  2681. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  2682. i9xx_pipe_crc_irq_handler(dev, pipe);
  2683. }
  2684. iir = new_iir;
  2685. }
  2686. return IRQ_HANDLED;
  2687. }
  2688. static void i8xx_irq_uninstall(struct drm_device * dev)
  2689. {
  2690. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2691. int pipe;
  2692. for_each_pipe(pipe) {
  2693. /* Clear enable bits; then clear status bits */
  2694. I915_WRITE(PIPESTAT(pipe), 0);
  2695. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2696. }
  2697. I915_WRITE16(IMR, 0xffff);
  2698. I915_WRITE16(IER, 0x0);
  2699. I915_WRITE16(IIR, I915_READ16(IIR));
  2700. }
  2701. static void i915_irq_preinstall(struct drm_device * dev)
  2702. {
  2703. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2704. int pipe;
  2705. atomic_set(&dev_priv->irq_received, 0);
  2706. if (I915_HAS_HOTPLUG(dev)) {
  2707. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2708. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2709. }
  2710. I915_WRITE16(HWSTAM, 0xeffe);
  2711. for_each_pipe(pipe)
  2712. I915_WRITE(PIPESTAT(pipe), 0);
  2713. I915_WRITE(IMR, 0xffffffff);
  2714. I915_WRITE(IER, 0x0);
  2715. POSTING_READ(IER);
  2716. }
  2717. static int i915_irq_postinstall(struct drm_device *dev)
  2718. {
  2719. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2720. u32 enable_mask;
  2721. unsigned long irqflags;
  2722. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2723. /* Unmask the interrupts that we always want on. */
  2724. dev_priv->irq_mask =
  2725. ~(I915_ASLE_INTERRUPT |
  2726. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2727. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2728. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2729. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2730. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2731. enable_mask =
  2732. I915_ASLE_INTERRUPT |
  2733. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2734. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2735. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2736. I915_USER_INTERRUPT;
  2737. if (I915_HAS_HOTPLUG(dev)) {
  2738. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2739. POSTING_READ(PORT_HOTPLUG_EN);
  2740. /* Enable in IER... */
  2741. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  2742. /* and unmask in IMR */
  2743. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  2744. }
  2745. I915_WRITE(IMR, dev_priv->irq_mask);
  2746. I915_WRITE(IER, enable_mask);
  2747. POSTING_READ(IER);
  2748. i915_enable_asle_pipestat(dev);
  2749. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2750. * just to make the assert_spin_locked check happy. */
  2751. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2752. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
  2753. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
  2754. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2755. return 0;
  2756. }
  2757. /*
  2758. * Returns true when a page flip has completed.
  2759. */
  2760. static bool i915_handle_vblank(struct drm_device *dev,
  2761. int plane, int pipe, u32 iir)
  2762. {
  2763. drm_i915_private_t *dev_priv = dev->dev_private;
  2764. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  2765. if (!drm_handle_vblank(dev, pipe))
  2766. return false;
  2767. if ((iir & flip_pending) == 0)
  2768. return false;
  2769. intel_prepare_page_flip(dev, plane);
  2770. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2771. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2772. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2773. * the flip is completed (no longer pending). Since this doesn't raise
  2774. * an interrupt per se, we watch for the change at vblank.
  2775. */
  2776. if (I915_READ(ISR) & flip_pending)
  2777. return false;
  2778. intel_finish_page_flip(dev, pipe);
  2779. return true;
  2780. }
  2781. static irqreturn_t i915_irq_handler(int irq, void *arg)
  2782. {
  2783. struct drm_device *dev = (struct drm_device *) arg;
  2784. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2785. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  2786. unsigned long irqflags;
  2787. u32 flip_mask =
  2788. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2789. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2790. int pipe, ret = IRQ_NONE;
  2791. atomic_inc(&dev_priv->irq_received);
  2792. iir = I915_READ(IIR);
  2793. do {
  2794. bool irq_received = (iir & ~flip_mask) != 0;
  2795. bool blc_event = false;
  2796. /* Can't rely on pipestat interrupt bit in iir as it might
  2797. * have been cleared after the pipestat interrupt was received.
  2798. * It doesn't set the bit in iir again, but it still produces
  2799. * interrupts (for non-MSI).
  2800. */
  2801. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2802. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2803. i915_handle_error(dev, false);
  2804. for_each_pipe(pipe) {
  2805. int reg = PIPESTAT(pipe);
  2806. pipe_stats[pipe] = I915_READ(reg);
  2807. /* Clear the PIPE*STAT regs before the IIR */
  2808. if (pipe_stats[pipe] & 0x8000ffff) {
  2809. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2810. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2811. pipe_name(pipe));
  2812. I915_WRITE(reg, pipe_stats[pipe]);
  2813. irq_received = true;
  2814. }
  2815. }
  2816. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2817. if (!irq_received)
  2818. break;
  2819. /* Consume port. Then clear IIR or we'll miss events */
  2820. if ((I915_HAS_HOTPLUG(dev)) &&
  2821. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  2822. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2823. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  2824. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2825. hotplug_status);
  2826. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  2827. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2828. POSTING_READ(PORT_HOTPLUG_STAT);
  2829. }
  2830. I915_WRITE(IIR, iir & ~flip_mask);
  2831. new_iir = I915_READ(IIR); /* Flush posted writes */
  2832. if (iir & I915_USER_INTERRUPT)
  2833. notify_ring(dev, &dev_priv->ring[RCS]);
  2834. for_each_pipe(pipe) {
  2835. int plane = pipe;
  2836. if (HAS_FBC(dev))
  2837. plane = !plane;
  2838. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2839. i915_handle_vblank(dev, plane, pipe, iir))
  2840. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  2841. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2842. blc_event = true;
  2843. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  2844. i9xx_pipe_crc_irq_handler(dev, pipe);
  2845. }
  2846. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2847. intel_opregion_asle_intr(dev);
  2848. /* With MSI, interrupts are only generated when iir
  2849. * transitions from zero to nonzero. If another bit got
  2850. * set while we were handling the existing iir bits, then
  2851. * we would never get another interrupt.
  2852. *
  2853. * This is fine on non-MSI as well, as if we hit this path
  2854. * we avoid exiting the interrupt handler only to generate
  2855. * another one.
  2856. *
  2857. * Note that for MSI this could cause a stray interrupt report
  2858. * if an interrupt landed in the time between writing IIR and
  2859. * the posting read. This should be rare enough to never
  2860. * trigger the 99% of 100,000 interrupts test for disabling
  2861. * stray interrupts.
  2862. */
  2863. ret = IRQ_HANDLED;
  2864. iir = new_iir;
  2865. } while (iir & ~flip_mask);
  2866. i915_update_dri1_breadcrumb(dev);
  2867. return ret;
  2868. }
  2869. static void i915_irq_uninstall(struct drm_device * dev)
  2870. {
  2871. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2872. int pipe;
  2873. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2874. if (I915_HAS_HOTPLUG(dev)) {
  2875. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2876. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2877. }
  2878. I915_WRITE16(HWSTAM, 0xffff);
  2879. for_each_pipe(pipe) {
  2880. /* Clear enable bits; then clear status bits */
  2881. I915_WRITE(PIPESTAT(pipe), 0);
  2882. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2883. }
  2884. I915_WRITE(IMR, 0xffffffff);
  2885. I915_WRITE(IER, 0x0);
  2886. I915_WRITE(IIR, I915_READ(IIR));
  2887. }
  2888. static void i965_irq_preinstall(struct drm_device * dev)
  2889. {
  2890. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2891. int pipe;
  2892. atomic_set(&dev_priv->irq_received, 0);
  2893. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2894. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2895. I915_WRITE(HWSTAM, 0xeffe);
  2896. for_each_pipe(pipe)
  2897. I915_WRITE(PIPESTAT(pipe), 0);
  2898. I915_WRITE(IMR, 0xffffffff);
  2899. I915_WRITE(IER, 0x0);
  2900. POSTING_READ(IER);
  2901. }
  2902. static int i965_irq_postinstall(struct drm_device *dev)
  2903. {
  2904. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2905. u32 enable_mask;
  2906. u32 error_mask;
  2907. unsigned long irqflags;
  2908. /* Unmask the interrupts that we always want on. */
  2909. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  2910. I915_DISPLAY_PORT_INTERRUPT |
  2911. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2912. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2913. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2914. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2915. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2916. enable_mask = ~dev_priv->irq_mask;
  2917. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2918. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  2919. enable_mask |= I915_USER_INTERRUPT;
  2920. if (IS_G4X(dev))
  2921. enable_mask |= I915_BSD_USER_INTERRUPT;
  2922. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2923. * just to make the assert_spin_locked check happy. */
  2924. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2925. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
  2926. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
  2927. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
  2928. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2929. /*
  2930. * Enable some error detection, note the instruction error mask
  2931. * bit is reserved, so we leave it masked.
  2932. */
  2933. if (IS_G4X(dev)) {
  2934. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  2935. GM45_ERROR_MEM_PRIV |
  2936. GM45_ERROR_CP_PRIV |
  2937. I915_ERROR_MEMORY_REFRESH);
  2938. } else {
  2939. error_mask = ~(I915_ERROR_PAGE_TABLE |
  2940. I915_ERROR_MEMORY_REFRESH);
  2941. }
  2942. I915_WRITE(EMR, error_mask);
  2943. I915_WRITE(IMR, dev_priv->irq_mask);
  2944. I915_WRITE(IER, enable_mask);
  2945. POSTING_READ(IER);
  2946. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2947. POSTING_READ(PORT_HOTPLUG_EN);
  2948. i915_enable_asle_pipestat(dev);
  2949. return 0;
  2950. }
  2951. static void i915_hpd_irq_setup(struct drm_device *dev)
  2952. {
  2953. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2954. struct drm_mode_config *mode_config = &dev->mode_config;
  2955. struct intel_encoder *intel_encoder;
  2956. u32 hotplug_en;
  2957. assert_spin_locked(&dev_priv->irq_lock);
  2958. if (I915_HAS_HOTPLUG(dev)) {
  2959. hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  2960. hotplug_en &= ~HOTPLUG_INT_EN_MASK;
  2961. /* Note HDMI and DP share hotplug bits */
  2962. /* enable bits are the same for all generations */
  2963. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2964. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2965. hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
  2966. /* Programming the CRT detection parameters tends
  2967. to generate a spurious hotplug event about three
  2968. seconds later. So just do it once.
  2969. */
  2970. if (IS_G4X(dev))
  2971. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  2972. hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
  2973. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  2974. /* Ignore TV since it's buggy */
  2975. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  2976. }
  2977. }
  2978. static irqreturn_t i965_irq_handler(int irq, void *arg)
  2979. {
  2980. struct drm_device *dev = (struct drm_device *) arg;
  2981. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2982. u32 iir, new_iir;
  2983. u32 pipe_stats[I915_MAX_PIPES];
  2984. unsigned long irqflags;
  2985. int irq_received;
  2986. int ret = IRQ_NONE, pipe;
  2987. u32 flip_mask =
  2988. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2989. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2990. atomic_inc(&dev_priv->irq_received);
  2991. iir = I915_READ(IIR);
  2992. for (;;) {
  2993. bool blc_event = false;
  2994. irq_received = (iir & ~flip_mask) != 0;
  2995. /* Can't rely on pipestat interrupt bit in iir as it might
  2996. * have been cleared after the pipestat interrupt was received.
  2997. * It doesn't set the bit in iir again, but it still produces
  2998. * interrupts (for non-MSI).
  2999. */
  3000. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3001. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3002. i915_handle_error(dev, false);
  3003. for_each_pipe(pipe) {
  3004. int reg = PIPESTAT(pipe);
  3005. pipe_stats[pipe] = I915_READ(reg);
  3006. /*
  3007. * Clear the PIPE*STAT regs before the IIR
  3008. */
  3009. if (pipe_stats[pipe] & 0x8000ffff) {
  3010. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3011. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  3012. pipe_name(pipe));
  3013. I915_WRITE(reg, pipe_stats[pipe]);
  3014. irq_received = 1;
  3015. }
  3016. }
  3017. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3018. if (!irq_received)
  3019. break;
  3020. ret = IRQ_HANDLED;
  3021. /* Consume port. Then clear IIR or we'll miss events */
  3022. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  3023. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  3024. u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
  3025. HOTPLUG_INT_STATUS_G4X :
  3026. HOTPLUG_INT_STATUS_I915);
  3027. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  3028. hotplug_status);
  3029. intel_hpd_irq_handler(dev, hotplug_trigger,
  3030. IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915);
  3031. if (IS_G4X(dev) &&
  3032. (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X))
  3033. dp_aux_irq_handler(dev);
  3034. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  3035. I915_READ(PORT_HOTPLUG_STAT);
  3036. }
  3037. I915_WRITE(IIR, iir & ~flip_mask);
  3038. new_iir = I915_READ(IIR); /* Flush posted writes */
  3039. if (iir & I915_USER_INTERRUPT)
  3040. notify_ring(dev, &dev_priv->ring[RCS]);
  3041. if (iir & I915_BSD_USER_INTERRUPT)
  3042. notify_ring(dev, &dev_priv->ring[VCS]);
  3043. for_each_pipe(pipe) {
  3044. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  3045. i915_handle_vblank(dev, pipe, pipe, iir))
  3046. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  3047. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3048. blc_event = true;
  3049. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3050. i9xx_pipe_crc_irq_handler(dev, pipe);
  3051. }
  3052. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3053. intel_opregion_asle_intr(dev);
  3054. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  3055. gmbus_irq_handler(dev);
  3056. /* With MSI, interrupts are only generated when iir
  3057. * transitions from zero to nonzero. If another bit got
  3058. * set while we were handling the existing iir bits, then
  3059. * we would never get another interrupt.
  3060. *
  3061. * This is fine on non-MSI as well, as if we hit this path
  3062. * we avoid exiting the interrupt handler only to generate
  3063. * another one.
  3064. *
  3065. * Note that for MSI this could cause a stray interrupt report
  3066. * if an interrupt landed in the time between writing IIR and
  3067. * the posting read. This should be rare enough to never
  3068. * trigger the 99% of 100,000 interrupts test for disabling
  3069. * stray interrupts.
  3070. */
  3071. iir = new_iir;
  3072. }
  3073. i915_update_dri1_breadcrumb(dev);
  3074. return ret;
  3075. }
  3076. static void i965_irq_uninstall(struct drm_device * dev)
  3077. {
  3078. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  3079. int pipe;
  3080. if (!dev_priv)
  3081. return;
  3082. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  3083. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3084. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3085. I915_WRITE(HWSTAM, 0xffffffff);
  3086. for_each_pipe(pipe)
  3087. I915_WRITE(PIPESTAT(pipe), 0);
  3088. I915_WRITE(IMR, 0xffffffff);
  3089. I915_WRITE(IER, 0x0);
  3090. for_each_pipe(pipe)
  3091. I915_WRITE(PIPESTAT(pipe),
  3092. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  3093. I915_WRITE(IIR, I915_READ(IIR));
  3094. }
  3095. static void i915_reenable_hotplug_timer_func(unsigned long data)
  3096. {
  3097. drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
  3098. struct drm_device *dev = dev_priv->dev;
  3099. struct drm_mode_config *mode_config = &dev->mode_config;
  3100. unsigned long irqflags;
  3101. int i;
  3102. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3103. for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
  3104. struct drm_connector *connector;
  3105. if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
  3106. continue;
  3107. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  3108. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3109. struct intel_connector *intel_connector = to_intel_connector(connector);
  3110. if (intel_connector->encoder->hpd_pin == i) {
  3111. if (connector->polled != intel_connector->polled)
  3112. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  3113. drm_get_connector_name(connector));
  3114. connector->polled = intel_connector->polled;
  3115. if (!connector->polled)
  3116. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3117. }
  3118. }
  3119. }
  3120. if (dev_priv->display.hpd_irq_setup)
  3121. dev_priv->display.hpd_irq_setup(dev);
  3122. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3123. }
  3124. void intel_irq_init(struct drm_device *dev)
  3125. {
  3126. struct drm_i915_private *dev_priv = dev->dev_private;
  3127. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  3128. INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
  3129. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  3130. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  3131. setup_timer(&dev_priv->gpu_error.hangcheck_timer,
  3132. i915_hangcheck_elapsed,
  3133. (unsigned long) dev);
  3134. setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
  3135. (unsigned long) dev_priv);
  3136. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  3137. if (IS_GEN2(dev)) {
  3138. dev->max_vblank_count = 0;
  3139. dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
  3140. } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  3141. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  3142. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  3143. } else {
  3144. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  3145. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  3146. }
  3147. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  3148. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  3149. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  3150. }
  3151. if (IS_VALLEYVIEW(dev)) {
  3152. dev->driver->irq_handler = valleyview_irq_handler;
  3153. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  3154. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  3155. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  3156. dev->driver->enable_vblank = valleyview_enable_vblank;
  3157. dev->driver->disable_vblank = valleyview_disable_vblank;
  3158. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3159. } else if (IS_GEN8(dev)) {
  3160. dev->driver->irq_handler = gen8_irq_handler;
  3161. dev->driver->irq_preinstall = gen8_irq_preinstall;
  3162. dev->driver->irq_postinstall = gen8_irq_postinstall;
  3163. dev->driver->irq_uninstall = gen8_irq_uninstall;
  3164. dev->driver->enable_vblank = gen8_enable_vblank;
  3165. dev->driver->disable_vblank = gen8_disable_vblank;
  3166. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3167. } else if (HAS_PCH_SPLIT(dev)) {
  3168. dev->driver->irq_handler = ironlake_irq_handler;
  3169. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  3170. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  3171. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  3172. dev->driver->enable_vblank = ironlake_enable_vblank;
  3173. dev->driver->disable_vblank = ironlake_disable_vblank;
  3174. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3175. } else {
  3176. if (INTEL_INFO(dev)->gen == 2) {
  3177. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  3178. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  3179. dev->driver->irq_handler = i8xx_irq_handler;
  3180. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  3181. } else if (INTEL_INFO(dev)->gen == 3) {
  3182. dev->driver->irq_preinstall = i915_irq_preinstall;
  3183. dev->driver->irq_postinstall = i915_irq_postinstall;
  3184. dev->driver->irq_uninstall = i915_irq_uninstall;
  3185. dev->driver->irq_handler = i915_irq_handler;
  3186. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3187. } else {
  3188. dev->driver->irq_preinstall = i965_irq_preinstall;
  3189. dev->driver->irq_postinstall = i965_irq_postinstall;
  3190. dev->driver->irq_uninstall = i965_irq_uninstall;
  3191. dev->driver->irq_handler = i965_irq_handler;
  3192. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3193. }
  3194. dev->driver->enable_vblank = i915_enable_vblank;
  3195. dev->driver->disable_vblank = i915_disable_vblank;
  3196. }
  3197. }
  3198. void intel_hpd_init(struct drm_device *dev)
  3199. {
  3200. struct drm_i915_private *dev_priv = dev->dev_private;
  3201. struct drm_mode_config *mode_config = &dev->mode_config;
  3202. struct drm_connector *connector;
  3203. unsigned long irqflags;
  3204. int i;
  3205. for (i = 1; i < HPD_NUM_PINS; i++) {
  3206. dev_priv->hpd_stats[i].hpd_cnt = 0;
  3207. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  3208. }
  3209. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3210. struct intel_connector *intel_connector = to_intel_connector(connector);
  3211. connector->polled = intel_connector->polled;
  3212. if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
  3213. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3214. }
  3215. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3216. * just to make the assert_spin_locked checks happy. */
  3217. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3218. if (dev_priv->display.hpd_irq_setup)
  3219. dev_priv->display.hpd_irq_setup(dev);
  3220. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3221. }
  3222. /* Disable interrupts so we can allow Package C8+. */
  3223. void hsw_pc8_disable_interrupts(struct drm_device *dev)
  3224. {
  3225. struct drm_i915_private *dev_priv = dev->dev_private;
  3226. unsigned long irqflags;
  3227. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3228. dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
  3229. dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
  3230. dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
  3231. dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
  3232. dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
  3233. ironlake_disable_display_irq(dev_priv, 0xffffffff);
  3234. ibx_disable_display_interrupt(dev_priv, 0xffffffff);
  3235. ilk_disable_gt_irq(dev_priv, 0xffffffff);
  3236. snb_disable_pm_irq(dev_priv, 0xffffffff);
  3237. dev_priv->pc8.irqs_disabled = true;
  3238. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3239. }
  3240. /* Restore interrupts so we can recover from Package C8+. */
  3241. void hsw_pc8_restore_interrupts(struct drm_device *dev)
  3242. {
  3243. struct drm_i915_private *dev_priv = dev->dev_private;
  3244. unsigned long irqflags;
  3245. uint32_t val;
  3246. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  3247. val = I915_READ(DEIMR);
  3248. WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
  3249. val = I915_READ(SDEIMR);
  3250. WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
  3251. val = I915_READ(GTIMR);
  3252. WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
  3253. val = I915_READ(GEN6_PMIMR);
  3254. WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
  3255. dev_priv->pc8.irqs_disabled = false;
  3256. ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
  3257. ibx_enable_display_interrupt(dev_priv, ~dev_priv->pc8.regsave.sdeimr);
  3258. ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
  3259. snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
  3260. I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
  3261. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  3262. }