i915_irq.c 97 KB

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