i915_irq.c 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538
  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 display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  991. uint32_t crc0, uint32_t crc1,
  992. uint32_t crc2, uint32_t crc3,
  993. uint32_t crc4)
  994. {
  995. struct drm_i915_private *dev_priv = dev->dev_private;
  996. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
  997. struct intel_pipe_crc_entry *entry;
  998. int head, tail;
  999. spin_lock(&pipe_crc->lock);
  1000. if (!pipe_crc->entries) {
  1001. spin_unlock(&pipe_crc->lock);
  1002. DRM_ERROR("spurious interrupt\n");
  1003. return;
  1004. }
  1005. head = pipe_crc->head;
  1006. tail = pipe_crc->tail;
  1007. if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
  1008. spin_unlock(&pipe_crc->lock);
  1009. DRM_ERROR("CRC buffer overflowing\n");
  1010. return;
  1011. }
  1012. entry = &pipe_crc->entries[head];
  1013. entry->frame = dev->driver->get_vblank_counter(dev, pipe);
  1014. entry->crc[0] = crc0;
  1015. entry->crc[1] = crc1;
  1016. entry->crc[2] = crc2;
  1017. entry->crc[3] = crc3;
  1018. entry->crc[4] = crc4;
  1019. head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
  1020. pipe_crc->head = head;
  1021. spin_unlock(&pipe_crc->lock);
  1022. wake_up_interruptible(&pipe_crc->wq);
  1023. }
  1024. #else
  1025. static inline void
  1026. display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1027. uint32_t crc0, uint32_t crc1,
  1028. uint32_t crc2, uint32_t crc3,
  1029. uint32_t crc4) {}
  1030. #endif
  1031. static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1032. {
  1033. struct drm_i915_private *dev_priv = dev->dev_private;
  1034. display_pipe_crc_irq_handler(dev, pipe,
  1035. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1036. 0, 0, 0, 0);
  1037. }
  1038. static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1039. {
  1040. struct drm_i915_private *dev_priv = dev->dev_private;
  1041. display_pipe_crc_irq_handler(dev, pipe,
  1042. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1043. I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
  1044. I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
  1045. I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
  1046. I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
  1047. }
  1048. static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1049. {
  1050. struct drm_i915_private *dev_priv = dev->dev_private;
  1051. uint32_t res1, res2;
  1052. if (INTEL_INFO(dev)->gen >= 3)
  1053. res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
  1054. else
  1055. res1 = 0;
  1056. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  1057. res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
  1058. else
  1059. res2 = 0;
  1060. display_pipe_crc_irq_handler(dev, pipe,
  1061. I915_READ(PIPE_CRC_RES_RED(pipe)),
  1062. I915_READ(PIPE_CRC_RES_GREEN(pipe)),
  1063. I915_READ(PIPE_CRC_RES_BLUE(pipe)),
  1064. res1, res2);
  1065. }
  1066. /* The RPS events need forcewake, so we add them to a work queue and mask their
  1067. * IMR bits until the work is done. Other interrupts can be processed without
  1068. * the work queue. */
  1069. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
  1070. {
  1071. if (pm_iir & GEN6_PM_RPS_EVENTS) {
  1072. spin_lock(&dev_priv->irq_lock);
  1073. dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
  1074. snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
  1075. spin_unlock(&dev_priv->irq_lock);
  1076. queue_work(dev_priv->wq, &dev_priv->rps.work);
  1077. }
  1078. if (HAS_VEBOX(dev_priv->dev)) {
  1079. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  1080. notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
  1081. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
  1082. DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
  1083. i915_handle_error(dev_priv->dev, false);
  1084. }
  1085. }
  1086. }
  1087. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  1088. {
  1089. struct drm_device *dev = (struct drm_device *) arg;
  1090. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1091. u32 iir, gt_iir, pm_iir;
  1092. irqreturn_t ret = IRQ_NONE;
  1093. unsigned long irqflags;
  1094. int pipe;
  1095. u32 pipe_stats[I915_MAX_PIPES];
  1096. atomic_inc(&dev_priv->irq_received);
  1097. while (true) {
  1098. iir = I915_READ(VLV_IIR);
  1099. gt_iir = I915_READ(GTIIR);
  1100. pm_iir = I915_READ(GEN6_PMIIR);
  1101. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  1102. goto out;
  1103. ret = IRQ_HANDLED;
  1104. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1105. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1106. for_each_pipe(pipe) {
  1107. int reg = PIPESTAT(pipe);
  1108. pipe_stats[pipe] = I915_READ(reg);
  1109. /*
  1110. * Clear the PIPE*STAT regs before the IIR
  1111. */
  1112. if (pipe_stats[pipe] & 0x8000ffff) {
  1113. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1114. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  1115. pipe_name(pipe));
  1116. I915_WRITE(reg, pipe_stats[pipe]);
  1117. }
  1118. }
  1119. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1120. for_each_pipe(pipe) {
  1121. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
  1122. drm_handle_vblank(dev, pipe);
  1123. if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
  1124. intel_prepare_page_flip(dev, pipe);
  1125. intel_finish_page_flip(dev, pipe);
  1126. }
  1127. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1128. i9xx_pipe_crc_irq_handler(dev, pipe);
  1129. }
  1130. /* Consume port. Then clear IIR or we'll miss events */
  1131. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  1132. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1133. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  1134. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  1135. hotplug_status);
  1136. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  1137. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1138. I915_READ(PORT_HOTPLUG_STAT);
  1139. }
  1140. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  1141. gmbus_irq_handler(dev);
  1142. if (pm_iir)
  1143. gen6_rps_irq_handler(dev_priv, pm_iir);
  1144. I915_WRITE(GTIIR, gt_iir);
  1145. I915_WRITE(GEN6_PMIIR, pm_iir);
  1146. I915_WRITE(VLV_IIR, iir);
  1147. }
  1148. out:
  1149. return ret;
  1150. }
  1151. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  1152. {
  1153. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1154. int pipe;
  1155. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  1156. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
  1157. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  1158. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  1159. SDE_AUDIO_POWER_SHIFT);
  1160. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  1161. port_name(port));
  1162. }
  1163. if (pch_iir & SDE_AUX_MASK)
  1164. dp_aux_irq_handler(dev);
  1165. if (pch_iir & SDE_GMBUS)
  1166. gmbus_irq_handler(dev);
  1167. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  1168. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  1169. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  1170. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  1171. if (pch_iir & SDE_POISON)
  1172. DRM_ERROR("PCH poison interrupt\n");
  1173. if (pch_iir & SDE_FDI_MASK)
  1174. for_each_pipe(pipe)
  1175. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1176. pipe_name(pipe),
  1177. I915_READ(FDI_RX_IIR(pipe)));
  1178. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  1179. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  1180. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  1181. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  1182. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  1183. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  1184. false))
  1185. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  1186. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  1187. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  1188. false))
  1189. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  1190. }
  1191. static void ivb_err_int_handler(struct drm_device *dev)
  1192. {
  1193. struct drm_i915_private *dev_priv = dev->dev_private;
  1194. u32 err_int = I915_READ(GEN7_ERR_INT);
  1195. enum pipe pipe;
  1196. if (err_int & ERR_INT_POISON)
  1197. DRM_ERROR("Poison interrupt\n");
  1198. for_each_pipe(pipe) {
  1199. if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
  1200. if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
  1201. false))
  1202. DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
  1203. pipe_name(pipe));
  1204. }
  1205. if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
  1206. if (IS_IVYBRIDGE(dev))
  1207. ivb_pipe_crc_irq_handler(dev, pipe);
  1208. else
  1209. hsw_pipe_crc_irq_handler(dev, pipe);
  1210. }
  1211. }
  1212. I915_WRITE(GEN7_ERR_INT, err_int);
  1213. }
  1214. static void cpt_serr_int_handler(struct drm_device *dev)
  1215. {
  1216. struct drm_i915_private *dev_priv = dev->dev_private;
  1217. u32 serr_int = I915_READ(SERR_INT);
  1218. if (serr_int & SERR_INT_POISON)
  1219. DRM_ERROR("PCH poison interrupt\n");
  1220. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  1221. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
  1222. false))
  1223. DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
  1224. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  1225. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
  1226. false))
  1227. DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
  1228. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  1229. if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
  1230. false))
  1231. DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
  1232. I915_WRITE(SERR_INT, serr_int);
  1233. }
  1234. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  1235. {
  1236. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1237. int pipe;
  1238. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  1239. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
  1240. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  1241. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  1242. SDE_AUDIO_POWER_SHIFT_CPT);
  1243. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  1244. port_name(port));
  1245. }
  1246. if (pch_iir & SDE_AUX_MASK_CPT)
  1247. dp_aux_irq_handler(dev);
  1248. if (pch_iir & SDE_GMBUS_CPT)
  1249. gmbus_irq_handler(dev);
  1250. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  1251. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  1252. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  1253. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  1254. if (pch_iir & SDE_FDI_MASK_CPT)
  1255. for_each_pipe(pipe)
  1256. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1257. pipe_name(pipe),
  1258. I915_READ(FDI_RX_IIR(pipe)));
  1259. if (pch_iir & SDE_ERROR_CPT)
  1260. cpt_serr_int_handler(dev);
  1261. }
  1262. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1263. {
  1264. struct drm_i915_private *dev_priv = dev->dev_private;
  1265. if (de_iir & DE_AUX_CHANNEL_A)
  1266. dp_aux_irq_handler(dev);
  1267. if (de_iir & DE_GSE)
  1268. intel_opregion_asle_intr(dev);
  1269. if (de_iir & DE_PIPEA_VBLANK)
  1270. drm_handle_vblank(dev, 0);
  1271. if (de_iir & DE_PIPEB_VBLANK)
  1272. drm_handle_vblank(dev, 1);
  1273. if (de_iir & DE_POISON)
  1274. DRM_ERROR("Poison interrupt\n");
  1275. if (de_iir & DE_PIPEA_FIFO_UNDERRUN)
  1276. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
  1277. DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
  1278. if (de_iir & DE_PIPEB_FIFO_UNDERRUN)
  1279. if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
  1280. DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
  1281. if (de_iir & DE_PIPEA_CRC_DONE)
  1282. i9xx_pipe_crc_irq_handler(dev, PIPE_A);
  1283. if (de_iir & DE_PIPEB_CRC_DONE)
  1284. i9xx_pipe_crc_irq_handler(dev, PIPE_B);
  1285. if (de_iir & DE_PLANEA_FLIP_DONE) {
  1286. intel_prepare_page_flip(dev, 0);
  1287. intel_finish_page_flip_plane(dev, 0);
  1288. }
  1289. if (de_iir & DE_PLANEB_FLIP_DONE) {
  1290. intel_prepare_page_flip(dev, 1);
  1291. intel_finish_page_flip_plane(dev, 1);
  1292. }
  1293. /* check event from PCH */
  1294. if (de_iir & DE_PCH_EVENT) {
  1295. u32 pch_iir = I915_READ(SDEIIR);
  1296. if (HAS_PCH_CPT(dev))
  1297. cpt_irq_handler(dev, pch_iir);
  1298. else
  1299. ibx_irq_handler(dev, pch_iir);
  1300. /* should clear PCH hotplug event before clear CPU irq */
  1301. I915_WRITE(SDEIIR, pch_iir);
  1302. }
  1303. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1304. ironlake_rps_change_irq_handler(dev);
  1305. }
  1306. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1307. {
  1308. struct drm_i915_private *dev_priv = dev->dev_private;
  1309. int i;
  1310. if (de_iir & DE_ERR_INT_IVB)
  1311. ivb_err_int_handler(dev);
  1312. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1313. dp_aux_irq_handler(dev);
  1314. if (de_iir & DE_GSE_IVB)
  1315. intel_opregion_asle_intr(dev);
  1316. for (i = 0; i < 3; i++) {
  1317. if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
  1318. drm_handle_vblank(dev, i);
  1319. if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
  1320. intel_prepare_page_flip(dev, i);
  1321. intel_finish_page_flip_plane(dev, i);
  1322. }
  1323. }
  1324. /* check event from PCH */
  1325. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1326. u32 pch_iir = I915_READ(SDEIIR);
  1327. cpt_irq_handler(dev, pch_iir);
  1328. /* clear PCH hotplug event before clear CPU irq */
  1329. I915_WRITE(SDEIIR, pch_iir);
  1330. }
  1331. }
  1332. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1333. {
  1334. struct drm_device *dev = (struct drm_device *) arg;
  1335. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1336. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1337. irqreturn_t ret = IRQ_NONE;
  1338. atomic_inc(&dev_priv->irq_received);
  1339. /* We get interrupts on unclaimed registers, so check for this before we
  1340. * do any I915_{READ,WRITE}. */
  1341. intel_uncore_check_errors(dev);
  1342. /* disable master interrupt before clearing iir */
  1343. de_ier = I915_READ(DEIER);
  1344. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1345. POSTING_READ(DEIER);
  1346. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1347. * interrupts will will be stored on its back queue, and then we'll be
  1348. * able to process them after we restore SDEIER (as soon as we restore
  1349. * it, we'll get an interrupt if SDEIIR still has something to process
  1350. * due to its back queue). */
  1351. if (!HAS_PCH_NOP(dev)) {
  1352. sde_ier = I915_READ(SDEIER);
  1353. I915_WRITE(SDEIER, 0);
  1354. POSTING_READ(SDEIER);
  1355. }
  1356. gt_iir = I915_READ(GTIIR);
  1357. if (gt_iir) {
  1358. if (INTEL_INFO(dev)->gen >= 6)
  1359. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1360. else
  1361. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1362. I915_WRITE(GTIIR, gt_iir);
  1363. ret = IRQ_HANDLED;
  1364. }
  1365. de_iir = I915_READ(DEIIR);
  1366. if (de_iir) {
  1367. if (INTEL_INFO(dev)->gen >= 7)
  1368. ivb_display_irq_handler(dev, de_iir);
  1369. else
  1370. ilk_display_irq_handler(dev, de_iir);
  1371. I915_WRITE(DEIIR, de_iir);
  1372. ret = IRQ_HANDLED;
  1373. }
  1374. if (INTEL_INFO(dev)->gen >= 6) {
  1375. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1376. if (pm_iir) {
  1377. gen6_rps_irq_handler(dev_priv, pm_iir);
  1378. I915_WRITE(GEN6_PMIIR, pm_iir);
  1379. ret = IRQ_HANDLED;
  1380. }
  1381. }
  1382. I915_WRITE(DEIER, de_ier);
  1383. POSTING_READ(DEIER);
  1384. if (!HAS_PCH_NOP(dev)) {
  1385. I915_WRITE(SDEIER, sde_ier);
  1386. POSTING_READ(SDEIER);
  1387. }
  1388. return ret;
  1389. }
  1390. static void i915_error_wake_up(struct drm_i915_private *dev_priv,
  1391. bool reset_completed)
  1392. {
  1393. struct intel_ring_buffer *ring;
  1394. int i;
  1395. /*
  1396. * Notify all waiters for GPU completion events that reset state has
  1397. * been changed, and that they need to restart their wait after
  1398. * checking for potential errors (and bail out to drop locks if there is
  1399. * a gpu reset pending so that i915_error_work_func can acquire them).
  1400. */
  1401. /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
  1402. for_each_ring(ring, dev_priv, i)
  1403. wake_up_all(&ring->irq_queue);
  1404. /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
  1405. wake_up_all(&dev_priv->pending_flip_queue);
  1406. /*
  1407. * Signal tasks blocked in i915_gem_wait_for_error that the pending
  1408. * reset state is cleared.
  1409. */
  1410. if (reset_completed)
  1411. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1412. }
  1413. /**
  1414. * i915_error_work_func - do process context error handling work
  1415. * @work: work struct
  1416. *
  1417. * Fire an error uevent so userspace can see that a hang or error
  1418. * was detected.
  1419. */
  1420. static void i915_error_work_func(struct work_struct *work)
  1421. {
  1422. struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
  1423. work);
  1424. drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
  1425. gpu_error);
  1426. struct drm_device *dev = dev_priv->dev;
  1427. char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
  1428. char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
  1429. char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
  1430. int ret;
  1431. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
  1432. /*
  1433. * Note that there's only one work item which does gpu resets, so we
  1434. * need not worry about concurrent gpu resets potentially incrementing
  1435. * error->reset_counter twice. We only need to take care of another
  1436. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1437. * quick check for that is good enough: schedule_work ensures the
  1438. * correct ordering between hang detection and this work item, and since
  1439. * the reset in-progress bit is only ever set by code outside of this
  1440. * work we don't need to worry about any other races.
  1441. */
  1442. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1443. DRM_DEBUG_DRIVER("resetting chip\n");
  1444. kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
  1445. reset_event);
  1446. /*
  1447. * All state reset _must_ be completed before we update the
  1448. * reset counter, for otherwise waiters might miss the reset
  1449. * pending state and not properly drop locks, resulting in
  1450. * deadlocks with the reset work.
  1451. */
  1452. ret = i915_reset(dev);
  1453. intel_display_handle_reset(dev);
  1454. if (ret == 0) {
  1455. /*
  1456. * After all the gem state is reset, increment the reset
  1457. * counter and wake up everyone waiting for the reset to
  1458. * complete.
  1459. *
  1460. * Since unlock operations are a one-sided barrier only,
  1461. * we need to insert a barrier here to order any seqno
  1462. * updates before
  1463. * the counter increment.
  1464. */
  1465. smp_mb__before_atomic_inc();
  1466. atomic_inc(&dev_priv->gpu_error.reset_counter);
  1467. kobject_uevent_env(&dev->primary->kdev.kobj,
  1468. KOBJ_CHANGE, reset_done_event);
  1469. } else {
  1470. atomic_set(&error->reset_counter, I915_WEDGED);
  1471. }
  1472. /*
  1473. * Note: The wake_up also serves as a memory barrier so that
  1474. * waiters see the update value of the reset counter atomic_t.
  1475. */
  1476. i915_error_wake_up(dev_priv, true);
  1477. }
  1478. }
  1479. static void i915_report_and_clear_eir(struct drm_device *dev)
  1480. {
  1481. struct drm_i915_private *dev_priv = dev->dev_private;
  1482. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1483. u32 eir = I915_READ(EIR);
  1484. int pipe, i;
  1485. if (!eir)
  1486. return;
  1487. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1488. i915_get_extra_instdone(dev, instdone);
  1489. if (IS_G4X(dev)) {
  1490. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1491. u32 ipeir = I915_READ(IPEIR_I965);
  1492. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1493. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1494. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1495. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1496. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1497. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1498. I915_WRITE(IPEIR_I965, ipeir);
  1499. POSTING_READ(IPEIR_I965);
  1500. }
  1501. if (eir & GM45_ERROR_PAGE_TABLE) {
  1502. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1503. pr_err("page table error\n");
  1504. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1505. I915_WRITE(PGTBL_ER, pgtbl_err);
  1506. POSTING_READ(PGTBL_ER);
  1507. }
  1508. }
  1509. if (!IS_GEN2(dev)) {
  1510. if (eir & I915_ERROR_PAGE_TABLE) {
  1511. u32 pgtbl_err = I915_READ(PGTBL_ER);
  1512. pr_err("page table error\n");
  1513. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  1514. I915_WRITE(PGTBL_ER, pgtbl_err);
  1515. POSTING_READ(PGTBL_ER);
  1516. }
  1517. }
  1518. if (eir & I915_ERROR_MEMORY_REFRESH) {
  1519. pr_err("memory refresh error:\n");
  1520. for_each_pipe(pipe)
  1521. pr_err("pipe %c stat: 0x%08x\n",
  1522. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  1523. /* pipestat has already been acked */
  1524. }
  1525. if (eir & I915_ERROR_INSTRUCTION) {
  1526. pr_err("instruction error\n");
  1527. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  1528. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1529. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1530. if (INTEL_INFO(dev)->gen < 4) {
  1531. u32 ipeir = I915_READ(IPEIR);
  1532. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  1533. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  1534. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  1535. I915_WRITE(IPEIR, ipeir);
  1536. POSTING_READ(IPEIR);
  1537. } else {
  1538. u32 ipeir = I915_READ(IPEIR_I965);
  1539. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1540. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1541. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1542. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1543. I915_WRITE(IPEIR_I965, ipeir);
  1544. POSTING_READ(IPEIR_I965);
  1545. }
  1546. }
  1547. I915_WRITE(EIR, eir);
  1548. POSTING_READ(EIR);
  1549. eir = I915_READ(EIR);
  1550. if (eir) {
  1551. /*
  1552. * some errors might have become stuck,
  1553. * mask them.
  1554. */
  1555. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  1556. I915_WRITE(EMR, I915_READ(EMR) | eir);
  1557. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  1558. }
  1559. }
  1560. /**
  1561. * i915_handle_error - handle an error interrupt
  1562. * @dev: drm device
  1563. *
  1564. * Do some basic checking of regsiter state at error interrupt time and
  1565. * dump it to the syslog. Also call i915_capture_error_state() to make
  1566. * sure we get a record and make it available in debugfs. Fire a uevent
  1567. * so userspace knows something bad happened (should trigger collection
  1568. * of a ring dump etc.).
  1569. */
  1570. void i915_handle_error(struct drm_device *dev, bool wedged)
  1571. {
  1572. struct drm_i915_private *dev_priv = dev->dev_private;
  1573. i915_capture_error_state(dev);
  1574. i915_report_and_clear_eir(dev);
  1575. if (wedged) {
  1576. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  1577. &dev_priv->gpu_error.reset_counter);
  1578. /*
  1579. * Wakeup waiting processes so that the reset work function
  1580. * i915_error_work_func doesn't deadlock trying to grab various
  1581. * locks. By bumping the reset counter first, the woken
  1582. * processes will see a reset in progress and back off,
  1583. * releasing their locks and then wait for the reset completion.
  1584. * We must do this for _all_ gpu waiters that might hold locks
  1585. * that the reset work needs to acquire.
  1586. *
  1587. * Note: The wake_up serves as the required memory barrier to
  1588. * ensure that the waiters see the updated value of the reset
  1589. * counter atomic_t.
  1590. */
  1591. i915_error_wake_up(dev_priv, false);
  1592. }
  1593. /*
  1594. * Our reset work can grab modeset locks (since it needs to reset the
  1595. * state of outstanding pagelips). Hence it must not be run on our own
  1596. * dev-priv->wq work queue for otherwise the flush_work in the pageflip
  1597. * code will deadlock.
  1598. */
  1599. schedule_work(&dev_priv->gpu_error.work);
  1600. }
  1601. static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
  1602. {
  1603. drm_i915_private_t *dev_priv = dev->dev_private;
  1604. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1605. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1606. struct drm_i915_gem_object *obj;
  1607. struct intel_unpin_work *work;
  1608. unsigned long flags;
  1609. bool stall_detected;
  1610. /* Ignore early vblank irqs */
  1611. if (intel_crtc == NULL)
  1612. return;
  1613. spin_lock_irqsave(&dev->event_lock, flags);
  1614. work = intel_crtc->unpin_work;
  1615. if (work == NULL ||
  1616. atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
  1617. !work->enable_stall_check) {
  1618. /* Either the pending flip IRQ arrived, or we're too early. Don't check */
  1619. spin_unlock_irqrestore(&dev->event_lock, flags);
  1620. return;
  1621. }
  1622. /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
  1623. obj = work->pending_flip_obj;
  1624. if (INTEL_INFO(dev)->gen >= 4) {
  1625. int dspsurf = DSPSURF(intel_crtc->plane);
  1626. stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
  1627. i915_gem_obj_ggtt_offset(obj);
  1628. } else {
  1629. int dspaddr = DSPADDR(intel_crtc->plane);
  1630. stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
  1631. crtc->y * crtc->fb->pitches[0] +
  1632. crtc->x * crtc->fb->bits_per_pixel/8);
  1633. }
  1634. spin_unlock_irqrestore(&dev->event_lock, flags);
  1635. if (stall_detected) {
  1636. DRM_DEBUG_DRIVER("Pageflip stall detected\n");
  1637. intel_prepare_page_flip(dev, intel_crtc->plane);
  1638. }
  1639. }
  1640. /* Called from drm generic code, passed 'crtc' which
  1641. * we use as a pipe index
  1642. */
  1643. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  1644. {
  1645. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1646. unsigned long irqflags;
  1647. if (!i915_pipe_enabled(dev, pipe))
  1648. return -EINVAL;
  1649. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1650. if (INTEL_INFO(dev)->gen >= 4)
  1651. i915_enable_pipestat(dev_priv, pipe,
  1652. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1653. else
  1654. i915_enable_pipestat(dev_priv, pipe,
  1655. PIPE_VBLANK_INTERRUPT_ENABLE);
  1656. /* maintain vblank delivery even in deep C-states */
  1657. if (dev_priv->info->gen == 3)
  1658. I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
  1659. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1660. return 0;
  1661. }
  1662. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  1663. {
  1664. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1665. unsigned long irqflags;
  1666. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  1667. DE_PIPE_VBLANK_ILK(pipe);
  1668. if (!i915_pipe_enabled(dev, pipe))
  1669. return -EINVAL;
  1670. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1671. ironlake_enable_display_irq(dev_priv, bit);
  1672. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1673. return 0;
  1674. }
  1675. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  1676. {
  1677. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1678. unsigned long irqflags;
  1679. u32 imr;
  1680. if (!i915_pipe_enabled(dev, pipe))
  1681. return -EINVAL;
  1682. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1683. imr = I915_READ(VLV_IMR);
  1684. if (pipe == 0)
  1685. imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1686. else
  1687. imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1688. I915_WRITE(VLV_IMR, imr);
  1689. i915_enable_pipestat(dev_priv, pipe,
  1690. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1691. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1692. return 0;
  1693. }
  1694. /* Called from drm generic code, passed 'crtc' which
  1695. * we use as a pipe index
  1696. */
  1697. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  1698. {
  1699. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1700. unsigned long irqflags;
  1701. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1702. if (dev_priv->info->gen == 3)
  1703. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
  1704. i915_disable_pipestat(dev_priv, pipe,
  1705. PIPE_VBLANK_INTERRUPT_ENABLE |
  1706. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1707. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1708. }
  1709. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  1710. {
  1711. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1712. unsigned long irqflags;
  1713. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  1714. DE_PIPE_VBLANK_ILK(pipe);
  1715. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1716. ironlake_disable_display_irq(dev_priv, bit);
  1717. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1718. }
  1719. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  1720. {
  1721. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1722. unsigned long irqflags;
  1723. u32 imr;
  1724. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  1725. i915_disable_pipestat(dev_priv, pipe,
  1726. PIPE_START_VBLANK_INTERRUPT_ENABLE);
  1727. imr = I915_READ(VLV_IMR);
  1728. if (pipe == 0)
  1729. imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
  1730. else
  1731. imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  1732. I915_WRITE(VLV_IMR, imr);
  1733. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  1734. }
  1735. static u32
  1736. ring_last_seqno(struct intel_ring_buffer *ring)
  1737. {
  1738. return list_entry(ring->request_list.prev,
  1739. struct drm_i915_gem_request, list)->seqno;
  1740. }
  1741. static bool
  1742. ring_idle(struct intel_ring_buffer *ring, u32 seqno)
  1743. {
  1744. return (list_empty(&ring->request_list) ||
  1745. i915_seqno_passed(seqno, ring_last_seqno(ring)));
  1746. }
  1747. static struct intel_ring_buffer *
  1748. semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
  1749. {
  1750. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1751. u32 cmd, ipehr, acthd, acthd_min;
  1752. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  1753. if ((ipehr & ~(0x3 << 16)) !=
  1754. (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
  1755. return NULL;
  1756. /* ACTHD is likely pointing to the dword after the actual command,
  1757. * so scan backwards until we find the MBOX.
  1758. */
  1759. acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
  1760. acthd_min = max((int)acthd - 3 * 4, 0);
  1761. do {
  1762. cmd = ioread32(ring->virtual_start + acthd);
  1763. if (cmd == ipehr)
  1764. break;
  1765. acthd -= 4;
  1766. if (acthd < acthd_min)
  1767. return NULL;
  1768. } while (1);
  1769. *seqno = ioread32(ring->virtual_start+acthd+4)+1;
  1770. return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
  1771. }
  1772. static int semaphore_passed(struct intel_ring_buffer *ring)
  1773. {
  1774. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  1775. struct intel_ring_buffer *signaller;
  1776. u32 seqno, ctl;
  1777. ring->hangcheck.deadlock = true;
  1778. signaller = semaphore_waits_for(ring, &seqno);
  1779. if (signaller == NULL || signaller->hangcheck.deadlock)
  1780. return -1;
  1781. /* cursory check for an unkickable deadlock */
  1782. ctl = I915_READ_CTL(signaller);
  1783. if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
  1784. return -1;
  1785. return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
  1786. }
  1787. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  1788. {
  1789. struct intel_ring_buffer *ring;
  1790. int i;
  1791. for_each_ring(ring, dev_priv, i)
  1792. ring->hangcheck.deadlock = false;
  1793. }
  1794. static enum intel_ring_hangcheck_action
  1795. ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
  1796. {
  1797. struct drm_device *dev = ring->dev;
  1798. struct drm_i915_private *dev_priv = dev->dev_private;
  1799. u32 tmp;
  1800. if (ring->hangcheck.acthd != acthd)
  1801. return HANGCHECK_ACTIVE;
  1802. if (IS_GEN2(dev))
  1803. return HANGCHECK_HUNG;
  1804. /* Is the chip hanging on a WAIT_FOR_EVENT?
  1805. * If so we can simply poke the RB_WAIT bit
  1806. * and break the hang. This should work on
  1807. * all but the second generation chipsets.
  1808. */
  1809. tmp = I915_READ_CTL(ring);
  1810. if (tmp & RING_WAIT) {
  1811. DRM_ERROR("Kicking stuck wait on %s\n",
  1812. ring->name);
  1813. i915_handle_error(dev, false);
  1814. I915_WRITE_CTL(ring, tmp);
  1815. return HANGCHECK_KICK;
  1816. }
  1817. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  1818. switch (semaphore_passed(ring)) {
  1819. default:
  1820. return HANGCHECK_HUNG;
  1821. case 1:
  1822. DRM_ERROR("Kicking stuck semaphore on %s\n",
  1823. ring->name);
  1824. i915_handle_error(dev, false);
  1825. I915_WRITE_CTL(ring, tmp);
  1826. return HANGCHECK_KICK;
  1827. case 0:
  1828. return HANGCHECK_WAIT;
  1829. }
  1830. }
  1831. return HANGCHECK_HUNG;
  1832. }
  1833. /**
  1834. * This is called when the chip hasn't reported back with completed
  1835. * batchbuffers in a long time. We keep track per ring seqno progress and
  1836. * if there are no progress, hangcheck score for that ring is increased.
  1837. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  1838. * we kick the ring. If we see no progress on three subsequent calls
  1839. * we assume chip is wedged and try to fix it by resetting the chip.
  1840. */
  1841. static void i915_hangcheck_elapsed(unsigned long data)
  1842. {
  1843. struct drm_device *dev = (struct drm_device *)data;
  1844. drm_i915_private_t *dev_priv = dev->dev_private;
  1845. struct intel_ring_buffer *ring;
  1846. int i;
  1847. int busy_count = 0, rings_hung = 0;
  1848. bool stuck[I915_NUM_RINGS] = { 0 };
  1849. #define BUSY 1
  1850. #define KICK 5
  1851. #define HUNG 20
  1852. #define FIRE 30
  1853. if (!i915_enable_hangcheck)
  1854. return;
  1855. for_each_ring(ring, dev_priv, i) {
  1856. u32 seqno, acthd;
  1857. bool busy = true;
  1858. semaphore_clear_deadlocks(dev_priv);
  1859. seqno = ring->get_seqno(ring, false);
  1860. acthd = intel_ring_get_active_head(ring);
  1861. if (ring->hangcheck.seqno == seqno) {
  1862. if (ring_idle(ring, seqno)) {
  1863. ring->hangcheck.action = HANGCHECK_IDLE;
  1864. if (waitqueue_active(&ring->irq_queue)) {
  1865. /* Issue a wake-up to catch stuck h/w. */
  1866. if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
  1867. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  1868. ring->name);
  1869. wake_up_all(&ring->irq_queue);
  1870. }
  1871. /* Safeguard against driver failure */
  1872. ring->hangcheck.score += BUSY;
  1873. } else
  1874. busy = false;
  1875. } else {
  1876. /* We always increment the hangcheck score
  1877. * if the ring is busy and still processing
  1878. * the same request, so that no single request
  1879. * can run indefinitely (such as a chain of
  1880. * batches). The only time we do not increment
  1881. * the hangcheck score on this ring, if this
  1882. * ring is in a legitimate wait for another
  1883. * ring. In that case the waiting ring is a
  1884. * victim and we want to be sure we catch the
  1885. * right culprit. Then every time we do kick
  1886. * the ring, add a small increment to the
  1887. * score so that we can catch a batch that is
  1888. * being repeatedly kicked and so responsible
  1889. * for stalling the machine.
  1890. */
  1891. ring->hangcheck.action = ring_stuck(ring,
  1892. acthd);
  1893. switch (ring->hangcheck.action) {
  1894. case HANGCHECK_IDLE:
  1895. case HANGCHECK_WAIT:
  1896. break;
  1897. case HANGCHECK_ACTIVE:
  1898. ring->hangcheck.score += BUSY;
  1899. break;
  1900. case HANGCHECK_KICK:
  1901. ring->hangcheck.score += KICK;
  1902. break;
  1903. case HANGCHECK_HUNG:
  1904. ring->hangcheck.score += HUNG;
  1905. stuck[i] = true;
  1906. break;
  1907. }
  1908. }
  1909. } else {
  1910. ring->hangcheck.action = HANGCHECK_ACTIVE;
  1911. /* Gradually reduce the count so that we catch DoS
  1912. * attempts across multiple batches.
  1913. */
  1914. if (ring->hangcheck.score > 0)
  1915. ring->hangcheck.score--;
  1916. }
  1917. ring->hangcheck.seqno = seqno;
  1918. ring->hangcheck.acthd = acthd;
  1919. busy_count += busy;
  1920. }
  1921. for_each_ring(ring, dev_priv, i) {
  1922. if (ring->hangcheck.score > FIRE) {
  1923. DRM_INFO("%s on %s\n",
  1924. stuck[i] ? "stuck" : "no progress",
  1925. ring->name);
  1926. rings_hung++;
  1927. }
  1928. }
  1929. if (rings_hung)
  1930. return i915_handle_error(dev, true);
  1931. if (busy_count)
  1932. /* Reset timer case chip hangs without another request
  1933. * being added */
  1934. i915_queue_hangcheck(dev);
  1935. }
  1936. void i915_queue_hangcheck(struct drm_device *dev)
  1937. {
  1938. struct drm_i915_private *dev_priv = dev->dev_private;
  1939. if (!i915_enable_hangcheck)
  1940. return;
  1941. mod_timer(&dev_priv->gpu_error.hangcheck_timer,
  1942. round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
  1943. }
  1944. static void ibx_irq_preinstall(struct drm_device *dev)
  1945. {
  1946. struct drm_i915_private *dev_priv = dev->dev_private;
  1947. if (HAS_PCH_NOP(dev))
  1948. return;
  1949. /* south display irq */
  1950. I915_WRITE(SDEIMR, 0xffffffff);
  1951. /*
  1952. * SDEIER is also touched by the interrupt handler to work around missed
  1953. * PCH interrupts. Hence we can't update it after the interrupt handler
  1954. * is enabled - instead we unconditionally enable all PCH interrupt
  1955. * sources here, but then only unmask them as needed with SDEIMR.
  1956. */
  1957. I915_WRITE(SDEIER, 0xffffffff);
  1958. POSTING_READ(SDEIER);
  1959. }
  1960. static void gen5_gt_irq_preinstall(struct drm_device *dev)
  1961. {
  1962. struct drm_i915_private *dev_priv = dev->dev_private;
  1963. /* and GT */
  1964. I915_WRITE(GTIMR, 0xffffffff);
  1965. I915_WRITE(GTIER, 0x0);
  1966. POSTING_READ(GTIER);
  1967. if (INTEL_INFO(dev)->gen >= 6) {
  1968. /* and PM */
  1969. I915_WRITE(GEN6_PMIMR, 0xffffffff);
  1970. I915_WRITE(GEN6_PMIER, 0x0);
  1971. POSTING_READ(GEN6_PMIER);
  1972. }
  1973. }
  1974. /* drm_dma.h hooks
  1975. */
  1976. static void ironlake_irq_preinstall(struct drm_device *dev)
  1977. {
  1978. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1979. atomic_set(&dev_priv->irq_received, 0);
  1980. I915_WRITE(HWSTAM, 0xeffe);
  1981. I915_WRITE(DEIMR, 0xffffffff);
  1982. I915_WRITE(DEIER, 0x0);
  1983. POSTING_READ(DEIER);
  1984. gen5_gt_irq_preinstall(dev);
  1985. ibx_irq_preinstall(dev);
  1986. }
  1987. static void valleyview_irq_preinstall(struct drm_device *dev)
  1988. {
  1989. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  1990. int pipe;
  1991. atomic_set(&dev_priv->irq_received, 0);
  1992. /* VLV magic */
  1993. I915_WRITE(VLV_IMR, 0);
  1994. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  1995. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  1996. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  1997. /* and GT */
  1998. I915_WRITE(GTIIR, I915_READ(GTIIR));
  1999. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2000. gen5_gt_irq_preinstall(dev);
  2001. I915_WRITE(DPINVGTT, 0xff);
  2002. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2003. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2004. for_each_pipe(pipe)
  2005. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2006. I915_WRITE(VLV_IIR, 0xffffffff);
  2007. I915_WRITE(VLV_IMR, 0xffffffff);
  2008. I915_WRITE(VLV_IER, 0x0);
  2009. POSTING_READ(VLV_IER);
  2010. }
  2011. static void ibx_hpd_irq_setup(struct drm_device *dev)
  2012. {
  2013. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2014. struct drm_mode_config *mode_config = &dev->mode_config;
  2015. struct intel_encoder *intel_encoder;
  2016. u32 hotplug_irqs, hotplug, enabled_irqs = 0;
  2017. if (HAS_PCH_IBX(dev)) {
  2018. hotplug_irqs = SDE_HOTPLUG_MASK;
  2019. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2020. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2021. enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
  2022. } else {
  2023. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  2024. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2025. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2026. enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
  2027. }
  2028. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2029. /*
  2030. * Enable digital hotplug on the PCH, and configure the DP short pulse
  2031. * duration to 2ms (which is the minimum in the Display Port spec)
  2032. *
  2033. * This register is the same on all known PCH chips.
  2034. */
  2035. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  2036. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  2037. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  2038. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  2039. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  2040. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  2041. }
  2042. static void ibx_irq_postinstall(struct drm_device *dev)
  2043. {
  2044. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2045. u32 mask;
  2046. if (HAS_PCH_NOP(dev))
  2047. return;
  2048. if (HAS_PCH_IBX(dev)) {
  2049. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
  2050. SDE_TRANSA_FIFO_UNDER | SDE_POISON;
  2051. } else {
  2052. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
  2053. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  2054. }
  2055. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  2056. I915_WRITE(SDEIMR, ~mask);
  2057. }
  2058. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  2059. {
  2060. struct drm_i915_private *dev_priv = dev->dev_private;
  2061. u32 pm_irqs, gt_irqs;
  2062. pm_irqs = gt_irqs = 0;
  2063. dev_priv->gt_irq_mask = ~0;
  2064. if (HAS_L3_DPF(dev)) {
  2065. /* L3 parity interrupt is always unmasked. */
  2066. dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
  2067. gt_irqs |= GT_PARITY_ERROR(dev);
  2068. }
  2069. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  2070. if (IS_GEN5(dev)) {
  2071. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  2072. ILK_BSD_USER_INTERRUPT;
  2073. } else {
  2074. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  2075. }
  2076. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2077. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  2078. I915_WRITE(GTIER, gt_irqs);
  2079. POSTING_READ(GTIER);
  2080. if (INTEL_INFO(dev)->gen >= 6) {
  2081. pm_irqs |= GEN6_PM_RPS_EVENTS;
  2082. if (HAS_VEBOX(dev))
  2083. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  2084. dev_priv->pm_irq_mask = 0xffffffff;
  2085. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  2086. I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
  2087. I915_WRITE(GEN6_PMIER, pm_irqs);
  2088. POSTING_READ(GEN6_PMIER);
  2089. }
  2090. }
  2091. static int ironlake_irq_postinstall(struct drm_device *dev)
  2092. {
  2093. unsigned long irqflags;
  2094. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2095. u32 display_mask, extra_mask;
  2096. if (INTEL_INFO(dev)->gen >= 7) {
  2097. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  2098. DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
  2099. DE_PLANEB_FLIP_DONE_IVB |
  2100. DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
  2101. DE_ERR_INT_IVB);
  2102. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  2103. DE_PIPEA_VBLANK_IVB);
  2104. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  2105. } else {
  2106. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  2107. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  2108. DE_AUX_CHANNEL_A |
  2109. DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
  2110. DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
  2111. DE_POISON);
  2112. extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
  2113. }
  2114. dev_priv->irq_mask = ~display_mask;
  2115. /* should always can generate irq */
  2116. I915_WRITE(DEIIR, I915_READ(DEIIR));
  2117. I915_WRITE(DEIMR, dev_priv->irq_mask);
  2118. I915_WRITE(DEIER, display_mask | extra_mask);
  2119. POSTING_READ(DEIER);
  2120. gen5_gt_irq_postinstall(dev);
  2121. ibx_irq_postinstall(dev);
  2122. if (IS_IRONLAKE_M(dev)) {
  2123. /* Enable PCU event interrupts
  2124. *
  2125. * spinlocking not required here for correctness since interrupt
  2126. * setup is guaranteed to run in single-threaded context. But we
  2127. * need it to make the assert_spin_locked happy. */
  2128. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2129. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  2130. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2131. }
  2132. return 0;
  2133. }
  2134. static int valleyview_irq_postinstall(struct drm_device *dev)
  2135. {
  2136. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2137. u32 enable_mask;
  2138. u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV |
  2139. PIPE_CRC_DONE_ENABLE;
  2140. unsigned long irqflags;
  2141. enable_mask = I915_DISPLAY_PORT_INTERRUPT;
  2142. enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2143. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  2144. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2145. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  2146. /*
  2147. *Leave vblank interrupts masked initially. enable/disable will
  2148. * toggle them based on usage.
  2149. */
  2150. dev_priv->irq_mask = (~enable_mask) |
  2151. I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
  2152. I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
  2153. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2154. POSTING_READ(PORT_HOTPLUG_EN);
  2155. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2156. I915_WRITE(VLV_IER, enable_mask);
  2157. I915_WRITE(VLV_IIR, 0xffffffff);
  2158. I915_WRITE(PIPESTAT(0), 0xffff);
  2159. I915_WRITE(PIPESTAT(1), 0xffff);
  2160. POSTING_READ(VLV_IER);
  2161. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2162. * just to make the assert_spin_locked check happy. */
  2163. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2164. i915_enable_pipestat(dev_priv, 0, pipestat_enable);
  2165. i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
  2166. i915_enable_pipestat(dev_priv, 1, pipestat_enable);
  2167. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2168. I915_WRITE(VLV_IIR, 0xffffffff);
  2169. I915_WRITE(VLV_IIR, 0xffffffff);
  2170. gen5_gt_irq_postinstall(dev);
  2171. /* ack & enable invalid PTE error interrupts */
  2172. #if 0 /* FIXME: add support to irq handler for checking these bits */
  2173. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2174. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  2175. #endif
  2176. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  2177. return 0;
  2178. }
  2179. static void valleyview_irq_uninstall(struct drm_device *dev)
  2180. {
  2181. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2182. int pipe;
  2183. if (!dev_priv)
  2184. return;
  2185. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2186. for_each_pipe(pipe)
  2187. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2188. I915_WRITE(HWSTAM, 0xffffffff);
  2189. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2190. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2191. for_each_pipe(pipe)
  2192. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2193. I915_WRITE(VLV_IIR, 0xffffffff);
  2194. I915_WRITE(VLV_IMR, 0xffffffff);
  2195. I915_WRITE(VLV_IER, 0x0);
  2196. POSTING_READ(VLV_IER);
  2197. }
  2198. static void ironlake_irq_uninstall(struct drm_device *dev)
  2199. {
  2200. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2201. if (!dev_priv)
  2202. return;
  2203. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2204. I915_WRITE(HWSTAM, 0xffffffff);
  2205. I915_WRITE(DEIMR, 0xffffffff);
  2206. I915_WRITE(DEIER, 0x0);
  2207. I915_WRITE(DEIIR, I915_READ(DEIIR));
  2208. if (IS_GEN7(dev))
  2209. I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
  2210. I915_WRITE(GTIMR, 0xffffffff);
  2211. I915_WRITE(GTIER, 0x0);
  2212. I915_WRITE(GTIIR, I915_READ(GTIIR));
  2213. if (HAS_PCH_NOP(dev))
  2214. return;
  2215. I915_WRITE(SDEIMR, 0xffffffff);
  2216. I915_WRITE(SDEIER, 0x0);
  2217. I915_WRITE(SDEIIR, I915_READ(SDEIIR));
  2218. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  2219. I915_WRITE(SERR_INT, I915_READ(SERR_INT));
  2220. }
  2221. static void i8xx_irq_preinstall(struct drm_device * dev)
  2222. {
  2223. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2224. int pipe;
  2225. atomic_set(&dev_priv->irq_received, 0);
  2226. for_each_pipe(pipe)
  2227. I915_WRITE(PIPESTAT(pipe), 0);
  2228. I915_WRITE16(IMR, 0xffff);
  2229. I915_WRITE16(IER, 0x0);
  2230. POSTING_READ16(IER);
  2231. }
  2232. static int i8xx_irq_postinstall(struct drm_device *dev)
  2233. {
  2234. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2235. unsigned long irqflags;
  2236. I915_WRITE16(EMR,
  2237. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2238. /* Unmask the interrupts that we always want on. */
  2239. dev_priv->irq_mask =
  2240. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2241. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2242. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2243. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2244. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2245. I915_WRITE16(IMR, dev_priv->irq_mask);
  2246. I915_WRITE16(IER,
  2247. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2248. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2249. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2250. I915_USER_INTERRUPT);
  2251. POSTING_READ16(IER);
  2252. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2253. * just to make the assert_spin_locked check happy. */
  2254. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2255. i915_enable_pipestat(dev_priv, 0, PIPE_CRC_DONE_ENABLE);
  2256. i915_enable_pipestat(dev_priv, 1, PIPE_CRC_DONE_ENABLE);
  2257. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2258. return 0;
  2259. }
  2260. /*
  2261. * Returns true when a page flip has completed.
  2262. */
  2263. static bool i8xx_handle_vblank(struct drm_device *dev,
  2264. int pipe, u16 iir)
  2265. {
  2266. drm_i915_private_t *dev_priv = dev->dev_private;
  2267. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
  2268. if (!drm_handle_vblank(dev, pipe))
  2269. return false;
  2270. if ((iir & flip_pending) == 0)
  2271. return false;
  2272. intel_prepare_page_flip(dev, pipe);
  2273. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2274. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2275. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2276. * the flip is completed (no longer pending). Since this doesn't raise
  2277. * an interrupt per se, we watch for the change at vblank.
  2278. */
  2279. if (I915_READ16(ISR) & flip_pending)
  2280. return false;
  2281. intel_finish_page_flip(dev, pipe);
  2282. return true;
  2283. }
  2284. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  2285. {
  2286. struct drm_device *dev = (struct drm_device *) arg;
  2287. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2288. u16 iir, new_iir;
  2289. u32 pipe_stats[2];
  2290. unsigned long irqflags;
  2291. int pipe;
  2292. u16 flip_mask =
  2293. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2294. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2295. atomic_inc(&dev_priv->irq_received);
  2296. iir = I915_READ16(IIR);
  2297. if (iir == 0)
  2298. return IRQ_NONE;
  2299. while (iir & ~flip_mask) {
  2300. /* Can't rely on pipestat interrupt bit in iir as it might
  2301. * have been cleared after the pipestat interrupt was received.
  2302. * It doesn't set the bit in iir again, but it still produces
  2303. * interrupts (for non-MSI).
  2304. */
  2305. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2306. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2307. i915_handle_error(dev, false);
  2308. for_each_pipe(pipe) {
  2309. int reg = PIPESTAT(pipe);
  2310. pipe_stats[pipe] = I915_READ(reg);
  2311. /*
  2312. * Clear the PIPE*STAT regs before the IIR
  2313. */
  2314. if (pipe_stats[pipe] & 0x8000ffff) {
  2315. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2316. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2317. pipe_name(pipe));
  2318. I915_WRITE(reg, pipe_stats[pipe]);
  2319. }
  2320. }
  2321. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2322. I915_WRITE16(IIR, iir & ~flip_mask);
  2323. new_iir = I915_READ16(IIR); /* Flush posted writes */
  2324. i915_update_dri1_breadcrumb(dev);
  2325. if (iir & I915_USER_INTERRUPT)
  2326. notify_ring(dev, &dev_priv->ring[RCS]);
  2327. for_each_pipe(pipe) {
  2328. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2329. i8xx_handle_vblank(dev, pipe, iir))
  2330. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  2331. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  2332. i9xx_pipe_crc_irq_handler(dev, pipe);
  2333. }
  2334. iir = new_iir;
  2335. }
  2336. return IRQ_HANDLED;
  2337. }
  2338. static void i8xx_irq_uninstall(struct drm_device * dev)
  2339. {
  2340. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2341. int pipe;
  2342. for_each_pipe(pipe) {
  2343. /* Clear enable bits; then clear status bits */
  2344. I915_WRITE(PIPESTAT(pipe), 0);
  2345. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2346. }
  2347. I915_WRITE16(IMR, 0xffff);
  2348. I915_WRITE16(IER, 0x0);
  2349. I915_WRITE16(IIR, I915_READ16(IIR));
  2350. }
  2351. static void i915_irq_preinstall(struct drm_device * dev)
  2352. {
  2353. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2354. int pipe;
  2355. atomic_set(&dev_priv->irq_received, 0);
  2356. if (I915_HAS_HOTPLUG(dev)) {
  2357. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2358. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2359. }
  2360. I915_WRITE16(HWSTAM, 0xeffe);
  2361. for_each_pipe(pipe)
  2362. I915_WRITE(PIPESTAT(pipe), 0);
  2363. I915_WRITE(IMR, 0xffffffff);
  2364. I915_WRITE(IER, 0x0);
  2365. POSTING_READ(IER);
  2366. }
  2367. static int i915_irq_postinstall(struct drm_device *dev)
  2368. {
  2369. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2370. u32 enable_mask;
  2371. unsigned long irqflags;
  2372. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2373. /* Unmask the interrupts that we always want on. */
  2374. dev_priv->irq_mask =
  2375. ~(I915_ASLE_INTERRUPT |
  2376. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2377. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2378. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2379. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2380. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2381. enable_mask =
  2382. I915_ASLE_INTERRUPT |
  2383. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2384. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2385. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
  2386. I915_USER_INTERRUPT;
  2387. if (I915_HAS_HOTPLUG(dev)) {
  2388. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2389. POSTING_READ(PORT_HOTPLUG_EN);
  2390. /* Enable in IER... */
  2391. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  2392. /* and unmask in IMR */
  2393. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  2394. }
  2395. I915_WRITE(IMR, dev_priv->irq_mask);
  2396. I915_WRITE(IER, enable_mask);
  2397. POSTING_READ(IER);
  2398. i915_enable_asle_pipestat(dev);
  2399. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2400. * just to make the assert_spin_locked check happy. */
  2401. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2402. i915_enable_pipestat(dev_priv, 0, PIPE_CRC_DONE_ENABLE);
  2403. i915_enable_pipestat(dev_priv, 1, PIPE_CRC_DONE_ENABLE);
  2404. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2405. return 0;
  2406. }
  2407. /*
  2408. * Returns true when a page flip has completed.
  2409. */
  2410. static bool i915_handle_vblank(struct drm_device *dev,
  2411. int plane, int pipe, u32 iir)
  2412. {
  2413. drm_i915_private_t *dev_priv = dev->dev_private;
  2414. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  2415. if (!drm_handle_vblank(dev, pipe))
  2416. return false;
  2417. if ((iir & flip_pending) == 0)
  2418. return false;
  2419. intel_prepare_page_flip(dev, plane);
  2420. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2421. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2422. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2423. * the flip is completed (no longer pending). Since this doesn't raise
  2424. * an interrupt per se, we watch for the change at vblank.
  2425. */
  2426. if (I915_READ(ISR) & flip_pending)
  2427. return false;
  2428. intel_finish_page_flip(dev, pipe);
  2429. return true;
  2430. }
  2431. static irqreturn_t i915_irq_handler(int irq, void *arg)
  2432. {
  2433. struct drm_device *dev = (struct drm_device *) arg;
  2434. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2435. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  2436. unsigned long irqflags;
  2437. u32 flip_mask =
  2438. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2439. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2440. int pipe, ret = IRQ_NONE;
  2441. atomic_inc(&dev_priv->irq_received);
  2442. iir = I915_READ(IIR);
  2443. do {
  2444. bool irq_received = (iir & ~flip_mask) != 0;
  2445. bool blc_event = false;
  2446. /* Can't rely on pipestat interrupt bit in iir as it might
  2447. * have been cleared after the pipestat interrupt was received.
  2448. * It doesn't set the bit in iir again, but it still produces
  2449. * interrupts (for non-MSI).
  2450. */
  2451. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2452. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2453. i915_handle_error(dev, false);
  2454. for_each_pipe(pipe) {
  2455. int reg = PIPESTAT(pipe);
  2456. pipe_stats[pipe] = I915_READ(reg);
  2457. /* Clear the PIPE*STAT regs before the IIR */
  2458. if (pipe_stats[pipe] & 0x8000ffff) {
  2459. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2460. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2461. pipe_name(pipe));
  2462. I915_WRITE(reg, pipe_stats[pipe]);
  2463. irq_received = true;
  2464. }
  2465. }
  2466. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2467. if (!irq_received)
  2468. break;
  2469. /* Consume port. Then clear IIR or we'll miss events */
  2470. if ((I915_HAS_HOTPLUG(dev)) &&
  2471. (iir & I915_DISPLAY_PORT_INTERRUPT)) {
  2472. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2473. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  2474. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2475. hotplug_status);
  2476. intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
  2477. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2478. POSTING_READ(PORT_HOTPLUG_STAT);
  2479. }
  2480. I915_WRITE(IIR, iir & ~flip_mask);
  2481. new_iir = I915_READ(IIR); /* Flush posted writes */
  2482. if (iir & I915_USER_INTERRUPT)
  2483. notify_ring(dev, &dev_priv->ring[RCS]);
  2484. for_each_pipe(pipe) {
  2485. int plane = pipe;
  2486. if (IS_MOBILE(dev))
  2487. plane = !plane;
  2488. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  2489. i915_handle_vblank(dev, plane, pipe, iir))
  2490. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  2491. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2492. blc_event = true;
  2493. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  2494. i9xx_pipe_crc_irq_handler(dev, pipe);
  2495. }
  2496. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2497. intel_opregion_asle_intr(dev);
  2498. /* With MSI, interrupts are only generated when iir
  2499. * transitions from zero to nonzero. If another bit got
  2500. * set while we were handling the existing iir bits, then
  2501. * we would never get another interrupt.
  2502. *
  2503. * This is fine on non-MSI as well, as if we hit this path
  2504. * we avoid exiting the interrupt handler only to generate
  2505. * another one.
  2506. *
  2507. * Note that for MSI this could cause a stray interrupt report
  2508. * if an interrupt landed in the time between writing IIR and
  2509. * the posting read. This should be rare enough to never
  2510. * trigger the 99% of 100,000 interrupts test for disabling
  2511. * stray interrupts.
  2512. */
  2513. ret = IRQ_HANDLED;
  2514. iir = new_iir;
  2515. } while (iir & ~flip_mask);
  2516. i915_update_dri1_breadcrumb(dev);
  2517. return ret;
  2518. }
  2519. static void i915_irq_uninstall(struct drm_device * dev)
  2520. {
  2521. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2522. int pipe;
  2523. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2524. if (I915_HAS_HOTPLUG(dev)) {
  2525. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2526. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2527. }
  2528. I915_WRITE16(HWSTAM, 0xffff);
  2529. for_each_pipe(pipe) {
  2530. /* Clear enable bits; then clear status bits */
  2531. I915_WRITE(PIPESTAT(pipe), 0);
  2532. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  2533. }
  2534. I915_WRITE(IMR, 0xffffffff);
  2535. I915_WRITE(IER, 0x0);
  2536. I915_WRITE(IIR, I915_READ(IIR));
  2537. }
  2538. static void i965_irq_preinstall(struct drm_device * dev)
  2539. {
  2540. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2541. int pipe;
  2542. atomic_set(&dev_priv->irq_received, 0);
  2543. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2544. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2545. I915_WRITE(HWSTAM, 0xeffe);
  2546. for_each_pipe(pipe)
  2547. I915_WRITE(PIPESTAT(pipe), 0);
  2548. I915_WRITE(IMR, 0xffffffff);
  2549. I915_WRITE(IER, 0x0);
  2550. POSTING_READ(IER);
  2551. }
  2552. static int i965_irq_postinstall(struct drm_device *dev)
  2553. {
  2554. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2555. u32 enable_mask;
  2556. u32 error_mask;
  2557. unsigned long irqflags;
  2558. /* Unmask the interrupts that we always want on. */
  2559. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  2560. I915_DISPLAY_PORT_INTERRUPT |
  2561. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2562. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2563. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2564. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  2565. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2566. enable_mask = ~dev_priv->irq_mask;
  2567. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2568. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  2569. enable_mask |= I915_USER_INTERRUPT;
  2570. if (IS_G4X(dev))
  2571. enable_mask |= I915_BSD_USER_INTERRUPT;
  2572. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2573. * just to make the assert_spin_locked check happy. */
  2574. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2575. i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
  2576. i915_enable_pipestat(dev_priv, 0, PIPE_CRC_DONE_ENABLE);
  2577. i915_enable_pipestat(dev_priv, 1, PIPE_CRC_DONE_ENABLE);
  2578. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2579. /*
  2580. * Enable some error detection, note the instruction error mask
  2581. * bit is reserved, so we leave it masked.
  2582. */
  2583. if (IS_G4X(dev)) {
  2584. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  2585. GM45_ERROR_MEM_PRIV |
  2586. GM45_ERROR_CP_PRIV |
  2587. I915_ERROR_MEMORY_REFRESH);
  2588. } else {
  2589. error_mask = ~(I915_ERROR_PAGE_TABLE |
  2590. I915_ERROR_MEMORY_REFRESH);
  2591. }
  2592. I915_WRITE(EMR, error_mask);
  2593. I915_WRITE(IMR, dev_priv->irq_mask);
  2594. I915_WRITE(IER, enable_mask);
  2595. POSTING_READ(IER);
  2596. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2597. POSTING_READ(PORT_HOTPLUG_EN);
  2598. i915_enable_asle_pipestat(dev);
  2599. return 0;
  2600. }
  2601. static void i915_hpd_irq_setup(struct drm_device *dev)
  2602. {
  2603. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2604. struct drm_mode_config *mode_config = &dev->mode_config;
  2605. struct intel_encoder *intel_encoder;
  2606. u32 hotplug_en;
  2607. assert_spin_locked(&dev_priv->irq_lock);
  2608. if (I915_HAS_HOTPLUG(dev)) {
  2609. hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  2610. hotplug_en &= ~HOTPLUG_INT_EN_MASK;
  2611. /* Note HDMI and DP share hotplug bits */
  2612. /* enable bits are the same for all generations */
  2613. list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
  2614. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2615. hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
  2616. /* Programming the CRT detection parameters tends
  2617. to generate a spurious hotplug event about three
  2618. seconds later. So just do it once.
  2619. */
  2620. if (IS_G4X(dev))
  2621. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  2622. hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
  2623. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  2624. /* Ignore TV since it's buggy */
  2625. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  2626. }
  2627. }
  2628. static irqreturn_t i965_irq_handler(int irq, void *arg)
  2629. {
  2630. struct drm_device *dev = (struct drm_device *) arg;
  2631. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2632. u32 iir, new_iir;
  2633. u32 pipe_stats[I915_MAX_PIPES];
  2634. unsigned long irqflags;
  2635. int irq_received;
  2636. int ret = IRQ_NONE, pipe;
  2637. u32 flip_mask =
  2638. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2639. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  2640. atomic_inc(&dev_priv->irq_received);
  2641. iir = I915_READ(IIR);
  2642. for (;;) {
  2643. bool blc_event = false;
  2644. irq_received = (iir & ~flip_mask) != 0;
  2645. /* Can't rely on pipestat interrupt bit in iir as it might
  2646. * have been cleared after the pipestat interrupt was received.
  2647. * It doesn't set the bit in iir again, but it still produces
  2648. * interrupts (for non-MSI).
  2649. */
  2650. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2651. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  2652. i915_handle_error(dev, false);
  2653. for_each_pipe(pipe) {
  2654. int reg = PIPESTAT(pipe);
  2655. pipe_stats[pipe] = I915_READ(reg);
  2656. /*
  2657. * Clear the PIPE*STAT regs before the IIR
  2658. */
  2659. if (pipe_stats[pipe] & 0x8000ffff) {
  2660. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  2661. DRM_DEBUG_DRIVER("pipe %c underrun\n",
  2662. pipe_name(pipe));
  2663. I915_WRITE(reg, pipe_stats[pipe]);
  2664. irq_received = 1;
  2665. }
  2666. }
  2667. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2668. if (!irq_received)
  2669. break;
  2670. ret = IRQ_HANDLED;
  2671. /* Consume port. Then clear IIR or we'll miss events */
  2672. if (iir & I915_DISPLAY_PORT_INTERRUPT) {
  2673. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  2674. u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
  2675. HOTPLUG_INT_STATUS_G4X :
  2676. HOTPLUG_INT_STATUS_I915);
  2677. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
  2678. hotplug_status);
  2679. intel_hpd_irq_handler(dev, hotplug_trigger,
  2680. IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
  2681. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  2682. I915_READ(PORT_HOTPLUG_STAT);
  2683. }
  2684. I915_WRITE(IIR, iir & ~flip_mask);
  2685. new_iir = I915_READ(IIR); /* Flush posted writes */
  2686. if (iir & I915_USER_INTERRUPT)
  2687. notify_ring(dev, &dev_priv->ring[RCS]);
  2688. if (iir & I915_BSD_USER_INTERRUPT)
  2689. notify_ring(dev, &dev_priv->ring[VCS]);
  2690. for_each_pipe(pipe) {
  2691. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  2692. i915_handle_vblank(dev, pipe, pipe, iir))
  2693. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  2694. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  2695. blc_event = true;
  2696. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  2697. i9xx_pipe_crc_irq_handler(dev, pipe);
  2698. }
  2699. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  2700. intel_opregion_asle_intr(dev);
  2701. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  2702. gmbus_irq_handler(dev);
  2703. /* With MSI, interrupts are only generated when iir
  2704. * transitions from zero to nonzero. If another bit got
  2705. * set while we were handling the existing iir bits, then
  2706. * we would never get another interrupt.
  2707. *
  2708. * This is fine on non-MSI as well, as if we hit this path
  2709. * we avoid exiting the interrupt handler only to generate
  2710. * another one.
  2711. *
  2712. * Note that for MSI this could cause a stray interrupt report
  2713. * if an interrupt landed in the time between writing IIR and
  2714. * the posting read. This should be rare enough to never
  2715. * trigger the 99% of 100,000 interrupts test for disabling
  2716. * stray interrupts.
  2717. */
  2718. iir = new_iir;
  2719. }
  2720. i915_update_dri1_breadcrumb(dev);
  2721. return ret;
  2722. }
  2723. static void i965_irq_uninstall(struct drm_device * dev)
  2724. {
  2725. drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
  2726. int pipe;
  2727. if (!dev_priv)
  2728. return;
  2729. del_timer_sync(&dev_priv->hotplug_reenable_timer);
  2730. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2731. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2732. I915_WRITE(HWSTAM, 0xffffffff);
  2733. for_each_pipe(pipe)
  2734. I915_WRITE(PIPESTAT(pipe), 0);
  2735. I915_WRITE(IMR, 0xffffffff);
  2736. I915_WRITE(IER, 0x0);
  2737. for_each_pipe(pipe)
  2738. I915_WRITE(PIPESTAT(pipe),
  2739. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  2740. I915_WRITE(IIR, I915_READ(IIR));
  2741. }
  2742. static void i915_reenable_hotplug_timer_func(unsigned long data)
  2743. {
  2744. drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
  2745. struct drm_device *dev = dev_priv->dev;
  2746. struct drm_mode_config *mode_config = &dev->mode_config;
  2747. unsigned long irqflags;
  2748. int i;
  2749. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2750. for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
  2751. struct drm_connector *connector;
  2752. if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
  2753. continue;
  2754. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  2755. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2756. struct intel_connector *intel_connector = to_intel_connector(connector);
  2757. if (intel_connector->encoder->hpd_pin == i) {
  2758. if (connector->polled != intel_connector->polled)
  2759. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  2760. drm_get_connector_name(connector));
  2761. connector->polled = intel_connector->polled;
  2762. if (!connector->polled)
  2763. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2764. }
  2765. }
  2766. }
  2767. if (dev_priv->display.hpd_irq_setup)
  2768. dev_priv->display.hpd_irq_setup(dev);
  2769. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2770. }
  2771. void intel_irq_init(struct drm_device *dev)
  2772. {
  2773. struct drm_i915_private *dev_priv = dev->dev_private;
  2774. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  2775. INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
  2776. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  2777. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  2778. setup_timer(&dev_priv->gpu_error.hangcheck_timer,
  2779. i915_hangcheck_elapsed,
  2780. (unsigned long) dev);
  2781. setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
  2782. (unsigned long) dev_priv);
  2783. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  2784. if (IS_GEN2(dev)) {
  2785. dev->max_vblank_count = 0;
  2786. dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
  2787. } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  2788. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  2789. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  2790. } else {
  2791. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  2792. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  2793. }
  2794. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  2795. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  2796. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  2797. }
  2798. if (IS_VALLEYVIEW(dev)) {
  2799. dev->driver->irq_handler = valleyview_irq_handler;
  2800. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  2801. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  2802. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  2803. dev->driver->enable_vblank = valleyview_enable_vblank;
  2804. dev->driver->disable_vblank = valleyview_disable_vblank;
  2805. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2806. } else if (HAS_PCH_SPLIT(dev)) {
  2807. dev->driver->irq_handler = ironlake_irq_handler;
  2808. dev->driver->irq_preinstall = ironlake_irq_preinstall;
  2809. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  2810. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  2811. dev->driver->enable_vblank = ironlake_enable_vblank;
  2812. dev->driver->disable_vblank = ironlake_disable_vblank;
  2813. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  2814. } else {
  2815. if (INTEL_INFO(dev)->gen == 2) {
  2816. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  2817. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  2818. dev->driver->irq_handler = i8xx_irq_handler;
  2819. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  2820. } else if (INTEL_INFO(dev)->gen == 3) {
  2821. dev->driver->irq_preinstall = i915_irq_preinstall;
  2822. dev->driver->irq_postinstall = i915_irq_postinstall;
  2823. dev->driver->irq_uninstall = i915_irq_uninstall;
  2824. dev->driver->irq_handler = i915_irq_handler;
  2825. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2826. } else {
  2827. dev->driver->irq_preinstall = i965_irq_preinstall;
  2828. dev->driver->irq_postinstall = i965_irq_postinstall;
  2829. dev->driver->irq_uninstall = i965_irq_uninstall;
  2830. dev->driver->irq_handler = i965_irq_handler;
  2831. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  2832. }
  2833. dev->driver->enable_vblank = i915_enable_vblank;
  2834. dev->driver->disable_vblank = i915_disable_vblank;
  2835. }
  2836. }
  2837. void intel_hpd_init(struct drm_device *dev)
  2838. {
  2839. struct drm_i915_private *dev_priv = dev->dev_private;
  2840. struct drm_mode_config *mode_config = &dev->mode_config;
  2841. struct drm_connector *connector;
  2842. unsigned long irqflags;
  2843. int i;
  2844. for (i = 1; i < HPD_NUM_PINS; i++) {
  2845. dev_priv->hpd_stats[i].hpd_cnt = 0;
  2846. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  2847. }
  2848. list_for_each_entry(connector, &mode_config->connector_list, head) {
  2849. struct intel_connector *intel_connector = to_intel_connector(connector);
  2850. connector->polled = intel_connector->polled;
  2851. if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
  2852. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2853. }
  2854. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2855. * just to make the assert_spin_locked checks happy. */
  2856. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2857. if (dev_priv->display.hpd_irq_setup)
  2858. dev_priv->display.hpd_irq_setup(dev);
  2859. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2860. }
  2861. /* Disable interrupts so we can allow Package C8+. */
  2862. void hsw_pc8_disable_interrupts(struct drm_device *dev)
  2863. {
  2864. struct drm_i915_private *dev_priv = dev->dev_private;
  2865. unsigned long irqflags;
  2866. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2867. dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
  2868. dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
  2869. dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
  2870. dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
  2871. dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
  2872. ironlake_disable_display_irq(dev_priv, ~DE_PCH_EVENT_IVB);
  2873. ibx_disable_display_interrupt(dev_priv, ~SDE_HOTPLUG_MASK_CPT);
  2874. ilk_disable_gt_irq(dev_priv, 0xffffffff);
  2875. snb_disable_pm_irq(dev_priv, 0xffffffff);
  2876. dev_priv->pc8.irqs_disabled = true;
  2877. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2878. }
  2879. /* Restore interrupts so we can recover from Package C8+. */
  2880. void hsw_pc8_restore_interrupts(struct drm_device *dev)
  2881. {
  2882. struct drm_i915_private *dev_priv = dev->dev_private;
  2883. unsigned long irqflags;
  2884. uint32_t val, expected;
  2885. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2886. val = I915_READ(DEIMR);
  2887. expected = ~DE_PCH_EVENT_IVB;
  2888. WARN(val != expected, "DEIMR is 0x%08x, not 0x%08x\n", val, expected);
  2889. val = I915_READ(SDEIMR) & ~SDE_HOTPLUG_MASK_CPT;
  2890. expected = ~SDE_HOTPLUG_MASK_CPT;
  2891. WARN(val != expected, "SDEIMR non-HPD bits are 0x%08x, not 0x%08x\n",
  2892. val, expected);
  2893. val = I915_READ(GTIMR);
  2894. expected = 0xffffffff;
  2895. WARN(val != expected, "GTIMR is 0x%08x, not 0x%08x\n", val, expected);
  2896. val = I915_READ(GEN6_PMIMR);
  2897. expected = 0xffffffff;
  2898. WARN(val != expected, "GEN6_PMIMR is 0x%08x, not 0x%08x\n", val,
  2899. expected);
  2900. dev_priv->pc8.irqs_disabled = false;
  2901. ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
  2902. ibx_enable_display_interrupt(dev_priv,
  2903. ~dev_priv->pc8.regsave.sdeimr &
  2904. ~SDE_HOTPLUG_MASK_CPT);
  2905. ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
  2906. snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
  2907. I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
  2908. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2909. }