i915_irq.c 113 KB

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