intel_display.c 321 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724
  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/dmi.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 <drm/drmP.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include <drm/drm_dp_helper.h>
  40. #include <drm/drm_crtc_helper.h>
  41. #include <linux/dma_remapping.h>
  42. static void intel_increase_pllclock(struct drm_crtc *crtc);
  43. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  44. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  45. struct intel_crtc_config *pipe_config);
  46. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  47. struct intel_crtc_config *pipe_config);
  48. static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
  49. int x, int y, struct drm_framebuffer *old_fb);
  50. typedef struct {
  51. int min, max;
  52. } intel_range_t;
  53. typedef struct {
  54. int dot_limit;
  55. int p2_slow, p2_fast;
  56. } intel_p2_t;
  57. typedef struct intel_limit intel_limit_t;
  58. struct intel_limit {
  59. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  60. intel_p2_t p2;
  61. };
  62. int
  63. intel_pch_rawclk(struct drm_device *dev)
  64. {
  65. struct drm_i915_private *dev_priv = dev->dev_private;
  66. WARN_ON(!HAS_PCH_SPLIT(dev));
  67. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  68. }
  69. static inline u32 /* units of 100MHz */
  70. intel_fdi_link_freq(struct drm_device *dev)
  71. {
  72. if (IS_GEN5(dev)) {
  73. struct drm_i915_private *dev_priv = dev->dev_private;
  74. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  75. } else
  76. return 27;
  77. }
  78. static const intel_limit_t intel_limits_i8xx_dac = {
  79. .dot = { .min = 25000, .max = 350000 },
  80. .vco = { .min = 908000, .max = 1512000 },
  81. .n = { .min = 2, .max = 16 },
  82. .m = { .min = 96, .max = 140 },
  83. .m1 = { .min = 18, .max = 26 },
  84. .m2 = { .min = 6, .max = 16 },
  85. .p = { .min = 4, .max = 128 },
  86. .p1 = { .min = 2, .max = 33 },
  87. .p2 = { .dot_limit = 165000,
  88. .p2_slow = 4, .p2_fast = 2 },
  89. };
  90. static const intel_limit_t intel_limits_i8xx_dvo = {
  91. .dot = { .min = 25000, .max = 350000 },
  92. .vco = { .min = 908000, .max = 1512000 },
  93. .n = { .min = 2, .max = 16 },
  94. .m = { .min = 96, .max = 140 },
  95. .m1 = { .min = 18, .max = 26 },
  96. .m2 = { .min = 6, .max = 16 },
  97. .p = { .min = 4, .max = 128 },
  98. .p1 = { .min = 2, .max = 33 },
  99. .p2 = { .dot_limit = 165000,
  100. .p2_slow = 4, .p2_fast = 4 },
  101. };
  102. static const intel_limit_t intel_limits_i8xx_lvds = {
  103. .dot = { .min = 25000, .max = 350000 },
  104. .vco = { .min = 908000, .max = 1512000 },
  105. .n = { .min = 2, .max = 16 },
  106. .m = { .min = 96, .max = 140 },
  107. .m1 = { .min = 18, .max = 26 },
  108. .m2 = { .min = 6, .max = 16 },
  109. .p = { .min = 4, .max = 128 },
  110. .p1 = { .min = 1, .max = 6 },
  111. .p2 = { .dot_limit = 165000,
  112. .p2_slow = 14, .p2_fast = 7 },
  113. };
  114. static const intel_limit_t intel_limits_i9xx_sdvo = {
  115. .dot = { .min = 20000, .max = 400000 },
  116. .vco = { .min = 1400000, .max = 2800000 },
  117. .n = { .min = 1, .max = 6 },
  118. .m = { .min = 70, .max = 120 },
  119. .m1 = { .min = 8, .max = 18 },
  120. .m2 = { .min = 3, .max = 7 },
  121. .p = { .min = 5, .max = 80 },
  122. .p1 = { .min = 1, .max = 8 },
  123. .p2 = { .dot_limit = 200000,
  124. .p2_slow = 10, .p2_fast = 5 },
  125. };
  126. static const intel_limit_t intel_limits_i9xx_lvds = {
  127. .dot = { .min = 20000, .max = 400000 },
  128. .vco = { .min = 1400000, .max = 2800000 },
  129. .n = { .min = 1, .max = 6 },
  130. .m = { .min = 70, .max = 120 },
  131. .m1 = { .min = 8, .max = 18 },
  132. .m2 = { .min = 3, .max = 7 },
  133. .p = { .min = 7, .max = 98 },
  134. .p1 = { .min = 1, .max = 8 },
  135. .p2 = { .dot_limit = 112000,
  136. .p2_slow = 14, .p2_fast = 7 },
  137. };
  138. static const intel_limit_t intel_limits_g4x_sdvo = {
  139. .dot = { .min = 25000, .max = 270000 },
  140. .vco = { .min = 1750000, .max = 3500000},
  141. .n = { .min = 1, .max = 4 },
  142. .m = { .min = 104, .max = 138 },
  143. .m1 = { .min = 17, .max = 23 },
  144. .m2 = { .min = 5, .max = 11 },
  145. .p = { .min = 10, .max = 30 },
  146. .p1 = { .min = 1, .max = 3},
  147. .p2 = { .dot_limit = 270000,
  148. .p2_slow = 10,
  149. .p2_fast = 10
  150. },
  151. };
  152. static const intel_limit_t intel_limits_g4x_hdmi = {
  153. .dot = { .min = 22000, .max = 400000 },
  154. .vco = { .min = 1750000, .max = 3500000},
  155. .n = { .min = 1, .max = 4 },
  156. .m = { .min = 104, .max = 138 },
  157. .m1 = { .min = 16, .max = 23 },
  158. .m2 = { .min = 5, .max = 11 },
  159. .p = { .min = 5, .max = 80 },
  160. .p1 = { .min = 1, .max = 8},
  161. .p2 = { .dot_limit = 165000,
  162. .p2_slow = 10, .p2_fast = 5 },
  163. };
  164. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  165. .dot = { .min = 20000, .max = 115000 },
  166. .vco = { .min = 1750000, .max = 3500000 },
  167. .n = { .min = 1, .max = 3 },
  168. .m = { .min = 104, .max = 138 },
  169. .m1 = { .min = 17, .max = 23 },
  170. .m2 = { .min = 5, .max = 11 },
  171. .p = { .min = 28, .max = 112 },
  172. .p1 = { .min = 2, .max = 8 },
  173. .p2 = { .dot_limit = 0,
  174. .p2_slow = 14, .p2_fast = 14
  175. },
  176. };
  177. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  178. .dot = { .min = 80000, .max = 224000 },
  179. .vco = { .min = 1750000, .max = 3500000 },
  180. .n = { .min = 1, .max = 3 },
  181. .m = { .min = 104, .max = 138 },
  182. .m1 = { .min = 17, .max = 23 },
  183. .m2 = { .min = 5, .max = 11 },
  184. .p = { .min = 14, .max = 42 },
  185. .p1 = { .min = 2, .max = 6 },
  186. .p2 = { .dot_limit = 0,
  187. .p2_slow = 7, .p2_fast = 7
  188. },
  189. };
  190. static const intel_limit_t intel_limits_pineview_sdvo = {
  191. .dot = { .min = 20000, .max = 400000},
  192. .vco = { .min = 1700000, .max = 3500000 },
  193. /* Pineview's Ncounter is a ring counter */
  194. .n = { .min = 3, .max = 6 },
  195. .m = { .min = 2, .max = 256 },
  196. /* Pineview only has one combined m divider, which we treat as m2. */
  197. .m1 = { .min = 0, .max = 0 },
  198. .m2 = { .min = 0, .max = 254 },
  199. .p = { .min = 5, .max = 80 },
  200. .p1 = { .min = 1, .max = 8 },
  201. .p2 = { .dot_limit = 200000,
  202. .p2_slow = 10, .p2_fast = 5 },
  203. };
  204. static const intel_limit_t intel_limits_pineview_lvds = {
  205. .dot = { .min = 20000, .max = 400000 },
  206. .vco = { .min = 1700000, .max = 3500000 },
  207. .n = { .min = 3, .max = 6 },
  208. .m = { .min = 2, .max = 256 },
  209. .m1 = { .min = 0, .max = 0 },
  210. .m2 = { .min = 0, .max = 254 },
  211. .p = { .min = 7, .max = 112 },
  212. .p1 = { .min = 1, .max = 8 },
  213. .p2 = { .dot_limit = 112000,
  214. .p2_slow = 14, .p2_fast = 14 },
  215. };
  216. /* Ironlake / Sandybridge
  217. *
  218. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  219. * the range value for them is (actual_value - 2).
  220. */
  221. static const intel_limit_t intel_limits_ironlake_dac = {
  222. .dot = { .min = 25000, .max = 350000 },
  223. .vco = { .min = 1760000, .max = 3510000 },
  224. .n = { .min = 1, .max = 5 },
  225. .m = { .min = 79, .max = 127 },
  226. .m1 = { .min = 12, .max = 22 },
  227. .m2 = { .min = 5, .max = 9 },
  228. .p = { .min = 5, .max = 80 },
  229. .p1 = { .min = 1, .max = 8 },
  230. .p2 = { .dot_limit = 225000,
  231. .p2_slow = 10, .p2_fast = 5 },
  232. };
  233. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  234. .dot = { .min = 25000, .max = 350000 },
  235. .vco = { .min = 1760000, .max = 3510000 },
  236. .n = { .min = 1, .max = 3 },
  237. .m = { .min = 79, .max = 118 },
  238. .m1 = { .min = 12, .max = 22 },
  239. .m2 = { .min = 5, .max = 9 },
  240. .p = { .min = 28, .max = 112 },
  241. .p1 = { .min = 2, .max = 8 },
  242. .p2 = { .dot_limit = 225000,
  243. .p2_slow = 14, .p2_fast = 14 },
  244. };
  245. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  246. .dot = { .min = 25000, .max = 350000 },
  247. .vco = { .min = 1760000, .max = 3510000 },
  248. .n = { .min = 1, .max = 3 },
  249. .m = { .min = 79, .max = 127 },
  250. .m1 = { .min = 12, .max = 22 },
  251. .m2 = { .min = 5, .max = 9 },
  252. .p = { .min = 14, .max = 56 },
  253. .p1 = { .min = 2, .max = 8 },
  254. .p2 = { .dot_limit = 225000,
  255. .p2_slow = 7, .p2_fast = 7 },
  256. };
  257. /* LVDS 100mhz refclk limits. */
  258. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  259. .dot = { .min = 25000, .max = 350000 },
  260. .vco = { .min = 1760000, .max = 3510000 },
  261. .n = { .min = 1, .max = 2 },
  262. .m = { .min = 79, .max = 126 },
  263. .m1 = { .min = 12, .max = 22 },
  264. .m2 = { .min = 5, .max = 9 },
  265. .p = { .min = 28, .max = 112 },
  266. .p1 = { .min = 2, .max = 8 },
  267. .p2 = { .dot_limit = 225000,
  268. .p2_slow = 14, .p2_fast = 14 },
  269. };
  270. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  271. .dot = { .min = 25000, .max = 350000 },
  272. .vco = { .min = 1760000, .max = 3510000 },
  273. .n = { .min = 1, .max = 3 },
  274. .m = { .min = 79, .max = 126 },
  275. .m1 = { .min = 12, .max = 22 },
  276. .m2 = { .min = 5, .max = 9 },
  277. .p = { .min = 14, .max = 42 },
  278. .p1 = { .min = 2, .max = 6 },
  279. .p2 = { .dot_limit = 225000,
  280. .p2_slow = 7, .p2_fast = 7 },
  281. };
  282. static const intel_limit_t intel_limits_vlv = {
  283. /*
  284. * These are the data rate limits (measured in fast clocks)
  285. * since those are the strictest limits we have. The fast
  286. * clock and actual rate limits are more relaxed, so checking
  287. * them would make no difference.
  288. */
  289. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  290. .vco = { .min = 4000000, .max = 6000000 },
  291. .n = { .min = 1, .max = 7 },
  292. .m1 = { .min = 2, .max = 3 },
  293. .m2 = { .min = 11, .max = 156 },
  294. .p1 = { .min = 2, .max = 3 },
  295. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  296. };
  297. static void vlv_clock(int refclk, intel_clock_t *clock)
  298. {
  299. clock->m = clock->m1 * clock->m2;
  300. clock->p = clock->p1 * clock->p2;
  301. if (WARN_ON(clock->n == 0 || clock->p == 0))
  302. return;
  303. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  304. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  305. }
  306. /**
  307. * Returns whether any output on the specified pipe is of the specified type
  308. */
  309. static bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  310. {
  311. struct drm_device *dev = crtc->dev;
  312. struct intel_encoder *encoder;
  313. for_each_encoder_on_crtc(dev, crtc, encoder)
  314. if (encoder->type == type)
  315. return true;
  316. return false;
  317. }
  318. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  319. int refclk)
  320. {
  321. struct drm_device *dev = crtc->dev;
  322. const intel_limit_t *limit;
  323. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  324. if (intel_is_dual_link_lvds(dev)) {
  325. if (refclk == 100000)
  326. limit = &intel_limits_ironlake_dual_lvds_100m;
  327. else
  328. limit = &intel_limits_ironlake_dual_lvds;
  329. } else {
  330. if (refclk == 100000)
  331. limit = &intel_limits_ironlake_single_lvds_100m;
  332. else
  333. limit = &intel_limits_ironlake_single_lvds;
  334. }
  335. } else
  336. limit = &intel_limits_ironlake_dac;
  337. return limit;
  338. }
  339. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  340. {
  341. struct drm_device *dev = crtc->dev;
  342. const intel_limit_t *limit;
  343. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  344. if (intel_is_dual_link_lvds(dev))
  345. limit = &intel_limits_g4x_dual_channel_lvds;
  346. else
  347. limit = &intel_limits_g4x_single_channel_lvds;
  348. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  349. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  350. limit = &intel_limits_g4x_hdmi;
  351. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  352. limit = &intel_limits_g4x_sdvo;
  353. } else /* The option is for other outputs */
  354. limit = &intel_limits_i9xx_sdvo;
  355. return limit;
  356. }
  357. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  358. {
  359. struct drm_device *dev = crtc->dev;
  360. const intel_limit_t *limit;
  361. if (HAS_PCH_SPLIT(dev))
  362. limit = intel_ironlake_limit(crtc, refclk);
  363. else if (IS_G4X(dev)) {
  364. limit = intel_g4x_limit(crtc);
  365. } else if (IS_PINEVIEW(dev)) {
  366. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  367. limit = &intel_limits_pineview_lvds;
  368. else
  369. limit = &intel_limits_pineview_sdvo;
  370. } else if (IS_VALLEYVIEW(dev)) {
  371. limit = &intel_limits_vlv;
  372. } else if (!IS_GEN2(dev)) {
  373. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  374. limit = &intel_limits_i9xx_lvds;
  375. else
  376. limit = &intel_limits_i9xx_sdvo;
  377. } else {
  378. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  379. limit = &intel_limits_i8xx_lvds;
  380. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  381. limit = &intel_limits_i8xx_dvo;
  382. else
  383. limit = &intel_limits_i8xx_dac;
  384. }
  385. return limit;
  386. }
  387. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  388. static void pineview_clock(int refclk, intel_clock_t *clock)
  389. {
  390. clock->m = clock->m2 + 2;
  391. clock->p = clock->p1 * clock->p2;
  392. if (WARN_ON(clock->n == 0 || clock->p == 0))
  393. return;
  394. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  395. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  396. }
  397. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  398. {
  399. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  400. }
  401. static void i9xx_clock(int refclk, intel_clock_t *clock)
  402. {
  403. clock->m = i9xx_dpll_compute_m(clock);
  404. clock->p = clock->p1 * clock->p2;
  405. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  406. return;
  407. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  408. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  409. }
  410. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  411. /**
  412. * Returns whether the given set of divisors are valid for a given refclk with
  413. * the given connectors.
  414. */
  415. static bool intel_PLL_is_valid(struct drm_device *dev,
  416. const intel_limit_t *limit,
  417. const intel_clock_t *clock)
  418. {
  419. if (clock->n < limit->n.min || limit->n.max < clock->n)
  420. INTELPllInvalid("n out of range\n");
  421. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  422. INTELPllInvalid("p1 out of range\n");
  423. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  424. INTELPllInvalid("m2 out of range\n");
  425. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  426. INTELPllInvalid("m1 out of range\n");
  427. if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev))
  428. if (clock->m1 <= clock->m2)
  429. INTELPllInvalid("m1 <= m2\n");
  430. if (!IS_VALLEYVIEW(dev)) {
  431. if (clock->p < limit->p.min || limit->p.max < clock->p)
  432. INTELPllInvalid("p out of range\n");
  433. if (clock->m < limit->m.min || limit->m.max < clock->m)
  434. INTELPllInvalid("m out of range\n");
  435. }
  436. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  437. INTELPllInvalid("vco out of range\n");
  438. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  439. * connector, etc., rather than just a single range.
  440. */
  441. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  442. INTELPllInvalid("dot out of range\n");
  443. return true;
  444. }
  445. static bool
  446. i9xx_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  447. int target, int refclk, intel_clock_t *match_clock,
  448. intel_clock_t *best_clock)
  449. {
  450. struct drm_device *dev = crtc->dev;
  451. intel_clock_t clock;
  452. int err = target;
  453. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  454. /*
  455. * For LVDS just rely on its current settings for dual-channel.
  456. * We haven't figured out how to reliably set up different
  457. * single/dual channel state, if we even can.
  458. */
  459. if (intel_is_dual_link_lvds(dev))
  460. clock.p2 = limit->p2.p2_fast;
  461. else
  462. clock.p2 = limit->p2.p2_slow;
  463. } else {
  464. if (target < limit->p2.dot_limit)
  465. clock.p2 = limit->p2.p2_slow;
  466. else
  467. clock.p2 = limit->p2.p2_fast;
  468. }
  469. memset(best_clock, 0, sizeof(*best_clock));
  470. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  471. clock.m1++) {
  472. for (clock.m2 = limit->m2.min;
  473. clock.m2 <= limit->m2.max; clock.m2++) {
  474. if (clock.m2 >= clock.m1)
  475. break;
  476. for (clock.n = limit->n.min;
  477. clock.n <= limit->n.max; clock.n++) {
  478. for (clock.p1 = limit->p1.min;
  479. clock.p1 <= limit->p1.max; clock.p1++) {
  480. int this_err;
  481. i9xx_clock(refclk, &clock);
  482. if (!intel_PLL_is_valid(dev, limit,
  483. &clock))
  484. continue;
  485. if (match_clock &&
  486. clock.p != match_clock->p)
  487. continue;
  488. this_err = abs(clock.dot - target);
  489. if (this_err < err) {
  490. *best_clock = clock;
  491. err = this_err;
  492. }
  493. }
  494. }
  495. }
  496. }
  497. return (err != target);
  498. }
  499. static bool
  500. pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  501. int target, int refclk, intel_clock_t *match_clock,
  502. intel_clock_t *best_clock)
  503. {
  504. struct drm_device *dev = crtc->dev;
  505. intel_clock_t clock;
  506. int err = target;
  507. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  508. /*
  509. * For LVDS just rely on its current settings for dual-channel.
  510. * We haven't figured out how to reliably set up different
  511. * single/dual channel state, if we even can.
  512. */
  513. if (intel_is_dual_link_lvds(dev))
  514. clock.p2 = limit->p2.p2_fast;
  515. else
  516. clock.p2 = limit->p2.p2_slow;
  517. } else {
  518. if (target < limit->p2.dot_limit)
  519. clock.p2 = limit->p2.p2_slow;
  520. else
  521. clock.p2 = limit->p2.p2_fast;
  522. }
  523. memset(best_clock, 0, sizeof(*best_clock));
  524. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  525. clock.m1++) {
  526. for (clock.m2 = limit->m2.min;
  527. clock.m2 <= limit->m2.max; clock.m2++) {
  528. for (clock.n = limit->n.min;
  529. clock.n <= limit->n.max; clock.n++) {
  530. for (clock.p1 = limit->p1.min;
  531. clock.p1 <= limit->p1.max; clock.p1++) {
  532. int this_err;
  533. pineview_clock(refclk, &clock);
  534. if (!intel_PLL_is_valid(dev, limit,
  535. &clock))
  536. continue;
  537. if (match_clock &&
  538. clock.p != match_clock->p)
  539. continue;
  540. this_err = abs(clock.dot - target);
  541. if (this_err < err) {
  542. *best_clock = clock;
  543. err = this_err;
  544. }
  545. }
  546. }
  547. }
  548. }
  549. return (err != target);
  550. }
  551. static bool
  552. g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  553. int target, int refclk, intel_clock_t *match_clock,
  554. intel_clock_t *best_clock)
  555. {
  556. struct drm_device *dev = crtc->dev;
  557. intel_clock_t clock;
  558. int max_n;
  559. bool found;
  560. /* approximately equals target * 0.00585 */
  561. int err_most = (target >> 8) + (target >> 9);
  562. found = false;
  563. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  564. if (intel_is_dual_link_lvds(dev))
  565. clock.p2 = limit->p2.p2_fast;
  566. else
  567. clock.p2 = limit->p2.p2_slow;
  568. } else {
  569. if (target < limit->p2.dot_limit)
  570. clock.p2 = limit->p2.p2_slow;
  571. else
  572. clock.p2 = limit->p2.p2_fast;
  573. }
  574. memset(best_clock, 0, sizeof(*best_clock));
  575. max_n = limit->n.max;
  576. /* based on hardware requirement, prefer smaller n to precision */
  577. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  578. /* based on hardware requirement, prefere larger m1,m2 */
  579. for (clock.m1 = limit->m1.max;
  580. clock.m1 >= limit->m1.min; clock.m1--) {
  581. for (clock.m2 = limit->m2.max;
  582. clock.m2 >= limit->m2.min; clock.m2--) {
  583. for (clock.p1 = limit->p1.max;
  584. clock.p1 >= limit->p1.min; clock.p1--) {
  585. int this_err;
  586. i9xx_clock(refclk, &clock);
  587. if (!intel_PLL_is_valid(dev, limit,
  588. &clock))
  589. continue;
  590. this_err = abs(clock.dot - target);
  591. if (this_err < err_most) {
  592. *best_clock = clock;
  593. err_most = this_err;
  594. max_n = clock.n;
  595. found = true;
  596. }
  597. }
  598. }
  599. }
  600. }
  601. return found;
  602. }
  603. static bool
  604. vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  605. int target, int refclk, intel_clock_t *match_clock,
  606. intel_clock_t *best_clock)
  607. {
  608. struct drm_device *dev = crtc->dev;
  609. intel_clock_t clock;
  610. unsigned int bestppm = 1000000;
  611. /* min update 19.2 MHz */
  612. int max_n = min(limit->n.max, refclk / 19200);
  613. bool found = false;
  614. target *= 5; /* fast clock */
  615. memset(best_clock, 0, sizeof(*best_clock));
  616. /* based on hardware requirement, prefer smaller n to precision */
  617. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  618. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  619. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  620. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  621. clock.p = clock.p1 * clock.p2;
  622. /* based on hardware requirement, prefer bigger m1,m2 values */
  623. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  624. unsigned int ppm, diff;
  625. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  626. refclk * clock.m1);
  627. vlv_clock(refclk, &clock);
  628. if (!intel_PLL_is_valid(dev, limit,
  629. &clock))
  630. continue;
  631. diff = abs(clock.dot - target);
  632. ppm = div_u64(1000000ULL * diff, target);
  633. if (ppm < 100 && clock.p > best_clock->p) {
  634. bestppm = 0;
  635. *best_clock = clock;
  636. found = true;
  637. }
  638. if (bestppm >= 10 && ppm < bestppm - 10) {
  639. bestppm = ppm;
  640. *best_clock = clock;
  641. found = true;
  642. }
  643. }
  644. }
  645. }
  646. }
  647. return found;
  648. }
  649. bool intel_crtc_active(struct drm_crtc *crtc)
  650. {
  651. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  652. /* Be paranoid as we can arrive here with only partial
  653. * state retrieved from the hardware during setup.
  654. *
  655. * We can ditch the adjusted_mode.crtc_clock check as soon
  656. * as Haswell has gained clock readout/fastboot support.
  657. *
  658. * We can ditch the crtc->fb check as soon as we can
  659. * properly reconstruct framebuffers.
  660. */
  661. return intel_crtc->active && crtc->fb &&
  662. intel_crtc->config.adjusted_mode.crtc_clock;
  663. }
  664. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  665. enum pipe pipe)
  666. {
  667. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  668. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  669. return intel_crtc->config.cpu_transcoder;
  670. }
  671. static void g4x_wait_for_vblank(struct drm_device *dev, int pipe)
  672. {
  673. struct drm_i915_private *dev_priv = dev->dev_private;
  674. u32 frame, frame_reg = PIPE_FRMCOUNT_GM45(pipe);
  675. frame = I915_READ(frame_reg);
  676. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  677. DRM_DEBUG_KMS("vblank wait timed out\n");
  678. }
  679. /**
  680. * intel_wait_for_vblank - wait for vblank on a given pipe
  681. * @dev: drm device
  682. * @pipe: pipe to wait for
  683. *
  684. * Wait for vblank to occur on a given pipe. Needed for various bits of
  685. * mode setting code.
  686. */
  687. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  688. {
  689. struct drm_i915_private *dev_priv = dev->dev_private;
  690. int pipestat_reg = PIPESTAT(pipe);
  691. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  692. g4x_wait_for_vblank(dev, pipe);
  693. return;
  694. }
  695. /* Clear existing vblank status. Note this will clear any other
  696. * sticky status fields as well.
  697. *
  698. * This races with i915_driver_irq_handler() with the result
  699. * that either function could miss a vblank event. Here it is not
  700. * fatal, as we will either wait upon the next vblank interrupt or
  701. * timeout. Generally speaking intel_wait_for_vblank() is only
  702. * called during modeset at which time the GPU should be idle and
  703. * should *not* be performing page flips and thus not waiting on
  704. * vblanks...
  705. * Currently, the result of us stealing a vblank from the irq
  706. * handler is that a single frame will be skipped during swapbuffers.
  707. */
  708. I915_WRITE(pipestat_reg,
  709. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  710. /* Wait for vblank interrupt bit to set */
  711. if (wait_for(I915_READ(pipestat_reg) &
  712. PIPE_VBLANK_INTERRUPT_STATUS,
  713. 50))
  714. DRM_DEBUG_KMS("vblank wait timed out\n");
  715. }
  716. static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
  717. {
  718. struct drm_i915_private *dev_priv = dev->dev_private;
  719. u32 reg = PIPEDSL(pipe);
  720. u32 line1, line2;
  721. u32 line_mask;
  722. if (IS_GEN2(dev))
  723. line_mask = DSL_LINEMASK_GEN2;
  724. else
  725. line_mask = DSL_LINEMASK_GEN3;
  726. line1 = I915_READ(reg) & line_mask;
  727. mdelay(5);
  728. line2 = I915_READ(reg) & line_mask;
  729. return line1 == line2;
  730. }
  731. /*
  732. * intel_wait_for_pipe_off - wait for pipe to turn off
  733. * @dev: drm device
  734. * @pipe: pipe to wait for
  735. *
  736. * After disabling a pipe, we can't wait for vblank in the usual way,
  737. * spinning on the vblank interrupt status bit, since we won't actually
  738. * see an interrupt when the pipe is disabled.
  739. *
  740. * On Gen4 and above:
  741. * wait for the pipe register state bit to turn off
  742. *
  743. * Otherwise:
  744. * wait for the display line value to settle (it usually
  745. * ends up stopping at the start of the next frame).
  746. *
  747. */
  748. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  749. {
  750. struct drm_i915_private *dev_priv = dev->dev_private;
  751. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  752. pipe);
  753. if (INTEL_INFO(dev)->gen >= 4) {
  754. int reg = PIPECONF(cpu_transcoder);
  755. /* Wait for the Pipe State to go off */
  756. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  757. 100))
  758. WARN(1, "pipe_off wait timed out\n");
  759. } else {
  760. /* Wait for the display line to settle */
  761. if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
  762. WARN(1, "pipe_off wait timed out\n");
  763. }
  764. }
  765. /*
  766. * ibx_digital_port_connected - is the specified port connected?
  767. * @dev_priv: i915 private structure
  768. * @port: the port to test
  769. *
  770. * Returns true if @port is connected, false otherwise.
  771. */
  772. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  773. struct intel_digital_port *port)
  774. {
  775. u32 bit;
  776. if (HAS_PCH_IBX(dev_priv->dev)) {
  777. switch(port->port) {
  778. case PORT_B:
  779. bit = SDE_PORTB_HOTPLUG;
  780. break;
  781. case PORT_C:
  782. bit = SDE_PORTC_HOTPLUG;
  783. break;
  784. case PORT_D:
  785. bit = SDE_PORTD_HOTPLUG;
  786. break;
  787. default:
  788. return true;
  789. }
  790. } else {
  791. switch(port->port) {
  792. case PORT_B:
  793. bit = SDE_PORTB_HOTPLUG_CPT;
  794. break;
  795. case PORT_C:
  796. bit = SDE_PORTC_HOTPLUG_CPT;
  797. break;
  798. case PORT_D:
  799. bit = SDE_PORTD_HOTPLUG_CPT;
  800. break;
  801. default:
  802. return true;
  803. }
  804. }
  805. return I915_READ(SDEISR) & bit;
  806. }
  807. static const char *state_string(bool enabled)
  808. {
  809. return enabled ? "on" : "off";
  810. }
  811. /* Only for pre-ILK configs */
  812. void assert_pll(struct drm_i915_private *dev_priv,
  813. enum pipe pipe, bool state)
  814. {
  815. int reg;
  816. u32 val;
  817. bool cur_state;
  818. reg = DPLL(pipe);
  819. val = I915_READ(reg);
  820. cur_state = !!(val & DPLL_VCO_ENABLE);
  821. WARN(cur_state != state,
  822. "PLL state assertion failure (expected %s, current %s)\n",
  823. state_string(state), state_string(cur_state));
  824. }
  825. /* XXX: the dsi pll is shared between MIPI DSI ports */
  826. static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  827. {
  828. u32 val;
  829. bool cur_state;
  830. mutex_lock(&dev_priv->dpio_lock);
  831. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  832. mutex_unlock(&dev_priv->dpio_lock);
  833. cur_state = val & DSI_PLL_VCO_EN;
  834. WARN(cur_state != state,
  835. "DSI PLL state assertion failure (expected %s, current %s)\n",
  836. state_string(state), state_string(cur_state));
  837. }
  838. #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
  839. #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
  840. struct intel_shared_dpll *
  841. intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
  842. {
  843. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  844. if (crtc->config.shared_dpll < 0)
  845. return NULL;
  846. return &dev_priv->shared_dplls[crtc->config.shared_dpll];
  847. }
  848. /* For ILK+ */
  849. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  850. struct intel_shared_dpll *pll,
  851. bool state)
  852. {
  853. bool cur_state;
  854. struct intel_dpll_hw_state hw_state;
  855. if (HAS_PCH_LPT(dev_priv->dev)) {
  856. DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
  857. return;
  858. }
  859. if (WARN (!pll,
  860. "asserting DPLL %s with no DPLL\n", state_string(state)))
  861. return;
  862. cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
  863. WARN(cur_state != state,
  864. "%s assertion failure (expected %s, current %s)\n",
  865. pll->name, state_string(state), state_string(cur_state));
  866. }
  867. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  868. enum pipe pipe, bool state)
  869. {
  870. int reg;
  871. u32 val;
  872. bool cur_state;
  873. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  874. pipe);
  875. if (HAS_DDI(dev_priv->dev)) {
  876. /* DDI does not have a specific FDI_TX register */
  877. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  878. val = I915_READ(reg);
  879. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  880. } else {
  881. reg = FDI_TX_CTL(pipe);
  882. val = I915_READ(reg);
  883. cur_state = !!(val & FDI_TX_ENABLE);
  884. }
  885. WARN(cur_state != state,
  886. "FDI TX state assertion failure (expected %s, current %s)\n",
  887. state_string(state), state_string(cur_state));
  888. }
  889. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  890. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  891. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  892. enum pipe pipe, bool state)
  893. {
  894. int reg;
  895. u32 val;
  896. bool cur_state;
  897. reg = FDI_RX_CTL(pipe);
  898. val = I915_READ(reg);
  899. cur_state = !!(val & FDI_RX_ENABLE);
  900. WARN(cur_state != state,
  901. "FDI RX state assertion failure (expected %s, current %s)\n",
  902. state_string(state), state_string(cur_state));
  903. }
  904. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  905. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  906. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  907. enum pipe pipe)
  908. {
  909. int reg;
  910. u32 val;
  911. /* ILK FDI PLL is always enabled */
  912. if (INTEL_INFO(dev_priv->dev)->gen == 5)
  913. return;
  914. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  915. if (HAS_DDI(dev_priv->dev))
  916. return;
  917. reg = FDI_TX_CTL(pipe);
  918. val = I915_READ(reg);
  919. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  920. }
  921. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  922. enum pipe pipe, bool state)
  923. {
  924. int reg;
  925. u32 val;
  926. bool cur_state;
  927. reg = FDI_RX_CTL(pipe);
  928. val = I915_READ(reg);
  929. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  930. WARN(cur_state != state,
  931. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  932. state_string(state), state_string(cur_state));
  933. }
  934. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  935. enum pipe pipe)
  936. {
  937. int pp_reg, lvds_reg;
  938. u32 val;
  939. enum pipe panel_pipe = PIPE_A;
  940. bool locked = true;
  941. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  942. pp_reg = PCH_PP_CONTROL;
  943. lvds_reg = PCH_LVDS;
  944. } else {
  945. pp_reg = PP_CONTROL;
  946. lvds_reg = LVDS;
  947. }
  948. val = I915_READ(pp_reg);
  949. if (!(val & PANEL_POWER_ON) ||
  950. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  951. locked = false;
  952. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  953. panel_pipe = PIPE_B;
  954. WARN(panel_pipe == pipe && locked,
  955. "panel assertion failure, pipe %c regs locked\n",
  956. pipe_name(pipe));
  957. }
  958. static void assert_cursor(struct drm_i915_private *dev_priv,
  959. enum pipe pipe, bool state)
  960. {
  961. struct drm_device *dev = dev_priv->dev;
  962. bool cur_state;
  963. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  964. cur_state = I915_READ(CURCNTR_IVB(pipe)) & CURSOR_MODE;
  965. else if (IS_845G(dev) || IS_I865G(dev))
  966. cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
  967. else
  968. cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  969. WARN(cur_state != state,
  970. "cursor on pipe %c assertion failure (expected %s, current %s)\n",
  971. pipe_name(pipe), state_string(state), state_string(cur_state));
  972. }
  973. #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
  974. #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
  975. void assert_pipe(struct drm_i915_private *dev_priv,
  976. enum pipe pipe, bool state)
  977. {
  978. int reg;
  979. u32 val;
  980. bool cur_state;
  981. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  982. pipe);
  983. /* if we need the pipe A quirk it must be always on */
  984. if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  985. state = true;
  986. if (!intel_display_power_enabled(dev_priv->dev,
  987. POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
  988. cur_state = false;
  989. } else {
  990. reg = PIPECONF(cpu_transcoder);
  991. val = I915_READ(reg);
  992. cur_state = !!(val & PIPECONF_ENABLE);
  993. }
  994. WARN(cur_state != state,
  995. "pipe %c assertion failure (expected %s, current %s)\n",
  996. pipe_name(pipe), state_string(state), state_string(cur_state));
  997. }
  998. static void assert_plane(struct drm_i915_private *dev_priv,
  999. enum plane plane, bool state)
  1000. {
  1001. int reg;
  1002. u32 val;
  1003. bool cur_state;
  1004. reg = DSPCNTR(plane);
  1005. val = I915_READ(reg);
  1006. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1007. WARN(cur_state != state,
  1008. "plane %c assertion failure (expected %s, current %s)\n",
  1009. plane_name(plane), state_string(state), state_string(cur_state));
  1010. }
  1011. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1012. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1013. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1014. enum pipe pipe)
  1015. {
  1016. struct drm_device *dev = dev_priv->dev;
  1017. int reg, i;
  1018. u32 val;
  1019. int cur_pipe;
  1020. /* Primary planes are fixed to pipes on gen4+ */
  1021. if (INTEL_INFO(dev)->gen >= 4) {
  1022. reg = DSPCNTR(pipe);
  1023. val = I915_READ(reg);
  1024. WARN((val & DISPLAY_PLANE_ENABLE),
  1025. "plane %c assertion failure, should be disabled but not\n",
  1026. plane_name(pipe));
  1027. return;
  1028. }
  1029. /* Need to check both planes against the pipe */
  1030. for_each_pipe(i) {
  1031. reg = DSPCNTR(i);
  1032. val = I915_READ(reg);
  1033. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1034. DISPPLANE_SEL_PIPE_SHIFT;
  1035. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1036. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1037. plane_name(i), pipe_name(pipe));
  1038. }
  1039. }
  1040. static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
  1041. enum pipe pipe)
  1042. {
  1043. struct drm_device *dev = dev_priv->dev;
  1044. int reg, i;
  1045. u32 val;
  1046. if (IS_VALLEYVIEW(dev)) {
  1047. for (i = 0; i < INTEL_INFO(dev)->num_sprites; i++) {
  1048. reg = SPCNTR(pipe, i);
  1049. val = I915_READ(reg);
  1050. WARN((val & SP_ENABLE),
  1051. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1052. sprite_name(pipe, i), pipe_name(pipe));
  1053. }
  1054. } else if (INTEL_INFO(dev)->gen >= 7) {
  1055. reg = SPRCTL(pipe);
  1056. val = I915_READ(reg);
  1057. WARN((val & SPRITE_ENABLE),
  1058. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1059. plane_name(pipe), pipe_name(pipe));
  1060. } else if (INTEL_INFO(dev)->gen >= 5) {
  1061. reg = DVSCNTR(pipe);
  1062. val = I915_READ(reg);
  1063. WARN((val & DVS_ENABLE),
  1064. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1065. plane_name(pipe), pipe_name(pipe));
  1066. }
  1067. }
  1068. static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1069. {
  1070. u32 val;
  1071. bool enabled;
  1072. WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
  1073. val = I915_READ(PCH_DREF_CONTROL);
  1074. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1075. DREF_SUPERSPREAD_SOURCE_MASK));
  1076. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1077. }
  1078. static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1079. enum pipe pipe)
  1080. {
  1081. int reg;
  1082. u32 val;
  1083. bool enabled;
  1084. reg = PCH_TRANSCONF(pipe);
  1085. val = I915_READ(reg);
  1086. enabled = !!(val & TRANS_ENABLE);
  1087. WARN(enabled,
  1088. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1089. pipe_name(pipe));
  1090. }
  1091. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1092. enum pipe pipe, u32 port_sel, u32 val)
  1093. {
  1094. if ((val & DP_PORT_EN) == 0)
  1095. return false;
  1096. if (HAS_PCH_CPT(dev_priv->dev)) {
  1097. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1098. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1099. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1100. return false;
  1101. } else {
  1102. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1103. return false;
  1104. }
  1105. return true;
  1106. }
  1107. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1108. enum pipe pipe, u32 val)
  1109. {
  1110. if ((val & SDVO_ENABLE) == 0)
  1111. return false;
  1112. if (HAS_PCH_CPT(dev_priv->dev)) {
  1113. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1114. return false;
  1115. } else {
  1116. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1117. return false;
  1118. }
  1119. return true;
  1120. }
  1121. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1122. enum pipe pipe, u32 val)
  1123. {
  1124. if ((val & LVDS_PORT_EN) == 0)
  1125. return false;
  1126. if (HAS_PCH_CPT(dev_priv->dev)) {
  1127. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1128. return false;
  1129. } else {
  1130. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1131. return false;
  1132. }
  1133. return true;
  1134. }
  1135. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1136. enum pipe pipe, u32 val)
  1137. {
  1138. if ((val & ADPA_DAC_ENABLE) == 0)
  1139. return false;
  1140. if (HAS_PCH_CPT(dev_priv->dev)) {
  1141. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1142. return false;
  1143. } else {
  1144. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1145. return false;
  1146. }
  1147. return true;
  1148. }
  1149. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1150. enum pipe pipe, int reg, u32 port_sel)
  1151. {
  1152. u32 val = I915_READ(reg);
  1153. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1154. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1155. reg, pipe_name(pipe));
  1156. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1157. && (val & DP_PIPEB_SELECT),
  1158. "IBX PCH dp port still using transcoder B\n");
  1159. }
  1160. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1161. enum pipe pipe, int reg)
  1162. {
  1163. u32 val = I915_READ(reg);
  1164. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1165. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1166. reg, pipe_name(pipe));
  1167. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
  1168. && (val & SDVO_PIPE_B_SELECT),
  1169. "IBX PCH hdmi port still using transcoder B\n");
  1170. }
  1171. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1172. enum pipe pipe)
  1173. {
  1174. int reg;
  1175. u32 val;
  1176. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1177. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1178. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1179. reg = PCH_ADPA;
  1180. val = I915_READ(reg);
  1181. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1182. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1183. pipe_name(pipe));
  1184. reg = PCH_LVDS;
  1185. val = I915_READ(reg);
  1186. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1187. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1188. pipe_name(pipe));
  1189. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1190. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1191. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1192. }
  1193. static void intel_init_dpio(struct drm_device *dev)
  1194. {
  1195. struct drm_i915_private *dev_priv = dev->dev_private;
  1196. if (!IS_VALLEYVIEW(dev))
  1197. return;
  1198. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  1199. }
  1200. static void intel_reset_dpio(struct drm_device *dev)
  1201. {
  1202. struct drm_i915_private *dev_priv = dev->dev_private;
  1203. if (!IS_VALLEYVIEW(dev))
  1204. return;
  1205. /*
  1206. * Enable the CRI clock source so we can get at the display and the
  1207. * reference clock for VGA hotplug / manual detection.
  1208. */
  1209. I915_WRITE(DPLL(PIPE_B), I915_READ(DPLL(PIPE_B)) |
  1210. DPLL_REFA_CLK_ENABLE_VLV |
  1211. DPLL_INTEGRATED_CRI_CLK_VLV);
  1212. /*
  1213. * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
  1214. * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
  1215. * a. GUnit 0x2110 bit[0] set to 1 (def 0)
  1216. * b. The other bits such as sfr settings / modesel may all be set
  1217. * to 0.
  1218. *
  1219. * This should only be done on init and resume from S3 with both
  1220. * PLLs disabled, or we risk losing DPIO and PLL synchronization.
  1221. */
  1222. I915_WRITE(DPIO_CTL, I915_READ(DPIO_CTL) | DPIO_CMNRST);
  1223. }
  1224. static void vlv_enable_pll(struct intel_crtc *crtc)
  1225. {
  1226. struct drm_device *dev = crtc->base.dev;
  1227. struct drm_i915_private *dev_priv = dev->dev_private;
  1228. int reg = DPLL(crtc->pipe);
  1229. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1230. assert_pipe_disabled(dev_priv, crtc->pipe);
  1231. /* No really, not for ILK+ */
  1232. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1233. /* PLL is protected by panel, make sure we can write it */
  1234. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1235. assert_panel_unlocked(dev_priv, crtc->pipe);
  1236. I915_WRITE(reg, dpll);
  1237. POSTING_READ(reg);
  1238. udelay(150);
  1239. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1240. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1241. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1242. POSTING_READ(DPLL_MD(crtc->pipe));
  1243. /* We do this three times for luck */
  1244. I915_WRITE(reg, dpll);
  1245. POSTING_READ(reg);
  1246. udelay(150); /* wait for warmup */
  1247. I915_WRITE(reg, dpll);
  1248. POSTING_READ(reg);
  1249. udelay(150); /* wait for warmup */
  1250. I915_WRITE(reg, dpll);
  1251. POSTING_READ(reg);
  1252. udelay(150); /* wait for warmup */
  1253. }
  1254. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1255. {
  1256. struct drm_device *dev = crtc->base.dev;
  1257. struct drm_i915_private *dev_priv = dev->dev_private;
  1258. int reg = DPLL(crtc->pipe);
  1259. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1260. assert_pipe_disabled(dev_priv, crtc->pipe);
  1261. /* No really, not for ILK+ */
  1262. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1263. /* PLL is protected by panel, make sure we can write it */
  1264. if (IS_MOBILE(dev) && !IS_I830(dev))
  1265. assert_panel_unlocked(dev_priv, crtc->pipe);
  1266. I915_WRITE(reg, dpll);
  1267. /* Wait for the clocks to stabilize. */
  1268. POSTING_READ(reg);
  1269. udelay(150);
  1270. if (INTEL_INFO(dev)->gen >= 4) {
  1271. I915_WRITE(DPLL_MD(crtc->pipe),
  1272. crtc->config.dpll_hw_state.dpll_md);
  1273. } else {
  1274. /* The pixel multiplier can only be updated once the
  1275. * DPLL is enabled and the clocks are stable.
  1276. *
  1277. * So write it again.
  1278. */
  1279. I915_WRITE(reg, dpll);
  1280. }
  1281. /* We do this three times for luck */
  1282. I915_WRITE(reg, dpll);
  1283. POSTING_READ(reg);
  1284. udelay(150); /* wait for warmup */
  1285. I915_WRITE(reg, dpll);
  1286. POSTING_READ(reg);
  1287. udelay(150); /* wait for warmup */
  1288. I915_WRITE(reg, dpll);
  1289. POSTING_READ(reg);
  1290. udelay(150); /* wait for warmup */
  1291. }
  1292. /**
  1293. * i9xx_disable_pll - disable a PLL
  1294. * @dev_priv: i915 private structure
  1295. * @pipe: pipe PLL to disable
  1296. *
  1297. * Disable the PLL for @pipe, making sure the pipe is off first.
  1298. *
  1299. * Note! This is for pre-ILK only.
  1300. */
  1301. static void i9xx_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1302. {
  1303. /* Don't disable pipe A or pipe A PLLs if needed */
  1304. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1305. return;
  1306. /* Make sure the pipe isn't still relying on us */
  1307. assert_pipe_disabled(dev_priv, pipe);
  1308. I915_WRITE(DPLL(pipe), 0);
  1309. POSTING_READ(DPLL(pipe));
  1310. }
  1311. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1312. {
  1313. u32 val = 0;
  1314. /* Make sure the pipe isn't still relying on us */
  1315. assert_pipe_disabled(dev_priv, pipe);
  1316. /*
  1317. * Leave integrated clock source and reference clock enabled for pipe B.
  1318. * The latter is needed for VGA hotplug / manual detection.
  1319. */
  1320. if (pipe == PIPE_B)
  1321. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1322. I915_WRITE(DPLL(pipe), val);
  1323. POSTING_READ(DPLL(pipe));
  1324. }
  1325. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1326. struct intel_digital_port *dport)
  1327. {
  1328. u32 port_mask;
  1329. switch (dport->port) {
  1330. case PORT_B:
  1331. port_mask = DPLL_PORTB_READY_MASK;
  1332. break;
  1333. case PORT_C:
  1334. port_mask = DPLL_PORTC_READY_MASK;
  1335. break;
  1336. default:
  1337. BUG();
  1338. }
  1339. if (wait_for((I915_READ(DPLL(0)) & port_mask) == 0, 1000))
  1340. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1341. port_name(dport->port), I915_READ(DPLL(0)));
  1342. }
  1343. /**
  1344. * ironlake_enable_shared_dpll - enable PCH PLL
  1345. * @dev_priv: i915 private structure
  1346. * @pipe: pipe PLL to enable
  1347. *
  1348. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1349. * drives the transcoder clock.
  1350. */
  1351. static void ironlake_enable_shared_dpll(struct intel_crtc *crtc)
  1352. {
  1353. struct drm_device *dev = crtc->base.dev;
  1354. struct drm_i915_private *dev_priv = dev->dev_private;
  1355. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1356. /* PCH PLLs only available on ILK, SNB and IVB */
  1357. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1358. if (WARN_ON(pll == NULL))
  1359. return;
  1360. if (WARN_ON(pll->refcount == 0))
  1361. return;
  1362. DRM_DEBUG_KMS("enable %s (active %d, on? %d)for crtc %d\n",
  1363. pll->name, pll->active, pll->on,
  1364. crtc->base.base.id);
  1365. if (pll->active++) {
  1366. WARN_ON(!pll->on);
  1367. assert_shared_dpll_enabled(dev_priv, pll);
  1368. return;
  1369. }
  1370. WARN_ON(pll->on);
  1371. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1372. pll->enable(dev_priv, pll);
  1373. pll->on = true;
  1374. }
  1375. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1376. {
  1377. struct drm_device *dev = crtc->base.dev;
  1378. struct drm_i915_private *dev_priv = dev->dev_private;
  1379. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1380. /* PCH only available on ILK+ */
  1381. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1382. if (WARN_ON(pll == NULL))
  1383. return;
  1384. if (WARN_ON(pll->refcount == 0))
  1385. return;
  1386. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1387. pll->name, pll->active, pll->on,
  1388. crtc->base.base.id);
  1389. if (WARN_ON(pll->active == 0)) {
  1390. assert_shared_dpll_disabled(dev_priv, pll);
  1391. return;
  1392. }
  1393. assert_shared_dpll_enabled(dev_priv, pll);
  1394. WARN_ON(!pll->on);
  1395. if (--pll->active)
  1396. return;
  1397. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1398. pll->disable(dev_priv, pll);
  1399. pll->on = false;
  1400. }
  1401. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1402. enum pipe pipe)
  1403. {
  1404. struct drm_device *dev = dev_priv->dev;
  1405. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1406. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1407. uint32_t reg, val, pipeconf_val;
  1408. /* PCH only available on ILK+ */
  1409. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1410. /* Make sure PCH DPLL is enabled */
  1411. assert_shared_dpll_enabled(dev_priv,
  1412. intel_crtc_to_shared_dpll(intel_crtc));
  1413. /* FDI must be feeding us bits for PCH ports */
  1414. assert_fdi_tx_enabled(dev_priv, pipe);
  1415. assert_fdi_rx_enabled(dev_priv, pipe);
  1416. if (HAS_PCH_CPT(dev)) {
  1417. /* Workaround: Set the timing override bit before enabling the
  1418. * pch transcoder. */
  1419. reg = TRANS_CHICKEN2(pipe);
  1420. val = I915_READ(reg);
  1421. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1422. I915_WRITE(reg, val);
  1423. }
  1424. reg = PCH_TRANSCONF(pipe);
  1425. val = I915_READ(reg);
  1426. pipeconf_val = I915_READ(PIPECONF(pipe));
  1427. if (HAS_PCH_IBX(dev_priv->dev)) {
  1428. /*
  1429. * make the BPC in transcoder be consistent with
  1430. * that in pipeconf reg.
  1431. */
  1432. val &= ~PIPECONF_BPC_MASK;
  1433. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1434. }
  1435. val &= ~TRANS_INTERLACE_MASK;
  1436. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1437. if (HAS_PCH_IBX(dev_priv->dev) &&
  1438. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1439. val |= TRANS_LEGACY_INTERLACED_ILK;
  1440. else
  1441. val |= TRANS_INTERLACED;
  1442. else
  1443. val |= TRANS_PROGRESSIVE;
  1444. I915_WRITE(reg, val | TRANS_ENABLE);
  1445. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1446. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1447. }
  1448. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1449. enum transcoder cpu_transcoder)
  1450. {
  1451. u32 val, pipeconf_val;
  1452. /* PCH only available on ILK+ */
  1453. BUG_ON(INTEL_INFO(dev_priv->dev)->gen < 5);
  1454. /* FDI must be feeding us bits for PCH ports */
  1455. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1456. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1457. /* Workaround: set timing override bit. */
  1458. val = I915_READ(_TRANSA_CHICKEN2);
  1459. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1460. I915_WRITE(_TRANSA_CHICKEN2, val);
  1461. val = TRANS_ENABLE;
  1462. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1463. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1464. PIPECONF_INTERLACED_ILK)
  1465. val |= TRANS_INTERLACED;
  1466. else
  1467. val |= TRANS_PROGRESSIVE;
  1468. I915_WRITE(LPT_TRANSCONF, val);
  1469. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1470. DRM_ERROR("Failed to enable PCH transcoder\n");
  1471. }
  1472. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1473. enum pipe pipe)
  1474. {
  1475. struct drm_device *dev = dev_priv->dev;
  1476. uint32_t reg, val;
  1477. /* FDI relies on the transcoder */
  1478. assert_fdi_tx_disabled(dev_priv, pipe);
  1479. assert_fdi_rx_disabled(dev_priv, pipe);
  1480. /* Ports must be off as well */
  1481. assert_pch_ports_disabled(dev_priv, pipe);
  1482. reg = PCH_TRANSCONF(pipe);
  1483. val = I915_READ(reg);
  1484. val &= ~TRANS_ENABLE;
  1485. I915_WRITE(reg, val);
  1486. /* wait for PCH transcoder off, transcoder state */
  1487. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1488. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1489. if (!HAS_PCH_IBX(dev)) {
  1490. /* Workaround: Clear the timing override chicken bit again. */
  1491. reg = TRANS_CHICKEN2(pipe);
  1492. val = I915_READ(reg);
  1493. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1494. I915_WRITE(reg, val);
  1495. }
  1496. }
  1497. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1498. {
  1499. u32 val;
  1500. val = I915_READ(LPT_TRANSCONF);
  1501. val &= ~TRANS_ENABLE;
  1502. I915_WRITE(LPT_TRANSCONF, val);
  1503. /* wait for PCH transcoder off, transcoder state */
  1504. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1505. DRM_ERROR("Failed to disable PCH transcoder\n");
  1506. /* Workaround: clear timing override bit. */
  1507. val = I915_READ(_TRANSA_CHICKEN2);
  1508. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1509. I915_WRITE(_TRANSA_CHICKEN2, val);
  1510. }
  1511. /**
  1512. * intel_enable_pipe - enable a pipe, asserting requirements
  1513. * @dev_priv: i915 private structure
  1514. * @pipe: pipe to enable
  1515. * @pch_port: on ILK+, is this pipe driving a PCH port or not
  1516. *
  1517. * Enable @pipe, making sure that various hardware specific requirements
  1518. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1519. *
  1520. * @pipe should be %PIPE_A or %PIPE_B.
  1521. *
  1522. * Will wait until the pipe is actually running (i.e. first vblank) before
  1523. * returning.
  1524. */
  1525. static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
  1526. bool pch_port, bool dsi)
  1527. {
  1528. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1529. pipe);
  1530. enum pipe pch_transcoder;
  1531. int reg;
  1532. u32 val;
  1533. assert_planes_disabled(dev_priv, pipe);
  1534. assert_cursor_disabled(dev_priv, pipe);
  1535. assert_sprites_disabled(dev_priv, pipe);
  1536. if (HAS_PCH_LPT(dev_priv->dev))
  1537. pch_transcoder = TRANSCODER_A;
  1538. else
  1539. pch_transcoder = pipe;
  1540. /*
  1541. * A pipe without a PLL won't actually be able to drive bits from
  1542. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1543. * need the check.
  1544. */
  1545. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1546. if (dsi)
  1547. assert_dsi_pll_enabled(dev_priv);
  1548. else
  1549. assert_pll_enabled(dev_priv, pipe);
  1550. else {
  1551. if (pch_port) {
  1552. /* if driving the PCH, we need FDI enabled */
  1553. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1554. assert_fdi_tx_pll_enabled(dev_priv,
  1555. (enum pipe) cpu_transcoder);
  1556. }
  1557. /* FIXME: assert CPU port conditions for SNB+ */
  1558. }
  1559. reg = PIPECONF(cpu_transcoder);
  1560. val = I915_READ(reg);
  1561. if (val & PIPECONF_ENABLE)
  1562. return;
  1563. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1564. intel_wait_for_vblank(dev_priv->dev, pipe);
  1565. }
  1566. /**
  1567. * intel_disable_pipe - disable a pipe, asserting requirements
  1568. * @dev_priv: i915 private structure
  1569. * @pipe: pipe to disable
  1570. *
  1571. * Disable @pipe, making sure that various hardware specific requirements
  1572. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1573. *
  1574. * @pipe should be %PIPE_A or %PIPE_B.
  1575. *
  1576. * Will wait until the pipe has shut down before returning.
  1577. */
  1578. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1579. enum pipe pipe)
  1580. {
  1581. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1582. pipe);
  1583. int reg;
  1584. u32 val;
  1585. /*
  1586. * Make sure planes won't keep trying to pump pixels to us,
  1587. * or we might hang the display.
  1588. */
  1589. assert_planes_disabled(dev_priv, pipe);
  1590. assert_cursor_disabled(dev_priv, pipe);
  1591. assert_sprites_disabled(dev_priv, pipe);
  1592. /* Don't disable pipe A or pipe A PLLs if needed */
  1593. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1594. return;
  1595. reg = PIPECONF(cpu_transcoder);
  1596. val = I915_READ(reg);
  1597. if ((val & PIPECONF_ENABLE) == 0)
  1598. return;
  1599. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1600. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1601. }
  1602. /*
  1603. * Plane regs are double buffered, going from enabled->disabled needs a
  1604. * trigger in order to latch. The display address reg provides this.
  1605. */
  1606. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1607. enum plane plane)
  1608. {
  1609. struct drm_device *dev = dev_priv->dev;
  1610. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1611. I915_WRITE(reg, I915_READ(reg));
  1612. POSTING_READ(reg);
  1613. }
  1614. /**
  1615. * intel_enable_primary_plane - enable the primary plane on a given pipe
  1616. * @dev_priv: i915 private structure
  1617. * @plane: plane to enable
  1618. * @pipe: pipe being fed
  1619. *
  1620. * Enable @plane on @pipe, making sure that @pipe is running first.
  1621. */
  1622. static void intel_enable_primary_plane(struct drm_i915_private *dev_priv,
  1623. enum plane plane, enum pipe pipe)
  1624. {
  1625. struct intel_crtc *intel_crtc =
  1626. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1627. int reg;
  1628. u32 val;
  1629. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1630. assert_pipe_enabled(dev_priv, pipe);
  1631. WARN(intel_crtc->primary_enabled, "Primary plane already enabled\n");
  1632. intel_crtc->primary_enabled = true;
  1633. reg = DSPCNTR(plane);
  1634. val = I915_READ(reg);
  1635. if (val & DISPLAY_PLANE_ENABLE)
  1636. return;
  1637. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1638. intel_flush_primary_plane(dev_priv, plane);
  1639. intel_wait_for_vblank(dev_priv->dev, pipe);
  1640. }
  1641. /**
  1642. * intel_disable_primary_plane - disable the primary plane
  1643. * @dev_priv: i915 private structure
  1644. * @plane: plane to disable
  1645. * @pipe: pipe consuming the data
  1646. *
  1647. * Disable @plane; should be an independent operation.
  1648. */
  1649. static void intel_disable_primary_plane(struct drm_i915_private *dev_priv,
  1650. enum plane plane, enum pipe pipe)
  1651. {
  1652. struct intel_crtc *intel_crtc =
  1653. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1654. int reg;
  1655. u32 val;
  1656. WARN(!intel_crtc->primary_enabled, "Primary plane already disabled\n");
  1657. intel_crtc->primary_enabled = false;
  1658. reg = DSPCNTR(plane);
  1659. val = I915_READ(reg);
  1660. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  1661. return;
  1662. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1663. intel_flush_primary_plane(dev_priv, plane);
  1664. intel_wait_for_vblank(dev_priv->dev, pipe);
  1665. }
  1666. static bool need_vtd_wa(struct drm_device *dev)
  1667. {
  1668. #ifdef CONFIG_INTEL_IOMMU
  1669. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1670. return true;
  1671. #endif
  1672. return false;
  1673. }
  1674. int
  1675. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1676. struct drm_i915_gem_object *obj,
  1677. struct intel_ring_buffer *pipelined)
  1678. {
  1679. struct drm_i915_private *dev_priv = dev->dev_private;
  1680. u32 alignment;
  1681. int ret;
  1682. switch (obj->tiling_mode) {
  1683. case I915_TILING_NONE:
  1684. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1685. alignment = 128 * 1024;
  1686. else if (INTEL_INFO(dev)->gen >= 4)
  1687. alignment = 4 * 1024;
  1688. else
  1689. alignment = 64 * 1024;
  1690. break;
  1691. case I915_TILING_X:
  1692. /* pin() will align the object as required by fence */
  1693. alignment = 0;
  1694. break;
  1695. case I915_TILING_Y:
  1696. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1697. return -EINVAL;
  1698. default:
  1699. BUG();
  1700. }
  1701. /* Note that the w/a also requires 64 PTE of padding following the
  1702. * bo. We currently fill all unused PTE with the shadow page and so
  1703. * we should always have valid PTE following the scanout preventing
  1704. * the VT-d warning.
  1705. */
  1706. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1707. alignment = 256 * 1024;
  1708. dev_priv->mm.interruptible = false;
  1709. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1710. if (ret)
  1711. goto err_interruptible;
  1712. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1713. * fence, whereas 965+ only requires a fence if using
  1714. * framebuffer compression. For simplicity, we always install
  1715. * a fence as the cost is not that onerous.
  1716. */
  1717. ret = i915_gem_object_get_fence(obj);
  1718. if (ret)
  1719. goto err_unpin;
  1720. i915_gem_object_pin_fence(obj);
  1721. dev_priv->mm.interruptible = true;
  1722. return 0;
  1723. err_unpin:
  1724. i915_gem_object_unpin_from_display_plane(obj);
  1725. err_interruptible:
  1726. dev_priv->mm.interruptible = true;
  1727. return ret;
  1728. }
  1729. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1730. {
  1731. i915_gem_object_unpin_fence(obj);
  1732. i915_gem_object_unpin_from_display_plane(obj);
  1733. }
  1734. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1735. * is assumed to be a power-of-two. */
  1736. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1737. unsigned int tiling_mode,
  1738. unsigned int cpp,
  1739. unsigned int pitch)
  1740. {
  1741. if (tiling_mode != I915_TILING_NONE) {
  1742. unsigned int tile_rows, tiles;
  1743. tile_rows = *y / 8;
  1744. *y %= 8;
  1745. tiles = *x / (512/cpp);
  1746. *x %= 512/cpp;
  1747. return tile_rows * pitch * 8 + tiles * 4096;
  1748. } else {
  1749. unsigned int offset;
  1750. offset = *y * pitch + *x * cpp;
  1751. *y = 0;
  1752. *x = (offset & 4095) / cpp;
  1753. return offset & -4096;
  1754. }
  1755. }
  1756. static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1757. int x, int y)
  1758. {
  1759. struct drm_device *dev = crtc->dev;
  1760. struct drm_i915_private *dev_priv = dev->dev_private;
  1761. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1762. struct intel_framebuffer *intel_fb;
  1763. struct drm_i915_gem_object *obj;
  1764. int plane = intel_crtc->plane;
  1765. unsigned long linear_offset;
  1766. u32 dspcntr;
  1767. u32 reg;
  1768. switch (plane) {
  1769. case 0:
  1770. case 1:
  1771. break;
  1772. default:
  1773. DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane));
  1774. return -EINVAL;
  1775. }
  1776. intel_fb = to_intel_framebuffer(fb);
  1777. obj = intel_fb->obj;
  1778. reg = DSPCNTR(plane);
  1779. dspcntr = I915_READ(reg);
  1780. /* Mask out pixel format bits in case we change it */
  1781. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1782. switch (fb->pixel_format) {
  1783. case DRM_FORMAT_C8:
  1784. dspcntr |= DISPPLANE_8BPP;
  1785. break;
  1786. case DRM_FORMAT_XRGB1555:
  1787. case DRM_FORMAT_ARGB1555:
  1788. dspcntr |= DISPPLANE_BGRX555;
  1789. break;
  1790. case DRM_FORMAT_RGB565:
  1791. dspcntr |= DISPPLANE_BGRX565;
  1792. break;
  1793. case DRM_FORMAT_XRGB8888:
  1794. case DRM_FORMAT_ARGB8888:
  1795. dspcntr |= DISPPLANE_BGRX888;
  1796. break;
  1797. case DRM_FORMAT_XBGR8888:
  1798. case DRM_FORMAT_ABGR8888:
  1799. dspcntr |= DISPPLANE_RGBX888;
  1800. break;
  1801. case DRM_FORMAT_XRGB2101010:
  1802. case DRM_FORMAT_ARGB2101010:
  1803. dspcntr |= DISPPLANE_BGRX101010;
  1804. break;
  1805. case DRM_FORMAT_XBGR2101010:
  1806. case DRM_FORMAT_ABGR2101010:
  1807. dspcntr |= DISPPLANE_RGBX101010;
  1808. break;
  1809. default:
  1810. BUG();
  1811. }
  1812. if (INTEL_INFO(dev)->gen >= 4) {
  1813. if (obj->tiling_mode != I915_TILING_NONE)
  1814. dspcntr |= DISPPLANE_TILED;
  1815. else
  1816. dspcntr &= ~DISPPLANE_TILED;
  1817. }
  1818. if (IS_G4X(dev))
  1819. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1820. I915_WRITE(reg, dspcntr);
  1821. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1822. if (INTEL_INFO(dev)->gen >= 4) {
  1823. intel_crtc->dspaddr_offset =
  1824. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  1825. fb->bits_per_pixel / 8,
  1826. fb->pitches[0]);
  1827. linear_offset -= intel_crtc->dspaddr_offset;
  1828. } else {
  1829. intel_crtc->dspaddr_offset = linear_offset;
  1830. }
  1831. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  1832. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  1833. fb->pitches[0]);
  1834. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1835. if (INTEL_INFO(dev)->gen >= 4) {
  1836. I915_WRITE(DSPSURF(plane),
  1837. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  1838. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1839. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1840. } else
  1841. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  1842. POSTING_READ(reg);
  1843. return 0;
  1844. }
  1845. static int ironlake_update_plane(struct drm_crtc *crtc,
  1846. struct drm_framebuffer *fb, int x, int y)
  1847. {
  1848. struct drm_device *dev = crtc->dev;
  1849. struct drm_i915_private *dev_priv = dev->dev_private;
  1850. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1851. struct intel_framebuffer *intel_fb;
  1852. struct drm_i915_gem_object *obj;
  1853. int plane = intel_crtc->plane;
  1854. unsigned long linear_offset;
  1855. u32 dspcntr;
  1856. u32 reg;
  1857. switch (plane) {
  1858. case 0:
  1859. case 1:
  1860. case 2:
  1861. break;
  1862. default:
  1863. DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane));
  1864. return -EINVAL;
  1865. }
  1866. intel_fb = to_intel_framebuffer(fb);
  1867. obj = intel_fb->obj;
  1868. reg = DSPCNTR(plane);
  1869. dspcntr = I915_READ(reg);
  1870. /* Mask out pixel format bits in case we change it */
  1871. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1872. switch (fb->pixel_format) {
  1873. case DRM_FORMAT_C8:
  1874. dspcntr |= DISPPLANE_8BPP;
  1875. break;
  1876. case DRM_FORMAT_RGB565:
  1877. dspcntr |= DISPPLANE_BGRX565;
  1878. break;
  1879. case DRM_FORMAT_XRGB8888:
  1880. case DRM_FORMAT_ARGB8888:
  1881. dspcntr |= DISPPLANE_BGRX888;
  1882. break;
  1883. case DRM_FORMAT_XBGR8888:
  1884. case DRM_FORMAT_ABGR8888:
  1885. dspcntr |= DISPPLANE_RGBX888;
  1886. break;
  1887. case DRM_FORMAT_XRGB2101010:
  1888. case DRM_FORMAT_ARGB2101010:
  1889. dspcntr |= DISPPLANE_BGRX101010;
  1890. break;
  1891. case DRM_FORMAT_XBGR2101010:
  1892. case DRM_FORMAT_ABGR2101010:
  1893. dspcntr |= DISPPLANE_RGBX101010;
  1894. break;
  1895. default:
  1896. BUG();
  1897. }
  1898. if (obj->tiling_mode != I915_TILING_NONE)
  1899. dspcntr |= DISPPLANE_TILED;
  1900. else
  1901. dspcntr &= ~DISPPLANE_TILED;
  1902. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  1903. dspcntr &= ~DISPPLANE_TRICKLE_FEED_DISABLE;
  1904. else
  1905. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1906. I915_WRITE(reg, dspcntr);
  1907. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1908. intel_crtc->dspaddr_offset =
  1909. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  1910. fb->bits_per_pixel / 8,
  1911. fb->pitches[0]);
  1912. linear_offset -= intel_crtc->dspaddr_offset;
  1913. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  1914. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  1915. fb->pitches[0]);
  1916. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1917. I915_WRITE(DSPSURF(plane),
  1918. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  1919. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  1920. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  1921. } else {
  1922. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1923. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1924. }
  1925. POSTING_READ(reg);
  1926. return 0;
  1927. }
  1928. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  1929. static int
  1930. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1931. int x, int y, enum mode_set_atomic state)
  1932. {
  1933. struct drm_device *dev = crtc->dev;
  1934. struct drm_i915_private *dev_priv = dev->dev_private;
  1935. if (dev_priv->display.disable_fbc)
  1936. dev_priv->display.disable_fbc(dev);
  1937. intel_increase_pllclock(crtc);
  1938. return dev_priv->display.update_plane(crtc, fb, x, y);
  1939. }
  1940. void intel_display_handle_reset(struct drm_device *dev)
  1941. {
  1942. struct drm_i915_private *dev_priv = dev->dev_private;
  1943. struct drm_crtc *crtc;
  1944. /*
  1945. * Flips in the rings have been nuked by the reset,
  1946. * so complete all pending flips so that user space
  1947. * will get its events and not get stuck.
  1948. *
  1949. * Also update the base address of all primary
  1950. * planes to the the last fb to make sure we're
  1951. * showing the correct fb after a reset.
  1952. *
  1953. * Need to make two loops over the crtcs so that we
  1954. * don't try to grab a crtc mutex before the
  1955. * pending_flip_queue really got woken up.
  1956. */
  1957. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1958. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1959. enum plane plane = intel_crtc->plane;
  1960. intel_prepare_page_flip(dev, plane);
  1961. intel_finish_page_flip_plane(dev, plane);
  1962. }
  1963. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1964. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1965. mutex_lock(&crtc->mutex);
  1966. /*
  1967. * FIXME: Once we have proper support for primary planes (and
  1968. * disabling them without disabling the entire crtc) allow again
  1969. * a NULL crtc->fb.
  1970. */
  1971. if (intel_crtc->active && crtc->fb)
  1972. dev_priv->display.update_plane(crtc, crtc->fb,
  1973. crtc->x, crtc->y);
  1974. mutex_unlock(&crtc->mutex);
  1975. }
  1976. }
  1977. static int
  1978. intel_finish_fb(struct drm_framebuffer *old_fb)
  1979. {
  1980. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  1981. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1982. bool was_interruptible = dev_priv->mm.interruptible;
  1983. int ret;
  1984. /* Big Hammer, we also need to ensure that any pending
  1985. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  1986. * current scanout is retired before unpinning the old
  1987. * framebuffer.
  1988. *
  1989. * This should only fail upon a hung GPU, in which case we
  1990. * can safely continue.
  1991. */
  1992. dev_priv->mm.interruptible = false;
  1993. ret = i915_gem_object_finish_gpu(obj);
  1994. dev_priv->mm.interruptible = was_interruptible;
  1995. return ret;
  1996. }
  1997. static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y)
  1998. {
  1999. struct drm_device *dev = crtc->dev;
  2000. struct drm_i915_master_private *master_priv;
  2001. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2002. if (!dev->primary->master)
  2003. return;
  2004. master_priv = dev->primary->master->driver_priv;
  2005. if (!master_priv->sarea_priv)
  2006. return;
  2007. switch (intel_crtc->pipe) {
  2008. case 0:
  2009. master_priv->sarea_priv->pipeA_x = x;
  2010. master_priv->sarea_priv->pipeA_y = y;
  2011. break;
  2012. case 1:
  2013. master_priv->sarea_priv->pipeB_x = x;
  2014. master_priv->sarea_priv->pipeB_y = y;
  2015. break;
  2016. default:
  2017. break;
  2018. }
  2019. }
  2020. static int
  2021. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2022. struct drm_framebuffer *fb)
  2023. {
  2024. struct drm_device *dev = crtc->dev;
  2025. struct drm_i915_private *dev_priv = dev->dev_private;
  2026. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2027. struct drm_framebuffer *old_fb;
  2028. int ret;
  2029. /* no fb bound */
  2030. if (!fb) {
  2031. DRM_ERROR("No FB bound\n");
  2032. return 0;
  2033. }
  2034. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2035. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2036. plane_name(intel_crtc->plane),
  2037. INTEL_INFO(dev)->num_pipes);
  2038. return -EINVAL;
  2039. }
  2040. mutex_lock(&dev->struct_mutex);
  2041. ret = intel_pin_and_fence_fb_obj(dev,
  2042. to_intel_framebuffer(fb)->obj,
  2043. NULL);
  2044. if (ret != 0) {
  2045. mutex_unlock(&dev->struct_mutex);
  2046. DRM_ERROR("pin & fence failed\n");
  2047. return ret;
  2048. }
  2049. /*
  2050. * Update pipe size and adjust fitter if needed: the reason for this is
  2051. * that in compute_mode_changes we check the native mode (not the pfit
  2052. * mode) to see if we can flip rather than do a full mode set. In the
  2053. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2054. * pfit state, we'll end up with a big fb scanned out into the wrong
  2055. * sized surface.
  2056. *
  2057. * To fix this properly, we need to hoist the checks up into
  2058. * compute_mode_changes (or above), check the actual pfit state and
  2059. * whether the platform allows pfit disable with pipe active, and only
  2060. * then update the pipesrc and pfit state, even on the flip path.
  2061. */
  2062. if (i915.fastboot) {
  2063. const struct drm_display_mode *adjusted_mode =
  2064. &intel_crtc->config.adjusted_mode;
  2065. I915_WRITE(PIPESRC(intel_crtc->pipe),
  2066. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2067. (adjusted_mode->crtc_vdisplay - 1));
  2068. if (!intel_crtc->config.pch_pfit.enabled &&
  2069. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2070. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2071. I915_WRITE(PF_CTL(intel_crtc->pipe), 0);
  2072. I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0);
  2073. I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0);
  2074. }
  2075. intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2076. intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2077. }
  2078. ret = dev_priv->display.update_plane(crtc, fb, x, y);
  2079. if (ret) {
  2080. intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
  2081. mutex_unlock(&dev->struct_mutex);
  2082. DRM_ERROR("failed to update base address\n");
  2083. return ret;
  2084. }
  2085. old_fb = crtc->fb;
  2086. crtc->fb = fb;
  2087. crtc->x = x;
  2088. crtc->y = y;
  2089. if (old_fb) {
  2090. if (intel_crtc->active && old_fb != fb)
  2091. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2092. intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
  2093. }
  2094. intel_update_fbc(dev);
  2095. intel_edp_psr_update(dev);
  2096. mutex_unlock(&dev->struct_mutex);
  2097. intel_crtc_update_sarea_pos(crtc, x, y);
  2098. return 0;
  2099. }
  2100. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2101. {
  2102. struct drm_device *dev = crtc->dev;
  2103. struct drm_i915_private *dev_priv = dev->dev_private;
  2104. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2105. int pipe = intel_crtc->pipe;
  2106. u32 reg, temp;
  2107. /* enable normal train */
  2108. reg = FDI_TX_CTL(pipe);
  2109. temp = I915_READ(reg);
  2110. if (IS_IVYBRIDGE(dev)) {
  2111. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2112. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2113. } else {
  2114. temp &= ~FDI_LINK_TRAIN_NONE;
  2115. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2116. }
  2117. I915_WRITE(reg, temp);
  2118. reg = FDI_RX_CTL(pipe);
  2119. temp = I915_READ(reg);
  2120. if (HAS_PCH_CPT(dev)) {
  2121. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2122. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2123. } else {
  2124. temp &= ~FDI_LINK_TRAIN_NONE;
  2125. temp |= FDI_LINK_TRAIN_NONE;
  2126. }
  2127. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2128. /* wait one idle pattern time */
  2129. POSTING_READ(reg);
  2130. udelay(1000);
  2131. /* IVB wants error correction enabled */
  2132. if (IS_IVYBRIDGE(dev))
  2133. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2134. FDI_FE_ERRC_ENABLE);
  2135. }
  2136. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2137. {
  2138. return crtc->base.enabled && crtc->active &&
  2139. crtc->config.has_pch_encoder;
  2140. }
  2141. static void ivb_modeset_global_resources(struct drm_device *dev)
  2142. {
  2143. struct drm_i915_private *dev_priv = dev->dev_private;
  2144. struct intel_crtc *pipe_B_crtc =
  2145. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2146. struct intel_crtc *pipe_C_crtc =
  2147. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2148. uint32_t temp;
  2149. /*
  2150. * When everything is off disable fdi C so that we could enable fdi B
  2151. * with all lanes. Note that we don't care about enabled pipes without
  2152. * an enabled pch encoder.
  2153. */
  2154. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2155. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2156. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2157. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2158. temp = I915_READ(SOUTH_CHICKEN1);
  2159. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2160. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2161. I915_WRITE(SOUTH_CHICKEN1, temp);
  2162. }
  2163. }
  2164. /* The FDI link training functions for ILK/Ibexpeak. */
  2165. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2166. {
  2167. struct drm_device *dev = crtc->dev;
  2168. struct drm_i915_private *dev_priv = dev->dev_private;
  2169. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2170. int pipe = intel_crtc->pipe;
  2171. int plane = intel_crtc->plane;
  2172. u32 reg, temp, tries;
  2173. /* FDI needs bits from pipe & plane first */
  2174. assert_pipe_enabled(dev_priv, pipe);
  2175. assert_plane_enabled(dev_priv, plane);
  2176. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2177. for train result */
  2178. reg = FDI_RX_IMR(pipe);
  2179. temp = I915_READ(reg);
  2180. temp &= ~FDI_RX_SYMBOL_LOCK;
  2181. temp &= ~FDI_RX_BIT_LOCK;
  2182. I915_WRITE(reg, temp);
  2183. I915_READ(reg);
  2184. udelay(150);
  2185. /* enable CPU FDI TX and PCH FDI RX */
  2186. reg = FDI_TX_CTL(pipe);
  2187. temp = I915_READ(reg);
  2188. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2189. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2190. temp &= ~FDI_LINK_TRAIN_NONE;
  2191. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2192. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2193. reg = FDI_RX_CTL(pipe);
  2194. temp = I915_READ(reg);
  2195. temp &= ~FDI_LINK_TRAIN_NONE;
  2196. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2197. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2198. POSTING_READ(reg);
  2199. udelay(150);
  2200. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2201. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2202. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2203. FDI_RX_PHASE_SYNC_POINTER_EN);
  2204. reg = FDI_RX_IIR(pipe);
  2205. for (tries = 0; tries < 5; tries++) {
  2206. temp = I915_READ(reg);
  2207. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2208. if ((temp & FDI_RX_BIT_LOCK)) {
  2209. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2210. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2211. break;
  2212. }
  2213. }
  2214. if (tries == 5)
  2215. DRM_ERROR("FDI train 1 fail!\n");
  2216. /* Train 2 */
  2217. reg = FDI_TX_CTL(pipe);
  2218. temp = I915_READ(reg);
  2219. temp &= ~FDI_LINK_TRAIN_NONE;
  2220. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2221. I915_WRITE(reg, temp);
  2222. reg = FDI_RX_CTL(pipe);
  2223. temp = I915_READ(reg);
  2224. temp &= ~FDI_LINK_TRAIN_NONE;
  2225. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2226. I915_WRITE(reg, temp);
  2227. POSTING_READ(reg);
  2228. udelay(150);
  2229. reg = FDI_RX_IIR(pipe);
  2230. for (tries = 0; tries < 5; tries++) {
  2231. temp = I915_READ(reg);
  2232. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2233. if (temp & FDI_RX_SYMBOL_LOCK) {
  2234. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2235. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2236. break;
  2237. }
  2238. }
  2239. if (tries == 5)
  2240. DRM_ERROR("FDI train 2 fail!\n");
  2241. DRM_DEBUG_KMS("FDI train done\n");
  2242. }
  2243. static const int snb_b_fdi_train_param[] = {
  2244. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2245. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2246. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2247. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2248. };
  2249. /* The FDI link training functions for SNB/Cougarpoint. */
  2250. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2251. {
  2252. struct drm_device *dev = crtc->dev;
  2253. struct drm_i915_private *dev_priv = dev->dev_private;
  2254. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2255. int pipe = intel_crtc->pipe;
  2256. u32 reg, temp, i, retry;
  2257. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2258. for train result */
  2259. reg = FDI_RX_IMR(pipe);
  2260. temp = I915_READ(reg);
  2261. temp &= ~FDI_RX_SYMBOL_LOCK;
  2262. temp &= ~FDI_RX_BIT_LOCK;
  2263. I915_WRITE(reg, temp);
  2264. POSTING_READ(reg);
  2265. udelay(150);
  2266. /* enable CPU FDI TX and PCH FDI RX */
  2267. reg = FDI_TX_CTL(pipe);
  2268. temp = I915_READ(reg);
  2269. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2270. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2271. temp &= ~FDI_LINK_TRAIN_NONE;
  2272. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2273. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2274. /* SNB-B */
  2275. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2276. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2277. I915_WRITE(FDI_RX_MISC(pipe),
  2278. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2279. reg = FDI_RX_CTL(pipe);
  2280. temp = I915_READ(reg);
  2281. if (HAS_PCH_CPT(dev)) {
  2282. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2283. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2284. } else {
  2285. temp &= ~FDI_LINK_TRAIN_NONE;
  2286. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2287. }
  2288. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2289. POSTING_READ(reg);
  2290. udelay(150);
  2291. for (i = 0; i < 4; i++) {
  2292. reg = FDI_TX_CTL(pipe);
  2293. temp = I915_READ(reg);
  2294. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2295. temp |= snb_b_fdi_train_param[i];
  2296. I915_WRITE(reg, temp);
  2297. POSTING_READ(reg);
  2298. udelay(500);
  2299. for (retry = 0; retry < 5; retry++) {
  2300. reg = FDI_RX_IIR(pipe);
  2301. temp = I915_READ(reg);
  2302. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2303. if (temp & FDI_RX_BIT_LOCK) {
  2304. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2305. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2306. break;
  2307. }
  2308. udelay(50);
  2309. }
  2310. if (retry < 5)
  2311. break;
  2312. }
  2313. if (i == 4)
  2314. DRM_ERROR("FDI train 1 fail!\n");
  2315. /* Train 2 */
  2316. reg = FDI_TX_CTL(pipe);
  2317. temp = I915_READ(reg);
  2318. temp &= ~FDI_LINK_TRAIN_NONE;
  2319. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2320. if (IS_GEN6(dev)) {
  2321. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2322. /* SNB-B */
  2323. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2324. }
  2325. I915_WRITE(reg, temp);
  2326. reg = FDI_RX_CTL(pipe);
  2327. temp = I915_READ(reg);
  2328. if (HAS_PCH_CPT(dev)) {
  2329. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2330. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2331. } else {
  2332. temp &= ~FDI_LINK_TRAIN_NONE;
  2333. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2334. }
  2335. I915_WRITE(reg, temp);
  2336. POSTING_READ(reg);
  2337. udelay(150);
  2338. for (i = 0; i < 4; i++) {
  2339. reg = FDI_TX_CTL(pipe);
  2340. temp = I915_READ(reg);
  2341. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2342. temp |= snb_b_fdi_train_param[i];
  2343. I915_WRITE(reg, temp);
  2344. POSTING_READ(reg);
  2345. udelay(500);
  2346. for (retry = 0; retry < 5; retry++) {
  2347. reg = FDI_RX_IIR(pipe);
  2348. temp = I915_READ(reg);
  2349. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2350. if (temp & FDI_RX_SYMBOL_LOCK) {
  2351. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2352. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2353. break;
  2354. }
  2355. udelay(50);
  2356. }
  2357. if (retry < 5)
  2358. break;
  2359. }
  2360. if (i == 4)
  2361. DRM_ERROR("FDI train 2 fail!\n");
  2362. DRM_DEBUG_KMS("FDI train done.\n");
  2363. }
  2364. /* Manual link training for Ivy Bridge A0 parts */
  2365. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2366. {
  2367. struct drm_device *dev = crtc->dev;
  2368. struct drm_i915_private *dev_priv = dev->dev_private;
  2369. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2370. int pipe = intel_crtc->pipe;
  2371. u32 reg, temp, i, j;
  2372. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2373. for train result */
  2374. reg = FDI_RX_IMR(pipe);
  2375. temp = I915_READ(reg);
  2376. temp &= ~FDI_RX_SYMBOL_LOCK;
  2377. temp &= ~FDI_RX_BIT_LOCK;
  2378. I915_WRITE(reg, temp);
  2379. POSTING_READ(reg);
  2380. udelay(150);
  2381. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2382. I915_READ(FDI_RX_IIR(pipe)));
  2383. /* Try each vswing and preemphasis setting twice before moving on */
  2384. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2385. /* disable first in case we need to retry */
  2386. reg = FDI_TX_CTL(pipe);
  2387. temp = I915_READ(reg);
  2388. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2389. temp &= ~FDI_TX_ENABLE;
  2390. I915_WRITE(reg, temp);
  2391. reg = FDI_RX_CTL(pipe);
  2392. temp = I915_READ(reg);
  2393. temp &= ~FDI_LINK_TRAIN_AUTO;
  2394. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2395. temp &= ~FDI_RX_ENABLE;
  2396. I915_WRITE(reg, temp);
  2397. /* enable CPU FDI TX and PCH FDI RX */
  2398. reg = FDI_TX_CTL(pipe);
  2399. temp = I915_READ(reg);
  2400. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2401. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2402. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2403. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2404. temp |= snb_b_fdi_train_param[j/2];
  2405. temp |= FDI_COMPOSITE_SYNC;
  2406. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2407. I915_WRITE(FDI_RX_MISC(pipe),
  2408. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2409. reg = FDI_RX_CTL(pipe);
  2410. temp = I915_READ(reg);
  2411. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2412. temp |= FDI_COMPOSITE_SYNC;
  2413. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2414. POSTING_READ(reg);
  2415. udelay(1); /* should be 0.5us */
  2416. for (i = 0; i < 4; i++) {
  2417. reg = FDI_RX_IIR(pipe);
  2418. temp = I915_READ(reg);
  2419. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2420. if (temp & FDI_RX_BIT_LOCK ||
  2421. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2422. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2423. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2424. i);
  2425. break;
  2426. }
  2427. udelay(1); /* should be 0.5us */
  2428. }
  2429. if (i == 4) {
  2430. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2431. continue;
  2432. }
  2433. /* Train 2 */
  2434. reg = FDI_TX_CTL(pipe);
  2435. temp = I915_READ(reg);
  2436. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2437. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2438. I915_WRITE(reg, temp);
  2439. reg = FDI_RX_CTL(pipe);
  2440. temp = I915_READ(reg);
  2441. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2442. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2443. I915_WRITE(reg, temp);
  2444. POSTING_READ(reg);
  2445. udelay(2); /* should be 1.5us */
  2446. for (i = 0; i < 4; i++) {
  2447. reg = FDI_RX_IIR(pipe);
  2448. temp = I915_READ(reg);
  2449. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2450. if (temp & FDI_RX_SYMBOL_LOCK ||
  2451. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2452. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2453. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2454. i);
  2455. goto train_done;
  2456. }
  2457. udelay(2); /* should be 1.5us */
  2458. }
  2459. if (i == 4)
  2460. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2461. }
  2462. train_done:
  2463. DRM_DEBUG_KMS("FDI train done.\n");
  2464. }
  2465. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2466. {
  2467. struct drm_device *dev = intel_crtc->base.dev;
  2468. struct drm_i915_private *dev_priv = dev->dev_private;
  2469. int pipe = intel_crtc->pipe;
  2470. u32 reg, temp;
  2471. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2472. reg = FDI_RX_CTL(pipe);
  2473. temp = I915_READ(reg);
  2474. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2475. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2476. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2477. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2478. POSTING_READ(reg);
  2479. udelay(200);
  2480. /* Switch from Rawclk to PCDclk */
  2481. temp = I915_READ(reg);
  2482. I915_WRITE(reg, temp | FDI_PCDCLK);
  2483. POSTING_READ(reg);
  2484. udelay(200);
  2485. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2486. reg = FDI_TX_CTL(pipe);
  2487. temp = I915_READ(reg);
  2488. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2489. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2490. POSTING_READ(reg);
  2491. udelay(100);
  2492. }
  2493. }
  2494. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2495. {
  2496. struct drm_device *dev = intel_crtc->base.dev;
  2497. struct drm_i915_private *dev_priv = dev->dev_private;
  2498. int pipe = intel_crtc->pipe;
  2499. u32 reg, temp;
  2500. /* Switch from PCDclk to Rawclk */
  2501. reg = FDI_RX_CTL(pipe);
  2502. temp = I915_READ(reg);
  2503. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2504. /* Disable CPU FDI TX PLL */
  2505. reg = FDI_TX_CTL(pipe);
  2506. temp = I915_READ(reg);
  2507. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2508. POSTING_READ(reg);
  2509. udelay(100);
  2510. reg = FDI_RX_CTL(pipe);
  2511. temp = I915_READ(reg);
  2512. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2513. /* Wait for the clocks to turn off. */
  2514. POSTING_READ(reg);
  2515. udelay(100);
  2516. }
  2517. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2518. {
  2519. struct drm_device *dev = crtc->dev;
  2520. struct drm_i915_private *dev_priv = dev->dev_private;
  2521. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2522. int pipe = intel_crtc->pipe;
  2523. u32 reg, temp;
  2524. /* disable CPU FDI tx and PCH FDI rx */
  2525. reg = FDI_TX_CTL(pipe);
  2526. temp = I915_READ(reg);
  2527. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2528. POSTING_READ(reg);
  2529. reg = FDI_RX_CTL(pipe);
  2530. temp = I915_READ(reg);
  2531. temp &= ~(0x7 << 16);
  2532. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2533. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2534. POSTING_READ(reg);
  2535. udelay(100);
  2536. /* Ironlake workaround, disable clock pointer after downing FDI */
  2537. if (HAS_PCH_IBX(dev)) {
  2538. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2539. }
  2540. /* still set train pattern 1 */
  2541. reg = FDI_TX_CTL(pipe);
  2542. temp = I915_READ(reg);
  2543. temp &= ~FDI_LINK_TRAIN_NONE;
  2544. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2545. I915_WRITE(reg, temp);
  2546. reg = FDI_RX_CTL(pipe);
  2547. temp = I915_READ(reg);
  2548. if (HAS_PCH_CPT(dev)) {
  2549. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2550. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2551. } else {
  2552. temp &= ~FDI_LINK_TRAIN_NONE;
  2553. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2554. }
  2555. /* BPC in FDI rx is consistent with that in PIPECONF */
  2556. temp &= ~(0x07 << 16);
  2557. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2558. I915_WRITE(reg, temp);
  2559. POSTING_READ(reg);
  2560. udelay(100);
  2561. }
  2562. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2563. {
  2564. struct drm_device *dev = crtc->dev;
  2565. struct drm_i915_private *dev_priv = dev->dev_private;
  2566. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2567. unsigned long flags;
  2568. bool pending;
  2569. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2570. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2571. return false;
  2572. spin_lock_irqsave(&dev->event_lock, flags);
  2573. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2574. spin_unlock_irqrestore(&dev->event_lock, flags);
  2575. return pending;
  2576. }
  2577. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2578. {
  2579. struct intel_crtc *crtc;
  2580. /* Note that we don't need to be called with mode_config.lock here
  2581. * as our list of CRTC objects is static for the lifetime of the
  2582. * device and so cannot disappear as we iterate. Similarly, we can
  2583. * happily treat the predicates as racy, atomic checks as userspace
  2584. * cannot claim and pin a new fb without at least acquring the
  2585. * struct_mutex and so serialising with us.
  2586. */
  2587. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
  2588. if (atomic_read(&crtc->unpin_work_count) == 0)
  2589. continue;
  2590. if (crtc->unpin_work)
  2591. intel_wait_for_vblank(dev, crtc->pipe);
  2592. return true;
  2593. }
  2594. return false;
  2595. }
  2596. static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2597. {
  2598. struct drm_device *dev = crtc->dev;
  2599. struct drm_i915_private *dev_priv = dev->dev_private;
  2600. if (crtc->fb == NULL)
  2601. return;
  2602. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2603. wait_event(dev_priv->pending_flip_queue,
  2604. !intel_crtc_has_pending_flip(crtc));
  2605. mutex_lock(&dev->struct_mutex);
  2606. intel_finish_fb(crtc->fb);
  2607. mutex_unlock(&dev->struct_mutex);
  2608. }
  2609. /* Program iCLKIP clock to the desired frequency */
  2610. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2611. {
  2612. struct drm_device *dev = crtc->dev;
  2613. struct drm_i915_private *dev_priv = dev->dev_private;
  2614. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2615. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2616. u32 temp;
  2617. mutex_lock(&dev_priv->dpio_lock);
  2618. /* It is necessary to ungate the pixclk gate prior to programming
  2619. * the divisors, and gate it back when it is done.
  2620. */
  2621. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2622. /* Disable SSCCTL */
  2623. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2624. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2625. SBI_SSCCTL_DISABLE,
  2626. SBI_ICLK);
  2627. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2628. if (clock == 20000) {
  2629. auxdiv = 1;
  2630. divsel = 0x41;
  2631. phaseinc = 0x20;
  2632. } else {
  2633. /* The iCLK virtual clock root frequency is in MHz,
  2634. * but the adjusted_mode->crtc_clock in in KHz. To get the
  2635. * divisors, it is necessary to divide one by another, so we
  2636. * convert the virtual clock precision to KHz here for higher
  2637. * precision.
  2638. */
  2639. u32 iclk_virtual_root_freq = 172800 * 1000;
  2640. u32 iclk_pi_range = 64;
  2641. u32 desired_divisor, msb_divisor_value, pi_value;
  2642. desired_divisor = (iclk_virtual_root_freq / clock);
  2643. msb_divisor_value = desired_divisor / iclk_pi_range;
  2644. pi_value = desired_divisor % iclk_pi_range;
  2645. auxdiv = 0;
  2646. divsel = msb_divisor_value - 2;
  2647. phaseinc = pi_value;
  2648. }
  2649. /* This should not happen with any sane values */
  2650. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  2651. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  2652. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  2653. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  2654. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  2655. clock,
  2656. auxdiv,
  2657. divsel,
  2658. phasedir,
  2659. phaseinc);
  2660. /* Program SSCDIVINTPHASE6 */
  2661. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  2662. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  2663. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  2664. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  2665. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  2666. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  2667. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  2668. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  2669. /* Program SSCAUXDIV */
  2670. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  2671. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  2672. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  2673. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  2674. /* Enable modulator and associated divider */
  2675. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  2676. temp &= ~SBI_SSCCTL_DISABLE;
  2677. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  2678. /* Wait for initialization time */
  2679. udelay(24);
  2680. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  2681. mutex_unlock(&dev_priv->dpio_lock);
  2682. }
  2683. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  2684. enum pipe pch_transcoder)
  2685. {
  2686. struct drm_device *dev = crtc->base.dev;
  2687. struct drm_i915_private *dev_priv = dev->dev_private;
  2688. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  2689. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  2690. I915_READ(HTOTAL(cpu_transcoder)));
  2691. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  2692. I915_READ(HBLANK(cpu_transcoder)));
  2693. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  2694. I915_READ(HSYNC(cpu_transcoder)));
  2695. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  2696. I915_READ(VTOTAL(cpu_transcoder)));
  2697. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  2698. I915_READ(VBLANK(cpu_transcoder)));
  2699. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  2700. I915_READ(VSYNC(cpu_transcoder)));
  2701. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  2702. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  2703. }
  2704. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  2705. {
  2706. struct drm_i915_private *dev_priv = dev->dev_private;
  2707. uint32_t temp;
  2708. temp = I915_READ(SOUTH_CHICKEN1);
  2709. if (temp & FDI_BC_BIFURCATION_SELECT)
  2710. return;
  2711. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2712. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2713. temp |= FDI_BC_BIFURCATION_SELECT;
  2714. DRM_DEBUG_KMS("enabling fdi C rx\n");
  2715. I915_WRITE(SOUTH_CHICKEN1, temp);
  2716. POSTING_READ(SOUTH_CHICKEN1);
  2717. }
  2718. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  2719. {
  2720. struct drm_device *dev = intel_crtc->base.dev;
  2721. struct drm_i915_private *dev_priv = dev->dev_private;
  2722. switch (intel_crtc->pipe) {
  2723. case PIPE_A:
  2724. break;
  2725. case PIPE_B:
  2726. if (intel_crtc->config.fdi_lanes > 2)
  2727. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  2728. else
  2729. cpt_enable_fdi_bc_bifurcation(dev);
  2730. break;
  2731. case PIPE_C:
  2732. cpt_enable_fdi_bc_bifurcation(dev);
  2733. break;
  2734. default:
  2735. BUG();
  2736. }
  2737. }
  2738. /*
  2739. * Enable PCH resources required for PCH ports:
  2740. * - PCH PLLs
  2741. * - FDI training & RX/TX
  2742. * - update transcoder timings
  2743. * - DP transcoding bits
  2744. * - transcoder
  2745. */
  2746. static void ironlake_pch_enable(struct drm_crtc *crtc)
  2747. {
  2748. struct drm_device *dev = crtc->dev;
  2749. struct drm_i915_private *dev_priv = dev->dev_private;
  2750. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2751. int pipe = intel_crtc->pipe;
  2752. u32 reg, temp;
  2753. assert_pch_transcoder_disabled(dev_priv, pipe);
  2754. if (IS_IVYBRIDGE(dev))
  2755. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  2756. /* Write the TU size bits before fdi link training, so that error
  2757. * detection works. */
  2758. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  2759. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  2760. /* For PCH output, training FDI link */
  2761. dev_priv->display.fdi_link_train(crtc);
  2762. /* We need to program the right clock selection before writing the pixel
  2763. * mutliplier into the DPLL. */
  2764. if (HAS_PCH_CPT(dev)) {
  2765. u32 sel;
  2766. temp = I915_READ(PCH_DPLL_SEL);
  2767. temp |= TRANS_DPLL_ENABLE(pipe);
  2768. sel = TRANS_DPLLB_SEL(pipe);
  2769. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  2770. temp |= sel;
  2771. else
  2772. temp &= ~sel;
  2773. I915_WRITE(PCH_DPLL_SEL, temp);
  2774. }
  2775. /* XXX: pch pll's can be enabled any time before we enable the PCH
  2776. * transcoder, and we actually should do this to not upset any PCH
  2777. * transcoder that already use the clock when we share it.
  2778. *
  2779. * Note that enable_shared_dpll tries to do the right thing, but
  2780. * get_shared_dpll unconditionally resets the pll - we need that to have
  2781. * the right LVDS enable sequence. */
  2782. ironlake_enable_shared_dpll(intel_crtc);
  2783. /* set transcoder timing, panel must allow it */
  2784. assert_panel_unlocked(dev_priv, pipe);
  2785. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  2786. intel_fdi_normal_train(crtc);
  2787. /* For PCH DP, enable TRANS_DP_CTL */
  2788. if (HAS_PCH_CPT(dev) &&
  2789. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  2790. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2791. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  2792. reg = TRANS_DP_CTL(pipe);
  2793. temp = I915_READ(reg);
  2794. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  2795. TRANS_DP_SYNC_MASK |
  2796. TRANS_DP_BPC_MASK);
  2797. temp |= (TRANS_DP_OUTPUT_ENABLE |
  2798. TRANS_DP_ENH_FRAMING);
  2799. temp |= bpc << 9; /* same format but at 11:9 */
  2800. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  2801. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  2802. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  2803. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  2804. switch (intel_trans_dp_port_sel(crtc)) {
  2805. case PCH_DP_B:
  2806. temp |= TRANS_DP_PORT_SEL_B;
  2807. break;
  2808. case PCH_DP_C:
  2809. temp |= TRANS_DP_PORT_SEL_C;
  2810. break;
  2811. case PCH_DP_D:
  2812. temp |= TRANS_DP_PORT_SEL_D;
  2813. break;
  2814. default:
  2815. BUG();
  2816. }
  2817. I915_WRITE(reg, temp);
  2818. }
  2819. ironlake_enable_pch_transcoder(dev_priv, pipe);
  2820. }
  2821. static void lpt_pch_enable(struct drm_crtc *crtc)
  2822. {
  2823. struct drm_device *dev = crtc->dev;
  2824. struct drm_i915_private *dev_priv = dev->dev_private;
  2825. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2826. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  2827. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  2828. lpt_program_iclkip(crtc);
  2829. /* Set transcoder timing. */
  2830. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  2831. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  2832. }
  2833. static void intel_put_shared_dpll(struct intel_crtc *crtc)
  2834. {
  2835. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  2836. if (pll == NULL)
  2837. return;
  2838. if (pll->refcount == 0) {
  2839. WARN(1, "bad %s refcount\n", pll->name);
  2840. return;
  2841. }
  2842. if (--pll->refcount == 0) {
  2843. WARN_ON(pll->on);
  2844. WARN_ON(pll->active);
  2845. }
  2846. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  2847. }
  2848. static struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  2849. {
  2850. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  2851. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  2852. enum intel_dpll_id i;
  2853. if (pll) {
  2854. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  2855. crtc->base.base.id, pll->name);
  2856. intel_put_shared_dpll(crtc);
  2857. }
  2858. if (HAS_PCH_IBX(dev_priv->dev)) {
  2859. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  2860. i = (enum intel_dpll_id) crtc->pipe;
  2861. pll = &dev_priv->shared_dplls[i];
  2862. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  2863. crtc->base.base.id, pll->name);
  2864. goto found;
  2865. }
  2866. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  2867. pll = &dev_priv->shared_dplls[i];
  2868. /* Only want to check enabled timings first */
  2869. if (pll->refcount == 0)
  2870. continue;
  2871. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  2872. sizeof(pll->hw_state)) == 0) {
  2873. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  2874. crtc->base.base.id,
  2875. pll->name, pll->refcount, pll->active);
  2876. goto found;
  2877. }
  2878. }
  2879. /* Ok no matching timings, maybe there's a free one? */
  2880. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  2881. pll = &dev_priv->shared_dplls[i];
  2882. if (pll->refcount == 0) {
  2883. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  2884. crtc->base.base.id, pll->name);
  2885. goto found;
  2886. }
  2887. }
  2888. return NULL;
  2889. found:
  2890. crtc->config.shared_dpll = i;
  2891. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  2892. pipe_name(crtc->pipe));
  2893. if (pll->active == 0) {
  2894. memcpy(&pll->hw_state, &crtc->config.dpll_hw_state,
  2895. sizeof(pll->hw_state));
  2896. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  2897. WARN_ON(pll->on);
  2898. assert_shared_dpll_disabled(dev_priv, pll);
  2899. pll->mode_set(dev_priv, pll);
  2900. }
  2901. pll->refcount++;
  2902. return pll;
  2903. }
  2904. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  2905. {
  2906. struct drm_i915_private *dev_priv = dev->dev_private;
  2907. int dslreg = PIPEDSL(pipe);
  2908. u32 temp;
  2909. temp = I915_READ(dslreg);
  2910. udelay(500);
  2911. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  2912. if (wait_for(I915_READ(dslreg) != temp, 5))
  2913. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  2914. }
  2915. }
  2916. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  2917. {
  2918. struct drm_device *dev = crtc->base.dev;
  2919. struct drm_i915_private *dev_priv = dev->dev_private;
  2920. int pipe = crtc->pipe;
  2921. if (crtc->config.pch_pfit.enabled) {
  2922. /* Force use of hard-coded filter coefficients
  2923. * as some pre-programmed values are broken,
  2924. * e.g. x201.
  2925. */
  2926. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  2927. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  2928. PF_PIPE_SEL_IVB(pipe));
  2929. else
  2930. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  2931. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  2932. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  2933. }
  2934. }
  2935. static void intel_enable_planes(struct drm_crtc *crtc)
  2936. {
  2937. struct drm_device *dev = crtc->dev;
  2938. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  2939. struct intel_plane *intel_plane;
  2940. list_for_each_entry(intel_plane, &dev->mode_config.plane_list, base.head)
  2941. if (intel_plane->pipe == pipe)
  2942. intel_plane_restore(&intel_plane->base);
  2943. }
  2944. static void intel_disable_planes(struct drm_crtc *crtc)
  2945. {
  2946. struct drm_device *dev = crtc->dev;
  2947. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  2948. struct intel_plane *intel_plane;
  2949. list_for_each_entry(intel_plane, &dev->mode_config.plane_list, base.head)
  2950. if (intel_plane->pipe == pipe)
  2951. intel_plane_disable(&intel_plane->base);
  2952. }
  2953. void hsw_enable_ips(struct intel_crtc *crtc)
  2954. {
  2955. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  2956. if (!crtc->config.ips_enabled)
  2957. return;
  2958. /* We can only enable IPS after we enable a plane and wait for a vblank.
  2959. * We guarantee that the plane is enabled by calling intel_enable_ips
  2960. * only after intel_enable_plane. And intel_enable_plane already waits
  2961. * for a vblank, so all we need to do here is to enable the IPS bit. */
  2962. assert_plane_enabled(dev_priv, crtc->plane);
  2963. if (IS_BROADWELL(crtc->base.dev)) {
  2964. mutex_lock(&dev_priv->rps.hw_lock);
  2965. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  2966. mutex_unlock(&dev_priv->rps.hw_lock);
  2967. /* Quoting Art Runyan: "its not safe to expect any particular
  2968. * value in IPS_CTL bit 31 after enabling IPS through the
  2969. * mailbox." Moreover, the mailbox may return a bogus state,
  2970. * so we need to just enable it and continue on.
  2971. */
  2972. } else {
  2973. I915_WRITE(IPS_CTL, IPS_ENABLE);
  2974. /* The bit only becomes 1 in the next vblank, so this wait here
  2975. * is essentially intel_wait_for_vblank. If we don't have this
  2976. * and don't wait for vblanks until the end of crtc_enable, then
  2977. * the HW state readout code will complain that the expected
  2978. * IPS_CTL value is not the one we read. */
  2979. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  2980. DRM_ERROR("Timed out waiting for IPS enable\n");
  2981. }
  2982. }
  2983. void hsw_disable_ips(struct intel_crtc *crtc)
  2984. {
  2985. struct drm_device *dev = crtc->base.dev;
  2986. struct drm_i915_private *dev_priv = dev->dev_private;
  2987. if (!crtc->config.ips_enabled)
  2988. return;
  2989. assert_plane_enabled(dev_priv, crtc->plane);
  2990. if (IS_BROADWELL(crtc->base.dev)) {
  2991. mutex_lock(&dev_priv->rps.hw_lock);
  2992. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  2993. mutex_unlock(&dev_priv->rps.hw_lock);
  2994. } else {
  2995. I915_WRITE(IPS_CTL, 0);
  2996. POSTING_READ(IPS_CTL);
  2997. }
  2998. /* We need to wait for a vblank before we can disable the plane. */
  2999. intel_wait_for_vblank(dev, crtc->pipe);
  3000. }
  3001. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3002. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3003. {
  3004. struct drm_device *dev = crtc->dev;
  3005. struct drm_i915_private *dev_priv = dev->dev_private;
  3006. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3007. enum pipe pipe = intel_crtc->pipe;
  3008. int palreg = PALETTE(pipe);
  3009. int i;
  3010. bool reenable_ips = false;
  3011. /* The clocks have to be on to load the palette. */
  3012. if (!crtc->enabled || !intel_crtc->active)
  3013. return;
  3014. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3015. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3016. assert_dsi_pll_enabled(dev_priv);
  3017. else
  3018. assert_pll_enabled(dev_priv, pipe);
  3019. }
  3020. /* use legacy palette for Ironlake */
  3021. if (HAS_PCH_SPLIT(dev))
  3022. palreg = LGC_PALETTE(pipe);
  3023. /* Workaround : Do not read or write the pipe palette/gamma data while
  3024. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3025. */
  3026. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3027. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3028. GAMMA_MODE_MODE_SPLIT)) {
  3029. hsw_disable_ips(intel_crtc);
  3030. reenable_ips = true;
  3031. }
  3032. for (i = 0; i < 256; i++) {
  3033. I915_WRITE(palreg + 4 * i,
  3034. (intel_crtc->lut_r[i] << 16) |
  3035. (intel_crtc->lut_g[i] << 8) |
  3036. intel_crtc->lut_b[i]);
  3037. }
  3038. if (reenable_ips)
  3039. hsw_enable_ips(intel_crtc);
  3040. }
  3041. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3042. {
  3043. struct drm_device *dev = crtc->dev;
  3044. struct drm_i915_private *dev_priv = dev->dev_private;
  3045. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3046. struct intel_encoder *encoder;
  3047. int pipe = intel_crtc->pipe;
  3048. int plane = intel_crtc->plane;
  3049. WARN_ON(!crtc->enabled);
  3050. if (intel_crtc->active)
  3051. return;
  3052. intel_crtc->active = true;
  3053. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3054. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3055. for_each_encoder_on_crtc(dev, crtc, encoder)
  3056. if (encoder->pre_enable)
  3057. encoder->pre_enable(encoder);
  3058. if (intel_crtc->config.has_pch_encoder) {
  3059. /* Note: FDI PLL enabling _must_ be done before we enable the
  3060. * cpu pipes, hence this is separate from all the other fdi/pch
  3061. * enabling. */
  3062. ironlake_fdi_pll_enable(intel_crtc);
  3063. } else {
  3064. assert_fdi_tx_disabled(dev_priv, pipe);
  3065. assert_fdi_rx_disabled(dev_priv, pipe);
  3066. }
  3067. ironlake_pfit_enable(intel_crtc);
  3068. /*
  3069. * On ILK+ LUT must be loaded before the pipe is running but with
  3070. * clocks enabled
  3071. */
  3072. intel_crtc_load_lut(crtc);
  3073. intel_update_watermarks(crtc);
  3074. intel_enable_pipe(dev_priv, pipe,
  3075. intel_crtc->config.has_pch_encoder, false);
  3076. intel_enable_primary_plane(dev_priv, plane, pipe);
  3077. intel_enable_planes(crtc);
  3078. intel_crtc_update_cursor(crtc, true);
  3079. if (intel_crtc->config.has_pch_encoder)
  3080. ironlake_pch_enable(crtc);
  3081. mutex_lock(&dev->struct_mutex);
  3082. intel_update_fbc(dev);
  3083. mutex_unlock(&dev->struct_mutex);
  3084. for_each_encoder_on_crtc(dev, crtc, encoder)
  3085. encoder->enable(encoder);
  3086. if (HAS_PCH_CPT(dev))
  3087. cpt_verify_modeset(dev, intel_crtc->pipe);
  3088. /*
  3089. * There seems to be a race in PCH platform hw (at least on some
  3090. * outputs) where an enabled pipe still completes any pageflip right
  3091. * away (as if the pipe is off) instead of waiting for vblank. As soon
  3092. * as the first vblank happend, everything works as expected. Hence just
  3093. * wait for one vblank before returning to avoid strange things
  3094. * happening.
  3095. */
  3096. intel_wait_for_vblank(dev, intel_crtc->pipe);
  3097. }
  3098. /* IPS only exists on ULT machines and is tied to pipe A. */
  3099. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3100. {
  3101. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3102. }
  3103. static void haswell_crtc_enable_planes(struct drm_crtc *crtc)
  3104. {
  3105. struct drm_device *dev = crtc->dev;
  3106. struct drm_i915_private *dev_priv = dev->dev_private;
  3107. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3108. int pipe = intel_crtc->pipe;
  3109. int plane = intel_crtc->plane;
  3110. intel_enable_primary_plane(dev_priv, plane, pipe);
  3111. intel_enable_planes(crtc);
  3112. intel_crtc_update_cursor(crtc, true);
  3113. hsw_enable_ips(intel_crtc);
  3114. mutex_lock(&dev->struct_mutex);
  3115. intel_update_fbc(dev);
  3116. mutex_unlock(&dev->struct_mutex);
  3117. }
  3118. static void haswell_crtc_disable_planes(struct drm_crtc *crtc)
  3119. {
  3120. struct drm_device *dev = crtc->dev;
  3121. struct drm_i915_private *dev_priv = dev->dev_private;
  3122. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3123. int pipe = intel_crtc->pipe;
  3124. int plane = intel_crtc->plane;
  3125. intel_crtc_wait_for_pending_flips(crtc);
  3126. drm_vblank_off(dev, pipe);
  3127. /* FBC must be disabled before disabling the plane on HSW. */
  3128. if (dev_priv->fbc.plane == plane)
  3129. intel_disable_fbc(dev);
  3130. hsw_disable_ips(intel_crtc);
  3131. intel_crtc_update_cursor(crtc, false);
  3132. intel_disable_planes(crtc);
  3133. intel_disable_primary_plane(dev_priv, plane, pipe);
  3134. }
  3135. /*
  3136. * This implements the workaround described in the "notes" section of the mode
  3137. * set sequence documentation. When going from no pipes or single pipe to
  3138. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3139. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3140. */
  3141. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3142. {
  3143. struct drm_device *dev = crtc->base.dev;
  3144. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3145. /* We want to get the other_active_crtc only if there's only 1 other
  3146. * active crtc. */
  3147. list_for_each_entry(crtc_it, &dev->mode_config.crtc_list, base.head) {
  3148. if (!crtc_it->active || crtc_it == crtc)
  3149. continue;
  3150. if (other_active_crtc)
  3151. return;
  3152. other_active_crtc = crtc_it;
  3153. }
  3154. if (!other_active_crtc)
  3155. return;
  3156. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3157. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3158. }
  3159. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3160. {
  3161. struct drm_device *dev = crtc->dev;
  3162. struct drm_i915_private *dev_priv = dev->dev_private;
  3163. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3164. struct intel_encoder *encoder;
  3165. int pipe = intel_crtc->pipe;
  3166. WARN_ON(!crtc->enabled);
  3167. if (intel_crtc->active)
  3168. return;
  3169. intel_crtc->active = true;
  3170. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3171. if (intel_crtc->config.has_pch_encoder)
  3172. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3173. if (intel_crtc->config.has_pch_encoder)
  3174. dev_priv->display.fdi_link_train(crtc);
  3175. for_each_encoder_on_crtc(dev, crtc, encoder)
  3176. if (encoder->pre_enable)
  3177. encoder->pre_enable(encoder);
  3178. intel_ddi_enable_pipe_clock(intel_crtc);
  3179. ironlake_pfit_enable(intel_crtc);
  3180. /*
  3181. * On ILK+ LUT must be loaded before the pipe is running but with
  3182. * clocks enabled
  3183. */
  3184. intel_crtc_load_lut(crtc);
  3185. intel_ddi_set_pipe_settings(crtc);
  3186. intel_ddi_enable_transcoder_func(crtc);
  3187. intel_update_watermarks(crtc);
  3188. intel_enable_pipe(dev_priv, pipe,
  3189. intel_crtc->config.has_pch_encoder, false);
  3190. if (intel_crtc->config.has_pch_encoder)
  3191. lpt_pch_enable(crtc);
  3192. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3193. encoder->enable(encoder);
  3194. intel_opregion_notify_encoder(encoder, true);
  3195. }
  3196. /* If we change the relative order between pipe/planes enabling, we need
  3197. * to change the workaround. */
  3198. haswell_mode_set_planes_workaround(intel_crtc);
  3199. haswell_crtc_enable_planes(crtc);
  3200. /*
  3201. * There seems to be a race in PCH platform hw (at least on some
  3202. * outputs) where an enabled pipe still completes any pageflip right
  3203. * away (as if the pipe is off) instead of waiting for vblank. As soon
  3204. * as the first vblank happend, everything works as expected. Hence just
  3205. * wait for one vblank before returning to avoid strange things
  3206. * happening.
  3207. */
  3208. intel_wait_for_vblank(dev, intel_crtc->pipe);
  3209. }
  3210. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3211. {
  3212. struct drm_device *dev = crtc->base.dev;
  3213. struct drm_i915_private *dev_priv = dev->dev_private;
  3214. int pipe = crtc->pipe;
  3215. /* To avoid upsetting the power well on haswell only disable the pfit if
  3216. * it's in use. The hw state code will make sure we get this right. */
  3217. if (crtc->config.pch_pfit.enabled) {
  3218. I915_WRITE(PF_CTL(pipe), 0);
  3219. I915_WRITE(PF_WIN_POS(pipe), 0);
  3220. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3221. }
  3222. }
  3223. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3224. {
  3225. struct drm_device *dev = crtc->dev;
  3226. struct drm_i915_private *dev_priv = dev->dev_private;
  3227. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3228. struct intel_encoder *encoder;
  3229. int pipe = intel_crtc->pipe;
  3230. int plane = intel_crtc->plane;
  3231. u32 reg, temp;
  3232. if (!intel_crtc->active)
  3233. return;
  3234. for_each_encoder_on_crtc(dev, crtc, encoder)
  3235. encoder->disable(encoder);
  3236. intel_crtc_wait_for_pending_flips(crtc);
  3237. drm_vblank_off(dev, pipe);
  3238. if (dev_priv->fbc.plane == plane)
  3239. intel_disable_fbc(dev);
  3240. intel_crtc_update_cursor(crtc, false);
  3241. intel_disable_planes(crtc);
  3242. intel_disable_primary_plane(dev_priv, plane, pipe);
  3243. if (intel_crtc->config.has_pch_encoder)
  3244. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3245. intel_disable_pipe(dev_priv, pipe);
  3246. ironlake_pfit_disable(intel_crtc);
  3247. for_each_encoder_on_crtc(dev, crtc, encoder)
  3248. if (encoder->post_disable)
  3249. encoder->post_disable(encoder);
  3250. if (intel_crtc->config.has_pch_encoder) {
  3251. ironlake_fdi_disable(crtc);
  3252. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3253. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3254. if (HAS_PCH_CPT(dev)) {
  3255. /* disable TRANS_DP_CTL */
  3256. reg = TRANS_DP_CTL(pipe);
  3257. temp = I915_READ(reg);
  3258. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3259. TRANS_DP_PORT_SEL_MASK);
  3260. temp |= TRANS_DP_PORT_SEL_NONE;
  3261. I915_WRITE(reg, temp);
  3262. /* disable DPLL_SEL */
  3263. temp = I915_READ(PCH_DPLL_SEL);
  3264. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3265. I915_WRITE(PCH_DPLL_SEL, temp);
  3266. }
  3267. /* disable PCH DPLL */
  3268. intel_disable_shared_dpll(intel_crtc);
  3269. ironlake_fdi_pll_disable(intel_crtc);
  3270. }
  3271. intel_crtc->active = false;
  3272. intel_update_watermarks(crtc);
  3273. mutex_lock(&dev->struct_mutex);
  3274. intel_update_fbc(dev);
  3275. mutex_unlock(&dev->struct_mutex);
  3276. }
  3277. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3278. {
  3279. struct drm_device *dev = crtc->dev;
  3280. struct drm_i915_private *dev_priv = dev->dev_private;
  3281. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3282. struct intel_encoder *encoder;
  3283. int pipe = intel_crtc->pipe;
  3284. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3285. if (!intel_crtc->active)
  3286. return;
  3287. haswell_crtc_disable_planes(crtc);
  3288. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3289. intel_opregion_notify_encoder(encoder, false);
  3290. encoder->disable(encoder);
  3291. }
  3292. if (intel_crtc->config.has_pch_encoder)
  3293. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3294. intel_disable_pipe(dev_priv, pipe);
  3295. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3296. ironlake_pfit_disable(intel_crtc);
  3297. intel_ddi_disable_pipe_clock(intel_crtc);
  3298. for_each_encoder_on_crtc(dev, crtc, encoder)
  3299. if (encoder->post_disable)
  3300. encoder->post_disable(encoder);
  3301. if (intel_crtc->config.has_pch_encoder) {
  3302. lpt_disable_pch_transcoder(dev_priv);
  3303. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3304. intel_ddi_fdi_disable(crtc);
  3305. }
  3306. intel_crtc->active = false;
  3307. intel_update_watermarks(crtc);
  3308. mutex_lock(&dev->struct_mutex);
  3309. intel_update_fbc(dev);
  3310. mutex_unlock(&dev->struct_mutex);
  3311. }
  3312. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3313. {
  3314. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3315. intel_put_shared_dpll(intel_crtc);
  3316. }
  3317. static void haswell_crtc_off(struct drm_crtc *crtc)
  3318. {
  3319. intel_ddi_put_crtc_pll(crtc);
  3320. }
  3321. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3322. {
  3323. if (!enable && intel_crtc->overlay) {
  3324. struct drm_device *dev = intel_crtc->base.dev;
  3325. struct drm_i915_private *dev_priv = dev->dev_private;
  3326. mutex_lock(&dev->struct_mutex);
  3327. dev_priv->mm.interruptible = false;
  3328. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3329. dev_priv->mm.interruptible = true;
  3330. mutex_unlock(&dev->struct_mutex);
  3331. }
  3332. /* Let userspace switch the overlay on again. In most cases userspace
  3333. * has to recompute where to put it anyway.
  3334. */
  3335. }
  3336. /**
  3337. * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
  3338. * cursor plane briefly if not already running after enabling the display
  3339. * plane.
  3340. * This workaround avoids occasional blank screens when self refresh is
  3341. * enabled.
  3342. */
  3343. static void
  3344. g4x_fixup_plane(struct drm_i915_private *dev_priv, enum pipe pipe)
  3345. {
  3346. u32 cntl = I915_READ(CURCNTR(pipe));
  3347. if ((cntl & CURSOR_MODE) == 0) {
  3348. u32 fw_bcl_self = I915_READ(FW_BLC_SELF);
  3349. I915_WRITE(FW_BLC_SELF, fw_bcl_self & ~FW_BLC_SELF_EN);
  3350. I915_WRITE(CURCNTR(pipe), CURSOR_MODE_64_ARGB_AX);
  3351. intel_wait_for_vblank(dev_priv->dev, pipe);
  3352. I915_WRITE(CURCNTR(pipe), cntl);
  3353. I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe)));
  3354. I915_WRITE(FW_BLC_SELF, fw_bcl_self);
  3355. }
  3356. }
  3357. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3358. {
  3359. struct drm_device *dev = crtc->base.dev;
  3360. struct drm_i915_private *dev_priv = dev->dev_private;
  3361. struct intel_crtc_config *pipe_config = &crtc->config;
  3362. if (!crtc->config.gmch_pfit.control)
  3363. return;
  3364. /*
  3365. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3366. * according to register description and PRM.
  3367. */
  3368. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3369. assert_pipe_disabled(dev_priv, crtc->pipe);
  3370. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3371. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3372. /* Border color in case we don't scale up to the full screen. Black by
  3373. * default, change to something else for debugging. */
  3374. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3375. }
  3376. int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3377. {
  3378. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3379. /* Obtain SKU information */
  3380. mutex_lock(&dev_priv->dpio_lock);
  3381. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3382. CCK_FUSE_HPLL_FREQ_MASK;
  3383. mutex_unlock(&dev_priv->dpio_lock);
  3384. return vco_freq[hpll_freq];
  3385. }
  3386. /* Adjust CDclk dividers to allow high res or save power if possible */
  3387. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3388. {
  3389. struct drm_i915_private *dev_priv = dev->dev_private;
  3390. u32 val, cmd;
  3391. if (cdclk >= 320) /* jump to highest voltage for 400MHz too */
  3392. cmd = 2;
  3393. else if (cdclk == 266)
  3394. cmd = 1;
  3395. else
  3396. cmd = 0;
  3397. mutex_lock(&dev_priv->rps.hw_lock);
  3398. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3399. val &= ~DSPFREQGUAR_MASK;
  3400. val |= (cmd << DSPFREQGUAR_SHIFT);
  3401. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3402. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3403. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3404. 50)) {
  3405. DRM_ERROR("timed out waiting for CDclk change\n");
  3406. }
  3407. mutex_unlock(&dev_priv->rps.hw_lock);
  3408. if (cdclk == 400) {
  3409. u32 divider, vco;
  3410. vco = valleyview_get_vco(dev_priv);
  3411. divider = ((vco << 1) / cdclk) - 1;
  3412. mutex_lock(&dev_priv->dpio_lock);
  3413. /* adjust cdclk divider */
  3414. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3415. val &= ~0xf;
  3416. val |= divider;
  3417. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3418. mutex_unlock(&dev_priv->dpio_lock);
  3419. }
  3420. mutex_lock(&dev_priv->dpio_lock);
  3421. /* adjust self-refresh exit latency value */
  3422. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3423. val &= ~0x7f;
  3424. /*
  3425. * For high bandwidth configs, we set a higher latency in the bunit
  3426. * so that the core display fetch happens in time to avoid underruns.
  3427. */
  3428. if (cdclk == 400)
  3429. val |= 4500 / 250; /* 4.5 usec */
  3430. else
  3431. val |= 3000 / 250; /* 3.0 usec */
  3432. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3433. mutex_unlock(&dev_priv->dpio_lock);
  3434. /* Since we changed the CDclk, we need to update the GMBUSFREQ too */
  3435. intel_i2c_reset(dev);
  3436. }
  3437. static int valleyview_cur_cdclk(struct drm_i915_private *dev_priv)
  3438. {
  3439. int cur_cdclk, vco;
  3440. int divider;
  3441. vco = valleyview_get_vco(dev_priv);
  3442. mutex_lock(&dev_priv->dpio_lock);
  3443. divider = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3444. mutex_unlock(&dev_priv->dpio_lock);
  3445. divider &= 0xf;
  3446. cur_cdclk = (vco << 1) / (divider + 1);
  3447. return cur_cdclk;
  3448. }
  3449. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3450. int max_pixclk)
  3451. {
  3452. int cur_cdclk;
  3453. cur_cdclk = valleyview_cur_cdclk(dev_priv);
  3454. /*
  3455. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3456. * 200MHz
  3457. * 267MHz
  3458. * 320MHz
  3459. * 400MHz
  3460. * So we check to see whether we're above 90% of the lower bin and
  3461. * adjust if needed.
  3462. */
  3463. if (max_pixclk > 288000) {
  3464. return 400;
  3465. } else if (max_pixclk > 240000) {
  3466. return 320;
  3467. } else
  3468. return 266;
  3469. /* Looks like the 200MHz CDclk freq doesn't work on some configs */
  3470. }
  3471. /* compute the max pixel clock for new configuration */
  3472. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3473. {
  3474. struct drm_device *dev = dev_priv->dev;
  3475. struct intel_crtc *intel_crtc;
  3476. int max_pixclk = 0;
  3477. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  3478. base.head) {
  3479. if (intel_crtc->new_enabled)
  3480. max_pixclk = max(max_pixclk,
  3481. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3482. }
  3483. return max_pixclk;
  3484. }
  3485. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  3486. unsigned *prepare_pipes)
  3487. {
  3488. struct drm_i915_private *dev_priv = dev->dev_private;
  3489. struct intel_crtc *intel_crtc;
  3490. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3491. int cur_cdclk = valleyview_cur_cdclk(dev_priv);
  3492. if (valleyview_calc_cdclk(dev_priv, max_pixclk) == cur_cdclk)
  3493. return;
  3494. /* disable/enable all currently active pipes while we change cdclk */
  3495. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  3496. base.head)
  3497. if (intel_crtc->base.enabled)
  3498. *prepare_pipes |= (1 << intel_crtc->pipe);
  3499. }
  3500. static void valleyview_modeset_global_resources(struct drm_device *dev)
  3501. {
  3502. struct drm_i915_private *dev_priv = dev->dev_private;
  3503. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3504. int cur_cdclk = valleyview_cur_cdclk(dev_priv);
  3505. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  3506. if (req_cdclk != cur_cdclk)
  3507. valleyview_set_cdclk(dev, req_cdclk);
  3508. }
  3509. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  3510. {
  3511. struct drm_device *dev = crtc->dev;
  3512. struct drm_i915_private *dev_priv = dev->dev_private;
  3513. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3514. struct intel_encoder *encoder;
  3515. int pipe = intel_crtc->pipe;
  3516. int plane = intel_crtc->plane;
  3517. bool is_dsi;
  3518. WARN_ON(!crtc->enabled);
  3519. if (intel_crtc->active)
  3520. return;
  3521. intel_crtc->active = true;
  3522. for_each_encoder_on_crtc(dev, crtc, encoder)
  3523. if (encoder->pre_pll_enable)
  3524. encoder->pre_pll_enable(encoder);
  3525. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  3526. if (!is_dsi)
  3527. vlv_enable_pll(intel_crtc);
  3528. for_each_encoder_on_crtc(dev, crtc, encoder)
  3529. if (encoder->pre_enable)
  3530. encoder->pre_enable(encoder);
  3531. i9xx_pfit_enable(intel_crtc);
  3532. intel_crtc_load_lut(crtc);
  3533. intel_update_watermarks(crtc);
  3534. intel_enable_pipe(dev_priv, pipe, false, is_dsi);
  3535. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3536. intel_enable_primary_plane(dev_priv, plane, pipe);
  3537. intel_enable_planes(crtc);
  3538. intel_crtc_update_cursor(crtc, true);
  3539. intel_update_fbc(dev);
  3540. for_each_encoder_on_crtc(dev, crtc, encoder)
  3541. encoder->enable(encoder);
  3542. }
  3543. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  3544. {
  3545. struct drm_device *dev = crtc->dev;
  3546. struct drm_i915_private *dev_priv = dev->dev_private;
  3547. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3548. struct intel_encoder *encoder;
  3549. int pipe = intel_crtc->pipe;
  3550. int plane = intel_crtc->plane;
  3551. WARN_ON(!crtc->enabled);
  3552. if (intel_crtc->active)
  3553. return;
  3554. intel_crtc->active = true;
  3555. for_each_encoder_on_crtc(dev, crtc, encoder)
  3556. if (encoder->pre_enable)
  3557. encoder->pre_enable(encoder);
  3558. i9xx_enable_pll(intel_crtc);
  3559. i9xx_pfit_enable(intel_crtc);
  3560. intel_crtc_load_lut(crtc);
  3561. intel_update_watermarks(crtc);
  3562. intel_enable_pipe(dev_priv, pipe, false, false);
  3563. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3564. intel_enable_primary_plane(dev_priv, plane, pipe);
  3565. intel_enable_planes(crtc);
  3566. /* The fixup needs to happen before cursor is enabled */
  3567. if (IS_G4X(dev))
  3568. g4x_fixup_plane(dev_priv, pipe);
  3569. intel_crtc_update_cursor(crtc, true);
  3570. /* Give the overlay scaler a chance to enable if it's on this pipe */
  3571. intel_crtc_dpms_overlay(intel_crtc, true);
  3572. intel_update_fbc(dev);
  3573. for_each_encoder_on_crtc(dev, crtc, encoder)
  3574. encoder->enable(encoder);
  3575. }
  3576. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  3577. {
  3578. struct drm_device *dev = crtc->base.dev;
  3579. struct drm_i915_private *dev_priv = dev->dev_private;
  3580. if (!crtc->config.gmch_pfit.control)
  3581. return;
  3582. assert_pipe_disabled(dev_priv, crtc->pipe);
  3583. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  3584. I915_READ(PFIT_CONTROL));
  3585. I915_WRITE(PFIT_CONTROL, 0);
  3586. }
  3587. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  3588. {
  3589. struct drm_device *dev = crtc->dev;
  3590. struct drm_i915_private *dev_priv = dev->dev_private;
  3591. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3592. struct intel_encoder *encoder;
  3593. int pipe = intel_crtc->pipe;
  3594. int plane = intel_crtc->plane;
  3595. if (!intel_crtc->active)
  3596. return;
  3597. for_each_encoder_on_crtc(dev, crtc, encoder)
  3598. encoder->disable(encoder);
  3599. /* Give the overlay scaler a chance to disable if it's on this pipe */
  3600. intel_crtc_wait_for_pending_flips(crtc);
  3601. drm_vblank_off(dev, pipe);
  3602. if (dev_priv->fbc.plane == plane)
  3603. intel_disable_fbc(dev);
  3604. intel_crtc_dpms_overlay(intel_crtc, false);
  3605. intel_crtc_update_cursor(crtc, false);
  3606. intel_disable_planes(crtc);
  3607. intel_disable_primary_plane(dev_priv, plane, pipe);
  3608. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  3609. intel_disable_pipe(dev_priv, pipe);
  3610. i9xx_pfit_disable(intel_crtc);
  3611. for_each_encoder_on_crtc(dev, crtc, encoder)
  3612. if (encoder->post_disable)
  3613. encoder->post_disable(encoder);
  3614. if (IS_VALLEYVIEW(dev) && !intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3615. vlv_disable_pll(dev_priv, pipe);
  3616. else if (!IS_VALLEYVIEW(dev))
  3617. i9xx_disable_pll(dev_priv, pipe);
  3618. intel_crtc->active = false;
  3619. intel_update_watermarks(crtc);
  3620. intel_update_fbc(dev);
  3621. }
  3622. static void i9xx_crtc_off(struct drm_crtc *crtc)
  3623. {
  3624. }
  3625. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  3626. bool enabled)
  3627. {
  3628. struct drm_device *dev = crtc->dev;
  3629. struct drm_i915_master_private *master_priv;
  3630. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3631. int pipe = intel_crtc->pipe;
  3632. if (!dev->primary->master)
  3633. return;
  3634. master_priv = dev->primary->master->driver_priv;
  3635. if (!master_priv->sarea_priv)
  3636. return;
  3637. switch (pipe) {
  3638. case 0:
  3639. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  3640. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  3641. break;
  3642. case 1:
  3643. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  3644. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  3645. break;
  3646. default:
  3647. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  3648. break;
  3649. }
  3650. }
  3651. /**
  3652. * Sets the power management mode of the pipe and plane.
  3653. */
  3654. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  3655. {
  3656. struct drm_device *dev = crtc->dev;
  3657. struct drm_i915_private *dev_priv = dev->dev_private;
  3658. struct intel_encoder *intel_encoder;
  3659. bool enable = false;
  3660. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3661. enable |= intel_encoder->connectors_active;
  3662. if (enable)
  3663. dev_priv->display.crtc_enable(crtc);
  3664. else
  3665. dev_priv->display.crtc_disable(crtc);
  3666. intel_crtc_update_sarea(crtc, enable);
  3667. }
  3668. static void intel_crtc_disable(struct drm_crtc *crtc)
  3669. {
  3670. struct drm_device *dev = crtc->dev;
  3671. struct drm_connector *connector;
  3672. struct drm_i915_private *dev_priv = dev->dev_private;
  3673. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3674. /* crtc should still be enabled when we disable it. */
  3675. WARN_ON(!crtc->enabled);
  3676. dev_priv->display.crtc_disable(crtc);
  3677. intel_crtc->eld_vld = false;
  3678. intel_crtc_update_sarea(crtc, false);
  3679. dev_priv->display.off(crtc);
  3680. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  3681. assert_cursor_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  3682. assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
  3683. if (crtc->fb) {
  3684. mutex_lock(&dev->struct_mutex);
  3685. intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
  3686. mutex_unlock(&dev->struct_mutex);
  3687. crtc->fb = NULL;
  3688. }
  3689. /* Update computed state. */
  3690. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  3691. if (!connector->encoder || !connector->encoder->crtc)
  3692. continue;
  3693. if (connector->encoder->crtc != crtc)
  3694. continue;
  3695. connector->dpms = DRM_MODE_DPMS_OFF;
  3696. to_intel_encoder(connector->encoder)->connectors_active = false;
  3697. }
  3698. }
  3699. void intel_encoder_destroy(struct drm_encoder *encoder)
  3700. {
  3701. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  3702. drm_encoder_cleanup(encoder);
  3703. kfree(intel_encoder);
  3704. }
  3705. /* Simple dpms helper for encoders with just one connector, no cloning and only
  3706. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  3707. * state of the entire output pipe. */
  3708. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  3709. {
  3710. if (mode == DRM_MODE_DPMS_ON) {
  3711. encoder->connectors_active = true;
  3712. intel_crtc_update_dpms(encoder->base.crtc);
  3713. } else {
  3714. encoder->connectors_active = false;
  3715. intel_crtc_update_dpms(encoder->base.crtc);
  3716. }
  3717. }
  3718. /* Cross check the actual hw state with our own modeset state tracking (and it's
  3719. * internal consistency). */
  3720. static void intel_connector_check_state(struct intel_connector *connector)
  3721. {
  3722. if (connector->get_hw_state(connector)) {
  3723. struct intel_encoder *encoder = connector->encoder;
  3724. struct drm_crtc *crtc;
  3725. bool encoder_enabled;
  3726. enum pipe pipe;
  3727. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3728. connector->base.base.id,
  3729. drm_get_connector_name(&connector->base));
  3730. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  3731. "wrong connector dpms state\n");
  3732. WARN(connector->base.encoder != &encoder->base,
  3733. "active connector not linked to encoder\n");
  3734. WARN(!encoder->connectors_active,
  3735. "encoder->connectors_active not set\n");
  3736. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  3737. WARN(!encoder_enabled, "encoder not enabled\n");
  3738. if (WARN_ON(!encoder->base.crtc))
  3739. return;
  3740. crtc = encoder->base.crtc;
  3741. WARN(!crtc->enabled, "crtc not enabled\n");
  3742. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  3743. WARN(pipe != to_intel_crtc(crtc)->pipe,
  3744. "encoder active on the wrong pipe\n");
  3745. }
  3746. }
  3747. /* Even simpler default implementation, if there's really no special case to
  3748. * consider. */
  3749. void intel_connector_dpms(struct drm_connector *connector, int mode)
  3750. {
  3751. /* All the simple cases only support two dpms states. */
  3752. if (mode != DRM_MODE_DPMS_ON)
  3753. mode = DRM_MODE_DPMS_OFF;
  3754. if (mode == connector->dpms)
  3755. return;
  3756. connector->dpms = mode;
  3757. /* Only need to change hw state when actually enabled */
  3758. if (connector->encoder)
  3759. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  3760. intel_modeset_check_state(connector->dev);
  3761. }
  3762. /* Simple connector->get_hw_state implementation for encoders that support only
  3763. * one connector and no cloning and hence the encoder state determines the state
  3764. * of the connector. */
  3765. bool intel_connector_get_hw_state(struct intel_connector *connector)
  3766. {
  3767. enum pipe pipe = 0;
  3768. struct intel_encoder *encoder = connector->encoder;
  3769. return encoder->get_hw_state(encoder, &pipe);
  3770. }
  3771. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  3772. struct intel_crtc_config *pipe_config)
  3773. {
  3774. struct drm_i915_private *dev_priv = dev->dev_private;
  3775. struct intel_crtc *pipe_B_crtc =
  3776. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  3777. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  3778. pipe_name(pipe), pipe_config->fdi_lanes);
  3779. if (pipe_config->fdi_lanes > 4) {
  3780. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  3781. pipe_name(pipe), pipe_config->fdi_lanes);
  3782. return false;
  3783. }
  3784. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  3785. if (pipe_config->fdi_lanes > 2) {
  3786. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  3787. pipe_config->fdi_lanes);
  3788. return false;
  3789. } else {
  3790. return true;
  3791. }
  3792. }
  3793. if (INTEL_INFO(dev)->num_pipes == 2)
  3794. return true;
  3795. /* Ivybridge 3 pipe is really complicated */
  3796. switch (pipe) {
  3797. case PIPE_A:
  3798. return true;
  3799. case PIPE_B:
  3800. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  3801. pipe_config->fdi_lanes > 2) {
  3802. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  3803. pipe_name(pipe), pipe_config->fdi_lanes);
  3804. return false;
  3805. }
  3806. return true;
  3807. case PIPE_C:
  3808. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  3809. pipe_B_crtc->config.fdi_lanes <= 2) {
  3810. if (pipe_config->fdi_lanes > 2) {
  3811. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  3812. pipe_name(pipe), pipe_config->fdi_lanes);
  3813. return false;
  3814. }
  3815. } else {
  3816. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  3817. return false;
  3818. }
  3819. return true;
  3820. default:
  3821. BUG();
  3822. }
  3823. }
  3824. #define RETRY 1
  3825. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  3826. struct intel_crtc_config *pipe_config)
  3827. {
  3828. struct drm_device *dev = intel_crtc->base.dev;
  3829. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  3830. int lane, link_bw, fdi_dotclock;
  3831. bool setup_ok, needs_recompute = false;
  3832. retry:
  3833. /* FDI is a binary signal running at ~2.7GHz, encoding
  3834. * each output octet as 10 bits. The actual frequency
  3835. * is stored as a divider into a 100MHz clock, and the
  3836. * mode pixel clock is stored in units of 1KHz.
  3837. * Hence the bw of each lane in terms of the mode signal
  3838. * is:
  3839. */
  3840. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  3841. fdi_dotclock = adjusted_mode->crtc_clock;
  3842. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  3843. pipe_config->pipe_bpp);
  3844. pipe_config->fdi_lanes = lane;
  3845. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  3846. link_bw, &pipe_config->fdi_m_n);
  3847. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  3848. intel_crtc->pipe, pipe_config);
  3849. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  3850. pipe_config->pipe_bpp -= 2*3;
  3851. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  3852. pipe_config->pipe_bpp);
  3853. needs_recompute = true;
  3854. pipe_config->bw_constrained = true;
  3855. goto retry;
  3856. }
  3857. if (needs_recompute)
  3858. return RETRY;
  3859. return setup_ok ? 0 : -EINVAL;
  3860. }
  3861. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  3862. struct intel_crtc_config *pipe_config)
  3863. {
  3864. pipe_config->ips_enabled = i915.enable_ips &&
  3865. hsw_crtc_supports_ips(crtc) &&
  3866. pipe_config->pipe_bpp <= 24;
  3867. }
  3868. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  3869. struct intel_crtc_config *pipe_config)
  3870. {
  3871. struct drm_device *dev = crtc->base.dev;
  3872. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  3873. /* FIXME should check pixel clock limits on all platforms */
  3874. if (INTEL_INFO(dev)->gen < 4) {
  3875. struct drm_i915_private *dev_priv = dev->dev_private;
  3876. int clock_limit =
  3877. dev_priv->display.get_display_clock_speed(dev);
  3878. /*
  3879. * Enable pixel doubling when the dot clock
  3880. * is > 90% of the (display) core speed.
  3881. *
  3882. * GDG double wide on either pipe,
  3883. * otherwise pipe A only.
  3884. */
  3885. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  3886. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  3887. clock_limit *= 2;
  3888. pipe_config->double_wide = true;
  3889. }
  3890. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  3891. return -EINVAL;
  3892. }
  3893. /*
  3894. * Pipe horizontal size must be even in:
  3895. * - DVO ganged mode
  3896. * - LVDS dual channel mode
  3897. * - Double wide pipe
  3898. */
  3899. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  3900. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  3901. pipe_config->pipe_src_w &= ~1;
  3902. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  3903. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  3904. */
  3905. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  3906. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  3907. return -EINVAL;
  3908. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  3909. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  3910. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  3911. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  3912. * for lvds. */
  3913. pipe_config->pipe_bpp = 8*3;
  3914. }
  3915. if (HAS_IPS(dev))
  3916. hsw_compute_ips_config(crtc, pipe_config);
  3917. /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old
  3918. * clock survives for now. */
  3919. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  3920. pipe_config->shared_dpll = crtc->config.shared_dpll;
  3921. if (pipe_config->has_pch_encoder)
  3922. return ironlake_fdi_compute_config(crtc, pipe_config);
  3923. return 0;
  3924. }
  3925. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  3926. {
  3927. return 400000; /* FIXME */
  3928. }
  3929. static int i945_get_display_clock_speed(struct drm_device *dev)
  3930. {
  3931. return 400000;
  3932. }
  3933. static int i915_get_display_clock_speed(struct drm_device *dev)
  3934. {
  3935. return 333000;
  3936. }
  3937. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  3938. {
  3939. return 200000;
  3940. }
  3941. static int pnv_get_display_clock_speed(struct drm_device *dev)
  3942. {
  3943. u16 gcfgc = 0;
  3944. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3945. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  3946. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  3947. return 267000;
  3948. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  3949. return 333000;
  3950. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  3951. return 444000;
  3952. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  3953. return 200000;
  3954. default:
  3955. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  3956. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  3957. return 133000;
  3958. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  3959. return 167000;
  3960. }
  3961. }
  3962. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  3963. {
  3964. u16 gcfgc = 0;
  3965. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3966. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  3967. return 133000;
  3968. else {
  3969. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  3970. case GC_DISPLAY_CLOCK_333_MHZ:
  3971. return 333000;
  3972. default:
  3973. case GC_DISPLAY_CLOCK_190_200_MHZ:
  3974. return 190000;
  3975. }
  3976. }
  3977. }
  3978. static int i865_get_display_clock_speed(struct drm_device *dev)
  3979. {
  3980. return 266000;
  3981. }
  3982. static int i855_get_display_clock_speed(struct drm_device *dev)
  3983. {
  3984. u16 hpllcc = 0;
  3985. /* Assume that the hardware is in the high speed state. This
  3986. * should be the default.
  3987. */
  3988. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  3989. case GC_CLOCK_133_200:
  3990. case GC_CLOCK_100_200:
  3991. return 200000;
  3992. case GC_CLOCK_166_250:
  3993. return 250000;
  3994. case GC_CLOCK_100_133:
  3995. return 133000;
  3996. }
  3997. /* Shouldn't happen */
  3998. return 0;
  3999. }
  4000. static int i830_get_display_clock_speed(struct drm_device *dev)
  4001. {
  4002. return 133000;
  4003. }
  4004. static void
  4005. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4006. {
  4007. while (*num > DATA_LINK_M_N_MASK ||
  4008. *den > DATA_LINK_M_N_MASK) {
  4009. *num >>= 1;
  4010. *den >>= 1;
  4011. }
  4012. }
  4013. static void compute_m_n(unsigned int m, unsigned int n,
  4014. uint32_t *ret_m, uint32_t *ret_n)
  4015. {
  4016. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4017. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4018. intel_reduce_m_n_ratio(ret_m, ret_n);
  4019. }
  4020. void
  4021. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4022. int pixel_clock, int link_clock,
  4023. struct intel_link_m_n *m_n)
  4024. {
  4025. m_n->tu = 64;
  4026. compute_m_n(bits_per_pixel * pixel_clock,
  4027. link_clock * nlanes * 8,
  4028. &m_n->gmch_m, &m_n->gmch_n);
  4029. compute_m_n(pixel_clock, link_clock,
  4030. &m_n->link_m, &m_n->link_n);
  4031. }
  4032. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4033. {
  4034. if (i915.panel_use_ssc >= 0)
  4035. return i915.panel_use_ssc != 0;
  4036. return dev_priv->vbt.lvds_use_ssc
  4037. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4038. }
  4039. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4040. {
  4041. struct drm_device *dev = crtc->dev;
  4042. struct drm_i915_private *dev_priv = dev->dev_private;
  4043. int refclk;
  4044. if (IS_VALLEYVIEW(dev)) {
  4045. refclk = 100000;
  4046. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4047. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4048. refclk = dev_priv->vbt.lvds_ssc_freq;
  4049. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4050. } else if (!IS_GEN2(dev)) {
  4051. refclk = 96000;
  4052. } else {
  4053. refclk = 48000;
  4054. }
  4055. return refclk;
  4056. }
  4057. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4058. {
  4059. return (1 << dpll->n) << 16 | dpll->m2;
  4060. }
  4061. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4062. {
  4063. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4064. }
  4065. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4066. intel_clock_t *reduced_clock)
  4067. {
  4068. struct drm_device *dev = crtc->base.dev;
  4069. struct drm_i915_private *dev_priv = dev->dev_private;
  4070. int pipe = crtc->pipe;
  4071. u32 fp, fp2 = 0;
  4072. if (IS_PINEVIEW(dev)) {
  4073. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4074. if (reduced_clock)
  4075. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4076. } else {
  4077. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4078. if (reduced_clock)
  4079. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4080. }
  4081. I915_WRITE(FP0(pipe), fp);
  4082. crtc->config.dpll_hw_state.fp0 = fp;
  4083. crtc->lowfreq_avail = false;
  4084. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4085. reduced_clock && i915.powersave) {
  4086. I915_WRITE(FP1(pipe), fp2);
  4087. crtc->config.dpll_hw_state.fp1 = fp2;
  4088. crtc->lowfreq_avail = true;
  4089. } else {
  4090. I915_WRITE(FP1(pipe), fp);
  4091. crtc->config.dpll_hw_state.fp1 = fp;
  4092. }
  4093. }
  4094. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4095. pipe)
  4096. {
  4097. u32 reg_val;
  4098. /*
  4099. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4100. * and set it to a reasonable value instead.
  4101. */
  4102. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4103. reg_val &= 0xffffff00;
  4104. reg_val |= 0x00000030;
  4105. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4106. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4107. reg_val &= 0x8cffffff;
  4108. reg_val = 0x8c000000;
  4109. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4110. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4111. reg_val &= 0xffffff00;
  4112. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4113. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4114. reg_val &= 0x00ffffff;
  4115. reg_val |= 0xb0000000;
  4116. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4117. }
  4118. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4119. struct intel_link_m_n *m_n)
  4120. {
  4121. struct drm_device *dev = crtc->base.dev;
  4122. struct drm_i915_private *dev_priv = dev->dev_private;
  4123. int pipe = crtc->pipe;
  4124. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4125. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4126. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4127. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4128. }
  4129. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4130. struct intel_link_m_n *m_n)
  4131. {
  4132. struct drm_device *dev = crtc->base.dev;
  4133. struct drm_i915_private *dev_priv = dev->dev_private;
  4134. int pipe = crtc->pipe;
  4135. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4136. if (INTEL_INFO(dev)->gen >= 5) {
  4137. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4138. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4139. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4140. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4141. } else {
  4142. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4143. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4144. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4145. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4146. }
  4147. }
  4148. static void intel_dp_set_m_n(struct intel_crtc *crtc)
  4149. {
  4150. if (crtc->config.has_pch_encoder)
  4151. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4152. else
  4153. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4154. }
  4155. static void vlv_update_pll(struct intel_crtc *crtc)
  4156. {
  4157. struct drm_device *dev = crtc->base.dev;
  4158. struct drm_i915_private *dev_priv = dev->dev_private;
  4159. int pipe = crtc->pipe;
  4160. u32 dpll, mdiv;
  4161. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4162. u32 coreclk, reg_val, dpll_md;
  4163. mutex_lock(&dev_priv->dpio_lock);
  4164. bestn = crtc->config.dpll.n;
  4165. bestm1 = crtc->config.dpll.m1;
  4166. bestm2 = crtc->config.dpll.m2;
  4167. bestp1 = crtc->config.dpll.p1;
  4168. bestp2 = crtc->config.dpll.p2;
  4169. /* See eDP HDMI DPIO driver vbios notes doc */
  4170. /* PLL B needs special handling */
  4171. if (pipe)
  4172. vlv_pllb_recal_opamp(dev_priv, pipe);
  4173. /* Set up Tx target for periodic Rcomp update */
  4174. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4175. /* Disable target IRef on PLL */
  4176. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4177. reg_val &= 0x00ffffff;
  4178. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4179. /* Disable fast lock */
  4180. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4181. /* Set idtafcrecal before PLL is enabled */
  4182. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4183. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4184. mdiv |= ((bestn << DPIO_N_SHIFT));
  4185. mdiv |= (1 << DPIO_K_SHIFT);
  4186. /*
  4187. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4188. * but we don't support that).
  4189. * Note: don't use the DAC post divider as it seems unstable.
  4190. */
  4191. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4192. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4193. mdiv |= DPIO_ENABLE_CALIBRATION;
  4194. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4195. /* Set HBR and RBR LPF coefficients */
  4196. if (crtc->config.port_clock == 162000 ||
  4197. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4198. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4199. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4200. 0x009f0003);
  4201. else
  4202. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4203. 0x00d0000f);
  4204. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4205. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4206. /* Use SSC source */
  4207. if (!pipe)
  4208. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4209. 0x0df40000);
  4210. else
  4211. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4212. 0x0df70000);
  4213. } else { /* HDMI or VGA */
  4214. /* Use bend source */
  4215. if (!pipe)
  4216. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4217. 0x0df70000);
  4218. else
  4219. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4220. 0x0df40000);
  4221. }
  4222. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4223. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4224. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4225. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4226. coreclk |= 0x01000000;
  4227. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4228. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4229. /*
  4230. * Enable DPIO clock input. We should never disable the reference
  4231. * clock for pipe B, since VGA hotplug / manual detection depends
  4232. * on it.
  4233. */
  4234. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4235. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4236. /* We should never disable this, set it here for state tracking */
  4237. if (pipe == PIPE_B)
  4238. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4239. dpll |= DPLL_VCO_ENABLE;
  4240. crtc->config.dpll_hw_state.dpll = dpll;
  4241. dpll_md = (crtc->config.pixel_multiplier - 1)
  4242. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4243. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4244. if (crtc->config.has_dp_encoder)
  4245. intel_dp_set_m_n(crtc);
  4246. mutex_unlock(&dev_priv->dpio_lock);
  4247. }
  4248. static void i9xx_update_pll(struct intel_crtc *crtc,
  4249. intel_clock_t *reduced_clock,
  4250. int num_connectors)
  4251. {
  4252. struct drm_device *dev = crtc->base.dev;
  4253. struct drm_i915_private *dev_priv = dev->dev_private;
  4254. u32 dpll;
  4255. bool is_sdvo;
  4256. struct dpll *clock = &crtc->config.dpll;
  4257. i9xx_update_pll_dividers(crtc, reduced_clock);
  4258. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4259. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4260. dpll = DPLL_VGA_MODE_DIS;
  4261. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4262. dpll |= DPLLB_MODE_LVDS;
  4263. else
  4264. dpll |= DPLLB_MODE_DAC_SERIAL;
  4265. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4266. dpll |= (crtc->config.pixel_multiplier - 1)
  4267. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4268. }
  4269. if (is_sdvo)
  4270. dpll |= DPLL_SDVO_HIGH_SPEED;
  4271. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4272. dpll |= DPLL_SDVO_HIGH_SPEED;
  4273. /* compute bitmask from p1 value */
  4274. if (IS_PINEVIEW(dev))
  4275. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4276. else {
  4277. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4278. if (IS_G4X(dev) && reduced_clock)
  4279. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4280. }
  4281. switch (clock->p2) {
  4282. case 5:
  4283. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4284. break;
  4285. case 7:
  4286. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4287. break;
  4288. case 10:
  4289. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4290. break;
  4291. case 14:
  4292. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4293. break;
  4294. }
  4295. if (INTEL_INFO(dev)->gen >= 4)
  4296. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4297. if (crtc->config.sdvo_tv_clock)
  4298. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4299. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4300. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4301. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4302. else
  4303. dpll |= PLL_REF_INPUT_DREFCLK;
  4304. dpll |= DPLL_VCO_ENABLE;
  4305. crtc->config.dpll_hw_state.dpll = dpll;
  4306. if (INTEL_INFO(dev)->gen >= 4) {
  4307. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4308. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4309. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4310. }
  4311. if (crtc->config.has_dp_encoder)
  4312. intel_dp_set_m_n(crtc);
  4313. }
  4314. static void i8xx_update_pll(struct intel_crtc *crtc,
  4315. intel_clock_t *reduced_clock,
  4316. int num_connectors)
  4317. {
  4318. struct drm_device *dev = crtc->base.dev;
  4319. struct drm_i915_private *dev_priv = dev->dev_private;
  4320. u32 dpll;
  4321. struct dpll *clock = &crtc->config.dpll;
  4322. i9xx_update_pll_dividers(crtc, reduced_clock);
  4323. dpll = DPLL_VGA_MODE_DIS;
  4324. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  4325. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4326. } else {
  4327. if (clock->p1 == 2)
  4328. dpll |= PLL_P1_DIVIDE_BY_TWO;
  4329. else
  4330. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4331. if (clock->p2 == 4)
  4332. dpll |= PLL_P2_DIVIDE_BY_4;
  4333. }
  4334. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  4335. dpll |= DPLL_DVO_2X_MODE;
  4336. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4337. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4338. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4339. else
  4340. dpll |= PLL_REF_INPUT_DREFCLK;
  4341. dpll |= DPLL_VCO_ENABLE;
  4342. crtc->config.dpll_hw_state.dpll = dpll;
  4343. }
  4344. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  4345. {
  4346. struct drm_device *dev = intel_crtc->base.dev;
  4347. struct drm_i915_private *dev_priv = dev->dev_private;
  4348. enum pipe pipe = intel_crtc->pipe;
  4349. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  4350. struct drm_display_mode *adjusted_mode =
  4351. &intel_crtc->config.adjusted_mode;
  4352. uint32_t vsyncshift, crtc_vtotal, crtc_vblank_end;
  4353. /* We need to be careful not to changed the adjusted mode, for otherwise
  4354. * the hw state checker will get angry at the mismatch. */
  4355. crtc_vtotal = adjusted_mode->crtc_vtotal;
  4356. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  4357. if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4358. /* the chip adds 2 halflines automatically */
  4359. crtc_vtotal -= 1;
  4360. crtc_vblank_end -= 1;
  4361. vsyncshift = adjusted_mode->crtc_hsync_start
  4362. - adjusted_mode->crtc_htotal / 2;
  4363. } else {
  4364. vsyncshift = 0;
  4365. }
  4366. if (INTEL_INFO(dev)->gen > 3)
  4367. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  4368. I915_WRITE(HTOTAL(cpu_transcoder),
  4369. (adjusted_mode->crtc_hdisplay - 1) |
  4370. ((adjusted_mode->crtc_htotal - 1) << 16));
  4371. I915_WRITE(HBLANK(cpu_transcoder),
  4372. (adjusted_mode->crtc_hblank_start - 1) |
  4373. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  4374. I915_WRITE(HSYNC(cpu_transcoder),
  4375. (adjusted_mode->crtc_hsync_start - 1) |
  4376. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  4377. I915_WRITE(VTOTAL(cpu_transcoder),
  4378. (adjusted_mode->crtc_vdisplay - 1) |
  4379. ((crtc_vtotal - 1) << 16));
  4380. I915_WRITE(VBLANK(cpu_transcoder),
  4381. (adjusted_mode->crtc_vblank_start - 1) |
  4382. ((crtc_vblank_end - 1) << 16));
  4383. I915_WRITE(VSYNC(cpu_transcoder),
  4384. (adjusted_mode->crtc_vsync_start - 1) |
  4385. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  4386. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  4387. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  4388. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  4389. * bits. */
  4390. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  4391. (pipe == PIPE_B || pipe == PIPE_C))
  4392. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  4393. /* pipesrc controls the size that is scaled from, which should
  4394. * always be the user's requested size.
  4395. */
  4396. I915_WRITE(PIPESRC(pipe),
  4397. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  4398. (intel_crtc->config.pipe_src_h - 1));
  4399. }
  4400. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  4401. struct intel_crtc_config *pipe_config)
  4402. {
  4403. struct drm_device *dev = crtc->base.dev;
  4404. struct drm_i915_private *dev_priv = dev->dev_private;
  4405. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  4406. uint32_t tmp;
  4407. tmp = I915_READ(HTOTAL(cpu_transcoder));
  4408. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  4409. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  4410. tmp = I915_READ(HBLANK(cpu_transcoder));
  4411. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  4412. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  4413. tmp = I915_READ(HSYNC(cpu_transcoder));
  4414. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  4415. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  4416. tmp = I915_READ(VTOTAL(cpu_transcoder));
  4417. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  4418. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  4419. tmp = I915_READ(VBLANK(cpu_transcoder));
  4420. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  4421. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  4422. tmp = I915_READ(VSYNC(cpu_transcoder));
  4423. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  4424. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  4425. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  4426. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  4427. pipe_config->adjusted_mode.crtc_vtotal += 1;
  4428. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  4429. }
  4430. tmp = I915_READ(PIPESRC(crtc->pipe));
  4431. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  4432. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  4433. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  4434. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  4435. }
  4436. static void intel_crtc_mode_from_pipe_config(struct intel_crtc *intel_crtc,
  4437. struct intel_crtc_config *pipe_config)
  4438. {
  4439. struct drm_crtc *crtc = &intel_crtc->base;
  4440. crtc->mode.hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  4441. crtc->mode.htotal = pipe_config->adjusted_mode.crtc_htotal;
  4442. crtc->mode.hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  4443. crtc->mode.hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  4444. crtc->mode.vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  4445. crtc->mode.vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  4446. crtc->mode.vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  4447. crtc->mode.vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  4448. crtc->mode.flags = pipe_config->adjusted_mode.flags;
  4449. crtc->mode.clock = pipe_config->adjusted_mode.crtc_clock;
  4450. crtc->mode.flags |= pipe_config->adjusted_mode.flags;
  4451. }
  4452. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  4453. {
  4454. struct drm_device *dev = intel_crtc->base.dev;
  4455. struct drm_i915_private *dev_priv = dev->dev_private;
  4456. uint32_t pipeconf;
  4457. pipeconf = 0;
  4458. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  4459. I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE)
  4460. pipeconf |= PIPECONF_ENABLE;
  4461. if (intel_crtc->config.double_wide)
  4462. pipeconf |= PIPECONF_DOUBLE_WIDE;
  4463. /* only g4x and later have fancy bpc/dither controls */
  4464. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  4465. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  4466. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  4467. pipeconf |= PIPECONF_DITHER_EN |
  4468. PIPECONF_DITHER_TYPE_SP;
  4469. switch (intel_crtc->config.pipe_bpp) {
  4470. case 18:
  4471. pipeconf |= PIPECONF_6BPC;
  4472. break;
  4473. case 24:
  4474. pipeconf |= PIPECONF_8BPC;
  4475. break;
  4476. case 30:
  4477. pipeconf |= PIPECONF_10BPC;
  4478. break;
  4479. default:
  4480. /* Case prevented by intel_choose_pipe_bpp_dither. */
  4481. BUG();
  4482. }
  4483. }
  4484. if (HAS_PIPE_CXSR(dev)) {
  4485. if (intel_crtc->lowfreq_avail) {
  4486. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  4487. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  4488. } else {
  4489. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  4490. }
  4491. }
  4492. if (!IS_GEN2(dev) &&
  4493. intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  4494. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  4495. else
  4496. pipeconf |= PIPECONF_PROGRESSIVE;
  4497. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  4498. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  4499. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  4500. POSTING_READ(PIPECONF(intel_crtc->pipe));
  4501. }
  4502. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  4503. int x, int y,
  4504. struct drm_framebuffer *fb)
  4505. {
  4506. struct drm_device *dev = crtc->dev;
  4507. struct drm_i915_private *dev_priv = dev->dev_private;
  4508. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4509. int pipe = intel_crtc->pipe;
  4510. int plane = intel_crtc->plane;
  4511. int refclk, num_connectors = 0;
  4512. intel_clock_t clock, reduced_clock;
  4513. u32 dspcntr;
  4514. bool ok, has_reduced_clock = false;
  4515. bool is_lvds = false, is_dsi = false;
  4516. struct intel_encoder *encoder;
  4517. const intel_limit_t *limit;
  4518. int ret;
  4519. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4520. switch (encoder->type) {
  4521. case INTEL_OUTPUT_LVDS:
  4522. is_lvds = true;
  4523. break;
  4524. case INTEL_OUTPUT_DSI:
  4525. is_dsi = true;
  4526. break;
  4527. }
  4528. num_connectors++;
  4529. }
  4530. if (is_dsi)
  4531. goto skip_dpll;
  4532. if (!intel_crtc->config.clock_set) {
  4533. refclk = i9xx_get_refclk(crtc, num_connectors);
  4534. /*
  4535. * Returns a set of divisors for the desired target clock with
  4536. * the given refclk, or FALSE. The returned values represent
  4537. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  4538. * 2) / p1 / p2.
  4539. */
  4540. limit = intel_limit(crtc, refclk);
  4541. ok = dev_priv->display.find_dpll(limit, crtc,
  4542. intel_crtc->config.port_clock,
  4543. refclk, NULL, &clock);
  4544. if (!ok) {
  4545. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  4546. return -EINVAL;
  4547. }
  4548. if (is_lvds && dev_priv->lvds_downclock_avail) {
  4549. /*
  4550. * Ensure we match the reduced clock's P to the target
  4551. * clock. If the clocks don't match, we can't switch
  4552. * the display clock by using the FP0/FP1. In such case
  4553. * we will disable the LVDS downclock feature.
  4554. */
  4555. has_reduced_clock =
  4556. dev_priv->display.find_dpll(limit, crtc,
  4557. dev_priv->lvds_downclock,
  4558. refclk, &clock,
  4559. &reduced_clock);
  4560. }
  4561. /* Compat-code for transition, will disappear. */
  4562. intel_crtc->config.dpll.n = clock.n;
  4563. intel_crtc->config.dpll.m1 = clock.m1;
  4564. intel_crtc->config.dpll.m2 = clock.m2;
  4565. intel_crtc->config.dpll.p1 = clock.p1;
  4566. intel_crtc->config.dpll.p2 = clock.p2;
  4567. }
  4568. if (IS_GEN2(dev)) {
  4569. i8xx_update_pll(intel_crtc,
  4570. has_reduced_clock ? &reduced_clock : NULL,
  4571. num_connectors);
  4572. } else if (IS_VALLEYVIEW(dev)) {
  4573. vlv_update_pll(intel_crtc);
  4574. } else {
  4575. i9xx_update_pll(intel_crtc,
  4576. has_reduced_clock ? &reduced_clock : NULL,
  4577. num_connectors);
  4578. }
  4579. skip_dpll:
  4580. /* Set up the display plane register */
  4581. dspcntr = DISPPLANE_GAMMA_ENABLE;
  4582. if (!IS_VALLEYVIEW(dev)) {
  4583. if (pipe == 0)
  4584. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  4585. else
  4586. dspcntr |= DISPPLANE_SEL_PIPE_B;
  4587. }
  4588. intel_set_pipe_timings(intel_crtc);
  4589. /* pipesrc and dspsize control the size that is scaled from,
  4590. * which should always be the user's requested size.
  4591. */
  4592. I915_WRITE(DSPSIZE(plane),
  4593. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  4594. (intel_crtc->config.pipe_src_w - 1));
  4595. I915_WRITE(DSPPOS(plane), 0);
  4596. i9xx_set_pipeconf(intel_crtc);
  4597. I915_WRITE(DSPCNTR(plane), dspcntr);
  4598. POSTING_READ(DSPCNTR(plane));
  4599. ret = intel_pipe_set_base(crtc, x, y, fb);
  4600. return ret;
  4601. }
  4602. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  4603. struct intel_crtc_config *pipe_config)
  4604. {
  4605. struct drm_device *dev = crtc->base.dev;
  4606. struct drm_i915_private *dev_priv = dev->dev_private;
  4607. uint32_t tmp;
  4608. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  4609. return;
  4610. tmp = I915_READ(PFIT_CONTROL);
  4611. if (!(tmp & PFIT_ENABLE))
  4612. return;
  4613. /* Check whether the pfit is attached to our pipe. */
  4614. if (INTEL_INFO(dev)->gen < 4) {
  4615. if (crtc->pipe != PIPE_B)
  4616. return;
  4617. } else {
  4618. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  4619. return;
  4620. }
  4621. pipe_config->gmch_pfit.control = tmp;
  4622. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  4623. if (INTEL_INFO(dev)->gen < 5)
  4624. pipe_config->gmch_pfit.lvds_border_bits =
  4625. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  4626. }
  4627. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  4628. struct intel_crtc_config *pipe_config)
  4629. {
  4630. struct drm_device *dev = crtc->base.dev;
  4631. struct drm_i915_private *dev_priv = dev->dev_private;
  4632. int pipe = pipe_config->cpu_transcoder;
  4633. intel_clock_t clock;
  4634. u32 mdiv;
  4635. int refclk = 100000;
  4636. mutex_lock(&dev_priv->dpio_lock);
  4637. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  4638. mutex_unlock(&dev_priv->dpio_lock);
  4639. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  4640. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  4641. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  4642. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  4643. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  4644. vlv_clock(refclk, &clock);
  4645. /* clock.dot is the fast clock */
  4646. pipe_config->port_clock = clock.dot / 5;
  4647. }
  4648. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  4649. struct intel_crtc_config *pipe_config)
  4650. {
  4651. struct drm_device *dev = crtc->base.dev;
  4652. struct drm_i915_private *dev_priv = dev->dev_private;
  4653. uint32_t tmp;
  4654. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  4655. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  4656. tmp = I915_READ(PIPECONF(crtc->pipe));
  4657. if (!(tmp & PIPECONF_ENABLE))
  4658. return false;
  4659. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  4660. switch (tmp & PIPECONF_BPC_MASK) {
  4661. case PIPECONF_6BPC:
  4662. pipe_config->pipe_bpp = 18;
  4663. break;
  4664. case PIPECONF_8BPC:
  4665. pipe_config->pipe_bpp = 24;
  4666. break;
  4667. case PIPECONF_10BPC:
  4668. pipe_config->pipe_bpp = 30;
  4669. break;
  4670. default:
  4671. break;
  4672. }
  4673. }
  4674. if (INTEL_INFO(dev)->gen < 4)
  4675. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  4676. intel_get_pipe_timings(crtc, pipe_config);
  4677. i9xx_get_pfit_config(crtc, pipe_config);
  4678. if (INTEL_INFO(dev)->gen >= 4) {
  4679. tmp = I915_READ(DPLL_MD(crtc->pipe));
  4680. pipe_config->pixel_multiplier =
  4681. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  4682. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  4683. pipe_config->dpll_hw_state.dpll_md = tmp;
  4684. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4685. tmp = I915_READ(DPLL(crtc->pipe));
  4686. pipe_config->pixel_multiplier =
  4687. ((tmp & SDVO_MULTIPLIER_MASK)
  4688. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  4689. } else {
  4690. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  4691. * port and will be fixed up in the encoder->get_config
  4692. * function. */
  4693. pipe_config->pixel_multiplier = 1;
  4694. }
  4695. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  4696. if (!IS_VALLEYVIEW(dev)) {
  4697. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  4698. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  4699. } else {
  4700. /* Mask out read-only status bits. */
  4701. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  4702. DPLL_PORTC_READY_MASK |
  4703. DPLL_PORTB_READY_MASK);
  4704. }
  4705. if (IS_VALLEYVIEW(dev))
  4706. vlv_crtc_clock_get(crtc, pipe_config);
  4707. else
  4708. i9xx_crtc_clock_get(crtc, pipe_config);
  4709. return true;
  4710. }
  4711. static void ironlake_init_pch_refclk(struct drm_device *dev)
  4712. {
  4713. struct drm_i915_private *dev_priv = dev->dev_private;
  4714. struct drm_mode_config *mode_config = &dev->mode_config;
  4715. struct intel_encoder *encoder;
  4716. u32 val, final;
  4717. bool has_lvds = false;
  4718. bool has_cpu_edp = false;
  4719. bool has_panel = false;
  4720. bool has_ck505 = false;
  4721. bool can_ssc = false;
  4722. /* We need to take the global config into account */
  4723. list_for_each_entry(encoder, &mode_config->encoder_list,
  4724. base.head) {
  4725. switch (encoder->type) {
  4726. case INTEL_OUTPUT_LVDS:
  4727. has_panel = true;
  4728. has_lvds = true;
  4729. break;
  4730. case INTEL_OUTPUT_EDP:
  4731. has_panel = true;
  4732. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  4733. has_cpu_edp = true;
  4734. break;
  4735. }
  4736. }
  4737. if (HAS_PCH_IBX(dev)) {
  4738. has_ck505 = dev_priv->vbt.display_clock_mode;
  4739. can_ssc = has_ck505;
  4740. } else {
  4741. has_ck505 = false;
  4742. can_ssc = true;
  4743. }
  4744. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  4745. has_panel, has_lvds, has_ck505);
  4746. /* Ironlake: try to setup display ref clock before DPLL
  4747. * enabling. This is only under driver's control after
  4748. * PCH B stepping, previous chipset stepping should be
  4749. * ignoring this setting.
  4750. */
  4751. val = I915_READ(PCH_DREF_CONTROL);
  4752. /* As we must carefully and slowly disable/enable each source in turn,
  4753. * compute the final state we want first and check if we need to
  4754. * make any changes at all.
  4755. */
  4756. final = val;
  4757. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  4758. if (has_ck505)
  4759. final |= DREF_NONSPREAD_CK505_ENABLE;
  4760. else
  4761. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  4762. final &= ~DREF_SSC_SOURCE_MASK;
  4763. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4764. final &= ~DREF_SSC1_ENABLE;
  4765. if (has_panel) {
  4766. final |= DREF_SSC_SOURCE_ENABLE;
  4767. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  4768. final |= DREF_SSC1_ENABLE;
  4769. if (has_cpu_edp) {
  4770. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  4771. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  4772. else
  4773. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  4774. } else
  4775. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4776. } else {
  4777. final |= DREF_SSC_SOURCE_DISABLE;
  4778. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4779. }
  4780. if (final == val)
  4781. return;
  4782. /* Always enable nonspread source */
  4783. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  4784. if (has_ck505)
  4785. val |= DREF_NONSPREAD_CK505_ENABLE;
  4786. else
  4787. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  4788. if (has_panel) {
  4789. val &= ~DREF_SSC_SOURCE_MASK;
  4790. val |= DREF_SSC_SOURCE_ENABLE;
  4791. /* SSC must be turned on before enabling the CPU output */
  4792. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4793. DRM_DEBUG_KMS("Using SSC on panel\n");
  4794. val |= DREF_SSC1_ENABLE;
  4795. } else
  4796. val &= ~DREF_SSC1_ENABLE;
  4797. /* Get SSC going before enabling the outputs */
  4798. I915_WRITE(PCH_DREF_CONTROL, val);
  4799. POSTING_READ(PCH_DREF_CONTROL);
  4800. udelay(200);
  4801. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4802. /* Enable CPU source on CPU attached eDP */
  4803. if (has_cpu_edp) {
  4804. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4805. DRM_DEBUG_KMS("Using SSC on eDP\n");
  4806. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  4807. }
  4808. else
  4809. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  4810. } else
  4811. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4812. I915_WRITE(PCH_DREF_CONTROL, val);
  4813. POSTING_READ(PCH_DREF_CONTROL);
  4814. udelay(200);
  4815. } else {
  4816. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  4817. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4818. /* Turn off CPU output */
  4819. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4820. I915_WRITE(PCH_DREF_CONTROL, val);
  4821. POSTING_READ(PCH_DREF_CONTROL);
  4822. udelay(200);
  4823. /* Turn off the SSC source */
  4824. val &= ~DREF_SSC_SOURCE_MASK;
  4825. val |= DREF_SSC_SOURCE_DISABLE;
  4826. /* Turn off SSC1 */
  4827. val &= ~DREF_SSC1_ENABLE;
  4828. I915_WRITE(PCH_DREF_CONTROL, val);
  4829. POSTING_READ(PCH_DREF_CONTROL);
  4830. udelay(200);
  4831. }
  4832. BUG_ON(val != final);
  4833. }
  4834. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  4835. {
  4836. uint32_t tmp;
  4837. tmp = I915_READ(SOUTH_CHICKEN2);
  4838. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  4839. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4840. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  4841. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  4842. DRM_ERROR("FDI mPHY reset assert timeout\n");
  4843. tmp = I915_READ(SOUTH_CHICKEN2);
  4844. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  4845. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4846. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  4847. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  4848. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  4849. }
  4850. /* WaMPhyProgramming:hsw */
  4851. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  4852. {
  4853. uint32_t tmp;
  4854. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  4855. tmp &= ~(0xFF << 24);
  4856. tmp |= (0x12 << 24);
  4857. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  4858. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  4859. tmp |= (1 << 11);
  4860. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  4861. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  4862. tmp |= (1 << 11);
  4863. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  4864. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  4865. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4866. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  4867. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  4868. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4869. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  4870. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  4871. tmp &= ~(7 << 13);
  4872. tmp |= (5 << 13);
  4873. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  4874. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  4875. tmp &= ~(7 << 13);
  4876. tmp |= (5 << 13);
  4877. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  4878. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  4879. tmp &= ~0xFF;
  4880. tmp |= 0x1C;
  4881. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  4882. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  4883. tmp &= ~0xFF;
  4884. tmp |= 0x1C;
  4885. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  4886. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  4887. tmp &= ~(0xFF << 16);
  4888. tmp |= (0x1C << 16);
  4889. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  4890. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  4891. tmp &= ~(0xFF << 16);
  4892. tmp |= (0x1C << 16);
  4893. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  4894. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  4895. tmp |= (1 << 27);
  4896. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  4897. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  4898. tmp |= (1 << 27);
  4899. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  4900. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  4901. tmp &= ~(0xF << 28);
  4902. tmp |= (4 << 28);
  4903. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  4904. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  4905. tmp &= ~(0xF << 28);
  4906. tmp |= (4 << 28);
  4907. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  4908. }
  4909. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  4910. * Programming" based on the parameters passed:
  4911. * - Sequence to enable CLKOUT_DP
  4912. * - Sequence to enable CLKOUT_DP without spread
  4913. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  4914. */
  4915. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  4916. bool with_fdi)
  4917. {
  4918. struct drm_i915_private *dev_priv = dev->dev_private;
  4919. uint32_t reg, tmp;
  4920. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  4921. with_spread = true;
  4922. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  4923. with_fdi, "LP PCH doesn't have FDI\n"))
  4924. with_fdi = false;
  4925. mutex_lock(&dev_priv->dpio_lock);
  4926. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4927. tmp &= ~SBI_SSCCTL_DISABLE;
  4928. tmp |= SBI_SSCCTL_PATHALT;
  4929. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4930. udelay(24);
  4931. if (with_spread) {
  4932. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4933. tmp &= ~SBI_SSCCTL_PATHALT;
  4934. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4935. if (with_fdi) {
  4936. lpt_reset_fdi_mphy(dev_priv);
  4937. lpt_program_fdi_mphy(dev_priv);
  4938. }
  4939. }
  4940. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  4941. SBI_GEN0 : SBI_DBUFF0;
  4942. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  4943. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  4944. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  4945. mutex_unlock(&dev_priv->dpio_lock);
  4946. }
  4947. /* Sequence to disable CLKOUT_DP */
  4948. static void lpt_disable_clkout_dp(struct drm_device *dev)
  4949. {
  4950. struct drm_i915_private *dev_priv = dev->dev_private;
  4951. uint32_t reg, tmp;
  4952. mutex_lock(&dev_priv->dpio_lock);
  4953. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  4954. SBI_GEN0 : SBI_DBUFF0;
  4955. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  4956. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  4957. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  4958. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4959. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  4960. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  4961. tmp |= SBI_SSCCTL_PATHALT;
  4962. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4963. udelay(32);
  4964. }
  4965. tmp |= SBI_SSCCTL_DISABLE;
  4966. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4967. }
  4968. mutex_unlock(&dev_priv->dpio_lock);
  4969. }
  4970. static void lpt_init_pch_refclk(struct drm_device *dev)
  4971. {
  4972. struct drm_mode_config *mode_config = &dev->mode_config;
  4973. struct intel_encoder *encoder;
  4974. bool has_vga = false;
  4975. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  4976. switch (encoder->type) {
  4977. case INTEL_OUTPUT_ANALOG:
  4978. has_vga = true;
  4979. break;
  4980. }
  4981. }
  4982. if (has_vga)
  4983. lpt_enable_clkout_dp(dev, true, true);
  4984. else
  4985. lpt_disable_clkout_dp(dev);
  4986. }
  4987. /*
  4988. * Initialize reference clocks when the driver loads
  4989. */
  4990. void intel_init_pch_refclk(struct drm_device *dev)
  4991. {
  4992. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  4993. ironlake_init_pch_refclk(dev);
  4994. else if (HAS_PCH_LPT(dev))
  4995. lpt_init_pch_refclk(dev);
  4996. }
  4997. static int ironlake_get_refclk(struct drm_crtc *crtc)
  4998. {
  4999. struct drm_device *dev = crtc->dev;
  5000. struct drm_i915_private *dev_priv = dev->dev_private;
  5001. struct intel_encoder *encoder;
  5002. int num_connectors = 0;
  5003. bool is_lvds = false;
  5004. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5005. switch (encoder->type) {
  5006. case INTEL_OUTPUT_LVDS:
  5007. is_lvds = true;
  5008. break;
  5009. }
  5010. num_connectors++;
  5011. }
  5012. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5013. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5014. dev_priv->vbt.lvds_ssc_freq);
  5015. return dev_priv->vbt.lvds_ssc_freq;
  5016. }
  5017. return 120000;
  5018. }
  5019. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5020. {
  5021. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5022. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5023. int pipe = intel_crtc->pipe;
  5024. uint32_t val;
  5025. val = 0;
  5026. switch (intel_crtc->config.pipe_bpp) {
  5027. case 18:
  5028. val |= PIPECONF_6BPC;
  5029. break;
  5030. case 24:
  5031. val |= PIPECONF_8BPC;
  5032. break;
  5033. case 30:
  5034. val |= PIPECONF_10BPC;
  5035. break;
  5036. case 36:
  5037. val |= PIPECONF_12BPC;
  5038. break;
  5039. default:
  5040. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5041. BUG();
  5042. }
  5043. if (intel_crtc->config.dither)
  5044. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5045. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5046. val |= PIPECONF_INTERLACED_ILK;
  5047. else
  5048. val |= PIPECONF_PROGRESSIVE;
  5049. if (intel_crtc->config.limited_color_range)
  5050. val |= PIPECONF_COLOR_RANGE_SELECT;
  5051. I915_WRITE(PIPECONF(pipe), val);
  5052. POSTING_READ(PIPECONF(pipe));
  5053. }
  5054. /*
  5055. * Set up the pipe CSC unit.
  5056. *
  5057. * Currently only full range RGB to limited range RGB conversion
  5058. * is supported, but eventually this should handle various
  5059. * RGB<->YCbCr scenarios as well.
  5060. */
  5061. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5062. {
  5063. struct drm_device *dev = crtc->dev;
  5064. struct drm_i915_private *dev_priv = dev->dev_private;
  5065. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5066. int pipe = intel_crtc->pipe;
  5067. uint16_t coeff = 0x7800; /* 1.0 */
  5068. /*
  5069. * TODO: Check what kind of values actually come out of the pipe
  5070. * with these coeff/postoff values and adjust to get the best
  5071. * accuracy. Perhaps we even need to take the bpc value into
  5072. * consideration.
  5073. */
  5074. if (intel_crtc->config.limited_color_range)
  5075. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5076. /*
  5077. * GY/GU and RY/RU should be the other way around according
  5078. * to BSpec, but reality doesn't agree. Just set them up in
  5079. * a way that results in the correct picture.
  5080. */
  5081. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5082. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5083. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5084. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5085. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5086. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5087. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5088. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5089. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5090. if (INTEL_INFO(dev)->gen > 6) {
  5091. uint16_t postoff = 0;
  5092. if (intel_crtc->config.limited_color_range)
  5093. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5094. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5095. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5096. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5097. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5098. } else {
  5099. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5100. if (intel_crtc->config.limited_color_range)
  5101. mode |= CSC_BLACK_SCREEN_OFFSET;
  5102. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5103. }
  5104. }
  5105. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5106. {
  5107. struct drm_device *dev = crtc->dev;
  5108. struct drm_i915_private *dev_priv = dev->dev_private;
  5109. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5110. enum pipe pipe = intel_crtc->pipe;
  5111. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5112. uint32_t val;
  5113. val = 0;
  5114. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5115. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5116. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5117. val |= PIPECONF_INTERLACED_ILK;
  5118. else
  5119. val |= PIPECONF_PROGRESSIVE;
  5120. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5121. POSTING_READ(PIPECONF(cpu_transcoder));
  5122. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5123. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5124. if (IS_BROADWELL(dev)) {
  5125. val = 0;
  5126. switch (intel_crtc->config.pipe_bpp) {
  5127. case 18:
  5128. val |= PIPEMISC_DITHER_6_BPC;
  5129. break;
  5130. case 24:
  5131. val |= PIPEMISC_DITHER_8_BPC;
  5132. break;
  5133. case 30:
  5134. val |= PIPEMISC_DITHER_10_BPC;
  5135. break;
  5136. case 36:
  5137. val |= PIPEMISC_DITHER_12_BPC;
  5138. break;
  5139. default:
  5140. /* Case prevented by pipe_config_set_bpp. */
  5141. BUG();
  5142. }
  5143. if (intel_crtc->config.dither)
  5144. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5145. I915_WRITE(PIPEMISC(pipe), val);
  5146. }
  5147. }
  5148. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5149. intel_clock_t *clock,
  5150. bool *has_reduced_clock,
  5151. intel_clock_t *reduced_clock)
  5152. {
  5153. struct drm_device *dev = crtc->dev;
  5154. struct drm_i915_private *dev_priv = dev->dev_private;
  5155. struct intel_encoder *intel_encoder;
  5156. int refclk;
  5157. const intel_limit_t *limit;
  5158. bool ret, is_lvds = false;
  5159. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5160. switch (intel_encoder->type) {
  5161. case INTEL_OUTPUT_LVDS:
  5162. is_lvds = true;
  5163. break;
  5164. }
  5165. }
  5166. refclk = ironlake_get_refclk(crtc);
  5167. /*
  5168. * Returns a set of divisors for the desired target clock with the given
  5169. * refclk, or FALSE. The returned values represent the clock equation:
  5170. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5171. */
  5172. limit = intel_limit(crtc, refclk);
  5173. ret = dev_priv->display.find_dpll(limit, crtc,
  5174. to_intel_crtc(crtc)->config.port_clock,
  5175. refclk, NULL, clock);
  5176. if (!ret)
  5177. return false;
  5178. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5179. /*
  5180. * Ensure we match the reduced clock's P to the target clock.
  5181. * If the clocks don't match, we can't switch the display clock
  5182. * by using the FP0/FP1. In such case we will disable the LVDS
  5183. * downclock feature.
  5184. */
  5185. *has_reduced_clock =
  5186. dev_priv->display.find_dpll(limit, crtc,
  5187. dev_priv->lvds_downclock,
  5188. refclk, clock,
  5189. reduced_clock);
  5190. }
  5191. return true;
  5192. }
  5193. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5194. {
  5195. /*
  5196. * Account for spread spectrum to avoid
  5197. * oversubscribing the link. Max center spread
  5198. * is 2.5%; use 5% for safety's sake.
  5199. */
  5200. u32 bps = target_clock * bpp * 21 / 20;
  5201. return bps / (link_bw * 8) + 1;
  5202. }
  5203. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5204. {
  5205. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5206. }
  5207. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5208. u32 *fp,
  5209. intel_clock_t *reduced_clock, u32 *fp2)
  5210. {
  5211. struct drm_crtc *crtc = &intel_crtc->base;
  5212. struct drm_device *dev = crtc->dev;
  5213. struct drm_i915_private *dev_priv = dev->dev_private;
  5214. struct intel_encoder *intel_encoder;
  5215. uint32_t dpll;
  5216. int factor, num_connectors = 0;
  5217. bool is_lvds = false, is_sdvo = false;
  5218. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5219. switch (intel_encoder->type) {
  5220. case INTEL_OUTPUT_LVDS:
  5221. is_lvds = true;
  5222. break;
  5223. case INTEL_OUTPUT_SDVO:
  5224. case INTEL_OUTPUT_HDMI:
  5225. is_sdvo = true;
  5226. break;
  5227. }
  5228. num_connectors++;
  5229. }
  5230. /* Enable autotuning of the PLL clock (if permissible) */
  5231. factor = 21;
  5232. if (is_lvds) {
  5233. if ((intel_panel_use_ssc(dev_priv) &&
  5234. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5235. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5236. factor = 25;
  5237. } else if (intel_crtc->config.sdvo_tv_clock)
  5238. factor = 20;
  5239. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5240. *fp |= FP_CB_TUNE;
  5241. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5242. *fp2 |= FP_CB_TUNE;
  5243. dpll = 0;
  5244. if (is_lvds)
  5245. dpll |= DPLLB_MODE_LVDS;
  5246. else
  5247. dpll |= DPLLB_MODE_DAC_SERIAL;
  5248. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  5249. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  5250. if (is_sdvo)
  5251. dpll |= DPLL_SDVO_HIGH_SPEED;
  5252. if (intel_crtc->config.has_dp_encoder)
  5253. dpll |= DPLL_SDVO_HIGH_SPEED;
  5254. /* compute bitmask from p1 value */
  5255. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5256. /* also FPA1 */
  5257. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  5258. switch (intel_crtc->config.dpll.p2) {
  5259. case 5:
  5260. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  5261. break;
  5262. case 7:
  5263. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  5264. break;
  5265. case 10:
  5266. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  5267. break;
  5268. case 14:
  5269. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  5270. break;
  5271. }
  5272. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5273. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5274. else
  5275. dpll |= PLL_REF_INPUT_DREFCLK;
  5276. return dpll | DPLL_VCO_ENABLE;
  5277. }
  5278. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  5279. int x, int y,
  5280. struct drm_framebuffer *fb)
  5281. {
  5282. struct drm_device *dev = crtc->dev;
  5283. struct drm_i915_private *dev_priv = dev->dev_private;
  5284. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5285. int pipe = intel_crtc->pipe;
  5286. int plane = intel_crtc->plane;
  5287. int num_connectors = 0;
  5288. intel_clock_t clock, reduced_clock;
  5289. u32 dpll = 0, fp = 0, fp2 = 0;
  5290. bool ok, has_reduced_clock = false;
  5291. bool is_lvds = false;
  5292. struct intel_encoder *encoder;
  5293. struct intel_shared_dpll *pll;
  5294. int ret;
  5295. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5296. switch (encoder->type) {
  5297. case INTEL_OUTPUT_LVDS:
  5298. is_lvds = true;
  5299. break;
  5300. }
  5301. num_connectors++;
  5302. }
  5303. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  5304. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  5305. ok = ironlake_compute_clocks(crtc, &clock,
  5306. &has_reduced_clock, &reduced_clock);
  5307. if (!ok && !intel_crtc->config.clock_set) {
  5308. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5309. return -EINVAL;
  5310. }
  5311. /* Compat-code for transition, will disappear. */
  5312. if (!intel_crtc->config.clock_set) {
  5313. intel_crtc->config.dpll.n = clock.n;
  5314. intel_crtc->config.dpll.m1 = clock.m1;
  5315. intel_crtc->config.dpll.m2 = clock.m2;
  5316. intel_crtc->config.dpll.p1 = clock.p1;
  5317. intel_crtc->config.dpll.p2 = clock.p2;
  5318. }
  5319. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  5320. if (intel_crtc->config.has_pch_encoder) {
  5321. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  5322. if (has_reduced_clock)
  5323. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  5324. dpll = ironlake_compute_dpll(intel_crtc,
  5325. &fp, &reduced_clock,
  5326. has_reduced_clock ? &fp2 : NULL);
  5327. intel_crtc->config.dpll_hw_state.dpll = dpll;
  5328. intel_crtc->config.dpll_hw_state.fp0 = fp;
  5329. if (has_reduced_clock)
  5330. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  5331. else
  5332. intel_crtc->config.dpll_hw_state.fp1 = fp;
  5333. pll = intel_get_shared_dpll(intel_crtc);
  5334. if (pll == NULL) {
  5335. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  5336. pipe_name(pipe));
  5337. return -EINVAL;
  5338. }
  5339. } else
  5340. intel_put_shared_dpll(intel_crtc);
  5341. if (intel_crtc->config.has_dp_encoder)
  5342. intel_dp_set_m_n(intel_crtc);
  5343. if (is_lvds && has_reduced_clock && i915.powersave)
  5344. intel_crtc->lowfreq_avail = true;
  5345. else
  5346. intel_crtc->lowfreq_avail = false;
  5347. intel_set_pipe_timings(intel_crtc);
  5348. if (intel_crtc->config.has_pch_encoder) {
  5349. intel_cpu_transcoder_set_m_n(intel_crtc,
  5350. &intel_crtc->config.fdi_m_n);
  5351. }
  5352. ironlake_set_pipeconf(crtc);
  5353. /* Set up the display plane register */
  5354. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  5355. POSTING_READ(DSPCNTR(plane));
  5356. ret = intel_pipe_set_base(crtc, x, y, fb);
  5357. return ret;
  5358. }
  5359. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  5360. struct intel_link_m_n *m_n)
  5361. {
  5362. struct drm_device *dev = crtc->base.dev;
  5363. struct drm_i915_private *dev_priv = dev->dev_private;
  5364. enum pipe pipe = crtc->pipe;
  5365. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  5366. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  5367. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  5368. & ~TU_SIZE_MASK;
  5369. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  5370. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  5371. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5372. }
  5373. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  5374. enum transcoder transcoder,
  5375. struct intel_link_m_n *m_n)
  5376. {
  5377. struct drm_device *dev = crtc->base.dev;
  5378. struct drm_i915_private *dev_priv = dev->dev_private;
  5379. enum pipe pipe = crtc->pipe;
  5380. if (INTEL_INFO(dev)->gen >= 5) {
  5381. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  5382. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  5383. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  5384. & ~TU_SIZE_MASK;
  5385. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  5386. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  5387. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5388. } else {
  5389. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  5390. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  5391. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  5392. & ~TU_SIZE_MASK;
  5393. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  5394. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  5395. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5396. }
  5397. }
  5398. void intel_dp_get_m_n(struct intel_crtc *crtc,
  5399. struct intel_crtc_config *pipe_config)
  5400. {
  5401. if (crtc->config.has_pch_encoder)
  5402. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  5403. else
  5404. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  5405. &pipe_config->dp_m_n);
  5406. }
  5407. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  5408. struct intel_crtc_config *pipe_config)
  5409. {
  5410. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  5411. &pipe_config->fdi_m_n);
  5412. }
  5413. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  5414. struct intel_crtc_config *pipe_config)
  5415. {
  5416. struct drm_device *dev = crtc->base.dev;
  5417. struct drm_i915_private *dev_priv = dev->dev_private;
  5418. uint32_t tmp;
  5419. tmp = I915_READ(PF_CTL(crtc->pipe));
  5420. if (tmp & PF_ENABLE) {
  5421. pipe_config->pch_pfit.enabled = true;
  5422. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  5423. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  5424. /* We currently do not free assignements of panel fitters on
  5425. * ivb/hsw (since we don't use the higher upscaling modes which
  5426. * differentiates them) so just WARN about this case for now. */
  5427. if (IS_GEN7(dev)) {
  5428. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  5429. PF_PIPE_SEL_IVB(crtc->pipe));
  5430. }
  5431. }
  5432. }
  5433. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  5434. struct intel_crtc_config *pipe_config)
  5435. {
  5436. struct drm_device *dev = crtc->base.dev;
  5437. struct drm_i915_private *dev_priv = dev->dev_private;
  5438. uint32_t tmp;
  5439. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5440. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5441. tmp = I915_READ(PIPECONF(crtc->pipe));
  5442. if (!(tmp & PIPECONF_ENABLE))
  5443. return false;
  5444. switch (tmp & PIPECONF_BPC_MASK) {
  5445. case PIPECONF_6BPC:
  5446. pipe_config->pipe_bpp = 18;
  5447. break;
  5448. case PIPECONF_8BPC:
  5449. pipe_config->pipe_bpp = 24;
  5450. break;
  5451. case PIPECONF_10BPC:
  5452. pipe_config->pipe_bpp = 30;
  5453. break;
  5454. case PIPECONF_12BPC:
  5455. pipe_config->pipe_bpp = 36;
  5456. break;
  5457. default:
  5458. break;
  5459. }
  5460. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  5461. struct intel_shared_dpll *pll;
  5462. pipe_config->has_pch_encoder = true;
  5463. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  5464. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  5465. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  5466. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  5467. if (HAS_PCH_IBX(dev_priv->dev)) {
  5468. pipe_config->shared_dpll =
  5469. (enum intel_dpll_id) crtc->pipe;
  5470. } else {
  5471. tmp = I915_READ(PCH_DPLL_SEL);
  5472. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  5473. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  5474. else
  5475. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  5476. }
  5477. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  5478. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  5479. &pipe_config->dpll_hw_state));
  5480. tmp = pipe_config->dpll_hw_state.dpll;
  5481. pipe_config->pixel_multiplier =
  5482. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  5483. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  5484. ironlake_pch_clock_get(crtc, pipe_config);
  5485. } else {
  5486. pipe_config->pixel_multiplier = 1;
  5487. }
  5488. intel_get_pipe_timings(crtc, pipe_config);
  5489. ironlake_get_pfit_config(crtc, pipe_config);
  5490. return true;
  5491. }
  5492. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  5493. {
  5494. struct drm_device *dev = dev_priv->dev;
  5495. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  5496. struct intel_crtc *crtc;
  5497. unsigned long irqflags;
  5498. uint32_t val;
  5499. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head)
  5500. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  5501. pipe_name(crtc->pipe));
  5502. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  5503. WARN(plls->spll_refcount, "SPLL enabled\n");
  5504. WARN(plls->wrpll1_refcount, "WRPLL1 enabled\n");
  5505. WARN(plls->wrpll2_refcount, "WRPLL2 enabled\n");
  5506. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  5507. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  5508. "CPU PWM1 enabled\n");
  5509. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  5510. "CPU PWM2 enabled\n");
  5511. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  5512. "PCH PWM1 enabled\n");
  5513. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  5514. "Utility pin enabled\n");
  5515. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  5516. spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
  5517. val = I915_READ(DEIMR);
  5518. WARN((val | DE_PCH_EVENT_IVB) != 0xffffffff,
  5519. "Unexpected DEIMR bits enabled: 0x%x\n", val);
  5520. val = I915_READ(SDEIMR);
  5521. WARN((val | SDE_HOTPLUG_MASK_CPT) != 0xffffffff,
  5522. "Unexpected SDEIMR bits enabled: 0x%x\n", val);
  5523. spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
  5524. }
  5525. /*
  5526. * This function implements pieces of two sequences from BSpec:
  5527. * - Sequence for display software to disable LCPLL
  5528. * - Sequence for display software to allow package C8+
  5529. * The steps implemented here are just the steps that actually touch the LCPLL
  5530. * register. Callers should take care of disabling all the display engine
  5531. * functions, doing the mode unset, fixing interrupts, etc.
  5532. */
  5533. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  5534. bool switch_to_fclk, bool allow_power_down)
  5535. {
  5536. uint32_t val;
  5537. assert_can_disable_lcpll(dev_priv);
  5538. val = I915_READ(LCPLL_CTL);
  5539. if (switch_to_fclk) {
  5540. val |= LCPLL_CD_SOURCE_FCLK;
  5541. I915_WRITE(LCPLL_CTL, val);
  5542. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  5543. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  5544. DRM_ERROR("Switching to FCLK failed\n");
  5545. val = I915_READ(LCPLL_CTL);
  5546. }
  5547. val |= LCPLL_PLL_DISABLE;
  5548. I915_WRITE(LCPLL_CTL, val);
  5549. POSTING_READ(LCPLL_CTL);
  5550. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  5551. DRM_ERROR("LCPLL still locked\n");
  5552. val = I915_READ(D_COMP);
  5553. val |= D_COMP_COMP_DISABLE;
  5554. mutex_lock(&dev_priv->rps.hw_lock);
  5555. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, val))
  5556. DRM_ERROR("Failed to disable D_COMP\n");
  5557. mutex_unlock(&dev_priv->rps.hw_lock);
  5558. POSTING_READ(D_COMP);
  5559. ndelay(100);
  5560. if (wait_for((I915_READ(D_COMP) & D_COMP_RCOMP_IN_PROGRESS) == 0, 1))
  5561. DRM_ERROR("D_COMP RCOMP still in progress\n");
  5562. if (allow_power_down) {
  5563. val = I915_READ(LCPLL_CTL);
  5564. val |= LCPLL_POWER_DOWN_ALLOW;
  5565. I915_WRITE(LCPLL_CTL, val);
  5566. POSTING_READ(LCPLL_CTL);
  5567. }
  5568. }
  5569. /*
  5570. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  5571. * source.
  5572. */
  5573. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  5574. {
  5575. uint32_t val;
  5576. val = I915_READ(LCPLL_CTL);
  5577. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  5578. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  5579. return;
  5580. /* Make sure we're not on PC8 state before disabling PC8, otherwise
  5581. * we'll hang the machine! */
  5582. gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
  5583. if (val & LCPLL_POWER_DOWN_ALLOW) {
  5584. val &= ~LCPLL_POWER_DOWN_ALLOW;
  5585. I915_WRITE(LCPLL_CTL, val);
  5586. POSTING_READ(LCPLL_CTL);
  5587. }
  5588. val = I915_READ(D_COMP);
  5589. val |= D_COMP_COMP_FORCE;
  5590. val &= ~D_COMP_COMP_DISABLE;
  5591. mutex_lock(&dev_priv->rps.hw_lock);
  5592. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, val))
  5593. DRM_ERROR("Failed to enable D_COMP\n");
  5594. mutex_unlock(&dev_priv->rps.hw_lock);
  5595. POSTING_READ(D_COMP);
  5596. val = I915_READ(LCPLL_CTL);
  5597. val &= ~LCPLL_PLL_DISABLE;
  5598. I915_WRITE(LCPLL_CTL, val);
  5599. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  5600. DRM_ERROR("LCPLL not locked yet\n");
  5601. if (val & LCPLL_CD_SOURCE_FCLK) {
  5602. val = I915_READ(LCPLL_CTL);
  5603. val &= ~LCPLL_CD_SOURCE_FCLK;
  5604. I915_WRITE(LCPLL_CTL, val);
  5605. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  5606. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  5607. DRM_ERROR("Switching back to LCPLL failed\n");
  5608. }
  5609. gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
  5610. }
  5611. void hsw_enable_pc8_work(struct work_struct *__work)
  5612. {
  5613. struct drm_i915_private *dev_priv =
  5614. container_of(to_delayed_work(__work), struct drm_i915_private,
  5615. pc8.enable_work);
  5616. struct drm_device *dev = dev_priv->dev;
  5617. uint32_t val;
  5618. WARN_ON(!HAS_PC8(dev));
  5619. if (dev_priv->pc8.enabled)
  5620. return;
  5621. DRM_DEBUG_KMS("Enabling package C8+\n");
  5622. dev_priv->pc8.enabled = true;
  5623. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  5624. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  5625. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  5626. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  5627. }
  5628. lpt_disable_clkout_dp(dev);
  5629. hsw_pc8_disable_interrupts(dev);
  5630. hsw_disable_lcpll(dev_priv, true, true);
  5631. intel_runtime_pm_put(dev_priv);
  5632. }
  5633. static void __hsw_enable_package_c8(struct drm_i915_private *dev_priv)
  5634. {
  5635. WARN_ON(!mutex_is_locked(&dev_priv->pc8.lock));
  5636. WARN(dev_priv->pc8.disable_count < 1,
  5637. "pc8.disable_count: %d\n", dev_priv->pc8.disable_count);
  5638. dev_priv->pc8.disable_count--;
  5639. if (dev_priv->pc8.disable_count != 0)
  5640. return;
  5641. schedule_delayed_work(&dev_priv->pc8.enable_work,
  5642. msecs_to_jiffies(i915.pc8_timeout));
  5643. }
  5644. static void __hsw_disable_package_c8(struct drm_i915_private *dev_priv)
  5645. {
  5646. struct drm_device *dev = dev_priv->dev;
  5647. uint32_t val;
  5648. WARN_ON(!mutex_is_locked(&dev_priv->pc8.lock));
  5649. WARN(dev_priv->pc8.disable_count < 0,
  5650. "pc8.disable_count: %d\n", dev_priv->pc8.disable_count);
  5651. dev_priv->pc8.disable_count++;
  5652. if (dev_priv->pc8.disable_count != 1)
  5653. return;
  5654. WARN_ON(!HAS_PC8(dev));
  5655. cancel_delayed_work_sync(&dev_priv->pc8.enable_work);
  5656. if (!dev_priv->pc8.enabled)
  5657. return;
  5658. DRM_DEBUG_KMS("Disabling package C8+\n");
  5659. intel_runtime_pm_get(dev_priv);
  5660. hsw_restore_lcpll(dev_priv);
  5661. hsw_pc8_restore_interrupts(dev);
  5662. lpt_init_pch_refclk(dev);
  5663. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  5664. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  5665. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  5666. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  5667. }
  5668. intel_prepare_ddi(dev);
  5669. i915_gem_init_swizzling(dev);
  5670. mutex_lock(&dev_priv->rps.hw_lock);
  5671. gen6_update_ring_freq(dev);
  5672. mutex_unlock(&dev_priv->rps.hw_lock);
  5673. dev_priv->pc8.enabled = false;
  5674. }
  5675. void hsw_enable_package_c8(struct drm_i915_private *dev_priv)
  5676. {
  5677. if (!HAS_PC8(dev_priv->dev))
  5678. return;
  5679. mutex_lock(&dev_priv->pc8.lock);
  5680. __hsw_enable_package_c8(dev_priv);
  5681. mutex_unlock(&dev_priv->pc8.lock);
  5682. }
  5683. void hsw_disable_package_c8(struct drm_i915_private *dev_priv)
  5684. {
  5685. if (!HAS_PC8(dev_priv->dev))
  5686. return;
  5687. mutex_lock(&dev_priv->pc8.lock);
  5688. __hsw_disable_package_c8(dev_priv);
  5689. mutex_unlock(&dev_priv->pc8.lock);
  5690. }
  5691. static bool hsw_can_enable_package_c8(struct drm_i915_private *dev_priv)
  5692. {
  5693. struct drm_device *dev = dev_priv->dev;
  5694. struct intel_crtc *crtc;
  5695. uint32_t val;
  5696. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head)
  5697. if (crtc->base.enabled)
  5698. return false;
  5699. /* This case is still possible since we have the i915.disable_power_well
  5700. * parameter and also the KVMr or something else might be requesting the
  5701. * power well. */
  5702. val = I915_READ(HSW_PWR_WELL_DRIVER);
  5703. if (val != 0) {
  5704. DRM_DEBUG_KMS("Not enabling PC8: power well on\n");
  5705. return false;
  5706. }
  5707. return true;
  5708. }
  5709. /* Since we're called from modeset_global_resources there's no way to
  5710. * symmetrically increase and decrease the refcount, so we use
  5711. * dev_priv->pc8.requirements_met to track whether we already have the refcount
  5712. * or not.
  5713. */
  5714. static void hsw_update_package_c8(struct drm_device *dev)
  5715. {
  5716. struct drm_i915_private *dev_priv = dev->dev_private;
  5717. bool allow;
  5718. if (!HAS_PC8(dev_priv->dev))
  5719. return;
  5720. if (!i915.enable_pc8)
  5721. return;
  5722. mutex_lock(&dev_priv->pc8.lock);
  5723. allow = hsw_can_enable_package_c8(dev_priv);
  5724. if (allow == dev_priv->pc8.requirements_met)
  5725. goto done;
  5726. dev_priv->pc8.requirements_met = allow;
  5727. if (allow)
  5728. __hsw_enable_package_c8(dev_priv);
  5729. else
  5730. __hsw_disable_package_c8(dev_priv);
  5731. done:
  5732. mutex_unlock(&dev_priv->pc8.lock);
  5733. }
  5734. static void hsw_package_c8_gpu_idle(struct drm_i915_private *dev_priv)
  5735. {
  5736. if (!HAS_PC8(dev_priv->dev))
  5737. return;
  5738. mutex_lock(&dev_priv->pc8.lock);
  5739. if (!dev_priv->pc8.gpu_idle) {
  5740. dev_priv->pc8.gpu_idle = true;
  5741. __hsw_enable_package_c8(dev_priv);
  5742. }
  5743. mutex_unlock(&dev_priv->pc8.lock);
  5744. }
  5745. static void hsw_package_c8_gpu_busy(struct drm_i915_private *dev_priv)
  5746. {
  5747. if (!HAS_PC8(dev_priv->dev))
  5748. return;
  5749. mutex_lock(&dev_priv->pc8.lock);
  5750. if (dev_priv->pc8.gpu_idle) {
  5751. dev_priv->pc8.gpu_idle = false;
  5752. __hsw_disable_package_c8(dev_priv);
  5753. }
  5754. mutex_unlock(&dev_priv->pc8.lock);
  5755. }
  5756. #define for_each_power_domain(domain, mask) \
  5757. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  5758. if ((1 << (domain)) & (mask))
  5759. static unsigned long get_pipe_power_domains(struct drm_device *dev,
  5760. enum pipe pipe, bool pfit_enabled)
  5761. {
  5762. unsigned long mask;
  5763. enum transcoder transcoder;
  5764. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  5765. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  5766. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  5767. if (pfit_enabled)
  5768. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  5769. return mask;
  5770. }
  5771. void intel_display_set_init_power(struct drm_device *dev, bool enable)
  5772. {
  5773. struct drm_i915_private *dev_priv = dev->dev_private;
  5774. if (dev_priv->power_domains.init_power_on == enable)
  5775. return;
  5776. if (enable)
  5777. intel_display_power_get(dev, POWER_DOMAIN_INIT);
  5778. else
  5779. intel_display_power_put(dev, POWER_DOMAIN_INIT);
  5780. dev_priv->power_domains.init_power_on = enable;
  5781. }
  5782. static void modeset_update_power_wells(struct drm_device *dev)
  5783. {
  5784. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  5785. struct intel_crtc *crtc;
  5786. /*
  5787. * First get all needed power domains, then put all unneeded, to avoid
  5788. * any unnecessary toggling of the power wells.
  5789. */
  5790. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
  5791. enum intel_display_power_domain domain;
  5792. if (!crtc->base.enabled)
  5793. continue;
  5794. pipe_domains[crtc->pipe] = get_pipe_power_domains(dev,
  5795. crtc->pipe,
  5796. crtc->config.pch_pfit.enabled);
  5797. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  5798. intel_display_power_get(dev, domain);
  5799. }
  5800. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
  5801. enum intel_display_power_domain domain;
  5802. for_each_power_domain(domain, crtc->enabled_power_domains)
  5803. intel_display_power_put(dev, domain);
  5804. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  5805. }
  5806. intel_display_set_init_power(dev, false);
  5807. }
  5808. static void haswell_modeset_global_resources(struct drm_device *dev)
  5809. {
  5810. modeset_update_power_wells(dev);
  5811. hsw_update_package_c8(dev);
  5812. }
  5813. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  5814. int x, int y,
  5815. struct drm_framebuffer *fb)
  5816. {
  5817. struct drm_device *dev = crtc->dev;
  5818. struct drm_i915_private *dev_priv = dev->dev_private;
  5819. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5820. int plane = intel_crtc->plane;
  5821. int ret;
  5822. if (!intel_ddi_pll_select(intel_crtc))
  5823. return -EINVAL;
  5824. intel_ddi_pll_enable(intel_crtc);
  5825. if (intel_crtc->config.has_dp_encoder)
  5826. intel_dp_set_m_n(intel_crtc);
  5827. intel_crtc->lowfreq_avail = false;
  5828. intel_set_pipe_timings(intel_crtc);
  5829. if (intel_crtc->config.has_pch_encoder) {
  5830. intel_cpu_transcoder_set_m_n(intel_crtc,
  5831. &intel_crtc->config.fdi_m_n);
  5832. }
  5833. haswell_set_pipeconf(crtc);
  5834. intel_set_pipe_csc(crtc);
  5835. /* Set up the display plane register */
  5836. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
  5837. POSTING_READ(DSPCNTR(plane));
  5838. ret = intel_pipe_set_base(crtc, x, y, fb);
  5839. return ret;
  5840. }
  5841. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  5842. struct intel_crtc_config *pipe_config)
  5843. {
  5844. struct drm_device *dev = crtc->base.dev;
  5845. struct drm_i915_private *dev_priv = dev->dev_private;
  5846. enum intel_display_power_domain pfit_domain;
  5847. uint32_t tmp;
  5848. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5849. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5850. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  5851. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  5852. enum pipe trans_edp_pipe;
  5853. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  5854. default:
  5855. WARN(1, "unknown pipe linked to edp transcoder\n");
  5856. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  5857. case TRANS_DDI_EDP_INPUT_A_ON:
  5858. trans_edp_pipe = PIPE_A;
  5859. break;
  5860. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  5861. trans_edp_pipe = PIPE_B;
  5862. break;
  5863. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  5864. trans_edp_pipe = PIPE_C;
  5865. break;
  5866. }
  5867. if (trans_edp_pipe == crtc->pipe)
  5868. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  5869. }
  5870. if (!intel_display_power_enabled(dev,
  5871. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  5872. return false;
  5873. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  5874. if (!(tmp & PIPECONF_ENABLE))
  5875. return false;
  5876. /*
  5877. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  5878. * DDI E. So just check whether this pipe is wired to DDI E and whether
  5879. * the PCH transcoder is on.
  5880. */
  5881. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  5882. if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(PORT_E) &&
  5883. I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  5884. pipe_config->has_pch_encoder = true;
  5885. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  5886. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  5887. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  5888. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  5889. }
  5890. intel_get_pipe_timings(crtc, pipe_config);
  5891. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  5892. if (intel_display_power_enabled(dev, pfit_domain))
  5893. ironlake_get_pfit_config(crtc, pipe_config);
  5894. if (IS_HASWELL(dev))
  5895. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  5896. (I915_READ(IPS_CTL) & IPS_ENABLE);
  5897. pipe_config->pixel_multiplier = 1;
  5898. return true;
  5899. }
  5900. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  5901. int x, int y,
  5902. struct drm_framebuffer *fb)
  5903. {
  5904. struct drm_device *dev = crtc->dev;
  5905. struct drm_i915_private *dev_priv = dev->dev_private;
  5906. struct intel_encoder *encoder;
  5907. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5908. struct drm_display_mode *mode = &intel_crtc->config.requested_mode;
  5909. int pipe = intel_crtc->pipe;
  5910. int ret;
  5911. drm_vblank_pre_modeset(dev, pipe);
  5912. ret = dev_priv->display.crtc_mode_set(crtc, x, y, fb);
  5913. drm_vblank_post_modeset(dev, pipe);
  5914. if (ret != 0)
  5915. return ret;
  5916. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5917. DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
  5918. encoder->base.base.id,
  5919. drm_get_encoder_name(&encoder->base),
  5920. mode->base.id, mode->name);
  5921. encoder->mode_set(encoder);
  5922. }
  5923. return 0;
  5924. }
  5925. static struct {
  5926. int clock;
  5927. u32 config;
  5928. } hdmi_audio_clock[] = {
  5929. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  5930. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  5931. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  5932. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  5933. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  5934. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  5935. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  5936. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  5937. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  5938. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  5939. };
  5940. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  5941. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  5942. {
  5943. int i;
  5944. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  5945. if (mode->clock == hdmi_audio_clock[i].clock)
  5946. break;
  5947. }
  5948. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  5949. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  5950. i = 1;
  5951. }
  5952. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  5953. hdmi_audio_clock[i].clock,
  5954. hdmi_audio_clock[i].config);
  5955. return hdmi_audio_clock[i].config;
  5956. }
  5957. static bool intel_eld_uptodate(struct drm_connector *connector,
  5958. int reg_eldv, uint32_t bits_eldv,
  5959. int reg_elda, uint32_t bits_elda,
  5960. int reg_edid)
  5961. {
  5962. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  5963. uint8_t *eld = connector->eld;
  5964. uint32_t i;
  5965. i = I915_READ(reg_eldv);
  5966. i &= bits_eldv;
  5967. if (!eld[0])
  5968. return !i;
  5969. if (!i)
  5970. return false;
  5971. i = I915_READ(reg_elda);
  5972. i &= ~bits_elda;
  5973. I915_WRITE(reg_elda, i);
  5974. for (i = 0; i < eld[2]; i++)
  5975. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  5976. return false;
  5977. return true;
  5978. }
  5979. static void g4x_write_eld(struct drm_connector *connector,
  5980. struct drm_crtc *crtc,
  5981. struct drm_display_mode *mode)
  5982. {
  5983. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  5984. uint8_t *eld = connector->eld;
  5985. uint32_t eldv;
  5986. uint32_t len;
  5987. uint32_t i;
  5988. i = I915_READ(G4X_AUD_VID_DID);
  5989. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  5990. eldv = G4X_ELDV_DEVCL_DEVBLC;
  5991. else
  5992. eldv = G4X_ELDV_DEVCTG;
  5993. if (intel_eld_uptodate(connector,
  5994. G4X_AUD_CNTL_ST, eldv,
  5995. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  5996. G4X_HDMIW_HDMIEDID))
  5997. return;
  5998. i = I915_READ(G4X_AUD_CNTL_ST);
  5999. i &= ~(eldv | G4X_ELD_ADDR);
  6000. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6001. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6002. if (!eld[0])
  6003. return;
  6004. len = min_t(uint8_t, eld[2], len);
  6005. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6006. for (i = 0; i < len; i++)
  6007. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6008. i = I915_READ(G4X_AUD_CNTL_ST);
  6009. i |= eldv;
  6010. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6011. }
  6012. static void haswell_write_eld(struct drm_connector *connector,
  6013. struct drm_crtc *crtc,
  6014. struct drm_display_mode *mode)
  6015. {
  6016. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6017. uint8_t *eld = connector->eld;
  6018. struct drm_device *dev = crtc->dev;
  6019. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6020. uint32_t eldv;
  6021. uint32_t i;
  6022. int len;
  6023. int pipe = to_intel_crtc(crtc)->pipe;
  6024. int tmp;
  6025. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6026. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6027. int aud_config = HSW_AUD_CFG(pipe);
  6028. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6029. DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
  6030. /* Audio output enable */
  6031. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6032. tmp = I915_READ(aud_cntrl_st2);
  6033. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6034. I915_WRITE(aud_cntrl_st2, tmp);
  6035. /* Wait for 1 vertical blank */
  6036. intel_wait_for_vblank(dev, pipe);
  6037. /* Set ELD valid state */
  6038. tmp = I915_READ(aud_cntrl_st2);
  6039. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6040. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6041. I915_WRITE(aud_cntrl_st2, tmp);
  6042. tmp = I915_READ(aud_cntrl_st2);
  6043. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6044. /* Enable HDMI mode */
  6045. tmp = I915_READ(aud_config);
  6046. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6047. /* clear N_programing_enable and N_value_index */
  6048. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6049. I915_WRITE(aud_config, tmp);
  6050. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6051. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6052. intel_crtc->eld_vld = true;
  6053. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6054. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6055. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6056. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6057. } else {
  6058. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6059. }
  6060. if (intel_eld_uptodate(connector,
  6061. aud_cntrl_st2, eldv,
  6062. aud_cntl_st, IBX_ELD_ADDRESS,
  6063. hdmiw_hdmiedid))
  6064. return;
  6065. i = I915_READ(aud_cntrl_st2);
  6066. i &= ~eldv;
  6067. I915_WRITE(aud_cntrl_st2, i);
  6068. if (!eld[0])
  6069. return;
  6070. i = I915_READ(aud_cntl_st);
  6071. i &= ~IBX_ELD_ADDRESS;
  6072. I915_WRITE(aud_cntl_st, i);
  6073. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6074. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6075. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6076. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6077. for (i = 0; i < len; i++)
  6078. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6079. i = I915_READ(aud_cntrl_st2);
  6080. i |= eldv;
  6081. I915_WRITE(aud_cntrl_st2, i);
  6082. }
  6083. static void ironlake_write_eld(struct drm_connector *connector,
  6084. struct drm_crtc *crtc,
  6085. struct drm_display_mode *mode)
  6086. {
  6087. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6088. uint8_t *eld = connector->eld;
  6089. uint32_t eldv;
  6090. uint32_t i;
  6091. int len;
  6092. int hdmiw_hdmiedid;
  6093. int aud_config;
  6094. int aud_cntl_st;
  6095. int aud_cntrl_st2;
  6096. int pipe = to_intel_crtc(crtc)->pipe;
  6097. if (HAS_PCH_IBX(connector->dev)) {
  6098. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6099. aud_config = IBX_AUD_CFG(pipe);
  6100. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6101. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6102. } else if (IS_VALLEYVIEW(connector->dev)) {
  6103. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6104. aud_config = VLV_AUD_CFG(pipe);
  6105. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6106. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6107. } else {
  6108. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6109. aud_config = CPT_AUD_CFG(pipe);
  6110. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6111. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6112. }
  6113. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6114. if (IS_VALLEYVIEW(connector->dev)) {
  6115. struct intel_encoder *intel_encoder;
  6116. struct intel_digital_port *intel_dig_port;
  6117. intel_encoder = intel_attached_encoder(connector);
  6118. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6119. i = intel_dig_port->port;
  6120. } else {
  6121. i = I915_READ(aud_cntl_st);
  6122. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6123. /* DIP_Port_Select, 0x1 = PortB */
  6124. }
  6125. if (!i) {
  6126. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6127. /* operate blindly on all ports */
  6128. eldv = IBX_ELD_VALIDB;
  6129. eldv |= IBX_ELD_VALIDB << 4;
  6130. eldv |= IBX_ELD_VALIDB << 8;
  6131. } else {
  6132. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6133. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6134. }
  6135. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6136. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6137. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6138. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6139. } else {
  6140. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6141. }
  6142. if (intel_eld_uptodate(connector,
  6143. aud_cntrl_st2, eldv,
  6144. aud_cntl_st, IBX_ELD_ADDRESS,
  6145. hdmiw_hdmiedid))
  6146. return;
  6147. i = I915_READ(aud_cntrl_st2);
  6148. i &= ~eldv;
  6149. I915_WRITE(aud_cntrl_st2, i);
  6150. if (!eld[0])
  6151. return;
  6152. i = I915_READ(aud_cntl_st);
  6153. i &= ~IBX_ELD_ADDRESS;
  6154. I915_WRITE(aud_cntl_st, i);
  6155. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6156. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6157. for (i = 0; i < len; i++)
  6158. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6159. i = I915_READ(aud_cntrl_st2);
  6160. i |= eldv;
  6161. I915_WRITE(aud_cntrl_st2, i);
  6162. }
  6163. void intel_write_eld(struct drm_encoder *encoder,
  6164. struct drm_display_mode *mode)
  6165. {
  6166. struct drm_crtc *crtc = encoder->crtc;
  6167. struct drm_connector *connector;
  6168. struct drm_device *dev = encoder->dev;
  6169. struct drm_i915_private *dev_priv = dev->dev_private;
  6170. connector = drm_select_eld(encoder, mode);
  6171. if (!connector)
  6172. return;
  6173. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6174. connector->base.id,
  6175. drm_get_connector_name(connector),
  6176. connector->encoder->base.id,
  6177. drm_get_encoder_name(connector->encoder));
  6178. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6179. if (dev_priv->display.write_eld)
  6180. dev_priv->display.write_eld(connector, crtc, mode);
  6181. }
  6182. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6183. {
  6184. struct drm_device *dev = crtc->dev;
  6185. struct drm_i915_private *dev_priv = dev->dev_private;
  6186. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6187. bool visible = base != 0;
  6188. u32 cntl;
  6189. if (intel_crtc->cursor_visible == visible)
  6190. return;
  6191. cntl = I915_READ(_CURACNTR);
  6192. if (visible) {
  6193. /* On these chipsets we can only modify the base whilst
  6194. * the cursor is disabled.
  6195. */
  6196. I915_WRITE(_CURABASE, base);
  6197. cntl &= ~(CURSOR_FORMAT_MASK);
  6198. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  6199. cntl |= CURSOR_ENABLE |
  6200. CURSOR_GAMMA_ENABLE |
  6201. CURSOR_FORMAT_ARGB;
  6202. } else
  6203. cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  6204. I915_WRITE(_CURACNTR, cntl);
  6205. intel_crtc->cursor_visible = visible;
  6206. }
  6207. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6208. {
  6209. struct drm_device *dev = crtc->dev;
  6210. struct drm_i915_private *dev_priv = dev->dev_private;
  6211. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6212. int pipe = intel_crtc->pipe;
  6213. bool visible = base != 0;
  6214. if (intel_crtc->cursor_visible != visible) {
  6215. uint32_t cntl = I915_READ(CURCNTR(pipe));
  6216. if (base) {
  6217. cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  6218. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  6219. cntl |= pipe << 28; /* Connect to correct pipe */
  6220. } else {
  6221. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  6222. cntl |= CURSOR_MODE_DISABLE;
  6223. }
  6224. I915_WRITE(CURCNTR(pipe), cntl);
  6225. intel_crtc->cursor_visible = visible;
  6226. }
  6227. /* and commit changes on next vblank */
  6228. POSTING_READ(CURCNTR(pipe));
  6229. I915_WRITE(CURBASE(pipe), base);
  6230. POSTING_READ(CURBASE(pipe));
  6231. }
  6232. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  6233. {
  6234. struct drm_device *dev = crtc->dev;
  6235. struct drm_i915_private *dev_priv = dev->dev_private;
  6236. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6237. int pipe = intel_crtc->pipe;
  6238. bool visible = base != 0;
  6239. if (intel_crtc->cursor_visible != visible) {
  6240. uint32_t cntl = I915_READ(CURCNTR_IVB(pipe));
  6241. if (base) {
  6242. cntl &= ~CURSOR_MODE;
  6243. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  6244. } else {
  6245. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  6246. cntl |= CURSOR_MODE_DISABLE;
  6247. }
  6248. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6249. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6250. cntl &= ~CURSOR_TRICKLE_FEED_DISABLE;
  6251. }
  6252. I915_WRITE(CURCNTR_IVB(pipe), cntl);
  6253. intel_crtc->cursor_visible = visible;
  6254. }
  6255. /* and commit changes on next vblank */
  6256. POSTING_READ(CURCNTR_IVB(pipe));
  6257. I915_WRITE(CURBASE_IVB(pipe), base);
  6258. POSTING_READ(CURBASE_IVB(pipe));
  6259. }
  6260. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6261. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6262. bool on)
  6263. {
  6264. struct drm_device *dev = crtc->dev;
  6265. struct drm_i915_private *dev_priv = dev->dev_private;
  6266. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6267. int pipe = intel_crtc->pipe;
  6268. int x = intel_crtc->cursor_x;
  6269. int y = intel_crtc->cursor_y;
  6270. u32 base = 0, pos = 0;
  6271. bool visible;
  6272. if (on)
  6273. base = intel_crtc->cursor_addr;
  6274. if (x >= intel_crtc->config.pipe_src_w)
  6275. base = 0;
  6276. if (y >= intel_crtc->config.pipe_src_h)
  6277. base = 0;
  6278. if (x < 0) {
  6279. if (x + intel_crtc->cursor_width <= 0)
  6280. base = 0;
  6281. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6282. x = -x;
  6283. }
  6284. pos |= x << CURSOR_X_SHIFT;
  6285. if (y < 0) {
  6286. if (y + intel_crtc->cursor_height <= 0)
  6287. base = 0;
  6288. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6289. y = -y;
  6290. }
  6291. pos |= y << CURSOR_Y_SHIFT;
  6292. visible = base != 0;
  6293. if (!visible && !intel_crtc->cursor_visible)
  6294. return;
  6295. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6296. I915_WRITE(CURPOS_IVB(pipe), pos);
  6297. ivb_update_cursor(crtc, base);
  6298. } else {
  6299. I915_WRITE(CURPOS(pipe), pos);
  6300. if (IS_845G(dev) || IS_I865G(dev))
  6301. i845_update_cursor(crtc, base);
  6302. else
  6303. i9xx_update_cursor(crtc, base);
  6304. }
  6305. }
  6306. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  6307. struct drm_file *file,
  6308. uint32_t handle,
  6309. uint32_t width, uint32_t height)
  6310. {
  6311. struct drm_device *dev = crtc->dev;
  6312. struct drm_i915_private *dev_priv = dev->dev_private;
  6313. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6314. struct drm_i915_gem_object *obj;
  6315. uint32_t addr;
  6316. int ret;
  6317. /* if we want to turn off the cursor ignore width and height */
  6318. if (!handle) {
  6319. DRM_DEBUG_KMS("cursor off\n");
  6320. addr = 0;
  6321. obj = NULL;
  6322. mutex_lock(&dev->struct_mutex);
  6323. goto finish;
  6324. }
  6325. /* Currently we only support 64x64 cursors */
  6326. if (width != 64 || height != 64) {
  6327. DRM_ERROR("we currently only support 64x64 cursors\n");
  6328. return -EINVAL;
  6329. }
  6330. obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
  6331. if (&obj->base == NULL)
  6332. return -ENOENT;
  6333. if (obj->base.size < width * height * 4) {
  6334. DRM_ERROR("buffer is to small\n");
  6335. ret = -ENOMEM;
  6336. goto fail;
  6337. }
  6338. /* we only need to pin inside GTT if cursor is non-phy */
  6339. mutex_lock(&dev->struct_mutex);
  6340. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  6341. unsigned alignment;
  6342. if (obj->tiling_mode) {
  6343. DRM_ERROR("cursor cannot be tiled\n");
  6344. ret = -EINVAL;
  6345. goto fail_locked;
  6346. }
  6347. /* Note that the w/a also requires 2 PTE of padding following
  6348. * the bo. We currently fill all unused PTE with the shadow
  6349. * page and so we should always have valid PTE following the
  6350. * cursor preventing the VT-d warning.
  6351. */
  6352. alignment = 0;
  6353. if (need_vtd_wa(dev))
  6354. alignment = 64*1024;
  6355. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  6356. if (ret) {
  6357. DRM_ERROR("failed to move cursor bo into the GTT\n");
  6358. goto fail_locked;
  6359. }
  6360. ret = i915_gem_object_put_fence(obj);
  6361. if (ret) {
  6362. DRM_ERROR("failed to release fence for cursor");
  6363. goto fail_unpin;
  6364. }
  6365. addr = i915_gem_obj_ggtt_offset(obj);
  6366. } else {
  6367. int align = IS_I830(dev) ? 16 * 1024 : 256;
  6368. ret = i915_gem_attach_phys_object(dev, obj,
  6369. (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
  6370. align);
  6371. if (ret) {
  6372. DRM_ERROR("failed to attach phys object\n");
  6373. goto fail_locked;
  6374. }
  6375. addr = obj->phys_obj->handle->busaddr;
  6376. }
  6377. if (IS_GEN2(dev))
  6378. I915_WRITE(CURSIZE, (height << 12) | width);
  6379. finish:
  6380. if (intel_crtc->cursor_bo) {
  6381. if (INTEL_INFO(dev)->cursor_needs_physical) {
  6382. if (intel_crtc->cursor_bo != obj)
  6383. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  6384. } else
  6385. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  6386. drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
  6387. }
  6388. mutex_unlock(&dev->struct_mutex);
  6389. intel_crtc->cursor_addr = addr;
  6390. intel_crtc->cursor_bo = obj;
  6391. intel_crtc->cursor_width = width;
  6392. intel_crtc->cursor_height = height;
  6393. if (intel_crtc->active)
  6394. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  6395. return 0;
  6396. fail_unpin:
  6397. i915_gem_object_unpin_from_display_plane(obj);
  6398. fail_locked:
  6399. mutex_unlock(&dev->struct_mutex);
  6400. fail:
  6401. drm_gem_object_unreference_unlocked(&obj->base);
  6402. return ret;
  6403. }
  6404. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  6405. {
  6406. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6407. intel_crtc->cursor_x = clamp_t(int, x, SHRT_MIN, SHRT_MAX);
  6408. intel_crtc->cursor_y = clamp_t(int, y, SHRT_MIN, SHRT_MAX);
  6409. if (intel_crtc->active)
  6410. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  6411. return 0;
  6412. }
  6413. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  6414. u16 *blue, uint32_t start, uint32_t size)
  6415. {
  6416. int end = (start + size > 256) ? 256 : start + size, i;
  6417. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6418. for (i = start; i < end; i++) {
  6419. intel_crtc->lut_r[i] = red[i] >> 8;
  6420. intel_crtc->lut_g[i] = green[i] >> 8;
  6421. intel_crtc->lut_b[i] = blue[i] >> 8;
  6422. }
  6423. intel_crtc_load_lut(crtc);
  6424. }
  6425. /* VESA 640x480x72Hz mode to set on the pipe */
  6426. static struct drm_display_mode load_detect_mode = {
  6427. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  6428. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  6429. };
  6430. static int intel_framebuffer_init(struct drm_device *dev,
  6431. struct intel_framebuffer *ifb,
  6432. struct drm_mode_fb_cmd2 *mode_cmd,
  6433. struct drm_i915_gem_object *obj);
  6434. struct drm_framebuffer *
  6435. __intel_framebuffer_create(struct drm_device *dev,
  6436. struct drm_mode_fb_cmd2 *mode_cmd,
  6437. struct drm_i915_gem_object *obj)
  6438. {
  6439. struct intel_framebuffer *intel_fb;
  6440. int ret;
  6441. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  6442. if (!intel_fb) {
  6443. drm_gem_object_unreference_unlocked(&obj->base);
  6444. return ERR_PTR(-ENOMEM);
  6445. }
  6446. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  6447. if (ret)
  6448. goto err;
  6449. return &intel_fb->base;
  6450. err:
  6451. drm_gem_object_unreference_unlocked(&obj->base);
  6452. kfree(intel_fb);
  6453. return ERR_PTR(ret);
  6454. }
  6455. struct drm_framebuffer *
  6456. intel_framebuffer_create(struct drm_device *dev,
  6457. struct drm_mode_fb_cmd2 *mode_cmd,
  6458. struct drm_i915_gem_object *obj)
  6459. {
  6460. struct drm_framebuffer *fb;
  6461. int ret;
  6462. ret = i915_mutex_lock_interruptible(dev);
  6463. if (ret)
  6464. return ERR_PTR(ret);
  6465. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  6466. mutex_unlock(&dev->struct_mutex);
  6467. return fb;
  6468. }
  6469. static u32
  6470. intel_framebuffer_pitch_for_width(int width, int bpp)
  6471. {
  6472. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  6473. return ALIGN(pitch, 64);
  6474. }
  6475. static u32
  6476. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  6477. {
  6478. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  6479. return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
  6480. }
  6481. static struct drm_framebuffer *
  6482. intel_framebuffer_create_for_mode(struct drm_device *dev,
  6483. struct drm_display_mode *mode,
  6484. int depth, int bpp)
  6485. {
  6486. struct drm_i915_gem_object *obj;
  6487. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  6488. obj = i915_gem_alloc_object(dev,
  6489. intel_framebuffer_size_for_mode(mode, bpp));
  6490. if (obj == NULL)
  6491. return ERR_PTR(-ENOMEM);
  6492. mode_cmd.width = mode->hdisplay;
  6493. mode_cmd.height = mode->vdisplay;
  6494. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  6495. bpp);
  6496. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  6497. return intel_framebuffer_create(dev, &mode_cmd, obj);
  6498. }
  6499. static struct drm_framebuffer *
  6500. mode_fits_in_fbdev(struct drm_device *dev,
  6501. struct drm_display_mode *mode)
  6502. {
  6503. #ifdef CONFIG_DRM_I915_FBDEV
  6504. struct drm_i915_private *dev_priv = dev->dev_private;
  6505. struct drm_i915_gem_object *obj;
  6506. struct drm_framebuffer *fb;
  6507. if (dev_priv->fbdev == NULL)
  6508. return NULL;
  6509. obj = dev_priv->fbdev->fb->obj;
  6510. if (obj == NULL)
  6511. return NULL;
  6512. fb = &dev_priv->fbdev->fb->base;
  6513. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  6514. fb->bits_per_pixel))
  6515. return NULL;
  6516. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  6517. return NULL;
  6518. return fb;
  6519. #else
  6520. return NULL;
  6521. #endif
  6522. }
  6523. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  6524. struct drm_display_mode *mode,
  6525. struct intel_load_detect_pipe *old)
  6526. {
  6527. struct intel_crtc *intel_crtc;
  6528. struct intel_encoder *intel_encoder =
  6529. intel_attached_encoder(connector);
  6530. struct drm_crtc *possible_crtc;
  6531. struct drm_encoder *encoder = &intel_encoder->base;
  6532. struct drm_crtc *crtc = NULL;
  6533. struct drm_device *dev = encoder->dev;
  6534. struct drm_framebuffer *fb;
  6535. int i = -1;
  6536. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6537. connector->base.id, drm_get_connector_name(connector),
  6538. encoder->base.id, drm_get_encoder_name(encoder));
  6539. /*
  6540. * Algorithm gets a little messy:
  6541. *
  6542. * - if the connector already has an assigned crtc, use it (but make
  6543. * sure it's on first)
  6544. *
  6545. * - try to find the first unused crtc that can drive this connector,
  6546. * and use that if we find one
  6547. */
  6548. /* See if we already have a CRTC for this connector */
  6549. if (encoder->crtc) {
  6550. crtc = encoder->crtc;
  6551. mutex_lock(&crtc->mutex);
  6552. old->dpms_mode = connector->dpms;
  6553. old->load_detect_temp = false;
  6554. /* Make sure the crtc and connector are running */
  6555. if (connector->dpms != DRM_MODE_DPMS_ON)
  6556. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  6557. return true;
  6558. }
  6559. /* Find an unused one (if possible) */
  6560. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  6561. i++;
  6562. if (!(encoder->possible_crtcs & (1 << i)))
  6563. continue;
  6564. if (!possible_crtc->enabled) {
  6565. crtc = possible_crtc;
  6566. break;
  6567. }
  6568. }
  6569. /*
  6570. * If we didn't find an unused CRTC, don't use any.
  6571. */
  6572. if (!crtc) {
  6573. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  6574. return false;
  6575. }
  6576. mutex_lock(&crtc->mutex);
  6577. intel_encoder->new_crtc = to_intel_crtc(crtc);
  6578. to_intel_connector(connector)->new_encoder = intel_encoder;
  6579. intel_crtc = to_intel_crtc(crtc);
  6580. intel_crtc->new_enabled = true;
  6581. intel_crtc->new_config = &intel_crtc->config;
  6582. old->dpms_mode = connector->dpms;
  6583. old->load_detect_temp = true;
  6584. old->release_fb = NULL;
  6585. if (!mode)
  6586. mode = &load_detect_mode;
  6587. /* We need a framebuffer large enough to accommodate all accesses
  6588. * that the plane may generate whilst we perform load detection.
  6589. * We can not rely on the fbcon either being present (we get called
  6590. * during its initialisation to detect all boot displays, or it may
  6591. * not even exist) or that it is large enough to satisfy the
  6592. * requested mode.
  6593. */
  6594. fb = mode_fits_in_fbdev(dev, mode);
  6595. if (fb == NULL) {
  6596. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  6597. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  6598. old->release_fb = fb;
  6599. } else
  6600. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  6601. if (IS_ERR(fb)) {
  6602. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  6603. goto fail;
  6604. }
  6605. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  6606. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  6607. if (old->release_fb)
  6608. old->release_fb->funcs->destroy(old->release_fb);
  6609. goto fail;
  6610. }
  6611. /* let the connector get through one full cycle before testing */
  6612. intel_wait_for_vblank(dev, intel_crtc->pipe);
  6613. return true;
  6614. fail:
  6615. intel_crtc->new_enabled = crtc->enabled;
  6616. if (intel_crtc->new_enabled)
  6617. intel_crtc->new_config = &intel_crtc->config;
  6618. else
  6619. intel_crtc->new_config = NULL;
  6620. mutex_unlock(&crtc->mutex);
  6621. return false;
  6622. }
  6623. void intel_release_load_detect_pipe(struct drm_connector *connector,
  6624. struct intel_load_detect_pipe *old)
  6625. {
  6626. struct intel_encoder *intel_encoder =
  6627. intel_attached_encoder(connector);
  6628. struct drm_encoder *encoder = &intel_encoder->base;
  6629. struct drm_crtc *crtc = encoder->crtc;
  6630. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6631. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6632. connector->base.id, drm_get_connector_name(connector),
  6633. encoder->base.id, drm_get_encoder_name(encoder));
  6634. if (old->load_detect_temp) {
  6635. to_intel_connector(connector)->new_encoder = NULL;
  6636. intel_encoder->new_crtc = NULL;
  6637. intel_crtc->new_enabled = false;
  6638. intel_crtc->new_config = NULL;
  6639. intel_set_mode(crtc, NULL, 0, 0, NULL);
  6640. if (old->release_fb) {
  6641. drm_framebuffer_unregister_private(old->release_fb);
  6642. drm_framebuffer_unreference(old->release_fb);
  6643. }
  6644. mutex_unlock(&crtc->mutex);
  6645. return;
  6646. }
  6647. /* Switch crtc and encoder back off if necessary */
  6648. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  6649. connector->funcs->dpms(connector, old->dpms_mode);
  6650. mutex_unlock(&crtc->mutex);
  6651. }
  6652. static int i9xx_pll_refclk(struct drm_device *dev,
  6653. const struct intel_crtc_config *pipe_config)
  6654. {
  6655. struct drm_i915_private *dev_priv = dev->dev_private;
  6656. u32 dpll = pipe_config->dpll_hw_state.dpll;
  6657. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  6658. return dev_priv->vbt.lvds_ssc_freq;
  6659. else if (HAS_PCH_SPLIT(dev))
  6660. return 120000;
  6661. else if (!IS_GEN2(dev))
  6662. return 96000;
  6663. else
  6664. return 48000;
  6665. }
  6666. /* Returns the clock of the currently programmed mode of the given pipe. */
  6667. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  6668. struct intel_crtc_config *pipe_config)
  6669. {
  6670. struct drm_device *dev = crtc->base.dev;
  6671. struct drm_i915_private *dev_priv = dev->dev_private;
  6672. int pipe = pipe_config->cpu_transcoder;
  6673. u32 dpll = pipe_config->dpll_hw_state.dpll;
  6674. u32 fp;
  6675. intel_clock_t clock;
  6676. int refclk = i9xx_pll_refclk(dev, pipe_config);
  6677. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  6678. fp = pipe_config->dpll_hw_state.fp0;
  6679. else
  6680. fp = pipe_config->dpll_hw_state.fp1;
  6681. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  6682. if (IS_PINEVIEW(dev)) {
  6683. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  6684. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  6685. } else {
  6686. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  6687. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  6688. }
  6689. if (!IS_GEN2(dev)) {
  6690. if (IS_PINEVIEW(dev))
  6691. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  6692. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  6693. else
  6694. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  6695. DPLL_FPA01_P1_POST_DIV_SHIFT);
  6696. switch (dpll & DPLL_MODE_MASK) {
  6697. case DPLLB_MODE_DAC_SERIAL:
  6698. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  6699. 5 : 10;
  6700. break;
  6701. case DPLLB_MODE_LVDS:
  6702. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  6703. 7 : 14;
  6704. break;
  6705. default:
  6706. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  6707. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  6708. return;
  6709. }
  6710. if (IS_PINEVIEW(dev))
  6711. pineview_clock(refclk, &clock);
  6712. else
  6713. i9xx_clock(refclk, &clock);
  6714. } else {
  6715. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  6716. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  6717. if (is_lvds) {
  6718. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  6719. DPLL_FPA01_P1_POST_DIV_SHIFT);
  6720. if (lvds & LVDS_CLKB_POWER_UP)
  6721. clock.p2 = 7;
  6722. else
  6723. clock.p2 = 14;
  6724. } else {
  6725. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  6726. clock.p1 = 2;
  6727. else {
  6728. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  6729. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  6730. }
  6731. if (dpll & PLL_P2_DIVIDE_BY_4)
  6732. clock.p2 = 4;
  6733. else
  6734. clock.p2 = 2;
  6735. }
  6736. i9xx_clock(refclk, &clock);
  6737. }
  6738. /*
  6739. * This value includes pixel_multiplier. We will use
  6740. * port_clock to compute adjusted_mode.crtc_clock in the
  6741. * encoder's get_config() function.
  6742. */
  6743. pipe_config->port_clock = clock.dot;
  6744. }
  6745. int intel_dotclock_calculate(int link_freq,
  6746. const struct intel_link_m_n *m_n)
  6747. {
  6748. /*
  6749. * The calculation for the data clock is:
  6750. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  6751. * But we want to avoid losing precison if possible, so:
  6752. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  6753. *
  6754. * and the link clock is simpler:
  6755. * link_clock = (m * link_clock) / n
  6756. */
  6757. if (!m_n->link_n)
  6758. return 0;
  6759. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  6760. }
  6761. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  6762. struct intel_crtc_config *pipe_config)
  6763. {
  6764. struct drm_device *dev = crtc->base.dev;
  6765. /* read out port_clock from the DPLL */
  6766. i9xx_crtc_clock_get(crtc, pipe_config);
  6767. /*
  6768. * This value does not include pixel_multiplier.
  6769. * We will check that port_clock and adjusted_mode.crtc_clock
  6770. * agree once we know their relationship in the encoder's
  6771. * get_config() function.
  6772. */
  6773. pipe_config->adjusted_mode.crtc_clock =
  6774. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  6775. &pipe_config->fdi_m_n);
  6776. }
  6777. /** Returns the currently programmed mode of the given pipe. */
  6778. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  6779. struct drm_crtc *crtc)
  6780. {
  6781. struct drm_i915_private *dev_priv = dev->dev_private;
  6782. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6783. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  6784. struct drm_display_mode *mode;
  6785. struct intel_crtc_config pipe_config;
  6786. int htot = I915_READ(HTOTAL(cpu_transcoder));
  6787. int hsync = I915_READ(HSYNC(cpu_transcoder));
  6788. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  6789. int vsync = I915_READ(VSYNC(cpu_transcoder));
  6790. enum pipe pipe = intel_crtc->pipe;
  6791. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  6792. if (!mode)
  6793. return NULL;
  6794. /*
  6795. * Construct a pipe_config sufficient for getting the clock info
  6796. * back out of crtc_clock_get.
  6797. *
  6798. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  6799. * to use a real value here instead.
  6800. */
  6801. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  6802. pipe_config.pixel_multiplier = 1;
  6803. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  6804. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  6805. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  6806. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  6807. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  6808. mode->hdisplay = (htot & 0xffff) + 1;
  6809. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  6810. mode->hsync_start = (hsync & 0xffff) + 1;
  6811. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  6812. mode->vdisplay = (vtot & 0xffff) + 1;
  6813. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  6814. mode->vsync_start = (vsync & 0xffff) + 1;
  6815. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  6816. drm_mode_set_name(mode);
  6817. return mode;
  6818. }
  6819. static void intel_increase_pllclock(struct drm_crtc *crtc)
  6820. {
  6821. struct drm_device *dev = crtc->dev;
  6822. drm_i915_private_t *dev_priv = dev->dev_private;
  6823. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6824. int pipe = intel_crtc->pipe;
  6825. int dpll_reg = DPLL(pipe);
  6826. int dpll;
  6827. if (HAS_PCH_SPLIT(dev))
  6828. return;
  6829. if (!dev_priv->lvds_downclock_avail)
  6830. return;
  6831. dpll = I915_READ(dpll_reg);
  6832. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  6833. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  6834. assert_panel_unlocked(dev_priv, pipe);
  6835. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  6836. I915_WRITE(dpll_reg, dpll);
  6837. intel_wait_for_vblank(dev, pipe);
  6838. dpll = I915_READ(dpll_reg);
  6839. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  6840. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  6841. }
  6842. }
  6843. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  6844. {
  6845. struct drm_device *dev = crtc->dev;
  6846. drm_i915_private_t *dev_priv = dev->dev_private;
  6847. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6848. if (HAS_PCH_SPLIT(dev))
  6849. return;
  6850. if (!dev_priv->lvds_downclock_avail)
  6851. return;
  6852. /*
  6853. * Since this is called by a timer, we should never get here in
  6854. * the manual case.
  6855. */
  6856. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  6857. int pipe = intel_crtc->pipe;
  6858. int dpll_reg = DPLL(pipe);
  6859. int dpll;
  6860. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  6861. assert_panel_unlocked(dev_priv, pipe);
  6862. dpll = I915_READ(dpll_reg);
  6863. dpll |= DISPLAY_RATE_SELECT_FPA1;
  6864. I915_WRITE(dpll_reg, dpll);
  6865. intel_wait_for_vblank(dev, pipe);
  6866. dpll = I915_READ(dpll_reg);
  6867. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  6868. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  6869. }
  6870. }
  6871. void intel_mark_busy(struct drm_device *dev)
  6872. {
  6873. struct drm_i915_private *dev_priv = dev->dev_private;
  6874. hsw_package_c8_gpu_busy(dev_priv);
  6875. i915_update_gfx_val(dev_priv);
  6876. }
  6877. void intel_mark_idle(struct drm_device *dev)
  6878. {
  6879. struct drm_i915_private *dev_priv = dev->dev_private;
  6880. struct drm_crtc *crtc;
  6881. hsw_package_c8_gpu_idle(dev_priv);
  6882. if (!i915.powersave)
  6883. return;
  6884. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  6885. if (!crtc->fb)
  6886. continue;
  6887. intel_decrease_pllclock(crtc);
  6888. }
  6889. if (INTEL_INFO(dev)->gen >= 6)
  6890. gen6_rps_idle(dev->dev_private);
  6891. }
  6892. void intel_mark_fb_busy(struct drm_i915_gem_object *obj,
  6893. struct intel_ring_buffer *ring)
  6894. {
  6895. struct drm_device *dev = obj->base.dev;
  6896. struct drm_crtc *crtc;
  6897. if (!i915.powersave)
  6898. return;
  6899. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  6900. if (!crtc->fb)
  6901. continue;
  6902. if (to_intel_framebuffer(crtc->fb)->obj != obj)
  6903. continue;
  6904. intel_increase_pllclock(crtc);
  6905. if (ring && intel_fbc_enabled(dev))
  6906. ring->fbc_dirty = true;
  6907. }
  6908. }
  6909. static void intel_crtc_destroy(struct drm_crtc *crtc)
  6910. {
  6911. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6912. struct drm_device *dev = crtc->dev;
  6913. struct intel_unpin_work *work;
  6914. unsigned long flags;
  6915. spin_lock_irqsave(&dev->event_lock, flags);
  6916. work = intel_crtc->unpin_work;
  6917. intel_crtc->unpin_work = NULL;
  6918. spin_unlock_irqrestore(&dev->event_lock, flags);
  6919. if (work) {
  6920. cancel_work_sync(&work->work);
  6921. kfree(work);
  6922. }
  6923. intel_crtc_cursor_set(crtc, NULL, 0, 0, 0);
  6924. drm_crtc_cleanup(crtc);
  6925. kfree(intel_crtc);
  6926. }
  6927. static void intel_unpin_work_fn(struct work_struct *__work)
  6928. {
  6929. struct intel_unpin_work *work =
  6930. container_of(__work, struct intel_unpin_work, work);
  6931. struct drm_device *dev = work->crtc->dev;
  6932. mutex_lock(&dev->struct_mutex);
  6933. intel_unpin_fb_obj(work->old_fb_obj);
  6934. drm_gem_object_unreference(&work->pending_flip_obj->base);
  6935. drm_gem_object_unreference(&work->old_fb_obj->base);
  6936. intel_update_fbc(dev);
  6937. mutex_unlock(&dev->struct_mutex);
  6938. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  6939. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  6940. kfree(work);
  6941. }
  6942. static void do_intel_finish_page_flip(struct drm_device *dev,
  6943. struct drm_crtc *crtc)
  6944. {
  6945. drm_i915_private_t *dev_priv = dev->dev_private;
  6946. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6947. struct intel_unpin_work *work;
  6948. unsigned long flags;
  6949. /* Ignore early vblank irqs */
  6950. if (intel_crtc == NULL)
  6951. return;
  6952. spin_lock_irqsave(&dev->event_lock, flags);
  6953. work = intel_crtc->unpin_work;
  6954. /* Ensure we don't miss a work->pending update ... */
  6955. smp_rmb();
  6956. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  6957. spin_unlock_irqrestore(&dev->event_lock, flags);
  6958. return;
  6959. }
  6960. /* and that the unpin work is consistent wrt ->pending. */
  6961. smp_rmb();
  6962. intel_crtc->unpin_work = NULL;
  6963. if (work->event)
  6964. drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
  6965. drm_vblank_put(dev, intel_crtc->pipe);
  6966. spin_unlock_irqrestore(&dev->event_lock, flags);
  6967. wake_up_all(&dev_priv->pending_flip_queue);
  6968. queue_work(dev_priv->wq, &work->work);
  6969. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  6970. }
  6971. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  6972. {
  6973. drm_i915_private_t *dev_priv = dev->dev_private;
  6974. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  6975. do_intel_finish_page_flip(dev, crtc);
  6976. }
  6977. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  6978. {
  6979. drm_i915_private_t *dev_priv = dev->dev_private;
  6980. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  6981. do_intel_finish_page_flip(dev, crtc);
  6982. }
  6983. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  6984. {
  6985. drm_i915_private_t *dev_priv = dev->dev_private;
  6986. struct intel_crtc *intel_crtc =
  6987. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  6988. unsigned long flags;
  6989. /* NB: An MMIO update of the plane base pointer will also
  6990. * generate a page-flip completion irq, i.e. every modeset
  6991. * is also accompanied by a spurious intel_prepare_page_flip().
  6992. */
  6993. spin_lock_irqsave(&dev->event_lock, flags);
  6994. if (intel_crtc->unpin_work)
  6995. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  6996. spin_unlock_irqrestore(&dev->event_lock, flags);
  6997. }
  6998. inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  6999. {
  7000. /* Ensure that the work item is consistent when activating it ... */
  7001. smp_wmb();
  7002. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7003. /* and that it is marked active as soon as the irq could fire. */
  7004. smp_wmb();
  7005. }
  7006. static int intel_gen2_queue_flip(struct drm_device *dev,
  7007. struct drm_crtc *crtc,
  7008. struct drm_framebuffer *fb,
  7009. struct drm_i915_gem_object *obj,
  7010. uint32_t flags)
  7011. {
  7012. struct drm_i915_private *dev_priv = dev->dev_private;
  7013. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7014. u32 flip_mask;
  7015. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  7016. int ret;
  7017. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  7018. if (ret)
  7019. goto err;
  7020. ret = intel_ring_begin(ring, 6);
  7021. if (ret)
  7022. goto err_unpin;
  7023. /* Can't queue multiple flips, so wait for the previous
  7024. * one to finish before executing the next.
  7025. */
  7026. if (intel_crtc->plane)
  7027. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7028. else
  7029. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7030. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7031. intel_ring_emit(ring, MI_NOOP);
  7032. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7033. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7034. intel_ring_emit(ring, fb->pitches[0]);
  7035. intel_ring_emit(ring, i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  7036. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7037. intel_mark_page_flip_active(intel_crtc);
  7038. __intel_ring_advance(ring);
  7039. return 0;
  7040. err_unpin:
  7041. intel_unpin_fb_obj(obj);
  7042. err:
  7043. return ret;
  7044. }
  7045. static int intel_gen3_queue_flip(struct drm_device *dev,
  7046. struct drm_crtc *crtc,
  7047. struct drm_framebuffer *fb,
  7048. struct drm_i915_gem_object *obj,
  7049. uint32_t flags)
  7050. {
  7051. struct drm_i915_private *dev_priv = dev->dev_private;
  7052. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7053. u32 flip_mask;
  7054. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  7055. int ret;
  7056. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  7057. if (ret)
  7058. goto err;
  7059. ret = intel_ring_begin(ring, 6);
  7060. if (ret)
  7061. goto err_unpin;
  7062. if (intel_crtc->plane)
  7063. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7064. else
  7065. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7066. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7067. intel_ring_emit(ring, MI_NOOP);
  7068. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7069. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7070. intel_ring_emit(ring, fb->pitches[0]);
  7071. intel_ring_emit(ring, i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  7072. intel_ring_emit(ring, MI_NOOP);
  7073. intel_mark_page_flip_active(intel_crtc);
  7074. __intel_ring_advance(ring);
  7075. return 0;
  7076. err_unpin:
  7077. intel_unpin_fb_obj(obj);
  7078. err:
  7079. return ret;
  7080. }
  7081. static int intel_gen4_queue_flip(struct drm_device *dev,
  7082. struct drm_crtc *crtc,
  7083. struct drm_framebuffer *fb,
  7084. struct drm_i915_gem_object *obj,
  7085. uint32_t flags)
  7086. {
  7087. struct drm_i915_private *dev_priv = dev->dev_private;
  7088. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7089. uint32_t pf, pipesrc;
  7090. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  7091. int ret;
  7092. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  7093. if (ret)
  7094. goto err;
  7095. ret = intel_ring_begin(ring, 4);
  7096. if (ret)
  7097. goto err_unpin;
  7098. /* i965+ uses the linear or tiled offsets from the
  7099. * Display Registers (which do not change across a page-flip)
  7100. * so we need only reprogram the base address.
  7101. */
  7102. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7103. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7104. intel_ring_emit(ring, fb->pitches[0]);
  7105. intel_ring_emit(ring,
  7106. (i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset) |
  7107. obj->tiling_mode);
  7108. /* XXX Enabling the panel-fitter across page-flip is so far
  7109. * untested on non-native modes, so ignore it for now.
  7110. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  7111. */
  7112. pf = 0;
  7113. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7114. intel_ring_emit(ring, pf | pipesrc);
  7115. intel_mark_page_flip_active(intel_crtc);
  7116. __intel_ring_advance(ring);
  7117. return 0;
  7118. err_unpin:
  7119. intel_unpin_fb_obj(obj);
  7120. err:
  7121. return ret;
  7122. }
  7123. static int intel_gen6_queue_flip(struct drm_device *dev,
  7124. struct drm_crtc *crtc,
  7125. struct drm_framebuffer *fb,
  7126. struct drm_i915_gem_object *obj,
  7127. uint32_t flags)
  7128. {
  7129. struct drm_i915_private *dev_priv = dev->dev_private;
  7130. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7131. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  7132. uint32_t pf, pipesrc;
  7133. int ret;
  7134. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  7135. if (ret)
  7136. goto err;
  7137. ret = intel_ring_begin(ring, 4);
  7138. if (ret)
  7139. goto err_unpin;
  7140. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7141. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7142. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  7143. intel_ring_emit(ring, i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  7144. /* Contrary to the suggestions in the documentation,
  7145. * "Enable Panel Fitter" does not seem to be required when page
  7146. * flipping with a non-native mode, and worse causes a normal
  7147. * modeset to fail.
  7148. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  7149. */
  7150. pf = 0;
  7151. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7152. intel_ring_emit(ring, pf | pipesrc);
  7153. intel_mark_page_flip_active(intel_crtc);
  7154. __intel_ring_advance(ring);
  7155. return 0;
  7156. err_unpin:
  7157. intel_unpin_fb_obj(obj);
  7158. err:
  7159. return ret;
  7160. }
  7161. static int intel_gen7_queue_flip(struct drm_device *dev,
  7162. struct drm_crtc *crtc,
  7163. struct drm_framebuffer *fb,
  7164. struct drm_i915_gem_object *obj,
  7165. uint32_t flags)
  7166. {
  7167. struct drm_i915_private *dev_priv = dev->dev_private;
  7168. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7169. struct intel_ring_buffer *ring;
  7170. uint32_t plane_bit = 0;
  7171. int len, ret;
  7172. ring = obj->ring;
  7173. if (IS_VALLEYVIEW(dev) || ring == NULL || ring->id != RCS)
  7174. ring = &dev_priv->ring[BCS];
  7175. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  7176. if (ret)
  7177. goto err;
  7178. switch(intel_crtc->plane) {
  7179. case PLANE_A:
  7180. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  7181. break;
  7182. case PLANE_B:
  7183. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  7184. break;
  7185. case PLANE_C:
  7186. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  7187. break;
  7188. default:
  7189. WARN_ONCE(1, "unknown plane in flip command\n");
  7190. ret = -ENODEV;
  7191. goto err_unpin;
  7192. }
  7193. len = 4;
  7194. if (ring->id == RCS)
  7195. len += 6;
  7196. ret = intel_ring_begin(ring, len);
  7197. if (ret)
  7198. goto err_unpin;
  7199. /* Unmask the flip-done completion message. Note that the bspec says that
  7200. * we should do this for both the BCS and RCS, and that we must not unmask
  7201. * more than one flip event at any time (or ensure that one flip message
  7202. * can be sent by waiting for flip-done prior to queueing new flips).
  7203. * Experimentation says that BCS works despite DERRMR masking all
  7204. * flip-done completion events and that unmasking all planes at once
  7205. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  7206. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  7207. */
  7208. if (ring->id == RCS) {
  7209. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  7210. intel_ring_emit(ring, DERRMR);
  7211. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  7212. DERRMR_PIPEB_PRI_FLIP_DONE |
  7213. DERRMR_PIPEC_PRI_FLIP_DONE));
  7214. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  7215. MI_SRM_LRM_GLOBAL_GTT);
  7216. intel_ring_emit(ring, DERRMR);
  7217. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  7218. }
  7219. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  7220. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  7221. intel_ring_emit(ring, i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  7222. intel_ring_emit(ring, (MI_NOOP));
  7223. intel_mark_page_flip_active(intel_crtc);
  7224. __intel_ring_advance(ring);
  7225. return 0;
  7226. err_unpin:
  7227. intel_unpin_fb_obj(obj);
  7228. err:
  7229. return ret;
  7230. }
  7231. static int intel_default_queue_flip(struct drm_device *dev,
  7232. struct drm_crtc *crtc,
  7233. struct drm_framebuffer *fb,
  7234. struct drm_i915_gem_object *obj,
  7235. uint32_t flags)
  7236. {
  7237. return -ENODEV;
  7238. }
  7239. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  7240. struct drm_framebuffer *fb,
  7241. struct drm_pending_vblank_event *event,
  7242. uint32_t page_flip_flags)
  7243. {
  7244. struct drm_device *dev = crtc->dev;
  7245. struct drm_i915_private *dev_priv = dev->dev_private;
  7246. struct drm_framebuffer *old_fb = crtc->fb;
  7247. struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
  7248. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7249. struct intel_unpin_work *work;
  7250. unsigned long flags;
  7251. int ret;
  7252. /* Can't change pixel format via MI display flips. */
  7253. if (fb->pixel_format != crtc->fb->pixel_format)
  7254. return -EINVAL;
  7255. /*
  7256. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  7257. * Note that pitch changes could also affect these register.
  7258. */
  7259. if (INTEL_INFO(dev)->gen > 3 &&
  7260. (fb->offsets[0] != crtc->fb->offsets[0] ||
  7261. fb->pitches[0] != crtc->fb->pitches[0]))
  7262. return -EINVAL;
  7263. work = kzalloc(sizeof(*work), GFP_KERNEL);
  7264. if (work == NULL)
  7265. return -ENOMEM;
  7266. work->event = event;
  7267. work->crtc = crtc;
  7268. work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
  7269. INIT_WORK(&work->work, intel_unpin_work_fn);
  7270. ret = drm_vblank_get(dev, intel_crtc->pipe);
  7271. if (ret)
  7272. goto free_work;
  7273. /* We borrow the event spin lock for protecting unpin_work */
  7274. spin_lock_irqsave(&dev->event_lock, flags);
  7275. if (intel_crtc->unpin_work) {
  7276. spin_unlock_irqrestore(&dev->event_lock, flags);
  7277. kfree(work);
  7278. drm_vblank_put(dev, intel_crtc->pipe);
  7279. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  7280. return -EBUSY;
  7281. }
  7282. intel_crtc->unpin_work = work;
  7283. spin_unlock_irqrestore(&dev->event_lock, flags);
  7284. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  7285. flush_workqueue(dev_priv->wq);
  7286. ret = i915_mutex_lock_interruptible(dev);
  7287. if (ret)
  7288. goto cleanup;
  7289. /* Reference the objects for the scheduled work. */
  7290. drm_gem_object_reference(&work->old_fb_obj->base);
  7291. drm_gem_object_reference(&obj->base);
  7292. crtc->fb = fb;
  7293. work->pending_flip_obj = obj;
  7294. work->enable_stall_check = true;
  7295. atomic_inc(&intel_crtc->unpin_work_count);
  7296. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  7297. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, page_flip_flags);
  7298. if (ret)
  7299. goto cleanup_pending;
  7300. intel_disable_fbc(dev);
  7301. intel_mark_fb_busy(obj, NULL);
  7302. mutex_unlock(&dev->struct_mutex);
  7303. trace_i915_flip_request(intel_crtc->plane, obj);
  7304. return 0;
  7305. cleanup_pending:
  7306. atomic_dec(&intel_crtc->unpin_work_count);
  7307. crtc->fb = old_fb;
  7308. drm_gem_object_unreference(&work->old_fb_obj->base);
  7309. drm_gem_object_unreference(&obj->base);
  7310. mutex_unlock(&dev->struct_mutex);
  7311. cleanup:
  7312. spin_lock_irqsave(&dev->event_lock, flags);
  7313. intel_crtc->unpin_work = NULL;
  7314. spin_unlock_irqrestore(&dev->event_lock, flags);
  7315. drm_vblank_put(dev, intel_crtc->pipe);
  7316. free_work:
  7317. kfree(work);
  7318. return ret;
  7319. }
  7320. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  7321. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  7322. .load_lut = intel_crtc_load_lut,
  7323. };
  7324. /**
  7325. * intel_modeset_update_staged_output_state
  7326. *
  7327. * Updates the staged output configuration state, e.g. after we've read out the
  7328. * current hw state.
  7329. */
  7330. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  7331. {
  7332. struct intel_crtc *crtc;
  7333. struct intel_encoder *encoder;
  7334. struct intel_connector *connector;
  7335. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7336. base.head) {
  7337. connector->new_encoder =
  7338. to_intel_encoder(connector->base.encoder);
  7339. }
  7340. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7341. base.head) {
  7342. encoder->new_crtc =
  7343. to_intel_crtc(encoder->base.crtc);
  7344. }
  7345. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  7346. base.head) {
  7347. crtc->new_enabled = crtc->base.enabled;
  7348. if (crtc->new_enabled)
  7349. crtc->new_config = &crtc->config;
  7350. else
  7351. crtc->new_config = NULL;
  7352. }
  7353. }
  7354. /**
  7355. * intel_modeset_commit_output_state
  7356. *
  7357. * This function copies the stage display pipe configuration to the real one.
  7358. */
  7359. static void intel_modeset_commit_output_state(struct drm_device *dev)
  7360. {
  7361. struct intel_crtc *crtc;
  7362. struct intel_encoder *encoder;
  7363. struct intel_connector *connector;
  7364. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7365. base.head) {
  7366. connector->base.encoder = &connector->new_encoder->base;
  7367. }
  7368. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7369. base.head) {
  7370. encoder->base.crtc = &encoder->new_crtc->base;
  7371. }
  7372. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  7373. base.head) {
  7374. crtc->base.enabled = crtc->new_enabled;
  7375. }
  7376. }
  7377. static void
  7378. connected_sink_compute_bpp(struct intel_connector * connector,
  7379. struct intel_crtc_config *pipe_config)
  7380. {
  7381. int bpp = pipe_config->pipe_bpp;
  7382. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  7383. connector->base.base.id,
  7384. drm_get_connector_name(&connector->base));
  7385. /* Don't use an invalid EDID bpc value */
  7386. if (connector->base.display_info.bpc &&
  7387. connector->base.display_info.bpc * 3 < bpp) {
  7388. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  7389. bpp, connector->base.display_info.bpc*3);
  7390. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  7391. }
  7392. /* Clamp bpp to 8 on screens without EDID 1.4 */
  7393. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  7394. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  7395. bpp);
  7396. pipe_config->pipe_bpp = 24;
  7397. }
  7398. }
  7399. static int
  7400. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  7401. struct drm_framebuffer *fb,
  7402. struct intel_crtc_config *pipe_config)
  7403. {
  7404. struct drm_device *dev = crtc->base.dev;
  7405. struct intel_connector *connector;
  7406. int bpp;
  7407. switch (fb->pixel_format) {
  7408. case DRM_FORMAT_C8:
  7409. bpp = 8*3; /* since we go through a colormap */
  7410. break;
  7411. case DRM_FORMAT_XRGB1555:
  7412. case DRM_FORMAT_ARGB1555:
  7413. /* checked in intel_framebuffer_init already */
  7414. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  7415. return -EINVAL;
  7416. case DRM_FORMAT_RGB565:
  7417. bpp = 6*3; /* min is 18bpp */
  7418. break;
  7419. case DRM_FORMAT_XBGR8888:
  7420. case DRM_FORMAT_ABGR8888:
  7421. /* checked in intel_framebuffer_init already */
  7422. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  7423. return -EINVAL;
  7424. case DRM_FORMAT_XRGB8888:
  7425. case DRM_FORMAT_ARGB8888:
  7426. bpp = 8*3;
  7427. break;
  7428. case DRM_FORMAT_XRGB2101010:
  7429. case DRM_FORMAT_ARGB2101010:
  7430. case DRM_FORMAT_XBGR2101010:
  7431. case DRM_FORMAT_ABGR2101010:
  7432. /* checked in intel_framebuffer_init already */
  7433. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  7434. return -EINVAL;
  7435. bpp = 10*3;
  7436. break;
  7437. /* TODO: gen4+ supports 16 bpc floating point, too. */
  7438. default:
  7439. DRM_DEBUG_KMS("unsupported depth\n");
  7440. return -EINVAL;
  7441. }
  7442. pipe_config->pipe_bpp = bpp;
  7443. /* Clamp display bpp to EDID value */
  7444. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7445. base.head) {
  7446. if (!connector->new_encoder ||
  7447. connector->new_encoder->new_crtc != crtc)
  7448. continue;
  7449. connected_sink_compute_bpp(connector, pipe_config);
  7450. }
  7451. return bpp;
  7452. }
  7453. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  7454. {
  7455. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  7456. "type: 0x%x flags: 0x%x\n",
  7457. mode->crtc_clock,
  7458. mode->crtc_hdisplay, mode->crtc_hsync_start,
  7459. mode->crtc_hsync_end, mode->crtc_htotal,
  7460. mode->crtc_vdisplay, mode->crtc_vsync_start,
  7461. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  7462. }
  7463. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  7464. struct intel_crtc_config *pipe_config,
  7465. const char *context)
  7466. {
  7467. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  7468. context, pipe_name(crtc->pipe));
  7469. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  7470. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  7471. pipe_config->pipe_bpp, pipe_config->dither);
  7472. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  7473. pipe_config->has_pch_encoder,
  7474. pipe_config->fdi_lanes,
  7475. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  7476. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  7477. pipe_config->fdi_m_n.tu);
  7478. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  7479. pipe_config->has_dp_encoder,
  7480. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  7481. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  7482. pipe_config->dp_m_n.tu);
  7483. DRM_DEBUG_KMS("requested mode:\n");
  7484. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  7485. DRM_DEBUG_KMS("adjusted mode:\n");
  7486. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  7487. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  7488. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  7489. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  7490. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  7491. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  7492. pipe_config->gmch_pfit.control,
  7493. pipe_config->gmch_pfit.pgm_ratios,
  7494. pipe_config->gmch_pfit.lvds_border_bits);
  7495. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  7496. pipe_config->pch_pfit.pos,
  7497. pipe_config->pch_pfit.size,
  7498. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  7499. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  7500. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  7501. }
  7502. static bool check_encoder_cloning(struct drm_crtc *crtc)
  7503. {
  7504. int num_encoders = 0;
  7505. bool uncloneable_encoders = false;
  7506. struct intel_encoder *encoder;
  7507. list_for_each_entry(encoder, &crtc->dev->mode_config.encoder_list,
  7508. base.head) {
  7509. if (&encoder->new_crtc->base != crtc)
  7510. continue;
  7511. num_encoders++;
  7512. if (!encoder->cloneable)
  7513. uncloneable_encoders = true;
  7514. }
  7515. return !(num_encoders > 1 && uncloneable_encoders);
  7516. }
  7517. static struct intel_crtc_config *
  7518. intel_modeset_pipe_config(struct drm_crtc *crtc,
  7519. struct drm_framebuffer *fb,
  7520. struct drm_display_mode *mode)
  7521. {
  7522. struct drm_device *dev = crtc->dev;
  7523. struct intel_encoder *encoder;
  7524. struct intel_crtc_config *pipe_config;
  7525. int plane_bpp, ret = -EINVAL;
  7526. bool retry = true;
  7527. if (!check_encoder_cloning(crtc)) {
  7528. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  7529. return ERR_PTR(-EINVAL);
  7530. }
  7531. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  7532. if (!pipe_config)
  7533. return ERR_PTR(-ENOMEM);
  7534. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  7535. drm_mode_copy(&pipe_config->requested_mode, mode);
  7536. pipe_config->cpu_transcoder =
  7537. (enum transcoder) to_intel_crtc(crtc)->pipe;
  7538. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  7539. /*
  7540. * Sanitize sync polarity flags based on requested ones. If neither
  7541. * positive or negative polarity is requested, treat this as meaning
  7542. * negative polarity.
  7543. */
  7544. if (!(pipe_config->adjusted_mode.flags &
  7545. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  7546. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  7547. if (!(pipe_config->adjusted_mode.flags &
  7548. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  7549. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  7550. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  7551. * plane pixel format and any sink constraints into account. Returns the
  7552. * source plane bpp so that dithering can be selected on mismatches
  7553. * after encoders and crtc also have had their say. */
  7554. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  7555. fb, pipe_config);
  7556. if (plane_bpp < 0)
  7557. goto fail;
  7558. /*
  7559. * Determine the real pipe dimensions. Note that stereo modes can
  7560. * increase the actual pipe size due to the frame doubling and
  7561. * insertion of additional space for blanks between the frame. This
  7562. * is stored in the crtc timings. We use the requested mode to do this
  7563. * computation to clearly distinguish it from the adjusted mode, which
  7564. * can be changed by the connectors in the below retry loop.
  7565. */
  7566. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  7567. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  7568. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  7569. encoder_retry:
  7570. /* Ensure the port clock defaults are reset when retrying. */
  7571. pipe_config->port_clock = 0;
  7572. pipe_config->pixel_multiplier = 1;
  7573. /* Fill in default crtc timings, allow encoders to overwrite them. */
  7574. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  7575. /* Pass our mode to the connectors and the CRTC to give them a chance to
  7576. * adjust it according to limitations or connector properties, and also
  7577. * a chance to reject the mode entirely.
  7578. */
  7579. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7580. base.head) {
  7581. if (&encoder->new_crtc->base != crtc)
  7582. continue;
  7583. if (!(encoder->compute_config(encoder, pipe_config))) {
  7584. DRM_DEBUG_KMS("Encoder config failure\n");
  7585. goto fail;
  7586. }
  7587. }
  7588. /* Set default port clock if not overwritten by the encoder. Needs to be
  7589. * done afterwards in case the encoder adjusts the mode. */
  7590. if (!pipe_config->port_clock)
  7591. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  7592. * pipe_config->pixel_multiplier;
  7593. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  7594. if (ret < 0) {
  7595. DRM_DEBUG_KMS("CRTC fixup failed\n");
  7596. goto fail;
  7597. }
  7598. if (ret == RETRY) {
  7599. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  7600. ret = -EINVAL;
  7601. goto fail;
  7602. }
  7603. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  7604. retry = false;
  7605. goto encoder_retry;
  7606. }
  7607. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  7608. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  7609. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  7610. return pipe_config;
  7611. fail:
  7612. kfree(pipe_config);
  7613. return ERR_PTR(ret);
  7614. }
  7615. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  7616. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  7617. static void
  7618. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  7619. unsigned *prepare_pipes, unsigned *disable_pipes)
  7620. {
  7621. struct intel_crtc *intel_crtc;
  7622. struct drm_device *dev = crtc->dev;
  7623. struct intel_encoder *encoder;
  7624. struct intel_connector *connector;
  7625. struct drm_crtc *tmp_crtc;
  7626. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  7627. /* Check which crtcs have changed outputs connected to them, these need
  7628. * to be part of the prepare_pipes mask. We don't (yet) support global
  7629. * modeset across multiple crtcs, so modeset_pipes will only have one
  7630. * bit set at most. */
  7631. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7632. base.head) {
  7633. if (connector->base.encoder == &connector->new_encoder->base)
  7634. continue;
  7635. if (connector->base.encoder) {
  7636. tmp_crtc = connector->base.encoder->crtc;
  7637. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  7638. }
  7639. if (connector->new_encoder)
  7640. *prepare_pipes |=
  7641. 1 << connector->new_encoder->new_crtc->pipe;
  7642. }
  7643. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7644. base.head) {
  7645. if (encoder->base.crtc == &encoder->new_crtc->base)
  7646. continue;
  7647. if (encoder->base.crtc) {
  7648. tmp_crtc = encoder->base.crtc;
  7649. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  7650. }
  7651. if (encoder->new_crtc)
  7652. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  7653. }
  7654. /* Check for pipes that will be enabled/disabled ... */
  7655. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  7656. base.head) {
  7657. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  7658. continue;
  7659. if (!intel_crtc->new_enabled)
  7660. *disable_pipes |= 1 << intel_crtc->pipe;
  7661. else
  7662. *prepare_pipes |= 1 << intel_crtc->pipe;
  7663. }
  7664. /* set_mode is also used to update properties on life display pipes. */
  7665. intel_crtc = to_intel_crtc(crtc);
  7666. if (intel_crtc->new_enabled)
  7667. *prepare_pipes |= 1 << intel_crtc->pipe;
  7668. /*
  7669. * For simplicity do a full modeset on any pipe where the output routing
  7670. * changed. We could be more clever, but that would require us to be
  7671. * more careful with calling the relevant encoder->mode_set functions.
  7672. */
  7673. if (*prepare_pipes)
  7674. *modeset_pipes = *prepare_pipes;
  7675. /* ... and mask these out. */
  7676. *modeset_pipes &= ~(*disable_pipes);
  7677. *prepare_pipes &= ~(*disable_pipes);
  7678. /*
  7679. * HACK: We don't (yet) fully support global modesets. intel_set_config
  7680. * obies this rule, but the modeset restore mode of
  7681. * intel_modeset_setup_hw_state does not.
  7682. */
  7683. *modeset_pipes &= 1 << intel_crtc->pipe;
  7684. *prepare_pipes &= 1 << intel_crtc->pipe;
  7685. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  7686. *modeset_pipes, *prepare_pipes, *disable_pipes);
  7687. }
  7688. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  7689. {
  7690. struct drm_encoder *encoder;
  7691. struct drm_device *dev = crtc->dev;
  7692. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  7693. if (encoder->crtc == crtc)
  7694. return true;
  7695. return false;
  7696. }
  7697. static void
  7698. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  7699. {
  7700. struct intel_encoder *intel_encoder;
  7701. struct intel_crtc *intel_crtc;
  7702. struct drm_connector *connector;
  7703. list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
  7704. base.head) {
  7705. if (!intel_encoder->base.crtc)
  7706. continue;
  7707. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  7708. if (prepare_pipes & (1 << intel_crtc->pipe))
  7709. intel_encoder->connectors_active = false;
  7710. }
  7711. intel_modeset_commit_output_state(dev);
  7712. /* Double check state. */
  7713. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  7714. base.head) {
  7715. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  7716. WARN_ON(intel_crtc->new_config &&
  7717. intel_crtc->new_config != &intel_crtc->config);
  7718. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  7719. }
  7720. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  7721. if (!connector->encoder || !connector->encoder->crtc)
  7722. continue;
  7723. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  7724. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  7725. struct drm_property *dpms_property =
  7726. dev->mode_config.dpms_property;
  7727. connector->dpms = DRM_MODE_DPMS_ON;
  7728. drm_object_property_set_value(&connector->base,
  7729. dpms_property,
  7730. DRM_MODE_DPMS_ON);
  7731. intel_encoder = to_intel_encoder(connector->encoder);
  7732. intel_encoder->connectors_active = true;
  7733. }
  7734. }
  7735. }
  7736. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  7737. {
  7738. int diff;
  7739. if (clock1 == clock2)
  7740. return true;
  7741. if (!clock1 || !clock2)
  7742. return false;
  7743. diff = abs(clock1 - clock2);
  7744. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  7745. return true;
  7746. return false;
  7747. }
  7748. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  7749. list_for_each_entry((intel_crtc), \
  7750. &(dev)->mode_config.crtc_list, \
  7751. base.head) \
  7752. if (mask & (1 <<(intel_crtc)->pipe))
  7753. static bool
  7754. intel_pipe_config_compare(struct drm_device *dev,
  7755. struct intel_crtc_config *current_config,
  7756. struct intel_crtc_config *pipe_config)
  7757. {
  7758. #define PIPE_CONF_CHECK_X(name) \
  7759. if (current_config->name != pipe_config->name) { \
  7760. DRM_ERROR("mismatch in " #name " " \
  7761. "(expected 0x%08x, found 0x%08x)\n", \
  7762. current_config->name, \
  7763. pipe_config->name); \
  7764. return false; \
  7765. }
  7766. #define PIPE_CONF_CHECK_I(name) \
  7767. if (current_config->name != pipe_config->name) { \
  7768. DRM_ERROR("mismatch in " #name " " \
  7769. "(expected %i, found %i)\n", \
  7770. current_config->name, \
  7771. pipe_config->name); \
  7772. return false; \
  7773. }
  7774. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  7775. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  7776. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  7777. "(expected %i, found %i)\n", \
  7778. current_config->name & (mask), \
  7779. pipe_config->name & (mask)); \
  7780. return false; \
  7781. }
  7782. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  7783. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  7784. DRM_ERROR("mismatch in " #name " " \
  7785. "(expected %i, found %i)\n", \
  7786. current_config->name, \
  7787. pipe_config->name); \
  7788. return false; \
  7789. }
  7790. #define PIPE_CONF_QUIRK(quirk) \
  7791. ((current_config->quirks | pipe_config->quirks) & (quirk))
  7792. PIPE_CONF_CHECK_I(cpu_transcoder);
  7793. PIPE_CONF_CHECK_I(has_pch_encoder);
  7794. PIPE_CONF_CHECK_I(fdi_lanes);
  7795. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  7796. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  7797. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  7798. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  7799. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  7800. PIPE_CONF_CHECK_I(has_dp_encoder);
  7801. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  7802. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  7803. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  7804. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  7805. PIPE_CONF_CHECK_I(dp_m_n.tu);
  7806. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  7807. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  7808. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  7809. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  7810. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  7811. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  7812. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  7813. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  7814. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  7815. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  7816. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  7817. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  7818. PIPE_CONF_CHECK_I(pixel_multiplier);
  7819. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  7820. DRM_MODE_FLAG_INTERLACE);
  7821. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  7822. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  7823. DRM_MODE_FLAG_PHSYNC);
  7824. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  7825. DRM_MODE_FLAG_NHSYNC);
  7826. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  7827. DRM_MODE_FLAG_PVSYNC);
  7828. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  7829. DRM_MODE_FLAG_NVSYNC);
  7830. }
  7831. PIPE_CONF_CHECK_I(pipe_src_w);
  7832. PIPE_CONF_CHECK_I(pipe_src_h);
  7833. PIPE_CONF_CHECK_I(gmch_pfit.control);
  7834. /* pfit ratios are autocomputed by the hw on gen4+ */
  7835. if (INTEL_INFO(dev)->gen < 4)
  7836. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  7837. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  7838. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  7839. if (current_config->pch_pfit.enabled) {
  7840. PIPE_CONF_CHECK_I(pch_pfit.pos);
  7841. PIPE_CONF_CHECK_I(pch_pfit.size);
  7842. }
  7843. /* BDW+ don't expose a synchronous way to read the state */
  7844. if (IS_HASWELL(dev))
  7845. PIPE_CONF_CHECK_I(ips_enabled);
  7846. PIPE_CONF_CHECK_I(double_wide);
  7847. PIPE_CONF_CHECK_I(shared_dpll);
  7848. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  7849. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  7850. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  7851. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  7852. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  7853. PIPE_CONF_CHECK_I(pipe_bpp);
  7854. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  7855. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  7856. #undef PIPE_CONF_CHECK_X
  7857. #undef PIPE_CONF_CHECK_I
  7858. #undef PIPE_CONF_CHECK_FLAGS
  7859. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  7860. #undef PIPE_CONF_QUIRK
  7861. return true;
  7862. }
  7863. static void
  7864. check_connector_state(struct drm_device *dev)
  7865. {
  7866. struct intel_connector *connector;
  7867. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7868. base.head) {
  7869. /* This also checks the encoder/connector hw state with the
  7870. * ->get_hw_state callbacks. */
  7871. intel_connector_check_state(connector);
  7872. WARN(&connector->new_encoder->base != connector->base.encoder,
  7873. "connector's staged encoder doesn't match current encoder\n");
  7874. }
  7875. }
  7876. static void
  7877. check_encoder_state(struct drm_device *dev)
  7878. {
  7879. struct intel_encoder *encoder;
  7880. struct intel_connector *connector;
  7881. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7882. base.head) {
  7883. bool enabled = false;
  7884. bool active = false;
  7885. enum pipe pipe, tracked_pipe;
  7886. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  7887. encoder->base.base.id,
  7888. drm_get_encoder_name(&encoder->base));
  7889. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  7890. "encoder's stage crtc doesn't match current crtc\n");
  7891. WARN(encoder->connectors_active && !encoder->base.crtc,
  7892. "encoder's active_connectors set, but no crtc\n");
  7893. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7894. base.head) {
  7895. if (connector->base.encoder != &encoder->base)
  7896. continue;
  7897. enabled = true;
  7898. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  7899. active = true;
  7900. }
  7901. WARN(!!encoder->base.crtc != enabled,
  7902. "encoder's enabled state mismatch "
  7903. "(expected %i, found %i)\n",
  7904. !!encoder->base.crtc, enabled);
  7905. WARN(active && !encoder->base.crtc,
  7906. "active encoder with no crtc\n");
  7907. WARN(encoder->connectors_active != active,
  7908. "encoder's computed active state doesn't match tracked active state "
  7909. "(expected %i, found %i)\n", active, encoder->connectors_active);
  7910. active = encoder->get_hw_state(encoder, &pipe);
  7911. WARN(active != encoder->connectors_active,
  7912. "encoder's hw state doesn't match sw tracking "
  7913. "(expected %i, found %i)\n",
  7914. encoder->connectors_active, active);
  7915. if (!encoder->base.crtc)
  7916. continue;
  7917. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  7918. WARN(active && pipe != tracked_pipe,
  7919. "active encoder's pipe doesn't match"
  7920. "(expected %i, found %i)\n",
  7921. tracked_pipe, pipe);
  7922. }
  7923. }
  7924. static void
  7925. check_crtc_state(struct drm_device *dev)
  7926. {
  7927. drm_i915_private_t *dev_priv = dev->dev_private;
  7928. struct intel_crtc *crtc;
  7929. struct intel_encoder *encoder;
  7930. struct intel_crtc_config pipe_config;
  7931. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  7932. base.head) {
  7933. bool enabled = false;
  7934. bool active = false;
  7935. memset(&pipe_config, 0, sizeof(pipe_config));
  7936. DRM_DEBUG_KMS("[CRTC:%d]\n",
  7937. crtc->base.base.id);
  7938. WARN(crtc->active && !crtc->base.enabled,
  7939. "active crtc, but not enabled in sw tracking\n");
  7940. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7941. base.head) {
  7942. if (encoder->base.crtc != &crtc->base)
  7943. continue;
  7944. enabled = true;
  7945. if (encoder->connectors_active)
  7946. active = true;
  7947. }
  7948. WARN(active != crtc->active,
  7949. "crtc's computed active state doesn't match tracked active state "
  7950. "(expected %i, found %i)\n", active, crtc->active);
  7951. WARN(enabled != crtc->base.enabled,
  7952. "crtc's computed enabled state doesn't match tracked enabled state "
  7953. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  7954. active = dev_priv->display.get_pipe_config(crtc,
  7955. &pipe_config);
  7956. /* hw state is inconsistent with the pipe A quirk */
  7957. if (crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  7958. active = crtc->active;
  7959. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7960. base.head) {
  7961. enum pipe pipe;
  7962. if (encoder->base.crtc != &crtc->base)
  7963. continue;
  7964. if (encoder->get_hw_state(encoder, &pipe))
  7965. encoder->get_config(encoder, &pipe_config);
  7966. }
  7967. WARN(crtc->active != active,
  7968. "crtc active state doesn't match with hw state "
  7969. "(expected %i, found %i)\n", crtc->active, active);
  7970. if (active &&
  7971. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  7972. WARN(1, "pipe state doesn't match!\n");
  7973. intel_dump_pipe_config(crtc, &pipe_config,
  7974. "[hw state]");
  7975. intel_dump_pipe_config(crtc, &crtc->config,
  7976. "[sw state]");
  7977. }
  7978. }
  7979. }
  7980. static void
  7981. check_shared_dpll_state(struct drm_device *dev)
  7982. {
  7983. drm_i915_private_t *dev_priv = dev->dev_private;
  7984. struct intel_crtc *crtc;
  7985. struct intel_dpll_hw_state dpll_hw_state;
  7986. int i;
  7987. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  7988. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  7989. int enabled_crtcs = 0, active_crtcs = 0;
  7990. bool active;
  7991. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  7992. DRM_DEBUG_KMS("%s\n", pll->name);
  7993. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  7994. WARN(pll->active > pll->refcount,
  7995. "more active pll users than references: %i vs %i\n",
  7996. pll->active, pll->refcount);
  7997. WARN(pll->active && !pll->on,
  7998. "pll in active use but not on in sw tracking\n");
  7999. WARN(pll->on && !pll->active,
  8000. "pll in on but not on in use in sw tracking\n");
  8001. WARN(pll->on != active,
  8002. "pll on state mismatch (expected %i, found %i)\n",
  8003. pll->on, active);
  8004. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  8005. base.head) {
  8006. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  8007. enabled_crtcs++;
  8008. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  8009. active_crtcs++;
  8010. }
  8011. WARN(pll->active != active_crtcs,
  8012. "pll active crtcs mismatch (expected %i, found %i)\n",
  8013. pll->active, active_crtcs);
  8014. WARN(pll->refcount != enabled_crtcs,
  8015. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  8016. pll->refcount, enabled_crtcs);
  8017. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  8018. sizeof(dpll_hw_state)),
  8019. "pll hw state mismatch\n");
  8020. }
  8021. }
  8022. void
  8023. intel_modeset_check_state(struct drm_device *dev)
  8024. {
  8025. check_connector_state(dev);
  8026. check_encoder_state(dev);
  8027. check_crtc_state(dev);
  8028. check_shared_dpll_state(dev);
  8029. }
  8030. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  8031. int dotclock)
  8032. {
  8033. /*
  8034. * FDI already provided one idea for the dotclock.
  8035. * Yell if the encoder disagrees.
  8036. */
  8037. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  8038. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  8039. pipe_config->adjusted_mode.crtc_clock, dotclock);
  8040. }
  8041. static int __intel_set_mode(struct drm_crtc *crtc,
  8042. struct drm_display_mode *mode,
  8043. int x, int y, struct drm_framebuffer *fb)
  8044. {
  8045. struct drm_device *dev = crtc->dev;
  8046. drm_i915_private_t *dev_priv = dev->dev_private;
  8047. struct drm_display_mode *saved_mode;
  8048. struct intel_crtc_config *pipe_config = NULL;
  8049. struct intel_crtc *intel_crtc;
  8050. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  8051. int ret = 0;
  8052. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  8053. if (!saved_mode)
  8054. return -ENOMEM;
  8055. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  8056. &prepare_pipes, &disable_pipes);
  8057. *saved_mode = crtc->mode;
  8058. /* Hack: Because we don't (yet) support global modeset on multiple
  8059. * crtcs, we don't keep track of the new mode for more than one crtc.
  8060. * Hence simply check whether any bit is set in modeset_pipes in all the
  8061. * pieces of code that are not yet converted to deal with mutliple crtcs
  8062. * changing their mode at the same time. */
  8063. if (modeset_pipes) {
  8064. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  8065. if (IS_ERR(pipe_config)) {
  8066. ret = PTR_ERR(pipe_config);
  8067. pipe_config = NULL;
  8068. goto out;
  8069. }
  8070. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  8071. "[modeset]");
  8072. to_intel_crtc(crtc)->new_config = pipe_config;
  8073. }
  8074. /*
  8075. * See if the config requires any additional preparation, e.g.
  8076. * to adjust global state with pipes off. We need to do this
  8077. * here so we can get the modeset_pipe updated config for the new
  8078. * mode set on this crtc. For other crtcs we need to use the
  8079. * adjusted_mode bits in the crtc directly.
  8080. */
  8081. if (IS_VALLEYVIEW(dev)) {
  8082. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  8083. /* may have added more to prepare_pipes than we should */
  8084. prepare_pipes &= ~disable_pipes;
  8085. }
  8086. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  8087. intel_crtc_disable(&intel_crtc->base);
  8088. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  8089. if (intel_crtc->base.enabled)
  8090. dev_priv->display.crtc_disable(&intel_crtc->base);
  8091. }
  8092. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  8093. * to set it here already despite that we pass it down the callchain.
  8094. */
  8095. if (modeset_pipes) {
  8096. crtc->mode = *mode;
  8097. /* mode_set/enable/disable functions rely on a correct pipe
  8098. * config. */
  8099. to_intel_crtc(crtc)->config = *pipe_config;
  8100. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  8101. /*
  8102. * Calculate and store various constants which
  8103. * are later needed by vblank and swap-completion
  8104. * timestamping. They are derived from true hwmode.
  8105. */
  8106. drm_calc_timestamping_constants(crtc,
  8107. &pipe_config->adjusted_mode);
  8108. }
  8109. /* Only after disabling all output pipelines that will be changed can we
  8110. * update the the output configuration. */
  8111. intel_modeset_update_state(dev, prepare_pipes);
  8112. if (dev_priv->display.modeset_global_resources)
  8113. dev_priv->display.modeset_global_resources(dev);
  8114. /* Set up the DPLL and any encoders state that needs to adjust or depend
  8115. * on the DPLL.
  8116. */
  8117. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  8118. ret = intel_crtc_mode_set(&intel_crtc->base,
  8119. x, y, fb);
  8120. if (ret)
  8121. goto done;
  8122. }
  8123. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  8124. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
  8125. dev_priv->display.crtc_enable(&intel_crtc->base);
  8126. /* FIXME: add subpixel order */
  8127. done:
  8128. if (ret && crtc->enabled)
  8129. crtc->mode = *saved_mode;
  8130. out:
  8131. kfree(pipe_config);
  8132. kfree(saved_mode);
  8133. return ret;
  8134. }
  8135. static int intel_set_mode(struct drm_crtc *crtc,
  8136. struct drm_display_mode *mode,
  8137. int x, int y, struct drm_framebuffer *fb)
  8138. {
  8139. int ret;
  8140. ret = __intel_set_mode(crtc, mode, x, y, fb);
  8141. if (ret == 0)
  8142. intel_modeset_check_state(crtc->dev);
  8143. return ret;
  8144. }
  8145. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  8146. {
  8147. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);
  8148. }
  8149. #undef for_each_intel_crtc_masked
  8150. static void intel_set_config_free(struct intel_set_config *config)
  8151. {
  8152. if (!config)
  8153. return;
  8154. kfree(config->save_connector_encoders);
  8155. kfree(config->save_encoder_crtcs);
  8156. kfree(config->save_crtc_enabled);
  8157. kfree(config);
  8158. }
  8159. static int intel_set_config_save_state(struct drm_device *dev,
  8160. struct intel_set_config *config)
  8161. {
  8162. struct drm_crtc *crtc;
  8163. struct drm_encoder *encoder;
  8164. struct drm_connector *connector;
  8165. int count;
  8166. config->save_crtc_enabled =
  8167. kcalloc(dev->mode_config.num_crtc,
  8168. sizeof(bool), GFP_KERNEL);
  8169. if (!config->save_crtc_enabled)
  8170. return -ENOMEM;
  8171. config->save_encoder_crtcs =
  8172. kcalloc(dev->mode_config.num_encoder,
  8173. sizeof(struct drm_crtc *), GFP_KERNEL);
  8174. if (!config->save_encoder_crtcs)
  8175. return -ENOMEM;
  8176. config->save_connector_encoders =
  8177. kcalloc(dev->mode_config.num_connector,
  8178. sizeof(struct drm_encoder *), GFP_KERNEL);
  8179. if (!config->save_connector_encoders)
  8180. return -ENOMEM;
  8181. /* Copy data. Note that driver private data is not affected.
  8182. * Should anything bad happen only the expected state is
  8183. * restored, not the drivers personal bookkeeping.
  8184. */
  8185. count = 0;
  8186. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  8187. config->save_crtc_enabled[count++] = crtc->enabled;
  8188. }
  8189. count = 0;
  8190. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  8191. config->save_encoder_crtcs[count++] = encoder->crtc;
  8192. }
  8193. count = 0;
  8194. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8195. config->save_connector_encoders[count++] = connector->encoder;
  8196. }
  8197. return 0;
  8198. }
  8199. static void intel_set_config_restore_state(struct drm_device *dev,
  8200. struct intel_set_config *config)
  8201. {
  8202. struct intel_crtc *crtc;
  8203. struct intel_encoder *encoder;
  8204. struct intel_connector *connector;
  8205. int count;
  8206. count = 0;
  8207. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
  8208. crtc->new_enabled = config->save_crtc_enabled[count++];
  8209. if (crtc->new_enabled)
  8210. crtc->new_config = &crtc->config;
  8211. else
  8212. crtc->new_config = NULL;
  8213. }
  8214. count = 0;
  8215. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  8216. encoder->new_crtc =
  8217. to_intel_crtc(config->save_encoder_crtcs[count++]);
  8218. }
  8219. count = 0;
  8220. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  8221. connector->new_encoder =
  8222. to_intel_encoder(config->save_connector_encoders[count++]);
  8223. }
  8224. }
  8225. static bool
  8226. is_crtc_connector_off(struct drm_mode_set *set)
  8227. {
  8228. int i;
  8229. if (set->num_connectors == 0)
  8230. return false;
  8231. if (WARN_ON(set->connectors == NULL))
  8232. return false;
  8233. for (i = 0; i < set->num_connectors; i++)
  8234. if (set->connectors[i]->encoder &&
  8235. set->connectors[i]->encoder->crtc == set->crtc &&
  8236. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  8237. return true;
  8238. return false;
  8239. }
  8240. static void
  8241. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  8242. struct intel_set_config *config)
  8243. {
  8244. /* We should be able to check here if the fb has the same properties
  8245. * and then just flip_or_move it */
  8246. if (is_crtc_connector_off(set)) {
  8247. config->mode_changed = true;
  8248. } else if (set->crtc->fb != set->fb) {
  8249. /* If we have no fb then treat it as a full mode set */
  8250. if (set->crtc->fb == NULL) {
  8251. struct intel_crtc *intel_crtc =
  8252. to_intel_crtc(set->crtc);
  8253. if (intel_crtc->active && i915.fastboot) {
  8254. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  8255. config->fb_changed = true;
  8256. } else {
  8257. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  8258. config->mode_changed = true;
  8259. }
  8260. } else if (set->fb == NULL) {
  8261. config->mode_changed = true;
  8262. } else if (set->fb->pixel_format !=
  8263. set->crtc->fb->pixel_format) {
  8264. config->mode_changed = true;
  8265. } else {
  8266. config->fb_changed = true;
  8267. }
  8268. }
  8269. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  8270. config->fb_changed = true;
  8271. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  8272. DRM_DEBUG_KMS("modes are different, full mode set\n");
  8273. drm_mode_debug_printmodeline(&set->crtc->mode);
  8274. drm_mode_debug_printmodeline(set->mode);
  8275. config->mode_changed = true;
  8276. }
  8277. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  8278. set->crtc->base.id, config->mode_changed, config->fb_changed);
  8279. }
  8280. static int
  8281. intel_modeset_stage_output_state(struct drm_device *dev,
  8282. struct drm_mode_set *set,
  8283. struct intel_set_config *config)
  8284. {
  8285. struct intel_connector *connector;
  8286. struct intel_encoder *encoder;
  8287. struct intel_crtc *crtc;
  8288. int ro;
  8289. /* The upper layers ensure that we either disable a crtc or have a list
  8290. * of connectors. For paranoia, double-check this. */
  8291. WARN_ON(!set->fb && (set->num_connectors != 0));
  8292. WARN_ON(set->fb && (set->num_connectors == 0));
  8293. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8294. base.head) {
  8295. /* Otherwise traverse passed in connector list and get encoders
  8296. * for them. */
  8297. for (ro = 0; ro < set->num_connectors; ro++) {
  8298. if (set->connectors[ro] == &connector->base) {
  8299. connector->new_encoder = connector->encoder;
  8300. break;
  8301. }
  8302. }
  8303. /* If we disable the crtc, disable all its connectors. Also, if
  8304. * the connector is on the changing crtc but not on the new
  8305. * connector list, disable it. */
  8306. if ((!set->fb || ro == set->num_connectors) &&
  8307. connector->base.encoder &&
  8308. connector->base.encoder->crtc == set->crtc) {
  8309. connector->new_encoder = NULL;
  8310. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  8311. connector->base.base.id,
  8312. drm_get_connector_name(&connector->base));
  8313. }
  8314. if (&connector->new_encoder->base != connector->base.encoder) {
  8315. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  8316. config->mode_changed = true;
  8317. }
  8318. }
  8319. /* connector->new_encoder is now updated for all connectors. */
  8320. /* Update crtc of enabled connectors. */
  8321. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8322. base.head) {
  8323. struct drm_crtc *new_crtc;
  8324. if (!connector->new_encoder)
  8325. continue;
  8326. new_crtc = connector->new_encoder->base.crtc;
  8327. for (ro = 0; ro < set->num_connectors; ro++) {
  8328. if (set->connectors[ro] == &connector->base)
  8329. new_crtc = set->crtc;
  8330. }
  8331. /* Make sure the new CRTC will work with the encoder */
  8332. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  8333. new_crtc)) {
  8334. return -EINVAL;
  8335. }
  8336. connector->encoder->new_crtc = to_intel_crtc(new_crtc);
  8337. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  8338. connector->base.base.id,
  8339. drm_get_connector_name(&connector->base),
  8340. new_crtc->base.id);
  8341. }
  8342. /* Check for any encoders that needs to be disabled. */
  8343. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8344. base.head) {
  8345. int num_connectors = 0;
  8346. list_for_each_entry(connector,
  8347. &dev->mode_config.connector_list,
  8348. base.head) {
  8349. if (connector->new_encoder == encoder) {
  8350. WARN_ON(!connector->new_encoder->new_crtc);
  8351. num_connectors++;
  8352. }
  8353. }
  8354. if (num_connectors == 0)
  8355. encoder->new_crtc = NULL;
  8356. else if (num_connectors > 1)
  8357. return -EINVAL;
  8358. /* Only now check for crtc changes so we don't miss encoders
  8359. * that will be disabled. */
  8360. if (&encoder->new_crtc->base != encoder->base.crtc) {
  8361. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  8362. config->mode_changed = true;
  8363. }
  8364. }
  8365. /* Now we've also updated encoder->new_crtc for all encoders. */
  8366. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  8367. base.head) {
  8368. crtc->new_enabled = false;
  8369. list_for_each_entry(encoder,
  8370. &dev->mode_config.encoder_list,
  8371. base.head) {
  8372. if (encoder->new_crtc == crtc) {
  8373. crtc->new_enabled = true;
  8374. break;
  8375. }
  8376. }
  8377. if (crtc->new_enabled != crtc->base.enabled) {
  8378. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  8379. crtc->new_enabled ? "en" : "dis");
  8380. config->mode_changed = true;
  8381. }
  8382. if (crtc->new_enabled)
  8383. crtc->new_config = &crtc->config;
  8384. else
  8385. crtc->new_config = NULL;
  8386. }
  8387. return 0;
  8388. }
  8389. static void disable_crtc_nofb(struct intel_crtc *crtc)
  8390. {
  8391. struct drm_device *dev = crtc->base.dev;
  8392. struct intel_encoder *encoder;
  8393. struct intel_connector *connector;
  8394. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  8395. pipe_name(crtc->pipe));
  8396. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  8397. if (connector->new_encoder &&
  8398. connector->new_encoder->new_crtc == crtc)
  8399. connector->new_encoder = NULL;
  8400. }
  8401. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  8402. if (encoder->new_crtc == crtc)
  8403. encoder->new_crtc = NULL;
  8404. }
  8405. crtc->new_enabled = false;
  8406. crtc->new_config = NULL;
  8407. }
  8408. static int intel_crtc_set_config(struct drm_mode_set *set)
  8409. {
  8410. struct drm_device *dev;
  8411. struct drm_mode_set save_set;
  8412. struct intel_set_config *config;
  8413. int ret;
  8414. BUG_ON(!set);
  8415. BUG_ON(!set->crtc);
  8416. BUG_ON(!set->crtc->helper_private);
  8417. /* Enforce sane interface api - has been abused by the fb helper. */
  8418. BUG_ON(!set->mode && set->fb);
  8419. BUG_ON(set->fb && set->num_connectors == 0);
  8420. if (set->fb) {
  8421. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  8422. set->crtc->base.id, set->fb->base.id,
  8423. (int)set->num_connectors, set->x, set->y);
  8424. } else {
  8425. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  8426. }
  8427. dev = set->crtc->dev;
  8428. ret = -ENOMEM;
  8429. config = kzalloc(sizeof(*config), GFP_KERNEL);
  8430. if (!config)
  8431. goto out_config;
  8432. ret = intel_set_config_save_state(dev, config);
  8433. if (ret)
  8434. goto out_config;
  8435. save_set.crtc = set->crtc;
  8436. save_set.mode = &set->crtc->mode;
  8437. save_set.x = set->crtc->x;
  8438. save_set.y = set->crtc->y;
  8439. save_set.fb = set->crtc->fb;
  8440. /* Compute whether we need a full modeset, only an fb base update or no
  8441. * change at all. In the future we might also check whether only the
  8442. * mode changed, e.g. for LVDS where we only change the panel fitter in
  8443. * such cases. */
  8444. intel_set_config_compute_mode_changes(set, config);
  8445. ret = intel_modeset_stage_output_state(dev, set, config);
  8446. if (ret)
  8447. goto fail;
  8448. if (config->mode_changed) {
  8449. ret = intel_set_mode(set->crtc, set->mode,
  8450. set->x, set->y, set->fb);
  8451. } else if (config->fb_changed) {
  8452. intel_crtc_wait_for_pending_flips(set->crtc);
  8453. ret = intel_pipe_set_base(set->crtc,
  8454. set->x, set->y, set->fb);
  8455. /*
  8456. * In the fastboot case this may be our only check of the
  8457. * state after boot. It would be better to only do it on
  8458. * the first update, but we don't have a nice way of doing that
  8459. * (and really, set_config isn't used much for high freq page
  8460. * flipping, so increasing its cost here shouldn't be a big
  8461. * deal).
  8462. */
  8463. if (i915.fastboot && ret == 0)
  8464. intel_modeset_check_state(set->crtc->dev);
  8465. }
  8466. if (ret) {
  8467. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  8468. set->crtc->base.id, ret);
  8469. fail:
  8470. intel_set_config_restore_state(dev, config);
  8471. /*
  8472. * HACK: if the pipe was on, but we didn't have a framebuffer,
  8473. * force the pipe off to avoid oopsing in the modeset code
  8474. * due to fb==NULL. This should only happen during boot since
  8475. * we don't yet reconstruct the FB from the hardware state.
  8476. */
  8477. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  8478. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  8479. /* Try to restore the config */
  8480. if (config->mode_changed &&
  8481. intel_set_mode(save_set.crtc, save_set.mode,
  8482. save_set.x, save_set.y, save_set.fb))
  8483. DRM_ERROR("failed to restore config after modeset failure\n");
  8484. }
  8485. out_config:
  8486. intel_set_config_free(config);
  8487. return ret;
  8488. }
  8489. static const struct drm_crtc_funcs intel_crtc_funcs = {
  8490. .cursor_set = intel_crtc_cursor_set,
  8491. .cursor_move = intel_crtc_cursor_move,
  8492. .gamma_set = intel_crtc_gamma_set,
  8493. .set_config = intel_crtc_set_config,
  8494. .destroy = intel_crtc_destroy,
  8495. .page_flip = intel_crtc_page_flip,
  8496. };
  8497. static void intel_cpu_pll_init(struct drm_device *dev)
  8498. {
  8499. if (HAS_DDI(dev))
  8500. intel_ddi_pll_init(dev);
  8501. }
  8502. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  8503. struct intel_shared_dpll *pll,
  8504. struct intel_dpll_hw_state *hw_state)
  8505. {
  8506. uint32_t val;
  8507. val = I915_READ(PCH_DPLL(pll->id));
  8508. hw_state->dpll = val;
  8509. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  8510. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  8511. return val & DPLL_VCO_ENABLE;
  8512. }
  8513. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  8514. struct intel_shared_dpll *pll)
  8515. {
  8516. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  8517. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  8518. }
  8519. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  8520. struct intel_shared_dpll *pll)
  8521. {
  8522. /* PCH refclock must be enabled first */
  8523. ibx_assert_pch_refclk_enabled(dev_priv);
  8524. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  8525. /* Wait for the clocks to stabilize. */
  8526. POSTING_READ(PCH_DPLL(pll->id));
  8527. udelay(150);
  8528. /* The pixel multiplier can only be updated once the
  8529. * DPLL is enabled and the clocks are stable.
  8530. *
  8531. * So write it again.
  8532. */
  8533. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  8534. POSTING_READ(PCH_DPLL(pll->id));
  8535. udelay(200);
  8536. }
  8537. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  8538. struct intel_shared_dpll *pll)
  8539. {
  8540. struct drm_device *dev = dev_priv->dev;
  8541. struct intel_crtc *crtc;
  8542. /* Make sure no transcoder isn't still depending on us. */
  8543. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
  8544. if (intel_crtc_to_shared_dpll(crtc) == pll)
  8545. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  8546. }
  8547. I915_WRITE(PCH_DPLL(pll->id), 0);
  8548. POSTING_READ(PCH_DPLL(pll->id));
  8549. udelay(200);
  8550. }
  8551. static char *ibx_pch_dpll_names[] = {
  8552. "PCH DPLL A",
  8553. "PCH DPLL B",
  8554. };
  8555. static void ibx_pch_dpll_init(struct drm_device *dev)
  8556. {
  8557. struct drm_i915_private *dev_priv = dev->dev_private;
  8558. int i;
  8559. dev_priv->num_shared_dpll = 2;
  8560. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  8561. dev_priv->shared_dplls[i].id = i;
  8562. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  8563. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  8564. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  8565. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  8566. dev_priv->shared_dplls[i].get_hw_state =
  8567. ibx_pch_dpll_get_hw_state;
  8568. }
  8569. }
  8570. static void intel_shared_dpll_init(struct drm_device *dev)
  8571. {
  8572. struct drm_i915_private *dev_priv = dev->dev_private;
  8573. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  8574. ibx_pch_dpll_init(dev);
  8575. else
  8576. dev_priv->num_shared_dpll = 0;
  8577. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  8578. }
  8579. static void intel_crtc_init(struct drm_device *dev, int pipe)
  8580. {
  8581. drm_i915_private_t *dev_priv = dev->dev_private;
  8582. struct intel_crtc *intel_crtc;
  8583. int i;
  8584. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  8585. if (intel_crtc == NULL)
  8586. return;
  8587. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  8588. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  8589. for (i = 0; i < 256; i++) {
  8590. intel_crtc->lut_r[i] = i;
  8591. intel_crtc->lut_g[i] = i;
  8592. intel_crtc->lut_b[i] = i;
  8593. }
  8594. /*
  8595. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  8596. * is hooked to plane B. Hence we want plane A feeding pipe B.
  8597. */
  8598. intel_crtc->pipe = pipe;
  8599. intel_crtc->plane = pipe;
  8600. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  8601. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  8602. intel_crtc->plane = !pipe;
  8603. }
  8604. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  8605. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  8606. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  8607. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  8608. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  8609. }
  8610. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  8611. {
  8612. struct drm_encoder *encoder = connector->base.encoder;
  8613. WARN_ON(!mutex_is_locked(&connector->base.dev->mode_config.mutex));
  8614. if (!encoder)
  8615. return INVALID_PIPE;
  8616. return to_intel_crtc(encoder->crtc)->pipe;
  8617. }
  8618. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  8619. struct drm_file *file)
  8620. {
  8621. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  8622. struct drm_mode_object *drmmode_obj;
  8623. struct intel_crtc *crtc;
  8624. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  8625. return -ENODEV;
  8626. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  8627. DRM_MODE_OBJECT_CRTC);
  8628. if (!drmmode_obj) {
  8629. DRM_ERROR("no such CRTC id\n");
  8630. return -ENOENT;
  8631. }
  8632. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  8633. pipe_from_crtc_id->pipe = crtc->pipe;
  8634. return 0;
  8635. }
  8636. static int intel_encoder_clones(struct intel_encoder *encoder)
  8637. {
  8638. struct drm_device *dev = encoder->base.dev;
  8639. struct intel_encoder *source_encoder;
  8640. int index_mask = 0;
  8641. int entry = 0;
  8642. list_for_each_entry(source_encoder,
  8643. &dev->mode_config.encoder_list, base.head) {
  8644. if (encoder == source_encoder)
  8645. index_mask |= (1 << entry);
  8646. /* Intel hw has only one MUX where enocoders could be cloned. */
  8647. if (encoder->cloneable && source_encoder->cloneable)
  8648. index_mask |= (1 << entry);
  8649. entry++;
  8650. }
  8651. return index_mask;
  8652. }
  8653. static bool has_edp_a(struct drm_device *dev)
  8654. {
  8655. struct drm_i915_private *dev_priv = dev->dev_private;
  8656. if (!IS_MOBILE(dev))
  8657. return false;
  8658. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  8659. return false;
  8660. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  8661. return false;
  8662. return true;
  8663. }
  8664. const char *intel_output_name(int output)
  8665. {
  8666. static const char *names[] = {
  8667. [INTEL_OUTPUT_UNUSED] = "Unused",
  8668. [INTEL_OUTPUT_ANALOG] = "Analog",
  8669. [INTEL_OUTPUT_DVO] = "DVO",
  8670. [INTEL_OUTPUT_SDVO] = "SDVO",
  8671. [INTEL_OUTPUT_LVDS] = "LVDS",
  8672. [INTEL_OUTPUT_TVOUT] = "TV",
  8673. [INTEL_OUTPUT_HDMI] = "HDMI",
  8674. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  8675. [INTEL_OUTPUT_EDP] = "eDP",
  8676. [INTEL_OUTPUT_DSI] = "DSI",
  8677. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  8678. };
  8679. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  8680. return "Invalid";
  8681. return names[output];
  8682. }
  8683. static void intel_setup_outputs(struct drm_device *dev)
  8684. {
  8685. struct drm_i915_private *dev_priv = dev->dev_private;
  8686. struct intel_encoder *encoder;
  8687. bool dpd_is_edp = false;
  8688. intel_lvds_init(dev);
  8689. if (!IS_ULT(dev))
  8690. intel_crt_init(dev);
  8691. if (HAS_DDI(dev)) {
  8692. int found;
  8693. /* Haswell uses DDI functions to detect digital outputs */
  8694. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  8695. /* DDI A only supports eDP */
  8696. if (found)
  8697. intel_ddi_init(dev, PORT_A);
  8698. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  8699. * register */
  8700. found = I915_READ(SFUSE_STRAP);
  8701. if (found & SFUSE_STRAP_DDIB_DETECTED)
  8702. intel_ddi_init(dev, PORT_B);
  8703. if (found & SFUSE_STRAP_DDIC_DETECTED)
  8704. intel_ddi_init(dev, PORT_C);
  8705. if (found & SFUSE_STRAP_DDID_DETECTED)
  8706. intel_ddi_init(dev, PORT_D);
  8707. } else if (HAS_PCH_SPLIT(dev)) {
  8708. int found;
  8709. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  8710. if (has_edp_a(dev))
  8711. intel_dp_init(dev, DP_A, PORT_A);
  8712. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  8713. /* PCH SDVOB multiplex with HDMIB */
  8714. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  8715. if (!found)
  8716. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  8717. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  8718. intel_dp_init(dev, PCH_DP_B, PORT_B);
  8719. }
  8720. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  8721. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  8722. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  8723. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  8724. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  8725. intel_dp_init(dev, PCH_DP_C, PORT_C);
  8726. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  8727. intel_dp_init(dev, PCH_DP_D, PORT_D);
  8728. } else if (IS_VALLEYVIEW(dev)) {
  8729. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) {
  8730. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  8731. PORT_B);
  8732. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  8733. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  8734. }
  8735. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) {
  8736. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  8737. PORT_C);
  8738. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  8739. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  8740. }
  8741. intel_dsi_init(dev);
  8742. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  8743. bool found = false;
  8744. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  8745. DRM_DEBUG_KMS("probing SDVOB\n");
  8746. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  8747. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  8748. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  8749. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  8750. }
  8751. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  8752. intel_dp_init(dev, DP_B, PORT_B);
  8753. }
  8754. /* Before G4X SDVOC doesn't have its own detect register */
  8755. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  8756. DRM_DEBUG_KMS("probing SDVOC\n");
  8757. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  8758. }
  8759. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  8760. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  8761. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  8762. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  8763. }
  8764. if (SUPPORTS_INTEGRATED_DP(dev))
  8765. intel_dp_init(dev, DP_C, PORT_C);
  8766. }
  8767. if (SUPPORTS_INTEGRATED_DP(dev) &&
  8768. (I915_READ(DP_D) & DP_DETECTED))
  8769. intel_dp_init(dev, DP_D, PORT_D);
  8770. } else if (IS_GEN2(dev))
  8771. intel_dvo_init(dev);
  8772. if (SUPPORTS_TV(dev))
  8773. intel_tv_init(dev);
  8774. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  8775. encoder->base.possible_crtcs = encoder->crtc_mask;
  8776. encoder->base.possible_clones =
  8777. intel_encoder_clones(encoder);
  8778. }
  8779. intel_init_pch_refclk(dev);
  8780. drm_helper_move_panel_connectors_to_head(dev);
  8781. }
  8782. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  8783. {
  8784. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  8785. drm_framebuffer_cleanup(fb);
  8786. WARN_ON(!intel_fb->obj->framebuffer_references--);
  8787. drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
  8788. kfree(intel_fb);
  8789. }
  8790. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  8791. struct drm_file *file,
  8792. unsigned int *handle)
  8793. {
  8794. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  8795. struct drm_i915_gem_object *obj = intel_fb->obj;
  8796. return drm_gem_handle_create(file, &obj->base, handle);
  8797. }
  8798. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  8799. .destroy = intel_user_framebuffer_destroy,
  8800. .create_handle = intel_user_framebuffer_create_handle,
  8801. };
  8802. int intel_framebuffer_init(struct drm_device *dev,
  8803. struct intel_framebuffer *intel_fb,
  8804. struct drm_mode_fb_cmd2 *mode_cmd,
  8805. struct drm_i915_gem_object *obj)
  8806. {
  8807. int aligned_height, tile_height;
  8808. int pitch_limit;
  8809. int ret;
  8810. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  8811. if (obj->tiling_mode == I915_TILING_Y) {
  8812. DRM_DEBUG("hardware does not support tiling Y\n");
  8813. return -EINVAL;
  8814. }
  8815. if (mode_cmd->pitches[0] & 63) {
  8816. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  8817. mode_cmd->pitches[0]);
  8818. return -EINVAL;
  8819. }
  8820. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  8821. pitch_limit = 32*1024;
  8822. } else if (INTEL_INFO(dev)->gen >= 4) {
  8823. if (obj->tiling_mode)
  8824. pitch_limit = 16*1024;
  8825. else
  8826. pitch_limit = 32*1024;
  8827. } else if (INTEL_INFO(dev)->gen >= 3) {
  8828. if (obj->tiling_mode)
  8829. pitch_limit = 8*1024;
  8830. else
  8831. pitch_limit = 16*1024;
  8832. } else
  8833. /* XXX DSPC is limited to 4k tiled */
  8834. pitch_limit = 8*1024;
  8835. if (mode_cmd->pitches[0] > pitch_limit) {
  8836. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  8837. obj->tiling_mode ? "tiled" : "linear",
  8838. mode_cmd->pitches[0], pitch_limit);
  8839. return -EINVAL;
  8840. }
  8841. if (obj->tiling_mode != I915_TILING_NONE &&
  8842. mode_cmd->pitches[0] != obj->stride) {
  8843. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  8844. mode_cmd->pitches[0], obj->stride);
  8845. return -EINVAL;
  8846. }
  8847. /* Reject formats not supported by any plane early. */
  8848. switch (mode_cmd->pixel_format) {
  8849. case DRM_FORMAT_C8:
  8850. case DRM_FORMAT_RGB565:
  8851. case DRM_FORMAT_XRGB8888:
  8852. case DRM_FORMAT_ARGB8888:
  8853. break;
  8854. case DRM_FORMAT_XRGB1555:
  8855. case DRM_FORMAT_ARGB1555:
  8856. if (INTEL_INFO(dev)->gen > 3) {
  8857. DRM_DEBUG("unsupported pixel format: %s\n",
  8858. drm_get_format_name(mode_cmd->pixel_format));
  8859. return -EINVAL;
  8860. }
  8861. break;
  8862. case DRM_FORMAT_XBGR8888:
  8863. case DRM_FORMAT_ABGR8888:
  8864. case DRM_FORMAT_XRGB2101010:
  8865. case DRM_FORMAT_ARGB2101010:
  8866. case DRM_FORMAT_XBGR2101010:
  8867. case DRM_FORMAT_ABGR2101010:
  8868. if (INTEL_INFO(dev)->gen < 4) {
  8869. DRM_DEBUG("unsupported pixel format: %s\n",
  8870. drm_get_format_name(mode_cmd->pixel_format));
  8871. return -EINVAL;
  8872. }
  8873. break;
  8874. case DRM_FORMAT_YUYV:
  8875. case DRM_FORMAT_UYVY:
  8876. case DRM_FORMAT_YVYU:
  8877. case DRM_FORMAT_VYUY:
  8878. if (INTEL_INFO(dev)->gen < 5) {
  8879. DRM_DEBUG("unsupported pixel format: %s\n",
  8880. drm_get_format_name(mode_cmd->pixel_format));
  8881. return -EINVAL;
  8882. }
  8883. break;
  8884. default:
  8885. DRM_DEBUG("unsupported pixel format: %s\n",
  8886. drm_get_format_name(mode_cmd->pixel_format));
  8887. return -EINVAL;
  8888. }
  8889. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  8890. if (mode_cmd->offsets[0] != 0)
  8891. return -EINVAL;
  8892. tile_height = IS_GEN2(dev) ? 16 : 8;
  8893. aligned_height = ALIGN(mode_cmd->height,
  8894. obj->tiling_mode ? tile_height : 1);
  8895. /* FIXME drm helper for size checks (especially planar formats)? */
  8896. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  8897. return -EINVAL;
  8898. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  8899. intel_fb->obj = obj;
  8900. intel_fb->obj->framebuffer_references++;
  8901. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  8902. if (ret) {
  8903. DRM_ERROR("framebuffer init failed %d\n", ret);
  8904. return ret;
  8905. }
  8906. return 0;
  8907. }
  8908. static struct drm_framebuffer *
  8909. intel_user_framebuffer_create(struct drm_device *dev,
  8910. struct drm_file *filp,
  8911. struct drm_mode_fb_cmd2 *mode_cmd)
  8912. {
  8913. struct drm_i915_gem_object *obj;
  8914. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  8915. mode_cmd->handles[0]));
  8916. if (&obj->base == NULL)
  8917. return ERR_PTR(-ENOENT);
  8918. return intel_framebuffer_create(dev, mode_cmd, obj);
  8919. }
  8920. #ifndef CONFIG_DRM_I915_FBDEV
  8921. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  8922. {
  8923. }
  8924. #endif
  8925. static const struct drm_mode_config_funcs intel_mode_funcs = {
  8926. .fb_create = intel_user_framebuffer_create,
  8927. .output_poll_changed = intel_fbdev_output_poll_changed,
  8928. };
  8929. /* Set up chip specific display functions */
  8930. static void intel_init_display(struct drm_device *dev)
  8931. {
  8932. struct drm_i915_private *dev_priv = dev->dev_private;
  8933. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  8934. dev_priv->display.find_dpll = g4x_find_best_dpll;
  8935. else if (IS_VALLEYVIEW(dev))
  8936. dev_priv->display.find_dpll = vlv_find_best_dpll;
  8937. else if (IS_PINEVIEW(dev))
  8938. dev_priv->display.find_dpll = pnv_find_best_dpll;
  8939. else
  8940. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  8941. if (HAS_DDI(dev)) {
  8942. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  8943. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  8944. dev_priv->display.crtc_enable = haswell_crtc_enable;
  8945. dev_priv->display.crtc_disable = haswell_crtc_disable;
  8946. dev_priv->display.off = haswell_crtc_off;
  8947. dev_priv->display.update_plane = ironlake_update_plane;
  8948. } else if (HAS_PCH_SPLIT(dev)) {
  8949. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  8950. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  8951. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  8952. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  8953. dev_priv->display.off = ironlake_crtc_off;
  8954. dev_priv->display.update_plane = ironlake_update_plane;
  8955. } else if (IS_VALLEYVIEW(dev)) {
  8956. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  8957. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  8958. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  8959. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  8960. dev_priv->display.off = i9xx_crtc_off;
  8961. dev_priv->display.update_plane = i9xx_update_plane;
  8962. } else {
  8963. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  8964. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  8965. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  8966. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  8967. dev_priv->display.off = i9xx_crtc_off;
  8968. dev_priv->display.update_plane = i9xx_update_plane;
  8969. }
  8970. /* Returns the core display clock speed */
  8971. if (IS_VALLEYVIEW(dev))
  8972. dev_priv->display.get_display_clock_speed =
  8973. valleyview_get_display_clock_speed;
  8974. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  8975. dev_priv->display.get_display_clock_speed =
  8976. i945_get_display_clock_speed;
  8977. else if (IS_I915G(dev))
  8978. dev_priv->display.get_display_clock_speed =
  8979. i915_get_display_clock_speed;
  8980. else if (IS_I945GM(dev) || IS_845G(dev))
  8981. dev_priv->display.get_display_clock_speed =
  8982. i9xx_misc_get_display_clock_speed;
  8983. else if (IS_PINEVIEW(dev))
  8984. dev_priv->display.get_display_clock_speed =
  8985. pnv_get_display_clock_speed;
  8986. else if (IS_I915GM(dev))
  8987. dev_priv->display.get_display_clock_speed =
  8988. i915gm_get_display_clock_speed;
  8989. else if (IS_I865G(dev))
  8990. dev_priv->display.get_display_clock_speed =
  8991. i865_get_display_clock_speed;
  8992. else if (IS_I85X(dev))
  8993. dev_priv->display.get_display_clock_speed =
  8994. i855_get_display_clock_speed;
  8995. else /* 852, 830 */
  8996. dev_priv->display.get_display_clock_speed =
  8997. i830_get_display_clock_speed;
  8998. if (HAS_PCH_SPLIT(dev)) {
  8999. if (IS_GEN5(dev)) {
  9000. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  9001. dev_priv->display.write_eld = ironlake_write_eld;
  9002. } else if (IS_GEN6(dev)) {
  9003. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  9004. dev_priv->display.write_eld = ironlake_write_eld;
  9005. } else if (IS_IVYBRIDGE(dev)) {
  9006. /* FIXME: detect B0+ stepping and use auto training */
  9007. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  9008. dev_priv->display.write_eld = ironlake_write_eld;
  9009. dev_priv->display.modeset_global_resources =
  9010. ivb_modeset_global_resources;
  9011. } else if (IS_HASWELL(dev) || IS_GEN8(dev)) {
  9012. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  9013. dev_priv->display.write_eld = haswell_write_eld;
  9014. dev_priv->display.modeset_global_resources =
  9015. haswell_modeset_global_resources;
  9016. }
  9017. } else if (IS_G4X(dev)) {
  9018. dev_priv->display.write_eld = g4x_write_eld;
  9019. } else if (IS_VALLEYVIEW(dev)) {
  9020. dev_priv->display.modeset_global_resources =
  9021. valleyview_modeset_global_resources;
  9022. dev_priv->display.write_eld = ironlake_write_eld;
  9023. }
  9024. /* Default just returns -ENODEV to indicate unsupported */
  9025. dev_priv->display.queue_flip = intel_default_queue_flip;
  9026. switch (INTEL_INFO(dev)->gen) {
  9027. case 2:
  9028. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  9029. break;
  9030. case 3:
  9031. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  9032. break;
  9033. case 4:
  9034. case 5:
  9035. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  9036. break;
  9037. case 6:
  9038. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  9039. break;
  9040. case 7:
  9041. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  9042. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  9043. break;
  9044. }
  9045. intel_panel_init_backlight_funcs(dev);
  9046. }
  9047. /*
  9048. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  9049. * resume, or other times. This quirk makes sure that's the case for
  9050. * affected systems.
  9051. */
  9052. static void quirk_pipea_force(struct drm_device *dev)
  9053. {
  9054. struct drm_i915_private *dev_priv = dev->dev_private;
  9055. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  9056. DRM_INFO("applying pipe a force quirk\n");
  9057. }
  9058. /*
  9059. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  9060. */
  9061. static void quirk_ssc_force_disable(struct drm_device *dev)
  9062. {
  9063. struct drm_i915_private *dev_priv = dev->dev_private;
  9064. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  9065. DRM_INFO("applying lvds SSC disable quirk\n");
  9066. }
  9067. /*
  9068. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  9069. * brightness value
  9070. */
  9071. static void quirk_invert_brightness(struct drm_device *dev)
  9072. {
  9073. struct drm_i915_private *dev_priv = dev->dev_private;
  9074. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  9075. DRM_INFO("applying inverted panel brightness quirk\n");
  9076. }
  9077. struct intel_quirk {
  9078. int device;
  9079. int subsystem_vendor;
  9080. int subsystem_device;
  9081. void (*hook)(struct drm_device *dev);
  9082. };
  9083. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  9084. struct intel_dmi_quirk {
  9085. void (*hook)(struct drm_device *dev);
  9086. const struct dmi_system_id (*dmi_id_list)[];
  9087. };
  9088. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  9089. {
  9090. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  9091. return 1;
  9092. }
  9093. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  9094. {
  9095. .dmi_id_list = &(const struct dmi_system_id[]) {
  9096. {
  9097. .callback = intel_dmi_reverse_brightness,
  9098. .ident = "NCR Corporation",
  9099. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  9100. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  9101. },
  9102. },
  9103. { } /* terminating entry */
  9104. },
  9105. .hook = quirk_invert_brightness,
  9106. },
  9107. };
  9108. static struct intel_quirk intel_quirks[] = {
  9109. /* HP Mini needs pipe A force quirk (LP: #322104) */
  9110. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  9111. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  9112. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  9113. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  9114. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  9115. /* 830 needs to leave pipe A & dpll A up */
  9116. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  9117. /* Lenovo U160 cannot use SSC on LVDS */
  9118. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  9119. /* Sony Vaio Y cannot use SSC on LVDS */
  9120. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  9121. /* Acer Aspire 5734Z must invert backlight brightness */
  9122. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  9123. /* Acer/eMachines G725 */
  9124. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  9125. /* Acer/eMachines e725 */
  9126. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  9127. /* Acer/Packard Bell NCL20 */
  9128. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  9129. /* Acer Aspire 4736Z */
  9130. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  9131. /* Acer Aspire 5336 */
  9132. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  9133. };
  9134. static void intel_init_quirks(struct drm_device *dev)
  9135. {
  9136. struct pci_dev *d = dev->pdev;
  9137. int i;
  9138. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  9139. struct intel_quirk *q = &intel_quirks[i];
  9140. if (d->device == q->device &&
  9141. (d->subsystem_vendor == q->subsystem_vendor ||
  9142. q->subsystem_vendor == PCI_ANY_ID) &&
  9143. (d->subsystem_device == q->subsystem_device ||
  9144. q->subsystem_device == PCI_ANY_ID))
  9145. q->hook(dev);
  9146. }
  9147. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  9148. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  9149. intel_dmi_quirks[i].hook(dev);
  9150. }
  9151. }
  9152. /* Disable the VGA plane that we never use */
  9153. static void i915_disable_vga(struct drm_device *dev)
  9154. {
  9155. struct drm_i915_private *dev_priv = dev->dev_private;
  9156. u8 sr1;
  9157. u32 vga_reg = i915_vgacntrl_reg(dev);
  9158. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  9159. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  9160. outb(SR01, VGA_SR_INDEX);
  9161. sr1 = inb(VGA_SR_DATA);
  9162. outb(sr1 | 1<<5, VGA_SR_DATA);
  9163. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  9164. udelay(300);
  9165. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  9166. POSTING_READ(vga_reg);
  9167. }
  9168. void intel_modeset_init_hw(struct drm_device *dev)
  9169. {
  9170. intel_prepare_ddi(dev);
  9171. intel_init_clock_gating(dev);
  9172. intel_reset_dpio(dev);
  9173. mutex_lock(&dev->struct_mutex);
  9174. intel_enable_gt_powersave(dev);
  9175. mutex_unlock(&dev->struct_mutex);
  9176. }
  9177. void intel_modeset_suspend_hw(struct drm_device *dev)
  9178. {
  9179. intel_suspend_hw(dev);
  9180. }
  9181. void intel_modeset_init(struct drm_device *dev)
  9182. {
  9183. struct drm_i915_private *dev_priv = dev->dev_private;
  9184. int i, j, ret;
  9185. drm_mode_config_init(dev);
  9186. dev->mode_config.min_width = 0;
  9187. dev->mode_config.min_height = 0;
  9188. dev->mode_config.preferred_depth = 24;
  9189. dev->mode_config.prefer_shadow = 1;
  9190. dev->mode_config.funcs = &intel_mode_funcs;
  9191. intel_init_quirks(dev);
  9192. intel_init_pm(dev);
  9193. if (INTEL_INFO(dev)->num_pipes == 0)
  9194. return;
  9195. intel_init_display(dev);
  9196. if (IS_GEN2(dev)) {
  9197. dev->mode_config.max_width = 2048;
  9198. dev->mode_config.max_height = 2048;
  9199. } else if (IS_GEN3(dev)) {
  9200. dev->mode_config.max_width = 4096;
  9201. dev->mode_config.max_height = 4096;
  9202. } else {
  9203. dev->mode_config.max_width = 8192;
  9204. dev->mode_config.max_height = 8192;
  9205. }
  9206. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  9207. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  9208. INTEL_INFO(dev)->num_pipes,
  9209. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  9210. for_each_pipe(i) {
  9211. intel_crtc_init(dev, i);
  9212. for (j = 0; j < INTEL_INFO(dev)->num_sprites; j++) {
  9213. ret = intel_plane_init(dev, i, j);
  9214. if (ret)
  9215. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  9216. pipe_name(i), sprite_name(i, j), ret);
  9217. }
  9218. }
  9219. intel_init_dpio(dev);
  9220. intel_reset_dpio(dev);
  9221. intel_cpu_pll_init(dev);
  9222. intel_shared_dpll_init(dev);
  9223. /* Just disable it once at startup */
  9224. i915_disable_vga(dev);
  9225. intel_setup_outputs(dev);
  9226. /* Just in case the BIOS is doing something questionable. */
  9227. intel_disable_fbc(dev);
  9228. }
  9229. static void
  9230. intel_connector_break_all_links(struct intel_connector *connector)
  9231. {
  9232. connector->base.dpms = DRM_MODE_DPMS_OFF;
  9233. connector->base.encoder = NULL;
  9234. connector->encoder->connectors_active = false;
  9235. connector->encoder->base.crtc = NULL;
  9236. }
  9237. static void intel_enable_pipe_a(struct drm_device *dev)
  9238. {
  9239. struct intel_connector *connector;
  9240. struct drm_connector *crt = NULL;
  9241. struct intel_load_detect_pipe load_detect_temp;
  9242. /* We can't just switch on the pipe A, we need to set things up with a
  9243. * proper mode and output configuration. As a gross hack, enable pipe A
  9244. * by enabling the load detect pipe once. */
  9245. list_for_each_entry(connector,
  9246. &dev->mode_config.connector_list,
  9247. base.head) {
  9248. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  9249. crt = &connector->base;
  9250. break;
  9251. }
  9252. }
  9253. if (!crt)
  9254. return;
  9255. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp))
  9256. intel_release_load_detect_pipe(crt, &load_detect_temp);
  9257. }
  9258. static bool
  9259. intel_check_plane_mapping(struct intel_crtc *crtc)
  9260. {
  9261. struct drm_device *dev = crtc->base.dev;
  9262. struct drm_i915_private *dev_priv = dev->dev_private;
  9263. u32 reg, val;
  9264. if (INTEL_INFO(dev)->num_pipes == 1)
  9265. return true;
  9266. reg = DSPCNTR(!crtc->plane);
  9267. val = I915_READ(reg);
  9268. if ((val & DISPLAY_PLANE_ENABLE) &&
  9269. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  9270. return false;
  9271. return true;
  9272. }
  9273. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  9274. {
  9275. struct drm_device *dev = crtc->base.dev;
  9276. struct drm_i915_private *dev_priv = dev->dev_private;
  9277. u32 reg;
  9278. /* Clear any frame start delays used for debugging left by the BIOS */
  9279. reg = PIPECONF(crtc->config.cpu_transcoder);
  9280. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  9281. /* We need to sanitize the plane -> pipe mapping first because this will
  9282. * disable the crtc (and hence change the state) if it is wrong. Note
  9283. * that gen4+ has a fixed plane -> pipe mapping. */
  9284. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  9285. struct intel_connector *connector;
  9286. bool plane;
  9287. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  9288. crtc->base.base.id);
  9289. /* Pipe has the wrong plane attached and the plane is active.
  9290. * Temporarily change the plane mapping and disable everything
  9291. * ... */
  9292. plane = crtc->plane;
  9293. crtc->plane = !plane;
  9294. dev_priv->display.crtc_disable(&crtc->base);
  9295. crtc->plane = plane;
  9296. /* ... and break all links. */
  9297. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9298. base.head) {
  9299. if (connector->encoder->base.crtc != &crtc->base)
  9300. continue;
  9301. intel_connector_break_all_links(connector);
  9302. }
  9303. WARN_ON(crtc->active);
  9304. crtc->base.enabled = false;
  9305. }
  9306. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  9307. crtc->pipe == PIPE_A && !crtc->active) {
  9308. /* BIOS forgot to enable pipe A, this mostly happens after
  9309. * resume. Force-enable the pipe to fix this, the update_dpms
  9310. * call below we restore the pipe to the right state, but leave
  9311. * the required bits on. */
  9312. intel_enable_pipe_a(dev);
  9313. }
  9314. /* Adjust the state of the output pipe according to whether we
  9315. * have active connectors/encoders. */
  9316. intel_crtc_update_dpms(&crtc->base);
  9317. if (crtc->active != crtc->base.enabled) {
  9318. struct intel_encoder *encoder;
  9319. /* This can happen either due to bugs in the get_hw_state
  9320. * functions or because the pipe is force-enabled due to the
  9321. * pipe A quirk. */
  9322. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  9323. crtc->base.base.id,
  9324. crtc->base.enabled ? "enabled" : "disabled",
  9325. crtc->active ? "enabled" : "disabled");
  9326. crtc->base.enabled = crtc->active;
  9327. /* Because we only establish the connector -> encoder ->
  9328. * crtc links if something is active, this means the
  9329. * crtc is now deactivated. Break the links. connector
  9330. * -> encoder links are only establish when things are
  9331. * actually up, hence no need to break them. */
  9332. WARN_ON(crtc->active);
  9333. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  9334. WARN_ON(encoder->connectors_active);
  9335. encoder->base.crtc = NULL;
  9336. }
  9337. }
  9338. }
  9339. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  9340. {
  9341. struct intel_connector *connector;
  9342. struct drm_device *dev = encoder->base.dev;
  9343. /* We need to check both for a crtc link (meaning that the
  9344. * encoder is active and trying to read from a pipe) and the
  9345. * pipe itself being active. */
  9346. bool has_active_crtc = encoder->base.crtc &&
  9347. to_intel_crtc(encoder->base.crtc)->active;
  9348. if (encoder->connectors_active && !has_active_crtc) {
  9349. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  9350. encoder->base.base.id,
  9351. drm_get_encoder_name(&encoder->base));
  9352. /* Connector is active, but has no active pipe. This is
  9353. * fallout from our resume register restoring. Disable
  9354. * the encoder manually again. */
  9355. if (encoder->base.crtc) {
  9356. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  9357. encoder->base.base.id,
  9358. drm_get_encoder_name(&encoder->base));
  9359. encoder->disable(encoder);
  9360. }
  9361. /* Inconsistent output/port/pipe state happens presumably due to
  9362. * a bug in one of the get_hw_state functions. Or someplace else
  9363. * in our code, like the register restore mess on resume. Clamp
  9364. * things to off as a safer default. */
  9365. list_for_each_entry(connector,
  9366. &dev->mode_config.connector_list,
  9367. base.head) {
  9368. if (connector->encoder != encoder)
  9369. continue;
  9370. intel_connector_break_all_links(connector);
  9371. }
  9372. }
  9373. /* Enabled encoders without active connectors will be fixed in
  9374. * the crtc fixup. */
  9375. }
  9376. void i915_redisable_vga(struct drm_device *dev)
  9377. {
  9378. struct drm_i915_private *dev_priv = dev->dev_private;
  9379. u32 vga_reg = i915_vgacntrl_reg(dev);
  9380. /* This function can be called both from intel_modeset_setup_hw_state or
  9381. * at a very early point in our resume sequence, where the power well
  9382. * structures are not yet restored. Since this function is at a very
  9383. * paranoid "someone might have enabled VGA while we were not looking"
  9384. * level, just check if the power well is enabled instead of trying to
  9385. * follow the "don't touch the power well if we don't need it" policy
  9386. * the rest of the driver uses. */
  9387. if ((IS_HASWELL(dev) || IS_BROADWELL(dev)) &&
  9388. (I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_STATE_ENABLED) == 0)
  9389. return;
  9390. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  9391. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  9392. i915_disable_vga(dev);
  9393. }
  9394. }
  9395. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  9396. {
  9397. struct drm_i915_private *dev_priv = dev->dev_private;
  9398. enum pipe pipe;
  9399. struct intel_crtc *crtc;
  9400. struct intel_encoder *encoder;
  9401. struct intel_connector *connector;
  9402. int i;
  9403. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  9404. base.head) {
  9405. memset(&crtc->config, 0, sizeof(crtc->config));
  9406. crtc->active = dev_priv->display.get_pipe_config(crtc,
  9407. &crtc->config);
  9408. crtc->base.enabled = crtc->active;
  9409. crtc->primary_enabled = crtc->active;
  9410. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  9411. crtc->base.base.id,
  9412. crtc->active ? "enabled" : "disabled");
  9413. }
  9414. /* FIXME: Smash this into the new shared dpll infrastructure. */
  9415. if (HAS_DDI(dev))
  9416. intel_ddi_setup_hw_pll_state(dev);
  9417. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9418. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  9419. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  9420. pll->active = 0;
  9421. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  9422. base.head) {
  9423. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  9424. pll->active++;
  9425. }
  9426. pll->refcount = pll->active;
  9427. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  9428. pll->name, pll->refcount, pll->on);
  9429. }
  9430. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  9431. base.head) {
  9432. pipe = 0;
  9433. if (encoder->get_hw_state(encoder, &pipe)) {
  9434. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  9435. encoder->base.crtc = &crtc->base;
  9436. encoder->get_config(encoder, &crtc->config);
  9437. } else {
  9438. encoder->base.crtc = NULL;
  9439. }
  9440. encoder->connectors_active = false;
  9441. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  9442. encoder->base.base.id,
  9443. drm_get_encoder_name(&encoder->base),
  9444. encoder->base.crtc ? "enabled" : "disabled",
  9445. pipe_name(pipe));
  9446. }
  9447. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9448. base.head) {
  9449. if (connector->get_hw_state(connector)) {
  9450. connector->base.dpms = DRM_MODE_DPMS_ON;
  9451. connector->encoder->connectors_active = true;
  9452. connector->base.encoder = &connector->encoder->base;
  9453. } else {
  9454. connector->base.dpms = DRM_MODE_DPMS_OFF;
  9455. connector->base.encoder = NULL;
  9456. }
  9457. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  9458. connector->base.base.id,
  9459. drm_get_connector_name(&connector->base),
  9460. connector->base.encoder ? "enabled" : "disabled");
  9461. }
  9462. }
  9463. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  9464. * and i915 state tracking structures. */
  9465. void intel_modeset_setup_hw_state(struct drm_device *dev,
  9466. bool force_restore)
  9467. {
  9468. struct drm_i915_private *dev_priv = dev->dev_private;
  9469. enum pipe pipe;
  9470. struct intel_crtc *crtc;
  9471. struct intel_encoder *encoder;
  9472. int i;
  9473. intel_modeset_readout_hw_state(dev);
  9474. /*
  9475. * Now that we have the config, copy it to each CRTC struct
  9476. * Note that this could go away if we move to using crtc_config
  9477. * checking everywhere.
  9478. */
  9479. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  9480. base.head) {
  9481. if (crtc->active && i915.fastboot) {
  9482. intel_crtc_mode_from_pipe_config(crtc, &crtc->config);
  9483. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  9484. crtc->base.base.id);
  9485. drm_mode_debug_printmodeline(&crtc->base.mode);
  9486. }
  9487. }
  9488. /* HW state is read out, now we need to sanitize this mess. */
  9489. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  9490. base.head) {
  9491. intel_sanitize_encoder(encoder);
  9492. }
  9493. for_each_pipe(pipe) {
  9494. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  9495. intel_sanitize_crtc(crtc);
  9496. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  9497. }
  9498. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9499. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  9500. if (!pll->on || pll->active)
  9501. continue;
  9502. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  9503. pll->disable(dev_priv, pll);
  9504. pll->on = false;
  9505. }
  9506. if (HAS_PCH_SPLIT(dev))
  9507. ilk_wm_get_hw_state(dev);
  9508. if (force_restore) {
  9509. i915_redisable_vga(dev);
  9510. /*
  9511. * We need to use raw interfaces for restoring state to avoid
  9512. * checking (bogus) intermediate states.
  9513. */
  9514. for_each_pipe(pipe) {
  9515. struct drm_crtc *crtc =
  9516. dev_priv->pipe_to_crtc_mapping[pipe];
  9517. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  9518. crtc->fb);
  9519. }
  9520. } else {
  9521. intel_modeset_update_staged_output_state(dev);
  9522. }
  9523. intel_modeset_check_state(dev);
  9524. }
  9525. void intel_modeset_gem_init(struct drm_device *dev)
  9526. {
  9527. intel_modeset_init_hw(dev);
  9528. intel_setup_overlay(dev);
  9529. mutex_lock(&dev->mode_config.mutex);
  9530. intel_modeset_setup_hw_state(dev, false);
  9531. mutex_unlock(&dev->mode_config.mutex);
  9532. }
  9533. void intel_modeset_cleanup(struct drm_device *dev)
  9534. {
  9535. struct drm_i915_private *dev_priv = dev->dev_private;
  9536. struct drm_crtc *crtc;
  9537. struct drm_connector *connector;
  9538. /*
  9539. * Interrupts and polling as the first thing to avoid creating havoc.
  9540. * Too much stuff here (turning of rps, connectors, ...) would
  9541. * experience fancy races otherwise.
  9542. */
  9543. drm_irq_uninstall(dev);
  9544. cancel_work_sync(&dev_priv->hotplug_work);
  9545. /*
  9546. * Due to the hpd irq storm handling the hotplug work can re-arm the
  9547. * poll handlers. Hence disable polling after hpd handling is shut down.
  9548. */
  9549. drm_kms_helper_poll_fini(dev);
  9550. mutex_lock(&dev->struct_mutex);
  9551. intel_unregister_dsm_handler();
  9552. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  9553. /* Skip inactive CRTCs */
  9554. if (!crtc->fb)
  9555. continue;
  9556. intel_increase_pllclock(crtc);
  9557. }
  9558. intel_disable_fbc(dev);
  9559. intel_disable_gt_powersave(dev);
  9560. ironlake_teardown_rc6(dev);
  9561. mutex_unlock(&dev->struct_mutex);
  9562. /* flush any delayed tasks or pending work */
  9563. flush_scheduled_work();
  9564. /* destroy the backlight and sysfs files before encoders/connectors */
  9565. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9566. intel_panel_destroy_backlight(connector);
  9567. drm_sysfs_connector_remove(connector);
  9568. }
  9569. drm_mode_config_cleanup(dev);
  9570. intel_cleanup_overlay(dev);
  9571. }
  9572. /*
  9573. * Return which encoder is currently attached for connector.
  9574. */
  9575. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  9576. {
  9577. return &intel_attached_encoder(connector)->base;
  9578. }
  9579. void intel_connector_attach_encoder(struct intel_connector *connector,
  9580. struct intel_encoder *encoder)
  9581. {
  9582. connector->encoder = encoder;
  9583. drm_mode_connector_attach_encoder(&connector->base,
  9584. &encoder->base);
  9585. }
  9586. /*
  9587. * set vga decode state - true == enable VGA decode
  9588. */
  9589. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  9590. {
  9591. struct drm_i915_private *dev_priv = dev->dev_private;
  9592. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  9593. u16 gmch_ctrl;
  9594. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  9595. DRM_ERROR("failed to read control word\n");
  9596. return -EIO;
  9597. }
  9598. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  9599. return 0;
  9600. if (state)
  9601. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  9602. else
  9603. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  9604. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  9605. DRM_ERROR("failed to write control word\n");
  9606. return -EIO;
  9607. }
  9608. return 0;
  9609. }
  9610. struct intel_display_error_state {
  9611. u32 power_well_driver;
  9612. int num_transcoders;
  9613. struct intel_cursor_error_state {
  9614. u32 control;
  9615. u32 position;
  9616. u32 base;
  9617. u32 size;
  9618. } cursor[I915_MAX_PIPES];
  9619. struct intel_pipe_error_state {
  9620. bool power_domain_on;
  9621. u32 source;
  9622. } pipe[I915_MAX_PIPES];
  9623. struct intel_plane_error_state {
  9624. u32 control;
  9625. u32 stride;
  9626. u32 size;
  9627. u32 pos;
  9628. u32 addr;
  9629. u32 surface;
  9630. u32 tile_offset;
  9631. } plane[I915_MAX_PIPES];
  9632. struct intel_transcoder_error_state {
  9633. bool power_domain_on;
  9634. enum transcoder cpu_transcoder;
  9635. u32 conf;
  9636. u32 htotal;
  9637. u32 hblank;
  9638. u32 hsync;
  9639. u32 vtotal;
  9640. u32 vblank;
  9641. u32 vsync;
  9642. } transcoder[4];
  9643. };
  9644. struct intel_display_error_state *
  9645. intel_display_capture_error_state(struct drm_device *dev)
  9646. {
  9647. drm_i915_private_t *dev_priv = dev->dev_private;
  9648. struct intel_display_error_state *error;
  9649. int transcoders[] = {
  9650. TRANSCODER_A,
  9651. TRANSCODER_B,
  9652. TRANSCODER_C,
  9653. TRANSCODER_EDP,
  9654. };
  9655. int i;
  9656. if (INTEL_INFO(dev)->num_pipes == 0)
  9657. return NULL;
  9658. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  9659. if (error == NULL)
  9660. return NULL;
  9661. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  9662. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  9663. for_each_pipe(i) {
  9664. error->pipe[i].power_domain_on =
  9665. intel_display_power_enabled_sw(dev, POWER_DOMAIN_PIPE(i));
  9666. if (!error->pipe[i].power_domain_on)
  9667. continue;
  9668. if (INTEL_INFO(dev)->gen <= 6 || IS_VALLEYVIEW(dev)) {
  9669. error->cursor[i].control = I915_READ(CURCNTR(i));
  9670. error->cursor[i].position = I915_READ(CURPOS(i));
  9671. error->cursor[i].base = I915_READ(CURBASE(i));
  9672. } else {
  9673. error->cursor[i].control = I915_READ(CURCNTR_IVB(i));
  9674. error->cursor[i].position = I915_READ(CURPOS_IVB(i));
  9675. error->cursor[i].base = I915_READ(CURBASE_IVB(i));
  9676. }
  9677. error->plane[i].control = I915_READ(DSPCNTR(i));
  9678. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  9679. if (INTEL_INFO(dev)->gen <= 3) {
  9680. error->plane[i].size = I915_READ(DSPSIZE(i));
  9681. error->plane[i].pos = I915_READ(DSPPOS(i));
  9682. }
  9683. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  9684. error->plane[i].addr = I915_READ(DSPADDR(i));
  9685. if (INTEL_INFO(dev)->gen >= 4) {
  9686. error->plane[i].surface = I915_READ(DSPSURF(i));
  9687. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  9688. }
  9689. error->pipe[i].source = I915_READ(PIPESRC(i));
  9690. }
  9691. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  9692. if (HAS_DDI(dev_priv->dev))
  9693. error->num_transcoders++; /* Account for eDP. */
  9694. for (i = 0; i < error->num_transcoders; i++) {
  9695. enum transcoder cpu_transcoder = transcoders[i];
  9696. error->transcoder[i].power_domain_on =
  9697. intel_display_power_enabled_sw(dev,
  9698. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  9699. if (!error->transcoder[i].power_domain_on)
  9700. continue;
  9701. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  9702. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  9703. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  9704. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  9705. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  9706. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  9707. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  9708. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  9709. }
  9710. return error;
  9711. }
  9712. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  9713. void
  9714. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  9715. struct drm_device *dev,
  9716. struct intel_display_error_state *error)
  9717. {
  9718. int i;
  9719. if (!error)
  9720. return;
  9721. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  9722. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  9723. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  9724. error->power_well_driver);
  9725. for_each_pipe(i) {
  9726. err_printf(m, "Pipe [%d]:\n", i);
  9727. err_printf(m, " Power: %s\n",
  9728. error->pipe[i].power_domain_on ? "on" : "off");
  9729. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  9730. err_printf(m, "Plane [%d]:\n", i);
  9731. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  9732. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  9733. if (INTEL_INFO(dev)->gen <= 3) {
  9734. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  9735. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  9736. }
  9737. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  9738. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  9739. if (INTEL_INFO(dev)->gen >= 4) {
  9740. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  9741. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  9742. }
  9743. err_printf(m, "Cursor [%d]:\n", i);
  9744. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  9745. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  9746. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  9747. }
  9748. for (i = 0; i < error->num_transcoders; i++) {
  9749. err_printf(m, "CPU transcoder: %c\n",
  9750. transcoder_name(error->transcoder[i].cpu_transcoder));
  9751. err_printf(m, " Power: %s\n",
  9752. error->transcoder[i].power_domain_on ? "on" : "off");
  9753. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  9754. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  9755. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  9756. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  9757. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  9758. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  9759. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  9760. }
  9761. }