i915_irq.c 109 KB

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