i915_irq.c 109 KB

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