intel_display.c 227 KB

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