intel_pm.c 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154
  1. /*
  2. * Copyright © 2012 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eugeni Dodonov <eugeni.dodonov@intel.com>
  25. *
  26. */
  27. #include <linux/cpufreq.h>
  28. #include "i915_drv.h"
  29. #include "intel_drv.h"
  30. #include "../../../platform/x86/intel_ips.h"
  31. #include <linux/module.h>
  32. #define FORCEWAKE_ACK_TIMEOUT_MS 2
  33. /* FBC, or Frame Buffer Compression, is a technique employed to compress the
  34. * framebuffer contents in-memory, aiming at reducing the required bandwidth
  35. * during in-memory transfers and, therefore, reduce the power packet.
  36. *
  37. * The benefits of FBC are mostly visible with solid backgrounds and
  38. * variation-less patterns.
  39. *
  40. * FBC-related functionality can be enabled by the means of the
  41. * i915.i915_enable_fbc parameter
  42. */
  43. static void i8xx_disable_fbc(struct drm_device *dev)
  44. {
  45. struct drm_i915_private *dev_priv = dev->dev_private;
  46. u32 fbc_ctl;
  47. /* Disable compression */
  48. fbc_ctl = I915_READ(FBC_CONTROL);
  49. if ((fbc_ctl & FBC_CTL_EN) == 0)
  50. return;
  51. fbc_ctl &= ~FBC_CTL_EN;
  52. I915_WRITE(FBC_CONTROL, fbc_ctl);
  53. /* Wait for compressing bit to clear */
  54. if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) {
  55. DRM_DEBUG_KMS("FBC idle timed out\n");
  56. return;
  57. }
  58. DRM_DEBUG_KMS("disabled FBC\n");
  59. }
  60. static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  61. {
  62. struct drm_device *dev = crtc->dev;
  63. struct drm_i915_private *dev_priv = dev->dev_private;
  64. struct drm_framebuffer *fb = crtc->fb;
  65. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  66. struct drm_i915_gem_object *obj = intel_fb->obj;
  67. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  68. int cfb_pitch;
  69. int plane, i;
  70. u32 fbc_ctl, fbc_ctl2;
  71. cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE;
  72. if (fb->pitches[0] < cfb_pitch)
  73. cfb_pitch = fb->pitches[0];
  74. /* FBC_CTL wants 64B units */
  75. cfb_pitch = (cfb_pitch / 64) - 1;
  76. plane = intel_crtc->plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB;
  77. /* Clear old tags */
  78. for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++)
  79. I915_WRITE(FBC_TAG + (i * 4), 0);
  80. /* Set it up... */
  81. fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | FBC_CTL_CPU_FENCE;
  82. fbc_ctl2 |= plane;
  83. I915_WRITE(FBC_CONTROL2, fbc_ctl2);
  84. I915_WRITE(FBC_FENCE_OFF, crtc->y);
  85. /* enable it... */
  86. fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC;
  87. if (IS_I945GM(dev))
  88. fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */
  89. fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
  90. fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT;
  91. fbc_ctl |= obj->fence_reg;
  92. I915_WRITE(FBC_CONTROL, fbc_ctl);
  93. DRM_DEBUG_KMS("enabled FBC, pitch %d, yoff %d, plane %d, ",
  94. cfb_pitch, crtc->y, intel_crtc->plane);
  95. }
  96. static bool i8xx_fbc_enabled(struct drm_device *dev)
  97. {
  98. struct drm_i915_private *dev_priv = dev->dev_private;
  99. return I915_READ(FBC_CONTROL) & FBC_CTL_EN;
  100. }
  101. static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  102. {
  103. struct drm_device *dev = crtc->dev;
  104. struct drm_i915_private *dev_priv = dev->dev_private;
  105. struct drm_framebuffer *fb = crtc->fb;
  106. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  107. struct drm_i915_gem_object *obj = intel_fb->obj;
  108. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  109. int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
  110. unsigned long stall_watermark = 200;
  111. u32 dpfc_ctl;
  112. dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X;
  113. dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg;
  114. I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY);
  115. I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  116. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  117. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  118. I915_WRITE(DPFC_FENCE_YOFF, crtc->y);
  119. /* enable it... */
  120. I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN);
  121. DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
  122. }
  123. static void g4x_disable_fbc(struct drm_device *dev)
  124. {
  125. struct drm_i915_private *dev_priv = dev->dev_private;
  126. u32 dpfc_ctl;
  127. /* Disable compression */
  128. dpfc_ctl = I915_READ(DPFC_CONTROL);
  129. if (dpfc_ctl & DPFC_CTL_EN) {
  130. dpfc_ctl &= ~DPFC_CTL_EN;
  131. I915_WRITE(DPFC_CONTROL, dpfc_ctl);
  132. DRM_DEBUG_KMS("disabled FBC\n");
  133. }
  134. }
  135. static bool g4x_fbc_enabled(struct drm_device *dev)
  136. {
  137. struct drm_i915_private *dev_priv = dev->dev_private;
  138. return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN;
  139. }
  140. static void sandybridge_blit_fbc_update(struct drm_device *dev)
  141. {
  142. struct drm_i915_private *dev_priv = dev->dev_private;
  143. u32 blt_ecoskpd;
  144. /* Make sure blitter notifies FBC of writes */
  145. gen6_gt_force_wake_get(dev_priv);
  146. blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD);
  147. blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY <<
  148. GEN6_BLITTER_LOCK_SHIFT;
  149. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  150. blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY;
  151. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  152. blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY <<
  153. GEN6_BLITTER_LOCK_SHIFT);
  154. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  155. POSTING_READ(GEN6_BLITTER_ECOSKPD);
  156. gen6_gt_force_wake_put(dev_priv);
  157. }
  158. static void ironlake_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  159. {
  160. struct drm_device *dev = crtc->dev;
  161. struct drm_i915_private *dev_priv = dev->dev_private;
  162. struct drm_framebuffer *fb = crtc->fb;
  163. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  164. struct drm_i915_gem_object *obj = intel_fb->obj;
  165. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  166. int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
  167. unsigned long stall_watermark = 200;
  168. u32 dpfc_ctl;
  169. dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
  170. dpfc_ctl &= DPFC_RESERVED;
  171. dpfc_ctl |= (plane | DPFC_CTL_LIMIT_1X);
  172. /* Set persistent mode for front-buffer rendering, ala X. */
  173. dpfc_ctl |= DPFC_CTL_PERSISTENT_MODE;
  174. dpfc_ctl |= (DPFC_CTL_FENCE_EN | obj->fence_reg);
  175. I915_WRITE(ILK_DPFC_CHICKEN, DPFC_HT_MODIFY);
  176. I915_WRITE(ILK_DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  177. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  178. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  179. I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y);
  180. I915_WRITE(ILK_FBC_RT_BASE, obj->gtt_offset | ILK_FBC_RT_VALID);
  181. /* enable it... */
  182. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);
  183. if (IS_GEN6(dev)) {
  184. I915_WRITE(SNB_DPFC_CTL_SA,
  185. SNB_CPU_FENCE_ENABLE | obj->fence_reg);
  186. I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y);
  187. sandybridge_blit_fbc_update(dev);
  188. }
  189. DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
  190. }
  191. static void ironlake_disable_fbc(struct drm_device *dev)
  192. {
  193. struct drm_i915_private *dev_priv = dev->dev_private;
  194. u32 dpfc_ctl;
  195. /* Disable compression */
  196. dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
  197. if (dpfc_ctl & DPFC_CTL_EN) {
  198. dpfc_ctl &= ~DPFC_CTL_EN;
  199. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl);
  200. DRM_DEBUG_KMS("disabled FBC\n");
  201. }
  202. }
  203. static bool ironlake_fbc_enabled(struct drm_device *dev)
  204. {
  205. struct drm_i915_private *dev_priv = dev->dev_private;
  206. return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN;
  207. }
  208. bool intel_fbc_enabled(struct drm_device *dev)
  209. {
  210. struct drm_i915_private *dev_priv = dev->dev_private;
  211. if (!dev_priv->display.fbc_enabled)
  212. return false;
  213. return dev_priv->display.fbc_enabled(dev);
  214. }
  215. static void intel_fbc_work_fn(struct work_struct *__work)
  216. {
  217. struct intel_fbc_work *work =
  218. container_of(to_delayed_work(__work),
  219. struct intel_fbc_work, work);
  220. struct drm_device *dev = work->crtc->dev;
  221. struct drm_i915_private *dev_priv = dev->dev_private;
  222. mutex_lock(&dev->struct_mutex);
  223. if (work == dev_priv->fbc_work) {
  224. /* Double check that we haven't switched fb without cancelling
  225. * the prior work.
  226. */
  227. if (work->crtc->fb == work->fb) {
  228. dev_priv->display.enable_fbc(work->crtc,
  229. work->interval);
  230. dev_priv->cfb_plane = to_intel_crtc(work->crtc)->plane;
  231. dev_priv->cfb_fb = work->crtc->fb->base.id;
  232. dev_priv->cfb_y = work->crtc->y;
  233. }
  234. dev_priv->fbc_work = NULL;
  235. }
  236. mutex_unlock(&dev->struct_mutex);
  237. kfree(work);
  238. }
  239. static void intel_cancel_fbc_work(struct drm_i915_private *dev_priv)
  240. {
  241. if (dev_priv->fbc_work == NULL)
  242. return;
  243. DRM_DEBUG_KMS("cancelling pending FBC enable\n");
  244. /* Synchronisation is provided by struct_mutex and checking of
  245. * dev_priv->fbc_work, so we can perform the cancellation
  246. * entirely asynchronously.
  247. */
  248. if (cancel_delayed_work(&dev_priv->fbc_work->work))
  249. /* tasklet was killed before being run, clean up */
  250. kfree(dev_priv->fbc_work);
  251. /* Mark the work as no longer wanted so that if it does
  252. * wake-up (because the work was already running and waiting
  253. * for our mutex), it will discover that is no longer
  254. * necessary to run.
  255. */
  256. dev_priv->fbc_work = NULL;
  257. }
  258. void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  259. {
  260. struct intel_fbc_work *work;
  261. struct drm_device *dev = crtc->dev;
  262. struct drm_i915_private *dev_priv = dev->dev_private;
  263. if (!dev_priv->display.enable_fbc)
  264. return;
  265. intel_cancel_fbc_work(dev_priv);
  266. work = kzalloc(sizeof *work, GFP_KERNEL);
  267. if (work == NULL) {
  268. dev_priv->display.enable_fbc(crtc, interval);
  269. return;
  270. }
  271. work->crtc = crtc;
  272. work->fb = crtc->fb;
  273. work->interval = interval;
  274. INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn);
  275. dev_priv->fbc_work = work;
  276. DRM_DEBUG_KMS("scheduling delayed FBC enable\n");
  277. /* Delay the actual enabling to let pageflipping cease and the
  278. * display to settle before starting the compression. Note that
  279. * this delay also serves a second purpose: it allows for a
  280. * vblank to pass after disabling the FBC before we attempt
  281. * to modify the control registers.
  282. *
  283. * A more complicated solution would involve tracking vblanks
  284. * following the termination of the page-flipping sequence
  285. * and indeed performing the enable as a co-routine and not
  286. * waiting synchronously upon the vblank.
  287. */
  288. schedule_delayed_work(&work->work, msecs_to_jiffies(50));
  289. }
  290. void intel_disable_fbc(struct drm_device *dev)
  291. {
  292. struct drm_i915_private *dev_priv = dev->dev_private;
  293. intel_cancel_fbc_work(dev_priv);
  294. if (!dev_priv->display.disable_fbc)
  295. return;
  296. dev_priv->display.disable_fbc(dev);
  297. dev_priv->cfb_plane = -1;
  298. }
  299. /**
  300. * intel_update_fbc - enable/disable FBC as needed
  301. * @dev: the drm_device
  302. *
  303. * Set up the framebuffer compression hardware at mode set time. We
  304. * enable it if possible:
  305. * - plane A only (on pre-965)
  306. * - no pixel mulitply/line duplication
  307. * - no alpha buffer discard
  308. * - no dual wide
  309. * - framebuffer <= 2048 in width, 1536 in height
  310. *
  311. * We can't assume that any compression will take place (worst case),
  312. * so the compressed buffer has to be the same size as the uncompressed
  313. * one. It also must reside (along with the line length buffer) in
  314. * stolen memory.
  315. *
  316. * We need to enable/disable FBC on a global basis.
  317. */
  318. void intel_update_fbc(struct drm_device *dev)
  319. {
  320. struct drm_i915_private *dev_priv = dev->dev_private;
  321. struct drm_crtc *crtc = NULL, *tmp_crtc;
  322. struct intel_crtc *intel_crtc;
  323. struct drm_framebuffer *fb;
  324. struct intel_framebuffer *intel_fb;
  325. struct drm_i915_gem_object *obj;
  326. int enable_fbc;
  327. if (!i915_powersave)
  328. return;
  329. if (!I915_HAS_FBC(dev))
  330. return;
  331. /*
  332. * If FBC is already on, we just have to verify that we can
  333. * keep it that way...
  334. * Need to disable if:
  335. * - more than one pipe is active
  336. * - changing FBC params (stride, fence, mode)
  337. * - new fb is too large to fit in compressed buffer
  338. * - going to an unsupported config (interlace, pixel multiply, etc.)
  339. */
  340. list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head) {
  341. if (tmp_crtc->enabled &&
  342. !to_intel_crtc(tmp_crtc)->primary_disabled &&
  343. tmp_crtc->fb) {
  344. if (crtc) {
  345. DRM_DEBUG_KMS("more than one pipe active, disabling compression\n");
  346. dev_priv->no_fbc_reason = FBC_MULTIPLE_PIPES;
  347. goto out_disable;
  348. }
  349. crtc = tmp_crtc;
  350. }
  351. }
  352. if (!crtc || crtc->fb == NULL) {
  353. DRM_DEBUG_KMS("no output, disabling\n");
  354. dev_priv->no_fbc_reason = FBC_NO_OUTPUT;
  355. goto out_disable;
  356. }
  357. intel_crtc = to_intel_crtc(crtc);
  358. fb = crtc->fb;
  359. intel_fb = to_intel_framebuffer(fb);
  360. obj = intel_fb->obj;
  361. enable_fbc = i915_enable_fbc;
  362. if (enable_fbc < 0) {
  363. DRM_DEBUG_KMS("fbc set to per-chip default\n");
  364. enable_fbc = 1;
  365. if (INTEL_INFO(dev)->gen <= 6)
  366. enable_fbc = 0;
  367. }
  368. if (!enable_fbc) {
  369. DRM_DEBUG_KMS("fbc disabled per module param\n");
  370. dev_priv->no_fbc_reason = FBC_MODULE_PARAM;
  371. goto out_disable;
  372. }
  373. if (intel_fb->obj->base.size > dev_priv->cfb_size) {
  374. DRM_DEBUG_KMS("framebuffer too large, disabling "
  375. "compression\n");
  376. dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL;
  377. goto out_disable;
  378. }
  379. if ((crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) ||
  380. (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)) {
  381. DRM_DEBUG_KMS("mode incompatible with compression, "
  382. "disabling\n");
  383. dev_priv->no_fbc_reason = FBC_UNSUPPORTED_MODE;
  384. goto out_disable;
  385. }
  386. if ((crtc->mode.hdisplay > 2048) ||
  387. (crtc->mode.vdisplay > 1536)) {
  388. DRM_DEBUG_KMS("mode too large for compression, disabling\n");
  389. dev_priv->no_fbc_reason = FBC_MODE_TOO_LARGE;
  390. goto out_disable;
  391. }
  392. if ((IS_I915GM(dev) || IS_I945GM(dev)) && intel_crtc->plane != 0) {
  393. DRM_DEBUG_KMS("plane not 0, disabling compression\n");
  394. dev_priv->no_fbc_reason = FBC_BAD_PLANE;
  395. goto out_disable;
  396. }
  397. /* The use of a CPU fence is mandatory in order to detect writes
  398. * by the CPU to the scanout and trigger updates to the FBC.
  399. */
  400. if (obj->tiling_mode != I915_TILING_X ||
  401. obj->fence_reg == I915_FENCE_REG_NONE) {
  402. DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n");
  403. dev_priv->no_fbc_reason = FBC_NOT_TILED;
  404. goto out_disable;
  405. }
  406. /* If the kernel debugger is active, always disable compression */
  407. if (in_dbg_master())
  408. goto out_disable;
  409. /* If the scanout has not changed, don't modify the FBC settings.
  410. * Note that we make the fundamental assumption that the fb->obj
  411. * cannot be unpinned (and have its GTT offset and fence revoked)
  412. * without first being decoupled from the scanout and FBC disabled.
  413. */
  414. if (dev_priv->cfb_plane == intel_crtc->plane &&
  415. dev_priv->cfb_fb == fb->base.id &&
  416. dev_priv->cfb_y == crtc->y)
  417. return;
  418. if (intel_fbc_enabled(dev)) {
  419. /* We update FBC along two paths, after changing fb/crtc
  420. * configuration (modeswitching) and after page-flipping
  421. * finishes. For the latter, we know that not only did
  422. * we disable the FBC at the start of the page-flip
  423. * sequence, but also more than one vblank has passed.
  424. *
  425. * For the former case of modeswitching, it is possible
  426. * to switch between two FBC valid configurations
  427. * instantaneously so we do need to disable the FBC
  428. * before we can modify its control registers. We also
  429. * have to wait for the next vblank for that to take
  430. * effect. However, since we delay enabling FBC we can
  431. * assume that a vblank has passed since disabling and
  432. * that we can safely alter the registers in the deferred
  433. * callback.
  434. *
  435. * In the scenario that we go from a valid to invalid
  436. * and then back to valid FBC configuration we have
  437. * no strict enforcement that a vblank occurred since
  438. * disabling the FBC. However, along all current pipe
  439. * disabling paths we do need to wait for a vblank at
  440. * some point. And we wait before enabling FBC anyway.
  441. */
  442. DRM_DEBUG_KMS("disabling active FBC for update\n");
  443. intel_disable_fbc(dev);
  444. }
  445. intel_enable_fbc(crtc, 500);
  446. return;
  447. out_disable:
  448. /* Multiple disables should be harmless */
  449. if (intel_fbc_enabled(dev)) {
  450. DRM_DEBUG_KMS("unsupported config, disabling FBC\n");
  451. intel_disable_fbc(dev);
  452. }
  453. }
  454. static void i915_pineview_get_mem_freq(struct drm_device *dev)
  455. {
  456. drm_i915_private_t *dev_priv = dev->dev_private;
  457. u32 tmp;
  458. tmp = I915_READ(CLKCFG);
  459. switch (tmp & CLKCFG_FSB_MASK) {
  460. case CLKCFG_FSB_533:
  461. dev_priv->fsb_freq = 533; /* 133*4 */
  462. break;
  463. case CLKCFG_FSB_800:
  464. dev_priv->fsb_freq = 800; /* 200*4 */
  465. break;
  466. case CLKCFG_FSB_667:
  467. dev_priv->fsb_freq = 667; /* 167*4 */
  468. break;
  469. case CLKCFG_FSB_400:
  470. dev_priv->fsb_freq = 400; /* 100*4 */
  471. break;
  472. }
  473. switch (tmp & CLKCFG_MEM_MASK) {
  474. case CLKCFG_MEM_533:
  475. dev_priv->mem_freq = 533;
  476. break;
  477. case CLKCFG_MEM_667:
  478. dev_priv->mem_freq = 667;
  479. break;
  480. case CLKCFG_MEM_800:
  481. dev_priv->mem_freq = 800;
  482. break;
  483. }
  484. /* detect pineview DDR3 setting */
  485. tmp = I915_READ(CSHRDDR3CTL);
  486. dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0;
  487. }
  488. static void i915_ironlake_get_mem_freq(struct drm_device *dev)
  489. {
  490. drm_i915_private_t *dev_priv = dev->dev_private;
  491. u16 ddrpll, csipll;
  492. ddrpll = I915_READ16(DDRMPLL1);
  493. csipll = I915_READ16(CSIPLL0);
  494. switch (ddrpll & 0xff) {
  495. case 0xc:
  496. dev_priv->mem_freq = 800;
  497. break;
  498. case 0x10:
  499. dev_priv->mem_freq = 1066;
  500. break;
  501. case 0x14:
  502. dev_priv->mem_freq = 1333;
  503. break;
  504. case 0x18:
  505. dev_priv->mem_freq = 1600;
  506. break;
  507. default:
  508. DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n",
  509. ddrpll & 0xff);
  510. dev_priv->mem_freq = 0;
  511. break;
  512. }
  513. dev_priv->ips.r_t = dev_priv->mem_freq;
  514. switch (csipll & 0x3ff) {
  515. case 0x00c:
  516. dev_priv->fsb_freq = 3200;
  517. break;
  518. case 0x00e:
  519. dev_priv->fsb_freq = 3733;
  520. break;
  521. case 0x010:
  522. dev_priv->fsb_freq = 4266;
  523. break;
  524. case 0x012:
  525. dev_priv->fsb_freq = 4800;
  526. break;
  527. case 0x014:
  528. dev_priv->fsb_freq = 5333;
  529. break;
  530. case 0x016:
  531. dev_priv->fsb_freq = 5866;
  532. break;
  533. case 0x018:
  534. dev_priv->fsb_freq = 6400;
  535. break;
  536. default:
  537. DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n",
  538. csipll & 0x3ff);
  539. dev_priv->fsb_freq = 0;
  540. break;
  541. }
  542. if (dev_priv->fsb_freq == 3200) {
  543. dev_priv->ips.c_m = 0;
  544. } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) {
  545. dev_priv->ips.c_m = 1;
  546. } else {
  547. dev_priv->ips.c_m = 2;
  548. }
  549. }
  550. static const struct cxsr_latency cxsr_latency_table[] = {
  551. {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
  552. {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
  553. {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
  554. {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
  555. {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
  556. {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
  557. {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
  558. {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
  559. {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
  560. {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
  561. {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
  562. {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
  563. {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
  564. {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
  565. {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
  566. {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
  567. {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
  568. {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
  569. {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
  570. {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
  571. {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
  572. {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
  573. {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
  574. {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
  575. {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
  576. {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
  577. {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
  578. {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
  579. {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
  580. {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
  581. };
  582. static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop,
  583. int is_ddr3,
  584. int fsb,
  585. int mem)
  586. {
  587. const struct cxsr_latency *latency;
  588. int i;
  589. if (fsb == 0 || mem == 0)
  590. return NULL;
  591. for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
  592. latency = &cxsr_latency_table[i];
  593. if (is_desktop == latency->is_desktop &&
  594. is_ddr3 == latency->is_ddr3 &&
  595. fsb == latency->fsb_freq && mem == latency->mem_freq)
  596. return latency;
  597. }
  598. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  599. return NULL;
  600. }
  601. static void pineview_disable_cxsr(struct drm_device *dev)
  602. {
  603. struct drm_i915_private *dev_priv = dev->dev_private;
  604. /* deactivate cxsr */
  605. I915_WRITE(DSPFW3, I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN);
  606. }
  607. /*
  608. * Latency for FIFO fetches is dependent on several factors:
  609. * - memory configuration (speed, channels)
  610. * - chipset
  611. * - current MCH state
  612. * It can be fairly high in some situations, so here we assume a fairly
  613. * pessimal value. It's a tradeoff between extra memory fetches (if we
  614. * set this value too high, the FIFO will fetch frequently to stay full)
  615. * and power consumption (set it too low to save power and we might see
  616. * FIFO underruns and display "flicker").
  617. *
  618. * A value of 5us seems to be a good balance; safe for very low end
  619. * platforms but not overly aggressive on lower latency configs.
  620. */
  621. static const int latency_ns = 5000;
  622. static int i9xx_get_fifo_size(struct drm_device *dev, int plane)
  623. {
  624. struct drm_i915_private *dev_priv = dev->dev_private;
  625. uint32_t dsparb = I915_READ(DSPARB);
  626. int size;
  627. size = dsparb & 0x7f;
  628. if (plane)
  629. size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
  630. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  631. plane ? "B" : "A", size);
  632. return size;
  633. }
  634. static int i85x_get_fifo_size(struct drm_device *dev, int plane)
  635. {
  636. struct drm_i915_private *dev_priv = dev->dev_private;
  637. uint32_t dsparb = I915_READ(DSPARB);
  638. int size;
  639. size = dsparb & 0x1ff;
  640. if (plane)
  641. size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
  642. size >>= 1; /* Convert to cachelines */
  643. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  644. plane ? "B" : "A", size);
  645. return size;
  646. }
  647. static int i845_get_fifo_size(struct drm_device *dev, int plane)
  648. {
  649. struct drm_i915_private *dev_priv = dev->dev_private;
  650. uint32_t dsparb = I915_READ(DSPARB);
  651. int size;
  652. size = dsparb & 0x7f;
  653. size >>= 2; /* Convert to cachelines */
  654. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  655. plane ? "B" : "A",
  656. size);
  657. return size;
  658. }
  659. static int i830_get_fifo_size(struct drm_device *dev, int plane)
  660. {
  661. struct drm_i915_private *dev_priv = dev->dev_private;
  662. uint32_t dsparb = I915_READ(DSPARB);
  663. int size;
  664. size = dsparb & 0x7f;
  665. size >>= 1; /* Convert to cachelines */
  666. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  667. plane ? "B" : "A", size);
  668. return size;
  669. }
  670. /* Pineview has different values for various configs */
  671. static const struct intel_watermark_params pineview_display_wm = {
  672. PINEVIEW_DISPLAY_FIFO,
  673. PINEVIEW_MAX_WM,
  674. PINEVIEW_DFT_WM,
  675. PINEVIEW_GUARD_WM,
  676. PINEVIEW_FIFO_LINE_SIZE
  677. };
  678. static const struct intel_watermark_params pineview_display_hplloff_wm = {
  679. PINEVIEW_DISPLAY_FIFO,
  680. PINEVIEW_MAX_WM,
  681. PINEVIEW_DFT_HPLLOFF_WM,
  682. PINEVIEW_GUARD_WM,
  683. PINEVIEW_FIFO_LINE_SIZE
  684. };
  685. static const struct intel_watermark_params pineview_cursor_wm = {
  686. PINEVIEW_CURSOR_FIFO,
  687. PINEVIEW_CURSOR_MAX_WM,
  688. PINEVIEW_CURSOR_DFT_WM,
  689. PINEVIEW_CURSOR_GUARD_WM,
  690. PINEVIEW_FIFO_LINE_SIZE,
  691. };
  692. static const struct intel_watermark_params pineview_cursor_hplloff_wm = {
  693. PINEVIEW_CURSOR_FIFO,
  694. PINEVIEW_CURSOR_MAX_WM,
  695. PINEVIEW_CURSOR_DFT_WM,
  696. PINEVIEW_CURSOR_GUARD_WM,
  697. PINEVIEW_FIFO_LINE_SIZE
  698. };
  699. static const struct intel_watermark_params g4x_wm_info = {
  700. G4X_FIFO_SIZE,
  701. G4X_MAX_WM,
  702. G4X_MAX_WM,
  703. 2,
  704. G4X_FIFO_LINE_SIZE,
  705. };
  706. static const struct intel_watermark_params g4x_cursor_wm_info = {
  707. I965_CURSOR_FIFO,
  708. I965_CURSOR_MAX_WM,
  709. I965_CURSOR_DFT_WM,
  710. 2,
  711. G4X_FIFO_LINE_SIZE,
  712. };
  713. static const struct intel_watermark_params valleyview_wm_info = {
  714. VALLEYVIEW_FIFO_SIZE,
  715. VALLEYVIEW_MAX_WM,
  716. VALLEYVIEW_MAX_WM,
  717. 2,
  718. G4X_FIFO_LINE_SIZE,
  719. };
  720. static const struct intel_watermark_params valleyview_cursor_wm_info = {
  721. I965_CURSOR_FIFO,
  722. VALLEYVIEW_CURSOR_MAX_WM,
  723. I965_CURSOR_DFT_WM,
  724. 2,
  725. G4X_FIFO_LINE_SIZE,
  726. };
  727. static const struct intel_watermark_params i965_cursor_wm_info = {
  728. I965_CURSOR_FIFO,
  729. I965_CURSOR_MAX_WM,
  730. I965_CURSOR_DFT_WM,
  731. 2,
  732. I915_FIFO_LINE_SIZE,
  733. };
  734. static const struct intel_watermark_params i945_wm_info = {
  735. I945_FIFO_SIZE,
  736. I915_MAX_WM,
  737. 1,
  738. 2,
  739. I915_FIFO_LINE_SIZE
  740. };
  741. static const struct intel_watermark_params i915_wm_info = {
  742. I915_FIFO_SIZE,
  743. I915_MAX_WM,
  744. 1,
  745. 2,
  746. I915_FIFO_LINE_SIZE
  747. };
  748. static const struct intel_watermark_params i855_wm_info = {
  749. I855GM_FIFO_SIZE,
  750. I915_MAX_WM,
  751. 1,
  752. 2,
  753. I830_FIFO_LINE_SIZE
  754. };
  755. static const struct intel_watermark_params i830_wm_info = {
  756. I830_FIFO_SIZE,
  757. I915_MAX_WM,
  758. 1,
  759. 2,
  760. I830_FIFO_LINE_SIZE
  761. };
  762. static const struct intel_watermark_params ironlake_display_wm_info = {
  763. ILK_DISPLAY_FIFO,
  764. ILK_DISPLAY_MAXWM,
  765. ILK_DISPLAY_DFTWM,
  766. 2,
  767. ILK_FIFO_LINE_SIZE
  768. };
  769. static const struct intel_watermark_params ironlake_cursor_wm_info = {
  770. ILK_CURSOR_FIFO,
  771. ILK_CURSOR_MAXWM,
  772. ILK_CURSOR_DFTWM,
  773. 2,
  774. ILK_FIFO_LINE_SIZE
  775. };
  776. static const struct intel_watermark_params ironlake_display_srwm_info = {
  777. ILK_DISPLAY_SR_FIFO,
  778. ILK_DISPLAY_MAX_SRWM,
  779. ILK_DISPLAY_DFT_SRWM,
  780. 2,
  781. ILK_FIFO_LINE_SIZE
  782. };
  783. static const struct intel_watermark_params ironlake_cursor_srwm_info = {
  784. ILK_CURSOR_SR_FIFO,
  785. ILK_CURSOR_MAX_SRWM,
  786. ILK_CURSOR_DFT_SRWM,
  787. 2,
  788. ILK_FIFO_LINE_SIZE
  789. };
  790. static const struct intel_watermark_params sandybridge_display_wm_info = {
  791. SNB_DISPLAY_FIFO,
  792. SNB_DISPLAY_MAXWM,
  793. SNB_DISPLAY_DFTWM,
  794. 2,
  795. SNB_FIFO_LINE_SIZE
  796. };
  797. static const struct intel_watermark_params sandybridge_cursor_wm_info = {
  798. SNB_CURSOR_FIFO,
  799. SNB_CURSOR_MAXWM,
  800. SNB_CURSOR_DFTWM,
  801. 2,
  802. SNB_FIFO_LINE_SIZE
  803. };
  804. static const struct intel_watermark_params sandybridge_display_srwm_info = {
  805. SNB_DISPLAY_SR_FIFO,
  806. SNB_DISPLAY_MAX_SRWM,
  807. SNB_DISPLAY_DFT_SRWM,
  808. 2,
  809. SNB_FIFO_LINE_SIZE
  810. };
  811. static const struct intel_watermark_params sandybridge_cursor_srwm_info = {
  812. SNB_CURSOR_SR_FIFO,
  813. SNB_CURSOR_MAX_SRWM,
  814. SNB_CURSOR_DFT_SRWM,
  815. 2,
  816. SNB_FIFO_LINE_SIZE
  817. };
  818. /**
  819. * intel_calculate_wm - calculate watermark level
  820. * @clock_in_khz: pixel clock
  821. * @wm: chip FIFO params
  822. * @pixel_size: display pixel size
  823. * @latency_ns: memory latency for the platform
  824. *
  825. * Calculate the watermark level (the level at which the display plane will
  826. * start fetching from memory again). Each chip has a different display
  827. * FIFO size and allocation, so the caller needs to figure that out and pass
  828. * in the correct intel_watermark_params structure.
  829. *
  830. * As the pixel clock runs, the FIFO will be drained at a rate that depends
  831. * on the pixel size. When it reaches the watermark level, it'll start
  832. * fetching FIFO line sized based chunks from memory until the FIFO fills
  833. * past the watermark point. If the FIFO drains completely, a FIFO underrun
  834. * will occur, and a display engine hang could result.
  835. */
  836. static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
  837. const struct intel_watermark_params *wm,
  838. int fifo_size,
  839. int pixel_size,
  840. unsigned long latency_ns)
  841. {
  842. long entries_required, wm_size;
  843. /*
  844. * Note: we need to make sure we don't overflow for various clock &
  845. * latency values.
  846. * clocks go from a few thousand to several hundred thousand.
  847. * latency is usually a few thousand
  848. */
  849. entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
  850. 1000;
  851. entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size);
  852. DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required);
  853. wm_size = fifo_size - (entries_required + wm->guard_size);
  854. DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size);
  855. /* Don't promote wm_size to unsigned... */
  856. if (wm_size > (long)wm->max_wm)
  857. wm_size = wm->max_wm;
  858. if (wm_size <= 0)
  859. wm_size = wm->default_wm;
  860. return wm_size;
  861. }
  862. static struct drm_crtc *single_enabled_crtc(struct drm_device *dev)
  863. {
  864. struct drm_crtc *crtc, *enabled = NULL;
  865. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  866. if (crtc->enabled && crtc->fb) {
  867. if (enabled)
  868. return NULL;
  869. enabled = crtc;
  870. }
  871. }
  872. return enabled;
  873. }
  874. static void pineview_update_wm(struct drm_device *dev)
  875. {
  876. struct drm_i915_private *dev_priv = dev->dev_private;
  877. struct drm_crtc *crtc;
  878. const struct cxsr_latency *latency;
  879. u32 reg;
  880. unsigned long wm;
  881. latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3,
  882. dev_priv->fsb_freq, dev_priv->mem_freq);
  883. if (!latency) {
  884. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  885. pineview_disable_cxsr(dev);
  886. return;
  887. }
  888. crtc = single_enabled_crtc(dev);
  889. if (crtc) {
  890. int clock = crtc->mode.clock;
  891. int pixel_size = crtc->fb->bits_per_pixel / 8;
  892. /* Display SR */
  893. wm = intel_calculate_wm(clock, &pineview_display_wm,
  894. pineview_display_wm.fifo_size,
  895. pixel_size, latency->display_sr);
  896. reg = I915_READ(DSPFW1);
  897. reg &= ~DSPFW_SR_MASK;
  898. reg |= wm << DSPFW_SR_SHIFT;
  899. I915_WRITE(DSPFW1, reg);
  900. DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg);
  901. /* cursor SR */
  902. wm = intel_calculate_wm(clock, &pineview_cursor_wm,
  903. pineview_display_wm.fifo_size,
  904. pixel_size, latency->cursor_sr);
  905. reg = I915_READ(DSPFW3);
  906. reg &= ~DSPFW_CURSOR_SR_MASK;
  907. reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT;
  908. I915_WRITE(DSPFW3, reg);
  909. /* Display HPLL off SR */
  910. wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm,
  911. pineview_display_hplloff_wm.fifo_size,
  912. pixel_size, latency->display_hpll_disable);
  913. reg = I915_READ(DSPFW3);
  914. reg &= ~DSPFW_HPLL_SR_MASK;
  915. reg |= wm & DSPFW_HPLL_SR_MASK;
  916. I915_WRITE(DSPFW3, reg);
  917. /* cursor HPLL off SR */
  918. wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm,
  919. pineview_display_hplloff_wm.fifo_size,
  920. pixel_size, latency->cursor_hpll_disable);
  921. reg = I915_READ(DSPFW3);
  922. reg &= ~DSPFW_HPLL_CURSOR_MASK;
  923. reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT;
  924. I915_WRITE(DSPFW3, reg);
  925. DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg);
  926. /* activate cxsr */
  927. I915_WRITE(DSPFW3,
  928. I915_READ(DSPFW3) | PINEVIEW_SELF_REFRESH_EN);
  929. DRM_DEBUG_KMS("Self-refresh is enabled\n");
  930. } else {
  931. pineview_disable_cxsr(dev);
  932. DRM_DEBUG_KMS("Self-refresh is disabled\n");
  933. }
  934. }
  935. static bool g4x_compute_wm0(struct drm_device *dev,
  936. int plane,
  937. const struct intel_watermark_params *display,
  938. int display_latency_ns,
  939. const struct intel_watermark_params *cursor,
  940. int cursor_latency_ns,
  941. int *plane_wm,
  942. int *cursor_wm)
  943. {
  944. struct drm_crtc *crtc;
  945. int htotal, hdisplay, clock, pixel_size;
  946. int line_time_us, line_count;
  947. int entries, tlb_miss;
  948. crtc = intel_get_crtc_for_plane(dev, plane);
  949. if (crtc->fb == NULL || !crtc->enabled) {
  950. *cursor_wm = cursor->guard_size;
  951. *plane_wm = display->guard_size;
  952. return false;
  953. }
  954. htotal = crtc->mode.htotal;
  955. hdisplay = crtc->mode.hdisplay;
  956. clock = crtc->mode.clock;
  957. pixel_size = crtc->fb->bits_per_pixel / 8;
  958. /* Use the small buffer method to calculate plane watermark */
  959. entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
  960. tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;
  961. if (tlb_miss > 0)
  962. entries += tlb_miss;
  963. entries = DIV_ROUND_UP(entries, display->cacheline_size);
  964. *plane_wm = entries + display->guard_size;
  965. if (*plane_wm > (int)display->max_wm)
  966. *plane_wm = display->max_wm;
  967. /* Use the large buffer method to calculate cursor watermark */
  968. line_time_us = ((htotal * 1000) / clock);
  969. line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
  970. entries = line_count * 64 * pixel_size;
  971. tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
  972. if (tlb_miss > 0)
  973. entries += tlb_miss;
  974. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  975. *cursor_wm = entries + cursor->guard_size;
  976. if (*cursor_wm > (int)cursor->max_wm)
  977. *cursor_wm = (int)cursor->max_wm;
  978. return true;
  979. }
  980. /*
  981. * Check the wm result.
  982. *
  983. * If any calculated watermark values is larger than the maximum value that
  984. * can be programmed into the associated watermark register, that watermark
  985. * must be disabled.
  986. */
  987. static bool g4x_check_srwm(struct drm_device *dev,
  988. int display_wm, int cursor_wm,
  989. const struct intel_watermark_params *display,
  990. const struct intel_watermark_params *cursor)
  991. {
  992. DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n",
  993. display_wm, cursor_wm);
  994. if (display_wm > display->max_wm) {
  995. DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n",
  996. display_wm, display->max_wm);
  997. return false;
  998. }
  999. if (cursor_wm > cursor->max_wm) {
  1000. DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n",
  1001. cursor_wm, cursor->max_wm);
  1002. return false;
  1003. }
  1004. if (!(display_wm || cursor_wm)) {
  1005. DRM_DEBUG_KMS("SR latency is 0, disabling\n");
  1006. return false;
  1007. }
  1008. return true;
  1009. }
  1010. static bool g4x_compute_srwm(struct drm_device *dev,
  1011. int plane,
  1012. int latency_ns,
  1013. const struct intel_watermark_params *display,
  1014. const struct intel_watermark_params *cursor,
  1015. int *display_wm, int *cursor_wm)
  1016. {
  1017. struct drm_crtc *crtc;
  1018. int hdisplay, htotal, pixel_size, clock;
  1019. unsigned long line_time_us;
  1020. int line_count, line_size;
  1021. int small, large;
  1022. int entries;
  1023. if (!latency_ns) {
  1024. *display_wm = *cursor_wm = 0;
  1025. return false;
  1026. }
  1027. crtc = intel_get_crtc_for_plane(dev, plane);
  1028. hdisplay = crtc->mode.hdisplay;
  1029. htotal = crtc->mode.htotal;
  1030. clock = crtc->mode.clock;
  1031. pixel_size = crtc->fb->bits_per_pixel / 8;
  1032. line_time_us = (htotal * 1000) / clock;
  1033. line_count = (latency_ns / line_time_us + 1000) / 1000;
  1034. line_size = hdisplay * pixel_size;
  1035. /* Use the minimum of the small and large buffer method for primary */
  1036. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  1037. large = line_count * line_size;
  1038. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  1039. *display_wm = entries + display->guard_size;
  1040. /* calculate the self-refresh watermark for display cursor */
  1041. entries = line_count * pixel_size * 64;
  1042. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  1043. *cursor_wm = entries + cursor->guard_size;
  1044. return g4x_check_srwm(dev,
  1045. *display_wm, *cursor_wm,
  1046. display, cursor);
  1047. }
  1048. static bool vlv_compute_drain_latency(struct drm_device *dev,
  1049. int plane,
  1050. int *plane_prec_mult,
  1051. int *plane_dl,
  1052. int *cursor_prec_mult,
  1053. int *cursor_dl)
  1054. {
  1055. struct drm_crtc *crtc;
  1056. int clock, pixel_size;
  1057. int entries;
  1058. crtc = intel_get_crtc_for_plane(dev, plane);
  1059. if (crtc->fb == NULL || !crtc->enabled)
  1060. return false;
  1061. clock = crtc->mode.clock; /* VESA DOT Clock */
  1062. pixel_size = crtc->fb->bits_per_pixel / 8; /* BPP */
  1063. entries = (clock / 1000) * pixel_size;
  1064. *plane_prec_mult = (entries > 256) ?
  1065. DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16;
  1066. *plane_dl = (64 * (*plane_prec_mult) * 4) / ((clock / 1000) *
  1067. pixel_size);
  1068. entries = (clock / 1000) * 4; /* BPP is always 4 for cursor */
  1069. *cursor_prec_mult = (entries > 256) ?
  1070. DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_16;
  1071. *cursor_dl = (64 * (*cursor_prec_mult) * 4) / ((clock / 1000) * 4);
  1072. return true;
  1073. }
  1074. /*
  1075. * Update drain latency registers of memory arbiter
  1076. *
  1077. * Valleyview SoC has a new memory arbiter and needs drain latency registers
  1078. * to be programmed. Each plane has a drain latency multiplier and a drain
  1079. * latency value.
  1080. */
  1081. static void vlv_update_drain_latency(struct drm_device *dev)
  1082. {
  1083. struct drm_i915_private *dev_priv = dev->dev_private;
  1084. int planea_prec, planea_dl, planeb_prec, planeb_dl;
  1085. int cursora_prec, cursora_dl, cursorb_prec, cursorb_dl;
  1086. int plane_prec_mult, cursor_prec_mult; /* Precision multiplier is
  1087. either 16 or 32 */
  1088. /* For plane A, Cursor A */
  1089. if (vlv_compute_drain_latency(dev, 0, &plane_prec_mult, &planea_dl,
  1090. &cursor_prec_mult, &cursora_dl)) {
  1091. cursora_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ?
  1092. DDL_CURSORA_PRECISION_32 : DDL_CURSORA_PRECISION_16;
  1093. planea_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ?
  1094. DDL_PLANEA_PRECISION_32 : DDL_PLANEA_PRECISION_16;
  1095. I915_WRITE(VLV_DDL1, cursora_prec |
  1096. (cursora_dl << DDL_CURSORA_SHIFT) |
  1097. planea_prec | planea_dl);
  1098. }
  1099. /* For plane B, Cursor B */
  1100. if (vlv_compute_drain_latency(dev, 1, &plane_prec_mult, &planeb_dl,
  1101. &cursor_prec_mult, &cursorb_dl)) {
  1102. cursorb_prec = (cursor_prec_mult == DRAIN_LATENCY_PRECISION_32) ?
  1103. DDL_CURSORB_PRECISION_32 : DDL_CURSORB_PRECISION_16;
  1104. planeb_prec = (plane_prec_mult == DRAIN_LATENCY_PRECISION_32) ?
  1105. DDL_PLANEB_PRECISION_32 : DDL_PLANEB_PRECISION_16;
  1106. I915_WRITE(VLV_DDL2, cursorb_prec |
  1107. (cursorb_dl << DDL_CURSORB_SHIFT) |
  1108. planeb_prec | planeb_dl);
  1109. }
  1110. }
  1111. #define single_plane_enabled(mask) is_power_of_2(mask)
  1112. static void valleyview_update_wm(struct drm_device *dev)
  1113. {
  1114. static const int sr_latency_ns = 12000;
  1115. struct drm_i915_private *dev_priv = dev->dev_private;
  1116. int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
  1117. int plane_sr, cursor_sr;
  1118. unsigned int enabled = 0;
  1119. vlv_update_drain_latency(dev);
  1120. if (g4x_compute_wm0(dev, 0,
  1121. &valleyview_wm_info, latency_ns,
  1122. &valleyview_cursor_wm_info, latency_ns,
  1123. &planea_wm, &cursora_wm))
  1124. enabled |= 1;
  1125. if (g4x_compute_wm0(dev, 1,
  1126. &valleyview_wm_info, latency_ns,
  1127. &valleyview_cursor_wm_info, latency_ns,
  1128. &planeb_wm, &cursorb_wm))
  1129. enabled |= 2;
  1130. plane_sr = cursor_sr = 0;
  1131. if (single_plane_enabled(enabled) &&
  1132. g4x_compute_srwm(dev, ffs(enabled) - 1,
  1133. sr_latency_ns,
  1134. &valleyview_wm_info,
  1135. &valleyview_cursor_wm_info,
  1136. &plane_sr, &cursor_sr))
  1137. I915_WRITE(FW_BLC_SELF_VLV, FW_CSPWRDWNEN);
  1138. else
  1139. I915_WRITE(FW_BLC_SELF_VLV,
  1140. I915_READ(FW_BLC_SELF_VLV) & ~FW_CSPWRDWNEN);
  1141. DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
  1142. planea_wm, cursora_wm,
  1143. planeb_wm, cursorb_wm,
  1144. plane_sr, cursor_sr);
  1145. I915_WRITE(DSPFW1,
  1146. (plane_sr << DSPFW_SR_SHIFT) |
  1147. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  1148. (planeb_wm << DSPFW_PLANEB_SHIFT) |
  1149. planea_wm);
  1150. I915_WRITE(DSPFW2,
  1151. (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) |
  1152. (cursora_wm << DSPFW_CURSORA_SHIFT));
  1153. I915_WRITE(DSPFW3,
  1154. (I915_READ(DSPFW3) | (cursor_sr << DSPFW_CURSOR_SR_SHIFT)));
  1155. }
  1156. static void g4x_update_wm(struct drm_device *dev)
  1157. {
  1158. static const int sr_latency_ns = 12000;
  1159. struct drm_i915_private *dev_priv = dev->dev_private;
  1160. int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
  1161. int plane_sr, cursor_sr;
  1162. unsigned int enabled = 0;
  1163. if (g4x_compute_wm0(dev, 0,
  1164. &g4x_wm_info, latency_ns,
  1165. &g4x_cursor_wm_info, latency_ns,
  1166. &planea_wm, &cursora_wm))
  1167. enabled |= 1;
  1168. if (g4x_compute_wm0(dev, 1,
  1169. &g4x_wm_info, latency_ns,
  1170. &g4x_cursor_wm_info, latency_ns,
  1171. &planeb_wm, &cursorb_wm))
  1172. enabled |= 2;
  1173. plane_sr = cursor_sr = 0;
  1174. if (single_plane_enabled(enabled) &&
  1175. g4x_compute_srwm(dev, ffs(enabled) - 1,
  1176. sr_latency_ns,
  1177. &g4x_wm_info,
  1178. &g4x_cursor_wm_info,
  1179. &plane_sr, &cursor_sr))
  1180. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  1181. else
  1182. I915_WRITE(FW_BLC_SELF,
  1183. I915_READ(FW_BLC_SELF) & ~FW_BLC_SELF_EN);
  1184. DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
  1185. planea_wm, cursora_wm,
  1186. planeb_wm, cursorb_wm,
  1187. plane_sr, cursor_sr);
  1188. I915_WRITE(DSPFW1,
  1189. (plane_sr << DSPFW_SR_SHIFT) |
  1190. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  1191. (planeb_wm << DSPFW_PLANEB_SHIFT) |
  1192. planea_wm);
  1193. I915_WRITE(DSPFW2,
  1194. (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) |
  1195. (cursora_wm << DSPFW_CURSORA_SHIFT));
  1196. /* HPLL off in SR has some issues on G4x... disable it */
  1197. I915_WRITE(DSPFW3,
  1198. (I915_READ(DSPFW3) & ~DSPFW_HPLL_SR_EN) |
  1199. (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  1200. }
  1201. static void i965_update_wm(struct drm_device *dev)
  1202. {
  1203. struct drm_i915_private *dev_priv = dev->dev_private;
  1204. struct drm_crtc *crtc;
  1205. int srwm = 1;
  1206. int cursor_sr = 16;
  1207. /* Calc sr entries for one plane configs */
  1208. crtc = single_enabled_crtc(dev);
  1209. if (crtc) {
  1210. /* self-refresh has much higher latency */
  1211. static const int sr_latency_ns = 12000;
  1212. int clock = crtc->mode.clock;
  1213. int htotal = crtc->mode.htotal;
  1214. int hdisplay = crtc->mode.hdisplay;
  1215. int pixel_size = crtc->fb->bits_per_pixel / 8;
  1216. unsigned long line_time_us;
  1217. int entries;
  1218. line_time_us = ((htotal * 1000) / clock);
  1219. /* Use ns/us then divide to preserve precision */
  1220. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  1221. pixel_size * hdisplay;
  1222. entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE);
  1223. srwm = I965_FIFO_SIZE - entries;
  1224. if (srwm < 0)
  1225. srwm = 1;
  1226. srwm &= 0x1ff;
  1227. DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n",
  1228. entries, srwm);
  1229. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  1230. pixel_size * 64;
  1231. entries = DIV_ROUND_UP(entries,
  1232. i965_cursor_wm_info.cacheline_size);
  1233. cursor_sr = i965_cursor_wm_info.fifo_size -
  1234. (entries + i965_cursor_wm_info.guard_size);
  1235. if (cursor_sr > i965_cursor_wm_info.max_wm)
  1236. cursor_sr = i965_cursor_wm_info.max_wm;
  1237. DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
  1238. "cursor %d\n", srwm, cursor_sr);
  1239. if (IS_CRESTLINE(dev))
  1240. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  1241. } else {
  1242. /* Turn off self refresh if both pipes are enabled */
  1243. if (IS_CRESTLINE(dev))
  1244. I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
  1245. & ~FW_BLC_SELF_EN);
  1246. }
  1247. DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
  1248. srwm);
  1249. /* 965 has limitations... */
  1250. I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) |
  1251. (8 << 16) | (8 << 8) | (8 << 0));
  1252. I915_WRITE(DSPFW2, (8 << 8) | (8 << 0));
  1253. /* update cursor SR watermark */
  1254. I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  1255. }
  1256. static void i9xx_update_wm(struct drm_device *dev)
  1257. {
  1258. struct drm_i915_private *dev_priv = dev->dev_private;
  1259. const struct intel_watermark_params *wm_info;
  1260. uint32_t fwater_lo;
  1261. uint32_t fwater_hi;
  1262. int cwm, srwm = 1;
  1263. int fifo_size;
  1264. int planea_wm, planeb_wm;
  1265. struct drm_crtc *crtc, *enabled = NULL;
  1266. if (IS_I945GM(dev))
  1267. wm_info = &i945_wm_info;
  1268. else if (!IS_GEN2(dev))
  1269. wm_info = &i915_wm_info;
  1270. else
  1271. wm_info = &i855_wm_info;
  1272. fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  1273. crtc = intel_get_crtc_for_plane(dev, 0);
  1274. if (crtc->enabled && crtc->fb) {
  1275. planea_wm = intel_calculate_wm(crtc->mode.clock,
  1276. wm_info, fifo_size,
  1277. crtc->fb->bits_per_pixel / 8,
  1278. latency_ns);
  1279. enabled = crtc;
  1280. } else
  1281. planea_wm = fifo_size - wm_info->guard_size;
  1282. fifo_size = dev_priv->display.get_fifo_size(dev, 1);
  1283. crtc = intel_get_crtc_for_plane(dev, 1);
  1284. if (crtc->enabled && crtc->fb) {
  1285. planeb_wm = intel_calculate_wm(crtc->mode.clock,
  1286. wm_info, fifo_size,
  1287. crtc->fb->bits_per_pixel / 8,
  1288. latency_ns);
  1289. if (enabled == NULL)
  1290. enabled = crtc;
  1291. else
  1292. enabled = NULL;
  1293. } else
  1294. planeb_wm = fifo_size - wm_info->guard_size;
  1295. DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  1296. /*
  1297. * Overlay gets an aggressive default since video jitter is bad.
  1298. */
  1299. cwm = 2;
  1300. /* Play safe and disable self-refresh before adjusting watermarks. */
  1301. if (IS_I945G(dev) || IS_I945GM(dev))
  1302. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | 0);
  1303. else if (IS_I915GM(dev))
  1304. I915_WRITE(INSTPM, I915_READ(INSTPM) & ~INSTPM_SELF_EN);
  1305. /* Calc sr entries for one plane configs */
  1306. if (HAS_FW_BLC(dev) && enabled) {
  1307. /* self-refresh has much higher latency */
  1308. static const int sr_latency_ns = 6000;
  1309. int clock = enabled->mode.clock;
  1310. int htotal = enabled->mode.htotal;
  1311. int hdisplay = enabled->mode.hdisplay;
  1312. int pixel_size = enabled->fb->bits_per_pixel / 8;
  1313. unsigned long line_time_us;
  1314. int entries;
  1315. line_time_us = (htotal * 1000) / clock;
  1316. /* Use ns/us then divide to preserve precision */
  1317. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  1318. pixel_size * hdisplay;
  1319. entries = DIV_ROUND_UP(entries, wm_info->cacheline_size);
  1320. DRM_DEBUG_KMS("self-refresh entries: %d\n", entries);
  1321. srwm = wm_info->fifo_size - entries;
  1322. if (srwm < 0)
  1323. srwm = 1;
  1324. if (IS_I945G(dev) || IS_I945GM(dev))
  1325. I915_WRITE(FW_BLC_SELF,
  1326. FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
  1327. else if (IS_I915GM(dev))
  1328. I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
  1329. }
  1330. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
  1331. planea_wm, planeb_wm, cwm, srwm);
  1332. fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
  1333. fwater_hi = (cwm & 0x1f);
  1334. /* Set request length to 8 cachelines per fetch */
  1335. fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
  1336. fwater_hi = fwater_hi | (1 << 8);
  1337. I915_WRITE(FW_BLC, fwater_lo);
  1338. I915_WRITE(FW_BLC2, fwater_hi);
  1339. if (HAS_FW_BLC(dev)) {
  1340. if (enabled) {
  1341. if (IS_I945G(dev) || IS_I945GM(dev))
  1342. I915_WRITE(FW_BLC_SELF,
  1343. FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN);
  1344. else if (IS_I915GM(dev))
  1345. I915_WRITE(INSTPM, I915_READ(INSTPM) | INSTPM_SELF_EN);
  1346. DRM_DEBUG_KMS("memory self refresh enabled\n");
  1347. } else
  1348. DRM_DEBUG_KMS("memory self refresh disabled\n");
  1349. }
  1350. }
  1351. static void i830_update_wm(struct drm_device *dev)
  1352. {
  1353. struct drm_i915_private *dev_priv = dev->dev_private;
  1354. struct drm_crtc *crtc;
  1355. uint32_t fwater_lo;
  1356. int planea_wm;
  1357. crtc = single_enabled_crtc(dev);
  1358. if (crtc == NULL)
  1359. return;
  1360. planea_wm = intel_calculate_wm(crtc->mode.clock, &i830_wm_info,
  1361. dev_priv->display.get_fifo_size(dev, 0),
  1362. crtc->fb->bits_per_pixel / 8,
  1363. latency_ns);
  1364. fwater_lo = I915_READ(FW_BLC) & ~0xfff;
  1365. fwater_lo |= (3<<8) | planea_wm;
  1366. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm);
  1367. I915_WRITE(FW_BLC, fwater_lo);
  1368. }
  1369. #define ILK_LP0_PLANE_LATENCY 700
  1370. #define ILK_LP0_CURSOR_LATENCY 1300
  1371. /*
  1372. * Check the wm result.
  1373. *
  1374. * If any calculated watermark values is larger than the maximum value that
  1375. * can be programmed into the associated watermark register, that watermark
  1376. * must be disabled.
  1377. */
  1378. static bool ironlake_check_srwm(struct drm_device *dev, int level,
  1379. int fbc_wm, int display_wm, int cursor_wm,
  1380. const struct intel_watermark_params *display,
  1381. const struct intel_watermark_params *cursor)
  1382. {
  1383. struct drm_i915_private *dev_priv = dev->dev_private;
  1384. DRM_DEBUG_KMS("watermark %d: display plane %d, fbc lines %d,"
  1385. " cursor %d\n", level, display_wm, fbc_wm, cursor_wm);
  1386. if (fbc_wm > SNB_FBC_MAX_SRWM) {
  1387. DRM_DEBUG_KMS("fbc watermark(%d) is too large(%d), disabling wm%d+\n",
  1388. fbc_wm, SNB_FBC_MAX_SRWM, level);
  1389. /* fbc has it's own way to disable FBC WM */
  1390. I915_WRITE(DISP_ARB_CTL,
  1391. I915_READ(DISP_ARB_CTL) | DISP_FBC_WM_DIS);
  1392. return false;
  1393. }
  1394. if (display_wm > display->max_wm) {
  1395. DRM_DEBUG_KMS("display watermark(%d) is too large(%d), disabling wm%d+\n",
  1396. display_wm, SNB_DISPLAY_MAX_SRWM, level);
  1397. return false;
  1398. }
  1399. if (cursor_wm > cursor->max_wm) {
  1400. DRM_DEBUG_KMS("cursor watermark(%d) is too large(%d), disabling wm%d+\n",
  1401. cursor_wm, SNB_CURSOR_MAX_SRWM, level);
  1402. return false;
  1403. }
  1404. if (!(fbc_wm || display_wm || cursor_wm)) {
  1405. DRM_DEBUG_KMS("latency %d is 0, disabling wm%d+\n", level, level);
  1406. return false;
  1407. }
  1408. return true;
  1409. }
  1410. /*
  1411. * Compute watermark values of WM[1-3],
  1412. */
  1413. static bool ironlake_compute_srwm(struct drm_device *dev, int level, int plane,
  1414. int latency_ns,
  1415. const struct intel_watermark_params *display,
  1416. const struct intel_watermark_params *cursor,
  1417. int *fbc_wm, int *display_wm, int *cursor_wm)
  1418. {
  1419. struct drm_crtc *crtc;
  1420. unsigned long line_time_us;
  1421. int hdisplay, htotal, pixel_size, clock;
  1422. int line_count, line_size;
  1423. int small, large;
  1424. int entries;
  1425. if (!latency_ns) {
  1426. *fbc_wm = *display_wm = *cursor_wm = 0;
  1427. return false;
  1428. }
  1429. crtc = intel_get_crtc_for_plane(dev, plane);
  1430. hdisplay = crtc->mode.hdisplay;
  1431. htotal = crtc->mode.htotal;
  1432. clock = crtc->mode.clock;
  1433. pixel_size = crtc->fb->bits_per_pixel / 8;
  1434. line_time_us = (htotal * 1000) / clock;
  1435. line_count = (latency_ns / line_time_us + 1000) / 1000;
  1436. line_size = hdisplay * pixel_size;
  1437. /* Use the minimum of the small and large buffer method for primary */
  1438. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  1439. large = line_count * line_size;
  1440. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  1441. *display_wm = entries + display->guard_size;
  1442. /*
  1443. * Spec says:
  1444. * FBC WM = ((Final Primary WM * 64) / number of bytes per line) + 2
  1445. */
  1446. *fbc_wm = DIV_ROUND_UP(*display_wm * 64, line_size) + 2;
  1447. /* calculate the self-refresh watermark for display cursor */
  1448. entries = line_count * pixel_size * 64;
  1449. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  1450. *cursor_wm = entries + cursor->guard_size;
  1451. return ironlake_check_srwm(dev, level,
  1452. *fbc_wm, *display_wm, *cursor_wm,
  1453. display, cursor);
  1454. }
  1455. static void ironlake_update_wm(struct drm_device *dev)
  1456. {
  1457. struct drm_i915_private *dev_priv = dev->dev_private;
  1458. int fbc_wm, plane_wm, cursor_wm;
  1459. unsigned int enabled;
  1460. enabled = 0;
  1461. if (g4x_compute_wm0(dev, 0,
  1462. &ironlake_display_wm_info,
  1463. ILK_LP0_PLANE_LATENCY,
  1464. &ironlake_cursor_wm_info,
  1465. ILK_LP0_CURSOR_LATENCY,
  1466. &plane_wm, &cursor_wm)) {
  1467. I915_WRITE(WM0_PIPEA_ILK,
  1468. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  1469. DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
  1470. " plane %d, " "cursor: %d\n",
  1471. plane_wm, cursor_wm);
  1472. enabled |= 1;
  1473. }
  1474. if (g4x_compute_wm0(dev, 1,
  1475. &ironlake_display_wm_info,
  1476. ILK_LP0_PLANE_LATENCY,
  1477. &ironlake_cursor_wm_info,
  1478. ILK_LP0_CURSOR_LATENCY,
  1479. &plane_wm, &cursor_wm)) {
  1480. I915_WRITE(WM0_PIPEB_ILK,
  1481. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  1482. DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
  1483. " plane %d, cursor: %d\n",
  1484. plane_wm, cursor_wm);
  1485. enabled |= 2;
  1486. }
  1487. /*
  1488. * Calculate and update the self-refresh watermark only when one
  1489. * display plane is used.
  1490. */
  1491. I915_WRITE(WM3_LP_ILK, 0);
  1492. I915_WRITE(WM2_LP_ILK, 0);
  1493. I915_WRITE(WM1_LP_ILK, 0);
  1494. if (!single_plane_enabled(enabled))
  1495. return;
  1496. enabled = ffs(enabled) - 1;
  1497. /* WM1 */
  1498. if (!ironlake_compute_srwm(dev, 1, enabled,
  1499. ILK_READ_WM1_LATENCY() * 500,
  1500. &ironlake_display_srwm_info,
  1501. &ironlake_cursor_srwm_info,
  1502. &fbc_wm, &plane_wm, &cursor_wm))
  1503. return;
  1504. I915_WRITE(WM1_LP_ILK,
  1505. WM1_LP_SR_EN |
  1506. (ILK_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  1507. (fbc_wm << WM1_LP_FBC_SHIFT) |
  1508. (plane_wm << WM1_LP_SR_SHIFT) |
  1509. cursor_wm);
  1510. /* WM2 */
  1511. if (!ironlake_compute_srwm(dev, 2, enabled,
  1512. ILK_READ_WM2_LATENCY() * 500,
  1513. &ironlake_display_srwm_info,
  1514. &ironlake_cursor_srwm_info,
  1515. &fbc_wm, &plane_wm, &cursor_wm))
  1516. return;
  1517. I915_WRITE(WM2_LP_ILK,
  1518. WM2_LP_EN |
  1519. (ILK_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  1520. (fbc_wm << WM1_LP_FBC_SHIFT) |
  1521. (plane_wm << WM1_LP_SR_SHIFT) |
  1522. cursor_wm);
  1523. /*
  1524. * WM3 is unsupported on ILK, probably because we don't have latency
  1525. * data for that power state
  1526. */
  1527. }
  1528. static void sandybridge_update_wm(struct drm_device *dev)
  1529. {
  1530. struct drm_i915_private *dev_priv = dev->dev_private;
  1531. int latency = SNB_READ_WM0_LATENCY() * 100; /* In unit 0.1us */
  1532. u32 val;
  1533. int fbc_wm, plane_wm, cursor_wm;
  1534. unsigned int enabled;
  1535. enabled = 0;
  1536. if (g4x_compute_wm0(dev, 0,
  1537. &sandybridge_display_wm_info, latency,
  1538. &sandybridge_cursor_wm_info, latency,
  1539. &plane_wm, &cursor_wm)) {
  1540. val = I915_READ(WM0_PIPEA_ILK);
  1541. val &= ~(WM0_PIPE_PLANE_MASK | WM0_PIPE_CURSOR_MASK);
  1542. I915_WRITE(WM0_PIPEA_ILK, val |
  1543. ((plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm));
  1544. DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
  1545. " plane %d, " "cursor: %d\n",
  1546. plane_wm, cursor_wm);
  1547. enabled |= 1;
  1548. }
  1549. if (g4x_compute_wm0(dev, 1,
  1550. &sandybridge_display_wm_info, latency,
  1551. &sandybridge_cursor_wm_info, latency,
  1552. &plane_wm, &cursor_wm)) {
  1553. val = I915_READ(WM0_PIPEB_ILK);
  1554. val &= ~(WM0_PIPE_PLANE_MASK | WM0_PIPE_CURSOR_MASK);
  1555. I915_WRITE(WM0_PIPEB_ILK, val |
  1556. ((plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm));
  1557. DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
  1558. " plane %d, cursor: %d\n",
  1559. plane_wm, cursor_wm);
  1560. enabled |= 2;
  1561. }
  1562. if ((dev_priv->num_pipe == 3) &&
  1563. g4x_compute_wm0(dev, 2,
  1564. &sandybridge_display_wm_info, latency,
  1565. &sandybridge_cursor_wm_info, latency,
  1566. &plane_wm, &cursor_wm)) {
  1567. val = I915_READ(WM0_PIPEC_IVB);
  1568. val &= ~(WM0_PIPE_PLANE_MASK | WM0_PIPE_CURSOR_MASK);
  1569. I915_WRITE(WM0_PIPEC_IVB, val |
  1570. ((plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm));
  1571. DRM_DEBUG_KMS("FIFO watermarks For pipe C -"
  1572. " plane %d, cursor: %d\n",
  1573. plane_wm, cursor_wm);
  1574. enabled |= 3;
  1575. }
  1576. /*
  1577. * Calculate and update the self-refresh watermark only when one
  1578. * display plane is used.
  1579. *
  1580. * SNB support 3 levels of watermark.
  1581. *
  1582. * WM1/WM2/WM2 watermarks have to be enabled in the ascending order,
  1583. * and disabled in the descending order
  1584. *
  1585. */
  1586. I915_WRITE(WM3_LP_ILK, 0);
  1587. I915_WRITE(WM2_LP_ILK, 0);
  1588. I915_WRITE(WM1_LP_ILK, 0);
  1589. if (!single_plane_enabled(enabled) ||
  1590. dev_priv->sprite_scaling_enabled)
  1591. return;
  1592. enabled = ffs(enabled) - 1;
  1593. /* WM1 */
  1594. if (!ironlake_compute_srwm(dev, 1, enabled,
  1595. SNB_READ_WM1_LATENCY() * 500,
  1596. &sandybridge_display_srwm_info,
  1597. &sandybridge_cursor_srwm_info,
  1598. &fbc_wm, &plane_wm, &cursor_wm))
  1599. return;
  1600. I915_WRITE(WM1_LP_ILK,
  1601. WM1_LP_SR_EN |
  1602. (SNB_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  1603. (fbc_wm << WM1_LP_FBC_SHIFT) |
  1604. (plane_wm << WM1_LP_SR_SHIFT) |
  1605. cursor_wm);
  1606. /* WM2 */
  1607. if (!ironlake_compute_srwm(dev, 2, enabled,
  1608. SNB_READ_WM2_LATENCY() * 500,
  1609. &sandybridge_display_srwm_info,
  1610. &sandybridge_cursor_srwm_info,
  1611. &fbc_wm, &plane_wm, &cursor_wm))
  1612. return;
  1613. I915_WRITE(WM2_LP_ILK,
  1614. WM2_LP_EN |
  1615. (SNB_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  1616. (fbc_wm << WM1_LP_FBC_SHIFT) |
  1617. (plane_wm << WM1_LP_SR_SHIFT) |
  1618. cursor_wm);
  1619. /* WM3 */
  1620. if (!ironlake_compute_srwm(dev, 3, enabled,
  1621. SNB_READ_WM3_LATENCY() * 500,
  1622. &sandybridge_display_srwm_info,
  1623. &sandybridge_cursor_srwm_info,
  1624. &fbc_wm, &plane_wm, &cursor_wm))
  1625. return;
  1626. I915_WRITE(WM3_LP_ILK,
  1627. WM3_LP_EN |
  1628. (SNB_READ_WM3_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  1629. (fbc_wm << WM1_LP_FBC_SHIFT) |
  1630. (plane_wm << WM1_LP_SR_SHIFT) |
  1631. cursor_wm);
  1632. }
  1633. static void
  1634. haswell_update_linetime_wm(struct drm_device *dev, int pipe,
  1635. struct drm_display_mode *mode)
  1636. {
  1637. struct drm_i915_private *dev_priv = dev->dev_private;
  1638. u32 temp;
  1639. temp = I915_READ(PIPE_WM_LINETIME(pipe));
  1640. temp &= ~PIPE_WM_LINETIME_MASK;
  1641. /* The WM are computed with base on how long it takes to fill a single
  1642. * row at the given clock rate, multiplied by 8.
  1643. * */
  1644. temp |= PIPE_WM_LINETIME_TIME(
  1645. ((mode->crtc_hdisplay * 1000) / mode->clock) * 8);
  1646. /* IPS watermarks are only used by pipe A, and are ignored by
  1647. * pipes B and C. They are calculated similarly to the common
  1648. * linetime values, except that we are using CD clock frequency
  1649. * in MHz instead of pixel rate for the division.
  1650. *
  1651. * This is a placeholder for the IPS watermark calculation code.
  1652. */
  1653. I915_WRITE(PIPE_WM_LINETIME(pipe), temp);
  1654. }
  1655. static bool
  1656. sandybridge_compute_sprite_wm(struct drm_device *dev, int plane,
  1657. uint32_t sprite_width, int pixel_size,
  1658. const struct intel_watermark_params *display,
  1659. int display_latency_ns, int *sprite_wm)
  1660. {
  1661. struct drm_crtc *crtc;
  1662. int clock;
  1663. int entries, tlb_miss;
  1664. crtc = intel_get_crtc_for_plane(dev, plane);
  1665. if (crtc->fb == NULL || !crtc->enabled) {
  1666. *sprite_wm = display->guard_size;
  1667. return false;
  1668. }
  1669. clock = crtc->mode.clock;
  1670. /* Use the small buffer method to calculate the sprite watermark */
  1671. entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
  1672. tlb_miss = display->fifo_size*display->cacheline_size -
  1673. sprite_width * 8;
  1674. if (tlb_miss > 0)
  1675. entries += tlb_miss;
  1676. entries = DIV_ROUND_UP(entries, display->cacheline_size);
  1677. *sprite_wm = entries + display->guard_size;
  1678. if (*sprite_wm > (int)display->max_wm)
  1679. *sprite_wm = display->max_wm;
  1680. return true;
  1681. }
  1682. static bool
  1683. sandybridge_compute_sprite_srwm(struct drm_device *dev, int plane,
  1684. uint32_t sprite_width, int pixel_size,
  1685. const struct intel_watermark_params *display,
  1686. int latency_ns, int *sprite_wm)
  1687. {
  1688. struct drm_crtc *crtc;
  1689. unsigned long line_time_us;
  1690. int clock;
  1691. int line_count, line_size;
  1692. int small, large;
  1693. int entries;
  1694. if (!latency_ns) {
  1695. *sprite_wm = 0;
  1696. return false;
  1697. }
  1698. crtc = intel_get_crtc_for_plane(dev, plane);
  1699. clock = crtc->mode.clock;
  1700. if (!clock) {
  1701. *sprite_wm = 0;
  1702. return false;
  1703. }
  1704. line_time_us = (sprite_width * 1000) / clock;
  1705. if (!line_time_us) {
  1706. *sprite_wm = 0;
  1707. return false;
  1708. }
  1709. line_count = (latency_ns / line_time_us + 1000) / 1000;
  1710. line_size = sprite_width * pixel_size;
  1711. /* Use the minimum of the small and large buffer method for primary */
  1712. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  1713. large = line_count * line_size;
  1714. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  1715. *sprite_wm = entries + display->guard_size;
  1716. return *sprite_wm > 0x3ff ? false : true;
  1717. }
  1718. static void sandybridge_update_sprite_wm(struct drm_device *dev, int pipe,
  1719. uint32_t sprite_width, int pixel_size)
  1720. {
  1721. struct drm_i915_private *dev_priv = dev->dev_private;
  1722. int latency = SNB_READ_WM0_LATENCY() * 100; /* In unit 0.1us */
  1723. u32 val;
  1724. int sprite_wm, reg;
  1725. int ret;
  1726. switch (pipe) {
  1727. case 0:
  1728. reg = WM0_PIPEA_ILK;
  1729. break;
  1730. case 1:
  1731. reg = WM0_PIPEB_ILK;
  1732. break;
  1733. case 2:
  1734. reg = WM0_PIPEC_IVB;
  1735. break;
  1736. default:
  1737. return; /* bad pipe */
  1738. }
  1739. ret = sandybridge_compute_sprite_wm(dev, pipe, sprite_width, pixel_size,
  1740. &sandybridge_display_wm_info,
  1741. latency, &sprite_wm);
  1742. if (!ret) {
  1743. DRM_DEBUG_KMS("failed to compute sprite wm for pipe %d\n",
  1744. pipe);
  1745. return;
  1746. }
  1747. val = I915_READ(reg);
  1748. val &= ~WM0_PIPE_SPRITE_MASK;
  1749. I915_WRITE(reg, val | (sprite_wm << WM0_PIPE_SPRITE_SHIFT));
  1750. DRM_DEBUG_KMS("sprite watermarks For pipe %d - %d\n", pipe, sprite_wm);
  1751. ret = sandybridge_compute_sprite_srwm(dev, pipe, sprite_width,
  1752. pixel_size,
  1753. &sandybridge_display_srwm_info,
  1754. SNB_READ_WM1_LATENCY() * 500,
  1755. &sprite_wm);
  1756. if (!ret) {
  1757. DRM_DEBUG_KMS("failed to compute sprite lp1 wm on pipe %d\n",
  1758. pipe);
  1759. return;
  1760. }
  1761. I915_WRITE(WM1S_LP_ILK, sprite_wm);
  1762. /* Only IVB has two more LP watermarks for sprite */
  1763. if (!IS_IVYBRIDGE(dev))
  1764. return;
  1765. ret = sandybridge_compute_sprite_srwm(dev, pipe, sprite_width,
  1766. pixel_size,
  1767. &sandybridge_display_srwm_info,
  1768. SNB_READ_WM2_LATENCY() * 500,
  1769. &sprite_wm);
  1770. if (!ret) {
  1771. DRM_DEBUG_KMS("failed to compute sprite lp2 wm on pipe %d\n",
  1772. pipe);
  1773. return;
  1774. }
  1775. I915_WRITE(WM2S_LP_IVB, sprite_wm);
  1776. ret = sandybridge_compute_sprite_srwm(dev, pipe, sprite_width,
  1777. pixel_size,
  1778. &sandybridge_display_srwm_info,
  1779. SNB_READ_WM3_LATENCY() * 500,
  1780. &sprite_wm);
  1781. if (!ret) {
  1782. DRM_DEBUG_KMS("failed to compute sprite lp3 wm on pipe %d\n",
  1783. pipe);
  1784. return;
  1785. }
  1786. I915_WRITE(WM3S_LP_IVB, sprite_wm);
  1787. }
  1788. /**
  1789. * intel_update_watermarks - update FIFO watermark values based on current modes
  1790. *
  1791. * Calculate watermark values for the various WM regs based on current mode
  1792. * and plane configuration.
  1793. *
  1794. * There are several cases to deal with here:
  1795. * - normal (i.e. non-self-refresh)
  1796. * - self-refresh (SR) mode
  1797. * - lines are large relative to FIFO size (buffer can hold up to 2)
  1798. * - lines are small relative to FIFO size (buffer can hold more than 2
  1799. * lines), so need to account for TLB latency
  1800. *
  1801. * The normal calculation is:
  1802. * watermark = dotclock * bytes per pixel * latency
  1803. * where latency is platform & configuration dependent (we assume pessimal
  1804. * values here).
  1805. *
  1806. * The SR calculation is:
  1807. * watermark = (trunc(latency/line time)+1) * surface width *
  1808. * bytes per pixel
  1809. * where
  1810. * line time = htotal / dotclock
  1811. * surface width = hdisplay for normal plane and 64 for cursor
  1812. * and latency is assumed to be high, as above.
  1813. *
  1814. * The final value programmed to the register should always be rounded up,
  1815. * and include an extra 2 entries to account for clock crossings.
  1816. *
  1817. * We don't use the sprite, so we can ignore that. And on Crestline we have
  1818. * to set the non-SR watermarks to 8.
  1819. */
  1820. void intel_update_watermarks(struct drm_device *dev)
  1821. {
  1822. struct drm_i915_private *dev_priv = dev->dev_private;
  1823. if (dev_priv->display.update_wm)
  1824. dev_priv->display.update_wm(dev);
  1825. }
  1826. void intel_update_linetime_watermarks(struct drm_device *dev,
  1827. int pipe, struct drm_display_mode *mode)
  1828. {
  1829. struct drm_i915_private *dev_priv = dev->dev_private;
  1830. if (dev_priv->display.update_linetime_wm)
  1831. dev_priv->display.update_linetime_wm(dev, pipe, mode);
  1832. }
  1833. void intel_update_sprite_watermarks(struct drm_device *dev, int pipe,
  1834. uint32_t sprite_width, int pixel_size)
  1835. {
  1836. struct drm_i915_private *dev_priv = dev->dev_private;
  1837. if (dev_priv->display.update_sprite_wm)
  1838. dev_priv->display.update_sprite_wm(dev, pipe, sprite_width,
  1839. pixel_size);
  1840. }
  1841. static struct drm_i915_gem_object *
  1842. intel_alloc_context_page(struct drm_device *dev)
  1843. {
  1844. struct drm_i915_gem_object *ctx;
  1845. int ret;
  1846. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  1847. ctx = i915_gem_alloc_object(dev, 4096);
  1848. if (!ctx) {
  1849. DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
  1850. return NULL;
  1851. }
  1852. ret = i915_gem_object_pin(ctx, 4096, true, false);
  1853. if (ret) {
  1854. DRM_ERROR("failed to pin power context: %d\n", ret);
  1855. goto err_unref;
  1856. }
  1857. ret = i915_gem_object_set_to_gtt_domain(ctx, 1);
  1858. if (ret) {
  1859. DRM_ERROR("failed to set-domain on power context: %d\n", ret);
  1860. goto err_unpin;
  1861. }
  1862. return ctx;
  1863. err_unpin:
  1864. i915_gem_object_unpin(ctx);
  1865. err_unref:
  1866. drm_gem_object_unreference(&ctx->base);
  1867. mutex_unlock(&dev->struct_mutex);
  1868. return NULL;
  1869. }
  1870. /**
  1871. * Lock protecting IPS related data structures
  1872. */
  1873. DEFINE_SPINLOCK(mchdev_lock);
  1874. /* Global for IPS driver to get at the current i915 device. Protected by
  1875. * mchdev_lock. */
  1876. static struct drm_i915_private *i915_mch_dev;
  1877. bool ironlake_set_drps(struct drm_device *dev, u8 val)
  1878. {
  1879. struct drm_i915_private *dev_priv = dev->dev_private;
  1880. u16 rgvswctl;
  1881. assert_spin_locked(&mchdev_lock);
  1882. rgvswctl = I915_READ16(MEMSWCTL);
  1883. if (rgvswctl & MEMCTL_CMD_STS) {
  1884. DRM_DEBUG("gpu busy, RCS change rejected\n");
  1885. return false; /* still busy with another command */
  1886. }
  1887. rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
  1888. (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM;
  1889. I915_WRITE16(MEMSWCTL, rgvswctl);
  1890. POSTING_READ16(MEMSWCTL);
  1891. rgvswctl |= MEMCTL_CMD_STS;
  1892. I915_WRITE16(MEMSWCTL, rgvswctl);
  1893. return true;
  1894. }
  1895. static void ironlake_enable_drps(struct drm_device *dev)
  1896. {
  1897. struct drm_i915_private *dev_priv = dev->dev_private;
  1898. u32 rgvmodectl = I915_READ(MEMMODECTL);
  1899. u8 fmax, fmin, fstart, vstart;
  1900. spin_lock_irq(&mchdev_lock);
  1901. /* Enable temp reporting */
  1902. I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN);
  1903. I915_WRITE16(TSC1, I915_READ(TSC1) | TSE);
  1904. /* 100ms RC evaluation intervals */
  1905. I915_WRITE(RCUPEI, 100000);
  1906. I915_WRITE(RCDNEI, 100000);
  1907. /* Set max/min thresholds to 90ms and 80ms respectively */
  1908. I915_WRITE(RCBMAXAVG, 90000);
  1909. I915_WRITE(RCBMINAVG, 80000);
  1910. I915_WRITE(MEMIHYST, 1);
  1911. /* Set up min, max, and cur for interrupt handling */
  1912. fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT;
  1913. fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
  1914. fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
  1915. MEMMODE_FSTART_SHIFT;
  1916. vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >>
  1917. PXVFREQ_PX_SHIFT;
  1918. dev_priv->ips.fmax = fmax; /* IPS callback will increase this */
  1919. dev_priv->ips.fstart = fstart;
  1920. dev_priv->ips.max_delay = fstart;
  1921. dev_priv->ips.min_delay = fmin;
  1922. dev_priv->ips.cur_delay = fstart;
  1923. DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
  1924. fmax, fmin, fstart);
  1925. I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
  1926. /*
  1927. * Interrupts will be enabled in ironlake_irq_postinstall
  1928. */
  1929. I915_WRITE(VIDSTART, vstart);
  1930. POSTING_READ(VIDSTART);
  1931. rgvmodectl |= MEMMODE_SWMODE_EN;
  1932. I915_WRITE(MEMMODECTL, rgvmodectl);
  1933. if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10))
  1934. DRM_ERROR("stuck trying to change perf mode\n");
  1935. mdelay(1);
  1936. ironlake_set_drps(dev, fstart);
  1937. dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) +
  1938. I915_READ(0x112e0);
  1939. dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies);
  1940. dev_priv->ips.last_count2 = I915_READ(0x112f4);
  1941. getrawmonotonic(&dev_priv->ips.last_time2);
  1942. spin_unlock_irq(&mchdev_lock);
  1943. }
  1944. static void ironlake_disable_drps(struct drm_device *dev)
  1945. {
  1946. struct drm_i915_private *dev_priv = dev->dev_private;
  1947. u16 rgvswctl;
  1948. spin_lock_irq(&mchdev_lock);
  1949. rgvswctl = I915_READ16(MEMSWCTL);
  1950. /* Ack interrupts, disable EFC interrupt */
  1951. I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN);
  1952. I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG);
  1953. I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT);
  1954. I915_WRITE(DEIIR, DE_PCU_EVENT);
  1955. I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT);
  1956. /* Go back to the starting frequency */
  1957. ironlake_set_drps(dev, dev_priv->ips.fstart);
  1958. mdelay(1);
  1959. rgvswctl |= MEMCTL_CMD_STS;
  1960. I915_WRITE(MEMSWCTL, rgvswctl);
  1961. mdelay(1);
  1962. spin_unlock_irq(&mchdev_lock);
  1963. }
  1964. /* There's a funny hw issue where the hw returns all 0 when reading from
  1965. * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value
  1966. * ourselves, instead of doing a rmw cycle (which might result in us clearing
  1967. * all limits and the gpu stuck at whatever frequency it is at atm).
  1968. */
  1969. static u32 gen6_rps_limits(struct drm_i915_private *dev_priv, u8 *val)
  1970. {
  1971. u32 limits;
  1972. limits = 0;
  1973. if (*val >= dev_priv->rps.max_delay)
  1974. *val = dev_priv->rps.max_delay;
  1975. limits |= dev_priv->rps.max_delay << 24;
  1976. /* Only set the down limit when we've reached the lowest level to avoid
  1977. * getting more interrupts, otherwise leave this clear. This prevents a
  1978. * race in the hw when coming out of rc6: There's a tiny window where
  1979. * the hw runs at the minimal clock before selecting the desired
  1980. * frequency, if the down threshold expires in that window we will not
  1981. * receive a down interrupt. */
  1982. if (*val <= dev_priv->rps.min_delay) {
  1983. *val = dev_priv->rps.min_delay;
  1984. limits |= dev_priv->rps.min_delay << 16;
  1985. }
  1986. return limits;
  1987. }
  1988. void gen6_set_rps(struct drm_device *dev, u8 val)
  1989. {
  1990. struct drm_i915_private *dev_priv = dev->dev_private;
  1991. u32 limits = gen6_rps_limits(dev_priv, &val);
  1992. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  1993. WARN_ON(val > dev_priv->rps.max_delay);
  1994. WARN_ON(val < dev_priv->rps.min_delay);
  1995. if (val == dev_priv->rps.cur_delay)
  1996. return;
  1997. I915_WRITE(GEN6_RPNSWREQ,
  1998. GEN6_FREQUENCY(val) |
  1999. GEN6_OFFSET(0) |
  2000. GEN6_AGGRESSIVE_TURBO);
  2001. /* Make sure we continue to get interrupts
  2002. * until we hit the minimum or maximum frequencies.
  2003. */
  2004. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, limits);
  2005. POSTING_READ(GEN6_RPNSWREQ);
  2006. dev_priv->rps.cur_delay = val;
  2007. trace_intel_gpu_freq_change(val * 50);
  2008. }
  2009. static void gen6_disable_rps(struct drm_device *dev)
  2010. {
  2011. struct drm_i915_private *dev_priv = dev->dev_private;
  2012. I915_WRITE(GEN6_RC_CONTROL, 0);
  2013. I915_WRITE(GEN6_RPNSWREQ, 1 << 31);
  2014. I915_WRITE(GEN6_PMINTRMSK, 0xffffffff);
  2015. I915_WRITE(GEN6_PMIER, 0);
  2016. /* Complete PM interrupt masking here doesn't race with the rps work
  2017. * item again unmasking PM interrupts because that is using a different
  2018. * register (PMIMR) to mask PM interrupts. The only risk is in leaving
  2019. * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */
  2020. spin_lock_irq(&dev_priv->rps.lock);
  2021. dev_priv->rps.pm_iir = 0;
  2022. spin_unlock_irq(&dev_priv->rps.lock);
  2023. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  2024. }
  2025. int intel_enable_rc6(const struct drm_device *dev)
  2026. {
  2027. /* Respect the kernel parameter if it is set */
  2028. if (i915_enable_rc6 >= 0)
  2029. return i915_enable_rc6;
  2030. if (INTEL_INFO(dev)->gen == 5) {
  2031. #ifdef CONFIG_INTEL_IOMMU
  2032. /* Disable rc6 on ilk if VT-d is on. */
  2033. if (intel_iommu_gfx_mapped)
  2034. return false;
  2035. #endif
  2036. DRM_DEBUG_DRIVER("Ironlake: only RC6 available\n");
  2037. return INTEL_RC6_ENABLE;
  2038. }
  2039. if (IS_HASWELL(dev)) {
  2040. DRM_DEBUG_DRIVER("Haswell: only RC6 available\n");
  2041. return INTEL_RC6_ENABLE;
  2042. }
  2043. /* snb/ivb have more than one rc6 state. */
  2044. if (INTEL_INFO(dev)->gen == 6) {
  2045. DRM_DEBUG_DRIVER("Sandybridge: deep RC6 disabled\n");
  2046. return INTEL_RC6_ENABLE;
  2047. }
  2048. DRM_DEBUG_DRIVER("RC6 and deep RC6 enabled\n");
  2049. return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE);
  2050. }
  2051. static void gen6_enable_rps(struct drm_device *dev)
  2052. {
  2053. struct drm_i915_private *dev_priv = dev->dev_private;
  2054. struct intel_ring_buffer *ring;
  2055. u32 rp_state_cap;
  2056. u32 gt_perf_status;
  2057. u32 pcu_mbox, rc6_mask = 0;
  2058. u32 gtfifodbg;
  2059. int rc6_mode;
  2060. int i;
  2061. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  2062. /* Here begins a magic sequence of register writes to enable
  2063. * auto-downclocking.
  2064. *
  2065. * Perhaps there might be some value in exposing these to
  2066. * userspace...
  2067. */
  2068. I915_WRITE(GEN6_RC_STATE, 0);
  2069. /* Clear the DBG now so we don't confuse earlier errors */
  2070. if ((gtfifodbg = I915_READ(GTFIFODBG))) {
  2071. DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg);
  2072. I915_WRITE(GTFIFODBG, gtfifodbg);
  2073. }
  2074. gen6_gt_force_wake_get(dev_priv);
  2075. rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  2076. gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
  2077. /* In units of 100MHz */
  2078. dev_priv->rps.max_delay = rp_state_cap & 0xff;
  2079. dev_priv->rps.min_delay = (rp_state_cap & 0xff0000) >> 16;
  2080. dev_priv->rps.cur_delay = 0;
  2081. /* disable the counters and set deterministic thresholds */
  2082. I915_WRITE(GEN6_RC_CONTROL, 0);
  2083. I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16);
  2084. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30);
  2085. I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30);
  2086. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000);
  2087. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25);
  2088. for_each_ring(ring, dev_priv, i)
  2089. I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10);
  2090. I915_WRITE(GEN6_RC_SLEEP, 0);
  2091. I915_WRITE(GEN6_RC1e_THRESHOLD, 1000);
  2092. I915_WRITE(GEN6_RC6_THRESHOLD, 50000);
  2093. I915_WRITE(GEN6_RC6p_THRESHOLD, 100000);
  2094. I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */
  2095. /* Check if we are enabling RC6 */
  2096. rc6_mode = intel_enable_rc6(dev_priv->dev);
  2097. if (rc6_mode & INTEL_RC6_ENABLE)
  2098. rc6_mask |= GEN6_RC_CTL_RC6_ENABLE;
  2099. /* We don't use those on Haswell */
  2100. if (!IS_HASWELL(dev)) {
  2101. if (rc6_mode & INTEL_RC6p_ENABLE)
  2102. rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE;
  2103. if (rc6_mode & INTEL_RC6pp_ENABLE)
  2104. rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE;
  2105. }
  2106. DRM_INFO("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n",
  2107. (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off",
  2108. (rc6_mask & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off",
  2109. (rc6_mask & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off");
  2110. I915_WRITE(GEN6_RC_CONTROL,
  2111. rc6_mask |
  2112. GEN6_RC_CTL_EI_MODE(1) |
  2113. GEN6_RC_CTL_HW_ENABLE);
  2114. I915_WRITE(GEN6_RPNSWREQ,
  2115. GEN6_FREQUENCY(10) |
  2116. GEN6_OFFSET(0) |
  2117. GEN6_AGGRESSIVE_TURBO);
  2118. I915_WRITE(GEN6_RC_VIDEO_FREQ,
  2119. GEN6_FREQUENCY(12));
  2120. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000);
  2121. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  2122. dev_priv->rps.max_delay << 24 |
  2123. dev_priv->rps.min_delay << 16);
  2124. I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400);
  2125. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000);
  2126. I915_WRITE(GEN6_RP_UP_EI, 66000);
  2127. I915_WRITE(GEN6_RP_DOWN_EI, 350000);
  2128. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  2129. I915_WRITE(GEN6_RP_CONTROL,
  2130. GEN6_RP_MEDIA_TURBO |
  2131. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  2132. GEN6_RP_MEDIA_IS_GFX |
  2133. GEN6_RP_ENABLE |
  2134. GEN6_RP_UP_BUSY_AVG |
  2135. (IS_HASWELL(dev) ? GEN7_RP_DOWN_IDLE_AVG : GEN6_RP_DOWN_IDLE_CONT));
  2136. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  2137. 500))
  2138. DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
  2139. I915_WRITE(GEN6_PCODE_DATA, 0);
  2140. I915_WRITE(GEN6_PCODE_MAILBOX,
  2141. GEN6_PCODE_READY |
  2142. GEN6_PCODE_WRITE_MIN_FREQ_TABLE);
  2143. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  2144. 500))
  2145. DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
  2146. /* Check for overclock support */
  2147. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  2148. 500))
  2149. DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
  2150. I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_READ_OC_PARAMS);
  2151. pcu_mbox = I915_READ(GEN6_PCODE_DATA);
  2152. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  2153. 500))
  2154. DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
  2155. if (pcu_mbox & (1<<31)) { /* OC supported */
  2156. dev_priv->rps.max_delay = pcu_mbox & 0xff;
  2157. DRM_DEBUG_DRIVER("overclocking supported, adjusting frequency max to %dMHz\n", pcu_mbox * 50);
  2158. }
  2159. gen6_set_rps(dev_priv->dev, (gt_perf_status & 0xff00) >> 8);
  2160. /* requires MSI enabled */
  2161. I915_WRITE(GEN6_PMIER, GEN6_PM_DEFERRED_EVENTS);
  2162. spin_lock_irq(&dev_priv->rps.lock);
  2163. WARN_ON(dev_priv->rps.pm_iir != 0);
  2164. I915_WRITE(GEN6_PMIMR, 0);
  2165. spin_unlock_irq(&dev_priv->rps.lock);
  2166. /* enable all PM interrupts */
  2167. I915_WRITE(GEN6_PMINTRMSK, 0);
  2168. gen6_gt_force_wake_put(dev_priv);
  2169. }
  2170. static void gen6_update_ring_freq(struct drm_device *dev)
  2171. {
  2172. struct drm_i915_private *dev_priv = dev->dev_private;
  2173. int min_freq = 15;
  2174. int gpu_freq, ia_freq, max_ia_freq;
  2175. int scaling_factor = 180;
  2176. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  2177. max_ia_freq = cpufreq_quick_get_max(0);
  2178. /*
  2179. * Default to measured freq if none found, PCU will ensure we don't go
  2180. * over
  2181. */
  2182. if (!max_ia_freq)
  2183. max_ia_freq = tsc_khz;
  2184. /* Convert from kHz to MHz */
  2185. max_ia_freq /= 1000;
  2186. /*
  2187. * For each potential GPU frequency, load a ring frequency we'd like
  2188. * to use for memory access. We do this by specifying the IA frequency
  2189. * the PCU should use as a reference to determine the ring frequency.
  2190. */
  2191. for (gpu_freq = dev_priv->rps.max_delay; gpu_freq >= dev_priv->rps.min_delay;
  2192. gpu_freq--) {
  2193. int diff = dev_priv->rps.max_delay - gpu_freq;
  2194. /*
  2195. * For GPU frequencies less than 750MHz, just use the lowest
  2196. * ring freq.
  2197. */
  2198. if (gpu_freq < min_freq)
  2199. ia_freq = 800;
  2200. else
  2201. ia_freq = max_ia_freq - ((diff * scaling_factor) / 2);
  2202. ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100);
  2203. I915_WRITE(GEN6_PCODE_DATA,
  2204. (ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT) |
  2205. gpu_freq);
  2206. I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY |
  2207. GEN6_PCODE_WRITE_MIN_FREQ_TABLE);
  2208. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) &
  2209. GEN6_PCODE_READY) == 0, 10)) {
  2210. DRM_ERROR("pcode write of freq table timed out\n");
  2211. continue;
  2212. }
  2213. }
  2214. }
  2215. void ironlake_teardown_rc6(struct drm_device *dev)
  2216. {
  2217. struct drm_i915_private *dev_priv = dev->dev_private;
  2218. if (dev_priv->renderctx) {
  2219. i915_gem_object_unpin(dev_priv->renderctx);
  2220. drm_gem_object_unreference(&dev_priv->renderctx->base);
  2221. dev_priv->renderctx = NULL;
  2222. }
  2223. if (dev_priv->pwrctx) {
  2224. i915_gem_object_unpin(dev_priv->pwrctx);
  2225. drm_gem_object_unreference(&dev_priv->pwrctx->base);
  2226. dev_priv->pwrctx = NULL;
  2227. }
  2228. }
  2229. static void ironlake_disable_rc6(struct drm_device *dev)
  2230. {
  2231. struct drm_i915_private *dev_priv = dev->dev_private;
  2232. if (I915_READ(PWRCTXA)) {
  2233. /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */
  2234. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT);
  2235. wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON),
  2236. 50);
  2237. I915_WRITE(PWRCTXA, 0);
  2238. POSTING_READ(PWRCTXA);
  2239. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  2240. POSTING_READ(RSTDBYCTL);
  2241. }
  2242. }
  2243. static int ironlake_setup_rc6(struct drm_device *dev)
  2244. {
  2245. struct drm_i915_private *dev_priv = dev->dev_private;
  2246. if (dev_priv->renderctx == NULL)
  2247. dev_priv->renderctx = intel_alloc_context_page(dev);
  2248. if (!dev_priv->renderctx)
  2249. return -ENOMEM;
  2250. if (dev_priv->pwrctx == NULL)
  2251. dev_priv->pwrctx = intel_alloc_context_page(dev);
  2252. if (!dev_priv->pwrctx) {
  2253. ironlake_teardown_rc6(dev);
  2254. return -ENOMEM;
  2255. }
  2256. return 0;
  2257. }
  2258. static void ironlake_enable_rc6(struct drm_device *dev)
  2259. {
  2260. struct drm_i915_private *dev_priv = dev->dev_private;
  2261. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  2262. int ret;
  2263. /* rc6 disabled by default due to repeated reports of hanging during
  2264. * boot and resume.
  2265. */
  2266. if (!intel_enable_rc6(dev))
  2267. return;
  2268. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  2269. ret = ironlake_setup_rc6(dev);
  2270. if (ret)
  2271. return;
  2272. /*
  2273. * GPU can automatically power down the render unit if given a page
  2274. * to save state.
  2275. */
  2276. ret = intel_ring_begin(ring, 6);
  2277. if (ret) {
  2278. ironlake_teardown_rc6(dev);
  2279. return;
  2280. }
  2281. intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN);
  2282. intel_ring_emit(ring, MI_SET_CONTEXT);
  2283. intel_ring_emit(ring, dev_priv->renderctx->gtt_offset |
  2284. MI_MM_SPACE_GTT |
  2285. MI_SAVE_EXT_STATE_EN |
  2286. MI_RESTORE_EXT_STATE_EN |
  2287. MI_RESTORE_INHIBIT);
  2288. intel_ring_emit(ring, MI_SUSPEND_FLUSH);
  2289. intel_ring_emit(ring, MI_NOOP);
  2290. intel_ring_emit(ring, MI_FLUSH);
  2291. intel_ring_advance(ring);
  2292. /*
  2293. * Wait for the command parser to advance past MI_SET_CONTEXT. The HW
  2294. * does an implicit flush, combined with MI_FLUSH above, it should be
  2295. * safe to assume that renderctx is valid
  2296. */
  2297. ret = intel_wait_ring_idle(ring);
  2298. if (ret) {
  2299. DRM_ERROR("failed to enable ironlake power power savings\n");
  2300. ironlake_teardown_rc6(dev);
  2301. return;
  2302. }
  2303. I915_WRITE(PWRCTXA, dev_priv->pwrctx->gtt_offset | PWRCTX_EN);
  2304. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  2305. }
  2306. static unsigned long intel_pxfreq(u32 vidfreq)
  2307. {
  2308. unsigned long freq;
  2309. int div = (vidfreq & 0x3f0000) >> 16;
  2310. int post = (vidfreq & 0x3000) >> 12;
  2311. int pre = (vidfreq & 0x7);
  2312. if (!pre)
  2313. return 0;
  2314. freq = ((div * 133333) / ((1<<post) * pre));
  2315. return freq;
  2316. }
  2317. static const struct cparams {
  2318. u16 i;
  2319. u16 t;
  2320. u16 m;
  2321. u16 c;
  2322. } cparams[] = {
  2323. { 1, 1333, 301, 28664 },
  2324. { 1, 1066, 294, 24460 },
  2325. { 1, 800, 294, 25192 },
  2326. { 0, 1333, 276, 27605 },
  2327. { 0, 1066, 276, 27605 },
  2328. { 0, 800, 231, 23784 },
  2329. };
  2330. unsigned long i915_chipset_val(struct drm_i915_private *dev_priv)
  2331. {
  2332. u64 total_count, diff, ret;
  2333. u32 count1, count2, count3, m = 0, c = 0;
  2334. unsigned long now = jiffies_to_msecs(jiffies), diff1;
  2335. int i;
  2336. assert_spin_locked(&mchdev_lock);
  2337. diff1 = now - dev_priv->ips.last_time1;
  2338. /* Prevent division-by-zero if we are asking too fast.
  2339. * Also, we don't get interesting results if we are polling
  2340. * faster than once in 10ms, so just return the saved value
  2341. * in such cases.
  2342. */
  2343. if (diff1 <= 10)
  2344. return dev_priv->ips.chipset_power;
  2345. count1 = I915_READ(DMIEC);
  2346. count2 = I915_READ(DDREC);
  2347. count3 = I915_READ(CSIEC);
  2348. total_count = count1 + count2 + count3;
  2349. /* FIXME: handle per-counter overflow */
  2350. if (total_count < dev_priv->ips.last_count1) {
  2351. diff = ~0UL - dev_priv->ips.last_count1;
  2352. diff += total_count;
  2353. } else {
  2354. diff = total_count - dev_priv->ips.last_count1;
  2355. }
  2356. for (i = 0; i < ARRAY_SIZE(cparams); i++) {
  2357. if (cparams[i].i == dev_priv->ips.c_m &&
  2358. cparams[i].t == dev_priv->ips.r_t) {
  2359. m = cparams[i].m;
  2360. c = cparams[i].c;
  2361. break;
  2362. }
  2363. }
  2364. diff = div_u64(diff, diff1);
  2365. ret = ((m * diff) + c);
  2366. ret = div_u64(ret, 10);
  2367. dev_priv->ips.last_count1 = total_count;
  2368. dev_priv->ips.last_time1 = now;
  2369. dev_priv->ips.chipset_power = ret;
  2370. return ret;
  2371. }
  2372. unsigned long i915_mch_val(struct drm_i915_private *dev_priv)
  2373. {
  2374. unsigned long m, x, b;
  2375. u32 tsfs;
  2376. tsfs = I915_READ(TSFS);
  2377. m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT);
  2378. x = I915_READ8(TR1);
  2379. b = tsfs & TSFS_INTR_MASK;
  2380. return ((m * x) / 127) - b;
  2381. }
  2382. static u16 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid)
  2383. {
  2384. static const struct v_table {
  2385. u16 vd; /* in .1 mil */
  2386. u16 vm; /* in .1 mil */
  2387. } v_table[] = {
  2388. { 0, 0, },
  2389. { 375, 0, },
  2390. { 500, 0, },
  2391. { 625, 0, },
  2392. { 750, 0, },
  2393. { 875, 0, },
  2394. { 1000, 0, },
  2395. { 1125, 0, },
  2396. { 4125, 3000, },
  2397. { 4125, 3000, },
  2398. { 4125, 3000, },
  2399. { 4125, 3000, },
  2400. { 4125, 3000, },
  2401. { 4125, 3000, },
  2402. { 4125, 3000, },
  2403. { 4125, 3000, },
  2404. { 4125, 3000, },
  2405. { 4125, 3000, },
  2406. { 4125, 3000, },
  2407. { 4125, 3000, },
  2408. { 4125, 3000, },
  2409. { 4125, 3000, },
  2410. { 4125, 3000, },
  2411. { 4125, 3000, },
  2412. { 4125, 3000, },
  2413. { 4125, 3000, },
  2414. { 4125, 3000, },
  2415. { 4125, 3000, },
  2416. { 4125, 3000, },
  2417. { 4125, 3000, },
  2418. { 4125, 3000, },
  2419. { 4125, 3000, },
  2420. { 4250, 3125, },
  2421. { 4375, 3250, },
  2422. { 4500, 3375, },
  2423. { 4625, 3500, },
  2424. { 4750, 3625, },
  2425. { 4875, 3750, },
  2426. { 5000, 3875, },
  2427. { 5125, 4000, },
  2428. { 5250, 4125, },
  2429. { 5375, 4250, },
  2430. { 5500, 4375, },
  2431. { 5625, 4500, },
  2432. { 5750, 4625, },
  2433. { 5875, 4750, },
  2434. { 6000, 4875, },
  2435. { 6125, 5000, },
  2436. { 6250, 5125, },
  2437. { 6375, 5250, },
  2438. { 6500, 5375, },
  2439. { 6625, 5500, },
  2440. { 6750, 5625, },
  2441. { 6875, 5750, },
  2442. { 7000, 5875, },
  2443. { 7125, 6000, },
  2444. { 7250, 6125, },
  2445. { 7375, 6250, },
  2446. { 7500, 6375, },
  2447. { 7625, 6500, },
  2448. { 7750, 6625, },
  2449. { 7875, 6750, },
  2450. { 8000, 6875, },
  2451. { 8125, 7000, },
  2452. { 8250, 7125, },
  2453. { 8375, 7250, },
  2454. { 8500, 7375, },
  2455. { 8625, 7500, },
  2456. { 8750, 7625, },
  2457. { 8875, 7750, },
  2458. { 9000, 7875, },
  2459. { 9125, 8000, },
  2460. { 9250, 8125, },
  2461. { 9375, 8250, },
  2462. { 9500, 8375, },
  2463. { 9625, 8500, },
  2464. { 9750, 8625, },
  2465. { 9875, 8750, },
  2466. { 10000, 8875, },
  2467. { 10125, 9000, },
  2468. { 10250, 9125, },
  2469. { 10375, 9250, },
  2470. { 10500, 9375, },
  2471. { 10625, 9500, },
  2472. { 10750, 9625, },
  2473. { 10875, 9750, },
  2474. { 11000, 9875, },
  2475. { 11125, 10000, },
  2476. { 11250, 10125, },
  2477. { 11375, 10250, },
  2478. { 11500, 10375, },
  2479. { 11625, 10500, },
  2480. { 11750, 10625, },
  2481. { 11875, 10750, },
  2482. { 12000, 10875, },
  2483. { 12125, 11000, },
  2484. { 12250, 11125, },
  2485. { 12375, 11250, },
  2486. { 12500, 11375, },
  2487. { 12625, 11500, },
  2488. { 12750, 11625, },
  2489. { 12875, 11750, },
  2490. { 13000, 11875, },
  2491. { 13125, 12000, },
  2492. { 13250, 12125, },
  2493. { 13375, 12250, },
  2494. { 13500, 12375, },
  2495. { 13625, 12500, },
  2496. { 13750, 12625, },
  2497. { 13875, 12750, },
  2498. { 14000, 12875, },
  2499. { 14125, 13000, },
  2500. { 14250, 13125, },
  2501. { 14375, 13250, },
  2502. { 14500, 13375, },
  2503. { 14625, 13500, },
  2504. { 14750, 13625, },
  2505. { 14875, 13750, },
  2506. { 15000, 13875, },
  2507. { 15125, 14000, },
  2508. { 15250, 14125, },
  2509. { 15375, 14250, },
  2510. { 15500, 14375, },
  2511. { 15625, 14500, },
  2512. { 15750, 14625, },
  2513. { 15875, 14750, },
  2514. { 16000, 14875, },
  2515. { 16125, 15000, },
  2516. };
  2517. if (dev_priv->info->is_mobile)
  2518. return v_table[pxvid].vm;
  2519. else
  2520. return v_table[pxvid].vd;
  2521. }
  2522. static void __i915_update_gfx_val(struct drm_i915_private *dev_priv)
  2523. {
  2524. struct timespec now, diff1;
  2525. u64 diff;
  2526. unsigned long diffms;
  2527. u32 count;
  2528. assert_spin_locked(&mchdev_lock);
  2529. getrawmonotonic(&now);
  2530. diff1 = timespec_sub(now, dev_priv->ips.last_time2);
  2531. /* Don't divide by 0 */
  2532. diffms = diff1.tv_sec * 1000 + diff1.tv_nsec / 1000000;
  2533. if (!diffms)
  2534. return;
  2535. count = I915_READ(GFXEC);
  2536. if (count < dev_priv->ips.last_count2) {
  2537. diff = ~0UL - dev_priv->ips.last_count2;
  2538. diff += count;
  2539. } else {
  2540. diff = count - dev_priv->ips.last_count2;
  2541. }
  2542. dev_priv->ips.last_count2 = count;
  2543. dev_priv->ips.last_time2 = now;
  2544. /* More magic constants... */
  2545. diff = diff * 1181;
  2546. diff = div_u64(diff, diffms * 10);
  2547. dev_priv->ips.gfx_power = diff;
  2548. }
  2549. void i915_update_gfx_val(struct drm_i915_private *dev_priv)
  2550. {
  2551. if (dev_priv->info->gen != 5)
  2552. return;
  2553. spin_lock_irq(&mchdev_lock);
  2554. __i915_update_gfx_val(dev_priv);
  2555. spin_unlock_irq(&mchdev_lock);
  2556. }
  2557. unsigned long i915_gfx_val(struct drm_i915_private *dev_priv)
  2558. {
  2559. unsigned long t, corr, state1, corr2, state2;
  2560. u32 pxvid, ext_v;
  2561. assert_spin_locked(&mchdev_lock);
  2562. pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_delay * 4));
  2563. pxvid = (pxvid >> 24) & 0x7f;
  2564. ext_v = pvid_to_extvid(dev_priv, pxvid);
  2565. state1 = ext_v;
  2566. t = i915_mch_val(dev_priv);
  2567. /* Revel in the empirically derived constants */
  2568. /* Correction factor in 1/100000 units */
  2569. if (t > 80)
  2570. corr = ((t * 2349) + 135940);
  2571. else if (t >= 50)
  2572. corr = ((t * 964) + 29317);
  2573. else /* < 50 */
  2574. corr = ((t * 301) + 1004);
  2575. corr = corr * ((150142 * state1) / 10000 - 78642);
  2576. corr /= 100000;
  2577. corr2 = (corr * dev_priv->ips.corr);
  2578. state2 = (corr2 * state1) / 10000;
  2579. state2 /= 100; /* convert to mW */
  2580. __i915_update_gfx_val(dev_priv);
  2581. return dev_priv->ips.gfx_power + state2;
  2582. }
  2583. /**
  2584. * i915_read_mch_val - return value for IPS use
  2585. *
  2586. * Calculate and return a value for the IPS driver to use when deciding whether
  2587. * we have thermal and power headroom to increase CPU or GPU power budget.
  2588. */
  2589. unsigned long i915_read_mch_val(void)
  2590. {
  2591. struct drm_i915_private *dev_priv;
  2592. unsigned long chipset_val, graphics_val, ret = 0;
  2593. spin_lock_irq(&mchdev_lock);
  2594. if (!i915_mch_dev)
  2595. goto out_unlock;
  2596. dev_priv = i915_mch_dev;
  2597. chipset_val = i915_chipset_val(dev_priv);
  2598. graphics_val = i915_gfx_val(dev_priv);
  2599. ret = chipset_val + graphics_val;
  2600. out_unlock:
  2601. spin_unlock_irq(&mchdev_lock);
  2602. return ret;
  2603. }
  2604. EXPORT_SYMBOL_GPL(i915_read_mch_val);
  2605. /**
  2606. * i915_gpu_raise - raise GPU frequency limit
  2607. *
  2608. * Raise the limit; IPS indicates we have thermal headroom.
  2609. */
  2610. bool i915_gpu_raise(void)
  2611. {
  2612. struct drm_i915_private *dev_priv;
  2613. bool ret = true;
  2614. spin_lock_irq(&mchdev_lock);
  2615. if (!i915_mch_dev) {
  2616. ret = false;
  2617. goto out_unlock;
  2618. }
  2619. dev_priv = i915_mch_dev;
  2620. if (dev_priv->ips.max_delay > dev_priv->ips.fmax)
  2621. dev_priv->ips.max_delay--;
  2622. out_unlock:
  2623. spin_unlock_irq(&mchdev_lock);
  2624. return ret;
  2625. }
  2626. EXPORT_SYMBOL_GPL(i915_gpu_raise);
  2627. /**
  2628. * i915_gpu_lower - lower GPU frequency limit
  2629. *
  2630. * IPS indicates we're close to a thermal limit, so throttle back the GPU
  2631. * frequency maximum.
  2632. */
  2633. bool i915_gpu_lower(void)
  2634. {
  2635. struct drm_i915_private *dev_priv;
  2636. bool ret = true;
  2637. spin_lock_irq(&mchdev_lock);
  2638. if (!i915_mch_dev) {
  2639. ret = false;
  2640. goto out_unlock;
  2641. }
  2642. dev_priv = i915_mch_dev;
  2643. if (dev_priv->ips.max_delay < dev_priv->ips.min_delay)
  2644. dev_priv->ips.max_delay++;
  2645. out_unlock:
  2646. spin_unlock_irq(&mchdev_lock);
  2647. return ret;
  2648. }
  2649. EXPORT_SYMBOL_GPL(i915_gpu_lower);
  2650. /**
  2651. * i915_gpu_busy - indicate GPU business to IPS
  2652. *
  2653. * Tell the IPS driver whether or not the GPU is busy.
  2654. */
  2655. bool i915_gpu_busy(void)
  2656. {
  2657. struct drm_i915_private *dev_priv;
  2658. struct intel_ring_buffer *ring;
  2659. bool ret = false;
  2660. int i;
  2661. spin_lock_irq(&mchdev_lock);
  2662. if (!i915_mch_dev)
  2663. goto out_unlock;
  2664. dev_priv = i915_mch_dev;
  2665. for_each_ring(ring, dev_priv, i)
  2666. ret |= !list_empty(&ring->request_list);
  2667. out_unlock:
  2668. spin_unlock_irq(&mchdev_lock);
  2669. return ret;
  2670. }
  2671. EXPORT_SYMBOL_GPL(i915_gpu_busy);
  2672. /**
  2673. * i915_gpu_turbo_disable - disable graphics turbo
  2674. *
  2675. * Disable graphics turbo by resetting the max frequency and setting the
  2676. * current frequency to the default.
  2677. */
  2678. bool i915_gpu_turbo_disable(void)
  2679. {
  2680. struct drm_i915_private *dev_priv;
  2681. bool ret = true;
  2682. spin_lock_irq(&mchdev_lock);
  2683. if (!i915_mch_dev) {
  2684. ret = false;
  2685. goto out_unlock;
  2686. }
  2687. dev_priv = i915_mch_dev;
  2688. dev_priv->ips.max_delay = dev_priv->ips.fstart;
  2689. if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart))
  2690. ret = false;
  2691. out_unlock:
  2692. spin_unlock_irq(&mchdev_lock);
  2693. return ret;
  2694. }
  2695. EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable);
  2696. /**
  2697. * Tells the intel_ips driver that the i915 driver is now loaded, if
  2698. * IPS got loaded first.
  2699. *
  2700. * This awkward dance is so that neither module has to depend on the
  2701. * other in order for IPS to do the appropriate communication of
  2702. * GPU turbo limits to i915.
  2703. */
  2704. static void
  2705. ips_ping_for_i915_load(void)
  2706. {
  2707. void (*link)(void);
  2708. link = symbol_get(ips_link_to_i915_driver);
  2709. if (link) {
  2710. link();
  2711. symbol_put(ips_link_to_i915_driver);
  2712. }
  2713. }
  2714. void intel_gpu_ips_init(struct drm_i915_private *dev_priv)
  2715. {
  2716. /* We only register the i915 ips part with intel-ips once everything is
  2717. * set up, to avoid intel-ips sneaking in and reading bogus values. */
  2718. spin_lock_irq(&mchdev_lock);
  2719. i915_mch_dev = dev_priv;
  2720. spin_unlock_irq(&mchdev_lock);
  2721. ips_ping_for_i915_load();
  2722. }
  2723. void intel_gpu_ips_teardown(void)
  2724. {
  2725. spin_lock_irq(&mchdev_lock);
  2726. i915_mch_dev = NULL;
  2727. spin_unlock_irq(&mchdev_lock);
  2728. }
  2729. static void intel_init_emon(struct drm_device *dev)
  2730. {
  2731. struct drm_i915_private *dev_priv = dev->dev_private;
  2732. u32 lcfuse;
  2733. u8 pxw[16];
  2734. int i;
  2735. /* Disable to program */
  2736. I915_WRITE(ECR, 0);
  2737. POSTING_READ(ECR);
  2738. /* Program energy weights for various events */
  2739. I915_WRITE(SDEW, 0x15040d00);
  2740. I915_WRITE(CSIEW0, 0x007f0000);
  2741. I915_WRITE(CSIEW1, 0x1e220004);
  2742. I915_WRITE(CSIEW2, 0x04000004);
  2743. for (i = 0; i < 5; i++)
  2744. I915_WRITE(PEW + (i * 4), 0);
  2745. for (i = 0; i < 3; i++)
  2746. I915_WRITE(DEW + (i * 4), 0);
  2747. /* Program P-state weights to account for frequency power adjustment */
  2748. for (i = 0; i < 16; i++) {
  2749. u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4));
  2750. unsigned long freq = intel_pxfreq(pxvidfreq);
  2751. unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >>
  2752. PXVFREQ_PX_SHIFT;
  2753. unsigned long val;
  2754. val = vid * vid;
  2755. val *= (freq / 1000);
  2756. val *= 255;
  2757. val /= (127*127*900);
  2758. if (val > 0xff)
  2759. DRM_ERROR("bad pxval: %ld\n", val);
  2760. pxw[i] = val;
  2761. }
  2762. /* Render standby states get 0 weight */
  2763. pxw[14] = 0;
  2764. pxw[15] = 0;
  2765. for (i = 0; i < 4; i++) {
  2766. u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) |
  2767. (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]);
  2768. I915_WRITE(PXW + (i * 4), val);
  2769. }
  2770. /* Adjust magic regs to magic values (more experimental results) */
  2771. I915_WRITE(OGW0, 0);
  2772. I915_WRITE(OGW1, 0);
  2773. I915_WRITE(EG0, 0x00007f00);
  2774. I915_WRITE(EG1, 0x0000000e);
  2775. I915_WRITE(EG2, 0x000e0000);
  2776. I915_WRITE(EG3, 0x68000300);
  2777. I915_WRITE(EG4, 0x42000000);
  2778. I915_WRITE(EG5, 0x00140031);
  2779. I915_WRITE(EG6, 0);
  2780. I915_WRITE(EG7, 0);
  2781. for (i = 0; i < 8; i++)
  2782. I915_WRITE(PXWL + (i * 4), 0);
  2783. /* Enable PMON + select events */
  2784. I915_WRITE(ECR, 0x80000019);
  2785. lcfuse = I915_READ(LCFUSE02);
  2786. dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK);
  2787. }
  2788. void intel_disable_gt_powersave(struct drm_device *dev)
  2789. {
  2790. if (IS_IRONLAKE_M(dev)) {
  2791. ironlake_disable_drps(dev);
  2792. ironlake_disable_rc6(dev);
  2793. } else if (INTEL_INFO(dev)->gen >= 6 && !IS_VALLEYVIEW(dev)) {
  2794. gen6_disable_rps(dev);
  2795. }
  2796. }
  2797. void intel_enable_gt_powersave(struct drm_device *dev)
  2798. {
  2799. if (IS_IRONLAKE_M(dev)) {
  2800. ironlake_enable_drps(dev);
  2801. ironlake_enable_rc6(dev);
  2802. intel_init_emon(dev);
  2803. } else if ((IS_GEN6(dev) || IS_GEN7(dev)) && !IS_VALLEYVIEW(dev)) {
  2804. gen6_enable_rps(dev);
  2805. gen6_update_ring_freq(dev);
  2806. }
  2807. }
  2808. static void ironlake_init_clock_gating(struct drm_device *dev)
  2809. {
  2810. struct drm_i915_private *dev_priv = dev->dev_private;
  2811. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  2812. /* Required for FBC */
  2813. dspclk_gate |= DPFCUNIT_CLOCK_GATE_DISABLE |
  2814. DPFCRUNIT_CLOCK_GATE_DISABLE |
  2815. DPFDUNIT_CLOCK_GATE_DISABLE;
  2816. /* Required for CxSR */
  2817. dspclk_gate |= DPARBUNIT_CLOCK_GATE_DISABLE;
  2818. I915_WRITE(PCH_3DCGDIS0,
  2819. MARIUNIT_CLOCK_GATE_DISABLE |
  2820. SVSMUNIT_CLOCK_GATE_DISABLE);
  2821. I915_WRITE(PCH_3DCGDIS1,
  2822. VFMUNIT_CLOCK_GATE_DISABLE);
  2823. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  2824. /*
  2825. * According to the spec the following bits should be set in
  2826. * order to enable memory self-refresh
  2827. * The bit 22/21 of 0x42004
  2828. * The bit 5 of 0x42020
  2829. * The bit 15 of 0x45000
  2830. */
  2831. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  2832. (I915_READ(ILK_DISPLAY_CHICKEN2) |
  2833. ILK_DPARB_GATE | ILK_VSDPFD_FULL));
  2834. I915_WRITE(ILK_DSPCLK_GATE,
  2835. (I915_READ(ILK_DSPCLK_GATE) |
  2836. ILK_DPARB_CLK_GATE));
  2837. I915_WRITE(DISP_ARB_CTL,
  2838. (I915_READ(DISP_ARB_CTL) |
  2839. DISP_FBC_WM_DIS));
  2840. I915_WRITE(WM3_LP_ILK, 0);
  2841. I915_WRITE(WM2_LP_ILK, 0);
  2842. I915_WRITE(WM1_LP_ILK, 0);
  2843. /*
  2844. * Based on the document from hardware guys the following bits
  2845. * should be set unconditionally in order to enable FBC.
  2846. * The bit 22 of 0x42000
  2847. * The bit 22 of 0x42004
  2848. * The bit 7,8,9 of 0x42020.
  2849. */
  2850. if (IS_IRONLAKE_M(dev)) {
  2851. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  2852. I915_READ(ILK_DISPLAY_CHICKEN1) |
  2853. ILK_FBCQ_DIS);
  2854. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  2855. I915_READ(ILK_DISPLAY_CHICKEN2) |
  2856. ILK_DPARB_GATE);
  2857. I915_WRITE(ILK_DSPCLK_GATE,
  2858. I915_READ(ILK_DSPCLK_GATE) |
  2859. ILK_DPFC_DIS1 |
  2860. ILK_DPFC_DIS2 |
  2861. ILK_CLK_FBC);
  2862. }
  2863. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  2864. I915_READ(ILK_DISPLAY_CHICKEN2) |
  2865. ILK_ELPIN_409_SELECT);
  2866. I915_WRITE(_3D_CHICKEN2,
  2867. _3D_CHICKEN2_WM_READ_PIPELINED << 16 |
  2868. _3D_CHICKEN2_WM_READ_PIPELINED);
  2869. }
  2870. static void gen6_init_clock_gating(struct drm_device *dev)
  2871. {
  2872. struct drm_i915_private *dev_priv = dev->dev_private;
  2873. int pipe;
  2874. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  2875. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  2876. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  2877. I915_READ(ILK_DISPLAY_CHICKEN2) |
  2878. ILK_ELPIN_409_SELECT);
  2879. I915_WRITE(WM3_LP_ILK, 0);
  2880. I915_WRITE(WM2_LP_ILK, 0);
  2881. I915_WRITE(WM1_LP_ILK, 0);
  2882. I915_WRITE(CACHE_MODE_0,
  2883. _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB));
  2884. I915_WRITE(GEN6_UCGCTL1,
  2885. I915_READ(GEN6_UCGCTL1) |
  2886. GEN6_BLBUNIT_CLOCK_GATE_DISABLE |
  2887. GEN6_CSUNIT_CLOCK_GATE_DISABLE);
  2888. /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
  2889. * gating disable must be set. Failure to set it results in
  2890. * flickering pixels due to Z write ordering failures after
  2891. * some amount of runtime in the Mesa "fire" demo, and Unigine
  2892. * Sanctuary and Tropics, and apparently anything else with
  2893. * alpha test or pixel discard.
  2894. *
  2895. * According to the spec, bit 11 (RCCUNIT) must also be set,
  2896. * but we didn't debug actual testcases to find it out.
  2897. *
  2898. * Also apply WaDisableVDSUnitClockGating and
  2899. * WaDisableRCPBUnitClockGating.
  2900. */
  2901. I915_WRITE(GEN6_UCGCTL2,
  2902. GEN7_VDSUNIT_CLOCK_GATE_DISABLE |
  2903. GEN6_RCPBUNIT_CLOCK_GATE_DISABLE |
  2904. GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
  2905. /* Bspec says we need to always set all mask bits. */
  2906. I915_WRITE(_3D_CHICKEN, (0xFFFF << 16) |
  2907. _3D_CHICKEN_SF_DISABLE_FASTCLIP_CULL);
  2908. /*
  2909. * According to the spec the following bits should be
  2910. * set in order to enable memory self-refresh and fbc:
  2911. * The bit21 and bit22 of 0x42000
  2912. * The bit21 and bit22 of 0x42004
  2913. * The bit5 and bit7 of 0x42020
  2914. * The bit14 of 0x70180
  2915. * The bit14 of 0x71180
  2916. */
  2917. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  2918. I915_READ(ILK_DISPLAY_CHICKEN1) |
  2919. ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
  2920. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  2921. I915_READ(ILK_DISPLAY_CHICKEN2) |
  2922. ILK_DPARB_GATE | ILK_VSDPFD_FULL);
  2923. I915_WRITE(ILK_DSPCLK_GATE,
  2924. I915_READ(ILK_DSPCLK_GATE) |
  2925. ILK_DPARB_CLK_GATE |
  2926. ILK_DPFD_CLK_GATE);
  2927. I915_WRITE(GEN6_MBCTL, I915_READ(GEN6_MBCTL) |
  2928. GEN6_MBCTL_ENABLE_BOOT_FETCH);
  2929. for_each_pipe(pipe) {
  2930. I915_WRITE(DSPCNTR(pipe),
  2931. I915_READ(DSPCNTR(pipe)) |
  2932. DISPPLANE_TRICKLE_FEED_DISABLE);
  2933. intel_flush_display_plane(dev_priv, pipe);
  2934. }
  2935. }
  2936. static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv)
  2937. {
  2938. uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE);
  2939. reg &= ~GEN7_FF_SCHED_MASK;
  2940. reg |= GEN7_FF_TS_SCHED_HW;
  2941. reg |= GEN7_FF_VS_SCHED_HW;
  2942. reg |= GEN7_FF_DS_SCHED_HW;
  2943. I915_WRITE(GEN7_FF_THREAD_MODE, reg);
  2944. }
  2945. static void haswell_init_clock_gating(struct drm_device *dev)
  2946. {
  2947. struct drm_i915_private *dev_priv = dev->dev_private;
  2948. int pipe;
  2949. I915_WRITE(WM3_LP_ILK, 0);
  2950. I915_WRITE(WM2_LP_ILK, 0);
  2951. I915_WRITE(WM1_LP_ILK, 0);
  2952. /* According to the spec, bit 13 (RCZUNIT) must be set on IVB.
  2953. * This implements the WaDisableRCZUnitClockGating workaround.
  2954. */
  2955. I915_WRITE(GEN6_UCGCTL2, GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
  2956. /* Apply the WaDisableRHWOOptimizationForRenderHang workaround. */
  2957. I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1,
  2958. GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC);
  2959. /* WaApplyL3ControlAndL3ChickenMode requires those two on Ivy Bridge */
  2960. I915_WRITE(GEN7_L3CNTLREG1,
  2961. GEN7_WA_FOR_GEN7_L3_CONTROL);
  2962. I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER,
  2963. GEN7_WA_L3_CHICKEN_MODE);
  2964. /* This is required by WaCatErrorRejectionIssue */
  2965. I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  2966. I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
  2967. GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  2968. for_each_pipe(pipe) {
  2969. I915_WRITE(DSPCNTR(pipe),
  2970. I915_READ(DSPCNTR(pipe)) |
  2971. DISPPLANE_TRICKLE_FEED_DISABLE);
  2972. intel_flush_display_plane(dev_priv, pipe);
  2973. }
  2974. gen7_setup_fixed_func_scheduler(dev_priv);
  2975. /* WaDisable4x2SubspanOptimization */
  2976. I915_WRITE(CACHE_MODE_1,
  2977. _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
  2978. /* XXX: This is a workaround for early silicon revisions and should be
  2979. * removed later.
  2980. */
  2981. I915_WRITE(WM_DBG,
  2982. I915_READ(WM_DBG) |
  2983. WM_DBG_DISALLOW_MULTIPLE_LP |
  2984. WM_DBG_DISALLOW_SPRITE |
  2985. WM_DBG_DISALLOW_MAXFIFO);
  2986. }
  2987. static void ivybridge_init_clock_gating(struct drm_device *dev)
  2988. {
  2989. struct drm_i915_private *dev_priv = dev->dev_private;
  2990. int pipe;
  2991. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  2992. uint32_t snpcr;
  2993. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  2994. I915_WRITE(WM3_LP_ILK, 0);
  2995. I915_WRITE(WM2_LP_ILK, 0);
  2996. I915_WRITE(WM1_LP_ILK, 0);
  2997. I915_WRITE(ILK_DSPCLK_GATE, IVB_VRHUNIT_CLK_GATE);
  2998. /* WaDisableEarlyCull */
  2999. I915_WRITE(_3D_CHICKEN3,
  3000. _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL));
  3001. /* WaDisableBackToBackFlipFix */
  3002. I915_WRITE(IVB_CHICKEN3,
  3003. CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
  3004. CHICKEN3_DGMG_DONE_FIX_DISABLE);
  3005. /* Apply the WaDisableRHWOOptimizationForRenderHang workaround. */
  3006. I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1,
  3007. GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC);
  3008. /* WaApplyL3ControlAndL3ChickenMode requires those two on Ivy Bridge */
  3009. I915_WRITE(GEN7_L3CNTLREG1,
  3010. GEN7_WA_FOR_GEN7_L3_CONTROL);
  3011. I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER,
  3012. GEN7_WA_L3_CHICKEN_MODE);
  3013. /* WaForceL3Serialization */
  3014. I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) &
  3015. ~L3SQ_URB_READ_CAM_MATCH_DISABLE);
  3016. /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
  3017. * gating disable must be set. Failure to set it results in
  3018. * flickering pixels due to Z write ordering failures after
  3019. * some amount of runtime in the Mesa "fire" demo, and Unigine
  3020. * Sanctuary and Tropics, and apparently anything else with
  3021. * alpha test or pixel discard.
  3022. *
  3023. * According to the spec, bit 11 (RCCUNIT) must also be set,
  3024. * but we didn't debug actual testcases to find it out.
  3025. *
  3026. * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
  3027. * This implements the WaDisableRCZUnitClockGating workaround.
  3028. */
  3029. I915_WRITE(GEN6_UCGCTL2,
  3030. GEN6_RCZUNIT_CLOCK_GATE_DISABLE |
  3031. GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
  3032. /* This is required by WaCatErrorRejectionIssue */
  3033. I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  3034. I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
  3035. GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  3036. for_each_pipe(pipe) {
  3037. I915_WRITE(DSPCNTR(pipe),
  3038. I915_READ(DSPCNTR(pipe)) |
  3039. DISPPLANE_TRICKLE_FEED_DISABLE);
  3040. intel_flush_display_plane(dev_priv, pipe);
  3041. }
  3042. I915_WRITE(GEN6_MBCTL, I915_READ(GEN6_MBCTL) |
  3043. GEN6_MBCTL_ENABLE_BOOT_FETCH);
  3044. gen7_setup_fixed_func_scheduler(dev_priv);
  3045. /* WaDisable4x2SubspanOptimization */
  3046. I915_WRITE(CACHE_MODE_1,
  3047. _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
  3048. snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
  3049. snpcr &= ~GEN6_MBC_SNPCR_MASK;
  3050. snpcr |= GEN6_MBC_SNPCR_MED;
  3051. I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
  3052. }
  3053. static void valleyview_init_clock_gating(struct drm_device *dev)
  3054. {
  3055. struct drm_i915_private *dev_priv = dev->dev_private;
  3056. int pipe;
  3057. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  3058. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  3059. I915_WRITE(WM3_LP_ILK, 0);
  3060. I915_WRITE(WM2_LP_ILK, 0);
  3061. I915_WRITE(WM1_LP_ILK, 0);
  3062. I915_WRITE(ILK_DSPCLK_GATE, IVB_VRHUNIT_CLK_GATE);
  3063. /* WaDisableEarlyCull */
  3064. I915_WRITE(_3D_CHICKEN3,
  3065. _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL));
  3066. /* WaDisableBackToBackFlipFix */
  3067. I915_WRITE(IVB_CHICKEN3,
  3068. CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
  3069. CHICKEN3_DGMG_DONE_FIX_DISABLE);
  3070. /* Apply the WaDisableRHWOOptimizationForRenderHang workaround. */
  3071. I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1,
  3072. GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC);
  3073. /* WaApplyL3ControlAndL3ChickenMode requires those two on Ivy Bridge */
  3074. I915_WRITE(GEN7_L3CNTLREG1, GEN7_WA_FOR_GEN7_L3_CONTROL);
  3075. I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER, GEN7_WA_L3_CHICKEN_MODE);
  3076. /* WaForceL3Serialization */
  3077. I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) &
  3078. ~L3SQ_URB_READ_CAM_MATCH_DISABLE);
  3079. /* This is required by WaCatErrorRejectionIssue */
  3080. I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  3081. I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
  3082. GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  3083. I915_WRITE(GEN6_MBCTL, I915_READ(GEN6_MBCTL) |
  3084. GEN6_MBCTL_ENABLE_BOOT_FETCH);
  3085. /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
  3086. * gating disable must be set. Failure to set it results in
  3087. * flickering pixels due to Z write ordering failures after
  3088. * some amount of runtime in the Mesa "fire" demo, and Unigine
  3089. * Sanctuary and Tropics, and apparently anything else with
  3090. * alpha test or pixel discard.
  3091. *
  3092. * According to the spec, bit 11 (RCCUNIT) must also be set,
  3093. * but we didn't debug actual testcases to find it out.
  3094. *
  3095. * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
  3096. * This implements the WaDisableRCZUnitClockGating workaround.
  3097. *
  3098. * Also apply WaDisableVDSUnitClockGating and
  3099. * WaDisableRCPBUnitClockGating.
  3100. */
  3101. I915_WRITE(GEN6_UCGCTL2,
  3102. GEN7_VDSUNIT_CLOCK_GATE_DISABLE |
  3103. GEN7_TDLUNIT_CLOCK_GATE_DISABLE |
  3104. GEN6_RCZUNIT_CLOCK_GATE_DISABLE |
  3105. GEN6_RCPBUNIT_CLOCK_GATE_DISABLE |
  3106. GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
  3107. I915_WRITE(GEN7_UCGCTL4, GEN7_L3BANK2X_CLOCK_GATE_DISABLE);
  3108. for_each_pipe(pipe) {
  3109. I915_WRITE(DSPCNTR(pipe),
  3110. I915_READ(DSPCNTR(pipe)) |
  3111. DISPPLANE_TRICKLE_FEED_DISABLE);
  3112. intel_flush_display_plane(dev_priv, pipe);
  3113. }
  3114. I915_WRITE(CACHE_MODE_1,
  3115. _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
  3116. /*
  3117. * On ValleyView, the GUnit needs to signal the GT
  3118. * when flip and other events complete. So enable
  3119. * all the GUnit->GT interrupts here
  3120. */
  3121. I915_WRITE(VLV_DPFLIPSTAT, PIPEB_LINE_COMPARE_INT_EN |
  3122. PIPEB_HLINE_INT_EN | PIPEB_VBLANK_INT_EN |
  3123. SPRITED_FLIPDONE_INT_EN | SPRITEC_FLIPDONE_INT_EN |
  3124. PLANEB_FLIPDONE_INT_EN | PIPEA_LINE_COMPARE_INT_EN |
  3125. PIPEA_HLINE_INT_EN | PIPEA_VBLANK_INT_EN |
  3126. SPRITEB_FLIPDONE_INT_EN | SPRITEA_FLIPDONE_INT_EN |
  3127. PLANEA_FLIPDONE_INT_EN);
  3128. }
  3129. static void g4x_init_clock_gating(struct drm_device *dev)
  3130. {
  3131. struct drm_i915_private *dev_priv = dev->dev_private;
  3132. uint32_t dspclk_gate;
  3133. I915_WRITE(RENCLK_GATE_D1, 0);
  3134. I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  3135. GS_UNIT_CLOCK_GATE_DISABLE |
  3136. CL_UNIT_CLOCK_GATE_DISABLE);
  3137. I915_WRITE(RAMCLK_GATE_D, 0);
  3138. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  3139. OVRUNIT_CLOCK_GATE_DISABLE |
  3140. OVCUNIT_CLOCK_GATE_DISABLE;
  3141. if (IS_GM45(dev))
  3142. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  3143. I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
  3144. }
  3145. static void crestline_init_clock_gating(struct drm_device *dev)
  3146. {
  3147. struct drm_i915_private *dev_priv = dev->dev_private;
  3148. I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  3149. I915_WRITE(RENCLK_GATE_D2, 0);
  3150. I915_WRITE(DSPCLK_GATE_D, 0);
  3151. I915_WRITE(RAMCLK_GATE_D, 0);
  3152. I915_WRITE16(DEUC, 0);
  3153. }
  3154. static void broadwater_init_clock_gating(struct drm_device *dev)
  3155. {
  3156. struct drm_i915_private *dev_priv = dev->dev_private;
  3157. I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  3158. I965_RCC_CLOCK_GATE_DISABLE |
  3159. I965_RCPB_CLOCK_GATE_DISABLE |
  3160. I965_ISC_CLOCK_GATE_DISABLE |
  3161. I965_FBC_CLOCK_GATE_DISABLE);
  3162. I915_WRITE(RENCLK_GATE_D2, 0);
  3163. }
  3164. static void gen3_init_clock_gating(struct drm_device *dev)
  3165. {
  3166. struct drm_i915_private *dev_priv = dev->dev_private;
  3167. u32 dstate = I915_READ(D_STATE);
  3168. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  3169. DSTATE_DOT_CLOCK_GATING;
  3170. I915_WRITE(D_STATE, dstate);
  3171. if (IS_PINEVIEW(dev))
  3172. I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY));
  3173. /* IIR "flip pending" means done if this bit is set */
  3174. I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE));
  3175. }
  3176. static void i85x_init_clock_gating(struct drm_device *dev)
  3177. {
  3178. struct drm_i915_private *dev_priv = dev->dev_private;
  3179. I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  3180. }
  3181. static void i830_init_clock_gating(struct drm_device *dev)
  3182. {
  3183. struct drm_i915_private *dev_priv = dev->dev_private;
  3184. I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
  3185. }
  3186. static void ibx_init_clock_gating(struct drm_device *dev)
  3187. {
  3188. struct drm_i915_private *dev_priv = dev->dev_private;
  3189. /*
  3190. * On Ibex Peak and Cougar Point, we need to disable clock
  3191. * gating for the panel power sequencer or it will fail to
  3192. * start up when no ports are active.
  3193. */
  3194. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
  3195. }
  3196. static void cpt_init_clock_gating(struct drm_device *dev)
  3197. {
  3198. struct drm_i915_private *dev_priv = dev->dev_private;
  3199. int pipe;
  3200. /*
  3201. * On Ibex Peak and Cougar Point, we need to disable clock
  3202. * gating for the panel power sequencer or it will fail to
  3203. * start up when no ports are active.
  3204. */
  3205. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
  3206. I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) |
  3207. DPLS_EDP_PPS_FIX_DIS);
  3208. /* Without this, mode sets may fail silently on FDI */
  3209. for_each_pipe(pipe)
  3210. I915_WRITE(TRANS_CHICKEN2(pipe), TRANS_AUTOTRAIN_GEN_STALL_DIS);
  3211. }
  3212. void intel_init_clock_gating(struct drm_device *dev)
  3213. {
  3214. struct drm_i915_private *dev_priv = dev->dev_private;
  3215. dev_priv->display.init_clock_gating(dev);
  3216. if (dev_priv->display.init_pch_clock_gating)
  3217. dev_priv->display.init_pch_clock_gating(dev);
  3218. }
  3219. /* Starting with Haswell, we have different power wells for
  3220. * different parts of the GPU. This attempts to enable them all.
  3221. */
  3222. void intel_init_power_wells(struct drm_device *dev)
  3223. {
  3224. struct drm_i915_private *dev_priv = dev->dev_private;
  3225. unsigned long power_wells[] = {
  3226. HSW_PWR_WELL_CTL1,
  3227. HSW_PWR_WELL_CTL2,
  3228. HSW_PWR_WELL_CTL4
  3229. };
  3230. int i;
  3231. if (!IS_HASWELL(dev))
  3232. return;
  3233. mutex_lock(&dev->struct_mutex);
  3234. for (i = 0; i < ARRAY_SIZE(power_wells); i++) {
  3235. int well = I915_READ(power_wells[i]);
  3236. if ((well & HSW_PWR_WELL_STATE) == 0) {
  3237. I915_WRITE(power_wells[i], well & HSW_PWR_WELL_ENABLE);
  3238. if (wait_for(I915_READ(power_wells[i] & HSW_PWR_WELL_STATE), 20))
  3239. DRM_ERROR("Error enabling power well %lx\n", power_wells[i]);
  3240. }
  3241. }
  3242. mutex_unlock(&dev->struct_mutex);
  3243. }
  3244. /* Set up chip specific power management-related functions */
  3245. void intel_init_pm(struct drm_device *dev)
  3246. {
  3247. struct drm_i915_private *dev_priv = dev->dev_private;
  3248. if (I915_HAS_FBC(dev)) {
  3249. if (HAS_PCH_SPLIT(dev)) {
  3250. dev_priv->display.fbc_enabled = ironlake_fbc_enabled;
  3251. dev_priv->display.enable_fbc = ironlake_enable_fbc;
  3252. dev_priv->display.disable_fbc = ironlake_disable_fbc;
  3253. } else if (IS_GM45(dev)) {
  3254. dev_priv->display.fbc_enabled = g4x_fbc_enabled;
  3255. dev_priv->display.enable_fbc = g4x_enable_fbc;
  3256. dev_priv->display.disable_fbc = g4x_disable_fbc;
  3257. } else if (IS_CRESTLINE(dev)) {
  3258. dev_priv->display.fbc_enabled = i8xx_fbc_enabled;
  3259. dev_priv->display.enable_fbc = i8xx_enable_fbc;
  3260. dev_priv->display.disable_fbc = i8xx_disable_fbc;
  3261. }
  3262. /* 855GM needs testing */
  3263. }
  3264. /* For cxsr */
  3265. if (IS_PINEVIEW(dev))
  3266. i915_pineview_get_mem_freq(dev);
  3267. else if (IS_GEN5(dev))
  3268. i915_ironlake_get_mem_freq(dev);
  3269. /* For FIFO watermark updates */
  3270. if (HAS_PCH_SPLIT(dev)) {
  3271. if (HAS_PCH_IBX(dev))
  3272. dev_priv->display.init_pch_clock_gating = ibx_init_clock_gating;
  3273. else if (HAS_PCH_CPT(dev))
  3274. dev_priv->display.init_pch_clock_gating = cpt_init_clock_gating;
  3275. if (IS_GEN5(dev)) {
  3276. if (I915_READ(MLTR_ILK) & ILK_SRLT_MASK)
  3277. dev_priv->display.update_wm = ironlake_update_wm;
  3278. else {
  3279. DRM_DEBUG_KMS("Failed to get proper latency. "
  3280. "Disable CxSR\n");
  3281. dev_priv->display.update_wm = NULL;
  3282. }
  3283. dev_priv->display.init_clock_gating = ironlake_init_clock_gating;
  3284. } else if (IS_GEN6(dev)) {
  3285. if (SNB_READ_WM0_LATENCY()) {
  3286. dev_priv->display.update_wm = sandybridge_update_wm;
  3287. dev_priv->display.update_sprite_wm = sandybridge_update_sprite_wm;
  3288. } else {
  3289. DRM_DEBUG_KMS("Failed to read display plane latency. "
  3290. "Disable CxSR\n");
  3291. dev_priv->display.update_wm = NULL;
  3292. }
  3293. dev_priv->display.init_clock_gating = gen6_init_clock_gating;
  3294. } else if (IS_IVYBRIDGE(dev)) {
  3295. /* FIXME: detect B0+ stepping and use auto training */
  3296. if (SNB_READ_WM0_LATENCY()) {
  3297. dev_priv->display.update_wm = sandybridge_update_wm;
  3298. dev_priv->display.update_sprite_wm = sandybridge_update_sprite_wm;
  3299. } else {
  3300. DRM_DEBUG_KMS("Failed to read display plane latency. "
  3301. "Disable CxSR\n");
  3302. dev_priv->display.update_wm = NULL;
  3303. }
  3304. dev_priv->display.init_clock_gating = ivybridge_init_clock_gating;
  3305. } else if (IS_HASWELL(dev)) {
  3306. if (SNB_READ_WM0_LATENCY()) {
  3307. dev_priv->display.update_wm = sandybridge_update_wm;
  3308. dev_priv->display.update_sprite_wm = sandybridge_update_sprite_wm;
  3309. dev_priv->display.update_linetime_wm = haswell_update_linetime_wm;
  3310. } else {
  3311. DRM_DEBUG_KMS("Failed to read display plane latency. "
  3312. "Disable CxSR\n");
  3313. dev_priv->display.update_wm = NULL;
  3314. }
  3315. dev_priv->display.init_clock_gating = haswell_init_clock_gating;
  3316. } else
  3317. dev_priv->display.update_wm = NULL;
  3318. } else if (IS_VALLEYVIEW(dev)) {
  3319. dev_priv->display.update_wm = valleyview_update_wm;
  3320. dev_priv->display.init_clock_gating =
  3321. valleyview_init_clock_gating;
  3322. } else if (IS_PINEVIEW(dev)) {
  3323. if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev),
  3324. dev_priv->is_ddr3,
  3325. dev_priv->fsb_freq,
  3326. dev_priv->mem_freq)) {
  3327. DRM_INFO("failed to find known CxSR latency "
  3328. "(found ddr%s fsb freq %d, mem freq %d), "
  3329. "disabling CxSR\n",
  3330. (dev_priv->is_ddr3 == 1) ? "3" : "2",
  3331. dev_priv->fsb_freq, dev_priv->mem_freq);
  3332. /* Disable CxSR and never update its watermark again */
  3333. pineview_disable_cxsr(dev);
  3334. dev_priv->display.update_wm = NULL;
  3335. } else
  3336. dev_priv->display.update_wm = pineview_update_wm;
  3337. dev_priv->display.init_clock_gating = gen3_init_clock_gating;
  3338. } else if (IS_G4X(dev)) {
  3339. dev_priv->display.update_wm = g4x_update_wm;
  3340. dev_priv->display.init_clock_gating = g4x_init_clock_gating;
  3341. } else if (IS_GEN4(dev)) {
  3342. dev_priv->display.update_wm = i965_update_wm;
  3343. if (IS_CRESTLINE(dev))
  3344. dev_priv->display.init_clock_gating = crestline_init_clock_gating;
  3345. else if (IS_BROADWATER(dev))
  3346. dev_priv->display.init_clock_gating = broadwater_init_clock_gating;
  3347. } else if (IS_GEN3(dev)) {
  3348. dev_priv->display.update_wm = i9xx_update_wm;
  3349. dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
  3350. dev_priv->display.init_clock_gating = gen3_init_clock_gating;
  3351. } else if (IS_I865G(dev)) {
  3352. dev_priv->display.update_wm = i830_update_wm;
  3353. dev_priv->display.init_clock_gating = i85x_init_clock_gating;
  3354. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  3355. } else if (IS_I85X(dev)) {
  3356. dev_priv->display.update_wm = i9xx_update_wm;
  3357. dev_priv->display.get_fifo_size = i85x_get_fifo_size;
  3358. dev_priv->display.init_clock_gating = i85x_init_clock_gating;
  3359. } else {
  3360. dev_priv->display.update_wm = i830_update_wm;
  3361. dev_priv->display.init_clock_gating = i830_init_clock_gating;
  3362. if (IS_845G(dev))
  3363. dev_priv->display.get_fifo_size = i845_get_fifo_size;
  3364. else
  3365. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  3366. }
  3367. }
  3368. static void __gen6_gt_wait_for_thread_c0(struct drm_i915_private *dev_priv)
  3369. {
  3370. u32 gt_thread_status_mask;
  3371. if (IS_HASWELL(dev_priv->dev))
  3372. gt_thread_status_mask = GEN6_GT_THREAD_STATUS_CORE_MASK_HSW;
  3373. else
  3374. gt_thread_status_mask = GEN6_GT_THREAD_STATUS_CORE_MASK;
  3375. /* w/a for a sporadic read returning 0 by waiting for the GT
  3376. * thread to wake up.
  3377. */
  3378. if (wait_for_atomic_us((I915_READ_NOTRACE(GEN6_GT_THREAD_STATUS_REG) & gt_thread_status_mask) == 0, 500))
  3379. DRM_ERROR("GT thread status wait timed out\n");
  3380. }
  3381. static void __gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)
  3382. {
  3383. u32 forcewake_ack;
  3384. if (IS_HASWELL(dev_priv->dev))
  3385. forcewake_ack = FORCEWAKE_ACK_HSW;
  3386. else
  3387. forcewake_ack = FORCEWAKE_ACK;
  3388. if (wait_for_atomic((I915_READ_NOTRACE(forcewake_ack) & 1) == 0,
  3389. FORCEWAKE_ACK_TIMEOUT_MS))
  3390. DRM_ERROR("Timed out waiting for forcewake old ack to clear.\n");
  3391. I915_WRITE_NOTRACE(FORCEWAKE, 1);
  3392. POSTING_READ(ECOBUS); /* something from same cacheline, but !FORCEWAKE */
  3393. if (wait_for_atomic((I915_READ_NOTRACE(forcewake_ack) & 1),
  3394. FORCEWAKE_ACK_TIMEOUT_MS))
  3395. DRM_ERROR("Timed out waiting for forcewake to ack request.\n");
  3396. __gen6_gt_wait_for_thread_c0(dev_priv);
  3397. }
  3398. static void __gen6_gt_force_wake_mt_get(struct drm_i915_private *dev_priv)
  3399. {
  3400. u32 forcewake_ack;
  3401. if (IS_HASWELL(dev_priv->dev))
  3402. forcewake_ack = FORCEWAKE_ACK_HSW;
  3403. else
  3404. forcewake_ack = FORCEWAKE_MT_ACK;
  3405. if (wait_for_atomic((I915_READ_NOTRACE(forcewake_ack) & 1) == 0,
  3406. FORCEWAKE_ACK_TIMEOUT_MS))
  3407. DRM_ERROR("Timed out waiting for forcewake old ack to clear.\n");
  3408. I915_WRITE_NOTRACE(FORCEWAKE_MT, _MASKED_BIT_ENABLE(1));
  3409. POSTING_READ(ECOBUS); /* something from same cacheline, but !FORCEWAKE */
  3410. if (wait_for_atomic((I915_READ_NOTRACE(forcewake_ack) & 1),
  3411. FORCEWAKE_ACK_TIMEOUT_MS))
  3412. DRM_ERROR("Timed out waiting for forcewake to ack request.\n");
  3413. __gen6_gt_wait_for_thread_c0(dev_priv);
  3414. }
  3415. /*
  3416. * Generally this is called implicitly by the register read function. However,
  3417. * if some sequence requires the GT to not power down then this function should
  3418. * be called at the beginning of the sequence followed by a call to
  3419. * gen6_gt_force_wake_put() at the end of the sequence.
  3420. */
  3421. void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv)
  3422. {
  3423. unsigned long irqflags;
  3424. spin_lock_irqsave(&dev_priv->gt_lock, irqflags);
  3425. if (dev_priv->forcewake_count++ == 0)
  3426. dev_priv->gt.force_wake_get(dev_priv);
  3427. spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags);
  3428. }
  3429. void gen6_gt_check_fifodbg(struct drm_i915_private *dev_priv)
  3430. {
  3431. u32 gtfifodbg;
  3432. gtfifodbg = I915_READ_NOTRACE(GTFIFODBG);
  3433. if (WARN(gtfifodbg & GT_FIFO_CPU_ERROR_MASK,
  3434. "MMIO read or write has been dropped %x\n", gtfifodbg))
  3435. I915_WRITE_NOTRACE(GTFIFODBG, GT_FIFO_CPU_ERROR_MASK);
  3436. }
  3437. static void __gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
  3438. {
  3439. I915_WRITE_NOTRACE(FORCEWAKE, 0);
  3440. /* gen6_gt_check_fifodbg doubles as the POSTING_READ */
  3441. gen6_gt_check_fifodbg(dev_priv);
  3442. }
  3443. static void __gen6_gt_force_wake_mt_put(struct drm_i915_private *dev_priv)
  3444. {
  3445. I915_WRITE_NOTRACE(FORCEWAKE_MT, _MASKED_BIT_DISABLE(1));
  3446. /* gen6_gt_check_fifodbg doubles as the POSTING_READ */
  3447. gen6_gt_check_fifodbg(dev_priv);
  3448. }
  3449. /*
  3450. * see gen6_gt_force_wake_get()
  3451. */
  3452. void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv)
  3453. {
  3454. unsigned long irqflags;
  3455. spin_lock_irqsave(&dev_priv->gt_lock, irqflags);
  3456. if (--dev_priv->forcewake_count == 0)
  3457. dev_priv->gt.force_wake_put(dev_priv);
  3458. spin_unlock_irqrestore(&dev_priv->gt_lock, irqflags);
  3459. }
  3460. int __gen6_gt_wait_for_fifo(struct drm_i915_private *dev_priv)
  3461. {
  3462. int ret = 0;
  3463. if (dev_priv->gt_fifo_count < GT_FIFO_NUM_RESERVED_ENTRIES) {
  3464. int loop = 500;
  3465. u32 fifo = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES);
  3466. while (fifo <= GT_FIFO_NUM_RESERVED_ENTRIES && loop--) {
  3467. udelay(10);
  3468. fifo = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES);
  3469. }
  3470. if (WARN_ON(loop < 0 && fifo <= GT_FIFO_NUM_RESERVED_ENTRIES))
  3471. ++ret;
  3472. dev_priv->gt_fifo_count = fifo;
  3473. }
  3474. dev_priv->gt_fifo_count--;
  3475. return ret;
  3476. }
  3477. static void vlv_force_wake_get(struct drm_i915_private *dev_priv)
  3478. {
  3479. if (wait_for_atomic((I915_READ_NOTRACE(FORCEWAKE_ACK_VLV) & 1) == 0,
  3480. FORCEWAKE_ACK_TIMEOUT_MS))
  3481. DRM_ERROR("Timed out waiting for forcewake old ack to clear.\n");
  3482. I915_WRITE_NOTRACE(FORCEWAKE_VLV, _MASKED_BIT_ENABLE(1));
  3483. if (wait_for_atomic((I915_READ_NOTRACE(FORCEWAKE_ACK_VLV) & 1),
  3484. FORCEWAKE_ACK_TIMEOUT_MS))
  3485. DRM_ERROR("Timed out waiting for forcewake to ack request.\n");
  3486. __gen6_gt_wait_for_thread_c0(dev_priv);
  3487. }
  3488. static void vlv_force_wake_put(struct drm_i915_private *dev_priv)
  3489. {
  3490. I915_WRITE_NOTRACE(FORCEWAKE_VLV, _MASKED_BIT_DISABLE(1));
  3491. /* The below doubles as a POSTING_READ */
  3492. gen6_gt_check_fifodbg(dev_priv);
  3493. }
  3494. void intel_gt_init(struct drm_device *dev)
  3495. {
  3496. struct drm_i915_private *dev_priv = dev->dev_private;
  3497. spin_lock_init(&dev_priv->gt_lock);
  3498. if (IS_VALLEYVIEW(dev)) {
  3499. dev_priv->gt.force_wake_get = vlv_force_wake_get;
  3500. dev_priv->gt.force_wake_put = vlv_force_wake_put;
  3501. } else if (INTEL_INFO(dev)->gen >= 6) {
  3502. dev_priv->gt.force_wake_get = __gen6_gt_force_wake_get;
  3503. dev_priv->gt.force_wake_put = __gen6_gt_force_wake_put;
  3504. /* IVB configs may use multi-threaded forcewake */
  3505. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
  3506. u32 ecobus;
  3507. /* A small trick here - if the bios hasn't configured
  3508. * MT forcewake, and if the device is in RC6, then
  3509. * force_wake_mt_get will not wake the device and the
  3510. * ECOBUS read will return zero. Which will be
  3511. * (correctly) interpreted by the test below as MT
  3512. * forcewake being disabled.
  3513. */
  3514. mutex_lock(&dev->struct_mutex);
  3515. __gen6_gt_force_wake_mt_get(dev_priv);
  3516. ecobus = I915_READ_NOTRACE(ECOBUS);
  3517. __gen6_gt_force_wake_mt_put(dev_priv);
  3518. mutex_unlock(&dev->struct_mutex);
  3519. if (ecobus & FORCEWAKE_MT_ENABLE) {
  3520. DRM_DEBUG_KMS("Using MT version of forcewake\n");
  3521. dev_priv->gt.force_wake_get =
  3522. __gen6_gt_force_wake_mt_get;
  3523. dev_priv->gt.force_wake_put =
  3524. __gen6_gt_force_wake_mt_put;
  3525. }
  3526. }
  3527. }
  3528. }