intel_display.c 215 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997
  1. /*
  2. * Copyright © 2006-2007 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
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/module.h>
  27. #include <linux/input.h>
  28. #include <linux/i2c.h>
  29. #include <linux/kernel.h>
  30. #include <linux/slab.h>
  31. #include <linux/vgaarb.h>
  32. #include "drmP.h"
  33. #include "intel_drv.h"
  34. #include "i915_drm.h"
  35. #include "i915_drv.h"
  36. #include "i915_trace.h"
  37. #include "drm_dp_helper.h"
  38. #include "drm_crtc_helper.h"
  39. #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  40. bool intel_pipe_has_type (struct drm_crtc *crtc, int type);
  41. static void intel_update_watermarks(struct drm_device *dev);
  42. static void intel_increase_pllclock(struct drm_crtc *crtc);
  43. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  44. typedef struct {
  45. /* given values */
  46. int n;
  47. int m1, m2;
  48. int p1, p2;
  49. /* derived values */
  50. int dot;
  51. int vco;
  52. int m;
  53. int p;
  54. } intel_clock_t;
  55. typedef struct {
  56. int min, max;
  57. } intel_range_t;
  58. typedef struct {
  59. int dot_limit;
  60. int p2_slow, p2_fast;
  61. } intel_p2_t;
  62. #define INTEL_P2_NUM 2
  63. typedef struct intel_limit intel_limit_t;
  64. struct intel_limit {
  65. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  66. intel_p2_t p2;
  67. bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
  68. int, int, intel_clock_t *);
  69. };
  70. /* FDI */
  71. #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
  72. static bool
  73. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  74. int target, int refclk, intel_clock_t *best_clock);
  75. static bool
  76. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  77. int target, int refclk, intel_clock_t *best_clock);
  78. static bool
  79. intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
  80. int target, int refclk, intel_clock_t *best_clock);
  81. static bool
  82. intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc,
  83. int target, int refclk, intel_clock_t *best_clock);
  84. static inline u32 /* units of 100MHz */
  85. intel_fdi_link_freq(struct drm_device *dev)
  86. {
  87. if (IS_GEN5(dev)) {
  88. struct drm_i915_private *dev_priv = dev->dev_private;
  89. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  90. } else
  91. return 27;
  92. }
  93. static const intel_limit_t intel_limits_i8xx_dvo = {
  94. .dot = { .min = 25000, .max = 350000 },
  95. .vco = { .min = 930000, .max = 1400000 },
  96. .n = { .min = 3, .max = 16 },
  97. .m = { .min = 96, .max = 140 },
  98. .m1 = { .min = 18, .max = 26 },
  99. .m2 = { .min = 6, .max = 16 },
  100. .p = { .min = 4, .max = 128 },
  101. .p1 = { .min = 2, .max = 33 },
  102. .p2 = { .dot_limit = 165000,
  103. .p2_slow = 4, .p2_fast = 2 },
  104. .find_pll = intel_find_best_PLL,
  105. };
  106. static const intel_limit_t intel_limits_i8xx_lvds = {
  107. .dot = { .min = 25000, .max = 350000 },
  108. .vco = { .min = 930000, .max = 1400000 },
  109. .n = { .min = 3, .max = 16 },
  110. .m = { .min = 96, .max = 140 },
  111. .m1 = { .min = 18, .max = 26 },
  112. .m2 = { .min = 6, .max = 16 },
  113. .p = { .min = 4, .max = 128 },
  114. .p1 = { .min = 1, .max = 6 },
  115. .p2 = { .dot_limit = 165000,
  116. .p2_slow = 14, .p2_fast = 7 },
  117. .find_pll = intel_find_best_PLL,
  118. };
  119. static const intel_limit_t intel_limits_i9xx_sdvo = {
  120. .dot = { .min = 20000, .max = 400000 },
  121. .vco = { .min = 1400000, .max = 2800000 },
  122. .n = { .min = 1, .max = 6 },
  123. .m = { .min = 70, .max = 120 },
  124. .m1 = { .min = 10, .max = 22 },
  125. .m2 = { .min = 5, .max = 9 },
  126. .p = { .min = 5, .max = 80 },
  127. .p1 = { .min = 1, .max = 8 },
  128. .p2 = { .dot_limit = 200000,
  129. .p2_slow = 10, .p2_fast = 5 },
  130. .find_pll = intel_find_best_PLL,
  131. };
  132. static const intel_limit_t intel_limits_i9xx_lvds = {
  133. .dot = { .min = 20000, .max = 400000 },
  134. .vco = { .min = 1400000, .max = 2800000 },
  135. .n = { .min = 1, .max = 6 },
  136. .m = { .min = 70, .max = 120 },
  137. .m1 = { .min = 10, .max = 22 },
  138. .m2 = { .min = 5, .max = 9 },
  139. .p = { .min = 7, .max = 98 },
  140. .p1 = { .min = 1, .max = 8 },
  141. .p2 = { .dot_limit = 112000,
  142. .p2_slow = 14, .p2_fast = 7 },
  143. .find_pll = intel_find_best_PLL,
  144. };
  145. static const intel_limit_t intel_limits_g4x_sdvo = {
  146. .dot = { .min = 25000, .max = 270000 },
  147. .vco = { .min = 1750000, .max = 3500000},
  148. .n = { .min = 1, .max = 4 },
  149. .m = { .min = 104, .max = 138 },
  150. .m1 = { .min = 17, .max = 23 },
  151. .m2 = { .min = 5, .max = 11 },
  152. .p = { .min = 10, .max = 30 },
  153. .p1 = { .min = 1, .max = 3},
  154. .p2 = { .dot_limit = 270000,
  155. .p2_slow = 10,
  156. .p2_fast = 10
  157. },
  158. .find_pll = intel_g4x_find_best_PLL,
  159. };
  160. static const intel_limit_t intel_limits_g4x_hdmi = {
  161. .dot = { .min = 22000, .max = 400000 },
  162. .vco = { .min = 1750000, .max = 3500000},
  163. .n = { .min = 1, .max = 4 },
  164. .m = { .min = 104, .max = 138 },
  165. .m1 = { .min = 16, .max = 23 },
  166. .m2 = { .min = 5, .max = 11 },
  167. .p = { .min = 5, .max = 80 },
  168. .p1 = { .min = 1, .max = 8},
  169. .p2 = { .dot_limit = 165000,
  170. .p2_slow = 10, .p2_fast = 5 },
  171. .find_pll = intel_g4x_find_best_PLL,
  172. };
  173. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  174. .dot = { .min = 20000, .max = 115000 },
  175. .vco = { .min = 1750000, .max = 3500000 },
  176. .n = { .min = 1, .max = 3 },
  177. .m = { .min = 104, .max = 138 },
  178. .m1 = { .min = 17, .max = 23 },
  179. .m2 = { .min = 5, .max = 11 },
  180. .p = { .min = 28, .max = 112 },
  181. .p1 = { .min = 2, .max = 8 },
  182. .p2 = { .dot_limit = 0,
  183. .p2_slow = 14, .p2_fast = 14
  184. },
  185. .find_pll = intel_g4x_find_best_PLL,
  186. };
  187. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  188. .dot = { .min = 80000, .max = 224000 },
  189. .vco = { .min = 1750000, .max = 3500000 },
  190. .n = { .min = 1, .max = 3 },
  191. .m = { .min = 104, .max = 138 },
  192. .m1 = { .min = 17, .max = 23 },
  193. .m2 = { .min = 5, .max = 11 },
  194. .p = { .min = 14, .max = 42 },
  195. .p1 = { .min = 2, .max = 6 },
  196. .p2 = { .dot_limit = 0,
  197. .p2_slow = 7, .p2_fast = 7
  198. },
  199. .find_pll = intel_g4x_find_best_PLL,
  200. };
  201. static const intel_limit_t intel_limits_g4x_display_port = {
  202. .dot = { .min = 161670, .max = 227000 },
  203. .vco = { .min = 1750000, .max = 3500000},
  204. .n = { .min = 1, .max = 2 },
  205. .m = { .min = 97, .max = 108 },
  206. .m1 = { .min = 0x10, .max = 0x12 },
  207. .m2 = { .min = 0x05, .max = 0x06 },
  208. .p = { .min = 10, .max = 20 },
  209. .p1 = { .min = 1, .max = 2},
  210. .p2 = { .dot_limit = 0,
  211. .p2_slow = 10, .p2_fast = 10 },
  212. .find_pll = intel_find_pll_g4x_dp,
  213. };
  214. static const intel_limit_t intel_limits_pineview_sdvo = {
  215. .dot = { .min = 20000, .max = 400000},
  216. .vco = { .min = 1700000, .max = 3500000 },
  217. /* Pineview's Ncounter is a ring counter */
  218. .n = { .min = 3, .max = 6 },
  219. .m = { .min = 2, .max = 256 },
  220. /* Pineview only has one combined m divider, which we treat as m2. */
  221. .m1 = { .min = 0, .max = 0 },
  222. .m2 = { .min = 0, .max = 254 },
  223. .p = { .min = 5, .max = 80 },
  224. .p1 = { .min = 1, .max = 8 },
  225. .p2 = { .dot_limit = 200000,
  226. .p2_slow = 10, .p2_fast = 5 },
  227. .find_pll = intel_find_best_PLL,
  228. };
  229. static const intel_limit_t intel_limits_pineview_lvds = {
  230. .dot = { .min = 20000, .max = 400000 },
  231. .vco = { .min = 1700000, .max = 3500000 },
  232. .n = { .min = 3, .max = 6 },
  233. .m = { .min = 2, .max = 256 },
  234. .m1 = { .min = 0, .max = 0 },
  235. .m2 = { .min = 0, .max = 254 },
  236. .p = { .min = 7, .max = 112 },
  237. .p1 = { .min = 1, .max = 8 },
  238. .p2 = { .dot_limit = 112000,
  239. .p2_slow = 14, .p2_fast = 14 },
  240. .find_pll = intel_find_best_PLL,
  241. };
  242. /* Ironlake / Sandybridge
  243. *
  244. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  245. * the range value for them is (actual_value - 2).
  246. */
  247. static const intel_limit_t intel_limits_ironlake_dac = {
  248. .dot = { .min = 25000, .max = 350000 },
  249. .vco = { .min = 1760000, .max = 3510000 },
  250. .n = { .min = 1, .max = 5 },
  251. .m = { .min = 79, .max = 127 },
  252. .m1 = { .min = 12, .max = 22 },
  253. .m2 = { .min = 5, .max = 9 },
  254. .p = { .min = 5, .max = 80 },
  255. .p1 = { .min = 1, .max = 8 },
  256. .p2 = { .dot_limit = 225000,
  257. .p2_slow = 10, .p2_fast = 5 },
  258. .find_pll = intel_g4x_find_best_PLL,
  259. };
  260. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  261. .dot = { .min = 25000, .max = 350000 },
  262. .vco = { .min = 1760000, .max = 3510000 },
  263. .n = { .min = 1, .max = 3 },
  264. .m = { .min = 79, .max = 118 },
  265. .m1 = { .min = 12, .max = 22 },
  266. .m2 = { .min = 5, .max = 9 },
  267. .p = { .min = 28, .max = 112 },
  268. .p1 = { .min = 2, .max = 8 },
  269. .p2 = { .dot_limit = 225000,
  270. .p2_slow = 14, .p2_fast = 14 },
  271. .find_pll = intel_g4x_find_best_PLL,
  272. };
  273. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  274. .dot = { .min = 25000, .max = 350000 },
  275. .vco = { .min = 1760000, .max = 3510000 },
  276. .n = { .min = 1, .max = 3 },
  277. .m = { .min = 79, .max = 127 },
  278. .m1 = { .min = 12, .max = 22 },
  279. .m2 = { .min = 5, .max = 9 },
  280. .p = { .min = 14, .max = 56 },
  281. .p1 = { .min = 2, .max = 8 },
  282. .p2 = { .dot_limit = 225000,
  283. .p2_slow = 7, .p2_fast = 7 },
  284. .find_pll = intel_g4x_find_best_PLL,
  285. };
  286. /* LVDS 100mhz refclk limits. */
  287. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  288. .dot = { .min = 25000, .max = 350000 },
  289. .vco = { .min = 1760000, .max = 3510000 },
  290. .n = { .min = 1, .max = 2 },
  291. .m = { .min = 79, .max = 126 },
  292. .m1 = { .min = 12, .max = 22 },
  293. .m2 = { .min = 5, .max = 9 },
  294. .p = { .min = 28, .max = 112 },
  295. .p1 = { .min = 2,.max = 8 },
  296. .p2 = { .dot_limit = 225000,
  297. .p2_slow = 14, .p2_fast = 14 },
  298. .find_pll = intel_g4x_find_best_PLL,
  299. };
  300. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  301. .dot = { .min = 25000, .max = 350000 },
  302. .vco = { .min = 1760000, .max = 3510000 },
  303. .n = { .min = 1, .max = 3 },
  304. .m = { .min = 79, .max = 126 },
  305. .m1 = { .min = 12, .max = 22 },
  306. .m2 = { .min = 5, .max = 9 },
  307. .p = { .min = 14, .max = 42 },
  308. .p1 = { .min = 2,.max = 6 },
  309. .p2 = { .dot_limit = 225000,
  310. .p2_slow = 7, .p2_fast = 7 },
  311. .find_pll = intel_g4x_find_best_PLL,
  312. };
  313. static const intel_limit_t intel_limits_ironlake_display_port = {
  314. .dot = { .min = 25000, .max = 350000 },
  315. .vco = { .min = 1760000, .max = 3510000},
  316. .n = { .min = 1, .max = 2 },
  317. .m = { .min = 81, .max = 90 },
  318. .m1 = { .min = 12, .max = 22 },
  319. .m2 = { .min = 5, .max = 9 },
  320. .p = { .min = 10, .max = 20 },
  321. .p1 = { .min = 1, .max = 2},
  322. .p2 = { .dot_limit = 0,
  323. .p2_slow = 10, .p2_fast = 10 },
  324. .find_pll = intel_find_pll_ironlake_dp,
  325. };
  326. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  327. int refclk)
  328. {
  329. struct drm_device *dev = crtc->dev;
  330. struct drm_i915_private *dev_priv = dev->dev_private;
  331. const intel_limit_t *limit;
  332. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  333. if ((I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) ==
  334. LVDS_CLKB_POWER_UP) {
  335. /* LVDS dual channel */
  336. if (refclk == 100000)
  337. limit = &intel_limits_ironlake_dual_lvds_100m;
  338. else
  339. limit = &intel_limits_ironlake_dual_lvds;
  340. } else {
  341. if (refclk == 100000)
  342. limit = &intel_limits_ironlake_single_lvds_100m;
  343. else
  344. limit = &intel_limits_ironlake_single_lvds;
  345. }
  346. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  347. HAS_eDP)
  348. limit = &intel_limits_ironlake_display_port;
  349. else
  350. limit = &intel_limits_ironlake_dac;
  351. return limit;
  352. }
  353. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  354. {
  355. struct drm_device *dev = crtc->dev;
  356. struct drm_i915_private *dev_priv = dev->dev_private;
  357. const intel_limit_t *limit;
  358. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  359. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  360. LVDS_CLKB_POWER_UP)
  361. /* LVDS with dual channel */
  362. limit = &intel_limits_g4x_dual_channel_lvds;
  363. else
  364. /* LVDS with dual channel */
  365. limit = &intel_limits_g4x_single_channel_lvds;
  366. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  367. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  368. limit = &intel_limits_g4x_hdmi;
  369. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  370. limit = &intel_limits_g4x_sdvo;
  371. } else if (intel_pipe_has_type (crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  372. limit = &intel_limits_g4x_display_port;
  373. } else /* The option is for other outputs */
  374. limit = &intel_limits_i9xx_sdvo;
  375. return limit;
  376. }
  377. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  378. {
  379. struct drm_device *dev = crtc->dev;
  380. const intel_limit_t *limit;
  381. if (HAS_PCH_SPLIT(dev))
  382. limit = intel_ironlake_limit(crtc, refclk);
  383. else if (IS_G4X(dev)) {
  384. limit = intel_g4x_limit(crtc);
  385. } else if (IS_PINEVIEW(dev)) {
  386. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  387. limit = &intel_limits_pineview_lvds;
  388. else
  389. limit = &intel_limits_pineview_sdvo;
  390. } else if (!IS_GEN2(dev)) {
  391. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  392. limit = &intel_limits_i9xx_lvds;
  393. else
  394. limit = &intel_limits_i9xx_sdvo;
  395. } else {
  396. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  397. limit = &intel_limits_i8xx_lvds;
  398. else
  399. limit = &intel_limits_i8xx_dvo;
  400. }
  401. return limit;
  402. }
  403. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  404. static void pineview_clock(int refclk, intel_clock_t *clock)
  405. {
  406. clock->m = clock->m2 + 2;
  407. clock->p = clock->p1 * clock->p2;
  408. clock->vco = refclk * clock->m / clock->n;
  409. clock->dot = clock->vco / clock->p;
  410. }
  411. static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
  412. {
  413. if (IS_PINEVIEW(dev)) {
  414. pineview_clock(refclk, clock);
  415. return;
  416. }
  417. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  418. clock->p = clock->p1 * clock->p2;
  419. clock->vco = refclk * clock->m / (clock->n + 2);
  420. clock->dot = clock->vco / clock->p;
  421. }
  422. /**
  423. * Returns whether any output on the specified pipe is of the specified type
  424. */
  425. bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  426. {
  427. struct drm_device *dev = crtc->dev;
  428. struct drm_mode_config *mode_config = &dev->mode_config;
  429. struct intel_encoder *encoder;
  430. list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
  431. if (encoder->base.crtc == crtc && encoder->type == type)
  432. return true;
  433. return false;
  434. }
  435. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  436. /**
  437. * Returns whether the given set of divisors are valid for a given refclk with
  438. * the given connectors.
  439. */
  440. static bool intel_PLL_is_valid(struct drm_device *dev,
  441. const intel_limit_t *limit,
  442. const intel_clock_t *clock)
  443. {
  444. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  445. INTELPllInvalid ("p1 out of range\n");
  446. if (clock->p < limit->p.min || limit->p.max < clock->p)
  447. INTELPllInvalid ("p out of range\n");
  448. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  449. INTELPllInvalid ("m2 out of range\n");
  450. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  451. INTELPllInvalid ("m1 out of range\n");
  452. if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
  453. INTELPllInvalid ("m1 <= m2\n");
  454. if (clock->m < limit->m.min || limit->m.max < clock->m)
  455. INTELPllInvalid ("m out of range\n");
  456. if (clock->n < limit->n.min || limit->n.max < clock->n)
  457. INTELPllInvalid ("n out of range\n");
  458. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  459. INTELPllInvalid ("vco out of range\n");
  460. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  461. * connector, etc., rather than just a single range.
  462. */
  463. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  464. INTELPllInvalid ("dot out of range\n");
  465. return true;
  466. }
  467. static bool
  468. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  469. int target, int refclk, intel_clock_t *best_clock)
  470. {
  471. struct drm_device *dev = crtc->dev;
  472. struct drm_i915_private *dev_priv = dev->dev_private;
  473. intel_clock_t clock;
  474. int err = target;
  475. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  476. (I915_READ(LVDS)) != 0) {
  477. /*
  478. * For LVDS, if the panel is on, just rely on its current
  479. * settings for dual-channel. We haven't figured out how to
  480. * reliably set up different single/dual channel state, if we
  481. * even can.
  482. */
  483. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  484. LVDS_CLKB_POWER_UP)
  485. clock.p2 = limit->p2.p2_fast;
  486. else
  487. clock.p2 = limit->p2.p2_slow;
  488. } else {
  489. if (target < limit->p2.dot_limit)
  490. clock.p2 = limit->p2.p2_slow;
  491. else
  492. clock.p2 = limit->p2.p2_fast;
  493. }
  494. memset (best_clock, 0, sizeof (*best_clock));
  495. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  496. clock.m1++) {
  497. for (clock.m2 = limit->m2.min;
  498. clock.m2 <= limit->m2.max; clock.m2++) {
  499. /* m1 is always 0 in Pineview */
  500. if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
  501. break;
  502. for (clock.n = limit->n.min;
  503. clock.n <= limit->n.max; clock.n++) {
  504. for (clock.p1 = limit->p1.min;
  505. clock.p1 <= limit->p1.max; clock.p1++) {
  506. int this_err;
  507. intel_clock(dev, refclk, &clock);
  508. if (!intel_PLL_is_valid(dev, limit,
  509. &clock))
  510. continue;
  511. this_err = abs(clock.dot - target);
  512. if (this_err < err) {
  513. *best_clock = clock;
  514. err = this_err;
  515. }
  516. }
  517. }
  518. }
  519. }
  520. return (err != target);
  521. }
  522. static bool
  523. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  524. int target, int refclk, intel_clock_t *best_clock)
  525. {
  526. struct drm_device *dev = crtc->dev;
  527. struct drm_i915_private *dev_priv = dev->dev_private;
  528. intel_clock_t clock;
  529. int max_n;
  530. bool found;
  531. /* approximately equals target * 0.00585 */
  532. int err_most = (target >> 8) + (target >> 9);
  533. found = false;
  534. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  535. int lvds_reg;
  536. if (HAS_PCH_SPLIT(dev))
  537. lvds_reg = PCH_LVDS;
  538. else
  539. lvds_reg = LVDS;
  540. if ((I915_READ(lvds_reg) & LVDS_CLKB_POWER_MASK) ==
  541. LVDS_CLKB_POWER_UP)
  542. clock.p2 = limit->p2.p2_fast;
  543. else
  544. clock.p2 = limit->p2.p2_slow;
  545. } else {
  546. if (target < limit->p2.dot_limit)
  547. clock.p2 = limit->p2.p2_slow;
  548. else
  549. clock.p2 = limit->p2.p2_fast;
  550. }
  551. memset(best_clock, 0, sizeof(*best_clock));
  552. max_n = limit->n.max;
  553. /* based on hardware requirement, prefer smaller n to precision */
  554. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  555. /* based on hardware requirement, prefere larger m1,m2 */
  556. for (clock.m1 = limit->m1.max;
  557. clock.m1 >= limit->m1.min; clock.m1--) {
  558. for (clock.m2 = limit->m2.max;
  559. clock.m2 >= limit->m2.min; clock.m2--) {
  560. for (clock.p1 = limit->p1.max;
  561. clock.p1 >= limit->p1.min; clock.p1--) {
  562. int this_err;
  563. intel_clock(dev, refclk, &clock);
  564. if (!intel_PLL_is_valid(dev, limit,
  565. &clock))
  566. continue;
  567. this_err = abs(clock.dot - target);
  568. if (this_err < err_most) {
  569. *best_clock = clock;
  570. err_most = this_err;
  571. max_n = clock.n;
  572. found = true;
  573. }
  574. }
  575. }
  576. }
  577. }
  578. return found;
  579. }
  580. static bool
  581. intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  582. int target, int refclk, intel_clock_t *best_clock)
  583. {
  584. struct drm_device *dev = crtc->dev;
  585. intel_clock_t clock;
  586. if (target < 200000) {
  587. clock.n = 1;
  588. clock.p1 = 2;
  589. clock.p2 = 10;
  590. clock.m1 = 12;
  591. clock.m2 = 9;
  592. } else {
  593. clock.n = 2;
  594. clock.p1 = 1;
  595. clock.p2 = 10;
  596. clock.m1 = 14;
  597. clock.m2 = 8;
  598. }
  599. intel_clock(dev, refclk, &clock);
  600. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  601. return true;
  602. }
  603. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  604. static bool
  605. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  606. int target, int refclk, intel_clock_t *best_clock)
  607. {
  608. intel_clock_t clock;
  609. if (target < 200000) {
  610. clock.p1 = 2;
  611. clock.p2 = 10;
  612. clock.n = 2;
  613. clock.m1 = 23;
  614. clock.m2 = 8;
  615. } else {
  616. clock.p1 = 1;
  617. clock.p2 = 10;
  618. clock.n = 1;
  619. clock.m1 = 14;
  620. clock.m2 = 2;
  621. }
  622. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  623. clock.p = (clock.p1 * clock.p2);
  624. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  625. clock.vco = 0;
  626. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  627. return true;
  628. }
  629. /**
  630. * intel_wait_for_vblank - wait for vblank on a given pipe
  631. * @dev: drm device
  632. * @pipe: pipe to wait for
  633. *
  634. * Wait for vblank to occur on a given pipe. Needed for various bits of
  635. * mode setting code.
  636. */
  637. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  638. {
  639. struct drm_i915_private *dev_priv = dev->dev_private;
  640. int pipestat_reg = PIPESTAT(pipe);
  641. /* Clear existing vblank status. Note this will clear any other
  642. * sticky status fields as well.
  643. *
  644. * This races with i915_driver_irq_handler() with the result
  645. * that either function could miss a vblank event. Here it is not
  646. * fatal, as we will either wait upon the next vblank interrupt or
  647. * timeout. Generally speaking intel_wait_for_vblank() is only
  648. * called during modeset at which time the GPU should be idle and
  649. * should *not* be performing page flips and thus not waiting on
  650. * vblanks...
  651. * Currently, the result of us stealing a vblank from the irq
  652. * handler is that a single frame will be skipped during swapbuffers.
  653. */
  654. I915_WRITE(pipestat_reg,
  655. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  656. /* Wait for vblank interrupt bit to set */
  657. if (wait_for(I915_READ(pipestat_reg) &
  658. PIPE_VBLANK_INTERRUPT_STATUS,
  659. 50))
  660. DRM_DEBUG_KMS("vblank wait timed out\n");
  661. }
  662. /*
  663. * intel_wait_for_pipe_off - wait for pipe to turn off
  664. * @dev: drm device
  665. * @pipe: pipe to wait for
  666. *
  667. * After disabling a pipe, we can't wait for vblank in the usual way,
  668. * spinning on the vblank interrupt status bit, since we won't actually
  669. * see an interrupt when the pipe is disabled.
  670. *
  671. * On Gen4 and above:
  672. * wait for the pipe register state bit to turn off
  673. *
  674. * Otherwise:
  675. * wait for the display line value to settle (it usually
  676. * ends up stopping at the start of the next frame).
  677. *
  678. */
  679. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  680. {
  681. struct drm_i915_private *dev_priv = dev->dev_private;
  682. if (INTEL_INFO(dev)->gen >= 4) {
  683. int reg = PIPECONF(pipe);
  684. /* Wait for the Pipe State to go off */
  685. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  686. 100))
  687. DRM_DEBUG_KMS("pipe_off wait timed out\n");
  688. } else {
  689. u32 last_line;
  690. int reg = PIPEDSL(pipe);
  691. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  692. /* Wait for the display line to settle */
  693. do {
  694. last_line = I915_READ(reg) & DSL_LINEMASK;
  695. mdelay(5);
  696. } while (((I915_READ(reg) & DSL_LINEMASK) != last_line) &&
  697. time_after(timeout, jiffies));
  698. if (time_after(jiffies, timeout))
  699. DRM_DEBUG_KMS("pipe_off wait timed out\n");
  700. }
  701. }
  702. static const char *state_string(bool enabled)
  703. {
  704. return enabled ? "on" : "off";
  705. }
  706. /* Only for pre-ILK configs */
  707. static void assert_pll(struct drm_i915_private *dev_priv,
  708. enum pipe pipe, bool state)
  709. {
  710. int reg;
  711. u32 val;
  712. bool cur_state;
  713. reg = DPLL(pipe);
  714. val = I915_READ(reg);
  715. cur_state = !!(val & DPLL_VCO_ENABLE);
  716. WARN(cur_state != state,
  717. "PLL state assertion failure (expected %s, current %s)\n",
  718. state_string(state), state_string(cur_state));
  719. }
  720. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  721. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  722. /* For ILK+ */
  723. static void assert_pch_pll(struct drm_i915_private *dev_priv,
  724. enum pipe pipe, bool state)
  725. {
  726. int reg;
  727. u32 val;
  728. bool cur_state;
  729. reg = PCH_DPLL(pipe);
  730. val = I915_READ(reg);
  731. cur_state = !!(val & DPLL_VCO_ENABLE);
  732. WARN(cur_state != state,
  733. "PCH PLL state assertion failure (expected %s, current %s)\n",
  734. state_string(state), state_string(cur_state));
  735. }
  736. #define assert_pch_pll_enabled(d, p) assert_pch_pll(d, p, true)
  737. #define assert_pch_pll_disabled(d, p) assert_pch_pll(d, p, false)
  738. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  739. enum pipe pipe, bool state)
  740. {
  741. int reg;
  742. u32 val;
  743. bool cur_state;
  744. reg = FDI_TX_CTL(pipe);
  745. val = I915_READ(reg);
  746. cur_state = !!(val & FDI_TX_ENABLE);
  747. WARN(cur_state != state,
  748. "FDI TX state assertion failure (expected %s, current %s)\n",
  749. state_string(state), state_string(cur_state));
  750. }
  751. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  752. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  753. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  754. enum pipe pipe, bool state)
  755. {
  756. int reg;
  757. u32 val;
  758. bool cur_state;
  759. reg = FDI_RX_CTL(pipe);
  760. val = I915_READ(reg);
  761. cur_state = !!(val & FDI_RX_ENABLE);
  762. WARN(cur_state != state,
  763. "FDI RX state assertion failure (expected %s, current %s)\n",
  764. state_string(state), state_string(cur_state));
  765. }
  766. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  767. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  768. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  769. enum pipe pipe)
  770. {
  771. int reg;
  772. u32 val;
  773. /* ILK FDI PLL is always enabled */
  774. if (dev_priv->info->gen == 5)
  775. return;
  776. reg = FDI_TX_CTL(pipe);
  777. val = I915_READ(reg);
  778. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  779. }
  780. static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv,
  781. enum pipe pipe)
  782. {
  783. int reg;
  784. u32 val;
  785. reg = FDI_RX_CTL(pipe);
  786. val = I915_READ(reg);
  787. WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
  788. }
  789. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  790. enum pipe pipe)
  791. {
  792. int pp_reg, lvds_reg;
  793. u32 val;
  794. enum pipe panel_pipe = PIPE_A;
  795. bool locked = locked;
  796. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  797. pp_reg = PCH_PP_CONTROL;
  798. lvds_reg = PCH_LVDS;
  799. } else {
  800. pp_reg = PP_CONTROL;
  801. lvds_reg = LVDS;
  802. }
  803. val = I915_READ(pp_reg);
  804. if (!(val & PANEL_POWER_ON) ||
  805. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  806. locked = false;
  807. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  808. panel_pipe = PIPE_B;
  809. WARN(panel_pipe == pipe && locked,
  810. "panel assertion failure, pipe %c regs locked\n",
  811. pipe_name(pipe));
  812. }
  813. static void assert_pipe(struct drm_i915_private *dev_priv,
  814. enum pipe pipe, bool state)
  815. {
  816. int reg;
  817. u32 val;
  818. bool cur_state;
  819. reg = PIPECONF(pipe);
  820. val = I915_READ(reg);
  821. cur_state = !!(val & PIPECONF_ENABLE);
  822. WARN(cur_state != state,
  823. "pipe %c assertion failure (expected %s, current %s)\n",
  824. pipe_name(pipe), state_string(state), state_string(cur_state));
  825. }
  826. #define assert_pipe_enabled(d, p) assert_pipe(d, p, true)
  827. #define assert_pipe_disabled(d, p) assert_pipe(d, p, false)
  828. static void assert_plane_enabled(struct drm_i915_private *dev_priv,
  829. enum plane plane)
  830. {
  831. int reg;
  832. u32 val;
  833. reg = DSPCNTR(plane);
  834. val = I915_READ(reg);
  835. WARN(!(val & DISPLAY_PLANE_ENABLE),
  836. "plane %c assertion failure, should be active but is disabled\n",
  837. plane_name(plane));
  838. }
  839. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  840. enum pipe pipe)
  841. {
  842. int reg, i;
  843. u32 val;
  844. int cur_pipe;
  845. /* Planes are fixed to pipes on ILK+ */
  846. if (HAS_PCH_SPLIT(dev_priv->dev))
  847. return;
  848. /* Need to check both planes against the pipe */
  849. for (i = 0; i < 2; i++) {
  850. reg = DSPCNTR(i);
  851. val = I915_READ(reg);
  852. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  853. DISPPLANE_SEL_PIPE_SHIFT;
  854. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  855. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  856. plane_name(i), pipe_name(pipe));
  857. }
  858. }
  859. static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  860. {
  861. u32 val;
  862. bool enabled;
  863. val = I915_READ(PCH_DREF_CONTROL);
  864. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  865. DREF_SUPERSPREAD_SOURCE_MASK));
  866. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  867. }
  868. static void assert_transcoder_disabled(struct drm_i915_private *dev_priv,
  869. enum pipe pipe)
  870. {
  871. int reg;
  872. u32 val;
  873. bool enabled;
  874. reg = TRANSCONF(pipe);
  875. val = I915_READ(reg);
  876. enabled = !!(val & TRANS_ENABLE);
  877. WARN(enabled,
  878. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  879. pipe_name(pipe));
  880. }
  881. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  882. enum pipe pipe, int reg)
  883. {
  884. u32 val = I915_READ(reg);
  885. WARN(DP_PIPE_ENABLED(val, pipe),
  886. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  887. reg, pipe_name(pipe));
  888. }
  889. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  890. enum pipe pipe, int reg)
  891. {
  892. u32 val = I915_READ(reg);
  893. WARN(HDMI_PIPE_ENABLED(val, pipe),
  894. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  895. reg, pipe_name(pipe));
  896. }
  897. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  898. enum pipe pipe)
  899. {
  900. int reg;
  901. u32 val;
  902. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B);
  903. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C);
  904. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D);
  905. reg = PCH_ADPA;
  906. val = I915_READ(reg);
  907. WARN(ADPA_PIPE_ENABLED(val, pipe),
  908. "PCH VGA enabled on transcoder %c, should be disabled\n",
  909. pipe_name(pipe));
  910. reg = PCH_LVDS;
  911. val = I915_READ(reg);
  912. WARN(LVDS_PIPE_ENABLED(val, pipe),
  913. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  914. pipe_name(pipe));
  915. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
  916. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
  917. assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
  918. }
  919. /**
  920. * intel_enable_pll - enable a PLL
  921. * @dev_priv: i915 private structure
  922. * @pipe: pipe PLL to enable
  923. *
  924. * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
  925. * make sure the PLL reg is writable first though, since the panel write
  926. * protect mechanism may be enabled.
  927. *
  928. * Note! This is for pre-ILK only.
  929. */
  930. static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  931. {
  932. int reg;
  933. u32 val;
  934. /* No really, not for ILK+ */
  935. BUG_ON(dev_priv->info->gen >= 5);
  936. /* PLL is protected by panel, make sure we can write it */
  937. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  938. assert_panel_unlocked(dev_priv, pipe);
  939. reg = DPLL(pipe);
  940. val = I915_READ(reg);
  941. val |= DPLL_VCO_ENABLE;
  942. /* We do this three times for luck */
  943. I915_WRITE(reg, val);
  944. POSTING_READ(reg);
  945. udelay(150); /* wait for warmup */
  946. I915_WRITE(reg, val);
  947. POSTING_READ(reg);
  948. udelay(150); /* wait for warmup */
  949. I915_WRITE(reg, val);
  950. POSTING_READ(reg);
  951. udelay(150); /* wait for warmup */
  952. }
  953. /**
  954. * intel_disable_pll - disable a PLL
  955. * @dev_priv: i915 private structure
  956. * @pipe: pipe PLL to disable
  957. *
  958. * Disable the PLL for @pipe, making sure the pipe is off first.
  959. *
  960. * Note! This is for pre-ILK only.
  961. */
  962. static void intel_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  963. {
  964. int reg;
  965. u32 val;
  966. /* Don't disable pipe A or pipe A PLLs if needed */
  967. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  968. return;
  969. /* Make sure the pipe isn't still relying on us */
  970. assert_pipe_disabled(dev_priv, pipe);
  971. reg = DPLL(pipe);
  972. val = I915_READ(reg);
  973. val &= ~DPLL_VCO_ENABLE;
  974. I915_WRITE(reg, val);
  975. POSTING_READ(reg);
  976. }
  977. /**
  978. * intel_enable_pch_pll - enable PCH PLL
  979. * @dev_priv: i915 private structure
  980. * @pipe: pipe PLL to enable
  981. *
  982. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  983. * drives the transcoder clock.
  984. */
  985. static void intel_enable_pch_pll(struct drm_i915_private *dev_priv,
  986. enum pipe pipe)
  987. {
  988. int reg;
  989. u32 val;
  990. /* PCH only available on ILK+ */
  991. BUG_ON(dev_priv->info->gen < 5);
  992. /* PCH refclock must be enabled first */
  993. assert_pch_refclk_enabled(dev_priv);
  994. reg = PCH_DPLL(pipe);
  995. val = I915_READ(reg);
  996. val |= DPLL_VCO_ENABLE;
  997. I915_WRITE(reg, val);
  998. POSTING_READ(reg);
  999. udelay(200);
  1000. }
  1001. static void intel_disable_pch_pll(struct drm_i915_private *dev_priv,
  1002. enum pipe pipe)
  1003. {
  1004. int reg;
  1005. u32 val;
  1006. /* PCH only available on ILK+ */
  1007. BUG_ON(dev_priv->info->gen < 5);
  1008. /* Make sure transcoder isn't still depending on us */
  1009. assert_transcoder_disabled(dev_priv, pipe);
  1010. reg = PCH_DPLL(pipe);
  1011. val = I915_READ(reg);
  1012. val &= ~DPLL_VCO_ENABLE;
  1013. I915_WRITE(reg, val);
  1014. POSTING_READ(reg);
  1015. udelay(200);
  1016. }
  1017. static void intel_enable_transcoder(struct drm_i915_private *dev_priv,
  1018. enum pipe pipe)
  1019. {
  1020. int reg;
  1021. u32 val;
  1022. /* PCH only available on ILK+ */
  1023. BUG_ON(dev_priv->info->gen < 5);
  1024. /* Make sure PCH DPLL is enabled */
  1025. assert_pch_pll_enabled(dev_priv, pipe);
  1026. /* FDI must be feeding us bits for PCH ports */
  1027. assert_fdi_tx_enabled(dev_priv, pipe);
  1028. assert_fdi_rx_enabled(dev_priv, pipe);
  1029. reg = TRANSCONF(pipe);
  1030. val = I915_READ(reg);
  1031. /*
  1032. * make the BPC in transcoder be consistent with
  1033. * that in pipeconf reg.
  1034. */
  1035. val &= ~PIPE_BPC_MASK;
  1036. val |= I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK;
  1037. I915_WRITE(reg, val | TRANS_ENABLE);
  1038. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1039. DRM_ERROR("failed to enable transcoder %d\n", pipe);
  1040. }
  1041. static void intel_disable_transcoder(struct drm_i915_private *dev_priv,
  1042. enum pipe pipe)
  1043. {
  1044. int reg;
  1045. u32 val;
  1046. /* FDI relies on the transcoder */
  1047. assert_fdi_tx_disabled(dev_priv, pipe);
  1048. assert_fdi_rx_disabled(dev_priv, pipe);
  1049. /* Ports must be off as well */
  1050. assert_pch_ports_disabled(dev_priv, pipe);
  1051. reg = TRANSCONF(pipe);
  1052. val = I915_READ(reg);
  1053. val &= ~TRANS_ENABLE;
  1054. I915_WRITE(reg, val);
  1055. /* wait for PCH transcoder off, transcoder state */
  1056. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1057. DRM_ERROR("failed to disable transcoder\n");
  1058. }
  1059. /**
  1060. * intel_enable_pipe - enable a pipe, asserting requirements
  1061. * @dev_priv: i915 private structure
  1062. * @pipe: pipe to enable
  1063. * @pch_port: on ILK+, is this pipe driving a PCH port or not
  1064. *
  1065. * Enable @pipe, making sure that various hardware specific requirements
  1066. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1067. *
  1068. * @pipe should be %PIPE_A or %PIPE_B.
  1069. *
  1070. * Will wait until the pipe is actually running (i.e. first vblank) before
  1071. * returning.
  1072. */
  1073. static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
  1074. bool pch_port)
  1075. {
  1076. int reg;
  1077. u32 val;
  1078. /*
  1079. * A pipe without a PLL won't actually be able to drive bits from
  1080. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1081. * need the check.
  1082. */
  1083. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1084. assert_pll_enabled(dev_priv, pipe);
  1085. else {
  1086. if (pch_port) {
  1087. /* if driving the PCH, we need FDI enabled */
  1088. assert_fdi_rx_pll_enabled(dev_priv, pipe);
  1089. assert_fdi_tx_pll_enabled(dev_priv, pipe);
  1090. }
  1091. /* FIXME: assert CPU port conditions for SNB+ */
  1092. }
  1093. reg = PIPECONF(pipe);
  1094. val = I915_READ(reg);
  1095. if (val & PIPECONF_ENABLE)
  1096. return;
  1097. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1098. intel_wait_for_vblank(dev_priv->dev, pipe);
  1099. }
  1100. /**
  1101. * intel_disable_pipe - disable a pipe, asserting requirements
  1102. * @dev_priv: i915 private structure
  1103. * @pipe: pipe to disable
  1104. *
  1105. * Disable @pipe, making sure that various hardware specific requirements
  1106. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1107. *
  1108. * @pipe should be %PIPE_A or %PIPE_B.
  1109. *
  1110. * Will wait until the pipe has shut down before returning.
  1111. */
  1112. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1113. enum pipe pipe)
  1114. {
  1115. int reg;
  1116. u32 val;
  1117. /*
  1118. * Make sure planes won't keep trying to pump pixels to us,
  1119. * or we might hang the display.
  1120. */
  1121. assert_planes_disabled(dev_priv, pipe);
  1122. /* Don't disable pipe A or pipe A PLLs if needed */
  1123. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1124. return;
  1125. reg = PIPECONF(pipe);
  1126. val = I915_READ(reg);
  1127. if ((val & PIPECONF_ENABLE) == 0)
  1128. return;
  1129. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1130. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1131. }
  1132. /**
  1133. * intel_enable_plane - enable a display plane on a given pipe
  1134. * @dev_priv: i915 private structure
  1135. * @plane: plane to enable
  1136. * @pipe: pipe being fed
  1137. *
  1138. * Enable @plane on @pipe, making sure that @pipe is running first.
  1139. */
  1140. static void intel_enable_plane(struct drm_i915_private *dev_priv,
  1141. enum plane plane, enum pipe pipe)
  1142. {
  1143. int reg;
  1144. u32 val;
  1145. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1146. assert_pipe_enabled(dev_priv, pipe);
  1147. reg = DSPCNTR(plane);
  1148. val = I915_READ(reg);
  1149. if (val & DISPLAY_PLANE_ENABLE)
  1150. return;
  1151. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1152. intel_wait_for_vblank(dev_priv->dev, pipe);
  1153. }
  1154. /*
  1155. * Plane regs are double buffered, going from enabled->disabled needs a
  1156. * trigger in order to latch. The display address reg provides this.
  1157. */
  1158. static void intel_flush_display_plane(struct drm_i915_private *dev_priv,
  1159. enum plane plane)
  1160. {
  1161. u32 reg = DSPADDR(plane);
  1162. I915_WRITE(reg, I915_READ(reg));
  1163. }
  1164. /**
  1165. * intel_disable_plane - disable a display plane
  1166. * @dev_priv: i915 private structure
  1167. * @plane: plane to disable
  1168. * @pipe: pipe consuming the data
  1169. *
  1170. * Disable @plane; should be an independent operation.
  1171. */
  1172. static void intel_disable_plane(struct drm_i915_private *dev_priv,
  1173. enum plane plane, enum pipe pipe)
  1174. {
  1175. int reg;
  1176. u32 val;
  1177. reg = DSPCNTR(plane);
  1178. val = I915_READ(reg);
  1179. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  1180. return;
  1181. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1182. intel_flush_display_plane(dev_priv, plane);
  1183. intel_wait_for_vblank(dev_priv->dev, pipe);
  1184. }
  1185. static void disable_pch_dp(struct drm_i915_private *dev_priv,
  1186. enum pipe pipe, int reg)
  1187. {
  1188. u32 val = I915_READ(reg);
  1189. if (DP_PIPE_ENABLED(val, pipe))
  1190. I915_WRITE(reg, val & ~DP_PORT_EN);
  1191. }
  1192. static void disable_pch_hdmi(struct drm_i915_private *dev_priv,
  1193. enum pipe pipe, int reg)
  1194. {
  1195. u32 val = I915_READ(reg);
  1196. if (HDMI_PIPE_ENABLED(val, pipe))
  1197. I915_WRITE(reg, val & ~PORT_ENABLE);
  1198. }
  1199. /* Disable any ports connected to this transcoder */
  1200. static void intel_disable_pch_ports(struct drm_i915_private *dev_priv,
  1201. enum pipe pipe)
  1202. {
  1203. u32 reg, val;
  1204. val = I915_READ(PCH_PP_CONTROL);
  1205. I915_WRITE(PCH_PP_CONTROL, val | PANEL_UNLOCK_REGS);
  1206. disable_pch_dp(dev_priv, pipe, PCH_DP_B);
  1207. disable_pch_dp(dev_priv, pipe, PCH_DP_C);
  1208. disable_pch_dp(dev_priv, pipe, PCH_DP_D);
  1209. reg = PCH_ADPA;
  1210. val = I915_READ(reg);
  1211. if (ADPA_PIPE_ENABLED(val, pipe))
  1212. I915_WRITE(reg, val & ~ADPA_DAC_ENABLE);
  1213. reg = PCH_LVDS;
  1214. val = I915_READ(reg);
  1215. if (LVDS_PIPE_ENABLED(val, pipe)) {
  1216. I915_WRITE(reg, val & ~LVDS_PORT_EN);
  1217. POSTING_READ(reg);
  1218. udelay(100);
  1219. }
  1220. disable_pch_hdmi(dev_priv, pipe, HDMIB);
  1221. disable_pch_hdmi(dev_priv, pipe, HDMIC);
  1222. disable_pch_hdmi(dev_priv, pipe, HDMID);
  1223. }
  1224. static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1225. {
  1226. struct drm_device *dev = crtc->dev;
  1227. struct drm_i915_private *dev_priv = dev->dev_private;
  1228. struct drm_framebuffer *fb = crtc->fb;
  1229. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1230. struct drm_i915_gem_object *obj = intel_fb->obj;
  1231. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1232. int plane, i;
  1233. u32 fbc_ctl, fbc_ctl2;
  1234. if (fb->pitch == dev_priv->cfb_pitch &&
  1235. obj->fence_reg == dev_priv->cfb_fence &&
  1236. intel_crtc->plane == dev_priv->cfb_plane &&
  1237. I915_READ(FBC_CONTROL) & FBC_CTL_EN)
  1238. return;
  1239. i8xx_disable_fbc(dev);
  1240. dev_priv->cfb_pitch = dev_priv->cfb_size / FBC_LL_SIZE;
  1241. if (fb->pitch < dev_priv->cfb_pitch)
  1242. dev_priv->cfb_pitch = fb->pitch;
  1243. /* FBC_CTL wants 64B units */
  1244. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  1245. dev_priv->cfb_fence = obj->fence_reg;
  1246. dev_priv->cfb_plane = intel_crtc->plane;
  1247. plane = dev_priv->cfb_plane == 0 ? FBC_CTL_PLANEA : FBC_CTL_PLANEB;
  1248. /* Clear old tags */
  1249. for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++)
  1250. I915_WRITE(FBC_TAG + (i * 4), 0);
  1251. /* Set it up... */
  1252. fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | plane;
  1253. if (obj->tiling_mode != I915_TILING_NONE)
  1254. fbc_ctl2 |= FBC_CTL_CPU_FENCE;
  1255. I915_WRITE(FBC_CONTROL2, fbc_ctl2);
  1256. I915_WRITE(FBC_FENCE_OFF, crtc->y);
  1257. /* enable it... */
  1258. fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC;
  1259. if (IS_I945GM(dev))
  1260. fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */
  1261. fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
  1262. fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT;
  1263. if (obj->tiling_mode != I915_TILING_NONE)
  1264. fbc_ctl |= dev_priv->cfb_fence;
  1265. I915_WRITE(FBC_CONTROL, fbc_ctl);
  1266. DRM_DEBUG_KMS("enabled FBC, pitch %ld, yoff %d, plane %d, ",
  1267. dev_priv->cfb_pitch, crtc->y, dev_priv->cfb_plane);
  1268. }
  1269. void i8xx_disable_fbc(struct drm_device *dev)
  1270. {
  1271. struct drm_i915_private *dev_priv = dev->dev_private;
  1272. u32 fbc_ctl;
  1273. /* Disable compression */
  1274. fbc_ctl = I915_READ(FBC_CONTROL);
  1275. if ((fbc_ctl & FBC_CTL_EN) == 0)
  1276. return;
  1277. fbc_ctl &= ~FBC_CTL_EN;
  1278. I915_WRITE(FBC_CONTROL, fbc_ctl);
  1279. /* Wait for compressing bit to clear */
  1280. if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) {
  1281. DRM_DEBUG_KMS("FBC idle timed out\n");
  1282. return;
  1283. }
  1284. DRM_DEBUG_KMS("disabled FBC\n");
  1285. }
  1286. static bool i8xx_fbc_enabled(struct drm_device *dev)
  1287. {
  1288. struct drm_i915_private *dev_priv = dev->dev_private;
  1289. return I915_READ(FBC_CONTROL) & FBC_CTL_EN;
  1290. }
  1291. static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1292. {
  1293. struct drm_device *dev = crtc->dev;
  1294. struct drm_i915_private *dev_priv = dev->dev_private;
  1295. struct drm_framebuffer *fb = crtc->fb;
  1296. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1297. struct drm_i915_gem_object *obj = intel_fb->obj;
  1298. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1299. int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
  1300. unsigned long stall_watermark = 200;
  1301. u32 dpfc_ctl;
  1302. dpfc_ctl = I915_READ(DPFC_CONTROL);
  1303. if (dpfc_ctl & DPFC_CTL_EN) {
  1304. if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 &&
  1305. dev_priv->cfb_fence == obj->fence_reg &&
  1306. dev_priv->cfb_plane == intel_crtc->plane &&
  1307. dev_priv->cfb_y == crtc->y)
  1308. return;
  1309. I915_WRITE(DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN);
  1310. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1311. }
  1312. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  1313. dev_priv->cfb_fence = obj->fence_reg;
  1314. dev_priv->cfb_plane = intel_crtc->plane;
  1315. dev_priv->cfb_y = crtc->y;
  1316. dpfc_ctl = plane | DPFC_SR_EN | DPFC_CTL_LIMIT_1X;
  1317. if (obj->tiling_mode != I915_TILING_NONE) {
  1318. dpfc_ctl |= DPFC_CTL_FENCE_EN | dev_priv->cfb_fence;
  1319. I915_WRITE(DPFC_CHICKEN, DPFC_HT_MODIFY);
  1320. } else {
  1321. I915_WRITE(DPFC_CHICKEN, ~DPFC_HT_MODIFY);
  1322. }
  1323. I915_WRITE(DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  1324. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  1325. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  1326. I915_WRITE(DPFC_FENCE_YOFF, crtc->y);
  1327. /* enable it... */
  1328. I915_WRITE(DPFC_CONTROL, I915_READ(DPFC_CONTROL) | DPFC_CTL_EN);
  1329. DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
  1330. }
  1331. void g4x_disable_fbc(struct drm_device *dev)
  1332. {
  1333. struct drm_i915_private *dev_priv = dev->dev_private;
  1334. u32 dpfc_ctl;
  1335. /* Disable compression */
  1336. dpfc_ctl = I915_READ(DPFC_CONTROL);
  1337. if (dpfc_ctl & DPFC_CTL_EN) {
  1338. dpfc_ctl &= ~DPFC_CTL_EN;
  1339. I915_WRITE(DPFC_CONTROL, dpfc_ctl);
  1340. DRM_DEBUG_KMS("disabled FBC\n");
  1341. }
  1342. }
  1343. static bool g4x_fbc_enabled(struct drm_device *dev)
  1344. {
  1345. struct drm_i915_private *dev_priv = dev->dev_private;
  1346. return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN;
  1347. }
  1348. static void sandybridge_blit_fbc_update(struct drm_device *dev)
  1349. {
  1350. struct drm_i915_private *dev_priv = dev->dev_private;
  1351. u32 blt_ecoskpd;
  1352. /* Make sure blitter notifies FBC of writes */
  1353. gen6_gt_force_wake_get(dev_priv);
  1354. blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD);
  1355. blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY <<
  1356. GEN6_BLITTER_LOCK_SHIFT;
  1357. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  1358. blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY;
  1359. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  1360. blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY <<
  1361. GEN6_BLITTER_LOCK_SHIFT);
  1362. I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
  1363. POSTING_READ(GEN6_BLITTER_ECOSKPD);
  1364. gen6_gt_force_wake_put(dev_priv);
  1365. }
  1366. static void ironlake_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1367. {
  1368. struct drm_device *dev = crtc->dev;
  1369. struct drm_i915_private *dev_priv = dev->dev_private;
  1370. struct drm_framebuffer *fb = crtc->fb;
  1371. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1372. struct drm_i915_gem_object *obj = intel_fb->obj;
  1373. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1374. int plane = intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : DPFC_CTL_PLANEB;
  1375. unsigned long stall_watermark = 200;
  1376. u32 dpfc_ctl;
  1377. dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
  1378. if (dpfc_ctl & DPFC_CTL_EN) {
  1379. if (dev_priv->cfb_pitch == dev_priv->cfb_pitch / 64 - 1 &&
  1380. dev_priv->cfb_fence == obj->fence_reg &&
  1381. dev_priv->cfb_plane == intel_crtc->plane &&
  1382. dev_priv->cfb_offset == obj->gtt_offset &&
  1383. dev_priv->cfb_y == crtc->y)
  1384. return;
  1385. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl & ~DPFC_CTL_EN);
  1386. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1387. }
  1388. dev_priv->cfb_pitch = (dev_priv->cfb_pitch / 64) - 1;
  1389. dev_priv->cfb_fence = obj->fence_reg;
  1390. dev_priv->cfb_plane = intel_crtc->plane;
  1391. dev_priv->cfb_offset = obj->gtt_offset;
  1392. dev_priv->cfb_y = crtc->y;
  1393. dpfc_ctl &= DPFC_RESERVED;
  1394. dpfc_ctl |= (plane | DPFC_CTL_LIMIT_1X);
  1395. if (obj->tiling_mode != I915_TILING_NONE) {
  1396. dpfc_ctl |= (DPFC_CTL_FENCE_EN | dev_priv->cfb_fence);
  1397. I915_WRITE(ILK_DPFC_CHICKEN, DPFC_HT_MODIFY);
  1398. } else {
  1399. I915_WRITE(ILK_DPFC_CHICKEN, ~DPFC_HT_MODIFY);
  1400. }
  1401. I915_WRITE(ILK_DPFC_RECOMP_CTL, DPFC_RECOMP_STALL_EN |
  1402. (stall_watermark << DPFC_RECOMP_STALL_WM_SHIFT) |
  1403. (interval << DPFC_RECOMP_TIMER_COUNT_SHIFT));
  1404. I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y);
  1405. I915_WRITE(ILK_FBC_RT_BASE, obj->gtt_offset | ILK_FBC_RT_VALID);
  1406. /* enable it... */
  1407. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);
  1408. if (IS_GEN6(dev)) {
  1409. I915_WRITE(SNB_DPFC_CTL_SA,
  1410. SNB_CPU_FENCE_ENABLE | dev_priv->cfb_fence);
  1411. I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y);
  1412. sandybridge_blit_fbc_update(dev);
  1413. }
  1414. DRM_DEBUG_KMS("enabled fbc on plane %d\n", intel_crtc->plane);
  1415. }
  1416. void ironlake_disable_fbc(struct drm_device *dev)
  1417. {
  1418. struct drm_i915_private *dev_priv = dev->dev_private;
  1419. u32 dpfc_ctl;
  1420. /* Disable compression */
  1421. dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
  1422. if (dpfc_ctl & DPFC_CTL_EN) {
  1423. dpfc_ctl &= ~DPFC_CTL_EN;
  1424. I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl);
  1425. DRM_DEBUG_KMS("disabled FBC\n");
  1426. }
  1427. }
  1428. static bool ironlake_fbc_enabled(struct drm_device *dev)
  1429. {
  1430. struct drm_i915_private *dev_priv = dev->dev_private;
  1431. return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN;
  1432. }
  1433. bool intel_fbc_enabled(struct drm_device *dev)
  1434. {
  1435. struct drm_i915_private *dev_priv = dev->dev_private;
  1436. if (!dev_priv->display.fbc_enabled)
  1437. return false;
  1438. return dev_priv->display.fbc_enabled(dev);
  1439. }
  1440. void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval)
  1441. {
  1442. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  1443. if (!dev_priv->display.enable_fbc)
  1444. return;
  1445. dev_priv->display.enable_fbc(crtc, interval);
  1446. }
  1447. void intel_disable_fbc(struct drm_device *dev)
  1448. {
  1449. struct drm_i915_private *dev_priv = dev->dev_private;
  1450. if (!dev_priv->display.disable_fbc)
  1451. return;
  1452. dev_priv->display.disable_fbc(dev);
  1453. }
  1454. /**
  1455. * intel_update_fbc - enable/disable FBC as needed
  1456. * @dev: the drm_device
  1457. *
  1458. * Set up the framebuffer compression hardware at mode set time. We
  1459. * enable it if possible:
  1460. * - plane A only (on pre-965)
  1461. * - no pixel mulitply/line duplication
  1462. * - no alpha buffer discard
  1463. * - no dual wide
  1464. * - framebuffer <= 2048 in width, 1536 in height
  1465. *
  1466. * We can't assume that any compression will take place (worst case),
  1467. * so the compressed buffer has to be the same size as the uncompressed
  1468. * one. It also must reside (along with the line length buffer) in
  1469. * stolen memory.
  1470. *
  1471. * We need to enable/disable FBC on a global basis.
  1472. */
  1473. static void intel_update_fbc(struct drm_device *dev)
  1474. {
  1475. struct drm_i915_private *dev_priv = dev->dev_private;
  1476. struct drm_crtc *crtc = NULL, *tmp_crtc;
  1477. struct intel_crtc *intel_crtc;
  1478. struct drm_framebuffer *fb;
  1479. struct intel_framebuffer *intel_fb;
  1480. struct drm_i915_gem_object *obj;
  1481. DRM_DEBUG_KMS("\n");
  1482. if (!i915_powersave)
  1483. return;
  1484. if (!I915_HAS_FBC(dev))
  1485. return;
  1486. /*
  1487. * If FBC is already on, we just have to verify that we can
  1488. * keep it that way...
  1489. * Need to disable if:
  1490. * - more than one pipe is active
  1491. * - changing FBC params (stride, fence, mode)
  1492. * - new fb is too large to fit in compressed buffer
  1493. * - going to an unsupported config (interlace, pixel multiply, etc.)
  1494. */
  1495. list_for_each_entry(tmp_crtc, &dev->mode_config.crtc_list, head) {
  1496. if (tmp_crtc->enabled && tmp_crtc->fb) {
  1497. if (crtc) {
  1498. DRM_DEBUG_KMS("more than one pipe active, disabling compression\n");
  1499. dev_priv->no_fbc_reason = FBC_MULTIPLE_PIPES;
  1500. goto out_disable;
  1501. }
  1502. crtc = tmp_crtc;
  1503. }
  1504. }
  1505. if (!crtc || crtc->fb == NULL) {
  1506. DRM_DEBUG_KMS("no output, disabling\n");
  1507. dev_priv->no_fbc_reason = FBC_NO_OUTPUT;
  1508. goto out_disable;
  1509. }
  1510. intel_crtc = to_intel_crtc(crtc);
  1511. fb = crtc->fb;
  1512. intel_fb = to_intel_framebuffer(fb);
  1513. obj = intel_fb->obj;
  1514. if (!i915_enable_fbc) {
  1515. DRM_DEBUG_KMS("fbc disabled per module param (default off)\n");
  1516. dev_priv->no_fbc_reason = FBC_MODULE_PARAM;
  1517. goto out_disable;
  1518. }
  1519. if (intel_fb->obj->base.size > dev_priv->cfb_size) {
  1520. DRM_DEBUG_KMS("framebuffer too large, disabling "
  1521. "compression\n");
  1522. dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL;
  1523. goto out_disable;
  1524. }
  1525. if ((crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) ||
  1526. (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)) {
  1527. DRM_DEBUG_KMS("mode incompatible with compression, "
  1528. "disabling\n");
  1529. dev_priv->no_fbc_reason = FBC_UNSUPPORTED_MODE;
  1530. goto out_disable;
  1531. }
  1532. if ((crtc->mode.hdisplay > 2048) ||
  1533. (crtc->mode.vdisplay > 1536)) {
  1534. DRM_DEBUG_KMS("mode too large for compression, disabling\n");
  1535. dev_priv->no_fbc_reason = FBC_MODE_TOO_LARGE;
  1536. goto out_disable;
  1537. }
  1538. if ((IS_I915GM(dev) || IS_I945GM(dev)) && intel_crtc->plane != 0) {
  1539. DRM_DEBUG_KMS("plane not 0, disabling compression\n");
  1540. dev_priv->no_fbc_reason = FBC_BAD_PLANE;
  1541. goto out_disable;
  1542. }
  1543. if (obj->tiling_mode != I915_TILING_X) {
  1544. DRM_DEBUG_KMS("framebuffer not tiled, disabling compression\n");
  1545. dev_priv->no_fbc_reason = FBC_NOT_TILED;
  1546. goto out_disable;
  1547. }
  1548. /* If the kernel debugger is active, always disable compression */
  1549. if (in_dbg_master())
  1550. goto out_disable;
  1551. intel_enable_fbc(crtc, 500);
  1552. return;
  1553. out_disable:
  1554. /* Multiple disables should be harmless */
  1555. if (intel_fbc_enabled(dev)) {
  1556. DRM_DEBUG_KMS("unsupported config, disabling FBC\n");
  1557. intel_disable_fbc(dev);
  1558. }
  1559. }
  1560. int
  1561. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1562. struct drm_i915_gem_object *obj,
  1563. struct intel_ring_buffer *pipelined)
  1564. {
  1565. struct drm_i915_private *dev_priv = dev->dev_private;
  1566. u32 alignment;
  1567. int ret;
  1568. switch (obj->tiling_mode) {
  1569. case I915_TILING_NONE:
  1570. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1571. alignment = 128 * 1024;
  1572. else if (INTEL_INFO(dev)->gen >= 4)
  1573. alignment = 4 * 1024;
  1574. else
  1575. alignment = 64 * 1024;
  1576. break;
  1577. case I915_TILING_X:
  1578. /* pin() will align the object as required by fence */
  1579. alignment = 0;
  1580. break;
  1581. case I915_TILING_Y:
  1582. /* FIXME: Is this true? */
  1583. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1584. return -EINVAL;
  1585. default:
  1586. BUG();
  1587. }
  1588. dev_priv->mm.interruptible = false;
  1589. ret = i915_gem_object_pin(obj, alignment, true);
  1590. if (ret)
  1591. goto err_interruptible;
  1592. ret = i915_gem_object_set_to_display_plane(obj, pipelined);
  1593. if (ret)
  1594. goto err_unpin;
  1595. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1596. * fence, whereas 965+ only requires a fence if using
  1597. * framebuffer compression. For simplicity, we always install
  1598. * a fence as the cost is not that onerous.
  1599. */
  1600. if (obj->tiling_mode != I915_TILING_NONE) {
  1601. ret = i915_gem_object_get_fence(obj, pipelined);
  1602. if (ret)
  1603. goto err_unpin;
  1604. }
  1605. dev_priv->mm.interruptible = true;
  1606. return 0;
  1607. err_unpin:
  1608. i915_gem_object_unpin(obj);
  1609. err_interruptible:
  1610. dev_priv->mm.interruptible = true;
  1611. return ret;
  1612. }
  1613. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  1614. static int
  1615. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1616. int x, int y, enum mode_set_atomic state)
  1617. {
  1618. struct drm_device *dev = crtc->dev;
  1619. struct drm_i915_private *dev_priv = dev->dev_private;
  1620. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1621. struct intel_framebuffer *intel_fb;
  1622. struct drm_i915_gem_object *obj;
  1623. int plane = intel_crtc->plane;
  1624. unsigned long Start, Offset;
  1625. u32 dspcntr;
  1626. u32 reg;
  1627. switch (plane) {
  1628. case 0:
  1629. case 1:
  1630. break;
  1631. default:
  1632. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1633. return -EINVAL;
  1634. }
  1635. intel_fb = to_intel_framebuffer(fb);
  1636. obj = intel_fb->obj;
  1637. reg = DSPCNTR(plane);
  1638. dspcntr = I915_READ(reg);
  1639. /* Mask out pixel format bits in case we change it */
  1640. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1641. switch (fb->bits_per_pixel) {
  1642. case 8:
  1643. dspcntr |= DISPPLANE_8BPP;
  1644. break;
  1645. case 16:
  1646. if (fb->depth == 15)
  1647. dspcntr |= DISPPLANE_15_16BPP;
  1648. else
  1649. dspcntr |= DISPPLANE_16BPP;
  1650. break;
  1651. case 24:
  1652. case 32:
  1653. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  1654. break;
  1655. default:
  1656. DRM_ERROR("Unknown color depth\n");
  1657. return -EINVAL;
  1658. }
  1659. if (INTEL_INFO(dev)->gen >= 4) {
  1660. if (obj->tiling_mode != I915_TILING_NONE)
  1661. dspcntr |= DISPPLANE_TILED;
  1662. else
  1663. dspcntr &= ~DISPPLANE_TILED;
  1664. }
  1665. if (HAS_PCH_SPLIT(dev))
  1666. /* must disable */
  1667. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1668. I915_WRITE(reg, dspcntr);
  1669. Start = obj->gtt_offset;
  1670. Offset = y * fb->pitch + x * (fb->bits_per_pixel / 8);
  1671. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  1672. Start, Offset, x, y, fb->pitch);
  1673. I915_WRITE(DSPSTRIDE(plane), fb->pitch);
  1674. if (INTEL_INFO(dev)->gen >= 4) {
  1675. I915_WRITE(DSPSURF(plane), Start);
  1676. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1677. I915_WRITE(DSPADDR(plane), Offset);
  1678. } else
  1679. I915_WRITE(DSPADDR(plane), Start + Offset);
  1680. POSTING_READ(reg);
  1681. intel_update_fbc(dev);
  1682. intel_increase_pllclock(crtc);
  1683. return 0;
  1684. }
  1685. static int
  1686. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  1687. struct drm_framebuffer *old_fb)
  1688. {
  1689. struct drm_device *dev = crtc->dev;
  1690. struct drm_i915_master_private *master_priv;
  1691. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1692. int ret;
  1693. /* no fb bound */
  1694. if (!crtc->fb) {
  1695. DRM_DEBUG_KMS("No FB bound\n");
  1696. return 0;
  1697. }
  1698. switch (intel_crtc->plane) {
  1699. case 0:
  1700. case 1:
  1701. break;
  1702. default:
  1703. return -EINVAL;
  1704. }
  1705. mutex_lock(&dev->struct_mutex);
  1706. ret = intel_pin_and_fence_fb_obj(dev,
  1707. to_intel_framebuffer(crtc->fb)->obj,
  1708. NULL);
  1709. if (ret != 0) {
  1710. mutex_unlock(&dev->struct_mutex);
  1711. return ret;
  1712. }
  1713. if (old_fb) {
  1714. struct drm_i915_private *dev_priv = dev->dev_private;
  1715. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  1716. wait_event(dev_priv->pending_flip_queue,
  1717. atomic_read(&dev_priv->mm.wedged) ||
  1718. atomic_read(&obj->pending_flip) == 0);
  1719. /* Big Hammer, we also need to ensure that any pending
  1720. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  1721. * current scanout is retired before unpinning the old
  1722. * framebuffer.
  1723. *
  1724. * This should only fail upon a hung GPU, in which case we
  1725. * can safely continue.
  1726. */
  1727. ret = i915_gem_object_finish_gpu(obj);
  1728. (void) ret;
  1729. }
  1730. ret = intel_pipe_set_base_atomic(crtc, crtc->fb, x, y,
  1731. LEAVE_ATOMIC_MODE_SET);
  1732. if (ret) {
  1733. i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
  1734. mutex_unlock(&dev->struct_mutex);
  1735. return ret;
  1736. }
  1737. if (old_fb) {
  1738. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1739. i915_gem_object_unpin(to_intel_framebuffer(old_fb)->obj);
  1740. }
  1741. mutex_unlock(&dev->struct_mutex);
  1742. if (!dev->primary->master)
  1743. return 0;
  1744. master_priv = dev->primary->master->driver_priv;
  1745. if (!master_priv->sarea_priv)
  1746. return 0;
  1747. if (intel_crtc->pipe) {
  1748. master_priv->sarea_priv->pipeB_x = x;
  1749. master_priv->sarea_priv->pipeB_y = y;
  1750. } else {
  1751. master_priv->sarea_priv->pipeA_x = x;
  1752. master_priv->sarea_priv->pipeA_y = y;
  1753. }
  1754. return 0;
  1755. }
  1756. static void ironlake_set_pll_edp(struct drm_crtc *crtc, int clock)
  1757. {
  1758. struct drm_device *dev = crtc->dev;
  1759. struct drm_i915_private *dev_priv = dev->dev_private;
  1760. u32 dpa_ctl;
  1761. DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock);
  1762. dpa_ctl = I915_READ(DP_A);
  1763. dpa_ctl &= ~DP_PLL_FREQ_MASK;
  1764. if (clock < 200000) {
  1765. u32 temp;
  1766. dpa_ctl |= DP_PLL_FREQ_160MHZ;
  1767. /* workaround for 160Mhz:
  1768. 1) program 0x4600c bits 15:0 = 0x8124
  1769. 2) program 0x46010 bit 0 = 1
  1770. 3) program 0x46034 bit 24 = 1
  1771. 4) program 0x64000 bit 14 = 1
  1772. */
  1773. temp = I915_READ(0x4600c);
  1774. temp &= 0xffff0000;
  1775. I915_WRITE(0x4600c, temp | 0x8124);
  1776. temp = I915_READ(0x46010);
  1777. I915_WRITE(0x46010, temp | 1);
  1778. temp = I915_READ(0x46034);
  1779. I915_WRITE(0x46034, temp | (1 << 24));
  1780. } else {
  1781. dpa_ctl |= DP_PLL_FREQ_270MHZ;
  1782. }
  1783. I915_WRITE(DP_A, dpa_ctl);
  1784. POSTING_READ(DP_A);
  1785. udelay(500);
  1786. }
  1787. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  1788. {
  1789. struct drm_device *dev = crtc->dev;
  1790. struct drm_i915_private *dev_priv = dev->dev_private;
  1791. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1792. int pipe = intel_crtc->pipe;
  1793. u32 reg, temp;
  1794. /* enable normal train */
  1795. reg = FDI_TX_CTL(pipe);
  1796. temp = I915_READ(reg);
  1797. if (IS_IVYBRIDGE(dev)) {
  1798. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  1799. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  1800. } else {
  1801. temp &= ~FDI_LINK_TRAIN_NONE;
  1802. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  1803. }
  1804. I915_WRITE(reg, temp);
  1805. reg = FDI_RX_CTL(pipe);
  1806. temp = I915_READ(reg);
  1807. if (HAS_PCH_CPT(dev)) {
  1808. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  1809. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  1810. } else {
  1811. temp &= ~FDI_LINK_TRAIN_NONE;
  1812. temp |= FDI_LINK_TRAIN_NONE;
  1813. }
  1814. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  1815. /* wait one idle pattern time */
  1816. POSTING_READ(reg);
  1817. udelay(1000);
  1818. /* IVB wants error correction enabled */
  1819. if (IS_IVYBRIDGE(dev))
  1820. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  1821. FDI_FE_ERRC_ENABLE);
  1822. }
  1823. /* The FDI link training functions for ILK/Ibexpeak. */
  1824. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  1825. {
  1826. struct drm_device *dev = crtc->dev;
  1827. struct drm_i915_private *dev_priv = dev->dev_private;
  1828. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1829. int pipe = intel_crtc->pipe;
  1830. int plane = intel_crtc->plane;
  1831. u32 reg, temp, tries;
  1832. /* FDI needs bits from pipe & plane first */
  1833. assert_pipe_enabled(dev_priv, pipe);
  1834. assert_plane_enabled(dev_priv, plane);
  1835. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  1836. for train result */
  1837. reg = FDI_RX_IMR(pipe);
  1838. temp = I915_READ(reg);
  1839. temp &= ~FDI_RX_SYMBOL_LOCK;
  1840. temp &= ~FDI_RX_BIT_LOCK;
  1841. I915_WRITE(reg, temp);
  1842. I915_READ(reg);
  1843. udelay(150);
  1844. /* enable CPU FDI TX and PCH FDI RX */
  1845. reg = FDI_TX_CTL(pipe);
  1846. temp = I915_READ(reg);
  1847. temp &= ~(7 << 19);
  1848. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  1849. temp &= ~FDI_LINK_TRAIN_NONE;
  1850. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1851. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  1852. reg = FDI_RX_CTL(pipe);
  1853. temp = I915_READ(reg);
  1854. temp &= ~FDI_LINK_TRAIN_NONE;
  1855. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1856. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  1857. POSTING_READ(reg);
  1858. udelay(150);
  1859. /* Ironlake workaround, enable clock pointer after FDI enable*/
  1860. if (HAS_PCH_IBX(dev)) {
  1861. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  1862. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  1863. FDI_RX_PHASE_SYNC_POINTER_EN);
  1864. }
  1865. reg = FDI_RX_IIR(pipe);
  1866. for (tries = 0; tries < 5; tries++) {
  1867. temp = I915_READ(reg);
  1868. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  1869. if ((temp & FDI_RX_BIT_LOCK)) {
  1870. DRM_DEBUG_KMS("FDI train 1 done.\n");
  1871. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  1872. break;
  1873. }
  1874. }
  1875. if (tries == 5)
  1876. DRM_ERROR("FDI train 1 fail!\n");
  1877. /* Train 2 */
  1878. reg = FDI_TX_CTL(pipe);
  1879. temp = I915_READ(reg);
  1880. temp &= ~FDI_LINK_TRAIN_NONE;
  1881. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1882. I915_WRITE(reg, temp);
  1883. reg = FDI_RX_CTL(pipe);
  1884. temp = I915_READ(reg);
  1885. temp &= ~FDI_LINK_TRAIN_NONE;
  1886. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1887. I915_WRITE(reg, temp);
  1888. POSTING_READ(reg);
  1889. udelay(150);
  1890. reg = FDI_RX_IIR(pipe);
  1891. for (tries = 0; tries < 5; tries++) {
  1892. temp = I915_READ(reg);
  1893. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  1894. if (temp & FDI_RX_SYMBOL_LOCK) {
  1895. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  1896. DRM_DEBUG_KMS("FDI train 2 done.\n");
  1897. break;
  1898. }
  1899. }
  1900. if (tries == 5)
  1901. DRM_ERROR("FDI train 2 fail!\n");
  1902. DRM_DEBUG_KMS("FDI train done\n");
  1903. }
  1904. static const int snb_b_fdi_train_param [] = {
  1905. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  1906. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  1907. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  1908. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  1909. };
  1910. /* The FDI link training functions for SNB/Cougarpoint. */
  1911. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  1912. {
  1913. struct drm_device *dev = crtc->dev;
  1914. struct drm_i915_private *dev_priv = dev->dev_private;
  1915. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1916. int pipe = intel_crtc->pipe;
  1917. u32 reg, temp, i;
  1918. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  1919. for train result */
  1920. reg = FDI_RX_IMR(pipe);
  1921. temp = I915_READ(reg);
  1922. temp &= ~FDI_RX_SYMBOL_LOCK;
  1923. temp &= ~FDI_RX_BIT_LOCK;
  1924. I915_WRITE(reg, temp);
  1925. POSTING_READ(reg);
  1926. udelay(150);
  1927. /* enable CPU FDI TX and PCH FDI RX */
  1928. reg = FDI_TX_CTL(pipe);
  1929. temp = I915_READ(reg);
  1930. temp &= ~(7 << 19);
  1931. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  1932. temp &= ~FDI_LINK_TRAIN_NONE;
  1933. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1934. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  1935. /* SNB-B */
  1936. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  1937. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  1938. reg = FDI_RX_CTL(pipe);
  1939. temp = I915_READ(reg);
  1940. if (HAS_PCH_CPT(dev)) {
  1941. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  1942. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  1943. } else {
  1944. temp &= ~FDI_LINK_TRAIN_NONE;
  1945. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1946. }
  1947. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  1948. POSTING_READ(reg);
  1949. udelay(150);
  1950. for (i = 0; i < 4; i++ ) {
  1951. reg = FDI_TX_CTL(pipe);
  1952. temp = I915_READ(reg);
  1953. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  1954. temp |= snb_b_fdi_train_param[i];
  1955. I915_WRITE(reg, temp);
  1956. POSTING_READ(reg);
  1957. udelay(500);
  1958. reg = FDI_RX_IIR(pipe);
  1959. temp = I915_READ(reg);
  1960. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  1961. if (temp & FDI_RX_BIT_LOCK) {
  1962. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  1963. DRM_DEBUG_KMS("FDI train 1 done.\n");
  1964. break;
  1965. }
  1966. }
  1967. if (i == 4)
  1968. DRM_ERROR("FDI train 1 fail!\n");
  1969. /* Train 2 */
  1970. reg = FDI_TX_CTL(pipe);
  1971. temp = I915_READ(reg);
  1972. temp &= ~FDI_LINK_TRAIN_NONE;
  1973. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1974. if (IS_GEN6(dev)) {
  1975. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  1976. /* SNB-B */
  1977. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  1978. }
  1979. I915_WRITE(reg, temp);
  1980. reg = FDI_RX_CTL(pipe);
  1981. temp = I915_READ(reg);
  1982. if (HAS_PCH_CPT(dev)) {
  1983. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  1984. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  1985. } else {
  1986. temp &= ~FDI_LINK_TRAIN_NONE;
  1987. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1988. }
  1989. I915_WRITE(reg, temp);
  1990. POSTING_READ(reg);
  1991. udelay(150);
  1992. for (i = 0; i < 4; i++ ) {
  1993. reg = FDI_TX_CTL(pipe);
  1994. temp = I915_READ(reg);
  1995. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  1996. temp |= snb_b_fdi_train_param[i];
  1997. I915_WRITE(reg, temp);
  1998. POSTING_READ(reg);
  1999. udelay(500);
  2000. reg = FDI_RX_IIR(pipe);
  2001. temp = I915_READ(reg);
  2002. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2003. if (temp & FDI_RX_SYMBOL_LOCK) {
  2004. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2005. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2006. break;
  2007. }
  2008. }
  2009. if (i == 4)
  2010. DRM_ERROR("FDI train 2 fail!\n");
  2011. DRM_DEBUG_KMS("FDI train done.\n");
  2012. }
  2013. /* Manual link training for Ivy Bridge A0 parts */
  2014. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2015. {
  2016. struct drm_device *dev = crtc->dev;
  2017. struct drm_i915_private *dev_priv = dev->dev_private;
  2018. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2019. int pipe = intel_crtc->pipe;
  2020. u32 reg, temp, i;
  2021. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2022. for train result */
  2023. reg = FDI_RX_IMR(pipe);
  2024. temp = I915_READ(reg);
  2025. temp &= ~FDI_RX_SYMBOL_LOCK;
  2026. temp &= ~FDI_RX_BIT_LOCK;
  2027. I915_WRITE(reg, temp);
  2028. POSTING_READ(reg);
  2029. udelay(150);
  2030. /* enable CPU FDI TX and PCH FDI RX */
  2031. reg = FDI_TX_CTL(pipe);
  2032. temp = I915_READ(reg);
  2033. temp &= ~(7 << 19);
  2034. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2035. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2036. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2037. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2038. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2039. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2040. reg = FDI_RX_CTL(pipe);
  2041. temp = I915_READ(reg);
  2042. temp &= ~FDI_LINK_TRAIN_AUTO;
  2043. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2044. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2045. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2046. POSTING_READ(reg);
  2047. udelay(150);
  2048. for (i = 0; i < 4; i++ ) {
  2049. reg = FDI_TX_CTL(pipe);
  2050. temp = I915_READ(reg);
  2051. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2052. temp |= snb_b_fdi_train_param[i];
  2053. I915_WRITE(reg, temp);
  2054. POSTING_READ(reg);
  2055. udelay(500);
  2056. reg = FDI_RX_IIR(pipe);
  2057. temp = I915_READ(reg);
  2058. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2059. if (temp & FDI_RX_BIT_LOCK ||
  2060. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2061. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2062. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2063. break;
  2064. }
  2065. }
  2066. if (i == 4)
  2067. DRM_ERROR("FDI train 1 fail!\n");
  2068. /* Train 2 */
  2069. reg = FDI_TX_CTL(pipe);
  2070. temp = I915_READ(reg);
  2071. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2072. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2073. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2074. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2075. I915_WRITE(reg, temp);
  2076. reg = FDI_RX_CTL(pipe);
  2077. temp = I915_READ(reg);
  2078. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2079. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2080. I915_WRITE(reg, temp);
  2081. POSTING_READ(reg);
  2082. udelay(150);
  2083. for (i = 0; i < 4; i++ ) {
  2084. reg = FDI_TX_CTL(pipe);
  2085. temp = I915_READ(reg);
  2086. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2087. temp |= snb_b_fdi_train_param[i];
  2088. I915_WRITE(reg, temp);
  2089. POSTING_READ(reg);
  2090. udelay(500);
  2091. reg = FDI_RX_IIR(pipe);
  2092. temp = I915_READ(reg);
  2093. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2094. if (temp & FDI_RX_SYMBOL_LOCK) {
  2095. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2096. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2097. break;
  2098. }
  2099. }
  2100. if (i == 4)
  2101. DRM_ERROR("FDI train 2 fail!\n");
  2102. DRM_DEBUG_KMS("FDI train done.\n");
  2103. }
  2104. static void ironlake_fdi_pll_enable(struct drm_crtc *crtc)
  2105. {
  2106. struct drm_device *dev = crtc->dev;
  2107. struct drm_i915_private *dev_priv = dev->dev_private;
  2108. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2109. int pipe = intel_crtc->pipe;
  2110. u32 reg, temp;
  2111. /* Write the TU size bits so error detection works */
  2112. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  2113. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  2114. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2115. reg = FDI_RX_CTL(pipe);
  2116. temp = I915_READ(reg);
  2117. temp &= ~((0x7 << 19) | (0x7 << 16));
  2118. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2119. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2120. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2121. POSTING_READ(reg);
  2122. udelay(200);
  2123. /* Switch from Rawclk to PCDclk */
  2124. temp = I915_READ(reg);
  2125. I915_WRITE(reg, temp | FDI_PCDCLK);
  2126. POSTING_READ(reg);
  2127. udelay(200);
  2128. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2129. reg = FDI_TX_CTL(pipe);
  2130. temp = I915_READ(reg);
  2131. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2132. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2133. POSTING_READ(reg);
  2134. udelay(100);
  2135. }
  2136. }
  2137. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2138. {
  2139. struct drm_device *dev = crtc->dev;
  2140. struct drm_i915_private *dev_priv = dev->dev_private;
  2141. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2142. int pipe = intel_crtc->pipe;
  2143. u32 reg, temp;
  2144. /* disable CPU FDI tx and PCH FDI rx */
  2145. reg = FDI_TX_CTL(pipe);
  2146. temp = I915_READ(reg);
  2147. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2148. POSTING_READ(reg);
  2149. reg = FDI_RX_CTL(pipe);
  2150. temp = I915_READ(reg);
  2151. temp &= ~(0x7 << 16);
  2152. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2153. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2154. POSTING_READ(reg);
  2155. udelay(100);
  2156. /* Ironlake workaround, disable clock pointer after downing FDI */
  2157. if (HAS_PCH_IBX(dev)) {
  2158. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2159. I915_WRITE(FDI_RX_CHICKEN(pipe),
  2160. I915_READ(FDI_RX_CHICKEN(pipe) &
  2161. ~FDI_RX_PHASE_SYNC_POINTER_EN));
  2162. }
  2163. /* still set train pattern 1 */
  2164. reg = FDI_TX_CTL(pipe);
  2165. temp = I915_READ(reg);
  2166. temp &= ~FDI_LINK_TRAIN_NONE;
  2167. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2168. I915_WRITE(reg, temp);
  2169. reg = FDI_RX_CTL(pipe);
  2170. temp = I915_READ(reg);
  2171. if (HAS_PCH_CPT(dev)) {
  2172. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2173. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2174. } else {
  2175. temp &= ~FDI_LINK_TRAIN_NONE;
  2176. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2177. }
  2178. /* BPC in FDI rx is consistent with that in PIPECONF */
  2179. temp &= ~(0x07 << 16);
  2180. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2181. I915_WRITE(reg, temp);
  2182. POSTING_READ(reg);
  2183. udelay(100);
  2184. }
  2185. /*
  2186. * When we disable a pipe, we need to clear any pending scanline wait events
  2187. * to avoid hanging the ring, which we assume we are waiting on.
  2188. */
  2189. static void intel_clear_scanline_wait(struct drm_device *dev)
  2190. {
  2191. struct drm_i915_private *dev_priv = dev->dev_private;
  2192. struct intel_ring_buffer *ring;
  2193. u32 tmp;
  2194. if (IS_GEN2(dev))
  2195. /* Can't break the hang on i8xx */
  2196. return;
  2197. ring = LP_RING(dev_priv);
  2198. tmp = I915_READ_CTL(ring);
  2199. if (tmp & RING_WAIT)
  2200. I915_WRITE_CTL(ring, tmp);
  2201. }
  2202. static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2203. {
  2204. struct drm_i915_gem_object *obj;
  2205. struct drm_i915_private *dev_priv;
  2206. if (crtc->fb == NULL)
  2207. return;
  2208. obj = to_intel_framebuffer(crtc->fb)->obj;
  2209. dev_priv = crtc->dev->dev_private;
  2210. wait_event(dev_priv->pending_flip_queue,
  2211. atomic_read(&obj->pending_flip) == 0);
  2212. }
  2213. static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
  2214. {
  2215. struct drm_device *dev = crtc->dev;
  2216. struct drm_mode_config *mode_config = &dev->mode_config;
  2217. struct intel_encoder *encoder;
  2218. /*
  2219. * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
  2220. * must be driven by its own crtc; no sharing is possible.
  2221. */
  2222. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  2223. if (encoder->base.crtc != crtc)
  2224. continue;
  2225. switch (encoder->type) {
  2226. case INTEL_OUTPUT_EDP:
  2227. if (!intel_encoder_is_pch_edp(&encoder->base))
  2228. return false;
  2229. continue;
  2230. }
  2231. }
  2232. return true;
  2233. }
  2234. /*
  2235. * Enable PCH resources required for PCH ports:
  2236. * - PCH PLLs
  2237. * - FDI training & RX/TX
  2238. * - update transcoder timings
  2239. * - DP transcoding bits
  2240. * - transcoder
  2241. */
  2242. static void ironlake_pch_enable(struct drm_crtc *crtc)
  2243. {
  2244. struct drm_device *dev = crtc->dev;
  2245. struct drm_i915_private *dev_priv = dev->dev_private;
  2246. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2247. int pipe = intel_crtc->pipe;
  2248. u32 reg, temp;
  2249. /* For PCH output, training FDI link */
  2250. dev_priv->display.fdi_link_train(crtc);
  2251. intel_enable_pch_pll(dev_priv, pipe);
  2252. if (HAS_PCH_CPT(dev)) {
  2253. /* Be sure PCH DPLL SEL is set */
  2254. temp = I915_READ(PCH_DPLL_SEL);
  2255. if (pipe == 0 && (temp & TRANSA_DPLL_ENABLE) == 0)
  2256. temp |= (TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL);
  2257. else if (pipe == 1 && (temp & TRANSB_DPLL_ENABLE) == 0)
  2258. temp |= (TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2259. I915_WRITE(PCH_DPLL_SEL, temp);
  2260. }
  2261. /* set transcoder timing, panel must allow it */
  2262. assert_panel_unlocked(dev_priv, pipe);
  2263. I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
  2264. I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
  2265. I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
  2266. I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
  2267. I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
  2268. I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
  2269. intel_fdi_normal_train(crtc);
  2270. /* For PCH DP, enable TRANS_DP_CTL */
  2271. if (HAS_PCH_CPT(dev) &&
  2272. intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  2273. reg = TRANS_DP_CTL(pipe);
  2274. temp = I915_READ(reg);
  2275. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  2276. TRANS_DP_SYNC_MASK |
  2277. TRANS_DP_BPC_MASK);
  2278. temp |= (TRANS_DP_OUTPUT_ENABLE |
  2279. TRANS_DP_ENH_FRAMING);
  2280. temp |= TRANS_DP_8BPC;
  2281. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  2282. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  2283. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  2284. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  2285. switch (intel_trans_dp_port_sel(crtc)) {
  2286. case PCH_DP_B:
  2287. temp |= TRANS_DP_PORT_SEL_B;
  2288. break;
  2289. case PCH_DP_C:
  2290. temp |= TRANS_DP_PORT_SEL_C;
  2291. break;
  2292. case PCH_DP_D:
  2293. temp |= TRANS_DP_PORT_SEL_D;
  2294. break;
  2295. default:
  2296. DRM_DEBUG_KMS("Wrong PCH DP port return. Guess port B\n");
  2297. temp |= TRANS_DP_PORT_SEL_B;
  2298. break;
  2299. }
  2300. I915_WRITE(reg, temp);
  2301. }
  2302. intel_enable_transcoder(dev_priv, pipe);
  2303. }
  2304. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  2305. {
  2306. struct drm_device *dev = crtc->dev;
  2307. struct drm_i915_private *dev_priv = dev->dev_private;
  2308. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2309. int pipe = intel_crtc->pipe;
  2310. int plane = intel_crtc->plane;
  2311. u32 temp;
  2312. bool is_pch_port;
  2313. if (intel_crtc->active)
  2314. return;
  2315. intel_crtc->active = true;
  2316. intel_update_watermarks(dev);
  2317. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  2318. temp = I915_READ(PCH_LVDS);
  2319. if ((temp & LVDS_PORT_EN) == 0)
  2320. I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
  2321. }
  2322. is_pch_port = intel_crtc_driving_pch(crtc);
  2323. if (is_pch_port)
  2324. ironlake_fdi_pll_enable(crtc);
  2325. else
  2326. ironlake_fdi_disable(crtc);
  2327. /* Enable panel fitting for LVDS */
  2328. if (dev_priv->pch_pf_size &&
  2329. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || HAS_eDP)) {
  2330. /* Force use of hard-coded filter coefficients
  2331. * as some pre-programmed values are broken,
  2332. * e.g. x201.
  2333. */
  2334. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  2335. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2336. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2337. }
  2338. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2339. intel_enable_plane(dev_priv, plane, pipe);
  2340. if (is_pch_port)
  2341. ironlake_pch_enable(crtc);
  2342. intel_crtc_load_lut(crtc);
  2343. mutex_lock(&dev->struct_mutex);
  2344. intel_update_fbc(dev);
  2345. mutex_unlock(&dev->struct_mutex);
  2346. intel_crtc_update_cursor(crtc, true);
  2347. }
  2348. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  2349. {
  2350. struct drm_device *dev = crtc->dev;
  2351. struct drm_i915_private *dev_priv = dev->dev_private;
  2352. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2353. int pipe = intel_crtc->pipe;
  2354. int plane = intel_crtc->plane;
  2355. u32 reg, temp;
  2356. if (!intel_crtc->active)
  2357. return;
  2358. intel_crtc_wait_for_pending_flips(crtc);
  2359. drm_vblank_off(dev, pipe);
  2360. intel_crtc_update_cursor(crtc, false);
  2361. intel_disable_plane(dev_priv, plane, pipe);
  2362. if (dev_priv->cfb_plane == plane &&
  2363. dev_priv->display.disable_fbc)
  2364. dev_priv->display.disable_fbc(dev);
  2365. intel_disable_pipe(dev_priv, pipe);
  2366. /* Disable PF */
  2367. I915_WRITE(PF_CTL(pipe), 0);
  2368. I915_WRITE(PF_WIN_SZ(pipe), 0);
  2369. ironlake_fdi_disable(crtc);
  2370. /* This is a horrible layering violation; we should be doing this in
  2371. * the connector/encoder ->prepare instead, but we don't always have
  2372. * enough information there about the config to know whether it will
  2373. * actually be necessary or just cause undesired flicker.
  2374. */
  2375. intel_disable_pch_ports(dev_priv, pipe);
  2376. intel_disable_transcoder(dev_priv, pipe);
  2377. if (HAS_PCH_CPT(dev)) {
  2378. /* disable TRANS_DP_CTL */
  2379. reg = TRANS_DP_CTL(pipe);
  2380. temp = I915_READ(reg);
  2381. temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
  2382. temp |= TRANS_DP_PORT_SEL_NONE;
  2383. I915_WRITE(reg, temp);
  2384. /* disable DPLL_SEL */
  2385. temp = I915_READ(PCH_DPLL_SEL);
  2386. switch (pipe) {
  2387. case 0:
  2388. temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL);
  2389. break;
  2390. case 1:
  2391. temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2392. break;
  2393. case 2:
  2394. /* FIXME: manage transcoder PLLs? */
  2395. temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
  2396. break;
  2397. default:
  2398. BUG(); /* wtf */
  2399. }
  2400. I915_WRITE(PCH_DPLL_SEL, temp);
  2401. }
  2402. /* disable PCH DPLL */
  2403. intel_disable_pch_pll(dev_priv, pipe);
  2404. /* Switch from PCDclk to Rawclk */
  2405. reg = FDI_RX_CTL(pipe);
  2406. temp = I915_READ(reg);
  2407. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2408. /* Disable CPU FDI TX PLL */
  2409. reg = FDI_TX_CTL(pipe);
  2410. temp = I915_READ(reg);
  2411. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2412. POSTING_READ(reg);
  2413. udelay(100);
  2414. reg = FDI_RX_CTL(pipe);
  2415. temp = I915_READ(reg);
  2416. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2417. /* Wait for the clocks to turn off. */
  2418. POSTING_READ(reg);
  2419. udelay(100);
  2420. intel_crtc->active = false;
  2421. intel_update_watermarks(dev);
  2422. mutex_lock(&dev->struct_mutex);
  2423. intel_update_fbc(dev);
  2424. intel_clear_scanline_wait(dev);
  2425. mutex_unlock(&dev->struct_mutex);
  2426. }
  2427. static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode)
  2428. {
  2429. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2430. int pipe = intel_crtc->pipe;
  2431. int plane = intel_crtc->plane;
  2432. /* XXX: When our outputs are all unaware of DPMS modes other than off
  2433. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  2434. */
  2435. switch (mode) {
  2436. case DRM_MODE_DPMS_ON:
  2437. case DRM_MODE_DPMS_STANDBY:
  2438. case DRM_MODE_DPMS_SUSPEND:
  2439. DRM_DEBUG_KMS("crtc %d/%d dpms on\n", pipe, plane);
  2440. ironlake_crtc_enable(crtc);
  2441. break;
  2442. case DRM_MODE_DPMS_OFF:
  2443. DRM_DEBUG_KMS("crtc %d/%d dpms off\n", pipe, plane);
  2444. ironlake_crtc_disable(crtc);
  2445. break;
  2446. }
  2447. }
  2448. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  2449. {
  2450. if (!enable && intel_crtc->overlay) {
  2451. struct drm_device *dev = intel_crtc->base.dev;
  2452. struct drm_i915_private *dev_priv = dev->dev_private;
  2453. mutex_lock(&dev->struct_mutex);
  2454. dev_priv->mm.interruptible = false;
  2455. (void) intel_overlay_switch_off(intel_crtc->overlay);
  2456. dev_priv->mm.interruptible = true;
  2457. mutex_unlock(&dev->struct_mutex);
  2458. }
  2459. /* Let userspace switch the overlay on again. In most cases userspace
  2460. * has to recompute where to put it anyway.
  2461. */
  2462. }
  2463. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  2464. {
  2465. struct drm_device *dev = crtc->dev;
  2466. struct drm_i915_private *dev_priv = dev->dev_private;
  2467. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2468. int pipe = intel_crtc->pipe;
  2469. int plane = intel_crtc->plane;
  2470. if (intel_crtc->active)
  2471. return;
  2472. intel_crtc->active = true;
  2473. intel_update_watermarks(dev);
  2474. intel_enable_pll(dev_priv, pipe);
  2475. intel_enable_pipe(dev_priv, pipe, false);
  2476. intel_enable_plane(dev_priv, plane, pipe);
  2477. intel_crtc_load_lut(crtc);
  2478. intel_update_fbc(dev);
  2479. /* Give the overlay scaler a chance to enable if it's on this pipe */
  2480. intel_crtc_dpms_overlay(intel_crtc, true);
  2481. intel_crtc_update_cursor(crtc, true);
  2482. }
  2483. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  2484. {
  2485. struct drm_device *dev = crtc->dev;
  2486. struct drm_i915_private *dev_priv = dev->dev_private;
  2487. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2488. int pipe = intel_crtc->pipe;
  2489. int plane = intel_crtc->plane;
  2490. if (!intel_crtc->active)
  2491. return;
  2492. /* Give the overlay scaler a chance to disable if it's on this pipe */
  2493. intel_crtc_wait_for_pending_flips(crtc);
  2494. drm_vblank_off(dev, pipe);
  2495. intel_crtc_dpms_overlay(intel_crtc, false);
  2496. intel_crtc_update_cursor(crtc, false);
  2497. if (dev_priv->cfb_plane == plane &&
  2498. dev_priv->display.disable_fbc)
  2499. dev_priv->display.disable_fbc(dev);
  2500. intel_disable_plane(dev_priv, plane, pipe);
  2501. intel_disable_pipe(dev_priv, pipe);
  2502. intel_disable_pll(dev_priv, pipe);
  2503. intel_crtc->active = false;
  2504. intel_update_fbc(dev);
  2505. intel_update_watermarks(dev);
  2506. intel_clear_scanline_wait(dev);
  2507. }
  2508. static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
  2509. {
  2510. /* XXX: When our outputs are all unaware of DPMS modes other than off
  2511. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  2512. */
  2513. switch (mode) {
  2514. case DRM_MODE_DPMS_ON:
  2515. case DRM_MODE_DPMS_STANDBY:
  2516. case DRM_MODE_DPMS_SUSPEND:
  2517. i9xx_crtc_enable(crtc);
  2518. break;
  2519. case DRM_MODE_DPMS_OFF:
  2520. i9xx_crtc_disable(crtc);
  2521. break;
  2522. }
  2523. }
  2524. /**
  2525. * Sets the power management mode of the pipe and plane.
  2526. */
  2527. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  2528. {
  2529. struct drm_device *dev = crtc->dev;
  2530. struct drm_i915_private *dev_priv = dev->dev_private;
  2531. struct drm_i915_master_private *master_priv;
  2532. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2533. int pipe = intel_crtc->pipe;
  2534. bool enabled;
  2535. if (intel_crtc->dpms_mode == mode)
  2536. return;
  2537. intel_crtc->dpms_mode = mode;
  2538. dev_priv->display.dpms(crtc, mode);
  2539. if (!dev->primary->master)
  2540. return;
  2541. master_priv = dev->primary->master->driver_priv;
  2542. if (!master_priv->sarea_priv)
  2543. return;
  2544. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  2545. switch (pipe) {
  2546. case 0:
  2547. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  2548. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  2549. break;
  2550. case 1:
  2551. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  2552. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  2553. break;
  2554. default:
  2555. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  2556. break;
  2557. }
  2558. }
  2559. static void intel_crtc_disable(struct drm_crtc *crtc)
  2560. {
  2561. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  2562. struct drm_device *dev = crtc->dev;
  2563. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  2564. if (crtc->fb) {
  2565. mutex_lock(&dev->struct_mutex);
  2566. i915_gem_object_unpin(to_intel_framebuffer(crtc->fb)->obj);
  2567. mutex_unlock(&dev->struct_mutex);
  2568. }
  2569. }
  2570. /* Prepare for a mode set.
  2571. *
  2572. * Note we could be a lot smarter here. We need to figure out which outputs
  2573. * will be enabled, which disabled (in short, how the config will changes)
  2574. * and perform the minimum necessary steps to accomplish that, e.g. updating
  2575. * watermarks, FBC configuration, making sure PLLs are programmed correctly,
  2576. * panel fitting is in the proper state, etc.
  2577. */
  2578. static void i9xx_crtc_prepare(struct drm_crtc *crtc)
  2579. {
  2580. i9xx_crtc_disable(crtc);
  2581. }
  2582. static void i9xx_crtc_commit(struct drm_crtc *crtc)
  2583. {
  2584. i9xx_crtc_enable(crtc);
  2585. }
  2586. static void ironlake_crtc_prepare(struct drm_crtc *crtc)
  2587. {
  2588. ironlake_crtc_disable(crtc);
  2589. }
  2590. static void ironlake_crtc_commit(struct drm_crtc *crtc)
  2591. {
  2592. ironlake_crtc_enable(crtc);
  2593. }
  2594. void intel_encoder_prepare (struct drm_encoder *encoder)
  2595. {
  2596. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2597. /* lvds has its own version of prepare see intel_lvds_prepare */
  2598. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  2599. }
  2600. void intel_encoder_commit (struct drm_encoder *encoder)
  2601. {
  2602. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2603. /* lvds has its own version of commit see intel_lvds_commit */
  2604. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  2605. }
  2606. void intel_encoder_destroy(struct drm_encoder *encoder)
  2607. {
  2608. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  2609. drm_encoder_cleanup(encoder);
  2610. kfree(intel_encoder);
  2611. }
  2612. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  2613. struct drm_display_mode *mode,
  2614. struct drm_display_mode *adjusted_mode)
  2615. {
  2616. struct drm_device *dev = crtc->dev;
  2617. if (HAS_PCH_SPLIT(dev)) {
  2618. /* FDI link clock is fixed at 2.7G */
  2619. if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
  2620. return false;
  2621. }
  2622. /* XXX some encoders set the crtcinfo, others don't.
  2623. * Obviously we need some form of conflict resolution here...
  2624. */
  2625. if (adjusted_mode->crtc_htotal == 0)
  2626. drm_mode_set_crtcinfo(adjusted_mode, 0);
  2627. return true;
  2628. }
  2629. static int i945_get_display_clock_speed(struct drm_device *dev)
  2630. {
  2631. return 400000;
  2632. }
  2633. static int i915_get_display_clock_speed(struct drm_device *dev)
  2634. {
  2635. return 333000;
  2636. }
  2637. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  2638. {
  2639. return 200000;
  2640. }
  2641. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  2642. {
  2643. u16 gcfgc = 0;
  2644. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  2645. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  2646. return 133000;
  2647. else {
  2648. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  2649. case GC_DISPLAY_CLOCK_333_MHZ:
  2650. return 333000;
  2651. default:
  2652. case GC_DISPLAY_CLOCK_190_200_MHZ:
  2653. return 190000;
  2654. }
  2655. }
  2656. }
  2657. static int i865_get_display_clock_speed(struct drm_device *dev)
  2658. {
  2659. return 266000;
  2660. }
  2661. static int i855_get_display_clock_speed(struct drm_device *dev)
  2662. {
  2663. u16 hpllcc = 0;
  2664. /* Assume that the hardware is in the high speed state. This
  2665. * should be the default.
  2666. */
  2667. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  2668. case GC_CLOCK_133_200:
  2669. case GC_CLOCK_100_200:
  2670. return 200000;
  2671. case GC_CLOCK_166_250:
  2672. return 250000;
  2673. case GC_CLOCK_100_133:
  2674. return 133000;
  2675. }
  2676. /* Shouldn't happen */
  2677. return 0;
  2678. }
  2679. static int i830_get_display_clock_speed(struct drm_device *dev)
  2680. {
  2681. return 133000;
  2682. }
  2683. struct fdi_m_n {
  2684. u32 tu;
  2685. u32 gmch_m;
  2686. u32 gmch_n;
  2687. u32 link_m;
  2688. u32 link_n;
  2689. };
  2690. static void
  2691. fdi_reduce_ratio(u32 *num, u32 *den)
  2692. {
  2693. while (*num > 0xffffff || *den > 0xffffff) {
  2694. *num >>= 1;
  2695. *den >>= 1;
  2696. }
  2697. }
  2698. static void
  2699. ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock,
  2700. int link_clock, struct fdi_m_n *m_n)
  2701. {
  2702. m_n->tu = 64; /* default size */
  2703. /* BUG_ON(pixel_clock > INT_MAX / 36); */
  2704. m_n->gmch_m = bits_per_pixel * pixel_clock;
  2705. m_n->gmch_n = link_clock * nlanes * 8;
  2706. fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  2707. m_n->link_m = pixel_clock;
  2708. m_n->link_n = link_clock;
  2709. fdi_reduce_ratio(&m_n->link_m, &m_n->link_n);
  2710. }
  2711. struct intel_watermark_params {
  2712. unsigned long fifo_size;
  2713. unsigned long max_wm;
  2714. unsigned long default_wm;
  2715. unsigned long guard_size;
  2716. unsigned long cacheline_size;
  2717. };
  2718. /* Pineview has different values for various configs */
  2719. static const struct intel_watermark_params pineview_display_wm = {
  2720. PINEVIEW_DISPLAY_FIFO,
  2721. PINEVIEW_MAX_WM,
  2722. PINEVIEW_DFT_WM,
  2723. PINEVIEW_GUARD_WM,
  2724. PINEVIEW_FIFO_LINE_SIZE
  2725. };
  2726. static const struct intel_watermark_params pineview_display_hplloff_wm = {
  2727. PINEVIEW_DISPLAY_FIFO,
  2728. PINEVIEW_MAX_WM,
  2729. PINEVIEW_DFT_HPLLOFF_WM,
  2730. PINEVIEW_GUARD_WM,
  2731. PINEVIEW_FIFO_LINE_SIZE
  2732. };
  2733. static const struct intel_watermark_params pineview_cursor_wm = {
  2734. PINEVIEW_CURSOR_FIFO,
  2735. PINEVIEW_CURSOR_MAX_WM,
  2736. PINEVIEW_CURSOR_DFT_WM,
  2737. PINEVIEW_CURSOR_GUARD_WM,
  2738. PINEVIEW_FIFO_LINE_SIZE,
  2739. };
  2740. static const struct intel_watermark_params pineview_cursor_hplloff_wm = {
  2741. PINEVIEW_CURSOR_FIFO,
  2742. PINEVIEW_CURSOR_MAX_WM,
  2743. PINEVIEW_CURSOR_DFT_WM,
  2744. PINEVIEW_CURSOR_GUARD_WM,
  2745. PINEVIEW_FIFO_LINE_SIZE
  2746. };
  2747. static const struct intel_watermark_params g4x_wm_info = {
  2748. G4X_FIFO_SIZE,
  2749. G4X_MAX_WM,
  2750. G4X_MAX_WM,
  2751. 2,
  2752. G4X_FIFO_LINE_SIZE,
  2753. };
  2754. static const struct intel_watermark_params g4x_cursor_wm_info = {
  2755. I965_CURSOR_FIFO,
  2756. I965_CURSOR_MAX_WM,
  2757. I965_CURSOR_DFT_WM,
  2758. 2,
  2759. G4X_FIFO_LINE_SIZE,
  2760. };
  2761. static const struct intel_watermark_params i965_cursor_wm_info = {
  2762. I965_CURSOR_FIFO,
  2763. I965_CURSOR_MAX_WM,
  2764. I965_CURSOR_DFT_WM,
  2765. 2,
  2766. I915_FIFO_LINE_SIZE,
  2767. };
  2768. static const struct intel_watermark_params i945_wm_info = {
  2769. I945_FIFO_SIZE,
  2770. I915_MAX_WM,
  2771. 1,
  2772. 2,
  2773. I915_FIFO_LINE_SIZE
  2774. };
  2775. static const struct intel_watermark_params i915_wm_info = {
  2776. I915_FIFO_SIZE,
  2777. I915_MAX_WM,
  2778. 1,
  2779. 2,
  2780. I915_FIFO_LINE_SIZE
  2781. };
  2782. static const struct intel_watermark_params i855_wm_info = {
  2783. I855GM_FIFO_SIZE,
  2784. I915_MAX_WM,
  2785. 1,
  2786. 2,
  2787. I830_FIFO_LINE_SIZE
  2788. };
  2789. static const struct intel_watermark_params i830_wm_info = {
  2790. I830_FIFO_SIZE,
  2791. I915_MAX_WM,
  2792. 1,
  2793. 2,
  2794. I830_FIFO_LINE_SIZE
  2795. };
  2796. static const struct intel_watermark_params ironlake_display_wm_info = {
  2797. ILK_DISPLAY_FIFO,
  2798. ILK_DISPLAY_MAXWM,
  2799. ILK_DISPLAY_DFTWM,
  2800. 2,
  2801. ILK_FIFO_LINE_SIZE
  2802. };
  2803. static const struct intel_watermark_params ironlake_cursor_wm_info = {
  2804. ILK_CURSOR_FIFO,
  2805. ILK_CURSOR_MAXWM,
  2806. ILK_CURSOR_DFTWM,
  2807. 2,
  2808. ILK_FIFO_LINE_SIZE
  2809. };
  2810. static const struct intel_watermark_params ironlake_display_srwm_info = {
  2811. ILK_DISPLAY_SR_FIFO,
  2812. ILK_DISPLAY_MAX_SRWM,
  2813. ILK_DISPLAY_DFT_SRWM,
  2814. 2,
  2815. ILK_FIFO_LINE_SIZE
  2816. };
  2817. static const struct intel_watermark_params ironlake_cursor_srwm_info = {
  2818. ILK_CURSOR_SR_FIFO,
  2819. ILK_CURSOR_MAX_SRWM,
  2820. ILK_CURSOR_DFT_SRWM,
  2821. 2,
  2822. ILK_FIFO_LINE_SIZE
  2823. };
  2824. static const struct intel_watermark_params sandybridge_display_wm_info = {
  2825. SNB_DISPLAY_FIFO,
  2826. SNB_DISPLAY_MAXWM,
  2827. SNB_DISPLAY_DFTWM,
  2828. 2,
  2829. SNB_FIFO_LINE_SIZE
  2830. };
  2831. static const struct intel_watermark_params sandybridge_cursor_wm_info = {
  2832. SNB_CURSOR_FIFO,
  2833. SNB_CURSOR_MAXWM,
  2834. SNB_CURSOR_DFTWM,
  2835. 2,
  2836. SNB_FIFO_LINE_SIZE
  2837. };
  2838. static const struct intel_watermark_params sandybridge_display_srwm_info = {
  2839. SNB_DISPLAY_SR_FIFO,
  2840. SNB_DISPLAY_MAX_SRWM,
  2841. SNB_DISPLAY_DFT_SRWM,
  2842. 2,
  2843. SNB_FIFO_LINE_SIZE
  2844. };
  2845. static const struct intel_watermark_params sandybridge_cursor_srwm_info = {
  2846. SNB_CURSOR_SR_FIFO,
  2847. SNB_CURSOR_MAX_SRWM,
  2848. SNB_CURSOR_DFT_SRWM,
  2849. 2,
  2850. SNB_FIFO_LINE_SIZE
  2851. };
  2852. /**
  2853. * intel_calculate_wm - calculate watermark level
  2854. * @clock_in_khz: pixel clock
  2855. * @wm: chip FIFO params
  2856. * @pixel_size: display pixel size
  2857. * @latency_ns: memory latency for the platform
  2858. *
  2859. * Calculate the watermark level (the level at which the display plane will
  2860. * start fetching from memory again). Each chip has a different display
  2861. * FIFO size and allocation, so the caller needs to figure that out and pass
  2862. * in the correct intel_watermark_params structure.
  2863. *
  2864. * As the pixel clock runs, the FIFO will be drained at a rate that depends
  2865. * on the pixel size. When it reaches the watermark level, it'll start
  2866. * fetching FIFO line sized based chunks from memory until the FIFO fills
  2867. * past the watermark point. If the FIFO drains completely, a FIFO underrun
  2868. * will occur, and a display engine hang could result.
  2869. */
  2870. static unsigned long intel_calculate_wm(unsigned long clock_in_khz,
  2871. const struct intel_watermark_params *wm,
  2872. int fifo_size,
  2873. int pixel_size,
  2874. unsigned long latency_ns)
  2875. {
  2876. long entries_required, wm_size;
  2877. /*
  2878. * Note: we need to make sure we don't overflow for various clock &
  2879. * latency values.
  2880. * clocks go from a few thousand to several hundred thousand.
  2881. * latency is usually a few thousand
  2882. */
  2883. entries_required = ((clock_in_khz / 1000) * pixel_size * latency_ns) /
  2884. 1000;
  2885. entries_required = DIV_ROUND_UP(entries_required, wm->cacheline_size);
  2886. DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required);
  2887. wm_size = fifo_size - (entries_required + wm->guard_size);
  2888. DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size);
  2889. /* Don't promote wm_size to unsigned... */
  2890. if (wm_size > (long)wm->max_wm)
  2891. wm_size = wm->max_wm;
  2892. if (wm_size <= 0)
  2893. wm_size = wm->default_wm;
  2894. return wm_size;
  2895. }
  2896. struct cxsr_latency {
  2897. int is_desktop;
  2898. int is_ddr3;
  2899. unsigned long fsb_freq;
  2900. unsigned long mem_freq;
  2901. unsigned long display_sr;
  2902. unsigned long display_hpll_disable;
  2903. unsigned long cursor_sr;
  2904. unsigned long cursor_hpll_disable;
  2905. };
  2906. static const struct cxsr_latency cxsr_latency_table[] = {
  2907. {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
  2908. {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
  2909. {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
  2910. {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
  2911. {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
  2912. {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
  2913. {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
  2914. {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
  2915. {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
  2916. {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
  2917. {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
  2918. {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
  2919. {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
  2920. {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
  2921. {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
  2922. {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
  2923. {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
  2924. {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
  2925. {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
  2926. {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
  2927. {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
  2928. {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
  2929. {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
  2930. {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
  2931. {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
  2932. {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
  2933. {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
  2934. {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
  2935. {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
  2936. {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
  2937. };
  2938. static const struct cxsr_latency *intel_get_cxsr_latency(int is_desktop,
  2939. int is_ddr3,
  2940. int fsb,
  2941. int mem)
  2942. {
  2943. const struct cxsr_latency *latency;
  2944. int i;
  2945. if (fsb == 0 || mem == 0)
  2946. return NULL;
  2947. for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
  2948. latency = &cxsr_latency_table[i];
  2949. if (is_desktop == latency->is_desktop &&
  2950. is_ddr3 == latency->is_ddr3 &&
  2951. fsb == latency->fsb_freq && mem == latency->mem_freq)
  2952. return latency;
  2953. }
  2954. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  2955. return NULL;
  2956. }
  2957. static void pineview_disable_cxsr(struct drm_device *dev)
  2958. {
  2959. struct drm_i915_private *dev_priv = dev->dev_private;
  2960. /* deactivate cxsr */
  2961. I915_WRITE(DSPFW3, I915_READ(DSPFW3) & ~PINEVIEW_SELF_REFRESH_EN);
  2962. }
  2963. /*
  2964. * Latency for FIFO fetches is dependent on several factors:
  2965. * - memory configuration (speed, channels)
  2966. * - chipset
  2967. * - current MCH state
  2968. * It can be fairly high in some situations, so here we assume a fairly
  2969. * pessimal value. It's a tradeoff between extra memory fetches (if we
  2970. * set this value too high, the FIFO will fetch frequently to stay full)
  2971. * and power consumption (set it too low to save power and we might see
  2972. * FIFO underruns and display "flicker").
  2973. *
  2974. * A value of 5us seems to be a good balance; safe for very low end
  2975. * platforms but not overly aggressive on lower latency configs.
  2976. */
  2977. static const int latency_ns = 5000;
  2978. static int i9xx_get_fifo_size(struct drm_device *dev, int plane)
  2979. {
  2980. struct drm_i915_private *dev_priv = dev->dev_private;
  2981. uint32_t dsparb = I915_READ(DSPARB);
  2982. int size;
  2983. size = dsparb & 0x7f;
  2984. if (plane)
  2985. size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
  2986. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  2987. plane ? "B" : "A", size);
  2988. return size;
  2989. }
  2990. static int i85x_get_fifo_size(struct drm_device *dev, int plane)
  2991. {
  2992. struct drm_i915_private *dev_priv = dev->dev_private;
  2993. uint32_t dsparb = I915_READ(DSPARB);
  2994. int size;
  2995. size = dsparb & 0x1ff;
  2996. if (plane)
  2997. size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
  2998. size >>= 1; /* Convert to cachelines */
  2999. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3000. plane ? "B" : "A", size);
  3001. return size;
  3002. }
  3003. static int i845_get_fifo_size(struct drm_device *dev, int plane)
  3004. {
  3005. struct drm_i915_private *dev_priv = dev->dev_private;
  3006. uint32_t dsparb = I915_READ(DSPARB);
  3007. int size;
  3008. size = dsparb & 0x7f;
  3009. size >>= 2; /* Convert to cachelines */
  3010. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3011. plane ? "B" : "A",
  3012. size);
  3013. return size;
  3014. }
  3015. static int i830_get_fifo_size(struct drm_device *dev, int plane)
  3016. {
  3017. struct drm_i915_private *dev_priv = dev->dev_private;
  3018. uint32_t dsparb = I915_READ(DSPARB);
  3019. int size;
  3020. size = dsparb & 0x7f;
  3021. size >>= 1; /* Convert to cachelines */
  3022. DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb,
  3023. plane ? "B" : "A", size);
  3024. return size;
  3025. }
  3026. static struct drm_crtc *single_enabled_crtc(struct drm_device *dev)
  3027. {
  3028. struct drm_crtc *crtc, *enabled = NULL;
  3029. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3030. if (crtc->enabled && crtc->fb) {
  3031. if (enabled)
  3032. return NULL;
  3033. enabled = crtc;
  3034. }
  3035. }
  3036. return enabled;
  3037. }
  3038. static void pineview_update_wm(struct drm_device *dev)
  3039. {
  3040. struct drm_i915_private *dev_priv = dev->dev_private;
  3041. struct drm_crtc *crtc;
  3042. const struct cxsr_latency *latency;
  3043. u32 reg;
  3044. unsigned long wm;
  3045. latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->is_ddr3,
  3046. dev_priv->fsb_freq, dev_priv->mem_freq);
  3047. if (!latency) {
  3048. DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
  3049. pineview_disable_cxsr(dev);
  3050. return;
  3051. }
  3052. crtc = single_enabled_crtc(dev);
  3053. if (crtc) {
  3054. int clock = crtc->mode.clock;
  3055. int pixel_size = crtc->fb->bits_per_pixel / 8;
  3056. /* Display SR */
  3057. wm = intel_calculate_wm(clock, &pineview_display_wm,
  3058. pineview_display_wm.fifo_size,
  3059. pixel_size, latency->display_sr);
  3060. reg = I915_READ(DSPFW1);
  3061. reg &= ~DSPFW_SR_MASK;
  3062. reg |= wm << DSPFW_SR_SHIFT;
  3063. I915_WRITE(DSPFW1, reg);
  3064. DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg);
  3065. /* cursor SR */
  3066. wm = intel_calculate_wm(clock, &pineview_cursor_wm,
  3067. pineview_display_wm.fifo_size,
  3068. pixel_size, latency->cursor_sr);
  3069. reg = I915_READ(DSPFW3);
  3070. reg &= ~DSPFW_CURSOR_SR_MASK;
  3071. reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT;
  3072. I915_WRITE(DSPFW3, reg);
  3073. /* Display HPLL off SR */
  3074. wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm,
  3075. pineview_display_hplloff_wm.fifo_size,
  3076. pixel_size, latency->display_hpll_disable);
  3077. reg = I915_READ(DSPFW3);
  3078. reg &= ~DSPFW_HPLL_SR_MASK;
  3079. reg |= wm & DSPFW_HPLL_SR_MASK;
  3080. I915_WRITE(DSPFW3, reg);
  3081. /* cursor HPLL off SR */
  3082. wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm,
  3083. pineview_display_hplloff_wm.fifo_size,
  3084. pixel_size, latency->cursor_hpll_disable);
  3085. reg = I915_READ(DSPFW3);
  3086. reg &= ~DSPFW_HPLL_CURSOR_MASK;
  3087. reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT;
  3088. I915_WRITE(DSPFW3, reg);
  3089. DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg);
  3090. /* activate cxsr */
  3091. I915_WRITE(DSPFW3,
  3092. I915_READ(DSPFW3) | PINEVIEW_SELF_REFRESH_EN);
  3093. DRM_DEBUG_KMS("Self-refresh is enabled\n");
  3094. } else {
  3095. pineview_disable_cxsr(dev);
  3096. DRM_DEBUG_KMS("Self-refresh is disabled\n");
  3097. }
  3098. }
  3099. static bool g4x_compute_wm0(struct drm_device *dev,
  3100. int plane,
  3101. const struct intel_watermark_params *display,
  3102. int display_latency_ns,
  3103. const struct intel_watermark_params *cursor,
  3104. int cursor_latency_ns,
  3105. int *plane_wm,
  3106. int *cursor_wm)
  3107. {
  3108. struct drm_crtc *crtc;
  3109. int htotal, hdisplay, clock, pixel_size;
  3110. int line_time_us, line_count;
  3111. int entries, tlb_miss;
  3112. crtc = intel_get_crtc_for_plane(dev, plane);
  3113. if (crtc->fb == NULL || !crtc->enabled) {
  3114. *cursor_wm = cursor->guard_size;
  3115. *plane_wm = display->guard_size;
  3116. return false;
  3117. }
  3118. htotal = crtc->mode.htotal;
  3119. hdisplay = crtc->mode.hdisplay;
  3120. clock = crtc->mode.clock;
  3121. pixel_size = crtc->fb->bits_per_pixel / 8;
  3122. /* Use the small buffer method to calculate plane watermark */
  3123. entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;
  3124. tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;
  3125. if (tlb_miss > 0)
  3126. entries += tlb_miss;
  3127. entries = DIV_ROUND_UP(entries, display->cacheline_size);
  3128. *plane_wm = entries + display->guard_size;
  3129. if (*plane_wm > (int)display->max_wm)
  3130. *plane_wm = display->max_wm;
  3131. /* Use the large buffer method to calculate cursor watermark */
  3132. line_time_us = ((htotal * 1000) / clock);
  3133. line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;
  3134. entries = line_count * 64 * pixel_size;
  3135. tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;
  3136. if (tlb_miss > 0)
  3137. entries += tlb_miss;
  3138. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3139. *cursor_wm = entries + cursor->guard_size;
  3140. if (*cursor_wm > (int)cursor->max_wm)
  3141. *cursor_wm = (int)cursor->max_wm;
  3142. return true;
  3143. }
  3144. /*
  3145. * Check the wm result.
  3146. *
  3147. * If any calculated watermark values is larger than the maximum value that
  3148. * can be programmed into the associated watermark register, that watermark
  3149. * must be disabled.
  3150. */
  3151. static bool g4x_check_srwm(struct drm_device *dev,
  3152. int display_wm, int cursor_wm,
  3153. const struct intel_watermark_params *display,
  3154. const struct intel_watermark_params *cursor)
  3155. {
  3156. DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n",
  3157. display_wm, cursor_wm);
  3158. if (display_wm > display->max_wm) {
  3159. DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n",
  3160. display_wm, display->max_wm);
  3161. return false;
  3162. }
  3163. if (cursor_wm > cursor->max_wm) {
  3164. DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n",
  3165. cursor_wm, cursor->max_wm);
  3166. return false;
  3167. }
  3168. if (!(display_wm || cursor_wm)) {
  3169. DRM_DEBUG_KMS("SR latency is 0, disabling\n");
  3170. return false;
  3171. }
  3172. return true;
  3173. }
  3174. static bool g4x_compute_srwm(struct drm_device *dev,
  3175. int plane,
  3176. int latency_ns,
  3177. const struct intel_watermark_params *display,
  3178. const struct intel_watermark_params *cursor,
  3179. int *display_wm, int *cursor_wm)
  3180. {
  3181. struct drm_crtc *crtc;
  3182. int hdisplay, htotal, pixel_size, clock;
  3183. unsigned long line_time_us;
  3184. int line_count, line_size;
  3185. int small, large;
  3186. int entries;
  3187. if (!latency_ns) {
  3188. *display_wm = *cursor_wm = 0;
  3189. return false;
  3190. }
  3191. crtc = intel_get_crtc_for_plane(dev, plane);
  3192. hdisplay = crtc->mode.hdisplay;
  3193. htotal = crtc->mode.htotal;
  3194. clock = crtc->mode.clock;
  3195. pixel_size = crtc->fb->bits_per_pixel / 8;
  3196. line_time_us = (htotal * 1000) / clock;
  3197. line_count = (latency_ns / line_time_us + 1000) / 1000;
  3198. line_size = hdisplay * pixel_size;
  3199. /* Use the minimum of the small and large buffer method for primary */
  3200. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  3201. large = line_count * line_size;
  3202. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  3203. *display_wm = entries + display->guard_size;
  3204. /* calculate the self-refresh watermark for display cursor */
  3205. entries = line_count * pixel_size * 64;
  3206. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3207. *cursor_wm = entries + cursor->guard_size;
  3208. return g4x_check_srwm(dev,
  3209. *display_wm, *cursor_wm,
  3210. display, cursor);
  3211. }
  3212. #define single_plane_enabled(mask) is_power_of_2(mask)
  3213. static void g4x_update_wm(struct drm_device *dev)
  3214. {
  3215. static const int sr_latency_ns = 12000;
  3216. struct drm_i915_private *dev_priv = dev->dev_private;
  3217. int planea_wm, planeb_wm, cursora_wm, cursorb_wm;
  3218. int plane_sr, cursor_sr;
  3219. unsigned int enabled = 0;
  3220. if (g4x_compute_wm0(dev, 0,
  3221. &g4x_wm_info, latency_ns,
  3222. &g4x_cursor_wm_info, latency_ns,
  3223. &planea_wm, &cursora_wm))
  3224. enabled |= 1;
  3225. if (g4x_compute_wm0(dev, 1,
  3226. &g4x_wm_info, latency_ns,
  3227. &g4x_cursor_wm_info, latency_ns,
  3228. &planeb_wm, &cursorb_wm))
  3229. enabled |= 2;
  3230. plane_sr = cursor_sr = 0;
  3231. if (single_plane_enabled(enabled) &&
  3232. g4x_compute_srwm(dev, ffs(enabled) - 1,
  3233. sr_latency_ns,
  3234. &g4x_wm_info,
  3235. &g4x_cursor_wm_info,
  3236. &plane_sr, &cursor_sr))
  3237. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  3238. else
  3239. I915_WRITE(FW_BLC_SELF,
  3240. I915_READ(FW_BLC_SELF) & ~FW_BLC_SELF_EN);
  3241. DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
  3242. planea_wm, cursora_wm,
  3243. planeb_wm, cursorb_wm,
  3244. plane_sr, cursor_sr);
  3245. I915_WRITE(DSPFW1,
  3246. (plane_sr << DSPFW_SR_SHIFT) |
  3247. (cursorb_wm << DSPFW_CURSORB_SHIFT) |
  3248. (planeb_wm << DSPFW_PLANEB_SHIFT) |
  3249. planea_wm);
  3250. I915_WRITE(DSPFW2,
  3251. (I915_READ(DSPFW2) & DSPFW_CURSORA_MASK) |
  3252. (cursora_wm << DSPFW_CURSORA_SHIFT));
  3253. /* HPLL off in SR has some issues on G4x... disable it */
  3254. I915_WRITE(DSPFW3,
  3255. (I915_READ(DSPFW3) & ~DSPFW_HPLL_SR_EN) |
  3256. (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  3257. }
  3258. static void i965_update_wm(struct drm_device *dev)
  3259. {
  3260. struct drm_i915_private *dev_priv = dev->dev_private;
  3261. struct drm_crtc *crtc;
  3262. int srwm = 1;
  3263. int cursor_sr = 16;
  3264. /* Calc sr entries for one plane configs */
  3265. crtc = single_enabled_crtc(dev);
  3266. if (crtc) {
  3267. /* self-refresh has much higher latency */
  3268. static const int sr_latency_ns = 12000;
  3269. int clock = crtc->mode.clock;
  3270. int htotal = crtc->mode.htotal;
  3271. int hdisplay = crtc->mode.hdisplay;
  3272. int pixel_size = crtc->fb->bits_per_pixel / 8;
  3273. unsigned long line_time_us;
  3274. int entries;
  3275. line_time_us = ((htotal * 1000) / clock);
  3276. /* Use ns/us then divide to preserve precision */
  3277. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  3278. pixel_size * hdisplay;
  3279. entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE);
  3280. srwm = I965_FIFO_SIZE - entries;
  3281. if (srwm < 0)
  3282. srwm = 1;
  3283. srwm &= 0x1ff;
  3284. DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n",
  3285. entries, srwm);
  3286. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  3287. pixel_size * 64;
  3288. entries = DIV_ROUND_UP(entries,
  3289. i965_cursor_wm_info.cacheline_size);
  3290. cursor_sr = i965_cursor_wm_info.fifo_size -
  3291. (entries + i965_cursor_wm_info.guard_size);
  3292. if (cursor_sr > i965_cursor_wm_info.max_wm)
  3293. cursor_sr = i965_cursor_wm_info.max_wm;
  3294. DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
  3295. "cursor %d\n", srwm, cursor_sr);
  3296. if (IS_CRESTLINE(dev))
  3297. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN);
  3298. } else {
  3299. /* Turn off self refresh if both pipes are enabled */
  3300. if (IS_CRESTLINE(dev))
  3301. I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF)
  3302. & ~FW_BLC_SELF_EN);
  3303. }
  3304. DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
  3305. srwm);
  3306. /* 965 has limitations... */
  3307. I915_WRITE(DSPFW1, (srwm << DSPFW_SR_SHIFT) |
  3308. (8 << 16) | (8 << 8) | (8 << 0));
  3309. I915_WRITE(DSPFW2, (8 << 8) | (8 << 0));
  3310. /* update cursor SR watermark */
  3311. I915_WRITE(DSPFW3, (cursor_sr << DSPFW_CURSOR_SR_SHIFT));
  3312. }
  3313. static void i9xx_update_wm(struct drm_device *dev)
  3314. {
  3315. struct drm_i915_private *dev_priv = dev->dev_private;
  3316. const struct intel_watermark_params *wm_info;
  3317. uint32_t fwater_lo;
  3318. uint32_t fwater_hi;
  3319. int cwm, srwm = 1;
  3320. int fifo_size;
  3321. int planea_wm, planeb_wm;
  3322. struct drm_crtc *crtc, *enabled = NULL;
  3323. if (IS_I945GM(dev))
  3324. wm_info = &i945_wm_info;
  3325. else if (!IS_GEN2(dev))
  3326. wm_info = &i915_wm_info;
  3327. else
  3328. wm_info = &i855_wm_info;
  3329. fifo_size = dev_priv->display.get_fifo_size(dev, 0);
  3330. crtc = intel_get_crtc_for_plane(dev, 0);
  3331. if (crtc->enabled && crtc->fb) {
  3332. planea_wm = intel_calculate_wm(crtc->mode.clock,
  3333. wm_info, fifo_size,
  3334. crtc->fb->bits_per_pixel / 8,
  3335. latency_ns);
  3336. enabled = crtc;
  3337. } else
  3338. planea_wm = fifo_size - wm_info->guard_size;
  3339. fifo_size = dev_priv->display.get_fifo_size(dev, 1);
  3340. crtc = intel_get_crtc_for_plane(dev, 1);
  3341. if (crtc->enabled && crtc->fb) {
  3342. planeb_wm = intel_calculate_wm(crtc->mode.clock,
  3343. wm_info, fifo_size,
  3344. crtc->fb->bits_per_pixel / 8,
  3345. latency_ns);
  3346. if (enabled == NULL)
  3347. enabled = crtc;
  3348. else
  3349. enabled = NULL;
  3350. } else
  3351. planeb_wm = fifo_size - wm_info->guard_size;
  3352. DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
  3353. /*
  3354. * Overlay gets an aggressive default since video jitter is bad.
  3355. */
  3356. cwm = 2;
  3357. /* Play safe and disable self-refresh before adjusting watermarks. */
  3358. if (IS_I945G(dev) || IS_I945GM(dev))
  3359. I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | 0);
  3360. else if (IS_I915GM(dev))
  3361. I915_WRITE(INSTPM, I915_READ(INSTPM) & ~INSTPM_SELF_EN);
  3362. /* Calc sr entries for one plane configs */
  3363. if (HAS_FW_BLC(dev) && enabled) {
  3364. /* self-refresh has much higher latency */
  3365. static const int sr_latency_ns = 6000;
  3366. int clock = enabled->mode.clock;
  3367. int htotal = enabled->mode.htotal;
  3368. int hdisplay = enabled->mode.hdisplay;
  3369. int pixel_size = enabled->fb->bits_per_pixel / 8;
  3370. unsigned long line_time_us;
  3371. int entries;
  3372. line_time_us = (htotal * 1000) / clock;
  3373. /* Use ns/us then divide to preserve precision */
  3374. entries = (((sr_latency_ns / line_time_us) + 1000) / 1000) *
  3375. pixel_size * hdisplay;
  3376. entries = DIV_ROUND_UP(entries, wm_info->cacheline_size);
  3377. DRM_DEBUG_KMS("self-refresh entries: %d\n", entries);
  3378. srwm = wm_info->fifo_size - entries;
  3379. if (srwm < 0)
  3380. srwm = 1;
  3381. if (IS_I945G(dev) || IS_I945GM(dev))
  3382. I915_WRITE(FW_BLC_SELF,
  3383. FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
  3384. else if (IS_I915GM(dev))
  3385. I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
  3386. }
  3387. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
  3388. planea_wm, planeb_wm, cwm, srwm);
  3389. fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
  3390. fwater_hi = (cwm & 0x1f);
  3391. /* Set request length to 8 cachelines per fetch */
  3392. fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
  3393. fwater_hi = fwater_hi | (1 << 8);
  3394. I915_WRITE(FW_BLC, fwater_lo);
  3395. I915_WRITE(FW_BLC2, fwater_hi);
  3396. if (HAS_FW_BLC(dev)) {
  3397. if (enabled) {
  3398. if (IS_I945G(dev) || IS_I945GM(dev))
  3399. I915_WRITE(FW_BLC_SELF,
  3400. FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN);
  3401. else if (IS_I915GM(dev))
  3402. I915_WRITE(INSTPM, I915_READ(INSTPM) | INSTPM_SELF_EN);
  3403. DRM_DEBUG_KMS("memory self refresh enabled\n");
  3404. } else
  3405. DRM_DEBUG_KMS("memory self refresh disabled\n");
  3406. }
  3407. }
  3408. static void i830_update_wm(struct drm_device *dev)
  3409. {
  3410. struct drm_i915_private *dev_priv = dev->dev_private;
  3411. struct drm_crtc *crtc;
  3412. uint32_t fwater_lo;
  3413. int planea_wm;
  3414. crtc = single_enabled_crtc(dev);
  3415. if (crtc == NULL)
  3416. return;
  3417. planea_wm = intel_calculate_wm(crtc->mode.clock, &i830_wm_info,
  3418. dev_priv->display.get_fifo_size(dev, 0),
  3419. crtc->fb->bits_per_pixel / 8,
  3420. latency_ns);
  3421. fwater_lo = I915_READ(FW_BLC) & ~0xfff;
  3422. fwater_lo |= (3<<8) | planea_wm;
  3423. DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm);
  3424. I915_WRITE(FW_BLC, fwater_lo);
  3425. }
  3426. #define ILK_LP0_PLANE_LATENCY 700
  3427. #define ILK_LP0_CURSOR_LATENCY 1300
  3428. /*
  3429. * Check the wm result.
  3430. *
  3431. * If any calculated watermark values is larger than the maximum value that
  3432. * can be programmed into the associated watermark register, that watermark
  3433. * must be disabled.
  3434. */
  3435. static bool ironlake_check_srwm(struct drm_device *dev, int level,
  3436. int fbc_wm, int display_wm, int cursor_wm,
  3437. const struct intel_watermark_params *display,
  3438. const struct intel_watermark_params *cursor)
  3439. {
  3440. struct drm_i915_private *dev_priv = dev->dev_private;
  3441. DRM_DEBUG_KMS("watermark %d: display plane %d, fbc lines %d,"
  3442. " cursor %d\n", level, display_wm, fbc_wm, cursor_wm);
  3443. if (fbc_wm > SNB_FBC_MAX_SRWM) {
  3444. DRM_DEBUG_KMS("fbc watermark(%d) is too large(%d), disabling wm%d+\n",
  3445. fbc_wm, SNB_FBC_MAX_SRWM, level);
  3446. /* fbc has it's own way to disable FBC WM */
  3447. I915_WRITE(DISP_ARB_CTL,
  3448. I915_READ(DISP_ARB_CTL) | DISP_FBC_WM_DIS);
  3449. return false;
  3450. }
  3451. if (display_wm > display->max_wm) {
  3452. DRM_DEBUG_KMS("display watermark(%d) is too large(%d), disabling wm%d+\n",
  3453. display_wm, SNB_DISPLAY_MAX_SRWM, level);
  3454. return false;
  3455. }
  3456. if (cursor_wm > cursor->max_wm) {
  3457. DRM_DEBUG_KMS("cursor watermark(%d) is too large(%d), disabling wm%d+\n",
  3458. cursor_wm, SNB_CURSOR_MAX_SRWM, level);
  3459. return false;
  3460. }
  3461. if (!(fbc_wm || display_wm || cursor_wm)) {
  3462. DRM_DEBUG_KMS("latency %d is 0, disabling wm%d+\n", level, level);
  3463. return false;
  3464. }
  3465. return true;
  3466. }
  3467. /*
  3468. * Compute watermark values of WM[1-3],
  3469. */
  3470. static bool ironlake_compute_srwm(struct drm_device *dev, int level, int plane,
  3471. int latency_ns,
  3472. const struct intel_watermark_params *display,
  3473. const struct intel_watermark_params *cursor,
  3474. int *fbc_wm, int *display_wm, int *cursor_wm)
  3475. {
  3476. struct drm_crtc *crtc;
  3477. unsigned long line_time_us;
  3478. int hdisplay, htotal, pixel_size, clock;
  3479. int line_count, line_size;
  3480. int small, large;
  3481. int entries;
  3482. if (!latency_ns) {
  3483. *fbc_wm = *display_wm = *cursor_wm = 0;
  3484. return false;
  3485. }
  3486. crtc = intel_get_crtc_for_plane(dev, plane);
  3487. hdisplay = crtc->mode.hdisplay;
  3488. htotal = crtc->mode.htotal;
  3489. clock = crtc->mode.clock;
  3490. pixel_size = crtc->fb->bits_per_pixel / 8;
  3491. line_time_us = (htotal * 1000) / clock;
  3492. line_count = (latency_ns / line_time_us + 1000) / 1000;
  3493. line_size = hdisplay * pixel_size;
  3494. /* Use the minimum of the small and large buffer method for primary */
  3495. small = ((clock * pixel_size / 1000) * latency_ns) / 1000;
  3496. large = line_count * line_size;
  3497. entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);
  3498. *display_wm = entries + display->guard_size;
  3499. /*
  3500. * Spec says:
  3501. * FBC WM = ((Final Primary WM * 64) / number of bytes per line) + 2
  3502. */
  3503. *fbc_wm = DIV_ROUND_UP(*display_wm * 64, line_size) + 2;
  3504. /* calculate the self-refresh watermark for display cursor */
  3505. entries = line_count * pixel_size * 64;
  3506. entries = DIV_ROUND_UP(entries, cursor->cacheline_size);
  3507. *cursor_wm = entries + cursor->guard_size;
  3508. return ironlake_check_srwm(dev, level,
  3509. *fbc_wm, *display_wm, *cursor_wm,
  3510. display, cursor);
  3511. }
  3512. static void ironlake_update_wm(struct drm_device *dev)
  3513. {
  3514. struct drm_i915_private *dev_priv = dev->dev_private;
  3515. int fbc_wm, plane_wm, cursor_wm;
  3516. unsigned int enabled;
  3517. enabled = 0;
  3518. if (g4x_compute_wm0(dev, 0,
  3519. &ironlake_display_wm_info,
  3520. ILK_LP0_PLANE_LATENCY,
  3521. &ironlake_cursor_wm_info,
  3522. ILK_LP0_CURSOR_LATENCY,
  3523. &plane_wm, &cursor_wm)) {
  3524. I915_WRITE(WM0_PIPEA_ILK,
  3525. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3526. DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
  3527. " plane %d, " "cursor: %d\n",
  3528. plane_wm, cursor_wm);
  3529. enabled |= 1;
  3530. }
  3531. if (g4x_compute_wm0(dev, 1,
  3532. &ironlake_display_wm_info,
  3533. ILK_LP0_PLANE_LATENCY,
  3534. &ironlake_cursor_wm_info,
  3535. ILK_LP0_CURSOR_LATENCY,
  3536. &plane_wm, &cursor_wm)) {
  3537. I915_WRITE(WM0_PIPEB_ILK,
  3538. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3539. DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
  3540. " plane %d, cursor: %d\n",
  3541. plane_wm, cursor_wm);
  3542. enabled |= 2;
  3543. }
  3544. /*
  3545. * Calculate and update the self-refresh watermark only when one
  3546. * display plane is used.
  3547. */
  3548. I915_WRITE(WM3_LP_ILK, 0);
  3549. I915_WRITE(WM2_LP_ILK, 0);
  3550. I915_WRITE(WM1_LP_ILK, 0);
  3551. if (!single_plane_enabled(enabled))
  3552. return;
  3553. enabled = ffs(enabled) - 1;
  3554. /* WM1 */
  3555. if (!ironlake_compute_srwm(dev, 1, enabled,
  3556. ILK_READ_WM1_LATENCY() * 500,
  3557. &ironlake_display_srwm_info,
  3558. &ironlake_cursor_srwm_info,
  3559. &fbc_wm, &plane_wm, &cursor_wm))
  3560. return;
  3561. I915_WRITE(WM1_LP_ILK,
  3562. WM1_LP_SR_EN |
  3563. (ILK_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3564. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3565. (plane_wm << WM1_LP_SR_SHIFT) |
  3566. cursor_wm);
  3567. /* WM2 */
  3568. if (!ironlake_compute_srwm(dev, 2, enabled,
  3569. ILK_READ_WM2_LATENCY() * 500,
  3570. &ironlake_display_srwm_info,
  3571. &ironlake_cursor_srwm_info,
  3572. &fbc_wm, &plane_wm, &cursor_wm))
  3573. return;
  3574. I915_WRITE(WM2_LP_ILK,
  3575. WM2_LP_EN |
  3576. (ILK_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3577. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3578. (plane_wm << WM1_LP_SR_SHIFT) |
  3579. cursor_wm);
  3580. /*
  3581. * WM3 is unsupported on ILK, probably because we don't have latency
  3582. * data for that power state
  3583. */
  3584. }
  3585. static void sandybridge_update_wm(struct drm_device *dev)
  3586. {
  3587. struct drm_i915_private *dev_priv = dev->dev_private;
  3588. int latency = SNB_READ_WM0_LATENCY() * 100; /* In unit 0.1us */
  3589. int fbc_wm, plane_wm, cursor_wm;
  3590. unsigned int enabled;
  3591. enabled = 0;
  3592. if (g4x_compute_wm0(dev, 0,
  3593. &sandybridge_display_wm_info, latency,
  3594. &sandybridge_cursor_wm_info, latency,
  3595. &plane_wm, &cursor_wm)) {
  3596. I915_WRITE(WM0_PIPEA_ILK,
  3597. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3598. DRM_DEBUG_KMS("FIFO watermarks For pipe A -"
  3599. " plane %d, " "cursor: %d\n",
  3600. plane_wm, cursor_wm);
  3601. enabled |= 1;
  3602. }
  3603. if (g4x_compute_wm0(dev, 1,
  3604. &sandybridge_display_wm_info, latency,
  3605. &sandybridge_cursor_wm_info, latency,
  3606. &plane_wm, &cursor_wm)) {
  3607. I915_WRITE(WM0_PIPEB_ILK,
  3608. (plane_wm << WM0_PIPE_PLANE_SHIFT) | cursor_wm);
  3609. DRM_DEBUG_KMS("FIFO watermarks For pipe B -"
  3610. " plane %d, cursor: %d\n",
  3611. plane_wm, cursor_wm);
  3612. enabled |= 2;
  3613. }
  3614. /*
  3615. * Calculate and update the self-refresh watermark only when one
  3616. * display plane is used.
  3617. *
  3618. * SNB support 3 levels of watermark.
  3619. *
  3620. * WM1/WM2/WM2 watermarks have to be enabled in the ascending order,
  3621. * and disabled in the descending order
  3622. *
  3623. */
  3624. I915_WRITE(WM3_LP_ILK, 0);
  3625. I915_WRITE(WM2_LP_ILK, 0);
  3626. I915_WRITE(WM1_LP_ILK, 0);
  3627. if (!single_plane_enabled(enabled))
  3628. return;
  3629. enabled = ffs(enabled) - 1;
  3630. /* WM1 */
  3631. if (!ironlake_compute_srwm(dev, 1, enabled,
  3632. SNB_READ_WM1_LATENCY() * 500,
  3633. &sandybridge_display_srwm_info,
  3634. &sandybridge_cursor_srwm_info,
  3635. &fbc_wm, &plane_wm, &cursor_wm))
  3636. return;
  3637. I915_WRITE(WM1_LP_ILK,
  3638. WM1_LP_SR_EN |
  3639. (SNB_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3640. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3641. (plane_wm << WM1_LP_SR_SHIFT) |
  3642. cursor_wm);
  3643. /* WM2 */
  3644. if (!ironlake_compute_srwm(dev, 2, enabled,
  3645. SNB_READ_WM2_LATENCY() * 500,
  3646. &sandybridge_display_srwm_info,
  3647. &sandybridge_cursor_srwm_info,
  3648. &fbc_wm, &plane_wm, &cursor_wm))
  3649. return;
  3650. I915_WRITE(WM2_LP_ILK,
  3651. WM2_LP_EN |
  3652. (SNB_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3653. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3654. (plane_wm << WM1_LP_SR_SHIFT) |
  3655. cursor_wm);
  3656. /* WM3 */
  3657. if (!ironlake_compute_srwm(dev, 3, enabled,
  3658. SNB_READ_WM3_LATENCY() * 500,
  3659. &sandybridge_display_srwm_info,
  3660. &sandybridge_cursor_srwm_info,
  3661. &fbc_wm, &plane_wm, &cursor_wm))
  3662. return;
  3663. I915_WRITE(WM3_LP_ILK,
  3664. WM3_LP_EN |
  3665. (SNB_READ_WM3_LATENCY() << WM1_LP_LATENCY_SHIFT) |
  3666. (fbc_wm << WM1_LP_FBC_SHIFT) |
  3667. (plane_wm << WM1_LP_SR_SHIFT) |
  3668. cursor_wm);
  3669. }
  3670. /**
  3671. * intel_update_watermarks - update FIFO watermark values based on current modes
  3672. *
  3673. * Calculate watermark values for the various WM regs based on current mode
  3674. * and plane configuration.
  3675. *
  3676. * There are several cases to deal with here:
  3677. * - normal (i.e. non-self-refresh)
  3678. * - self-refresh (SR) mode
  3679. * - lines are large relative to FIFO size (buffer can hold up to 2)
  3680. * - lines are small relative to FIFO size (buffer can hold more than 2
  3681. * lines), so need to account for TLB latency
  3682. *
  3683. * The normal calculation is:
  3684. * watermark = dotclock * bytes per pixel * latency
  3685. * where latency is platform & configuration dependent (we assume pessimal
  3686. * values here).
  3687. *
  3688. * The SR calculation is:
  3689. * watermark = (trunc(latency/line time)+1) * surface width *
  3690. * bytes per pixel
  3691. * where
  3692. * line time = htotal / dotclock
  3693. * surface width = hdisplay for normal plane and 64 for cursor
  3694. * and latency is assumed to be high, as above.
  3695. *
  3696. * The final value programmed to the register should always be rounded up,
  3697. * and include an extra 2 entries to account for clock crossings.
  3698. *
  3699. * We don't use the sprite, so we can ignore that. And on Crestline we have
  3700. * to set the non-SR watermarks to 8.
  3701. */
  3702. static void intel_update_watermarks(struct drm_device *dev)
  3703. {
  3704. struct drm_i915_private *dev_priv = dev->dev_private;
  3705. if (dev_priv->display.update_wm)
  3706. dev_priv->display.update_wm(dev);
  3707. }
  3708. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  3709. {
  3710. return dev_priv->lvds_use_ssc && i915_panel_use_ssc;
  3711. }
  3712. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  3713. struct drm_display_mode *mode,
  3714. struct drm_display_mode *adjusted_mode,
  3715. int x, int y,
  3716. struct drm_framebuffer *old_fb)
  3717. {
  3718. struct drm_device *dev = crtc->dev;
  3719. struct drm_i915_private *dev_priv = dev->dev_private;
  3720. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3721. int pipe = intel_crtc->pipe;
  3722. int plane = intel_crtc->plane;
  3723. int refclk, num_connectors = 0;
  3724. intel_clock_t clock, reduced_clock;
  3725. u32 dpll, fp = 0, fp2 = 0, dspcntr, pipeconf;
  3726. bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false;
  3727. bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
  3728. struct drm_mode_config *mode_config = &dev->mode_config;
  3729. struct intel_encoder *encoder;
  3730. const intel_limit_t *limit;
  3731. int ret;
  3732. u32 temp;
  3733. u32 lvds_sync = 0;
  3734. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  3735. if (encoder->base.crtc != crtc)
  3736. continue;
  3737. switch (encoder->type) {
  3738. case INTEL_OUTPUT_LVDS:
  3739. is_lvds = true;
  3740. break;
  3741. case INTEL_OUTPUT_SDVO:
  3742. case INTEL_OUTPUT_HDMI:
  3743. is_sdvo = true;
  3744. if (encoder->needs_tv_clock)
  3745. is_tv = true;
  3746. break;
  3747. case INTEL_OUTPUT_DVO:
  3748. is_dvo = true;
  3749. break;
  3750. case INTEL_OUTPUT_TVOUT:
  3751. is_tv = true;
  3752. break;
  3753. case INTEL_OUTPUT_ANALOG:
  3754. is_crt = true;
  3755. break;
  3756. case INTEL_OUTPUT_DISPLAYPORT:
  3757. is_dp = true;
  3758. break;
  3759. }
  3760. num_connectors++;
  3761. }
  3762. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  3763. refclk = dev_priv->lvds_ssc_freq * 1000;
  3764. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  3765. refclk / 1000);
  3766. } else if (!IS_GEN2(dev)) {
  3767. refclk = 96000;
  3768. } else {
  3769. refclk = 48000;
  3770. }
  3771. /*
  3772. * Returns a set of divisors for the desired target clock with the given
  3773. * refclk, or FALSE. The returned values represent the clock equation:
  3774. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  3775. */
  3776. limit = intel_limit(crtc, refclk);
  3777. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock);
  3778. if (!ok) {
  3779. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  3780. return -EINVAL;
  3781. }
  3782. /* Ensure that the cursor is valid for the new mode before changing... */
  3783. intel_crtc_update_cursor(crtc, true);
  3784. if (is_lvds && dev_priv->lvds_downclock_avail) {
  3785. has_reduced_clock = limit->find_pll(limit, crtc,
  3786. dev_priv->lvds_downclock,
  3787. refclk,
  3788. &reduced_clock);
  3789. if (has_reduced_clock && (clock.p != reduced_clock.p)) {
  3790. /*
  3791. * If the different P is found, it means that we can't
  3792. * switch the display clock by using the FP0/FP1.
  3793. * In such case we will disable the LVDS downclock
  3794. * feature.
  3795. */
  3796. DRM_DEBUG_KMS("Different P is found for "
  3797. "LVDS clock/downclock\n");
  3798. has_reduced_clock = 0;
  3799. }
  3800. }
  3801. /* SDVO TV has fixed PLL values depend on its clock range,
  3802. this mirrors vbios setting. */
  3803. if (is_sdvo && is_tv) {
  3804. if (adjusted_mode->clock >= 100000
  3805. && adjusted_mode->clock < 140500) {
  3806. clock.p1 = 2;
  3807. clock.p2 = 10;
  3808. clock.n = 3;
  3809. clock.m1 = 16;
  3810. clock.m2 = 8;
  3811. } else if (adjusted_mode->clock >= 140500
  3812. && adjusted_mode->clock <= 200000) {
  3813. clock.p1 = 1;
  3814. clock.p2 = 10;
  3815. clock.n = 6;
  3816. clock.m1 = 12;
  3817. clock.m2 = 8;
  3818. }
  3819. }
  3820. if (IS_PINEVIEW(dev)) {
  3821. fp = (1 << clock.n) << 16 | clock.m1 << 8 | clock.m2;
  3822. if (has_reduced_clock)
  3823. fp2 = (1 << reduced_clock.n) << 16 |
  3824. reduced_clock.m1 << 8 | reduced_clock.m2;
  3825. } else {
  3826. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  3827. if (has_reduced_clock)
  3828. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  3829. reduced_clock.m2;
  3830. }
  3831. dpll = DPLL_VGA_MODE_DIS;
  3832. if (!IS_GEN2(dev)) {
  3833. if (is_lvds)
  3834. dpll |= DPLLB_MODE_LVDS;
  3835. else
  3836. dpll |= DPLLB_MODE_DAC_SERIAL;
  3837. if (is_sdvo) {
  3838. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  3839. if (pixel_multiplier > 1) {
  3840. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  3841. dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  3842. }
  3843. dpll |= DPLL_DVO_HIGH_SPEED;
  3844. }
  3845. if (is_dp)
  3846. dpll |= DPLL_DVO_HIGH_SPEED;
  3847. /* compute bitmask from p1 value */
  3848. if (IS_PINEVIEW(dev))
  3849. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  3850. else {
  3851. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3852. if (IS_G4X(dev) && has_reduced_clock)
  3853. dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  3854. }
  3855. switch (clock.p2) {
  3856. case 5:
  3857. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  3858. break;
  3859. case 7:
  3860. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  3861. break;
  3862. case 10:
  3863. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  3864. break;
  3865. case 14:
  3866. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  3867. break;
  3868. }
  3869. if (INTEL_INFO(dev)->gen >= 4)
  3870. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  3871. } else {
  3872. if (is_lvds) {
  3873. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3874. } else {
  3875. if (clock.p1 == 2)
  3876. dpll |= PLL_P1_DIVIDE_BY_TWO;
  3877. else
  3878. dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3879. if (clock.p2 == 4)
  3880. dpll |= PLL_P2_DIVIDE_BY_4;
  3881. }
  3882. }
  3883. if (is_sdvo && is_tv)
  3884. dpll |= PLL_REF_INPUT_TVCLKINBC;
  3885. else if (is_tv)
  3886. /* XXX: just matching BIOS for now */
  3887. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3888. dpll |= 3;
  3889. else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3890. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3891. else
  3892. dpll |= PLL_REF_INPUT_DREFCLK;
  3893. /* setup pipeconf */
  3894. pipeconf = I915_READ(PIPECONF(pipe));
  3895. /* Set up the display plane register */
  3896. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3897. /* Ironlake's plane is forced to pipe, bit 24 is to
  3898. enable color space conversion */
  3899. if (pipe == 0)
  3900. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3901. else
  3902. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3903. if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
  3904. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  3905. * core speed.
  3906. *
  3907. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  3908. * pipe == 0 check?
  3909. */
  3910. if (mode->clock >
  3911. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  3912. pipeconf |= PIPECONF_DOUBLE_WIDE;
  3913. else
  3914. pipeconf &= ~PIPECONF_DOUBLE_WIDE;
  3915. }
  3916. dpll |= DPLL_VCO_ENABLE;
  3917. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  3918. drm_mode_debug_printmodeline(mode);
  3919. I915_WRITE(FP0(pipe), fp);
  3920. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3921. POSTING_READ(DPLL(pipe));
  3922. udelay(150);
  3923. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  3924. * This is an exception to the general rule that mode_set doesn't turn
  3925. * things on.
  3926. */
  3927. if (is_lvds) {
  3928. temp = I915_READ(LVDS);
  3929. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  3930. if (pipe == 1) {
  3931. temp |= LVDS_PIPEB_SELECT;
  3932. } else {
  3933. temp &= ~LVDS_PIPEB_SELECT;
  3934. }
  3935. /* set the corresponsding LVDS_BORDER bit */
  3936. temp |= dev_priv->lvds_border_bits;
  3937. /* Set the B0-B3 data pairs corresponding to whether we're going to
  3938. * set the DPLLs for dual-channel mode or not.
  3939. */
  3940. if (clock.p2 == 7)
  3941. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  3942. else
  3943. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  3944. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  3945. * appropriately here, but we need to look more thoroughly into how
  3946. * panels behave in the two modes.
  3947. */
  3948. /* set the dithering flag on LVDS as needed */
  3949. if (INTEL_INFO(dev)->gen >= 4) {
  3950. if (dev_priv->lvds_dither)
  3951. temp |= LVDS_ENABLE_DITHER;
  3952. else
  3953. temp &= ~LVDS_ENABLE_DITHER;
  3954. }
  3955. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  3956. lvds_sync |= LVDS_HSYNC_POLARITY;
  3957. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  3958. lvds_sync |= LVDS_VSYNC_POLARITY;
  3959. if ((temp & (LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY))
  3960. != lvds_sync) {
  3961. char flags[2] = "-+";
  3962. DRM_INFO("Changing LVDS panel from "
  3963. "(%chsync, %cvsync) to (%chsync, %cvsync)\n",
  3964. flags[!(temp & LVDS_HSYNC_POLARITY)],
  3965. flags[!(temp & LVDS_VSYNC_POLARITY)],
  3966. flags[!(lvds_sync & LVDS_HSYNC_POLARITY)],
  3967. flags[!(lvds_sync & LVDS_VSYNC_POLARITY)]);
  3968. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  3969. temp |= lvds_sync;
  3970. }
  3971. I915_WRITE(LVDS, temp);
  3972. }
  3973. if (is_dp) {
  3974. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3975. }
  3976. I915_WRITE(DPLL(pipe), dpll);
  3977. /* Wait for the clocks to stabilize. */
  3978. POSTING_READ(DPLL(pipe));
  3979. udelay(150);
  3980. if (INTEL_INFO(dev)->gen >= 4) {
  3981. temp = 0;
  3982. if (is_sdvo) {
  3983. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3984. if (temp > 1)
  3985. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3986. else
  3987. temp = 0;
  3988. }
  3989. I915_WRITE(DPLL_MD(pipe), temp);
  3990. } else {
  3991. /* The pixel multiplier can only be updated once the
  3992. * DPLL is enabled and the clocks are stable.
  3993. *
  3994. * So write it again.
  3995. */
  3996. I915_WRITE(DPLL(pipe), dpll);
  3997. }
  3998. intel_crtc->lowfreq_avail = false;
  3999. if (is_lvds && has_reduced_clock && i915_powersave) {
  4000. I915_WRITE(FP1(pipe), fp2);
  4001. intel_crtc->lowfreq_avail = true;
  4002. if (HAS_PIPE_CXSR(dev)) {
  4003. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  4004. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  4005. }
  4006. } else {
  4007. I915_WRITE(FP1(pipe), fp);
  4008. if (HAS_PIPE_CXSR(dev)) {
  4009. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  4010. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  4011. }
  4012. }
  4013. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4014. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  4015. /* the chip adds 2 halflines automatically */
  4016. adjusted_mode->crtc_vdisplay -= 1;
  4017. adjusted_mode->crtc_vtotal -= 1;
  4018. adjusted_mode->crtc_vblank_start -= 1;
  4019. adjusted_mode->crtc_vblank_end -= 1;
  4020. adjusted_mode->crtc_vsync_end -= 1;
  4021. adjusted_mode->crtc_vsync_start -= 1;
  4022. } else
  4023. pipeconf &= ~PIPECONF_INTERLACE_W_FIELD_INDICATION; /* progressive */
  4024. I915_WRITE(HTOTAL(pipe),
  4025. (adjusted_mode->crtc_hdisplay - 1) |
  4026. ((adjusted_mode->crtc_htotal - 1) << 16));
  4027. I915_WRITE(HBLANK(pipe),
  4028. (adjusted_mode->crtc_hblank_start - 1) |
  4029. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  4030. I915_WRITE(HSYNC(pipe),
  4031. (adjusted_mode->crtc_hsync_start - 1) |
  4032. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  4033. I915_WRITE(VTOTAL(pipe),
  4034. (adjusted_mode->crtc_vdisplay - 1) |
  4035. ((adjusted_mode->crtc_vtotal - 1) << 16));
  4036. I915_WRITE(VBLANK(pipe),
  4037. (adjusted_mode->crtc_vblank_start - 1) |
  4038. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  4039. I915_WRITE(VSYNC(pipe),
  4040. (adjusted_mode->crtc_vsync_start - 1) |
  4041. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  4042. /* pipesrc and dspsize control the size that is scaled from,
  4043. * which should always be the user's requested size.
  4044. */
  4045. I915_WRITE(DSPSIZE(plane),
  4046. ((mode->vdisplay - 1) << 16) |
  4047. (mode->hdisplay - 1));
  4048. I915_WRITE(DSPPOS(plane), 0);
  4049. I915_WRITE(PIPESRC(pipe),
  4050. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  4051. I915_WRITE(PIPECONF(pipe), pipeconf);
  4052. POSTING_READ(PIPECONF(pipe));
  4053. intel_enable_pipe(dev_priv, pipe, false);
  4054. intel_wait_for_vblank(dev, pipe);
  4055. I915_WRITE(DSPCNTR(plane), dspcntr);
  4056. POSTING_READ(DSPCNTR(plane));
  4057. intel_enable_plane(dev_priv, plane, pipe);
  4058. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  4059. intel_update_watermarks(dev);
  4060. return ret;
  4061. }
  4062. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  4063. struct drm_display_mode *mode,
  4064. struct drm_display_mode *adjusted_mode,
  4065. int x, int y,
  4066. struct drm_framebuffer *old_fb)
  4067. {
  4068. struct drm_device *dev = crtc->dev;
  4069. struct drm_i915_private *dev_priv = dev->dev_private;
  4070. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4071. int pipe = intel_crtc->pipe;
  4072. int plane = intel_crtc->plane;
  4073. int refclk, num_connectors = 0;
  4074. intel_clock_t clock, reduced_clock;
  4075. u32 dpll, fp = 0, fp2 = 0, dspcntr, pipeconf;
  4076. bool ok, has_reduced_clock = false, is_sdvo = false;
  4077. bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
  4078. struct intel_encoder *has_edp_encoder = NULL;
  4079. struct drm_mode_config *mode_config = &dev->mode_config;
  4080. struct intel_encoder *encoder;
  4081. const intel_limit_t *limit;
  4082. int ret;
  4083. struct fdi_m_n m_n = {0};
  4084. u32 temp;
  4085. u32 lvds_sync = 0;
  4086. int target_clock, pixel_multiplier, lane, link_bw, bpp, factor;
  4087. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  4088. if (encoder->base.crtc != crtc)
  4089. continue;
  4090. switch (encoder->type) {
  4091. case INTEL_OUTPUT_LVDS:
  4092. is_lvds = true;
  4093. break;
  4094. case INTEL_OUTPUT_SDVO:
  4095. case INTEL_OUTPUT_HDMI:
  4096. is_sdvo = true;
  4097. if (encoder->needs_tv_clock)
  4098. is_tv = true;
  4099. break;
  4100. case INTEL_OUTPUT_TVOUT:
  4101. is_tv = true;
  4102. break;
  4103. case INTEL_OUTPUT_ANALOG:
  4104. is_crt = true;
  4105. break;
  4106. case INTEL_OUTPUT_DISPLAYPORT:
  4107. is_dp = true;
  4108. break;
  4109. case INTEL_OUTPUT_EDP:
  4110. has_edp_encoder = encoder;
  4111. break;
  4112. }
  4113. num_connectors++;
  4114. }
  4115. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4116. refclk = dev_priv->lvds_ssc_freq * 1000;
  4117. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  4118. refclk / 1000);
  4119. } else {
  4120. refclk = 96000;
  4121. if (!has_edp_encoder ||
  4122. intel_encoder_is_pch_edp(&has_edp_encoder->base))
  4123. refclk = 120000; /* 120Mhz refclk */
  4124. }
  4125. /*
  4126. * Returns a set of divisors for the desired target clock with the given
  4127. * refclk, or FALSE. The returned values represent the clock equation:
  4128. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  4129. */
  4130. limit = intel_limit(crtc, refclk);
  4131. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, &clock);
  4132. if (!ok) {
  4133. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  4134. return -EINVAL;
  4135. }
  4136. /* Ensure that the cursor is valid for the new mode before changing... */
  4137. intel_crtc_update_cursor(crtc, true);
  4138. if (is_lvds && dev_priv->lvds_downclock_avail) {
  4139. has_reduced_clock = limit->find_pll(limit, crtc,
  4140. dev_priv->lvds_downclock,
  4141. refclk,
  4142. &reduced_clock);
  4143. if (has_reduced_clock && (clock.p != reduced_clock.p)) {
  4144. /*
  4145. * If the different P is found, it means that we can't
  4146. * switch the display clock by using the FP0/FP1.
  4147. * In such case we will disable the LVDS downclock
  4148. * feature.
  4149. */
  4150. DRM_DEBUG_KMS("Different P is found for "
  4151. "LVDS clock/downclock\n");
  4152. has_reduced_clock = 0;
  4153. }
  4154. }
  4155. /* SDVO TV has fixed PLL values depend on its clock range,
  4156. this mirrors vbios setting. */
  4157. if (is_sdvo && is_tv) {
  4158. if (adjusted_mode->clock >= 100000
  4159. && adjusted_mode->clock < 140500) {
  4160. clock.p1 = 2;
  4161. clock.p2 = 10;
  4162. clock.n = 3;
  4163. clock.m1 = 16;
  4164. clock.m2 = 8;
  4165. } else if (adjusted_mode->clock >= 140500
  4166. && adjusted_mode->clock <= 200000) {
  4167. clock.p1 = 1;
  4168. clock.p2 = 10;
  4169. clock.n = 6;
  4170. clock.m1 = 12;
  4171. clock.m2 = 8;
  4172. }
  4173. }
  4174. /* FDI link */
  4175. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4176. lane = 0;
  4177. /* CPU eDP doesn't require FDI link, so just set DP M/N
  4178. according to current link config */
  4179. if (has_edp_encoder &&
  4180. !intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4181. target_clock = mode->clock;
  4182. intel_edp_link_config(has_edp_encoder,
  4183. &lane, &link_bw);
  4184. } else {
  4185. /* [e]DP over FDI requires target mode clock
  4186. instead of link clock */
  4187. if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base))
  4188. target_clock = mode->clock;
  4189. else
  4190. target_clock = adjusted_mode->clock;
  4191. /* FDI is a binary signal running at ~2.7GHz, encoding
  4192. * each output octet as 10 bits. The actual frequency
  4193. * is stored as a divider into a 100MHz clock, and the
  4194. * mode pixel clock is stored in units of 1KHz.
  4195. * Hence the bw of each lane in terms of the mode signal
  4196. * is:
  4197. */
  4198. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4199. }
  4200. /* determine panel color depth */
  4201. temp = I915_READ(PIPECONF(pipe));
  4202. temp &= ~PIPE_BPC_MASK;
  4203. if (is_lvds) {
  4204. /* the BPC will be 6 if it is 18-bit LVDS panel */
  4205. if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) == LVDS_A3_POWER_UP)
  4206. temp |= PIPE_8BPC;
  4207. else
  4208. temp |= PIPE_6BPC;
  4209. } else if (has_edp_encoder) {
  4210. switch (dev_priv->edp.bpp/3) {
  4211. case 8:
  4212. temp |= PIPE_8BPC;
  4213. break;
  4214. case 10:
  4215. temp |= PIPE_10BPC;
  4216. break;
  4217. case 6:
  4218. temp |= PIPE_6BPC;
  4219. break;
  4220. case 12:
  4221. temp |= PIPE_12BPC;
  4222. break;
  4223. }
  4224. } else
  4225. temp |= PIPE_8BPC;
  4226. I915_WRITE(PIPECONF(pipe), temp);
  4227. switch (temp & PIPE_BPC_MASK) {
  4228. case PIPE_8BPC:
  4229. bpp = 24;
  4230. break;
  4231. case PIPE_10BPC:
  4232. bpp = 30;
  4233. break;
  4234. case PIPE_6BPC:
  4235. bpp = 18;
  4236. break;
  4237. case PIPE_12BPC:
  4238. bpp = 36;
  4239. break;
  4240. default:
  4241. DRM_ERROR("unknown pipe bpc value\n");
  4242. bpp = 24;
  4243. }
  4244. if (!lane) {
  4245. /*
  4246. * Account for spread spectrum to avoid
  4247. * oversubscribing the link. Max center spread
  4248. * is 2.5%; use 5% for safety's sake.
  4249. */
  4250. u32 bps = target_clock * bpp * 21 / 20;
  4251. lane = bps / (link_bw * 8) + 1;
  4252. }
  4253. intel_crtc->fdi_lanes = lane;
  4254. if (pixel_multiplier > 1)
  4255. link_bw *= pixel_multiplier;
  4256. ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n);
  4257. /* Ironlake: try to setup display ref clock before DPLL
  4258. * enabling. This is only under driver's control after
  4259. * PCH B stepping, previous chipset stepping should be
  4260. * ignoring this setting.
  4261. */
  4262. temp = I915_READ(PCH_DREF_CONTROL);
  4263. /* Always enable nonspread source */
  4264. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  4265. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  4266. temp &= ~DREF_SSC_SOURCE_MASK;
  4267. temp |= DREF_SSC_SOURCE_ENABLE;
  4268. I915_WRITE(PCH_DREF_CONTROL, temp);
  4269. POSTING_READ(PCH_DREF_CONTROL);
  4270. udelay(200);
  4271. if (has_edp_encoder) {
  4272. if (intel_panel_use_ssc(dev_priv)) {
  4273. temp |= DREF_SSC1_ENABLE;
  4274. I915_WRITE(PCH_DREF_CONTROL, temp);
  4275. POSTING_READ(PCH_DREF_CONTROL);
  4276. udelay(200);
  4277. }
  4278. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4279. /* Enable CPU source on CPU attached eDP */
  4280. if (!intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4281. if (intel_panel_use_ssc(dev_priv))
  4282. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  4283. else
  4284. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  4285. } else {
  4286. /* Enable SSC on PCH eDP if needed */
  4287. if (intel_panel_use_ssc(dev_priv)) {
  4288. DRM_ERROR("enabling SSC on PCH\n");
  4289. temp |= DREF_SUPERSPREAD_SOURCE_ENABLE;
  4290. }
  4291. }
  4292. I915_WRITE(PCH_DREF_CONTROL, temp);
  4293. POSTING_READ(PCH_DREF_CONTROL);
  4294. udelay(200);
  4295. }
  4296. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  4297. if (has_reduced_clock)
  4298. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  4299. reduced_clock.m2;
  4300. /* Enable autotuning of the PLL clock (if permissible) */
  4301. factor = 21;
  4302. if (is_lvds) {
  4303. if ((intel_panel_use_ssc(dev_priv) &&
  4304. dev_priv->lvds_ssc_freq == 100) ||
  4305. (I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP)
  4306. factor = 25;
  4307. } else if (is_sdvo && is_tv)
  4308. factor = 20;
  4309. if (clock.m1 < factor * clock.n)
  4310. fp |= FP_CB_TUNE;
  4311. dpll = 0;
  4312. if (is_lvds)
  4313. dpll |= DPLLB_MODE_LVDS;
  4314. else
  4315. dpll |= DPLLB_MODE_DAC_SERIAL;
  4316. if (is_sdvo) {
  4317. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4318. if (pixel_multiplier > 1) {
  4319. dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  4320. }
  4321. dpll |= DPLL_DVO_HIGH_SPEED;
  4322. }
  4323. if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base))
  4324. dpll |= DPLL_DVO_HIGH_SPEED;
  4325. /* compute bitmask from p1 value */
  4326. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4327. /* also FPA1 */
  4328. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4329. switch (clock.p2) {
  4330. case 5:
  4331. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4332. break;
  4333. case 7:
  4334. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4335. break;
  4336. case 10:
  4337. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4338. break;
  4339. case 14:
  4340. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4341. break;
  4342. }
  4343. if (is_sdvo && is_tv)
  4344. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4345. else if (is_tv)
  4346. /* XXX: just matching BIOS for now */
  4347. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  4348. dpll |= 3;
  4349. else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4350. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4351. else
  4352. dpll |= PLL_REF_INPUT_DREFCLK;
  4353. /* setup pipeconf */
  4354. pipeconf = I915_READ(PIPECONF(pipe));
  4355. /* Set up the display plane register */
  4356. dspcntr = DISPPLANE_GAMMA_ENABLE;
  4357. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  4358. drm_mode_debug_printmodeline(mode);
  4359. /* PCH eDP needs FDI, but CPU eDP does not */
  4360. if (!has_edp_encoder || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4361. I915_WRITE(PCH_FP0(pipe), fp);
  4362. I915_WRITE(PCH_DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  4363. POSTING_READ(PCH_DPLL(pipe));
  4364. udelay(150);
  4365. }
  4366. /* enable transcoder DPLL */
  4367. if (HAS_PCH_CPT(dev)) {
  4368. temp = I915_READ(PCH_DPLL_SEL);
  4369. switch (pipe) {
  4370. case 0:
  4371. temp |= TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL;
  4372. break;
  4373. case 1:
  4374. temp |= TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL;
  4375. break;
  4376. case 2:
  4377. /* FIXME: manage transcoder PLLs? */
  4378. temp |= TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL;
  4379. break;
  4380. default:
  4381. BUG();
  4382. }
  4383. I915_WRITE(PCH_DPLL_SEL, temp);
  4384. POSTING_READ(PCH_DPLL_SEL);
  4385. udelay(150);
  4386. }
  4387. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  4388. * This is an exception to the general rule that mode_set doesn't turn
  4389. * things on.
  4390. */
  4391. if (is_lvds) {
  4392. temp = I915_READ(PCH_LVDS);
  4393. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  4394. if (pipe == 1) {
  4395. if (HAS_PCH_CPT(dev))
  4396. temp |= PORT_TRANS_B_SEL_CPT;
  4397. else
  4398. temp |= LVDS_PIPEB_SELECT;
  4399. } else {
  4400. if (HAS_PCH_CPT(dev))
  4401. temp &= ~PORT_TRANS_SEL_MASK;
  4402. else
  4403. temp &= ~LVDS_PIPEB_SELECT;
  4404. }
  4405. /* set the corresponsding LVDS_BORDER bit */
  4406. temp |= dev_priv->lvds_border_bits;
  4407. /* Set the B0-B3 data pairs corresponding to whether we're going to
  4408. * set the DPLLs for dual-channel mode or not.
  4409. */
  4410. if (clock.p2 == 7)
  4411. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  4412. else
  4413. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  4414. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  4415. * appropriately here, but we need to look more thoroughly into how
  4416. * panels behave in the two modes.
  4417. */
  4418. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  4419. lvds_sync |= LVDS_HSYNC_POLARITY;
  4420. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  4421. lvds_sync |= LVDS_VSYNC_POLARITY;
  4422. if ((temp & (LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY))
  4423. != lvds_sync) {
  4424. char flags[2] = "-+";
  4425. DRM_INFO("Changing LVDS panel from "
  4426. "(%chsync, %cvsync) to (%chsync, %cvsync)\n",
  4427. flags[!(temp & LVDS_HSYNC_POLARITY)],
  4428. flags[!(temp & LVDS_VSYNC_POLARITY)],
  4429. flags[!(lvds_sync & LVDS_HSYNC_POLARITY)],
  4430. flags[!(lvds_sync & LVDS_VSYNC_POLARITY)]);
  4431. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  4432. temp |= lvds_sync;
  4433. }
  4434. I915_WRITE(PCH_LVDS, temp);
  4435. }
  4436. /* set the dithering flag and clear for anything other than a panel. */
  4437. pipeconf &= ~PIPECONF_DITHER_EN;
  4438. pipeconf &= ~PIPECONF_DITHER_TYPE_MASK;
  4439. if (dev_priv->lvds_dither && (is_lvds || has_edp_encoder)) {
  4440. pipeconf |= PIPECONF_DITHER_EN;
  4441. pipeconf |= PIPECONF_DITHER_TYPE_ST1;
  4442. }
  4443. if (is_dp || intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4444. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4445. } else {
  4446. /* For non-DP output, clear any trans DP clock recovery setting.*/
  4447. I915_WRITE(TRANSDATA_M1(pipe), 0);
  4448. I915_WRITE(TRANSDATA_N1(pipe), 0);
  4449. I915_WRITE(TRANSDPLINK_M1(pipe), 0);
  4450. I915_WRITE(TRANSDPLINK_N1(pipe), 0);
  4451. }
  4452. if (!has_edp_encoder ||
  4453. intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4454. I915_WRITE(PCH_DPLL(pipe), dpll);
  4455. /* Wait for the clocks to stabilize. */
  4456. POSTING_READ(PCH_DPLL(pipe));
  4457. udelay(150);
  4458. /* The pixel multiplier can only be updated once the
  4459. * DPLL is enabled and the clocks are stable.
  4460. *
  4461. * So write it again.
  4462. */
  4463. I915_WRITE(PCH_DPLL(pipe), dpll);
  4464. }
  4465. intel_crtc->lowfreq_avail = false;
  4466. if (is_lvds && has_reduced_clock && i915_powersave) {
  4467. I915_WRITE(PCH_FP1(pipe), fp2);
  4468. intel_crtc->lowfreq_avail = true;
  4469. if (HAS_PIPE_CXSR(dev)) {
  4470. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  4471. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  4472. }
  4473. } else {
  4474. I915_WRITE(PCH_FP1(pipe), fp);
  4475. if (HAS_PIPE_CXSR(dev)) {
  4476. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  4477. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  4478. }
  4479. }
  4480. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4481. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  4482. /* the chip adds 2 halflines automatically */
  4483. adjusted_mode->crtc_vdisplay -= 1;
  4484. adjusted_mode->crtc_vtotal -= 1;
  4485. adjusted_mode->crtc_vblank_start -= 1;
  4486. adjusted_mode->crtc_vblank_end -= 1;
  4487. adjusted_mode->crtc_vsync_end -= 1;
  4488. adjusted_mode->crtc_vsync_start -= 1;
  4489. } else
  4490. pipeconf &= ~PIPECONF_INTERLACE_W_FIELD_INDICATION; /* progressive */
  4491. I915_WRITE(HTOTAL(pipe),
  4492. (adjusted_mode->crtc_hdisplay - 1) |
  4493. ((adjusted_mode->crtc_htotal - 1) << 16));
  4494. I915_WRITE(HBLANK(pipe),
  4495. (adjusted_mode->crtc_hblank_start - 1) |
  4496. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  4497. I915_WRITE(HSYNC(pipe),
  4498. (adjusted_mode->crtc_hsync_start - 1) |
  4499. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  4500. I915_WRITE(VTOTAL(pipe),
  4501. (adjusted_mode->crtc_vdisplay - 1) |
  4502. ((adjusted_mode->crtc_vtotal - 1) << 16));
  4503. I915_WRITE(VBLANK(pipe),
  4504. (adjusted_mode->crtc_vblank_start - 1) |
  4505. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  4506. I915_WRITE(VSYNC(pipe),
  4507. (adjusted_mode->crtc_vsync_start - 1) |
  4508. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  4509. /* pipesrc controls the size that is scaled from, which should
  4510. * always be the user's requested size.
  4511. */
  4512. I915_WRITE(PIPESRC(pipe),
  4513. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  4514. I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
  4515. I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
  4516. I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
  4517. I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
  4518. if (has_edp_encoder &&
  4519. !intel_encoder_is_pch_edp(&has_edp_encoder->base)) {
  4520. ironlake_set_pll_edp(crtc, adjusted_mode->clock);
  4521. }
  4522. I915_WRITE(PIPECONF(pipe), pipeconf);
  4523. POSTING_READ(PIPECONF(pipe));
  4524. intel_wait_for_vblank(dev, pipe);
  4525. if (IS_GEN5(dev)) {
  4526. /* enable address swizzle for tiling buffer */
  4527. temp = I915_READ(DISP_ARB_CTL);
  4528. I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING);
  4529. }
  4530. I915_WRITE(DSPCNTR(plane), dspcntr);
  4531. POSTING_READ(DSPCNTR(plane));
  4532. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  4533. intel_update_watermarks(dev);
  4534. return ret;
  4535. }
  4536. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  4537. struct drm_display_mode *mode,
  4538. struct drm_display_mode *adjusted_mode,
  4539. int x, int y,
  4540. struct drm_framebuffer *old_fb)
  4541. {
  4542. struct drm_device *dev = crtc->dev;
  4543. struct drm_i915_private *dev_priv = dev->dev_private;
  4544. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4545. int pipe = intel_crtc->pipe;
  4546. int ret;
  4547. drm_vblank_pre_modeset(dev, pipe);
  4548. ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
  4549. x, y, old_fb);
  4550. drm_vblank_post_modeset(dev, pipe);
  4551. return ret;
  4552. }
  4553. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  4554. void intel_crtc_load_lut(struct drm_crtc *crtc)
  4555. {
  4556. struct drm_device *dev = crtc->dev;
  4557. struct drm_i915_private *dev_priv = dev->dev_private;
  4558. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4559. int palreg = PALETTE(intel_crtc->pipe);
  4560. int i;
  4561. /* The clocks have to be on to load the palette. */
  4562. if (!crtc->enabled)
  4563. return;
  4564. /* use legacy palette for Ironlake */
  4565. if (HAS_PCH_SPLIT(dev))
  4566. palreg = LGC_PALETTE(intel_crtc->pipe);
  4567. for (i = 0; i < 256; i++) {
  4568. I915_WRITE(palreg + 4 * i,
  4569. (intel_crtc->lut_r[i] << 16) |
  4570. (intel_crtc->lut_g[i] << 8) |
  4571. intel_crtc->lut_b[i]);
  4572. }
  4573. }
  4574. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  4575. {
  4576. struct drm_device *dev = crtc->dev;
  4577. struct drm_i915_private *dev_priv = dev->dev_private;
  4578. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4579. bool visible = base != 0;
  4580. u32 cntl;
  4581. if (intel_crtc->cursor_visible == visible)
  4582. return;
  4583. cntl = I915_READ(_CURACNTR);
  4584. if (visible) {
  4585. /* On these chipsets we can only modify the base whilst
  4586. * the cursor is disabled.
  4587. */
  4588. I915_WRITE(_CURABASE, base);
  4589. cntl &= ~(CURSOR_FORMAT_MASK);
  4590. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  4591. cntl |= CURSOR_ENABLE |
  4592. CURSOR_GAMMA_ENABLE |
  4593. CURSOR_FORMAT_ARGB;
  4594. } else
  4595. cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  4596. I915_WRITE(_CURACNTR, cntl);
  4597. intel_crtc->cursor_visible = visible;
  4598. }
  4599. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  4600. {
  4601. struct drm_device *dev = crtc->dev;
  4602. struct drm_i915_private *dev_priv = dev->dev_private;
  4603. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4604. int pipe = intel_crtc->pipe;
  4605. bool visible = base != 0;
  4606. if (intel_crtc->cursor_visible != visible) {
  4607. uint32_t cntl = I915_READ(CURCNTR(pipe));
  4608. if (base) {
  4609. cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  4610. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  4611. cntl |= pipe << 28; /* Connect to correct pipe */
  4612. } else {
  4613. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  4614. cntl |= CURSOR_MODE_DISABLE;
  4615. }
  4616. I915_WRITE(CURCNTR(pipe), cntl);
  4617. intel_crtc->cursor_visible = visible;
  4618. }
  4619. /* and commit changes on next vblank */
  4620. I915_WRITE(CURBASE(pipe), base);
  4621. }
  4622. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  4623. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  4624. bool on)
  4625. {
  4626. struct drm_device *dev = crtc->dev;
  4627. struct drm_i915_private *dev_priv = dev->dev_private;
  4628. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4629. int pipe = intel_crtc->pipe;
  4630. int x = intel_crtc->cursor_x;
  4631. int y = intel_crtc->cursor_y;
  4632. u32 base, pos;
  4633. bool visible;
  4634. pos = 0;
  4635. if (on && crtc->enabled && crtc->fb) {
  4636. base = intel_crtc->cursor_addr;
  4637. if (x > (int) crtc->fb->width)
  4638. base = 0;
  4639. if (y > (int) crtc->fb->height)
  4640. base = 0;
  4641. } else
  4642. base = 0;
  4643. if (x < 0) {
  4644. if (x + intel_crtc->cursor_width < 0)
  4645. base = 0;
  4646. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  4647. x = -x;
  4648. }
  4649. pos |= x << CURSOR_X_SHIFT;
  4650. if (y < 0) {
  4651. if (y + intel_crtc->cursor_height < 0)
  4652. base = 0;
  4653. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  4654. y = -y;
  4655. }
  4656. pos |= y << CURSOR_Y_SHIFT;
  4657. visible = base != 0;
  4658. if (!visible && !intel_crtc->cursor_visible)
  4659. return;
  4660. I915_WRITE(CURPOS(pipe), pos);
  4661. if (IS_845G(dev) || IS_I865G(dev))
  4662. i845_update_cursor(crtc, base);
  4663. else
  4664. i9xx_update_cursor(crtc, base);
  4665. if (visible)
  4666. intel_mark_busy(dev, to_intel_framebuffer(crtc->fb)->obj);
  4667. }
  4668. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  4669. struct drm_file *file,
  4670. uint32_t handle,
  4671. uint32_t width, uint32_t height)
  4672. {
  4673. struct drm_device *dev = crtc->dev;
  4674. struct drm_i915_private *dev_priv = dev->dev_private;
  4675. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4676. struct drm_i915_gem_object *obj;
  4677. uint32_t addr;
  4678. int ret;
  4679. DRM_DEBUG_KMS("\n");
  4680. /* if we want to turn off the cursor ignore width and height */
  4681. if (!handle) {
  4682. DRM_DEBUG_KMS("cursor off\n");
  4683. addr = 0;
  4684. obj = NULL;
  4685. mutex_lock(&dev->struct_mutex);
  4686. goto finish;
  4687. }
  4688. /* Currently we only support 64x64 cursors */
  4689. if (width != 64 || height != 64) {
  4690. DRM_ERROR("we currently only support 64x64 cursors\n");
  4691. return -EINVAL;
  4692. }
  4693. obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
  4694. if (&obj->base == NULL)
  4695. return -ENOENT;
  4696. if (obj->base.size < width * height * 4) {
  4697. DRM_ERROR("buffer is to small\n");
  4698. ret = -ENOMEM;
  4699. goto fail;
  4700. }
  4701. /* we only need to pin inside GTT if cursor is non-phy */
  4702. mutex_lock(&dev->struct_mutex);
  4703. if (!dev_priv->info->cursor_needs_physical) {
  4704. if (obj->tiling_mode) {
  4705. DRM_ERROR("cursor cannot be tiled\n");
  4706. ret = -EINVAL;
  4707. goto fail_locked;
  4708. }
  4709. ret = i915_gem_object_pin(obj, PAGE_SIZE, true);
  4710. if (ret) {
  4711. DRM_ERROR("failed to pin cursor bo\n");
  4712. goto fail_locked;
  4713. }
  4714. ret = i915_gem_object_set_to_display_plane(obj, NULL);
  4715. if (ret) {
  4716. DRM_ERROR("failed to move cursor bo into the GTT\n");
  4717. goto fail_unpin;
  4718. }
  4719. ret = i915_gem_object_put_fence(obj);
  4720. if (ret) {
  4721. DRM_ERROR("failed to move cursor bo into the GTT\n");
  4722. goto fail_unpin;
  4723. }
  4724. addr = obj->gtt_offset;
  4725. } else {
  4726. int align = IS_I830(dev) ? 16 * 1024 : 256;
  4727. ret = i915_gem_attach_phys_object(dev, obj,
  4728. (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
  4729. align);
  4730. if (ret) {
  4731. DRM_ERROR("failed to attach phys object\n");
  4732. goto fail_locked;
  4733. }
  4734. addr = obj->phys_obj->handle->busaddr;
  4735. }
  4736. if (IS_GEN2(dev))
  4737. I915_WRITE(CURSIZE, (height << 12) | width);
  4738. finish:
  4739. if (intel_crtc->cursor_bo) {
  4740. if (dev_priv->info->cursor_needs_physical) {
  4741. if (intel_crtc->cursor_bo != obj)
  4742. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  4743. } else
  4744. i915_gem_object_unpin(intel_crtc->cursor_bo);
  4745. drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
  4746. }
  4747. mutex_unlock(&dev->struct_mutex);
  4748. intel_crtc->cursor_addr = addr;
  4749. intel_crtc->cursor_bo = obj;
  4750. intel_crtc->cursor_width = width;
  4751. intel_crtc->cursor_height = height;
  4752. intel_crtc_update_cursor(crtc, true);
  4753. return 0;
  4754. fail_unpin:
  4755. i915_gem_object_unpin(obj);
  4756. fail_locked:
  4757. mutex_unlock(&dev->struct_mutex);
  4758. fail:
  4759. drm_gem_object_unreference_unlocked(&obj->base);
  4760. return ret;
  4761. }
  4762. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  4763. {
  4764. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4765. intel_crtc->cursor_x = x;
  4766. intel_crtc->cursor_y = y;
  4767. intel_crtc_update_cursor(crtc, true);
  4768. return 0;
  4769. }
  4770. /** Sets the color ramps on behalf of RandR */
  4771. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  4772. u16 blue, int regno)
  4773. {
  4774. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4775. intel_crtc->lut_r[regno] = red >> 8;
  4776. intel_crtc->lut_g[regno] = green >> 8;
  4777. intel_crtc->lut_b[regno] = blue >> 8;
  4778. }
  4779. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  4780. u16 *blue, int regno)
  4781. {
  4782. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4783. *red = intel_crtc->lut_r[regno] << 8;
  4784. *green = intel_crtc->lut_g[regno] << 8;
  4785. *blue = intel_crtc->lut_b[regno] << 8;
  4786. }
  4787. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  4788. u16 *blue, uint32_t start, uint32_t size)
  4789. {
  4790. int end = (start + size > 256) ? 256 : start + size, i;
  4791. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4792. for (i = start; i < end; i++) {
  4793. intel_crtc->lut_r[i] = red[i] >> 8;
  4794. intel_crtc->lut_g[i] = green[i] >> 8;
  4795. intel_crtc->lut_b[i] = blue[i] >> 8;
  4796. }
  4797. intel_crtc_load_lut(crtc);
  4798. }
  4799. /**
  4800. * Get a pipe with a simple mode set on it for doing load-based monitor
  4801. * detection.
  4802. *
  4803. * It will be up to the load-detect code to adjust the pipe as appropriate for
  4804. * its requirements. The pipe will be connected to no other encoders.
  4805. *
  4806. * Currently this code will only succeed if there is a pipe with no encoders
  4807. * configured for it. In the future, it could choose to temporarily disable
  4808. * some outputs to free up a pipe for its use.
  4809. *
  4810. * \return crtc, or NULL if no pipes are available.
  4811. */
  4812. /* VESA 640x480x72Hz mode to set on the pipe */
  4813. static struct drm_display_mode load_detect_mode = {
  4814. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  4815. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  4816. };
  4817. static struct drm_framebuffer *
  4818. intel_framebuffer_create(struct drm_device *dev,
  4819. struct drm_mode_fb_cmd *mode_cmd,
  4820. struct drm_i915_gem_object *obj)
  4821. {
  4822. struct intel_framebuffer *intel_fb;
  4823. int ret;
  4824. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  4825. if (!intel_fb) {
  4826. drm_gem_object_unreference_unlocked(&obj->base);
  4827. return ERR_PTR(-ENOMEM);
  4828. }
  4829. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  4830. if (ret) {
  4831. drm_gem_object_unreference_unlocked(&obj->base);
  4832. kfree(intel_fb);
  4833. return ERR_PTR(ret);
  4834. }
  4835. return &intel_fb->base;
  4836. }
  4837. static u32
  4838. intel_framebuffer_pitch_for_width(int width, int bpp)
  4839. {
  4840. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  4841. return ALIGN(pitch, 64);
  4842. }
  4843. static u32
  4844. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  4845. {
  4846. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  4847. return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
  4848. }
  4849. static struct drm_framebuffer *
  4850. intel_framebuffer_create_for_mode(struct drm_device *dev,
  4851. struct drm_display_mode *mode,
  4852. int depth, int bpp)
  4853. {
  4854. struct drm_i915_gem_object *obj;
  4855. struct drm_mode_fb_cmd mode_cmd;
  4856. obj = i915_gem_alloc_object(dev,
  4857. intel_framebuffer_size_for_mode(mode, bpp));
  4858. if (obj == NULL)
  4859. return ERR_PTR(-ENOMEM);
  4860. mode_cmd.width = mode->hdisplay;
  4861. mode_cmd.height = mode->vdisplay;
  4862. mode_cmd.depth = depth;
  4863. mode_cmd.bpp = bpp;
  4864. mode_cmd.pitch = intel_framebuffer_pitch_for_width(mode_cmd.width, bpp);
  4865. return intel_framebuffer_create(dev, &mode_cmd, obj);
  4866. }
  4867. static struct drm_framebuffer *
  4868. mode_fits_in_fbdev(struct drm_device *dev,
  4869. struct drm_display_mode *mode)
  4870. {
  4871. struct drm_i915_private *dev_priv = dev->dev_private;
  4872. struct drm_i915_gem_object *obj;
  4873. struct drm_framebuffer *fb;
  4874. if (dev_priv->fbdev == NULL)
  4875. return NULL;
  4876. obj = dev_priv->fbdev->ifb.obj;
  4877. if (obj == NULL)
  4878. return NULL;
  4879. fb = &dev_priv->fbdev->ifb.base;
  4880. if (fb->pitch < intel_framebuffer_pitch_for_width(mode->hdisplay,
  4881. fb->bits_per_pixel))
  4882. return NULL;
  4883. if (obj->base.size < mode->vdisplay * fb->pitch)
  4884. return NULL;
  4885. return fb;
  4886. }
  4887. bool intel_get_load_detect_pipe(struct intel_encoder *intel_encoder,
  4888. struct drm_connector *connector,
  4889. struct drm_display_mode *mode,
  4890. struct intel_load_detect_pipe *old)
  4891. {
  4892. struct intel_crtc *intel_crtc;
  4893. struct drm_crtc *possible_crtc;
  4894. struct drm_encoder *encoder = &intel_encoder->base;
  4895. struct drm_crtc *crtc = NULL;
  4896. struct drm_device *dev = encoder->dev;
  4897. struct drm_framebuffer *old_fb;
  4898. int i = -1;
  4899. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  4900. connector->base.id, drm_get_connector_name(connector),
  4901. encoder->base.id, drm_get_encoder_name(encoder));
  4902. /*
  4903. * Algorithm gets a little messy:
  4904. *
  4905. * - if the connector already has an assigned crtc, use it (but make
  4906. * sure it's on first)
  4907. *
  4908. * - try to find the first unused crtc that can drive this connector,
  4909. * and use that if we find one
  4910. */
  4911. /* See if we already have a CRTC for this connector */
  4912. if (encoder->crtc) {
  4913. crtc = encoder->crtc;
  4914. intel_crtc = to_intel_crtc(crtc);
  4915. old->dpms_mode = intel_crtc->dpms_mode;
  4916. old->load_detect_temp = false;
  4917. /* Make sure the crtc and connector are running */
  4918. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  4919. struct drm_encoder_helper_funcs *encoder_funcs;
  4920. struct drm_crtc_helper_funcs *crtc_funcs;
  4921. crtc_funcs = crtc->helper_private;
  4922. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  4923. encoder_funcs = encoder->helper_private;
  4924. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  4925. }
  4926. return true;
  4927. }
  4928. /* Find an unused one (if possible) */
  4929. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  4930. i++;
  4931. if (!(encoder->possible_crtcs & (1 << i)))
  4932. continue;
  4933. if (!possible_crtc->enabled) {
  4934. crtc = possible_crtc;
  4935. break;
  4936. }
  4937. }
  4938. /*
  4939. * If we didn't find an unused CRTC, don't use any.
  4940. */
  4941. if (!crtc) {
  4942. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  4943. return false;
  4944. }
  4945. encoder->crtc = crtc;
  4946. connector->encoder = encoder;
  4947. intel_crtc = to_intel_crtc(crtc);
  4948. old->dpms_mode = intel_crtc->dpms_mode;
  4949. old->load_detect_temp = true;
  4950. old->release_fb = NULL;
  4951. if (!mode)
  4952. mode = &load_detect_mode;
  4953. old_fb = crtc->fb;
  4954. /* We need a framebuffer large enough to accommodate all accesses
  4955. * that the plane may generate whilst we perform load detection.
  4956. * We can not rely on the fbcon either being present (we get called
  4957. * during its initialisation to detect all boot displays, or it may
  4958. * not even exist) or that it is large enough to satisfy the
  4959. * requested mode.
  4960. */
  4961. crtc->fb = mode_fits_in_fbdev(dev, mode);
  4962. if (crtc->fb == NULL) {
  4963. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  4964. crtc->fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  4965. old->release_fb = crtc->fb;
  4966. } else
  4967. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  4968. if (IS_ERR(crtc->fb)) {
  4969. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  4970. crtc->fb = old_fb;
  4971. return false;
  4972. }
  4973. if (!drm_crtc_helper_set_mode(crtc, mode, 0, 0, old_fb)) {
  4974. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  4975. if (old->release_fb)
  4976. old->release_fb->funcs->destroy(old->release_fb);
  4977. crtc->fb = old_fb;
  4978. return false;
  4979. }
  4980. /* let the connector get through one full cycle before testing */
  4981. intel_wait_for_vblank(dev, intel_crtc->pipe);
  4982. return true;
  4983. }
  4984. void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder,
  4985. struct drm_connector *connector,
  4986. struct intel_load_detect_pipe *old)
  4987. {
  4988. struct drm_encoder *encoder = &intel_encoder->base;
  4989. struct drm_device *dev = encoder->dev;
  4990. struct drm_crtc *crtc = encoder->crtc;
  4991. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  4992. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  4993. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  4994. connector->base.id, drm_get_connector_name(connector),
  4995. encoder->base.id, drm_get_encoder_name(encoder));
  4996. if (old->load_detect_temp) {
  4997. connector->encoder = NULL;
  4998. drm_helper_disable_unused_functions(dev);
  4999. if (old->release_fb)
  5000. old->release_fb->funcs->destroy(old->release_fb);
  5001. return;
  5002. }
  5003. /* Switch crtc and encoder back off if necessary */
  5004. if (old->dpms_mode != DRM_MODE_DPMS_ON) {
  5005. encoder_funcs->dpms(encoder, old->dpms_mode);
  5006. crtc_funcs->dpms(crtc, old->dpms_mode);
  5007. }
  5008. }
  5009. /* Returns the clock of the currently programmed mode of the given pipe. */
  5010. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  5011. {
  5012. struct drm_i915_private *dev_priv = dev->dev_private;
  5013. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5014. int pipe = intel_crtc->pipe;
  5015. u32 dpll = I915_READ(DPLL(pipe));
  5016. u32 fp;
  5017. intel_clock_t clock;
  5018. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  5019. fp = I915_READ(FP0(pipe));
  5020. else
  5021. fp = I915_READ(FP1(pipe));
  5022. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  5023. if (IS_PINEVIEW(dev)) {
  5024. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  5025. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5026. } else {
  5027. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  5028. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5029. }
  5030. if (!IS_GEN2(dev)) {
  5031. if (IS_PINEVIEW(dev))
  5032. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  5033. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  5034. else
  5035. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  5036. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5037. switch (dpll & DPLL_MODE_MASK) {
  5038. case DPLLB_MODE_DAC_SERIAL:
  5039. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  5040. 5 : 10;
  5041. break;
  5042. case DPLLB_MODE_LVDS:
  5043. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  5044. 7 : 14;
  5045. break;
  5046. default:
  5047. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  5048. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  5049. return 0;
  5050. }
  5051. /* XXX: Handle the 100Mhz refclk */
  5052. intel_clock(dev, 96000, &clock);
  5053. } else {
  5054. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  5055. if (is_lvds) {
  5056. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  5057. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5058. clock.p2 = 14;
  5059. if ((dpll & PLL_REF_INPUT_MASK) ==
  5060. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  5061. /* XXX: might not be 66MHz */
  5062. intel_clock(dev, 66000, &clock);
  5063. } else
  5064. intel_clock(dev, 48000, &clock);
  5065. } else {
  5066. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  5067. clock.p1 = 2;
  5068. else {
  5069. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  5070. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  5071. }
  5072. if (dpll & PLL_P2_DIVIDE_BY_4)
  5073. clock.p2 = 4;
  5074. else
  5075. clock.p2 = 2;
  5076. intel_clock(dev, 48000, &clock);
  5077. }
  5078. }
  5079. /* XXX: It would be nice to validate the clocks, but we can't reuse
  5080. * i830PllIsValid() because it relies on the xf86_config connector
  5081. * configuration being accurate, which it isn't necessarily.
  5082. */
  5083. return clock.dot;
  5084. }
  5085. /** Returns the currently programmed mode of the given pipe. */
  5086. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  5087. struct drm_crtc *crtc)
  5088. {
  5089. struct drm_i915_private *dev_priv = dev->dev_private;
  5090. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5091. int pipe = intel_crtc->pipe;
  5092. struct drm_display_mode *mode;
  5093. int htot = I915_READ(HTOTAL(pipe));
  5094. int hsync = I915_READ(HSYNC(pipe));
  5095. int vtot = I915_READ(VTOTAL(pipe));
  5096. int vsync = I915_READ(VSYNC(pipe));
  5097. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  5098. if (!mode)
  5099. return NULL;
  5100. mode->clock = intel_crtc_clock_get(dev, crtc);
  5101. mode->hdisplay = (htot & 0xffff) + 1;
  5102. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  5103. mode->hsync_start = (hsync & 0xffff) + 1;
  5104. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  5105. mode->vdisplay = (vtot & 0xffff) + 1;
  5106. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  5107. mode->vsync_start = (vsync & 0xffff) + 1;
  5108. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  5109. drm_mode_set_name(mode);
  5110. drm_mode_set_crtcinfo(mode, 0);
  5111. return mode;
  5112. }
  5113. #define GPU_IDLE_TIMEOUT 500 /* ms */
  5114. /* When this timer fires, we've been idle for awhile */
  5115. static void intel_gpu_idle_timer(unsigned long arg)
  5116. {
  5117. struct drm_device *dev = (struct drm_device *)arg;
  5118. drm_i915_private_t *dev_priv = dev->dev_private;
  5119. if (!list_empty(&dev_priv->mm.active_list)) {
  5120. /* Still processing requests, so just re-arm the timer. */
  5121. mod_timer(&dev_priv->idle_timer, jiffies +
  5122. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  5123. return;
  5124. }
  5125. dev_priv->busy = false;
  5126. queue_work(dev_priv->wq, &dev_priv->idle_work);
  5127. }
  5128. #define CRTC_IDLE_TIMEOUT 1000 /* ms */
  5129. static void intel_crtc_idle_timer(unsigned long arg)
  5130. {
  5131. struct intel_crtc *intel_crtc = (struct intel_crtc *)arg;
  5132. struct drm_crtc *crtc = &intel_crtc->base;
  5133. drm_i915_private_t *dev_priv = crtc->dev->dev_private;
  5134. struct intel_framebuffer *intel_fb;
  5135. intel_fb = to_intel_framebuffer(crtc->fb);
  5136. if (intel_fb && intel_fb->obj->active) {
  5137. /* The framebuffer is still being accessed by the GPU. */
  5138. mod_timer(&intel_crtc->idle_timer, jiffies +
  5139. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  5140. return;
  5141. }
  5142. intel_crtc->busy = false;
  5143. queue_work(dev_priv->wq, &dev_priv->idle_work);
  5144. }
  5145. static void intel_increase_pllclock(struct drm_crtc *crtc)
  5146. {
  5147. struct drm_device *dev = crtc->dev;
  5148. drm_i915_private_t *dev_priv = dev->dev_private;
  5149. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5150. int pipe = intel_crtc->pipe;
  5151. int dpll_reg = DPLL(pipe);
  5152. int dpll;
  5153. if (HAS_PCH_SPLIT(dev))
  5154. return;
  5155. if (!dev_priv->lvds_downclock_avail)
  5156. return;
  5157. dpll = I915_READ(dpll_reg);
  5158. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  5159. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  5160. /* Unlock panel regs */
  5161. I915_WRITE(PP_CONTROL,
  5162. I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
  5163. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  5164. I915_WRITE(dpll_reg, dpll);
  5165. intel_wait_for_vblank(dev, pipe);
  5166. dpll = I915_READ(dpll_reg);
  5167. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  5168. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  5169. /* ...and lock them again */
  5170. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  5171. }
  5172. /* Schedule downclock */
  5173. mod_timer(&intel_crtc->idle_timer, jiffies +
  5174. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  5175. }
  5176. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  5177. {
  5178. struct drm_device *dev = crtc->dev;
  5179. drm_i915_private_t *dev_priv = dev->dev_private;
  5180. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5181. int pipe = intel_crtc->pipe;
  5182. int dpll_reg = DPLL(pipe);
  5183. int dpll = I915_READ(dpll_reg);
  5184. if (HAS_PCH_SPLIT(dev))
  5185. return;
  5186. if (!dev_priv->lvds_downclock_avail)
  5187. return;
  5188. /*
  5189. * Since this is called by a timer, we should never get here in
  5190. * the manual case.
  5191. */
  5192. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  5193. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  5194. /* Unlock panel regs */
  5195. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) |
  5196. PANEL_UNLOCK_REGS);
  5197. dpll |= DISPLAY_RATE_SELECT_FPA1;
  5198. I915_WRITE(dpll_reg, dpll);
  5199. intel_wait_for_vblank(dev, pipe);
  5200. dpll = I915_READ(dpll_reg);
  5201. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  5202. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  5203. /* ...and lock them again */
  5204. I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) & 0x3);
  5205. }
  5206. }
  5207. /**
  5208. * intel_idle_update - adjust clocks for idleness
  5209. * @work: work struct
  5210. *
  5211. * Either the GPU or display (or both) went idle. Check the busy status
  5212. * here and adjust the CRTC and GPU clocks as necessary.
  5213. */
  5214. static void intel_idle_update(struct work_struct *work)
  5215. {
  5216. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  5217. idle_work);
  5218. struct drm_device *dev = dev_priv->dev;
  5219. struct drm_crtc *crtc;
  5220. struct intel_crtc *intel_crtc;
  5221. if (!i915_powersave)
  5222. return;
  5223. mutex_lock(&dev->struct_mutex);
  5224. i915_update_gfx_val(dev_priv);
  5225. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5226. /* Skip inactive CRTCs */
  5227. if (!crtc->fb)
  5228. continue;
  5229. intel_crtc = to_intel_crtc(crtc);
  5230. if (!intel_crtc->busy)
  5231. intel_decrease_pllclock(crtc);
  5232. }
  5233. mutex_unlock(&dev->struct_mutex);
  5234. }
  5235. /**
  5236. * intel_mark_busy - mark the GPU and possibly the display busy
  5237. * @dev: drm device
  5238. * @obj: object we're operating on
  5239. *
  5240. * Callers can use this function to indicate that the GPU is busy processing
  5241. * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout
  5242. * buffer), we'll also mark the display as busy, so we know to increase its
  5243. * clock frequency.
  5244. */
  5245. void intel_mark_busy(struct drm_device *dev, struct drm_i915_gem_object *obj)
  5246. {
  5247. drm_i915_private_t *dev_priv = dev->dev_private;
  5248. struct drm_crtc *crtc = NULL;
  5249. struct intel_framebuffer *intel_fb;
  5250. struct intel_crtc *intel_crtc;
  5251. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  5252. return;
  5253. if (!dev_priv->busy)
  5254. dev_priv->busy = true;
  5255. else
  5256. mod_timer(&dev_priv->idle_timer, jiffies +
  5257. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  5258. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5259. if (!crtc->fb)
  5260. continue;
  5261. intel_crtc = to_intel_crtc(crtc);
  5262. intel_fb = to_intel_framebuffer(crtc->fb);
  5263. if (intel_fb->obj == obj) {
  5264. if (!intel_crtc->busy) {
  5265. /* Non-busy -> busy, upclock */
  5266. intel_increase_pllclock(crtc);
  5267. intel_crtc->busy = true;
  5268. } else {
  5269. /* Busy -> busy, put off timer */
  5270. mod_timer(&intel_crtc->idle_timer, jiffies +
  5271. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  5272. }
  5273. }
  5274. }
  5275. }
  5276. static void intel_crtc_destroy(struct drm_crtc *crtc)
  5277. {
  5278. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5279. struct drm_device *dev = crtc->dev;
  5280. struct intel_unpin_work *work;
  5281. unsigned long flags;
  5282. spin_lock_irqsave(&dev->event_lock, flags);
  5283. work = intel_crtc->unpin_work;
  5284. intel_crtc->unpin_work = NULL;
  5285. spin_unlock_irqrestore(&dev->event_lock, flags);
  5286. if (work) {
  5287. cancel_work_sync(&work->work);
  5288. kfree(work);
  5289. }
  5290. drm_crtc_cleanup(crtc);
  5291. kfree(intel_crtc);
  5292. }
  5293. static void intel_unpin_work_fn(struct work_struct *__work)
  5294. {
  5295. struct intel_unpin_work *work =
  5296. container_of(__work, struct intel_unpin_work, work);
  5297. mutex_lock(&work->dev->struct_mutex);
  5298. i915_gem_object_unpin(work->old_fb_obj);
  5299. drm_gem_object_unreference(&work->pending_flip_obj->base);
  5300. drm_gem_object_unreference(&work->old_fb_obj->base);
  5301. mutex_unlock(&work->dev->struct_mutex);
  5302. kfree(work);
  5303. }
  5304. static void do_intel_finish_page_flip(struct drm_device *dev,
  5305. struct drm_crtc *crtc)
  5306. {
  5307. drm_i915_private_t *dev_priv = dev->dev_private;
  5308. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5309. struct intel_unpin_work *work;
  5310. struct drm_i915_gem_object *obj;
  5311. struct drm_pending_vblank_event *e;
  5312. struct timeval tnow, tvbl;
  5313. unsigned long flags;
  5314. /* Ignore early vblank irqs */
  5315. if (intel_crtc == NULL)
  5316. return;
  5317. do_gettimeofday(&tnow);
  5318. spin_lock_irqsave(&dev->event_lock, flags);
  5319. work = intel_crtc->unpin_work;
  5320. if (work == NULL || !work->pending) {
  5321. spin_unlock_irqrestore(&dev->event_lock, flags);
  5322. return;
  5323. }
  5324. intel_crtc->unpin_work = NULL;
  5325. if (work->event) {
  5326. e = work->event;
  5327. e->event.sequence = drm_vblank_count_and_time(dev, intel_crtc->pipe, &tvbl);
  5328. /* Called before vblank count and timestamps have
  5329. * been updated for the vblank interval of flip
  5330. * completion? Need to increment vblank count and
  5331. * add one videorefresh duration to returned timestamp
  5332. * to account for this. We assume this happened if we
  5333. * get called over 0.9 frame durations after the last
  5334. * timestamped vblank.
  5335. *
  5336. * This calculation can not be used with vrefresh rates
  5337. * below 5Hz (10Hz to be on the safe side) without
  5338. * promoting to 64 integers.
  5339. */
  5340. if (10 * (timeval_to_ns(&tnow) - timeval_to_ns(&tvbl)) >
  5341. 9 * crtc->framedur_ns) {
  5342. e->event.sequence++;
  5343. tvbl = ns_to_timeval(timeval_to_ns(&tvbl) +
  5344. crtc->framedur_ns);
  5345. }
  5346. e->event.tv_sec = tvbl.tv_sec;
  5347. e->event.tv_usec = tvbl.tv_usec;
  5348. list_add_tail(&e->base.link,
  5349. &e->base.file_priv->event_list);
  5350. wake_up_interruptible(&e->base.file_priv->event_wait);
  5351. }
  5352. drm_vblank_put(dev, intel_crtc->pipe);
  5353. spin_unlock_irqrestore(&dev->event_lock, flags);
  5354. obj = work->old_fb_obj;
  5355. atomic_clear_mask(1 << intel_crtc->plane,
  5356. &obj->pending_flip.counter);
  5357. if (atomic_read(&obj->pending_flip) == 0)
  5358. wake_up(&dev_priv->pending_flip_queue);
  5359. schedule_work(&work->work);
  5360. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  5361. }
  5362. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  5363. {
  5364. drm_i915_private_t *dev_priv = dev->dev_private;
  5365. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  5366. do_intel_finish_page_flip(dev, crtc);
  5367. }
  5368. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  5369. {
  5370. drm_i915_private_t *dev_priv = dev->dev_private;
  5371. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  5372. do_intel_finish_page_flip(dev, crtc);
  5373. }
  5374. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  5375. {
  5376. drm_i915_private_t *dev_priv = dev->dev_private;
  5377. struct intel_crtc *intel_crtc =
  5378. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  5379. unsigned long flags;
  5380. spin_lock_irqsave(&dev->event_lock, flags);
  5381. if (intel_crtc->unpin_work) {
  5382. if ((++intel_crtc->unpin_work->pending) > 1)
  5383. DRM_ERROR("Prepared flip multiple times\n");
  5384. } else {
  5385. DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n");
  5386. }
  5387. spin_unlock_irqrestore(&dev->event_lock, flags);
  5388. }
  5389. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  5390. struct drm_framebuffer *fb,
  5391. struct drm_pending_vblank_event *event)
  5392. {
  5393. struct drm_device *dev = crtc->dev;
  5394. struct drm_i915_private *dev_priv = dev->dev_private;
  5395. struct intel_framebuffer *intel_fb;
  5396. struct drm_i915_gem_object *obj;
  5397. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5398. struct intel_unpin_work *work;
  5399. unsigned long flags, offset;
  5400. int pipe = intel_crtc->pipe;
  5401. u32 pf, pipesrc;
  5402. int ret;
  5403. work = kzalloc(sizeof *work, GFP_KERNEL);
  5404. if (work == NULL)
  5405. return -ENOMEM;
  5406. work->event = event;
  5407. work->dev = crtc->dev;
  5408. intel_fb = to_intel_framebuffer(crtc->fb);
  5409. work->old_fb_obj = intel_fb->obj;
  5410. INIT_WORK(&work->work, intel_unpin_work_fn);
  5411. /* We borrow the event spin lock for protecting unpin_work */
  5412. spin_lock_irqsave(&dev->event_lock, flags);
  5413. if (intel_crtc->unpin_work) {
  5414. spin_unlock_irqrestore(&dev->event_lock, flags);
  5415. kfree(work);
  5416. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  5417. return -EBUSY;
  5418. }
  5419. intel_crtc->unpin_work = work;
  5420. spin_unlock_irqrestore(&dev->event_lock, flags);
  5421. intel_fb = to_intel_framebuffer(fb);
  5422. obj = intel_fb->obj;
  5423. mutex_lock(&dev->struct_mutex);
  5424. ret = intel_pin_and_fence_fb_obj(dev, obj, LP_RING(dev_priv));
  5425. if (ret)
  5426. goto cleanup_work;
  5427. /* Reference the objects for the scheduled work. */
  5428. drm_gem_object_reference(&work->old_fb_obj->base);
  5429. drm_gem_object_reference(&obj->base);
  5430. crtc->fb = fb;
  5431. ret = drm_vblank_get(dev, intel_crtc->pipe);
  5432. if (ret)
  5433. goto cleanup_objs;
  5434. if (IS_GEN3(dev) || IS_GEN2(dev)) {
  5435. u32 flip_mask;
  5436. /* Can't queue multiple flips, so wait for the previous
  5437. * one to finish before executing the next.
  5438. */
  5439. ret = BEGIN_LP_RING(2);
  5440. if (ret)
  5441. goto cleanup_objs;
  5442. if (intel_crtc->plane)
  5443. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5444. else
  5445. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5446. OUT_RING(MI_WAIT_FOR_EVENT | flip_mask);
  5447. OUT_RING(MI_NOOP);
  5448. ADVANCE_LP_RING();
  5449. }
  5450. work->pending_flip_obj = obj;
  5451. work->enable_stall_check = true;
  5452. /* Offset into the new buffer for cases of shared fbs between CRTCs */
  5453. offset = crtc->y * fb->pitch + crtc->x * fb->bits_per_pixel/8;
  5454. ret = BEGIN_LP_RING(4);
  5455. if (ret)
  5456. goto cleanup_objs;
  5457. /* Block clients from rendering to the new back buffer until
  5458. * the flip occurs and the object is no longer visible.
  5459. */
  5460. atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
  5461. switch (INTEL_INFO(dev)->gen) {
  5462. case 2:
  5463. OUT_RING(MI_DISPLAY_FLIP |
  5464. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5465. OUT_RING(fb->pitch);
  5466. OUT_RING(obj->gtt_offset + offset);
  5467. OUT_RING(MI_NOOP);
  5468. break;
  5469. case 3:
  5470. OUT_RING(MI_DISPLAY_FLIP_I915 |
  5471. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5472. OUT_RING(fb->pitch);
  5473. OUT_RING(obj->gtt_offset + offset);
  5474. OUT_RING(MI_NOOP);
  5475. break;
  5476. case 4:
  5477. case 5:
  5478. /* i965+ uses the linear or tiled offsets from the
  5479. * Display Registers (which do not change across a page-flip)
  5480. * so we need only reprogram the base address.
  5481. */
  5482. OUT_RING(MI_DISPLAY_FLIP |
  5483. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5484. OUT_RING(fb->pitch);
  5485. OUT_RING(obj->gtt_offset | obj->tiling_mode);
  5486. /* XXX Enabling the panel-fitter across page-flip is so far
  5487. * untested on non-native modes, so ignore it for now.
  5488. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  5489. */
  5490. pf = 0;
  5491. pipesrc = I915_READ(PIPESRC(pipe)) & 0x0fff0fff;
  5492. OUT_RING(pf | pipesrc);
  5493. break;
  5494. case 6:
  5495. case 7:
  5496. OUT_RING(MI_DISPLAY_FLIP |
  5497. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5498. OUT_RING(fb->pitch | obj->tiling_mode);
  5499. OUT_RING(obj->gtt_offset);
  5500. pf = I915_READ(PF_CTL(pipe)) & PF_ENABLE;
  5501. pipesrc = I915_READ(PIPESRC(pipe)) & 0x0fff0fff;
  5502. OUT_RING(pf | pipesrc);
  5503. break;
  5504. }
  5505. ADVANCE_LP_RING();
  5506. mutex_unlock(&dev->struct_mutex);
  5507. trace_i915_flip_request(intel_crtc->plane, obj);
  5508. return 0;
  5509. cleanup_objs:
  5510. drm_gem_object_unreference(&work->old_fb_obj->base);
  5511. drm_gem_object_unreference(&obj->base);
  5512. cleanup_work:
  5513. mutex_unlock(&dev->struct_mutex);
  5514. spin_lock_irqsave(&dev->event_lock, flags);
  5515. intel_crtc->unpin_work = NULL;
  5516. spin_unlock_irqrestore(&dev->event_lock, flags);
  5517. kfree(work);
  5518. return ret;
  5519. }
  5520. static void intel_sanitize_modesetting(struct drm_device *dev,
  5521. int pipe, int plane)
  5522. {
  5523. struct drm_i915_private *dev_priv = dev->dev_private;
  5524. u32 reg, val;
  5525. if (HAS_PCH_SPLIT(dev))
  5526. return;
  5527. /* Who knows what state these registers were left in by the BIOS or
  5528. * grub?
  5529. *
  5530. * If we leave the registers in a conflicting state (e.g. with the
  5531. * display plane reading from the other pipe than the one we intend
  5532. * to use) then when we attempt to teardown the active mode, we will
  5533. * not disable the pipes and planes in the correct order -- leaving
  5534. * a plane reading from a disabled pipe and possibly leading to
  5535. * undefined behaviour.
  5536. */
  5537. reg = DSPCNTR(plane);
  5538. val = I915_READ(reg);
  5539. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  5540. return;
  5541. if (!!(val & DISPPLANE_SEL_PIPE_MASK) == pipe)
  5542. return;
  5543. /* This display plane is active and attached to the other CPU pipe. */
  5544. pipe = !pipe;
  5545. /* Disable the plane and wait for it to stop reading from the pipe. */
  5546. intel_disable_plane(dev_priv, plane, pipe);
  5547. intel_disable_pipe(dev_priv, pipe);
  5548. }
  5549. static void intel_crtc_reset(struct drm_crtc *crtc)
  5550. {
  5551. struct drm_device *dev = crtc->dev;
  5552. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5553. /* Reset flags back to the 'unknown' status so that they
  5554. * will be correctly set on the initial modeset.
  5555. */
  5556. intel_crtc->dpms_mode = -1;
  5557. /* We need to fix up any BIOS configuration that conflicts with
  5558. * our expectations.
  5559. */
  5560. intel_sanitize_modesetting(dev, intel_crtc->pipe, intel_crtc->plane);
  5561. }
  5562. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  5563. .dpms = intel_crtc_dpms,
  5564. .mode_fixup = intel_crtc_mode_fixup,
  5565. .mode_set = intel_crtc_mode_set,
  5566. .mode_set_base = intel_pipe_set_base,
  5567. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  5568. .load_lut = intel_crtc_load_lut,
  5569. .disable = intel_crtc_disable,
  5570. };
  5571. static const struct drm_crtc_funcs intel_crtc_funcs = {
  5572. .reset = intel_crtc_reset,
  5573. .cursor_set = intel_crtc_cursor_set,
  5574. .cursor_move = intel_crtc_cursor_move,
  5575. .gamma_set = intel_crtc_gamma_set,
  5576. .set_config = drm_crtc_helper_set_config,
  5577. .destroy = intel_crtc_destroy,
  5578. .page_flip = intel_crtc_page_flip,
  5579. };
  5580. static void intel_crtc_init(struct drm_device *dev, int pipe)
  5581. {
  5582. drm_i915_private_t *dev_priv = dev->dev_private;
  5583. struct intel_crtc *intel_crtc;
  5584. int i;
  5585. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  5586. if (intel_crtc == NULL)
  5587. return;
  5588. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  5589. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  5590. for (i = 0; i < 256; i++) {
  5591. intel_crtc->lut_r[i] = i;
  5592. intel_crtc->lut_g[i] = i;
  5593. intel_crtc->lut_b[i] = i;
  5594. }
  5595. /* Swap pipes & planes for FBC on pre-965 */
  5596. intel_crtc->pipe = pipe;
  5597. intel_crtc->plane = pipe;
  5598. if (IS_MOBILE(dev) && IS_GEN3(dev)) {
  5599. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  5600. intel_crtc->plane = !pipe;
  5601. }
  5602. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  5603. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  5604. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  5605. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  5606. intel_crtc_reset(&intel_crtc->base);
  5607. intel_crtc->active = true; /* force the pipe off on setup_init_config */
  5608. if (HAS_PCH_SPLIT(dev)) {
  5609. intel_helper_funcs.prepare = ironlake_crtc_prepare;
  5610. intel_helper_funcs.commit = ironlake_crtc_commit;
  5611. } else {
  5612. intel_helper_funcs.prepare = i9xx_crtc_prepare;
  5613. intel_helper_funcs.commit = i9xx_crtc_commit;
  5614. }
  5615. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  5616. intel_crtc->busy = false;
  5617. setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer,
  5618. (unsigned long)intel_crtc);
  5619. }
  5620. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  5621. struct drm_file *file)
  5622. {
  5623. drm_i915_private_t *dev_priv = dev->dev_private;
  5624. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  5625. struct drm_mode_object *drmmode_obj;
  5626. struct intel_crtc *crtc;
  5627. if (!dev_priv) {
  5628. DRM_ERROR("called with no initialization\n");
  5629. return -EINVAL;
  5630. }
  5631. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  5632. DRM_MODE_OBJECT_CRTC);
  5633. if (!drmmode_obj) {
  5634. DRM_ERROR("no such CRTC id\n");
  5635. return -EINVAL;
  5636. }
  5637. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  5638. pipe_from_crtc_id->pipe = crtc->pipe;
  5639. return 0;
  5640. }
  5641. static int intel_encoder_clones(struct drm_device *dev, int type_mask)
  5642. {
  5643. struct intel_encoder *encoder;
  5644. int index_mask = 0;
  5645. int entry = 0;
  5646. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  5647. if (type_mask & encoder->clone_mask)
  5648. index_mask |= (1 << entry);
  5649. entry++;
  5650. }
  5651. return index_mask;
  5652. }
  5653. static bool has_edp_a(struct drm_device *dev)
  5654. {
  5655. struct drm_i915_private *dev_priv = dev->dev_private;
  5656. if (!IS_MOBILE(dev))
  5657. return false;
  5658. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  5659. return false;
  5660. if (IS_GEN5(dev) &&
  5661. (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
  5662. return false;
  5663. return true;
  5664. }
  5665. static void intel_setup_outputs(struct drm_device *dev)
  5666. {
  5667. struct drm_i915_private *dev_priv = dev->dev_private;
  5668. struct intel_encoder *encoder;
  5669. bool dpd_is_edp = false;
  5670. bool has_lvds = false;
  5671. if (IS_MOBILE(dev) && !IS_I830(dev))
  5672. has_lvds = intel_lvds_init(dev);
  5673. if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
  5674. /* disable the panel fitter on everything but LVDS */
  5675. I915_WRITE(PFIT_CONTROL, 0);
  5676. }
  5677. if (HAS_PCH_SPLIT(dev)) {
  5678. dpd_is_edp = intel_dpd_is_edp(dev);
  5679. if (has_edp_a(dev))
  5680. intel_dp_init(dev, DP_A);
  5681. if (dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
  5682. intel_dp_init(dev, PCH_DP_D);
  5683. }
  5684. intel_crt_init(dev);
  5685. if (HAS_PCH_SPLIT(dev)) {
  5686. int found;
  5687. if (I915_READ(HDMIB) & PORT_DETECTED) {
  5688. /* PCH SDVOB multiplex with HDMIB */
  5689. found = intel_sdvo_init(dev, PCH_SDVOB);
  5690. if (!found)
  5691. intel_hdmi_init(dev, HDMIB);
  5692. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  5693. intel_dp_init(dev, PCH_DP_B);
  5694. }
  5695. if (I915_READ(HDMIC) & PORT_DETECTED)
  5696. intel_hdmi_init(dev, HDMIC);
  5697. if (I915_READ(HDMID) & PORT_DETECTED)
  5698. intel_hdmi_init(dev, HDMID);
  5699. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  5700. intel_dp_init(dev, PCH_DP_C);
  5701. if (!dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
  5702. intel_dp_init(dev, PCH_DP_D);
  5703. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  5704. bool found = false;
  5705. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  5706. DRM_DEBUG_KMS("probing SDVOB\n");
  5707. found = intel_sdvo_init(dev, SDVOB);
  5708. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  5709. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  5710. intel_hdmi_init(dev, SDVOB);
  5711. }
  5712. if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
  5713. DRM_DEBUG_KMS("probing DP_B\n");
  5714. intel_dp_init(dev, DP_B);
  5715. }
  5716. }
  5717. /* Before G4X SDVOC doesn't have its own detect register */
  5718. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  5719. DRM_DEBUG_KMS("probing SDVOC\n");
  5720. found = intel_sdvo_init(dev, SDVOC);
  5721. }
  5722. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  5723. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  5724. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  5725. intel_hdmi_init(dev, SDVOC);
  5726. }
  5727. if (SUPPORTS_INTEGRATED_DP(dev)) {
  5728. DRM_DEBUG_KMS("probing DP_C\n");
  5729. intel_dp_init(dev, DP_C);
  5730. }
  5731. }
  5732. if (SUPPORTS_INTEGRATED_DP(dev) &&
  5733. (I915_READ(DP_D) & DP_DETECTED)) {
  5734. DRM_DEBUG_KMS("probing DP_D\n");
  5735. intel_dp_init(dev, DP_D);
  5736. }
  5737. } else if (IS_GEN2(dev))
  5738. intel_dvo_init(dev);
  5739. if (SUPPORTS_TV(dev))
  5740. intel_tv_init(dev);
  5741. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  5742. encoder->base.possible_crtcs = encoder->crtc_mask;
  5743. encoder->base.possible_clones =
  5744. intel_encoder_clones(dev, encoder->clone_mask);
  5745. }
  5746. intel_panel_setup_backlight(dev);
  5747. /* disable all the possible outputs/crtcs before entering KMS mode */
  5748. drm_helper_disable_unused_functions(dev);
  5749. }
  5750. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  5751. {
  5752. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  5753. drm_framebuffer_cleanup(fb);
  5754. drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
  5755. kfree(intel_fb);
  5756. }
  5757. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  5758. struct drm_file *file,
  5759. unsigned int *handle)
  5760. {
  5761. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  5762. struct drm_i915_gem_object *obj = intel_fb->obj;
  5763. return drm_gem_handle_create(file, &obj->base, handle);
  5764. }
  5765. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  5766. .destroy = intel_user_framebuffer_destroy,
  5767. .create_handle = intel_user_framebuffer_create_handle,
  5768. };
  5769. int intel_framebuffer_init(struct drm_device *dev,
  5770. struct intel_framebuffer *intel_fb,
  5771. struct drm_mode_fb_cmd *mode_cmd,
  5772. struct drm_i915_gem_object *obj)
  5773. {
  5774. int ret;
  5775. if (obj->tiling_mode == I915_TILING_Y)
  5776. return -EINVAL;
  5777. if (mode_cmd->pitch & 63)
  5778. return -EINVAL;
  5779. switch (mode_cmd->bpp) {
  5780. case 8:
  5781. case 16:
  5782. case 24:
  5783. case 32:
  5784. break;
  5785. default:
  5786. return -EINVAL;
  5787. }
  5788. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  5789. if (ret) {
  5790. DRM_ERROR("framebuffer init failed %d\n", ret);
  5791. return ret;
  5792. }
  5793. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  5794. intel_fb->obj = obj;
  5795. return 0;
  5796. }
  5797. static struct drm_framebuffer *
  5798. intel_user_framebuffer_create(struct drm_device *dev,
  5799. struct drm_file *filp,
  5800. struct drm_mode_fb_cmd *mode_cmd)
  5801. {
  5802. struct drm_i915_gem_object *obj;
  5803. obj = to_intel_bo(drm_gem_object_lookup(dev, filp, mode_cmd->handle));
  5804. if (&obj->base == NULL)
  5805. return ERR_PTR(-ENOENT);
  5806. return intel_framebuffer_create(dev, mode_cmd, obj);
  5807. }
  5808. static const struct drm_mode_config_funcs intel_mode_funcs = {
  5809. .fb_create = intel_user_framebuffer_create,
  5810. .output_poll_changed = intel_fb_output_poll_changed,
  5811. };
  5812. static struct drm_i915_gem_object *
  5813. intel_alloc_context_page(struct drm_device *dev)
  5814. {
  5815. struct drm_i915_gem_object *ctx;
  5816. int ret;
  5817. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  5818. ctx = i915_gem_alloc_object(dev, 4096);
  5819. if (!ctx) {
  5820. DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
  5821. return NULL;
  5822. }
  5823. ret = i915_gem_object_pin(ctx, 4096, true);
  5824. if (ret) {
  5825. DRM_ERROR("failed to pin power context: %d\n", ret);
  5826. goto err_unref;
  5827. }
  5828. ret = i915_gem_object_set_to_gtt_domain(ctx, 1);
  5829. if (ret) {
  5830. DRM_ERROR("failed to set-domain on power context: %d\n", ret);
  5831. goto err_unpin;
  5832. }
  5833. return ctx;
  5834. err_unpin:
  5835. i915_gem_object_unpin(ctx);
  5836. err_unref:
  5837. drm_gem_object_unreference(&ctx->base);
  5838. mutex_unlock(&dev->struct_mutex);
  5839. return NULL;
  5840. }
  5841. bool ironlake_set_drps(struct drm_device *dev, u8 val)
  5842. {
  5843. struct drm_i915_private *dev_priv = dev->dev_private;
  5844. u16 rgvswctl;
  5845. rgvswctl = I915_READ16(MEMSWCTL);
  5846. if (rgvswctl & MEMCTL_CMD_STS) {
  5847. DRM_DEBUG("gpu busy, RCS change rejected\n");
  5848. return false; /* still busy with another command */
  5849. }
  5850. rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
  5851. (val << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM;
  5852. I915_WRITE16(MEMSWCTL, rgvswctl);
  5853. POSTING_READ16(MEMSWCTL);
  5854. rgvswctl |= MEMCTL_CMD_STS;
  5855. I915_WRITE16(MEMSWCTL, rgvswctl);
  5856. return true;
  5857. }
  5858. void ironlake_enable_drps(struct drm_device *dev)
  5859. {
  5860. struct drm_i915_private *dev_priv = dev->dev_private;
  5861. u32 rgvmodectl = I915_READ(MEMMODECTL);
  5862. u8 fmax, fmin, fstart, vstart;
  5863. /* Enable temp reporting */
  5864. I915_WRITE16(PMMISC, I915_READ(PMMISC) | MCPPCE_EN);
  5865. I915_WRITE16(TSC1, I915_READ(TSC1) | TSE);
  5866. /* 100ms RC evaluation intervals */
  5867. I915_WRITE(RCUPEI, 100000);
  5868. I915_WRITE(RCDNEI, 100000);
  5869. /* Set max/min thresholds to 90ms and 80ms respectively */
  5870. I915_WRITE(RCBMAXAVG, 90000);
  5871. I915_WRITE(RCBMINAVG, 80000);
  5872. I915_WRITE(MEMIHYST, 1);
  5873. /* Set up min, max, and cur for interrupt handling */
  5874. fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT;
  5875. fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
  5876. fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
  5877. MEMMODE_FSTART_SHIFT;
  5878. vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >>
  5879. PXVFREQ_PX_SHIFT;
  5880. dev_priv->fmax = fmax; /* IPS callback will increase this */
  5881. dev_priv->fstart = fstart;
  5882. dev_priv->max_delay = fstart;
  5883. dev_priv->min_delay = fmin;
  5884. dev_priv->cur_delay = fstart;
  5885. DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
  5886. fmax, fmin, fstart);
  5887. I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
  5888. /*
  5889. * Interrupts will be enabled in ironlake_irq_postinstall
  5890. */
  5891. I915_WRITE(VIDSTART, vstart);
  5892. POSTING_READ(VIDSTART);
  5893. rgvmodectl |= MEMMODE_SWMODE_EN;
  5894. I915_WRITE(MEMMODECTL, rgvmodectl);
  5895. if (wait_for((I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) == 0, 10))
  5896. DRM_ERROR("stuck trying to change perf mode\n");
  5897. msleep(1);
  5898. ironlake_set_drps(dev, fstart);
  5899. dev_priv->last_count1 = I915_READ(0x112e4) + I915_READ(0x112e8) +
  5900. I915_READ(0x112e0);
  5901. dev_priv->last_time1 = jiffies_to_msecs(jiffies);
  5902. dev_priv->last_count2 = I915_READ(0x112f4);
  5903. getrawmonotonic(&dev_priv->last_time2);
  5904. }
  5905. void ironlake_disable_drps(struct drm_device *dev)
  5906. {
  5907. struct drm_i915_private *dev_priv = dev->dev_private;
  5908. u16 rgvswctl = I915_READ16(MEMSWCTL);
  5909. /* Ack interrupts, disable EFC interrupt */
  5910. I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN);
  5911. I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG);
  5912. I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT);
  5913. I915_WRITE(DEIIR, DE_PCU_EVENT);
  5914. I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT);
  5915. /* Go back to the starting frequency */
  5916. ironlake_set_drps(dev, dev_priv->fstart);
  5917. msleep(1);
  5918. rgvswctl |= MEMCTL_CMD_STS;
  5919. I915_WRITE(MEMSWCTL, rgvswctl);
  5920. msleep(1);
  5921. }
  5922. void gen6_set_rps(struct drm_device *dev, u8 val)
  5923. {
  5924. struct drm_i915_private *dev_priv = dev->dev_private;
  5925. u32 swreq;
  5926. swreq = (val & 0x3ff) << 25;
  5927. I915_WRITE(GEN6_RPNSWREQ, swreq);
  5928. }
  5929. void gen6_disable_rps(struct drm_device *dev)
  5930. {
  5931. struct drm_i915_private *dev_priv = dev->dev_private;
  5932. I915_WRITE(GEN6_RPNSWREQ, 1 << 31);
  5933. I915_WRITE(GEN6_PMINTRMSK, 0xffffffff);
  5934. I915_WRITE(GEN6_PMIER, 0);
  5935. spin_lock_irq(&dev_priv->rps_lock);
  5936. dev_priv->pm_iir = 0;
  5937. spin_unlock_irq(&dev_priv->rps_lock);
  5938. I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
  5939. }
  5940. static unsigned long intel_pxfreq(u32 vidfreq)
  5941. {
  5942. unsigned long freq;
  5943. int div = (vidfreq & 0x3f0000) >> 16;
  5944. int post = (vidfreq & 0x3000) >> 12;
  5945. int pre = (vidfreq & 0x7);
  5946. if (!pre)
  5947. return 0;
  5948. freq = ((div * 133333) / ((1<<post) * pre));
  5949. return freq;
  5950. }
  5951. void intel_init_emon(struct drm_device *dev)
  5952. {
  5953. struct drm_i915_private *dev_priv = dev->dev_private;
  5954. u32 lcfuse;
  5955. u8 pxw[16];
  5956. int i;
  5957. /* Disable to program */
  5958. I915_WRITE(ECR, 0);
  5959. POSTING_READ(ECR);
  5960. /* Program energy weights for various events */
  5961. I915_WRITE(SDEW, 0x15040d00);
  5962. I915_WRITE(CSIEW0, 0x007f0000);
  5963. I915_WRITE(CSIEW1, 0x1e220004);
  5964. I915_WRITE(CSIEW2, 0x04000004);
  5965. for (i = 0; i < 5; i++)
  5966. I915_WRITE(PEW + (i * 4), 0);
  5967. for (i = 0; i < 3; i++)
  5968. I915_WRITE(DEW + (i * 4), 0);
  5969. /* Program P-state weights to account for frequency power adjustment */
  5970. for (i = 0; i < 16; i++) {
  5971. u32 pxvidfreq = I915_READ(PXVFREQ_BASE + (i * 4));
  5972. unsigned long freq = intel_pxfreq(pxvidfreq);
  5973. unsigned long vid = (pxvidfreq & PXVFREQ_PX_MASK) >>
  5974. PXVFREQ_PX_SHIFT;
  5975. unsigned long val;
  5976. val = vid * vid;
  5977. val *= (freq / 1000);
  5978. val *= 255;
  5979. val /= (127*127*900);
  5980. if (val > 0xff)
  5981. DRM_ERROR("bad pxval: %ld\n", val);
  5982. pxw[i] = val;
  5983. }
  5984. /* Render standby states get 0 weight */
  5985. pxw[14] = 0;
  5986. pxw[15] = 0;
  5987. for (i = 0; i < 4; i++) {
  5988. u32 val = (pxw[i*4] << 24) | (pxw[(i*4)+1] << 16) |
  5989. (pxw[(i*4)+2] << 8) | (pxw[(i*4)+3]);
  5990. I915_WRITE(PXW + (i * 4), val);
  5991. }
  5992. /* Adjust magic regs to magic values (more experimental results) */
  5993. I915_WRITE(OGW0, 0);
  5994. I915_WRITE(OGW1, 0);
  5995. I915_WRITE(EG0, 0x00007f00);
  5996. I915_WRITE(EG1, 0x0000000e);
  5997. I915_WRITE(EG2, 0x000e0000);
  5998. I915_WRITE(EG3, 0x68000300);
  5999. I915_WRITE(EG4, 0x42000000);
  6000. I915_WRITE(EG5, 0x00140031);
  6001. I915_WRITE(EG6, 0);
  6002. I915_WRITE(EG7, 0);
  6003. for (i = 0; i < 8; i++)
  6004. I915_WRITE(PXWL + (i * 4), 0);
  6005. /* Enable PMON + select events */
  6006. I915_WRITE(ECR, 0x80000019);
  6007. lcfuse = I915_READ(LCFUSE02);
  6008. dev_priv->corr = (lcfuse & LCFUSE_HIV_MASK);
  6009. }
  6010. void gen6_enable_rps(struct drm_i915_private *dev_priv)
  6011. {
  6012. u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
  6013. u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
  6014. u32 pcu_mbox, rc6_mask = 0;
  6015. int cur_freq, min_freq, max_freq;
  6016. int i;
  6017. /* Here begins a magic sequence of register writes to enable
  6018. * auto-downclocking.
  6019. *
  6020. * Perhaps there might be some value in exposing these to
  6021. * userspace...
  6022. */
  6023. I915_WRITE(GEN6_RC_STATE, 0);
  6024. mutex_lock(&dev_priv->dev->struct_mutex);
  6025. gen6_gt_force_wake_get(dev_priv);
  6026. /* disable the counters and set deterministic thresholds */
  6027. I915_WRITE(GEN6_RC_CONTROL, 0);
  6028. I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT, 1000 << 16);
  6029. I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT, 40 << 16 | 30);
  6030. I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT, 30);
  6031. I915_WRITE(GEN6_RC_EVALUATION_INTERVAL, 125000);
  6032. I915_WRITE(GEN6_RC_IDLE_HYSTERSIS, 25);
  6033. for (i = 0; i < I915_NUM_RINGS; i++)
  6034. I915_WRITE(RING_MAX_IDLE(dev_priv->ring[i].mmio_base), 10);
  6035. I915_WRITE(GEN6_RC_SLEEP, 0);
  6036. I915_WRITE(GEN6_RC1e_THRESHOLD, 1000);
  6037. I915_WRITE(GEN6_RC6_THRESHOLD, 50000);
  6038. I915_WRITE(GEN6_RC6p_THRESHOLD, 100000);
  6039. I915_WRITE(GEN6_RC6pp_THRESHOLD, 64000); /* unused */
  6040. if (i915_enable_rc6)
  6041. rc6_mask = GEN6_RC_CTL_RC6p_ENABLE |
  6042. GEN6_RC_CTL_RC6_ENABLE;
  6043. I915_WRITE(GEN6_RC_CONTROL,
  6044. rc6_mask |
  6045. GEN6_RC_CTL_EI_MODE(1) |
  6046. GEN6_RC_CTL_HW_ENABLE);
  6047. I915_WRITE(GEN6_RPNSWREQ,
  6048. GEN6_FREQUENCY(10) |
  6049. GEN6_OFFSET(0) |
  6050. GEN6_AGGRESSIVE_TURBO);
  6051. I915_WRITE(GEN6_RC_VIDEO_FREQ,
  6052. GEN6_FREQUENCY(12));
  6053. I915_WRITE(GEN6_RP_DOWN_TIMEOUT, 1000000);
  6054. I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
  6055. 18 << 24 |
  6056. 6 << 16);
  6057. I915_WRITE(GEN6_RP_UP_THRESHOLD, 10000);
  6058. I915_WRITE(GEN6_RP_DOWN_THRESHOLD, 1000000);
  6059. I915_WRITE(GEN6_RP_UP_EI, 100000);
  6060. I915_WRITE(GEN6_RP_DOWN_EI, 5000000);
  6061. I915_WRITE(GEN6_RP_IDLE_HYSTERSIS, 10);
  6062. I915_WRITE(GEN6_RP_CONTROL,
  6063. GEN6_RP_MEDIA_TURBO |
  6064. GEN6_RP_USE_NORMAL_FREQ |
  6065. GEN6_RP_MEDIA_IS_GFX |
  6066. GEN6_RP_ENABLE |
  6067. GEN6_RP_UP_BUSY_AVG |
  6068. GEN6_RP_DOWN_IDLE_CONT);
  6069. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  6070. 500))
  6071. DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
  6072. I915_WRITE(GEN6_PCODE_DATA, 0);
  6073. I915_WRITE(GEN6_PCODE_MAILBOX,
  6074. GEN6_PCODE_READY |
  6075. GEN6_PCODE_WRITE_MIN_FREQ_TABLE);
  6076. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  6077. 500))
  6078. DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
  6079. min_freq = (rp_state_cap & 0xff0000) >> 16;
  6080. max_freq = rp_state_cap & 0xff;
  6081. cur_freq = (gt_perf_status & 0xff00) >> 8;
  6082. /* Check for overclock support */
  6083. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  6084. 500))
  6085. DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");
  6086. I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_READ_OC_PARAMS);
  6087. pcu_mbox = I915_READ(GEN6_PCODE_DATA);
  6088. if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,
  6089. 500))
  6090. DRM_ERROR("timeout waiting for pcode mailbox to finish\n");
  6091. if (pcu_mbox & (1<<31)) { /* OC supported */
  6092. max_freq = pcu_mbox & 0xff;
  6093. DRM_DEBUG_DRIVER("overclocking supported, adjusting frequency max to %dMHz\n", pcu_mbox * 50);
  6094. }
  6095. /* In units of 100MHz */
  6096. dev_priv->max_delay = max_freq;
  6097. dev_priv->min_delay = min_freq;
  6098. dev_priv->cur_delay = cur_freq;
  6099. /* requires MSI enabled */
  6100. I915_WRITE(GEN6_PMIER,
  6101. GEN6_PM_MBOX_EVENT |
  6102. GEN6_PM_THERMAL_EVENT |
  6103. GEN6_PM_RP_DOWN_TIMEOUT |
  6104. GEN6_PM_RP_UP_THRESHOLD |
  6105. GEN6_PM_RP_DOWN_THRESHOLD |
  6106. GEN6_PM_RP_UP_EI_EXPIRED |
  6107. GEN6_PM_RP_DOWN_EI_EXPIRED);
  6108. spin_lock_irq(&dev_priv->rps_lock);
  6109. WARN_ON(dev_priv->pm_iir != 0);
  6110. I915_WRITE(GEN6_PMIMR, 0);
  6111. spin_unlock_irq(&dev_priv->rps_lock);
  6112. /* enable all PM interrupts */
  6113. I915_WRITE(GEN6_PMINTRMSK, 0);
  6114. gen6_gt_force_wake_put(dev_priv);
  6115. mutex_unlock(&dev_priv->dev->struct_mutex);
  6116. }
  6117. static void ironlake_init_clock_gating(struct drm_device *dev)
  6118. {
  6119. struct drm_i915_private *dev_priv = dev->dev_private;
  6120. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  6121. /* Required for FBC */
  6122. dspclk_gate |= DPFCUNIT_CLOCK_GATE_DISABLE |
  6123. DPFCRUNIT_CLOCK_GATE_DISABLE |
  6124. DPFDUNIT_CLOCK_GATE_DISABLE;
  6125. /* Required for CxSR */
  6126. dspclk_gate |= DPARBUNIT_CLOCK_GATE_DISABLE;
  6127. I915_WRITE(PCH_3DCGDIS0,
  6128. MARIUNIT_CLOCK_GATE_DISABLE |
  6129. SVSMUNIT_CLOCK_GATE_DISABLE);
  6130. I915_WRITE(PCH_3DCGDIS1,
  6131. VFMUNIT_CLOCK_GATE_DISABLE);
  6132. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  6133. /*
  6134. * According to the spec the following bits should be set in
  6135. * order to enable memory self-refresh
  6136. * The bit 22/21 of 0x42004
  6137. * The bit 5 of 0x42020
  6138. * The bit 15 of 0x45000
  6139. */
  6140. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6141. (I915_READ(ILK_DISPLAY_CHICKEN2) |
  6142. ILK_DPARB_GATE | ILK_VSDPFD_FULL));
  6143. I915_WRITE(ILK_DSPCLK_GATE,
  6144. (I915_READ(ILK_DSPCLK_GATE) |
  6145. ILK_DPARB_CLK_GATE));
  6146. I915_WRITE(DISP_ARB_CTL,
  6147. (I915_READ(DISP_ARB_CTL) |
  6148. DISP_FBC_WM_DIS));
  6149. I915_WRITE(WM3_LP_ILK, 0);
  6150. I915_WRITE(WM2_LP_ILK, 0);
  6151. I915_WRITE(WM1_LP_ILK, 0);
  6152. /*
  6153. * Based on the document from hardware guys the following bits
  6154. * should be set unconditionally in order to enable FBC.
  6155. * The bit 22 of 0x42000
  6156. * The bit 22 of 0x42004
  6157. * The bit 7,8,9 of 0x42020.
  6158. */
  6159. if (IS_IRONLAKE_M(dev)) {
  6160. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  6161. I915_READ(ILK_DISPLAY_CHICKEN1) |
  6162. ILK_FBCQ_DIS);
  6163. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6164. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6165. ILK_DPARB_GATE);
  6166. I915_WRITE(ILK_DSPCLK_GATE,
  6167. I915_READ(ILK_DSPCLK_GATE) |
  6168. ILK_DPFC_DIS1 |
  6169. ILK_DPFC_DIS2 |
  6170. ILK_CLK_FBC);
  6171. }
  6172. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6173. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6174. ILK_ELPIN_409_SELECT);
  6175. I915_WRITE(_3D_CHICKEN2,
  6176. _3D_CHICKEN2_WM_READ_PIPELINED << 16 |
  6177. _3D_CHICKEN2_WM_READ_PIPELINED);
  6178. }
  6179. static void gen6_init_clock_gating(struct drm_device *dev)
  6180. {
  6181. struct drm_i915_private *dev_priv = dev->dev_private;
  6182. int pipe;
  6183. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  6184. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  6185. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6186. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6187. ILK_ELPIN_409_SELECT);
  6188. I915_WRITE(WM3_LP_ILK, 0);
  6189. I915_WRITE(WM2_LP_ILK, 0);
  6190. I915_WRITE(WM1_LP_ILK, 0);
  6191. /*
  6192. * According to the spec the following bits should be
  6193. * set in order to enable memory self-refresh and fbc:
  6194. * The bit21 and bit22 of 0x42000
  6195. * The bit21 and bit22 of 0x42004
  6196. * The bit5 and bit7 of 0x42020
  6197. * The bit14 of 0x70180
  6198. * The bit14 of 0x71180
  6199. */
  6200. I915_WRITE(ILK_DISPLAY_CHICKEN1,
  6201. I915_READ(ILK_DISPLAY_CHICKEN1) |
  6202. ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
  6203. I915_WRITE(ILK_DISPLAY_CHICKEN2,
  6204. I915_READ(ILK_DISPLAY_CHICKEN2) |
  6205. ILK_DPARB_GATE | ILK_VSDPFD_FULL);
  6206. I915_WRITE(ILK_DSPCLK_GATE,
  6207. I915_READ(ILK_DSPCLK_GATE) |
  6208. ILK_DPARB_CLK_GATE |
  6209. ILK_DPFD_CLK_GATE);
  6210. for_each_pipe(pipe)
  6211. I915_WRITE(DSPCNTR(pipe),
  6212. I915_READ(DSPCNTR(pipe)) |
  6213. DISPPLANE_TRICKLE_FEED_DISABLE);
  6214. }
  6215. static void ivybridge_init_clock_gating(struct drm_device *dev)
  6216. {
  6217. struct drm_i915_private *dev_priv = dev->dev_private;
  6218. int pipe;
  6219. uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE;
  6220. I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate);
  6221. I915_WRITE(WM3_LP_ILK, 0);
  6222. I915_WRITE(WM2_LP_ILK, 0);
  6223. I915_WRITE(WM1_LP_ILK, 0);
  6224. I915_WRITE(ILK_DSPCLK_GATE, IVB_VRHUNIT_CLK_GATE);
  6225. for_each_pipe(pipe)
  6226. I915_WRITE(DSPCNTR(pipe),
  6227. I915_READ(DSPCNTR(pipe)) |
  6228. DISPPLANE_TRICKLE_FEED_DISABLE);
  6229. }
  6230. static void g4x_init_clock_gating(struct drm_device *dev)
  6231. {
  6232. struct drm_i915_private *dev_priv = dev->dev_private;
  6233. uint32_t dspclk_gate;
  6234. I915_WRITE(RENCLK_GATE_D1, 0);
  6235. I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
  6236. GS_UNIT_CLOCK_GATE_DISABLE |
  6237. CL_UNIT_CLOCK_GATE_DISABLE);
  6238. I915_WRITE(RAMCLK_GATE_D, 0);
  6239. dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
  6240. OVRUNIT_CLOCK_GATE_DISABLE |
  6241. OVCUNIT_CLOCK_GATE_DISABLE;
  6242. if (IS_GM45(dev))
  6243. dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
  6244. I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
  6245. }
  6246. static void crestline_init_clock_gating(struct drm_device *dev)
  6247. {
  6248. struct drm_i915_private *dev_priv = dev->dev_private;
  6249. I915_WRITE(RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
  6250. I915_WRITE(RENCLK_GATE_D2, 0);
  6251. I915_WRITE(DSPCLK_GATE_D, 0);
  6252. I915_WRITE(RAMCLK_GATE_D, 0);
  6253. I915_WRITE16(DEUC, 0);
  6254. }
  6255. static void broadwater_init_clock_gating(struct drm_device *dev)
  6256. {
  6257. struct drm_i915_private *dev_priv = dev->dev_private;
  6258. I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
  6259. I965_RCC_CLOCK_GATE_DISABLE |
  6260. I965_RCPB_CLOCK_GATE_DISABLE |
  6261. I965_ISC_CLOCK_GATE_DISABLE |
  6262. I965_FBC_CLOCK_GATE_DISABLE);
  6263. I915_WRITE(RENCLK_GATE_D2, 0);
  6264. }
  6265. static void gen3_init_clock_gating(struct drm_device *dev)
  6266. {
  6267. struct drm_i915_private *dev_priv = dev->dev_private;
  6268. u32 dstate = I915_READ(D_STATE);
  6269. dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
  6270. DSTATE_DOT_CLOCK_GATING;
  6271. I915_WRITE(D_STATE, dstate);
  6272. }
  6273. static void i85x_init_clock_gating(struct drm_device *dev)
  6274. {
  6275. struct drm_i915_private *dev_priv = dev->dev_private;
  6276. I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
  6277. }
  6278. static void i830_init_clock_gating(struct drm_device *dev)
  6279. {
  6280. struct drm_i915_private *dev_priv = dev->dev_private;
  6281. I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);
  6282. }
  6283. static void ibx_init_clock_gating(struct drm_device *dev)
  6284. {
  6285. struct drm_i915_private *dev_priv = dev->dev_private;
  6286. /*
  6287. * On Ibex Peak and Cougar Point, we need to disable clock
  6288. * gating for the panel power sequencer or it will fail to
  6289. * start up when no ports are active.
  6290. */
  6291. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
  6292. }
  6293. static void cpt_init_clock_gating(struct drm_device *dev)
  6294. {
  6295. struct drm_i915_private *dev_priv = dev->dev_private;
  6296. /*
  6297. * On Ibex Peak and Cougar Point, we need to disable clock
  6298. * gating for the panel power sequencer or it will fail to
  6299. * start up when no ports are active.
  6300. */
  6301. I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
  6302. I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) |
  6303. DPLS_EDP_PPS_FIX_DIS);
  6304. }
  6305. static void ironlake_teardown_rc6(struct drm_device *dev)
  6306. {
  6307. struct drm_i915_private *dev_priv = dev->dev_private;
  6308. if (dev_priv->renderctx) {
  6309. i915_gem_object_unpin(dev_priv->renderctx);
  6310. drm_gem_object_unreference(&dev_priv->renderctx->base);
  6311. dev_priv->renderctx = NULL;
  6312. }
  6313. if (dev_priv->pwrctx) {
  6314. i915_gem_object_unpin(dev_priv->pwrctx);
  6315. drm_gem_object_unreference(&dev_priv->pwrctx->base);
  6316. dev_priv->pwrctx = NULL;
  6317. }
  6318. }
  6319. static void ironlake_disable_rc6(struct drm_device *dev)
  6320. {
  6321. struct drm_i915_private *dev_priv = dev->dev_private;
  6322. if (I915_READ(PWRCTXA)) {
  6323. /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */
  6324. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT);
  6325. wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON),
  6326. 50);
  6327. I915_WRITE(PWRCTXA, 0);
  6328. POSTING_READ(PWRCTXA);
  6329. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  6330. POSTING_READ(RSTDBYCTL);
  6331. }
  6332. ironlake_teardown_rc6(dev);
  6333. }
  6334. static int ironlake_setup_rc6(struct drm_device *dev)
  6335. {
  6336. struct drm_i915_private *dev_priv = dev->dev_private;
  6337. if (dev_priv->renderctx == NULL)
  6338. dev_priv->renderctx = intel_alloc_context_page(dev);
  6339. if (!dev_priv->renderctx)
  6340. return -ENOMEM;
  6341. if (dev_priv->pwrctx == NULL)
  6342. dev_priv->pwrctx = intel_alloc_context_page(dev);
  6343. if (!dev_priv->pwrctx) {
  6344. ironlake_teardown_rc6(dev);
  6345. return -ENOMEM;
  6346. }
  6347. return 0;
  6348. }
  6349. void ironlake_enable_rc6(struct drm_device *dev)
  6350. {
  6351. struct drm_i915_private *dev_priv = dev->dev_private;
  6352. int ret;
  6353. /* rc6 disabled by default due to repeated reports of hanging during
  6354. * boot and resume.
  6355. */
  6356. if (!i915_enable_rc6)
  6357. return;
  6358. mutex_lock(&dev->struct_mutex);
  6359. ret = ironlake_setup_rc6(dev);
  6360. if (ret) {
  6361. mutex_unlock(&dev->struct_mutex);
  6362. return;
  6363. }
  6364. /*
  6365. * GPU can automatically power down the render unit if given a page
  6366. * to save state.
  6367. */
  6368. ret = BEGIN_LP_RING(6);
  6369. if (ret) {
  6370. ironlake_teardown_rc6(dev);
  6371. mutex_unlock(&dev->struct_mutex);
  6372. return;
  6373. }
  6374. OUT_RING(MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN);
  6375. OUT_RING(MI_SET_CONTEXT);
  6376. OUT_RING(dev_priv->renderctx->gtt_offset |
  6377. MI_MM_SPACE_GTT |
  6378. MI_SAVE_EXT_STATE_EN |
  6379. MI_RESTORE_EXT_STATE_EN |
  6380. MI_RESTORE_INHIBIT);
  6381. OUT_RING(MI_SUSPEND_FLUSH);
  6382. OUT_RING(MI_NOOP);
  6383. OUT_RING(MI_FLUSH);
  6384. ADVANCE_LP_RING();
  6385. /*
  6386. * Wait for the command parser to advance past MI_SET_CONTEXT. The HW
  6387. * does an implicit flush, combined with MI_FLUSH above, it should be
  6388. * safe to assume that renderctx is valid
  6389. */
  6390. ret = intel_wait_ring_idle(LP_RING(dev_priv));
  6391. if (ret) {
  6392. DRM_ERROR("failed to enable ironlake power power savings\n");
  6393. ironlake_teardown_rc6(dev);
  6394. mutex_unlock(&dev->struct_mutex);
  6395. return;
  6396. }
  6397. I915_WRITE(PWRCTXA, dev_priv->pwrctx->gtt_offset | PWRCTX_EN);
  6398. I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);
  6399. mutex_unlock(&dev->struct_mutex);
  6400. }
  6401. void intel_init_clock_gating(struct drm_device *dev)
  6402. {
  6403. struct drm_i915_private *dev_priv = dev->dev_private;
  6404. dev_priv->display.init_clock_gating(dev);
  6405. if (dev_priv->display.init_pch_clock_gating)
  6406. dev_priv->display.init_pch_clock_gating(dev);
  6407. }
  6408. /* Set up chip specific display functions */
  6409. static void intel_init_display(struct drm_device *dev)
  6410. {
  6411. struct drm_i915_private *dev_priv = dev->dev_private;
  6412. /* We always want a DPMS function */
  6413. if (HAS_PCH_SPLIT(dev)) {
  6414. dev_priv->display.dpms = ironlake_crtc_dpms;
  6415. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  6416. } else {
  6417. dev_priv->display.dpms = i9xx_crtc_dpms;
  6418. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  6419. }
  6420. if (I915_HAS_FBC(dev)) {
  6421. if (HAS_PCH_SPLIT(dev)) {
  6422. dev_priv->display.fbc_enabled = ironlake_fbc_enabled;
  6423. dev_priv->display.enable_fbc = ironlake_enable_fbc;
  6424. dev_priv->display.disable_fbc = ironlake_disable_fbc;
  6425. } else if (IS_GM45(dev)) {
  6426. dev_priv->display.fbc_enabled = g4x_fbc_enabled;
  6427. dev_priv->display.enable_fbc = g4x_enable_fbc;
  6428. dev_priv->display.disable_fbc = g4x_disable_fbc;
  6429. } else if (IS_CRESTLINE(dev)) {
  6430. dev_priv->display.fbc_enabled = i8xx_fbc_enabled;
  6431. dev_priv->display.enable_fbc = i8xx_enable_fbc;
  6432. dev_priv->display.disable_fbc = i8xx_disable_fbc;
  6433. }
  6434. /* 855GM needs testing */
  6435. }
  6436. /* Returns the core display clock speed */
  6437. if (IS_I945G(dev) || (IS_G33(dev) && ! IS_PINEVIEW_M(dev)))
  6438. dev_priv->display.get_display_clock_speed =
  6439. i945_get_display_clock_speed;
  6440. else if (IS_I915G(dev))
  6441. dev_priv->display.get_display_clock_speed =
  6442. i915_get_display_clock_speed;
  6443. else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
  6444. dev_priv->display.get_display_clock_speed =
  6445. i9xx_misc_get_display_clock_speed;
  6446. else if (IS_I915GM(dev))
  6447. dev_priv->display.get_display_clock_speed =
  6448. i915gm_get_display_clock_speed;
  6449. else if (IS_I865G(dev))
  6450. dev_priv->display.get_display_clock_speed =
  6451. i865_get_display_clock_speed;
  6452. else if (IS_I85X(dev))
  6453. dev_priv->display.get_display_clock_speed =
  6454. i855_get_display_clock_speed;
  6455. else /* 852, 830 */
  6456. dev_priv->display.get_display_clock_speed =
  6457. i830_get_display_clock_speed;
  6458. /* For FIFO watermark updates */
  6459. if (HAS_PCH_SPLIT(dev)) {
  6460. if (HAS_PCH_IBX(dev))
  6461. dev_priv->display.init_pch_clock_gating = ibx_init_clock_gating;
  6462. else if (HAS_PCH_CPT(dev))
  6463. dev_priv->display.init_pch_clock_gating = cpt_init_clock_gating;
  6464. if (IS_GEN5(dev)) {
  6465. if (I915_READ(MLTR_ILK) & ILK_SRLT_MASK)
  6466. dev_priv->display.update_wm = ironlake_update_wm;
  6467. else {
  6468. DRM_DEBUG_KMS("Failed to get proper latency. "
  6469. "Disable CxSR\n");
  6470. dev_priv->display.update_wm = NULL;
  6471. }
  6472. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  6473. dev_priv->display.init_clock_gating = ironlake_init_clock_gating;
  6474. } else if (IS_GEN6(dev)) {
  6475. if (SNB_READ_WM0_LATENCY()) {
  6476. dev_priv->display.update_wm = sandybridge_update_wm;
  6477. } else {
  6478. DRM_DEBUG_KMS("Failed to read display plane latency. "
  6479. "Disable CxSR\n");
  6480. dev_priv->display.update_wm = NULL;
  6481. }
  6482. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  6483. dev_priv->display.init_clock_gating = gen6_init_clock_gating;
  6484. } else if (IS_IVYBRIDGE(dev)) {
  6485. /* FIXME: detect B0+ stepping and use auto training */
  6486. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  6487. if (SNB_READ_WM0_LATENCY()) {
  6488. dev_priv->display.update_wm = sandybridge_update_wm;
  6489. } else {
  6490. DRM_DEBUG_KMS("Failed to read display plane latency. "
  6491. "Disable CxSR\n");
  6492. dev_priv->display.update_wm = NULL;
  6493. }
  6494. dev_priv->display.init_clock_gating = ivybridge_init_clock_gating;
  6495. } else
  6496. dev_priv->display.update_wm = NULL;
  6497. } else if (IS_PINEVIEW(dev)) {
  6498. if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev),
  6499. dev_priv->is_ddr3,
  6500. dev_priv->fsb_freq,
  6501. dev_priv->mem_freq)) {
  6502. DRM_INFO("failed to find known CxSR latency "
  6503. "(found ddr%s fsb freq %d, mem freq %d), "
  6504. "disabling CxSR\n",
  6505. (dev_priv->is_ddr3 == 1) ? "3": "2",
  6506. dev_priv->fsb_freq, dev_priv->mem_freq);
  6507. /* Disable CxSR and never update its watermark again */
  6508. pineview_disable_cxsr(dev);
  6509. dev_priv->display.update_wm = NULL;
  6510. } else
  6511. dev_priv->display.update_wm = pineview_update_wm;
  6512. dev_priv->display.init_clock_gating = gen3_init_clock_gating;
  6513. } else if (IS_G4X(dev)) {
  6514. dev_priv->display.update_wm = g4x_update_wm;
  6515. dev_priv->display.init_clock_gating = g4x_init_clock_gating;
  6516. } else if (IS_GEN4(dev)) {
  6517. dev_priv->display.update_wm = i965_update_wm;
  6518. if (IS_CRESTLINE(dev))
  6519. dev_priv->display.init_clock_gating = crestline_init_clock_gating;
  6520. else if (IS_BROADWATER(dev))
  6521. dev_priv->display.init_clock_gating = broadwater_init_clock_gating;
  6522. } else if (IS_GEN3(dev)) {
  6523. dev_priv->display.update_wm = i9xx_update_wm;
  6524. dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
  6525. dev_priv->display.init_clock_gating = gen3_init_clock_gating;
  6526. } else if (IS_I865G(dev)) {
  6527. dev_priv->display.update_wm = i830_update_wm;
  6528. dev_priv->display.init_clock_gating = i85x_init_clock_gating;
  6529. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  6530. } else if (IS_I85X(dev)) {
  6531. dev_priv->display.update_wm = i9xx_update_wm;
  6532. dev_priv->display.get_fifo_size = i85x_get_fifo_size;
  6533. dev_priv->display.init_clock_gating = i85x_init_clock_gating;
  6534. } else {
  6535. dev_priv->display.update_wm = i830_update_wm;
  6536. dev_priv->display.init_clock_gating = i830_init_clock_gating;
  6537. if (IS_845G(dev))
  6538. dev_priv->display.get_fifo_size = i845_get_fifo_size;
  6539. else
  6540. dev_priv->display.get_fifo_size = i830_get_fifo_size;
  6541. }
  6542. }
  6543. /*
  6544. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  6545. * resume, or other times. This quirk makes sure that's the case for
  6546. * affected systems.
  6547. */
  6548. static void quirk_pipea_force (struct drm_device *dev)
  6549. {
  6550. struct drm_i915_private *dev_priv = dev->dev_private;
  6551. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  6552. DRM_DEBUG_DRIVER("applying pipe a force quirk\n");
  6553. }
  6554. struct intel_quirk {
  6555. int device;
  6556. int subsystem_vendor;
  6557. int subsystem_device;
  6558. void (*hook)(struct drm_device *dev);
  6559. };
  6560. struct intel_quirk intel_quirks[] = {
  6561. /* HP Compaq 2730p needs pipe A force quirk (LP: #291555) */
  6562. { 0x2a42, 0x103c, 0x30eb, quirk_pipea_force },
  6563. /* HP Mini needs pipe A force quirk (LP: #322104) */
  6564. { 0x27ae,0x103c, 0x361a, quirk_pipea_force },
  6565. /* Thinkpad R31 needs pipe A force quirk */
  6566. { 0x3577, 0x1014, 0x0505, quirk_pipea_force },
  6567. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  6568. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  6569. /* ThinkPad X30 needs pipe A force quirk (LP: #304614) */
  6570. { 0x3577, 0x1014, 0x0513, quirk_pipea_force },
  6571. /* ThinkPad X40 needs pipe A force quirk */
  6572. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  6573. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  6574. /* 855 & before need to leave pipe A & dpll A up */
  6575. { 0x3582, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  6576. { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  6577. };
  6578. static void intel_init_quirks(struct drm_device *dev)
  6579. {
  6580. struct pci_dev *d = dev->pdev;
  6581. int i;
  6582. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  6583. struct intel_quirk *q = &intel_quirks[i];
  6584. if (d->device == q->device &&
  6585. (d->subsystem_vendor == q->subsystem_vendor ||
  6586. q->subsystem_vendor == PCI_ANY_ID) &&
  6587. (d->subsystem_device == q->subsystem_device ||
  6588. q->subsystem_device == PCI_ANY_ID))
  6589. q->hook(dev);
  6590. }
  6591. }
  6592. /* Disable the VGA plane that we never use */
  6593. static void i915_disable_vga(struct drm_device *dev)
  6594. {
  6595. struct drm_i915_private *dev_priv = dev->dev_private;
  6596. u8 sr1;
  6597. u32 vga_reg;
  6598. if (HAS_PCH_SPLIT(dev))
  6599. vga_reg = CPU_VGACNTRL;
  6600. else
  6601. vga_reg = VGACNTRL;
  6602. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  6603. outb(1, VGA_SR_INDEX);
  6604. sr1 = inb(VGA_SR_DATA);
  6605. outb(sr1 | 1<<5, VGA_SR_DATA);
  6606. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  6607. udelay(300);
  6608. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  6609. POSTING_READ(vga_reg);
  6610. }
  6611. void intel_modeset_init(struct drm_device *dev)
  6612. {
  6613. struct drm_i915_private *dev_priv = dev->dev_private;
  6614. int i;
  6615. drm_mode_config_init(dev);
  6616. dev->mode_config.min_width = 0;
  6617. dev->mode_config.min_height = 0;
  6618. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  6619. intel_init_quirks(dev);
  6620. intel_init_display(dev);
  6621. if (IS_GEN2(dev)) {
  6622. dev->mode_config.max_width = 2048;
  6623. dev->mode_config.max_height = 2048;
  6624. } else if (IS_GEN3(dev)) {
  6625. dev->mode_config.max_width = 4096;
  6626. dev->mode_config.max_height = 4096;
  6627. } else {
  6628. dev->mode_config.max_width = 8192;
  6629. dev->mode_config.max_height = 8192;
  6630. }
  6631. dev->mode_config.fb_base = dev->agp->base;
  6632. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  6633. dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
  6634. for (i = 0; i < dev_priv->num_pipe; i++) {
  6635. intel_crtc_init(dev, i);
  6636. }
  6637. /* Just disable it once at startup */
  6638. i915_disable_vga(dev);
  6639. intel_setup_outputs(dev);
  6640. intel_init_clock_gating(dev);
  6641. if (IS_IRONLAKE_M(dev)) {
  6642. ironlake_enable_drps(dev);
  6643. intel_init_emon(dev);
  6644. }
  6645. if (IS_GEN6(dev))
  6646. gen6_enable_rps(dev_priv);
  6647. INIT_WORK(&dev_priv->idle_work, intel_idle_update);
  6648. setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer,
  6649. (unsigned long)dev);
  6650. }
  6651. void intel_modeset_gem_init(struct drm_device *dev)
  6652. {
  6653. if (IS_IRONLAKE_M(dev))
  6654. ironlake_enable_rc6(dev);
  6655. intel_setup_overlay(dev);
  6656. }
  6657. void intel_modeset_cleanup(struct drm_device *dev)
  6658. {
  6659. struct drm_i915_private *dev_priv = dev->dev_private;
  6660. struct drm_crtc *crtc;
  6661. struct intel_crtc *intel_crtc;
  6662. drm_kms_helper_poll_fini(dev);
  6663. mutex_lock(&dev->struct_mutex);
  6664. intel_unregister_dsm_handler();
  6665. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  6666. /* Skip inactive CRTCs */
  6667. if (!crtc->fb)
  6668. continue;
  6669. intel_crtc = to_intel_crtc(crtc);
  6670. intel_increase_pllclock(crtc);
  6671. }
  6672. if (dev_priv->display.disable_fbc)
  6673. dev_priv->display.disable_fbc(dev);
  6674. if (IS_IRONLAKE_M(dev))
  6675. ironlake_disable_drps(dev);
  6676. if (IS_GEN6(dev))
  6677. gen6_disable_rps(dev);
  6678. if (IS_IRONLAKE_M(dev))
  6679. ironlake_disable_rc6(dev);
  6680. mutex_unlock(&dev->struct_mutex);
  6681. /* Disable the irq before mode object teardown, for the irq might
  6682. * enqueue unpin/hotplug work. */
  6683. drm_irq_uninstall(dev);
  6684. cancel_work_sync(&dev_priv->hotplug_work);
  6685. /* Shut off idle work before the crtcs get freed. */
  6686. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  6687. intel_crtc = to_intel_crtc(crtc);
  6688. del_timer_sync(&intel_crtc->idle_timer);
  6689. }
  6690. del_timer_sync(&dev_priv->idle_timer);
  6691. cancel_work_sync(&dev_priv->idle_work);
  6692. drm_mode_config_cleanup(dev);
  6693. }
  6694. /*
  6695. * Return which encoder is currently attached for connector.
  6696. */
  6697. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  6698. {
  6699. return &intel_attached_encoder(connector)->base;
  6700. }
  6701. void intel_connector_attach_encoder(struct intel_connector *connector,
  6702. struct intel_encoder *encoder)
  6703. {
  6704. connector->encoder = encoder;
  6705. drm_mode_connector_attach_encoder(&connector->base,
  6706. &encoder->base);
  6707. }
  6708. /*
  6709. * set vga decode state - true == enable VGA decode
  6710. */
  6711. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  6712. {
  6713. struct drm_i915_private *dev_priv = dev->dev_private;
  6714. u16 gmch_ctrl;
  6715. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  6716. if (state)
  6717. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  6718. else
  6719. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  6720. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  6721. return 0;
  6722. }
  6723. #ifdef CONFIG_DEBUG_FS
  6724. #include <linux/seq_file.h>
  6725. struct intel_display_error_state {
  6726. struct intel_cursor_error_state {
  6727. u32 control;
  6728. u32 position;
  6729. u32 base;
  6730. u32 size;
  6731. } cursor[2];
  6732. struct intel_pipe_error_state {
  6733. u32 conf;
  6734. u32 source;
  6735. u32 htotal;
  6736. u32 hblank;
  6737. u32 hsync;
  6738. u32 vtotal;
  6739. u32 vblank;
  6740. u32 vsync;
  6741. } pipe[2];
  6742. struct intel_plane_error_state {
  6743. u32 control;
  6744. u32 stride;
  6745. u32 size;
  6746. u32 pos;
  6747. u32 addr;
  6748. u32 surface;
  6749. u32 tile_offset;
  6750. } plane[2];
  6751. };
  6752. struct intel_display_error_state *
  6753. intel_display_capture_error_state(struct drm_device *dev)
  6754. {
  6755. drm_i915_private_t *dev_priv = dev->dev_private;
  6756. struct intel_display_error_state *error;
  6757. int i;
  6758. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  6759. if (error == NULL)
  6760. return NULL;
  6761. for (i = 0; i < 2; i++) {
  6762. error->cursor[i].control = I915_READ(CURCNTR(i));
  6763. error->cursor[i].position = I915_READ(CURPOS(i));
  6764. error->cursor[i].base = I915_READ(CURBASE(i));
  6765. error->plane[i].control = I915_READ(DSPCNTR(i));
  6766. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  6767. error->plane[i].size = I915_READ(DSPSIZE(i));
  6768. error->plane[i].pos= I915_READ(DSPPOS(i));
  6769. error->plane[i].addr = I915_READ(DSPADDR(i));
  6770. if (INTEL_INFO(dev)->gen >= 4) {
  6771. error->plane[i].surface = I915_READ(DSPSURF(i));
  6772. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  6773. }
  6774. error->pipe[i].conf = I915_READ(PIPECONF(i));
  6775. error->pipe[i].source = I915_READ(PIPESRC(i));
  6776. error->pipe[i].htotal = I915_READ(HTOTAL(i));
  6777. error->pipe[i].hblank = I915_READ(HBLANK(i));
  6778. error->pipe[i].hsync = I915_READ(HSYNC(i));
  6779. error->pipe[i].vtotal = I915_READ(VTOTAL(i));
  6780. error->pipe[i].vblank = I915_READ(VBLANK(i));
  6781. error->pipe[i].vsync = I915_READ(VSYNC(i));
  6782. }
  6783. return error;
  6784. }
  6785. void
  6786. intel_display_print_error_state(struct seq_file *m,
  6787. struct drm_device *dev,
  6788. struct intel_display_error_state *error)
  6789. {
  6790. int i;
  6791. for (i = 0; i < 2; i++) {
  6792. seq_printf(m, "Pipe [%d]:\n", i);
  6793. seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
  6794. seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
  6795. seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
  6796. seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
  6797. seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
  6798. seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
  6799. seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
  6800. seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
  6801. seq_printf(m, "Plane [%d]:\n", i);
  6802. seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
  6803. seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  6804. seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
  6805. seq_printf(m, " POS: %08x\n", error->plane[i].pos);
  6806. seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  6807. if (INTEL_INFO(dev)->gen >= 4) {
  6808. seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
  6809. seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  6810. }
  6811. seq_printf(m, "Cursor [%d]:\n", i);
  6812. seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  6813. seq_printf(m, " POS: %08x\n", error->cursor[i].position);
  6814. seq_printf(m, " BASE: %08x\n", error->cursor[i].base);
  6815. }
  6816. }
  6817. #endif