i915_irq.c 110 KB

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