i915_irq.c 88 KB

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