i915_irq.c 103 KB

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