i915_irq.c 94 KB

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