i915_irq.c 103 KB

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