i915_irq.c 112 KB

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