i915_irq.c 90 KB

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