intel_pm.c 229 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142
  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 <drm/drm_plane_helper.h>
  29. #include "i915_drv.h"
  30. #include "intel_drv.h"
  31. #include "../../../platform/x86/intel_ips.h"
  32. #include <linux/module.h>
  33. /**
  34. * DOC: RC6
  35. *
  36. * RC6 is a special power stage which allows the GPU to enter an very
  37. * low-voltage mode when idle, using down to 0V while at this stage. This
  38. * stage is entered automatically when the GPU is idle when RC6 support is
  39. * enabled, and as soon as new workload arises GPU wakes up automatically as well.
  40. *
  41. * There are different RC6 modes available in Intel GPU, which differentiate
  42. * among each other with the latency required to enter and leave RC6 and
  43. * voltage consumed by the GPU in different states.
  44. *
  45. * The combination of the following flags define which states GPU is allowed
  46. * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and
  47. * RC6pp is deepest RC6. Their support by hardware varies according to the
  48. * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one
  49. * which brings the most power savings; deeper states save more power, but
  50. * require higher latency to switch to and wake up.
  51. */
  52. #define INTEL_RC6_ENABLE (1<<0)
  53. #define INTEL_RC6p_ENABLE (1<<1)
  54. #define INTEL_RC6pp_ENABLE (1<<2)
  55. static void gen9_init_clock_gating(struct drm_device *dev)
  56. {
  57. struct drm_i915_private *dev_priv = dev->dev_private;
  58. /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl */
  59. I915_WRITE(CHICKEN_PAR1_1,
  60. I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP);
  61. I915_WRITE(GEN8_CONFIG0,
  62. I915_READ(GEN8_CONFIG0) | GEN9_DEFAULT_FIXES);
  63. /* WaEnableChickenDCPR:skl,bxt,kbl */
  64. I915_WRITE(GEN8_CHICKEN_DCPR_1,
  65. I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM);
  66. /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl */
  67. /* WaFbcWakeMemOn:skl,bxt,kbl */
  68. I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) |
  69. DISP_FBC_WM_DIS |
  70. DISP_FBC_MEMORY_WAKE);
  71. /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl */
  72. I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
  73. ILK_DPFC_DISABLE_DUMMY0);
  74. }
  75. static void bxt_init_clock_gating(struct drm_device *dev)
  76. {
  77. struct drm_i915_private *dev_priv = to_i915(dev);
  78. gen9_init_clock_gating(dev);
  79. /* WaDisableSDEUnitClockGating:bxt */
  80. I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
  81. GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  82. /*
  83. * FIXME:
  84. * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only.
  85. */
  86. I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
  87. GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ);
  88. /*
  89. * Wa: Backlight PWM may stop in the asserted state, causing backlight
  90. * to stay fully on.
  91. */
  92. if (IS_BXT_REVID(dev_priv, BXT_REVID_B0, REVID_FOREVER))
  93. I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
  94. PWM1_GATING_DIS | PWM2_GATING_DIS);
  95. }
  96. static void i915_pineview_get_mem_freq(struct drm_device *dev)
  97. {
  98. struct drm_i915_private *dev_priv = to_i915(dev);
  99. u32 tmp;
  100. tmp = I915_READ(CLKCFG);
  101. switch (tmp & CLKCFG_FSB_MASK) {
  102. case CLKCFG_FSB_533:
  103. dev_priv->fsb_freq = 533; /* 133*4 */
  104. break;
  105. case CLKCFG_FSB_800:
  106. dev_priv->fsb_freq = 800; /* 200*4 */
  107. break;
  108. case CLKCFG_FSB_667:
  109. dev_priv->fsb_freq = 667; /* 167*4 */
  110. break;
  111. case CLKCFG_FSB_400:
  112. dev_priv->fsb_freq = 400; /* 100*4 */
  113. break;
  114. }
  115. switch (tmp & CLKCFG_MEM_MASK) {
  116. case CLKCFG_MEM_533:
  117. dev_priv->mem_freq = 533;
  118. break;
  119. case CLKCFG_MEM_667:
  120. dev_priv->mem_freq = 667;
  121. break;
  122. case CLKCFG_MEM_800:
  123. dev_priv->mem_freq = 800;
  124. break;
  125. }
  126. /* detect pineview DDR3 setting */
  127. tmp = I915_READ(CSHRDDR3CTL);
  128. dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0;
  129. }
  130. static void i915_ironlake_get_mem_freq(struct drm_device *dev)
  131. {
  132. struct drm_i915_private *dev_priv = to_i915(dev);
  133. u16 ddrpll, csipll;
  134. ddrpll = I915_READ16(DDRMPLL1);
  135. csipll = I915_READ16(CSIPLL0);
  136. switch (ddrpll & 0xff) {
  137. case 0xc:
  138. dev_priv->mem_freq = 800;
  139. break;
  140. case 0x10:
  141. dev_priv->mem_freq = 1066;
  142. break;
  143. case 0x14:
  144. dev_priv->mem_freq = 1333;
  145. break;
  146. case 0x18:
  147. dev_priv->mem_freq = 1600;
  148. break;
  149. default:
  150. DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n",
  151. ddrpll & 0xff);
  152. dev_priv->mem_freq = 0;
  153. break;
  154. }
  155. dev_priv->ips.r_t = dev_priv->mem_freq;
  156. switch (csipll & 0x3ff) {
  157. case 0x00c:
  158. dev_priv->fsb_freq = 3200;
  159. break;
  160. case 0x00e:
  161. dev_priv->fsb_freq = 3733;
  162. break;
  163. case 0x010:
  164. dev_priv->fsb_freq = 4266;
  165. break;
  166. case 0x012:
  167. dev_priv->fsb_freq = 4800;
  168. break;
  169. case 0x014:
  170. dev_priv->fsb_freq = 5333;
  171. break;
  172. case 0x016:
  173. dev_priv->fsb_freq = 5866;
  174. break;
  175. case 0x018:
  176. dev_priv->fsb_freq = 6400;
  177. break;
  178. default:
  179. DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n",
  180. csipll & 0x3ff);
  181. dev_priv->fsb_freq = 0;
  182. break;
  183. }
  184. if (dev_priv->fsb_freq == 3200) {
  185. dev_priv->ips.c_m = 0;
  186. } else if (dev_priv->fsb_freq > 3200 && dev_priv->fsb_freq <= 4800) {
  187. dev_priv->ips.c_m = 1;
  188. } else {
  189. dev_priv->ips.c_m = 2;
  190. }
  191. }
  192. static const struct cxsr_latency cxsr_latency_table[] = {
  193. {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
  194. {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
  195. {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
  196. {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
  197. {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
  198. {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
  199. {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
  200. {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
  201. {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
  202. {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
  203. {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
  204. {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
  205. {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
  206. {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
  207. {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
  208. {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
  209. {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
  210. {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
  211. {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
  212. {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
  213. {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
  214. {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
  215. {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
  216. {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
  217. {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
  218. {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
  219. {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
  220. {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
  221. {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
  222. {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
  223. };
  224. static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop,
  225. int is_ddr3,
  226. int fsb,
  227. int mem)
  228. {
  229. const struct cxsr_latency *latency;
  230. int i;
  231. if (fsb == 0 || mem == 0)
  232. return NULL;
  233. for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
  234. latency = &cxsr_latency_table[i];
  235. if (is_desktop == latency->is_desktop &&
  236. is_ddr3 == latency->is_ddr3 &&
  237. fsb == latency->fsb_freq && mem == latency->mem_freq)
  238. return latency;
  239. }
  240. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  241. return NULL;
  242. }
  243. static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable)
  244. {
  245. u32 val;
  246. mutex_lock(&dev_priv->rps.hw_lock);
  247. val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
  248. if (enable)
  249. val &= ~FORCE_DDR_HIGH_FREQ;
  250. else
  251. val |= FORCE_DDR_HIGH_FREQ;
  252. val &= ~FORCE_DDR_LOW_FREQ;
  253. val |= FORCE_DDR_FREQ_REQ_ACK;
  254. vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val);
  255. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) &
  256. FORCE_DDR_FREQ_REQ_ACK) == 0, 3))
  257. DRM_ERROR("timed out waiting for Punit DDR DVFS request\n");
  258. mutex_unlock(&dev_priv->rps.hw_lock);
  259. }
  260. static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable)
  261. {
  262. u32 val;
  263. mutex_lock(&dev_priv->rps.hw_lock);
  264. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  265. if (enable)
  266. val |= DSP_MAXFIFO_PM5_ENABLE;
  267. else
  268. val &= ~DSP_MAXFIFO_PM5_ENABLE;
  269. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  270. mutex_unlock(&dev_priv->rps.hw_lock);
  271. }
  272. #define FW_WM(value, plane) \
  273. (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK)
  274. void intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable)
  275. {
  276. struct drm_device *dev = &dev_priv->drm;
  277. u32 val;
  278. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  279. I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0);
  280. POSTING_READ(FW_BLC_SELF_VLV);
  281. dev_priv->wm.vlv.cxsr = enable;
  282. } else if (IS_G4X(dev) || IS_CRESTLINE(dev)) {
  283. I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0);
  284. POSTING_READ(FW_BLC_SELF);
  285. } else if (IS_PINEVIEW(dev)) {
  286. val = I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN;
  287. val |= enable ? PINEVIEW_SELF_REFRESH_EN : 0;
  288. I915_WRITE(DSPFW3, val);
  289. POSTING_READ(DSPFW3);
  290. } else if (IS_I945G(dev) || IS_I945GM(dev)) {
  291. val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) :
  292. _MASKED_BIT_DISABLE(FW_BLC_SELF_EN);
  293. I915_WRITE(FW_BLC_SELF, val);
  294. POSTING_READ(FW_BLC_SELF);
  295. } else if (IS_I915GM(dev)) {
  296. /*
  297. * FIXME can't find a bit like this for 915G, and
  298. * and yet it does have the related watermark in
  299. * FW_BLC_SELF. What's going on?
  300. */
  301. val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) :
  302. _MASKED_BIT_DISABLE(INSTPM_SELF_EN);
  303. I915_WRITE(INSTPM, val);
  304. POSTING_READ(INSTPM);
  305. } else {
  306. return;
  307. }
  308. DRM_DEBUG_KMS("memory self-refresh is %s\n",
  309. enable ? "enabled" : "disabled");
  310. }
  311. /*
  312. * Latency for FIFO fetches is dependent on several factors:
  313. * - memory configuration (speed, channels)
  314. * - chipset
  315. * - current MCH state
  316. * It can be fairly high in some situations, so here we assume a fairly
  317. * pessimal value. It's a tradeoff between extra memory fetches (if we
  318. * set this value too high, the FIFO will fetch frequently to stay full)
  319. * and power consumption (set it too low to save power and we might see
  320. * FIFO underruns and display "flicker").
  321. *
  322. * A value of 5us seems to be a good balance; safe for very low end
  323. * platforms but not overly aggressive on lower latency configs.
  324. */
  325. static const int pessimal_latency_ns = 5000;
  326. #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \
  327. ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8))
  328. static int vlv_get_fifo_size(struct drm_device *dev,
  329. enum pipe pipe, int plane)
  330. {
  331. struct drm_i915_private *dev_priv = to_i915(dev);
  332. int sprite0_start, sprite1_start, size;
  333. switch (pipe) {
  334. uint32_t dsparb, dsparb2, dsparb3;
  335. case PIPE_A:
  336. dsparb = I915_READ(DSPARB);
  337. dsparb2 = I915_READ(DSPARB2);
  338. sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0);
  339. sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4);
  340. break;
  341. case PIPE_B:
  342. dsparb = I915_READ(DSPARB);
  343. dsparb2 = I915_READ(DSPARB2);
  344. sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8);
  345. sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12);
  346. break;
  347. case PIPE_C:
  348. dsparb2 = I915_READ(DSPARB2);
  349. dsparb3 = I915_READ(DSPARB3);
  350. sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16);
  351. sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20);
  352. break;
  353. default:
  354. return 0;
  355. }
  356. switch (plane) {
  357. case 0:
  358. size = sprite0_start;
  359. break;
  360. case 1:
  361. size = sprite1_start - sprite0_start;
  362. break;
  363. case 2:
  364. size = 512 - 1 - sprite1_start;
  365. break;
  366. default:
  367. return 0;
  368. }
  369. DRM_DEBUG_KMS("Pipe %c %s %c FIFO size: %d\n",
  370. pipe_name(pipe), plane == 0 ? "primary" : "sprite",
  371. plane == 0 ? plane_name(pipe) : sprite_name(pipe, plane - 1),
  372. size);
  373. return size;
  374. }
  375. static int i9xx_get_fifo_size(struct drm_device *dev, int plane)
  376. {
  377. struct drm_i915_private *dev_priv = to_i915(dev);
  378. uint32_t dsparb = I915_READ(DSPARB);
  379. int size;
  380. size = dsparb & 0x7f;
  381. if (plane)
  382. size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
  383. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  384. plane ? "B" : "A", size);
  385. return size;
  386. }
  387. static int i830_get_fifo_size(struct drm_device *dev, int plane)
  388. {
  389. struct drm_i915_private *dev_priv = to_i915(dev);
  390. uint32_t dsparb = I915_READ(DSPARB);
  391. int size;
  392. size = dsparb & 0x1ff;
  393. if (plane)
  394. size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
  395. size >>= 1; /* Convert to cachelines */
  396. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  397. plane ? "B" : "A", size);
  398. return size;
  399. }
  400. static int i845_get_fifo_size(struct drm_device *dev, int plane)
  401. {
  402. struct drm_i915_private *dev_priv = to_i915(dev);
  403. uint32_t dsparb = I915_READ(DSPARB);
  404. int size;
  405. size = dsparb & 0x7f;
  406. size >>= 2; /* Convert to cachelines */
  407. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  408. plane ? "B" : "A",
  409. size);
  410. return size;
  411. }
  412. /* Pineview has different values for various configs */
  413. static const struct intel_watermark_params pineview_display_wm = {
  414. .fifo_size = PINEVIEW_DISPLAY_FIFO,
  415. .max_wm = PINEVIEW_MAX_WM,
  416. .default_wm = PINEVIEW_DFT_WM,
  417. .guard_size = PINEVIEW_GUARD_WM,
  418. .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
  419. };
  420. static const struct intel_watermark_params pineview_display_hplloff_wm = {
  421. .fifo_size = PINEVIEW_DISPLAY_FIFO,
  422. .max_wm = PINEVIEW_MAX_WM,
  423. .default_wm = PINEVIEW_DFT_HPLLOFF_WM,
  424. .guard_size = PINEVIEW_GUARD_WM,
  425. .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
  426. };
  427. static const struct intel_watermark_params pineview_cursor_wm = {
  428. .fifo_size = PINEVIEW_CURSOR_FIFO,
  429. .max_wm = PINEVIEW_CURSOR_MAX_WM,
  430. .default_wm = PINEVIEW_CURSOR_DFT_WM,
  431. .guard_size = PINEVIEW_CURSOR_GUARD_WM,
  432. .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
  433. };
  434. static const struct intel_watermark_params pineview_cursor_hplloff_wm = {
  435. .fifo_size = PINEVIEW_CURSOR_FIFO,
  436. .max_wm = PINEVIEW_CURSOR_MAX_WM,
  437. .default_wm = PINEVIEW_CURSOR_DFT_WM,
  438. .guard_size = PINEVIEW_CURSOR_GUARD_WM,
  439. .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
  440. };
  441. static const struct intel_watermark_params g4x_wm_info = {
  442. .fifo_size = G4X_FIFO_SIZE,
  443. .max_wm = G4X_MAX_WM,
  444. .default_wm = G4X_MAX_WM,
  445. .guard_size = 2,
  446. .cacheline_size = G4X_FIFO_LINE_SIZE,
  447. };
  448. static const struct intel_watermark_params g4x_cursor_wm_info = {
  449. .fifo_size = I965_CURSOR_FIFO,
  450. .max_wm = I965_CURSOR_MAX_WM,
  451. .default_wm = I965_CURSOR_DFT_WM,
  452. .guard_size = 2,
  453. .cacheline_size = G4X_FIFO_LINE_SIZE,
  454. };
  455. static const struct intel_watermark_params i965_cursor_wm_info = {
  456. .fifo_size = I965_CURSOR_FIFO,
  457. .max_wm = I965_CURSOR_MAX_WM,
  458. .default_wm = I965_CURSOR_DFT_WM,
  459. .guard_size = 2,
  460. .cacheline_size = I915_FIFO_LINE_SIZE,
  461. };
  462. static const struct intel_watermark_params i945_wm_info = {
  463. .fifo_size = I945_FIFO_SIZE,
  464. .max_wm = I915_MAX_WM,
  465. .default_wm = 1,
  466. .guard_size = 2,
  467. .cacheline_size = I915_FIFO_LINE_SIZE,
  468. };
  469. static const struct intel_watermark_params i915_wm_info = {
  470. .fifo_size = I915_FIFO_SIZE,
  471. .max_wm = I915_MAX_WM,
  472. .default_wm = 1,
  473. .guard_size = 2,
  474. .cacheline_size = I915_FIFO_LINE_SIZE,
  475. };
  476. static const struct intel_watermark_params i830_a_wm_info = {
  477. .fifo_size = I855GM_FIFO_SIZE,
  478. .max_wm = I915_MAX_WM,
  479. .default_wm = 1,
  480. .guard_size = 2,
  481. .cacheline_size = I830_FIFO_LINE_SIZE,
  482. };
  483. static const struct intel_watermark_params i830_bc_wm_info = {
  484. .fifo_size = I855GM_FIFO_SIZE,
  485. .max_wm = I915_MAX_WM/2,
  486. .default_wm = 1,
  487. .guard_size = 2,
  488. .cacheline_size = I830_FIFO_LINE_SIZE,
  489. };
  490. static const struct intel_watermark_params i845_wm_info = {
  491. .fifo_size = I830_FIFO_SIZE,
  492. .max_wm = I915_MAX_WM,
  493. .default_wm = 1,
  494. .guard_size = 2,
  495. .cacheline_size = I830_FIFO_LINE_SIZE,
  496. };
  497. /**
  498. * intel_calculate_wm - calculate watermark level
  499. * @clock_in_khz: pixel clock
  500. * @wm: chip FIFO params
  501. * @cpp: bytes per pixel
  502. * @latency_ns: memory latency for the platform
  503. *
  504. * Calculate the watermark level (the level at which the display plane will
  505. * start fetching from memory again). Each chip has a different display
  506. * FIFO size and allocation, so the caller needs to figure that out and pass
  507. * in the correct intel_watermark_params structure.
  508. *
  509. * As the pixel clock runs, the FIFO will be drained at a rate that depends
  510. * on the pixel size. When it reaches the watermark level, it'll start
  511. * fetching FIFO line sized based chunks from memory until the FIFO fills
  512. * past the watermark point. If the FIFO drains completely, a FIFO underrun
  513. * will occur, and a display engine hang could result.
  514. */
  515. static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
  516. const struct intel_watermark_params *wm,
  517. int fifo_size, int cpp,
  518. unsigned long latency_ns)
  519. {
  520. long entries_required, wm_size;
  521. /*
  522. * Note: we need to make sure we don't overflow for various clock &
  523. * latency values.
  524. * clocks go from a few thousand to several hundred thousand.
  525. * latency is usually a few thousand
  526. */
  527. entries_required = ((clock_in_khz / 1000) * cpp * latency_ns) /
  528. 1000;
  529. entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size);
  530. DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required);
  531. wm_size = fifo_size - (entries_required + wm->guard_size);
  532. DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size);
  533. /* Don't promote wm_size to unsigned... */
  534. if (wm_size > (long)wm->max_wm)
  535. wm_size = wm->max_wm;
  536. if (wm_size <= 0)
  537. wm_size = wm->default_wm;
  538. /*
  539. * Bspec seems to indicate that the value shouldn't be lower than
  540. * 'burst size + 1'. Certainly 830 is quite unhappy with low values.
  541. * Lets go for 8 which is the burst size since certain platforms
  542. * already use a hardcoded 8 (which is what the spec says should be
  543. * done).
  544. */
  545. if (wm_size <= 8)
  546. wm_size = 8;
  547. return wm_size;
  548. }
  549. static struct drm_crtc *single_enabled_crtc(struct drm_device *dev)
  550. {
  551. struct drm_crtc *crtc, *enabled = NULL;
  552. for_each_crtc(dev, crtc) {
  553. if (intel_crtc_active(crtc)) {
  554. if (enabled)
  555. return NULL;
  556. enabled = crtc;
  557. }
  558. }
  559. return enabled;
  560. }
  561. static void pineview_update_wm(struct drm_crtc *unused_crtc)
  562. {
  563. struct drm_device *dev = unused_crtc->dev;
  564. struct drm_i915_private *dev_priv = to_i915(dev);
  565. struct drm_crtc *crtc;
  566. const struct cxsr_latency *latency;
  567. u32 reg;
  568. unsigned long wm;
  569. latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3,
  570. dev_priv->fsb_freq, dev_priv->mem_freq);
  571. if (!latency) {
  572. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  573. intel_set_memory_cxsr(dev_priv, false);
  574. return;
  575. }
  576. crtc = single_enabled_crtc(dev);
  577. if (crtc) {
  578. const struct drm_display_mode *adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  579. int cpp = drm_format_plane_cpp(crtc->primary->state->fb->pixel_format, 0);
  580. int clock = adjusted_mode->crtc_clock;
  581. /* Display SR */
  582. wm = intel_calculate_wm(clock, &pineview_display_wm,
  583. pineview_display_wm.fifo_size,
  584. cpp, latency->display_sr);
  585. reg = I915_READ(DSPFW1);
  586. reg &= ~DSPFW_SR_MASK;
  587. reg |= FW_WM(wm, SR);
  588. I915_WRITE(DSPFW1, reg);
  589. DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg);
  590. /* cursor SR */
  591. wm = intel_calculate_wm(clock, &pineview_cursor_wm,
  592. pineview_display_wm.fifo_size,
  593. cpp, latency->cursor_sr);
  594. reg = I915_READ(DSPFW3);
  595. reg &= ~DSPFW_CURSOR_SR_MASK;
  596. reg |= FW_WM(wm, CURSOR_SR);
  597. I915_WRITE(DSPFW3, reg);
  598. /* Display HPLL off SR */
  599. wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm,
  600. pineview_display_hplloff_wm.fifo_size,
  601. cpp, latency->display_hpll_disable);
  602. reg = I915_READ(DSPFW3);
  603. reg &= ~DSPFW_HPLL_SR_MASK;
  604. reg |= FW_WM(wm, HPLL_SR);
  605. I915_WRITE(DSPFW3, reg);
  606. /* cursor HPLL off SR */
  607. wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm,
  608. pineview_display_hplloff_wm.fifo_size,
  609. cpp, latency->cursor_hpll_disable);
  610. reg = I915_READ(DSPFW3);
  611. reg &= ~DSPFW_HPLL_CURSOR_MASK;
  612. reg |= FW_WM(wm, HPLL_CURSOR);
  613. I915_WRITE(DSPFW3, reg);
  614. DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg);
  615. intel_set_memory_cxsr(dev_priv, true);
  616. } else {
  617. intel_set_memory_cxsr(dev_priv, false);
  618. }
  619. }
  620. static bool g4x_compute_wm0(struct drm_device *dev,
  621. int plane,
  622. const struct intel_watermark_params *display,
  623. int display_latency_ns,
  624. const struct intel_watermark_params *cursor,
  625. int cursor_latency_ns,
  626. int *plane_wm,
  627. int *cursor_wm)
  628. {
  629. struct drm_crtc *crtc;
  630. const struct drm_display_mode *adjusted_mode;
  631. int htotal, hdisplay, clock, cpp;
  632. int line_time_us, line_count;
  633. int entries, tlb_miss;
  634. crtc = intel_get_crtc_for_plane(dev, plane);
  635. if (!intel_crtc_active(crtc)) {
  636. *cursor_wm = cursor->guard_size;
  637. *plane_wm = display->guard_size;
  638. return false;
  639. }
  640. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  641. clock = adjusted_mode->crtc_clock;
  642. htotal = adjusted_mode->crtc_htotal;
  643. hdisplay = to_intel_crtc(crtc)->config->pipe_src_w;
  644. cpp = drm_format_plane_cpp(crtc->primary->state->fb->pixel_format, 0);
  645. /* Use the small buffer method to calculate plane watermark */
  646. entries = ((clock * cpp / 1000) * display_latency_ns) / 1000;
  647. tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;
  648. if (tlb_miss > 0)
  649. entries += tlb_miss;
  650. entries = DIV_ROUND_UP(entries, display->cacheline_size);
  651. *plane_wm = entries + display->guard_size;
  652. if (*plane_wm > (int)display->max_wm)
  653. *plane_wm = display->max_wm;
  654. /* Use the large buffer method to calculate cursor watermark */
  655. line_time_us = max(htotal * 1000 / clock, 1);
  656. line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
  657. entries = line_count * crtc->cursor->state->crtc_w * cpp;
  658. tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
  659. if (tlb_miss > 0)
  660. entries += tlb_miss;
  661. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  662. *cursor_wm = entries + cursor->guard_size;
  663. if (*cursor_wm > (int)cursor->max_wm)
  664. *cursor_wm = (int)cursor->max_wm;
  665. return true;
  666. }
  667. /*
  668. * Check the wm result.
  669. *
  670. * If any calculated watermark values is larger than the maximum value that
  671. * can be programmed into the associated watermark register, that watermark
  672. * must be disabled.
  673. */
  674. static bool g4x_check_srwm(struct drm_device *dev,
  675. int display_wm, int cursor_wm,
  676. const struct intel_watermark_params *display,
  677. const struct intel_watermark_params *cursor)
  678. {
  679. DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n",
  680. display_wm, cursor_wm);
  681. if (display_wm > display->max_wm) {
  682. DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n",
  683. display_wm, display->max_wm);
  684. return false;
  685. }
  686. if (cursor_wm > cursor->max_wm) {
  687. DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n",
  688. cursor_wm, cursor->max_wm);
  689. return false;
  690. }
  691. if (!(display_wm || cursor_wm)) {
  692. DRM_DEBUG_KMS("SR latency is 0, disabling\n");
  693. return false;
  694. }
  695. return true;
  696. }
  697. static bool g4x_compute_srwm(struct drm_device *dev,
  698. int plane,
  699. int latency_ns,
  700. const struct intel_watermark_params *display,
  701. const struct intel_watermark_params *cursor,
  702. int *display_wm, int *cursor_wm)
  703. {
  704. struct drm_crtc *crtc;
  705. const struct drm_display_mode *adjusted_mode;
  706. int hdisplay, htotal, cpp, clock;
  707. unsigned long line_time_us;
  708. int line_count, line_size;
  709. int small, large;
  710. int entries;
  711. if (!latency_ns) {
  712. *display_wm = *cursor_wm = 0;
  713. return false;
  714. }
  715. crtc = intel_get_crtc_for_plane(dev, plane);
  716. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  717. clock = adjusted_mode->crtc_clock;
  718. htotal = adjusted_mode->crtc_htotal;
  719. hdisplay = to_intel_crtc(crtc)->config->pipe_src_w;
  720. cpp = drm_format_plane_cpp(crtc->primary->state->fb->pixel_format, 0);
  721. line_time_us = max(htotal * 1000 / clock, 1);
  722. line_count = (latency_ns / line_time_us + 1000) / 1000;
  723. line_size = hdisplay * cpp;
  724. /* Use the minimum of the small and large buffer method for primary */
  725. small = ((clock * cpp / 1000) * latency_ns) / 1000;
  726. large = line_count * line_size;
  727. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  728. *display_wm = entries + display->guard_size;
  729. /* calculate the self-refresh watermark for display cursor */
  730. entries = line_count * cpp * crtc->cursor->state->crtc_w;
  731. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  732. *cursor_wm = entries + cursor->guard_size;
  733. return g4x_check_srwm(dev,
  734. *display_wm, *cursor_wm,
  735. display, cursor);
  736. }
  737. #define FW_WM_VLV(value, plane) \
  738. (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV)
  739. static void vlv_write_wm_values(struct intel_crtc *crtc,
  740. const struct vlv_wm_values *wm)
  741. {
  742. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  743. enum pipe pipe = crtc->pipe;
  744. I915_WRITE(VLV_DDL(pipe),
  745. (wm->ddl[pipe].cursor << DDL_CURSOR_SHIFT) |
  746. (wm->ddl[pipe].sprite[1] << DDL_SPRITE_SHIFT(1)) |
  747. (wm->ddl[pipe].sprite[0] << DDL_SPRITE_SHIFT(0)) |
  748. (wm->ddl[pipe].primary << DDL_PLANE_SHIFT));
  749. I915_WRITE(DSPFW1,
  750. FW_WM(wm->sr.plane, SR) |
  751. FW_WM(wm->pipe[PIPE_B].cursor, CURSORB) |
  752. FW_WM_VLV(wm->pipe[PIPE_B].primary, PLANEB) |
  753. FW_WM_VLV(wm->pipe[PIPE_A].primary, PLANEA));
  754. I915_WRITE(DSPFW2,
  755. FW_WM_VLV(wm->pipe[PIPE_A].sprite[1], SPRITEB) |
  756. FW_WM(wm->pipe[PIPE_A].cursor, CURSORA) |
  757. FW_WM_VLV(wm->pipe[PIPE_A].sprite[0], SPRITEA));
  758. I915_WRITE(DSPFW3,
  759. FW_WM(wm->sr.cursor, CURSOR_SR));
  760. if (IS_CHERRYVIEW(dev_priv)) {
  761. I915_WRITE(DSPFW7_CHV,
  762. FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) |
  763. FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC));
  764. I915_WRITE(DSPFW8_CHV,
  765. FW_WM_VLV(wm->pipe[PIPE_C].sprite[1], SPRITEF) |
  766. FW_WM_VLV(wm->pipe[PIPE_C].sprite[0], SPRITEE));
  767. I915_WRITE(DSPFW9_CHV,
  768. FW_WM_VLV(wm->pipe[PIPE_C].primary, PLANEC) |
  769. FW_WM(wm->pipe[PIPE_C].cursor, CURSORC));
  770. I915_WRITE(DSPHOWM,
  771. FW_WM(wm->sr.plane >> 9, SR_HI) |
  772. FW_WM(wm->pipe[PIPE_C].sprite[1] >> 8, SPRITEF_HI) |
  773. FW_WM(wm->pipe[PIPE_C].sprite[0] >> 8, SPRITEE_HI) |
  774. FW_WM(wm->pipe[PIPE_C].primary >> 8, PLANEC_HI) |
  775. FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) |
  776. FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) |
  777. FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) |
  778. FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) |
  779. FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) |
  780. FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI));
  781. } else {
  782. I915_WRITE(DSPFW7,
  783. FW_WM_VLV(wm->pipe[PIPE_B].sprite[1], SPRITED) |
  784. FW_WM_VLV(wm->pipe[PIPE_B].sprite[0], SPRITEC));
  785. I915_WRITE(DSPHOWM,
  786. FW_WM(wm->sr.plane >> 9, SR_HI) |
  787. FW_WM(wm->pipe[PIPE_B].sprite[1] >> 8, SPRITED_HI) |
  788. FW_WM(wm->pipe[PIPE_B].sprite[0] >> 8, SPRITEC_HI) |
  789. FW_WM(wm->pipe[PIPE_B].primary >> 8, PLANEB_HI) |
  790. FW_WM(wm->pipe[PIPE_A].sprite[1] >> 8, SPRITEB_HI) |
  791. FW_WM(wm->pipe[PIPE_A].sprite[0] >> 8, SPRITEA_HI) |
  792. FW_WM(wm->pipe[PIPE_A].primary >> 8, PLANEA_HI));
  793. }
  794. /* zero (unused) WM1 watermarks */
  795. I915_WRITE(DSPFW4, 0);
  796. I915_WRITE(DSPFW5, 0);
  797. I915_WRITE(DSPFW6, 0);
  798. I915_WRITE(DSPHOWM1, 0);
  799. POSTING_READ(DSPFW1);
  800. }
  801. #undef FW_WM_VLV
  802. enum vlv_wm_level {
  803. VLV_WM_LEVEL_PM2,
  804. VLV_WM_LEVEL_PM5,
  805. VLV_WM_LEVEL_DDR_DVFS,
  806. };
  807. /* latency must be in 0.1us units. */
  808. static unsigned int vlv_wm_method2(unsigned int pixel_rate,
  809. unsigned int pipe_htotal,
  810. unsigned int horiz_pixels,
  811. unsigned int cpp,
  812. unsigned int latency)
  813. {
  814. unsigned int ret;
  815. ret = (latency * pixel_rate) / (pipe_htotal * 10000);
  816. ret = (ret + 1) * horiz_pixels * cpp;
  817. ret = DIV_ROUND_UP(ret, 64);
  818. return ret;
  819. }
  820. static void vlv_setup_wm_latency(struct drm_device *dev)
  821. {
  822. struct drm_i915_private *dev_priv = to_i915(dev);
  823. /* all latencies in usec */
  824. dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3;
  825. dev_priv->wm.max_level = VLV_WM_LEVEL_PM2;
  826. if (IS_CHERRYVIEW(dev_priv)) {
  827. dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12;
  828. dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33;
  829. dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS;
  830. }
  831. }
  832. static uint16_t vlv_compute_wm_level(struct intel_plane *plane,
  833. struct intel_crtc *crtc,
  834. const struct intel_plane_state *state,
  835. int level)
  836. {
  837. struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
  838. int clock, htotal, cpp, width, wm;
  839. if (dev_priv->wm.pri_latency[level] == 0)
  840. return USHRT_MAX;
  841. if (!state->base.visible)
  842. return 0;
  843. cpp = drm_format_plane_cpp(state->base.fb->pixel_format, 0);
  844. clock = crtc->config->base.adjusted_mode.crtc_clock;
  845. htotal = crtc->config->base.adjusted_mode.crtc_htotal;
  846. width = crtc->config->pipe_src_w;
  847. if (WARN_ON(htotal == 0))
  848. htotal = 1;
  849. if (plane->base.type == DRM_PLANE_TYPE_CURSOR) {
  850. /*
  851. * FIXME the formula gives values that are
  852. * too big for the cursor FIFO, and hence we
  853. * would never be able to use cursors. For
  854. * now just hardcode the watermark.
  855. */
  856. wm = 63;
  857. } else {
  858. wm = vlv_wm_method2(clock, htotal, width, cpp,
  859. dev_priv->wm.pri_latency[level] * 10);
  860. }
  861. return min_t(int, wm, USHRT_MAX);
  862. }
  863. static void vlv_compute_fifo(struct intel_crtc *crtc)
  864. {
  865. struct drm_device *dev = crtc->base.dev;
  866. struct vlv_wm_state *wm_state = &crtc->wm_state;
  867. struct intel_plane *plane;
  868. unsigned int total_rate = 0;
  869. const int fifo_size = 512 - 1;
  870. int fifo_extra, fifo_left = fifo_size;
  871. for_each_intel_plane_on_crtc(dev, crtc, plane) {
  872. struct intel_plane_state *state =
  873. to_intel_plane_state(plane->base.state);
  874. if (plane->base.type == DRM_PLANE_TYPE_CURSOR)
  875. continue;
  876. if (state->base.visible) {
  877. wm_state->num_active_planes++;
  878. total_rate += drm_format_plane_cpp(state->base.fb->pixel_format, 0);
  879. }
  880. }
  881. for_each_intel_plane_on_crtc(dev, crtc, plane) {
  882. struct intel_plane_state *state =
  883. to_intel_plane_state(plane->base.state);
  884. unsigned int rate;
  885. if (plane->base.type == DRM_PLANE_TYPE_CURSOR) {
  886. plane->wm.fifo_size = 63;
  887. continue;
  888. }
  889. if (!state->base.visible) {
  890. plane->wm.fifo_size = 0;
  891. continue;
  892. }
  893. rate = drm_format_plane_cpp(state->base.fb->pixel_format, 0);
  894. plane->wm.fifo_size = fifo_size * rate / total_rate;
  895. fifo_left -= plane->wm.fifo_size;
  896. }
  897. fifo_extra = DIV_ROUND_UP(fifo_left, wm_state->num_active_planes ?: 1);
  898. /* spread the remainder evenly */
  899. for_each_intel_plane_on_crtc(dev, crtc, plane) {
  900. int plane_extra;
  901. if (fifo_left == 0)
  902. break;
  903. if (plane->base.type == DRM_PLANE_TYPE_CURSOR)
  904. continue;
  905. /* give it all to the first plane if none are active */
  906. if (plane->wm.fifo_size == 0 &&
  907. wm_state->num_active_planes)
  908. continue;
  909. plane_extra = min(fifo_extra, fifo_left);
  910. plane->wm.fifo_size += plane_extra;
  911. fifo_left -= plane_extra;
  912. }
  913. WARN_ON(fifo_left != 0);
  914. }
  915. static void vlv_invert_wms(struct intel_crtc *crtc)
  916. {
  917. struct vlv_wm_state *wm_state = &crtc->wm_state;
  918. int level;
  919. for (level = 0; level < wm_state->num_levels; level++) {
  920. struct drm_device *dev = crtc->base.dev;
  921. const int sr_fifo_size = INTEL_INFO(dev)->num_pipes * 512 - 1;
  922. struct intel_plane *plane;
  923. wm_state->sr[level].plane = sr_fifo_size - wm_state->sr[level].plane;
  924. wm_state->sr[level].cursor = 63 - wm_state->sr[level].cursor;
  925. for_each_intel_plane_on_crtc(dev, crtc, plane) {
  926. switch (plane->base.type) {
  927. int sprite;
  928. case DRM_PLANE_TYPE_CURSOR:
  929. wm_state->wm[level].cursor = plane->wm.fifo_size -
  930. wm_state->wm[level].cursor;
  931. break;
  932. case DRM_PLANE_TYPE_PRIMARY:
  933. wm_state->wm[level].primary = plane->wm.fifo_size -
  934. wm_state->wm[level].primary;
  935. break;
  936. case DRM_PLANE_TYPE_OVERLAY:
  937. sprite = plane->plane;
  938. wm_state->wm[level].sprite[sprite] = plane->wm.fifo_size -
  939. wm_state->wm[level].sprite[sprite];
  940. break;
  941. }
  942. }
  943. }
  944. }
  945. static void vlv_compute_wm(struct intel_crtc *crtc)
  946. {
  947. struct drm_device *dev = crtc->base.dev;
  948. struct vlv_wm_state *wm_state = &crtc->wm_state;
  949. struct intel_plane *plane;
  950. int sr_fifo_size = INTEL_INFO(dev)->num_pipes * 512 - 1;
  951. int level;
  952. memset(wm_state, 0, sizeof(*wm_state));
  953. wm_state->cxsr = crtc->pipe != PIPE_C && crtc->wm.cxsr_allowed;
  954. wm_state->num_levels = to_i915(dev)->wm.max_level + 1;
  955. wm_state->num_active_planes = 0;
  956. vlv_compute_fifo(crtc);
  957. if (wm_state->num_active_planes != 1)
  958. wm_state->cxsr = false;
  959. if (wm_state->cxsr) {
  960. for (level = 0; level < wm_state->num_levels; level++) {
  961. wm_state->sr[level].plane = sr_fifo_size;
  962. wm_state->sr[level].cursor = 63;
  963. }
  964. }
  965. for_each_intel_plane_on_crtc(dev, crtc, plane) {
  966. struct intel_plane_state *state =
  967. to_intel_plane_state(plane->base.state);
  968. if (!state->base.visible)
  969. continue;
  970. /* normal watermarks */
  971. for (level = 0; level < wm_state->num_levels; level++) {
  972. int wm = vlv_compute_wm_level(plane, crtc, state, level);
  973. int max_wm = plane->base.type == DRM_PLANE_TYPE_CURSOR ? 63 : 511;
  974. /* hack */
  975. if (WARN_ON(level == 0 && wm > max_wm))
  976. wm = max_wm;
  977. if (wm > plane->wm.fifo_size)
  978. break;
  979. switch (plane->base.type) {
  980. int sprite;
  981. case DRM_PLANE_TYPE_CURSOR:
  982. wm_state->wm[level].cursor = wm;
  983. break;
  984. case DRM_PLANE_TYPE_PRIMARY:
  985. wm_state->wm[level].primary = wm;
  986. break;
  987. case DRM_PLANE_TYPE_OVERLAY:
  988. sprite = plane->plane;
  989. wm_state->wm[level].sprite[sprite] = wm;
  990. break;
  991. }
  992. }
  993. wm_state->num_levels = level;
  994. if (!wm_state->cxsr)
  995. continue;
  996. /* maxfifo watermarks */
  997. switch (plane->base.type) {
  998. int sprite, level;
  999. case DRM_PLANE_TYPE_CURSOR:
  1000. for (level = 0; level < wm_state->num_levels; level++)
  1001. wm_state->sr[level].cursor =
  1002. wm_state->wm[level].cursor;
  1003. break;
  1004. case DRM_PLANE_TYPE_PRIMARY:
  1005. for (level = 0; level < wm_state->num_levels; level++)
  1006. wm_state->sr[level].plane =
  1007. min(wm_state->sr[level].plane,
  1008. wm_state->wm[level].primary);
  1009. break;
  1010. case DRM_PLANE_TYPE_OVERLAY:
  1011. sprite = plane->plane;
  1012. for (level = 0; level < wm_state->num_levels; level++)
  1013. wm_state->sr[level].plane =
  1014. min(wm_state->sr[level].plane,
  1015. wm_state->wm[level].sprite[sprite]);
  1016. break;
  1017. }
  1018. }
  1019. /* clear any (partially) filled invalid levels */
  1020. for (level = wm_state->num_levels; level < to_i915(dev)->wm.max_level + 1; level++) {
  1021. memset(&wm_state->wm[level], 0, sizeof(wm_state->wm[level]));
  1022. memset(&wm_state->sr[level], 0, sizeof(wm_state->sr[level]));
  1023. }
  1024. vlv_invert_wms(crtc);
  1025. }
  1026. #define VLV_FIFO(plane, value) \
  1027. (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV)
  1028. static void vlv_pipe_set_fifo_size(struct intel_crtc *crtc)
  1029. {
  1030. struct drm_device *dev = crtc->base.dev;
  1031. struct drm_i915_private *dev_priv = to_i915(dev);
  1032. struct intel_plane *plane;
  1033. int sprite0_start = 0, sprite1_start = 0, fifo_size = 0;
  1034. for_each_intel_plane_on_crtc(dev, crtc, plane) {
  1035. if (plane->base.type == DRM_PLANE_TYPE_CURSOR) {
  1036. WARN_ON(plane->wm.fifo_size != 63);
  1037. continue;
  1038. }
  1039. if (plane->base.type == DRM_PLANE_TYPE_PRIMARY)
  1040. sprite0_start = plane->wm.fifo_size;
  1041. else if (plane->plane == 0)
  1042. sprite1_start = sprite0_start + plane->wm.fifo_size;
  1043. else
  1044. fifo_size = sprite1_start + plane->wm.fifo_size;
  1045. }
  1046. WARN_ON(fifo_size != 512 - 1);
  1047. DRM_DEBUG_KMS("Pipe %c FIFO split %d / %d / %d\n",
  1048. pipe_name(crtc->pipe), sprite0_start,
  1049. sprite1_start, fifo_size);
  1050. switch (crtc->pipe) {
  1051. uint32_t dsparb, dsparb2, dsparb3;
  1052. case PIPE_A:
  1053. dsparb = I915_READ(DSPARB);
  1054. dsparb2 = I915_READ(DSPARB2);
  1055. dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) |
  1056. VLV_FIFO(SPRITEB, 0xff));
  1057. dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) |
  1058. VLV_FIFO(SPRITEB, sprite1_start));
  1059. dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) |
  1060. VLV_FIFO(SPRITEB_HI, 0x1));
  1061. dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) |
  1062. VLV_FIFO(SPRITEB_HI, sprite1_start >> 8));
  1063. I915_WRITE(DSPARB, dsparb);
  1064. I915_WRITE(DSPARB2, dsparb2);
  1065. break;
  1066. case PIPE_B:
  1067. dsparb = I915_READ(DSPARB);
  1068. dsparb2 = I915_READ(DSPARB2);
  1069. dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) |
  1070. VLV_FIFO(SPRITED, 0xff));
  1071. dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) |
  1072. VLV_FIFO(SPRITED, sprite1_start));
  1073. dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) |
  1074. VLV_FIFO(SPRITED_HI, 0xff));
  1075. dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) |
  1076. VLV_FIFO(SPRITED_HI, sprite1_start >> 8));
  1077. I915_WRITE(DSPARB, dsparb);
  1078. I915_WRITE(DSPARB2, dsparb2);
  1079. break;
  1080. case PIPE_C:
  1081. dsparb3 = I915_READ(DSPARB3);
  1082. dsparb2 = I915_READ(DSPARB2);
  1083. dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) |
  1084. VLV_FIFO(SPRITEF, 0xff));
  1085. dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) |
  1086. VLV_FIFO(SPRITEF, sprite1_start));
  1087. dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) |
  1088. VLV_FIFO(SPRITEF_HI, 0xff));
  1089. dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) |
  1090. VLV_FIFO(SPRITEF_HI, sprite1_start >> 8));
  1091. I915_WRITE(DSPARB3, dsparb3);
  1092. I915_WRITE(DSPARB2, dsparb2);
  1093. break;
  1094. default:
  1095. break;
  1096. }
  1097. }
  1098. #undef VLV_FIFO
  1099. static void vlv_merge_wm(struct drm_device *dev,
  1100. struct vlv_wm_values *wm)
  1101. {
  1102. struct intel_crtc *crtc;
  1103. int num_active_crtcs = 0;
  1104. wm->level = to_i915(dev)->wm.max_level;
  1105. wm->cxsr = true;
  1106. for_each_intel_crtc(dev, crtc) {
  1107. const struct vlv_wm_state *wm_state = &crtc->wm_state;
  1108. if (!crtc->active)
  1109. continue;
  1110. if (!wm_state->cxsr)
  1111. wm->cxsr = false;
  1112. num_active_crtcs++;
  1113. wm->level = min_t(int, wm->level, wm_state->num_levels - 1);
  1114. }
  1115. if (num_active_crtcs != 1)
  1116. wm->cxsr = false;
  1117. if (num_active_crtcs > 1)
  1118. wm->level = VLV_WM_LEVEL_PM2;
  1119. for_each_intel_crtc(dev, crtc) {
  1120. struct vlv_wm_state *wm_state = &crtc->wm_state;
  1121. enum pipe pipe = crtc->pipe;
  1122. if (!crtc->active)
  1123. continue;
  1124. wm->pipe[pipe] = wm_state->wm[wm->level];
  1125. if (wm->cxsr)
  1126. wm->sr = wm_state->sr[wm->level];
  1127. wm->ddl[pipe].primary = DDL_PRECISION_HIGH | 2;
  1128. wm->ddl[pipe].sprite[0] = DDL_PRECISION_HIGH | 2;
  1129. wm->ddl[pipe].sprite[1] = DDL_PRECISION_HIGH | 2;
  1130. wm->ddl[pipe].cursor = DDL_PRECISION_HIGH | 2;
  1131. }
  1132. }
  1133. static void vlv_update_wm(struct drm_crtc *crtc)
  1134. {
  1135. struct drm_device *dev = crtc->dev;
  1136. struct drm_i915_private *dev_priv = to_i915(dev);
  1137. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1138. enum pipe pipe = intel_crtc->pipe;
  1139. struct vlv_wm_values wm = {};
  1140. vlv_compute_wm(intel_crtc);
  1141. vlv_merge_wm(dev, &wm);
  1142. if (memcmp(&dev_priv->wm.vlv, &wm, sizeof(wm)) == 0) {
  1143. /* FIXME should be part of crtc atomic commit */
  1144. vlv_pipe_set_fifo_size(intel_crtc);
  1145. return;
  1146. }
  1147. if (wm.level < VLV_WM_LEVEL_DDR_DVFS &&
  1148. dev_priv->wm.vlv.level >= VLV_WM_LEVEL_DDR_DVFS)
  1149. chv_set_memory_dvfs(dev_priv, false);
  1150. if (wm.level < VLV_WM_LEVEL_PM5 &&
  1151. dev_priv->wm.vlv.level >= VLV_WM_LEVEL_PM5)
  1152. chv_set_memory_pm5(dev_priv, false);
  1153. if (!wm.cxsr && dev_priv->wm.vlv.cxsr)
  1154. intel_set_memory_cxsr(dev_priv, false);
  1155. /* FIXME should be part of crtc atomic commit */
  1156. vlv_pipe_set_fifo_size(intel_crtc);
  1157. vlv_write_wm_values(intel_crtc, &wm);
  1158. DRM_DEBUG_KMS("Setting FIFO watermarks - %c: plane=%d, cursor=%d, "
  1159. "sprite0=%d, sprite1=%d, SR: plane=%d, cursor=%d level=%d cxsr=%d\n",
  1160. pipe_name(pipe), wm.pipe[pipe].primary, wm.pipe[pipe].cursor,
  1161. wm.pipe[pipe].sprite[0], wm.pipe[pipe].sprite[1],
  1162. wm.sr.plane, wm.sr.cursor, wm.level, wm.cxsr);
  1163. if (wm.cxsr && !dev_priv->wm.vlv.cxsr)
  1164. intel_set_memory_cxsr(dev_priv, true);
  1165. if (wm.level >= VLV_WM_LEVEL_PM5 &&
  1166. dev_priv->wm.vlv.level < VLV_WM_LEVEL_PM5)
  1167. chv_set_memory_pm5(dev_priv, true);
  1168. if (wm.level >= VLV_WM_LEVEL_DDR_DVFS &&
  1169. dev_priv->wm.vlv.level < VLV_WM_LEVEL_DDR_DVFS)
  1170. chv_set_memory_dvfs(dev_priv, true);
  1171. dev_priv->wm.vlv = wm;
  1172. }
  1173. #define single_plane_enabled(mask) is_power_of_2(mask)
  1174. static void g4x_update_wm(struct drm_crtc *crtc)
  1175. {
  1176. struct drm_device *dev = crtc->dev;
  1177. static const int sr_latency_ns = 12000;
  1178. struct drm_i915_private *dev_priv = to_i915(dev);
  1179. int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
  1180. int plane_sr, cursor_sr;
  1181. unsigned int enabled = 0;
  1182. bool cxsr_enabled;
  1183. if (g4x_compute_wm0(dev, PIPE_A,
  1184. &g4x_wm_info, pessimal_latency_ns,
  1185. &g4x_cursor_wm_info, pessimal_latency_ns,
  1186. &planea_wm, &cursora_wm))
  1187. enabled |= 1 << PIPE_A;
  1188. if (g4x_compute_wm0(dev, PIPE_B,
  1189. &g4x_wm_info, pessimal_latency_ns,
  1190. &g4x_cursor_wm_info, pessimal_latency_ns,
  1191. &planeb_wm, &cursorb_wm))
  1192. enabled |= 1 << PIPE_B;
  1193. if (single_plane_enabled(enabled) &&
  1194. g4x_compute_srwm(dev, ffs(enabled) - 1,
  1195. sr_latency_ns,
  1196. &g4x_wm_info,
  1197. &g4x_cursor_wm_info,
  1198. &plane_sr, &cursor_sr)) {
  1199. cxsr_enabled = true;
  1200. } else {
  1201. cxsr_enabled = false;
  1202. intel_set_memory_cxsr(dev_priv, false);
  1203. plane_sr = cursor_sr = 0;
  1204. }
  1205. DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
  1206. "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
  1207. planea_wm, cursora_wm,
  1208. planeb_wm, cursorb_wm,
  1209. plane_sr, cursor_sr);
  1210. I915_WRITE(DSPFW1,
  1211. FW_WM(plane_sr, SR) |
  1212. FW_WM(cursorb_wm, CURSORB) |
  1213. FW_WM(planeb_wm, PLANEB) |
  1214. FW_WM(planea_wm, PLANEA));
  1215. I915_WRITE(DSPFW2,
  1216. (I915_READ(DSPFW2) & ~DSPFW_CURSORA_MASK) |
  1217. FW_WM(cursora_wm, CURSORA));
  1218. /* HPLL off in SR has some issues on G4x... disable it */
  1219. I915_WRITE(DSPFW3,
  1220. (I915_READ(DSPFW3) & ~(DSPFW_HPLL_SR_EN | DSPFW_CURSOR_SR_MASK)) |
  1221. FW_WM(cursor_sr, CURSOR_SR));
  1222. if (cxsr_enabled)
  1223. intel_set_memory_cxsr(dev_priv, true);
  1224. }
  1225. static void i965_update_wm(struct drm_crtc *unused_crtc)
  1226. {
  1227. struct drm_device *dev = unused_crtc->dev;
  1228. struct drm_i915_private *dev_priv = to_i915(dev);
  1229. struct drm_crtc *crtc;
  1230. int srwm = 1;
  1231. int cursor_sr = 16;
  1232. bool cxsr_enabled;
  1233. /* Calc sr entries for one plane configs */
  1234. crtc = single_enabled_crtc(dev);
  1235. if (crtc) {
  1236. /* self-refresh has much higher latency */
  1237. static const int sr_latency_ns = 12000;
  1238. const struct drm_display_mode *adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  1239. int clock = adjusted_mode->crtc_clock;
  1240. int htotal = adjusted_mode->crtc_htotal;
  1241. int hdisplay = to_intel_crtc(crtc)->config->pipe_src_w;
  1242. int cpp = drm_format_plane_cpp(crtc->primary->state->fb->pixel_format, 0);
  1243. unsigned long line_time_us;
  1244. int entries;
  1245. line_time_us = max(htotal * 1000 / clock, 1);
  1246. /* Use ns/us then divide to preserve precision */
  1247. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  1248. cpp * hdisplay;
  1249. entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE);
  1250. srwm = I965_FIFO_SIZE - entries;
  1251. if (srwm < 0)
  1252. srwm = 1;
  1253. srwm &= 0x1ff;
  1254. DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n",
  1255. entries, srwm);
  1256. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  1257. cpp * crtc->cursor->state->crtc_w;
  1258. entries = DIV_ROUND_UP(entries,
  1259. i965_cursor_wm_info.cacheline_size);
  1260. cursor_sr = i965_cursor_wm_info.fifo_size -
  1261. (entries + i965_cursor_wm_info.guard_size);
  1262. if (cursor_sr > i965_cursor_wm_info.max_wm)
  1263. cursor_sr = i965_cursor_wm_info.max_wm;
  1264. DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
  1265. "cursor %d\n", srwm, cursor_sr);
  1266. cxsr_enabled = true;
  1267. } else {
  1268. cxsr_enabled = false;
  1269. /* Turn off self refresh if both pipes are enabled */
  1270. intel_set_memory_cxsr(dev_priv, false);
  1271. }
  1272. DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
  1273. srwm);
  1274. /* 965 has limitations... */
  1275. I915_WRITE(DSPFW1, FW_WM(srwm, SR) |
  1276. FW_WM(8, CURSORB) |
  1277. FW_WM(8, PLANEB) |
  1278. FW_WM(8, PLANEA));
  1279. I915_WRITE(DSPFW2, FW_WM(8, CURSORA) |
  1280. FW_WM(8, PLANEC_OLD));
  1281. /* update cursor SR watermark */
  1282. I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR));
  1283. if (cxsr_enabled)
  1284. intel_set_memory_cxsr(dev_priv, true);
  1285. }
  1286. #undef FW_WM
  1287. static void i9xx_update_wm(struct drm_crtc *unused_crtc)
  1288. {
  1289. struct drm_device *dev = unused_crtc->dev;
  1290. struct drm_i915_private *dev_priv = to_i915(dev);
  1291. const struct intel_watermark_params *wm_info;
  1292. uint32_t fwater_lo;
  1293. uint32_t fwater_hi;
  1294. int cwm, srwm = 1;
  1295. int fifo_size;
  1296. int planea_wm, planeb_wm;
  1297. struct drm_crtc *crtc, *enabled = NULL;
  1298. if (IS_I945GM(dev))
  1299. wm_info = &i945_wm_info;
  1300. else if (!IS_GEN2(dev))
  1301. wm_info = &i915_wm_info;
  1302. else
  1303. wm_info = &i830_a_wm_info;
  1304. fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  1305. crtc = intel_get_crtc_for_plane(dev, 0);
  1306. if (intel_crtc_active(crtc)) {
  1307. const struct drm_display_mode *adjusted_mode;
  1308. int cpp = drm_format_plane_cpp(crtc->primary->state->fb->pixel_format, 0);
  1309. if (IS_GEN2(dev))
  1310. cpp = 4;
  1311. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  1312. planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
  1313. wm_info, fifo_size, cpp,
  1314. pessimal_latency_ns);
  1315. enabled = crtc;
  1316. } else {
  1317. planea_wm = fifo_size - wm_info->guard_size;
  1318. if (planea_wm > (long)wm_info->max_wm)
  1319. planea_wm = wm_info->max_wm;
  1320. }
  1321. if (IS_GEN2(dev))
  1322. wm_info = &i830_bc_wm_info;
  1323. fifo_size = dev_priv->display.get_fifo_size(dev, 1);
  1324. crtc = intel_get_crtc_for_plane(dev, 1);
  1325. if (intel_crtc_active(crtc)) {
  1326. const struct drm_display_mode *adjusted_mode;
  1327. int cpp = drm_format_plane_cpp(crtc->primary->state->fb->pixel_format, 0);
  1328. if (IS_GEN2(dev))
  1329. cpp = 4;
  1330. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  1331. planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
  1332. wm_info, fifo_size, cpp,
  1333. pessimal_latency_ns);
  1334. if (enabled == NULL)
  1335. enabled = crtc;
  1336. else
  1337. enabled = NULL;
  1338. } else {
  1339. planeb_wm = fifo_size - wm_info->guard_size;
  1340. if (planeb_wm > (long)wm_info->max_wm)
  1341. planeb_wm = wm_info->max_wm;
  1342. }
  1343. DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  1344. if (IS_I915GM(dev) && enabled) {
  1345. struct drm_i915_gem_object *obj;
  1346. obj = intel_fb_obj(enabled->primary->state->fb);
  1347. /* self-refresh seems busted with untiled */
  1348. if (!i915_gem_object_is_tiled(obj))
  1349. enabled = NULL;
  1350. }
  1351. /*
  1352. * Overlay gets an aggressive default since video jitter is bad.
  1353. */
  1354. cwm = 2;
  1355. /* Play safe and disable self-refresh before adjusting watermarks. */
  1356. intel_set_memory_cxsr(dev_priv, false);
  1357. /* Calc sr entries for one plane configs */
  1358. if (HAS_FW_BLC(dev) && enabled) {
  1359. /* self-refresh has much higher latency */
  1360. static const int sr_latency_ns = 6000;
  1361. const struct drm_display_mode *adjusted_mode = &to_intel_crtc(enabled)->config->base.adjusted_mode;
  1362. int clock = adjusted_mode->crtc_clock;
  1363. int htotal = adjusted_mode->crtc_htotal;
  1364. int hdisplay = to_intel_crtc(enabled)->config->pipe_src_w;
  1365. int cpp = drm_format_plane_cpp(enabled->primary->state->fb->pixel_format, 0);
  1366. unsigned long line_time_us;
  1367. int entries;
  1368. if (IS_I915GM(dev) || IS_I945GM(dev))
  1369. cpp = 4;
  1370. line_time_us = max(htotal * 1000 / clock, 1);
  1371. /* Use ns/us then divide to preserve precision */
  1372. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  1373. cpp * hdisplay;
  1374. entries = DIV_ROUND_UP(entries, wm_info->cacheline_size);
  1375. DRM_DEBUG_KMS("self-refresh entries: %d\n", entries);
  1376. srwm = wm_info->fifo_size - entries;
  1377. if (srwm < 0)
  1378. srwm = 1;
  1379. if (IS_I945G(dev) || IS_I945GM(dev))
  1380. I915_WRITE(FW_BLC_SELF,
  1381. FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
  1382. else
  1383. I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
  1384. }
  1385. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
  1386. planea_wm, planeb_wm, cwm, srwm);
  1387. fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
  1388. fwater_hi = (cwm & 0x1f);
  1389. /* Set request length to 8 cachelines per fetch */
  1390. fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
  1391. fwater_hi = fwater_hi | (1 << 8);
  1392. I915_WRITE(FW_BLC, fwater_lo);
  1393. I915_WRITE(FW_BLC2, fwater_hi);
  1394. if (enabled)
  1395. intel_set_memory_cxsr(dev_priv, true);
  1396. }
  1397. static void i845_update_wm(struct drm_crtc *unused_crtc)
  1398. {
  1399. struct drm_device *dev = unused_crtc->dev;
  1400. struct drm_i915_private *dev_priv = to_i915(dev);
  1401. struct drm_crtc *crtc;
  1402. const struct drm_display_mode *adjusted_mode;
  1403. uint32_t fwater_lo;
  1404. int planea_wm;
  1405. crtc = single_enabled_crtc(dev);
  1406. if (crtc == NULL)
  1407. return;
  1408. adjusted_mode = &to_intel_crtc(crtc)->config->base.adjusted_mode;
  1409. planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
  1410. &i845_wm_info,
  1411. dev_priv->display.get_fifo_size(dev, 0),
  1412. 4, pessimal_latency_ns);
  1413. fwater_lo = I915_READ(FW_BLC) & ~0xfff;
  1414. fwater_lo |= (3<<8) | planea_wm;
  1415. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm);
  1416. I915_WRITE(FW_BLC, fwater_lo);
  1417. }
  1418. uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
  1419. {
  1420. uint32_t pixel_rate;
  1421. pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
  1422. /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to
  1423. * adjust the pixel_rate here. */
  1424. if (pipe_config->pch_pfit.enabled) {
  1425. uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
  1426. uint32_t pfit_size = pipe_config->pch_pfit.size;
  1427. pipe_w = pipe_config->pipe_src_w;
  1428. pipe_h = pipe_config->pipe_src_h;
  1429. pfit_w = (pfit_size >> 16) & 0xFFFF;
  1430. pfit_h = pfit_size & 0xFFFF;
  1431. if (pipe_w < pfit_w)
  1432. pipe_w = pfit_w;
  1433. if (pipe_h < pfit_h)
  1434. pipe_h = pfit_h;
  1435. if (WARN_ON(!pfit_w || !pfit_h))
  1436. return pixel_rate;
  1437. pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
  1438. pfit_w * pfit_h);
  1439. }
  1440. return pixel_rate;
  1441. }
  1442. /* latency must be in 0.1us units. */
  1443. static uint32_t ilk_wm_method1(uint32_t pixel_rate, uint8_t cpp, uint32_t latency)
  1444. {
  1445. uint64_t ret;
  1446. if (WARN(latency == 0, "Latency value missing\n"))
  1447. return UINT_MAX;
  1448. ret = (uint64_t) pixel_rate * cpp * latency;
  1449. ret = DIV_ROUND_UP_ULL(ret, 64 * 10000) + 2;
  1450. return ret;
  1451. }
  1452. /* latency must be in 0.1us units. */
  1453. static uint32_t ilk_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal,
  1454. uint32_t horiz_pixels, uint8_t cpp,
  1455. uint32_t latency)
  1456. {
  1457. uint32_t ret;
  1458. if (WARN(latency == 0, "Latency value missing\n"))
  1459. return UINT_MAX;
  1460. if (WARN_ON(!pipe_htotal))
  1461. return UINT_MAX;
  1462. ret = (latency * pixel_rate) / (pipe_htotal * 10000);
  1463. ret = (ret + 1) * horiz_pixels * cpp;
  1464. ret = DIV_ROUND_UP(ret, 64) + 2;
  1465. return ret;
  1466. }
  1467. static uint32_t ilk_wm_fbc(uint32_t pri_val, uint32_t horiz_pixels,
  1468. uint8_t cpp)
  1469. {
  1470. /*
  1471. * Neither of these should be possible since this function shouldn't be
  1472. * called if the CRTC is off or the plane is invisible. But let's be
  1473. * extra paranoid to avoid a potential divide-by-zero if we screw up
  1474. * elsewhere in the driver.
  1475. */
  1476. if (WARN_ON(!cpp))
  1477. return 0;
  1478. if (WARN_ON(!horiz_pixels))
  1479. return 0;
  1480. return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2;
  1481. }
  1482. struct ilk_wm_maximums {
  1483. uint16_t pri;
  1484. uint16_t spr;
  1485. uint16_t cur;
  1486. uint16_t fbc;
  1487. };
  1488. /*
  1489. * For both WM_PIPE and WM_LP.
  1490. * mem_value must be in 0.1us units.
  1491. */
  1492. static uint32_t ilk_compute_pri_wm(const struct intel_crtc_state *cstate,
  1493. const struct intel_plane_state *pstate,
  1494. uint32_t mem_value,
  1495. bool is_lp)
  1496. {
  1497. int cpp = pstate->base.fb ?
  1498. drm_format_plane_cpp(pstate->base.fb->pixel_format, 0) : 0;
  1499. uint32_t method1, method2;
  1500. if (!cstate->base.active || !pstate->base.visible)
  1501. return 0;
  1502. method1 = ilk_wm_method1(ilk_pipe_pixel_rate(cstate), cpp, mem_value);
  1503. if (!is_lp)
  1504. return method1;
  1505. method2 = ilk_wm_method2(ilk_pipe_pixel_rate(cstate),
  1506. cstate->base.adjusted_mode.crtc_htotal,
  1507. drm_rect_width(&pstate->base.dst),
  1508. cpp, mem_value);
  1509. return min(method1, method2);
  1510. }
  1511. /*
  1512. * For both WM_PIPE and WM_LP.
  1513. * mem_value must be in 0.1us units.
  1514. */
  1515. static uint32_t ilk_compute_spr_wm(const struct intel_crtc_state *cstate,
  1516. const struct intel_plane_state *pstate,
  1517. uint32_t mem_value)
  1518. {
  1519. int cpp = pstate->base.fb ?
  1520. drm_format_plane_cpp(pstate->base.fb->pixel_format, 0) : 0;
  1521. uint32_t method1, method2;
  1522. if (!cstate->base.active || !pstate->base.visible)
  1523. return 0;
  1524. method1 = ilk_wm_method1(ilk_pipe_pixel_rate(cstate), cpp, mem_value);
  1525. method2 = ilk_wm_method2(ilk_pipe_pixel_rate(cstate),
  1526. cstate->base.adjusted_mode.crtc_htotal,
  1527. drm_rect_width(&pstate->base.dst),
  1528. cpp, mem_value);
  1529. return min(method1, method2);
  1530. }
  1531. /*
  1532. * For both WM_PIPE and WM_LP.
  1533. * mem_value must be in 0.1us units.
  1534. */
  1535. static uint32_t ilk_compute_cur_wm(const struct intel_crtc_state *cstate,
  1536. const struct intel_plane_state *pstate,
  1537. uint32_t mem_value)
  1538. {
  1539. /*
  1540. * We treat the cursor plane as always-on for the purposes of watermark
  1541. * calculation. Until we have two-stage watermark programming merged,
  1542. * this is necessary to avoid flickering.
  1543. */
  1544. int cpp = 4;
  1545. int width = pstate->base.visible ? pstate->base.crtc_w : 64;
  1546. if (!cstate->base.active)
  1547. return 0;
  1548. return ilk_wm_method2(ilk_pipe_pixel_rate(cstate),
  1549. cstate->base.adjusted_mode.crtc_htotal,
  1550. width, cpp, mem_value);
  1551. }
  1552. /* Only for WM_LP. */
  1553. static uint32_t ilk_compute_fbc_wm(const struct intel_crtc_state *cstate,
  1554. const struct intel_plane_state *pstate,
  1555. uint32_t pri_val)
  1556. {
  1557. int cpp = pstate->base.fb ?
  1558. drm_format_plane_cpp(pstate->base.fb->pixel_format, 0) : 0;
  1559. if (!cstate->base.active || !pstate->base.visible)
  1560. return 0;
  1561. return ilk_wm_fbc(pri_val, drm_rect_width(&pstate->base.dst), cpp);
  1562. }
  1563. static unsigned int ilk_display_fifo_size(const struct drm_device *dev)
  1564. {
  1565. if (INTEL_INFO(dev)->gen >= 8)
  1566. return 3072;
  1567. else if (INTEL_INFO(dev)->gen >= 7)
  1568. return 768;
  1569. else
  1570. return 512;
  1571. }
  1572. static unsigned int ilk_plane_wm_reg_max(const struct drm_device *dev,
  1573. int level, bool is_sprite)
  1574. {
  1575. if (INTEL_INFO(dev)->gen >= 8)
  1576. /* BDW primary/sprite plane watermarks */
  1577. return level == 0 ? 255 : 2047;
  1578. else if (INTEL_INFO(dev)->gen >= 7)
  1579. /* IVB/HSW primary/sprite plane watermarks */
  1580. return level == 0 ? 127 : 1023;
  1581. else if (!is_sprite)
  1582. /* ILK/SNB primary plane watermarks */
  1583. return level == 0 ? 127 : 511;
  1584. else
  1585. /* ILK/SNB sprite plane watermarks */
  1586. return level == 0 ? 63 : 255;
  1587. }
  1588. static unsigned int ilk_cursor_wm_reg_max(const struct drm_device *dev,
  1589. int level)
  1590. {
  1591. if (INTEL_INFO(dev)->gen >= 7)
  1592. return level == 0 ? 63 : 255;
  1593. else
  1594. return level == 0 ? 31 : 63;
  1595. }
  1596. static unsigned int ilk_fbc_wm_reg_max(const struct drm_device *dev)
  1597. {
  1598. if (INTEL_INFO(dev)->gen >= 8)
  1599. return 31;
  1600. else
  1601. return 15;
  1602. }
  1603. /* Calculate the maximum primary/sprite plane watermark */
  1604. static unsigned int ilk_plane_wm_max(const struct drm_device *dev,
  1605. int level,
  1606. const struct intel_wm_config *config,
  1607. enum intel_ddb_partitioning ddb_partitioning,
  1608. bool is_sprite)
  1609. {
  1610. unsigned int fifo_size = ilk_display_fifo_size(dev);
  1611. /* if sprites aren't enabled, sprites get nothing */
  1612. if (is_sprite && !config->sprites_enabled)
  1613. return 0;
  1614. /* HSW allows LP1+ watermarks even with multiple pipes */
  1615. if (level == 0 || config->num_pipes_active > 1) {
  1616. fifo_size /= INTEL_INFO(dev)->num_pipes;
  1617. /*
  1618. * For some reason the non self refresh
  1619. * FIFO size is only half of the self
  1620. * refresh FIFO size on ILK/SNB.
  1621. */
  1622. if (INTEL_INFO(dev)->gen <= 6)
  1623. fifo_size /= 2;
  1624. }
  1625. if (config->sprites_enabled) {
  1626. /* level 0 is always calculated with 1:1 split */
  1627. if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) {
  1628. if (is_sprite)
  1629. fifo_size *= 5;
  1630. fifo_size /= 6;
  1631. } else {
  1632. fifo_size /= 2;
  1633. }
  1634. }
  1635. /* clamp to max that the registers can hold */
  1636. return min(fifo_size, ilk_plane_wm_reg_max(dev, level, is_sprite));
  1637. }
  1638. /* Calculate the maximum cursor plane watermark */
  1639. static unsigned int ilk_cursor_wm_max(const struct drm_device *dev,
  1640. int level,
  1641. const struct intel_wm_config *config)
  1642. {
  1643. /* HSW LP1+ watermarks w/ multiple pipes */
  1644. if (level > 0 && config->num_pipes_active > 1)
  1645. return 64;
  1646. /* otherwise just report max that registers can hold */
  1647. return ilk_cursor_wm_reg_max(dev, level);
  1648. }
  1649. static void ilk_compute_wm_maximums(const struct drm_device *dev,
  1650. int level,
  1651. const struct intel_wm_config *config,
  1652. enum intel_ddb_partitioning ddb_partitioning,
  1653. struct ilk_wm_maximums *max)
  1654. {
  1655. max->pri = ilk_plane_wm_max(dev, level, config, ddb_partitioning, false);
  1656. max->spr = ilk_plane_wm_max(dev, level, config, ddb_partitioning, true);
  1657. max->cur = ilk_cursor_wm_max(dev, level, config);
  1658. max->fbc = ilk_fbc_wm_reg_max(dev);
  1659. }
  1660. static void ilk_compute_wm_reg_maximums(struct drm_device *dev,
  1661. int level,
  1662. struct ilk_wm_maximums *max)
  1663. {
  1664. max->pri = ilk_plane_wm_reg_max(dev, level, false);
  1665. max->spr = ilk_plane_wm_reg_max(dev, level, true);
  1666. max->cur = ilk_cursor_wm_reg_max(dev, level);
  1667. max->fbc = ilk_fbc_wm_reg_max(dev);
  1668. }
  1669. static bool ilk_validate_wm_level(int level,
  1670. const struct ilk_wm_maximums *max,
  1671. struct intel_wm_level *result)
  1672. {
  1673. bool ret;
  1674. /* already determined to be invalid? */
  1675. if (!result->enable)
  1676. return false;
  1677. result->enable = result->pri_val <= max->pri &&
  1678. result->spr_val <= max->spr &&
  1679. result->cur_val <= max->cur;
  1680. ret = result->enable;
  1681. /*
  1682. * HACK until we can pre-compute everything,
  1683. * and thus fail gracefully if LP0 watermarks
  1684. * are exceeded...
  1685. */
  1686. if (level == 0 && !result->enable) {
  1687. if (result->pri_val > max->pri)
  1688. DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n",
  1689. level, result->pri_val, max->pri);
  1690. if (result->spr_val > max->spr)
  1691. DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n",
  1692. level, result->spr_val, max->spr);
  1693. if (result->cur_val > max->cur)
  1694. DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n",
  1695. level, result->cur_val, max->cur);
  1696. result->pri_val = min_t(uint32_t, result->pri_val, max->pri);
  1697. result->spr_val = min_t(uint32_t, result->spr_val, max->spr);
  1698. result->cur_val = min_t(uint32_t, result->cur_val, max->cur);
  1699. result->enable = true;
  1700. }
  1701. return ret;
  1702. }
  1703. static void ilk_compute_wm_level(const struct drm_i915_private *dev_priv,
  1704. const struct intel_crtc *intel_crtc,
  1705. int level,
  1706. struct intel_crtc_state *cstate,
  1707. struct intel_plane_state *pristate,
  1708. struct intel_plane_state *sprstate,
  1709. struct intel_plane_state *curstate,
  1710. struct intel_wm_level *result)
  1711. {
  1712. uint16_t pri_latency = dev_priv->wm.pri_latency[level];
  1713. uint16_t spr_latency = dev_priv->wm.spr_latency[level];
  1714. uint16_t cur_latency = dev_priv->wm.cur_latency[level];
  1715. /* WM1+ latency values stored in 0.5us units */
  1716. if (level > 0) {
  1717. pri_latency *= 5;
  1718. spr_latency *= 5;
  1719. cur_latency *= 5;
  1720. }
  1721. if (pristate) {
  1722. result->pri_val = ilk_compute_pri_wm(cstate, pristate,
  1723. pri_latency, level);
  1724. result->fbc_val = ilk_compute_fbc_wm(cstate, pristate, result->pri_val);
  1725. }
  1726. if (sprstate)
  1727. result->spr_val = ilk_compute_spr_wm(cstate, sprstate, spr_latency);
  1728. if (curstate)
  1729. result->cur_val = ilk_compute_cur_wm(cstate, curstate, cur_latency);
  1730. result->enable = true;
  1731. }
  1732. static uint32_t
  1733. hsw_compute_linetime_wm(const struct intel_crtc_state *cstate)
  1734. {
  1735. const struct intel_atomic_state *intel_state =
  1736. to_intel_atomic_state(cstate->base.state);
  1737. const struct drm_display_mode *adjusted_mode =
  1738. &cstate->base.adjusted_mode;
  1739. u32 linetime, ips_linetime;
  1740. if (!cstate->base.active)
  1741. return 0;
  1742. if (WARN_ON(adjusted_mode->crtc_clock == 0))
  1743. return 0;
  1744. if (WARN_ON(intel_state->cdclk == 0))
  1745. return 0;
  1746. /* The WM are computed with base on how long it takes to fill a single
  1747. * row at the given clock rate, multiplied by 8.
  1748. * */
  1749. linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8,
  1750. adjusted_mode->crtc_clock);
  1751. ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8,
  1752. intel_state->cdclk);
  1753. return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) |
  1754. PIPE_WM_LINETIME_TIME(linetime);
  1755. }
  1756. static void intel_read_wm_latency(struct drm_device *dev, uint16_t wm[8])
  1757. {
  1758. struct drm_i915_private *dev_priv = to_i915(dev);
  1759. if (IS_GEN9(dev)) {
  1760. uint32_t val;
  1761. int ret, i;
  1762. int level, max_level = ilk_wm_max_level(dev);
  1763. /* read the first set of memory latencies[0:3] */
  1764. val = 0; /* data0 to be programmed to 0 for first set */
  1765. mutex_lock(&dev_priv->rps.hw_lock);
  1766. ret = sandybridge_pcode_read(dev_priv,
  1767. GEN9_PCODE_READ_MEM_LATENCY,
  1768. &val);
  1769. mutex_unlock(&dev_priv->rps.hw_lock);
  1770. if (ret) {
  1771. DRM_ERROR("SKL Mailbox read error = %d\n", ret);
  1772. return;
  1773. }
  1774. wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK;
  1775. wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
  1776. GEN9_MEM_LATENCY_LEVEL_MASK;
  1777. wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
  1778. GEN9_MEM_LATENCY_LEVEL_MASK;
  1779. wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
  1780. GEN9_MEM_LATENCY_LEVEL_MASK;
  1781. /* read the second set of memory latencies[4:7] */
  1782. val = 1; /* data0 to be programmed to 1 for second set */
  1783. mutex_lock(&dev_priv->rps.hw_lock);
  1784. ret = sandybridge_pcode_read(dev_priv,
  1785. GEN9_PCODE_READ_MEM_LATENCY,
  1786. &val);
  1787. mutex_unlock(&dev_priv->rps.hw_lock);
  1788. if (ret) {
  1789. DRM_ERROR("SKL Mailbox read error = %d\n", ret);
  1790. return;
  1791. }
  1792. wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK;
  1793. wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
  1794. GEN9_MEM_LATENCY_LEVEL_MASK;
  1795. wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
  1796. GEN9_MEM_LATENCY_LEVEL_MASK;
  1797. wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
  1798. GEN9_MEM_LATENCY_LEVEL_MASK;
  1799. /*
  1800. * If a level n (n > 1) has a 0us latency, all levels m (m >= n)
  1801. * need to be disabled. We make sure to sanitize the values out
  1802. * of the punit to satisfy this requirement.
  1803. */
  1804. for (level = 1; level <= max_level; level++) {
  1805. if (wm[level] == 0) {
  1806. for (i = level + 1; i <= max_level; i++)
  1807. wm[i] = 0;
  1808. break;
  1809. }
  1810. }
  1811. /*
  1812. * WaWmMemoryReadLatency:skl
  1813. *
  1814. * punit doesn't take into account the read latency so we need
  1815. * to add 2us to the various latency levels we retrieve from the
  1816. * punit when level 0 response data us 0us.
  1817. */
  1818. if (wm[0] == 0) {
  1819. wm[0] += 2;
  1820. for (level = 1; level <= max_level; level++) {
  1821. if (wm[level] == 0)
  1822. break;
  1823. wm[level] += 2;
  1824. }
  1825. }
  1826. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  1827. uint64_t sskpd = I915_READ64(MCH_SSKPD);
  1828. wm[0] = (sskpd >> 56) & 0xFF;
  1829. if (wm[0] == 0)
  1830. wm[0] = sskpd & 0xF;
  1831. wm[1] = (sskpd >> 4) & 0xFF;
  1832. wm[2] = (sskpd >> 12) & 0xFF;
  1833. wm[3] = (sskpd >> 20) & 0x1FF;
  1834. wm[4] = (sskpd >> 32) & 0x1FF;
  1835. } else if (INTEL_INFO(dev)->gen >= 6) {
  1836. uint32_t sskpd = I915_READ(MCH_SSKPD);
  1837. wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK;
  1838. wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK;
  1839. wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK;
  1840. wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK;
  1841. } else if (INTEL_INFO(dev)->gen >= 5) {
  1842. uint32_t mltr = I915_READ(MLTR_ILK);
  1843. /* ILK primary LP0 latency is 700 ns */
  1844. wm[0] = 7;
  1845. wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK;
  1846. wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK;
  1847. }
  1848. }
  1849. static void intel_fixup_spr_wm_latency(struct drm_device *dev, uint16_t wm[5])
  1850. {
  1851. /* ILK sprite LP0 latency is 1300 ns */
  1852. if (IS_GEN5(dev))
  1853. wm[0] = 13;
  1854. }
  1855. static void intel_fixup_cur_wm_latency(struct drm_device *dev, uint16_t wm[5])
  1856. {
  1857. /* ILK cursor LP0 latency is 1300 ns */
  1858. if (IS_GEN5(dev))
  1859. wm[0] = 13;
  1860. /* WaDoubleCursorLP3Latency:ivb */
  1861. if (IS_IVYBRIDGE(dev))
  1862. wm[3] *= 2;
  1863. }
  1864. int ilk_wm_max_level(const struct drm_device *dev)
  1865. {
  1866. /* how many WM levels are we expecting */
  1867. if (INTEL_INFO(dev)->gen >= 9)
  1868. return 7;
  1869. else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  1870. return 4;
  1871. else if (INTEL_INFO(dev)->gen >= 6)
  1872. return 3;
  1873. else
  1874. return 2;
  1875. }
  1876. static void intel_print_wm_latency(struct drm_device *dev,
  1877. const char *name,
  1878. const uint16_t wm[8])
  1879. {
  1880. int level, max_level = ilk_wm_max_level(dev);
  1881. for (level = 0; level <= max_level; level++) {
  1882. unsigned int latency = wm[level];
  1883. if (latency == 0) {
  1884. DRM_ERROR("%s WM%d latency not provided\n",
  1885. name, level);
  1886. continue;
  1887. }
  1888. /*
  1889. * - latencies are in us on gen9.
  1890. * - before then, WM1+ latency values are in 0.5us units
  1891. */
  1892. if (IS_GEN9(dev))
  1893. latency *= 10;
  1894. else if (level > 0)
  1895. latency *= 5;
  1896. DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n",
  1897. name, level, wm[level],
  1898. latency / 10, latency % 10);
  1899. }
  1900. }
  1901. static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv,
  1902. uint16_t wm[5], uint16_t min)
  1903. {
  1904. int level, max_level = ilk_wm_max_level(&dev_priv->drm);
  1905. if (wm[0] >= min)
  1906. return false;
  1907. wm[0] = max(wm[0], min);
  1908. for (level = 1; level <= max_level; level++)
  1909. wm[level] = max_t(uint16_t, wm[level], DIV_ROUND_UP(min, 5));
  1910. return true;
  1911. }
  1912. static void snb_wm_latency_quirk(struct drm_device *dev)
  1913. {
  1914. struct drm_i915_private *dev_priv = to_i915(dev);
  1915. bool changed;
  1916. /*
  1917. * The BIOS provided WM memory latency values are often
  1918. * inadequate for high resolution displays. Adjust them.
  1919. */
  1920. changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) |
  1921. ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) |
  1922. ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12);
  1923. if (!changed)
  1924. return;
  1925. DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n");
  1926. intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency);
  1927. intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency);
  1928. intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency);
  1929. }
  1930. static void ilk_setup_wm_latency(struct drm_device *dev)
  1931. {
  1932. struct drm_i915_private *dev_priv = to_i915(dev);
  1933. intel_read_wm_latency(dev, dev_priv->wm.pri_latency);
  1934. memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency,
  1935. sizeof(dev_priv->wm.pri_latency));
  1936. memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency,
  1937. sizeof(dev_priv->wm.pri_latency));
  1938. intel_fixup_spr_wm_latency(dev, dev_priv->wm.spr_latency);
  1939. intel_fixup_cur_wm_latency(dev, dev_priv->wm.cur_latency);
  1940. intel_print_wm_latency(dev, "Primary", dev_priv->wm.pri_latency);
  1941. intel_print_wm_latency(dev, "Sprite", dev_priv->wm.spr_latency);
  1942. intel_print_wm_latency(dev, "Cursor", dev_priv->wm.cur_latency);
  1943. if (IS_GEN6(dev))
  1944. snb_wm_latency_quirk(dev);
  1945. }
  1946. static void skl_setup_wm_latency(struct drm_device *dev)
  1947. {
  1948. struct drm_i915_private *dev_priv = to_i915(dev);
  1949. intel_read_wm_latency(dev, dev_priv->wm.skl_latency);
  1950. intel_print_wm_latency(dev, "Gen9 Plane", dev_priv->wm.skl_latency);
  1951. }
  1952. static bool ilk_validate_pipe_wm(struct drm_device *dev,
  1953. struct intel_pipe_wm *pipe_wm)
  1954. {
  1955. /* LP0 watermark maximums depend on this pipe alone */
  1956. const struct intel_wm_config config = {
  1957. .num_pipes_active = 1,
  1958. .sprites_enabled = pipe_wm->sprites_enabled,
  1959. .sprites_scaled = pipe_wm->sprites_scaled,
  1960. };
  1961. struct ilk_wm_maximums max;
  1962. /* LP0 watermarks always use 1/2 DDB partitioning */
  1963. ilk_compute_wm_maximums(dev, 0, &config, INTEL_DDB_PART_1_2, &max);
  1964. /* At least LP0 must be valid */
  1965. if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) {
  1966. DRM_DEBUG_KMS("LP0 watermark invalid\n");
  1967. return false;
  1968. }
  1969. return true;
  1970. }
  1971. /* Compute new watermarks for the pipe */
  1972. static int ilk_compute_pipe_wm(struct intel_crtc_state *cstate)
  1973. {
  1974. struct drm_atomic_state *state = cstate->base.state;
  1975. struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc);
  1976. struct intel_pipe_wm *pipe_wm;
  1977. struct drm_device *dev = state->dev;
  1978. const struct drm_i915_private *dev_priv = to_i915(dev);
  1979. struct intel_plane *intel_plane;
  1980. struct intel_plane_state *pristate = NULL;
  1981. struct intel_plane_state *sprstate = NULL;
  1982. struct intel_plane_state *curstate = NULL;
  1983. int level, max_level = ilk_wm_max_level(dev), usable_level;
  1984. struct ilk_wm_maximums max;
  1985. pipe_wm = &cstate->wm.ilk.optimal;
  1986. for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
  1987. struct intel_plane_state *ps;
  1988. ps = intel_atomic_get_existing_plane_state(state,
  1989. intel_plane);
  1990. if (!ps)
  1991. continue;
  1992. if (intel_plane->base.type == DRM_PLANE_TYPE_PRIMARY)
  1993. pristate = ps;
  1994. else if (intel_plane->base.type == DRM_PLANE_TYPE_OVERLAY)
  1995. sprstate = ps;
  1996. else if (intel_plane->base.type == DRM_PLANE_TYPE_CURSOR)
  1997. curstate = ps;
  1998. }
  1999. pipe_wm->pipe_enabled = cstate->base.active;
  2000. if (sprstate) {
  2001. pipe_wm->sprites_enabled = sprstate->base.visible;
  2002. pipe_wm->sprites_scaled = sprstate->base.visible &&
  2003. (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 ||
  2004. drm_rect_height(&sprstate->base.dst) != drm_rect_height(&sprstate->base.src) >> 16);
  2005. }
  2006. usable_level = max_level;
  2007. /* ILK/SNB: LP2+ watermarks only w/o sprites */
  2008. if (INTEL_INFO(dev)->gen <= 6 && pipe_wm->sprites_enabled)
  2009. usable_level = 1;
  2010. /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */
  2011. if (pipe_wm->sprites_scaled)
  2012. usable_level = 0;
  2013. ilk_compute_wm_level(dev_priv, intel_crtc, 0, cstate,
  2014. pristate, sprstate, curstate, &pipe_wm->raw_wm[0]);
  2015. memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm));
  2016. pipe_wm->wm[0] = pipe_wm->raw_wm[0];
  2017. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2018. pipe_wm->linetime = hsw_compute_linetime_wm(cstate);
  2019. if (!ilk_validate_pipe_wm(dev, pipe_wm))
  2020. return -EINVAL;
  2021. ilk_compute_wm_reg_maximums(dev, 1, &max);
  2022. for (level = 1; level <= max_level; level++) {
  2023. struct intel_wm_level *wm = &pipe_wm->raw_wm[level];
  2024. ilk_compute_wm_level(dev_priv, intel_crtc, level, cstate,
  2025. pristate, sprstate, curstate, wm);
  2026. /*
  2027. * Disable any watermark level that exceeds the
  2028. * register maximums since such watermarks are
  2029. * always invalid.
  2030. */
  2031. if (level > usable_level)
  2032. continue;
  2033. if (ilk_validate_wm_level(level, &max, wm))
  2034. pipe_wm->wm[level] = *wm;
  2035. else
  2036. usable_level = level;
  2037. }
  2038. return 0;
  2039. }
  2040. /*
  2041. * Build a set of 'intermediate' watermark values that satisfy both the old
  2042. * state and the new state. These can be programmed to the hardware
  2043. * immediately.
  2044. */
  2045. static int ilk_compute_intermediate_wm(struct drm_device *dev,
  2046. struct intel_crtc *intel_crtc,
  2047. struct intel_crtc_state *newstate)
  2048. {
  2049. struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate;
  2050. struct intel_pipe_wm *b = &intel_crtc->wm.active.ilk;
  2051. int level, max_level = ilk_wm_max_level(dev);
  2052. /*
  2053. * Start with the final, target watermarks, then combine with the
  2054. * currently active watermarks to get values that are safe both before
  2055. * and after the vblank.
  2056. */
  2057. *a = newstate->wm.ilk.optimal;
  2058. a->pipe_enabled |= b->pipe_enabled;
  2059. a->sprites_enabled |= b->sprites_enabled;
  2060. a->sprites_scaled |= b->sprites_scaled;
  2061. for (level = 0; level <= max_level; level++) {
  2062. struct intel_wm_level *a_wm = &a->wm[level];
  2063. const struct intel_wm_level *b_wm = &b->wm[level];
  2064. a_wm->enable &= b_wm->enable;
  2065. a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val);
  2066. a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val);
  2067. a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val);
  2068. a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val);
  2069. }
  2070. /*
  2071. * We need to make sure that these merged watermark values are
  2072. * actually a valid configuration themselves. If they're not,
  2073. * there's no safe way to transition from the old state to
  2074. * the new state, so we need to fail the atomic transaction.
  2075. */
  2076. if (!ilk_validate_pipe_wm(dev, a))
  2077. return -EINVAL;
  2078. /*
  2079. * If our intermediate WM are identical to the final WM, then we can
  2080. * omit the post-vblank programming; only update if it's different.
  2081. */
  2082. if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) == 0)
  2083. newstate->wm.need_postvbl_update = false;
  2084. return 0;
  2085. }
  2086. /*
  2087. * Merge the watermarks from all active pipes for a specific level.
  2088. */
  2089. static void ilk_merge_wm_level(struct drm_device *dev,
  2090. int level,
  2091. struct intel_wm_level *ret_wm)
  2092. {
  2093. const struct intel_crtc *intel_crtc;
  2094. ret_wm->enable = true;
  2095. for_each_intel_crtc(dev, intel_crtc) {
  2096. const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk;
  2097. const struct intel_wm_level *wm = &active->wm[level];
  2098. if (!active->pipe_enabled)
  2099. continue;
  2100. /*
  2101. * The watermark values may have been used in the past,
  2102. * so we must maintain them in the registers for some
  2103. * time even if the level is now disabled.
  2104. */
  2105. if (!wm->enable)
  2106. ret_wm->enable = false;
  2107. ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val);
  2108. ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val);
  2109. ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val);
  2110. ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val);
  2111. }
  2112. }
  2113. /*
  2114. * Merge all low power watermarks for all active pipes.
  2115. */
  2116. static void ilk_wm_merge(struct drm_device *dev,
  2117. const struct intel_wm_config *config,
  2118. const struct ilk_wm_maximums *max,
  2119. struct intel_pipe_wm *merged)
  2120. {
  2121. struct drm_i915_private *dev_priv = to_i915(dev);
  2122. int level, max_level = ilk_wm_max_level(dev);
  2123. int last_enabled_level = max_level;
  2124. /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */
  2125. if ((INTEL_INFO(dev)->gen <= 6 || IS_IVYBRIDGE(dev)) &&
  2126. config->num_pipes_active > 1)
  2127. last_enabled_level = 0;
  2128. /* ILK: FBC WM must be disabled always */
  2129. merged->fbc_wm_enabled = INTEL_INFO(dev)->gen >= 6;
  2130. /* merge each WM1+ level */
  2131. for (level = 1; level <= max_level; level++) {
  2132. struct intel_wm_level *wm = &merged->wm[level];
  2133. ilk_merge_wm_level(dev, level, wm);
  2134. if (level > last_enabled_level)
  2135. wm->enable = false;
  2136. else if (!ilk_validate_wm_level(level, max, wm))
  2137. /* make sure all following levels get disabled */
  2138. last_enabled_level = level - 1;
  2139. /*
  2140. * The spec says it is preferred to disable
  2141. * FBC WMs instead of disabling a WM level.
  2142. */
  2143. if (wm->fbc_val > max->fbc) {
  2144. if (wm->enable)
  2145. merged->fbc_wm_enabled = false;
  2146. wm->fbc_val = 0;
  2147. }
  2148. }
  2149. /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */
  2150. /*
  2151. * FIXME this is racy. FBC might get enabled later.
  2152. * What we should check here is whether FBC can be
  2153. * enabled sometime later.
  2154. */
  2155. if (IS_GEN5(dev) && !merged->fbc_wm_enabled &&
  2156. intel_fbc_is_active(dev_priv)) {
  2157. for (level = 2; level <= max_level; level++) {
  2158. struct intel_wm_level *wm = &merged->wm[level];
  2159. wm->enable = false;
  2160. }
  2161. }
  2162. }
  2163. static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm)
  2164. {
  2165. /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */
  2166. return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable);
  2167. }
  2168. /* The value we need to program into the WM_LPx latency field */
  2169. static unsigned int ilk_wm_lp_latency(struct drm_device *dev, int level)
  2170. {
  2171. struct drm_i915_private *dev_priv = to_i915(dev);
  2172. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2173. return 2 * level;
  2174. else
  2175. return dev_priv->wm.pri_latency[level];
  2176. }
  2177. static void ilk_compute_wm_results(struct drm_device *dev,
  2178. const struct intel_pipe_wm *merged,
  2179. enum intel_ddb_partitioning partitioning,
  2180. struct ilk_wm_values *results)
  2181. {
  2182. struct intel_crtc *intel_crtc;
  2183. int level, wm_lp;
  2184. results->enable_fbc_wm = merged->fbc_wm_enabled;
  2185. results->partitioning = partitioning;
  2186. /* LP1+ register values */
  2187. for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
  2188. const struct intel_wm_level *r;
  2189. level = ilk_wm_lp_to_level(wm_lp, merged);
  2190. r = &merged->wm[level];
  2191. /*
  2192. * Maintain the watermark values even if the level is
  2193. * disabled. Doing otherwise could cause underruns.
  2194. */
  2195. results->wm_lp[wm_lp - 1] =
  2196. (ilk_wm_lp_latency(dev, level) << WM1_LP_LATENCY_SHIFT) |
  2197. (r->pri_val << WM1_LP_SR_SHIFT) |
  2198. r->cur_val;
  2199. if (r->enable)
  2200. results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN;
  2201. if (INTEL_INFO(dev)->gen >= 8)
  2202. results->wm_lp[wm_lp - 1] |=
  2203. r->fbc_val << WM1_LP_FBC_SHIFT_BDW;
  2204. else
  2205. results->wm_lp[wm_lp - 1] |=
  2206. r->fbc_val << WM1_LP_FBC_SHIFT;
  2207. /*
  2208. * Always set WM1S_LP_EN when spr_val != 0, even if the
  2209. * level is disabled. Doing otherwise could cause underruns.
  2210. */
  2211. if (INTEL_INFO(dev)->gen <= 6 && r->spr_val) {
  2212. WARN_ON(wm_lp != 1);
  2213. results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val;
  2214. } else
  2215. results->wm_lp_spr[wm_lp - 1] = r->spr_val;
  2216. }
  2217. /* LP0 register values */
  2218. for_each_intel_crtc(dev, intel_crtc) {
  2219. enum pipe pipe = intel_crtc->pipe;
  2220. const struct intel_wm_level *r =
  2221. &intel_crtc->wm.active.ilk.wm[0];
  2222. if (WARN_ON(!r->enable))
  2223. continue;
  2224. results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime;
  2225. results->wm_pipe[pipe] =
  2226. (r->pri_val << WM0_PIPE_PLANE_SHIFT) |
  2227. (r->spr_val << WM0_PIPE_SPRITE_SHIFT) |
  2228. r->cur_val;
  2229. }
  2230. }
  2231. /* Find the result with the highest level enabled. Check for enable_fbc_wm in
  2232. * case both are at the same level. Prefer r1 in case they're the same. */
  2233. static struct intel_pipe_wm *ilk_find_best_result(struct drm_device *dev,
  2234. struct intel_pipe_wm *r1,
  2235. struct intel_pipe_wm *r2)
  2236. {
  2237. int level, max_level = ilk_wm_max_level(dev);
  2238. int level1 = 0, level2 = 0;
  2239. for (level = 1; level <= max_level; level++) {
  2240. if (r1->wm[level].enable)
  2241. level1 = level;
  2242. if (r2->wm[level].enable)
  2243. level2 = level;
  2244. }
  2245. if (level1 == level2) {
  2246. if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled)
  2247. return r2;
  2248. else
  2249. return r1;
  2250. } else if (level1 > level2) {
  2251. return r1;
  2252. } else {
  2253. return r2;
  2254. }
  2255. }
  2256. /* dirty bits used to track which watermarks need changes */
  2257. #define WM_DIRTY_PIPE(pipe) (1 << (pipe))
  2258. #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe)))
  2259. #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp)))
  2260. #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3))
  2261. #define WM_DIRTY_FBC (1 << 24)
  2262. #define WM_DIRTY_DDB (1 << 25)
  2263. static unsigned int ilk_compute_wm_dirty(struct drm_i915_private *dev_priv,
  2264. const struct ilk_wm_values *old,
  2265. const struct ilk_wm_values *new)
  2266. {
  2267. unsigned int dirty = 0;
  2268. enum pipe pipe;
  2269. int wm_lp;
  2270. for_each_pipe(dev_priv, pipe) {
  2271. if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) {
  2272. dirty |= WM_DIRTY_LINETIME(pipe);
  2273. /* Must disable LP1+ watermarks too */
  2274. dirty |= WM_DIRTY_LP_ALL;
  2275. }
  2276. if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) {
  2277. dirty |= WM_DIRTY_PIPE(pipe);
  2278. /* Must disable LP1+ watermarks too */
  2279. dirty |= WM_DIRTY_LP_ALL;
  2280. }
  2281. }
  2282. if (old->enable_fbc_wm != new->enable_fbc_wm) {
  2283. dirty |= WM_DIRTY_FBC;
  2284. /* Must disable LP1+ watermarks too */
  2285. dirty |= WM_DIRTY_LP_ALL;
  2286. }
  2287. if (old->partitioning != new->partitioning) {
  2288. dirty |= WM_DIRTY_DDB;
  2289. /* Must disable LP1+ watermarks too */
  2290. dirty |= WM_DIRTY_LP_ALL;
  2291. }
  2292. /* LP1+ watermarks already deemed dirty, no need to continue */
  2293. if (dirty & WM_DIRTY_LP_ALL)
  2294. return dirty;
  2295. /* Find the lowest numbered LP1+ watermark in need of an update... */
  2296. for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
  2297. if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] ||
  2298. old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1])
  2299. break;
  2300. }
  2301. /* ...and mark it and all higher numbered LP1+ watermarks as dirty */
  2302. for (; wm_lp <= 3; wm_lp++)
  2303. dirty |= WM_DIRTY_LP(wm_lp);
  2304. return dirty;
  2305. }
  2306. static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv,
  2307. unsigned int dirty)
  2308. {
  2309. struct ilk_wm_values *previous = &dev_priv->wm.hw;
  2310. bool changed = false;
  2311. if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) {
  2312. previous->wm_lp[2] &= ~WM1_LP_SR_EN;
  2313. I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]);
  2314. changed = true;
  2315. }
  2316. if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) {
  2317. previous->wm_lp[1] &= ~WM1_LP_SR_EN;
  2318. I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]);
  2319. changed = true;
  2320. }
  2321. if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) {
  2322. previous->wm_lp[0] &= ~WM1_LP_SR_EN;
  2323. I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]);
  2324. changed = true;
  2325. }
  2326. /*
  2327. * Don't touch WM1S_LP_EN here.
  2328. * Doing so could cause underruns.
  2329. */
  2330. return changed;
  2331. }
  2332. /*
  2333. * The spec says we shouldn't write when we don't need, because every write
  2334. * causes WMs to be re-evaluated, expending some power.
  2335. */
  2336. static void ilk_write_wm_values(struct drm_i915_private *dev_priv,
  2337. struct ilk_wm_values *results)
  2338. {
  2339. struct drm_device *dev = &dev_priv->drm;
  2340. struct ilk_wm_values *previous = &dev_priv->wm.hw;
  2341. unsigned int dirty;
  2342. uint32_t val;
  2343. dirty = ilk_compute_wm_dirty(dev_priv, previous, results);
  2344. if (!dirty)
  2345. return;
  2346. _ilk_disable_lp_wm(dev_priv, dirty);
  2347. if (dirty & WM_DIRTY_PIPE(PIPE_A))
  2348. I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]);
  2349. if (dirty & WM_DIRTY_PIPE(PIPE_B))
  2350. I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]);
  2351. if (dirty & WM_DIRTY_PIPE(PIPE_C))
  2352. I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]);
  2353. if (dirty & WM_DIRTY_LINETIME(PIPE_A))
  2354. I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]);
  2355. if (dirty & WM_DIRTY_LINETIME(PIPE_B))
  2356. I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]);
  2357. if (dirty & WM_DIRTY_LINETIME(PIPE_C))
  2358. I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]);
  2359. if (dirty & WM_DIRTY_DDB) {
  2360. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2361. val = I915_READ(WM_MISC);
  2362. if (results->partitioning == INTEL_DDB_PART_1_2)
  2363. val &= ~WM_MISC_DATA_PARTITION_5_6;
  2364. else
  2365. val |= WM_MISC_DATA_PARTITION_5_6;
  2366. I915_WRITE(WM_MISC, val);
  2367. } else {
  2368. val = I915_READ(DISP_ARB_CTL2);
  2369. if (results->partitioning == INTEL_DDB_PART_1_2)
  2370. val &= ~DISP_DATA_PARTITION_5_6;
  2371. else
  2372. val |= DISP_DATA_PARTITION_5_6;
  2373. I915_WRITE(DISP_ARB_CTL2, val);
  2374. }
  2375. }
  2376. if (dirty & WM_DIRTY_FBC) {
  2377. val = I915_READ(DISP_ARB_CTL);
  2378. if (results->enable_fbc_wm)
  2379. val &= ~DISP_FBC_WM_DIS;
  2380. else
  2381. val |= DISP_FBC_WM_DIS;
  2382. I915_WRITE(DISP_ARB_CTL, val);
  2383. }
  2384. if (dirty & WM_DIRTY_LP(1) &&
  2385. previous->wm_lp_spr[0] != results->wm_lp_spr[0])
  2386. I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]);
  2387. if (INTEL_INFO(dev)->gen >= 7) {
  2388. if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1])
  2389. I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]);
  2390. if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2])
  2391. I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]);
  2392. }
  2393. if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] != results->wm_lp[0])
  2394. I915_WRITE(WM1_LP_ILK, results->wm_lp[0]);
  2395. if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] != results->wm_lp[1])
  2396. I915_WRITE(WM2_LP_ILK, results->wm_lp[1]);
  2397. if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] != results->wm_lp[2])
  2398. I915_WRITE(WM3_LP_ILK, results->wm_lp[2]);
  2399. dev_priv->wm.hw = *results;
  2400. }
  2401. bool ilk_disable_lp_wm(struct drm_device *dev)
  2402. {
  2403. struct drm_i915_private *dev_priv = to_i915(dev);
  2404. return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL);
  2405. }
  2406. #define SKL_SAGV_BLOCK_TIME 30 /* µs */
  2407. /*
  2408. * Return the index of a plane in the SKL DDB and wm result arrays. Primary
  2409. * plane is always in slot 0, cursor is always in slot I915_MAX_PLANES-1, and
  2410. * other universal planes are in indices 1..n. Note that this may leave unused
  2411. * indices between the top "sprite" plane and the cursor.
  2412. */
  2413. static int
  2414. skl_wm_plane_id(const struct intel_plane *plane)
  2415. {
  2416. switch (plane->base.type) {
  2417. case DRM_PLANE_TYPE_PRIMARY:
  2418. return 0;
  2419. case DRM_PLANE_TYPE_CURSOR:
  2420. return PLANE_CURSOR;
  2421. case DRM_PLANE_TYPE_OVERLAY:
  2422. return plane->plane + 1;
  2423. default:
  2424. MISSING_CASE(plane->base.type);
  2425. return plane->plane;
  2426. }
  2427. }
  2428. /*
  2429. * FIXME: We still don't have the proper code detect if we need to apply the WA,
  2430. * so assume we'll always need it in order to avoid underruns.
  2431. */
  2432. static bool skl_needs_memory_bw_wa(struct intel_atomic_state *state)
  2433. {
  2434. struct drm_i915_private *dev_priv = to_i915(state->base.dev);
  2435. if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv) ||
  2436. IS_KABYLAKE(dev_priv))
  2437. return true;
  2438. return false;
  2439. }
  2440. static bool
  2441. intel_has_sagv(struct drm_i915_private *dev_priv)
  2442. {
  2443. if (IS_KABYLAKE(dev_priv))
  2444. return true;
  2445. if (IS_SKYLAKE(dev_priv) &&
  2446. dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED)
  2447. return true;
  2448. return false;
  2449. }
  2450. /*
  2451. * SAGV dynamically adjusts the system agent voltage and clock frequencies
  2452. * depending on power and performance requirements. The display engine access
  2453. * to system memory is blocked during the adjustment time. Because of the
  2454. * blocking time, having this enabled can cause full system hangs and/or pipe
  2455. * underruns if we don't meet all of the following requirements:
  2456. *
  2457. * - <= 1 pipe enabled
  2458. * - All planes can enable watermarks for latencies >= SAGV engine block time
  2459. * - We're not using an interlaced display configuration
  2460. */
  2461. int
  2462. intel_enable_sagv(struct drm_i915_private *dev_priv)
  2463. {
  2464. int ret;
  2465. if (!intel_has_sagv(dev_priv))
  2466. return 0;
  2467. if (dev_priv->sagv_status == I915_SAGV_ENABLED)
  2468. return 0;
  2469. DRM_DEBUG_KMS("Enabling the SAGV\n");
  2470. mutex_lock(&dev_priv->rps.hw_lock);
  2471. ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL,
  2472. GEN9_SAGV_ENABLE);
  2473. /* We don't need to wait for the SAGV when enabling */
  2474. mutex_unlock(&dev_priv->rps.hw_lock);
  2475. /*
  2476. * Some skl systems, pre-release machines in particular,
  2477. * don't actually have an SAGV.
  2478. */
  2479. if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) {
  2480. DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n");
  2481. dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED;
  2482. return 0;
  2483. } else if (ret < 0) {
  2484. DRM_ERROR("Failed to enable the SAGV\n");
  2485. return ret;
  2486. }
  2487. dev_priv->sagv_status = I915_SAGV_ENABLED;
  2488. return 0;
  2489. }
  2490. int
  2491. intel_disable_sagv(struct drm_i915_private *dev_priv)
  2492. {
  2493. int ret;
  2494. if (!intel_has_sagv(dev_priv))
  2495. return 0;
  2496. if (dev_priv->sagv_status == I915_SAGV_DISABLED)
  2497. return 0;
  2498. DRM_DEBUG_KMS("Disabling the SAGV\n");
  2499. mutex_lock(&dev_priv->rps.hw_lock);
  2500. /* bspec says to keep retrying for at least 1 ms */
  2501. ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL,
  2502. GEN9_SAGV_DISABLE,
  2503. GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED,
  2504. 1);
  2505. mutex_unlock(&dev_priv->rps.hw_lock);
  2506. /*
  2507. * Some skl systems, pre-release machines in particular,
  2508. * don't actually have an SAGV.
  2509. */
  2510. if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) {
  2511. DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n");
  2512. dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED;
  2513. return 0;
  2514. } else if (ret < 0) {
  2515. DRM_ERROR("Failed to disable the SAGV (%d)\n", ret);
  2516. return ret;
  2517. }
  2518. dev_priv->sagv_status = I915_SAGV_DISABLED;
  2519. return 0;
  2520. }
  2521. bool intel_can_enable_sagv(struct drm_atomic_state *state)
  2522. {
  2523. struct drm_device *dev = state->dev;
  2524. struct drm_i915_private *dev_priv = to_i915(dev);
  2525. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  2526. struct intel_crtc *crtc;
  2527. struct intel_plane *plane;
  2528. enum pipe pipe;
  2529. int level, id, latency;
  2530. if (!intel_has_sagv(dev_priv))
  2531. return false;
  2532. /*
  2533. * SKL workaround: bspec recommends we disable the SAGV when we have
  2534. * more then one pipe enabled
  2535. *
  2536. * If there are no active CRTCs, no additional checks need be performed
  2537. */
  2538. if (hweight32(intel_state->active_crtcs) == 0)
  2539. return true;
  2540. else if (hweight32(intel_state->active_crtcs) > 1)
  2541. return false;
  2542. /* Since we're now guaranteed to only have one active CRTC... */
  2543. pipe = ffs(intel_state->active_crtcs) - 1;
  2544. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  2545. if (crtc->base.state->mode.flags & DRM_MODE_FLAG_INTERLACE)
  2546. return false;
  2547. for_each_intel_plane_on_crtc(dev, crtc, plane) {
  2548. id = skl_wm_plane_id(plane);
  2549. /* Skip this plane if it's not enabled */
  2550. if (intel_state->wm_results.plane[pipe][id][0] == 0)
  2551. continue;
  2552. /* Find the highest enabled wm level for this plane */
  2553. for (level = ilk_wm_max_level(dev);
  2554. intel_state->wm_results.plane[pipe][id][level] == 0; --level)
  2555. { }
  2556. latency = dev_priv->wm.skl_latency[level];
  2557. if (skl_needs_memory_bw_wa(intel_state) &&
  2558. plane->base.state->fb->modifier[0] ==
  2559. I915_FORMAT_MOD_X_TILED)
  2560. latency += 15;
  2561. /*
  2562. * If any of the planes on this pipe don't enable wm levels
  2563. * that incur memory latencies higher then 30µs we can't enable
  2564. * the SAGV
  2565. */
  2566. if (latency < SKL_SAGV_BLOCK_TIME)
  2567. return false;
  2568. }
  2569. return true;
  2570. }
  2571. static void
  2572. skl_ddb_get_pipe_allocation_limits(struct drm_device *dev,
  2573. const struct intel_crtc_state *cstate,
  2574. struct skl_ddb_entry *alloc, /* out */
  2575. int *num_active /* out */)
  2576. {
  2577. struct drm_atomic_state *state = cstate->base.state;
  2578. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  2579. struct drm_i915_private *dev_priv = to_i915(dev);
  2580. struct drm_crtc *for_crtc = cstate->base.crtc;
  2581. unsigned int pipe_size, ddb_size;
  2582. int nth_active_pipe;
  2583. int pipe = to_intel_crtc(for_crtc)->pipe;
  2584. if (WARN_ON(!state) || !cstate->base.active) {
  2585. alloc->start = 0;
  2586. alloc->end = 0;
  2587. *num_active = hweight32(dev_priv->active_crtcs);
  2588. return;
  2589. }
  2590. if (intel_state->active_pipe_changes)
  2591. *num_active = hweight32(intel_state->active_crtcs);
  2592. else
  2593. *num_active = hweight32(dev_priv->active_crtcs);
  2594. ddb_size = INTEL_INFO(dev_priv)->ddb_size;
  2595. WARN_ON(ddb_size == 0);
  2596. ddb_size -= 4; /* 4 blocks for bypass path allocation */
  2597. /*
  2598. * If the state doesn't change the active CRTC's, then there's
  2599. * no need to recalculate; the existing pipe allocation limits
  2600. * should remain unchanged. Note that we're safe from racing
  2601. * commits since any racing commit that changes the active CRTC
  2602. * list would need to grab _all_ crtc locks, including the one
  2603. * we currently hold.
  2604. */
  2605. if (!intel_state->active_pipe_changes) {
  2606. *alloc = dev_priv->wm.skl_hw.ddb.pipe[pipe];
  2607. return;
  2608. }
  2609. nth_active_pipe = hweight32(intel_state->active_crtcs &
  2610. (drm_crtc_mask(for_crtc) - 1));
  2611. pipe_size = ddb_size / hweight32(intel_state->active_crtcs);
  2612. alloc->start = nth_active_pipe * ddb_size / *num_active;
  2613. alloc->end = alloc->start + pipe_size;
  2614. }
  2615. static unsigned int skl_cursor_allocation(int num_active)
  2616. {
  2617. if (num_active == 1)
  2618. return 32;
  2619. return 8;
  2620. }
  2621. static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg)
  2622. {
  2623. entry->start = reg & 0x3ff;
  2624. entry->end = (reg >> 16) & 0x3ff;
  2625. if (entry->end)
  2626. entry->end += 1;
  2627. }
  2628. void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv,
  2629. struct skl_ddb_allocation *ddb /* out */)
  2630. {
  2631. enum pipe pipe;
  2632. int plane;
  2633. u32 val;
  2634. memset(ddb, 0, sizeof(*ddb));
  2635. for_each_pipe(dev_priv, pipe) {
  2636. enum intel_display_power_domain power_domain;
  2637. power_domain = POWER_DOMAIN_PIPE(pipe);
  2638. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  2639. continue;
  2640. for_each_plane(dev_priv, pipe, plane) {
  2641. val = I915_READ(PLANE_BUF_CFG(pipe, plane));
  2642. skl_ddb_entry_init_from_hw(&ddb->plane[pipe][plane],
  2643. val);
  2644. }
  2645. val = I915_READ(CUR_BUF_CFG(pipe));
  2646. skl_ddb_entry_init_from_hw(&ddb->plane[pipe][PLANE_CURSOR],
  2647. val);
  2648. intel_display_power_put(dev_priv, power_domain);
  2649. }
  2650. }
  2651. /*
  2652. * Determines the downscale amount of a plane for the purposes of watermark calculations.
  2653. * The bspec defines downscale amount as:
  2654. *
  2655. * """
  2656. * Horizontal down scale amount = maximum[1, Horizontal source size /
  2657. * Horizontal destination size]
  2658. * Vertical down scale amount = maximum[1, Vertical source size /
  2659. * Vertical destination size]
  2660. * Total down scale amount = Horizontal down scale amount *
  2661. * Vertical down scale amount
  2662. * """
  2663. *
  2664. * Return value is provided in 16.16 fixed point form to retain fractional part.
  2665. * Caller should take care of dividing & rounding off the value.
  2666. */
  2667. static uint32_t
  2668. skl_plane_downscale_amount(const struct intel_plane_state *pstate)
  2669. {
  2670. uint32_t downscale_h, downscale_w;
  2671. uint32_t src_w, src_h, dst_w, dst_h;
  2672. if (WARN_ON(!pstate->base.visible))
  2673. return DRM_PLANE_HELPER_NO_SCALING;
  2674. /* n.b., src is 16.16 fixed point, dst is whole integer */
  2675. src_w = drm_rect_width(&pstate->base.src);
  2676. src_h = drm_rect_height(&pstate->base.src);
  2677. dst_w = drm_rect_width(&pstate->base.dst);
  2678. dst_h = drm_rect_height(&pstate->base.dst);
  2679. if (intel_rotation_90_or_270(pstate->base.rotation))
  2680. swap(dst_w, dst_h);
  2681. downscale_h = max(src_h / dst_h, (uint32_t)DRM_PLANE_HELPER_NO_SCALING);
  2682. downscale_w = max(src_w / dst_w, (uint32_t)DRM_PLANE_HELPER_NO_SCALING);
  2683. /* Provide result in 16.16 fixed point */
  2684. return (uint64_t)downscale_w * downscale_h >> 16;
  2685. }
  2686. static unsigned int
  2687. skl_plane_relative_data_rate(const struct intel_crtc_state *cstate,
  2688. const struct drm_plane_state *pstate,
  2689. int y)
  2690. {
  2691. struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate);
  2692. struct drm_framebuffer *fb = pstate->fb;
  2693. uint32_t down_scale_amount, data_rate;
  2694. uint32_t width = 0, height = 0;
  2695. unsigned format = fb ? fb->pixel_format : DRM_FORMAT_XRGB8888;
  2696. if (!intel_pstate->base.visible)
  2697. return 0;
  2698. if (pstate->plane->type == DRM_PLANE_TYPE_CURSOR)
  2699. return 0;
  2700. if (y && format != DRM_FORMAT_NV12)
  2701. return 0;
  2702. width = drm_rect_width(&intel_pstate->base.src) >> 16;
  2703. height = drm_rect_height(&intel_pstate->base.src) >> 16;
  2704. if (intel_rotation_90_or_270(pstate->rotation))
  2705. swap(width, height);
  2706. /* for planar format */
  2707. if (format == DRM_FORMAT_NV12) {
  2708. if (y) /* y-plane data rate */
  2709. data_rate = width * height *
  2710. drm_format_plane_cpp(format, 0);
  2711. else /* uv-plane data rate */
  2712. data_rate = (width / 2) * (height / 2) *
  2713. drm_format_plane_cpp(format, 1);
  2714. } else {
  2715. /* for packed formats */
  2716. data_rate = width * height * drm_format_plane_cpp(format, 0);
  2717. }
  2718. down_scale_amount = skl_plane_downscale_amount(intel_pstate);
  2719. return (uint64_t)data_rate * down_scale_amount >> 16;
  2720. }
  2721. /*
  2722. * We don't overflow 32 bits. Worst case is 3 planes enabled, each fetching
  2723. * a 8192x4096@32bpp framebuffer:
  2724. * 3 * 4096 * 8192 * 4 < 2^32
  2725. */
  2726. static unsigned int
  2727. skl_get_total_relative_data_rate(struct intel_crtc_state *intel_cstate)
  2728. {
  2729. struct drm_crtc_state *cstate = &intel_cstate->base;
  2730. struct drm_atomic_state *state = cstate->state;
  2731. struct drm_crtc *crtc = cstate->crtc;
  2732. struct drm_device *dev = crtc->dev;
  2733. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2734. const struct drm_plane *plane;
  2735. const struct intel_plane *intel_plane;
  2736. struct drm_plane_state *pstate;
  2737. unsigned int rate, total_data_rate = 0;
  2738. int id;
  2739. int i;
  2740. if (WARN_ON(!state))
  2741. return 0;
  2742. /* Calculate and cache data rate for each plane */
  2743. for_each_plane_in_state(state, plane, pstate, i) {
  2744. id = skl_wm_plane_id(to_intel_plane(plane));
  2745. intel_plane = to_intel_plane(plane);
  2746. if (intel_plane->pipe != intel_crtc->pipe)
  2747. continue;
  2748. /* packed/uv */
  2749. rate = skl_plane_relative_data_rate(intel_cstate,
  2750. pstate, 0);
  2751. intel_cstate->wm.skl.plane_data_rate[id] = rate;
  2752. /* y-plane */
  2753. rate = skl_plane_relative_data_rate(intel_cstate,
  2754. pstate, 1);
  2755. intel_cstate->wm.skl.plane_y_data_rate[id] = rate;
  2756. }
  2757. /* Calculate CRTC's total data rate from cached values */
  2758. for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
  2759. int id = skl_wm_plane_id(intel_plane);
  2760. /* packed/uv */
  2761. total_data_rate += intel_cstate->wm.skl.plane_data_rate[id];
  2762. total_data_rate += intel_cstate->wm.skl.plane_y_data_rate[id];
  2763. }
  2764. return total_data_rate;
  2765. }
  2766. static uint16_t
  2767. skl_ddb_min_alloc(const struct drm_plane_state *pstate,
  2768. const int y)
  2769. {
  2770. struct drm_framebuffer *fb = pstate->fb;
  2771. struct intel_plane_state *intel_pstate = to_intel_plane_state(pstate);
  2772. uint32_t src_w, src_h;
  2773. uint32_t min_scanlines = 8;
  2774. uint8_t plane_bpp;
  2775. if (WARN_ON(!fb))
  2776. return 0;
  2777. /* For packed formats, no y-plane, return 0 */
  2778. if (y && fb->pixel_format != DRM_FORMAT_NV12)
  2779. return 0;
  2780. /* For Non Y-tile return 8-blocks */
  2781. if (fb->modifier[0] != I915_FORMAT_MOD_Y_TILED &&
  2782. fb->modifier[0] != I915_FORMAT_MOD_Yf_TILED)
  2783. return 8;
  2784. src_w = drm_rect_width(&intel_pstate->base.src) >> 16;
  2785. src_h = drm_rect_height(&intel_pstate->base.src) >> 16;
  2786. if (intel_rotation_90_or_270(pstate->rotation))
  2787. swap(src_w, src_h);
  2788. /* Halve UV plane width and height for NV12 */
  2789. if (fb->pixel_format == DRM_FORMAT_NV12 && !y) {
  2790. src_w /= 2;
  2791. src_h /= 2;
  2792. }
  2793. if (fb->pixel_format == DRM_FORMAT_NV12 && !y)
  2794. plane_bpp = drm_format_plane_cpp(fb->pixel_format, 1);
  2795. else
  2796. plane_bpp = drm_format_plane_cpp(fb->pixel_format, 0);
  2797. if (intel_rotation_90_or_270(pstate->rotation)) {
  2798. switch (plane_bpp) {
  2799. case 1:
  2800. min_scanlines = 32;
  2801. break;
  2802. case 2:
  2803. min_scanlines = 16;
  2804. break;
  2805. case 4:
  2806. min_scanlines = 8;
  2807. break;
  2808. case 8:
  2809. min_scanlines = 4;
  2810. break;
  2811. default:
  2812. WARN(1, "Unsupported pixel depth %u for rotation",
  2813. plane_bpp);
  2814. min_scanlines = 32;
  2815. }
  2816. }
  2817. return DIV_ROUND_UP((4 * src_w * plane_bpp), 512) * min_scanlines/4 + 3;
  2818. }
  2819. static int
  2820. skl_allocate_pipe_ddb(struct intel_crtc_state *cstate,
  2821. struct skl_ddb_allocation *ddb /* out */)
  2822. {
  2823. struct drm_atomic_state *state = cstate->base.state;
  2824. struct drm_crtc *crtc = cstate->base.crtc;
  2825. struct drm_device *dev = crtc->dev;
  2826. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2827. struct intel_plane *intel_plane;
  2828. struct drm_plane *plane;
  2829. struct drm_plane_state *pstate;
  2830. enum pipe pipe = intel_crtc->pipe;
  2831. struct skl_ddb_entry *alloc = &ddb->pipe[pipe];
  2832. uint16_t alloc_size, start, cursor_blocks;
  2833. uint16_t *minimum = cstate->wm.skl.minimum_blocks;
  2834. uint16_t *y_minimum = cstate->wm.skl.minimum_y_blocks;
  2835. unsigned int total_data_rate;
  2836. int num_active;
  2837. int id, i;
  2838. /* Clear the partitioning for disabled planes. */
  2839. memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe]));
  2840. memset(ddb->y_plane[pipe], 0, sizeof(ddb->y_plane[pipe]));
  2841. if (WARN_ON(!state))
  2842. return 0;
  2843. if (!cstate->base.active) {
  2844. ddb->pipe[pipe].start = ddb->pipe[pipe].end = 0;
  2845. return 0;
  2846. }
  2847. skl_ddb_get_pipe_allocation_limits(dev, cstate, alloc, &num_active);
  2848. alloc_size = skl_ddb_entry_size(alloc);
  2849. if (alloc_size == 0) {
  2850. memset(ddb->plane[pipe], 0, sizeof(ddb->plane[pipe]));
  2851. return 0;
  2852. }
  2853. cursor_blocks = skl_cursor_allocation(num_active);
  2854. ddb->plane[pipe][PLANE_CURSOR].start = alloc->end - cursor_blocks;
  2855. ddb->plane[pipe][PLANE_CURSOR].end = alloc->end;
  2856. alloc_size -= cursor_blocks;
  2857. /* 1. Allocate the mininum required blocks for each active plane */
  2858. for_each_plane_in_state(state, plane, pstate, i) {
  2859. intel_plane = to_intel_plane(plane);
  2860. id = skl_wm_plane_id(intel_plane);
  2861. if (intel_plane->pipe != pipe)
  2862. continue;
  2863. if (!to_intel_plane_state(pstate)->base.visible) {
  2864. minimum[id] = 0;
  2865. y_minimum[id] = 0;
  2866. continue;
  2867. }
  2868. if (plane->type == DRM_PLANE_TYPE_CURSOR) {
  2869. minimum[id] = 0;
  2870. y_minimum[id] = 0;
  2871. continue;
  2872. }
  2873. minimum[id] = skl_ddb_min_alloc(pstate, 0);
  2874. y_minimum[id] = skl_ddb_min_alloc(pstate, 1);
  2875. }
  2876. for (i = 0; i < PLANE_CURSOR; i++) {
  2877. alloc_size -= minimum[i];
  2878. alloc_size -= y_minimum[i];
  2879. }
  2880. /*
  2881. * 2. Distribute the remaining space in proportion to the amount of
  2882. * data each plane needs to fetch from memory.
  2883. *
  2884. * FIXME: we may not allocate every single block here.
  2885. */
  2886. total_data_rate = skl_get_total_relative_data_rate(cstate);
  2887. if (total_data_rate == 0)
  2888. return 0;
  2889. start = alloc->start;
  2890. for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
  2891. unsigned int data_rate, y_data_rate;
  2892. uint16_t plane_blocks, y_plane_blocks = 0;
  2893. int id = skl_wm_plane_id(intel_plane);
  2894. data_rate = cstate->wm.skl.plane_data_rate[id];
  2895. /*
  2896. * allocation for (packed formats) or (uv-plane part of planar format):
  2897. * promote the expression to 64 bits to avoid overflowing, the
  2898. * result is < available as data_rate / total_data_rate < 1
  2899. */
  2900. plane_blocks = minimum[id];
  2901. plane_blocks += div_u64((uint64_t)alloc_size * data_rate,
  2902. total_data_rate);
  2903. /* Leave disabled planes at (0,0) */
  2904. if (data_rate) {
  2905. ddb->plane[pipe][id].start = start;
  2906. ddb->plane[pipe][id].end = start + plane_blocks;
  2907. }
  2908. start += plane_blocks;
  2909. /*
  2910. * allocation for y_plane part of planar format:
  2911. */
  2912. y_data_rate = cstate->wm.skl.plane_y_data_rate[id];
  2913. y_plane_blocks = y_minimum[id];
  2914. y_plane_blocks += div_u64((uint64_t)alloc_size * y_data_rate,
  2915. total_data_rate);
  2916. if (y_data_rate) {
  2917. ddb->y_plane[pipe][id].start = start;
  2918. ddb->y_plane[pipe][id].end = start + y_plane_blocks;
  2919. }
  2920. start += y_plane_blocks;
  2921. }
  2922. return 0;
  2923. }
  2924. /*
  2925. * The max latency should be 257 (max the punit can code is 255 and we add 2us
  2926. * for the read latency) and cpp should always be <= 8, so that
  2927. * should allow pixel_rate up to ~2 GHz which seems sufficient since max
  2928. * 2xcdclk is 1350 MHz and the pixel rate should never exceed that.
  2929. */
  2930. static uint32_t skl_wm_method1(uint32_t pixel_rate, uint8_t cpp, uint32_t latency)
  2931. {
  2932. uint32_t wm_intermediate_val, ret;
  2933. if (latency == 0)
  2934. return UINT_MAX;
  2935. wm_intermediate_val = latency * pixel_rate * cpp / 512;
  2936. ret = DIV_ROUND_UP(wm_intermediate_val, 1000);
  2937. return ret;
  2938. }
  2939. static uint32_t skl_wm_method2(uint32_t pixel_rate, uint32_t pipe_htotal,
  2940. uint32_t latency, uint32_t plane_blocks_per_line)
  2941. {
  2942. uint32_t ret;
  2943. uint32_t wm_intermediate_val;
  2944. if (latency == 0)
  2945. return UINT_MAX;
  2946. wm_intermediate_val = latency * pixel_rate;
  2947. ret = DIV_ROUND_UP(wm_intermediate_val, pipe_htotal * 1000) *
  2948. plane_blocks_per_line;
  2949. return ret;
  2950. }
  2951. static uint32_t skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *cstate,
  2952. struct intel_plane_state *pstate)
  2953. {
  2954. uint64_t adjusted_pixel_rate;
  2955. uint64_t downscale_amount;
  2956. uint64_t pixel_rate;
  2957. /* Shouldn't reach here on disabled planes... */
  2958. if (WARN_ON(!pstate->base.visible))
  2959. return 0;
  2960. /*
  2961. * Adjusted plane pixel rate is just the pipe's adjusted pixel rate
  2962. * with additional adjustments for plane-specific scaling.
  2963. */
  2964. adjusted_pixel_rate = ilk_pipe_pixel_rate(cstate);
  2965. downscale_amount = skl_plane_downscale_amount(pstate);
  2966. pixel_rate = adjusted_pixel_rate * downscale_amount >> 16;
  2967. WARN_ON(pixel_rate != clamp_t(uint32_t, pixel_rate, 0, ~0));
  2968. return pixel_rate;
  2969. }
  2970. static int skl_compute_plane_wm(const struct drm_i915_private *dev_priv,
  2971. struct intel_crtc_state *cstate,
  2972. struct intel_plane_state *intel_pstate,
  2973. uint16_t ddb_allocation,
  2974. int level,
  2975. uint16_t *out_blocks, /* out */
  2976. uint8_t *out_lines, /* out */
  2977. bool *enabled /* out */)
  2978. {
  2979. struct drm_plane_state *pstate = &intel_pstate->base;
  2980. struct drm_framebuffer *fb = pstate->fb;
  2981. uint32_t latency = dev_priv->wm.skl_latency[level];
  2982. uint32_t method1, method2;
  2983. uint32_t plane_bytes_per_line, plane_blocks_per_line;
  2984. uint32_t res_blocks, res_lines;
  2985. uint32_t selected_result;
  2986. uint8_t cpp;
  2987. uint32_t width = 0, height = 0;
  2988. uint32_t plane_pixel_rate;
  2989. uint32_t y_tile_minimum, y_min_scanlines;
  2990. struct intel_atomic_state *state =
  2991. to_intel_atomic_state(cstate->base.state);
  2992. bool apply_memory_bw_wa = skl_needs_memory_bw_wa(state);
  2993. if (latency == 0 || !cstate->base.active || !intel_pstate->base.visible) {
  2994. *enabled = false;
  2995. return 0;
  2996. }
  2997. if (apply_memory_bw_wa && fb->modifier[0] == I915_FORMAT_MOD_X_TILED)
  2998. latency += 15;
  2999. width = drm_rect_width(&intel_pstate->base.src) >> 16;
  3000. height = drm_rect_height(&intel_pstate->base.src) >> 16;
  3001. if (intel_rotation_90_or_270(pstate->rotation))
  3002. swap(width, height);
  3003. cpp = drm_format_plane_cpp(fb->pixel_format, 0);
  3004. plane_pixel_rate = skl_adjusted_plane_pixel_rate(cstate, intel_pstate);
  3005. if (intel_rotation_90_or_270(pstate->rotation)) {
  3006. int cpp = (fb->pixel_format == DRM_FORMAT_NV12) ?
  3007. drm_format_plane_cpp(fb->pixel_format, 1) :
  3008. drm_format_plane_cpp(fb->pixel_format, 0);
  3009. switch (cpp) {
  3010. case 1:
  3011. y_min_scanlines = 16;
  3012. break;
  3013. case 2:
  3014. y_min_scanlines = 8;
  3015. break;
  3016. default:
  3017. WARN(1, "Unsupported pixel depth for rotation");
  3018. case 4:
  3019. y_min_scanlines = 4;
  3020. break;
  3021. }
  3022. } else {
  3023. y_min_scanlines = 4;
  3024. }
  3025. if (apply_memory_bw_wa)
  3026. y_min_scanlines *= 2;
  3027. plane_bytes_per_line = width * cpp;
  3028. if (fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
  3029. fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED) {
  3030. plane_blocks_per_line =
  3031. DIV_ROUND_UP(plane_bytes_per_line * y_min_scanlines, 512);
  3032. plane_blocks_per_line /= y_min_scanlines;
  3033. } else if (fb->modifier[0] == DRM_FORMAT_MOD_NONE) {
  3034. plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512)
  3035. + 1;
  3036. } else {
  3037. plane_blocks_per_line = DIV_ROUND_UP(plane_bytes_per_line, 512);
  3038. }
  3039. method1 = skl_wm_method1(plane_pixel_rate, cpp, latency);
  3040. method2 = skl_wm_method2(plane_pixel_rate,
  3041. cstate->base.adjusted_mode.crtc_htotal,
  3042. latency,
  3043. plane_blocks_per_line);
  3044. y_tile_minimum = plane_blocks_per_line * y_min_scanlines;
  3045. if (fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
  3046. fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED) {
  3047. selected_result = max(method2, y_tile_minimum);
  3048. } else {
  3049. if ((ddb_allocation / plane_blocks_per_line) >= 1)
  3050. selected_result = min(method1, method2);
  3051. else
  3052. selected_result = method1;
  3053. }
  3054. res_blocks = selected_result + 1;
  3055. res_lines = DIV_ROUND_UP(selected_result, plane_blocks_per_line);
  3056. if (level >= 1 && level <= 7) {
  3057. if (fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
  3058. fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED) {
  3059. res_blocks += y_tile_minimum;
  3060. res_lines += y_min_scanlines;
  3061. } else {
  3062. res_blocks++;
  3063. }
  3064. }
  3065. if (res_blocks >= ddb_allocation || res_lines > 31) {
  3066. *enabled = false;
  3067. /*
  3068. * If there are no valid level 0 watermarks, then we can't
  3069. * support this display configuration.
  3070. */
  3071. if (level) {
  3072. return 0;
  3073. } else {
  3074. DRM_DEBUG_KMS("Requested display configuration exceeds system watermark limitations\n");
  3075. DRM_DEBUG_KMS("Plane %d.%d: blocks required = %u/%u, lines required = %u/31\n",
  3076. to_intel_crtc(cstate->base.crtc)->pipe,
  3077. skl_wm_plane_id(to_intel_plane(pstate->plane)),
  3078. res_blocks, ddb_allocation, res_lines);
  3079. return -EINVAL;
  3080. }
  3081. }
  3082. *out_blocks = res_blocks;
  3083. *out_lines = res_lines;
  3084. *enabled = true;
  3085. return 0;
  3086. }
  3087. static int
  3088. skl_compute_wm_level(const struct drm_i915_private *dev_priv,
  3089. struct skl_ddb_allocation *ddb,
  3090. struct intel_crtc_state *cstate,
  3091. int level,
  3092. struct skl_wm_level *result)
  3093. {
  3094. struct drm_atomic_state *state = cstate->base.state;
  3095. struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc);
  3096. struct drm_plane *plane;
  3097. struct intel_plane *intel_plane;
  3098. struct intel_plane_state *intel_pstate;
  3099. uint16_t ddb_blocks;
  3100. enum pipe pipe = intel_crtc->pipe;
  3101. int ret;
  3102. /*
  3103. * We'll only calculate watermarks for planes that are actually
  3104. * enabled, so make sure all other planes are set as disabled.
  3105. */
  3106. memset(result, 0, sizeof(*result));
  3107. for_each_intel_plane_mask(&dev_priv->drm,
  3108. intel_plane,
  3109. cstate->base.plane_mask) {
  3110. int i = skl_wm_plane_id(intel_plane);
  3111. plane = &intel_plane->base;
  3112. intel_pstate = NULL;
  3113. if (state)
  3114. intel_pstate =
  3115. intel_atomic_get_existing_plane_state(state,
  3116. intel_plane);
  3117. /*
  3118. * Note: If we start supporting multiple pending atomic commits
  3119. * against the same planes/CRTC's in the future, plane->state
  3120. * will no longer be the correct pre-state to use for the
  3121. * calculations here and we'll need to change where we get the
  3122. * 'unchanged' plane data from.
  3123. *
  3124. * For now this is fine because we only allow one queued commit
  3125. * against a CRTC. Even if the plane isn't modified by this
  3126. * transaction and we don't have a plane lock, we still have
  3127. * the CRTC's lock, so we know that no other transactions are
  3128. * racing with us to update it.
  3129. */
  3130. if (!intel_pstate)
  3131. intel_pstate = to_intel_plane_state(plane->state);
  3132. WARN_ON(!intel_pstate->base.fb);
  3133. ddb_blocks = skl_ddb_entry_size(&ddb->plane[pipe][i]);
  3134. ret = skl_compute_plane_wm(dev_priv,
  3135. cstate,
  3136. intel_pstate,
  3137. ddb_blocks,
  3138. level,
  3139. &result->plane_res_b[i],
  3140. &result->plane_res_l[i],
  3141. &result->plane_en[i]);
  3142. if (ret)
  3143. return ret;
  3144. }
  3145. return 0;
  3146. }
  3147. static uint32_t
  3148. skl_compute_linetime_wm(struct intel_crtc_state *cstate)
  3149. {
  3150. if (!cstate->base.active)
  3151. return 0;
  3152. if (WARN_ON(ilk_pipe_pixel_rate(cstate) == 0))
  3153. return 0;
  3154. return DIV_ROUND_UP(8 * cstate->base.adjusted_mode.crtc_htotal * 1000,
  3155. ilk_pipe_pixel_rate(cstate));
  3156. }
  3157. static void skl_compute_transition_wm(struct intel_crtc_state *cstate,
  3158. struct skl_wm_level *trans_wm /* out */)
  3159. {
  3160. struct drm_crtc *crtc = cstate->base.crtc;
  3161. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3162. struct intel_plane *intel_plane;
  3163. if (!cstate->base.active)
  3164. return;
  3165. /* Until we know more, just disable transition WMs */
  3166. for_each_intel_plane_on_crtc(crtc->dev, intel_crtc, intel_plane) {
  3167. int i = skl_wm_plane_id(intel_plane);
  3168. trans_wm->plane_en[i] = false;
  3169. }
  3170. }
  3171. static int skl_build_pipe_wm(struct intel_crtc_state *cstate,
  3172. struct skl_ddb_allocation *ddb,
  3173. struct skl_pipe_wm *pipe_wm)
  3174. {
  3175. struct drm_device *dev = cstate->base.crtc->dev;
  3176. const struct drm_i915_private *dev_priv = to_i915(dev);
  3177. int level, max_level = ilk_wm_max_level(dev);
  3178. int ret;
  3179. for (level = 0; level <= max_level; level++) {
  3180. ret = skl_compute_wm_level(dev_priv, ddb, cstate,
  3181. level, &pipe_wm->wm[level]);
  3182. if (ret)
  3183. return ret;
  3184. }
  3185. pipe_wm->linetime = skl_compute_linetime_wm(cstate);
  3186. skl_compute_transition_wm(cstate, &pipe_wm->trans_wm);
  3187. return 0;
  3188. }
  3189. static void skl_compute_wm_results(struct drm_device *dev,
  3190. struct skl_pipe_wm *p_wm,
  3191. struct skl_wm_values *r,
  3192. struct intel_crtc *intel_crtc)
  3193. {
  3194. int level, max_level = ilk_wm_max_level(dev);
  3195. enum pipe pipe = intel_crtc->pipe;
  3196. uint32_t temp;
  3197. int i;
  3198. for (level = 0; level <= max_level; level++) {
  3199. for (i = 0; i < intel_num_planes(intel_crtc); i++) {
  3200. temp = 0;
  3201. temp |= p_wm->wm[level].plane_res_l[i] <<
  3202. PLANE_WM_LINES_SHIFT;
  3203. temp |= p_wm->wm[level].plane_res_b[i];
  3204. if (p_wm->wm[level].plane_en[i])
  3205. temp |= PLANE_WM_EN;
  3206. r->plane[pipe][i][level] = temp;
  3207. }
  3208. temp = 0;
  3209. temp |= p_wm->wm[level].plane_res_l[PLANE_CURSOR] << PLANE_WM_LINES_SHIFT;
  3210. temp |= p_wm->wm[level].plane_res_b[PLANE_CURSOR];
  3211. if (p_wm->wm[level].plane_en[PLANE_CURSOR])
  3212. temp |= PLANE_WM_EN;
  3213. r->plane[pipe][PLANE_CURSOR][level] = temp;
  3214. }
  3215. /* transition WMs */
  3216. for (i = 0; i < intel_num_planes(intel_crtc); i++) {
  3217. temp = 0;
  3218. temp |= p_wm->trans_wm.plane_res_l[i] << PLANE_WM_LINES_SHIFT;
  3219. temp |= p_wm->trans_wm.plane_res_b[i];
  3220. if (p_wm->trans_wm.plane_en[i])
  3221. temp |= PLANE_WM_EN;
  3222. r->plane_trans[pipe][i] = temp;
  3223. }
  3224. temp = 0;
  3225. temp |= p_wm->trans_wm.plane_res_l[PLANE_CURSOR] << PLANE_WM_LINES_SHIFT;
  3226. temp |= p_wm->trans_wm.plane_res_b[PLANE_CURSOR];
  3227. if (p_wm->trans_wm.plane_en[PLANE_CURSOR])
  3228. temp |= PLANE_WM_EN;
  3229. r->plane_trans[pipe][PLANE_CURSOR] = temp;
  3230. r->wm_linetime[pipe] = p_wm->linetime;
  3231. }
  3232. static void skl_ddb_entry_write(struct drm_i915_private *dev_priv,
  3233. i915_reg_t reg,
  3234. const struct skl_ddb_entry *entry)
  3235. {
  3236. if (entry->end)
  3237. I915_WRITE(reg, (entry->end - 1) << 16 | entry->start);
  3238. else
  3239. I915_WRITE(reg, 0);
  3240. }
  3241. void skl_write_plane_wm(struct intel_crtc *intel_crtc,
  3242. const struct skl_wm_values *wm,
  3243. int plane)
  3244. {
  3245. struct drm_crtc *crtc = &intel_crtc->base;
  3246. struct drm_device *dev = crtc->dev;
  3247. struct drm_i915_private *dev_priv = to_i915(dev);
  3248. int level, max_level = ilk_wm_max_level(dev);
  3249. enum pipe pipe = intel_crtc->pipe;
  3250. for (level = 0; level <= max_level; level++) {
  3251. I915_WRITE(PLANE_WM(pipe, plane, level),
  3252. wm->plane[pipe][plane][level]);
  3253. }
  3254. I915_WRITE(PLANE_WM_TRANS(pipe, plane), wm->plane_trans[pipe][plane]);
  3255. skl_ddb_entry_write(dev_priv, PLANE_BUF_CFG(pipe, plane),
  3256. &wm->ddb.plane[pipe][plane]);
  3257. skl_ddb_entry_write(dev_priv, PLANE_NV12_BUF_CFG(pipe, plane),
  3258. &wm->ddb.y_plane[pipe][plane]);
  3259. }
  3260. void skl_write_cursor_wm(struct intel_crtc *intel_crtc,
  3261. const struct skl_wm_values *wm)
  3262. {
  3263. struct drm_crtc *crtc = &intel_crtc->base;
  3264. struct drm_device *dev = crtc->dev;
  3265. struct drm_i915_private *dev_priv = to_i915(dev);
  3266. int level, max_level = ilk_wm_max_level(dev);
  3267. enum pipe pipe = intel_crtc->pipe;
  3268. for (level = 0; level <= max_level; level++) {
  3269. I915_WRITE(CUR_WM(pipe, level),
  3270. wm->plane[pipe][PLANE_CURSOR][level]);
  3271. }
  3272. I915_WRITE(CUR_WM_TRANS(pipe), wm->plane_trans[pipe][PLANE_CURSOR]);
  3273. skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe),
  3274. &wm->ddb.plane[pipe][PLANE_CURSOR]);
  3275. }
  3276. bool skl_ddb_allocation_equals(const struct skl_ddb_allocation *old,
  3277. const struct skl_ddb_allocation *new,
  3278. enum pipe pipe)
  3279. {
  3280. return new->pipe[pipe].start == old->pipe[pipe].start &&
  3281. new->pipe[pipe].end == old->pipe[pipe].end;
  3282. }
  3283. static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a,
  3284. const struct skl_ddb_entry *b)
  3285. {
  3286. return a->start < b->end && b->start < a->end;
  3287. }
  3288. bool skl_ddb_allocation_overlaps(struct drm_atomic_state *state,
  3289. const struct skl_ddb_allocation *old,
  3290. const struct skl_ddb_allocation *new,
  3291. enum pipe pipe)
  3292. {
  3293. struct drm_device *dev = state->dev;
  3294. struct intel_crtc *intel_crtc;
  3295. enum pipe otherp;
  3296. for_each_intel_crtc(dev, intel_crtc) {
  3297. otherp = intel_crtc->pipe;
  3298. if (otherp == pipe)
  3299. continue;
  3300. if (skl_ddb_entries_overlap(&new->pipe[pipe],
  3301. &old->pipe[otherp]))
  3302. return true;
  3303. }
  3304. return false;
  3305. }
  3306. static int skl_update_pipe_wm(struct drm_crtc_state *cstate,
  3307. struct skl_ddb_allocation *ddb, /* out */
  3308. struct skl_pipe_wm *pipe_wm, /* out */
  3309. bool *changed /* out */)
  3310. {
  3311. struct intel_crtc *intel_crtc = to_intel_crtc(cstate->crtc);
  3312. struct intel_crtc_state *intel_cstate = to_intel_crtc_state(cstate);
  3313. int ret;
  3314. ret = skl_build_pipe_wm(intel_cstate, ddb, pipe_wm);
  3315. if (ret)
  3316. return ret;
  3317. if (!memcmp(&intel_crtc->wm.active.skl, pipe_wm, sizeof(*pipe_wm)))
  3318. *changed = false;
  3319. else
  3320. *changed = true;
  3321. return 0;
  3322. }
  3323. static uint32_t
  3324. pipes_modified(struct drm_atomic_state *state)
  3325. {
  3326. struct drm_crtc *crtc;
  3327. struct drm_crtc_state *cstate;
  3328. uint32_t i, ret = 0;
  3329. for_each_crtc_in_state(state, crtc, cstate, i)
  3330. ret |= drm_crtc_mask(crtc);
  3331. return ret;
  3332. }
  3333. int
  3334. skl_ddb_add_affected_planes(struct intel_crtc_state *cstate)
  3335. {
  3336. struct drm_atomic_state *state = cstate->base.state;
  3337. struct drm_device *dev = state->dev;
  3338. struct drm_crtc *crtc = cstate->base.crtc;
  3339. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3340. struct drm_i915_private *dev_priv = to_i915(dev);
  3341. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  3342. struct skl_ddb_allocation *new_ddb = &intel_state->wm_results.ddb;
  3343. struct skl_ddb_allocation *cur_ddb = &dev_priv->wm.skl_hw.ddb;
  3344. struct drm_plane_state *plane_state;
  3345. struct drm_plane *plane;
  3346. enum pipe pipe = intel_crtc->pipe;
  3347. int id;
  3348. WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc));
  3349. drm_for_each_plane_mask(plane, dev, crtc->state->plane_mask) {
  3350. id = skl_wm_plane_id(to_intel_plane(plane));
  3351. if (skl_ddb_entry_equal(&cur_ddb->plane[pipe][id],
  3352. &new_ddb->plane[pipe][id]) &&
  3353. skl_ddb_entry_equal(&cur_ddb->y_plane[pipe][id],
  3354. &new_ddb->y_plane[pipe][id]))
  3355. continue;
  3356. plane_state = drm_atomic_get_plane_state(state, plane);
  3357. if (IS_ERR(plane_state))
  3358. return PTR_ERR(plane_state);
  3359. }
  3360. return 0;
  3361. }
  3362. static int
  3363. skl_compute_ddb(struct drm_atomic_state *state)
  3364. {
  3365. struct drm_device *dev = state->dev;
  3366. struct drm_i915_private *dev_priv = to_i915(dev);
  3367. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  3368. struct intel_crtc *intel_crtc;
  3369. struct skl_ddb_allocation *ddb = &intel_state->wm_results.ddb;
  3370. uint32_t realloc_pipes = pipes_modified(state);
  3371. int ret;
  3372. /*
  3373. * If this is our first atomic update following hardware readout,
  3374. * we can't trust the DDB that the BIOS programmed for us. Let's
  3375. * pretend that all pipes switched active status so that we'll
  3376. * ensure a full DDB recompute.
  3377. */
  3378. if (dev_priv->wm.distrust_bios_wm) {
  3379. ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
  3380. state->acquire_ctx);
  3381. if (ret)
  3382. return ret;
  3383. intel_state->active_pipe_changes = ~0;
  3384. /*
  3385. * We usually only initialize intel_state->active_crtcs if we
  3386. * we're doing a modeset; make sure this field is always
  3387. * initialized during the sanitization process that happens
  3388. * on the first commit too.
  3389. */
  3390. if (!intel_state->modeset)
  3391. intel_state->active_crtcs = dev_priv->active_crtcs;
  3392. }
  3393. /*
  3394. * If the modeset changes which CRTC's are active, we need to
  3395. * recompute the DDB allocation for *all* active pipes, even
  3396. * those that weren't otherwise being modified in any way by this
  3397. * atomic commit. Due to the shrinking of the per-pipe allocations
  3398. * when new active CRTC's are added, it's possible for a pipe that
  3399. * we were already using and aren't changing at all here to suddenly
  3400. * become invalid if its DDB needs exceeds its new allocation.
  3401. *
  3402. * Note that if we wind up doing a full DDB recompute, we can't let
  3403. * any other display updates race with this transaction, so we need
  3404. * to grab the lock on *all* CRTC's.
  3405. */
  3406. if (intel_state->active_pipe_changes) {
  3407. realloc_pipes = ~0;
  3408. intel_state->wm_results.dirty_pipes = ~0;
  3409. }
  3410. /*
  3411. * We're not recomputing for the pipes not included in the commit, so
  3412. * make sure we start with the current state.
  3413. */
  3414. memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb));
  3415. for_each_intel_crtc_mask(dev, intel_crtc, realloc_pipes) {
  3416. struct intel_crtc_state *cstate;
  3417. cstate = intel_atomic_get_crtc_state(state, intel_crtc);
  3418. if (IS_ERR(cstate))
  3419. return PTR_ERR(cstate);
  3420. ret = skl_allocate_pipe_ddb(cstate, ddb);
  3421. if (ret)
  3422. return ret;
  3423. ret = skl_ddb_add_affected_planes(cstate);
  3424. if (ret)
  3425. return ret;
  3426. }
  3427. return 0;
  3428. }
  3429. static void
  3430. skl_copy_wm_for_pipe(struct skl_wm_values *dst,
  3431. struct skl_wm_values *src,
  3432. enum pipe pipe)
  3433. {
  3434. dst->wm_linetime[pipe] = src->wm_linetime[pipe];
  3435. memcpy(dst->plane[pipe], src->plane[pipe],
  3436. sizeof(dst->plane[pipe]));
  3437. memcpy(dst->plane_trans[pipe], src->plane_trans[pipe],
  3438. sizeof(dst->plane_trans[pipe]));
  3439. dst->ddb.pipe[pipe] = src->ddb.pipe[pipe];
  3440. memcpy(dst->ddb.y_plane[pipe], src->ddb.y_plane[pipe],
  3441. sizeof(dst->ddb.y_plane[pipe]));
  3442. memcpy(dst->ddb.plane[pipe], src->ddb.plane[pipe],
  3443. sizeof(dst->ddb.plane[pipe]));
  3444. }
  3445. static int
  3446. skl_compute_wm(struct drm_atomic_state *state)
  3447. {
  3448. struct drm_crtc *crtc;
  3449. struct drm_crtc_state *cstate;
  3450. struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
  3451. struct skl_wm_values *results = &intel_state->wm_results;
  3452. struct drm_device *dev = state->dev;
  3453. struct skl_pipe_wm *pipe_wm;
  3454. bool changed = false;
  3455. int ret, i;
  3456. /*
  3457. * When we distrust bios wm we always need to recompute to set the
  3458. * expected DDB allocations for each CRTC.
  3459. */
  3460. if (to_i915(dev)->wm.distrust_bios_wm)
  3461. changed = true;
  3462. /*
  3463. * If this transaction isn't actually touching any CRTC's, don't
  3464. * bother with watermark calculation. Note that if we pass this
  3465. * test, we're guaranteed to hold at least one CRTC state mutex,
  3466. * which means we can safely use values like dev_priv->active_crtcs
  3467. * since any racing commits that want to update them would need to
  3468. * hold _all_ CRTC state mutexes.
  3469. */
  3470. for_each_crtc_in_state(state, crtc, cstate, i)
  3471. changed = true;
  3472. if (!changed)
  3473. return 0;
  3474. /* Clear all dirty flags */
  3475. results->dirty_pipes = 0;
  3476. ret = skl_compute_ddb(state);
  3477. if (ret)
  3478. return ret;
  3479. /*
  3480. * Calculate WM's for all pipes that are part of this transaction.
  3481. * Note that the DDB allocation above may have added more CRTC's that
  3482. * weren't otherwise being modified (and set bits in dirty_pipes) if
  3483. * pipe allocations had to change.
  3484. *
  3485. * FIXME: Now that we're doing this in the atomic check phase, we
  3486. * should allow skl_update_pipe_wm() to return failure in cases where
  3487. * no suitable watermark values can be found.
  3488. */
  3489. for_each_crtc_in_state(state, crtc, cstate, i) {
  3490. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3491. struct intel_crtc_state *intel_cstate =
  3492. to_intel_crtc_state(cstate);
  3493. pipe_wm = &intel_cstate->wm.skl.optimal;
  3494. ret = skl_update_pipe_wm(cstate, &results->ddb, pipe_wm,
  3495. &changed);
  3496. if (ret)
  3497. return ret;
  3498. if (changed)
  3499. results->dirty_pipes |= drm_crtc_mask(crtc);
  3500. if ((results->dirty_pipes & drm_crtc_mask(crtc)) == 0)
  3501. /* This pipe's WM's did not change */
  3502. continue;
  3503. intel_cstate->update_wm_pre = true;
  3504. skl_compute_wm_results(crtc->dev, pipe_wm, results, intel_crtc);
  3505. }
  3506. return 0;
  3507. }
  3508. static void skl_update_wm(struct drm_crtc *crtc)
  3509. {
  3510. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3511. struct drm_device *dev = crtc->dev;
  3512. struct drm_i915_private *dev_priv = to_i915(dev);
  3513. struct skl_wm_values *results = &dev_priv->wm.skl_results;
  3514. struct skl_wm_values *hw_vals = &dev_priv->wm.skl_hw;
  3515. struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state);
  3516. struct skl_pipe_wm *pipe_wm = &cstate->wm.skl.optimal;
  3517. enum pipe pipe = intel_crtc->pipe;
  3518. if ((results->dirty_pipes & drm_crtc_mask(crtc)) == 0)
  3519. return;
  3520. intel_crtc->wm.active.skl = *pipe_wm;
  3521. mutex_lock(&dev_priv->wm.wm_mutex);
  3522. /*
  3523. * If this pipe isn't active already, we're going to be enabling it
  3524. * very soon. Since it's safe to update a pipe's ddb allocation while
  3525. * the pipe's shut off, just do so here. Already active pipes will have
  3526. * their watermarks updated once we update their planes.
  3527. */
  3528. if (crtc->state->active_changed) {
  3529. int plane;
  3530. for (plane = 0; plane < intel_num_planes(intel_crtc); plane++)
  3531. skl_write_plane_wm(intel_crtc, results, plane);
  3532. skl_write_cursor_wm(intel_crtc, results);
  3533. }
  3534. skl_copy_wm_for_pipe(hw_vals, results, pipe);
  3535. mutex_unlock(&dev_priv->wm.wm_mutex);
  3536. }
  3537. static void ilk_compute_wm_config(struct drm_device *dev,
  3538. struct intel_wm_config *config)
  3539. {
  3540. struct intel_crtc *crtc;
  3541. /* Compute the currently _active_ config */
  3542. for_each_intel_crtc(dev, crtc) {
  3543. const struct intel_pipe_wm *wm = &crtc->wm.active.ilk;
  3544. if (!wm->pipe_enabled)
  3545. continue;
  3546. config->sprites_enabled |= wm->sprites_enabled;
  3547. config->sprites_scaled |= wm->sprites_scaled;
  3548. config->num_pipes_active++;
  3549. }
  3550. }
  3551. static void ilk_program_watermarks(struct drm_i915_private *dev_priv)
  3552. {
  3553. struct drm_device *dev = &dev_priv->drm;
  3554. struct intel_pipe_wm lp_wm_1_2 = {}, lp_wm_5_6 = {}, *best_lp_wm;
  3555. struct ilk_wm_maximums max;
  3556. struct intel_wm_config config = {};
  3557. struct ilk_wm_values results = {};
  3558. enum intel_ddb_partitioning partitioning;
  3559. ilk_compute_wm_config(dev, &config);
  3560. ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_1_2, &max);
  3561. ilk_wm_merge(dev, &config, &max, &lp_wm_1_2);
  3562. /* 5/6 split only in single pipe config on IVB+ */
  3563. if (INTEL_INFO(dev)->gen >= 7 &&
  3564. config.num_pipes_active == 1 && config.sprites_enabled) {
  3565. ilk_compute_wm_maximums(dev, 1, &config, INTEL_DDB_PART_5_6, &max);
  3566. ilk_wm_merge(dev, &config, &max, &lp_wm_5_6);
  3567. best_lp_wm = ilk_find_best_result(dev, &lp_wm_1_2, &lp_wm_5_6);
  3568. } else {
  3569. best_lp_wm = &lp_wm_1_2;
  3570. }
  3571. partitioning = (best_lp_wm == &lp_wm_1_2) ?
  3572. INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6;
  3573. ilk_compute_wm_results(dev, best_lp_wm, partitioning, &results);
  3574. ilk_write_wm_values(dev_priv, &results);
  3575. }
  3576. static void ilk_initial_watermarks(struct intel_crtc_state *cstate)
  3577. {
  3578. struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev);
  3579. struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc);
  3580. mutex_lock(&dev_priv->wm.wm_mutex);
  3581. intel_crtc->wm.active.ilk = cstate->wm.ilk.intermediate;
  3582. ilk_program_watermarks(dev_priv);
  3583. mutex_unlock(&dev_priv->wm.wm_mutex);
  3584. }
  3585. static void ilk_optimize_watermarks(struct intel_crtc_state *cstate)
  3586. {
  3587. struct drm_i915_private *dev_priv = to_i915(cstate->base.crtc->dev);
  3588. struct intel_crtc *intel_crtc = to_intel_crtc(cstate->base.crtc);
  3589. mutex_lock(&dev_priv->wm.wm_mutex);
  3590. if (cstate->wm.need_postvbl_update) {
  3591. intel_crtc->wm.active.ilk = cstate->wm.ilk.optimal;
  3592. ilk_program_watermarks(dev_priv);
  3593. }
  3594. mutex_unlock(&dev_priv->wm.wm_mutex);
  3595. }
  3596. static void skl_pipe_wm_active_state(uint32_t val,
  3597. struct skl_pipe_wm *active,
  3598. bool is_transwm,
  3599. bool is_cursor,
  3600. int i,
  3601. int level)
  3602. {
  3603. bool is_enabled = (val & PLANE_WM_EN) != 0;
  3604. if (!is_transwm) {
  3605. if (!is_cursor) {
  3606. active->wm[level].plane_en[i] = is_enabled;
  3607. active->wm[level].plane_res_b[i] =
  3608. val & PLANE_WM_BLOCKS_MASK;
  3609. active->wm[level].plane_res_l[i] =
  3610. (val >> PLANE_WM_LINES_SHIFT) &
  3611. PLANE_WM_LINES_MASK;
  3612. } else {
  3613. active->wm[level].plane_en[PLANE_CURSOR] = is_enabled;
  3614. active->wm[level].plane_res_b[PLANE_CURSOR] =
  3615. val & PLANE_WM_BLOCKS_MASK;
  3616. active->wm[level].plane_res_l[PLANE_CURSOR] =
  3617. (val >> PLANE_WM_LINES_SHIFT) &
  3618. PLANE_WM_LINES_MASK;
  3619. }
  3620. } else {
  3621. if (!is_cursor) {
  3622. active->trans_wm.plane_en[i] = is_enabled;
  3623. active->trans_wm.plane_res_b[i] =
  3624. val & PLANE_WM_BLOCKS_MASK;
  3625. active->trans_wm.plane_res_l[i] =
  3626. (val >> PLANE_WM_LINES_SHIFT) &
  3627. PLANE_WM_LINES_MASK;
  3628. } else {
  3629. active->trans_wm.plane_en[PLANE_CURSOR] = is_enabled;
  3630. active->trans_wm.plane_res_b[PLANE_CURSOR] =
  3631. val & PLANE_WM_BLOCKS_MASK;
  3632. active->trans_wm.plane_res_l[PLANE_CURSOR] =
  3633. (val >> PLANE_WM_LINES_SHIFT) &
  3634. PLANE_WM_LINES_MASK;
  3635. }
  3636. }
  3637. }
  3638. static void skl_pipe_wm_get_hw_state(struct drm_crtc *crtc)
  3639. {
  3640. struct drm_device *dev = crtc->dev;
  3641. struct drm_i915_private *dev_priv = to_i915(dev);
  3642. struct skl_wm_values *hw = &dev_priv->wm.skl_hw;
  3643. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3644. struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state);
  3645. struct skl_pipe_wm *active = &cstate->wm.skl.optimal;
  3646. enum pipe pipe = intel_crtc->pipe;
  3647. int level, i, max_level;
  3648. uint32_t temp;
  3649. max_level = ilk_wm_max_level(dev);
  3650. hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe));
  3651. for (level = 0; level <= max_level; level++) {
  3652. for (i = 0; i < intel_num_planes(intel_crtc); i++)
  3653. hw->plane[pipe][i][level] =
  3654. I915_READ(PLANE_WM(pipe, i, level));
  3655. hw->plane[pipe][PLANE_CURSOR][level] = I915_READ(CUR_WM(pipe, level));
  3656. }
  3657. for (i = 0; i < intel_num_planes(intel_crtc); i++)
  3658. hw->plane_trans[pipe][i] = I915_READ(PLANE_WM_TRANS(pipe, i));
  3659. hw->plane_trans[pipe][PLANE_CURSOR] = I915_READ(CUR_WM_TRANS(pipe));
  3660. if (!intel_crtc->active)
  3661. return;
  3662. hw->dirty_pipes |= drm_crtc_mask(crtc);
  3663. active->linetime = hw->wm_linetime[pipe];
  3664. for (level = 0; level <= max_level; level++) {
  3665. for (i = 0; i < intel_num_planes(intel_crtc); i++) {
  3666. temp = hw->plane[pipe][i][level];
  3667. skl_pipe_wm_active_state(temp, active, false,
  3668. false, i, level);
  3669. }
  3670. temp = hw->plane[pipe][PLANE_CURSOR][level];
  3671. skl_pipe_wm_active_state(temp, active, false, true, i, level);
  3672. }
  3673. for (i = 0; i < intel_num_planes(intel_crtc); i++) {
  3674. temp = hw->plane_trans[pipe][i];
  3675. skl_pipe_wm_active_state(temp, active, true, false, i, 0);
  3676. }
  3677. temp = hw->plane_trans[pipe][PLANE_CURSOR];
  3678. skl_pipe_wm_active_state(temp, active, true, true, i, 0);
  3679. intel_crtc->wm.active.skl = *active;
  3680. }
  3681. void skl_wm_get_hw_state(struct drm_device *dev)
  3682. {
  3683. struct drm_i915_private *dev_priv = to_i915(dev);
  3684. struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb;
  3685. struct drm_crtc *crtc;
  3686. skl_ddb_get_hw_state(dev_priv, ddb);
  3687. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  3688. skl_pipe_wm_get_hw_state(crtc);
  3689. if (dev_priv->active_crtcs) {
  3690. /* Fully recompute DDB on first atomic commit */
  3691. dev_priv->wm.distrust_bios_wm = true;
  3692. } else {
  3693. /* Easy/common case; just sanitize DDB now if everything off */
  3694. memset(ddb, 0, sizeof(*ddb));
  3695. }
  3696. }
  3697. static void ilk_pipe_wm_get_hw_state(struct drm_crtc *crtc)
  3698. {
  3699. struct drm_device *dev = crtc->dev;
  3700. struct drm_i915_private *dev_priv = to_i915(dev);
  3701. struct ilk_wm_values *hw = &dev_priv->wm.hw;
  3702. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3703. struct intel_crtc_state *cstate = to_intel_crtc_state(crtc->state);
  3704. struct intel_pipe_wm *active = &cstate->wm.ilk.optimal;
  3705. enum pipe pipe = intel_crtc->pipe;
  3706. static const i915_reg_t wm0_pipe_reg[] = {
  3707. [PIPE_A] = WM0_PIPEA_ILK,
  3708. [PIPE_B] = WM0_PIPEB_ILK,
  3709. [PIPE_C] = WM0_PIPEC_IVB,
  3710. };
  3711. hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]);
  3712. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  3713. hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe));
  3714. memset(active, 0, sizeof(*active));
  3715. active->pipe_enabled = intel_crtc->active;
  3716. if (active->pipe_enabled) {
  3717. u32 tmp = hw->wm_pipe[pipe];
  3718. /*
  3719. * For active pipes LP0 watermark is marked as
  3720. * enabled, and LP1+ watermaks as disabled since
  3721. * we can't really reverse compute them in case
  3722. * multiple pipes are active.
  3723. */
  3724. active->wm[0].enable = true;
  3725. active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT;
  3726. active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT;
  3727. active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK;
  3728. active->linetime = hw->wm_linetime[pipe];
  3729. } else {
  3730. int level, max_level = ilk_wm_max_level(dev);
  3731. /*
  3732. * For inactive pipes, all watermark levels
  3733. * should be marked as enabled but zeroed,
  3734. * which is what we'd compute them to.
  3735. */
  3736. for (level = 0; level <= max_level; level++)
  3737. active->wm[level].enable = true;
  3738. }
  3739. intel_crtc->wm.active.ilk = *active;
  3740. }
  3741. #define _FW_WM(value, plane) \
  3742. (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT)
  3743. #define _FW_WM_VLV(value, plane) \
  3744. (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT)
  3745. static void vlv_read_wm_values(struct drm_i915_private *dev_priv,
  3746. struct vlv_wm_values *wm)
  3747. {
  3748. enum pipe pipe;
  3749. uint32_t tmp;
  3750. for_each_pipe(dev_priv, pipe) {
  3751. tmp = I915_READ(VLV_DDL(pipe));
  3752. wm->ddl[pipe].primary =
  3753. (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
  3754. wm->ddl[pipe].cursor =
  3755. (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
  3756. wm->ddl[pipe].sprite[0] =
  3757. (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
  3758. wm->ddl[pipe].sprite[1] =
  3759. (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
  3760. }
  3761. tmp = I915_READ(DSPFW1);
  3762. wm->sr.plane = _FW_WM(tmp, SR);
  3763. wm->pipe[PIPE_B].cursor = _FW_WM(tmp, CURSORB);
  3764. wm->pipe[PIPE_B].primary = _FW_WM_VLV(tmp, PLANEB);
  3765. wm->pipe[PIPE_A].primary = _FW_WM_VLV(tmp, PLANEA);
  3766. tmp = I915_READ(DSPFW2);
  3767. wm->pipe[PIPE_A].sprite[1] = _FW_WM_VLV(tmp, SPRITEB);
  3768. wm->pipe[PIPE_A].cursor = _FW_WM(tmp, CURSORA);
  3769. wm->pipe[PIPE_A].sprite[0] = _FW_WM_VLV(tmp, SPRITEA);
  3770. tmp = I915_READ(DSPFW3);
  3771. wm->sr.cursor = _FW_WM(tmp, CURSOR_SR);
  3772. if (IS_CHERRYVIEW(dev_priv)) {
  3773. tmp = I915_READ(DSPFW7_CHV);
  3774. wm->pipe[PIPE_B].sprite[1] = _FW_WM_VLV(tmp, SPRITED);
  3775. wm->pipe[PIPE_B].sprite[0] = _FW_WM_VLV(tmp, SPRITEC);
  3776. tmp = I915_READ(DSPFW8_CHV);
  3777. wm->pipe[PIPE_C].sprite[1] = _FW_WM_VLV(tmp, SPRITEF);
  3778. wm->pipe[PIPE_C].sprite[0] = _FW_WM_VLV(tmp, SPRITEE);
  3779. tmp = I915_READ(DSPFW9_CHV);
  3780. wm->pipe[PIPE_C].primary = _FW_WM_VLV(tmp, PLANEC);
  3781. wm->pipe[PIPE_C].cursor = _FW_WM(tmp, CURSORC);
  3782. tmp = I915_READ(DSPHOWM);
  3783. wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9;
  3784. wm->pipe[PIPE_C].sprite[1] |= _FW_WM(tmp, SPRITEF_HI) << 8;
  3785. wm->pipe[PIPE_C].sprite[0] |= _FW_WM(tmp, SPRITEE_HI) << 8;
  3786. wm->pipe[PIPE_C].primary |= _FW_WM(tmp, PLANEC_HI) << 8;
  3787. wm->pipe[PIPE_B].sprite[1] |= _FW_WM(tmp, SPRITED_HI) << 8;
  3788. wm->pipe[PIPE_B].sprite[0] |= _FW_WM(tmp, SPRITEC_HI) << 8;
  3789. wm->pipe[PIPE_B].primary |= _FW_WM(tmp, PLANEB_HI) << 8;
  3790. wm->pipe[PIPE_A].sprite[1] |= _FW_WM(tmp, SPRITEB_HI) << 8;
  3791. wm->pipe[PIPE_A].sprite[0] |= _FW_WM(tmp, SPRITEA_HI) << 8;
  3792. wm->pipe[PIPE_A].primary |= _FW_WM(tmp, PLANEA_HI) << 8;
  3793. } else {
  3794. tmp = I915_READ(DSPFW7);
  3795. wm->pipe[PIPE_B].sprite[1] = _FW_WM_VLV(tmp, SPRITED);
  3796. wm->pipe[PIPE_B].sprite[0] = _FW_WM_VLV(tmp, SPRITEC);
  3797. tmp = I915_READ(DSPHOWM);
  3798. wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9;
  3799. wm->pipe[PIPE_B].sprite[1] |= _FW_WM(tmp, SPRITED_HI) << 8;
  3800. wm->pipe[PIPE_B].sprite[0] |= _FW_WM(tmp, SPRITEC_HI) << 8;
  3801. wm->pipe[PIPE_B].primary |= _FW_WM(tmp, PLANEB_HI) << 8;
  3802. wm->pipe[PIPE_A].sprite[1] |= _FW_WM(tmp, SPRITEB_HI) << 8;
  3803. wm->pipe[PIPE_A].sprite[0] |= _FW_WM(tmp, SPRITEA_HI) << 8;
  3804. wm->pipe[PIPE_A].primary |= _FW_WM(tmp, PLANEA_HI) << 8;
  3805. }
  3806. }
  3807. #undef _FW_WM
  3808. #undef _FW_WM_VLV
  3809. void vlv_wm_get_hw_state(struct drm_device *dev)
  3810. {
  3811. struct drm_i915_private *dev_priv = to_i915(dev);
  3812. struct vlv_wm_values *wm = &dev_priv->wm.vlv;
  3813. struct intel_plane *plane;
  3814. enum pipe pipe;
  3815. u32 val;
  3816. vlv_read_wm_values(dev_priv, wm);
  3817. for_each_intel_plane(dev, plane) {
  3818. switch (plane->base.type) {
  3819. int sprite;
  3820. case DRM_PLANE_TYPE_CURSOR:
  3821. plane->wm.fifo_size = 63;
  3822. break;
  3823. case DRM_PLANE_TYPE_PRIMARY:
  3824. plane->wm.fifo_size = vlv_get_fifo_size(dev, plane->pipe, 0);
  3825. break;
  3826. case DRM_PLANE_TYPE_OVERLAY:
  3827. sprite = plane->plane;
  3828. plane->wm.fifo_size = vlv_get_fifo_size(dev, plane->pipe, sprite + 1);
  3829. break;
  3830. }
  3831. }
  3832. wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
  3833. wm->level = VLV_WM_LEVEL_PM2;
  3834. if (IS_CHERRYVIEW(dev_priv)) {
  3835. mutex_lock(&dev_priv->rps.hw_lock);
  3836. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3837. if (val & DSP_MAXFIFO_PM5_ENABLE)
  3838. wm->level = VLV_WM_LEVEL_PM5;
  3839. /*
  3840. * If DDR DVFS is disabled in the BIOS, Punit
  3841. * will never ack the request. So if that happens
  3842. * assume we don't have to enable/disable DDR DVFS
  3843. * dynamically. To test that just set the REQ_ACK
  3844. * bit to poke the Punit, but don't change the
  3845. * HIGH/LOW bits so that we don't actually change
  3846. * the current state.
  3847. */
  3848. val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
  3849. val |= FORCE_DDR_FREQ_REQ_ACK;
  3850. vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val);
  3851. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) &
  3852. FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) {
  3853. DRM_DEBUG_KMS("Punit not acking DDR DVFS request, "
  3854. "assuming DDR DVFS is disabled\n");
  3855. dev_priv->wm.max_level = VLV_WM_LEVEL_PM5;
  3856. } else {
  3857. val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
  3858. if ((val & FORCE_DDR_HIGH_FREQ) == 0)
  3859. wm->level = VLV_WM_LEVEL_DDR_DVFS;
  3860. }
  3861. mutex_unlock(&dev_priv->rps.hw_lock);
  3862. }
  3863. for_each_pipe(dev_priv, pipe)
  3864. DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n",
  3865. pipe_name(pipe), wm->pipe[pipe].primary, wm->pipe[pipe].cursor,
  3866. wm->pipe[pipe].sprite[0], wm->pipe[pipe].sprite[1]);
  3867. DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n",
  3868. wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr);
  3869. }
  3870. void ilk_wm_get_hw_state(struct drm_device *dev)
  3871. {
  3872. struct drm_i915_private *dev_priv = to_i915(dev);
  3873. struct ilk_wm_values *hw = &dev_priv->wm.hw;
  3874. struct drm_crtc *crtc;
  3875. for_each_crtc(dev, crtc)
  3876. ilk_pipe_wm_get_hw_state(crtc);
  3877. hw->wm_lp[0] = I915_READ(WM1_LP_ILK);
  3878. hw->wm_lp[1] = I915_READ(WM2_LP_ILK);
  3879. hw->wm_lp[2] = I915_READ(WM3_LP_ILK);
  3880. hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK);
  3881. if (INTEL_INFO(dev)->gen >= 7) {
  3882. hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB);
  3883. hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB);
  3884. }
  3885. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  3886. hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ?
  3887. INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
  3888. else if (IS_IVYBRIDGE(dev))
  3889. hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ?
  3890. INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
  3891. hw->enable_fbc_wm =
  3892. !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS);
  3893. }
  3894. /**
  3895. * intel_update_watermarks - update FIFO watermark values based on current modes
  3896. *
  3897. * Calculate watermark values for the various WM regs based on current mode
  3898. * and plane configuration.
  3899. *
  3900. * There are several cases to deal with here:
  3901. * - normal (i.e. non-self-refresh)
  3902. * - self-refresh (SR) mode
  3903. * - lines are large relative to FIFO size (buffer can hold up to 2)
  3904. * - lines are small relative to FIFO size (buffer can hold more than 2
  3905. * lines), so need to account for TLB latency
  3906. *
  3907. * The normal calculation is:
  3908. * watermark = dotclock * bytes per pixel * latency
  3909. * where latency is platform & configuration dependent (we assume pessimal
  3910. * values here).
  3911. *
  3912. * The SR calculation is:
  3913. * watermark = (trunc(latency/line time)+1) * surface width *
  3914. * bytes per pixel
  3915. * where
  3916. * line time = htotal / dotclock
  3917. * surface width = hdisplay for normal plane and 64 for cursor
  3918. * and latency is assumed to be high, as above.
  3919. *
  3920. * The final value programmed to the register should always be rounded up,
  3921. * and include an extra 2 entries to account for clock crossings.
  3922. *
  3923. * We don't use the sprite, so we can ignore that. And on Crestline we have
  3924. * to set the non-SR watermarks to 8.
  3925. */
  3926. void intel_update_watermarks(struct drm_crtc *crtc)
  3927. {
  3928. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  3929. if (dev_priv->display.update_wm)
  3930. dev_priv->display.update_wm(crtc);
  3931. }
  3932. /*
  3933. * Lock protecting IPS related data structures
  3934. */
  3935. DEFINE_SPINLOCK(mchdev_lock);
  3936. /* Global for IPS driver to get at the current i915 device. Protected by
  3937. * mchdev_lock. */
  3938. static struct drm_i915_private *i915_mch_dev;
  3939. bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val)
  3940. {
  3941. u16 rgvswctl;
  3942. assert_spin_locked(&mchdev_lock);
  3943. rgvswctl = I915_READ16(MEMSWCTL);
  3944. if (rgvswctl & MEMCTL_CMD_STS) {
  3945. DRM_DEBUG("gpu busy, RCS change rejected\n");
  3946. return false; /* still busy with another command */
  3947. }
  3948. rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
  3949. (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM;
  3950. I915_WRITE16(MEMSWCTL, rgvswctl);
  3951. POSTING_READ16(MEMSWCTL);
  3952. rgvswctl |= MEMCTL_CMD_STS;
  3953. I915_WRITE16(MEMSWCTL, rgvswctl);
  3954. return true;
  3955. }
  3956. static void ironlake_enable_drps(struct drm_i915_private *dev_priv)
  3957. {
  3958. u32 rgvmodectl;
  3959. u8 fmax, fmin, fstart, vstart;
  3960. spin_lock_irq(&mchdev_lock);
  3961. rgvmodectl = I915_READ(MEMMODECTL);
  3962. /* Enable temp reporting */
  3963. I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN);
  3964. I915_WRITE16(TSC1, I915_READ(TSC1) | TSE);
  3965. /* 100ms RC evaluation intervals */
  3966. I915_WRITE(RCUPEI, 100000);
  3967. I915_WRITE(RCDNEI, 100000);
  3968. /* Set max/min thresholds to 90ms and 80ms respectively */
  3969. I915_WRITE(RCBMAXAVG, 90000);
  3970. I915_WRITE(RCBMINAVG, 80000);
  3971. I915_WRITE(MEMIHYST, 1);
  3972. /* Set up min, max, and cur for interrupt handling */
  3973. fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT;
  3974. fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
  3975. fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
  3976. MEMMODE_FSTART_SHIFT;
  3977. vstart = (I915_READ(PXVFREQ(fstart)) & PXVFREQ_PX_MASK) >>
  3978. PXVFREQ_PX_SHIFT;
  3979. dev_priv->ips.fmax = fmax; /* IPS callback will increase this */
  3980. dev_priv->ips.fstart = fstart;
  3981. dev_priv->ips.max_delay = fstart;
  3982. dev_priv->ips.min_delay = fmin;
  3983. dev_priv->ips.cur_delay = fstart;
  3984. DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
  3985. fmax, fmin, fstart);
  3986. I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
  3987. /*
  3988. * Interrupts will be enabled in ironlake_irq_postinstall
  3989. */
  3990. I915_WRITE(VIDSTART, vstart);
  3991. POSTING_READ(VIDSTART);
  3992. rgvmodectl |= MEMMODE_SWMODE_EN;
  3993. I915_WRITE(MEMMODECTL, rgvmodectl);
  3994. if (wait_for_atomic((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10))
  3995. DRM_ERROR("stuck trying to change perf mode\n");
  3996. mdelay(1);
  3997. ironlake_set_drps(dev_priv, fstart);
  3998. dev_priv->ips.last_count1 = I915_READ(DMIEC) +
  3999. I915_READ(DDREC) + I915_READ(CSIEC);
  4000. dev_priv->ips.last_time1 = jiffies_to_msecs(jiffies);
  4001. dev_priv->ips.last_count2 = I915_READ(GFXEC);
  4002. dev_priv->ips.last_time2 = ktime_get_raw_ns();
  4003. spin_unlock_irq(&mchdev_lock);
  4004. }
  4005. static void ironlake_disable_drps(struct drm_i915_private *dev_priv)
  4006. {
  4007. u16 rgvswctl;
  4008. spin_lock_irq(&mchdev_lock);
  4009. rgvswctl = I915_READ16(MEMSWCTL);
  4010. /* Ack interrupts, disable EFC interrupt */
  4011. I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN);
  4012. I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG);
  4013. I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT);
  4014. I915_WRITE(DEIIR, DE_PCU_EVENT);
  4015. I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT);
  4016. /* Go back to the starting frequency */
  4017. ironlake_set_drps(dev_priv, dev_priv->ips.fstart);
  4018. mdelay(1);
  4019. rgvswctl |= MEMCTL_CMD_STS;
  4020. I915_WRITE(MEMSWCTL, rgvswctl);
  4021. mdelay(1);
  4022. spin_unlock_irq(&mchdev_lock);
  4023. }
  4024. /* There's a funny hw issue where the hw returns all 0 when reading from
  4025. * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value
  4026. * ourselves, instead of doing a rmw cycle (which might result in us clearing
  4027. * all limits and the gpu stuck at whatever frequency it is at atm).
  4028. */
  4029. static u32 intel_rps_limits(struct drm_i915_private *dev_priv, u8 val)
  4030. {
  4031. u32 limits;
  4032. /* Only set the down limit when we've reached the lowest level to avoid
  4033. * getting more interrupts, otherwise leave this clear. This prevents a
  4034. * race in the hw when coming out of rc6: There's a tiny window where
  4035. * the hw runs at the minimal clock before selecting the desired
  4036. * frequency, if the down threshold expires in that window we will not
  4037. * receive a down interrupt. */
  4038. if (IS_GEN9(dev_priv)) {
  4039. limits = (dev_priv->rps.max_freq_softlimit) << 23;
  4040. if (val <= dev_priv->rps.min_freq_softlimit)
  4041. limits |= (dev_priv->rps.min_freq_softlimit) << 14;
  4042. } else {
  4043. limits = dev_priv->rps.max_freq_softlimit << 24;
  4044. if (val <= dev_priv->rps.min_freq_softlimit)
  4045. limits |= dev_priv->rps.min_freq_softlimit << 16;
  4046. }
  4047. return limits;
  4048. }
  4049. static void gen6_set_rps_thresholds(struct drm_i915_private *dev_priv, u8 val)
  4050. {
  4051. int new_power;
  4052. u32 threshold_up = 0, threshold_down = 0; /* in % */
  4053. u32 ei_up = 0, ei_down = 0;
  4054. new_power = dev_priv->rps.power;
  4055. switch (dev_priv->rps.power) {
  4056. case LOW_POWER:
  4057. if (val > dev_priv->rps.efficient_freq + 1 &&
  4058. val > dev_priv->rps.cur_freq)
  4059. new_power = BETWEEN;
  4060. break;
  4061. case BETWEEN:
  4062. if (val <= dev_priv->rps.efficient_freq &&
  4063. val < dev_priv->rps.cur_freq)
  4064. new_power = LOW_POWER;
  4065. else if (val >= dev_priv->rps.rp0_freq &&
  4066. val > dev_priv->rps.cur_freq)
  4067. new_power = HIGH_POWER;
  4068. break;
  4069. case HIGH_POWER:
  4070. if (val < (dev_priv->rps.rp1_freq + dev_priv->rps.rp0_freq) >> 1 &&
  4071. val < dev_priv->rps.cur_freq)
  4072. new_power = BETWEEN;
  4073. break;
  4074. }
  4075. /* Max/min bins are special */
  4076. if (val <= dev_priv->rps.min_freq_softlimit)
  4077. new_power = LOW_POWER;
  4078. if (val >= dev_priv->rps.max_freq_softlimit)
  4079. new_power = HIGH_POWER;
  4080. if (new_power == dev_priv->rps.power)
  4081. return;
  4082. /* Note the units here are not exactly 1us, but 1280ns. */
  4083. switch (new_power) {
  4084. case LOW_POWER:
  4085. /* Upclock if more than 95% busy over 16ms */
  4086. ei_up = 16000;
  4087. threshold_up = 95;
  4088. /* Downclock if less than 85% busy over 32ms */
  4089. ei_down = 32000;
  4090. threshold_down = 85;
  4091. break;
  4092. case BETWEEN:
  4093. /* Upclock if more than 90% busy over 13ms */
  4094. ei_up = 13000;
  4095. threshold_up = 90;
  4096. /* Downclock if less than 75% busy over 32ms */
  4097. ei_down = 32000;
  4098. threshold_down = 75;
  4099. break;
  4100. case HIGH_POWER:
  4101. /* Upclock if more than 85% busy over 10ms */
  4102. ei_up = 10000;
  4103. threshold_up = 85;
  4104. /* Downclock if less than 60% busy over 32ms */
  4105. ei_down = 32000;
  4106. threshold_down = 60;
  4107. break;
  4108. }
  4109. /* When byt can survive without system hang with dynamic
  4110. * sw freq adjustments, this restriction can be lifted.
  4111. */
  4112. if (IS_VALLEYVIEW(dev_priv))
  4113. goto skip_hw_write;
  4114. I915_WRITE(GEN6_RP_UP_EI,
  4115. GT_INTERVAL_FROM_US(dev_priv, ei_up));
  4116. I915_WRITE(GEN6_RP_UP_THRESHOLD,
  4117. GT_INTERVAL_FROM_US(dev_priv,
  4118. ei_up * threshold_up / 100));
  4119. I915_WRITE(GEN6_RP_DOWN_EI,
  4120. GT_INTERVAL_FROM_US(dev_priv, ei_down));
  4121. I915_WRITE(GEN6_RP_DOWN_THRESHOLD,
  4122. GT_INTERVAL_FROM_US(dev_priv,
  4123. ei_down * threshold_down / 100));
  4124. I915_WRITE(GEN6_RP_CONTROL,
  4125. GEN6_RP_MEDIA_TURBO |
  4126. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  4127. GEN6_RP_MEDIA_IS_GFX |
  4128. GEN6_RP_ENABLE |
  4129. GEN6_RP_UP_BUSY_AVG |
  4130. GEN6_RP_DOWN_IDLE_AVG);
  4131. skip_hw_write:
  4132. dev_priv->rps.power = new_power;
  4133. dev_priv->rps.up_threshold = threshold_up;
  4134. dev_priv->rps.down_threshold = threshold_down;
  4135. dev_priv->rps.last_adj = 0;
  4136. }
  4137. static u32 gen6_rps_pm_mask(struct drm_i915_private *dev_priv, u8 val)
  4138. {
  4139. u32 mask = 0;
  4140. /* We use UP_EI_EXPIRED interupts for both up/down in manual mode */
  4141. if (val > dev_priv->rps.min_freq_softlimit)
  4142. mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT;
  4143. if (val < dev_priv->rps.max_freq_softlimit)
  4144. mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD;
  4145. mask &= dev_priv->pm_rps_events;
  4146. return gen6_sanitize_rps_pm_mask(dev_priv, ~mask);
  4147. }
  4148. /* gen6_set_rps is called to update the frequency request, but should also be
  4149. * called when the range (min_delay and max_delay) is modified so that we can
  4150. * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */
  4151. static void gen6_set_rps(struct drm_i915_private *dev_priv, u8 val)
  4152. {
  4153. /* WaGsvDisableTurbo: Workaround to disable turbo on BXT A* */
  4154. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1))
  4155. return;
  4156. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  4157. WARN_ON(val > dev_priv->rps.max_freq);
  4158. WARN_ON(val < dev_priv->rps.min_freq);
  4159. /* min/max delay may still have been modified so be sure to
  4160. * write the limits value.
  4161. */
  4162. if (val != dev_priv->rps.cur_freq) {
  4163. gen6_set_rps_thresholds(dev_priv, val);
  4164. if (IS_GEN9(dev_priv))
  4165. I915_WRITE(GEN6_RPNSWREQ,
  4166. GEN9_FREQUENCY(val));
  4167. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  4168. I915_WRITE(GEN6_RPNSWREQ,
  4169. HSW_FREQUENCY(val));
  4170. else
  4171. I915_WRITE(GEN6_RPNSWREQ,
  4172. GEN6_FREQUENCY(val) |
  4173. GEN6_OFFSET(0) |
  4174. GEN6_AGGRESSIVE_TURBO);
  4175. }
  4176. /* Make sure we continue to get interrupts
  4177. * until we hit the minimum or maximum frequencies.
  4178. */
  4179. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS, intel_rps_limits(dev_priv, val));
  4180. I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val));
  4181. POSTING_READ(GEN6_RPNSWREQ);
  4182. dev_priv->rps.cur_freq = val;
  4183. trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val));
  4184. }
  4185. static void valleyview_set_rps(struct drm_i915_private *dev_priv, u8 val)
  4186. {
  4187. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  4188. WARN_ON(val > dev_priv->rps.max_freq);
  4189. WARN_ON(val < dev_priv->rps.min_freq);
  4190. if (WARN_ONCE(IS_CHERRYVIEW(dev_priv) && (val & 1),
  4191. "Odd GPU freq value\n"))
  4192. val &= ~1;
  4193. I915_WRITE(GEN6_PMINTRMSK, gen6_rps_pm_mask(dev_priv, val));
  4194. if (val != dev_priv->rps.cur_freq) {
  4195. vlv_punit_write(dev_priv, PUNIT_REG_GPU_FREQ_REQ, val);
  4196. if (!IS_CHERRYVIEW(dev_priv))
  4197. gen6_set_rps_thresholds(dev_priv, val);
  4198. }
  4199. dev_priv->rps.cur_freq = val;
  4200. trace_intel_gpu_freq_change(intel_gpu_freq(dev_priv, val));
  4201. }
  4202. /* vlv_set_rps_idle: Set the frequency to idle, if Gfx clocks are down
  4203. *
  4204. * * If Gfx is Idle, then
  4205. * 1. Forcewake Media well.
  4206. * 2. Request idle freq.
  4207. * 3. Release Forcewake of Media well.
  4208. */
  4209. static void vlv_set_rps_idle(struct drm_i915_private *dev_priv)
  4210. {
  4211. u32 val = dev_priv->rps.idle_freq;
  4212. if (dev_priv->rps.cur_freq <= val)
  4213. return;
  4214. /* Wake up the media well, as that takes a lot less
  4215. * power than the Render well. */
  4216. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_MEDIA);
  4217. valleyview_set_rps(dev_priv, val);
  4218. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_MEDIA);
  4219. }
  4220. void gen6_rps_busy(struct drm_i915_private *dev_priv)
  4221. {
  4222. mutex_lock(&dev_priv->rps.hw_lock);
  4223. if (dev_priv->rps.enabled) {
  4224. if (dev_priv->pm_rps_events & GEN6_PM_RP_UP_EI_EXPIRED)
  4225. gen6_rps_reset_ei(dev_priv);
  4226. I915_WRITE(GEN6_PMINTRMSK,
  4227. gen6_rps_pm_mask(dev_priv, dev_priv->rps.cur_freq));
  4228. gen6_enable_rps_interrupts(dev_priv);
  4229. /* Ensure we start at the user's desired frequency */
  4230. intel_set_rps(dev_priv,
  4231. clamp(dev_priv->rps.cur_freq,
  4232. dev_priv->rps.min_freq_softlimit,
  4233. dev_priv->rps.max_freq_softlimit));
  4234. }
  4235. mutex_unlock(&dev_priv->rps.hw_lock);
  4236. }
  4237. void gen6_rps_idle(struct drm_i915_private *dev_priv)
  4238. {
  4239. /* Flush our bottom-half so that it does not race with us
  4240. * setting the idle frequency and so that it is bounded by
  4241. * our rpm wakeref. And then disable the interrupts to stop any
  4242. * futher RPS reclocking whilst we are asleep.
  4243. */
  4244. gen6_disable_rps_interrupts(dev_priv);
  4245. mutex_lock(&dev_priv->rps.hw_lock);
  4246. if (dev_priv->rps.enabled) {
  4247. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  4248. vlv_set_rps_idle(dev_priv);
  4249. else
  4250. gen6_set_rps(dev_priv, dev_priv->rps.idle_freq);
  4251. dev_priv->rps.last_adj = 0;
  4252. I915_WRITE(GEN6_PMINTRMSK,
  4253. gen6_sanitize_rps_pm_mask(dev_priv, ~0));
  4254. }
  4255. mutex_unlock(&dev_priv->rps.hw_lock);
  4256. spin_lock(&dev_priv->rps.client_lock);
  4257. while (!list_empty(&dev_priv->rps.clients))
  4258. list_del_init(dev_priv->rps.clients.next);
  4259. spin_unlock(&dev_priv->rps.client_lock);
  4260. }
  4261. void gen6_rps_boost(struct drm_i915_private *dev_priv,
  4262. struct intel_rps_client *rps,
  4263. unsigned long submitted)
  4264. {
  4265. /* This is intentionally racy! We peek at the state here, then
  4266. * validate inside the RPS worker.
  4267. */
  4268. if (!(dev_priv->gt.awake &&
  4269. dev_priv->rps.enabled &&
  4270. dev_priv->rps.cur_freq < dev_priv->rps.boost_freq))
  4271. return;
  4272. /* Force a RPS boost (and don't count it against the client) if
  4273. * the GPU is severely congested.
  4274. */
  4275. if (rps && time_after(jiffies, submitted + DRM_I915_THROTTLE_JIFFIES))
  4276. rps = NULL;
  4277. spin_lock(&dev_priv->rps.client_lock);
  4278. if (rps == NULL || list_empty(&rps->link)) {
  4279. spin_lock_irq(&dev_priv->irq_lock);
  4280. if (dev_priv->rps.interrupts_enabled) {
  4281. dev_priv->rps.client_boost = true;
  4282. schedule_work(&dev_priv->rps.work);
  4283. }
  4284. spin_unlock_irq(&dev_priv->irq_lock);
  4285. if (rps != NULL) {
  4286. list_add(&rps->link, &dev_priv->rps.clients);
  4287. rps->boosts++;
  4288. } else
  4289. dev_priv->rps.boosts++;
  4290. }
  4291. spin_unlock(&dev_priv->rps.client_lock);
  4292. }
  4293. void intel_set_rps(struct drm_i915_private *dev_priv, u8 val)
  4294. {
  4295. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  4296. valleyview_set_rps(dev_priv, val);
  4297. else
  4298. gen6_set_rps(dev_priv, val);
  4299. }
  4300. static void gen9_disable_rc6(struct drm_i915_private *dev_priv)
  4301. {
  4302. I915_WRITE(GEN6_RC_CONTROL, 0);
  4303. I915_WRITE(GEN9_PG_ENABLE, 0);
  4304. }
  4305. static void gen9_disable_rps(struct drm_i915_private *dev_priv)
  4306. {
  4307. I915_WRITE(GEN6_RP_CONTROL, 0);
  4308. }
  4309. static void gen6_disable_rps(struct drm_i915_private *dev_priv)
  4310. {
  4311. I915_WRITE(GEN6_RC_CONTROL, 0);
  4312. I915_WRITE(GEN6_RPNSWREQ, 1 << 31);
  4313. I915_WRITE(GEN6_RP_CONTROL, 0);
  4314. }
  4315. static void cherryview_disable_rps(struct drm_i915_private *dev_priv)
  4316. {
  4317. I915_WRITE(GEN6_RC_CONTROL, 0);
  4318. }
  4319. static void valleyview_disable_rps(struct drm_i915_private *dev_priv)
  4320. {
  4321. /* we're doing forcewake before Disabling RC6,
  4322. * This what the BIOS expects when going into suspend */
  4323. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  4324. I915_WRITE(GEN6_RC_CONTROL, 0);
  4325. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  4326. }
  4327. static void intel_print_rc6_info(struct drm_i915_private *dev_priv, u32 mode)
  4328. {
  4329. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  4330. if (mode & (GEN7_RC_CTL_TO_MODE | GEN6_RC_CTL_EI_MODE(1)))
  4331. mode = GEN6_RC_CTL_RC6_ENABLE;
  4332. else
  4333. mode = 0;
  4334. }
  4335. if (HAS_RC6p(dev_priv))
  4336. DRM_DEBUG_DRIVER("Enabling RC6 states: "
  4337. "RC6 %s RC6p %s RC6pp %s\n",
  4338. onoff(mode & GEN6_RC_CTL_RC6_ENABLE),
  4339. onoff(mode & GEN6_RC_CTL_RC6p_ENABLE),
  4340. onoff(mode & GEN6_RC_CTL_RC6pp_ENABLE));
  4341. else
  4342. DRM_DEBUG_DRIVER("Enabling RC6 states: RC6 %s\n",
  4343. onoff(mode & GEN6_RC_CTL_RC6_ENABLE));
  4344. }
  4345. static bool bxt_check_bios_rc6_setup(struct drm_i915_private *dev_priv)
  4346. {
  4347. struct i915_ggtt *ggtt = &dev_priv->ggtt;
  4348. bool enable_rc6 = true;
  4349. unsigned long rc6_ctx_base;
  4350. u32 rc_ctl;
  4351. int rc_sw_target;
  4352. rc_ctl = I915_READ(GEN6_RC_CONTROL);
  4353. rc_sw_target = (I915_READ(GEN6_RC_STATE) & RC_SW_TARGET_STATE_MASK) >>
  4354. RC_SW_TARGET_STATE_SHIFT;
  4355. DRM_DEBUG_DRIVER("BIOS enabled RC states: "
  4356. "HW_CTRL %s HW_RC6 %s SW_TARGET_STATE %x\n",
  4357. onoff(rc_ctl & GEN6_RC_CTL_HW_ENABLE),
  4358. onoff(rc_ctl & GEN6_RC_CTL_RC6_ENABLE),
  4359. rc_sw_target);
  4360. if (!(I915_READ(RC6_LOCATION) & RC6_CTX_IN_DRAM)) {
  4361. DRM_DEBUG_DRIVER("RC6 Base location not set properly.\n");
  4362. enable_rc6 = false;
  4363. }
  4364. /*
  4365. * The exact context size is not known for BXT, so assume a page size
  4366. * for this check.
  4367. */
  4368. rc6_ctx_base = I915_READ(RC6_CTX_BASE) & RC6_CTX_BASE_MASK;
  4369. if (!((rc6_ctx_base >= ggtt->stolen_reserved_base) &&
  4370. (rc6_ctx_base + PAGE_SIZE <= ggtt->stolen_reserved_base +
  4371. ggtt->stolen_reserved_size))) {
  4372. DRM_DEBUG_DRIVER("RC6 Base address not as expected.\n");
  4373. enable_rc6 = false;
  4374. }
  4375. if (!(((I915_READ(PWRCTX_MAXCNT_RCSUNIT) & IDLE_TIME_MASK) > 1) &&
  4376. ((I915_READ(PWRCTX_MAXCNT_VCSUNIT0) & IDLE_TIME_MASK) > 1) &&
  4377. ((I915_READ(PWRCTX_MAXCNT_BCSUNIT) & IDLE_TIME_MASK) > 1) &&
  4378. ((I915_READ(PWRCTX_MAXCNT_VECSUNIT) & IDLE_TIME_MASK) > 1))) {
  4379. DRM_DEBUG_DRIVER("Engine Idle wait time not set properly.\n");
  4380. enable_rc6 = false;
  4381. }
  4382. if (!I915_READ(GEN8_PUSHBUS_CONTROL) ||
  4383. !I915_READ(GEN8_PUSHBUS_ENABLE) ||
  4384. !I915_READ(GEN8_PUSHBUS_SHIFT)) {
  4385. DRM_DEBUG_DRIVER("Pushbus not setup properly.\n");
  4386. enable_rc6 = false;
  4387. }
  4388. if (!I915_READ(GEN6_GFXPAUSE)) {
  4389. DRM_DEBUG_DRIVER("GFX pause not setup properly.\n");
  4390. enable_rc6 = false;
  4391. }
  4392. if (!I915_READ(GEN8_MISC_CTRL0)) {
  4393. DRM_DEBUG_DRIVER("GPM control not setup properly.\n");
  4394. enable_rc6 = false;
  4395. }
  4396. return enable_rc6;
  4397. }
  4398. int sanitize_rc6_option(struct drm_i915_private *dev_priv, int enable_rc6)
  4399. {
  4400. /* No RC6 before Ironlake and code is gone for ilk. */
  4401. if (INTEL_INFO(dev_priv)->gen < 6)
  4402. return 0;
  4403. if (!enable_rc6)
  4404. return 0;
  4405. if (IS_BROXTON(dev_priv) && !bxt_check_bios_rc6_setup(dev_priv)) {
  4406. DRM_INFO("RC6 disabled by BIOS\n");
  4407. return 0;
  4408. }
  4409. /* Respect the kernel parameter if it is set */
  4410. if (enable_rc6 >= 0) {
  4411. int mask;
  4412. if (HAS_RC6p(dev_priv))
  4413. mask = INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE |
  4414. INTEL_RC6pp_ENABLE;
  4415. else
  4416. mask = INTEL_RC6_ENABLE;
  4417. if ((enable_rc6 & mask) != enable_rc6)
  4418. DRM_DEBUG_DRIVER("Adjusting RC6 mask to %d "
  4419. "(requested %d, valid %d)\n",
  4420. enable_rc6 & mask, enable_rc6, mask);
  4421. return enable_rc6 & mask;
  4422. }
  4423. if (IS_IVYBRIDGE(dev_priv))
  4424. return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE);
  4425. return INTEL_RC6_ENABLE;
  4426. }
  4427. static void gen6_init_rps_frequencies(struct drm_i915_private *dev_priv)
  4428. {
  4429. /* All of these values are in units of 50MHz */
  4430. /* static values from HW: RP0 > RP1 > RPn (min_freq) */
  4431. if (IS_BROXTON(dev_priv)) {
  4432. u32 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
  4433. dev_priv->rps.rp0_freq = (rp_state_cap >> 16) & 0xff;
  4434. dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff;
  4435. dev_priv->rps.min_freq = (rp_state_cap >> 0) & 0xff;
  4436. } else {
  4437. u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  4438. dev_priv->rps.rp0_freq = (rp_state_cap >> 0) & 0xff;
  4439. dev_priv->rps.rp1_freq = (rp_state_cap >> 8) & 0xff;
  4440. dev_priv->rps.min_freq = (rp_state_cap >> 16) & 0xff;
  4441. }
  4442. /* hw_max = RP0 until we check for overclocking */
  4443. dev_priv->rps.max_freq = dev_priv->rps.rp0_freq;
  4444. dev_priv->rps.efficient_freq = dev_priv->rps.rp1_freq;
  4445. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv) ||
  4446. IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  4447. u32 ddcc_status = 0;
  4448. if (sandybridge_pcode_read(dev_priv,
  4449. HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL,
  4450. &ddcc_status) == 0)
  4451. dev_priv->rps.efficient_freq =
  4452. clamp_t(u8,
  4453. ((ddcc_status >> 8) & 0xff),
  4454. dev_priv->rps.min_freq,
  4455. dev_priv->rps.max_freq);
  4456. }
  4457. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  4458. /* Store the frequency values in 16.66 MHZ units, which is
  4459. * the natural hardware unit for SKL
  4460. */
  4461. dev_priv->rps.rp0_freq *= GEN9_FREQ_SCALER;
  4462. dev_priv->rps.rp1_freq *= GEN9_FREQ_SCALER;
  4463. dev_priv->rps.min_freq *= GEN9_FREQ_SCALER;
  4464. dev_priv->rps.max_freq *= GEN9_FREQ_SCALER;
  4465. dev_priv->rps.efficient_freq *= GEN9_FREQ_SCALER;
  4466. }
  4467. }
  4468. static void reset_rps(struct drm_i915_private *dev_priv,
  4469. void (*set)(struct drm_i915_private *, u8))
  4470. {
  4471. u8 freq = dev_priv->rps.cur_freq;
  4472. /* force a reset */
  4473. dev_priv->rps.power = -1;
  4474. dev_priv->rps.cur_freq = -1;
  4475. set(dev_priv, freq);
  4476. }
  4477. /* See the Gen9_GT_PM_Programming_Guide doc for the below */
  4478. static void gen9_enable_rps(struct drm_i915_private *dev_priv)
  4479. {
  4480. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  4481. /* WaGsvDisableTurbo: Workaround to disable turbo on BXT A* */
  4482. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
  4483. /*
  4484. * BIOS could leave the Hw Turbo enabled, so need to explicitly
  4485. * clear out the Control register just to avoid inconsitency
  4486. * with debugfs interface, which will show Turbo as enabled
  4487. * only and that is not expected by the User after adding the
  4488. * WaGsvDisableTurbo. Apart from this there is no problem even
  4489. * if the Turbo is left enabled in the Control register, as the
  4490. * Up/Down interrupts would remain masked.
  4491. */
  4492. gen9_disable_rps(dev_priv);
  4493. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  4494. return;
  4495. }
  4496. /* Program defaults and thresholds for RPS*/
  4497. I915_WRITE(GEN6_RC_VIDEO_FREQ,
  4498. GEN9_FREQUENCY(dev_priv->rps.rp1_freq));
  4499. /* 1 second timeout*/
  4500. I915_WRITE(GEN6_RP_DOWN_TIMEOUT,
  4501. GT_INTERVAL_FROM_US(dev_priv, 1000000));
  4502. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 0xa);
  4503. /* Leaning on the below call to gen6_set_rps to program/setup the
  4504. * Up/Down EI & threshold registers, as well as the RP_CONTROL,
  4505. * RP_INTERRUPT_LIMITS & RPNSWREQ registers */
  4506. reset_rps(dev_priv, gen6_set_rps);
  4507. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  4508. }
  4509. static void gen9_enable_rc6(struct drm_i915_private *dev_priv)
  4510. {
  4511. struct intel_engine_cs *engine;
  4512. uint32_t rc6_mask = 0;
  4513. /* 1a: Software RC state - RC0 */
  4514. I915_WRITE(GEN6_RC_STATE, 0);
  4515. /* 1b: Get forcewake during program sequence. Although the driver
  4516. * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
  4517. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  4518. /* 2a: Disable RC states. */
  4519. I915_WRITE(GEN6_RC_CONTROL, 0);
  4520. /* 2b: Program RC6 thresholds.*/
  4521. /* WaRsDoubleRc6WrlWithCoarsePowerGating: Doubling WRL only when CPG is enabled */
  4522. if (IS_SKYLAKE(dev_priv))
  4523. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 108 << 16);
  4524. else
  4525. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16);
  4526. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */
  4527. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */
  4528. for_each_engine(engine, dev_priv)
  4529. I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10);
  4530. if (HAS_GUC(dev_priv))
  4531. I915_WRITE(GUC_MAX_IDLE_COUNT, 0xA);
  4532. I915_WRITE(GEN6_RC_SLEEP, 0);
  4533. /* 2c: Program Coarse Power Gating Policies. */
  4534. I915_WRITE(GEN9_MEDIA_PG_IDLE_HYSTERESIS, 25);
  4535. I915_WRITE(GEN9_RENDER_PG_IDLE_HYSTERESIS, 25);
  4536. /* 3a: Enable RC6 */
  4537. if (intel_enable_rc6() & INTEL_RC6_ENABLE)
  4538. rc6_mask = GEN6_RC_CTL_RC6_ENABLE;
  4539. DRM_INFO("RC6 %s\n", onoff(rc6_mask & GEN6_RC_CTL_RC6_ENABLE));
  4540. /* WaRsUseTimeoutMode */
  4541. if (IS_SKL_REVID(dev_priv, 0, SKL_REVID_D0) ||
  4542. IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1)) {
  4543. I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us */
  4544. I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE |
  4545. GEN7_RC_CTL_TO_MODE |
  4546. rc6_mask);
  4547. } else {
  4548. I915_WRITE(GEN6_RC6_THRESHOLD, 37500); /* 37.5/125ms per EI */
  4549. I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE |
  4550. GEN6_RC_CTL_EI_MODE(1) |
  4551. rc6_mask);
  4552. }
  4553. /*
  4554. * 3b: Enable Coarse Power Gating only when RC6 is enabled.
  4555. * WaRsDisableCoarsePowerGating:skl,bxt - Render/Media PG need to be disabled with RC6.
  4556. */
  4557. if (NEEDS_WaRsDisableCoarsePowerGating(dev_priv))
  4558. I915_WRITE(GEN9_PG_ENABLE, 0);
  4559. else
  4560. I915_WRITE(GEN9_PG_ENABLE, (rc6_mask & GEN6_RC_CTL_RC6_ENABLE) ?
  4561. (GEN9_RENDER_PG_ENABLE | GEN9_MEDIA_PG_ENABLE) : 0);
  4562. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  4563. }
  4564. static void gen8_enable_rps(struct drm_i915_private *dev_priv)
  4565. {
  4566. struct intel_engine_cs *engine;
  4567. uint32_t rc6_mask = 0;
  4568. /* 1a: Software RC state - RC0 */
  4569. I915_WRITE(GEN6_RC_STATE, 0);
  4570. /* 1c & 1d: Get forcewake during program sequence. Although the driver
  4571. * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
  4572. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  4573. /* 2a: Disable RC states. */
  4574. I915_WRITE(GEN6_RC_CONTROL, 0);
  4575. /* 2b: Program RC6 thresholds.*/
  4576. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16);
  4577. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */
  4578. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */
  4579. for_each_engine(engine, dev_priv)
  4580. I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10);
  4581. I915_WRITE(GEN6_RC_SLEEP, 0);
  4582. if (IS_BROADWELL(dev_priv))
  4583. I915_WRITE(GEN6_RC6_THRESHOLD, 625); /* 800us/1.28 for TO */
  4584. else
  4585. I915_WRITE(GEN6_RC6_THRESHOLD, 50000); /* 50/125ms per EI */
  4586. /* 3: Enable RC6 */
  4587. if (intel_enable_rc6() & INTEL_RC6_ENABLE)
  4588. rc6_mask = GEN6_RC_CTL_RC6_ENABLE;
  4589. intel_print_rc6_info(dev_priv, rc6_mask);
  4590. if (IS_BROADWELL(dev_priv))
  4591. I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE |
  4592. GEN7_RC_CTL_TO_MODE |
  4593. rc6_mask);
  4594. else
  4595. I915_WRITE(GEN6_RC_CONTROL, GEN6_RC_CTL_HW_ENABLE |
  4596. GEN6_RC_CTL_EI_MODE(1) |
  4597. rc6_mask);
  4598. /* 4 Program defaults and thresholds for RPS*/
  4599. I915_WRITE(GEN6_RPNSWREQ,
  4600. HSW_FREQUENCY(dev_priv->rps.rp1_freq));
  4601. I915_WRITE(GEN6_RC_VIDEO_FREQ,
  4602. HSW_FREQUENCY(dev_priv->rps.rp1_freq));
  4603. /* NB: Docs say 1s, and 1000000 - which aren't equivalent */
  4604. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 100000000 / 128); /* 1 second timeout */
  4605. /* Docs recommend 900MHz, and 300 MHz respectively */
  4606. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  4607. dev_priv->rps.max_freq_softlimit << 24 |
  4608. dev_priv->rps.min_freq_softlimit << 16);
  4609. I915_WRITE(GEN6_RP_UP_THRESHOLD, 7600000 / 128); /* 76ms busyness per EI, 90% */
  4610. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 31300000 / 128); /* 313ms busyness per EI, 70%*/
  4611. I915_WRITE(GEN6_RP_UP_EI, 66000); /* 84.48ms, XXX: random? */
  4612. I915_WRITE(GEN6_RP_DOWN_EI, 350000); /* 448ms, XXX: random? */
  4613. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  4614. /* 5: Enable RPS */
  4615. I915_WRITE(GEN6_RP_CONTROL,
  4616. GEN6_RP_MEDIA_TURBO |
  4617. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  4618. GEN6_RP_MEDIA_IS_GFX |
  4619. GEN6_RP_ENABLE |
  4620. GEN6_RP_UP_BUSY_AVG |
  4621. GEN6_RP_DOWN_IDLE_AVG);
  4622. /* 6: Ring frequency + overclocking (our driver does this later */
  4623. reset_rps(dev_priv, gen6_set_rps);
  4624. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  4625. }
  4626. static void gen6_enable_rps(struct drm_i915_private *dev_priv)
  4627. {
  4628. struct intel_engine_cs *engine;
  4629. u32 rc6vids, rc6_mask = 0;
  4630. u32 gtfifodbg;
  4631. int rc6_mode;
  4632. int ret;
  4633. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  4634. /* Here begins a magic sequence of register writes to enable
  4635. * auto-downclocking.
  4636. *
  4637. * Perhaps there might be some value in exposing these to
  4638. * userspace...
  4639. */
  4640. I915_WRITE(GEN6_RC_STATE, 0);
  4641. /* Clear the DBG now so we don't confuse earlier errors */
  4642. gtfifodbg = I915_READ(GTFIFODBG);
  4643. if (gtfifodbg) {
  4644. DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg);
  4645. I915_WRITE(GTFIFODBG, gtfifodbg);
  4646. }
  4647. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  4648. /* disable the counters and set deterministic thresholds */
  4649. I915_WRITE(GEN6_RC_CONTROL, 0);
  4650. I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16);
  4651. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30);
  4652. I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30);
  4653. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000);
  4654. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25);
  4655. for_each_engine(engine, dev_priv)
  4656. I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10);
  4657. I915_WRITE(GEN6_RC_SLEEP, 0);
  4658. I915_WRITE(GEN6_RC1e_THRESHOLD, 1000);
  4659. if (IS_IVYBRIDGE(dev_priv))
  4660. I915_WRITE(GEN6_RC6_THRESHOLD, 125000);
  4661. else
  4662. I915_WRITE(GEN6_RC6_THRESHOLD, 50000);
  4663. I915_WRITE(GEN6_RC6p_THRESHOLD, 150000);
  4664. I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */
  4665. /* Check if we are enabling RC6 */
  4666. rc6_mode = intel_enable_rc6();
  4667. if (rc6_mode & INTEL_RC6_ENABLE)
  4668. rc6_mask |= GEN6_RC_CTL_RC6_ENABLE;
  4669. /* We don't use those on Haswell */
  4670. if (!IS_HASWELL(dev_priv)) {
  4671. if (rc6_mode & INTEL_RC6p_ENABLE)
  4672. rc6_mask |= GEN6_RC_CTL_RC6p_ENABLE;
  4673. if (rc6_mode & INTEL_RC6pp_ENABLE)
  4674. rc6_mask |= GEN6_RC_CTL_RC6pp_ENABLE;
  4675. }
  4676. intel_print_rc6_info(dev_priv, rc6_mask);
  4677. I915_WRITE(GEN6_RC_CONTROL,
  4678. rc6_mask |
  4679. GEN6_RC_CTL_EI_MODE(1) |
  4680. GEN6_RC_CTL_HW_ENABLE);
  4681. /* Power down if completely idle for over 50ms */
  4682. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 50000);
  4683. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  4684. ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_MIN_FREQ_TABLE, 0);
  4685. if (ret)
  4686. DRM_DEBUG_DRIVER("Failed to set the min frequency\n");
  4687. reset_rps(dev_priv, gen6_set_rps);
  4688. rc6vids = 0;
  4689. ret = sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
  4690. if (IS_GEN6(dev_priv) && ret) {
  4691. DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n");
  4692. } else if (IS_GEN6(dev_priv) && (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) {
  4693. DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n",
  4694. GEN6_DECODE_RC6_VID(rc6vids & 0xff), 450);
  4695. rc6vids &= 0xffff00;
  4696. rc6vids |= GEN6_ENCODE_RC6_VID(450);
  4697. ret = sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_RC6VIDS, rc6vids);
  4698. if (ret)
  4699. DRM_ERROR("Couldn't fix incorrect rc6 voltage\n");
  4700. }
  4701. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  4702. }
  4703. static void gen6_update_ring_freq(struct drm_i915_private *dev_priv)
  4704. {
  4705. int min_freq = 15;
  4706. unsigned int gpu_freq;
  4707. unsigned int max_ia_freq, min_ring_freq;
  4708. unsigned int max_gpu_freq, min_gpu_freq;
  4709. int scaling_factor = 180;
  4710. struct cpufreq_policy *policy;
  4711. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  4712. policy = cpufreq_cpu_get(0);
  4713. if (policy) {
  4714. max_ia_freq = policy->cpuinfo.max_freq;
  4715. cpufreq_cpu_put(policy);
  4716. } else {
  4717. /*
  4718. * Default to measured freq if none found, PCU will ensure we
  4719. * don't go over
  4720. */
  4721. max_ia_freq = tsc_khz;
  4722. }
  4723. /* Convert from kHz to MHz */
  4724. max_ia_freq /= 1000;
  4725. min_ring_freq = I915_READ(DCLK) & 0xf;
  4726. /* convert DDR frequency from units of 266.6MHz to bandwidth */
  4727. min_ring_freq = mult_frac(min_ring_freq, 8, 3);
  4728. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  4729. /* Convert GT frequency to 50 HZ units */
  4730. min_gpu_freq = dev_priv->rps.min_freq / GEN9_FREQ_SCALER;
  4731. max_gpu_freq = dev_priv->rps.max_freq / GEN9_FREQ_SCALER;
  4732. } else {
  4733. min_gpu_freq = dev_priv->rps.min_freq;
  4734. max_gpu_freq = dev_priv->rps.max_freq;
  4735. }
  4736. /*
  4737. * For each potential GPU frequency, load a ring frequency we'd like
  4738. * to use for memory access. We do this by specifying the IA frequency
  4739. * the PCU should use as a reference to determine the ring frequency.
  4740. */
  4741. for (gpu_freq = max_gpu_freq; gpu_freq >= min_gpu_freq; gpu_freq--) {
  4742. int diff = max_gpu_freq - gpu_freq;
  4743. unsigned int ia_freq = 0, ring_freq = 0;
  4744. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  4745. /*
  4746. * ring_freq = 2 * GT. ring_freq is in 100MHz units
  4747. * No floor required for ring frequency on SKL.
  4748. */
  4749. ring_freq = gpu_freq;
  4750. } else if (INTEL_INFO(dev_priv)->gen >= 8) {
  4751. /* max(2 * GT, DDR). NB: GT is 50MHz units */
  4752. ring_freq = max(min_ring_freq, gpu_freq);
  4753. } else if (IS_HASWELL(dev_priv)) {
  4754. ring_freq = mult_frac(gpu_freq, 5, 4);
  4755. ring_freq = max(min_ring_freq, ring_freq);
  4756. /* leave ia_freq as the default, chosen by cpufreq */
  4757. } else {
  4758. /* On older processors, there is no separate ring
  4759. * clock domain, so in order to boost the bandwidth
  4760. * of the ring, we need to upclock the CPU (ia_freq).
  4761. *
  4762. * For GPU frequencies less than 750MHz,
  4763. * just use the lowest ring freq.
  4764. */
  4765. if (gpu_freq < min_freq)
  4766. ia_freq = 800;
  4767. else
  4768. ia_freq = max_ia_freq - ((diff * scaling_factor) / 2);
  4769. ia_freq = DIV_ROUND_CLOSEST(ia_freq, 100);
  4770. }
  4771. sandybridge_pcode_write(dev_priv,
  4772. GEN6_PCODE_WRITE_MIN_FREQ_TABLE,
  4773. ia_freq << GEN6_PCODE_FREQ_IA_RATIO_SHIFT |
  4774. ring_freq << GEN6_PCODE_FREQ_RING_RATIO_SHIFT |
  4775. gpu_freq);
  4776. }
  4777. }
  4778. static int cherryview_rps_max_freq(struct drm_i915_private *dev_priv)
  4779. {
  4780. u32 val, rp0;
  4781. val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE);
  4782. switch (INTEL_INFO(dev_priv)->sseu.eu_total) {
  4783. case 8:
  4784. /* (2 * 4) config */
  4785. rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT);
  4786. break;
  4787. case 12:
  4788. /* (2 * 6) config */
  4789. rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT);
  4790. break;
  4791. case 16:
  4792. /* (2 * 8) config */
  4793. default:
  4794. /* Setting (2 * 8) Min RP0 for any other combination */
  4795. rp0 = (val >> FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT);
  4796. break;
  4797. }
  4798. rp0 = (rp0 & FB_GFX_FREQ_FUSE_MASK);
  4799. return rp0;
  4800. }
  4801. static int cherryview_rps_rpe_freq(struct drm_i915_private *dev_priv)
  4802. {
  4803. u32 val, rpe;
  4804. val = vlv_punit_read(dev_priv, PUNIT_GPU_DUTYCYCLE_REG);
  4805. rpe = (val >> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK;
  4806. return rpe;
  4807. }
  4808. static int cherryview_rps_guar_freq(struct drm_i915_private *dev_priv)
  4809. {
  4810. u32 val, rp1;
  4811. val = vlv_punit_read(dev_priv, FB_GFX_FMAX_AT_VMAX_FUSE);
  4812. rp1 = (val & FB_GFX_FREQ_FUSE_MASK);
  4813. return rp1;
  4814. }
  4815. static int valleyview_rps_guar_freq(struct drm_i915_private *dev_priv)
  4816. {
  4817. u32 val, rp1;
  4818. val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE);
  4819. rp1 = (val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT;
  4820. return rp1;
  4821. }
  4822. static int valleyview_rps_max_freq(struct drm_i915_private *dev_priv)
  4823. {
  4824. u32 val, rp0;
  4825. val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FREQ_FUSE);
  4826. rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT;
  4827. /* Clamp to max */
  4828. rp0 = min_t(u32, rp0, 0xea);
  4829. return rp0;
  4830. }
  4831. static int valleyview_rps_rpe_freq(struct drm_i915_private *dev_priv)
  4832. {
  4833. u32 val, rpe;
  4834. val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FMAX_FUSE_LO);
  4835. rpe = (val & FB_FMAX_VMIN_FREQ_LO_MASK) >> FB_FMAX_VMIN_FREQ_LO_SHIFT;
  4836. val = vlv_nc_read(dev_priv, IOSF_NC_FB_GFX_FMAX_FUSE_HI);
  4837. rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5;
  4838. return rpe;
  4839. }
  4840. static int valleyview_rps_min_freq(struct drm_i915_private *dev_priv)
  4841. {
  4842. u32 val;
  4843. val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_LFM) & 0xff;
  4844. /*
  4845. * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value
  4846. * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on
  4847. * a BYT-M B0 the above register contains 0xbf. Moreover when setting
  4848. * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0
  4849. * to make sure it matches what Punit accepts.
  4850. */
  4851. return max_t(u32, val, 0xc0);
  4852. }
  4853. /* Check that the pctx buffer wasn't move under us. */
  4854. static void valleyview_check_pctx(struct drm_i915_private *dev_priv)
  4855. {
  4856. unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095;
  4857. WARN_ON(pctx_addr != dev_priv->mm.stolen_base +
  4858. dev_priv->vlv_pctx->stolen->start);
  4859. }
  4860. /* Check that the pcbr address is not empty. */
  4861. static void cherryview_check_pctx(struct drm_i915_private *dev_priv)
  4862. {
  4863. unsigned long pctx_addr = I915_READ(VLV_PCBR) & ~4095;
  4864. WARN_ON((pctx_addr >> VLV_PCBR_ADDR_SHIFT) == 0);
  4865. }
  4866. static void cherryview_setup_pctx(struct drm_i915_private *dev_priv)
  4867. {
  4868. struct i915_ggtt *ggtt = &dev_priv->ggtt;
  4869. unsigned long pctx_paddr, paddr;
  4870. u32 pcbr;
  4871. int pctx_size = 32*1024;
  4872. pcbr = I915_READ(VLV_PCBR);
  4873. if ((pcbr >> VLV_PCBR_ADDR_SHIFT) == 0) {
  4874. DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n");
  4875. paddr = (dev_priv->mm.stolen_base +
  4876. (ggtt->stolen_size - pctx_size));
  4877. pctx_paddr = (paddr & (~4095));
  4878. I915_WRITE(VLV_PCBR, pctx_paddr);
  4879. }
  4880. DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR));
  4881. }
  4882. static void valleyview_setup_pctx(struct drm_i915_private *dev_priv)
  4883. {
  4884. struct drm_i915_gem_object *pctx;
  4885. unsigned long pctx_paddr;
  4886. u32 pcbr;
  4887. int pctx_size = 24*1024;
  4888. pcbr = I915_READ(VLV_PCBR);
  4889. if (pcbr) {
  4890. /* BIOS set it up already, grab the pre-alloc'd space */
  4891. int pcbr_offset;
  4892. pcbr_offset = (pcbr & (~4095)) - dev_priv->mm.stolen_base;
  4893. pctx = i915_gem_object_create_stolen_for_preallocated(&dev_priv->drm,
  4894. pcbr_offset,
  4895. I915_GTT_OFFSET_NONE,
  4896. pctx_size);
  4897. goto out;
  4898. }
  4899. DRM_DEBUG_DRIVER("BIOS didn't set up PCBR, fixing up\n");
  4900. /*
  4901. * From the Gunit register HAS:
  4902. * The Gfx driver is expected to program this register and ensure
  4903. * proper allocation within Gfx stolen memory. For example, this
  4904. * register should be programmed such than the PCBR range does not
  4905. * overlap with other ranges, such as the frame buffer, protected
  4906. * memory, or any other relevant ranges.
  4907. */
  4908. pctx = i915_gem_object_create_stolen(&dev_priv->drm, pctx_size);
  4909. if (!pctx) {
  4910. DRM_DEBUG("not enough stolen space for PCTX, disabling\n");
  4911. goto out;
  4912. }
  4913. pctx_paddr = dev_priv->mm.stolen_base + pctx->stolen->start;
  4914. I915_WRITE(VLV_PCBR, pctx_paddr);
  4915. out:
  4916. DRM_DEBUG_DRIVER("PCBR: 0x%08x\n", I915_READ(VLV_PCBR));
  4917. dev_priv->vlv_pctx = pctx;
  4918. }
  4919. static void valleyview_cleanup_pctx(struct drm_i915_private *dev_priv)
  4920. {
  4921. if (WARN_ON(!dev_priv->vlv_pctx))
  4922. return;
  4923. i915_gem_object_put_unlocked(dev_priv->vlv_pctx);
  4924. dev_priv->vlv_pctx = NULL;
  4925. }
  4926. static void vlv_init_gpll_ref_freq(struct drm_i915_private *dev_priv)
  4927. {
  4928. dev_priv->rps.gpll_ref_freq =
  4929. vlv_get_cck_clock(dev_priv, "GPLL ref",
  4930. CCK_GPLL_CLOCK_CONTROL,
  4931. dev_priv->czclk_freq);
  4932. DRM_DEBUG_DRIVER("GPLL reference freq: %d kHz\n",
  4933. dev_priv->rps.gpll_ref_freq);
  4934. }
  4935. static void valleyview_init_gt_powersave(struct drm_i915_private *dev_priv)
  4936. {
  4937. u32 val;
  4938. valleyview_setup_pctx(dev_priv);
  4939. vlv_init_gpll_ref_freq(dev_priv);
  4940. val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  4941. switch ((val >> 6) & 3) {
  4942. case 0:
  4943. case 1:
  4944. dev_priv->mem_freq = 800;
  4945. break;
  4946. case 2:
  4947. dev_priv->mem_freq = 1066;
  4948. break;
  4949. case 3:
  4950. dev_priv->mem_freq = 1333;
  4951. break;
  4952. }
  4953. DRM_DEBUG_DRIVER("DDR speed: %d MHz\n", dev_priv->mem_freq);
  4954. dev_priv->rps.max_freq = valleyview_rps_max_freq(dev_priv);
  4955. dev_priv->rps.rp0_freq = dev_priv->rps.max_freq;
  4956. DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n",
  4957. intel_gpu_freq(dev_priv, dev_priv->rps.max_freq),
  4958. dev_priv->rps.max_freq);
  4959. dev_priv->rps.efficient_freq = valleyview_rps_rpe_freq(dev_priv);
  4960. DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n",
  4961. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
  4962. dev_priv->rps.efficient_freq);
  4963. dev_priv->rps.rp1_freq = valleyview_rps_guar_freq(dev_priv);
  4964. DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n",
  4965. intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq),
  4966. dev_priv->rps.rp1_freq);
  4967. dev_priv->rps.min_freq = valleyview_rps_min_freq(dev_priv);
  4968. DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n",
  4969. intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
  4970. dev_priv->rps.min_freq);
  4971. }
  4972. static void cherryview_init_gt_powersave(struct drm_i915_private *dev_priv)
  4973. {
  4974. u32 val;
  4975. cherryview_setup_pctx(dev_priv);
  4976. vlv_init_gpll_ref_freq(dev_priv);
  4977. mutex_lock(&dev_priv->sb_lock);
  4978. val = vlv_cck_read(dev_priv, CCK_FUSE_REG);
  4979. mutex_unlock(&dev_priv->sb_lock);
  4980. switch ((val >> 2) & 0x7) {
  4981. case 3:
  4982. dev_priv->mem_freq = 2000;
  4983. break;
  4984. default:
  4985. dev_priv->mem_freq = 1600;
  4986. break;
  4987. }
  4988. DRM_DEBUG_DRIVER("DDR speed: %d MHz\n", dev_priv->mem_freq);
  4989. dev_priv->rps.max_freq = cherryview_rps_max_freq(dev_priv);
  4990. dev_priv->rps.rp0_freq = dev_priv->rps.max_freq;
  4991. DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n",
  4992. intel_gpu_freq(dev_priv, dev_priv->rps.max_freq),
  4993. dev_priv->rps.max_freq);
  4994. dev_priv->rps.efficient_freq = cherryview_rps_rpe_freq(dev_priv);
  4995. DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n",
  4996. intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq),
  4997. dev_priv->rps.efficient_freq);
  4998. dev_priv->rps.rp1_freq = cherryview_rps_guar_freq(dev_priv);
  4999. DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n",
  5000. intel_gpu_freq(dev_priv, dev_priv->rps.rp1_freq),
  5001. dev_priv->rps.rp1_freq);
  5002. /* PUnit validated range is only [RPe, RP0] */
  5003. dev_priv->rps.min_freq = dev_priv->rps.efficient_freq;
  5004. DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n",
  5005. intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
  5006. dev_priv->rps.min_freq);
  5007. WARN_ONCE((dev_priv->rps.max_freq |
  5008. dev_priv->rps.efficient_freq |
  5009. dev_priv->rps.rp1_freq |
  5010. dev_priv->rps.min_freq) & 1,
  5011. "Odd GPU freq values\n");
  5012. }
  5013. static void valleyview_cleanup_gt_powersave(struct drm_i915_private *dev_priv)
  5014. {
  5015. valleyview_cleanup_pctx(dev_priv);
  5016. }
  5017. static void cherryview_enable_rps(struct drm_i915_private *dev_priv)
  5018. {
  5019. struct intel_engine_cs *engine;
  5020. u32 gtfifodbg, val, rc6_mode = 0, pcbr;
  5021. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  5022. gtfifodbg = I915_READ(GTFIFODBG) & ~(GT_FIFO_SBDEDICATE_FREE_ENTRY_CHV |
  5023. GT_FIFO_FREE_ENTRIES_CHV);
  5024. if (gtfifodbg) {
  5025. DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n",
  5026. gtfifodbg);
  5027. I915_WRITE(GTFIFODBG, gtfifodbg);
  5028. }
  5029. cherryview_check_pctx(dev_priv);
  5030. /* 1a & 1b: Get forcewake during program sequence. Although the driver
  5031. * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
  5032. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  5033. /* Disable RC states. */
  5034. I915_WRITE(GEN6_RC_CONTROL, 0);
  5035. /* 2a: Program RC6 thresholds.*/
  5036. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16);
  5037. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000); /* 12500 * 1280ns */
  5038. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25); /* 25 * 1280ns */
  5039. for_each_engine(engine, dev_priv)
  5040. I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10);
  5041. I915_WRITE(GEN6_RC_SLEEP, 0);
  5042. /* TO threshold set to 500 us ( 0x186 * 1.28 us) */
  5043. I915_WRITE(GEN6_RC6_THRESHOLD, 0x186);
  5044. /* allows RC6 residency counter to work */
  5045. I915_WRITE(VLV_COUNTER_CONTROL,
  5046. _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH |
  5047. VLV_MEDIA_RC6_COUNT_EN |
  5048. VLV_RENDER_RC6_COUNT_EN));
  5049. /* For now we assume BIOS is allocating and populating the PCBR */
  5050. pcbr = I915_READ(VLV_PCBR);
  5051. /* 3: Enable RC6 */
  5052. if ((intel_enable_rc6() & INTEL_RC6_ENABLE) &&
  5053. (pcbr >> VLV_PCBR_ADDR_SHIFT))
  5054. rc6_mode = GEN7_RC_CTL_TO_MODE;
  5055. I915_WRITE(GEN6_RC_CONTROL, rc6_mode);
  5056. /* 4 Program defaults and thresholds for RPS*/
  5057. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000);
  5058. I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400);
  5059. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000);
  5060. I915_WRITE(GEN6_RP_UP_EI, 66000);
  5061. I915_WRITE(GEN6_RP_DOWN_EI, 350000);
  5062. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  5063. /* 5: Enable RPS */
  5064. I915_WRITE(GEN6_RP_CONTROL,
  5065. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  5066. GEN6_RP_MEDIA_IS_GFX |
  5067. GEN6_RP_ENABLE |
  5068. GEN6_RP_UP_BUSY_AVG |
  5069. GEN6_RP_DOWN_IDLE_AVG);
  5070. /* Setting Fixed Bias */
  5071. val = VLV_OVERRIDE_EN |
  5072. VLV_SOC_TDP_EN |
  5073. CHV_BIAS_CPU_50_SOC_50;
  5074. vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val);
  5075. val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  5076. /* RPS code assumes GPLL is used */
  5077. WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n");
  5078. DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE));
  5079. DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val);
  5080. reset_rps(dev_priv, valleyview_set_rps);
  5081. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  5082. }
  5083. static void valleyview_enable_rps(struct drm_i915_private *dev_priv)
  5084. {
  5085. struct intel_engine_cs *engine;
  5086. u32 gtfifodbg, val, rc6_mode = 0;
  5087. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  5088. valleyview_check_pctx(dev_priv);
  5089. gtfifodbg = I915_READ(GTFIFODBG);
  5090. if (gtfifodbg) {
  5091. DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n",
  5092. gtfifodbg);
  5093. I915_WRITE(GTFIFODBG, gtfifodbg);
  5094. }
  5095. /* If VLV, Forcewake all wells, else re-direct to regular path */
  5096. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
  5097. /* Disable RC states. */
  5098. I915_WRITE(GEN6_RC_CONTROL, 0);
  5099. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000);
  5100. I915_WRITE(GEN6_RP_UP_THRESHOLD, 59400);
  5101. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 245000);
  5102. I915_WRITE(GEN6_RP_UP_EI, 66000);
  5103. I915_WRITE(GEN6_RP_DOWN_EI, 350000);
  5104. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  5105. I915_WRITE(GEN6_RP_CONTROL,
  5106. GEN6_RP_MEDIA_TURBO |
  5107. GEN6_RP_MEDIA_HW_NORMAL_MODE |
  5108. GEN6_RP_MEDIA_IS_GFX |
  5109. GEN6_RP_ENABLE |
  5110. GEN6_RP_UP_BUSY_AVG |
  5111. GEN6_RP_DOWN_IDLE_CONT);
  5112. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 0x00280000);
  5113. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000);
  5114. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25);
  5115. for_each_engine(engine, dev_priv)
  5116. I915_WRITE(RING_MAX_IDLE(engine->mmio_base), 10);
  5117. I915_WRITE(GEN6_RC6_THRESHOLD, 0x557);
  5118. /* allows RC6 residency counter to work */
  5119. I915_WRITE(VLV_COUNTER_CONTROL,
  5120. _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN |
  5121. VLV_RENDER_RC0_COUNT_EN |
  5122. VLV_MEDIA_RC6_COUNT_EN |
  5123. VLV_RENDER_RC6_COUNT_EN));
  5124. if (intel_enable_rc6() & INTEL_RC6_ENABLE)
  5125. rc6_mode = GEN7_RC_CTL_TO_MODE | VLV_RC_CTL_CTX_RST_PARALLEL;
  5126. intel_print_rc6_info(dev_priv, rc6_mode);
  5127. I915_WRITE(GEN6_RC_CONTROL, rc6_mode);
  5128. /* Setting Fixed Bias */
  5129. val = VLV_OVERRIDE_EN |
  5130. VLV_SOC_TDP_EN |
  5131. VLV_BIAS_CPU_125_SOC_875;
  5132. vlv_punit_write(dev_priv, VLV_TURBO_SOC_OVERRIDE, val);
  5133. val = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
  5134. /* RPS code assumes GPLL is used */
  5135. WARN_ONCE((val & GPLLENABLE) == 0, "GPLL not enabled\n");
  5136. DRM_DEBUG_DRIVER("GPLL enabled? %s\n", yesno(val & GPLLENABLE));
  5137. DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val);
  5138. reset_rps(dev_priv, valleyview_set_rps);
  5139. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
  5140. }
  5141. static unsigned long intel_pxfreq(u32 vidfreq)
  5142. {
  5143. unsigned long freq;
  5144. int div = (vidfreq & 0x3f0000) >> 16;
  5145. int post = (vidfreq & 0x3000) >> 12;
  5146. int pre = (vidfreq & 0x7);
  5147. if (!pre)
  5148. return 0;
  5149. freq = ((div * 133333) / ((1<<post) * pre));
  5150. return freq;
  5151. }
  5152. static const struct cparams {
  5153. u16 i;
  5154. u16 t;
  5155. u16 m;
  5156. u16 c;
  5157. } cparams[] = {
  5158. { 1, 1333, 301, 28664 },
  5159. { 1, 1066, 294, 24460 },
  5160. { 1, 800, 294, 25192 },
  5161. { 0, 1333, 276, 27605 },
  5162. { 0, 1066, 276, 27605 },
  5163. { 0, 800, 231, 23784 },
  5164. };
  5165. static unsigned long __i915_chipset_val(struct drm_i915_private *dev_priv)
  5166. {
  5167. u64 total_count, diff, ret;
  5168. u32 count1, count2, count3, m = 0, c = 0;
  5169. unsigned long now = jiffies_to_msecs(jiffies), diff1;
  5170. int i;
  5171. assert_spin_locked(&mchdev_lock);
  5172. diff1 = now - dev_priv->ips.last_time1;
  5173. /* Prevent division-by-zero if we are asking too fast.
  5174. * Also, we don't get interesting results if we are polling
  5175. * faster than once in 10ms, so just return the saved value
  5176. * in such cases.
  5177. */
  5178. if (diff1 <= 10)
  5179. return dev_priv->ips.chipset_power;
  5180. count1 = I915_READ(DMIEC);
  5181. count2 = I915_READ(DDREC);
  5182. count3 = I915_READ(CSIEC);
  5183. total_count = count1 + count2 + count3;
  5184. /* FIXME: handle per-counter overflow */
  5185. if (total_count < dev_priv->ips.last_count1) {
  5186. diff = ~0UL - dev_priv->ips.last_count1;
  5187. diff += total_count;
  5188. } else {
  5189. diff = total_count - dev_priv->ips.last_count1;
  5190. }
  5191. for (i = 0; i < ARRAY_SIZE(cparams); i++) {
  5192. if (cparams[i].i == dev_priv->ips.c_m &&
  5193. cparams[i].t == dev_priv->ips.r_t) {
  5194. m = cparams[i].m;
  5195. c = cparams[i].c;
  5196. break;
  5197. }
  5198. }
  5199. diff = div_u64(diff, diff1);
  5200. ret = ((m * diff) + c);
  5201. ret = div_u64(ret, 10);
  5202. dev_priv->ips.last_count1 = total_count;
  5203. dev_priv->ips.last_time1 = now;
  5204. dev_priv->ips.chipset_power = ret;
  5205. return ret;
  5206. }
  5207. unsigned long i915_chipset_val(struct drm_i915_private *dev_priv)
  5208. {
  5209. unsigned long val;
  5210. if (INTEL_INFO(dev_priv)->gen != 5)
  5211. return 0;
  5212. spin_lock_irq(&mchdev_lock);
  5213. val = __i915_chipset_val(dev_priv);
  5214. spin_unlock_irq(&mchdev_lock);
  5215. return val;
  5216. }
  5217. unsigned long i915_mch_val(struct drm_i915_private *dev_priv)
  5218. {
  5219. unsigned long m, x, b;
  5220. u32 tsfs;
  5221. tsfs = I915_READ(TSFS);
  5222. m = ((tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT);
  5223. x = I915_READ8(TR1);
  5224. b = tsfs & TSFS_INTR_MASK;
  5225. return ((m * x) / 127) - b;
  5226. }
  5227. static int _pxvid_to_vd(u8 pxvid)
  5228. {
  5229. if (pxvid == 0)
  5230. return 0;
  5231. if (pxvid >= 8 && pxvid < 31)
  5232. pxvid = 31;
  5233. return (pxvid + 2) * 125;
  5234. }
  5235. static u32 pvid_to_extvid(struct drm_i915_private *dev_priv, u8 pxvid)
  5236. {
  5237. const int vd = _pxvid_to_vd(pxvid);
  5238. const int vm = vd - 1125;
  5239. if (INTEL_INFO(dev_priv)->is_mobile)
  5240. return vm > 0 ? vm : 0;
  5241. return vd;
  5242. }
  5243. static void __i915_update_gfx_val(struct drm_i915_private *dev_priv)
  5244. {
  5245. u64 now, diff, diffms;
  5246. u32 count;
  5247. assert_spin_locked(&mchdev_lock);
  5248. now = ktime_get_raw_ns();
  5249. diffms = now - dev_priv->ips.last_time2;
  5250. do_div(diffms, NSEC_PER_MSEC);
  5251. /* Don't divide by 0 */
  5252. if (!diffms)
  5253. return;
  5254. count = I915_READ(GFXEC);
  5255. if (count < dev_priv->ips.last_count2) {
  5256. diff = ~0UL - dev_priv->ips.last_count2;
  5257. diff += count;
  5258. } else {
  5259. diff = count - dev_priv->ips.last_count2;
  5260. }
  5261. dev_priv->ips.last_count2 = count;
  5262. dev_priv->ips.last_time2 = now;
  5263. /* More magic constants... */
  5264. diff = diff * 1181;
  5265. diff = div_u64(diff, diffms * 10);
  5266. dev_priv->ips.gfx_power = diff;
  5267. }
  5268. void i915_update_gfx_val(struct drm_i915_private *dev_priv)
  5269. {
  5270. if (INTEL_INFO(dev_priv)->gen != 5)
  5271. return;
  5272. spin_lock_irq(&mchdev_lock);
  5273. __i915_update_gfx_val(dev_priv);
  5274. spin_unlock_irq(&mchdev_lock);
  5275. }
  5276. static unsigned long __i915_gfx_val(struct drm_i915_private *dev_priv)
  5277. {
  5278. unsigned long t, corr, state1, corr2, state2;
  5279. u32 pxvid, ext_v;
  5280. assert_spin_locked(&mchdev_lock);
  5281. pxvid = I915_READ(PXVFREQ(dev_priv->rps.cur_freq));
  5282. pxvid = (pxvid >> 24) & 0x7f;
  5283. ext_v = pvid_to_extvid(dev_priv, pxvid);
  5284. state1 = ext_v;
  5285. t = i915_mch_val(dev_priv);
  5286. /* Revel in the empirically derived constants */
  5287. /* Correction factor in 1/100000 units */
  5288. if (t > 80)
  5289. corr = ((t * 2349) + 135940);
  5290. else if (t >= 50)
  5291. corr = ((t * 964) + 29317);
  5292. else /* < 50 */
  5293. corr = ((t * 301) + 1004);
  5294. corr = corr * ((150142 * state1) / 10000 - 78642);
  5295. corr /= 100000;
  5296. corr2 = (corr * dev_priv->ips.corr);
  5297. state2 = (corr2 * state1) / 10000;
  5298. state2 /= 100; /* convert to mW */
  5299. __i915_update_gfx_val(dev_priv);
  5300. return dev_priv->ips.gfx_power + state2;
  5301. }
  5302. unsigned long i915_gfx_val(struct drm_i915_private *dev_priv)
  5303. {
  5304. unsigned long val;
  5305. if (INTEL_INFO(dev_priv)->gen != 5)
  5306. return 0;
  5307. spin_lock_irq(&mchdev_lock);
  5308. val = __i915_gfx_val(dev_priv);
  5309. spin_unlock_irq(&mchdev_lock);
  5310. return val;
  5311. }
  5312. /**
  5313. * i915_read_mch_val - return value for IPS use
  5314. *
  5315. * Calculate and return a value for the IPS driver to use when deciding whether
  5316. * we have thermal and power headroom to increase CPU or GPU power budget.
  5317. */
  5318. unsigned long i915_read_mch_val(void)
  5319. {
  5320. struct drm_i915_private *dev_priv;
  5321. unsigned long chipset_val, graphics_val, ret = 0;
  5322. spin_lock_irq(&mchdev_lock);
  5323. if (!i915_mch_dev)
  5324. goto out_unlock;
  5325. dev_priv = i915_mch_dev;
  5326. chipset_val = __i915_chipset_val(dev_priv);
  5327. graphics_val = __i915_gfx_val(dev_priv);
  5328. ret = chipset_val + graphics_val;
  5329. out_unlock:
  5330. spin_unlock_irq(&mchdev_lock);
  5331. return ret;
  5332. }
  5333. EXPORT_SYMBOL_GPL(i915_read_mch_val);
  5334. /**
  5335. * i915_gpu_raise - raise GPU frequency limit
  5336. *
  5337. * Raise the limit; IPS indicates we have thermal headroom.
  5338. */
  5339. bool i915_gpu_raise(void)
  5340. {
  5341. struct drm_i915_private *dev_priv;
  5342. bool ret = true;
  5343. spin_lock_irq(&mchdev_lock);
  5344. if (!i915_mch_dev) {
  5345. ret = false;
  5346. goto out_unlock;
  5347. }
  5348. dev_priv = i915_mch_dev;
  5349. if (dev_priv->ips.max_delay > dev_priv->ips.fmax)
  5350. dev_priv->ips.max_delay--;
  5351. out_unlock:
  5352. spin_unlock_irq(&mchdev_lock);
  5353. return ret;
  5354. }
  5355. EXPORT_SYMBOL_GPL(i915_gpu_raise);
  5356. /**
  5357. * i915_gpu_lower - lower GPU frequency limit
  5358. *
  5359. * IPS indicates we're close to a thermal limit, so throttle back the GPU
  5360. * frequency maximum.
  5361. */
  5362. bool i915_gpu_lower(void)
  5363. {
  5364. struct drm_i915_private *dev_priv;
  5365. bool ret = true;
  5366. spin_lock_irq(&mchdev_lock);
  5367. if (!i915_mch_dev) {
  5368. ret = false;
  5369. goto out_unlock;
  5370. }
  5371. dev_priv = i915_mch_dev;
  5372. if (dev_priv->ips.max_delay < dev_priv->ips.min_delay)
  5373. dev_priv->ips.max_delay++;
  5374. out_unlock:
  5375. spin_unlock_irq(&mchdev_lock);
  5376. return ret;
  5377. }
  5378. EXPORT_SYMBOL_GPL(i915_gpu_lower);
  5379. /**
  5380. * i915_gpu_busy - indicate GPU business to IPS
  5381. *
  5382. * Tell the IPS driver whether or not the GPU is busy.
  5383. */
  5384. bool i915_gpu_busy(void)
  5385. {
  5386. bool ret = false;
  5387. spin_lock_irq(&mchdev_lock);
  5388. if (i915_mch_dev)
  5389. ret = i915_mch_dev->gt.awake;
  5390. spin_unlock_irq(&mchdev_lock);
  5391. return ret;
  5392. }
  5393. EXPORT_SYMBOL_GPL(i915_gpu_busy);
  5394. /**
  5395. * i915_gpu_turbo_disable - disable graphics turbo
  5396. *
  5397. * Disable graphics turbo by resetting the max frequency and setting the
  5398. * current frequency to the default.
  5399. */
  5400. bool i915_gpu_turbo_disable(void)
  5401. {
  5402. struct drm_i915_private *dev_priv;
  5403. bool ret = true;
  5404. spin_lock_irq(&mchdev_lock);
  5405. if (!i915_mch_dev) {
  5406. ret = false;
  5407. goto out_unlock;
  5408. }
  5409. dev_priv = i915_mch_dev;
  5410. dev_priv->ips.max_delay = dev_priv->ips.fstart;
  5411. if (!ironlake_set_drps(dev_priv, dev_priv->ips.fstart))
  5412. ret = false;
  5413. out_unlock:
  5414. spin_unlock_irq(&mchdev_lock);
  5415. return ret;
  5416. }
  5417. EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable);
  5418. /**
  5419. * Tells the intel_ips driver that the i915 driver is now loaded, if
  5420. * IPS got loaded first.
  5421. *
  5422. * This awkward dance is so that neither module has to depend on the
  5423. * other in order for IPS to do the appropriate communication of
  5424. * GPU turbo limits to i915.
  5425. */
  5426. static void
  5427. ips_ping_for_i915_load(void)
  5428. {
  5429. void (*link)(void);
  5430. link = symbol_get(ips_link_to_i915_driver);
  5431. if (link) {
  5432. link();
  5433. symbol_put(ips_link_to_i915_driver);
  5434. }
  5435. }
  5436. void intel_gpu_ips_init(struct drm_i915_private *dev_priv)
  5437. {
  5438. /* We only register the i915 ips part with intel-ips once everything is
  5439. * set up, to avoid intel-ips sneaking in and reading bogus values. */
  5440. spin_lock_irq(&mchdev_lock);
  5441. i915_mch_dev = dev_priv;
  5442. spin_unlock_irq(&mchdev_lock);
  5443. ips_ping_for_i915_load();
  5444. }
  5445. void intel_gpu_ips_teardown(void)
  5446. {
  5447. spin_lock_irq(&mchdev_lock);
  5448. i915_mch_dev = NULL;
  5449. spin_unlock_irq(&mchdev_lock);
  5450. }
  5451. static void intel_init_emon(struct drm_i915_private *dev_priv)
  5452. {
  5453. u32 lcfuse;
  5454. u8 pxw[16];
  5455. int i;
  5456. /* Disable to program */
  5457. I915_WRITE(ECR, 0);
  5458. POSTING_READ(ECR);
  5459. /* Program energy weights for various events */
  5460. I915_WRITE(SDEW, 0x15040d00);
  5461. I915_WRITE(CSIEW0, 0x007f0000);
  5462. I915_WRITE(CSIEW1, 0x1e220004);
  5463. I915_WRITE(CSIEW2, 0x04000004);
  5464. for (i = 0; i < 5; i++)
  5465. I915_WRITE(PEW(i), 0);
  5466. for (i = 0; i < 3; i++)
  5467. I915_WRITE(DEW(i), 0);
  5468. /* Program P-state weights to account for frequency power adjustment */
  5469. for (i = 0; i < 16; i++) {
  5470. u32 pxvidfreq = I915_READ(PXVFREQ(i));
  5471. unsigned long freq = intel_pxfreq(pxvidfreq);
  5472. unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >>
  5473. PXVFREQ_PX_SHIFT;
  5474. unsigned long val;
  5475. val = vid * vid;
  5476. val *= (freq / 1000);
  5477. val *= 255;
  5478. val /= (127*127*900);
  5479. if (val > 0xff)
  5480. DRM_ERROR("bad pxval: %ld\n", val);
  5481. pxw[i] = val;
  5482. }
  5483. /* Render standby states get 0 weight */
  5484. pxw[14] = 0;
  5485. pxw[15] = 0;
  5486. for (i = 0; i < 4; i++) {
  5487. u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) |
  5488. (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]);
  5489. I915_WRITE(PXW(i), val);
  5490. }
  5491. /* Adjust magic regs to magic values (more experimental results) */
  5492. I915_WRITE(OGW0, 0);
  5493. I915_WRITE(OGW1, 0);
  5494. I915_WRITE(EG0, 0x00007f00);
  5495. I915_WRITE(EG1, 0x0000000e);
  5496. I915_WRITE(EG2, 0x000e0000);
  5497. I915_WRITE(EG3, 0x68000300);
  5498. I915_WRITE(EG4, 0x42000000);
  5499. I915_WRITE(EG5, 0x00140031);
  5500. I915_WRITE(EG6, 0);
  5501. I915_WRITE(EG7, 0);
  5502. for (i = 0; i < 8; i++)
  5503. I915_WRITE(PXWL(i), 0);
  5504. /* Enable PMON + select events */
  5505. I915_WRITE(ECR, 0x80000019);
  5506. lcfuse = I915_READ(LCFUSE02);
  5507. dev_priv->ips.corr = (lcfuse & LCFUSE_HIV_MASK);
  5508. }
  5509. void intel_init_gt_powersave(struct drm_i915_private *dev_priv)
  5510. {
  5511. /*
  5512. * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
  5513. * requirement.
  5514. */
  5515. if (!i915.enable_rc6) {
  5516. DRM_INFO("RC6 disabled, disabling runtime PM support\n");
  5517. intel_runtime_pm_get(dev_priv);
  5518. }
  5519. mutex_lock(&dev_priv->drm.struct_mutex);
  5520. mutex_lock(&dev_priv->rps.hw_lock);
  5521. /* Initialize RPS limits (for userspace) */
  5522. if (IS_CHERRYVIEW(dev_priv))
  5523. cherryview_init_gt_powersave(dev_priv);
  5524. else if (IS_VALLEYVIEW(dev_priv))
  5525. valleyview_init_gt_powersave(dev_priv);
  5526. else if (INTEL_GEN(dev_priv) >= 6)
  5527. gen6_init_rps_frequencies(dev_priv);
  5528. /* Derive initial user preferences/limits from the hardware limits */
  5529. dev_priv->rps.idle_freq = dev_priv->rps.min_freq;
  5530. dev_priv->rps.cur_freq = dev_priv->rps.idle_freq;
  5531. dev_priv->rps.max_freq_softlimit = dev_priv->rps.max_freq;
  5532. dev_priv->rps.min_freq_softlimit = dev_priv->rps.min_freq;
  5533. if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  5534. dev_priv->rps.min_freq_softlimit =
  5535. max_t(int,
  5536. dev_priv->rps.efficient_freq,
  5537. intel_freq_opcode(dev_priv, 450));
  5538. /* After setting max-softlimit, find the overclock max freq */
  5539. if (IS_GEN6(dev_priv) ||
  5540. IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) {
  5541. u32 params = 0;
  5542. sandybridge_pcode_read(dev_priv, GEN6_READ_OC_PARAMS, &params);
  5543. if (params & BIT(31)) { /* OC supported */
  5544. DRM_DEBUG_DRIVER("Overclocking supported, max: %dMHz, overclock: %dMHz\n",
  5545. (dev_priv->rps.max_freq & 0xff) * 50,
  5546. (params & 0xff) * 50);
  5547. dev_priv->rps.max_freq = params & 0xff;
  5548. }
  5549. }
  5550. /* Finally allow us to boost to max by default */
  5551. dev_priv->rps.boost_freq = dev_priv->rps.max_freq;
  5552. mutex_unlock(&dev_priv->rps.hw_lock);
  5553. mutex_unlock(&dev_priv->drm.struct_mutex);
  5554. intel_autoenable_gt_powersave(dev_priv);
  5555. }
  5556. void intel_cleanup_gt_powersave(struct drm_i915_private *dev_priv)
  5557. {
  5558. if (IS_VALLEYVIEW(dev_priv))
  5559. valleyview_cleanup_gt_powersave(dev_priv);
  5560. if (!i915.enable_rc6)
  5561. intel_runtime_pm_put(dev_priv);
  5562. }
  5563. /**
  5564. * intel_suspend_gt_powersave - suspend PM work and helper threads
  5565. * @dev_priv: i915 device
  5566. *
  5567. * We don't want to disable RC6 or other features here, we just want
  5568. * to make sure any work we've queued has finished and won't bother
  5569. * us while we're suspended.
  5570. */
  5571. void intel_suspend_gt_powersave(struct drm_i915_private *dev_priv)
  5572. {
  5573. if (INTEL_GEN(dev_priv) < 6)
  5574. return;
  5575. if (cancel_delayed_work_sync(&dev_priv->rps.autoenable_work))
  5576. intel_runtime_pm_put(dev_priv);
  5577. /* gen6_rps_idle() will be called later to disable interrupts */
  5578. }
  5579. void intel_sanitize_gt_powersave(struct drm_i915_private *dev_priv)
  5580. {
  5581. dev_priv->rps.enabled = true; /* force disabling */
  5582. intel_disable_gt_powersave(dev_priv);
  5583. gen6_reset_rps_interrupts(dev_priv);
  5584. }
  5585. void intel_disable_gt_powersave(struct drm_i915_private *dev_priv)
  5586. {
  5587. if (!READ_ONCE(dev_priv->rps.enabled))
  5588. return;
  5589. mutex_lock(&dev_priv->rps.hw_lock);
  5590. if (INTEL_GEN(dev_priv) >= 9) {
  5591. gen9_disable_rc6(dev_priv);
  5592. gen9_disable_rps(dev_priv);
  5593. } else if (IS_CHERRYVIEW(dev_priv)) {
  5594. cherryview_disable_rps(dev_priv);
  5595. } else if (IS_VALLEYVIEW(dev_priv)) {
  5596. valleyview_disable_rps(dev_priv);
  5597. } else if (INTEL_GEN(dev_priv) >= 6) {
  5598. gen6_disable_rps(dev_priv);
  5599. } else if (IS_IRONLAKE_M(dev_priv)) {
  5600. ironlake_disable_drps(dev_priv);
  5601. }
  5602. dev_priv->rps.enabled = false;
  5603. mutex_unlock(&dev_priv->rps.hw_lock);
  5604. }
  5605. void intel_enable_gt_powersave(struct drm_i915_private *dev_priv)
  5606. {
  5607. /* We shouldn't be disabling as we submit, so this should be less
  5608. * racy than it appears!
  5609. */
  5610. if (READ_ONCE(dev_priv->rps.enabled))
  5611. return;
  5612. /* Powersaving is controlled by the host when inside a VM */
  5613. if (intel_vgpu_active(dev_priv))
  5614. return;
  5615. mutex_lock(&dev_priv->rps.hw_lock);
  5616. if (IS_CHERRYVIEW(dev_priv)) {
  5617. cherryview_enable_rps(dev_priv);
  5618. } else if (IS_VALLEYVIEW(dev_priv)) {
  5619. valleyview_enable_rps(dev_priv);
  5620. } else if (INTEL_GEN(dev_priv) >= 9) {
  5621. gen9_enable_rc6(dev_priv);
  5622. gen9_enable_rps(dev_priv);
  5623. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
  5624. gen6_update_ring_freq(dev_priv);
  5625. } else if (IS_BROADWELL(dev_priv)) {
  5626. gen8_enable_rps(dev_priv);
  5627. gen6_update_ring_freq(dev_priv);
  5628. } else if (INTEL_GEN(dev_priv) >= 6) {
  5629. gen6_enable_rps(dev_priv);
  5630. gen6_update_ring_freq(dev_priv);
  5631. } else if (IS_IRONLAKE_M(dev_priv)) {
  5632. ironlake_enable_drps(dev_priv);
  5633. intel_init_emon(dev_priv);
  5634. }
  5635. WARN_ON(dev_priv->rps.max_freq < dev_priv->rps.min_freq);
  5636. WARN_ON(dev_priv->rps.idle_freq > dev_priv->rps.max_freq);
  5637. WARN_ON(dev_priv->rps.efficient_freq < dev_priv->rps.min_freq);
  5638. WARN_ON(dev_priv->rps.efficient_freq > dev_priv->rps.max_freq);
  5639. dev_priv->rps.enabled = true;
  5640. mutex_unlock(&dev_priv->rps.hw_lock);
  5641. }
  5642. static void __intel_autoenable_gt_powersave(struct work_struct *work)
  5643. {
  5644. struct drm_i915_private *dev_priv =
  5645. container_of(work, typeof(*dev_priv), rps.autoenable_work.work);
  5646. struct intel_engine_cs *rcs;
  5647. struct drm_i915_gem_request *req;
  5648. if (READ_ONCE(dev_priv->rps.enabled))
  5649. goto out;
  5650. rcs = &dev_priv->engine[RCS];
  5651. if (rcs->last_context)
  5652. goto out;
  5653. if (!rcs->init_context)
  5654. goto out;
  5655. mutex_lock(&dev_priv->drm.struct_mutex);
  5656. req = i915_gem_request_alloc(rcs, dev_priv->kernel_context);
  5657. if (IS_ERR(req))
  5658. goto unlock;
  5659. if (!i915.enable_execlists && i915_switch_context(req) == 0)
  5660. rcs->init_context(req);
  5661. /* Mark the device busy, calling intel_enable_gt_powersave() */
  5662. i915_add_request_no_flush(req);
  5663. unlock:
  5664. mutex_unlock(&dev_priv->drm.struct_mutex);
  5665. out:
  5666. intel_runtime_pm_put(dev_priv);
  5667. }
  5668. void intel_autoenable_gt_powersave(struct drm_i915_private *dev_priv)
  5669. {
  5670. if (READ_ONCE(dev_priv->rps.enabled))
  5671. return;
  5672. if (IS_IRONLAKE_M(dev_priv)) {
  5673. ironlake_enable_drps(dev_priv);
  5674. intel_init_emon(dev_priv);
  5675. } else if (INTEL_INFO(dev_priv)->gen >= 6) {
  5676. /*
  5677. * PCU communication is slow and this doesn't need to be
  5678. * done at any specific time, so do this out of our fast path
  5679. * to make resume and init faster.
  5680. *
  5681. * We depend on the HW RC6 power context save/restore
  5682. * mechanism when entering D3 through runtime PM suspend. So
  5683. * disable RPM until RPS/RC6 is properly setup. We can only
  5684. * get here via the driver load/system resume/runtime resume
  5685. * paths, so the _noresume version is enough (and in case of
  5686. * runtime resume it's necessary).
  5687. */
  5688. if (queue_delayed_work(dev_priv->wq,
  5689. &dev_priv->rps.autoenable_work,
  5690. round_jiffies_up_relative(HZ)))
  5691. intel_runtime_pm_get_noresume(dev_priv);
  5692. }
  5693. }
  5694. static void ibx_init_clock_gating(struct drm_device *dev)
  5695. {
  5696. struct drm_i915_private *dev_priv = to_i915(dev);
  5697. /*
  5698. * On Ibex Peak and Cougar Point, we need to disable clock
  5699. * gating for the panel power sequencer or it will fail to
  5700. * start up when no ports are active.
  5701. */
  5702. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
  5703. }
  5704. static void g4x_disable_trickle_feed(struct drm_device *dev)
  5705. {
  5706. struct drm_i915_private *dev_priv = to_i915(dev);
  5707. enum pipe pipe;
  5708. for_each_pipe(dev_priv, pipe) {
  5709. I915_WRITE(DSPCNTR(pipe),
  5710. I915_READ(DSPCNTR(pipe)) |
  5711. DISPPLANE_TRICKLE_FEED_DISABLE);
  5712. I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe)));
  5713. POSTING_READ(DSPSURF(pipe));
  5714. }
  5715. }
  5716. static void ilk_init_lp_watermarks(struct drm_device *dev)
  5717. {
  5718. struct drm_i915_private *dev_priv = to_i915(dev);
  5719. I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN);
  5720. I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN);
  5721. I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN);
  5722. /*
  5723. * Don't touch WM1S_LP_EN here.
  5724. * Doing so could cause underruns.
  5725. */
  5726. }
  5727. static void ironlake_init_clock_gating(struct drm_device *dev)
  5728. {
  5729. struct drm_i915_private *dev_priv = to_i915(dev);
  5730. uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
  5731. /*
  5732. * Required for FBC
  5733. * WaFbcDisableDpfcClockGating:ilk
  5734. */
  5735. dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE |
  5736. ILK_DPFCUNIT_CLOCK_GATE_DISABLE |
  5737. ILK_DPFDUNIT_CLOCK_GATE_ENABLE;
  5738. I915_WRITE(PCH_3DCGDIS0,
  5739. MARIUNIT_CLOCK_GATE_DISABLE |
  5740. SVSMUNIT_CLOCK_GATE_DISABLE);
  5741. I915_WRITE(PCH_3DCGDIS1,
  5742. VFMUNIT_CLOCK_GATE_DISABLE);
  5743. /*
  5744. * According to the spec the following bits should be set in
  5745. * order to enable memory self-refresh
  5746. * The bit 22/21 of 0x42004
  5747. * The bit 5 of 0x42020
  5748. * The bit 15 of 0x45000
  5749. */
  5750. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  5751. (I915_READ(ILK_DISPLAY_CHICKEN2) |
  5752. ILK_DPARB_GATE | ILK_VSDPFD_FULL));
  5753. dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE;
  5754. I915_WRITE(DISP_ARB_CTL,
  5755. (I915_READ(DISP_ARB_CTL) |
  5756. DISP_FBC_WM_DIS));
  5757. ilk_init_lp_watermarks(dev);
  5758. /*
  5759. * Based on the document from hardware guys the following bits
  5760. * should be set unconditionally in order to enable FBC.
  5761. * The bit 22 of 0x42000
  5762. * The bit 22 of 0x42004
  5763. * The bit 7,8,9 of 0x42020.
  5764. */
  5765. if (IS_IRONLAKE_M(dev)) {
  5766. /* WaFbcAsynchFlipDisableFbcQueue:ilk */
  5767. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  5768. I915_READ(ILK_DISPLAY_CHICKEN1) |
  5769. ILK_FBCQ_DIS);
  5770. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  5771. I915_READ(ILK_DISPLAY_CHICKEN2) |
  5772. ILK_DPARB_GATE);
  5773. }
  5774. I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate);
  5775. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  5776. I915_READ(ILK_DISPLAY_CHICKEN2) |
  5777. ILK_ELPIN_409_SELECT);
  5778. I915_WRITE(_3D_CHICKEN2,
  5779. _3D_CHICKEN2_WM_READ_PIPELINED << 16 |
  5780. _3D_CHICKEN2_WM_READ_PIPELINED);
  5781. /* WaDisableRenderCachePipelinedFlush:ilk */
  5782. I915_WRITE(CACHE_MODE_0,
  5783. _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE));
  5784. /* WaDisable_RenderCache_OperationalFlush:ilk */
  5785. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  5786. g4x_disable_trickle_feed(dev);
  5787. ibx_init_clock_gating(dev);
  5788. }
  5789. static void cpt_init_clock_gating(struct drm_device *dev)
  5790. {
  5791. struct drm_i915_private *dev_priv = to_i915(dev);
  5792. int pipe;
  5793. uint32_t val;
  5794. /*
  5795. * On Ibex Peak and Cougar Point, we need to disable clock
  5796. * gating for the panel power sequencer or it will fail to
  5797. * start up when no ports are active.
  5798. */
  5799. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE |
  5800. PCH_DPLUNIT_CLOCK_GATE_DISABLE |
  5801. PCH_CPUNIT_CLOCK_GATE_DISABLE);
  5802. I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) |
  5803. DPLS_EDP_PPS_FIX_DIS);
  5804. /* The below fixes the weird display corruption, a few pixels shifted
  5805. * downward, on (only) LVDS of some HP laptops with IVY.
  5806. */
  5807. for_each_pipe(dev_priv, pipe) {
  5808. val = I915_READ(TRANS_CHICKEN2(pipe));
  5809. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  5810. val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
  5811. if (dev_priv->vbt.fdi_rx_polarity_inverted)
  5812. val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
  5813. val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
  5814. val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER;
  5815. val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH;
  5816. I915_WRITE(TRANS_CHICKEN2(pipe), val);
  5817. }
  5818. /* WADP0ClockGatingDisable */
  5819. for_each_pipe(dev_priv, pipe) {
  5820. I915_WRITE(TRANS_CHICKEN1(pipe),
  5821. TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
  5822. }
  5823. }
  5824. static void gen6_check_mch_setup(struct drm_device *dev)
  5825. {
  5826. struct drm_i915_private *dev_priv = to_i915(dev);
  5827. uint32_t tmp;
  5828. tmp = I915_READ(MCH_SSKPD);
  5829. if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL)
  5830. DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n",
  5831. tmp);
  5832. }
  5833. static void gen6_init_clock_gating(struct drm_device *dev)
  5834. {
  5835. struct drm_i915_private *dev_priv = to_i915(dev);
  5836. uint32_t dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
  5837. I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate);
  5838. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  5839. I915_READ(ILK_DISPLAY_CHICKEN2) |
  5840. ILK_ELPIN_409_SELECT);
  5841. /* WaDisableHiZPlanesWhenMSAAEnabled:snb */
  5842. I915_WRITE(_3D_CHICKEN,
  5843. _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB));
  5844. /* WaDisable_RenderCache_OperationalFlush:snb */
  5845. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  5846. /*
  5847. * BSpec recoomends 8x4 when MSAA is used,
  5848. * however in practice 16x4 seems fastest.
  5849. *
  5850. * Note that PS/WM thread counts depend on the WIZ hashing
  5851. * disable bit, which we don't touch here, but it's good
  5852. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  5853. */
  5854. I915_WRITE(GEN6_GT_MODE,
  5855. _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
  5856. ilk_init_lp_watermarks(dev);
  5857. I915_WRITE(CACHE_MODE_0,
  5858. _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB));
  5859. I915_WRITE(GEN6_UCGCTL1,
  5860. I915_READ(GEN6_UCGCTL1) |
  5861. GEN6_BLBUNIT_CLOCK_GATE_DISABLE |
  5862. GEN6_CSUNIT_CLOCK_GATE_DISABLE);
  5863. /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
  5864. * gating disable must be set. Failure to set it results in
  5865. * flickering pixels due to Z write ordering failures after
  5866. * some amount of runtime in the Mesa "fire" demo, and Unigine
  5867. * Sanctuary and Tropics, and apparently anything else with
  5868. * alpha test or pixel discard.
  5869. *
  5870. * According to the spec, bit 11 (RCCUNIT) must also be set,
  5871. * but we didn't debug actual testcases to find it out.
  5872. *
  5873. * WaDisableRCCUnitClockGating:snb
  5874. * WaDisableRCPBUnitClockGating:snb
  5875. */
  5876. I915_WRITE(GEN6_UCGCTL2,
  5877. GEN6_RCPBUNIT_CLOCK_GATE_DISABLE |
  5878. GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
  5879. /* WaStripsFansDisableFastClipPerformanceFix:snb */
  5880. I915_WRITE(_3D_CHICKEN3,
  5881. _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL));
  5882. /*
  5883. * Bspec says:
  5884. * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and
  5885. * 3DSTATE_SF number of SF output attributes is more than 16."
  5886. */
  5887. I915_WRITE(_3D_CHICKEN3,
  5888. _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH));
  5889. /*
  5890. * According to the spec the following bits should be
  5891. * set in order to enable memory self-refresh and fbc:
  5892. * The bit21 and bit22 of 0x42000
  5893. * The bit21 and bit22 of 0x42004
  5894. * The bit5 and bit7 of 0x42020
  5895. * The bit14 of 0x70180
  5896. * The bit14 of 0x71180
  5897. *
  5898. * WaFbcAsynchFlipDisableFbcQueue:snb
  5899. */
  5900. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  5901. I915_READ(ILK_DISPLAY_CHICKEN1) |
  5902. ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
  5903. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  5904. I915_READ(ILK_DISPLAY_CHICKEN2) |
  5905. ILK_DPARB_GATE | ILK_VSDPFD_FULL);
  5906. I915_WRITE(ILK_DSPCLK_GATE_D,
  5907. I915_READ(ILK_DSPCLK_GATE_D) |
  5908. ILK_DPARBUNIT_CLOCK_GATE_ENABLE |
  5909. ILK_DPFDUNIT_CLOCK_GATE_ENABLE);
  5910. g4x_disable_trickle_feed(dev);
  5911. cpt_init_clock_gating(dev);
  5912. gen6_check_mch_setup(dev);
  5913. }
  5914. static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv)
  5915. {
  5916. uint32_t reg = I915_READ(GEN7_FF_THREAD_MODE);
  5917. /*
  5918. * WaVSThreadDispatchOverride:ivb,vlv
  5919. *
  5920. * This actually overrides the dispatch
  5921. * mode for all thread types.
  5922. */
  5923. reg &= ~GEN7_FF_SCHED_MASK;
  5924. reg |= GEN7_FF_TS_SCHED_HW;
  5925. reg |= GEN7_FF_VS_SCHED_HW;
  5926. reg |= GEN7_FF_DS_SCHED_HW;
  5927. I915_WRITE(GEN7_FF_THREAD_MODE, reg);
  5928. }
  5929. static void lpt_init_clock_gating(struct drm_device *dev)
  5930. {
  5931. struct drm_i915_private *dev_priv = to_i915(dev);
  5932. /*
  5933. * TODO: this bit should only be enabled when really needed, then
  5934. * disabled when not needed anymore in order to save power.
  5935. */
  5936. if (HAS_PCH_LPT_LP(dev))
  5937. I915_WRITE(SOUTH_DSPCLK_GATE_D,
  5938. I915_READ(SOUTH_DSPCLK_GATE_D) |
  5939. PCH_LP_PARTITION_LEVEL_DISABLE);
  5940. /* WADPOClockGatingDisable:hsw */
  5941. I915_WRITE(TRANS_CHICKEN1(PIPE_A),
  5942. I915_READ(TRANS_CHICKEN1(PIPE_A)) |
  5943. TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
  5944. }
  5945. static void lpt_suspend_hw(struct drm_device *dev)
  5946. {
  5947. struct drm_i915_private *dev_priv = to_i915(dev);
  5948. if (HAS_PCH_LPT_LP(dev)) {
  5949. uint32_t val = I915_READ(SOUTH_DSPCLK_GATE_D);
  5950. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  5951. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  5952. }
  5953. }
  5954. static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv,
  5955. int general_prio_credits,
  5956. int high_prio_credits)
  5957. {
  5958. u32 misccpctl;
  5959. /* WaTempDisableDOPClkGating:bdw */
  5960. misccpctl = I915_READ(GEN7_MISCCPCTL);
  5961. I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
  5962. I915_WRITE(GEN8_L3SQCREG1,
  5963. L3_GENERAL_PRIO_CREDITS(general_prio_credits) |
  5964. L3_HIGH_PRIO_CREDITS(high_prio_credits));
  5965. /*
  5966. * Wait at least 100 clocks before re-enabling clock gating.
  5967. * See the definition of L3SQCREG1 in BSpec.
  5968. */
  5969. POSTING_READ(GEN8_L3SQCREG1);
  5970. udelay(1);
  5971. I915_WRITE(GEN7_MISCCPCTL, misccpctl);
  5972. }
  5973. static void kabylake_init_clock_gating(struct drm_device *dev)
  5974. {
  5975. struct drm_i915_private *dev_priv = dev->dev_private;
  5976. gen9_init_clock_gating(dev);
  5977. /* WaDisableSDEUnitClockGating:kbl */
  5978. if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0))
  5979. I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
  5980. GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  5981. /* WaDisableGamClockGating:kbl */
  5982. if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0))
  5983. I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) |
  5984. GEN6_GAMUNIT_CLOCK_GATE_DISABLE);
  5985. /* WaFbcNukeOnHostModify:kbl */
  5986. I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
  5987. ILK_DPFC_NUKE_ON_ANY_MODIFICATION);
  5988. }
  5989. static void skylake_init_clock_gating(struct drm_device *dev)
  5990. {
  5991. struct drm_i915_private *dev_priv = dev->dev_private;
  5992. gen9_init_clock_gating(dev);
  5993. /* WAC6entrylatency:skl */
  5994. I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) |
  5995. FBC_LLC_FULLY_OPEN);
  5996. /* WaFbcNukeOnHostModify:skl */
  5997. I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
  5998. ILK_DPFC_NUKE_ON_ANY_MODIFICATION);
  5999. }
  6000. static void broadwell_init_clock_gating(struct drm_device *dev)
  6001. {
  6002. struct drm_i915_private *dev_priv = to_i915(dev);
  6003. enum pipe pipe;
  6004. ilk_init_lp_watermarks(dev);
  6005. /* WaSwitchSolVfFArbitrationPriority:bdw */
  6006. I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
  6007. /* WaPsrDPAMaskVBlankInSRD:bdw */
  6008. I915_WRITE(CHICKEN_PAR1_1,
  6009. I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD);
  6010. /* WaPsrDPRSUnmaskVBlankInSRD:bdw */
  6011. for_each_pipe(dev_priv, pipe) {
  6012. I915_WRITE(CHICKEN_PIPESL_1(pipe),
  6013. I915_READ(CHICKEN_PIPESL_1(pipe)) |
  6014. BDW_DPRS_MASK_VBLANK_SRD);
  6015. }
  6016. /* WaVSRefCountFullforceMissDisable:bdw */
  6017. /* WaDSRefCountFullforceMissDisable:bdw */
  6018. I915_WRITE(GEN7_FF_THREAD_MODE,
  6019. I915_READ(GEN7_FF_THREAD_MODE) &
  6020. ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
  6021. I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL,
  6022. _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
  6023. /* WaDisableSDEUnitClockGating:bdw */
  6024. I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
  6025. GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  6026. /* WaProgramL3SqcReg1Default:bdw */
  6027. gen8_set_l3sqc_credits(dev_priv, 30, 2);
  6028. /*
  6029. * WaGttCachingOffByDefault:bdw
  6030. * GTT cache may not work with big pages, so if those
  6031. * are ever enabled GTT cache may need to be disabled.
  6032. */
  6033. I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL);
  6034. /* WaKVMNotificationOnConfigChange:bdw */
  6035. I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1)
  6036. | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT);
  6037. lpt_init_clock_gating(dev);
  6038. }
  6039. static void haswell_init_clock_gating(struct drm_device *dev)
  6040. {
  6041. struct drm_i915_private *dev_priv = to_i915(dev);
  6042. ilk_init_lp_watermarks(dev);
  6043. /* L3 caching of data atomics doesn't work -- disable it. */
  6044. I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE);
  6045. I915_WRITE(HSW_ROW_CHICKEN3,
  6046. _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE));
  6047. /* This is required by WaCatErrorRejectionIssue:hsw */
  6048. I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  6049. I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
  6050. GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  6051. /* WaVSRefCountFullforceMissDisable:hsw */
  6052. I915_WRITE(GEN7_FF_THREAD_MODE,
  6053. I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME);
  6054. /* WaDisable_RenderCache_OperationalFlush:hsw */
  6055. I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  6056. /* enable HiZ Raw Stall Optimization */
  6057. I915_WRITE(CACHE_MODE_0_GEN7,
  6058. _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE));
  6059. /* WaDisable4x2SubspanOptimization:hsw */
  6060. I915_WRITE(CACHE_MODE_1,
  6061. _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
  6062. /*
  6063. * BSpec recommends 8x4 when MSAA is used,
  6064. * however in practice 16x4 seems fastest.
  6065. *
  6066. * Note that PS/WM thread counts depend on the WIZ hashing
  6067. * disable bit, which we don't touch here, but it's good
  6068. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  6069. */
  6070. I915_WRITE(GEN7_GT_MODE,
  6071. _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
  6072. /* WaSampleCChickenBitEnable:hsw */
  6073. I915_WRITE(HALF_SLICE_CHICKEN3,
  6074. _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE));
  6075. /* WaSwitchSolVfFArbitrationPriority:hsw */
  6076. I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
  6077. /* WaRsPkgCStateDisplayPMReq:hsw */
  6078. I915_WRITE(CHICKEN_PAR1_1,
  6079. I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
  6080. lpt_init_clock_gating(dev);
  6081. }
  6082. static void ivybridge_init_clock_gating(struct drm_device *dev)
  6083. {
  6084. struct drm_i915_private *dev_priv = to_i915(dev);
  6085. uint32_t snpcr;
  6086. ilk_init_lp_watermarks(dev);
  6087. I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE);
  6088. /* WaDisableEarlyCull:ivb */
  6089. I915_WRITE(_3D_CHICKEN3,
  6090. _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL));
  6091. /* WaDisableBackToBackFlipFix:ivb */
  6092. I915_WRITE(IVB_CHICKEN3,
  6093. CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
  6094. CHICKEN3_DGMG_DONE_FIX_DISABLE);
  6095. /* WaDisablePSDDualDispatchEnable:ivb */
  6096. if (IS_IVB_GT1(dev))
  6097. I915_WRITE(GEN7_HALF_SLICE_CHICKEN1,
  6098. _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE));
  6099. /* WaDisable_RenderCache_OperationalFlush:ivb */
  6100. I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  6101. /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */
  6102. I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1,
  6103. GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC);
  6104. /* WaApplyL3ControlAndL3ChickenMode:ivb */
  6105. I915_WRITE(GEN7_L3CNTLREG1,
  6106. GEN7_WA_FOR_GEN7_L3_CONTROL);
  6107. I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER,
  6108. GEN7_WA_L3_CHICKEN_MODE);
  6109. if (IS_IVB_GT1(dev))
  6110. I915_WRITE(GEN7_ROW_CHICKEN2,
  6111. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  6112. else {
  6113. /* must write both registers */
  6114. I915_WRITE(GEN7_ROW_CHICKEN2,
  6115. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  6116. I915_WRITE(GEN7_ROW_CHICKEN2_GT2,
  6117. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  6118. }
  6119. /* WaForceL3Serialization:ivb */
  6120. I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) &
  6121. ~L3SQ_URB_READ_CAM_MATCH_DISABLE);
  6122. /*
  6123. * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
  6124. * This implements the WaDisableRCZUnitClockGating:ivb workaround.
  6125. */
  6126. I915_WRITE(GEN6_UCGCTL2,
  6127. GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
  6128. /* This is required by WaCatErrorRejectionIssue:ivb */
  6129. I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  6130. I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
  6131. GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  6132. g4x_disable_trickle_feed(dev);
  6133. gen7_setup_fixed_func_scheduler(dev_priv);
  6134. if (0) { /* causes HiZ corruption on ivb:gt1 */
  6135. /* enable HiZ Raw Stall Optimization */
  6136. I915_WRITE(CACHE_MODE_0_GEN7,
  6137. _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE));
  6138. }
  6139. /* WaDisable4x2SubspanOptimization:ivb */
  6140. I915_WRITE(CACHE_MODE_1,
  6141. _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
  6142. /*
  6143. * BSpec recommends 8x4 when MSAA is used,
  6144. * however in practice 16x4 seems fastest.
  6145. *
  6146. * Note that PS/WM thread counts depend on the WIZ hashing
  6147. * disable bit, which we don't touch here, but it's good
  6148. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  6149. */
  6150. I915_WRITE(GEN7_GT_MODE,
  6151. _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
  6152. snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
  6153. snpcr &= ~GEN6_MBC_SNPCR_MASK;
  6154. snpcr |= GEN6_MBC_SNPCR_MED;
  6155. I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
  6156. if (!HAS_PCH_NOP(dev))
  6157. cpt_init_clock_gating(dev);
  6158. gen6_check_mch_setup(dev);
  6159. }
  6160. static void valleyview_init_clock_gating(struct drm_device *dev)
  6161. {
  6162. struct drm_i915_private *dev_priv = to_i915(dev);
  6163. /* WaDisableEarlyCull:vlv */
  6164. I915_WRITE(_3D_CHICKEN3,
  6165. _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL));
  6166. /* WaDisableBackToBackFlipFix:vlv */
  6167. I915_WRITE(IVB_CHICKEN3,
  6168. CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
  6169. CHICKEN3_DGMG_DONE_FIX_DISABLE);
  6170. /* WaPsdDispatchEnable:vlv */
  6171. /* WaDisablePSDDualDispatchEnable:vlv */
  6172. I915_WRITE(GEN7_HALF_SLICE_CHICKEN1,
  6173. _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP |
  6174. GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE));
  6175. /* WaDisable_RenderCache_OperationalFlush:vlv */
  6176. I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  6177. /* WaForceL3Serialization:vlv */
  6178. I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) &
  6179. ~L3SQ_URB_READ_CAM_MATCH_DISABLE);
  6180. /* WaDisableDopClockGating:vlv */
  6181. I915_WRITE(GEN7_ROW_CHICKEN2,
  6182. _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
  6183. /* This is required by WaCatErrorRejectionIssue:vlv */
  6184. I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
  6185. I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
  6186. GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
  6187. gen7_setup_fixed_func_scheduler(dev_priv);
  6188. /*
  6189. * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
  6190. * This implements the WaDisableRCZUnitClockGating:vlv workaround.
  6191. */
  6192. I915_WRITE(GEN6_UCGCTL2,
  6193. GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
  6194. /* WaDisableL3Bank2xClockGate:vlv
  6195. * Disabling L3 clock gating- MMIO 940c[25] = 1
  6196. * Set bit 25, to disable L3_BANK_2x_CLK_GATING */
  6197. I915_WRITE(GEN7_UCGCTL4,
  6198. I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE);
  6199. /*
  6200. * BSpec says this must be set, even though
  6201. * WaDisable4x2SubspanOptimization isn't listed for VLV.
  6202. */
  6203. I915_WRITE(CACHE_MODE_1,
  6204. _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
  6205. /*
  6206. * BSpec recommends 8x4 when MSAA is used,
  6207. * however in practice 16x4 seems fastest.
  6208. *
  6209. * Note that PS/WM thread counts depend on the WIZ hashing
  6210. * disable bit, which we don't touch here, but it's good
  6211. * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
  6212. */
  6213. I915_WRITE(GEN7_GT_MODE,
  6214. _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
  6215. /*
  6216. * WaIncreaseL3CreditsForVLVB0:vlv
  6217. * This is the hardware default actually.
  6218. */
  6219. I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE);
  6220. /*
  6221. * WaDisableVLVClockGating_VBIIssue:vlv
  6222. * Disable clock gating on th GCFG unit to prevent a delay
  6223. * in the reporting of vblank events.
  6224. */
  6225. I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS);
  6226. }
  6227. static void cherryview_init_clock_gating(struct drm_device *dev)
  6228. {
  6229. struct drm_i915_private *dev_priv = to_i915(dev);
  6230. /* WaVSRefCountFullforceMissDisable:chv */
  6231. /* WaDSRefCountFullforceMissDisable:chv */
  6232. I915_WRITE(GEN7_FF_THREAD_MODE,
  6233. I915_READ(GEN7_FF_THREAD_MODE) &
  6234. ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
  6235. /* WaDisableSemaphoreAndSyncFlipWait:chv */
  6236. I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL,
  6237. _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
  6238. /* WaDisableCSUnitClockGating:chv */
  6239. I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) |
  6240. GEN6_CSUNIT_CLOCK_GATE_DISABLE);
  6241. /* WaDisableSDEUnitClockGating:chv */
  6242. I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
  6243. GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
  6244. /*
  6245. * WaProgramL3SqcReg1Default:chv
  6246. * See gfxspecs/Related Documents/Performance Guide/
  6247. * LSQC Setting Recommendations.
  6248. */
  6249. gen8_set_l3sqc_credits(dev_priv, 38, 2);
  6250. /*
  6251. * GTT cache may not work with big pages, so if those
  6252. * are ever enabled GTT cache may need to be disabled.
  6253. */
  6254. I915_WRITE(HSW_GTT_CACHE_EN, GTT_CACHE_EN_ALL);
  6255. }
  6256. static void g4x_init_clock_gating(struct drm_device *dev)
  6257. {
  6258. struct drm_i915_private *dev_priv = to_i915(dev);
  6259. uint32_t dspclk_gate;
  6260. I915_WRITE(RENCLK_GATE_D1, 0);
  6261. I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  6262. GS_UNIT_CLOCK_GATE_DISABLE |
  6263. CL_UNIT_CLOCK_GATE_DISABLE);
  6264. I915_WRITE(RAMCLK_GATE_D, 0);
  6265. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  6266. OVRUNIT_CLOCK_GATE_DISABLE |
  6267. OVCUNIT_CLOCK_GATE_DISABLE;
  6268. if (IS_GM45(dev))
  6269. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  6270. I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
  6271. /* WaDisableRenderCachePipelinedFlush */
  6272. I915_WRITE(CACHE_MODE_0,
  6273. _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE));
  6274. /* WaDisable_RenderCache_OperationalFlush:g4x */
  6275. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  6276. g4x_disable_trickle_feed(dev);
  6277. }
  6278. static void crestline_init_clock_gating(struct drm_device *dev)
  6279. {
  6280. struct drm_i915_private *dev_priv = to_i915(dev);
  6281. I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  6282. I915_WRITE(RENCLK_GATE_D2, 0);
  6283. I915_WRITE(DSPCLK_GATE_D, 0);
  6284. I915_WRITE(RAMCLK_GATE_D, 0);
  6285. I915_WRITE16(DEUC, 0);
  6286. I915_WRITE(MI_ARB_STATE,
  6287. _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
  6288. /* WaDisable_RenderCache_OperationalFlush:gen4 */
  6289. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  6290. }
  6291. static void broadwater_init_clock_gating(struct drm_device *dev)
  6292. {
  6293. struct drm_i915_private *dev_priv = to_i915(dev);
  6294. I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  6295. I965_RCC_CLOCK_GATE_DISABLE |
  6296. I965_RCPB_CLOCK_GATE_DISABLE |
  6297. I965_ISC_CLOCK_GATE_DISABLE |
  6298. I965_FBC_CLOCK_GATE_DISABLE);
  6299. I915_WRITE(RENCLK_GATE_D2, 0);
  6300. I915_WRITE(MI_ARB_STATE,
  6301. _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
  6302. /* WaDisable_RenderCache_OperationalFlush:gen4 */
  6303. I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
  6304. }
  6305. static void gen3_init_clock_gating(struct drm_device *dev)
  6306. {
  6307. struct drm_i915_private *dev_priv = to_i915(dev);
  6308. u32 dstate = I915_READ(D_STATE);
  6309. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  6310. DSTATE_DOT_CLOCK_GATING;
  6311. I915_WRITE(D_STATE, dstate);
  6312. if (IS_PINEVIEW(dev))
  6313. I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY));
  6314. /* IIR "flip pending" means done if this bit is set */
  6315. I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE));
  6316. /* interrupts should cause a wake up from C3 */
  6317. I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN));
  6318. /* On GEN3 we really need to make sure the ARB C3 LP bit is set */
  6319. I915_WRITE(MI_ARB_STATE, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE));
  6320. I915_WRITE(MI_ARB_STATE,
  6321. _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
  6322. }
  6323. static void i85x_init_clock_gating(struct drm_device *dev)
  6324. {
  6325. struct drm_i915_private *dev_priv = to_i915(dev);
  6326. I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  6327. /* interrupts should cause a wake up from C3 */
  6328. I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) |
  6329. _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE));
  6330. I915_WRITE(MEM_MODE,
  6331. _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE));
  6332. }
  6333. static void i830_init_clock_gating(struct drm_device *dev)
  6334. {
  6335. struct drm_i915_private *dev_priv = to_i915(dev);
  6336. I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
  6337. I915_WRITE(MEM_MODE,
  6338. _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) |
  6339. _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE));
  6340. }
  6341. void intel_init_clock_gating(struct drm_device *dev)
  6342. {
  6343. struct drm_i915_private *dev_priv = to_i915(dev);
  6344. dev_priv->display.init_clock_gating(dev);
  6345. }
  6346. void intel_suspend_hw(struct drm_device *dev)
  6347. {
  6348. if (HAS_PCH_LPT(dev))
  6349. lpt_suspend_hw(dev);
  6350. }
  6351. static void nop_init_clock_gating(struct drm_device *dev)
  6352. {
  6353. DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n");
  6354. }
  6355. /**
  6356. * intel_init_clock_gating_hooks - setup the clock gating hooks
  6357. * @dev_priv: device private
  6358. *
  6359. * Setup the hooks that configure which clocks of a given platform can be
  6360. * gated and also apply various GT and display specific workarounds for these
  6361. * platforms. Note that some GT specific workarounds are applied separately
  6362. * when GPU contexts or batchbuffers start their execution.
  6363. */
  6364. void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv)
  6365. {
  6366. if (IS_SKYLAKE(dev_priv))
  6367. dev_priv->display.init_clock_gating = skylake_init_clock_gating;
  6368. else if (IS_KABYLAKE(dev_priv))
  6369. dev_priv->display.init_clock_gating = kabylake_init_clock_gating;
  6370. else if (IS_BROXTON(dev_priv))
  6371. dev_priv->display.init_clock_gating = bxt_init_clock_gating;
  6372. else if (IS_BROADWELL(dev_priv))
  6373. dev_priv->display.init_clock_gating = broadwell_init_clock_gating;
  6374. else if (IS_CHERRYVIEW(dev_priv))
  6375. dev_priv->display.init_clock_gating = cherryview_init_clock_gating;
  6376. else if (IS_HASWELL(dev_priv))
  6377. dev_priv->display.init_clock_gating = haswell_init_clock_gating;
  6378. else if (IS_IVYBRIDGE(dev_priv))
  6379. dev_priv->display.init_clock_gating = ivybridge_init_clock_gating;
  6380. else if (IS_VALLEYVIEW(dev_priv))
  6381. dev_priv->display.init_clock_gating = valleyview_init_clock_gating;
  6382. else if (IS_GEN6(dev_priv))
  6383. dev_priv->display.init_clock_gating = gen6_init_clock_gating;
  6384. else if (IS_GEN5(dev_priv))
  6385. dev_priv->display.init_clock_gating = ironlake_init_clock_gating;
  6386. else if (IS_G4X(dev_priv))
  6387. dev_priv->display.init_clock_gating = g4x_init_clock_gating;
  6388. else if (IS_CRESTLINE(dev_priv))
  6389. dev_priv->display.init_clock_gating = crestline_init_clock_gating;
  6390. else if (IS_BROADWATER(dev_priv))
  6391. dev_priv->display.init_clock_gating = broadwater_init_clock_gating;
  6392. else if (IS_GEN3(dev_priv))
  6393. dev_priv->display.init_clock_gating = gen3_init_clock_gating;
  6394. else if (IS_I85X(dev_priv) || IS_I865G(dev_priv))
  6395. dev_priv->display.init_clock_gating = i85x_init_clock_gating;
  6396. else if (IS_GEN2(dev_priv))
  6397. dev_priv->display.init_clock_gating = i830_init_clock_gating;
  6398. else {
  6399. MISSING_CASE(INTEL_DEVID(dev_priv));
  6400. dev_priv->display.init_clock_gating = nop_init_clock_gating;
  6401. }
  6402. }
  6403. /* Set up chip specific power management-related functions */
  6404. void intel_init_pm(struct drm_device *dev)
  6405. {
  6406. struct drm_i915_private *dev_priv = to_i915(dev);
  6407. intel_fbc_init(dev_priv);
  6408. /* For cxsr */
  6409. if (IS_PINEVIEW(dev))
  6410. i915_pineview_get_mem_freq(dev);
  6411. else if (IS_GEN5(dev))
  6412. i915_ironlake_get_mem_freq(dev);
  6413. /* For FIFO watermark updates */
  6414. if (INTEL_INFO(dev)->gen >= 9) {
  6415. skl_setup_wm_latency(dev);
  6416. dev_priv->display.update_wm = skl_update_wm;
  6417. dev_priv->display.compute_global_watermarks = skl_compute_wm;
  6418. } else if (HAS_PCH_SPLIT(dev)) {
  6419. ilk_setup_wm_latency(dev);
  6420. if ((IS_GEN5(dev) && dev_priv->wm.pri_latency[1] &&
  6421. dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) ||
  6422. (!IS_GEN5(dev) && dev_priv->wm.pri_latency[0] &&
  6423. dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) {
  6424. dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm;
  6425. dev_priv->display.compute_intermediate_wm =
  6426. ilk_compute_intermediate_wm;
  6427. dev_priv->display.initial_watermarks =
  6428. ilk_initial_watermarks;
  6429. dev_priv->display.optimize_watermarks =
  6430. ilk_optimize_watermarks;
  6431. } else {
  6432. DRM_DEBUG_KMS("Failed to read display plane latency. "
  6433. "Disable CxSR\n");
  6434. }
  6435. } else if (IS_CHERRYVIEW(dev)) {
  6436. vlv_setup_wm_latency(dev);
  6437. dev_priv->display.update_wm = vlv_update_wm;
  6438. } else if (IS_VALLEYVIEW(dev)) {
  6439. vlv_setup_wm_latency(dev);
  6440. dev_priv->display.update_wm = vlv_update_wm;
  6441. } else if (IS_PINEVIEW(dev)) {
  6442. if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev),
  6443. dev_priv->is_ddr3,
  6444. dev_priv->fsb_freq,
  6445. dev_priv->mem_freq)) {
  6446. DRM_INFO("failed to find known CxSR latency "
  6447. "(found ddr%s fsb freq %d, mem freq %d), "
  6448. "disabling CxSR\n",
  6449. (dev_priv->is_ddr3 == 1) ? "3" : "2",
  6450. dev_priv->fsb_freq, dev_priv->mem_freq);
  6451. /* Disable CxSR and never update its watermark again */
  6452. intel_set_memory_cxsr(dev_priv, false);
  6453. dev_priv->display.update_wm = NULL;
  6454. } else
  6455. dev_priv->display.update_wm = pineview_update_wm;
  6456. } else if (IS_G4X(dev)) {
  6457. dev_priv->display.update_wm = g4x_update_wm;
  6458. } else if (IS_GEN4(dev)) {
  6459. dev_priv->display.update_wm = i965_update_wm;
  6460. } else if (IS_GEN3(dev)) {
  6461. dev_priv->display.update_wm = i9xx_update_wm;
  6462. dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
  6463. } else if (IS_GEN2(dev)) {
  6464. if (INTEL_INFO(dev)->num_pipes == 1) {
  6465. dev_priv->display.update_wm = i845_update_wm;
  6466. dev_priv->display.get_fifo_size = i845_get_fifo_size;
  6467. } else {
  6468. dev_priv->display.update_wm = i9xx_update_wm;
  6469. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  6470. }
  6471. } else {
  6472. DRM_ERROR("unexpected fall-through in intel_init_pm\n");
  6473. }
  6474. }
  6475. static inline int gen6_check_mailbox_status(struct drm_i915_private *dev_priv)
  6476. {
  6477. uint32_t flags =
  6478. I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK;
  6479. switch (flags) {
  6480. case GEN6_PCODE_SUCCESS:
  6481. return 0;
  6482. case GEN6_PCODE_UNIMPLEMENTED_CMD:
  6483. case GEN6_PCODE_ILLEGAL_CMD:
  6484. return -ENXIO;
  6485. case GEN6_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE:
  6486. case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE:
  6487. return -EOVERFLOW;
  6488. case GEN6_PCODE_TIMEOUT:
  6489. return -ETIMEDOUT;
  6490. default:
  6491. MISSING_CASE(flags)
  6492. return 0;
  6493. }
  6494. }
  6495. static inline int gen7_check_mailbox_status(struct drm_i915_private *dev_priv)
  6496. {
  6497. uint32_t flags =
  6498. I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_ERROR_MASK;
  6499. switch (flags) {
  6500. case GEN6_PCODE_SUCCESS:
  6501. return 0;
  6502. case GEN6_PCODE_ILLEGAL_CMD:
  6503. return -ENXIO;
  6504. case GEN7_PCODE_TIMEOUT:
  6505. return -ETIMEDOUT;
  6506. case GEN7_PCODE_ILLEGAL_DATA:
  6507. return -EINVAL;
  6508. case GEN7_PCODE_MIN_FREQ_TABLE_GT_RATIO_OUT_OF_RANGE:
  6509. return -EOVERFLOW;
  6510. default:
  6511. MISSING_CASE(flags);
  6512. return 0;
  6513. }
  6514. }
  6515. int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val)
  6516. {
  6517. int status;
  6518. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  6519. /* GEN6_PCODE_* are outside of the forcewake domain, we can
  6520. * use te fw I915_READ variants to reduce the amount of work
  6521. * required when reading/writing.
  6522. */
  6523. if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) {
  6524. DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n");
  6525. return -EAGAIN;
  6526. }
  6527. I915_WRITE_FW(GEN6_PCODE_DATA, *val);
  6528. I915_WRITE_FW(GEN6_PCODE_DATA1, 0);
  6529. I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox);
  6530. if (intel_wait_for_register_fw(dev_priv,
  6531. GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0,
  6532. 500)) {
  6533. DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox);
  6534. return -ETIMEDOUT;
  6535. }
  6536. *val = I915_READ_FW(GEN6_PCODE_DATA);
  6537. I915_WRITE_FW(GEN6_PCODE_DATA, 0);
  6538. if (INTEL_GEN(dev_priv) > 6)
  6539. status = gen7_check_mailbox_status(dev_priv);
  6540. else
  6541. status = gen6_check_mailbox_status(dev_priv);
  6542. if (status) {
  6543. DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed: %d\n",
  6544. status);
  6545. return status;
  6546. }
  6547. return 0;
  6548. }
  6549. int sandybridge_pcode_write_timeout(struct drm_i915_private *dev_priv,
  6550. u32 mbox, u32 val, int timeout_us)
  6551. {
  6552. int status;
  6553. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  6554. /* GEN6_PCODE_* are outside of the forcewake domain, we can
  6555. * use te fw I915_READ variants to reduce the amount of work
  6556. * required when reading/writing.
  6557. */
  6558. if (I915_READ_FW(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) {
  6559. DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n");
  6560. return -EAGAIN;
  6561. }
  6562. I915_WRITE_FW(GEN6_PCODE_DATA, val);
  6563. I915_WRITE_FW(GEN6_PCODE_MAILBOX, GEN6_PCODE_READY | mbox);
  6564. if (intel_wait_for_register_fw(dev_priv,
  6565. GEN6_PCODE_MAILBOX, GEN6_PCODE_READY, 0,
  6566. timeout_us)) {
  6567. DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox);
  6568. return -ETIMEDOUT;
  6569. }
  6570. I915_WRITE_FW(GEN6_PCODE_DATA, 0);
  6571. if (INTEL_GEN(dev_priv) > 6)
  6572. status = gen7_check_mailbox_status(dev_priv);
  6573. else
  6574. status = gen6_check_mailbox_status(dev_priv);
  6575. if (status) {
  6576. DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed: %d\n",
  6577. status);
  6578. return status;
  6579. }
  6580. return 0;
  6581. }
  6582. static bool skl_pcode_try_request(struct drm_i915_private *dev_priv, u32 mbox,
  6583. u32 request, u32 reply_mask, u32 reply,
  6584. u32 *status)
  6585. {
  6586. u32 val = request;
  6587. *status = sandybridge_pcode_read(dev_priv, mbox, &val);
  6588. return *status || ((val & reply_mask) == reply);
  6589. }
  6590. /**
  6591. * skl_pcode_request - send PCODE request until acknowledgment
  6592. * @dev_priv: device private
  6593. * @mbox: PCODE mailbox ID the request is targeted for
  6594. * @request: request ID
  6595. * @reply_mask: mask used to check for request acknowledgment
  6596. * @reply: value used to check for request acknowledgment
  6597. * @timeout_base_ms: timeout for polling with preemption enabled
  6598. *
  6599. * Keep resending the @request to @mbox until PCODE acknowledges it, PCODE
  6600. * reports an error or an overall timeout of @timeout_base_ms+50 ms expires.
  6601. * The request is acknowledged once the PCODE reply dword equals @reply after
  6602. * applying @reply_mask. Polling is first attempted with preemption enabled
  6603. * for @timeout_base_ms and if this times out for another 50 ms with
  6604. * preemption disabled.
  6605. *
  6606. * Returns 0 on success, %-ETIMEDOUT in case of a timeout, <0 in case of some
  6607. * other error as reported by PCODE.
  6608. */
  6609. int skl_pcode_request(struct drm_i915_private *dev_priv, u32 mbox, u32 request,
  6610. u32 reply_mask, u32 reply, int timeout_base_ms)
  6611. {
  6612. u32 status;
  6613. int ret;
  6614. WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
  6615. #define COND skl_pcode_try_request(dev_priv, mbox, request, reply_mask, reply, \
  6616. &status)
  6617. /*
  6618. * Prime the PCODE by doing a request first. Normally it guarantees
  6619. * that a subsequent request, at most @timeout_base_ms later, succeeds.
  6620. * _wait_for() doesn't guarantee when its passed condition is evaluated
  6621. * first, so send the first request explicitly.
  6622. */
  6623. if (COND) {
  6624. ret = 0;
  6625. goto out;
  6626. }
  6627. ret = _wait_for(COND, timeout_base_ms * 1000, 10);
  6628. if (!ret)
  6629. goto out;
  6630. /*
  6631. * The above can time out if the number of requests was low (2 in the
  6632. * worst case) _and_ PCODE was busy for some reason even after a
  6633. * (queued) request and @timeout_base_ms delay. As a workaround retry
  6634. * the poll with preemption disabled to maximize the number of
  6635. * requests. Increase the timeout from @timeout_base_ms to 50ms to
  6636. * account for interrupts that could reduce the number of these
  6637. * requests, and for any quirks of the PCODE firmware that delays
  6638. * the request completion.
  6639. */
  6640. DRM_DEBUG_KMS("PCODE timeout, retrying with preemption disabled\n");
  6641. WARN_ON_ONCE(timeout_base_ms > 3);
  6642. preempt_disable();
  6643. ret = wait_for_atomic(COND, 50);
  6644. preempt_enable();
  6645. out:
  6646. return ret ? ret : status;
  6647. #undef COND
  6648. }
  6649. static int byt_gpu_freq(struct drm_i915_private *dev_priv, int val)
  6650. {
  6651. /*
  6652. * N = val - 0xb7
  6653. * Slow = Fast = GPLL ref * N
  6654. */
  6655. return DIV_ROUND_CLOSEST(dev_priv->rps.gpll_ref_freq * (val - 0xb7), 1000);
  6656. }
  6657. static int byt_freq_opcode(struct drm_i915_private *dev_priv, int val)
  6658. {
  6659. return DIV_ROUND_CLOSEST(1000 * val, dev_priv->rps.gpll_ref_freq) + 0xb7;
  6660. }
  6661. static int chv_gpu_freq(struct drm_i915_private *dev_priv, int val)
  6662. {
  6663. /*
  6664. * N = val / 2
  6665. * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2
  6666. */
  6667. return DIV_ROUND_CLOSEST(dev_priv->rps.gpll_ref_freq * val, 2 * 2 * 1000);
  6668. }
  6669. static int chv_freq_opcode(struct drm_i915_private *dev_priv, int val)
  6670. {
  6671. /* CHV needs even values */
  6672. return DIV_ROUND_CLOSEST(2 * 1000 * val, dev_priv->rps.gpll_ref_freq) * 2;
  6673. }
  6674. int intel_gpu_freq(struct drm_i915_private *dev_priv, int val)
  6675. {
  6676. if (IS_GEN9(dev_priv))
  6677. return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER,
  6678. GEN9_FREQ_SCALER);
  6679. else if (IS_CHERRYVIEW(dev_priv))
  6680. return chv_gpu_freq(dev_priv, val);
  6681. else if (IS_VALLEYVIEW(dev_priv))
  6682. return byt_gpu_freq(dev_priv, val);
  6683. else
  6684. return val * GT_FREQUENCY_MULTIPLIER;
  6685. }
  6686. int intel_freq_opcode(struct drm_i915_private *dev_priv, int val)
  6687. {
  6688. if (IS_GEN9(dev_priv))
  6689. return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER,
  6690. GT_FREQUENCY_MULTIPLIER);
  6691. else if (IS_CHERRYVIEW(dev_priv))
  6692. return chv_freq_opcode(dev_priv, val);
  6693. else if (IS_VALLEYVIEW(dev_priv))
  6694. return byt_freq_opcode(dev_priv, val);
  6695. else
  6696. return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER);
  6697. }
  6698. struct request_boost {
  6699. struct work_struct work;
  6700. struct drm_i915_gem_request *req;
  6701. };
  6702. static void __intel_rps_boost_work(struct work_struct *work)
  6703. {
  6704. struct request_boost *boost = container_of(work, struct request_boost, work);
  6705. struct drm_i915_gem_request *req = boost->req;
  6706. if (!i915_gem_request_completed(req))
  6707. gen6_rps_boost(req->i915, NULL, req->emitted_jiffies);
  6708. i915_gem_request_put(req);
  6709. kfree(boost);
  6710. }
  6711. void intel_queue_rps_boost_for_request(struct drm_i915_gem_request *req)
  6712. {
  6713. struct request_boost *boost;
  6714. if (req == NULL || INTEL_GEN(req->i915) < 6)
  6715. return;
  6716. if (i915_gem_request_completed(req))
  6717. return;
  6718. boost = kmalloc(sizeof(*boost), GFP_ATOMIC);
  6719. if (boost == NULL)
  6720. return;
  6721. boost->req = i915_gem_request_get(req);
  6722. INIT_WORK(&boost->work, __intel_rps_boost_work);
  6723. queue_work(req->i915->wq, &boost->work);
  6724. }
  6725. void intel_pm_setup(struct drm_device *dev)
  6726. {
  6727. struct drm_i915_private *dev_priv = to_i915(dev);
  6728. mutex_init(&dev_priv->rps.hw_lock);
  6729. spin_lock_init(&dev_priv->rps.client_lock);
  6730. INIT_DELAYED_WORK(&dev_priv->rps.autoenable_work,
  6731. __intel_autoenable_gt_powersave);
  6732. INIT_LIST_HEAD(&dev_priv->rps.clients);
  6733. dev_priv->pm.suspended = false;
  6734. atomic_set(&dev_priv->pm.wakeref_count, 0);
  6735. atomic_set(&dev_priv->pm.atomic_seq, 0);
  6736. }