i915_irq.c 101 KB

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