i915_irq.c 110 KB

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