i915_irq.c 94 KB

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