i915_irq.c 95 KB

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