i915_irq.c 98 KB

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