intel_pm.c 186 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647
  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. /**
  33. * RC6 is a special power stage which allows the GPU to enter an very
  34. * low-voltage mode when idle, using down to 0V while at this stage. This
  35. * stage is entered automatically when the GPU is idle when RC6 support is
  36. * enabled, and as soon as new workload arises GPU wakes up automatically as well.
  37. *
  38. * There are different RC6 modes available in Intel GPU, which differentiate
  39. * among each other with the latency required to enter and leave RC6 and
  40. * voltage consumed by the GPU in different states.
  41. *
  42. * The combination of the following flags define which states GPU is allowed
  43. * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and
  44. * RC6pp is deepest RC6. Their support by hardware varies according to the
  45. * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one
  46. * which brings the most power savings; deeper states save more power, but
  47. * require higher latency to switch to and wake up.
  48. */
  49. #define INTEL_RC6_ENABLE (1<<0)
  50. #define INTEL_RC6p_ENABLE (1<<1)
  51. #define INTEL_RC6pp_ENABLE (1<<2)
  52. static void skl_init_clock_gating(struct drm_device *dev)
  53. {
  54. struct drm_i915_private *dev_priv = dev->dev_private;
  55. if (INTEL_REVID(dev) == SKL_REVID_A0) {
  56. /*
  57. * WaDisableSDEUnitClockGating:skl
  58. * WaSetGAPSunitClckGateDisable:skl
  59. */
  60. I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
  61. GEN8_GAPSUNIT_CLOCK_GATE_DISABLE |
  62. GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  63. }
  64. }
  65. static void i915_pineview_get_mem_freq(struct drm_device *dev)
  66. {
  67. struct drm_i915_private *dev_priv = dev->dev_private;
  68. u32 tmp;
  69. tmp = I915_READ(CLKCFG);
  70. switch (tmp & CLKCFG_FSB_MASK) {
  71. case CLKCFG_FSB_533:
  72. dev_priv->fsb_freq = 533; /* 133*4 */
  73. break;
  74. case CLKCFG_FSB_800:
  75. dev_priv->fsb_freq = 800; /* 200*4 */
  76. break;
  77. case CLKCFG_FSB_667:
  78. dev_priv->fsb_freq = 667; /* 167*4 */
  79. break;
  80. case CLKCFG_FSB_400:
  81. dev_priv->fsb_freq = 400; /* 100*4 */
  82. break;
  83. }
  84. switch (tmp & CLKCFG_MEM_MASK) {
  85. case CLKCFG_MEM_533:
  86. dev_priv->mem_freq = 533;
  87. break;
  88. case CLKCFG_MEM_667:
  89. dev_priv->mem_freq = 667;
  90. break;
  91. case CLKCFG_MEM_800:
  92. dev_priv->mem_freq = 800;
  93. break;
  94. }
  95. /* detect pineview DDR3 setting */
  96. tmp = I915_READ(CSHRDDR3CTL);
  97. dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0;
  98. }
  99. static void i915_ironlake_get_mem_freq(struct drm_device *dev)
  100. {
  101. struct drm_i915_private *dev_priv = dev->dev_private;
  102. u16 ddrpll, csipll;
  103. ddrpll = I915_READ16(DDRMPLL1);
  104. csipll = I915_READ16(CSIPLL0);
  105. switch (ddrpll & 0xff) {
  106. case 0xc:
  107. dev_priv->mem_freq = 800;
  108. break;
  109. case 0x10:
  110. dev_priv->mem_freq = 1066;
  111. break;
  112. case 0x14:
  113. dev_priv->mem_freq = 1333;
  114. break;
  115. case 0x18:
  116. dev_priv->mem_freq = 1600;
  117. break;
  118. default:
  119. DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n",
  120. ddrpll & 0xff);
  121. dev_priv->mem_freq = 0;
  122. break;
  123. }
  124. dev_priv->ips.r_t = dev_priv->mem_freq;
  125. switch (csipll & 0x3ff) {
  126. case 0x00c:
  127. dev_priv->fsb_freq = 3200;
  128. break;
  129. case 0x00e:
  130. dev_priv->fsb_freq = 3733;
  131. break;
  132. case 0x010:
  133. dev_priv->fsb_freq = 4266;
  134. break;
  135. case 0x012:
  136. dev_priv->fsb_freq = 4800;
  137. break;
  138. case 0x014:
  139. dev_priv->fsb_freq = 5333;
  140. break;
  141. case 0x016:
  142. dev_priv->fsb_freq = 5866;
  143. break;
  144. case 0x018:
  145. dev_priv->fsb_freq = 6400;
  146. break;
  147. default:
  148. DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n",
  149. csipll & 0x3ff);
  150. dev_priv->fsb_freq = 0;
  151. break;
  152. }
  153. if (dev_priv->fsb_freq == 3200) {
  154. dev_priv->ips.c_m = 0;
  155. } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) {
  156. dev_priv->ips.c_m = 1;
  157. } else {
  158. dev_priv->ips.c_m = 2;
  159. }
  160. }
  161. static const struct cxsr_latency cxsr_latency_table[] = {
  162. {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
  163. {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
  164. {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
  165. {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
  166. {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
  167. {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
  168. {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
  169. {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
  170. {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
  171. {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
  172. {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
  173. {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
  174. {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
  175. {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
  176. {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
  177. {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
  178. {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
  179. {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
  180. {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
  181. {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
  182. {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
  183. {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
  184. {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
  185. {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
  186. {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
  187. {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
  188. {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
  189. {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
  190. {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
  191. {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
  192. };
  193. static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop,
  194. int is_ddr3,
  195. int fsb,
  196. int mem)
  197. {
  198. const struct cxsr_latency *latency;
  199. int i;
  200. if (fsb == 0 || mem == 0)
  201. return NULL;
  202. for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
  203. latency = &cxsr_latency_table[i];
  204. if (is_desktop == latency->is_desktop &&
  205. is_ddr3 == latency->is_ddr3 &&
  206. fsb == latency->fsb_freq && mem == latency->mem_freq)
  207. return latency;
  208. }
  209. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  210. return NULL;
  211. }
  212. void intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable)
  213. {
  214. struct drm_device *dev = dev_priv->dev;
  215. u32 val;
  216. if (IS_VALLEYVIEW(dev)) {
  217. I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0);
  218. } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) {
  219. I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0);
  220. } else if (IS_PINEVIEW(dev)) {
  221. val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN;
  222. val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0;
  223. I915_WRITE(DSPFW3, val);
  224. } else if (IS_I945G(dev) || IS_I945GM(dev)) {
  225. val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) :
  226. _MASKED_BIT_DISABLE(FW_BLC_SELF_EN);
  227. I915_WRITE(FW_BLC_SELF, val);
  228. } else if (IS_I915GM(dev)) {
  229. val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) :
  230. _MASKED_BIT_DISABLE(INSTPM_SELF_EN);
  231. I915_WRITE(INSTPM, val);
  232. } else {
  233. return;
  234. }
  235. DRM_DEBUG_KMS("memory self-refresh is %s\n",
  236. enable ? "enabled" : "disabled");
  237. }
  238. /*
  239. * Latency for FIFO fetches is dependent on several factors:
  240. * - memory configuration (speed, channels)
  241. * - chipset
  242. * - current MCH state
  243. * It can be fairly high in some situations, so here we assume a fairly
  244. * pessimal value. It's a tradeoff between extra memory fetches (if we
  245. * set this value too high, the FIFO will fetch frequently to stay full)
  246. * and power consumption (set it too low to save power and we might see
  247. * FIFO underruns and display "flicker").
  248. *
  249. * A value of 5us seems to be a good balance; safe for very low end
  250. * platforms but not overly aggressive on lower latency configs.
  251. */
  252. static const int pessimal_latency_ns = 5000;
  253. static int i9xx_get_fifo_size(struct drm_device *dev, int plane)
  254. {
  255. struct drm_i915_private *dev_priv = dev->dev_private;
  256. uint32_t dsparb = I915_READ(DSPARB);
  257. int size;
  258. size = dsparb & 0x7f;
  259. if (plane)
  260. size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
  261. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  262. plane ? "B" : "A", size);
  263. return size;
  264. }
  265. static int i830_get_fifo_size(struct drm_device *dev, int plane)
  266. {
  267. struct drm_i915_private *dev_priv = dev->dev_private;
  268. uint32_t dsparb = I915_READ(DSPARB);
  269. int size;
  270. size = dsparb & 0x1ff;
  271. if (plane)
  272. size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
  273. size >>= 1; /* Convert to cachelines */
  274. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  275. plane ? "B" : "A", size);
  276. return size;
  277. }
  278. static int i845_get_fifo_size(struct drm_device *dev, int plane)
  279. {
  280. struct drm_i915_private *dev_priv = dev->dev_private;
  281. uint32_t dsparb = I915_READ(DSPARB);
  282. int size;
  283. size = dsparb & 0x7f;
  284. size >>= 2; /* Convert to cachelines */
  285. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  286. plane ? "B" : "A",
  287. size);
  288. return size;
  289. }
  290. /* Pineview has different values for various configs */
  291. static const struct intel_watermark_params pineview_display_wm = {
  292. .fifo_size = PINEVIEW_DISPLAY_FIFO,
  293. .max_wm = PINEVIEW_MAX_WM,
  294. .default_wm = PINEVIEW_DFT_WM,
  295. .guard_size = PINEVIEW_GUARD_WM,
  296. .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
  297. };
  298. static const struct intel_watermark_params pineview_display_hplloff_wm = {
  299. .fifo_size = PINEVIEW_DISPLAY_FIFO,
  300. .max_wm = PINEVIEW_MAX_WM,
  301. .default_wm = PINEVIEW_DFT_HPLLOFF_WM,
  302. .guard_size = PINEVIEW_GUARD_WM,
  303. .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
  304. };
  305. static const struct intel_watermark_params pineview_cursor_wm = {
  306. .fifo_size = PINEVIEW_CURSOR_FIFO,
  307. .max_wm = PINEVIEW_CURSOR_MAX_WM,
  308. .default_wm = PINEVIEW_CURSOR_DFT_WM,
  309. .guard_size = PINEVIEW_CURSOR_GUARD_WM,
  310. .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
  311. };
  312. static const struct intel_watermark_params pineview_cursor_hplloff_wm = {
  313. .fifo_size = PINEVIEW_CURSOR_FIFO,
  314. .max_wm = PINEVIEW_CURSOR_MAX_WM,
  315. .default_wm = PINEVIEW_CURSOR_DFT_WM,
  316. .guard_size = PINEVIEW_CURSOR_GUARD_WM,
  317. .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
  318. };
  319. static const struct intel_watermark_params g4x_wm_info = {
  320. .fifo_size = G4X_FIFO_SIZE,
  321. .max_wm = G4X_MAX_WM,
  322. .default_wm = G4X_MAX_WM,
  323. .guard_size = 2,
  324. .cacheline_size = G4X_FIFO_LINE_SIZE,
  325. };
  326. static const struct intel_watermark_params g4x_cursor_wm_info = {
  327. .fifo_size = I965_CURSOR_FIFO,
  328. .max_wm = I965_CURSOR_MAX_WM,
  329. .default_wm = I965_CURSOR_DFT_WM,
  330. .guard_size = 2,
  331. .cacheline_size = G4X_FIFO_LINE_SIZE,
  332. };
  333. static const struct intel_watermark_params valleyview_wm_info = {
  334. .fifo_size = VALLEYVIEW_FIFO_SIZE,
  335. .max_wm = VALLEYVIEW_MAX_WM,
  336. .default_wm = VALLEYVIEW_MAX_WM,
  337. .guard_size = 2,
  338. .cacheline_size = G4X_FIFO_LINE_SIZE,
  339. };
  340. static const struct intel_watermark_params valleyview_cursor_wm_info = {
  341. .fifo_size = I965_CURSOR_FIFO,
  342. .max_wm = VALLEYVIEW_CURSOR_MAX_WM,
  343. .default_wm = I965_CURSOR_DFT_WM,
  344. .guard_size = 2,
  345. .cacheline_size = G4X_FIFO_LINE_SIZE,
  346. };
  347. static const struct intel_watermark_params i965_cursor_wm_info = {
  348. .fifo_size = I965_CURSOR_FIFO,
  349. .max_wm = I965_CURSOR_MAX_WM,
  350. .default_wm = I965_CURSOR_DFT_WM,
  351. .guard_size = 2,
  352. .cacheline_size = I915_FIFO_LINE_SIZE,
  353. };
  354. static const struct intel_watermark_params i945_wm_info = {
  355. .fifo_size = I945_FIFO_SIZE,
  356. .max_wm = I915_MAX_WM,
  357. .default_wm = 1,
  358. .guard_size = 2,
  359. .cacheline_size = I915_FIFO_LINE_SIZE,
  360. };
  361. static const struct intel_watermark_params i915_wm_info = {
  362. .fifo_size = I915_FIFO_SIZE,
  363. .max_wm = I915_MAX_WM,
  364. .default_wm = 1,
  365. .guard_size = 2,
  366. .cacheline_size = I915_FIFO_LINE_SIZE,
  367. };
  368. static const struct intel_watermark_params i830_a_wm_info = {
  369. .fifo_size = I855GM_FIFO_SIZE,
  370. .max_wm = I915_MAX_WM,
  371. .default_wm = 1,
  372. .guard_size = 2,
  373. .cacheline_size = I830_FIFO_LINE_SIZE,
  374. };
  375. static const struct intel_watermark_params i830_bc_wm_info = {
  376. .fifo_size = I855GM_FIFO_SIZE,
  377. .max_wm = I915_MAX_WM/2,
  378. .default_wm = 1,
  379. .guard_size = 2,
  380. .cacheline_size = I830_FIFO_LINE_SIZE,
  381. };
  382. static const struct intel_watermark_params i845_wm_info = {
  383. .fifo_size = I830_FIFO_SIZE,
  384. .max_wm = I915_MAX_WM,
  385. .default_wm = 1,
  386. .guard_size = 2,
  387. .cacheline_size = I830_FIFO_LINE_SIZE,
  388. };
  389. /**
  390. * intel_calculate_wm - calculate watermark level
  391. * @clock_in_khz: pixel clock
  392. * @wm: chip FIFO params
  393. * @pixel_size: display pixel size
  394. * @latency_ns: memory latency for the platform
  395. *
  396. * Calculate the watermark level (the level at which the display plane will
  397. * start fetching from memory again). Each chip has a different display
  398. * FIFO size and allocation, so the caller needs to figure that out and pass
  399. * in the correct intel_watermark_params structure.
  400. *
  401. * As the pixel clock runs, the FIFO will be drained at a rate that depends
  402. * on the pixel size. When it reaches the watermark level, it'll start
  403. * fetching FIFO line sized based chunks from memory until the FIFO fills
  404. * past the watermark point. If the FIFO drains completely, a FIFO underrun
  405. * will occur, and a display engine hang could result.
  406. */
  407. static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
  408. const struct intel_watermark_params *wm,
  409. int fifo_size,
  410. int pixel_size,
  411. unsigned long latency_ns)
  412. {
  413. long entries_required, wm_size;
  414. /*
  415. * Note: we need to make sure we don't overflow for various clock &
  416. * latency values.
  417. * clocks go from a few thousand to several hundred thousand.
  418. * latency is usually a few thousand
  419. */
  420. entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
  421. 1000;
  422. entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size);
  423. DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required);
  424. wm_size = fifo_size - (entries_required + wm->guard_size);
  425. DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size);
  426. /* Don't promote wm_size to unsigned... */
  427. if (wm_size > (long)wm->max_wm)
  428. wm_size = wm->max_wm;
  429. if (wm_size <= 0)
  430. wm_size = wm->default_wm;
  431. /*
  432. * Bspec seems to indicate that the value shouldn't be lower than
  433. * 'burst size + 1'. Certainly 830 is quite unhappy with low values.
  434. * Lets go for 8 which is the burst size since certain platforms
  435. * already use a hardcoded 8 (which is what the spec says should be
  436. * done).
  437. */
  438. if (wm_size <= 8)
  439. wm_size = 8;
  440. return wm_size;
  441. }
  442. static struct drm_crtc *single_enabled_crtc(struct drm_device *dev)
  443. {
  444. struct drm_crtc *crtc, *enabled = NULL;
  445. for_each_crtc(dev, crtc) {
  446. if (intel_crtc_active(crtc)) {
  447. if (enabled)
  448. return NULL;
  449. enabled = crtc;
  450. }
  451. }
  452. return enabled;
  453. }
  454. static void pineview_update_wm(struct drm_crtc *unused_crtc)
  455. {
  456. struct drm_device *dev = unused_crtc->dev;
  457. struct drm_i915_private *dev_priv = dev->dev_private;
  458. struct drm_crtc *crtc;
  459. const struct cxsr_latency *latency;
  460. u32 reg;
  461. unsigned long wm;
  462. latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3,
  463. dev_priv->fsb_freq, dev_priv->mem_freq);
  464. if (!latency) {
  465. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  466. intel_set_memory_cxsr(dev_priv, false);
  467. return;
  468. }
  469. crtc = single_enabled_crtc(dev);
  470. if (crtc) {
  471. const struct drm_display_mode *adjusted_mode;
  472. int pixel_size = crtc->primary->fb->bits_per_pixel / 8;
  473. int clock;
  474. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  475. clock = adjusted_mode->crtc_clock;
  476. /* Display SR */
  477. wm = intel_calculate_wm(clock, &pineview_display_wm,
  478. pineview_display_wm.fifo_size,
  479. pixel_size, latency->display_sr);
  480. reg = I915_READ(DSPFW1);
  481. reg &= ~DSPFW_SR_MASK;
  482. reg |= wm << DSPFW_SR_SHIFT;
  483. I915_WRITE(DSPFW1, reg);
  484. DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg);
  485. /* cursor SR */
  486. wm = intel_calculate_wm(clock, &pineview_cursor_wm,
  487. pineview_display_wm.fifo_size,
  488. pixel_size, latency->cursor_sr);
  489. reg = I915_READ(DSPFW3);
  490. reg &= ~DSPFW_CURSOR_SR_MASK;
  491. reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT;
  492. I915_WRITE(DSPFW3, reg);
  493. /* Display HPLL off SR */
  494. wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm,
  495. pineview_display_hplloff_wm.fifo_size,
  496. pixel_size, latency->display_hpll_disable);
  497. reg = I915_READ(DSPFW3);
  498. reg &= ~DSPFW_HPLL_SR_MASK;
  499. reg |= wm & DSPFW_HPLL_SR_MASK;
  500. I915_WRITE(DSPFW3, reg);
  501. /* cursor HPLL off SR */
  502. wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm,
  503. pineview_display_hplloff_wm.fifo_size,
  504. pixel_size, latency->cursor_hpll_disable);
  505. reg = I915_READ(DSPFW3);
  506. reg &= ~DSPFW_HPLL_CURSOR_MASK;
  507. reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT;
  508. I915_WRITE(DSPFW3, reg);
  509. DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg);
  510. intel_set_memory_cxsr(dev_priv, true);
  511. } else {
  512. intel_set_memory_cxsr(dev_priv, false);
  513. }
  514. }
  515. static bool g4x_compute_wm0(struct drm_device *dev,
  516. int plane,
  517. const struct intel_watermark_params *display,
  518. int display_latency_ns,
  519. const struct intel_watermark_params *cursor,
  520. int cursor_latency_ns,
  521. int *plane_wm,
  522. int *cursor_wm)
  523. {
  524. struct drm_crtc *crtc;
  525. const struct drm_display_mode *adjusted_mode;
  526. int htotal, hdisplay, clock, pixel_size;
  527. int line_time_us, line_count;
  528. int entries, tlb_miss;
  529. crtc = intel_get_crtc_for_plane(dev, plane);
  530. if (!intel_crtc_active(crtc)) {
  531. *cursor_wm = cursor->guard_size;
  532. *plane_wm = display->guard_size;
  533. return false;
  534. }
  535. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  536. clock = adjusted_mode->crtc_clock;
  537. htotal = adjusted_mode->crtc_htotal;
  538. hdisplay = to_intel_crtc(crtc)->config->pipe_src_w;
  539. pixel_size = crtc->primary->fb->bits_per_pixel / 8;
  540. /* Use the small buffer method to calculate plane watermark */
  541. entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
  542. tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;
  543. if (tlb_miss > 0)
  544. entries += tlb_miss;
  545. entries = DIV_ROUND_UP(entries, display->cacheline_size);
  546. *plane_wm = entries + display->guard_size;
  547. if (*plane_wm > (int)display->max_wm)
  548. *plane_wm = display->max_wm;
  549. /* Use the large buffer method to calculate cursor watermark */
  550. line_time_us = max(htotal * 1000 / clock, 1);
  551. line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
  552. entries = line_count * to_intel_crtc(crtc)->cursor_width * pixel_size;
  553. tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
  554. if (tlb_miss > 0)
  555. entries += tlb_miss;
  556. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  557. *cursor_wm = entries + cursor->guard_size;
  558. if (*cursor_wm > (int)cursor->max_wm)
  559. *cursor_wm = (int)cursor->max_wm;
  560. return true;
  561. }
  562. /*
  563. * Check the wm result.
  564. *
  565. * If any calculated watermark values is larger than the maximum value that
  566. * can be programmed into the associated watermark register, that watermark
  567. * must be disabled.
  568. */
  569. static bool g4x_check_srwm(struct drm_device *dev,
  570. int display_wm, int cursor_wm,
  571. const struct intel_watermark_params *display,
  572. const struct intel_watermark_params *cursor)
  573. {
  574. DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n",
  575. display_wm, cursor_wm);
  576. if (display_wm > display->max_wm) {
  577. DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n",
  578. display_wm, display->max_wm);
  579. return false;
  580. }
  581. if (cursor_wm > cursor->max_wm) {
  582. DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n",
  583. cursor_wm, cursor->max_wm);
  584. return false;
  585. }
  586. if (!(display_wm || cursor_wm)) {
  587. DRM_DEBUG_KMS("SR latency is 0, disabling\n");
  588. return false;
  589. }
  590. return true;
  591. }
  592. static bool g4x_compute_srwm(struct drm_device *dev,
  593. int plane,
  594. int latency_ns,
  595. const struct intel_watermark_params *display,
  596. const struct intel_watermark_params *cursor,
  597. int *display_wm, int *cursor_wm)
  598. {
  599. struct drm_crtc *crtc;
  600. const struct drm_display_mode *adjusted_mode;
  601. int hdisplay, htotal, pixel_size, clock;
  602. unsigned long line_time_us;
  603. int line_count, line_size;
  604. int small, large;
  605. int entries;
  606. if (!latency_ns) {
  607. *display_wm = *cursor_wm = 0;
  608. return false;
  609. }
  610. crtc = intel_get_crtc_for_plane(dev, plane);
  611. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  612. clock = adjusted_mode->crtc_clock;
  613. htotal = adjusted_mode->crtc_htotal;
  614. hdisplay = to_intel_crtc(crtc)->config->pipe_src_w;
  615. pixel_size = crtc->primary->fb->bits_per_pixel / 8;
  616. line_time_us = max(htotal * 1000 / clock, 1);
  617. line_count = (latency_ns / line_time_us + 1000) / 1000;
  618. line_size = hdisplay * pixel_size;
  619. /* Use the minimum of the small and large buffer method for primary */
  620. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  621. large = line_count * line_size;
  622. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  623. *display_wm = entries + display->guard_size;
  624. /* calculate the self-refresh watermark for display cursor */
  625. entries = line_count * pixel_size * to_intel_crtc(crtc)->cursor_width;
  626. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  627. *cursor_wm = entries + cursor->guard_size;
  628. return g4x_check_srwm(dev,
  629. *display_wm, *cursor_wm,
  630. display, cursor);
  631. }
  632. static bool vlv_compute_drain_latency(struct drm_crtc *crtc,
  633. int pixel_size,
  634. int *prec_mult,
  635. int *drain_latency)
  636. {
  637. struct drm_device *dev = crtc->dev;
  638. int entries;
  639. int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock;
  640. if (WARN(clock == 0, "Pixel clock is zero!\n"))
  641. return false;
  642. if (WARN(pixel_size == 0, "Pixel size is zero!\n"))
  643. return false;
  644. entries = DIV_ROUND_UP(clock, 1000) * pixel_size;
  645. if (IS_CHERRYVIEW(dev))
  646. *prec_mult = (entries > 128) ? DRAIN_LATENCY_PRECISION_32 :
  647. DRAIN_LATENCY_PRECISION_16;
  648. else
  649. *prec_mult = (entries > 128) ? DRAIN_LATENCY_PRECISION_64 :
  650. DRAIN_LATENCY_PRECISION_32;
  651. *drain_latency = (64 * (*prec_mult) * 4) / entries;
  652. if (*drain_latency > DRAIN_LATENCY_MASK)
  653. *drain_latency = DRAIN_LATENCY_MASK;
  654. return true;
  655. }
  656. /*
  657. * Update drain latency registers of memory arbiter
  658. *
  659. * Valleyview SoC has a new memory arbiter and needs drain latency registers
  660. * to be programmed. Each plane has a drain latency multiplier and a drain
  661. * latency value.
  662. */
  663. static void vlv_update_drain_latency(struct drm_crtc *crtc)
  664. {
  665. struct drm_device *dev = crtc->dev;
  666. struct drm_i915_private *dev_priv = dev->dev_private;
  667. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  668. int pixel_size;
  669. int drain_latency;
  670. enum pipe pipe = intel_crtc->pipe;
  671. int plane_prec, prec_mult, plane_dl;
  672. const int high_precision = IS_CHERRYVIEW(dev) ?
  673. DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_64;
  674. plane_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_PLANE_PRECISION_HIGH |
  675. DRAIN_LATENCY_MASK | DDL_CURSOR_PRECISION_HIGH |
  676. (DRAIN_LATENCY_MASK << DDL_CURSOR_SHIFT));
  677. if (!intel_crtc_active(crtc)) {
  678. I915_WRITE(VLV_DDL(pipe), plane_dl);
  679. return;
  680. }
  681. /* Primary plane Drain Latency */
  682. pixel_size = crtc->primary->fb->bits_per_pixel / 8; /* BPP */
  683. if (vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) {
  684. plane_prec = (prec_mult == high_precision) ?
  685. DDL_PLANE_PRECISION_HIGH :
  686. DDL_PLANE_PRECISION_LOW;
  687. plane_dl |= plane_prec | drain_latency;
  688. }
  689. /* Cursor Drain Latency
  690. * BPP is always 4 for cursor
  691. */
  692. pixel_size = 4;
  693. /* Program cursor DL only if it is enabled */
  694. if (intel_crtc->cursor_base &&
  695. vlv_compute_drain_latency(crtc, pixel_size, &prec_mult, &drain_latency)) {
  696. plane_prec = (prec_mult == high_precision) ?
  697. DDL_CURSOR_PRECISION_HIGH :
  698. DDL_CURSOR_PRECISION_LOW;
  699. plane_dl |= plane_prec | (drain_latency << DDL_CURSOR_SHIFT);
  700. }
  701. I915_WRITE(VLV_DDL(pipe), plane_dl);
  702. }
  703. #define single_plane_enabled(mask) is_power_of_2(mask)
  704. static void valleyview_update_wm(struct drm_crtc *crtc)
  705. {
  706. struct drm_device *dev = crtc->dev;
  707. static const int sr_latency_ns = 12000;
  708. struct drm_i915_private *dev_priv = dev->dev_private;
  709. int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
  710. int plane_sr, cursor_sr;
  711. int ignore_plane_sr, ignore_cursor_sr;
  712. unsigned int enabled = 0;
  713. bool cxsr_enabled;
  714. vlv_update_drain_latency(crtc);
  715. if (g4x_compute_wm0(dev, PIPE_A,
  716. &valleyview_wm_info, pessimal_latency_ns,
  717. &valleyview_cursor_wm_info, pessimal_latency_ns,
  718. &planea_wm, &cursora_wm))
  719. enabled |= 1 << PIPE_A;
  720. if (g4x_compute_wm0(dev, PIPE_B,
  721. &valleyview_wm_info, pessimal_latency_ns,
  722. &valleyview_cursor_wm_info, pessimal_latency_ns,
  723. &planeb_wm, &cursorb_wm))
  724. enabled |= 1 << PIPE_B;
  725. if (single_plane_enabled(enabled) &&
  726. g4x_compute_srwm(dev, ffs(enabled) - 1,
  727. sr_latency_ns,
  728. &valleyview_wm_info,
  729. &valleyview_cursor_wm_info,
  730. &plane_sr, &ignore_cursor_sr) &&
  731. g4x_compute_srwm(dev, ffs(enabled) - 1,
  732. 2*sr_latency_ns,
  733. &valleyview_wm_info,
  734. &valleyview_cursor_wm_info,
  735. &ignore_plane_sr, &cursor_sr)) {
  736. cxsr_enabled = true;
  737. } else {
  738. cxsr_enabled = false;
  739. intel_set_memory_cxsr(dev_priv, false);
  740. plane_sr = cursor_sr = 0;
  741. }
  742. DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
  743. "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
  744. planea_wm, cursora_wm,
  745. planeb_wm, cursorb_wm,
  746. plane_sr, cursor_sr);
  747. I915_WRITE(DSPFW1,
  748. (plane_sr << DSPFW_SR_SHIFT) |
  749. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  750. (planeb_wm << DSPFW_PLANEB_SHIFT) |
  751. (planea_wm << DSPFW_PLANEA_SHIFT));
  752. I915_WRITE(DSPFW2,
  753. (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) |
  754. (cursora_wm << DSPFW_CURSORA_SHIFT));
  755. I915_WRITE(DSPFW3,
  756. (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) |
  757. (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  758. if (cxsr_enabled)
  759. intel_set_memory_cxsr(dev_priv, true);
  760. }
  761. static void cherryview_update_wm(struct drm_crtc *crtc)
  762. {
  763. struct drm_device *dev = crtc->dev;
  764. static const int sr_latency_ns = 12000;
  765. struct drm_i915_private *dev_priv = dev->dev_private;
  766. int planea_wm, planeb_wm, planec_wm;
  767. int cursora_wm, cursorb_wm, cursorc_wm;
  768. int plane_sr, cursor_sr;
  769. int ignore_plane_sr, ignore_cursor_sr;
  770. unsigned int enabled = 0;
  771. bool cxsr_enabled;
  772. vlv_update_drain_latency(crtc);
  773. if (g4x_compute_wm0(dev, PIPE_A,
  774. &valleyview_wm_info, pessimal_latency_ns,
  775. &valleyview_cursor_wm_info, pessimal_latency_ns,
  776. &planea_wm, &cursora_wm))
  777. enabled |= 1 << PIPE_A;
  778. if (g4x_compute_wm0(dev, PIPE_B,
  779. &valleyview_wm_info, pessimal_latency_ns,
  780. &valleyview_cursor_wm_info, pessimal_latency_ns,
  781. &planeb_wm, &cursorb_wm))
  782. enabled |= 1 << PIPE_B;
  783. if (g4x_compute_wm0(dev, PIPE_C,
  784. &valleyview_wm_info, pessimal_latency_ns,
  785. &valleyview_cursor_wm_info, pessimal_latency_ns,
  786. &planec_wm, &cursorc_wm))
  787. enabled |= 1 << PIPE_C;
  788. if (single_plane_enabled(enabled) &&
  789. g4x_compute_srwm(dev, ffs(enabled) - 1,
  790. sr_latency_ns,
  791. &valleyview_wm_info,
  792. &valleyview_cursor_wm_info,
  793. &plane_sr, &ignore_cursor_sr) &&
  794. g4x_compute_srwm(dev, ffs(enabled) - 1,
  795. 2*sr_latency_ns,
  796. &valleyview_wm_info,
  797. &valleyview_cursor_wm_info,
  798. &ignore_plane_sr, &cursor_sr)) {
  799. cxsr_enabled = true;
  800. } else {
  801. cxsr_enabled = false;
  802. intel_set_memory_cxsr(dev_priv, false);
  803. plane_sr = cursor_sr = 0;
  804. }
  805. DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
  806. "B: plane=%d, cursor=%d, C: plane=%d, cursor=%d, "
  807. "SR: plane=%d, cursor=%d\n",
  808. planea_wm, cursora_wm,
  809. planeb_wm, cursorb_wm,
  810. planec_wm, cursorc_wm,
  811. plane_sr, cursor_sr);
  812. I915_WRITE(DSPFW1,
  813. (plane_sr << DSPFW_SR_SHIFT) |
  814. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  815. (planeb_wm << DSPFW_PLANEB_SHIFT) |
  816. (planea_wm << DSPFW_PLANEA_SHIFT));
  817. I915_WRITE(DSPFW2,
  818. (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) |
  819. (cursora_wm << DSPFW_CURSORA_SHIFT));
  820. I915_WRITE(DSPFW3,
  821. (I915_READ(DSPFW3) & ~DSPFW_CURSOR_SR_MASK) |
  822. (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  823. I915_WRITE(DSPFW9_CHV,
  824. (I915_READ(DSPFW9_CHV) & ~(DSPFW_PLANEC_MASK |
  825. DSPFW_CURSORC_MASK)) |
  826. (planec_wm << DSPFW_PLANEC_SHIFT) |
  827. (cursorc_wm << DSPFW_CURSORC_SHIFT));
  828. if (cxsr_enabled)
  829. intel_set_memory_cxsr(dev_priv, true);
  830. }
  831. static void valleyview_update_sprite_wm(struct drm_plane *plane,
  832. struct drm_crtc *crtc,
  833. uint32_t sprite_width,
  834. uint32_t sprite_height,
  835. int pixel_size,
  836. bool enabled, bool scaled)
  837. {
  838. struct drm_device *dev = crtc->dev;
  839. struct drm_i915_private *dev_priv = dev->dev_private;
  840. int pipe = to_intel_plane(plane)->pipe;
  841. int sprite = to_intel_plane(plane)->plane;
  842. int drain_latency;
  843. int plane_prec;
  844. int sprite_dl;
  845. int prec_mult;
  846. const int high_precision = IS_CHERRYVIEW(dev) ?
  847. DRAIN_LATENCY_PRECISION_32 : DRAIN_LATENCY_PRECISION_64;
  848. sprite_dl = I915_READ(VLV_DDL(pipe)) & ~(DDL_SPRITE_PRECISION_HIGH(sprite) |
  849. (DRAIN_LATENCY_MASK << DDL_SPRITE_SHIFT(sprite)));
  850. if (enabled && vlv_compute_drain_latency(crtc, pixel_size, &prec_mult,
  851. &drain_latency)) {
  852. plane_prec = (prec_mult == high_precision) ?
  853. DDL_SPRITE_PRECISION_HIGH(sprite) :
  854. DDL_SPRITE_PRECISION_LOW(sprite);
  855. sprite_dl |= plane_prec |
  856. (drain_latency << DDL_SPRITE_SHIFT(sprite));
  857. }
  858. I915_WRITE(VLV_DDL(pipe), sprite_dl);
  859. }
  860. static void g4x_update_wm(struct drm_crtc *crtc)
  861. {
  862. struct drm_device *dev = crtc->dev;
  863. static const int sr_latency_ns = 12000;
  864. struct drm_i915_private *dev_priv = dev->dev_private;
  865. int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
  866. int plane_sr, cursor_sr;
  867. unsigned int enabled = 0;
  868. bool cxsr_enabled;
  869. if (g4x_compute_wm0(dev, PIPE_A,
  870. &g4x_wm_info, pessimal_latency_ns,
  871. &g4x_cursor_wm_info, pessimal_latency_ns,
  872. &planea_wm, &cursora_wm))
  873. enabled |= 1 << PIPE_A;
  874. if (g4x_compute_wm0(dev, PIPE_B,
  875. &g4x_wm_info, pessimal_latency_ns,
  876. &g4x_cursor_wm_info, pessimal_latency_ns,
  877. &planeb_wm, &cursorb_wm))
  878. enabled |= 1 << PIPE_B;
  879. if (single_plane_enabled(enabled) &&
  880. g4x_compute_srwm(dev, ffs(enabled) - 1,
  881. sr_latency_ns,
  882. &g4x_wm_info,
  883. &g4x_cursor_wm_info,
  884. &plane_sr, &cursor_sr)) {
  885. cxsr_enabled = true;
  886. } else {
  887. cxsr_enabled = false;
  888. intel_set_memory_cxsr(dev_priv, false);
  889. plane_sr = cursor_sr = 0;
  890. }
  891. DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
  892. "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
  893. planea_wm, cursora_wm,
  894. planeb_wm, cursorb_wm,
  895. plane_sr, cursor_sr);
  896. I915_WRITE(DSPFW1,
  897. (plane_sr << DSPFW_SR_SHIFT) |
  898. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  899. (planeb_wm << DSPFW_PLANEB_SHIFT) |
  900. (planea_wm << DSPFW_PLANEA_SHIFT));
  901. I915_WRITE(DSPFW2,
  902. (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) |
  903. (cursora_wm << DSPFW_CURSORA_SHIFT));
  904. /* HPLL off in SR has some issues on G4x... disable it */
  905. I915_WRITE(DSPFW3,
  906. (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) |
  907. (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  908. if (cxsr_enabled)
  909. intel_set_memory_cxsr(dev_priv, true);
  910. }
  911. static void i965_update_wm(struct drm_crtc *unused_crtc)
  912. {
  913. struct drm_device *dev = unused_crtc->dev;
  914. struct drm_i915_private *dev_priv = dev->dev_private;
  915. struct drm_crtc *crtc;
  916. int srwm = 1;
  917. int cursor_sr = 16;
  918. bool cxsr_enabled;
  919. /* Calc sr entries for one plane configs */
  920. crtc = single_enabled_crtc(dev);
  921. if (crtc) {
  922. /* self-refresh has much higher latency */
  923. static const int sr_latency_ns = 12000;
  924. const struct drm_display_mode *adjusted_mode =
  925. &to_intel_crtc(crtc)->config->base.adjusted_mode;
  926. int clock = adjusted_mode->crtc_clock;
  927. int htotal = adjusted_mode->crtc_htotal;
  928. int hdisplay = to_intel_crtc(crtc)->config->pipe_src_w;
  929. int pixel_size = crtc->primary->fb->bits_per_pixel / 8;
  930. unsigned long line_time_us;
  931. int entries;
  932. line_time_us = max(htotal * 1000 / clock, 1);
  933. /* Use ns/us then divide to preserve precision */
  934. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  935. pixel_size * hdisplay;
  936. entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE);
  937. srwm = I965_FIFO_SIZE - entries;
  938. if (srwm < 0)
  939. srwm = 1;
  940. srwm &= 0x1ff;
  941. DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n",
  942. entries, srwm);
  943. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  944. pixel_size * to_intel_crtc(crtc)->cursor_width;
  945. entries = DIV_ROUND_UP(entries,
  946. i965_cursor_wm_info.cacheline_size);
  947. cursor_sr = i965_cursor_wm_info.fifo_size -
  948. (entries + i965_cursor_wm_info.guard_size);
  949. if (cursor_sr > i965_cursor_wm_info.max_wm)
  950. cursor_sr = i965_cursor_wm_info.max_wm;
  951. DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
  952. "cursor %d\n", srwm, cursor_sr);
  953. cxsr_enabled = true;
  954. } else {
  955. cxsr_enabled = false;
  956. /* Turn off self refresh if both pipes are enabled */
  957. intel_set_memory_cxsr(dev_priv, false);
  958. }
  959. DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
  960. srwm);
  961. /* 965 has limitations... */
  962. I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) |
  963. (8 << DSPFW_CURSORB_SHIFT) |
  964. (8 << DSPFW_PLANEB_SHIFT) |
  965. (8 << DSPFW_PLANEA_SHIFT));
  966. I915_WRITE(DSPFW2, (8 << DSPFW_CURSORA_SHIFT) |
  967. (8 << DSPFW_PLANEC_SHIFT_OLD));
  968. /* update cursor SR watermark */
  969. I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  970. if (cxsr_enabled)
  971. intel_set_memory_cxsr(dev_priv, true);
  972. }
  973. static void i9xx_update_wm(struct drm_crtc *unused_crtc)
  974. {
  975. struct drm_device *dev = unused_crtc->dev;
  976. struct drm_i915_private *dev_priv = dev->dev_private;
  977. const struct intel_watermark_params *wm_info;
  978. uint32_t fwater_lo;
  979. uint32_t fwater_hi;
  980. int cwm, srwm = 1;
  981. int fifo_size;
  982. int planea_wm, planeb_wm;
  983. struct drm_crtc *crtc, *enabled = NULL;
  984. if (IS_I945GM(dev))
  985. wm_info = &i945_wm_info;
  986. else if (!IS_GEN2(dev))
  987. wm_info = &i915_wm_info;
  988. else
  989. wm_info = &i830_a_wm_info;
  990. fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  991. crtc = intel_get_crtc_for_plane(dev, 0);
  992. if (intel_crtc_active(crtc)) {
  993. const struct drm_display_mode *adjusted_mode;
  994. int cpp = crtc->primary->fb->bits_per_pixel / 8;
  995. if (IS_GEN2(dev))
  996. cpp = 4;
  997. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  998. planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
  999. wm_info, fifo_size, cpp,
  1000. pessimal_latency_ns);
  1001. enabled = crtc;
  1002. } else {
  1003. planea_wm = fifo_size - wm_info->guard_size;
  1004. if (planea_wm > (long)wm_info->max_wm)
  1005. planea_wm = wm_info->max_wm;
  1006. }
  1007. if (IS_GEN2(dev))
  1008. wm_info = &i830_bc_wm_info;
  1009. fifo_size = dev_priv->display.get_fifo_size(dev, 1);
  1010. crtc = intel_get_crtc_for_plane(dev, 1);
  1011. if (intel_crtc_active(crtc)) {
  1012. const struct drm_display_mode *adjusted_mode;
  1013. int cpp = crtc->primary->fb->bits_per_pixel / 8;
  1014. if (IS_GEN2(dev))
  1015. cpp = 4;
  1016. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  1017. planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
  1018. wm_info, fifo_size, cpp,
  1019. pessimal_latency_ns);
  1020. if (enabled == NULL)
  1021. enabled = crtc;
  1022. else
  1023. enabled = NULL;
  1024. } else {
  1025. planeb_wm = fifo_size - wm_info->guard_size;
  1026. if (planeb_wm > (long)wm_info->max_wm)
  1027. planeb_wm = wm_info->max_wm;
  1028. }
  1029. DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  1030. if (IS_I915GM(dev) && enabled) {
  1031. struct drm_i915_gem_object *obj;
  1032. obj = intel_fb_obj(enabled->primary->fb);
  1033. /* self-refresh seems busted with untiled */
  1034. if (obj->tiling_mode == I915_TILING_NONE)
  1035. enabled = NULL;
  1036. }
  1037. /*
  1038. * Overlay gets an aggressive default since video jitter is bad.
  1039. */
  1040. cwm = 2;
  1041. /* Play safe and disable self-refresh before adjusting watermarks. */
  1042. intel_set_memory_cxsr(dev_priv, false);
  1043. /* Calc sr entries for one plane configs */
  1044. if (HAS_FW_BLC(dev) && enabled) {
  1045. /* self-refresh has much higher latency */
  1046. static const int sr_latency_ns = 6000;
  1047. const struct drm_display_mode *adjusted_mode =
  1048. &to_intel_crtc(enabled)->config->base.adjusted_mode;
  1049. int clock = adjusted_mode->crtc_clock;
  1050. int htotal = adjusted_mode->crtc_htotal;
  1051. int hdisplay = to_intel_crtc(enabled)->config->pipe_src_w;
  1052. int pixel_size = enabled->primary->fb->bits_per_pixel / 8;
  1053. unsigned long line_time_us;
  1054. int entries;
  1055. line_time_us = max(htotal * 1000 / clock, 1);
  1056. /* Use ns/us then divide to preserve precision */
  1057. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  1058. pixel_size * hdisplay;
  1059. entries = DIV_ROUND_UP(entries, wm_info->cacheline_size);
  1060. DRM_DEBUG_KMS("self-refresh entries: %d\n", entries);
  1061. srwm = wm_info->fifo_size - entries;
  1062. if (srwm < 0)
  1063. srwm = 1;
  1064. if (IS_I945G(dev) || IS_I945GM(dev))
  1065. I915_WRITE(FW_BLC_SELF,
  1066. FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
  1067. else if (IS_I915GM(dev))
  1068. I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
  1069. }
  1070. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
  1071. planea_wm, planeb_wm, cwm, srwm);
  1072. fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
  1073. fwater_hi = (cwm & 0x1f);
  1074. /* Set request length to 8 cachelines per fetch */
  1075. fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
  1076. fwater_hi = fwater_hi | (1 << 8);
  1077. I915_WRITE(FW_BLC, fwater_lo);
  1078. I915_WRITE(FW_BLC2, fwater_hi);
  1079. if (enabled)
  1080. intel_set_memory_cxsr(dev_priv, true);
  1081. }
  1082. static void i845_update_wm(struct drm_crtc *unused_crtc)
  1083. {
  1084. struct drm_device *dev = unused_crtc->dev;
  1085. struct drm_i915_private *dev_priv = dev->dev_private;
  1086. struct drm_crtc *crtc;
  1087. const struct drm_display_mode *adjusted_mode;
  1088. uint32_t fwater_lo;
  1089. int planea_wm;
  1090. crtc = single_enabled_crtc(dev);
  1091. if (crtc == NULL)
  1092. return;
  1093. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  1094. planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
  1095. &i845_wm_info,
  1096. dev_priv->display.get_fifo_size(dev, 0),
  1097. 4, pessimal_latency_ns);
  1098. fwater_lo = I915_READ(FW_BLC) & ~0xfff;
  1099. fwater_lo |= (3<<8) | planea_wm;
  1100. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm);
  1101. I915_WRITE(FW_BLC, fwater_lo);
  1102. }
  1103. static uint32_t ilk_pipe_pixel_rate(struct drm_device *dev,
  1104. struct drm_crtc *crtc)
  1105. {
  1106. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1107. uint32_t pixel_rate;
  1108. pixel_rate = intel_crtc->config->base.adjusted_mode.crtc_clock;
  1109. /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to
  1110. * adjust the pixel_rate here. */
  1111. if (intel_crtc->config->pch_pfit.enabled) {
  1112. uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
  1113. uint32_t pfit_size = intel_crtc->config->pch_pfit.size;
  1114. pipe_w = intel_crtc->config->pipe_src_w;
  1115. pipe_h = intel_crtc->config->pipe_src_h;
  1116. pfit_w = (pfit_size >> 16) & 0xFFFF;
  1117. pfit_h = pfit_size & 0xFFFF;
  1118. if (pipe_w < pfit_w)
  1119. pipe_w = pfit_w;
  1120. if (pipe_h < pfit_h)
  1121. pipe_h = pfit_h;
  1122. pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
  1123. pfit_w * pfit_h);
  1124. }
  1125. return pixel_rate;
  1126. }
  1127. /* latency must be in 0.1us units. */
  1128. static uint32_t ilk_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel,
  1129. uint32_t latency)
  1130. {
  1131. uint64_t ret;
  1132. if (WARN(latency == 0, "Latency value missing\n"))
  1133. return UINT_MAX;
  1134. ret = (uint64_t) pixel_rate * bytes_per_pixel * latency;
  1135. ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2;
  1136. return ret;
  1137. }
  1138. /* latency must be in 0.1us units. */
  1139. static uint32_t ilk_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal,
  1140. uint32_t horiz_pixels, uint8_t bytes_per_pixel,
  1141. uint32_t latency)
  1142. {
  1143. uint32_t ret;
  1144. if (WARN(latency == 0, "Latency value missing\n"))
  1145. return UINT_MAX;
  1146. ret = (latency * pixel_rate) / (pipe_htotal * 10000);
  1147. ret = (ret + 1) * horiz_pixels * bytes_per_pixel;
  1148. ret = DIV_ROUND_UP(ret, 64) + 2;
  1149. return ret;
  1150. }
  1151. static uint32_t ilk_wm_fbc(uint32_t pri_val, uint32_t horiz_pixels,
  1152. uint8_t bytes_per_pixel)
  1153. {
  1154. return DIV_ROUND_UP(pri_val * 64, horiz_pixels * bytes_per_pixel) + 2;
  1155. }
  1156. struct skl_pipe_wm_parameters {
  1157. bool active;
  1158. uint32_t pipe_htotal;
  1159. uint32_t pixel_rate; /* in KHz */
  1160. struct intel_plane_wm_parameters plane[I915_MAX_PLANES];
  1161. struct intel_plane_wm_parameters cursor;
  1162. };
  1163. struct ilk_pipe_wm_parameters {
  1164. bool active;
  1165. uint32_t pipe_htotal;
  1166. uint32_t pixel_rate;
  1167. struct intel_plane_wm_parameters pri;
  1168. struct intel_plane_wm_parameters spr;
  1169. struct intel_plane_wm_parameters cur;
  1170. };
  1171. struct ilk_wm_maximums {
  1172. uint16_t pri;
  1173. uint16_t spr;
  1174. uint16_t cur;
  1175. uint16_t fbc;
  1176. };
  1177. /* used in computing the new watermarks state */
  1178. struct intel_wm_config {
  1179. unsigned int num_pipes_active;
  1180. bool sprites_enabled;
  1181. bool sprites_scaled;
  1182. };
  1183. /*
  1184. * For both WM_PIPE and WM_LP.
  1185. * mem_value must be in 0.1us units.
  1186. */
  1187. static uint32_t ilk_compute_pri_wm(const struct ilk_pipe_wm_parameters *params,
  1188. uint32_t mem_value,
  1189. bool is_lp)
  1190. {
  1191. uint32_t method1, method2;
  1192. if (!params->active || !params->pri.enabled)
  1193. return 0;
  1194. method1 = ilk_wm_method1(params->pixel_rate,
  1195. params->pri.bytes_per_pixel,
  1196. mem_value);
  1197. if (!is_lp)
  1198. return method1;
  1199. method2 = ilk_wm_method2(params->pixel_rate,
  1200. params->pipe_htotal,
  1201. params->pri.horiz_pixels,
  1202. params->pri.bytes_per_pixel,
  1203. mem_value);
  1204. return min(method1, method2);
  1205. }
  1206. /*
  1207. * For both WM_PIPE and WM_LP.
  1208. * mem_value must be in 0.1us units.
  1209. */
  1210. static uint32_t ilk_compute_spr_wm(const struct ilk_pipe_wm_parameters *params,
  1211. uint32_t mem_value)
  1212. {
  1213. uint32_t method1, method2;
  1214. if (!params->active || !params->spr.enabled)
  1215. return 0;
  1216. method1 = ilk_wm_method1(params->pixel_rate,
  1217. params->spr.bytes_per_pixel,
  1218. mem_value);
  1219. method2 = ilk_wm_method2(params->pixel_rate,
  1220. params->pipe_htotal,
  1221. params->spr.horiz_pixels,
  1222. params->spr.bytes_per_pixel,
  1223. mem_value);
  1224. return min(method1, method2);
  1225. }
  1226. /*
  1227. * For both WM_PIPE and WM_LP.
  1228. * mem_value must be in 0.1us units.
  1229. */
  1230. static uint32_t ilk_compute_cur_wm(const struct ilk_pipe_wm_parameters *params,
  1231. uint32_t mem_value)
  1232. {
  1233. if (!params->active || !params->cur.enabled)
  1234. return 0;
  1235. return ilk_wm_method2(params->pixel_rate,
  1236. params->pipe_htotal,
  1237. params->cur.horiz_pixels,
  1238. params->cur.bytes_per_pixel,
  1239. mem_value);
  1240. }
  1241. /* Only for WM_LP. */
  1242. static uint32_t ilk_compute_fbc_wm(const struct ilk_pipe_wm_parameters *params,
  1243. uint32_t pri_val)
  1244. {
  1245. if (!params->active || !params->pri.enabled)
  1246. return 0;
  1247. return ilk_wm_fbc(pri_val,
  1248. params->pri.horiz_pixels,
  1249. params->pri.bytes_per_pixel);
  1250. }
  1251. static unsigned int ilk_display_fifo_size(const struct drm_device *dev)
  1252. {
  1253. if (INTEL_INFO(dev)->gen >= 8)
  1254. return 3072;
  1255. else if (INTEL_INFO(dev)->gen >= 7)
  1256. return 768;
  1257. else
  1258. return 512;
  1259. }
  1260. static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev,
  1261. int level, bool is_sprite)
  1262. {
  1263. if (INTEL_INFO(dev)->gen >= 8)
  1264. /* BDW primary/sprite plane watermarks */
  1265. return level == 0 ? 255 : 2047;
  1266. else if (INTEL_INFO(dev)->gen >= 7)
  1267. /* IVB/HSW primary/sprite plane watermarks */
  1268. return level == 0 ? 127 : 1023;
  1269. else if (!is_sprite)
  1270. /* ILK/SNB primary plane watermarks */
  1271. return level == 0 ? 127 : 511;
  1272. else
  1273. /* ILK/SNB sprite plane watermarks */
  1274. return level == 0 ? 63 : 255;
  1275. }
  1276. static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev,
  1277. int level)
  1278. {
  1279. if (INTEL_INFO(dev)->gen >= 7)
  1280. return level == 0 ? 63 : 255;
  1281. else
  1282. return level == 0 ? 31 : 63;
  1283. }
  1284. static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev)
  1285. {
  1286. if (INTEL_INFO(dev)->gen >= 8)
  1287. return 31;
  1288. else
  1289. return 15;
  1290. }
  1291. /* Calculate the maximum primary/sprite plane watermark */
  1292. static unsigned int ilk_plane_wm_max(const struct drm_device *dev,
  1293. int level,
  1294. const struct intel_wm_config *config,
  1295. enum intel_ddb_partitioning ddb_partitioning,
  1296. bool is_sprite)
  1297. {
  1298. unsigned int fifo_size = ilk_display_fifo_size(dev);
  1299. /* if sprites aren't enabled, sprites get nothing */
  1300. if (is_sprite && !config->sprites_enabled)
  1301. return 0;
  1302. /* HSW allows LP1+ watermarks even with multiple pipes */
  1303. if (level == 0 || config->num_pipes_active > 1) {
  1304. fifo_size /= INTEL_INFO(dev)->num_pipes;
  1305. /*
  1306. * For some reason the non self refresh
  1307. * FIFO size is only half of the self
  1308. * refresh FIFO size on ILK/SNB.
  1309. */
  1310. if (INTEL_INFO(dev)->gen <= 6)
  1311. fifo_size /= 2;
  1312. }
  1313. if (config->sprites_enabled) {
  1314. /* level 0 is always calculated with 1:1 split */
  1315. if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) {
  1316. if (is_sprite)
  1317. fifo_size *= 5;
  1318. fifo_size /= 6;
  1319. } else {
  1320. fifo_size /= 2;
  1321. }
  1322. }
  1323. /* clamp to max that the registers can hold */
  1324. return min(fifo_size, ilk_plane_wm_reg_max(dev, level, is_sprite));
  1325. }
  1326. /* Calculate the maximum cursor plane watermark */
  1327. static unsigned int ilk_cursor_wm_max(const struct drm_device *dev,
  1328. int level,
  1329. const struct intel_wm_config *config)
  1330. {
  1331. /* HSW LP1+ watermarks w/ multiple pipes */
  1332. if (level > 0 && config->num_pipes_active > 1)
  1333. return 64;
  1334. /* otherwise just report max that registers can hold */
  1335. return ilk_cursor_wm_reg_max(dev, level);
  1336. }
  1337. static void ilk_compute_wm_maximums(const struct drm_device *dev,
  1338. int level,
  1339. const struct intel_wm_config *config,
  1340. enum intel_ddb_partitioning ddb_partitioning,
  1341. struct ilk_wm_maximums *max)
  1342. {
  1343. max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false);
  1344. max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true);
  1345. max->cur = ilk_cursor_wm_max(dev, level, config);
  1346. max->fbc = ilk_fbc_wm_reg_max(dev);
  1347. }
  1348. static void ilk_compute_wm_reg_maximums(struct drm_device *dev,
  1349. int level,
  1350. struct ilk_wm_maximums *max)
  1351. {
  1352. max->pri = ilk_plane_wm_reg_max(dev, level, false);
  1353. max->spr = ilk_plane_wm_reg_max(dev, level, true);
  1354. max->cur = ilk_cursor_wm_reg_max(dev, level);
  1355. max->fbc = ilk_fbc_wm_reg_max(dev);
  1356. }
  1357. static bool ilk_validate_wm_level(int level,
  1358. const struct ilk_wm_maximums *max,
  1359. struct intel_wm_level *result)
  1360. {
  1361. bool ret;
  1362. /* already determined to be invalid? */
  1363. if (!result->enable)
  1364. return false;
  1365. result->enable = result->pri_val <= max->pri &&
  1366. result->spr_val <= max->spr &&
  1367. result->cur_val <= max->cur;
  1368. ret = result->enable;
  1369. /*
  1370. * HACK until we can pre-compute everything,
  1371. * and thus fail gracefully if LP0 watermarks
  1372. * are exceeded...
  1373. */
  1374. if (level == 0 && !result->enable) {
  1375. if (result->pri_val > max->pri)
  1376. DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n",
  1377. level, result->pri_val, max->pri);
  1378. if (result->spr_val > max->spr)
  1379. DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n",
  1380. level, result->spr_val, max->spr);
  1381. if (result->cur_val > max->cur)
  1382. DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n",
  1383. level, result->cur_val, max->cur);
  1384. result->pri_val = min_t(uint32_t, result->pri_val, max->pri);
  1385. result->spr_val = min_t(uint32_t, result->spr_val, max->spr);
  1386. result->cur_val = min_t(uint32_t, result->cur_val, max->cur);
  1387. result->enable = true;
  1388. }
  1389. return ret;
  1390. }
  1391. static void ilk_compute_wm_level(const struct drm_i915_private *dev_priv,
  1392. int level,
  1393. const struct ilk_pipe_wm_parameters *p,
  1394. struct intel_wm_level *result)
  1395. {
  1396. uint16_t pri_latency = dev_priv->wm.pri_latency[level];
  1397. uint16_t spr_latency = dev_priv->wm.spr_latency[level];
  1398. uint16_t cur_latency = dev_priv->wm.cur_latency[level];
  1399. /* WM1+ latency values stored in 0.5us units */
  1400. if (level > 0) {
  1401. pri_latency *= 5;
  1402. spr_latency *= 5;
  1403. cur_latency *= 5;
  1404. }
  1405. result->pri_val = ilk_compute_pri_wm(p, pri_latency, level);
  1406. result->spr_val = ilk_compute_spr_wm(p, spr_latency);
  1407. result->cur_val = ilk_compute_cur_wm(p, cur_latency);
  1408. result->fbc_val = ilk_compute_fbc_wm(p, result->pri_val);
  1409. result->enable = true;
  1410. }
  1411. static uint32_t
  1412. hsw_compute_linetime_wm(struct drm_device *dev, struct drm_crtc *crtc)
  1413. {
  1414. struct drm_i915_private *dev_priv = dev->dev_private;
  1415. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1416. struct drm_display_mode *mode = &intel_crtc->config->base.adjusted_mode;
  1417. u32 linetime, ips_linetime;
  1418. if (!intel_crtc_active(crtc))
  1419. return 0;
  1420. /* The WM are computed with base on how long it takes to fill a single
  1421. * row at the given clock rate, multiplied by 8.
  1422. * */
  1423. linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8,
  1424. mode->crtc_clock);
  1425. ips_linetime = DIV_ROUND_CLOSEST(mode->crtc_htotal * 1000 * 8,
  1426. intel_ddi_get_cdclk_freq(dev_priv));
  1427. return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) |
  1428. PIPE_WM_LINETIME_TIME(linetime);
  1429. }
  1430. static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[8])
  1431. {
  1432. struct drm_i915_private *dev_priv = dev->dev_private;
  1433. if (IS_GEN9(dev)) {
  1434. uint32_t val;
  1435. int ret, i;
  1436. int level, max_level = ilk_wm_max_level(dev);
  1437. /* read the first set of memory latencies[0:3] */
  1438. val = 0; /* data0 to be programmed to 0 for first set */
  1439. mutex_lock(&dev_priv->rps.hw_lock);
  1440. ret = sandybridge_pcode_read(dev_priv,
  1441. GEN9_PCODE_READ_MEM_LATENCY,
  1442. &val);
  1443. mutex_unlock(&dev_priv->rps.hw_lock);
  1444. if (ret) {
  1445. DRM_ERROR("SKL Mailbox read error = %d\n", ret);
  1446. return;
  1447. }
  1448. wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK;
  1449. wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
  1450. GEN9_MEM_LATENCY_LEVEL_MASK;
  1451. wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
  1452. GEN9_MEM_LATENCY_LEVEL_MASK;
  1453. wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
  1454. GEN9_MEM_LATENCY_LEVEL_MASK;
  1455. /* read the second set of memory latencies[4:7] */
  1456. val = 1; /* data0 to be programmed to 1 for second set */
  1457. mutex_lock(&dev_priv->rps.hw_lock);
  1458. ret = sandybridge_pcode_read(dev_priv,
  1459. GEN9_PCODE_READ_MEM_LATENCY,
  1460. &val);
  1461. mutex_unlock(&dev_priv->rps.hw_lock);
  1462. if (ret) {
  1463. DRM_ERROR("SKL Mailbox read error = %d\n", ret);
  1464. return;
  1465. }
  1466. wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK;
  1467. wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
  1468. GEN9_MEM_LATENCY_LEVEL_MASK;
  1469. wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
  1470. GEN9_MEM_LATENCY_LEVEL_MASK;
  1471. wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
  1472. GEN9_MEM_LATENCY_LEVEL_MASK;
  1473. /*
  1474. * WaWmMemoryReadLatency:skl
  1475. *
  1476. * punit doesn't take into account the read latency so we need
  1477. * to add 2us to the various latency levels we retrieve from
  1478. * the punit.
  1479. * - W0 is a bit special in that it's the only level that
  1480. * can't be disabled if we want to have display working, so
  1481. * we always add 2us there.
  1482. * - For levels >=1, punit returns 0us latency when they are
  1483. * disabled, so we respect that and don't add 2us then
  1484. *
  1485. * Additionally, if a level n (n > 1) has a 0us latency, all
  1486. * levels m (m >= n) need to be disabled. We make sure to
  1487. * sanitize the values out of the punit to satisfy this
  1488. * requirement.
  1489. */
  1490. wm[0] += 2;
  1491. for (level = 1; level <= max_level; level++)
  1492. if (wm[level] != 0)
  1493. wm[level] += 2;
  1494. else {
  1495. for (i = level + 1; i <= max_level; i++)
  1496. wm[i] = 0;
  1497. break;
  1498. }
  1499. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  1500. uint64_t sskpd = I915_READ64(MCH_SSKPD);
  1501. wm[0] = (sskpd >> 56) & 0xFF;
  1502. if (wm[0] == 0)
  1503. wm[0] = sskpd & 0xF;
  1504. wm[1] = (sskpd >> 4) & 0xFF;
  1505. wm[2] = (sskpd >> 12) & 0xFF;
  1506. wm[3] = (sskpd >> 20) & 0x1FF;
  1507. wm[4] = (sskpd >> 32) & 0x1FF;
  1508. } else if (INTEL_INFO(dev)->gen >= 6) {
  1509. uint32_t sskpd = I915_READ(MCH_SSKPD);
  1510. wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK;
  1511. wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK;
  1512. wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK;
  1513. wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK;
  1514. } else if (INTEL_INFO(dev)->gen >= 5) {
  1515. uint32_t mltr = I915_READ(MLTR_ILK);
  1516. /* ILK primary LP0 latency is 700 ns */
  1517. wm[0] = 7;
  1518. wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK;
  1519. wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK;
  1520. }
  1521. }
  1522. static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5])
  1523. {
  1524. /* ILK sprite LP0 latency is 1300 ns */
  1525. if (INTEL_INFO(dev)->gen == 5)
  1526. wm[0] = 13;
  1527. }
  1528. static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5])
  1529. {
  1530. /* ILK cursor LP0 latency is 1300 ns */
  1531. if (INTEL_INFO(dev)->gen == 5)
  1532. wm[0] = 13;
  1533. /* WaDoubleCursorLP3Latency:ivb */
  1534. if (IS_IVYBRIDGE(dev))
  1535. wm[3] *= 2;
  1536. }
  1537. int ilk_wm_max_level(const struct drm_device *dev)
  1538. {
  1539. /* how many WM levels are we expecting */
  1540. if (IS_GEN9(dev))
  1541. return 7;
  1542. else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  1543. return 4;
  1544. else if (INTEL_INFO(dev)->gen >= 6)
  1545. return 3;
  1546. else
  1547. return 2;
  1548. }
  1549. static void intel_print_wm_latency(struct drm_device *dev,
  1550. const char *name,
  1551. const uint16_t wm[8])
  1552. {
  1553. int level, max_level = ilk_wm_max_level(dev);
  1554. for (level = 0; level <= max_level; level++) {
  1555. unsigned int latency = wm[level];
  1556. if (latency == 0) {
  1557. DRM_ERROR("%s WM%d latency not provided\n",
  1558. name, level);
  1559. continue;
  1560. }
  1561. /*
  1562. * - latencies are in us on gen9.
  1563. * - before then, WM1+ latency values are in 0.5us units
  1564. */
  1565. if (IS_GEN9(dev))
  1566. latency *= 10;
  1567. else if (level > 0)
  1568. latency *= 5;
  1569. DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n",
  1570. name, level, wm[level],
  1571. latency / 10, latency % 10);
  1572. }
  1573. }
  1574. static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv,
  1575. uint16_t wm[5], uint16_t min)
  1576. {
  1577. int level, max_level = ilk_wm_max_level(dev_priv->dev);
  1578. if (wm[0] >= min)
  1579. return false;
  1580. wm[0] = max(wm[0], min);
  1581. for (level = 1; level <= max_level; level++)
  1582. wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5));
  1583. return true;
  1584. }
  1585. static void snb_wm_latency_quirk(struct drm_device *dev)
  1586. {
  1587. struct drm_i915_private *dev_priv = dev->dev_private;
  1588. bool changed;
  1589. /*
  1590. * The BIOS provided WM memory latency values are often
  1591. * inadequate for high resolution displays. Adjust them.
  1592. */
  1593. changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) |
  1594. ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) |
  1595. ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12);
  1596. if (!changed)
  1597. return;
  1598. DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n");
  1599. intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency);
  1600. intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency);
  1601. intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency);
  1602. }
  1603. static void ilk_setup_wm_latency(struct drm_device *dev)
  1604. {
  1605. struct drm_i915_private *dev_priv = dev->dev_private;
  1606. intel_read_wm_latency(dev, dev_priv->wm.pri_latency);
  1607. memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency,
  1608. sizeof(dev_priv->wm.pri_latency));
  1609. memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency,
  1610. sizeof(dev_priv->wm.pri_latency));
  1611. intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency);
  1612. intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency);
  1613. intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency);
  1614. intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency);
  1615. intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency);
  1616. if (IS_GEN6(dev))
  1617. snb_wm_latency_quirk(dev);
  1618. }
  1619. static void skl_setup_wm_latency(struct drm_device *dev)
  1620. {
  1621. struct drm_i915_private *dev_priv = dev->dev_private;
  1622. intel_read_wm_latency(dev, dev_priv->wm.skl_latency);
  1623. intel_print_wm_latency(dev, "Gen9 Plane", dev_priv->wm.skl_latency);
  1624. }
  1625. static void ilk_compute_wm_parameters(struct drm_crtc *crtc,
  1626. struct ilk_pipe_wm_parameters *p)
  1627. {
  1628. struct drm_device *dev = crtc->dev;
  1629. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1630. enum pipe pipe = intel_crtc->pipe;
  1631. struct drm_plane *plane;
  1632. if (!intel_crtc_active(crtc))
  1633. return;
  1634. p->active = true;
  1635. p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal;
  1636. p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc);
  1637. p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8;
  1638. p->cur.bytes_per_pixel = 4;
  1639. p->pri.horiz_pixels = intel_crtc->config->pipe_src_w;
  1640. p->cur.horiz_pixels = intel_crtc->cursor_width;
  1641. /* TODO: for now, assume primary and cursor planes are always enabled. */
  1642. p->pri.enabled = true;
  1643. p->cur.enabled = true;
  1644. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  1645. struct intel_plane *intel_plane = to_intel_plane(plane);
  1646. if (intel_plane->pipe == pipe) {
  1647. p->spr = intel_plane->wm;
  1648. break;
  1649. }
  1650. }
  1651. }
  1652. static void ilk_compute_wm_config(struct drm_device *dev,
  1653. struct intel_wm_config *config)
  1654. {
  1655. struct intel_crtc *intel_crtc;
  1656. /* Compute the currently _active_ config */
  1657. for_each_intel_crtc(dev, intel_crtc) {
  1658. const struct intel_pipe_wm *wm = &intel_crtc->wm.active;
  1659. if (!wm->pipe_enabled)
  1660. continue;
  1661. config->sprites_enabled |= wm->sprites_enabled;
  1662. config->sprites_scaled |= wm->sprites_scaled;
  1663. config->num_pipes_active++;
  1664. }
  1665. }
  1666. /* Compute new watermarks for the pipe */
  1667. static bool intel_compute_pipe_wm(struct drm_crtc *crtc,
  1668. const struct ilk_pipe_wm_parameters *params,
  1669. struct intel_pipe_wm *pipe_wm)
  1670. {
  1671. struct drm_device *dev = crtc->dev;
  1672. const struct drm_i915_private *dev_priv = dev->dev_private;
  1673. int level, max_level = ilk_wm_max_level(dev);
  1674. /* LP0 watermark maximums depend on this pipe alone */
  1675. struct intel_wm_config config = {
  1676. .num_pipes_active = 1,
  1677. .sprites_enabled = params->spr.enabled,
  1678. .sprites_scaled = params->spr.scaled,
  1679. };
  1680. struct ilk_wm_maximums max;
  1681. pipe_wm->pipe_enabled = params->active;
  1682. pipe_wm->sprites_enabled = params->spr.enabled;
  1683. pipe_wm->sprites_scaled = params->spr.scaled;
  1684. /* ILK/SNB: LP2+ watermarks only w/o sprites */
  1685. if (INTEL_INFO(dev)->gen <= 6 && params->spr.enabled)
  1686. max_level = 1;
  1687. /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */
  1688. if (params->spr.scaled)
  1689. max_level = 0;
  1690. ilk_compute_wm_level(dev_priv, 0, params, &pipe_wm->wm[0]);
  1691. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  1692. pipe_wm->linetime = hsw_compute_linetime_wm(dev, crtc);
  1693. /* LP0 watermarks always use 1/2 DDB partitioning */
  1694. ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max);
  1695. /* At least LP0 must be valid */
  1696. if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0]))
  1697. return false;
  1698. ilk_compute_wm_reg_maximums(dev, 1, &max);
  1699. for (level = 1; level <= max_level; level++) {
  1700. struct intel_wm_level wm = {};
  1701. ilk_compute_wm_level(dev_priv, level, params, &wm);
  1702. /*
  1703. * Disable any watermark level that exceeds the
  1704. * register maximums since such watermarks are
  1705. * always invalid.
  1706. */
  1707. if (!ilk_validate_wm_level(level, &max, &wm))
  1708. break;
  1709. pipe_wm->wm[level] = wm;
  1710. }
  1711. return true;
  1712. }
  1713. /*
  1714. * Merge the watermarks from all active pipes for a specific level.
  1715. */
  1716. static void ilk_merge_wm_level(struct drm_device *dev,
  1717. int level,
  1718. struct intel_wm_level *ret_wm)
  1719. {
  1720. const struct intel_crtc *intel_crtc;
  1721. ret_wm->enable = true;
  1722. for_each_intel_crtc(dev, intel_crtc) {
  1723. const struct intel_pipe_wm *active = &intel_crtc->wm.active;
  1724. const struct intel_wm_level *wm = &active->wm[level];
  1725. if (!active->pipe_enabled)
  1726. continue;
  1727. /*
  1728. * The watermark values may have been used in the past,
  1729. * so we must maintain them in the registers for some
  1730. * time even if the level is now disabled.
  1731. */
  1732. if (!wm->enable)
  1733. ret_wm->enable = false;
  1734. ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val);
  1735. ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val);
  1736. ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val);
  1737. ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val);
  1738. }
  1739. }
  1740. /*
  1741. * Merge all low power watermarks for all active pipes.
  1742. */
  1743. static void ilk_wm_merge(struct drm_device *dev,
  1744. const struct intel_wm_config *config,
  1745. const struct ilk_wm_maximums *max,
  1746. struct intel_pipe_wm *merged)
  1747. {
  1748. int level, max_level = ilk_wm_max_level(dev);
  1749. int last_enabled_level = max_level;
  1750. /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */
  1751. if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) &&
  1752. config->num_pipes_active > 1)
  1753. return;
  1754. /* ILK: FBC WM must be disabled always */
  1755. merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6;
  1756. /* merge each WM1+ level */
  1757. for (level = 1; level <= max_level; level++) {
  1758. struct intel_wm_level *wm = &merged->wm[level];
  1759. ilk_merge_wm_level(dev, level, wm);
  1760. if (level > last_enabled_level)
  1761. wm->enable = false;
  1762. else if (!ilk_validate_wm_level(level, max, wm))
  1763. /* make sure all following levels get disabled */
  1764. last_enabled_level = level - 1;
  1765. /*
  1766. * The spec says it is preferred to disable
  1767. * FBC WMs instead of disabling a WM level.
  1768. */
  1769. if (wm->fbc_val > max->fbc) {
  1770. if (wm->enable)
  1771. merged->fbc_wm_enabled = false;
  1772. wm->fbc_val = 0;
  1773. }
  1774. }
  1775. /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */
  1776. /*
  1777. * FIXME this is racy. FBC might get enabled later.
  1778. * What we should check here is whether FBC can be
  1779. * enabled sometime later.
  1780. */
  1781. if (IS_GEN5(dev) && !merged->fbc_wm_enabled && intel_fbc_enabled(dev)) {
  1782. for (level = 2; level <= max_level; level++) {
  1783. struct intel_wm_level *wm = &merged->wm[level];
  1784. wm->enable = false;
  1785. }
  1786. }
  1787. }
  1788. static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm)
  1789. {
  1790. /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */
  1791. return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable);
  1792. }
  1793. /* The value we need to program into the WM_LPx latency field */
  1794. static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level)
  1795. {
  1796. struct drm_i915_private *dev_priv = dev->dev_private;
  1797. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  1798. return 2 * level;
  1799. else
  1800. return dev_priv->wm.pri_latency[level];
  1801. }
  1802. static void ilk_compute_wm_results(struct drm_device *dev,
  1803. const struct intel_pipe_wm *merged,
  1804. enum intel_ddb_partitioning partitioning,
  1805. struct ilk_wm_values *results)
  1806. {
  1807. struct intel_crtc *intel_crtc;
  1808. int level, wm_lp;
  1809. results->enable_fbc_wm = merged->fbc_wm_enabled;
  1810. results->partitioning = partitioning;
  1811. /* LP1+ register values */
  1812. for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
  1813. const struct intel_wm_level *r;
  1814. level = ilk_wm_lp_to_level(wm_lp, merged);
  1815. r = &merged->wm[level];
  1816. /*
  1817. * Maintain the watermark values even if the level is
  1818. * disabled. Doing otherwise could cause underruns.
  1819. */
  1820. results->wm_lp[wm_lp - 1] =
  1821. (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) |
  1822. (r->pri_val << WM1_LP_SR_SHIFT) |
  1823. r->cur_val;
  1824. if (r->enable)
  1825. results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN;
  1826. if (INTEL_INFO(dev)->gen >= 8)
  1827. results->wm_lp[wm_lp - 1] |=
  1828. r->fbc_val << WM1_LP_FBC_SHIFT_BDW;
  1829. else
  1830. results->wm_lp[wm_lp - 1] |=
  1831. r->fbc_val << WM1_LP_FBC_SHIFT;
  1832. /*
  1833. * Always set WM1S_LP_EN when spr_val != 0, even if the
  1834. * level is disabled. Doing otherwise could cause underruns.
  1835. */
  1836. if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) {
  1837. WARN_ON(wm_lp != 1);
  1838. results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val;
  1839. } else
  1840. results->wm_lp_spr[wm_lp - 1] = r->spr_val;
  1841. }
  1842. /* LP0 register values */
  1843. for_each_intel_crtc(dev, intel_crtc) {
  1844. enum pipe pipe = intel_crtc->pipe;
  1845. const struct intel_wm_level *r =
  1846. &intel_crtc->wm.active.wm[0];
  1847. if (WARN_ON(!r->enable))
  1848. continue;
  1849. results->wm_linetime[pipe] = intel_crtc->wm.active.linetime;
  1850. results->wm_pipe[pipe] =
  1851. (r->pri_val << WM0_PIPE_PLANE_SHIFT) |
  1852. (r->spr_val << WM0_PIPE_SPRITE_SHIFT) |
  1853. r->cur_val;
  1854. }
  1855. }
  1856. /* Find the result with the highest level enabled. Check for enable_fbc_wm in
  1857. * case both are at the same level. Prefer r1 in case they're the same. */
  1858. static struct intel_pipe_wm *ilk_find_best_result(struct drm_device *dev,
  1859. struct intel_pipe_wm *r1,
  1860. struct intel_pipe_wm *r2)
  1861. {
  1862. int level, max_level = ilk_wm_max_level(dev);
  1863. int level1 = 0, level2 = 0;
  1864. for (level = 1; level <= max_level; level++) {
  1865. if (r1->wm[level].enable)
  1866. level1 = level;
  1867. if (r2->wm[level].enable)
  1868. level2 = level;
  1869. }
  1870. if (level1 == level2) {
  1871. if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled)
  1872. return r2;
  1873. else
  1874. return r1;
  1875. } else if (level1 > level2) {
  1876. return r1;
  1877. } else {
  1878. return r2;
  1879. }
  1880. }
  1881. /* dirty bits used to track which watermarks need changes */
  1882. #define WM_DIRTY_PIPE(pipe) (1 << (pipe))
  1883. #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe)))
  1884. #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp)))
  1885. #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3))
  1886. #define WM_DIRTY_FBC (1 << 24)
  1887. #define WM_DIRTY_DDB (1 << 25)
  1888. static unsigned int ilk_compute_wm_dirty(struct drm_i915_private *dev_priv,
  1889. const struct ilk_wm_values *old,
  1890. const struct ilk_wm_values *new)
  1891. {
  1892. unsigned int dirty = 0;
  1893. enum pipe pipe;
  1894. int wm_lp;
  1895. for_each_pipe(dev_priv, pipe) {
  1896. if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) {
  1897. dirty |= WM_DIRTY_LINETIME(pipe);
  1898. /* Must disable LP1+ watermarks too */
  1899. dirty |= WM_DIRTY_LP_ALL;
  1900. }
  1901. if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) {
  1902. dirty |= WM_DIRTY_PIPE(pipe);
  1903. /* Must disable LP1+ watermarks too */
  1904. dirty |= WM_DIRTY_LP_ALL;
  1905. }
  1906. }
  1907. if (old->enable_fbc_wm != new->enable_fbc_wm) {
  1908. dirty |= WM_DIRTY_FBC;
  1909. /* Must disable LP1+ watermarks too */
  1910. dirty |= WM_DIRTY_LP_ALL;
  1911. }
  1912. if (old->partitioning != new->partitioning) {
  1913. dirty |= WM_DIRTY_DDB;
  1914. /* Must disable LP1+ watermarks too */
  1915. dirty |= WM_DIRTY_LP_ALL;
  1916. }
  1917. /* LP1+ watermarks already deemed dirty, no need to continue */
  1918. if (dirty & WM_DIRTY_LP_ALL)
  1919. return dirty;
  1920. /* Find the lowest numbered LP1+ watermark in need of an update... */
  1921. for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
  1922. if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] ||
  1923. old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1])
  1924. break;
  1925. }
  1926. /* ...and mark it and all higher numbered LP1+ watermarks as dirty */
  1927. for (; wm_lp <= 3; wm_lp++)
  1928. dirty |= WM_DIRTY_LP(wm_lp);
  1929. return dirty;
  1930. }
  1931. static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv,
  1932. unsigned int dirty)
  1933. {
  1934. struct ilk_wm_values *previous = &dev_priv->wm.hw;
  1935. bool changed = false;
  1936. if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) {
  1937. previous->wm_lp[2] &= ~WM1_LP_SR_EN;
  1938. I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]);
  1939. changed = true;
  1940. }
  1941. if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) {
  1942. previous->wm_lp[1] &= ~WM1_LP_SR_EN;
  1943. I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]);
  1944. changed = true;
  1945. }
  1946. if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) {
  1947. previous->wm_lp[0] &= ~WM1_LP_SR_EN;
  1948. I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]);
  1949. changed = true;
  1950. }
  1951. /*
  1952. * Don't touch WM1S_LP_EN here.
  1953. * Doing so could cause underruns.
  1954. */
  1955. return changed;
  1956. }
  1957. /*
  1958. * The spec says we shouldn't write when we don't need, because every write
  1959. * causes WMs to be re-evaluated, expending some power.
  1960. */
  1961. static void ilk_write_wm_values(struct drm_i915_private *dev_priv,
  1962. struct ilk_wm_values *results)
  1963. {
  1964. struct drm_device *dev = dev_priv->dev;
  1965. struct ilk_wm_values *previous = &dev_priv->wm.hw;
  1966. unsigned int dirty;
  1967. uint32_t val;
  1968. dirty = ilk_compute_wm_dirty(dev_priv, previous, results);
  1969. if (!dirty)
  1970. return;
  1971. _ilk_disable_lp_wm(dev_priv, dirty);
  1972. if (dirty & WM_DIRTY_PIPE(PIPE_A))
  1973. I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]);
  1974. if (dirty & WM_DIRTY_PIPE(PIPE_B))
  1975. I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]);
  1976. if (dirty & WM_DIRTY_PIPE(PIPE_C))
  1977. I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]);
  1978. if (dirty & WM_DIRTY_LINETIME(PIPE_A))
  1979. I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]);
  1980. if (dirty & WM_DIRTY_LINETIME(PIPE_B))
  1981. I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]);
  1982. if (dirty & WM_DIRTY_LINETIME(PIPE_C))
  1983. I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]);
  1984. if (dirty & WM_DIRTY_DDB) {
  1985. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  1986. val = I915_READ(WM_MISC);
  1987. if (results->partitioning == INTEL_DDB_PART_1_2)
  1988. val &= ~WM_MISC_DATA_PARTITION_5_6;
  1989. else
  1990. val |= WM_MISC_DATA_PARTITION_5_6;
  1991. I915_WRITE(WM_MISC, val);
  1992. } else {
  1993. val = I915_READ(DISP_ARB_CTL2);
  1994. if (results->partitioning == INTEL_DDB_PART_1_2)
  1995. val &= ~DISP_DATA_PARTITION_5_6;
  1996. else
  1997. val |= DISP_DATA_PARTITION_5_6;
  1998. I915_WRITE(DISP_ARB_CTL2, val);
  1999. }
  2000. }
  2001. if (dirty & WM_DIRTY_FBC) {
  2002. val = I915_READ(DISP_ARB_CTL);
  2003. if (results->enable_fbc_wm)
  2004. val &= ~DISP_FBC_WM_DIS;
  2005. else
  2006. val |= DISP_FBC_WM_DIS;
  2007. I915_WRITE(DISP_ARB_CTL, val);
  2008. }
  2009. if (dirty & WM_DIRTY_LP(1) &&
  2010. previous->wm_lp_spr[0] != results->wm_lp_spr[0])
  2011. I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]);
  2012. if (INTEL_INFO(dev)->gen >= 7) {
  2013. if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1])
  2014. I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]);
  2015. if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2])
  2016. I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]);
  2017. }
  2018. if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] != results->wm_lp[0])
  2019. I915_WRITE(WM1_LP_ILK, results->wm_lp[0]);
  2020. if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] != results->wm_lp[1])
  2021. I915_WRITE(WM2_LP_ILK, results->wm_lp[1]);
  2022. if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] != results->wm_lp[2])
  2023. I915_WRITE(WM3_LP_ILK, results->wm_lp[2]);
  2024. dev_priv->wm.hw = *results;
  2025. }
  2026. static bool ilk_disable_lp_wm(struct drm_device *dev)
  2027. {
  2028. struct drm_i915_private *dev_priv = dev->dev_private;
  2029. return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL);
  2030. }
  2031. /*
  2032. * On gen9, we need to allocate Display Data Buffer (DDB) portions to the
  2033. * different active planes.
  2034. */
  2035. #define SKL_DDB_SIZE 896 /* in blocks */
  2036. static void
  2037. skl_ddb_get_pipe_allocation_limits(struct drm_device *dev,
  2038. struct drm_crtc *for_crtc,
  2039. const struct intel_wm_config *config,
  2040. const struct skl_pipe_wm_parameters *params,
  2041. struct skl_ddb_entry *alloc /* out */)
  2042. {
  2043. struct drm_crtc *crtc;
  2044. unsigned int pipe_size, ddb_size;
  2045. int nth_active_pipe;
  2046. if (!params->active) {
  2047. alloc->start = 0;
  2048. alloc->end = 0;
  2049. return;
  2050. }
  2051. ddb_size = SKL_DDB_SIZE;
  2052. ddb_size -= 4; /* 4 blocks for bypass path allocation */
  2053. nth_active_pipe = 0;
  2054. for_each_crtc(dev, crtc) {
  2055. if (!intel_crtc_active(crtc))
  2056. continue;
  2057. if (crtc == for_crtc)
  2058. break;
  2059. nth_active_pipe++;
  2060. }
  2061. pipe_size = ddb_size / config->num_pipes_active;
  2062. alloc->start = nth_active_pipe * ddb_size / config->num_pipes_active;
  2063. alloc->end = alloc->start + pipe_size;
  2064. }
  2065. static unsigned int skl_cursor_allocation(const struct intel_wm_config *config)
  2066. {
  2067. if (config->num_pipes_active == 1)
  2068. return 32;
  2069. return 8;
  2070. }
  2071. static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg)
  2072. {
  2073. entry->start = reg & 0x3ff;
  2074. entry->end = (reg >> 16) & 0x3ff;
  2075. if (entry->end)
  2076. entry->end += 1;
  2077. }
  2078. void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv,
  2079. struct skl_ddb_allocation *ddb /* out */)
  2080. {
  2081. struct drm_device *dev = dev_priv->dev;
  2082. enum pipe pipe;
  2083. int plane;
  2084. u32 val;
  2085. for_each_pipe(dev_priv, pipe) {
  2086. for_each_plane(pipe, plane) {
  2087. val = I915_READ(PLANE_BUF_CFG(pipe, plane));
  2088. skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane],
  2089. val);
  2090. }
  2091. val = I915_READ(CUR_BUF_CFG(pipe));
  2092. skl_ddb_entry_init_from_hw(&ddb->cursor[pipe], val);
  2093. }
  2094. }
  2095. static unsigned int
  2096. skl_plane_relative_data_rate(const struct intel_plane_wm_parameters *p)
  2097. {
  2098. return p->horiz_pixels * p->vert_pixels * p->bytes_per_pixel;
  2099. }
  2100. /*
  2101. * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching
  2102. * a 8192x4096@32bpp framebuffer:
  2103. * 3 * 4096 * 8192 * 4 < 2^32
  2104. */
  2105. static unsigned int
  2106. skl_get_total_relative_data_rate(struct intel_crtc *intel_crtc,
  2107. const struct skl_pipe_wm_parameters *params)
  2108. {
  2109. unsigned int total_data_rate = 0;
  2110. int plane;
  2111. for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) {
  2112. const struct intel_plane_wm_parameters *p;
  2113. p = &params->plane[plane];
  2114. if (!p->enabled)
  2115. continue;
  2116. total_data_rate += skl_plane_relative_data_rate(p);
  2117. }
  2118. return total_data_rate;
  2119. }
  2120. static void
  2121. skl_allocate_pipe_ddb(struct drm_crtc *crtc,
  2122. const struct intel_wm_config *config,
  2123. const struct skl_pipe_wm_parameters *params,
  2124. struct skl_ddb_allocation *ddb /* out */)
  2125. {
  2126. struct drm_device *dev = crtc->dev;
  2127. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2128. enum pipe pipe = intel_crtc->pipe;
  2129. struct skl_ddb_entry *alloc = &ddb->pipe[pipe];
  2130. uint16_t alloc_size, start, cursor_blocks;
  2131. unsigned int total_data_rate;
  2132. int plane;
  2133. skl_ddb_get_pipe_allocation_limits(dev, crtc, config, params, alloc);
  2134. alloc_size = skl_ddb_entry_size(alloc);
  2135. if (alloc_size == 0) {
  2136. memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe]));
  2137. memset(&ddb->cursor[pipe], 0, sizeof(ddb->cursor[pipe]));
  2138. return;
  2139. }
  2140. cursor_blocks = skl_cursor_allocation(config);
  2141. ddb->cursor[pipe].start = alloc->end - cursor_blocks;
  2142. ddb->cursor[pipe].end = alloc->end;
  2143. alloc_size -= cursor_blocks;
  2144. alloc->end -= cursor_blocks;
  2145. /*
  2146. * Each active plane get a portion of the remaining space, in
  2147. * proportion to the amount of data they need to fetch from memory.
  2148. *
  2149. * FIXME: we may not allocate every single block here.
  2150. */
  2151. total_data_rate = skl_get_total_relative_data_rate(intel_crtc, params);
  2152. start = alloc->start;
  2153. for (plane = 0; plane < intel_num_planes(intel_crtc); plane++) {
  2154. const struct intel_plane_wm_parameters *p;
  2155. unsigned int data_rate;
  2156. uint16_t plane_blocks;
  2157. p = &params->plane[plane];
  2158. if (!p->enabled)
  2159. continue;
  2160. data_rate = skl_plane_relative_data_rate(p);
  2161. /*
  2162. * promote the expression to 64 bits to avoid overflowing, the
  2163. * result is < available as data_rate / total_data_rate < 1
  2164. */
  2165. plane_blocks = div_u64((uint64_t)alloc_size * data_rate,
  2166. total_data_rate);
  2167. ddb->plane[pipe][plane].start = start;
  2168. ddb->plane[pipe][plane].end = start + plane_blocks;
  2169. start += plane_blocks;
  2170. }
  2171. }
  2172. static uint32_t skl_pipe_pixel_rate(const struct intel_crtc_state *config)
  2173. {
  2174. /* TODO: Take into account the scalers once we support them */
  2175. return config->base.adjusted_mode.crtc_clock;
  2176. }
  2177. /*
  2178. * The max latency should be 257 (max the punit can code is 255 and we add 2us
  2179. * for the read latency) and bytes_per_pixel should always be <= 8, so that
  2180. * should allow pixel_rate up to ~2 GHz which seems sufficient since max
  2181. * 2xcdclk is 1350 MHz and the pixel rate should never exceed that.
  2182. */
  2183. static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t bytes_per_pixel,
  2184. uint32_t latency)
  2185. {
  2186. uint32_t wm_intermediate_val, ret;
  2187. if (latency == 0)
  2188. return UINT_MAX;
  2189. wm_intermediate_val = latency * pixel_rate * bytes_per_pixel;
  2190. ret = DIV_ROUND_UP(wm_intermediate_val, 1000);
  2191. return ret;
  2192. }
  2193. static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal,
  2194. uint32_t horiz_pixels, uint8_t bytes_per_pixel,
  2195. uint32_t latency)
  2196. {
  2197. uint32_t ret, plane_bytes_per_line, wm_intermediate_val;
  2198. if (latency == 0)
  2199. return UINT_MAX;
  2200. plane_bytes_per_line = horiz_pixels * bytes_per_pixel;
  2201. wm_intermediate_val = latency * pixel_rate;
  2202. ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) *
  2203. plane_bytes_per_line;
  2204. return ret;
  2205. }
  2206. static bool skl_ddb_allocation_changed(const struct skl_ddb_allocation *new_ddb,
  2207. const struct intel_crtc *intel_crtc)
  2208. {
  2209. struct drm_device *dev = intel_crtc->base.dev;
  2210. struct drm_i915_private *dev_priv = dev->dev_private;
  2211. const struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb;
  2212. enum pipe pipe = intel_crtc->pipe;
  2213. if (memcmp(new_ddb->plane[pipe], cur_ddb->plane[pipe],
  2214. sizeof(new_ddb->plane[pipe])))
  2215. return true;
  2216. if (memcmp(&new_ddb->cursor[pipe], &cur_ddb->cursor[pipe],
  2217. sizeof(new_ddb->cursor[pipe])))
  2218. return true;
  2219. return false;
  2220. }
  2221. static void skl_compute_wm_global_parameters(struct drm_device *dev,
  2222. struct intel_wm_config *config)
  2223. {
  2224. struct drm_crtc *crtc;
  2225. struct drm_plane *plane;
  2226. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  2227. config->num_pipes_active += intel_crtc_active(crtc);
  2228. /* FIXME: I don't think we need those two global parameters on SKL */
  2229. list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
  2230. struct intel_plane *intel_plane = to_intel_plane(plane);
  2231. config->sprites_enabled |= intel_plane->wm.enabled;
  2232. config->sprites_scaled |= intel_plane->wm.scaled;
  2233. }
  2234. }
  2235. static void skl_compute_wm_pipe_parameters(struct drm_crtc *crtc,
  2236. struct skl_pipe_wm_parameters *p)
  2237. {
  2238. struct drm_device *dev = crtc->dev;
  2239. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2240. enum pipe pipe = intel_crtc->pipe;
  2241. struct drm_plane *plane;
  2242. int i = 1; /* Index for sprite planes start */
  2243. p->active = intel_crtc_active(crtc);
  2244. if (p->active) {
  2245. p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal;
  2246. p->pixel_rate = skl_pipe_pixel_rate(intel_crtc->config);
  2247. /*
  2248. * For now, assume primary and cursor planes are always enabled.
  2249. */
  2250. p->plane[0].enabled = true;
  2251. p->plane[0].bytes_per_pixel =
  2252. crtc->primary->fb->bits_per_pixel / 8;
  2253. p->plane[0].horiz_pixels = intel_crtc->config->pipe_src_w;
  2254. p->plane[0].vert_pixels = intel_crtc->config->pipe_src_h;
  2255. p->cursor.enabled = true;
  2256. p->cursor.bytes_per_pixel = 4;
  2257. p->cursor.horiz_pixels = intel_crtc->cursor_width ?
  2258. intel_crtc->cursor_width : 64;
  2259. }
  2260. list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
  2261. struct intel_plane *intel_plane = to_intel_plane(plane);
  2262. if (intel_plane->pipe == pipe &&
  2263. plane->type == DRM_PLANE_TYPE_OVERLAY)
  2264. p->plane[i++] = intel_plane->wm;
  2265. }
  2266. }
  2267. static bool skl_compute_plane_wm(struct skl_pipe_wm_parameters *p,
  2268. struct intel_plane_wm_parameters *p_params,
  2269. uint16_t ddb_allocation,
  2270. uint32_t mem_value,
  2271. uint16_t *out_blocks, /* out */
  2272. uint8_t *out_lines /* out */)
  2273. {
  2274. uint32_t method1, method2, plane_bytes_per_line, res_blocks, res_lines;
  2275. uint32_t result_bytes;
  2276. if (mem_value == 0 || !p->active || !p_params->enabled)
  2277. return false;
  2278. method1 = skl_wm_method1(p->pixel_rate,
  2279. p_params->bytes_per_pixel,
  2280. mem_value);
  2281. method2 = skl_wm_method2(p->pixel_rate,
  2282. p->pipe_htotal,
  2283. p_params->horiz_pixels,
  2284. p_params->bytes_per_pixel,
  2285. mem_value);
  2286. plane_bytes_per_line = p_params->horiz_pixels *
  2287. p_params->bytes_per_pixel;
  2288. /* For now xtile and linear */
  2289. if (((ddb_allocation * 512) / plane_bytes_per_line) >= 1)
  2290. result_bytes = min(method1, method2);
  2291. else
  2292. result_bytes = method1;
  2293. res_blocks = DIV_ROUND_UP(result_bytes, 512) + 1;
  2294. res_lines = DIV_ROUND_UP(result_bytes, plane_bytes_per_line);
  2295. if (res_blocks > ddb_allocation || res_lines > 31)
  2296. return false;
  2297. *out_blocks = res_blocks;
  2298. *out_lines = res_lines;
  2299. return true;
  2300. }
  2301. static void skl_compute_wm_level(const struct drm_i915_private *dev_priv,
  2302. struct skl_ddb_allocation *ddb,
  2303. struct skl_pipe_wm_parameters *p,
  2304. enum pipe pipe,
  2305. int level,
  2306. int num_planes,
  2307. struct skl_wm_level *result)
  2308. {
  2309. uint16_t latency = dev_priv->wm.skl_latency[level];
  2310. uint16_t ddb_blocks;
  2311. int i;
  2312. for (i = 0; i < num_planes; i++) {
  2313. ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]);
  2314. result->plane_en[i] = skl_compute_plane_wm(p, &p->plane[i],
  2315. ddb_blocks,
  2316. latency,
  2317. &result->plane_res_b[i],
  2318. &result->plane_res_l[i]);
  2319. }
  2320. ddb_blocks = skl_ddb_entry_size(&ddb->cursor[pipe]);
  2321. result->cursor_en = skl_compute_plane_wm(p, &p->cursor, ddb_blocks,
  2322. latency, &result->cursor_res_b,
  2323. &result->cursor_res_l);
  2324. }
  2325. static uint32_t
  2326. skl_compute_linetime_wm(struct drm_crtc *crtc, struct skl_pipe_wm_parameters *p)
  2327. {
  2328. if (!intel_crtc_active(crtc))
  2329. return 0;
  2330. return DIV_ROUND_UP(8 * p->pipe_htotal * 1000, p->pixel_rate);
  2331. }
  2332. static void skl_compute_transition_wm(struct drm_crtc *crtc,
  2333. struct skl_pipe_wm_parameters *params,
  2334. struct skl_wm_level *trans_wm /* out */)
  2335. {
  2336. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2337. int i;
  2338. if (!params->active)
  2339. return;
  2340. /* Until we know more, just disable transition WMs */
  2341. for (i = 0; i < intel_num_planes(intel_crtc); i++)
  2342. trans_wm->plane_en[i] = false;
  2343. trans_wm->cursor_en = false;
  2344. }
  2345. static void skl_compute_pipe_wm(struct drm_crtc *crtc,
  2346. struct skl_ddb_allocation *ddb,
  2347. struct skl_pipe_wm_parameters *params,
  2348. struct skl_pipe_wm *pipe_wm)
  2349. {
  2350. struct drm_device *dev = crtc->dev;
  2351. const struct drm_i915_private *dev_priv = dev->dev_private;
  2352. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2353. int level, max_level = ilk_wm_max_level(dev);
  2354. for (level = 0; level <= max_level; level++) {
  2355. skl_compute_wm_level(dev_priv, ddb, params, intel_crtc->pipe,
  2356. level, intel_num_planes(intel_crtc),
  2357. &pipe_wm->wm[level]);
  2358. }
  2359. pipe_wm->linetime = skl_compute_linetime_wm(crtc, params);
  2360. skl_compute_transition_wm(crtc, params, &pipe_wm->trans_wm);
  2361. }
  2362. static void skl_compute_wm_results(struct drm_device *dev,
  2363. struct skl_pipe_wm_parameters *p,
  2364. struct skl_pipe_wm *p_wm,
  2365. struct skl_wm_values *r,
  2366. struct intel_crtc *intel_crtc)
  2367. {
  2368. int level, max_level = ilk_wm_max_level(dev);
  2369. enum pipe pipe = intel_crtc->pipe;
  2370. uint32_t temp;
  2371. int i;
  2372. for (level = 0; level <= max_level; level++) {
  2373. for (i = 0; i < intel_num_planes(intel_crtc); i++) {
  2374. temp = 0;
  2375. temp |= p_wm->wm[level].plane_res_l[i] <<
  2376. PLANE_WM_LINES_SHIFT;
  2377. temp |= p_wm->wm[level].plane_res_b[i];
  2378. if (p_wm->wm[level].plane_en[i])
  2379. temp |= PLANE_WM_EN;
  2380. r->plane[pipe][i][level] = temp;
  2381. }
  2382. temp = 0;
  2383. temp |= p_wm->wm[level].cursor_res_l << PLANE_WM_LINES_SHIFT;
  2384. temp |= p_wm->wm[level].cursor_res_b;
  2385. if (p_wm->wm[level].cursor_en)
  2386. temp |= PLANE_WM_EN;
  2387. r->cursor[pipe][level] = temp;
  2388. }
  2389. /* transition WMs */
  2390. for (i = 0; i < intel_num_planes(intel_crtc); i++) {
  2391. temp = 0;
  2392. temp |= p_wm->trans_wm.plane_res_l[i] << PLANE_WM_LINES_SHIFT;
  2393. temp |= p_wm->trans_wm.plane_res_b[i];
  2394. if (p_wm->trans_wm.plane_en[i])
  2395. temp |= PLANE_WM_EN;
  2396. r->plane_trans[pipe][i] = temp;
  2397. }
  2398. temp = 0;
  2399. temp |= p_wm->trans_wm.cursor_res_l << PLANE_WM_LINES_SHIFT;
  2400. temp |= p_wm->trans_wm.cursor_res_b;
  2401. if (p_wm->trans_wm.cursor_en)
  2402. temp |= PLANE_WM_EN;
  2403. r->cursor_trans[pipe] = temp;
  2404. r->wm_linetime[pipe] = p_wm->linetime;
  2405. }
  2406. static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, uint32_t reg,
  2407. const struct skl_ddb_entry *entry)
  2408. {
  2409. if (entry->end)
  2410. I915_WRITE(reg, (entry->end - 1) << 16 | entry->start);
  2411. else
  2412. I915_WRITE(reg, 0);
  2413. }
  2414. static void skl_write_wm_values(struct drm_i915_private *dev_priv,
  2415. const struct skl_wm_values *new)
  2416. {
  2417. struct drm_device *dev = dev_priv->dev;
  2418. struct intel_crtc *crtc;
  2419. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
  2420. int i, level, max_level = ilk_wm_max_level(dev);
  2421. enum pipe pipe = crtc->pipe;
  2422. if (!new->dirty[pipe])
  2423. continue;
  2424. I915_WRITE(PIPE_WM_LINETIME(pipe), new->wm_linetime[pipe]);
  2425. for (level = 0; level <= max_level; level++) {
  2426. for (i = 0; i < intel_num_planes(crtc); i++)
  2427. I915_WRITE(PLANE_WM(pipe, i, level),
  2428. new->plane[pipe][i][level]);
  2429. I915_WRITE(CUR_WM(pipe, level),
  2430. new->cursor[pipe][level]);
  2431. }
  2432. for (i = 0; i < intel_num_planes(crtc); i++)
  2433. I915_WRITE(PLANE_WM_TRANS(pipe, i),
  2434. new->plane_trans[pipe][i]);
  2435. I915_WRITE(CUR_WM_TRANS(pipe), new->cursor_trans[pipe]);
  2436. for (i = 0; i < intel_num_planes(crtc); i++)
  2437. skl_ddb_entry_write(dev_priv,
  2438. PLANE_BUF_CFG(pipe, i),
  2439. &new->ddb.plane[pipe][i]);
  2440. skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe),
  2441. &new->ddb.cursor[pipe]);
  2442. }
  2443. }
  2444. /*
  2445. * When setting up a new DDB allocation arrangement, we need to correctly
  2446. * sequence the times at which the new allocations for the pipes are taken into
  2447. * account or we'll have pipes fetching from space previously allocated to
  2448. * another pipe.
  2449. *
  2450. * Roughly the sequence looks like:
  2451. * 1. re-allocate the pipe(s) with the allocation being reduced and not
  2452. * overlapping with a previous light-up pipe (another way to put it is:
  2453. * pipes with their new allocation strickly included into their old ones).
  2454. * 2. re-allocate the other pipes that get their allocation reduced
  2455. * 3. allocate the pipes having their allocation increased
  2456. *
  2457. * Steps 1. and 2. are here to take care of the following case:
  2458. * - Initially DDB looks like this:
  2459. * | B | C |
  2460. * - enable pipe A.
  2461. * - pipe B has a reduced DDB allocation that overlaps with the old pipe C
  2462. * allocation
  2463. * | A | B | C |
  2464. *
  2465. * We need to sequence the re-allocation: C, B, A (and not B, C, A).
  2466. */
  2467. static void
  2468. skl_wm_flush_pipe(struct drm_i915_private *dev_priv, enum pipe pipe, int pass)
  2469. {
  2470. struct drm_device *dev = dev_priv->dev;
  2471. int plane;
  2472. DRM_DEBUG_KMS("flush pipe %c (pass %d)\n", pipe_name(pipe), pass);
  2473. for_each_plane(pipe, plane) {
  2474. I915_WRITE(PLANE_SURF(pipe, plane),
  2475. I915_READ(PLANE_SURF(pipe, plane)));
  2476. }
  2477. I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe)));
  2478. }
  2479. static bool
  2480. skl_ddb_allocation_included(const struct skl_ddb_allocation *old,
  2481. const struct skl_ddb_allocation *new,
  2482. enum pipe pipe)
  2483. {
  2484. uint16_t old_size, new_size;
  2485. old_size = skl_ddb_entry_size(&old->pipe[pipe]);
  2486. new_size = skl_ddb_entry_size(&new->pipe[pipe]);
  2487. return old_size != new_size &&
  2488. new->pipe[pipe].start >= old->pipe[pipe].start &&
  2489. new->pipe[pipe].end <= old->pipe[pipe].end;
  2490. }
  2491. static void skl_flush_wm_values(struct drm_i915_private *dev_priv,
  2492. struct skl_wm_values *new_values)
  2493. {
  2494. struct drm_device *dev = dev_priv->dev;
  2495. struct skl_ddb_allocation *cur_ddb, *new_ddb;
  2496. bool reallocated[I915_MAX_PIPES] = {false, false, false};
  2497. struct intel_crtc *crtc;
  2498. enum pipe pipe;
  2499. new_ddb = &new_values->ddb;
  2500. cur_ddb = &dev_priv->wm.skl_hw.ddb;
  2501. /*
  2502. * First pass: flush the pipes with the new allocation contained into
  2503. * the old space.
  2504. *
  2505. * We'll wait for the vblank on those pipes to ensure we can safely
  2506. * re-allocate the freed space without this pipe fetching from it.
  2507. */
  2508. for_each_intel_crtc(dev, crtc) {
  2509. if (!crtc->active)
  2510. continue;
  2511. pipe = crtc->pipe;
  2512. if (!skl_ddb_allocation_included(cur_ddb, new_ddb, pipe))
  2513. continue;
  2514. skl_wm_flush_pipe(dev_priv, pipe, 1);
  2515. intel_wait_for_vblank(dev, pipe);
  2516. reallocated[pipe] = true;
  2517. }
  2518. /*
  2519. * Second pass: flush the pipes that are having their allocation
  2520. * reduced, but overlapping with a previous allocation.
  2521. *
  2522. * Here as well we need to wait for the vblank to make sure the freed
  2523. * space is not used anymore.
  2524. */
  2525. for_each_intel_crtc(dev, crtc) {
  2526. if (!crtc->active)
  2527. continue;
  2528. pipe = crtc->pipe;
  2529. if (reallocated[pipe])
  2530. continue;
  2531. if (skl_ddb_entry_size(&new_ddb->pipe[pipe]) <
  2532. skl_ddb_entry_size(&cur_ddb->pipe[pipe])) {
  2533. skl_wm_flush_pipe(dev_priv, pipe, 2);
  2534. intel_wait_for_vblank(dev, pipe);
  2535. reallocated[pipe] = true;
  2536. }
  2537. }
  2538. /*
  2539. * Third pass: flush the pipes that got more space allocated.
  2540. *
  2541. * We don't need to actively wait for the update here, next vblank
  2542. * will just get more DDB space with the correct WM values.
  2543. */
  2544. for_each_intel_crtc(dev, crtc) {
  2545. if (!crtc->active)
  2546. continue;
  2547. pipe = crtc->pipe;
  2548. /*
  2549. * At this point, only the pipes more space than before are
  2550. * left to re-allocate.
  2551. */
  2552. if (reallocated[pipe])
  2553. continue;
  2554. skl_wm_flush_pipe(dev_priv, pipe, 3);
  2555. }
  2556. }
  2557. static bool skl_update_pipe_wm(struct drm_crtc *crtc,
  2558. struct skl_pipe_wm_parameters *params,
  2559. struct intel_wm_config *config,
  2560. struct skl_ddb_allocation *ddb, /* out */
  2561. struct skl_pipe_wm *pipe_wm /* out */)
  2562. {
  2563. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2564. skl_compute_wm_pipe_parameters(crtc, params);
  2565. skl_allocate_pipe_ddb(crtc, config, params, ddb);
  2566. skl_compute_pipe_wm(crtc, ddb, params, pipe_wm);
  2567. if (!memcmp(&intel_crtc->wm.skl_active, pipe_wm, sizeof(*pipe_wm)))
  2568. return false;
  2569. intel_crtc->wm.skl_active = *pipe_wm;
  2570. return true;
  2571. }
  2572. static void skl_update_other_pipe_wm(struct drm_device *dev,
  2573. struct drm_crtc *crtc,
  2574. struct intel_wm_config *config,
  2575. struct skl_wm_values *r)
  2576. {
  2577. struct intel_crtc *intel_crtc;
  2578. struct intel_crtc *this_crtc = to_intel_crtc(crtc);
  2579. /*
  2580. * If the WM update hasn't changed the allocation for this_crtc (the
  2581. * crtc we are currently computing the new WM values for), other
  2582. * enabled crtcs will keep the same allocation and we don't need to
  2583. * recompute anything for them.
  2584. */
  2585. if (!skl_ddb_allocation_changed(&r->ddb, this_crtc))
  2586. return;
  2587. /*
  2588. * Otherwise, because of this_crtc being freshly enabled/disabled, the
  2589. * other active pipes need new DDB allocation and WM values.
  2590. */
  2591. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  2592. base.head) {
  2593. struct skl_pipe_wm_parameters params = {};
  2594. struct skl_pipe_wm pipe_wm = {};
  2595. bool wm_changed;
  2596. if (this_crtc->pipe == intel_crtc->pipe)
  2597. continue;
  2598. if (!intel_crtc->active)
  2599. continue;
  2600. wm_changed = skl_update_pipe_wm(&intel_crtc->base,
  2601. &params, config,
  2602. &r->ddb, &pipe_wm);
  2603. /*
  2604. * If we end up re-computing the other pipe WM values, it's
  2605. * because it was really needed, so we expect the WM values to
  2606. * be different.
  2607. */
  2608. WARN_ON(!wm_changed);
  2609. skl_compute_wm_results(dev, &params, &pipe_wm, r, intel_crtc);
  2610. r->dirty[intel_crtc->pipe] = true;
  2611. }
  2612. }
  2613. static void skl_update_wm(struct drm_crtc *crtc)
  2614. {
  2615. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2616. struct drm_device *dev = crtc->dev;
  2617. struct drm_i915_private *dev_priv = dev->dev_private;
  2618. struct skl_pipe_wm_parameters params = {};
  2619. struct skl_wm_values *results = &dev_priv->wm.skl_results;
  2620. struct skl_pipe_wm pipe_wm = {};
  2621. struct intel_wm_config config = {};
  2622. memset(results, 0, sizeof(*results));
  2623. skl_compute_wm_global_parameters(dev, &config);
  2624. if (!skl_update_pipe_wm(crtc, &params, &config,
  2625. &results->ddb, &pipe_wm))
  2626. return;
  2627. skl_compute_wm_results(dev, &params, &pipe_wm, results, intel_crtc);
  2628. results->dirty[intel_crtc->pipe] = true;
  2629. skl_update_other_pipe_wm(dev, crtc, &config, results);
  2630. skl_write_wm_values(dev_priv, results);
  2631. skl_flush_wm_values(dev_priv, results);
  2632. /* store the new configuration */
  2633. dev_priv->wm.skl_hw = *results;
  2634. }
  2635. static void
  2636. skl_update_sprite_wm(struct drm_plane *plane, struct drm_crtc *crtc,
  2637. uint32_t sprite_width, uint32_t sprite_height,
  2638. int pixel_size, bool enabled, bool scaled)
  2639. {
  2640. struct intel_plane *intel_plane = to_intel_plane(plane);
  2641. intel_plane->wm.enabled = enabled;
  2642. intel_plane->wm.scaled = scaled;
  2643. intel_plane->wm.horiz_pixels = sprite_width;
  2644. intel_plane->wm.vert_pixels = sprite_height;
  2645. intel_plane->wm.bytes_per_pixel = pixel_size;
  2646. skl_update_wm(crtc);
  2647. }
  2648. static void ilk_update_wm(struct drm_crtc *crtc)
  2649. {
  2650. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2651. struct drm_device *dev = crtc->dev;
  2652. struct drm_i915_private *dev_priv = dev->dev_private;
  2653. struct ilk_wm_maximums max;
  2654. struct ilk_pipe_wm_parameters params = {};
  2655. struct ilk_wm_values results = {};
  2656. enum intel_ddb_partitioning partitioning;
  2657. struct intel_pipe_wm pipe_wm = {};
  2658. struct intel_pipe_wm lp_wm_1_2 = {}, lp_wm_5_6 = {}, *best_lp_wm;
  2659. struct intel_wm_config config = {};
  2660. ilk_compute_wm_parameters(crtc, &params);
  2661. intel_compute_pipe_wm(crtc, &params, &pipe_wm);
  2662. if (!memcmp(&intel_crtc->wm.active, &pipe_wm, sizeof(pipe_wm)))
  2663. return;
  2664. intel_crtc->wm.active = pipe_wm;
  2665. ilk_compute_wm_config(dev, &config);
  2666. ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_1_2, &max);
  2667. ilk_wm_merge(dev, &config, &max, &lp_wm_1_2);
  2668. /* 5/6 split only in single pipe config on IVB+ */
  2669. if (INTEL_INFO(dev)->gen >= 7 &&
  2670. config.num_pipes_active == 1 && config.sprites_enabled) {
  2671. ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_5_6, &max);
  2672. ilk_wm_merge(dev, &config, &max, &lp_wm_5_6);
  2673. best_lp_wm = ilk_find_best_result(dev, &lp_wm_1_2, &lp_wm_5_6);
  2674. } else {
  2675. best_lp_wm = &lp_wm_1_2;
  2676. }
  2677. partitioning = (best_lp_wm == &lp_wm_1_2) ?
  2678. INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6;
  2679. ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results);
  2680. ilk_write_wm_values(dev_priv, &results);
  2681. }
  2682. static void
  2683. ilk_update_sprite_wm(struct drm_plane *plane,
  2684. struct drm_crtc *crtc,
  2685. uint32_t sprite_width, uint32_t sprite_height,
  2686. int pixel_size, bool enabled, bool scaled)
  2687. {
  2688. struct drm_device *dev = plane->dev;
  2689. struct intel_plane *intel_plane = to_intel_plane(plane);
  2690. intel_plane->wm.enabled = enabled;
  2691. intel_plane->wm.scaled = scaled;
  2692. intel_plane->wm.horiz_pixels = sprite_width;
  2693. intel_plane->wm.vert_pixels = sprite_width;
  2694. intel_plane->wm.bytes_per_pixel = pixel_size;
  2695. /*
  2696. * IVB workaround: must disable low power watermarks for at least
  2697. * one frame before enabling scaling. LP watermarks can be re-enabled
  2698. * when scaling is disabled.
  2699. *
  2700. * WaCxSRDisabledForSpriteScaling:ivb
  2701. */
  2702. if (IS_IVYBRIDGE(dev) && scaled && ilk_disable_lp_wm(dev))
  2703. intel_wait_for_vblank(dev, intel_plane->pipe);
  2704. ilk_update_wm(crtc);
  2705. }
  2706. static void skl_pipe_wm_active_state(uint32_t val,
  2707. struct skl_pipe_wm *active,
  2708. bool is_transwm,
  2709. bool is_cursor,
  2710. int i,
  2711. int level)
  2712. {
  2713. bool is_enabled = (val & PLANE_WM_EN) != 0;
  2714. if (!is_transwm) {
  2715. if (!is_cursor) {
  2716. active->wm[level].plane_en[i] = is_enabled;
  2717. active->wm[level].plane_res_b[i] =
  2718. val & PLANE_WM_BLOCKS_MASK;
  2719. active->wm[level].plane_res_l[i] =
  2720. (val >> PLANE_WM_LINES_SHIFT) &
  2721. PLANE_WM_LINES_MASK;
  2722. } else {
  2723. active->wm[level].cursor_en = is_enabled;
  2724. active->wm[level].cursor_res_b =
  2725. val & PLANE_WM_BLOCKS_MASK;
  2726. active->wm[level].cursor_res_l =
  2727. (val >> PLANE_WM_LINES_SHIFT) &
  2728. PLANE_WM_LINES_MASK;
  2729. }
  2730. } else {
  2731. if (!is_cursor) {
  2732. active->trans_wm.plane_en[i] = is_enabled;
  2733. active->trans_wm.plane_res_b[i] =
  2734. val & PLANE_WM_BLOCKS_MASK;
  2735. active->trans_wm.plane_res_l[i] =
  2736. (val >> PLANE_WM_LINES_SHIFT) &
  2737. PLANE_WM_LINES_MASK;
  2738. } else {
  2739. active->trans_wm.cursor_en = is_enabled;
  2740. active->trans_wm.cursor_res_b =
  2741. val & PLANE_WM_BLOCKS_MASK;
  2742. active->trans_wm.cursor_res_l =
  2743. (val >> PLANE_WM_LINES_SHIFT) &
  2744. PLANE_WM_LINES_MASK;
  2745. }
  2746. }
  2747. }
  2748. static void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc)
  2749. {
  2750. struct drm_device *dev = crtc->dev;
  2751. struct drm_i915_private *dev_priv = dev->dev_private;
  2752. struct skl_wm_values *hw = &dev_priv->wm.skl_hw;
  2753. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2754. struct skl_pipe_wm *active = &intel_crtc->wm.skl_active;
  2755. enum pipe pipe = intel_crtc->pipe;
  2756. int level, i, max_level;
  2757. uint32_t temp;
  2758. max_level = ilk_wm_max_level(dev);
  2759. hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe));
  2760. for (level = 0; level <= max_level; level++) {
  2761. for (i = 0; i < intel_num_planes(intel_crtc); i++)
  2762. hw->plane[pipe][i][level] =
  2763. I915_READ(PLANE_WM(pipe, i, level));
  2764. hw->cursor[pipe][level] = I915_READ(CUR_WM(pipe, level));
  2765. }
  2766. for (i = 0; i < intel_num_planes(intel_crtc); i++)
  2767. hw->plane_trans[pipe][i] = I915_READ(PLANE_WM_TRANS(pipe, i));
  2768. hw->cursor_trans[pipe] = I915_READ(CUR_WM_TRANS(pipe));
  2769. if (!intel_crtc_active(crtc))
  2770. return;
  2771. hw->dirty[pipe] = true;
  2772. active->linetime = hw->wm_linetime[pipe];
  2773. for (level = 0; level <= max_level; level++) {
  2774. for (i = 0; i < intel_num_planes(intel_crtc); i++) {
  2775. temp = hw->plane[pipe][i][level];
  2776. skl_pipe_wm_active_state(temp, active, false,
  2777. false, i, level);
  2778. }
  2779. temp = hw->cursor[pipe][level];
  2780. skl_pipe_wm_active_state(temp, active, false, true, i, level);
  2781. }
  2782. for (i = 0; i < intel_num_planes(intel_crtc); i++) {
  2783. temp = hw->plane_trans[pipe][i];
  2784. skl_pipe_wm_active_state(temp, active, true, false, i, 0);
  2785. }
  2786. temp = hw->cursor_trans[pipe];
  2787. skl_pipe_wm_active_state(temp, active, true, true, i, 0);
  2788. }
  2789. void skl_wm_get_hw_state(struct drm_device *dev)
  2790. {
  2791. struct drm_i915_private *dev_priv = dev->dev_private;
  2792. struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb;
  2793. struct drm_crtc *crtc;
  2794. skl_ddb_get_hw_state(dev_priv, ddb);
  2795. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  2796. skl_pipe_wm_get_hw_state(crtc);
  2797. }
  2798. static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc)
  2799. {
  2800. struct drm_device *dev = crtc->dev;
  2801. struct drm_i915_private *dev_priv = dev->dev_private;
  2802. struct ilk_wm_values *hw = &dev_priv->wm.hw;
  2803. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2804. struct intel_pipe_wm *active = &intel_crtc->wm.active;
  2805. enum pipe pipe = intel_crtc->pipe;
  2806. static const unsigned int wm0_pipe_reg[] = {
  2807. [PIPE_A] = WM0_PIPEA_ILK,
  2808. [PIPE_B] = WM0_PIPEB_ILK,
  2809. [PIPE_C] = WM0_PIPEC_IVB,
  2810. };
  2811. hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]);
  2812. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2813. hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe));
  2814. active->pipe_enabled = intel_crtc_active(crtc);
  2815. if (active->pipe_enabled) {
  2816. u32 tmp = hw->wm_pipe[pipe];
  2817. /*
  2818. * For active pipes LP0 watermark is marked as
  2819. * enabled, and LP1+ watermaks as disabled since
  2820. * we can't really reverse compute them in case
  2821. * multiple pipes are active.
  2822. */
  2823. active->wm[0].enable = true;
  2824. active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT;
  2825. active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT;
  2826. active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK;
  2827. active->linetime = hw->wm_linetime[pipe];
  2828. } else {
  2829. int level, max_level = ilk_wm_max_level(dev);
  2830. /*
  2831. * For inactive pipes, all watermark levels
  2832. * should be marked as enabled but zeroed,
  2833. * which is what we'd compute them to.
  2834. */
  2835. for (level = 0; level <= max_level; level++)
  2836. active->wm[level].enable = true;
  2837. }
  2838. }
  2839. void ilk_wm_get_hw_state(struct drm_device *dev)
  2840. {
  2841. struct drm_i915_private *dev_priv = dev->dev_private;
  2842. struct ilk_wm_values *hw = &dev_priv->wm.hw;
  2843. struct drm_crtc *crtc;
  2844. for_each_crtc(dev, crtc)
  2845. ilk_pipe_wm_get_hw_state(crtc);
  2846. hw->wm_lp[0] = I915_READ(WM1_LP_ILK);
  2847. hw->wm_lp[1] = I915_READ(WM2_LP_ILK);
  2848. hw->wm_lp[2] = I915_READ(WM3_LP_ILK);
  2849. hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK);
  2850. if (INTEL_INFO(dev)->gen >= 7) {
  2851. hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB);
  2852. hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB);
  2853. }
  2854. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2855. hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ?
  2856. INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
  2857. else if (IS_IVYBRIDGE(dev))
  2858. hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ?
  2859. INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
  2860. hw->enable_fbc_wm =
  2861. !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS);
  2862. }
  2863. /**
  2864. * intel_update_watermarks - update FIFO watermark values based on current modes
  2865. *
  2866. * Calculate watermark values for the various WM regs based on current mode
  2867. * and plane configuration.
  2868. *
  2869. * There are several cases to deal with here:
  2870. * - normal (i.e. non-self-refresh)
  2871. * - self-refresh (SR) mode
  2872. * - lines are large relative to FIFO size (buffer can hold up to 2)
  2873. * - lines are small relative to FIFO size (buffer can hold more than 2
  2874. * lines), so need to account for TLB latency
  2875. *
  2876. * The normal calculation is:
  2877. * watermark = dotclock * bytes per pixel * latency
  2878. * where latency is platform & configuration dependent (we assume pessimal
  2879. * values here).
  2880. *
  2881. * The SR calculation is:
  2882. * watermark = (trunc(latency/line time)+1) * surface width *
  2883. * bytes per pixel
  2884. * where
  2885. * line time = htotal / dotclock
  2886. * surface width = hdisplay for normal plane and 64 for cursor
  2887. * and latency is assumed to be high, as above.
  2888. *
  2889. * The final value programmed to the register should always be rounded up,
  2890. * and include an extra 2 entries to account for clock crossings.
  2891. *
  2892. * We don't use the sprite, so we can ignore that. And on Crestline we have
  2893. * to set the non-SR watermarks to 8.
  2894. */
  2895. void intel_update_watermarks(struct drm_crtc *crtc)
  2896. {
  2897. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  2898. if (dev_priv->display.update_wm)
  2899. dev_priv->display.update_wm(crtc);
  2900. }
  2901. void intel_update_sprite_watermarks(struct drm_plane *plane,
  2902. struct drm_crtc *crtc,
  2903. uint32_t sprite_width,
  2904. uint32_t sprite_height,
  2905. int pixel_size,
  2906. bool enabled, bool scaled)
  2907. {
  2908. struct drm_i915_private *dev_priv = plane->dev->dev_private;
  2909. if (dev_priv->display.update_sprite_wm)
  2910. dev_priv->display.update_sprite_wm(plane, crtc,
  2911. sprite_width, sprite_height,
  2912. pixel_size, enabled, scaled);
  2913. }
  2914. static struct drm_i915_gem_object *
  2915. intel_alloc_context_page(struct drm_device *dev)
  2916. {
  2917. struct drm_i915_gem_object *ctx;
  2918. int ret;
  2919. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  2920. ctx = i915_gem_alloc_object(dev, 4096);
  2921. if (!ctx) {
  2922. DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
  2923. return NULL;
  2924. }
  2925. ret = i915_gem_obj_ggtt_pin(ctx, 4096, 0);
  2926. if (ret) {
  2927. DRM_ERROR("failed to pin power context: %d\n", ret);
  2928. goto err_unref;
  2929. }
  2930. ret = i915_gem_object_set_to_gtt_domain(ctx, 1);
  2931. if (ret) {
  2932. DRM_ERROR("failed to set-domain on power context: %d\n", ret);
  2933. goto err_unpin;
  2934. }
  2935. return ctx;
  2936. err_unpin:
  2937. i915_gem_object_ggtt_unpin(ctx);
  2938. err_unref:
  2939. drm_gem_object_unreference(&ctx->base);
  2940. return NULL;
  2941. }
  2942. /**
  2943. * Lock protecting IPS related data structures
  2944. */
  2945. DEFINE_SPINLOCK(mchdev_lock);
  2946. /* Global for IPS driver to get at the current i915 device. Protected by
  2947. * mchdev_lock. */
  2948. static struct drm_i915_private *i915_mch_dev;
  2949. bool ironlake_set_drps(struct drm_device *dev, u8 val)
  2950. {
  2951. struct drm_i915_private *dev_priv = dev->dev_private;
  2952. u16 rgvswctl;
  2953. assert_spin_locked(&mchdev_lock);
  2954. rgvswctl = I915_READ16(MEMSWCTL);
  2955. if (rgvswctl & MEMCTL_CMD_STS) {
  2956. DRM_DEBUG("gpu busy, RCS change rejected\n");
  2957. return false; /* still busy with another command */
  2958. }
  2959. rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
  2960. (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM;
  2961. I915_WRITE16(MEMSWCTL, rgvswctl);
  2962. POSTING_READ16(MEMSWCTL);
  2963. rgvswctl |= MEMCTL_CMD_STS;
  2964. I915_WRITE16(MEMSWCTL, rgvswctl);
  2965. return true;
  2966. }
  2967. static void ironlake_enable_drps(struct drm_device *dev)
  2968. {
  2969. struct drm_i915_private *dev_priv = dev->dev_private;
  2970. u32 rgvmodectl = I915_READ(MEMMODECTL);
  2971. u8 fmax, fmin, fstart, vstart;
  2972. spin_lock_irq(&mchdev_lock);
  2973. /* Enable temp reporting */
  2974. I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN);
  2975. I915_WRITE16(TSC1, I915_READ(TSC1) | TSE);
  2976. /* 100ms RC evaluation intervals */
  2977. I915_WRITE(RCUPEI, 100000);
  2978. I915_WRITE(RCDNEI, 100000);
  2979. /* Set max/min thresholds to 90ms and 80ms respectively */
  2980. I915_WRITE(RCBMAXAVG, 90000);
  2981. I915_WRITE(RCBMINAVG, 80000);
  2982. I915_WRITE(MEMIHYST, 1);
  2983. /* Set up min, max, and cur for interrupt handling */
  2984. fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT;
  2985. fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
  2986. fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
  2987. MEMMODE_FSTART_SHIFT;
  2988. vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >>
  2989. PXVFREQ_PX_SHIFT;
  2990. dev_priv->ips.fmax = fmax; /* IPS callback will increase this */
  2991. dev_priv->ips.fstart = fstart;
  2992. dev_priv->ips.max_delay = fstart;
  2993. dev_priv->ips.min_delay = fmin;
  2994. dev_priv->ips.cur_delay = fstart;
  2995. DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
  2996. fmax, fmin, fstart);
  2997. I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
  2998. /*
  2999. * Interrupts will be enabled in ironlake_irq_postinstall
  3000. */
  3001. I915_WRITE(VIDSTART, vstart);
  3002. POSTING_READ(VIDSTART);
  3003. rgvmodectl |= MEMMODE_SWMODE_EN;
  3004. I915_WRITE(MEMMODECTL, rgvmodectl);
  3005. if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10))
  3006. DRM_ERROR("stuck trying to change perf mode\n");
  3007. mdelay(1);
  3008. ironlake_set_drps(dev, fstart);
  3009. dev_priv->ips.last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) +
  3010. I915_READ(0x112e0);
  3011. dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies);
  3012. dev_priv->ips.last_count2 = I915_READ(0x112f4);
  3013. dev_priv->ips.last_time2 = ktime_get_raw_ns();
  3014. spin_unlock_irq(&mchdev_lock);
  3015. }
  3016. static void ironlake_disable_drps(struct drm_device *dev)
  3017. {
  3018. struct drm_i915_private *dev_priv = dev->dev_private;
  3019. u16 rgvswctl;
  3020. spin_lock_irq(&mchdev_lock);
  3021. rgvswctl = I915_READ16(MEMSWCTL);
  3022. /* Ack interrupts, disable EFC interrupt */
  3023. I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN);
  3024. I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG);
  3025. I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT);
  3026. I915_WRITE(DEIIR, DE_PCU_EVENT);
  3027. I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT);
  3028. /* Go back to the starting frequency */
  3029. ironlake_set_drps(dev, dev_priv->ips.fstart);
  3030. mdelay(1);
  3031. rgvswctl |= MEMCTL_CMD_STS;
  3032. I915_WRITE(MEMSWCTL, rgvswctl);
  3033. mdelay(1);
  3034. spin_unlock_irq(&mchdev_lock);
  3035. }
  3036. /* There's a funny hw issue where the hw returns all 0 when reading from
  3037. * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value
  3038. * ourselves, instead of doing a rmw cycle (which might result in us clearing
  3039. * all limits and the gpu stuck at whatever frequency it is at atm).
  3040. */
  3041. static u32 gen6_rps_limits(struct drm_i915_private *dev_priv, u8 val)
  3042. {
  3043. u32 limits;
  3044. /* Only set the down limit when we've reached the lowest level to avoid
  3045. * getting more interrupts, otherwise leave this clear. This prevents a
  3046. * race in the hw when coming out of rc6: There's a tiny window where
  3047. * the hw runs at the minimal clock before selecting the desired
  3048. * frequency, if the down threshold expires in that window we will not
  3049. * receive a down interrupt. */
  3050. limits = dev_priv->rps.max_freq_softlimit << 24;
  3051. if (val <= dev_priv->rps.min_freq_softlimit)
  3052. limits |= dev_priv->rps.min_freq_softlimit << 16;
  3053. return limits;
  3054. }
  3055. static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val)
  3056. {
  3057. int new_power;
  3058. new_power = dev_priv->rps.power;
  3059. switch (dev_priv->rps.power) {
  3060. case LOW_POWER:
  3061. if (val > dev_priv->rps.efficient_freq + 1 && val > dev_priv->rps.cur_freq)
  3062. new_power = BETWEEN;
  3063. break;
  3064. case BETWEEN:
  3065. if (val <= dev_priv->rps.efficient_freq && val < dev_priv->rps.cur_freq)
  3066. new_power = LOW_POWER;
  3067. else if (val >= dev_priv->rps.rp0_freq && val > dev_priv->rps.cur_freq)
  3068. new_power = HIGH_POWER;
  3069. break;
  3070. case HIGH_POWER:
  3071. if (val < (dev_priv->rps.rp1_freq + dev_priv->rps.rp0_freq) >> 1 && val < dev_priv->rps.cur_freq)
  3072. new_power = BETWEEN;
  3073. break;
  3074. }
  3075. /* Max/min bins are special */
  3076. if (val == dev_priv->rps.min_freq_softlimit)
  3077. new_power = LOW_POWER;
  3078. if (val == dev_priv->rps.max_freq_softlimit)
  3079. new_power = HIGH_POWER;
  3080. if (new_power == dev_priv->rps.power)
  3081. return;
  3082. /* Note the units here are not exactly 1us, but 1280ns. */
  3083. switch (new_power) {
  3084. case LOW_POWER:
  3085. /* Upclock if more than 95% busy over 16ms */
  3086. I915_WRITE(GEN6_RP_UP_EI, 12500);
  3087. I915_WRITE(GEN6_RP_UP_THRESHOLD, 11800);
  3088. /* Downclock if less than 85% busy over 32ms */
  3089. I915_WRITE(GEN6_RP_DOWN_EI, 25000);
  3090. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 21250);
  3091. I915_WRITE(GEN6_RP_CONTROL,
  3092. GEN6_RP_MEDIA_TURBO |
  3093. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  3094. GEN6_RP_MEDIA_IS_GFX |
  3095. GEN6_RP_ENABLE |
  3096. GEN6_RP_UP_BUSY_AVG |
  3097. GEN6_RP_DOWN_IDLE_AVG);
  3098. break;
  3099. case BETWEEN:
  3100. /* Upclock if more than 90% busy over 13ms */
  3101. I915_WRITE(GEN6_RP_UP_EI, 10250);
  3102. I915_WRITE(GEN6_RP_UP_THRESHOLD, 9225);
  3103. /* Downclock if less than 75% busy over 32ms */
  3104. I915_WRITE(GEN6_RP_DOWN_EI, 25000);
  3105. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 18750);
  3106. I915_WRITE(GEN6_RP_CONTROL,
  3107. GEN6_RP_MEDIA_TURBO |
  3108. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  3109. GEN6_RP_MEDIA_IS_GFX |
  3110. GEN6_RP_ENABLE |
  3111. GEN6_RP_UP_BUSY_AVG |
  3112. GEN6_RP_DOWN_IDLE_AVG);
  3113. break;
  3114. case HIGH_POWER:
  3115. /* Upclock if more than 85% busy over 10ms */
  3116. I915_WRITE(GEN6_RP_UP_EI, 8000);
  3117. I915_WRITE(GEN6_RP_UP_THRESHOLD, 6800);
  3118. /* Downclock if less than 60% busy over 32ms */
  3119. I915_WRITE(GEN6_RP_DOWN_EI, 25000);
  3120. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 15000);
  3121. I915_WRITE(GEN6_RP_CONTROL,
  3122. GEN6_RP_MEDIA_TURBO |
  3123. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  3124. GEN6_RP_MEDIA_IS_GFX |
  3125. GEN6_RP_ENABLE |
  3126. GEN6_RP_UP_BUSY_AVG |
  3127. GEN6_RP_DOWN_IDLE_AVG);
  3128. break;
  3129. }
  3130. dev_priv->rps.power = new_power;
  3131. dev_priv->rps.last_adj = 0;
  3132. }
  3133. static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val)
  3134. {
  3135. u32 mask = 0;
  3136. if (val > dev_priv->rps.min_freq_softlimit)
  3137. mask |= GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT;
  3138. if (val < dev_priv->rps.max_freq_softlimit)
  3139. mask |= GEN6_PM_RP_UP_THRESHOLD;
  3140. mask |= dev_priv->pm_rps_events & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED);
  3141. mask &= dev_priv->pm_rps_events;
  3142. return gen6_sanitize_rps_pm_mask(dev_priv, ~mask);
  3143. }
  3144. /* gen6_set_rps is called to update the frequency request, but should also be
  3145. * called when the range (min_delay and max_delay) is modified so that we can
  3146. * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */
  3147. static void gen6_set_rps(struct drm_device *dev, u8 val)
  3148. {
  3149. struct drm_i915_private *dev_priv = dev->dev_private;
  3150. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  3151. WARN_ON(val > dev_priv->rps.max_freq_softlimit);
  3152. WARN_ON(val < dev_priv->rps.min_freq_softlimit);
  3153. /* min/max delay may still have been modified so be sure to
  3154. * write the limits value.
  3155. */
  3156. if (val != dev_priv->rps.cur_freq) {
  3157. gen6_set_rps_thresholds(dev_priv, val);
  3158. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  3159. I915_WRITE(GEN6_RPNSWREQ,
  3160. HSW_FREQUENCY(val));
  3161. else
  3162. I915_WRITE(GEN6_RPNSWREQ,
  3163. GEN6_FREQUENCY(val) |
  3164. GEN6_OFFSET(0) |
  3165. GEN6_AGGRESSIVE_TURBO);
  3166. }
  3167. /* Make sure we continue to get interrupts
  3168. * until we hit the minimum or maximum frequencies.
  3169. */
  3170. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, gen6_rps_limits(dev_priv, val));
  3171. I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val));
  3172. POSTING_READ(GEN6_RPNSWREQ);
  3173. dev_priv->rps.cur_freq = val;
  3174. trace_intel_gpu_freq_change(val * 50);
  3175. }
  3176. static void valleyview_set_rps(struct drm_device *dev, u8 val)
  3177. {
  3178. struct drm_i915_private *dev_priv = dev->dev_private;
  3179. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  3180. WARN_ON(val > dev_priv->rps.max_freq_softlimit);
  3181. WARN_ON(val < dev_priv->rps.min_freq_softlimit);
  3182. if (WARN_ONCE(IS_CHERRYVIEW(dev) && (val & 1),
  3183. "Odd GPU freq value\n"))
  3184. val &= ~1;
  3185. if (val != dev_priv->rps.cur_freq)
  3186. vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val);
  3187. I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val));
  3188. dev_priv->rps.cur_freq = val;
  3189. trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val));
  3190. }
  3191. /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down
  3192. *
  3193. * * If Gfx is Idle, then
  3194. * 1. Mask Turbo interrupts
  3195. * 2. Bring up Gfx clock
  3196. * 3. Change the freq to Rpn and wait till P-Unit updates freq
  3197. * 4. Clear the Force GFX CLK ON bit so that Gfx can down
  3198. * 5. Unmask Turbo interrupts
  3199. */
  3200. static void vlv_set_rps_idle(struct drm_i915_private *dev_priv)
  3201. {
  3202. struct drm_device *dev = dev_priv->dev;
  3203. /* CHV and latest VLV don't need to force the gfx clock */
  3204. if (IS_CHERRYVIEW(dev) || dev->pdev->revision >= 0xd) {
  3205. valleyview_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit);
  3206. return;
  3207. }
  3208. /*
  3209. * When we are idle. Drop to min voltage state.
  3210. */
  3211. if (dev_priv->rps.cur_freq <= dev_priv->rps.min_freq_softlimit)
  3212. return;
  3213. /* Mask turbo interrupt so that they will not come in between */
  3214. I915_WRITE(GEN6_PMINTRMSK,
  3215. gen6_sanitize_rps_pm_mask(dev_priv, ~0));
  3216. vlv_force_gfx_clock(dev_priv, true);
  3217. dev_priv->rps.cur_freq = dev_priv->rps.min_freq_softlimit;
  3218. vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ,
  3219. dev_priv->rps.min_freq_softlimit);
  3220. if (wait_for(((vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS))
  3221. & GENFREQSTATUS) == 0, 100))
  3222. DRM_ERROR("timed out waiting for Punit\n");
  3223. vlv_force_gfx_clock(dev_priv, false);
  3224. I915_WRITE(GEN6_PMINTRMSK,
  3225. gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq));
  3226. }
  3227. void gen6_rps_idle(struct drm_i915_private *dev_priv)
  3228. {
  3229. struct drm_device *dev = dev_priv->dev;
  3230. mutex_lock(&dev_priv->rps.hw_lock);
  3231. if (dev_priv->rps.enabled) {
  3232. if (IS_VALLEYVIEW(dev))
  3233. vlv_set_rps_idle(dev_priv);
  3234. else
  3235. gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit);
  3236. dev_priv->rps.last_adj = 0;
  3237. }
  3238. mutex_unlock(&dev_priv->rps.hw_lock);
  3239. }
  3240. void gen6_rps_boost(struct drm_i915_private *dev_priv)
  3241. {
  3242. mutex_lock(&dev_priv->rps.hw_lock);
  3243. if (dev_priv->rps.enabled) {
  3244. intel_set_rps(dev_priv->dev, dev_priv->rps.max_freq_softlimit);
  3245. dev_priv->rps.last_adj = 0;
  3246. }
  3247. mutex_unlock(&dev_priv->rps.hw_lock);
  3248. }
  3249. void intel_set_rps(struct drm_device *dev, u8 val)
  3250. {
  3251. if (IS_VALLEYVIEW(dev))
  3252. valleyview_set_rps(dev, val);
  3253. else
  3254. gen6_set_rps(dev, val);
  3255. }
  3256. static void gen9_disable_rps(struct drm_device *dev)
  3257. {
  3258. struct drm_i915_private *dev_priv = dev->dev_private;
  3259. I915_WRITE(GEN6_RC_CONTROL, 0);
  3260. I915_WRITE(GEN9_PG_ENABLE, 0);
  3261. }
  3262. static void gen6_disable_rps(struct drm_device *dev)
  3263. {
  3264. struct drm_i915_private *dev_priv = dev->dev_private;
  3265. I915_WRITE(GEN6_RC_CONTROL, 0);
  3266. I915_WRITE(GEN6_RPNSWREQ, 1 << 31);
  3267. }
  3268. static void cherryview_disable_rps(struct drm_device *dev)
  3269. {
  3270. struct drm_i915_private *dev_priv = dev->dev_private;
  3271. I915_WRITE(GEN6_RC_CONTROL, 0);
  3272. }
  3273. static void valleyview_disable_rps(struct drm_device *dev)
  3274. {
  3275. struct drm_i915_private *dev_priv = dev->dev_private;
  3276. /* we're doing forcewake before Disabling RC6,
  3277. * This what the BIOS expects when going into suspend */
  3278. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  3279. I915_WRITE(GEN6_RC_CONTROL, 0);
  3280. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  3281. }
  3282. static void intel_print_rc6_info(struct drm_device *dev, u32 mode)
  3283. {
  3284. if (IS_VALLEYVIEW(dev)) {
  3285. if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1)))
  3286. mode = GEN6_RC_CTL_RC6_ENABLE;
  3287. else
  3288. mode = 0;
  3289. }
  3290. if (HAS_RC6p(dev))
  3291. DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s RC6p %s RC6pp %s\n",
  3292. (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off",
  3293. (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off",
  3294. (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off");
  3295. else
  3296. DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s\n",
  3297. (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off");
  3298. }
  3299. static int sanitize_rc6_option(const struct drm_device *dev, int enable_rc6)
  3300. {
  3301. /* No RC6 before Ironlake */
  3302. if (INTEL_INFO(dev)->gen < 5)
  3303. return 0;
  3304. /* RC6 is only on Ironlake mobile not on desktop */
  3305. if (INTEL_INFO(dev)->gen == 5 && !IS_IRONLAKE_M(dev))
  3306. return 0;
  3307. /* Respect the kernel parameter if it is set */
  3308. if (enable_rc6 >= 0) {
  3309. int mask;
  3310. if (HAS_RC6p(dev))
  3311. mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE |
  3312. INTEL_RC6pp_ENABLE;
  3313. else
  3314. mask = INTEL_RC6_ENABLE;
  3315. if ((enable_rc6 & mask) != enable_rc6)
  3316. DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n",
  3317. enable_rc6 & mask, enable_rc6, mask);
  3318. return enable_rc6 & mask;
  3319. }
  3320. /* Disable RC6 on Ironlake */
  3321. if (INTEL_INFO(dev)->gen == 5)
  3322. return 0;
  3323. if (IS_IVYBRIDGE(dev))
  3324. return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE);
  3325. return INTEL_RC6_ENABLE;
  3326. }
  3327. int intel_enable_rc6(const struct drm_device *dev)
  3328. {
  3329. return i915.enable_rc6;
  3330. }
  3331. static void gen6_init_rps_frequencies(struct drm_device *dev)
  3332. {
  3333. struct drm_i915_private *dev_priv = dev->dev_private;
  3334. uint32_t rp_state_cap;
  3335. u32 ddcc_status = 0;
  3336. int ret;
  3337. rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  3338. /* All of these values are in units of 50MHz */
  3339. dev_priv->rps.cur_freq = 0;
  3340. /* static values from HW: RP0 > RP1 > RPn (min_freq) */
  3341. dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff;
  3342. dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff;
  3343. dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff;
  3344. /* hw_max = RP0 until we check for overclocking */
  3345. dev_priv->rps.max_freq = dev_priv->rps.rp0_freq;
  3346. dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq;
  3347. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  3348. ret = sandybridge_pcode_read(dev_priv,
  3349. HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL,
  3350. &ddcc_status);
  3351. if (0 == ret)
  3352. dev_priv->rps.efficient_freq =
  3353. (ddcc_status >> 8) & 0xff;
  3354. }
  3355. /* Preserve min/max settings in case of re-init */
  3356. if (dev_priv->rps.max_freq_softlimit == 0)
  3357. dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq;
  3358. if (dev_priv->rps.min_freq_softlimit == 0) {
  3359. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  3360. dev_priv->rps.min_freq_softlimit =
  3361. /* max(RPe, 450 MHz) */
  3362. max(dev_priv->rps.efficient_freq, (u8) 9);
  3363. else
  3364. dev_priv->rps.min_freq_softlimit =
  3365. dev_priv->rps.min_freq;
  3366. }
  3367. }
  3368. /* See the Gen9_GT_PM_Programming_Guide doc for the below */
  3369. static void gen9_enable_rps(struct drm_device *dev)
  3370. {
  3371. struct drm_i915_private *dev_priv = dev->dev_private;
  3372. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  3373. gen6_init_rps_frequencies(dev);
  3374. I915_WRITE(GEN6_RPNSWREQ, 0xc800000);
  3375. I915_WRITE(GEN6_RC_VIDEO_FREQ, 0xc800000);
  3376. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 0xf4240);
  3377. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, 0x12060000);
  3378. I915_WRITE(GEN6_RP_UP_THRESHOLD, 0xe808);
  3379. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 0x3bd08);
  3380. I915_WRITE(GEN6_RP_UP_EI, 0x101d0);
  3381. I915_WRITE(GEN6_RP_DOWN_EI, 0x55730);
  3382. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa);
  3383. I915_WRITE(GEN6_PMINTRMSK, 0x6);
  3384. I915_WRITE(GEN6_RP_CONTROL, GEN6_RP_MEDIA_TURBO |
  3385. GEN6_RP_MEDIA_HW_MODE | GEN6_RP_MEDIA_IS_GFX |
  3386. GEN6_RP_ENABLE | GEN6_RP_UP_BUSY_AVG |
  3387. GEN6_RP_DOWN_IDLE_AVG);
  3388. gen6_enable_rps_interrupts(dev);
  3389. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  3390. }
  3391. static void gen9_enable_rc6(struct drm_device *dev)
  3392. {
  3393. struct drm_i915_private *dev_priv = dev->dev_private;
  3394. struct intel_engine_cs *ring;
  3395. uint32_t rc6_mask = 0;
  3396. int unused;
  3397. /* 1a: Software RC state - RC0 */
  3398. I915_WRITE(GEN6_RC_STATE, 0);
  3399. /* 1b: Get forcewake during program sequence. Although the driver
  3400. * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
  3401. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  3402. /* 2a: Disable RC states. */
  3403. I915_WRITE(GEN6_RC_CONTROL, 0);
  3404. /* 2b: Program RC6 thresholds.*/
  3405. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16);
  3406. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */
  3407. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */
  3408. for_each_ring(ring, dev_priv, unused)
  3409. I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10);
  3410. I915_WRITE(GEN6_RC_SLEEP, 0);
  3411. I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */
  3412. /* 2c: Program Coarse Power Gating Policies. */
  3413. I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25);
  3414. I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25);
  3415. /* 3a: Enable RC6 */
  3416. if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE)
  3417. rc6_mask = GEN6_RC_CTL_RC6_ENABLE;
  3418. DRM_INFO("RC6 %s\n", (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ?
  3419. "on" : "off");
  3420. I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE |
  3421. GEN6_RC_CTL_EI_MODE(1) |
  3422. rc6_mask);
  3423. /* 3b: Enable Coarse Power Gating only when RC6 is enabled */
  3424. I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ? 3 : 0);
  3425. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  3426. }
  3427. static void gen8_enable_rps(struct drm_device *dev)
  3428. {
  3429. struct drm_i915_private *dev_priv = dev->dev_private;
  3430. struct intel_engine_cs *ring;
  3431. uint32_t rc6_mask = 0;
  3432. int unused;
  3433. /* 1a: Software RC state - RC0 */
  3434. I915_WRITE(GEN6_RC_STATE, 0);
  3435. /* 1c & 1d: Get forcewake during program sequence. Although the driver
  3436. * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
  3437. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  3438. /* 2a: Disable RC states. */
  3439. I915_WRITE(GEN6_RC_CONTROL, 0);
  3440. /* Initialize rps frequencies */
  3441. gen6_init_rps_frequencies(dev);
  3442. /* 2b: Program RC6 thresholds.*/
  3443. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16);
  3444. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */
  3445. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */
  3446. for_each_ring(ring, dev_priv, unused)
  3447. I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10);
  3448. I915_WRITE(GEN6_RC_SLEEP, 0);
  3449. if (IS_BROADWELL(dev))
  3450. I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */
  3451. else
  3452. I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */
  3453. /* 3: Enable RC6 */
  3454. if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE)
  3455. rc6_mask = GEN6_RC_CTL_RC6_ENABLE;
  3456. intel_print_rc6_info(dev, rc6_mask);
  3457. if (IS_BROADWELL(dev))
  3458. I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE |
  3459. GEN7_RC_CTL_TO_MODE |
  3460. rc6_mask);
  3461. else
  3462. I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE |
  3463. GEN6_RC_CTL_EI_MODE(1) |
  3464. rc6_mask);
  3465. /* 4 Program defaults and thresholds for RPS*/
  3466. I915_WRITE(GEN6_RPNSWREQ,
  3467. HSW_FREQUENCY(dev_priv->rps.rp1_freq));
  3468. I915_WRITE(GEN6_RC_VIDEO_FREQ,
  3469. HSW_FREQUENCY(dev_priv->rps.rp1_freq));
  3470. /* NB: Docs say 1s, and 1000000 - which aren't equivalent */
  3471. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */
  3472. /* Docs recommend 900MHz, and 300 MHz respectively */
  3473. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  3474. dev_priv->rps.max_freq_softlimit << 24 |
  3475. dev_priv->rps.min_freq_softlimit << 16);
  3476. I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */
  3477. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/
  3478. I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */
  3479. I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */
  3480. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  3481. /* 5: Enable RPS */
  3482. I915_WRITE(GEN6_RP_CONTROL,
  3483. GEN6_RP_MEDIA_TURBO |
  3484. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  3485. GEN6_RP_MEDIA_IS_GFX |
  3486. GEN6_RP_ENABLE |
  3487. GEN6_RP_UP_BUSY_AVG |
  3488. GEN6_RP_DOWN_IDLE_AVG);
  3489. /* 6: Ring frequency + overclocking (our driver does this later */
  3490. dev_priv->rps.power = HIGH_POWER; /* force a reset */
  3491. gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit);
  3492. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  3493. }
  3494. static void gen6_enable_rps(struct drm_device *dev)
  3495. {
  3496. struct drm_i915_private *dev_priv = dev->dev_private;
  3497. struct intel_engine_cs *ring;
  3498. u32 rc6vids, pcu_mbox = 0, rc6_mask = 0;
  3499. u32 gtfifodbg;
  3500. int rc6_mode;
  3501. int i, ret;
  3502. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  3503. /* Here begins a magic sequence of register writes to enable
  3504. * auto-downclocking.
  3505. *
  3506. * Perhaps there might be some value in exposing these to
  3507. * userspace...
  3508. */
  3509. I915_WRITE(GEN6_RC_STATE, 0);
  3510. /* Clear the DBG now so we don't confuse earlier errors */
  3511. if ((gtfifodbg = I915_READ(GTFIFODBG))) {
  3512. DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg);
  3513. I915_WRITE(GTFIFODBG, gtfifodbg);
  3514. }
  3515. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  3516. /* Initialize rps frequencies */
  3517. gen6_init_rps_frequencies(dev);
  3518. /* disable the counters and set deterministic thresholds */
  3519. I915_WRITE(GEN6_RC_CONTROL, 0);
  3520. I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16);
  3521. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30);
  3522. I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30);
  3523. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000);
  3524. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25);
  3525. for_each_ring(ring, dev_priv, i)
  3526. I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10);
  3527. I915_WRITE(GEN6_RC_SLEEP, 0);
  3528. I915_WRITE(GEN6_RC1e_THRESHOLD, 1000);
  3529. if (IS_IVYBRIDGE(dev))
  3530. I915_WRITE(GEN6_RC6_THRESHOLD, 125000);
  3531. else
  3532. I915_WRITE(GEN6_RC6_THRESHOLD, 50000);
  3533. I915_WRITE(GEN6_RC6p_THRESHOLD, 150000);
  3534. I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */
  3535. /* Check if we are enabling RC6 */
  3536. rc6_mode = intel_enable_rc6(dev_priv->dev);
  3537. if (rc6_mode & INTEL_RC6_ENABLE)
  3538. rc6_mask |= GEN6_RC_CTL_RC6_ENABLE;
  3539. /* We don't use those on Haswell */
  3540. if (!IS_HASWELL(dev)) {
  3541. if (rc6_mode & INTEL_RC6p_ENABLE)
  3542. rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE;
  3543. if (rc6_mode & INTEL_RC6pp_ENABLE)
  3544. rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE;
  3545. }
  3546. intel_print_rc6_info(dev, rc6_mask);
  3547. I915_WRITE(GEN6_RC_CONTROL,
  3548. rc6_mask |
  3549. GEN6_RC_CTL_EI_MODE(1) |
  3550. GEN6_RC_CTL_HW_ENABLE);
  3551. /* Power down if completely idle for over 50ms */
  3552. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000);
  3553. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  3554. ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_MIN_FREQ_TABLE, 0);
  3555. if (ret)
  3556. DRM_DEBUG_DRIVER("Failed to set the min frequency\n");
  3557. ret = sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &pcu_mbox);
  3558. if (!ret && (pcu_mbox & (1<<31))) { /* OC supported */
  3559. DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n",
  3560. (dev_priv->rps.max_freq_softlimit & 0xff) * 50,
  3561. (pcu_mbox & 0xff) * 50);
  3562. dev_priv->rps.max_freq = pcu_mbox & 0xff;
  3563. }
  3564. dev_priv->rps.power = HIGH_POWER; /* force a reset */
  3565. gen6_set_rps(dev_priv->dev, dev_priv->rps.min_freq_softlimit);
  3566. rc6vids = 0;
  3567. ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
  3568. if (IS_GEN6(dev) && ret) {
  3569. DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n");
  3570. } else if (IS_GEN6(dev) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) {
  3571. DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n",
  3572. GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450);
  3573. rc6vids &= 0xffff00;
  3574. rc6vids |= GEN6_ENCODE_RC6_VID(450);
  3575. ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids);
  3576. if (ret)
  3577. DRM_ERROR("Couldn't fix incorrect rc6 voltage\n");
  3578. }
  3579. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  3580. }
  3581. static void __gen6_update_ring_freq(struct drm_device *dev)
  3582. {
  3583. struct drm_i915_private *dev_priv = dev->dev_private;
  3584. int min_freq = 15;
  3585. unsigned int gpu_freq;
  3586. unsigned int max_ia_freq, min_ring_freq;
  3587. int scaling_factor = 180;
  3588. struct cpufreq_policy *policy;
  3589. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  3590. policy = cpufreq_cpu_get(0);
  3591. if (policy) {
  3592. max_ia_freq = policy->cpuinfo.max_freq;
  3593. cpufreq_cpu_put(policy);
  3594. } else {
  3595. /*
  3596. * Default to measured freq if none found, PCU will ensure we
  3597. * don't go over
  3598. */
  3599. max_ia_freq = tsc_khz;
  3600. }
  3601. /* Convert from kHz to MHz */
  3602. max_ia_freq /= 1000;
  3603. min_ring_freq = I915_READ(DCLK) & 0xf;
  3604. /* convert DDR frequency from units of 266.6MHz to bandwidth */
  3605. min_ring_freq = mult_frac(min_ring_freq, 8, 3);
  3606. /*
  3607. * For each potential GPU frequency, load a ring frequency we'd like
  3608. * to use for memory access. We do this by specifying the IA frequency
  3609. * the PCU should use as a reference to determine the ring frequency.
  3610. */
  3611. for (gpu_freq = dev_priv->rps.max_freq; gpu_freq >= dev_priv->rps.min_freq;
  3612. gpu_freq--) {
  3613. int diff = dev_priv->rps.max_freq - gpu_freq;
  3614. unsigned int ia_freq = 0, ring_freq = 0;
  3615. if (INTEL_INFO(dev)->gen >= 8) {
  3616. /* max(2 * GT, DDR). NB: GT is 50MHz units */
  3617. ring_freq = max(min_ring_freq, gpu_freq);
  3618. } else if (IS_HASWELL(dev)) {
  3619. ring_freq = mult_frac(gpu_freq, 5, 4);
  3620. ring_freq = max(min_ring_freq, ring_freq);
  3621. /* leave ia_freq as the default, chosen by cpufreq */
  3622. } else {
  3623. /* On older processors, there is no separate ring
  3624. * clock domain, so in order to boost the bandwidth
  3625. * of the ring, we need to upclock the CPU (ia_freq).
  3626. *
  3627. * For GPU frequencies less than 750MHz,
  3628. * just use the lowest ring freq.
  3629. */
  3630. if (gpu_freq < min_freq)
  3631. ia_freq = 800;
  3632. else
  3633. ia_freq = max_ia_freq - ((diff * scaling_factor) / 2);
  3634. ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100);
  3635. }
  3636. sandybridge_pcode_write(dev_priv,
  3637. GEN6_PCODE_WRITE_MIN_FREQ_TABLE,
  3638. ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT |
  3639. ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT |
  3640. gpu_freq);
  3641. }
  3642. }
  3643. void gen6_update_ring_freq(struct drm_device *dev)
  3644. {
  3645. struct drm_i915_private *dev_priv = dev->dev_private;
  3646. if (INTEL_INFO(dev)->gen < 6 || IS_VALLEYVIEW(dev))
  3647. return;
  3648. mutex_lock(&dev_priv->rps.hw_lock);
  3649. __gen6_update_ring_freq(dev);
  3650. mutex_unlock(&dev_priv->rps.hw_lock);
  3651. }
  3652. static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv)
  3653. {
  3654. struct drm_device *dev = dev_priv->dev;
  3655. u32 val, rp0;
  3656. if (dev->pdev->revision >= 0x20) {
  3657. val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE);
  3658. switch (INTEL_INFO(dev)->eu_total) {
  3659. case 8:
  3660. /* (2 * 4) config */
  3661. rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT);
  3662. break;
  3663. case 12:
  3664. /* (2 * 6) config */
  3665. rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT);
  3666. break;
  3667. case 16:
  3668. /* (2 * 8) config */
  3669. default:
  3670. /* Setting (2 * 8) Min RP0 for any other combination */
  3671. rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT);
  3672. break;
  3673. }
  3674. rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK);
  3675. } else {
  3676. /* For pre-production hardware */
  3677. val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG);
  3678. rp0 = (val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) &
  3679. PUNIT_GPU_STATUS_MAX_FREQ_MASK;
  3680. }
  3681. return rp0;
  3682. }
  3683. static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv)
  3684. {
  3685. u32 val, rpe;
  3686. val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG);
  3687. rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK;
  3688. return rpe;
  3689. }
  3690. static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv)
  3691. {
  3692. struct drm_device *dev = dev_priv->dev;
  3693. u32 val, rp1;
  3694. if (dev->pdev->revision >= 0x20) {
  3695. val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE);
  3696. rp1 = (val & FB_GFX_FREQ_FUSE_MASK);
  3697. } else {
  3698. /* For pre-production hardware */
  3699. val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  3700. rp1 = ((val >> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT) &
  3701. PUNIT_GPU_STATUS_MAX_FREQ_MASK);
  3702. }
  3703. return rp1;
  3704. }
  3705. static int cherryview_rps_min_freq(struct drm_i915_private *dev_priv)
  3706. {
  3707. struct drm_device *dev = dev_priv->dev;
  3708. u32 val, rpn;
  3709. if (dev->pdev->revision >= 0x20) {
  3710. val = vlv_punit_read(dev_priv, FB_GFX_FMIN_AT_VMIN_FUSE);
  3711. rpn = ((val >> FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT) &
  3712. FB_GFX_FREQ_FUSE_MASK);
  3713. } else { /* For pre-production hardware */
  3714. val = vlv_punit_read(dev_priv, PUNIT_GPU_STATUS_REG);
  3715. rpn = ((val >> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT) &
  3716. PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK);
  3717. }
  3718. return rpn;
  3719. }
  3720. static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv)
  3721. {
  3722. u32 val, rp1;
  3723. val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE);
  3724. rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT;
  3725. return rp1;
  3726. }
  3727. static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv)
  3728. {
  3729. u32 val, rp0;
  3730. val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE);
  3731. rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT;
  3732. /* Clamp to max */
  3733. rp0 = min_t(u32, rp0, 0xea);
  3734. return rp0;
  3735. }
  3736. static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv)
  3737. {
  3738. u32 val, rpe;
  3739. val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FMAX_FUSE_LO);
  3740. rpe = (val & FB_FMAX_VMIN_FREQ_LO_MASK) >> FB_FMAX_VMIN_FREQ_LO_SHIFT;
  3741. val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FMAX_FUSE_HI);
  3742. rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5;
  3743. return rpe;
  3744. }
  3745. static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv)
  3746. {
  3747. return vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff;
  3748. }
  3749. /* Check that the pctx buffer wasn't move under us. */
  3750. static void valleyview_check_pctx(struct drm_i915_private *dev_priv)
  3751. {
  3752. unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095;
  3753. WARN_ON(pctx_addr != dev_priv->mm.stolen_base +
  3754. dev_priv->vlv_pctx->stolen->start);
  3755. }
  3756. /* Check that the pcbr address is not empty. */
  3757. static void cherryview_check_pctx(struct drm_i915_private *dev_priv)
  3758. {
  3759. unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095;
  3760. WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0);
  3761. }
  3762. static void cherryview_setup_pctx(struct drm_device *dev)
  3763. {
  3764. struct drm_i915_private *dev_priv = dev->dev_private;
  3765. unsigned long pctx_paddr, paddr;
  3766. struct i915_gtt *gtt = &dev_priv->gtt;
  3767. u32 pcbr;
  3768. int pctx_size = 32*1024;
  3769. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  3770. pcbr = I915_READ(VLV_PCBR);
  3771. if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) {
  3772. DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n");
  3773. paddr = (dev_priv->mm.stolen_base +
  3774. (gtt->stolen_size - pctx_size));
  3775. pctx_paddr = (paddr & (~4095));
  3776. I915_WRITE(VLV_PCBR, pctx_paddr);
  3777. }
  3778. DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR));
  3779. }
  3780. static void valleyview_setup_pctx(struct drm_device *dev)
  3781. {
  3782. struct drm_i915_private *dev_priv = dev->dev_private;
  3783. struct drm_i915_gem_object *pctx;
  3784. unsigned long pctx_paddr;
  3785. u32 pcbr;
  3786. int pctx_size = 24*1024;
  3787. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  3788. pcbr = I915_READ(VLV_PCBR);
  3789. if (pcbr) {
  3790. /* BIOS set it up already, grab the pre-alloc'd space */
  3791. int pcbr_offset;
  3792. pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base;
  3793. pctx = i915_gem_object_create_stolen_for_preallocated(dev_priv->dev,
  3794. pcbr_offset,
  3795. I915_GTT_OFFSET_NONE,
  3796. pctx_size);
  3797. goto out;
  3798. }
  3799. DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n");
  3800. /*
  3801. * From the Gunit register HAS:
  3802. * The Gfx driver is expected to program this register and ensure
  3803. * proper allocation within Gfx stolen memory. For example, this
  3804. * register should be programmed such than the PCBR range does not
  3805. * overlap with other ranges, such as the frame buffer, protected
  3806. * memory, or any other relevant ranges.
  3807. */
  3808. pctx = i915_gem_object_create_stolen(dev, pctx_size);
  3809. if (!pctx) {
  3810. DRM_DEBUG("not enough stolen space for PCTX, disabling\n");
  3811. return;
  3812. }
  3813. pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start;
  3814. I915_WRITE(VLV_PCBR, pctx_paddr);
  3815. out:
  3816. DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR));
  3817. dev_priv->vlv_pctx = pctx;
  3818. }
  3819. static void valleyview_cleanup_pctx(struct drm_device *dev)
  3820. {
  3821. struct drm_i915_private *dev_priv = dev->dev_private;
  3822. if (WARN_ON(!dev_priv->vlv_pctx))
  3823. return;
  3824. drm_gem_object_unreference(&dev_priv->vlv_pctx->base);
  3825. dev_priv->vlv_pctx = NULL;
  3826. }
  3827. static void valleyview_init_gt_powersave(struct drm_device *dev)
  3828. {
  3829. struct drm_i915_private *dev_priv = dev->dev_private;
  3830. u32 val;
  3831. valleyview_setup_pctx(dev);
  3832. mutex_lock(&dev_priv->rps.hw_lock);
  3833. val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  3834. switch ((val >> 6) & 3) {
  3835. case 0:
  3836. case 1:
  3837. dev_priv->mem_freq = 800;
  3838. break;
  3839. case 2:
  3840. dev_priv->mem_freq = 1066;
  3841. break;
  3842. case 3:
  3843. dev_priv->mem_freq = 1333;
  3844. break;
  3845. }
  3846. DRM_DEBUG_DRIVER("DDR speed: %d MHz\n", dev_priv->mem_freq);
  3847. dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv);
  3848. dev_priv->rps.rp0_freq = dev_priv->rps.max_freq;
  3849. DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n",
  3850. intel_gpu_freq(dev_priv, dev_priv->rps.max_freq),
  3851. dev_priv->rps.max_freq);
  3852. dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv);
  3853. DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n",
  3854. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
  3855. dev_priv->rps.efficient_freq);
  3856. dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv);
  3857. DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n",
  3858. intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq),
  3859. dev_priv->rps.rp1_freq);
  3860. dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv);
  3861. DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n",
  3862. intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
  3863. dev_priv->rps.min_freq);
  3864. /* Preserve min/max settings in case of re-init */
  3865. if (dev_priv->rps.max_freq_softlimit == 0)
  3866. dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq;
  3867. if (dev_priv->rps.min_freq_softlimit == 0)
  3868. dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq;
  3869. mutex_unlock(&dev_priv->rps.hw_lock);
  3870. }
  3871. static void cherryview_init_gt_powersave(struct drm_device *dev)
  3872. {
  3873. struct drm_i915_private *dev_priv = dev->dev_private;
  3874. u32 val;
  3875. cherryview_setup_pctx(dev);
  3876. mutex_lock(&dev_priv->rps.hw_lock);
  3877. mutex_lock(&dev_priv->dpio_lock);
  3878. val = vlv_cck_read(dev_priv, CCK_FUSE_REG);
  3879. mutex_unlock(&dev_priv->dpio_lock);
  3880. switch ((val >> 2) & 0x7) {
  3881. case 0:
  3882. case 1:
  3883. dev_priv->rps.cz_freq = 200;
  3884. dev_priv->mem_freq = 1600;
  3885. break;
  3886. case 2:
  3887. dev_priv->rps.cz_freq = 267;
  3888. dev_priv->mem_freq = 1600;
  3889. break;
  3890. case 3:
  3891. dev_priv->rps.cz_freq = 333;
  3892. dev_priv->mem_freq = 2000;
  3893. break;
  3894. case 4:
  3895. dev_priv->rps.cz_freq = 320;
  3896. dev_priv->mem_freq = 1600;
  3897. break;
  3898. case 5:
  3899. dev_priv->rps.cz_freq = 400;
  3900. dev_priv->mem_freq = 1600;
  3901. break;
  3902. }
  3903. DRM_DEBUG_DRIVER("DDR speed: %d MHz\n", dev_priv->mem_freq);
  3904. dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv);
  3905. dev_priv->rps.rp0_freq = dev_priv->rps.max_freq;
  3906. DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n",
  3907. intel_gpu_freq(dev_priv, dev_priv->rps.max_freq),
  3908. dev_priv->rps.max_freq);
  3909. dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv);
  3910. DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n",
  3911. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
  3912. dev_priv->rps.efficient_freq);
  3913. dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv);
  3914. DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n",
  3915. intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq),
  3916. dev_priv->rps.rp1_freq);
  3917. dev_priv->rps.min_freq = cherryview_rps_min_freq(dev_priv);
  3918. DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n",
  3919. intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
  3920. dev_priv->rps.min_freq);
  3921. WARN_ONCE((dev_priv->rps.max_freq |
  3922. dev_priv->rps.efficient_freq |
  3923. dev_priv->rps.rp1_freq |
  3924. dev_priv->rps.min_freq) & 1,
  3925. "Odd GPU freq values\n");
  3926. /* Preserve min/max settings in case of re-init */
  3927. if (dev_priv->rps.max_freq_softlimit == 0)
  3928. dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq;
  3929. if (dev_priv->rps.min_freq_softlimit == 0)
  3930. dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq;
  3931. mutex_unlock(&dev_priv->rps.hw_lock);
  3932. }
  3933. static void valleyview_cleanup_gt_powersave(struct drm_device *dev)
  3934. {
  3935. valleyview_cleanup_pctx(dev);
  3936. }
  3937. static void cherryview_enable_rps(struct drm_device *dev)
  3938. {
  3939. struct drm_i915_private *dev_priv = dev->dev_private;
  3940. struct intel_engine_cs *ring;
  3941. u32 gtfifodbg, val, rc6_mode = 0, pcbr;
  3942. int i;
  3943. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  3944. gtfifodbg = I915_READ(GTFIFODBG);
  3945. if (gtfifodbg) {
  3946. DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n",
  3947. gtfifodbg);
  3948. I915_WRITE(GTFIFODBG, gtfifodbg);
  3949. }
  3950. cherryview_check_pctx(dev_priv);
  3951. /* 1a & 1b: Get forcewake during program sequence. Although the driver
  3952. * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
  3953. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  3954. /* Disable RC states. */
  3955. I915_WRITE(GEN6_RC_CONTROL, 0);
  3956. /* 2a: Program RC6 thresholds.*/
  3957. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16);
  3958. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */
  3959. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */
  3960. for_each_ring(ring, dev_priv, i)
  3961. I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10);
  3962. I915_WRITE(GEN6_RC_SLEEP, 0);
  3963. /* TO threshold set to 1750 us ( 0x557 * 1.28 us) */
  3964. I915_WRITE(GEN6_RC6_THRESHOLD, 0x557);
  3965. /* allows RC6 residency counter to work */
  3966. I915_WRITE(VLV_COUNTER_CONTROL,
  3967. _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH |
  3968. VLV_MEDIA_RC6_COUNT_EN |
  3969. VLV_RENDER_RC6_COUNT_EN));
  3970. /* For now we assume BIOS is allocating and populating the PCBR */
  3971. pcbr = I915_READ(VLV_PCBR);
  3972. /* 3: Enable RC6 */
  3973. if ((intel_enable_rc6(dev) & INTEL_RC6_ENABLE) &&
  3974. (pcbr >> VLV_PCBR_ADDR_SHIFT))
  3975. rc6_mode = GEN7_RC_CTL_TO_MODE;
  3976. I915_WRITE(GEN6_RC_CONTROL, rc6_mode);
  3977. /* 4 Program defaults and thresholds for RPS*/
  3978. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000);
  3979. I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400);
  3980. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000);
  3981. I915_WRITE(GEN6_RP_UP_EI, 66000);
  3982. I915_WRITE(GEN6_RP_DOWN_EI, 350000);
  3983. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  3984. /* 5: Enable RPS */
  3985. I915_WRITE(GEN6_RP_CONTROL,
  3986. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  3987. GEN6_RP_MEDIA_IS_GFX |
  3988. GEN6_RP_ENABLE |
  3989. GEN6_RP_UP_BUSY_AVG |
  3990. GEN6_RP_DOWN_IDLE_AVG);
  3991. val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  3992. /* RPS code assumes GPLL is used */
  3993. WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n");
  3994. DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no");
  3995. DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val);
  3996. dev_priv->rps.cur_freq = (val >> 8) & 0xff;
  3997. DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n",
  3998. intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
  3999. dev_priv->rps.cur_freq);
  4000. DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n",
  4001. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
  4002. dev_priv->rps.efficient_freq);
  4003. valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq);
  4004. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  4005. }
  4006. static void valleyview_enable_rps(struct drm_device *dev)
  4007. {
  4008. struct drm_i915_private *dev_priv = dev->dev_private;
  4009. struct intel_engine_cs *ring;
  4010. u32 gtfifodbg, val, rc6_mode = 0;
  4011. int i;
  4012. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  4013. valleyview_check_pctx(dev_priv);
  4014. if ((gtfifodbg = I915_READ(GTFIFODBG))) {
  4015. DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n",
  4016. gtfifodbg);
  4017. I915_WRITE(GTFIFODBG, gtfifodbg);
  4018. }
  4019. /* If VLV, Forcewake all wells, else re-direct to regular path */
  4020. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  4021. /* Disable RC states. */
  4022. I915_WRITE(GEN6_RC_CONTROL, 0);
  4023. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000);
  4024. I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400);
  4025. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000);
  4026. I915_WRITE(GEN6_RP_UP_EI, 66000);
  4027. I915_WRITE(GEN6_RP_DOWN_EI, 350000);
  4028. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  4029. I915_WRITE(GEN6_RP_CONTROL,
  4030. GEN6_RP_MEDIA_TURBO |
  4031. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  4032. GEN6_RP_MEDIA_IS_GFX |
  4033. GEN6_RP_ENABLE |
  4034. GEN6_RP_UP_BUSY_AVG |
  4035. GEN6_RP_DOWN_IDLE_CONT);
  4036. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000);
  4037. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000);
  4038. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25);
  4039. for_each_ring(ring, dev_priv, i)
  4040. I915_WRITE(RING_MAX_IDLE(ring->mmio_base), 10);
  4041. I915_WRITE(GEN6_RC6_THRESHOLD, 0x557);
  4042. /* allows RC6 residency counter to work */
  4043. I915_WRITE(VLV_COUNTER_CONTROL,
  4044. _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN |
  4045. VLV_RENDER_RC0_COUNT_EN |
  4046. VLV_MEDIA_RC6_COUNT_EN |
  4047. VLV_RENDER_RC6_COUNT_EN));
  4048. if (intel_enable_rc6(dev) & INTEL_RC6_ENABLE)
  4049. rc6_mode = GEN7_RC_CTL_TO_MODE | VLV_RC_CTL_CTX_RST_PARALLEL;
  4050. intel_print_rc6_info(dev, rc6_mode);
  4051. I915_WRITE(GEN6_RC_CONTROL, rc6_mode);
  4052. val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  4053. /* RPS code assumes GPLL is used */
  4054. WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n");
  4055. DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val & GPLLENABLE ? "yes" : "no");
  4056. DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val);
  4057. dev_priv->rps.cur_freq = (val >> 8) & 0xff;
  4058. DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n",
  4059. intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
  4060. dev_priv->rps.cur_freq);
  4061. DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n",
  4062. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
  4063. dev_priv->rps.efficient_freq);
  4064. valleyview_set_rps(dev_priv->dev, dev_priv->rps.efficient_freq);
  4065. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  4066. }
  4067. void ironlake_teardown_rc6(struct drm_device *dev)
  4068. {
  4069. struct drm_i915_private *dev_priv = dev->dev_private;
  4070. if (dev_priv->ips.renderctx) {
  4071. i915_gem_object_ggtt_unpin(dev_priv->ips.renderctx);
  4072. drm_gem_object_unreference(&dev_priv->ips.renderctx->base);
  4073. dev_priv->ips.renderctx = NULL;
  4074. }
  4075. if (dev_priv->ips.pwrctx) {
  4076. i915_gem_object_ggtt_unpin(dev_priv->ips.pwrctx);
  4077. drm_gem_object_unreference(&dev_priv->ips.pwrctx->base);
  4078. dev_priv->ips.pwrctx = NULL;
  4079. }
  4080. }
  4081. static void ironlake_disable_rc6(struct drm_device *dev)
  4082. {
  4083. struct drm_i915_private *dev_priv = dev->dev_private;
  4084. if (I915_READ(PWRCTXA)) {
  4085. /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */
  4086. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT);
  4087. wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON),
  4088. 50);
  4089. I915_WRITE(PWRCTXA, 0);
  4090. POSTING_READ(PWRCTXA);
  4091. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  4092. POSTING_READ(RSTDBYCTL);
  4093. }
  4094. }
  4095. static int ironlake_setup_rc6(struct drm_device *dev)
  4096. {
  4097. struct drm_i915_private *dev_priv = dev->dev_private;
  4098. if (dev_priv->ips.renderctx == NULL)
  4099. dev_priv->ips.renderctx = intel_alloc_context_page(dev);
  4100. if (!dev_priv->ips.renderctx)
  4101. return -ENOMEM;
  4102. if (dev_priv->ips.pwrctx == NULL)
  4103. dev_priv->ips.pwrctx = intel_alloc_context_page(dev);
  4104. if (!dev_priv->ips.pwrctx) {
  4105. ironlake_teardown_rc6(dev);
  4106. return -ENOMEM;
  4107. }
  4108. return 0;
  4109. }
  4110. static void ironlake_enable_rc6(struct drm_device *dev)
  4111. {
  4112. struct drm_i915_private *dev_priv = dev->dev_private;
  4113. struct intel_engine_cs *ring = &dev_priv->ring[RCS];
  4114. bool was_interruptible;
  4115. int ret;
  4116. /* rc6 disabled by default due to repeated reports of hanging during
  4117. * boot and resume.
  4118. */
  4119. if (!intel_enable_rc6(dev))
  4120. return;
  4121. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  4122. ret = ironlake_setup_rc6(dev);
  4123. if (ret)
  4124. return;
  4125. was_interruptible = dev_priv->mm.interruptible;
  4126. dev_priv->mm.interruptible = false;
  4127. /*
  4128. * GPU can automatically power down the render unit if given a page
  4129. * to save state.
  4130. */
  4131. ret = intel_ring_begin(ring, 6);
  4132. if (ret) {
  4133. ironlake_teardown_rc6(dev);
  4134. dev_priv->mm.interruptible = was_interruptible;
  4135. return;
  4136. }
  4137. intel_ring_emit(ring, MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN);
  4138. intel_ring_emit(ring, MI_SET_CONTEXT);
  4139. intel_ring_emit(ring, i915_gem_obj_ggtt_offset(dev_priv->ips.renderctx) |
  4140. MI_MM_SPACE_GTT |
  4141. MI_SAVE_EXT_STATE_EN |
  4142. MI_RESTORE_EXT_STATE_EN |
  4143. MI_RESTORE_INHIBIT);
  4144. intel_ring_emit(ring, MI_SUSPEND_FLUSH);
  4145. intel_ring_emit(ring, MI_NOOP);
  4146. intel_ring_emit(ring, MI_FLUSH);
  4147. intel_ring_advance(ring);
  4148. /*
  4149. * Wait for the command parser to advance past MI_SET_CONTEXT. The HW
  4150. * does an implicit flush, combined with MI_FLUSH above, it should be
  4151. * safe to assume that renderctx is valid
  4152. */
  4153. ret = intel_ring_idle(ring);
  4154. dev_priv->mm.interruptible = was_interruptible;
  4155. if (ret) {
  4156. DRM_ERROR("failed to enable ironlake power savings\n");
  4157. ironlake_teardown_rc6(dev);
  4158. return;
  4159. }
  4160. I915_WRITE(PWRCTXA, i915_gem_obj_ggtt_offset(dev_priv->ips.pwrctx) | PWRCTX_EN);
  4161. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  4162. intel_print_rc6_info(dev, GEN6_RC_CTL_RC6_ENABLE);
  4163. }
  4164. static unsigned long intel_pxfreq(u32 vidfreq)
  4165. {
  4166. unsigned long freq;
  4167. int div = (vidfreq & 0x3f0000) >> 16;
  4168. int post = (vidfreq & 0x3000) >> 12;
  4169. int pre = (vidfreq & 0x7);
  4170. if (!pre)
  4171. return 0;
  4172. freq = ((div * 133333) / ((1<<post) * pre));
  4173. return freq;
  4174. }
  4175. static const struct cparams {
  4176. u16 i;
  4177. u16 t;
  4178. u16 m;
  4179. u16 c;
  4180. } cparams[] = {
  4181. { 1, 1333, 301, 28664 },
  4182. { 1, 1066, 294, 24460 },
  4183. { 1, 800, 294, 25192 },
  4184. { 0, 1333, 276, 27605 },
  4185. { 0, 1066, 276, 27605 },
  4186. { 0, 800, 231, 23784 },
  4187. };
  4188. static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv)
  4189. {
  4190. u64 total_count, diff, ret;
  4191. u32 count1, count2, count3, m = 0, c = 0;
  4192. unsigned long now = jiffies_to_msecs(jiffies), diff1;
  4193. int i;
  4194. assert_spin_locked(&mchdev_lock);
  4195. diff1 = now - dev_priv->ips.last_time1;
  4196. /* Prevent division-by-zero if we are asking too fast.
  4197. * Also, we don't get interesting results if we are polling
  4198. * faster than once in 10ms, so just return the saved value
  4199. * in such cases.
  4200. */
  4201. if (diff1 <= 10)
  4202. return dev_priv->ips.chipset_power;
  4203. count1 = I915_READ(DMIEC);
  4204. count2 = I915_READ(DDREC);
  4205. count3 = I915_READ(CSIEC);
  4206. total_count = count1 + count2 + count3;
  4207. /* FIXME: handle per-counter overflow */
  4208. if (total_count < dev_priv->ips.last_count1) {
  4209. diff = ~0UL - dev_priv->ips.last_count1;
  4210. diff += total_count;
  4211. } else {
  4212. diff = total_count - dev_priv->ips.last_count1;
  4213. }
  4214. for (i = 0; i < ARRAY_SIZE(cparams); i++) {
  4215. if (cparams[i].i == dev_priv->ips.c_m &&
  4216. cparams[i].t == dev_priv->ips.r_t) {
  4217. m = cparams[i].m;
  4218. c = cparams[i].c;
  4219. break;
  4220. }
  4221. }
  4222. diff = div_u64(diff, diff1);
  4223. ret = ((m * diff) + c);
  4224. ret = div_u64(ret, 10);
  4225. dev_priv->ips.last_count1 = total_count;
  4226. dev_priv->ips.last_time1 = now;
  4227. dev_priv->ips.chipset_power = ret;
  4228. return ret;
  4229. }
  4230. unsigned long i915_chipset_val(struct drm_i915_private *dev_priv)
  4231. {
  4232. struct drm_device *dev = dev_priv->dev;
  4233. unsigned long val;
  4234. if (INTEL_INFO(dev)->gen != 5)
  4235. return 0;
  4236. spin_lock_irq(&mchdev_lock);
  4237. val = __i915_chipset_val(dev_priv);
  4238. spin_unlock_irq(&mchdev_lock);
  4239. return val;
  4240. }
  4241. unsigned long i915_mch_val(struct drm_i915_private *dev_priv)
  4242. {
  4243. unsigned long m, x, b;
  4244. u32 tsfs;
  4245. tsfs = I915_READ(TSFS);
  4246. m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT);
  4247. x = I915_READ8(TR1);
  4248. b = tsfs & TSFS_INTR_MASK;
  4249. return ((m * x) / 127) - b;
  4250. }
  4251. static int _pxvid_to_vd(u8 pxvid)
  4252. {
  4253. if (pxvid == 0)
  4254. return 0;
  4255. if (pxvid >= 8 && pxvid < 31)
  4256. pxvid = 31;
  4257. return (pxvid + 2) * 125;
  4258. }
  4259. static u32 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid)
  4260. {
  4261. struct drm_device *dev = dev_priv->dev;
  4262. const int vd = _pxvid_to_vd(pxvid);
  4263. const int vm = vd - 1125;
  4264. if (INTEL_INFO(dev)->is_mobile)
  4265. return vm > 0 ? vm : 0;
  4266. return vd;
  4267. }
  4268. static void __i915_update_gfx_val(struct drm_i915_private *dev_priv)
  4269. {
  4270. u64 now, diff, diffms;
  4271. u32 count;
  4272. assert_spin_locked(&mchdev_lock);
  4273. now = ktime_get_raw_ns();
  4274. diffms = now - dev_priv->ips.last_time2;
  4275. do_div(diffms, NSEC_PER_MSEC);
  4276. /* Don't divide by 0 */
  4277. if (!diffms)
  4278. return;
  4279. count = I915_READ(GFXEC);
  4280. if (count < dev_priv->ips.last_count2) {
  4281. diff = ~0UL - dev_priv->ips.last_count2;
  4282. diff += count;
  4283. } else {
  4284. diff = count - dev_priv->ips.last_count2;
  4285. }
  4286. dev_priv->ips.last_count2 = count;
  4287. dev_priv->ips.last_time2 = now;
  4288. /* More magic constants... */
  4289. diff = diff * 1181;
  4290. diff = div_u64(diff, diffms * 10);
  4291. dev_priv->ips.gfx_power = diff;
  4292. }
  4293. void i915_update_gfx_val(struct drm_i915_private *dev_priv)
  4294. {
  4295. struct drm_device *dev = dev_priv->dev;
  4296. if (INTEL_INFO(dev)->gen != 5)
  4297. return;
  4298. spin_lock_irq(&mchdev_lock);
  4299. __i915_update_gfx_val(dev_priv);
  4300. spin_unlock_irq(&mchdev_lock);
  4301. }
  4302. static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv)
  4303. {
  4304. unsigned long t, corr, state1, corr2, state2;
  4305. u32 pxvid, ext_v;
  4306. assert_spin_locked(&mchdev_lock);
  4307. pxvid = I915_READ(PXVFREQ_BASE + (dev_priv->rps.cur_freq * 4));
  4308. pxvid = (pxvid >> 24) & 0x7f;
  4309. ext_v = pvid_to_extvid(dev_priv, pxvid);
  4310. state1 = ext_v;
  4311. t = i915_mch_val(dev_priv);
  4312. /* Revel in the empirically derived constants */
  4313. /* Correction factor in 1/100000 units */
  4314. if (t > 80)
  4315. corr = ((t * 2349) + 135940);
  4316. else if (t >= 50)
  4317. corr = ((t * 964) + 29317);
  4318. else /* < 50 */
  4319. corr = ((t * 301) + 1004);
  4320. corr = corr * ((150142 * state1) / 10000 - 78642);
  4321. corr /= 100000;
  4322. corr2 = (corr * dev_priv->ips.corr);
  4323. state2 = (corr2 * state1) / 10000;
  4324. state2 /= 100; /* convert to mW */
  4325. __i915_update_gfx_val(dev_priv);
  4326. return dev_priv->ips.gfx_power + state2;
  4327. }
  4328. unsigned long i915_gfx_val(struct drm_i915_private *dev_priv)
  4329. {
  4330. struct drm_device *dev = dev_priv->dev;
  4331. unsigned long val;
  4332. if (INTEL_INFO(dev)->gen != 5)
  4333. return 0;
  4334. spin_lock_irq(&mchdev_lock);
  4335. val = __i915_gfx_val(dev_priv);
  4336. spin_unlock_irq(&mchdev_lock);
  4337. return val;
  4338. }
  4339. /**
  4340. * i915_read_mch_val - return value for IPS use
  4341. *
  4342. * Calculate and return a value for the IPS driver to use when deciding whether
  4343. * we have thermal and power headroom to increase CPU or GPU power budget.
  4344. */
  4345. unsigned long i915_read_mch_val(void)
  4346. {
  4347. struct drm_i915_private *dev_priv;
  4348. unsigned long chipset_val, graphics_val, ret = 0;
  4349. spin_lock_irq(&mchdev_lock);
  4350. if (!i915_mch_dev)
  4351. goto out_unlock;
  4352. dev_priv = i915_mch_dev;
  4353. chipset_val = __i915_chipset_val(dev_priv);
  4354. graphics_val = __i915_gfx_val(dev_priv);
  4355. ret = chipset_val + graphics_val;
  4356. out_unlock:
  4357. spin_unlock_irq(&mchdev_lock);
  4358. return ret;
  4359. }
  4360. EXPORT_SYMBOL_GPL(i915_read_mch_val);
  4361. /**
  4362. * i915_gpu_raise - raise GPU frequency limit
  4363. *
  4364. * Raise the limit; IPS indicates we have thermal headroom.
  4365. */
  4366. bool i915_gpu_raise(void)
  4367. {
  4368. struct drm_i915_private *dev_priv;
  4369. bool ret = true;
  4370. spin_lock_irq(&mchdev_lock);
  4371. if (!i915_mch_dev) {
  4372. ret = false;
  4373. goto out_unlock;
  4374. }
  4375. dev_priv = i915_mch_dev;
  4376. if (dev_priv->ips.max_delay > dev_priv->ips.fmax)
  4377. dev_priv->ips.max_delay--;
  4378. out_unlock:
  4379. spin_unlock_irq(&mchdev_lock);
  4380. return ret;
  4381. }
  4382. EXPORT_SYMBOL_GPL(i915_gpu_raise);
  4383. /**
  4384. * i915_gpu_lower - lower GPU frequency limit
  4385. *
  4386. * IPS indicates we're close to a thermal limit, so throttle back the GPU
  4387. * frequency maximum.
  4388. */
  4389. bool i915_gpu_lower(void)
  4390. {
  4391. struct drm_i915_private *dev_priv;
  4392. bool ret = true;
  4393. spin_lock_irq(&mchdev_lock);
  4394. if (!i915_mch_dev) {
  4395. ret = false;
  4396. goto out_unlock;
  4397. }
  4398. dev_priv = i915_mch_dev;
  4399. if (dev_priv->ips.max_delay < dev_priv->ips.min_delay)
  4400. dev_priv->ips.max_delay++;
  4401. out_unlock:
  4402. spin_unlock_irq(&mchdev_lock);
  4403. return ret;
  4404. }
  4405. EXPORT_SYMBOL_GPL(i915_gpu_lower);
  4406. /**
  4407. * i915_gpu_busy - indicate GPU business to IPS
  4408. *
  4409. * Tell the IPS driver whether or not the GPU is busy.
  4410. */
  4411. bool i915_gpu_busy(void)
  4412. {
  4413. struct drm_i915_private *dev_priv;
  4414. struct intel_engine_cs *ring;
  4415. bool ret = false;
  4416. int i;
  4417. spin_lock_irq(&mchdev_lock);
  4418. if (!i915_mch_dev)
  4419. goto out_unlock;
  4420. dev_priv = i915_mch_dev;
  4421. for_each_ring(ring, dev_priv, i)
  4422. ret |= !list_empty(&ring->request_list);
  4423. out_unlock:
  4424. spin_unlock_irq(&mchdev_lock);
  4425. return ret;
  4426. }
  4427. EXPORT_SYMBOL_GPL(i915_gpu_busy);
  4428. /**
  4429. * i915_gpu_turbo_disable - disable graphics turbo
  4430. *
  4431. * Disable graphics turbo by resetting the max frequency and setting the
  4432. * current frequency to the default.
  4433. */
  4434. bool i915_gpu_turbo_disable(void)
  4435. {
  4436. struct drm_i915_private *dev_priv;
  4437. bool ret = true;
  4438. spin_lock_irq(&mchdev_lock);
  4439. if (!i915_mch_dev) {
  4440. ret = false;
  4441. goto out_unlock;
  4442. }
  4443. dev_priv = i915_mch_dev;
  4444. dev_priv->ips.max_delay = dev_priv->ips.fstart;
  4445. if (!ironlake_set_drps(dev_priv->dev, dev_priv->ips.fstart))
  4446. ret = false;
  4447. out_unlock:
  4448. spin_unlock_irq(&mchdev_lock);
  4449. return ret;
  4450. }
  4451. EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable);
  4452. /**
  4453. * Tells the intel_ips driver that the i915 driver is now loaded, if
  4454. * IPS got loaded first.
  4455. *
  4456. * This awkward dance is so that neither module has to depend on the
  4457. * other in order for IPS to do the appropriate communication of
  4458. * GPU turbo limits to i915.
  4459. */
  4460. static void
  4461. ips_ping_for_i915_load(void)
  4462. {
  4463. void (*link)(void);
  4464. link = symbol_get(ips_link_to_i915_driver);
  4465. if (link) {
  4466. link();
  4467. symbol_put(ips_link_to_i915_driver);
  4468. }
  4469. }
  4470. void intel_gpu_ips_init(struct drm_i915_private *dev_priv)
  4471. {
  4472. /* We only register the i915 ips part with intel-ips once everything is
  4473. * set up, to avoid intel-ips sneaking in and reading bogus values. */
  4474. spin_lock_irq(&mchdev_lock);
  4475. i915_mch_dev = dev_priv;
  4476. spin_unlock_irq(&mchdev_lock);
  4477. ips_ping_for_i915_load();
  4478. }
  4479. void intel_gpu_ips_teardown(void)
  4480. {
  4481. spin_lock_irq(&mchdev_lock);
  4482. i915_mch_dev = NULL;
  4483. spin_unlock_irq(&mchdev_lock);
  4484. }
  4485. static void intel_init_emon(struct drm_device *dev)
  4486. {
  4487. struct drm_i915_private *dev_priv = dev->dev_private;
  4488. u32 lcfuse;
  4489. u8 pxw[16];
  4490. int i;
  4491. /* Disable to program */
  4492. I915_WRITE(ECR, 0);
  4493. POSTING_READ(ECR);
  4494. /* Program energy weights for various events */
  4495. I915_WRITE(SDEW, 0x15040d00);
  4496. I915_WRITE(CSIEW0, 0x007f0000);
  4497. I915_WRITE(CSIEW1, 0x1e220004);
  4498. I915_WRITE(CSIEW2, 0x04000004);
  4499. for (i = 0; i < 5; i++)
  4500. I915_WRITE(PEW + (i * 4), 0);
  4501. for (i = 0; i < 3; i++)
  4502. I915_WRITE(DEW + (i * 4), 0);
  4503. /* Program P-state weights to account for frequency power adjustment */
  4504. for (i = 0; i < 16; i++) {
  4505. u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4));
  4506. unsigned long freq = intel_pxfreq(pxvidfreq);
  4507. unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >>
  4508. PXVFREQ_PX_SHIFT;
  4509. unsigned long val;
  4510. val = vid * vid;
  4511. val *= (freq / 1000);
  4512. val *= 255;
  4513. val /= (127*127*900);
  4514. if (val > 0xff)
  4515. DRM_ERROR("bad pxval: %ld\n", val);
  4516. pxw[i] = val;
  4517. }
  4518. /* Render standby states get 0 weight */
  4519. pxw[14] = 0;
  4520. pxw[15] = 0;
  4521. for (i = 0; i < 4; i++) {
  4522. u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) |
  4523. (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]);
  4524. I915_WRITE(PXW + (i * 4), val);
  4525. }
  4526. /* Adjust magic regs to magic values (more experimental results) */
  4527. I915_WRITE(OGW0, 0);
  4528. I915_WRITE(OGW1, 0);
  4529. I915_WRITE(EG0, 0x00007f00);
  4530. I915_WRITE(EG1, 0x0000000e);
  4531. I915_WRITE(EG2, 0x000e0000);
  4532. I915_WRITE(EG3, 0x68000300);
  4533. I915_WRITE(EG4, 0x42000000);
  4534. I915_WRITE(EG5, 0x00140031);
  4535. I915_WRITE(EG6, 0);
  4536. I915_WRITE(EG7, 0);
  4537. for (i = 0; i < 8; i++)
  4538. I915_WRITE(PXWL + (i * 4), 0);
  4539. /* Enable PMON + select events */
  4540. I915_WRITE(ECR, 0x80000019);
  4541. lcfuse = I915_READ(LCFUSE02);
  4542. dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK);
  4543. }
  4544. void intel_init_gt_powersave(struct drm_device *dev)
  4545. {
  4546. i915.enable_rc6 = sanitize_rc6_option(dev, i915.enable_rc6);
  4547. if (IS_CHERRYVIEW(dev))
  4548. cherryview_init_gt_powersave(dev);
  4549. else if (IS_VALLEYVIEW(dev))
  4550. valleyview_init_gt_powersave(dev);
  4551. }
  4552. void intel_cleanup_gt_powersave(struct drm_device *dev)
  4553. {
  4554. if (IS_CHERRYVIEW(dev))
  4555. return;
  4556. else if (IS_VALLEYVIEW(dev))
  4557. valleyview_cleanup_gt_powersave(dev);
  4558. }
  4559. static void gen6_suspend_rps(struct drm_device *dev)
  4560. {
  4561. struct drm_i915_private *dev_priv = dev->dev_private;
  4562. flush_delayed_work(&dev_priv->rps.delayed_resume_work);
  4563. /*
  4564. * TODO: disable RPS interrupts on GEN9+ too once RPS support
  4565. * is added for it.
  4566. */
  4567. if (INTEL_INFO(dev)->gen < 9)
  4568. gen6_disable_rps_interrupts(dev);
  4569. }
  4570. /**
  4571. * intel_suspend_gt_powersave - suspend PM work and helper threads
  4572. * @dev: drm device
  4573. *
  4574. * We don't want to disable RC6 or other features here, we just want
  4575. * to make sure any work we've queued has finished and won't bother
  4576. * us while we're suspended.
  4577. */
  4578. void intel_suspend_gt_powersave(struct drm_device *dev)
  4579. {
  4580. struct drm_i915_private *dev_priv = dev->dev_private;
  4581. if (INTEL_INFO(dev)->gen < 6)
  4582. return;
  4583. gen6_suspend_rps(dev);
  4584. /* Force GPU to min freq during suspend */
  4585. gen6_rps_idle(dev_priv);
  4586. }
  4587. void intel_disable_gt_powersave(struct drm_device *dev)
  4588. {
  4589. struct drm_i915_private *dev_priv = dev->dev_private;
  4590. if (IS_IRONLAKE_M(dev)) {
  4591. ironlake_disable_drps(dev);
  4592. ironlake_disable_rc6(dev);
  4593. } else if (INTEL_INFO(dev)->gen >= 6) {
  4594. intel_suspend_gt_powersave(dev);
  4595. mutex_lock(&dev_priv->rps.hw_lock);
  4596. if (INTEL_INFO(dev)->gen >= 9)
  4597. gen9_disable_rps(dev);
  4598. else if (IS_CHERRYVIEW(dev))
  4599. cherryview_disable_rps(dev);
  4600. else if (IS_VALLEYVIEW(dev))
  4601. valleyview_disable_rps(dev);
  4602. else
  4603. gen6_disable_rps(dev);
  4604. dev_priv->rps.enabled = false;
  4605. mutex_unlock(&dev_priv->rps.hw_lock);
  4606. }
  4607. }
  4608. static void intel_gen6_powersave_work(struct work_struct *work)
  4609. {
  4610. struct drm_i915_private *dev_priv =
  4611. container_of(work, struct drm_i915_private,
  4612. rps.delayed_resume_work.work);
  4613. struct drm_device *dev = dev_priv->dev;
  4614. mutex_lock(&dev_priv->rps.hw_lock);
  4615. /*
  4616. * TODO: reset/enable RPS interrupts on GEN9+ too, once RPS support is
  4617. * added for it.
  4618. */
  4619. if (INTEL_INFO(dev)->gen < 9)
  4620. gen6_reset_rps_interrupts(dev);
  4621. if (IS_CHERRYVIEW(dev)) {
  4622. cherryview_enable_rps(dev);
  4623. } else if (IS_VALLEYVIEW(dev)) {
  4624. valleyview_enable_rps(dev);
  4625. } else if (INTEL_INFO(dev)->gen >= 9) {
  4626. gen9_enable_rc6(dev);
  4627. gen9_enable_rps(dev);
  4628. __gen6_update_ring_freq(dev);
  4629. } else if (IS_BROADWELL(dev)) {
  4630. gen8_enable_rps(dev);
  4631. __gen6_update_ring_freq(dev);
  4632. } else {
  4633. gen6_enable_rps(dev);
  4634. __gen6_update_ring_freq(dev);
  4635. }
  4636. dev_priv->rps.enabled = true;
  4637. if (INTEL_INFO(dev)->gen < 9)
  4638. gen6_enable_rps_interrupts(dev);
  4639. mutex_unlock(&dev_priv->rps.hw_lock);
  4640. intel_runtime_pm_put(dev_priv);
  4641. }
  4642. void intel_enable_gt_powersave(struct drm_device *dev)
  4643. {
  4644. struct drm_i915_private *dev_priv = dev->dev_private;
  4645. /* Powersaving is controlled by the host when inside a VM */
  4646. if (intel_vgpu_active(dev))
  4647. return;
  4648. if (IS_IRONLAKE_M(dev)) {
  4649. mutex_lock(&dev->struct_mutex);
  4650. ironlake_enable_drps(dev);
  4651. ironlake_enable_rc6(dev);
  4652. intel_init_emon(dev);
  4653. mutex_unlock(&dev->struct_mutex);
  4654. } else if (INTEL_INFO(dev)->gen >= 6) {
  4655. /*
  4656. * PCU communication is slow and this doesn't need to be
  4657. * done at any specific time, so do this out of our fast path
  4658. * to make resume and init faster.
  4659. *
  4660. * We depend on the HW RC6 power context save/restore
  4661. * mechanism when entering D3 through runtime PM suspend. So
  4662. * disable RPM until RPS/RC6 is properly setup. We can only
  4663. * get here via the driver load/system resume/runtime resume
  4664. * paths, so the _noresume version is enough (and in case of
  4665. * runtime resume it's necessary).
  4666. */
  4667. if (schedule_delayed_work(&dev_priv->rps.delayed_resume_work,
  4668. round_jiffies_up_relative(HZ)))
  4669. intel_runtime_pm_get_noresume(dev_priv);
  4670. }
  4671. }
  4672. void intel_reset_gt_powersave(struct drm_device *dev)
  4673. {
  4674. struct drm_i915_private *dev_priv = dev->dev_private;
  4675. if (INTEL_INFO(dev)->gen < 6)
  4676. return;
  4677. gen6_suspend_rps(dev);
  4678. dev_priv->rps.enabled = false;
  4679. }
  4680. static void ibx_init_clock_gating(struct drm_device *dev)
  4681. {
  4682. struct drm_i915_private *dev_priv = dev->dev_private;
  4683. /*
  4684. * On Ibex Peak and Cougar Point, we need to disable clock
  4685. * gating for the panel power sequencer or it will fail to
  4686. * start up when no ports are active.
  4687. */
  4688. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
  4689. }
  4690. static void g4x_disable_trickle_feed(struct drm_device *dev)
  4691. {
  4692. struct drm_i915_private *dev_priv = dev->dev_private;
  4693. int pipe;
  4694. for_each_pipe(dev_priv, pipe) {
  4695. I915_WRITE(DSPCNTR(pipe),
  4696. I915_READ(DSPCNTR(pipe)) |
  4697. DISPPLANE_TRICKLE_FEED_DISABLE);
  4698. intel_flush_primary_plane(dev_priv, pipe);
  4699. }
  4700. }
  4701. static void ilk_init_lp_watermarks(struct drm_device *dev)
  4702. {
  4703. struct drm_i915_private *dev_priv = dev->dev_private;
  4704. I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN);
  4705. I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN);
  4706. I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN);
  4707. /*
  4708. * Don't touch WM1S_LP_EN here.
  4709. * Doing so could cause underruns.
  4710. */
  4711. }
  4712. static void ironlake_init_clock_gating(struct drm_device *dev)
  4713. {
  4714. struct drm_i915_private *dev_priv = dev->dev_private;
  4715. uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
  4716. /*
  4717. * Required for FBC
  4718. * WaFbcDisableDpfcClockGating:ilk
  4719. */
  4720. dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE |
  4721. ILK_DPFCUNIT_CLOCK_GATE_DISABLE |
  4722. ILK_DPFDUNIT_CLOCK_GATE_ENABLE;
  4723. I915_WRITE(PCH_3DCGDIS0,
  4724. MARIUNIT_CLOCK_GATE_DISABLE |
  4725. SVSMUNIT_CLOCK_GATE_DISABLE);
  4726. I915_WRITE(PCH_3DCGDIS1,
  4727. VFMUNIT_CLOCK_GATE_DISABLE);
  4728. /*
  4729. * According to the spec the following bits should be set in
  4730. * order to enable memory self-refresh
  4731. * The bit 22/21 of 0x42004
  4732. * The bit 5 of 0x42020
  4733. * The bit 15 of 0x45000
  4734. */
  4735. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  4736. (I915_READ(ILK_DISPLAY_CHICKEN2) |
  4737. ILK_DPARB_GATE | ILK_VSDPFD_FULL));
  4738. dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE;
  4739. I915_WRITE(DISP_ARB_CTL,
  4740. (I915_READ(DISP_ARB_CTL) |
  4741. DISP_FBC_WM_DIS));
  4742. ilk_init_lp_watermarks(dev);
  4743. /*
  4744. * Based on the document from hardware guys the following bits
  4745. * should be set unconditionally in order to enable FBC.
  4746. * The bit 22 of 0x42000
  4747. * The bit 22 of 0x42004
  4748. * The bit 7,8,9 of 0x42020.
  4749. */
  4750. if (IS_IRONLAKE_M(dev)) {
  4751. /* WaFbcAsynchFlipDisableFbcQueue:ilk */
  4752. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  4753. I915_READ(ILK_DISPLAY_CHICKEN1) |
  4754. ILK_FBCQ_DIS);
  4755. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  4756. I915_READ(ILK_DISPLAY_CHICKEN2) |
  4757. ILK_DPARB_GATE);
  4758. }
  4759. I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate);
  4760. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  4761. I915_READ(ILK_DISPLAY_CHICKEN2) |
  4762. ILK_ELPIN_409_SELECT);
  4763. I915_WRITE(_3D_CHICKEN2,
  4764. _3D_CHICKEN2_WM_READ_PIPELINED << 16 |
  4765. _3D_CHICKEN2_WM_READ_PIPELINED);
  4766. /* WaDisableRenderCachePipelinedFlush:ilk */
  4767. I915_WRITE(CACHE_MODE_0,
  4768. _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE));
  4769. /* WaDisable_RenderCache_OperationalFlush:ilk */
  4770. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  4771. g4x_disable_trickle_feed(dev);
  4772. ibx_init_clock_gating(dev);
  4773. }
  4774. static void cpt_init_clock_gating(struct drm_device *dev)
  4775. {
  4776. struct drm_i915_private *dev_priv = dev->dev_private;
  4777. int pipe;
  4778. uint32_t val;
  4779. /*
  4780. * On Ibex Peak and Cougar Point, we need to disable clock
  4781. * gating for the panel power sequencer or it will fail to
  4782. * start up when no ports are active.
  4783. */
  4784. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE |
  4785. PCH_DPLUNIT_CLOCK_GATE_DISABLE |
  4786. PCH_CPUNIT_CLOCK_GATE_DISABLE);
  4787. I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) |
  4788. DPLS_EDP_PPS_FIX_DIS);
  4789. /* The below fixes the weird display corruption, a few pixels shifted
  4790. * downward, on (only) LVDS of some HP laptops with IVY.
  4791. */
  4792. for_each_pipe(dev_priv, pipe) {
  4793. val = I915_READ(TRANS_CHICKEN2(pipe));
  4794. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  4795. val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
  4796. if (dev_priv->vbt.fdi_rx_polarity_inverted)
  4797. val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
  4798. val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
  4799. val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER;
  4800. val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH;
  4801. I915_WRITE(TRANS_CHICKEN2(pipe), val);
  4802. }
  4803. /* WADP0ClockGatingDisable */
  4804. for_each_pipe(dev_priv, pipe) {
  4805. I915_WRITE(TRANS_CHICKEN1(pipe),
  4806. TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
  4807. }
  4808. }
  4809. static void gen6_check_mch_setup(struct drm_device *dev)
  4810. {
  4811. struct drm_i915_private *dev_priv = dev->dev_private;
  4812. uint32_t tmp;
  4813. tmp = I915_READ(MCH_SSKPD);
  4814. if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL)
  4815. DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n",
  4816. tmp);
  4817. }
  4818. static void gen6_init_clock_gating(struct drm_device *dev)
  4819. {
  4820. struct drm_i915_private *dev_priv = dev->dev_private;
  4821. uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
  4822. I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate);
  4823. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  4824. I915_READ(ILK_DISPLAY_CHICKEN2) |
  4825. ILK_ELPIN_409_SELECT);
  4826. /* WaDisableHiZPlanesWhenMSAAEnabled:snb */
  4827. I915_WRITE(_3D_CHICKEN,
  4828. _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB));
  4829. /* WaDisable_RenderCache_OperationalFlush:snb */
  4830. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  4831. /*
  4832. * BSpec recoomends 8x4 when MSAA is used,
  4833. * however in practice 16x4 seems fastest.
  4834. *
  4835. * Note that PS/WM thread counts depend on the WIZ hashing
  4836. * disable bit, which we don't touch here, but it's good
  4837. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  4838. */
  4839. I915_WRITE(GEN6_GT_MODE,
  4840. _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
  4841. ilk_init_lp_watermarks(dev);
  4842. I915_WRITE(CACHE_MODE_0,
  4843. _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB));
  4844. I915_WRITE(GEN6_UCGCTL1,
  4845. I915_READ(GEN6_UCGCTL1) |
  4846. GEN6_BLBUNIT_CLOCK_GATE_DISABLE |
  4847. GEN6_CSUNIT_CLOCK_GATE_DISABLE);
  4848. /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
  4849. * gating disable must be set. Failure to set it results in
  4850. * flickering pixels due to Z write ordering failures after
  4851. * some amount of runtime in the Mesa "fire" demo, and Unigine
  4852. * Sanctuary and Tropics, and apparently anything else with
  4853. * alpha test or pixel discard.
  4854. *
  4855. * According to the spec, bit 11 (RCCUNIT) must also be set,
  4856. * but we didn't debug actual testcases to find it out.
  4857. *
  4858. * WaDisableRCCUnitClockGating:snb
  4859. * WaDisableRCPBUnitClockGating:snb
  4860. */
  4861. I915_WRITE(GEN6_UCGCTL2,
  4862. GEN6_RCPBUNIT_CLOCK_GATE_DISABLE |
  4863. GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
  4864. /* WaStripsFansDisableFastClipPerformanceFix:snb */
  4865. I915_WRITE(_3D_CHICKEN3,
  4866. _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL));
  4867. /*
  4868. * Bspec says:
  4869. * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and
  4870. * 3DSTATE_SF number of SF output attributes is more than 16."
  4871. */
  4872. I915_WRITE(_3D_CHICKEN3,
  4873. _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH));
  4874. /*
  4875. * According to the spec the following bits should be
  4876. * set in order to enable memory self-refresh and fbc:
  4877. * The bit21 and bit22 of 0x42000
  4878. * The bit21 and bit22 of 0x42004
  4879. * The bit5 and bit7 of 0x42020
  4880. * The bit14 of 0x70180
  4881. * The bit14 of 0x71180
  4882. *
  4883. * WaFbcAsynchFlipDisableFbcQueue:snb
  4884. */
  4885. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  4886. I915_READ(ILK_DISPLAY_CHICKEN1) |
  4887. ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
  4888. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  4889. I915_READ(ILK_DISPLAY_CHICKEN2) |
  4890. ILK_DPARB_GATE | ILK_VSDPFD_FULL);
  4891. I915_WRITE(ILK_DSPCLK_GATE_D,
  4892. I915_READ(ILK_DSPCLK_GATE_D) |
  4893. ILK_DPARBUNIT_CLOCK_GATE_ENABLE |
  4894. ILK_DPFDUNIT_CLOCK_GATE_ENABLE);
  4895. g4x_disable_trickle_feed(dev);
  4896. cpt_init_clock_gating(dev);
  4897. gen6_check_mch_setup(dev);
  4898. }
  4899. static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv)
  4900. {
  4901. uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE);
  4902. /*
  4903. * WaVSThreadDispatchOverride:ivb,vlv
  4904. *
  4905. * This actually overrides the dispatch
  4906. * mode for all thread types.
  4907. */
  4908. reg &= ~GEN7_FF_SCHED_MASK;
  4909. reg |= GEN7_FF_TS_SCHED_HW;
  4910. reg |= GEN7_FF_VS_SCHED_HW;
  4911. reg |= GEN7_FF_DS_SCHED_HW;
  4912. I915_WRITE(GEN7_FF_THREAD_MODE, reg);
  4913. }
  4914. static void lpt_init_clock_gating(struct drm_device *dev)
  4915. {
  4916. struct drm_i915_private *dev_priv = dev->dev_private;
  4917. /*
  4918. * TODO: this bit should only be enabled when really needed, then
  4919. * disabled when not needed anymore in order to save power.
  4920. */
  4921. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE)
  4922. I915_WRITE(SOUTH_DSPCLK_GATE_D,
  4923. I915_READ(SOUTH_DSPCLK_GATE_D) |
  4924. PCH_LP_PARTITION_LEVEL_DISABLE);
  4925. /* WADPOClockGatingDisable:hsw */
  4926. I915_WRITE(_TRANSA_CHICKEN1,
  4927. I915_READ(_TRANSA_CHICKEN1) |
  4928. TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
  4929. }
  4930. static void lpt_suspend_hw(struct drm_device *dev)
  4931. {
  4932. struct drm_i915_private *dev_priv = dev->dev_private;
  4933. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  4934. uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D);
  4935. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  4936. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  4937. }
  4938. }
  4939. static void broadwell_init_clock_gating(struct drm_device *dev)
  4940. {
  4941. struct drm_i915_private *dev_priv = dev->dev_private;
  4942. enum pipe pipe;
  4943. I915_WRITE(WM3_LP_ILK, 0);
  4944. I915_WRITE(WM2_LP_ILK, 0);
  4945. I915_WRITE(WM1_LP_ILK, 0);
  4946. /* WaSwitchSolVfFArbitrationPriority:bdw */
  4947. I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
  4948. /* WaPsrDPAMaskVBlankInSRD:bdw */
  4949. I915_WRITE(CHICKEN_PAR1_1,
  4950. I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD);
  4951. /* WaPsrDPRSUnmaskVBlankInSRD:bdw */
  4952. for_each_pipe(dev_priv, pipe) {
  4953. I915_WRITE(CHICKEN_PIPESL_1(pipe),
  4954. I915_READ(CHICKEN_PIPESL_1(pipe)) |
  4955. BDW_DPRS_MASK_VBLANK_SRD);
  4956. }
  4957. /* WaVSRefCountFullforceMissDisable:bdw */
  4958. /* WaDSRefCountFullforceMissDisable:bdw */
  4959. I915_WRITE(GEN7_FF_THREAD_MODE,
  4960. I915_READ(GEN7_FF_THREAD_MODE) &
  4961. ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
  4962. I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL,
  4963. _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
  4964. /* WaDisableSDEUnitClockGating:bdw */
  4965. I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
  4966. GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  4967. lpt_init_clock_gating(dev);
  4968. }
  4969. static void haswell_init_clock_gating(struct drm_device *dev)
  4970. {
  4971. struct drm_i915_private *dev_priv = dev->dev_private;
  4972. ilk_init_lp_watermarks(dev);
  4973. /* L3 caching of data atomics doesn't work -- disable it. */
  4974. I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE);
  4975. I915_WRITE(HSW_ROW_CHICKEN3,
  4976. _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE));
  4977. /* This is required by WaCatErrorRejectionIssue:hsw */
  4978. I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  4979. I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
  4980. GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  4981. /* WaVSRefCountFullforceMissDisable:hsw */
  4982. I915_WRITE(GEN7_FF_THREAD_MODE,
  4983. I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME);
  4984. /* WaDisable_RenderCache_OperationalFlush:hsw */
  4985. I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  4986. /* enable HiZ Raw Stall Optimization */
  4987. I915_WRITE(CACHE_MODE_0_GEN7,
  4988. _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE));
  4989. /* WaDisable4x2SubspanOptimization:hsw */
  4990. I915_WRITE(CACHE_MODE_1,
  4991. _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
  4992. /*
  4993. * BSpec recommends 8x4 when MSAA is used,
  4994. * however in practice 16x4 seems fastest.
  4995. *
  4996. * Note that PS/WM thread counts depend on the WIZ hashing
  4997. * disable bit, which we don't touch here, but it's good
  4998. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  4999. */
  5000. I915_WRITE(GEN7_GT_MODE,
  5001. _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
  5002. /* WaSampleCChickenBitEnable:hsw */
  5003. I915_WRITE(HALF_SLICE_CHICKEN3,
  5004. _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE));
  5005. /* WaSwitchSolVfFArbitrationPriority:hsw */
  5006. I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
  5007. /* WaRsPkgCStateDisplayPMReq:hsw */
  5008. I915_WRITE(CHICKEN_PAR1_1,
  5009. I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
  5010. lpt_init_clock_gating(dev);
  5011. }
  5012. static void ivybridge_init_clock_gating(struct drm_device *dev)
  5013. {
  5014. struct drm_i915_private *dev_priv = dev->dev_private;
  5015. uint32_t snpcr;
  5016. ilk_init_lp_watermarks(dev);
  5017. I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE);
  5018. /* WaDisableEarlyCull:ivb */
  5019. I915_WRITE(_3D_CHICKEN3,
  5020. _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL));
  5021. /* WaDisableBackToBackFlipFix:ivb */
  5022. I915_WRITE(IVB_CHICKEN3,
  5023. CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
  5024. CHICKEN3_DGMG_DONE_FIX_DISABLE);
  5025. /* WaDisablePSDDualDispatchEnable:ivb */
  5026. if (IS_IVB_GT1(dev))
  5027. I915_WRITE(GEN7_HALF_SLICE_CHICKEN1,
  5028. _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE));
  5029. /* WaDisable_RenderCache_OperationalFlush:ivb */
  5030. I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  5031. /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */
  5032. I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1,
  5033. GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC);
  5034. /* WaApplyL3ControlAndL3ChickenMode:ivb */
  5035. I915_WRITE(GEN7_L3CNTLREG1,
  5036. GEN7_WA_FOR_GEN7_L3_CONTROL);
  5037. I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER,
  5038. GEN7_WA_L3_CHICKEN_MODE);
  5039. if (IS_IVB_GT1(dev))
  5040. I915_WRITE(GEN7_ROW_CHICKEN2,
  5041. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  5042. else {
  5043. /* must write both registers */
  5044. I915_WRITE(GEN7_ROW_CHICKEN2,
  5045. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  5046. I915_WRITE(GEN7_ROW_CHICKEN2_GT2,
  5047. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  5048. }
  5049. /* WaForceL3Serialization:ivb */
  5050. I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) &
  5051. ~L3SQ_URB_READ_CAM_MATCH_DISABLE);
  5052. /*
  5053. * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
  5054. * This implements the WaDisableRCZUnitClockGating:ivb workaround.
  5055. */
  5056. I915_WRITE(GEN6_UCGCTL2,
  5057. GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
  5058. /* This is required by WaCatErrorRejectionIssue:ivb */
  5059. I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  5060. I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
  5061. GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  5062. g4x_disable_trickle_feed(dev);
  5063. gen7_setup_fixed_func_scheduler(dev_priv);
  5064. if (0) { /* causes HiZ corruption on ivb:gt1 */
  5065. /* enable HiZ Raw Stall Optimization */
  5066. I915_WRITE(CACHE_MODE_0_GEN7,
  5067. _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE));
  5068. }
  5069. /* WaDisable4x2SubspanOptimization:ivb */
  5070. I915_WRITE(CACHE_MODE_1,
  5071. _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
  5072. /*
  5073. * BSpec recommends 8x4 when MSAA is used,
  5074. * however in practice 16x4 seems fastest.
  5075. *
  5076. * Note that PS/WM thread counts depend on the WIZ hashing
  5077. * disable bit, which we don't touch here, but it's good
  5078. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  5079. */
  5080. I915_WRITE(GEN7_GT_MODE,
  5081. _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
  5082. snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
  5083. snpcr &= ~GEN6_MBC_SNPCR_MASK;
  5084. snpcr |= GEN6_MBC_SNPCR_MED;
  5085. I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
  5086. if (!HAS_PCH_NOP(dev))
  5087. cpt_init_clock_gating(dev);
  5088. gen6_check_mch_setup(dev);
  5089. }
  5090. static void valleyview_init_clock_gating(struct drm_device *dev)
  5091. {
  5092. struct drm_i915_private *dev_priv = dev->dev_private;
  5093. I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE);
  5094. /* WaDisableEarlyCull:vlv */
  5095. I915_WRITE(_3D_CHICKEN3,
  5096. _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL));
  5097. /* WaDisableBackToBackFlipFix:vlv */
  5098. I915_WRITE(IVB_CHICKEN3,
  5099. CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
  5100. CHICKEN3_DGMG_DONE_FIX_DISABLE);
  5101. /* WaPsdDispatchEnable:vlv */
  5102. /* WaDisablePSDDualDispatchEnable:vlv */
  5103. I915_WRITE(GEN7_HALF_SLICE_CHICKEN1,
  5104. _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP |
  5105. GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE));
  5106. /* WaDisable_RenderCache_OperationalFlush:vlv */
  5107. I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  5108. /* WaForceL3Serialization:vlv */
  5109. I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) &
  5110. ~L3SQ_URB_READ_CAM_MATCH_DISABLE);
  5111. /* WaDisableDopClockGating:vlv */
  5112. I915_WRITE(GEN7_ROW_CHICKEN2,
  5113. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  5114. /* This is required by WaCatErrorRejectionIssue:vlv */
  5115. I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  5116. I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
  5117. GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  5118. gen7_setup_fixed_func_scheduler(dev_priv);
  5119. /*
  5120. * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
  5121. * This implements the WaDisableRCZUnitClockGating:vlv workaround.
  5122. */
  5123. I915_WRITE(GEN6_UCGCTL2,
  5124. GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
  5125. /* WaDisableL3Bank2xClockGate:vlv
  5126. * Disabling L3 clock gating- MMIO 940c[25] = 1
  5127. * Set bit 25, to disable L3_BANK_2x_CLK_GATING */
  5128. I915_WRITE(GEN7_UCGCTL4,
  5129. I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE);
  5130. I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
  5131. /*
  5132. * BSpec says this must be set, even though
  5133. * WaDisable4x2SubspanOptimization isn't listed for VLV.
  5134. */
  5135. I915_WRITE(CACHE_MODE_1,
  5136. _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
  5137. /*
  5138. * BSpec recommends 8x4 when MSAA is used,
  5139. * however in practice 16x4 seems fastest.
  5140. *
  5141. * Note that PS/WM thread counts depend on the WIZ hashing
  5142. * disable bit, which we don't touch here, but it's good
  5143. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  5144. */
  5145. I915_WRITE(GEN7_GT_MODE,
  5146. _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
  5147. /*
  5148. * WaIncreaseL3CreditsForVLVB0:vlv
  5149. * This is the hardware default actually.
  5150. */
  5151. I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE);
  5152. /*
  5153. * WaDisableVLVClockGating_VBIIssue:vlv
  5154. * Disable clock gating on th GCFG unit to prevent a delay
  5155. * in the reporting of vblank events.
  5156. */
  5157. I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS);
  5158. }
  5159. static void cherryview_init_clock_gating(struct drm_device *dev)
  5160. {
  5161. struct drm_i915_private *dev_priv = dev->dev_private;
  5162. I915_WRITE(DSPCLK_GATE_D, VRHUNIT_CLOCK_GATE_DISABLE);
  5163. I915_WRITE(MI_ARB_VLV, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE);
  5164. /* WaVSRefCountFullforceMissDisable:chv */
  5165. /* WaDSRefCountFullforceMissDisable:chv */
  5166. I915_WRITE(GEN7_FF_THREAD_MODE,
  5167. I915_READ(GEN7_FF_THREAD_MODE) &
  5168. ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
  5169. /* WaDisableSemaphoreAndSyncFlipWait:chv */
  5170. I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL,
  5171. _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
  5172. /* WaDisableCSUnitClockGating:chv */
  5173. I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) |
  5174. GEN6_CSUNIT_CLOCK_GATE_DISABLE);
  5175. /* WaDisableSDEUnitClockGating:chv */
  5176. I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
  5177. GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  5178. }
  5179. static void g4x_init_clock_gating(struct drm_device *dev)
  5180. {
  5181. struct drm_i915_private *dev_priv = dev->dev_private;
  5182. uint32_t dspclk_gate;
  5183. I915_WRITE(RENCLK_GATE_D1, 0);
  5184. I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  5185. GS_UNIT_CLOCK_GATE_DISABLE |
  5186. CL_UNIT_CLOCK_GATE_DISABLE);
  5187. I915_WRITE(RAMCLK_GATE_D, 0);
  5188. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  5189. OVRUNIT_CLOCK_GATE_DISABLE |
  5190. OVCUNIT_CLOCK_GATE_DISABLE;
  5191. if (IS_GM45(dev))
  5192. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  5193. I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
  5194. /* WaDisableRenderCachePipelinedFlush */
  5195. I915_WRITE(CACHE_MODE_0,
  5196. _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE));
  5197. /* WaDisable_RenderCache_OperationalFlush:g4x */
  5198. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  5199. g4x_disable_trickle_feed(dev);
  5200. }
  5201. static void crestline_init_clock_gating(struct drm_device *dev)
  5202. {
  5203. struct drm_i915_private *dev_priv = dev->dev_private;
  5204. I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  5205. I915_WRITE(RENCLK_GATE_D2, 0);
  5206. I915_WRITE(DSPCLK_GATE_D, 0);
  5207. I915_WRITE(RAMCLK_GATE_D, 0);
  5208. I915_WRITE16(DEUC, 0);
  5209. I915_WRITE(MI_ARB_STATE,
  5210. _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
  5211. /* WaDisable_RenderCache_OperationalFlush:gen4 */
  5212. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  5213. }
  5214. static void broadwater_init_clock_gating(struct drm_device *dev)
  5215. {
  5216. struct drm_i915_private *dev_priv = dev->dev_private;
  5217. I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  5218. I965_RCC_CLOCK_GATE_DISABLE |
  5219. I965_RCPB_CLOCK_GATE_DISABLE |
  5220. I965_ISC_CLOCK_GATE_DISABLE |
  5221. I965_FBC_CLOCK_GATE_DISABLE);
  5222. I915_WRITE(RENCLK_GATE_D2, 0);
  5223. I915_WRITE(MI_ARB_STATE,
  5224. _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
  5225. /* WaDisable_RenderCache_OperationalFlush:gen4 */
  5226. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  5227. }
  5228. static void gen3_init_clock_gating(struct drm_device *dev)
  5229. {
  5230. struct drm_i915_private *dev_priv = dev->dev_private;
  5231. u32 dstate = I915_READ(D_STATE);
  5232. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  5233. DSTATE_DOT_CLOCK_GATING;
  5234. I915_WRITE(D_STATE, dstate);
  5235. if (IS_PINEVIEW(dev))
  5236. I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY));
  5237. /* IIR "flip pending" means done if this bit is set */
  5238. I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE));
  5239. /* interrupts should cause a wake up from C3 */
  5240. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN));
  5241. /* On GEN3 we really need to make sure the ARB C3 LP bit is set */
  5242. I915_WRITE(MI_ARB_STATE, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE));
  5243. I915_WRITE(MI_ARB_STATE,
  5244. _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
  5245. }
  5246. static void i85x_init_clock_gating(struct drm_device *dev)
  5247. {
  5248. struct drm_i915_private *dev_priv = dev->dev_private;
  5249. I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  5250. /* interrupts should cause a wake up from C3 */
  5251. I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) |
  5252. _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE));
  5253. I915_WRITE(MEM_MODE,
  5254. _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE));
  5255. }
  5256. static void i830_init_clock_gating(struct drm_device *dev)
  5257. {
  5258. struct drm_i915_private *dev_priv = dev->dev_private;
  5259. I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
  5260. I915_WRITE(MEM_MODE,
  5261. _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) |
  5262. _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE));
  5263. }
  5264. void intel_init_clock_gating(struct drm_device *dev)
  5265. {
  5266. struct drm_i915_private *dev_priv = dev->dev_private;
  5267. if (dev_priv->display.init_clock_gating)
  5268. dev_priv->display.init_clock_gating(dev);
  5269. }
  5270. void intel_suspend_hw(struct drm_device *dev)
  5271. {
  5272. if (HAS_PCH_LPT(dev))
  5273. lpt_suspend_hw(dev);
  5274. }
  5275. /* Set up chip specific power management-related functions */
  5276. void intel_init_pm(struct drm_device *dev)
  5277. {
  5278. struct drm_i915_private *dev_priv = dev->dev_private;
  5279. intel_fbc_init(dev_priv);
  5280. /* For cxsr */
  5281. if (IS_PINEVIEW(dev))
  5282. i915_pineview_get_mem_freq(dev);
  5283. else if (IS_GEN5(dev))
  5284. i915_ironlake_get_mem_freq(dev);
  5285. /* For FIFO watermark updates */
  5286. if (INTEL_INFO(dev)->gen >= 9) {
  5287. skl_setup_wm_latency(dev);
  5288. dev_priv->display.init_clock_gating = skl_init_clock_gating;
  5289. dev_priv->display.update_wm = skl_update_wm;
  5290. dev_priv->display.update_sprite_wm = skl_update_sprite_wm;
  5291. } else if (HAS_PCH_SPLIT(dev)) {
  5292. ilk_setup_wm_latency(dev);
  5293. if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] &&
  5294. dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) ||
  5295. (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] &&
  5296. dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) {
  5297. dev_priv->display.update_wm = ilk_update_wm;
  5298. dev_priv->display.update_sprite_wm = ilk_update_sprite_wm;
  5299. } else {
  5300. DRM_DEBUG_KMS("Failed to read display plane latency. "
  5301. "Disable CxSR\n");
  5302. }
  5303. if (IS_GEN5(dev))
  5304. dev_priv->display.init_clock_gating = ironlake_init_clock_gating;
  5305. else if (IS_GEN6(dev))
  5306. dev_priv->display.init_clock_gating = gen6_init_clock_gating;
  5307. else if (IS_IVYBRIDGE(dev))
  5308. dev_priv->display.init_clock_gating = ivybridge_init_clock_gating;
  5309. else if (IS_HASWELL(dev))
  5310. dev_priv->display.init_clock_gating = haswell_init_clock_gating;
  5311. else if (INTEL_INFO(dev)->gen == 8)
  5312. dev_priv->display.init_clock_gating = broadwell_init_clock_gating;
  5313. } else if (IS_CHERRYVIEW(dev)) {
  5314. dev_priv->display.update_wm = cherryview_update_wm;
  5315. dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm;
  5316. dev_priv->display.init_clock_gating =
  5317. cherryview_init_clock_gating;
  5318. } else if (IS_VALLEYVIEW(dev)) {
  5319. dev_priv->display.update_wm = valleyview_update_wm;
  5320. dev_priv->display.update_sprite_wm = valleyview_update_sprite_wm;
  5321. dev_priv->display.init_clock_gating =
  5322. valleyview_init_clock_gating;
  5323. } else if (IS_PINEVIEW(dev)) {
  5324. if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev),
  5325. dev_priv->is_ddr3,
  5326. dev_priv->fsb_freq,
  5327. dev_priv->mem_freq)) {
  5328. DRM_INFO("failed to find known CxSR latency "
  5329. "(found ddr%s fsb freq %d, mem freq %d), "
  5330. "disabling CxSR\n",
  5331. (dev_priv->is_ddr3 == 1) ? "3" : "2",
  5332. dev_priv->fsb_freq, dev_priv->mem_freq);
  5333. /* Disable CxSR and never update its watermark again */
  5334. intel_set_memory_cxsr(dev_priv, false);
  5335. dev_priv->display.update_wm = NULL;
  5336. } else
  5337. dev_priv->display.update_wm = pineview_update_wm;
  5338. dev_priv->display.init_clock_gating = gen3_init_clock_gating;
  5339. } else if (IS_G4X(dev)) {
  5340. dev_priv->display.update_wm = g4x_update_wm;
  5341. dev_priv->display.init_clock_gating = g4x_init_clock_gating;
  5342. } else if (IS_GEN4(dev)) {
  5343. dev_priv->display.update_wm = i965_update_wm;
  5344. if (IS_CRESTLINE(dev))
  5345. dev_priv->display.init_clock_gating = crestline_init_clock_gating;
  5346. else if (IS_BROADWATER(dev))
  5347. dev_priv->display.init_clock_gating = broadwater_init_clock_gating;
  5348. } else if (IS_GEN3(dev)) {
  5349. dev_priv->display.update_wm = i9xx_update_wm;
  5350. dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
  5351. dev_priv->display.init_clock_gating = gen3_init_clock_gating;
  5352. } else if (IS_GEN2(dev)) {
  5353. if (INTEL_INFO(dev)->num_pipes == 1) {
  5354. dev_priv->display.update_wm = i845_update_wm;
  5355. dev_priv->display.get_fifo_size = i845_get_fifo_size;
  5356. } else {
  5357. dev_priv->display.update_wm = i9xx_update_wm;
  5358. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  5359. }
  5360. if (IS_I85X(dev) || IS_I865G(dev))
  5361. dev_priv->display.init_clock_gating = i85x_init_clock_gating;
  5362. else
  5363. dev_priv->display.init_clock_gating = i830_init_clock_gating;
  5364. } else {
  5365. DRM_ERROR("unexpected fall-through in intel_init_pm\n");
  5366. }
  5367. }
  5368. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val)
  5369. {
  5370. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  5371. if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) {
  5372. DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n");
  5373. return -EAGAIN;
  5374. }
  5375. I915_WRITE(GEN6_PCODE_DATA, *val);
  5376. I915_WRITE(GEN6_PCODE_DATA1, 0);
  5377. I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox);
  5378. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5379. 500)) {
  5380. DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox);
  5381. return -ETIMEDOUT;
  5382. }
  5383. *val = I915_READ(GEN6_PCODE_DATA);
  5384. I915_WRITE(GEN6_PCODE_DATA, 0);
  5385. return 0;
  5386. }
  5387. int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u32 mbox, u32 val)
  5388. {
  5389. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  5390. if (I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) {
  5391. DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n");
  5392. return -EAGAIN;
  5393. }
  5394. I915_WRITE(GEN6_PCODE_DATA, val);
  5395. I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox);
  5396. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  5397. 500)) {
  5398. DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox);
  5399. return -ETIMEDOUT;
  5400. }
  5401. I915_WRITE(GEN6_PCODE_DATA, 0);
  5402. return 0;
  5403. }
  5404. static int vlv_gpu_freq_div(unsigned int czclk_freq)
  5405. {
  5406. switch (czclk_freq) {
  5407. case 200:
  5408. return 10;
  5409. case 267:
  5410. return 12;
  5411. case 320:
  5412. case 333:
  5413. return 16;
  5414. case 400:
  5415. return 20;
  5416. default:
  5417. return -1;
  5418. }
  5419. }
  5420. static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val)
  5421. {
  5422. int div, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4);
  5423. div = vlv_gpu_freq_div(czclk_freq);
  5424. if (div < 0)
  5425. return div;
  5426. return DIV_ROUND_CLOSEST(czclk_freq * (val + 6 - 0xbd), div);
  5427. }
  5428. static int byt_freq_opcode(struct drm_i915_private *dev_priv, int val)
  5429. {
  5430. int mul, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->mem_freq, 4);
  5431. mul = vlv_gpu_freq_div(czclk_freq);
  5432. if (mul < 0)
  5433. return mul;
  5434. return DIV_ROUND_CLOSEST(mul * val, czclk_freq) + 0xbd - 6;
  5435. }
  5436. static int chv_gpu_freq(struct drm_i915_private *dev_priv, int val)
  5437. {
  5438. int div, czclk_freq = dev_priv->rps.cz_freq;
  5439. div = vlv_gpu_freq_div(czclk_freq) / 2;
  5440. if (div < 0)
  5441. return div;
  5442. return DIV_ROUND_CLOSEST(czclk_freq * val, 2 * div) / 2;
  5443. }
  5444. static int chv_freq_opcode(struct drm_i915_private *dev_priv, int val)
  5445. {
  5446. int mul, czclk_freq = dev_priv->rps.cz_freq;
  5447. mul = vlv_gpu_freq_div(czclk_freq) / 2;
  5448. if (mul < 0)
  5449. return mul;
  5450. /* CHV needs even values */
  5451. return DIV_ROUND_CLOSEST(val * 2 * mul, czclk_freq) * 2;
  5452. }
  5453. int intel_gpu_freq(struct drm_i915_private *dev_priv, int val)
  5454. {
  5455. if (IS_CHERRYVIEW(dev_priv->dev))
  5456. return chv_gpu_freq(dev_priv, val);
  5457. else if (IS_VALLEYVIEW(dev_priv->dev))
  5458. return byt_gpu_freq(dev_priv, val);
  5459. else
  5460. return val * GT_FREQUENCY_MULTIPLIER;
  5461. }
  5462. int intel_freq_opcode(struct drm_i915_private *dev_priv, int val)
  5463. {
  5464. if (IS_CHERRYVIEW(dev_priv->dev))
  5465. return chv_freq_opcode(dev_priv, val);
  5466. else if (IS_VALLEYVIEW(dev_priv->dev))
  5467. return byt_freq_opcode(dev_priv, val);
  5468. else
  5469. return val / GT_FREQUENCY_MULTIPLIER;
  5470. }
  5471. void intel_pm_setup(struct drm_device *dev)
  5472. {
  5473. struct drm_i915_private *dev_priv = dev->dev_private;
  5474. mutex_init(&dev_priv->rps.hw_lock);
  5475. INIT_DELAYED_WORK(&dev_priv->rps.delayed_resume_work,
  5476. intel_gen6_powersave_work);
  5477. dev_priv->pm.suspended = false;
  5478. }