i915_irq.c 91 KB

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