i915_irq.c 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216
  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. queue_work(dev_priv->wq,
  854. &dev_priv->hotplug_work);
  855. }
  856. static void gmbus_irq_handler(struct drm_device *dev)
  857. {
  858. struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
  859. wake_up_all(&dev_priv->gmbus_wait_queue);
  860. }
  861. static void dp_aux_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. /* The RPS events need forcewake, so we add them to a work queue and mask their
  867. * IMR bits until the work is done. Other interrupts can be processed without
  868. * the work queue. */
  869. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
  870. {
  871. if (pm_iir & GEN6_PM_RPS_EVENTS) {
  872. spin_lock(&dev_priv->irq_lock);
  873. dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
  874. snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
  875. spin_unlock(&dev_priv->irq_lock);
  876. queue_work(dev_priv->wq, &dev_priv->rps.work);
  877. }
  878. if (HAS_VEBOX(dev_priv->dev)) {
  879. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  880. notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
  881. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
  882. DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
  883. i915_handle_error(dev_priv->dev, false);
  884. }
  885. }
  886. }
  887. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  888. {
  889. struct drm_device *dev = (struct drm_device *) arg;
  890. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  891. u32 iir, gt_iir, pm_iir;
  892. irqreturn_t ret = IRQ_NONE;
  893. unsigned long irqflags;
  894. int pipe;
  895. u32 pipe_stats[I915_MAX_PIPES];
  896. atomic_inc(&dev_priv->irq_received);
  897. while (true) {
  898. iir = I915_READ(VLV_IIR);
  899. gt_iir = I915_READ(GTIIR);
  900. pm_iir = I915_READ(GEN6_PMIIR);
  901. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  902. goto out;
  903. ret = IRQ_HANDLED;
  904. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  905. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  906. for_each_pipe(pipe) {
  907. int reg = PIPESTAT(pipe);
  908. pipe_stats[pipe] = I915_READ(reg);
  909. /*
  910. * Clear the PIPE*STAT regs before the IIR
  911. */
  912. if (pipe_stats[pipe] & 0x8000ffff) {
  913. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  914. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  915. pipe_name(pipe));
  916. I915_WRITE(reg, pipe_stats[pipe]);
  917. }
  918. }
  919. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  920. for_each_pipe(pipe) {
  921. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
  922. drm_handle_vblank(dev, pipe);
  923. if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
  924. intel_prepare_page_flip(dev, pipe);
  925. intel_finish_page_flip(dev, pipe);
  926. }
  927. }
  928. /* Consume port. Then clear IIR or we'll miss events */
  929. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  930. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  931. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  932. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  933. hotplug_status);
  934. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  935. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  936. I915_READ(PORT_HOTPLUG_STAT);
  937. }
  938. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  939. gmbus_irq_handler(dev);
  940. if (pm_iir)
  941. gen6_rps_irq_handler(dev_priv, pm_iir);
  942. I915_WRITE(GTIIR, gt_iir);
  943. I915_WRITE(GEN6_PMIIR, pm_iir);
  944. I915_WRITE(VLV_IIR, iir);
  945. }
  946. out:
  947. return ret;
  948. }
  949. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  950. {
  951. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  952. int pipe;
  953. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  954. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
  955. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  956. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  957. SDE_AUDIO_POWER_SHIFT);
  958. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  959. port_name(port));
  960. }
  961. if (pch_iir & SDE_AUX_MASK)
  962. dp_aux_irq_handler(dev);
  963. if (pch_iir & SDE_GMBUS)
  964. gmbus_irq_handler(dev);
  965. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  966. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  967. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  968. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  969. if (pch_iir & SDE_POISON)
  970. DRM_ERROR("PCH poison interrupt\n");
  971. if (pch_iir & SDE_FDI_MASK)
  972. for_each_pipe(pipe)
  973. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  974. pipe_name(pipe),
  975. I915_READ(FDI_RX_IIR(pipe)));
  976. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  977. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  978. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  979. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  980. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  981. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  982. false))
  983. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  984. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  985. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  986. false))
  987. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  988. }
  989. static void ivb_err_int_handler(struct drm_device *dev)
  990. {
  991. struct drm_i915_private *dev_priv = dev->dev_private;
  992. u32 err_int = I915_READ(GEN7_ERR_INT);
  993. if (err_int & ERR_INT_POISON)
  994. DRM_ERROR("Poison interrupt\n");
  995. if (err_int & ERR_INT_FIFO_UNDERRUN_A)
  996. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
  997. DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
  998. if (err_int & ERR_INT_FIFO_UNDERRUN_B)
  999. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
  1000. DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
  1001. if (err_int & ERR_INT_FIFO_UNDERRUN_C)
  1002. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false))
  1003. DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n");
  1004. I915_WRITE(GEN7_ERR_INT, err_int);
  1005. }
  1006. static void cpt_serr_int_handler(struct drm_device *dev)
  1007. {
  1008. struct drm_i915_private *dev_priv = dev->dev_private;
  1009. u32 serr_int = I915_READ(SERR_INT);
  1010. if (serr_int & SERR_INT_POISON)
  1011. DRM_ERROR("PCH poison interrupt\n");
  1012. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  1013. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  1014. false))
  1015. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  1016. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  1017. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  1018. false))
  1019. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  1020. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  1021. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
  1022. false))
  1023. DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
  1024. I915_WRITE(SERR_INT, serr_int);
  1025. }
  1026. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  1027. {
  1028. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1029. int pipe;
  1030. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  1031. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
  1032. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  1033. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  1034. SDE_AUDIO_POWER_SHIFT_CPT);
  1035. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  1036. port_name(port));
  1037. }
  1038. if (pch_iir & SDE_AUX_MASK_CPT)
  1039. dp_aux_irq_handler(dev);
  1040. if (pch_iir & SDE_GMBUS_CPT)
  1041. gmbus_irq_handler(dev);
  1042. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  1043. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  1044. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  1045. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  1046. if (pch_iir & SDE_FDI_MASK_CPT)
  1047. for_each_pipe(pipe)
  1048. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1049. pipe_name(pipe),
  1050. I915_READ(FDI_RX_IIR(pipe)));
  1051. if (pch_iir & SDE_ERROR_CPT)
  1052. cpt_serr_int_handler(dev);
  1053. }
  1054. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1055. {
  1056. struct drm_i915_private *dev_priv = dev->dev_private;
  1057. if (de_iir & DE_AUX_CHANNEL_A)
  1058. dp_aux_irq_handler(dev);
  1059. if (de_iir & DE_GSE)
  1060. intel_opregion_asle_intr(dev);
  1061. if (de_iir & DE_PIPEA_VBLANK)
  1062. drm_handle_vblank(dev, 0);
  1063. if (de_iir & DE_PIPEB_VBLANK)
  1064. drm_handle_vblank(dev, 1);
  1065. if (de_iir & DE_POISON)
  1066. DRM_ERROR("Poison interrupt\n");
  1067. if (de_iir & DE_PIPEA_FIFO_UNDERRUN)
  1068. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
  1069. DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
  1070. if (de_iir & DE_PIPEB_FIFO_UNDERRUN)
  1071. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
  1072. DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
  1073. if (de_iir & DE_PLANEA_FLIP_DONE) {
  1074. intel_prepare_page_flip(dev, 0);
  1075. intel_finish_page_flip_plane(dev, 0);
  1076. }
  1077. if (de_iir & DE_PLANEB_FLIP_DONE) {
  1078. intel_prepare_page_flip(dev, 1);
  1079. intel_finish_page_flip_plane(dev, 1);
  1080. }
  1081. /* check event from PCH */
  1082. if (de_iir & DE_PCH_EVENT) {
  1083. u32 pch_iir = I915_READ(SDEIIR);
  1084. if (HAS_PCH_CPT(dev))
  1085. cpt_irq_handler(dev, pch_iir);
  1086. else
  1087. ibx_irq_handler(dev, pch_iir);
  1088. /* should clear PCH hotplug event before clear CPU irq */
  1089. I915_WRITE(SDEIIR, pch_iir);
  1090. }
  1091. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1092. ironlake_rps_change_irq_handler(dev);
  1093. }
  1094. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1095. {
  1096. struct drm_i915_private *dev_priv = dev->dev_private;
  1097. int i;
  1098. if (de_iir & DE_ERR_INT_IVB)
  1099. ivb_err_int_handler(dev);
  1100. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1101. dp_aux_irq_handler(dev);
  1102. if (de_iir & DE_GSE_IVB)
  1103. intel_opregion_asle_intr(dev);
  1104. for (i = 0; i < 3; i++) {
  1105. if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
  1106. drm_handle_vblank(dev, i);
  1107. if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
  1108. intel_prepare_page_flip(dev, i);
  1109. intel_finish_page_flip_plane(dev, i);
  1110. }
  1111. }
  1112. /* check event from PCH */
  1113. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1114. u32 pch_iir = I915_READ(SDEIIR);
  1115. cpt_irq_handler(dev, pch_iir);
  1116. /* clear PCH hotplug event before clear CPU irq */
  1117. I915_WRITE(SDEIIR, pch_iir);
  1118. }
  1119. }
  1120. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1121. {
  1122. struct drm_device *dev = (struct drm_device *) arg;
  1123. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1124. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1125. irqreturn_t ret = IRQ_NONE;
  1126. bool err_int_reenable = false;
  1127. atomic_inc(&dev_priv->irq_received);
  1128. /* We get interrupts on unclaimed registers, so check for this before we
  1129. * do any I915_{READ,WRITE}. */
  1130. intel_uncore_check_errors(dev);
  1131. /* disable master interrupt before clearing iir */
  1132. de_ier = I915_READ(DEIER);
  1133. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1134. POSTING_READ(DEIER);
  1135. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1136. * interrupts will will be stored on its back queue, and then we'll be
  1137. * able to process them after we restore SDEIER (as soon as we restore
  1138. * it, we'll get an interrupt if SDEIIR still has something to process
  1139. * due to its back queue). */
  1140. if (!HAS_PCH_NOP(dev)) {
  1141. sde_ier = I915_READ(SDEIER);
  1142. I915_WRITE(SDEIER, 0);
  1143. POSTING_READ(SDEIER);
  1144. }
  1145. /* On Haswell, also mask ERR_INT because we don't want to risk
  1146. * generating "unclaimed register" interrupts from inside the interrupt
  1147. * handler. */
  1148. if (IS_HASWELL(dev)) {
  1149. spin_lock(&dev_priv->irq_lock);
  1150. err_int_reenable = ~dev_priv->irq_mask & DE_ERR_INT_IVB;
  1151. if (err_int_reenable)
  1152. ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
  1153. spin_unlock(&dev_priv->irq_lock);
  1154. }
  1155. gt_iir = I915_READ(GTIIR);
  1156. if (gt_iir) {
  1157. if (INTEL_INFO(dev)->gen >= 6)
  1158. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1159. else
  1160. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1161. I915_WRITE(GTIIR, gt_iir);
  1162. ret = IRQ_HANDLED;
  1163. }
  1164. de_iir = I915_READ(DEIIR);
  1165. if (de_iir) {
  1166. if (INTEL_INFO(dev)->gen >= 7)
  1167. ivb_display_irq_handler(dev, de_iir);
  1168. else
  1169. ilk_display_irq_handler(dev, de_iir);
  1170. I915_WRITE(DEIIR, de_iir);
  1171. ret = IRQ_HANDLED;
  1172. }
  1173. if (INTEL_INFO(dev)->gen >= 6) {
  1174. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1175. if (pm_iir) {
  1176. gen6_rps_irq_handler(dev_priv, pm_iir);
  1177. I915_WRITE(GEN6_PMIIR, pm_iir);
  1178. ret = IRQ_HANDLED;
  1179. }
  1180. }
  1181. if (err_int_reenable) {
  1182. spin_lock(&dev_priv->irq_lock);
  1183. if (ivb_can_enable_err_int(dev))
  1184. ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
  1185. spin_unlock(&dev_priv->irq_lock);
  1186. }
  1187. I915_WRITE(DEIER, de_ier);
  1188. POSTING_READ(DEIER);
  1189. if (!HAS_PCH_NOP(dev)) {
  1190. I915_WRITE(SDEIER, sde_ier);
  1191. POSTING_READ(SDEIER);
  1192. }
  1193. return ret;
  1194. }
  1195. /**
  1196. * i915_error_work_func - do process context error handling work
  1197. * @work: work struct
  1198. *
  1199. * Fire an error uevent so userspace can see that a hang or error
  1200. * was detected.
  1201. */
  1202. static void i915_error_work_func(struct work_struct *work)
  1203. {
  1204. struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
  1205. work);
  1206. drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
  1207. gpu_error);
  1208. struct drm_device *dev = dev_priv->dev;
  1209. struct intel_ring_buffer *ring;
  1210. char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
  1211. char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
  1212. char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
  1213. int i, ret;
  1214. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  1215. /*
  1216. * Note that there's only one work item which does gpu resets, so we
  1217. * need not worry about concurrent gpu resets potentially incrementing
  1218. * error->reset_counter twice. We only need to take care of another
  1219. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1220. * quick check for that is good enough: schedule_work ensures the
  1221. * correct ordering between hang detection and this work item, and since
  1222. * the reset in-progress bit is only ever set by code outside of this
  1223. * work we don't need to worry about any other races.
  1224. */
  1225. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1226. DRM_DEBUG_DRIVER("resetting chip\n");
  1227. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
  1228. reset_event);
  1229. ret = i915_reset(dev);
  1230. if (ret == 0) {
  1231. /*
  1232. * After all the gem state is reset, increment the reset
  1233. * counter and wake up everyone waiting for the reset to
  1234. * complete.
  1235. *
  1236. * Since unlock operations are a one-sided barrier only,
  1237. * we need to insert a barrier here to order any seqno
  1238. * updates before
  1239. * the counter increment.
  1240. */
  1241. smp_mb__before_atomic_inc();
  1242. atomic_inc(&dev_priv->gpu_error.reset_counter);
  1243. kobject_uevent_env(&dev->primary->kdev.kobj,
  1244. KOBJ_CHANGE, reset_done_event);
  1245. } else {
  1246. atomic_set(&error->reset_counter, I915_WEDGED);
  1247. }
  1248. for_each_ring(ring, dev_priv, i)
  1249. wake_up_all(&ring->irq_queue);
  1250. intel_display_handle_reset(dev);
  1251. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1252. }
  1253. }
  1254. static void i915_report_and_clear_eir(struct drm_device *dev)
  1255. {
  1256. struct drm_i915_private *dev_priv = dev->dev_private;
  1257. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1258. u32 eir = I915_READ(EIR);
  1259. int pipe, i;
  1260. if (!eir)
  1261. return;
  1262. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1263. i915_get_extra_instdone(dev, instdone);
  1264. if (IS_G4X(dev)) {
  1265. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1266. u32 ipeir = I915_READ(IPEIR_I965);
  1267. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1268. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1269. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1270. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1271. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1272. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1273. I915_WRITE(IPEIR_I965, ipeir);
  1274. POSTING_READ(IPEIR_I965);
  1275. }
  1276. if (eir & GM45_ERROR_PAGE_TABLE) {
  1277. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1278. pr_err("page table error\n");
  1279. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1280. I915_WRITE(PGTBL_ER, pgtbl_err);
  1281. POSTING_READ(PGTBL_ER);
  1282. }
  1283. }
  1284. if (!IS_GEN2(dev)) {
  1285. if (eir & I915_ERROR_PAGE_TABLE) {
  1286. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1287. pr_err("page table error\n");
  1288. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1289. I915_WRITE(PGTBL_ER, pgtbl_err);
  1290. POSTING_READ(PGTBL_ER);
  1291. }
  1292. }
  1293. if (eir & I915_ERROR_MEMORY_REFRESH) {
  1294. pr_err("memory refresh error:\n");
  1295. for_each_pipe(pipe)
  1296. pr_err("pipe %c stat: 0x%08x\n",
  1297. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  1298. /* pipestat has already been acked */
  1299. }
  1300. if (eir & I915_ERROR_INSTRUCTION) {
  1301. pr_err("instruction error\n");
  1302. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  1303. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1304. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1305. if (INTEL_INFO(dev)->gen < 4) {
  1306. u32 ipeir = I915_READ(IPEIR);
  1307. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  1308. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  1309. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  1310. I915_WRITE(IPEIR, ipeir);
  1311. POSTING_READ(IPEIR);
  1312. } else {
  1313. u32 ipeir = I915_READ(IPEIR_I965);
  1314. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1315. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1316. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1317. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1318. I915_WRITE(IPEIR_I965, ipeir);
  1319. POSTING_READ(IPEIR_I965);
  1320. }
  1321. }
  1322. I915_WRITE(EIR, eir);
  1323. POSTING_READ(EIR);
  1324. eir = I915_READ(EIR);
  1325. if (eir) {
  1326. /*
  1327. * some errors might have become stuck,
  1328. * mask them.
  1329. */
  1330. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1331. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1332. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1333. }
  1334. }
  1335. /**
  1336. * i915_handle_error - handle an error interrupt
  1337. * @dev: drm device
  1338. *
  1339. * Do some basic checking of regsiter state at error interrupt time and
  1340. * dump it to the syslog. Also call i915_capture_error_state() to make
  1341. * sure we get a record and make it available in debugfs. Fire a uevent
  1342. * so userspace knows something bad happened (should trigger collection
  1343. * of a ring dump etc.).
  1344. */
  1345. void i915_handle_error(struct drm_device *dev, bool wedged)
  1346. {
  1347. struct drm_i915_private *dev_priv = dev->dev_private;
  1348. struct intel_ring_buffer *ring;
  1349. int i;
  1350. i915_capture_error_state(dev);
  1351. i915_report_and_clear_eir(dev);
  1352. if (wedged) {
  1353. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  1354. &dev_priv->gpu_error.reset_counter);
  1355. /*
  1356. * Wakeup waiting processes so that the reset work item
  1357. * doesn't deadlock trying to grab various locks.
  1358. */
  1359. for_each_ring(ring, dev_priv, i)
  1360. wake_up_all(&ring->irq_queue);
  1361. }
  1362. queue_work(dev_priv->wq, &dev_priv->gpu_error.work);
  1363. }
  1364. static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1365. {
  1366. drm_i915_private_t *dev_priv = dev->dev_private;
  1367. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1368. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1369. struct drm_i915_gem_object *obj;
  1370. struct intel_unpin_work *work;
  1371. unsigned long flags;
  1372. bool stall_detected;
  1373. /* Ignore early vblank irqs */
  1374. if (intel_crtc == NULL)
  1375. return;
  1376. spin_lock_irqsave(&dev->event_lock, flags);
  1377. work = intel_crtc->unpin_work;
  1378. if (work == NULL ||
  1379. atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
  1380. !work->enable_stall_check) {
  1381. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1382. spin_unlock_irqrestore(&dev->event_lock, flags);
  1383. return;
  1384. }
  1385. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1386. obj = work->pending_flip_obj;
  1387. if (INTEL_INFO(dev)->gen >= 4) {
  1388. int dspsurf = DSPSURF(intel_crtc->plane);
  1389. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  1390. i915_gem_obj_ggtt_offset(obj);
  1391. } else {
  1392. int dspaddr = DSPADDR(intel_crtc->plane);
  1393. stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
  1394. crtc->y * crtc->fb->pitches[0] +
  1395. crtc->x * crtc->fb->bits_per_pixel/8);
  1396. }
  1397. spin_unlock_irqrestore(&dev->event_lock, flags);
  1398. if (stall_detected) {
  1399. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1400. intel_prepare_page_flip(dev, intel_crtc->plane);
  1401. }
  1402. }
  1403. /* Called from drm generic code, passed 'crtc' which
  1404. * we use as a pipe index
  1405. */
  1406. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1407. {
  1408. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1409. unsigned long irqflags;
  1410. if (!i915_pipe_enabled(dev, pipe))
  1411. return -EINVAL;
  1412. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1413. if (INTEL_INFO(dev)->gen >= 4)
  1414. i915_enable_pipestat(dev_priv, pipe,
  1415. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1416. else
  1417. i915_enable_pipestat(dev_priv, pipe,
  1418. PIPE_VBLANK_INTERRUPT_ENABLE);
  1419. /* maintain vblank delivery even in deep C-states */
  1420. if (dev_priv->info->gen == 3)
  1421. I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
  1422. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1423. return 0;
  1424. }
  1425. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1426. {
  1427. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1428. unsigned long irqflags;
  1429. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  1430. DE_PIPE_VBLANK_ILK(pipe);
  1431. if (!i915_pipe_enabled(dev, pipe))
  1432. return -EINVAL;
  1433. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1434. ironlake_enable_display_irq(dev_priv, bit);
  1435. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1436. return 0;
  1437. }
  1438. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  1439. {
  1440. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1441. unsigned long irqflags;
  1442. u32 imr;
  1443. if (!i915_pipe_enabled(dev, pipe))
  1444. return -EINVAL;
  1445. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1446. imr = I915_READ(VLV_IMR);
  1447. if (pipe == 0)
  1448. imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1449. else
  1450. imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1451. I915_WRITE(VLV_IMR, imr);
  1452. i915_enable_pipestat(dev_priv, pipe,
  1453. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1454. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1455. return 0;
  1456. }
  1457. /* Called from drm generic code, passed 'crtc' which
  1458. * we use as a pipe index
  1459. */
  1460. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  1461. {
  1462. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1463. unsigned long irqflags;
  1464. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1465. if (dev_priv->info->gen == 3)
  1466. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
  1467. i915_disable_pipestat(dev_priv, pipe,
  1468. PIPE_VBLANK_INTERRUPT_ENABLE |
  1469. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1470. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1471. }
  1472. static void ironlake_disable_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. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1479. ironlake_disable_display_irq(dev_priv, bit);
  1480. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1481. }
  1482. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  1483. {
  1484. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1485. unsigned long irqflags;
  1486. u32 imr;
  1487. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1488. i915_disable_pipestat(dev_priv, pipe,
  1489. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1490. imr = I915_READ(VLV_IMR);
  1491. if (pipe == 0)
  1492. imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1493. else
  1494. imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1495. I915_WRITE(VLV_IMR, imr);
  1496. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1497. }
  1498. static u32
  1499. ring_last_seqno(struct intel_ring_buffer *ring)
  1500. {
  1501. return list_entry(ring->request_list.prev,
  1502. struct drm_i915_gem_request, list)->seqno;
  1503. }
  1504. static bool
  1505. ring_idle(struct intel_ring_buffer *ring, u32 seqno)
  1506. {
  1507. return (list_empty(&ring->request_list) ||
  1508. i915_seqno_passed(seqno, ring_last_seqno(ring)));
  1509. }
  1510. static struct intel_ring_buffer *
  1511. semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
  1512. {
  1513. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1514. u32 cmd, ipehr, acthd, acthd_min;
  1515. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  1516. if ((ipehr & ~(0x3 << 16)) !=
  1517. (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
  1518. return NULL;
  1519. /* ACTHD is likely pointing to the dword after the actual command,
  1520. * so scan backwards until we find the MBOX.
  1521. */
  1522. acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
  1523. acthd_min = max((int)acthd - 3 * 4, 0);
  1524. do {
  1525. cmd = ioread32(ring->virtual_start + acthd);
  1526. if (cmd == ipehr)
  1527. break;
  1528. acthd -= 4;
  1529. if (acthd < acthd_min)
  1530. return NULL;
  1531. } while (1);
  1532. *seqno = ioread32(ring->virtual_start+acthd+4)+1;
  1533. return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
  1534. }
  1535. static int semaphore_passed(struct intel_ring_buffer *ring)
  1536. {
  1537. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1538. struct intel_ring_buffer *signaller;
  1539. u32 seqno, ctl;
  1540. ring->hangcheck.deadlock = true;
  1541. signaller = semaphore_waits_for(ring, &seqno);
  1542. if (signaller == NULL || signaller->hangcheck.deadlock)
  1543. return -1;
  1544. /* cursory check for an unkickable deadlock */
  1545. ctl = I915_READ_CTL(signaller);
  1546. if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
  1547. return -1;
  1548. return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
  1549. }
  1550. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  1551. {
  1552. struct intel_ring_buffer *ring;
  1553. int i;
  1554. for_each_ring(ring, dev_priv, i)
  1555. ring->hangcheck.deadlock = false;
  1556. }
  1557. static enum intel_ring_hangcheck_action
  1558. ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
  1559. {
  1560. struct drm_device *dev = ring->dev;
  1561. struct drm_i915_private *dev_priv = dev->dev_private;
  1562. u32 tmp;
  1563. if (ring->hangcheck.acthd != acthd)
  1564. return HANGCHECK_ACTIVE;
  1565. if (IS_GEN2(dev))
  1566. return HANGCHECK_HUNG;
  1567. /* Is the chip hanging on a WAIT_FOR_EVENT?
  1568. * If so we can simply poke the RB_WAIT bit
  1569. * and break the hang. This should work on
  1570. * all but the second generation chipsets.
  1571. */
  1572. tmp = I915_READ_CTL(ring);
  1573. if (tmp & RING_WAIT) {
  1574. DRM_ERROR("Kicking stuck wait on %s\n",
  1575. ring->name);
  1576. I915_WRITE_CTL(ring, tmp);
  1577. return HANGCHECK_KICK;
  1578. }
  1579. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  1580. switch (semaphore_passed(ring)) {
  1581. default:
  1582. return HANGCHECK_HUNG;
  1583. case 1:
  1584. DRM_ERROR("Kicking stuck semaphore on %s\n",
  1585. ring->name);
  1586. I915_WRITE_CTL(ring, tmp);
  1587. return HANGCHECK_KICK;
  1588. case 0:
  1589. return HANGCHECK_WAIT;
  1590. }
  1591. }
  1592. return HANGCHECK_HUNG;
  1593. }
  1594. /**
  1595. * This is called when the chip hasn't reported back with completed
  1596. * batchbuffers in a long time. We keep track per ring seqno progress and
  1597. * if there are no progress, hangcheck score for that ring is increased.
  1598. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  1599. * we kick the ring. If we see no progress on three subsequent calls
  1600. * we assume chip is wedged and try to fix it by resetting the chip.
  1601. */
  1602. static void i915_hangcheck_elapsed(unsigned long data)
  1603. {
  1604. struct drm_device *dev = (struct drm_device *)data;
  1605. drm_i915_private_t *dev_priv = dev->dev_private;
  1606. struct intel_ring_buffer *ring;
  1607. int i;
  1608. int busy_count = 0, rings_hung = 0;
  1609. bool stuck[I915_NUM_RINGS] = { 0 };
  1610. #define BUSY 1
  1611. #define KICK 5
  1612. #define HUNG 20
  1613. #define FIRE 30
  1614. if (!i915_enable_hangcheck)
  1615. return;
  1616. for_each_ring(ring, dev_priv, i) {
  1617. u32 seqno, acthd;
  1618. bool busy = true;
  1619. semaphore_clear_deadlocks(dev_priv);
  1620. seqno = ring->get_seqno(ring, false);
  1621. acthd = intel_ring_get_active_head(ring);
  1622. if (ring->hangcheck.seqno == seqno) {
  1623. if (ring_idle(ring, seqno)) {
  1624. if (waitqueue_active(&ring->irq_queue)) {
  1625. /* Issue a wake-up to catch stuck h/w. */
  1626. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  1627. ring->name);
  1628. wake_up_all(&ring->irq_queue);
  1629. ring->hangcheck.score += HUNG;
  1630. } else
  1631. busy = false;
  1632. } else {
  1633. /* We always increment the hangcheck score
  1634. * if the ring is busy and still processing
  1635. * the same request, so that no single request
  1636. * can run indefinitely (such as a chain of
  1637. * batches). The only time we do not increment
  1638. * the hangcheck score on this ring, if this
  1639. * ring is in a legitimate wait for another
  1640. * ring. In that case the waiting ring is a
  1641. * victim and we want to be sure we catch the
  1642. * right culprit. Then every time we do kick
  1643. * the ring, add a small increment to the
  1644. * score so that we can catch a batch that is
  1645. * being repeatedly kicked and so responsible
  1646. * for stalling the machine.
  1647. */
  1648. ring->hangcheck.action = ring_stuck(ring,
  1649. acthd);
  1650. switch (ring->hangcheck.action) {
  1651. case HANGCHECK_WAIT:
  1652. break;
  1653. case HANGCHECK_ACTIVE:
  1654. ring->hangcheck.score += BUSY;
  1655. break;
  1656. case HANGCHECK_KICK:
  1657. ring->hangcheck.score += KICK;
  1658. break;
  1659. case HANGCHECK_HUNG:
  1660. ring->hangcheck.score += HUNG;
  1661. stuck[i] = true;
  1662. break;
  1663. }
  1664. }
  1665. } else {
  1666. /* Gradually reduce the count so that we catch DoS
  1667. * attempts across multiple batches.
  1668. */
  1669. if (ring->hangcheck.score > 0)
  1670. ring->hangcheck.score--;
  1671. }
  1672. ring->hangcheck.seqno = seqno;
  1673. ring->hangcheck.acthd = acthd;
  1674. busy_count += busy;
  1675. }
  1676. for_each_ring(ring, dev_priv, i) {
  1677. if (ring->hangcheck.score > FIRE) {
  1678. DRM_ERROR("%s on %s\n",
  1679. stuck[i] ? "stuck" : "no progress",
  1680. ring->name);
  1681. rings_hung++;
  1682. }
  1683. }
  1684. if (rings_hung)
  1685. return i915_handle_error(dev, true);
  1686. if (busy_count)
  1687. /* Reset timer case chip hangs without another request
  1688. * being added */
  1689. i915_queue_hangcheck(dev);
  1690. }
  1691. void i915_queue_hangcheck(struct drm_device *dev)
  1692. {
  1693. struct drm_i915_private *dev_priv = dev->dev_private;
  1694. if (!i915_enable_hangcheck)
  1695. return;
  1696. mod_timer(&dev_priv->gpu_error.hangcheck_timer,
  1697. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  1698. }
  1699. static void ibx_irq_preinstall(struct drm_device *dev)
  1700. {
  1701. struct drm_i915_private *dev_priv = dev->dev_private;
  1702. if (HAS_PCH_NOP(dev))
  1703. return;
  1704. /* south display irq */
  1705. I915_WRITE(SDEIMR, 0xffffffff);
  1706. /*
  1707. * SDEIER is also touched by the interrupt handler to work around missed
  1708. * PCH interrupts. Hence we can't update it after the interrupt handler
  1709. * is enabled - instead we unconditionally enable all PCH interrupt
  1710. * sources here, but then only unmask them as needed with SDEIMR.
  1711. */
  1712. I915_WRITE(SDEIER, 0xffffffff);
  1713. POSTING_READ(SDEIER);
  1714. }
  1715. static void gen5_gt_irq_preinstall(struct drm_device *dev)
  1716. {
  1717. struct drm_i915_private *dev_priv = dev->dev_private;
  1718. /* and GT */
  1719. I915_WRITE(GTIMR, 0xffffffff);
  1720. I915_WRITE(GTIER, 0x0);
  1721. POSTING_READ(GTIER);
  1722. if (INTEL_INFO(dev)->gen >= 6) {
  1723. /* and PM */
  1724. I915_WRITE(GEN6_PMIMR, 0xffffffff);
  1725. I915_WRITE(GEN6_PMIER, 0x0);
  1726. POSTING_READ(GEN6_PMIER);
  1727. }
  1728. }
  1729. /* drm_dma.h hooks
  1730. */
  1731. static void ironlake_irq_preinstall(struct drm_device *dev)
  1732. {
  1733. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1734. atomic_set(&dev_priv->irq_received, 0);
  1735. I915_WRITE(HWSTAM, 0xeffe);
  1736. I915_WRITE(DEIMR, 0xffffffff);
  1737. I915_WRITE(DEIER, 0x0);
  1738. POSTING_READ(DEIER);
  1739. gen5_gt_irq_preinstall(dev);
  1740. ibx_irq_preinstall(dev);
  1741. }
  1742. static void valleyview_irq_preinstall(struct drm_device *dev)
  1743. {
  1744. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1745. int pipe;
  1746. atomic_set(&dev_priv->irq_received, 0);
  1747. /* VLV magic */
  1748. I915_WRITE(VLV_IMR, 0);
  1749. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  1750. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  1751. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  1752. /* and GT */
  1753. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1754. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1755. gen5_gt_irq_preinstall(dev);
  1756. I915_WRITE(DPINVGTT, 0xff);
  1757. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1758. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1759. for_each_pipe(pipe)
  1760. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1761. I915_WRITE(VLV_IIR, 0xffffffff);
  1762. I915_WRITE(VLV_IMR, 0xffffffff);
  1763. I915_WRITE(VLV_IER, 0x0);
  1764. POSTING_READ(VLV_IER);
  1765. }
  1766. static void ibx_hpd_irq_setup(struct drm_device *dev)
  1767. {
  1768. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1769. struct drm_mode_config *mode_config = &dev->mode_config;
  1770. struct intel_encoder *intel_encoder;
  1771. u32 hotplug_irqs, hotplug, enabled_irqs = 0;
  1772. if (HAS_PCH_IBX(dev)) {
  1773. hotplug_irqs = SDE_HOTPLUG_MASK;
  1774. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  1775. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  1776. enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
  1777. } else {
  1778. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  1779. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  1780. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  1781. enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
  1782. }
  1783. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  1784. /*
  1785. * Enable digital hotplug on the PCH, and configure the DP short pulse
  1786. * duration to 2ms (which is the minimum in the Display Port spec)
  1787. *
  1788. * This register is the same on all known PCH chips.
  1789. */
  1790. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  1791. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  1792. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  1793. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  1794. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  1795. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  1796. }
  1797. static void ibx_irq_postinstall(struct drm_device *dev)
  1798. {
  1799. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1800. u32 mask;
  1801. if (HAS_PCH_NOP(dev))
  1802. return;
  1803. if (HAS_PCH_IBX(dev)) {
  1804. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
  1805. SDE_TRANSA_FIFO_UNDER | SDE_POISON;
  1806. } else {
  1807. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
  1808. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  1809. }
  1810. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1811. I915_WRITE(SDEIMR, ~mask);
  1812. }
  1813. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  1814. {
  1815. struct drm_i915_private *dev_priv = dev->dev_private;
  1816. u32 pm_irqs, gt_irqs;
  1817. pm_irqs = gt_irqs = 0;
  1818. dev_priv->gt_irq_mask = ~0;
  1819. if (HAS_L3_GPU_CACHE(dev)) {
  1820. /* L3 parity interrupt is always unmasked. */
  1821. dev_priv->gt_irq_mask = ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  1822. gt_irqs |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  1823. }
  1824. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  1825. if (IS_GEN5(dev)) {
  1826. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  1827. ILK_BSD_USER_INTERRUPT;
  1828. } else {
  1829. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  1830. }
  1831. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1832. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  1833. I915_WRITE(GTIER, gt_irqs);
  1834. POSTING_READ(GTIER);
  1835. if (INTEL_INFO(dev)->gen >= 6) {
  1836. pm_irqs |= GEN6_PM_RPS_EVENTS;
  1837. if (HAS_VEBOX(dev))
  1838. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  1839. dev_priv->pm_irq_mask = 0xffffffff;
  1840. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  1841. I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
  1842. I915_WRITE(GEN6_PMIER, pm_irqs);
  1843. POSTING_READ(GEN6_PMIER);
  1844. }
  1845. }
  1846. static int ironlake_irq_postinstall(struct drm_device *dev)
  1847. {
  1848. unsigned long irqflags;
  1849. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1850. u32 display_mask, extra_mask;
  1851. if (INTEL_INFO(dev)->gen >= 7) {
  1852. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  1853. DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
  1854. DE_PLANEB_FLIP_DONE_IVB |
  1855. DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
  1856. DE_ERR_INT_IVB);
  1857. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  1858. DE_PIPEA_VBLANK_IVB);
  1859. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  1860. } else {
  1861. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  1862. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  1863. DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN |
  1864. DE_PIPEA_FIFO_UNDERRUN | DE_POISON);
  1865. extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
  1866. }
  1867. dev_priv->irq_mask = ~display_mask;
  1868. /* should always can generate irq */
  1869. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1870. I915_WRITE(DEIMR, dev_priv->irq_mask);
  1871. I915_WRITE(DEIER, display_mask | extra_mask);
  1872. POSTING_READ(DEIER);
  1873. gen5_gt_irq_postinstall(dev);
  1874. ibx_irq_postinstall(dev);
  1875. if (IS_IRONLAKE_M(dev)) {
  1876. /* Enable PCU event interrupts
  1877. *
  1878. * spinlocking not required here for correctness since interrupt
  1879. * setup is guaranteed to run in single-threaded context. But we
  1880. * need it to make the assert_spin_locked happy. */
  1881. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1882. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  1883. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1884. }
  1885. return 0;
  1886. }
  1887. static int valleyview_irq_postinstall(struct drm_device *dev)
  1888. {
  1889. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1890. u32 enable_mask;
  1891. u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV;
  1892. unsigned long irqflags;
  1893. enable_mask = I915_DISPLAY_PORT_INTERRUPT;
  1894. enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1895. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1896. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1897. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1898. /*
  1899. *Leave vblank interrupts masked initially. enable/disable will
  1900. * toggle them based on usage.
  1901. */
  1902. dev_priv->irq_mask = (~enable_mask) |
  1903. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  1904. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1905. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1906. POSTING_READ(PORT_HOTPLUG_EN);
  1907. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  1908. I915_WRITE(VLV_IER, enable_mask);
  1909. I915_WRITE(VLV_IIR, 0xffffffff);
  1910. I915_WRITE(PIPESTAT(0), 0xffff);
  1911. I915_WRITE(PIPESTAT(1), 0xffff);
  1912. POSTING_READ(VLV_IER);
  1913. /* Interrupt setup is already guaranteed to be single-threaded, this is
  1914. * just to make the assert_spin_locked check happy. */
  1915. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1916. i915_enable_pipestat(dev_priv, 0, pipestat_enable);
  1917. i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
  1918. i915_enable_pipestat(dev_priv, 1, pipestat_enable);
  1919. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1920. I915_WRITE(VLV_IIR, 0xffffffff);
  1921. I915_WRITE(VLV_IIR, 0xffffffff);
  1922. gen5_gt_irq_postinstall(dev);
  1923. /* ack & enable invalid PTE error interrupts */
  1924. #if 0 /* FIXME: add support to irq handler for checking these bits */
  1925. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  1926. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  1927. #endif
  1928. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  1929. return 0;
  1930. }
  1931. static void valleyview_irq_uninstall(struct drm_device *dev)
  1932. {
  1933. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1934. int pipe;
  1935. if (!dev_priv)
  1936. return;
  1937. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  1938. for_each_pipe(pipe)
  1939. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1940. I915_WRITE(HWSTAM, 0xffffffff);
  1941. I915_WRITE(PORT_HOTPLUG_EN, 0);
  1942. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  1943. for_each_pipe(pipe)
  1944. I915_WRITE(PIPESTAT(pipe), 0xffff);
  1945. I915_WRITE(VLV_IIR, 0xffffffff);
  1946. I915_WRITE(VLV_IMR, 0xffffffff);
  1947. I915_WRITE(VLV_IER, 0x0);
  1948. POSTING_READ(VLV_IER);
  1949. }
  1950. static void ironlake_irq_uninstall(struct drm_device *dev)
  1951. {
  1952. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1953. if (!dev_priv)
  1954. return;
  1955. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  1956. I915_WRITE(HWSTAM, 0xffffffff);
  1957. I915_WRITE(DEIMR, 0xffffffff);
  1958. I915_WRITE(DEIER, 0x0);
  1959. I915_WRITE(DEIIR, I915_READ(DEIIR));
  1960. if (IS_GEN7(dev))
  1961. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  1962. I915_WRITE(GTIMR, 0xffffffff);
  1963. I915_WRITE(GTIER, 0x0);
  1964. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1965. if (HAS_PCH_NOP(dev))
  1966. return;
  1967. I915_WRITE(SDEIMR, 0xffffffff);
  1968. I915_WRITE(SDEIER, 0x0);
  1969. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  1970. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  1971. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  1972. }
  1973. static void i8xx_irq_preinstall(struct drm_device * dev)
  1974. {
  1975. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1976. int pipe;
  1977. atomic_set(&dev_priv->irq_received, 0);
  1978. for_each_pipe(pipe)
  1979. I915_WRITE(PIPESTAT(pipe), 0);
  1980. I915_WRITE16(IMR, 0xffff);
  1981. I915_WRITE16(IER, 0x0);
  1982. POSTING_READ16(IER);
  1983. }
  1984. static int i8xx_irq_postinstall(struct drm_device *dev)
  1985. {
  1986. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1987. I915_WRITE16(EMR,
  1988. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  1989. /* Unmask the interrupts that we always want on. */
  1990. dev_priv->irq_mask =
  1991. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1992. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  1993. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  1994. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  1995. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1996. I915_WRITE16(IMR, dev_priv->irq_mask);
  1997. I915_WRITE16(IER,
  1998. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  1999. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2000. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2001. I915_USER_INTERRUPT);
  2002. POSTING_READ16(IER);
  2003. return 0;
  2004. }
  2005. /*
  2006. * Returns true when a page flip has completed.
  2007. */
  2008. static bool i8xx_handle_vblank(struct drm_device *dev,
  2009. int pipe, u16 iir)
  2010. {
  2011. drm_i915_private_t *dev_priv = dev->dev_private;
  2012. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
  2013. if (!drm_handle_vblank(dev, pipe))
  2014. return false;
  2015. if ((iir & flip_pending) == 0)
  2016. return false;
  2017. intel_prepare_page_flip(dev, pipe);
  2018. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2019. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2020. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2021. * the flip is completed (no longer pending). Since this doesn't raise
  2022. * an interrupt per se, we watch for the change at vblank.
  2023. */
  2024. if (I915_READ16(ISR) & flip_pending)
  2025. return false;
  2026. intel_finish_page_flip(dev, pipe);
  2027. return true;
  2028. }
  2029. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  2030. {
  2031. struct drm_device *dev = (struct drm_device *) arg;
  2032. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2033. u16 iir, new_iir;
  2034. u32 pipe_stats[2];
  2035. unsigned long irqflags;
  2036. int pipe;
  2037. u16 flip_mask =
  2038. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2039. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2040. atomic_inc(&dev_priv->irq_received);
  2041. iir = I915_READ16(IIR);
  2042. if (iir == 0)
  2043. return IRQ_NONE;
  2044. while (iir & ~flip_mask) {
  2045. /* Can't rely on pipestat interrupt bit in iir as it might
  2046. * have been cleared after the pipestat interrupt was received.
  2047. * It doesn't set the bit in iir again, but it still produces
  2048. * interrupts (for non-MSI).
  2049. */
  2050. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2051. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2052. i915_handle_error(dev, false);
  2053. for_each_pipe(pipe) {
  2054. int reg = PIPESTAT(pipe);
  2055. pipe_stats[pipe] = I915_READ(reg);
  2056. /*
  2057. * Clear the PIPE*STAT regs before the IIR
  2058. */
  2059. if (pipe_stats[pipe] & 0x8000ffff) {
  2060. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2061. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2062. pipe_name(pipe));
  2063. I915_WRITE(reg, pipe_stats[pipe]);
  2064. }
  2065. }
  2066. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2067. I915_WRITE16(IIR, iir & ~flip_mask);
  2068. new_iir = I915_READ16(IIR); /* Flush posted writes */
  2069. i915_update_dri1_breadcrumb(dev);
  2070. if (iir & I915_USER_INTERRUPT)
  2071. notify_ring(dev, &dev_priv->ring[RCS]);
  2072. if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2073. i8xx_handle_vblank(dev, 0, iir))
  2074. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0);
  2075. if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2076. i8xx_handle_vblank(dev, 1, iir))
  2077. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1);
  2078. iir = new_iir;
  2079. }
  2080. return IRQ_HANDLED;
  2081. }
  2082. static void i8xx_irq_uninstall(struct drm_device * dev)
  2083. {
  2084. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2085. int pipe;
  2086. for_each_pipe(pipe) {
  2087. /* Clear enable bits; then clear status bits */
  2088. I915_WRITE(PIPESTAT(pipe), 0);
  2089. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2090. }
  2091. I915_WRITE16(IMR, 0xffff);
  2092. I915_WRITE16(IER, 0x0);
  2093. I915_WRITE16(IIR, I915_READ16(IIR));
  2094. }
  2095. static void i915_irq_preinstall(struct drm_device * dev)
  2096. {
  2097. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2098. int pipe;
  2099. atomic_set(&dev_priv->irq_received, 0);
  2100. if (I915_HAS_HOTPLUG(dev)) {
  2101. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2102. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2103. }
  2104. I915_WRITE16(HWSTAM, 0xeffe);
  2105. for_each_pipe(pipe)
  2106. I915_WRITE(PIPESTAT(pipe), 0);
  2107. I915_WRITE(IMR, 0xffffffff);
  2108. I915_WRITE(IER, 0x0);
  2109. POSTING_READ(IER);
  2110. }
  2111. static int i915_irq_postinstall(struct drm_device *dev)
  2112. {
  2113. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2114. u32 enable_mask;
  2115. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2116. /* Unmask the interrupts that we always want on. */
  2117. dev_priv->irq_mask =
  2118. ~(I915_ASLE_INTERRUPT |
  2119. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2120. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2121. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2122. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2123. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2124. enable_mask =
  2125. I915_ASLE_INTERRUPT |
  2126. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2127. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2128. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2129. I915_USER_INTERRUPT;
  2130. if (I915_HAS_HOTPLUG(dev)) {
  2131. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2132. POSTING_READ(PORT_HOTPLUG_EN);
  2133. /* Enable in IER... */
  2134. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  2135. /* and unmask in IMR */
  2136. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  2137. }
  2138. I915_WRITE(IMR, dev_priv->irq_mask);
  2139. I915_WRITE(IER, enable_mask);
  2140. POSTING_READ(IER);
  2141. i915_enable_asle_pipestat(dev);
  2142. return 0;
  2143. }
  2144. /*
  2145. * Returns true when a page flip has completed.
  2146. */
  2147. static bool i915_handle_vblank(struct drm_device *dev,
  2148. int plane, int pipe, u32 iir)
  2149. {
  2150. drm_i915_private_t *dev_priv = dev->dev_private;
  2151. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  2152. if (!drm_handle_vblank(dev, pipe))
  2153. return false;
  2154. if ((iir & flip_pending) == 0)
  2155. return false;
  2156. intel_prepare_page_flip(dev, plane);
  2157. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2158. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2159. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2160. * the flip is completed (no longer pending). Since this doesn't raise
  2161. * an interrupt per se, we watch for the change at vblank.
  2162. */
  2163. if (I915_READ(ISR) & flip_pending)
  2164. return false;
  2165. intel_finish_page_flip(dev, pipe);
  2166. return true;
  2167. }
  2168. static irqreturn_t i915_irq_handler(int irq, void *arg)
  2169. {
  2170. struct drm_device *dev = (struct drm_device *) arg;
  2171. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2172. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  2173. unsigned long irqflags;
  2174. u32 flip_mask =
  2175. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2176. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2177. int pipe, ret = IRQ_NONE;
  2178. atomic_inc(&dev_priv->irq_received);
  2179. iir = I915_READ(IIR);
  2180. do {
  2181. bool irq_received = (iir & ~flip_mask) != 0;
  2182. bool blc_event = false;
  2183. /* Can't rely on pipestat interrupt bit in iir as it might
  2184. * have been cleared after the pipestat interrupt was received.
  2185. * It doesn't set the bit in iir again, but it still produces
  2186. * interrupts (for non-MSI).
  2187. */
  2188. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2189. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2190. i915_handle_error(dev, false);
  2191. for_each_pipe(pipe) {
  2192. int reg = PIPESTAT(pipe);
  2193. pipe_stats[pipe] = I915_READ(reg);
  2194. /* Clear the PIPE*STAT regs before the IIR */
  2195. if (pipe_stats[pipe] & 0x8000ffff) {
  2196. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2197. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2198. pipe_name(pipe));
  2199. I915_WRITE(reg, pipe_stats[pipe]);
  2200. irq_received = true;
  2201. }
  2202. }
  2203. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2204. if (!irq_received)
  2205. break;
  2206. /* Consume port. Then clear IIR or we'll miss events */
  2207. if ((I915_HAS_HOTPLUG(dev)) &&
  2208. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  2209. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2210. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  2211. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2212. hotplug_status);
  2213. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  2214. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2215. POSTING_READ(PORT_HOTPLUG_STAT);
  2216. }
  2217. I915_WRITE(IIR, iir & ~flip_mask);
  2218. new_iir = I915_READ(IIR); /* Flush posted writes */
  2219. if (iir & I915_USER_INTERRUPT)
  2220. notify_ring(dev, &dev_priv->ring[RCS]);
  2221. for_each_pipe(pipe) {
  2222. int plane = pipe;
  2223. if (IS_MOBILE(dev))
  2224. plane = !plane;
  2225. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2226. i915_handle_vblank(dev, plane, pipe, iir))
  2227. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  2228. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2229. blc_event = true;
  2230. }
  2231. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2232. intel_opregion_asle_intr(dev);
  2233. /* With MSI, interrupts are only generated when iir
  2234. * transitions from zero to nonzero. If another bit got
  2235. * set while we were handling the existing iir bits, then
  2236. * we would never get another interrupt.
  2237. *
  2238. * This is fine on non-MSI as well, as if we hit this path
  2239. * we avoid exiting the interrupt handler only to generate
  2240. * another one.
  2241. *
  2242. * Note that for MSI this could cause a stray interrupt report
  2243. * if an interrupt landed in the time between writing IIR and
  2244. * the posting read. This should be rare enough to never
  2245. * trigger the 99% of 100,000 interrupts test for disabling
  2246. * stray interrupts.
  2247. */
  2248. ret = IRQ_HANDLED;
  2249. iir = new_iir;
  2250. } while (iir & ~flip_mask);
  2251. i915_update_dri1_breadcrumb(dev);
  2252. return ret;
  2253. }
  2254. static void i915_irq_uninstall(struct drm_device * dev)
  2255. {
  2256. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2257. int pipe;
  2258. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2259. if (I915_HAS_HOTPLUG(dev)) {
  2260. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2261. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2262. }
  2263. I915_WRITE16(HWSTAM, 0xffff);
  2264. for_each_pipe(pipe) {
  2265. /* Clear enable bits; then clear status bits */
  2266. I915_WRITE(PIPESTAT(pipe), 0);
  2267. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2268. }
  2269. I915_WRITE(IMR, 0xffffffff);
  2270. I915_WRITE(IER, 0x0);
  2271. I915_WRITE(IIR, I915_READ(IIR));
  2272. }
  2273. static void i965_irq_preinstall(struct drm_device * dev)
  2274. {
  2275. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2276. int pipe;
  2277. atomic_set(&dev_priv->irq_received, 0);
  2278. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2279. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2280. I915_WRITE(HWSTAM, 0xeffe);
  2281. for_each_pipe(pipe)
  2282. I915_WRITE(PIPESTAT(pipe), 0);
  2283. I915_WRITE(IMR, 0xffffffff);
  2284. I915_WRITE(IER, 0x0);
  2285. POSTING_READ(IER);
  2286. }
  2287. static int i965_irq_postinstall(struct drm_device *dev)
  2288. {
  2289. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2290. u32 enable_mask;
  2291. u32 error_mask;
  2292. unsigned long irqflags;
  2293. /* Unmask the interrupts that we always want on. */
  2294. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  2295. I915_DISPLAY_PORT_INTERRUPT |
  2296. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2297. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2298. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2299. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2300. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2301. enable_mask = ~dev_priv->irq_mask;
  2302. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2303. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  2304. enable_mask |= I915_USER_INTERRUPT;
  2305. if (IS_G4X(dev))
  2306. enable_mask |= I915_BSD_USER_INTERRUPT;
  2307. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2308. * just to make the assert_spin_locked check happy. */
  2309. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2310. i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
  2311. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2312. /*
  2313. * Enable some error detection, note the instruction error mask
  2314. * bit is reserved, so we leave it masked.
  2315. */
  2316. if (IS_G4X(dev)) {
  2317. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  2318. GM45_ERROR_MEM_PRIV |
  2319. GM45_ERROR_CP_PRIV |
  2320. I915_ERROR_MEMORY_REFRESH);
  2321. } else {
  2322. error_mask = ~(I915_ERROR_PAGE_TABLE |
  2323. I915_ERROR_MEMORY_REFRESH);
  2324. }
  2325. I915_WRITE(EMR, error_mask);
  2326. I915_WRITE(IMR, dev_priv->irq_mask);
  2327. I915_WRITE(IER, enable_mask);
  2328. POSTING_READ(IER);
  2329. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2330. POSTING_READ(PORT_HOTPLUG_EN);
  2331. i915_enable_asle_pipestat(dev);
  2332. return 0;
  2333. }
  2334. static void i915_hpd_irq_setup(struct drm_device *dev)
  2335. {
  2336. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2337. struct drm_mode_config *mode_config = &dev->mode_config;
  2338. struct intel_encoder *intel_encoder;
  2339. u32 hotplug_en;
  2340. assert_spin_locked(&dev_priv->irq_lock);
  2341. if (I915_HAS_HOTPLUG(dev)) {
  2342. hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  2343. hotplug_en &= ~HOTPLUG_INT_EN_MASK;
  2344. /* Note HDMI and DP share hotplug bits */
  2345. /* enable bits are the same for all generations */
  2346. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2347. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2348. hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
  2349. /* Programming the CRT detection parameters tends
  2350. to generate a spurious hotplug event about three
  2351. seconds later. So just do it once.
  2352. */
  2353. if (IS_G4X(dev))
  2354. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  2355. hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
  2356. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  2357. /* Ignore TV since it's buggy */
  2358. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  2359. }
  2360. }
  2361. static irqreturn_t i965_irq_handler(int irq, void *arg)
  2362. {
  2363. struct drm_device *dev = (struct drm_device *) arg;
  2364. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2365. u32 iir, new_iir;
  2366. u32 pipe_stats[I915_MAX_PIPES];
  2367. unsigned long irqflags;
  2368. int irq_received;
  2369. int ret = IRQ_NONE, pipe;
  2370. u32 flip_mask =
  2371. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2372. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2373. atomic_inc(&dev_priv->irq_received);
  2374. iir = I915_READ(IIR);
  2375. for (;;) {
  2376. bool blc_event = false;
  2377. irq_received = (iir & ~flip_mask) != 0;
  2378. /* Can't rely on pipestat interrupt bit in iir as it might
  2379. * have been cleared after the pipestat interrupt was received.
  2380. * It doesn't set the bit in iir again, but it still produces
  2381. * interrupts (for non-MSI).
  2382. */
  2383. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2384. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2385. i915_handle_error(dev, false);
  2386. for_each_pipe(pipe) {
  2387. int reg = PIPESTAT(pipe);
  2388. pipe_stats[pipe] = I915_READ(reg);
  2389. /*
  2390. * Clear the PIPE*STAT regs before the IIR
  2391. */
  2392. if (pipe_stats[pipe] & 0x8000ffff) {
  2393. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2394. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2395. pipe_name(pipe));
  2396. I915_WRITE(reg, pipe_stats[pipe]);
  2397. irq_received = 1;
  2398. }
  2399. }
  2400. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2401. if (!irq_received)
  2402. break;
  2403. ret = IRQ_HANDLED;
  2404. /* Consume port. Then clear IIR or we'll miss events */
  2405. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  2406. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2407. u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
  2408. HOTPLUG_INT_STATUS_G4X :
  2409. HOTPLUG_INT_STATUS_I915);
  2410. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2411. hotplug_status);
  2412. intel_hpd_irq_handler(dev, hotplug_trigger,
  2413. IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
  2414. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2415. I915_READ(PORT_HOTPLUG_STAT);
  2416. }
  2417. I915_WRITE(IIR, iir & ~flip_mask);
  2418. new_iir = I915_READ(IIR); /* Flush posted writes */
  2419. if (iir & I915_USER_INTERRUPT)
  2420. notify_ring(dev, &dev_priv->ring[RCS]);
  2421. if (iir & I915_BSD_USER_INTERRUPT)
  2422. notify_ring(dev, &dev_priv->ring[VCS]);
  2423. for_each_pipe(pipe) {
  2424. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  2425. i915_handle_vblank(dev, pipe, pipe, iir))
  2426. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  2427. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2428. blc_event = true;
  2429. }
  2430. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2431. intel_opregion_asle_intr(dev);
  2432. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  2433. gmbus_irq_handler(dev);
  2434. /* With MSI, interrupts are only generated when iir
  2435. * transitions from zero to nonzero. If another bit got
  2436. * set while we were handling the existing iir bits, then
  2437. * we would never get another interrupt.
  2438. *
  2439. * This is fine on non-MSI as well, as if we hit this path
  2440. * we avoid exiting the interrupt handler only to generate
  2441. * another one.
  2442. *
  2443. * Note that for MSI this could cause a stray interrupt report
  2444. * if an interrupt landed in the time between writing IIR and
  2445. * the posting read. This should be rare enough to never
  2446. * trigger the 99% of 100,000 interrupts test for disabling
  2447. * stray interrupts.
  2448. */
  2449. iir = new_iir;
  2450. }
  2451. i915_update_dri1_breadcrumb(dev);
  2452. return ret;
  2453. }
  2454. static void i965_irq_uninstall(struct drm_device * dev)
  2455. {
  2456. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2457. int pipe;
  2458. if (!dev_priv)
  2459. return;
  2460. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2461. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2462. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2463. I915_WRITE(HWSTAM, 0xffffffff);
  2464. for_each_pipe(pipe)
  2465. I915_WRITE(PIPESTAT(pipe), 0);
  2466. I915_WRITE(IMR, 0xffffffff);
  2467. I915_WRITE(IER, 0x0);
  2468. for_each_pipe(pipe)
  2469. I915_WRITE(PIPESTAT(pipe),
  2470. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  2471. I915_WRITE(IIR, I915_READ(IIR));
  2472. }
  2473. static void i915_reenable_hotplug_timer_func(unsigned long data)
  2474. {
  2475. drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
  2476. struct drm_device *dev = dev_priv->dev;
  2477. struct drm_mode_config *mode_config = &dev->mode_config;
  2478. unsigned long irqflags;
  2479. int i;
  2480. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2481. for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
  2482. struct drm_connector *connector;
  2483. if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
  2484. continue;
  2485. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  2486. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2487. struct intel_connector *intel_connector = to_intel_connector(connector);
  2488. if (intel_connector->encoder->hpd_pin == i) {
  2489. if (connector->polled != intel_connector->polled)
  2490. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  2491. drm_get_connector_name(connector));
  2492. connector->polled = intel_connector->polled;
  2493. if (!connector->polled)
  2494. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2495. }
  2496. }
  2497. }
  2498. if (dev_priv->display.hpd_irq_setup)
  2499. dev_priv->display.hpd_irq_setup(dev);
  2500. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2501. }
  2502. void intel_irq_init(struct drm_device *dev)
  2503. {
  2504. struct drm_i915_private *dev_priv = dev->dev_private;
  2505. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  2506. INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
  2507. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  2508. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  2509. setup_timer(&dev_priv->gpu_error.hangcheck_timer,
  2510. i915_hangcheck_elapsed,
  2511. (unsigned long) dev);
  2512. setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
  2513. (unsigned long) dev_priv);
  2514. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  2515. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  2516. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  2517. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  2518. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  2519. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  2520. }
  2521. if (drm_core_check_feature(dev, DRIVER_MODESET))
  2522. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  2523. else
  2524. dev->driver->get_vblank_timestamp = NULL;
  2525. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  2526. if (IS_VALLEYVIEW(dev)) {
  2527. dev->driver->irq_handler = valleyview_irq_handler;
  2528. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  2529. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  2530. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  2531. dev->driver->enable_vblank = valleyview_enable_vblank;
  2532. dev->driver->disable_vblank = valleyview_disable_vblank;
  2533. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2534. } else if (HAS_PCH_SPLIT(dev)) {
  2535. dev->driver->irq_handler = ironlake_irq_handler;
  2536. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2537. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  2538. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2539. dev->driver->enable_vblank = ironlake_enable_vblank;
  2540. dev->driver->disable_vblank = ironlake_disable_vblank;
  2541. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  2542. } else {
  2543. if (INTEL_INFO(dev)->gen == 2) {
  2544. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  2545. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  2546. dev->driver->irq_handler = i8xx_irq_handler;
  2547. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  2548. } else if (INTEL_INFO(dev)->gen == 3) {
  2549. dev->driver->irq_preinstall = i915_irq_preinstall;
  2550. dev->driver->irq_postinstall = i915_irq_postinstall;
  2551. dev->driver->irq_uninstall = i915_irq_uninstall;
  2552. dev->driver->irq_handler = i915_irq_handler;
  2553. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2554. } else {
  2555. dev->driver->irq_preinstall = i965_irq_preinstall;
  2556. dev->driver->irq_postinstall = i965_irq_postinstall;
  2557. dev->driver->irq_uninstall = i965_irq_uninstall;
  2558. dev->driver->irq_handler = i965_irq_handler;
  2559. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2560. }
  2561. dev->driver->enable_vblank = i915_enable_vblank;
  2562. dev->driver->disable_vblank = i915_disable_vblank;
  2563. }
  2564. }
  2565. void intel_hpd_init(struct drm_device *dev)
  2566. {
  2567. struct drm_i915_private *dev_priv = dev->dev_private;
  2568. struct drm_mode_config *mode_config = &dev->mode_config;
  2569. struct drm_connector *connector;
  2570. unsigned long irqflags;
  2571. int i;
  2572. for (i = 1; i < HPD_NUM_PINS; i++) {
  2573. dev_priv->hpd_stats[i].hpd_cnt = 0;
  2574. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  2575. }
  2576. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2577. struct intel_connector *intel_connector = to_intel_connector(connector);
  2578. connector->polled = intel_connector->polled;
  2579. if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
  2580. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2581. }
  2582. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2583. * just to make the assert_spin_locked checks happy. */
  2584. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2585. if (dev_priv->display.hpd_irq_setup)
  2586. dev_priv->display.hpd_irq_setup(dev);
  2587. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2588. }
  2589. /* Disable interrupts so we can allow Package C8+. */
  2590. void hsw_pc8_disable_interrupts(struct drm_device *dev)
  2591. {
  2592. struct drm_i915_private *dev_priv = dev->dev_private;
  2593. unsigned long irqflags;
  2594. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2595. dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
  2596. dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
  2597. dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
  2598. dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
  2599. dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
  2600. ironlake_disable_display_irq(dev_priv, ~DE_PCH_EVENT_IVB);
  2601. ibx_disable_display_interrupt(dev_priv, ~SDE_HOTPLUG_MASK_CPT);
  2602. ilk_disable_gt_irq(dev_priv, 0xffffffff);
  2603. snb_disable_pm_irq(dev_priv, 0xffffffff);
  2604. dev_priv->pc8.irqs_disabled = true;
  2605. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2606. }
  2607. /* Restore interrupts so we can recover from Package C8+. */
  2608. void hsw_pc8_restore_interrupts(struct drm_device *dev)
  2609. {
  2610. struct drm_i915_private *dev_priv = dev->dev_private;
  2611. unsigned long irqflags;
  2612. uint32_t val, expected;
  2613. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2614. val = I915_READ(DEIMR);
  2615. expected = ~DE_PCH_EVENT_IVB;
  2616. WARN(val != expected, "DEIMR is 0x%08x, not 0x%08x\n", val, expected);
  2617. val = I915_READ(SDEIMR) & ~SDE_HOTPLUG_MASK_CPT;
  2618. expected = ~SDE_HOTPLUG_MASK_CPT;
  2619. WARN(val != expected, "SDEIMR non-HPD bits are 0x%08x, not 0x%08x\n",
  2620. val, expected);
  2621. val = I915_READ(GTIMR);
  2622. expected = 0xffffffff;
  2623. WARN(val != expected, "GTIMR is 0x%08x, not 0x%08x\n", val, expected);
  2624. val = I915_READ(GEN6_PMIMR);
  2625. expected = 0xffffffff;
  2626. WARN(val != expected, "GEN6_PMIMR is 0x%08x, not 0x%08x\n", val,
  2627. expected);
  2628. dev_priv->pc8.irqs_disabled = false;
  2629. ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
  2630. ibx_enable_display_interrupt(dev_priv,
  2631. ~dev_priv->pc8.regsave.sdeimr &
  2632. ~SDE_HOTPLUG_MASK_CPT);
  2633. ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
  2634. snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
  2635. I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
  2636. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2637. }