i915_irq.c 98 KB

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