intel_display.c 279 KB

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