i915_irq.c 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433
  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. /**
  38. * DOC: interrupt handling
  39. *
  40. * These functions provide the basic support for enabling and disabling the
  41. * interrupt handling support. There's a lot more functionality in i915_irq.c
  42. * and related files, but that will be described in separate chapters.
  43. */
  44. static const u32 hpd_ibx[HPD_NUM_PINS] = {
  45. [HPD_CRT] = SDE_CRT_HOTPLUG,
  46. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
  47. [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
  48. [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
  49. [HPD_PORT_D] = SDE_PORTD_HOTPLUG
  50. };
  51. static const u32 hpd_cpt[HPD_NUM_PINS] = {
  52. [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
  53. [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
  54. [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
  55. [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
  56. [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
  57. };
  58. static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
  59. [HPD_CRT] = CRT_HOTPLUG_INT_EN,
  60. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
  61. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
  62. [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
  63. [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
  64. [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
  65. };
  66. static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
  67. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  68. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
  69. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
  70. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  71. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  72. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
  73. };
  74. static const u32 hpd_status_i915[HPD_NUM_PINS] = { /* i915 and valleyview are the same */
  75. [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
  76. [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
  77. [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
  78. [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
  79. [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
  80. [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
  81. };
  82. /* IIR can theoretically queue up two events. Be paranoid. */
  83. #define GEN8_IRQ_RESET_NDX(type, which) do { \
  84. I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
  85. POSTING_READ(GEN8_##type##_IMR(which)); \
  86. I915_WRITE(GEN8_##type##_IER(which), 0); \
  87. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  88. POSTING_READ(GEN8_##type##_IIR(which)); \
  89. I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
  90. POSTING_READ(GEN8_##type##_IIR(which)); \
  91. } while (0)
  92. #define GEN5_IRQ_RESET(type) do { \
  93. I915_WRITE(type##IMR, 0xffffffff); \
  94. POSTING_READ(type##IMR); \
  95. I915_WRITE(type##IER, 0); \
  96. I915_WRITE(type##IIR, 0xffffffff); \
  97. POSTING_READ(type##IIR); \
  98. I915_WRITE(type##IIR, 0xffffffff); \
  99. POSTING_READ(type##IIR); \
  100. } while (0)
  101. /*
  102. * We should clear IMR at preinstall/uninstall, and just check at postinstall.
  103. */
  104. #define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \
  105. u32 val = I915_READ(reg); \
  106. if (val) { \
  107. WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \
  108. (reg), val); \
  109. I915_WRITE((reg), 0xffffffff); \
  110. POSTING_READ(reg); \
  111. I915_WRITE((reg), 0xffffffff); \
  112. POSTING_READ(reg); \
  113. } \
  114. } while (0)
  115. #define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
  116. GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \
  117. I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
  118. I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
  119. POSTING_READ(GEN8_##type##_IMR(which)); \
  120. } while (0)
  121. #define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
  122. GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \
  123. I915_WRITE(type##IER, (ier_val)); \
  124. I915_WRITE(type##IMR, (imr_val)); \
  125. POSTING_READ(type##IMR); \
  126. } while (0)
  127. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
  128. /* For display hotplug interrupt */
  129. void
  130. ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
  131. {
  132. assert_spin_locked(&dev_priv->irq_lock);
  133. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  134. return;
  135. if ((dev_priv->irq_mask & mask) != 0) {
  136. dev_priv->irq_mask &= ~mask;
  137. I915_WRITE(DEIMR, dev_priv->irq_mask);
  138. POSTING_READ(DEIMR);
  139. }
  140. }
  141. void
  142. ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
  143. {
  144. assert_spin_locked(&dev_priv->irq_lock);
  145. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  146. return;
  147. if ((dev_priv->irq_mask & mask) != mask) {
  148. dev_priv->irq_mask |= mask;
  149. I915_WRITE(DEIMR, dev_priv->irq_mask);
  150. POSTING_READ(DEIMR);
  151. }
  152. }
  153. /**
  154. * ilk_update_gt_irq - update GTIMR
  155. * @dev_priv: driver private
  156. * @interrupt_mask: mask of interrupt bits to update
  157. * @enabled_irq_mask: mask of interrupt bits to enable
  158. */
  159. static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
  160. uint32_t interrupt_mask,
  161. uint32_t enabled_irq_mask)
  162. {
  163. assert_spin_locked(&dev_priv->irq_lock);
  164. WARN_ON(enabled_irq_mask & ~interrupt_mask);
  165. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  166. return;
  167. dev_priv->gt_irq_mask &= ~interrupt_mask;
  168. dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
  169. I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
  170. POSTING_READ(GTIMR);
  171. }
  172. void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  173. {
  174. ilk_update_gt_irq(dev_priv, mask, mask);
  175. }
  176. void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  177. {
  178. ilk_update_gt_irq(dev_priv, mask, 0);
  179. }
  180. static u32 gen6_pm_iir(struct drm_i915_private *dev_priv)
  181. {
  182. return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
  183. }
  184. static u32 gen6_pm_imr(struct drm_i915_private *dev_priv)
  185. {
  186. return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
  187. }
  188. static u32 gen6_pm_ier(struct drm_i915_private *dev_priv)
  189. {
  190. return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
  191. }
  192. /**
  193. * snb_update_pm_irq - update GEN6_PMIMR
  194. * @dev_priv: driver private
  195. * @interrupt_mask: mask of interrupt bits to update
  196. * @enabled_irq_mask: mask of interrupt bits to enable
  197. */
  198. static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
  199. uint32_t interrupt_mask,
  200. uint32_t enabled_irq_mask)
  201. {
  202. uint32_t new_val;
  203. WARN_ON(enabled_irq_mask & ~interrupt_mask);
  204. assert_spin_locked(&dev_priv->irq_lock);
  205. new_val = dev_priv->pm_irq_mask;
  206. new_val &= ~interrupt_mask;
  207. new_val |= (~enabled_irq_mask & interrupt_mask);
  208. if (new_val != dev_priv->pm_irq_mask) {
  209. dev_priv->pm_irq_mask = new_val;
  210. I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
  211. POSTING_READ(gen6_pm_imr(dev_priv));
  212. }
  213. }
  214. void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  215. {
  216. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  217. return;
  218. snb_update_pm_irq(dev_priv, mask, mask);
  219. }
  220. static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
  221. uint32_t mask)
  222. {
  223. snb_update_pm_irq(dev_priv, mask, 0);
  224. }
  225. void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
  226. {
  227. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  228. return;
  229. __gen6_disable_pm_irq(dev_priv, mask);
  230. }
  231. void gen6_reset_rps_interrupts(struct drm_device *dev)
  232. {
  233. struct drm_i915_private *dev_priv = dev->dev_private;
  234. uint32_t reg = gen6_pm_iir(dev_priv);
  235. spin_lock_irq(&dev_priv->irq_lock);
  236. I915_WRITE(reg, dev_priv->pm_rps_events);
  237. I915_WRITE(reg, dev_priv->pm_rps_events);
  238. POSTING_READ(reg);
  239. dev_priv->rps.pm_iir = 0;
  240. spin_unlock_irq(&dev_priv->irq_lock);
  241. }
  242. void gen6_enable_rps_interrupts(struct drm_device *dev)
  243. {
  244. struct drm_i915_private *dev_priv = dev->dev_private;
  245. spin_lock_irq(&dev_priv->irq_lock);
  246. WARN_ON(dev_priv->rps.pm_iir);
  247. WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
  248. dev_priv->rps.interrupts_enabled = true;
  249. I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
  250. dev_priv->pm_rps_events);
  251. gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
  252. spin_unlock_irq(&dev_priv->irq_lock);
  253. }
  254. u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
  255. {
  256. /*
  257. * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
  258. * if GEN6_PM_UP_EI_EXPIRED is masked.
  259. *
  260. * TODO: verify if this can be reproduced on VLV,CHV.
  261. */
  262. if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
  263. mask &= ~GEN6_PM_RP_UP_EI_EXPIRED;
  264. if (INTEL_INFO(dev_priv)->gen >= 8)
  265. mask &= ~GEN8_PMINTR_REDIRECT_TO_NON_DISP;
  266. return mask;
  267. }
  268. void gen6_disable_rps_interrupts(struct drm_device *dev)
  269. {
  270. struct drm_i915_private *dev_priv = dev->dev_private;
  271. spin_lock_irq(&dev_priv->irq_lock);
  272. dev_priv->rps.interrupts_enabled = false;
  273. spin_unlock_irq(&dev_priv->irq_lock);
  274. cancel_work_sync(&dev_priv->rps.work);
  275. spin_lock_irq(&dev_priv->irq_lock);
  276. I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
  277. __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
  278. I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
  279. ~dev_priv->pm_rps_events);
  280. spin_unlock_irq(&dev_priv->irq_lock);
  281. synchronize_irq(dev->irq);
  282. }
  283. /**
  284. * ibx_display_interrupt_update - update SDEIMR
  285. * @dev_priv: driver private
  286. * @interrupt_mask: mask of interrupt bits to update
  287. * @enabled_irq_mask: mask of interrupt bits to enable
  288. */
  289. void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
  290. uint32_t interrupt_mask,
  291. uint32_t enabled_irq_mask)
  292. {
  293. uint32_t sdeimr = I915_READ(SDEIMR);
  294. sdeimr &= ~interrupt_mask;
  295. sdeimr |= (~enabled_irq_mask & interrupt_mask);
  296. WARN_ON(enabled_irq_mask & ~interrupt_mask);
  297. assert_spin_locked(&dev_priv->irq_lock);
  298. if (WARN_ON(!intel_irqs_enabled(dev_priv)))
  299. return;
  300. I915_WRITE(SDEIMR, sdeimr);
  301. POSTING_READ(SDEIMR);
  302. }
  303. static void
  304. __i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  305. u32 enable_mask, u32 status_mask)
  306. {
  307. u32 reg = PIPESTAT(pipe);
  308. u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
  309. assert_spin_locked(&dev_priv->irq_lock);
  310. WARN_ON(!intel_irqs_enabled(dev_priv));
  311. if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
  312. status_mask & ~PIPESTAT_INT_STATUS_MASK,
  313. "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
  314. pipe_name(pipe), enable_mask, status_mask))
  315. return;
  316. if ((pipestat & enable_mask) == enable_mask)
  317. return;
  318. dev_priv->pipestat_irq_mask[pipe] |= status_mask;
  319. /* Enable the interrupt, clear any pending status */
  320. pipestat |= enable_mask | status_mask;
  321. I915_WRITE(reg, pipestat);
  322. POSTING_READ(reg);
  323. }
  324. static void
  325. __i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  326. u32 enable_mask, u32 status_mask)
  327. {
  328. u32 reg = PIPESTAT(pipe);
  329. u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
  330. assert_spin_locked(&dev_priv->irq_lock);
  331. WARN_ON(!intel_irqs_enabled(dev_priv));
  332. if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
  333. status_mask & ~PIPESTAT_INT_STATUS_MASK,
  334. "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
  335. pipe_name(pipe), enable_mask, status_mask))
  336. return;
  337. if ((pipestat & enable_mask) == 0)
  338. return;
  339. dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
  340. pipestat &= ~enable_mask;
  341. I915_WRITE(reg, pipestat);
  342. POSTING_READ(reg);
  343. }
  344. static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
  345. {
  346. u32 enable_mask = status_mask << 16;
  347. /*
  348. * On pipe A we don't support the PSR interrupt yet,
  349. * on pipe B and C the same bit MBZ.
  350. */
  351. if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
  352. return 0;
  353. /*
  354. * On pipe B and C we don't support the PSR interrupt yet, on pipe
  355. * A the same bit is for perf counters which we don't use either.
  356. */
  357. if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
  358. return 0;
  359. enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
  360. SPRITE0_FLIP_DONE_INT_EN_VLV |
  361. SPRITE1_FLIP_DONE_INT_EN_VLV);
  362. if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
  363. enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
  364. if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
  365. enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
  366. return enable_mask;
  367. }
  368. void
  369. i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  370. u32 status_mask)
  371. {
  372. u32 enable_mask;
  373. if (IS_VALLEYVIEW(dev_priv->dev))
  374. enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
  375. status_mask);
  376. else
  377. enable_mask = status_mask << 16;
  378. __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
  379. }
  380. void
  381. i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
  382. u32 status_mask)
  383. {
  384. u32 enable_mask;
  385. if (IS_VALLEYVIEW(dev_priv->dev))
  386. enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
  387. status_mask);
  388. else
  389. enable_mask = status_mask << 16;
  390. __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
  391. }
  392. /**
  393. * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
  394. */
  395. static void i915_enable_asle_pipestat(struct drm_device *dev)
  396. {
  397. struct drm_i915_private *dev_priv = dev->dev_private;
  398. if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
  399. return;
  400. spin_lock_irq(&dev_priv->irq_lock);
  401. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
  402. if (INTEL_INFO(dev)->gen >= 4)
  403. i915_enable_pipestat(dev_priv, PIPE_A,
  404. PIPE_LEGACY_BLC_EVENT_STATUS);
  405. spin_unlock_irq(&dev_priv->irq_lock);
  406. }
  407. /*
  408. * This timing diagram depicts the video signal in and
  409. * around the vertical blanking period.
  410. *
  411. * Assumptions about the fictitious mode used in this example:
  412. * vblank_start >= 3
  413. * vsync_start = vblank_start + 1
  414. * vsync_end = vblank_start + 2
  415. * vtotal = vblank_start + 3
  416. *
  417. * start of vblank:
  418. * latch double buffered registers
  419. * increment frame counter (ctg+)
  420. * generate start of vblank interrupt (gen4+)
  421. * |
  422. * | frame start:
  423. * | generate frame start interrupt (aka. vblank interrupt) (gmch)
  424. * | may be shifted forward 1-3 extra lines via PIPECONF
  425. * | |
  426. * | | start of vsync:
  427. * | | generate vsync interrupt
  428. * | | |
  429. * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
  430. * . \hs/ . \hs/ \hs/ \hs/ . \hs/
  431. * ----va---> <-----------------vb--------------------> <--------va-------------
  432. * | | <----vs-----> |
  433. * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
  434. * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
  435. * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
  436. * | | |
  437. * last visible pixel first visible pixel
  438. * | increment frame counter (gen3/4)
  439. * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
  440. *
  441. * x = horizontal active
  442. * _ = horizontal blanking
  443. * hs = horizontal sync
  444. * va = vertical active
  445. * vb = vertical blanking
  446. * vs = vertical sync
  447. * vbs = vblank_start (number)
  448. *
  449. * Summary:
  450. * - most events happen at the start of horizontal sync
  451. * - frame start happens at the start of horizontal blank, 1-4 lines
  452. * (depending on PIPECONF settings) after the start of vblank
  453. * - gen3/4 pixel and frame counter are synchronized with the start
  454. * of horizontal active on the first line of vertical active
  455. */
  456. static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
  457. {
  458. /* Gen2 doesn't have a hardware frame counter */
  459. return 0;
  460. }
  461. /* Called from drm generic code, passed a 'crtc', which
  462. * we use as a pipe index
  463. */
  464. static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
  465. {
  466. struct drm_i915_private *dev_priv = dev->dev_private;
  467. unsigned long high_frame;
  468. unsigned long low_frame;
  469. u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
  470. struct intel_crtc *intel_crtc =
  471. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  472. const struct drm_display_mode *mode =
  473. &intel_crtc->config->base.adjusted_mode;
  474. htotal = mode->crtc_htotal;
  475. hsync_start = mode->crtc_hsync_start;
  476. vbl_start = mode->crtc_vblank_start;
  477. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  478. vbl_start = DIV_ROUND_UP(vbl_start, 2);
  479. /* Convert to pixel count */
  480. vbl_start *= htotal;
  481. /* Start of vblank event occurs at start of hsync */
  482. vbl_start -= htotal - hsync_start;
  483. high_frame = PIPEFRAME(pipe);
  484. low_frame = PIPEFRAMEPIXEL(pipe);
  485. /*
  486. * High & low register fields aren't synchronized, so make sure
  487. * we get a low value that's stable across two reads of the high
  488. * register.
  489. */
  490. do {
  491. high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  492. low = I915_READ(low_frame);
  493. high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
  494. } while (high1 != high2);
  495. high1 >>= PIPE_FRAME_HIGH_SHIFT;
  496. pixel = low & PIPE_PIXEL_MASK;
  497. low >>= PIPE_FRAME_LOW_SHIFT;
  498. /*
  499. * The frame counter increments at beginning of active.
  500. * Cook up a vblank counter by also checking the pixel
  501. * counter against vblank start.
  502. */
  503. return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
  504. }
  505. static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
  506. {
  507. struct drm_i915_private *dev_priv = dev->dev_private;
  508. int reg = PIPE_FRMCOUNT_GM45(pipe);
  509. return I915_READ(reg);
  510. }
  511. /* raw reads, only for fast reads of display block, no need for forcewake etc. */
  512. #define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
  513. static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
  514. {
  515. struct drm_device *dev = crtc->base.dev;
  516. struct drm_i915_private *dev_priv = dev->dev_private;
  517. const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode;
  518. enum pipe pipe = crtc->pipe;
  519. int position, vtotal;
  520. vtotal = mode->crtc_vtotal;
  521. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  522. vtotal /= 2;
  523. if (IS_GEN2(dev))
  524. position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
  525. else
  526. position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
  527. /*
  528. * See update_scanline_offset() for the details on the
  529. * scanline_offset adjustment.
  530. */
  531. return (position + crtc->scanline_offset) % vtotal;
  532. }
  533. static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
  534. unsigned int flags, int *vpos, int *hpos,
  535. ktime_t *stime, ktime_t *etime)
  536. {
  537. struct drm_i915_private *dev_priv = dev->dev_private;
  538. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  539. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  540. const struct drm_display_mode *mode = &intel_crtc->config->base.adjusted_mode;
  541. int position;
  542. int vbl_start, vbl_end, hsync_start, htotal, vtotal;
  543. bool in_vbl = true;
  544. int ret = 0;
  545. unsigned long irqflags;
  546. if (!intel_crtc->active) {
  547. DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
  548. "pipe %c\n", pipe_name(pipe));
  549. return 0;
  550. }
  551. htotal = mode->crtc_htotal;
  552. hsync_start = mode->crtc_hsync_start;
  553. vtotal = mode->crtc_vtotal;
  554. vbl_start = mode->crtc_vblank_start;
  555. vbl_end = mode->crtc_vblank_end;
  556. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  557. vbl_start = DIV_ROUND_UP(vbl_start, 2);
  558. vbl_end /= 2;
  559. vtotal /= 2;
  560. }
  561. ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
  562. /*
  563. * Lock uncore.lock, as we will do multiple timing critical raw
  564. * register reads, potentially with preemption disabled, so the
  565. * following code must not block on uncore.lock.
  566. */
  567. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  568. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  569. /* Get optional system timestamp before query. */
  570. if (stime)
  571. *stime = ktime_get();
  572. if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  573. /* No obvious pixelcount register. Only query vertical
  574. * scanout position from Display scan line register.
  575. */
  576. position = __intel_get_crtc_scanline(intel_crtc);
  577. } else {
  578. /* Have access to pixelcount since start of frame.
  579. * We can split this into vertical and horizontal
  580. * scanout position.
  581. */
  582. position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
  583. /* convert to pixel counts */
  584. vbl_start *= htotal;
  585. vbl_end *= htotal;
  586. vtotal *= htotal;
  587. /*
  588. * In interlaced modes, the pixel counter counts all pixels,
  589. * so one field will have htotal more pixels. In order to avoid
  590. * the reported position from jumping backwards when the pixel
  591. * counter is beyond the length of the shorter field, just
  592. * clamp the position the length of the shorter field. This
  593. * matches how the scanline counter based position works since
  594. * the scanline counter doesn't count the two half lines.
  595. */
  596. if (position >= vtotal)
  597. position = vtotal - 1;
  598. /*
  599. * Start of vblank interrupt is triggered at start of hsync,
  600. * just prior to the first active line of vblank. However we
  601. * consider lines to start at the leading edge of horizontal
  602. * active. So, should we get here before we've crossed into
  603. * the horizontal active of the first line in vblank, we would
  604. * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
  605. * always add htotal-hsync_start to the current pixel position.
  606. */
  607. position = (position + htotal - hsync_start) % vtotal;
  608. }
  609. /* Get optional system timestamp after query. */
  610. if (etime)
  611. *etime = ktime_get();
  612. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  613. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  614. in_vbl = position >= vbl_start && position < vbl_end;
  615. /*
  616. * While in vblank, position will be negative
  617. * counting up towards 0 at vbl_end. And outside
  618. * vblank, position will be positive counting
  619. * up since vbl_end.
  620. */
  621. if (position >= vbl_start)
  622. position -= vbl_end;
  623. else
  624. position += vtotal - vbl_end;
  625. if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  626. *vpos = position;
  627. *hpos = 0;
  628. } else {
  629. *vpos = position / htotal;
  630. *hpos = position - (*vpos * htotal);
  631. }
  632. /* In vblank? */
  633. if (in_vbl)
  634. ret |= DRM_SCANOUTPOS_IN_VBLANK;
  635. return ret;
  636. }
  637. int intel_get_crtc_scanline(struct intel_crtc *crtc)
  638. {
  639. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  640. unsigned long irqflags;
  641. int position;
  642. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  643. position = __intel_get_crtc_scanline(crtc);
  644. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  645. return position;
  646. }
  647. static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
  648. int *max_error,
  649. struct timeval *vblank_time,
  650. unsigned flags)
  651. {
  652. struct drm_crtc *crtc;
  653. if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
  654. DRM_ERROR("Invalid crtc %d\n", pipe);
  655. return -EINVAL;
  656. }
  657. /* Get drm_crtc to timestamp: */
  658. crtc = intel_get_crtc_for_pipe(dev, pipe);
  659. if (crtc == NULL) {
  660. DRM_ERROR("Invalid crtc %d\n", pipe);
  661. return -EINVAL;
  662. }
  663. if (!crtc->state->enable) {
  664. DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
  665. return -EBUSY;
  666. }
  667. /* Helper routine in DRM core does all the work: */
  668. return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
  669. vblank_time, flags,
  670. crtc,
  671. &to_intel_crtc(crtc)->config->base.adjusted_mode);
  672. }
  673. static bool intel_hpd_irq_event(struct drm_device *dev,
  674. struct drm_connector *connector)
  675. {
  676. enum drm_connector_status old_status;
  677. WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
  678. old_status = connector->status;
  679. connector->status = connector->funcs->detect(connector, false);
  680. if (old_status == connector->status)
  681. return false;
  682. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
  683. connector->base.id,
  684. connector->name,
  685. drm_get_connector_status_name(old_status),
  686. drm_get_connector_status_name(connector->status));
  687. return true;
  688. }
  689. static void i915_digport_work_func(struct work_struct *work)
  690. {
  691. struct drm_i915_private *dev_priv =
  692. container_of(work, struct drm_i915_private, dig_port_work);
  693. u32 long_port_mask, short_port_mask;
  694. struct intel_digital_port *intel_dig_port;
  695. int i;
  696. u32 old_bits = 0;
  697. spin_lock_irq(&dev_priv->irq_lock);
  698. long_port_mask = dev_priv->long_hpd_port_mask;
  699. dev_priv->long_hpd_port_mask = 0;
  700. short_port_mask = dev_priv->short_hpd_port_mask;
  701. dev_priv->short_hpd_port_mask = 0;
  702. spin_unlock_irq(&dev_priv->irq_lock);
  703. for (i = 0; i < I915_MAX_PORTS; i++) {
  704. bool valid = false;
  705. bool long_hpd = false;
  706. intel_dig_port = dev_priv->hpd_irq_port[i];
  707. if (!intel_dig_port || !intel_dig_port->hpd_pulse)
  708. continue;
  709. if (long_port_mask & (1 << i)) {
  710. valid = true;
  711. long_hpd = true;
  712. } else if (short_port_mask & (1 << i))
  713. valid = true;
  714. if (valid) {
  715. enum irqreturn ret;
  716. ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd);
  717. if (ret == IRQ_NONE) {
  718. /* fall back to old school hpd */
  719. old_bits |= (1 << intel_dig_port->base.hpd_pin);
  720. }
  721. }
  722. }
  723. if (old_bits) {
  724. spin_lock_irq(&dev_priv->irq_lock);
  725. dev_priv->hpd_event_bits |= old_bits;
  726. spin_unlock_irq(&dev_priv->irq_lock);
  727. schedule_work(&dev_priv->hotplug_work);
  728. }
  729. }
  730. /*
  731. * Handle hotplug events outside the interrupt handler proper.
  732. */
  733. #define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
  734. static void i915_hotplug_work_func(struct work_struct *work)
  735. {
  736. struct drm_i915_private *dev_priv =
  737. container_of(work, struct drm_i915_private, hotplug_work);
  738. struct drm_device *dev = dev_priv->dev;
  739. struct drm_mode_config *mode_config = &dev->mode_config;
  740. struct intel_connector *intel_connector;
  741. struct intel_encoder *intel_encoder;
  742. struct drm_connector *connector;
  743. bool hpd_disabled = false;
  744. bool changed = false;
  745. u32 hpd_event_bits;
  746. mutex_lock(&mode_config->mutex);
  747. DRM_DEBUG_KMS("running encoder hotplug functions\n");
  748. spin_lock_irq(&dev_priv->irq_lock);
  749. hpd_event_bits = dev_priv->hpd_event_bits;
  750. dev_priv->hpd_event_bits = 0;
  751. list_for_each_entry(connector, &mode_config->connector_list, head) {
  752. intel_connector = to_intel_connector(connector);
  753. if (!intel_connector->encoder)
  754. continue;
  755. intel_encoder = intel_connector->encoder;
  756. if (intel_encoder->hpd_pin > HPD_NONE &&
  757. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
  758. connector->polled == DRM_CONNECTOR_POLL_HPD) {
  759. DRM_INFO("HPD interrupt storm detected on connector %s: "
  760. "switching from hotplug detection to polling\n",
  761. connector->name);
  762. dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
  763. connector->polled = DRM_CONNECTOR_POLL_CONNECT
  764. | DRM_CONNECTOR_POLL_DISCONNECT;
  765. hpd_disabled = true;
  766. }
  767. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  768. DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
  769. connector->name, intel_encoder->hpd_pin);
  770. }
  771. }
  772. /* if there were no outputs to poll, poll was disabled,
  773. * therefore make sure it's enabled when disabling HPD on
  774. * some connectors */
  775. if (hpd_disabled) {
  776. drm_kms_helper_poll_enable(dev);
  777. mod_delayed_work(system_wq, &dev_priv->hotplug_reenable_work,
  778. msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
  779. }
  780. spin_unlock_irq(&dev_priv->irq_lock);
  781. list_for_each_entry(connector, &mode_config->connector_list, head) {
  782. intel_connector = to_intel_connector(connector);
  783. if (!intel_connector->encoder)
  784. continue;
  785. intel_encoder = intel_connector->encoder;
  786. if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
  787. if (intel_encoder->hot_plug)
  788. intel_encoder->hot_plug(intel_encoder);
  789. if (intel_hpd_irq_event(dev, connector))
  790. changed = true;
  791. }
  792. }
  793. mutex_unlock(&mode_config->mutex);
  794. if (changed)
  795. drm_kms_helper_hotplug_event(dev);
  796. }
  797. static void ironlake_rps_change_irq_handler(struct drm_device *dev)
  798. {
  799. struct drm_i915_private *dev_priv = dev->dev_private;
  800. u32 busy_up, busy_down, max_avg, min_avg;
  801. u8 new_delay;
  802. spin_lock(&mchdev_lock);
  803. I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
  804. new_delay = dev_priv->ips.cur_delay;
  805. I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
  806. busy_up = I915_READ(RCPREVBSYTUPAVG);
  807. busy_down = I915_READ(RCPREVBSYTDNAVG);
  808. max_avg = I915_READ(RCBMAXAVG);
  809. min_avg = I915_READ(RCBMINAVG);
  810. /* Handle RCS change request from hw */
  811. if (busy_up > max_avg) {
  812. if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
  813. new_delay = dev_priv->ips.cur_delay - 1;
  814. if (new_delay < dev_priv->ips.max_delay)
  815. new_delay = dev_priv->ips.max_delay;
  816. } else if (busy_down < min_avg) {
  817. if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
  818. new_delay = dev_priv->ips.cur_delay + 1;
  819. if (new_delay > dev_priv->ips.min_delay)
  820. new_delay = dev_priv->ips.min_delay;
  821. }
  822. if (ironlake_set_drps(dev, new_delay))
  823. dev_priv->ips.cur_delay = new_delay;
  824. spin_unlock(&mchdev_lock);
  825. return;
  826. }
  827. static void notify_ring(struct drm_device *dev,
  828. struct intel_engine_cs *ring)
  829. {
  830. if (!intel_ring_initialized(ring))
  831. return;
  832. trace_i915_gem_request_notify(ring);
  833. wake_up_all(&ring->irq_queue);
  834. }
  835. static void vlv_c0_read(struct drm_i915_private *dev_priv,
  836. struct intel_rps_ei *ei)
  837. {
  838. ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
  839. ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
  840. ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
  841. }
  842. static bool vlv_c0_above(struct drm_i915_private *dev_priv,
  843. const struct intel_rps_ei *old,
  844. const struct intel_rps_ei *now,
  845. int threshold)
  846. {
  847. u64 time, c0;
  848. if (old->cz_clock == 0)
  849. return false;
  850. time = now->cz_clock - old->cz_clock;
  851. time *= threshold * dev_priv->mem_freq;
  852. /* Workload can be split between render + media, e.g. SwapBuffers
  853. * being blitted in X after being rendered in mesa. To account for
  854. * this we need to combine both engines into our activity counter.
  855. */
  856. c0 = now->render_c0 - old->render_c0;
  857. c0 += now->media_c0 - old->media_c0;
  858. c0 *= 100 * VLV_CZ_CLOCK_TO_MILLI_SEC * 4 / 1000;
  859. return c0 >= time;
  860. }
  861. void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
  862. {
  863. vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
  864. dev_priv->rps.up_ei = dev_priv->rps.down_ei;
  865. }
  866. static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
  867. {
  868. struct intel_rps_ei now;
  869. u32 events = 0;
  870. if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
  871. return 0;
  872. vlv_c0_read(dev_priv, &now);
  873. if (now.cz_clock == 0)
  874. return 0;
  875. if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
  876. if (!vlv_c0_above(dev_priv,
  877. &dev_priv->rps.down_ei, &now,
  878. VLV_RP_DOWN_EI_THRESHOLD))
  879. events |= GEN6_PM_RP_DOWN_THRESHOLD;
  880. dev_priv->rps.down_ei = now;
  881. }
  882. if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
  883. if (vlv_c0_above(dev_priv,
  884. &dev_priv->rps.up_ei, &now,
  885. VLV_RP_UP_EI_THRESHOLD))
  886. events |= GEN6_PM_RP_UP_THRESHOLD;
  887. dev_priv->rps.up_ei = now;
  888. }
  889. return events;
  890. }
  891. static void gen6_pm_rps_work(struct work_struct *work)
  892. {
  893. struct drm_i915_private *dev_priv =
  894. container_of(work, struct drm_i915_private, rps.work);
  895. u32 pm_iir;
  896. int new_delay, adj;
  897. spin_lock_irq(&dev_priv->irq_lock);
  898. /* Speed up work cancelation during disabling rps interrupts. */
  899. if (!dev_priv->rps.interrupts_enabled) {
  900. spin_unlock_irq(&dev_priv->irq_lock);
  901. return;
  902. }
  903. pm_iir = dev_priv->rps.pm_iir;
  904. dev_priv->rps.pm_iir = 0;
  905. /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
  906. gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
  907. spin_unlock_irq(&dev_priv->irq_lock);
  908. /* Make sure we didn't queue anything we're not going to process. */
  909. WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
  910. if ((pm_iir & dev_priv->pm_rps_events) == 0)
  911. return;
  912. mutex_lock(&dev_priv->rps.hw_lock);
  913. pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
  914. adj = dev_priv->rps.last_adj;
  915. if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
  916. if (adj > 0)
  917. adj *= 2;
  918. else {
  919. /* CHV needs even encode values */
  920. adj = IS_CHERRYVIEW(dev_priv->dev) ? 2 : 1;
  921. }
  922. new_delay = dev_priv->rps.cur_freq + adj;
  923. /*
  924. * For better performance, jump directly
  925. * to RPe if we're below it.
  926. */
  927. if (new_delay < dev_priv->rps.efficient_freq)
  928. new_delay = dev_priv->rps.efficient_freq;
  929. } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
  930. if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
  931. new_delay = dev_priv->rps.efficient_freq;
  932. else
  933. new_delay = dev_priv->rps.min_freq_softlimit;
  934. adj = 0;
  935. } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
  936. if (adj < 0)
  937. adj *= 2;
  938. else {
  939. /* CHV needs even encode values */
  940. adj = IS_CHERRYVIEW(dev_priv->dev) ? -2 : -1;
  941. }
  942. new_delay = dev_priv->rps.cur_freq + adj;
  943. } else { /* unknown event */
  944. new_delay = dev_priv->rps.cur_freq;
  945. }
  946. /* sysfs frequency interfaces may have snuck in while servicing the
  947. * interrupt
  948. */
  949. new_delay = clamp_t(int, new_delay,
  950. dev_priv->rps.min_freq_softlimit,
  951. dev_priv->rps.max_freq_softlimit);
  952. dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
  953. intel_set_rps(dev_priv->dev, new_delay);
  954. mutex_unlock(&dev_priv->rps.hw_lock);
  955. }
  956. /**
  957. * ivybridge_parity_work - Workqueue called when a parity error interrupt
  958. * occurred.
  959. * @work: workqueue struct
  960. *
  961. * Doesn't actually do anything except notify userspace. As a consequence of
  962. * this event, userspace should try to remap the bad rows since statistically
  963. * it is likely the same row is more likely to go bad again.
  964. */
  965. static void ivybridge_parity_work(struct work_struct *work)
  966. {
  967. struct drm_i915_private *dev_priv =
  968. container_of(work, struct drm_i915_private, l3_parity.error_work);
  969. u32 error_status, row, bank, subbank;
  970. char *parity_event[6];
  971. uint32_t misccpctl;
  972. uint8_t slice = 0;
  973. /* We must turn off DOP level clock gating to access the L3 registers.
  974. * In order to prevent a get/put style interface, acquire struct mutex
  975. * any time we access those registers.
  976. */
  977. mutex_lock(&dev_priv->dev->struct_mutex);
  978. /* If we've screwed up tracking, just let the interrupt fire again */
  979. if (WARN_ON(!dev_priv->l3_parity.which_slice))
  980. goto out;
  981. misccpctl = I915_READ(GEN7_MISCCPCTL);
  982. I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  983. POSTING_READ(GEN7_MISCCPCTL);
  984. while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
  985. u32 reg;
  986. slice--;
  987. if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
  988. break;
  989. dev_priv->l3_parity.which_slice &= ~(1<<slice);
  990. reg = GEN7_L3CDERRST1 + (slice * 0x200);
  991. error_status = I915_READ(reg);
  992. row = GEN7_PARITY_ERROR_ROW(error_status);
  993. bank = GEN7_PARITY_ERROR_BANK(error_status);
  994. subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
  995. I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
  996. POSTING_READ(reg);
  997. parity_event[0] = I915_L3_PARITY_UEVENT "=1";
  998. parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
  999. parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
  1000. parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
  1001. parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
  1002. parity_event[5] = NULL;
  1003. kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
  1004. KOBJ_CHANGE, parity_event);
  1005. DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
  1006. slice, row, bank, subbank);
  1007. kfree(parity_event[4]);
  1008. kfree(parity_event[3]);
  1009. kfree(parity_event[2]);
  1010. kfree(parity_event[1]);
  1011. }
  1012. I915_WRITE(GEN7_MISCCPCTL, misccpctl);
  1013. out:
  1014. WARN_ON(dev_priv->l3_parity.which_slice);
  1015. spin_lock_irq(&dev_priv->irq_lock);
  1016. gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
  1017. spin_unlock_irq(&dev_priv->irq_lock);
  1018. mutex_unlock(&dev_priv->dev->struct_mutex);
  1019. }
  1020. static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
  1021. {
  1022. struct drm_i915_private *dev_priv = dev->dev_private;
  1023. if (!HAS_L3_DPF(dev))
  1024. return;
  1025. spin_lock(&dev_priv->irq_lock);
  1026. gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
  1027. spin_unlock(&dev_priv->irq_lock);
  1028. iir &= GT_PARITY_ERROR(dev);
  1029. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
  1030. dev_priv->l3_parity.which_slice |= 1 << 1;
  1031. if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
  1032. dev_priv->l3_parity.which_slice |= 1 << 0;
  1033. queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
  1034. }
  1035. static void ilk_gt_irq_handler(struct drm_device *dev,
  1036. struct drm_i915_private *dev_priv,
  1037. u32 gt_iir)
  1038. {
  1039. if (gt_iir &
  1040. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  1041. notify_ring(dev, &dev_priv->ring[RCS]);
  1042. if (gt_iir & ILK_BSD_USER_INTERRUPT)
  1043. notify_ring(dev, &dev_priv->ring[VCS]);
  1044. }
  1045. static void snb_gt_irq_handler(struct drm_device *dev,
  1046. struct drm_i915_private *dev_priv,
  1047. u32 gt_iir)
  1048. {
  1049. if (gt_iir &
  1050. (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
  1051. notify_ring(dev, &dev_priv->ring[RCS]);
  1052. if (gt_iir & GT_BSD_USER_INTERRUPT)
  1053. notify_ring(dev, &dev_priv->ring[VCS]);
  1054. if (gt_iir & GT_BLT_USER_INTERRUPT)
  1055. notify_ring(dev, &dev_priv->ring[BCS]);
  1056. if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
  1057. GT_BSD_CS_ERROR_INTERRUPT |
  1058. GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
  1059. DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
  1060. if (gt_iir & GT_PARITY_ERROR(dev))
  1061. ivybridge_parity_error_irq_handler(dev, gt_iir);
  1062. }
  1063. static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
  1064. struct drm_i915_private *dev_priv,
  1065. u32 master_ctl)
  1066. {
  1067. struct intel_engine_cs *ring;
  1068. u32 rcs, bcs, vcs;
  1069. uint32_t tmp = 0;
  1070. irqreturn_t ret = IRQ_NONE;
  1071. if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
  1072. tmp = I915_READ(GEN8_GT_IIR(0));
  1073. if (tmp) {
  1074. I915_WRITE(GEN8_GT_IIR(0), tmp);
  1075. ret = IRQ_HANDLED;
  1076. rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
  1077. ring = &dev_priv->ring[RCS];
  1078. if (rcs & GT_RENDER_USER_INTERRUPT)
  1079. notify_ring(dev, ring);
  1080. if (rcs & GT_CONTEXT_SWITCH_INTERRUPT)
  1081. intel_lrc_irq_handler(ring);
  1082. bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
  1083. ring = &dev_priv->ring[BCS];
  1084. if (bcs & GT_RENDER_USER_INTERRUPT)
  1085. notify_ring(dev, ring);
  1086. if (bcs & GT_CONTEXT_SWITCH_INTERRUPT)
  1087. intel_lrc_irq_handler(ring);
  1088. } else
  1089. DRM_ERROR("The master control interrupt lied (GT0)!\n");
  1090. }
  1091. if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
  1092. tmp = I915_READ(GEN8_GT_IIR(1));
  1093. if (tmp) {
  1094. I915_WRITE(GEN8_GT_IIR(1), tmp);
  1095. ret = IRQ_HANDLED;
  1096. vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
  1097. ring = &dev_priv->ring[VCS];
  1098. if (vcs & GT_RENDER_USER_INTERRUPT)
  1099. notify_ring(dev, ring);
  1100. if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
  1101. intel_lrc_irq_handler(ring);
  1102. vcs = tmp >> GEN8_VCS2_IRQ_SHIFT;
  1103. ring = &dev_priv->ring[VCS2];
  1104. if (vcs & GT_RENDER_USER_INTERRUPT)
  1105. notify_ring(dev, ring);
  1106. if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
  1107. intel_lrc_irq_handler(ring);
  1108. } else
  1109. DRM_ERROR("The master control interrupt lied (GT1)!\n");
  1110. }
  1111. if (master_ctl & GEN8_GT_PM_IRQ) {
  1112. tmp = I915_READ(GEN8_GT_IIR(2));
  1113. if (tmp & dev_priv->pm_rps_events) {
  1114. I915_WRITE(GEN8_GT_IIR(2),
  1115. tmp & dev_priv->pm_rps_events);
  1116. ret = IRQ_HANDLED;
  1117. gen6_rps_irq_handler(dev_priv, tmp);
  1118. } else
  1119. DRM_ERROR("The master control interrupt lied (PM)!\n");
  1120. }
  1121. if (master_ctl & GEN8_GT_VECS_IRQ) {
  1122. tmp = I915_READ(GEN8_GT_IIR(3));
  1123. if (tmp) {
  1124. I915_WRITE(GEN8_GT_IIR(3), tmp);
  1125. ret = IRQ_HANDLED;
  1126. vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
  1127. ring = &dev_priv->ring[VECS];
  1128. if (vcs & GT_RENDER_USER_INTERRUPT)
  1129. notify_ring(dev, ring);
  1130. if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
  1131. intel_lrc_irq_handler(ring);
  1132. } else
  1133. DRM_ERROR("The master control interrupt lied (GT3)!\n");
  1134. }
  1135. return ret;
  1136. }
  1137. #define HPD_STORM_DETECT_PERIOD 1000
  1138. #define HPD_STORM_THRESHOLD 5
  1139. static int pch_port_to_hotplug_shift(enum port port)
  1140. {
  1141. switch (port) {
  1142. case PORT_A:
  1143. case PORT_E:
  1144. default:
  1145. return -1;
  1146. case PORT_B:
  1147. return 0;
  1148. case PORT_C:
  1149. return 8;
  1150. case PORT_D:
  1151. return 16;
  1152. }
  1153. }
  1154. static int i915_port_to_hotplug_shift(enum port port)
  1155. {
  1156. switch (port) {
  1157. case PORT_A:
  1158. case PORT_E:
  1159. default:
  1160. return -1;
  1161. case PORT_B:
  1162. return 17;
  1163. case PORT_C:
  1164. return 19;
  1165. case PORT_D:
  1166. return 21;
  1167. }
  1168. }
  1169. static inline enum port get_port_from_pin(enum hpd_pin pin)
  1170. {
  1171. switch (pin) {
  1172. case HPD_PORT_B:
  1173. return PORT_B;
  1174. case HPD_PORT_C:
  1175. return PORT_C;
  1176. case HPD_PORT_D:
  1177. return PORT_D;
  1178. default:
  1179. return PORT_A; /* no hpd */
  1180. }
  1181. }
  1182. static inline void intel_hpd_irq_handler(struct drm_device *dev,
  1183. u32 hotplug_trigger,
  1184. u32 dig_hotplug_reg,
  1185. const u32 hpd[HPD_NUM_PINS])
  1186. {
  1187. struct drm_i915_private *dev_priv = dev->dev_private;
  1188. int i;
  1189. enum port port;
  1190. bool storm_detected = false;
  1191. bool queue_dig = false, queue_hp = false;
  1192. u32 dig_shift;
  1193. u32 dig_port_mask = 0;
  1194. if (!hotplug_trigger)
  1195. return;
  1196. DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x\n",
  1197. hotplug_trigger, dig_hotplug_reg);
  1198. spin_lock(&dev_priv->irq_lock);
  1199. for (i = 1; i < HPD_NUM_PINS; i++) {
  1200. if (!(hpd[i] & hotplug_trigger))
  1201. continue;
  1202. port = get_port_from_pin(i);
  1203. if (port && dev_priv->hpd_irq_port[port]) {
  1204. bool long_hpd;
  1205. if (HAS_PCH_SPLIT(dev)) {
  1206. dig_shift = pch_port_to_hotplug_shift(port);
  1207. long_hpd = (dig_hotplug_reg >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
  1208. } else {
  1209. dig_shift = i915_port_to_hotplug_shift(port);
  1210. long_hpd = (hotplug_trigger >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
  1211. }
  1212. DRM_DEBUG_DRIVER("digital hpd port %c - %s\n",
  1213. port_name(port),
  1214. long_hpd ? "long" : "short");
  1215. /* for long HPD pulses we want to have the digital queue happen,
  1216. but we still want HPD storm detection to function. */
  1217. if (long_hpd) {
  1218. dev_priv->long_hpd_port_mask |= (1 << port);
  1219. dig_port_mask |= hpd[i];
  1220. } else {
  1221. /* for short HPD just trigger the digital queue */
  1222. dev_priv->short_hpd_port_mask |= (1 << port);
  1223. hotplug_trigger &= ~hpd[i];
  1224. }
  1225. queue_dig = true;
  1226. }
  1227. }
  1228. for (i = 1; i < HPD_NUM_PINS; i++) {
  1229. if (hpd[i] & hotplug_trigger &&
  1230. dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) {
  1231. /*
  1232. * On GMCH platforms the interrupt mask bits only
  1233. * prevent irq generation, not the setting of the
  1234. * hotplug bits itself. So only WARN about unexpected
  1235. * interrupts on saner platforms.
  1236. */
  1237. WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev),
  1238. "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
  1239. hotplug_trigger, i, hpd[i]);
  1240. continue;
  1241. }
  1242. if (!(hpd[i] & hotplug_trigger) ||
  1243. dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
  1244. continue;
  1245. if (!(dig_port_mask & hpd[i])) {
  1246. dev_priv->hpd_event_bits |= (1 << i);
  1247. queue_hp = true;
  1248. }
  1249. if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
  1250. dev_priv->hpd_stats[i].hpd_last_jiffies
  1251. + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
  1252. dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
  1253. dev_priv->hpd_stats[i].hpd_cnt = 0;
  1254. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
  1255. } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
  1256. dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
  1257. dev_priv->hpd_event_bits &= ~(1 << i);
  1258. DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
  1259. storm_detected = true;
  1260. } else {
  1261. dev_priv->hpd_stats[i].hpd_cnt++;
  1262. DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
  1263. dev_priv->hpd_stats[i].hpd_cnt);
  1264. }
  1265. }
  1266. if (storm_detected)
  1267. dev_priv->display.hpd_irq_setup(dev);
  1268. spin_unlock(&dev_priv->irq_lock);
  1269. /*
  1270. * Our hotplug handler can grab modeset locks (by calling down into the
  1271. * fb helpers). Hence it must not be run on our own dev-priv->wq work
  1272. * queue for otherwise the flush_work in the pageflip code will
  1273. * deadlock.
  1274. */
  1275. if (queue_dig)
  1276. queue_work(dev_priv->dp_wq, &dev_priv->dig_port_work);
  1277. if (queue_hp)
  1278. schedule_work(&dev_priv->hotplug_work);
  1279. }
  1280. static void gmbus_irq_handler(struct drm_device *dev)
  1281. {
  1282. struct drm_i915_private *dev_priv = dev->dev_private;
  1283. wake_up_all(&dev_priv->gmbus_wait_queue);
  1284. }
  1285. static void dp_aux_irq_handler(struct drm_device *dev)
  1286. {
  1287. struct drm_i915_private *dev_priv = dev->dev_private;
  1288. wake_up_all(&dev_priv->gmbus_wait_queue);
  1289. }
  1290. #if defined(CONFIG_DEBUG_FS)
  1291. static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1292. uint32_t crc0, uint32_t crc1,
  1293. uint32_t crc2, uint32_t crc3,
  1294. uint32_t crc4)
  1295. {
  1296. struct drm_i915_private *dev_priv = dev->dev_private;
  1297. struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
  1298. struct intel_pipe_crc_entry *entry;
  1299. int head, tail;
  1300. spin_lock(&pipe_crc->lock);
  1301. if (!pipe_crc->entries) {
  1302. spin_unlock(&pipe_crc->lock);
  1303. DRM_DEBUG_KMS("spurious interrupt\n");
  1304. return;
  1305. }
  1306. head = pipe_crc->head;
  1307. tail = pipe_crc->tail;
  1308. if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
  1309. spin_unlock(&pipe_crc->lock);
  1310. DRM_ERROR("CRC buffer overflowing\n");
  1311. return;
  1312. }
  1313. entry = &pipe_crc->entries[head];
  1314. entry->frame = dev->driver->get_vblank_counter(dev, pipe);
  1315. entry->crc[0] = crc0;
  1316. entry->crc[1] = crc1;
  1317. entry->crc[2] = crc2;
  1318. entry->crc[3] = crc3;
  1319. entry->crc[4] = crc4;
  1320. head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
  1321. pipe_crc->head = head;
  1322. spin_unlock(&pipe_crc->lock);
  1323. wake_up_interruptible(&pipe_crc->wq);
  1324. }
  1325. #else
  1326. static inline void
  1327. display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
  1328. uint32_t crc0, uint32_t crc1,
  1329. uint32_t crc2, uint32_t crc3,
  1330. uint32_t crc4) {}
  1331. #endif
  1332. static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1333. {
  1334. struct drm_i915_private *dev_priv = dev->dev_private;
  1335. display_pipe_crc_irq_handler(dev, pipe,
  1336. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1337. 0, 0, 0, 0);
  1338. }
  1339. static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1340. {
  1341. struct drm_i915_private *dev_priv = dev->dev_private;
  1342. display_pipe_crc_irq_handler(dev, pipe,
  1343. I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
  1344. I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
  1345. I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
  1346. I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
  1347. I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
  1348. }
  1349. static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
  1350. {
  1351. struct drm_i915_private *dev_priv = dev->dev_private;
  1352. uint32_t res1, res2;
  1353. if (INTEL_INFO(dev)->gen >= 3)
  1354. res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
  1355. else
  1356. res1 = 0;
  1357. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  1358. res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
  1359. else
  1360. res2 = 0;
  1361. display_pipe_crc_irq_handler(dev, pipe,
  1362. I915_READ(PIPE_CRC_RES_RED(pipe)),
  1363. I915_READ(PIPE_CRC_RES_GREEN(pipe)),
  1364. I915_READ(PIPE_CRC_RES_BLUE(pipe)),
  1365. res1, res2);
  1366. }
  1367. /* The RPS events need forcewake, so we add them to a work queue and mask their
  1368. * IMR bits until the work is done. Other interrupts can be processed without
  1369. * the work queue. */
  1370. static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
  1371. {
  1372. if (pm_iir & dev_priv->pm_rps_events) {
  1373. spin_lock(&dev_priv->irq_lock);
  1374. gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
  1375. if (dev_priv->rps.interrupts_enabled) {
  1376. dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
  1377. queue_work(dev_priv->wq, &dev_priv->rps.work);
  1378. }
  1379. spin_unlock(&dev_priv->irq_lock);
  1380. }
  1381. if (INTEL_INFO(dev_priv)->gen >= 8)
  1382. return;
  1383. if (HAS_VEBOX(dev_priv->dev)) {
  1384. if (pm_iir & PM_VEBOX_USER_INTERRUPT)
  1385. notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
  1386. if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
  1387. DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
  1388. }
  1389. }
  1390. static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
  1391. {
  1392. if (!drm_handle_vblank(dev, pipe))
  1393. return false;
  1394. return true;
  1395. }
  1396. static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
  1397. {
  1398. struct drm_i915_private *dev_priv = dev->dev_private;
  1399. u32 pipe_stats[I915_MAX_PIPES] = { };
  1400. int pipe;
  1401. spin_lock(&dev_priv->irq_lock);
  1402. for_each_pipe(dev_priv, pipe) {
  1403. int reg;
  1404. u32 mask, iir_bit = 0;
  1405. /*
  1406. * PIPESTAT bits get signalled even when the interrupt is
  1407. * disabled with the mask bits, and some of the status bits do
  1408. * not generate interrupts at all (like the underrun bit). Hence
  1409. * we need to be careful that we only handle what we want to
  1410. * handle.
  1411. */
  1412. /* fifo underruns are filterered in the underrun handler. */
  1413. mask = PIPE_FIFO_UNDERRUN_STATUS;
  1414. switch (pipe) {
  1415. case PIPE_A:
  1416. iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
  1417. break;
  1418. case PIPE_B:
  1419. iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  1420. break;
  1421. case PIPE_C:
  1422. iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  1423. break;
  1424. }
  1425. if (iir & iir_bit)
  1426. mask |= dev_priv->pipestat_irq_mask[pipe];
  1427. if (!mask)
  1428. continue;
  1429. reg = PIPESTAT(pipe);
  1430. mask |= PIPESTAT_INT_ENABLE_MASK;
  1431. pipe_stats[pipe] = I915_READ(reg) & mask;
  1432. /*
  1433. * Clear the PIPE*STAT regs before the IIR
  1434. */
  1435. if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
  1436. PIPESTAT_INT_STATUS_MASK))
  1437. I915_WRITE(reg, pipe_stats[pipe]);
  1438. }
  1439. spin_unlock(&dev_priv->irq_lock);
  1440. for_each_pipe(dev_priv, pipe) {
  1441. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  1442. intel_pipe_handle_vblank(dev, pipe))
  1443. intel_check_page_flip(dev, pipe);
  1444. if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
  1445. intel_prepare_page_flip(dev, pipe);
  1446. intel_finish_page_flip(dev, pipe);
  1447. }
  1448. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  1449. i9xx_pipe_crc_irq_handler(dev, pipe);
  1450. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  1451. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1452. }
  1453. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  1454. gmbus_irq_handler(dev);
  1455. }
  1456. static void i9xx_hpd_irq_handler(struct drm_device *dev)
  1457. {
  1458. struct drm_i915_private *dev_priv = dev->dev_private;
  1459. u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
  1460. if (hotplug_status) {
  1461. I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
  1462. /*
  1463. * Make sure hotplug status is cleared before we clear IIR, or else we
  1464. * may miss hotplug events.
  1465. */
  1466. POSTING_READ(PORT_HOTPLUG_STAT);
  1467. if (IS_G4X(dev)) {
  1468. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
  1469. intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_g4x);
  1470. } else {
  1471. u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
  1472. intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_i915);
  1473. }
  1474. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
  1475. hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
  1476. dp_aux_irq_handler(dev);
  1477. }
  1478. }
  1479. static irqreturn_t valleyview_irq_handler(int irq, void *arg)
  1480. {
  1481. struct drm_device *dev = arg;
  1482. struct drm_i915_private *dev_priv = dev->dev_private;
  1483. u32 iir, gt_iir, pm_iir;
  1484. irqreturn_t ret = IRQ_NONE;
  1485. if (!intel_irqs_enabled(dev_priv))
  1486. return IRQ_NONE;
  1487. while (true) {
  1488. /* Find, clear, then process each source of interrupt */
  1489. gt_iir = I915_READ(GTIIR);
  1490. if (gt_iir)
  1491. I915_WRITE(GTIIR, gt_iir);
  1492. pm_iir = I915_READ(GEN6_PMIIR);
  1493. if (pm_iir)
  1494. I915_WRITE(GEN6_PMIIR, pm_iir);
  1495. iir = I915_READ(VLV_IIR);
  1496. if (iir) {
  1497. /* Consume port before clearing IIR or we'll miss events */
  1498. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  1499. i9xx_hpd_irq_handler(dev);
  1500. I915_WRITE(VLV_IIR, iir);
  1501. }
  1502. if (gt_iir == 0 && pm_iir == 0 && iir == 0)
  1503. goto out;
  1504. ret = IRQ_HANDLED;
  1505. if (gt_iir)
  1506. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1507. if (pm_iir)
  1508. gen6_rps_irq_handler(dev_priv, pm_iir);
  1509. /* Call regardless, as some status bits might not be
  1510. * signalled in iir */
  1511. valleyview_pipestat_irq_handler(dev, iir);
  1512. }
  1513. out:
  1514. return ret;
  1515. }
  1516. static irqreturn_t cherryview_irq_handler(int irq, void *arg)
  1517. {
  1518. struct drm_device *dev = arg;
  1519. struct drm_i915_private *dev_priv = dev->dev_private;
  1520. u32 master_ctl, iir;
  1521. irqreturn_t ret = IRQ_NONE;
  1522. if (!intel_irqs_enabled(dev_priv))
  1523. return IRQ_NONE;
  1524. for (;;) {
  1525. master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
  1526. iir = I915_READ(VLV_IIR);
  1527. if (master_ctl == 0 && iir == 0)
  1528. break;
  1529. ret = IRQ_HANDLED;
  1530. I915_WRITE(GEN8_MASTER_IRQ, 0);
  1531. /* Find, clear, then process each source of interrupt */
  1532. if (iir) {
  1533. /* Consume port before clearing IIR or we'll miss events */
  1534. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  1535. i9xx_hpd_irq_handler(dev);
  1536. I915_WRITE(VLV_IIR, iir);
  1537. }
  1538. gen8_gt_irq_handler(dev, dev_priv, master_ctl);
  1539. /* Call regardless, as some status bits might not be
  1540. * signalled in iir */
  1541. valleyview_pipestat_irq_handler(dev, iir);
  1542. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  1543. POSTING_READ(GEN8_MASTER_IRQ);
  1544. }
  1545. return ret;
  1546. }
  1547. static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
  1548. {
  1549. struct drm_i915_private *dev_priv = dev->dev_private;
  1550. int pipe;
  1551. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
  1552. u32 dig_hotplug_reg;
  1553. dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
  1554. I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1555. intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_ibx);
  1556. if (pch_iir & SDE_AUDIO_POWER_MASK) {
  1557. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
  1558. SDE_AUDIO_POWER_SHIFT);
  1559. DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
  1560. port_name(port));
  1561. }
  1562. if (pch_iir & SDE_AUX_MASK)
  1563. dp_aux_irq_handler(dev);
  1564. if (pch_iir & SDE_GMBUS)
  1565. gmbus_irq_handler(dev);
  1566. if (pch_iir & SDE_AUDIO_HDCP_MASK)
  1567. DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
  1568. if (pch_iir & SDE_AUDIO_TRANS_MASK)
  1569. DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
  1570. if (pch_iir & SDE_POISON)
  1571. DRM_ERROR("PCH poison interrupt\n");
  1572. if (pch_iir & SDE_FDI_MASK)
  1573. for_each_pipe(dev_priv, pipe)
  1574. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1575. pipe_name(pipe),
  1576. I915_READ(FDI_RX_IIR(pipe)));
  1577. if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
  1578. DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
  1579. if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
  1580. DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
  1581. if (pch_iir & SDE_TRANSA_FIFO_UNDER)
  1582. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
  1583. if (pch_iir & SDE_TRANSB_FIFO_UNDER)
  1584. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
  1585. }
  1586. static void ivb_err_int_handler(struct drm_device *dev)
  1587. {
  1588. struct drm_i915_private *dev_priv = dev->dev_private;
  1589. u32 err_int = I915_READ(GEN7_ERR_INT);
  1590. enum pipe pipe;
  1591. if (err_int & ERR_INT_POISON)
  1592. DRM_ERROR("Poison interrupt\n");
  1593. for_each_pipe(dev_priv, pipe) {
  1594. if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
  1595. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1596. if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
  1597. if (IS_IVYBRIDGE(dev))
  1598. ivb_pipe_crc_irq_handler(dev, pipe);
  1599. else
  1600. hsw_pipe_crc_irq_handler(dev, pipe);
  1601. }
  1602. }
  1603. I915_WRITE(GEN7_ERR_INT, err_int);
  1604. }
  1605. static void cpt_serr_int_handler(struct drm_device *dev)
  1606. {
  1607. struct drm_i915_private *dev_priv = dev->dev_private;
  1608. u32 serr_int = I915_READ(SERR_INT);
  1609. if (serr_int & SERR_INT_POISON)
  1610. DRM_ERROR("PCH poison interrupt\n");
  1611. if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
  1612. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
  1613. if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
  1614. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
  1615. if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
  1616. intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
  1617. I915_WRITE(SERR_INT, serr_int);
  1618. }
  1619. static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
  1620. {
  1621. struct drm_i915_private *dev_priv = dev->dev_private;
  1622. int pipe;
  1623. u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
  1624. u32 dig_hotplug_reg;
  1625. dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
  1626. I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
  1627. intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_cpt);
  1628. if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
  1629. int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
  1630. SDE_AUDIO_POWER_SHIFT_CPT);
  1631. DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
  1632. port_name(port));
  1633. }
  1634. if (pch_iir & SDE_AUX_MASK_CPT)
  1635. dp_aux_irq_handler(dev);
  1636. if (pch_iir & SDE_GMBUS_CPT)
  1637. gmbus_irq_handler(dev);
  1638. if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
  1639. DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
  1640. if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
  1641. DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
  1642. if (pch_iir & SDE_FDI_MASK_CPT)
  1643. for_each_pipe(dev_priv, pipe)
  1644. DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
  1645. pipe_name(pipe),
  1646. I915_READ(FDI_RX_IIR(pipe)));
  1647. if (pch_iir & SDE_ERROR_CPT)
  1648. cpt_serr_int_handler(dev);
  1649. }
  1650. static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1651. {
  1652. struct drm_i915_private *dev_priv = dev->dev_private;
  1653. enum pipe pipe;
  1654. if (de_iir & DE_AUX_CHANNEL_A)
  1655. dp_aux_irq_handler(dev);
  1656. if (de_iir & DE_GSE)
  1657. intel_opregion_asle_intr(dev);
  1658. if (de_iir & DE_POISON)
  1659. DRM_ERROR("Poison interrupt\n");
  1660. for_each_pipe(dev_priv, pipe) {
  1661. if (de_iir & DE_PIPE_VBLANK(pipe) &&
  1662. intel_pipe_handle_vblank(dev, pipe))
  1663. intel_check_page_flip(dev, pipe);
  1664. if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
  1665. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  1666. if (de_iir & DE_PIPE_CRC_DONE(pipe))
  1667. i9xx_pipe_crc_irq_handler(dev, pipe);
  1668. /* plane/pipes map 1:1 on ilk+ */
  1669. if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
  1670. intel_prepare_page_flip(dev, pipe);
  1671. intel_finish_page_flip_plane(dev, pipe);
  1672. }
  1673. }
  1674. /* check event from PCH */
  1675. if (de_iir & DE_PCH_EVENT) {
  1676. u32 pch_iir = I915_READ(SDEIIR);
  1677. if (HAS_PCH_CPT(dev))
  1678. cpt_irq_handler(dev, pch_iir);
  1679. else
  1680. ibx_irq_handler(dev, pch_iir);
  1681. /* should clear PCH hotplug event before clear CPU irq */
  1682. I915_WRITE(SDEIIR, pch_iir);
  1683. }
  1684. if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
  1685. ironlake_rps_change_irq_handler(dev);
  1686. }
  1687. static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
  1688. {
  1689. struct drm_i915_private *dev_priv = dev->dev_private;
  1690. enum pipe pipe;
  1691. if (de_iir & DE_ERR_INT_IVB)
  1692. ivb_err_int_handler(dev);
  1693. if (de_iir & DE_AUX_CHANNEL_A_IVB)
  1694. dp_aux_irq_handler(dev);
  1695. if (de_iir & DE_GSE_IVB)
  1696. intel_opregion_asle_intr(dev);
  1697. for_each_pipe(dev_priv, pipe) {
  1698. if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
  1699. intel_pipe_handle_vblank(dev, pipe))
  1700. intel_check_page_flip(dev, pipe);
  1701. /* plane/pipes map 1:1 on ilk+ */
  1702. if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
  1703. intel_prepare_page_flip(dev, pipe);
  1704. intel_finish_page_flip_plane(dev, pipe);
  1705. }
  1706. }
  1707. /* check event from PCH */
  1708. if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
  1709. u32 pch_iir = I915_READ(SDEIIR);
  1710. cpt_irq_handler(dev, pch_iir);
  1711. /* clear PCH hotplug event before clear CPU irq */
  1712. I915_WRITE(SDEIIR, pch_iir);
  1713. }
  1714. }
  1715. /*
  1716. * To handle irqs with the minimum potential races with fresh interrupts, we:
  1717. * 1 - Disable Master Interrupt Control.
  1718. * 2 - Find the source(s) of the interrupt.
  1719. * 3 - Clear the Interrupt Identity bits (IIR).
  1720. * 4 - Process the interrupt(s) that had bits set in the IIRs.
  1721. * 5 - Re-enable Master Interrupt Control.
  1722. */
  1723. static irqreturn_t ironlake_irq_handler(int irq, void *arg)
  1724. {
  1725. struct drm_device *dev = arg;
  1726. struct drm_i915_private *dev_priv = dev->dev_private;
  1727. u32 de_iir, gt_iir, de_ier, sde_ier = 0;
  1728. irqreturn_t ret = IRQ_NONE;
  1729. if (!intel_irqs_enabled(dev_priv))
  1730. return IRQ_NONE;
  1731. /* We get interrupts on unclaimed registers, so check for this before we
  1732. * do any I915_{READ,WRITE}. */
  1733. intel_uncore_check_errors(dev);
  1734. /* disable master interrupt before clearing iir */
  1735. de_ier = I915_READ(DEIER);
  1736. I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
  1737. POSTING_READ(DEIER);
  1738. /* Disable south interrupts. We'll only write to SDEIIR once, so further
  1739. * interrupts will will be stored on its back queue, and then we'll be
  1740. * able to process them after we restore SDEIER (as soon as we restore
  1741. * it, we'll get an interrupt if SDEIIR still has something to process
  1742. * due to its back queue). */
  1743. if (!HAS_PCH_NOP(dev)) {
  1744. sde_ier = I915_READ(SDEIER);
  1745. I915_WRITE(SDEIER, 0);
  1746. POSTING_READ(SDEIER);
  1747. }
  1748. /* Find, clear, then process each source of interrupt */
  1749. gt_iir = I915_READ(GTIIR);
  1750. if (gt_iir) {
  1751. I915_WRITE(GTIIR, gt_iir);
  1752. ret = IRQ_HANDLED;
  1753. if (INTEL_INFO(dev)->gen >= 6)
  1754. snb_gt_irq_handler(dev, dev_priv, gt_iir);
  1755. else
  1756. ilk_gt_irq_handler(dev, dev_priv, gt_iir);
  1757. }
  1758. de_iir = I915_READ(DEIIR);
  1759. if (de_iir) {
  1760. I915_WRITE(DEIIR, de_iir);
  1761. ret = IRQ_HANDLED;
  1762. if (INTEL_INFO(dev)->gen >= 7)
  1763. ivb_display_irq_handler(dev, de_iir);
  1764. else
  1765. ilk_display_irq_handler(dev, de_iir);
  1766. }
  1767. if (INTEL_INFO(dev)->gen >= 6) {
  1768. u32 pm_iir = I915_READ(GEN6_PMIIR);
  1769. if (pm_iir) {
  1770. I915_WRITE(GEN6_PMIIR, pm_iir);
  1771. ret = IRQ_HANDLED;
  1772. gen6_rps_irq_handler(dev_priv, pm_iir);
  1773. }
  1774. }
  1775. I915_WRITE(DEIER, de_ier);
  1776. POSTING_READ(DEIER);
  1777. if (!HAS_PCH_NOP(dev)) {
  1778. I915_WRITE(SDEIER, sde_ier);
  1779. POSTING_READ(SDEIER);
  1780. }
  1781. return ret;
  1782. }
  1783. static irqreturn_t gen8_irq_handler(int irq, void *arg)
  1784. {
  1785. struct drm_device *dev = arg;
  1786. struct drm_i915_private *dev_priv = dev->dev_private;
  1787. u32 master_ctl;
  1788. irqreturn_t ret = IRQ_NONE;
  1789. uint32_t tmp = 0;
  1790. enum pipe pipe;
  1791. u32 aux_mask = GEN8_AUX_CHANNEL_A;
  1792. if (!intel_irqs_enabled(dev_priv))
  1793. return IRQ_NONE;
  1794. if (IS_GEN9(dev))
  1795. aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
  1796. GEN9_AUX_CHANNEL_D;
  1797. master_ctl = I915_READ(GEN8_MASTER_IRQ);
  1798. master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
  1799. if (!master_ctl)
  1800. return IRQ_NONE;
  1801. I915_WRITE(GEN8_MASTER_IRQ, 0);
  1802. POSTING_READ(GEN8_MASTER_IRQ);
  1803. /* Find, clear, then process each source of interrupt */
  1804. ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
  1805. if (master_ctl & GEN8_DE_MISC_IRQ) {
  1806. tmp = I915_READ(GEN8_DE_MISC_IIR);
  1807. if (tmp) {
  1808. I915_WRITE(GEN8_DE_MISC_IIR, tmp);
  1809. ret = IRQ_HANDLED;
  1810. if (tmp & GEN8_DE_MISC_GSE)
  1811. intel_opregion_asle_intr(dev);
  1812. else
  1813. DRM_ERROR("Unexpected DE Misc interrupt\n");
  1814. }
  1815. else
  1816. DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
  1817. }
  1818. if (master_ctl & GEN8_DE_PORT_IRQ) {
  1819. tmp = I915_READ(GEN8_DE_PORT_IIR);
  1820. if (tmp) {
  1821. I915_WRITE(GEN8_DE_PORT_IIR, tmp);
  1822. ret = IRQ_HANDLED;
  1823. if (tmp & aux_mask)
  1824. dp_aux_irq_handler(dev);
  1825. else
  1826. DRM_ERROR("Unexpected DE Port interrupt\n");
  1827. }
  1828. else
  1829. DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
  1830. }
  1831. for_each_pipe(dev_priv, pipe) {
  1832. uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
  1833. if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
  1834. continue;
  1835. pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
  1836. if (pipe_iir) {
  1837. ret = IRQ_HANDLED;
  1838. I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
  1839. if (pipe_iir & GEN8_PIPE_VBLANK &&
  1840. intel_pipe_handle_vblank(dev, pipe))
  1841. intel_check_page_flip(dev, pipe);
  1842. if (IS_GEN9(dev))
  1843. flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
  1844. else
  1845. flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
  1846. if (flip_done) {
  1847. intel_prepare_page_flip(dev, pipe);
  1848. intel_finish_page_flip_plane(dev, pipe);
  1849. }
  1850. if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
  1851. hsw_pipe_crc_irq_handler(dev, pipe);
  1852. if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN)
  1853. intel_cpu_fifo_underrun_irq_handler(dev_priv,
  1854. pipe);
  1855. if (IS_GEN9(dev))
  1856. fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
  1857. else
  1858. fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  1859. if (fault_errors)
  1860. DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
  1861. pipe_name(pipe),
  1862. pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
  1863. } else
  1864. DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
  1865. }
  1866. if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
  1867. /*
  1868. * FIXME(BDW): Assume for now that the new interrupt handling
  1869. * scheme also closed the SDE interrupt handling race we've seen
  1870. * on older pch-split platforms. But this needs testing.
  1871. */
  1872. u32 pch_iir = I915_READ(SDEIIR);
  1873. if (pch_iir) {
  1874. I915_WRITE(SDEIIR, pch_iir);
  1875. ret = IRQ_HANDLED;
  1876. cpt_irq_handler(dev, pch_iir);
  1877. } else
  1878. DRM_ERROR("The master control interrupt lied (SDE)!\n");
  1879. }
  1880. I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
  1881. POSTING_READ(GEN8_MASTER_IRQ);
  1882. return ret;
  1883. }
  1884. static void i915_error_wake_up(struct drm_i915_private *dev_priv,
  1885. bool reset_completed)
  1886. {
  1887. struct intel_engine_cs *ring;
  1888. int i;
  1889. /*
  1890. * Notify all waiters for GPU completion events that reset state has
  1891. * been changed, and that they need to restart their wait after
  1892. * checking for potential errors (and bail out to drop locks if there is
  1893. * a gpu reset pending so that i915_error_work_func can acquire them).
  1894. */
  1895. /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
  1896. for_each_ring(ring, dev_priv, i)
  1897. wake_up_all(&ring->irq_queue);
  1898. /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
  1899. wake_up_all(&dev_priv->pending_flip_queue);
  1900. /*
  1901. * Signal tasks blocked in i915_gem_wait_for_error that the pending
  1902. * reset state is cleared.
  1903. */
  1904. if (reset_completed)
  1905. wake_up_all(&dev_priv->gpu_error.reset_queue);
  1906. }
  1907. /**
  1908. * i915_reset_and_wakeup - do process context error handling work
  1909. *
  1910. * Fire an error uevent so userspace can see that a hang or error
  1911. * was detected.
  1912. */
  1913. static void i915_reset_and_wakeup(struct drm_device *dev)
  1914. {
  1915. struct drm_i915_private *dev_priv = to_i915(dev);
  1916. struct i915_gpu_error *error = &dev_priv->gpu_error;
  1917. char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
  1918. char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
  1919. char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
  1920. int ret;
  1921. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
  1922. /*
  1923. * Note that there's only one work item which does gpu resets, so we
  1924. * need not worry about concurrent gpu resets potentially incrementing
  1925. * error->reset_counter twice. We only need to take care of another
  1926. * racing irq/hangcheck declaring the gpu dead for a second time. A
  1927. * quick check for that is good enough: schedule_work ensures the
  1928. * correct ordering between hang detection and this work item, and since
  1929. * the reset in-progress bit is only ever set by code outside of this
  1930. * work we don't need to worry about any other races.
  1931. */
  1932. if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
  1933. DRM_DEBUG_DRIVER("resetting chip\n");
  1934. kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
  1935. reset_event);
  1936. /*
  1937. * In most cases it's guaranteed that we get here with an RPM
  1938. * reference held, for example because there is a pending GPU
  1939. * request that won't finish until the reset is done. This
  1940. * isn't the case at least when we get here by doing a
  1941. * simulated reset via debugs, so get an RPM reference.
  1942. */
  1943. intel_runtime_pm_get(dev_priv);
  1944. intel_prepare_reset(dev);
  1945. /*
  1946. * All state reset _must_ be completed before we update the
  1947. * reset counter, for otherwise waiters might miss the reset
  1948. * pending state and not properly drop locks, resulting in
  1949. * deadlocks with the reset work.
  1950. */
  1951. ret = i915_reset(dev);
  1952. intel_finish_reset(dev);
  1953. intel_runtime_pm_put(dev_priv);
  1954. if (ret == 0) {
  1955. /*
  1956. * After all the gem state is reset, increment the reset
  1957. * counter and wake up everyone waiting for the reset to
  1958. * complete.
  1959. *
  1960. * Since unlock operations are a one-sided barrier only,
  1961. * we need to insert a barrier here to order any seqno
  1962. * updates before
  1963. * the counter increment.
  1964. */
  1965. smp_mb__before_atomic();
  1966. atomic_inc(&dev_priv->gpu_error.reset_counter);
  1967. kobject_uevent_env(&dev->primary->kdev->kobj,
  1968. KOBJ_CHANGE, reset_done_event);
  1969. } else {
  1970. atomic_set_mask(I915_WEDGED, &error->reset_counter);
  1971. }
  1972. /*
  1973. * Note: The wake_up also serves as a memory barrier so that
  1974. * waiters see the update value of the reset counter atomic_t.
  1975. */
  1976. i915_error_wake_up(dev_priv, true);
  1977. }
  1978. }
  1979. static void i915_report_and_clear_eir(struct drm_device *dev)
  1980. {
  1981. struct drm_i915_private *dev_priv = dev->dev_private;
  1982. uint32_t instdone[I915_NUM_INSTDONE_REG];
  1983. u32 eir = I915_READ(EIR);
  1984. int pipe, i;
  1985. if (!eir)
  1986. return;
  1987. pr_err("render error detected, EIR: 0x%08x\n", eir);
  1988. i915_get_extra_instdone(dev, instdone);
  1989. if (IS_G4X(dev)) {
  1990. if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
  1991. u32 ipeir = I915_READ(IPEIR_I965);
  1992. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  1993. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  1994. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  1995. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  1996. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  1997. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  1998. I915_WRITE(IPEIR_I965, ipeir);
  1999. POSTING_READ(IPEIR_I965);
  2000. }
  2001. if (eir & GM45_ERROR_PAGE_TABLE) {
  2002. u32 pgtbl_err = I915_READ(PGTBL_ER);
  2003. pr_err("page table error\n");
  2004. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  2005. I915_WRITE(PGTBL_ER, pgtbl_err);
  2006. POSTING_READ(PGTBL_ER);
  2007. }
  2008. }
  2009. if (!IS_GEN2(dev)) {
  2010. if (eir & I915_ERROR_PAGE_TABLE) {
  2011. u32 pgtbl_err = I915_READ(PGTBL_ER);
  2012. pr_err("page table error\n");
  2013. pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
  2014. I915_WRITE(PGTBL_ER, pgtbl_err);
  2015. POSTING_READ(PGTBL_ER);
  2016. }
  2017. }
  2018. if (eir & I915_ERROR_MEMORY_REFRESH) {
  2019. pr_err("memory refresh error:\n");
  2020. for_each_pipe(dev_priv, pipe)
  2021. pr_err("pipe %c stat: 0x%08x\n",
  2022. pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
  2023. /* pipestat has already been acked */
  2024. }
  2025. if (eir & I915_ERROR_INSTRUCTION) {
  2026. pr_err("instruction error\n");
  2027. pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
  2028. for (i = 0; i < ARRAY_SIZE(instdone); i++)
  2029. pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
  2030. if (INTEL_INFO(dev)->gen < 4) {
  2031. u32 ipeir = I915_READ(IPEIR);
  2032. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
  2033. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
  2034. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
  2035. I915_WRITE(IPEIR, ipeir);
  2036. POSTING_READ(IPEIR);
  2037. } else {
  2038. u32 ipeir = I915_READ(IPEIR_I965);
  2039. pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
  2040. pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
  2041. pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
  2042. pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
  2043. I915_WRITE(IPEIR_I965, ipeir);
  2044. POSTING_READ(IPEIR_I965);
  2045. }
  2046. }
  2047. I915_WRITE(EIR, eir);
  2048. POSTING_READ(EIR);
  2049. eir = I915_READ(EIR);
  2050. if (eir) {
  2051. /*
  2052. * some errors might have become stuck,
  2053. * mask them.
  2054. */
  2055. DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
  2056. I915_WRITE(EMR, I915_READ(EMR) | eir);
  2057. I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  2058. }
  2059. }
  2060. /**
  2061. * i915_handle_error - handle a gpu error
  2062. * @dev: drm device
  2063. *
  2064. * Do some basic checking of regsiter state at error time and
  2065. * dump it to the syslog. Also call i915_capture_error_state() to make
  2066. * sure we get a record and make it available in debugfs. Fire a uevent
  2067. * so userspace knows something bad happened (should trigger collection
  2068. * of a ring dump etc.).
  2069. */
  2070. void i915_handle_error(struct drm_device *dev, bool wedged,
  2071. const char *fmt, ...)
  2072. {
  2073. struct drm_i915_private *dev_priv = dev->dev_private;
  2074. va_list args;
  2075. char error_msg[80];
  2076. va_start(args, fmt);
  2077. vscnprintf(error_msg, sizeof(error_msg), fmt, args);
  2078. va_end(args);
  2079. i915_capture_error_state(dev, wedged, error_msg);
  2080. i915_report_and_clear_eir(dev);
  2081. if (wedged) {
  2082. atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
  2083. &dev_priv->gpu_error.reset_counter);
  2084. /*
  2085. * Wakeup waiting processes so that the reset function
  2086. * i915_reset_and_wakeup doesn't deadlock trying to grab
  2087. * various locks. By bumping the reset counter first, the woken
  2088. * processes will see a reset in progress and back off,
  2089. * releasing their locks and then wait for the reset completion.
  2090. * We must do this for _all_ gpu waiters that might hold locks
  2091. * that the reset work needs to acquire.
  2092. *
  2093. * Note: The wake_up serves as the required memory barrier to
  2094. * ensure that the waiters see the updated value of the reset
  2095. * counter atomic_t.
  2096. */
  2097. i915_error_wake_up(dev_priv, false);
  2098. }
  2099. i915_reset_and_wakeup(dev);
  2100. }
  2101. /* Called from drm generic code, passed 'crtc' which
  2102. * we use as a pipe index
  2103. */
  2104. static int i915_enable_vblank(struct drm_device *dev, int pipe)
  2105. {
  2106. struct drm_i915_private *dev_priv = dev->dev_private;
  2107. unsigned long irqflags;
  2108. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2109. if (INTEL_INFO(dev)->gen >= 4)
  2110. i915_enable_pipestat(dev_priv, pipe,
  2111. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2112. else
  2113. i915_enable_pipestat(dev_priv, pipe,
  2114. PIPE_VBLANK_INTERRUPT_STATUS);
  2115. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2116. return 0;
  2117. }
  2118. static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
  2119. {
  2120. struct drm_i915_private *dev_priv = dev->dev_private;
  2121. unsigned long irqflags;
  2122. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2123. DE_PIPE_VBLANK(pipe);
  2124. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2125. ironlake_enable_display_irq(dev_priv, bit);
  2126. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2127. return 0;
  2128. }
  2129. static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
  2130. {
  2131. struct drm_i915_private *dev_priv = dev->dev_private;
  2132. unsigned long irqflags;
  2133. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2134. i915_enable_pipestat(dev_priv, pipe,
  2135. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2136. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2137. return 0;
  2138. }
  2139. static int gen8_enable_vblank(struct drm_device *dev, int pipe)
  2140. {
  2141. struct drm_i915_private *dev_priv = dev->dev_private;
  2142. unsigned long irqflags;
  2143. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2144. dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
  2145. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2146. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2147. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2148. return 0;
  2149. }
  2150. /* Called from drm generic code, passed 'crtc' which
  2151. * we use as a pipe index
  2152. */
  2153. static void i915_disable_vblank(struct drm_device *dev, int pipe)
  2154. {
  2155. struct drm_i915_private *dev_priv = dev->dev_private;
  2156. unsigned long irqflags;
  2157. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2158. i915_disable_pipestat(dev_priv, pipe,
  2159. PIPE_VBLANK_INTERRUPT_STATUS |
  2160. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2161. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2162. }
  2163. static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
  2164. {
  2165. struct drm_i915_private *dev_priv = dev->dev_private;
  2166. unsigned long irqflags;
  2167. uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
  2168. DE_PIPE_VBLANK(pipe);
  2169. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2170. ironlake_disable_display_irq(dev_priv, bit);
  2171. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2172. }
  2173. static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
  2174. {
  2175. struct drm_i915_private *dev_priv = dev->dev_private;
  2176. unsigned long irqflags;
  2177. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2178. i915_disable_pipestat(dev_priv, pipe,
  2179. PIPE_START_VBLANK_INTERRUPT_STATUS);
  2180. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2181. }
  2182. static void gen8_disable_vblank(struct drm_device *dev, int pipe)
  2183. {
  2184. struct drm_i915_private *dev_priv = dev->dev_private;
  2185. unsigned long irqflags;
  2186. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  2187. dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
  2188. I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
  2189. POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
  2190. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  2191. }
  2192. static struct drm_i915_gem_request *
  2193. ring_last_request(struct intel_engine_cs *ring)
  2194. {
  2195. return list_entry(ring->request_list.prev,
  2196. struct drm_i915_gem_request, list);
  2197. }
  2198. static bool
  2199. ring_idle(struct intel_engine_cs *ring)
  2200. {
  2201. return (list_empty(&ring->request_list) ||
  2202. i915_gem_request_completed(ring_last_request(ring), false));
  2203. }
  2204. static bool
  2205. ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
  2206. {
  2207. if (INTEL_INFO(dev)->gen >= 8) {
  2208. return (ipehr >> 23) == 0x1c;
  2209. } else {
  2210. ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
  2211. return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
  2212. MI_SEMAPHORE_REGISTER);
  2213. }
  2214. }
  2215. static struct intel_engine_cs *
  2216. semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
  2217. {
  2218. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2219. struct intel_engine_cs *signaller;
  2220. int i;
  2221. if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
  2222. for_each_ring(signaller, dev_priv, i) {
  2223. if (ring == signaller)
  2224. continue;
  2225. if (offset == signaller->semaphore.signal_ggtt[ring->id])
  2226. return signaller;
  2227. }
  2228. } else {
  2229. u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
  2230. for_each_ring(signaller, dev_priv, i) {
  2231. if(ring == signaller)
  2232. continue;
  2233. if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
  2234. return signaller;
  2235. }
  2236. }
  2237. DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
  2238. ring->id, ipehr, offset);
  2239. return NULL;
  2240. }
  2241. static struct intel_engine_cs *
  2242. semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
  2243. {
  2244. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2245. u32 cmd, ipehr, head;
  2246. u64 offset = 0;
  2247. int i, backwards;
  2248. ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  2249. if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
  2250. return NULL;
  2251. /*
  2252. * HEAD is likely pointing to the dword after the actual command,
  2253. * so scan backwards until we find the MBOX. But limit it to just 3
  2254. * or 4 dwords depending on the semaphore wait command size.
  2255. * Note that we don't care about ACTHD here since that might
  2256. * point at at batch, and semaphores are always emitted into the
  2257. * ringbuffer itself.
  2258. */
  2259. head = I915_READ_HEAD(ring) & HEAD_ADDR;
  2260. backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
  2261. for (i = backwards; i; --i) {
  2262. /*
  2263. * Be paranoid and presume the hw has gone off into the wild -
  2264. * our ring is smaller than what the hardware (and hence
  2265. * HEAD_ADDR) allows. Also handles wrap-around.
  2266. */
  2267. head &= ring->buffer->size - 1;
  2268. /* This here seems to blow up */
  2269. cmd = ioread32(ring->buffer->virtual_start + head);
  2270. if (cmd == ipehr)
  2271. break;
  2272. head -= 4;
  2273. }
  2274. if (!i)
  2275. return NULL;
  2276. *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
  2277. if (INTEL_INFO(ring->dev)->gen >= 8) {
  2278. offset = ioread32(ring->buffer->virtual_start + head + 12);
  2279. offset <<= 32;
  2280. offset = ioread32(ring->buffer->virtual_start + head + 8);
  2281. }
  2282. return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
  2283. }
  2284. static int semaphore_passed(struct intel_engine_cs *ring)
  2285. {
  2286. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  2287. struct intel_engine_cs *signaller;
  2288. u32 seqno;
  2289. ring->hangcheck.deadlock++;
  2290. signaller = semaphore_waits_for(ring, &seqno);
  2291. if (signaller == NULL)
  2292. return -1;
  2293. /* Prevent pathological recursion due to driver bugs */
  2294. if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
  2295. return -1;
  2296. if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
  2297. return 1;
  2298. /* cursory check for an unkickable deadlock */
  2299. if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
  2300. semaphore_passed(signaller) < 0)
  2301. return -1;
  2302. return 0;
  2303. }
  2304. static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
  2305. {
  2306. struct intel_engine_cs *ring;
  2307. int i;
  2308. for_each_ring(ring, dev_priv, i)
  2309. ring->hangcheck.deadlock = 0;
  2310. }
  2311. static enum intel_ring_hangcheck_action
  2312. ring_stuck(struct intel_engine_cs *ring, u64 acthd)
  2313. {
  2314. struct drm_device *dev = ring->dev;
  2315. struct drm_i915_private *dev_priv = dev->dev_private;
  2316. u32 tmp;
  2317. if (acthd != ring->hangcheck.acthd) {
  2318. if (acthd > ring->hangcheck.max_acthd) {
  2319. ring->hangcheck.max_acthd = acthd;
  2320. return HANGCHECK_ACTIVE;
  2321. }
  2322. return HANGCHECK_ACTIVE_LOOP;
  2323. }
  2324. if (IS_GEN2(dev))
  2325. return HANGCHECK_HUNG;
  2326. /* Is the chip hanging on a WAIT_FOR_EVENT?
  2327. * If so we can simply poke the RB_WAIT bit
  2328. * and break the hang. This should work on
  2329. * all but the second generation chipsets.
  2330. */
  2331. tmp = I915_READ_CTL(ring);
  2332. if (tmp & RING_WAIT) {
  2333. i915_handle_error(dev, false,
  2334. "Kicking stuck wait on %s",
  2335. ring->name);
  2336. I915_WRITE_CTL(ring, tmp);
  2337. return HANGCHECK_KICK;
  2338. }
  2339. if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
  2340. switch (semaphore_passed(ring)) {
  2341. default:
  2342. return HANGCHECK_HUNG;
  2343. case 1:
  2344. i915_handle_error(dev, false,
  2345. "Kicking stuck semaphore on %s",
  2346. ring->name);
  2347. I915_WRITE_CTL(ring, tmp);
  2348. return HANGCHECK_KICK;
  2349. case 0:
  2350. return HANGCHECK_WAIT;
  2351. }
  2352. }
  2353. return HANGCHECK_HUNG;
  2354. }
  2355. /*
  2356. * This is called when the chip hasn't reported back with completed
  2357. * batchbuffers in a long time. We keep track per ring seqno progress and
  2358. * if there are no progress, hangcheck score for that ring is increased.
  2359. * Further, acthd is inspected to see if the ring is stuck. On stuck case
  2360. * we kick the ring. If we see no progress on three subsequent calls
  2361. * we assume chip is wedged and try to fix it by resetting the chip.
  2362. */
  2363. static void i915_hangcheck_elapsed(struct work_struct *work)
  2364. {
  2365. struct drm_i915_private *dev_priv =
  2366. container_of(work, typeof(*dev_priv),
  2367. gpu_error.hangcheck_work.work);
  2368. struct drm_device *dev = dev_priv->dev;
  2369. struct intel_engine_cs *ring;
  2370. int i;
  2371. int busy_count = 0, rings_hung = 0;
  2372. bool stuck[I915_NUM_RINGS] = { 0 };
  2373. #define BUSY 1
  2374. #define KICK 5
  2375. #define HUNG 20
  2376. if (!i915.enable_hangcheck)
  2377. return;
  2378. for_each_ring(ring, dev_priv, i) {
  2379. u64 acthd;
  2380. u32 seqno;
  2381. bool busy = true;
  2382. semaphore_clear_deadlocks(dev_priv);
  2383. seqno = ring->get_seqno(ring, false);
  2384. acthd = intel_ring_get_active_head(ring);
  2385. if (ring->hangcheck.seqno == seqno) {
  2386. if (ring_idle(ring)) {
  2387. ring->hangcheck.action = HANGCHECK_IDLE;
  2388. if (waitqueue_active(&ring->irq_queue)) {
  2389. /* Issue a wake-up to catch stuck h/w. */
  2390. if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
  2391. if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
  2392. DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
  2393. ring->name);
  2394. else
  2395. DRM_INFO("Fake missed irq on %s\n",
  2396. ring->name);
  2397. wake_up_all(&ring->irq_queue);
  2398. }
  2399. /* Safeguard against driver failure */
  2400. ring->hangcheck.score += BUSY;
  2401. } else
  2402. busy = false;
  2403. } else {
  2404. /* We always increment the hangcheck score
  2405. * if the ring is busy and still processing
  2406. * the same request, so that no single request
  2407. * can run indefinitely (such as a chain of
  2408. * batches). The only time we do not increment
  2409. * the hangcheck score on this ring, if this
  2410. * ring is in a legitimate wait for another
  2411. * ring. In that case the waiting ring is a
  2412. * victim and we want to be sure we catch the
  2413. * right culprit. Then every time we do kick
  2414. * the ring, add a small increment to the
  2415. * score so that we can catch a batch that is
  2416. * being repeatedly kicked and so responsible
  2417. * for stalling the machine.
  2418. */
  2419. ring->hangcheck.action = ring_stuck(ring,
  2420. acthd);
  2421. switch (ring->hangcheck.action) {
  2422. case HANGCHECK_IDLE:
  2423. case HANGCHECK_WAIT:
  2424. case HANGCHECK_ACTIVE:
  2425. break;
  2426. case HANGCHECK_ACTIVE_LOOP:
  2427. ring->hangcheck.score += BUSY;
  2428. break;
  2429. case HANGCHECK_KICK:
  2430. ring->hangcheck.score += KICK;
  2431. break;
  2432. case HANGCHECK_HUNG:
  2433. ring->hangcheck.score += HUNG;
  2434. stuck[i] = true;
  2435. break;
  2436. }
  2437. }
  2438. } else {
  2439. ring->hangcheck.action = HANGCHECK_ACTIVE;
  2440. /* Gradually reduce the count so that we catch DoS
  2441. * attempts across multiple batches.
  2442. */
  2443. if (ring->hangcheck.score > 0)
  2444. ring->hangcheck.score--;
  2445. ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
  2446. }
  2447. ring->hangcheck.seqno = seqno;
  2448. ring->hangcheck.acthd = acthd;
  2449. busy_count += busy;
  2450. }
  2451. for_each_ring(ring, dev_priv, i) {
  2452. if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
  2453. DRM_INFO("%s on %s\n",
  2454. stuck[i] ? "stuck" : "no progress",
  2455. ring->name);
  2456. rings_hung++;
  2457. }
  2458. }
  2459. if (rings_hung)
  2460. return i915_handle_error(dev, true, "Ring hung");
  2461. if (busy_count)
  2462. /* Reset timer case chip hangs without another request
  2463. * being added */
  2464. i915_queue_hangcheck(dev);
  2465. }
  2466. void i915_queue_hangcheck(struct drm_device *dev)
  2467. {
  2468. struct i915_gpu_error *e = &to_i915(dev)->gpu_error;
  2469. if (!i915.enable_hangcheck)
  2470. return;
  2471. /* Don't continually defer the hangcheck so that it is always run at
  2472. * least once after work has been scheduled on any ring. Otherwise,
  2473. * we will ignore a hung ring if a second ring is kept busy.
  2474. */
  2475. queue_delayed_work(e->hangcheck_wq, &e->hangcheck_work,
  2476. round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES));
  2477. }
  2478. static void ibx_irq_reset(struct drm_device *dev)
  2479. {
  2480. struct drm_i915_private *dev_priv = dev->dev_private;
  2481. if (HAS_PCH_NOP(dev))
  2482. return;
  2483. GEN5_IRQ_RESET(SDE);
  2484. if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
  2485. I915_WRITE(SERR_INT, 0xffffffff);
  2486. }
  2487. /*
  2488. * SDEIER is also touched by the interrupt handler to work around missed PCH
  2489. * interrupts. Hence we can't update it after the interrupt handler is enabled -
  2490. * instead we unconditionally enable all PCH interrupt sources here, but then
  2491. * only unmask them as needed with SDEIMR.
  2492. *
  2493. * This function needs to be called before interrupts are enabled.
  2494. */
  2495. static void ibx_irq_pre_postinstall(struct drm_device *dev)
  2496. {
  2497. struct drm_i915_private *dev_priv = dev->dev_private;
  2498. if (HAS_PCH_NOP(dev))
  2499. return;
  2500. WARN_ON(I915_READ(SDEIER) != 0);
  2501. I915_WRITE(SDEIER, 0xffffffff);
  2502. POSTING_READ(SDEIER);
  2503. }
  2504. static void gen5_gt_irq_reset(struct drm_device *dev)
  2505. {
  2506. struct drm_i915_private *dev_priv = dev->dev_private;
  2507. GEN5_IRQ_RESET(GT);
  2508. if (INTEL_INFO(dev)->gen >= 6)
  2509. GEN5_IRQ_RESET(GEN6_PM);
  2510. }
  2511. /* drm_dma.h hooks
  2512. */
  2513. static void ironlake_irq_reset(struct drm_device *dev)
  2514. {
  2515. struct drm_i915_private *dev_priv = dev->dev_private;
  2516. I915_WRITE(HWSTAM, 0xffffffff);
  2517. GEN5_IRQ_RESET(DE);
  2518. if (IS_GEN7(dev))
  2519. I915_WRITE(GEN7_ERR_INT, 0xffffffff);
  2520. gen5_gt_irq_reset(dev);
  2521. ibx_irq_reset(dev);
  2522. }
  2523. static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
  2524. {
  2525. enum pipe pipe;
  2526. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2527. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  2528. for_each_pipe(dev_priv, pipe)
  2529. I915_WRITE(PIPESTAT(pipe), 0xffff);
  2530. GEN5_IRQ_RESET(VLV_);
  2531. }
  2532. static void valleyview_irq_preinstall(struct drm_device *dev)
  2533. {
  2534. struct drm_i915_private *dev_priv = dev->dev_private;
  2535. /* VLV magic */
  2536. I915_WRITE(VLV_IMR, 0);
  2537. I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
  2538. I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
  2539. I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
  2540. gen5_gt_irq_reset(dev);
  2541. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2542. vlv_display_irq_reset(dev_priv);
  2543. }
  2544. static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
  2545. {
  2546. GEN8_IRQ_RESET_NDX(GT, 0);
  2547. GEN8_IRQ_RESET_NDX(GT, 1);
  2548. GEN8_IRQ_RESET_NDX(GT, 2);
  2549. GEN8_IRQ_RESET_NDX(GT, 3);
  2550. }
  2551. static void gen8_irq_reset(struct drm_device *dev)
  2552. {
  2553. struct drm_i915_private *dev_priv = dev->dev_private;
  2554. int pipe;
  2555. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2556. POSTING_READ(GEN8_MASTER_IRQ);
  2557. gen8_gt_irq_reset(dev_priv);
  2558. for_each_pipe(dev_priv, pipe)
  2559. if (intel_display_power_is_enabled(dev_priv,
  2560. POWER_DOMAIN_PIPE(pipe)))
  2561. GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
  2562. GEN5_IRQ_RESET(GEN8_DE_PORT_);
  2563. GEN5_IRQ_RESET(GEN8_DE_MISC_);
  2564. GEN5_IRQ_RESET(GEN8_PCU_);
  2565. ibx_irq_reset(dev);
  2566. }
  2567. void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
  2568. unsigned int pipe_mask)
  2569. {
  2570. uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
  2571. spin_lock_irq(&dev_priv->irq_lock);
  2572. if (pipe_mask & 1 << PIPE_A)
  2573. GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_A,
  2574. dev_priv->de_irq_mask[PIPE_A],
  2575. ~dev_priv->de_irq_mask[PIPE_A] | extra_ier);
  2576. if (pipe_mask & 1 << PIPE_B)
  2577. GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B,
  2578. dev_priv->de_irq_mask[PIPE_B],
  2579. ~dev_priv->de_irq_mask[PIPE_B] | extra_ier);
  2580. if (pipe_mask & 1 << PIPE_C)
  2581. GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C,
  2582. dev_priv->de_irq_mask[PIPE_C],
  2583. ~dev_priv->de_irq_mask[PIPE_C] | extra_ier);
  2584. spin_unlock_irq(&dev_priv->irq_lock);
  2585. }
  2586. static void cherryview_irq_preinstall(struct drm_device *dev)
  2587. {
  2588. struct drm_i915_private *dev_priv = dev->dev_private;
  2589. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2590. POSTING_READ(GEN8_MASTER_IRQ);
  2591. gen8_gt_irq_reset(dev_priv);
  2592. GEN5_IRQ_RESET(GEN8_PCU_);
  2593. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
  2594. vlv_display_irq_reset(dev_priv);
  2595. }
  2596. static void ibx_hpd_irq_setup(struct drm_device *dev)
  2597. {
  2598. struct drm_i915_private *dev_priv = dev->dev_private;
  2599. struct intel_encoder *intel_encoder;
  2600. u32 hotplug_irqs, hotplug, enabled_irqs = 0;
  2601. if (HAS_PCH_IBX(dev)) {
  2602. hotplug_irqs = SDE_HOTPLUG_MASK;
  2603. for_each_intel_encoder(dev, intel_encoder)
  2604. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2605. enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
  2606. } else {
  2607. hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
  2608. for_each_intel_encoder(dev, intel_encoder)
  2609. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  2610. enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
  2611. }
  2612. ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
  2613. /*
  2614. * Enable digital hotplug on the PCH, and configure the DP short pulse
  2615. * duration to 2ms (which is the minimum in the Display Port spec)
  2616. *
  2617. * This register is the same on all known PCH chips.
  2618. */
  2619. hotplug = I915_READ(PCH_PORT_HOTPLUG);
  2620. hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
  2621. hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
  2622. hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
  2623. hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
  2624. I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
  2625. }
  2626. static void ibx_irq_postinstall(struct drm_device *dev)
  2627. {
  2628. struct drm_i915_private *dev_priv = dev->dev_private;
  2629. u32 mask;
  2630. if (HAS_PCH_NOP(dev))
  2631. return;
  2632. if (HAS_PCH_IBX(dev))
  2633. mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
  2634. else
  2635. mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
  2636. GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
  2637. I915_WRITE(SDEIMR, ~mask);
  2638. }
  2639. static void gen5_gt_irq_postinstall(struct drm_device *dev)
  2640. {
  2641. struct drm_i915_private *dev_priv = dev->dev_private;
  2642. u32 pm_irqs, gt_irqs;
  2643. pm_irqs = gt_irqs = 0;
  2644. dev_priv->gt_irq_mask = ~0;
  2645. if (HAS_L3_DPF(dev)) {
  2646. /* L3 parity interrupt is always unmasked. */
  2647. dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
  2648. gt_irqs |= GT_PARITY_ERROR(dev);
  2649. }
  2650. gt_irqs |= GT_RENDER_USER_INTERRUPT;
  2651. if (IS_GEN5(dev)) {
  2652. gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
  2653. ILK_BSD_USER_INTERRUPT;
  2654. } else {
  2655. gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
  2656. }
  2657. GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
  2658. if (INTEL_INFO(dev)->gen >= 6) {
  2659. /*
  2660. * RPS interrupts will get enabled/disabled on demand when RPS
  2661. * itself is enabled/disabled.
  2662. */
  2663. if (HAS_VEBOX(dev))
  2664. pm_irqs |= PM_VEBOX_USER_INTERRUPT;
  2665. dev_priv->pm_irq_mask = 0xffffffff;
  2666. GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
  2667. }
  2668. }
  2669. static int ironlake_irq_postinstall(struct drm_device *dev)
  2670. {
  2671. struct drm_i915_private *dev_priv = dev->dev_private;
  2672. u32 display_mask, extra_mask;
  2673. if (INTEL_INFO(dev)->gen >= 7) {
  2674. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
  2675. DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
  2676. DE_PLANEB_FLIP_DONE_IVB |
  2677. DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
  2678. extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
  2679. DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
  2680. } else {
  2681. display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
  2682. DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
  2683. DE_AUX_CHANNEL_A |
  2684. DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
  2685. DE_POISON);
  2686. extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
  2687. DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
  2688. }
  2689. dev_priv->irq_mask = ~display_mask;
  2690. I915_WRITE(HWSTAM, 0xeffe);
  2691. ibx_irq_pre_postinstall(dev);
  2692. GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
  2693. gen5_gt_irq_postinstall(dev);
  2694. ibx_irq_postinstall(dev);
  2695. if (IS_IRONLAKE_M(dev)) {
  2696. /* Enable PCU event interrupts
  2697. *
  2698. * spinlocking not required here for correctness since interrupt
  2699. * setup is guaranteed to run in single-threaded context. But we
  2700. * need it to make the assert_spin_locked happy. */
  2701. spin_lock_irq(&dev_priv->irq_lock);
  2702. ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
  2703. spin_unlock_irq(&dev_priv->irq_lock);
  2704. }
  2705. return 0;
  2706. }
  2707. static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
  2708. {
  2709. u32 pipestat_mask;
  2710. u32 iir_mask;
  2711. enum pipe pipe;
  2712. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2713. PIPE_FIFO_UNDERRUN_STATUS;
  2714. for_each_pipe(dev_priv, pipe)
  2715. I915_WRITE(PIPESTAT(pipe), pipestat_mask);
  2716. POSTING_READ(PIPESTAT(PIPE_A));
  2717. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2718. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2719. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  2720. for_each_pipe(dev_priv, pipe)
  2721. i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
  2722. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2723. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2724. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2725. if (IS_CHERRYVIEW(dev_priv))
  2726. iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  2727. dev_priv->irq_mask &= ~iir_mask;
  2728. I915_WRITE(VLV_IIR, iir_mask);
  2729. I915_WRITE(VLV_IIR, iir_mask);
  2730. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2731. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2732. POSTING_READ(VLV_IMR);
  2733. }
  2734. static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
  2735. {
  2736. u32 pipestat_mask;
  2737. u32 iir_mask;
  2738. enum pipe pipe;
  2739. iir_mask = I915_DISPLAY_PORT_INTERRUPT |
  2740. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2741. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
  2742. if (IS_CHERRYVIEW(dev_priv))
  2743. iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
  2744. dev_priv->irq_mask |= iir_mask;
  2745. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2746. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2747. I915_WRITE(VLV_IIR, iir_mask);
  2748. I915_WRITE(VLV_IIR, iir_mask);
  2749. POSTING_READ(VLV_IIR);
  2750. pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
  2751. PIPE_CRC_DONE_INTERRUPT_STATUS;
  2752. i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  2753. for_each_pipe(dev_priv, pipe)
  2754. i915_disable_pipestat(dev_priv, pipe, pipestat_mask);
  2755. pipestat_mask = PIPESTAT_INT_STATUS_MASK |
  2756. PIPE_FIFO_UNDERRUN_STATUS;
  2757. for_each_pipe(dev_priv, pipe)
  2758. I915_WRITE(PIPESTAT(pipe), pipestat_mask);
  2759. POSTING_READ(PIPESTAT(PIPE_A));
  2760. }
  2761. void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
  2762. {
  2763. assert_spin_locked(&dev_priv->irq_lock);
  2764. if (dev_priv->display_irqs_enabled)
  2765. return;
  2766. dev_priv->display_irqs_enabled = true;
  2767. if (intel_irqs_enabled(dev_priv))
  2768. valleyview_display_irqs_install(dev_priv);
  2769. }
  2770. void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
  2771. {
  2772. assert_spin_locked(&dev_priv->irq_lock);
  2773. if (!dev_priv->display_irqs_enabled)
  2774. return;
  2775. dev_priv->display_irqs_enabled = false;
  2776. if (intel_irqs_enabled(dev_priv))
  2777. valleyview_display_irqs_uninstall(dev_priv);
  2778. }
  2779. static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
  2780. {
  2781. dev_priv->irq_mask = ~0;
  2782. I915_WRITE(PORT_HOTPLUG_EN, 0);
  2783. POSTING_READ(PORT_HOTPLUG_EN);
  2784. I915_WRITE(VLV_IIR, 0xffffffff);
  2785. I915_WRITE(VLV_IIR, 0xffffffff);
  2786. I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
  2787. I915_WRITE(VLV_IMR, dev_priv->irq_mask);
  2788. POSTING_READ(VLV_IMR);
  2789. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2790. * just to make the assert_spin_locked check happy. */
  2791. spin_lock_irq(&dev_priv->irq_lock);
  2792. if (dev_priv->display_irqs_enabled)
  2793. valleyview_display_irqs_install(dev_priv);
  2794. spin_unlock_irq(&dev_priv->irq_lock);
  2795. }
  2796. static int valleyview_irq_postinstall(struct drm_device *dev)
  2797. {
  2798. struct drm_i915_private *dev_priv = dev->dev_private;
  2799. vlv_display_irq_postinstall(dev_priv);
  2800. gen5_gt_irq_postinstall(dev);
  2801. /* ack & enable invalid PTE error interrupts */
  2802. #if 0 /* FIXME: add support to irq handler for checking these bits */
  2803. I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
  2804. I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
  2805. #endif
  2806. I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
  2807. return 0;
  2808. }
  2809. static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
  2810. {
  2811. /* These are interrupts we'll toggle with the ring mask register */
  2812. uint32_t gt_interrupts[] = {
  2813. GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  2814. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  2815. GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
  2816. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
  2817. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
  2818. GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
  2819. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
  2820. GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
  2821. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
  2822. 0,
  2823. GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
  2824. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
  2825. };
  2826. dev_priv->pm_irq_mask = 0xffffffff;
  2827. GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
  2828. GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
  2829. /*
  2830. * RPS interrupts will get enabled/disabled on demand when RPS itself
  2831. * is enabled/disabled.
  2832. */
  2833. GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
  2834. GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
  2835. }
  2836. static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
  2837. {
  2838. uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
  2839. uint32_t de_pipe_enables;
  2840. int pipe;
  2841. u32 aux_en = GEN8_AUX_CHANNEL_A;
  2842. if (IS_GEN9(dev_priv)) {
  2843. de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
  2844. GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
  2845. aux_en |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
  2846. GEN9_AUX_CHANNEL_D;
  2847. } else
  2848. de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
  2849. GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
  2850. de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
  2851. GEN8_PIPE_FIFO_UNDERRUN;
  2852. dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
  2853. dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
  2854. dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
  2855. for_each_pipe(dev_priv, pipe)
  2856. if (intel_display_power_is_enabled(dev_priv,
  2857. POWER_DOMAIN_PIPE(pipe)))
  2858. GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
  2859. dev_priv->de_irq_mask[pipe],
  2860. de_pipe_enables);
  2861. GEN5_IRQ_INIT(GEN8_DE_PORT_, ~aux_en, aux_en);
  2862. }
  2863. static int gen8_irq_postinstall(struct drm_device *dev)
  2864. {
  2865. struct drm_i915_private *dev_priv = dev->dev_private;
  2866. ibx_irq_pre_postinstall(dev);
  2867. gen8_gt_irq_postinstall(dev_priv);
  2868. gen8_de_irq_postinstall(dev_priv);
  2869. ibx_irq_postinstall(dev);
  2870. I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
  2871. POSTING_READ(GEN8_MASTER_IRQ);
  2872. return 0;
  2873. }
  2874. static int cherryview_irq_postinstall(struct drm_device *dev)
  2875. {
  2876. struct drm_i915_private *dev_priv = dev->dev_private;
  2877. vlv_display_irq_postinstall(dev_priv);
  2878. gen8_gt_irq_postinstall(dev_priv);
  2879. I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
  2880. POSTING_READ(GEN8_MASTER_IRQ);
  2881. return 0;
  2882. }
  2883. static void gen8_irq_uninstall(struct drm_device *dev)
  2884. {
  2885. struct drm_i915_private *dev_priv = dev->dev_private;
  2886. if (!dev_priv)
  2887. return;
  2888. gen8_irq_reset(dev);
  2889. }
  2890. static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv)
  2891. {
  2892. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2893. * just to make the assert_spin_locked check happy. */
  2894. spin_lock_irq(&dev_priv->irq_lock);
  2895. if (dev_priv->display_irqs_enabled)
  2896. valleyview_display_irqs_uninstall(dev_priv);
  2897. spin_unlock_irq(&dev_priv->irq_lock);
  2898. vlv_display_irq_reset(dev_priv);
  2899. dev_priv->irq_mask = ~0;
  2900. }
  2901. static void valleyview_irq_uninstall(struct drm_device *dev)
  2902. {
  2903. struct drm_i915_private *dev_priv = dev->dev_private;
  2904. if (!dev_priv)
  2905. return;
  2906. I915_WRITE(VLV_MASTER_IER, 0);
  2907. gen5_gt_irq_reset(dev);
  2908. I915_WRITE(HWSTAM, 0xffffffff);
  2909. vlv_display_irq_uninstall(dev_priv);
  2910. }
  2911. static void cherryview_irq_uninstall(struct drm_device *dev)
  2912. {
  2913. struct drm_i915_private *dev_priv = dev->dev_private;
  2914. if (!dev_priv)
  2915. return;
  2916. I915_WRITE(GEN8_MASTER_IRQ, 0);
  2917. POSTING_READ(GEN8_MASTER_IRQ);
  2918. gen8_gt_irq_reset(dev_priv);
  2919. GEN5_IRQ_RESET(GEN8_PCU_);
  2920. vlv_display_irq_uninstall(dev_priv);
  2921. }
  2922. static void ironlake_irq_uninstall(struct drm_device *dev)
  2923. {
  2924. struct drm_i915_private *dev_priv = dev->dev_private;
  2925. if (!dev_priv)
  2926. return;
  2927. ironlake_irq_reset(dev);
  2928. }
  2929. static void i8xx_irq_preinstall(struct drm_device * dev)
  2930. {
  2931. struct drm_i915_private *dev_priv = dev->dev_private;
  2932. int pipe;
  2933. for_each_pipe(dev_priv, pipe)
  2934. I915_WRITE(PIPESTAT(pipe), 0);
  2935. I915_WRITE16(IMR, 0xffff);
  2936. I915_WRITE16(IER, 0x0);
  2937. POSTING_READ16(IER);
  2938. }
  2939. static int i8xx_irq_postinstall(struct drm_device *dev)
  2940. {
  2941. struct drm_i915_private *dev_priv = dev->dev_private;
  2942. I915_WRITE16(EMR,
  2943. ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  2944. /* Unmask the interrupts that we always want on. */
  2945. dev_priv->irq_mask =
  2946. ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2947. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2948. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  2949. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  2950. I915_WRITE16(IMR, dev_priv->irq_mask);
  2951. I915_WRITE16(IER,
  2952. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  2953. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  2954. I915_USER_INTERRUPT);
  2955. POSTING_READ16(IER);
  2956. /* Interrupt setup is already guaranteed to be single-threaded, this is
  2957. * just to make the assert_spin_locked check happy. */
  2958. spin_lock_irq(&dev_priv->irq_lock);
  2959. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  2960. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  2961. spin_unlock_irq(&dev_priv->irq_lock);
  2962. return 0;
  2963. }
  2964. /*
  2965. * Returns true when a page flip has completed.
  2966. */
  2967. static bool i8xx_handle_vblank(struct drm_device *dev,
  2968. int plane, int pipe, u32 iir)
  2969. {
  2970. struct drm_i915_private *dev_priv = dev->dev_private;
  2971. u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  2972. if (!intel_pipe_handle_vblank(dev, pipe))
  2973. return false;
  2974. if ((iir & flip_pending) == 0)
  2975. goto check_page_flip;
  2976. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  2977. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  2978. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  2979. * the flip is completed (no longer pending). Since this doesn't raise
  2980. * an interrupt per se, we watch for the change at vblank.
  2981. */
  2982. if (I915_READ16(ISR) & flip_pending)
  2983. goto check_page_flip;
  2984. intel_prepare_page_flip(dev, plane);
  2985. intel_finish_page_flip(dev, pipe);
  2986. return true;
  2987. check_page_flip:
  2988. intel_check_page_flip(dev, pipe);
  2989. return false;
  2990. }
  2991. static irqreturn_t i8xx_irq_handler(int irq, void *arg)
  2992. {
  2993. struct drm_device *dev = arg;
  2994. struct drm_i915_private *dev_priv = dev->dev_private;
  2995. u16 iir, new_iir;
  2996. u32 pipe_stats[2];
  2997. int pipe;
  2998. u16 flip_mask =
  2999. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3000. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3001. if (!intel_irqs_enabled(dev_priv))
  3002. return IRQ_NONE;
  3003. iir = I915_READ16(IIR);
  3004. if (iir == 0)
  3005. return IRQ_NONE;
  3006. while (iir & ~flip_mask) {
  3007. /* Can't rely on pipestat interrupt bit in iir as it might
  3008. * have been cleared after the pipestat interrupt was received.
  3009. * It doesn't set the bit in iir again, but it still produces
  3010. * interrupts (for non-MSI).
  3011. */
  3012. spin_lock(&dev_priv->irq_lock);
  3013. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3014. DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
  3015. for_each_pipe(dev_priv, pipe) {
  3016. int reg = PIPESTAT(pipe);
  3017. pipe_stats[pipe] = I915_READ(reg);
  3018. /*
  3019. * Clear the PIPE*STAT regs before the IIR
  3020. */
  3021. if (pipe_stats[pipe] & 0x8000ffff)
  3022. I915_WRITE(reg, pipe_stats[pipe]);
  3023. }
  3024. spin_unlock(&dev_priv->irq_lock);
  3025. I915_WRITE16(IIR, iir & ~flip_mask);
  3026. new_iir = I915_READ16(IIR); /* Flush posted writes */
  3027. if (iir & I915_USER_INTERRUPT)
  3028. notify_ring(dev, &dev_priv->ring[RCS]);
  3029. for_each_pipe(dev_priv, pipe) {
  3030. int plane = pipe;
  3031. if (HAS_FBC(dev))
  3032. plane = !plane;
  3033. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  3034. i8xx_handle_vblank(dev, plane, pipe, iir))
  3035. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  3036. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3037. i9xx_pipe_crc_irq_handler(dev, pipe);
  3038. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3039. intel_cpu_fifo_underrun_irq_handler(dev_priv,
  3040. pipe);
  3041. }
  3042. iir = new_iir;
  3043. }
  3044. return IRQ_HANDLED;
  3045. }
  3046. static void i8xx_irq_uninstall(struct drm_device * dev)
  3047. {
  3048. struct drm_i915_private *dev_priv = dev->dev_private;
  3049. int pipe;
  3050. for_each_pipe(dev_priv, pipe) {
  3051. /* Clear enable bits; then clear status bits */
  3052. I915_WRITE(PIPESTAT(pipe), 0);
  3053. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  3054. }
  3055. I915_WRITE16(IMR, 0xffff);
  3056. I915_WRITE16(IER, 0x0);
  3057. I915_WRITE16(IIR, I915_READ16(IIR));
  3058. }
  3059. static void i915_irq_preinstall(struct drm_device * dev)
  3060. {
  3061. struct drm_i915_private *dev_priv = dev->dev_private;
  3062. int pipe;
  3063. if (I915_HAS_HOTPLUG(dev)) {
  3064. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3065. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3066. }
  3067. I915_WRITE16(HWSTAM, 0xeffe);
  3068. for_each_pipe(dev_priv, pipe)
  3069. I915_WRITE(PIPESTAT(pipe), 0);
  3070. I915_WRITE(IMR, 0xffffffff);
  3071. I915_WRITE(IER, 0x0);
  3072. POSTING_READ(IER);
  3073. }
  3074. static int i915_irq_postinstall(struct drm_device *dev)
  3075. {
  3076. struct drm_i915_private *dev_priv = dev->dev_private;
  3077. u32 enable_mask;
  3078. I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
  3079. /* Unmask the interrupts that we always want on. */
  3080. dev_priv->irq_mask =
  3081. ~(I915_ASLE_INTERRUPT |
  3082. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3083. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3084. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3085. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3086. enable_mask =
  3087. I915_ASLE_INTERRUPT |
  3088. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3089. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3090. I915_USER_INTERRUPT;
  3091. if (I915_HAS_HOTPLUG(dev)) {
  3092. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3093. POSTING_READ(PORT_HOTPLUG_EN);
  3094. /* Enable in IER... */
  3095. enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
  3096. /* and unmask in IMR */
  3097. dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
  3098. }
  3099. I915_WRITE(IMR, dev_priv->irq_mask);
  3100. I915_WRITE(IER, enable_mask);
  3101. POSTING_READ(IER);
  3102. i915_enable_asle_pipestat(dev);
  3103. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3104. * just to make the assert_spin_locked check happy. */
  3105. spin_lock_irq(&dev_priv->irq_lock);
  3106. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3107. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3108. spin_unlock_irq(&dev_priv->irq_lock);
  3109. return 0;
  3110. }
  3111. /*
  3112. * Returns true when a page flip has completed.
  3113. */
  3114. static bool i915_handle_vblank(struct drm_device *dev,
  3115. int plane, int pipe, u32 iir)
  3116. {
  3117. struct drm_i915_private *dev_priv = dev->dev_private;
  3118. u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
  3119. if (!intel_pipe_handle_vblank(dev, pipe))
  3120. return false;
  3121. if ((iir & flip_pending) == 0)
  3122. goto check_page_flip;
  3123. /* We detect FlipDone by looking for the change in PendingFlip from '1'
  3124. * to '0' on the following vblank, i.e. IIR has the Pendingflip
  3125. * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
  3126. * the flip is completed (no longer pending). Since this doesn't raise
  3127. * an interrupt per se, we watch for the change at vblank.
  3128. */
  3129. if (I915_READ(ISR) & flip_pending)
  3130. goto check_page_flip;
  3131. intel_prepare_page_flip(dev, plane);
  3132. intel_finish_page_flip(dev, pipe);
  3133. return true;
  3134. check_page_flip:
  3135. intel_check_page_flip(dev, pipe);
  3136. return false;
  3137. }
  3138. static irqreturn_t i915_irq_handler(int irq, void *arg)
  3139. {
  3140. struct drm_device *dev = arg;
  3141. struct drm_i915_private *dev_priv = dev->dev_private;
  3142. u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
  3143. u32 flip_mask =
  3144. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3145. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3146. int pipe, ret = IRQ_NONE;
  3147. if (!intel_irqs_enabled(dev_priv))
  3148. return IRQ_NONE;
  3149. iir = I915_READ(IIR);
  3150. do {
  3151. bool irq_received = (iir & ~flip_mask) != 0;
  3152. bool blc_event = false;
  3153. /* Can't rely on pipestat interrupt bit in iir as it might
  3154. * have been cleared after the pipestat interrupt was received.
  3155. * It doesn't set the bit in iir again, but it still produces
  3156. * interrupts (for non-MSI).
  3157. */
  3158. spin_lock(&dev_priv->irq_lock);
  3159. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3160. DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
  3161. for_each_pipe(dev_priv, pipe) {
  3162. int reg = PIPESTAT(pipe);
  3163. pipe_stats[pipe] = I915_READ(reg);
  3164. /* Clear the PIPE*STAT regs before the IIR */
  3165. if (pipe_stats[pipe] & 0x8000ffff) {
  3166. I915_WRITE(reg, pipe_stats[pipe]);
  3167. irq_received = true;
  3168. }
  3169. }
  3170. spin_unlock(&dev_priv->irq_lock);
  3171. if (!irq_received)
  3172. break;
  3173. /* Consume port. Then clear IIR or we'll miss events */
  3174. if (I915_HAS_HOTPLUG(dev) &&
  3175. iir & I915_DISPLAY_PORT_INTERRUPT)
  3176. i9xx_hpd_irq_handler(dev);
  3177. I915_WRITE(IIR, iir & ~flip_mask);
  3178. new_iir = I915_READ(IIR); /* Flush posted writes */
  3179. if (iir & I915_USER_INTERRUPT)
  3180. notify_ring(dev, &dev_priv->ring[RCS]);
  3181. for_each_pipe(dev_priv, pipe) {
  3182. int plane = pipe;
  3183. if (HAS_FBC(dev))
  3184. plane = !plane;
  3185. if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
  3186. i915_handle_vblank(dev, plane, pipe, iir))
  3187. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
  3188. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3189. blc_event = true;
  3190. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3191. i9xx_pipe_crc_irq_handler(dev, pipe);
  3192. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3193. intel_cpu_fifo_underrun_irq_handler(dev_priv,
  3194. pipe);
  3195. }
  3196. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3197. intel_opregion_asle_intr(dev);
  3198. /* With MSI, interrupts are only generated when iir
  3199. * transitions from zero to nonzero. If another bit got
  3200. * set while we were handling the existing iir bits, then
  3201. * we would never get another interrupt.
  3202. *
  3203. * This is fine on non-MSI as well, as if we hit this path
  3204. * we avoid exiting the interrupt handler only to generate
  3205. * another one.
  3206. *
  3207. * Note that for MSI this could cause a stray interrupt report
  3208. * if an interrupt landed in the time between writing IIR and
  3209. * the posting read. This should be rare enough to never
  3210. * trigger the 99% of 100,000 interrupts test for disabling
  3211. * stray interrupts.
  3212. */
  3213. ret = IRQ_HANDLED;
  3214. iir = new_iir;
  3215. } while (iir & ~flip_mask);
  3216. return ret;
  3217. }
  3218. static void i915_irq_uninstall(struct drm_device * dev)
  3219. {
  3220. struct drm_i915_private *dev_priv = dev->dev_private;
  3221. int pipe;
  3222. if (I915_HAS_HOTPLUG(dev)) {
  3223. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3224. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3225. }
  3226. I915_WRITE16(HWSTAM, 0xffff);
  3227. for_each_pipe(dev_priv, pipe) {
  3228. /* Clear enable bits; then clear status bits */
  3229. I915_WRITE(PIPESTAT(pipe), 0);
  3230. I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
  3231. }
  3232. I915_WRITE(IMR, 0xffffffff);
  3233. I915_WRITE(IER, 0x0);
  3234. I915_WRITE(IIR, I915_READ(IIR));
  3235. }
  3236. static void i965_irq_preinstall(struct drm_device * dev)
  3237. {
  3238. struct drm_i915_private *dev_priv = dev->dev_private;
  3239. int pipe;
  3240. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3241. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3242. I915_WRITE(HWSTAM, 0xeffe);
  3243. for_each_pipe(dev_priv, pipe)
  3244. I915_WRITE(PIPESTAT(pipe), 0);
  3245. I915_WRITE(IMR, 0xffffffff);
  3246. I915_WRITE(IER, 0x0);
  3247. POSTING_READ(IER);
  3248. }
  3249. static int i965_irq_postinstall(struct drm_device *dev)
  3250. {
  3251. struct drm_i915_private *dev_priv = dev->dev_private;
  3252. u32 enable_mask;
  3253. u32 error_mask;
  3254. /* Unmask the interrupts that we always want on. */
  3255. dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
  3256. I915_DISPLAY_PORT_INTERRUPT |
  3257. I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
  3258. I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
  3259. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3260. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
  3261. I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
  3262. enable_mask = ~dev_priv->irq_mask;
  3263. enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3264. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
  3265. enable_mask |= I915_USER_INTERRUPT;
  3266. if (IS_G4X(dev))
  3267. enable_mask |= I915_BSD_USER_INTERRUPT;
  3268. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3269. * just to make the assert_spin_locked check happy. */
  3270. spin_lock_irq(&dev_priv->irq_lock);
  3271. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
  3272. i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3273. i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
  3274. spin_unlock_irq(&dev_priv->irq_lock);
  3275. /*
  3276. * Enable some error detection, note the instruction error mask
  3277. * bit is reserved, so we leave it masked.
  3278. */
  3279. if (IS_G4X(dev)) {
  3280. error_mask = ~(GM45_ERROR_PAGE_TABLE |
  3281. GM45_ERROR_MEM_PRIV |
  3282. GM45_ERROR_CP_PRIV |
  3283. I915_ERROR_MEMORY_REFRESH);
  3284. } else {
  3285. error_mask = ~(I915_ERROR_PAGE_TABLE |
  3286. I915_ERROR_MEMORY_REFRESH);
  3287. }
  3288. I915_WRITE(EMR, error_mask);
  3289. I915_WRITE(IMR, dev_priv->irq_mask);
  3290. I915_WRITE(IER, enable_mask);
  3291. POSTING_READ(IER);
  3292. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3293. POSTING_READ(PORT_HOTPLUG_EN);
  3294. i915_enable_asle_pipestat(dev);
  3295. return 0;
  3296. }
  3297. static void i915_hpd_irq_setup(struct drm_device *dev)
  3298. {
  3299. struct drm_i915_private *dev_priv = dev->dev_private;
  3300. struct intel_encoder *intel_encoder;
  3301. u32 hotplug_en;
  3302. assert_spin_locked(&dev_priv->irq_lock);
  3303. hotplug_en = I915_READ(PORT_HOTPLUG_EN);
  3304. hotplug_en &= ~HOTPLUG_INT_EN_MASK;
  3305. /* Note HDMI and DP share hotplug bits */
  3306. /* enable bits are the same for all generations */
  3307. for_each_intel_encoder(dev, intel_encoder)
  3308. if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
  3309. hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
  3310. /* Programming the CRT detection parameters tends
  3311. to generate a spurious hotplug event about three
  3312. seconds later. So just do it once.
  3313. */
  3314. if (IS_G4X(dev))
  3315. hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
  3316. hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
  3317. hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
  3318. /* Ignore TV since it's buggy */
  3319. I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
  3320. }
  3321. static irqreturn_t i965_irq_handler(int irq, void *arg)
  3322. {
  3323. struct drm_device *dev = arg;
  3324. struct drm_i915_private *dev_priv = dev->dev_private;
  3325. u32 iir, new_iir;
  3326. u32 pipe_stats[I915_MAX_PIPES];
  3327. int ret = IRQ_NONE, pipe;
  3328. u32 flip_mask =
  3329. I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
  3330. I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
  3331. if (!intel_irqs_enabled(dev_priv))
  3332. return IRQ_NONE;
  3333. iir = I915_READ(IIR);
  3334. for (;;) {
  3335. bool irq_received = (iir & ~flip_mask) != 0;
  3336. bool blc_event = false;
  3337. /* Can't rely on pipestat interrupt bit in iir as it might
  3338. * have been cleared after the pipestat interrupt was received.
  3339. * It doesn't set the bit in iir again, but it still produces
  3340. * interrupts (for non-MSI).
  3341. */
  3342. spin_lock(&dev_priv->irq_lock);
  3343. if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
  3344. DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
  3345. for_each_pipe(dev_priv, pipe) {
  3346. int reg = PIPESTAT(pipe);
  3347. pipe_stats[pipe] = I915_READ(reg);
  3348. /*
  3349. * Clear the PIPE*STAT regs before the IIR
  3350. */
  3351. if (pipe_stats[pipe] & 0x8000ffff) {
  3352. I915_WRITE(reg, pipe_stats[pipe]);
  3353. irq_received = true;
  3354. }
  3355. }
  3356. spin_unlock(&dev_priv->irq_lock);
  3357. if (!irq_received)
  3358. break;
  3359. ret = IRQ_HANDLED;
  3360. /* Consume port. Then clear IIR or we'll miss events */
  3361. if (iir & I915_DISPLAY_PORT_INTERRUPT)
  3362. i9xx_hpd_irq_handler(dev);
  3363. I915_WRITE(IIR, iir & ~flip_mask);
  3364. new_iir = I915_READ(IIR); /* Flush posted writes */
  3365. if (iir & I915_USER_INTERRUPT)
  3366. notify_ring(dev, &dev_priv->ring[RCS]);
  3367. if (iir & I915_BSD_USER_INTERRUPT)
  3368. notify_ring(dev, &dev_priv->ring[VCS]);
  3369. for_each_pipe(dev_priv, pipe) {
  3370. if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
  3371. i915_handle_vblank(dev, pipe, pipe, iir))
  3372. flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
  3373. if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
  3374. blc_event = true;
  3375. if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
  3376. i9xx_pipe_crc_irq_handler(dev, pipe);
  3377. if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
  3378. intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
  3379. }
  3380. if (blc_event || (iir & I915_ASLE_INTERRUPT))
  3381. intel_opregion_asle_intr(dev);
  3382. if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
  3383. gmbus_irq_handler(dev);
  3384. /* With MSI, interrupts are only generated when iir
  3385. * transitions from zero to nonzero. If another bit got
  3386. * set while we were handling the existing iir bits, then
  3387. * we would never get another interrupt.
  3388. *
  3389. * This is fine on non-MSI as well, as if we hit this path
  3390. * we avoid exiting the interrupt handler only to generate
  3391. * another one.
  3392. *
  3393. * Note that for MSI this could cause a stray interrupt report
  3394. * if an interrupt landed in the time between writing IIR and
  3395. * the posting read. This should be rare enough to never
  3396. * trigger the 99% of 100,000 interrupts test for disabling
  3397. * stray interrupts.
  3398. */
  3399. iir = new_iir;
  3400. }
  3401. return ret;
  3402. }
  3403. static void i965_irq_uninstall(struct drm_device * dev)
  3404. {
  3405. struct drm_i915_private *dev_priv = dev->dev_private;
  3406. int pipe;
  3407. if (!dev_priv)
  3408. return;
  3409. I915_WRITE(PORT_HOTPLUG_EN, 0);
  3410. I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
  3411. I915_WRITE(HWSTAM, 0xffffffff);
  3412. for_each_pipe(dev_priv, pipe)
  3413. I915_WRITE(PIPESTAT(pipe), 0);
  3414. I915_WRITE(IMR, 0xffffffff);
  3415. I915_WRITE(IER, 0x0);
  3416. for_each_pipe(dev_priv, pipe)
  3417. I915_WRITE(PIPESTAT(pipe),
  3418. I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
  3419. I915_WRITE(IIR, I915_READ(IIR));
  3420. }
  3421. static void intel_hpd_irq_reenable_work(struct work_struct *work)
  3422. {
  3423. struct drm_i915_private *dev_priv =
  3424. container_of(work, typeof(*dev_priv),
  3425. hotplug_reenable_work.work);
  3426. struct drm_device *dev = dev_priv->dev;
  3427. struct drm_mode_config *mode_config = &dev->mode_config;
  3428. int i;
  3429. intel_runtime_pm_get(dev_priv);
  3430. spin_lock_irq(&dev_priv->irq_lock);
  3431. for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
  3432. struct drm_connector *connector;
  3433. if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
  3434. continue;
  3435. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  3436. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3437. struct intel_connector *intel_connector = to_intel_connector(connector);
  3438. if (intel_connector->encoder->hpd_pin == i) {
  3439. if (connector->polled != intel_connector->polled)
  3440. DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
  3441. connector->name);
  3442. connector->polled = intel_connector->polled;
  3443. if (!connector->polled)
  3444. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3445. }
  3446. }
  3447. }
  3448. if (dev_priv->display.hpd_irq_setup)
  3449. dev_priv->display.hpd_irq_setup(dev);
  3450. spin_unlock_irq(&dev_priv->irq_lock);
  3451. intel_runtime_pm_put(dev_priv);
  3452. }
  3453. /**
  3454. * intel_irq_init - initializes irq support
  3455. * @dev_priv: i915 device instance
  3456. *
  3457. * This function initializes all the irq support including work items, timers
  3458. * and all the vtables. It does not setup the interrupt itself though.
  3459. */
  3460. void intel_irq_init(struct drm_i915_private *dev_priv)
  3461. {
  3462. struct drm_device *dev = dev_priv->dev;
  3463. INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
  3464. INIT_WORK(&dev_priv->dig_port_work, i915_digport_work_func);
  3465. INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
  3466. INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
  3467. /* Let's track the enabled rps events */
  3468. if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
  3469. /* WaGsvRC0ResidencyMethod:vlv */
  3470. dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
  3471. else
  3472. dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
  3473. INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
  3474. i915_hangcheck_elapsed);
  3475. INIT_DELAYED_WORK(&dev_priv->hotplug_reenable_work,
  3476. intel_hpd_irq_reenable_work);
  3477. pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
  3478. if (IS_GEN2(dev_priv)) {
  3479. dev->max_vblank_count = 0;
  3480. dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
  3481. } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
  3482. dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
  3483. dev->driver->get_vblank_counter = gm45_get_vblank_counter;
  3484. } else {
  3485. dev->driver->get_vblank_counter = i915_get_vblank_counter;
  3486. dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
  3487. }
  3488. /*
  3489. * Opt out of the vblank disable timer on everything except gen2.
  3490. * Gen2 doesn't have a hardware frame counter and so depends on
  3491. * vblank interrupts to produce sane vblank seuquence numbers.
  3492. */
  3493. if (!IS_GEN2(dev_priv))
  3494. dev->vblank_disable_immediate = true;
  3495. dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
  3496. dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
  3497. if (IS_CHERRYVIEW(dev_priv)) {
  3498. dev->driver->irq_handler = cherryview_irq_handler;
  3499. dev->driver->irq_preinstall = cherryview_irq_preinstall;
  3500. dev->driver->irq_postinstall = cherryview_irq_postinstall;
  3501. dev->driver->irq_uninstall = cherryview_irq_uninstall;
  3502. dev->driver->enable_vblank = valleyview_enable_vblank;
  3503. dev->driver->disable_vblank = valleyview_disable_vblank;
  3504. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3505. } else if (IS_VALLEYVIEW(dev_priv)) {
  3506. dev->driver->irq_handler = valleyview_irq_handler;
  3507. dev->driver->irq_preinstall = valleyview_irq_preinstall;
  3508. dev->driver->irq_postinstall = valleyview_irq_postinstall;
  3509. dev->driver->irq_uninstall = valleyview_irq_uninstall;
  3510. dev->driver->enable_vblank = valleyview_enable_vblank;
  3511. dev->driver->disable_vblank = valleyview_disable_vblank;
  3512. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3513. } else if (INTEL_INFO(dev_priv)->gen >= 8) {
  3514. dev->driver->irq_handler = gen8_irq_handler;
  3515. dev->driver->irq_preinstall = gen8_irq_reset;
  3516. dev->driver->irq_postinstall = gen8_irq_postinstall;
  3517. dev->driver->irq_uninstall = gen8_irq_uninstall;
  3518. dev->driver->enable_vblank = gen8_enable_vblank;
  3519. dev->driver->disable_vblank = gen8_disable_vblank;
  3520. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3521. } else if (HAS_PCH_SPLIT(dev)) {
  3522. dev->driver->irq_handler = ironlake_irq_handler;
  3523. dev->driver->irq_preinstall = ironlake_irq_reset;
  3524. dev->driver->irq_postinstall = ironlake_irq_postinstall;
  3525. dev->driver->irq_uninstall = ironlake_irq_uninstall;
  3526. dev->driver->enable_vblank = ironlake_enable_vblank;
  3527. dev->driver->disable_vblank = ironlake_disable_vblank;
  3528. dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
  3529. } else {
  3530. if (INTEL_INFO(dev_priv)->gen == 2) {
  3531. dev->driver->irq_preinstall = i8xx_irq_preinstall;
  3532. dev->driver->irq_postinstall = i8xx_irq_postinstall;
  3533. dev->driver->irq_handler = i8xx_irq_handler;
  3534. dev->driver->irq_uninstall = i8xx_irq_uninstall;
  3535. } else if (INTEL_INFO(dev_priv)->gen == 3) {
  3536. dev->driver->irq_preinstall = i915_irq_preinstall;
  3537. dev->driver->irq_postinstall = i915_irq_postinstall;
  3538. dev->driver->irq_uninstall = i915_irq_uninstall;
  3539. dev->driver->irq_handler = i915_irq_handler;
  3540. } else {
  3541. dev->driver->irq_preinstall = i965_irq_preinstall;
  3542. dev->driver->irq_postinstall = i965_irq_postinstall;
  3543. dev->driver->irq_uninstall = i965_irq_uninstall;
  3544. dev->driver->irq_handler = i965_irq_handler;
  3545. }
  3546. if (I915_HAS_HOTPLUG(dev_priv))
  3547. dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
  3548. dev->driver->enable_vblank = i915_enable_vblank;
  3549. dev->driver->disable_vblank = i915_disable_vblank;
  3550. }
  3551. }
  3552. /**
  3553. * intel_hpd_init - initializes and enables hpd support
  3554. * @dev_priv: i915 device instance
  3555. *
  3556. * This function enables the hotplug support. It requires that interrupts have
  3557. * already been enabled with intel_irq_init_hw(). From this point on hotplug and
  3558. * poll request can run concurrently to other code, so locking rules must be
  3559. * obeyed.
  3560. *
  3561. * This is a separate step from interrupt enabling to simplify the locking rules
  3562. * in the driver load and resume code.
  3563. */
  3564. void intel_hpd_init(struct drm_i915_private *dev_priv)
  3565. {
  3566. struct drm_device *dev = dev_priv->dev;
  3567. struct drm_mode_config *mode_config = &dev->mode_config;
  3568. struct drm_connector *connector;
  3569. int i;
  3570. for (i = 1; i < HPD_NUM_PINS; i++) {
  3571. dev_priv->hpd_stats[i].hpd_cnt = 0;
  3572. dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
  3573. }
  3574. list_for_each_entry(connector, &mode_config->connector_list, head) {
  3575. struct intel_connector *intel_connector = to_intel_connector(connector);
  3576. connector->polled = intel_connector->polled;
  3577. if (connector->encoder && !connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
  3578. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3579. if (intel_connector->mst_port)
  3580. connector->polled = DRM_CONNECTOR_POLL_HPD;
  3581. }
  3582. /* Interrupt setup is already guaranteed to be single-threaded, this is
  3583. * just to make the assert_spin_locked checks happy. */
  3584. spin_lock_irq(&dev_priv->irq_lock);
  3585. if (dev_priv->display.hpd_irq_setup)
  3586. dev_priv->display.hpd_irq_setup(dev);
  3587. spin_unlock_irq(&dev_priv->irq_lock);
  3588. }
  3589. /**
  3590. * intel_irq_install - enables the hardware interrupt
  3591. * @dev_priv: i915 device instance
  3592. *
  3593. * This function enables the hardware interrupt handling, but leaves the hotplug
  3594. * handling still disabled. It is called after intel_irq_init().
  3595. *
  3596. * In the driver load and resume code we need working interrupts in a few places
  3597. * but don't want to deal with the hassle of concurrent probe and hotplug
  3598. * workers. Hence the split into this two-stage approach.
  3599. */
  3600. int intel_irq_install(struct drm_i915_private *dev_priv)
  3601. {
  3602. /*
  3603. * We enable some interrupt sources in our postinstall hooks, so mark
  3604. * interrupts as enabled _before_ actually enabling them to avoid
  3605. * special cases in our ordering checks.
  3606. */
  3607. dev_priv->pm.irqs_enabled = true;
  3608. return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
  3609. }
  3610. /**
  3611. * intel_irq_uninstall - finilizes all irq handling
  3612. * @dev_priv: i915 device instance
  3613. *
  3614. * This stops interrupt and hotplug handling and unregisters and frees all
  3615. * resources acquired in the init functions.
  3616. */
  3617. void intel_irq_uninstall(struct drm_i915_private *dev_priv)
  3618. {
  3619. drm_irq_uninstall(dev_priv->dev);
  3620. intel_hpd_cancel_work(dev_priv);
  3621. dev_priv->pm.irqs_enabled = false;
  3622. }
  3623. /**
  3624. * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
  3625. * @dev_priv: i915 device instance
  3626. *
  3627. * This function is used to disable interrupts at runtime, both in the runtime
  3628. * pm and the system suspend/resume code.
  3629. */
  3630. void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
  3631. {
  3632. dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
  3633. dev_priv->pm.irqs_enabled = false;
  3634. synchronize_irq(dev_priv->dev->irq);
  3635. }
  3636. /**
  3637. * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
  3638. * @dev_priv: i915 device instance
  3639. *
  3640. * This function is used to enable interrupts at runtime, both in the runtime
  3641. * pm and the system suspend/resume code.
  3642. */
  3643. void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
  3644. {
  3645. dev_priv->pm.irqs_enabled = true;
  3646. dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
  3647. dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
  3648. }