intel_display.c 243 KB

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