i915_irq.c 92 KB

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