i915_irq.c 98 KB

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