i915_irq.c 89 KB

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