intel_display.c 365 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263
  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 <drm/drm_plane_helper.h>
  42. #include <drm/drm_rect.h>
  43. #include <linux/dma_remapping.h>
  44. /* Primary plane formats supported by all gen */
  45. #define COMMON_PRIMARY_FORMATS \
  46. DRM_FORMAT_C8, \
  47. DRM_FORMAT_RGB565, \
  48. DRM_FORMAT_XRGB8888, \
  49. DRM_FORMAT_ARGB8888
  50. /* Primary plane formats for gen <= 3 */
  51. static const uint32_t intel_primary_formats_gen2[] = {
  52. COMMON_PRIMARY_FORMATS,
  53. DRM_FORMAT_XRGB1555,
  54. DRM_FORMAT_ARGB1555,
  55. };
  56. /* Primary plane formats for gen >= 4 */
  57. static const uint32_t intel_primary_formats_gen4[] = {
  58. COMMON_PRIMARY_FORMATS, \
  59. DRM_FORMAT_XBGR8888,
  60. DRM_FORMAT_ABGR8888,
  61. DRM_FORMAT_XRGB2101010,
  62. DRM_FORMAT_ARGB2101010,
  63. DRM_FORMAT_XBGR2101010,
  64. DRM_FORMAT_ABGR2101010,
  65. };
  66. /* Cursor formats */
  67. static const uint32_t intel_cursor_formats[] = {
  68. DRM_FORMAT_ARGB8888,
  69. };
  70. #define DIV_ROUND_CLOSEST_ULL(ll, d) \
  71. ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
  72. static void intel_increase_pllclock(struct drm_device *dev,
  73. enum pipe pipe);
  74. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  75. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  76. struct intel_crtc_config *pipe_config);
  77. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  78. struct intel_crtc_config *pipe_config);
  79. static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
  80. int x, int y, struct drm_framebuffer *old_fb);
  81. static int intel_framebuffer_init(struct drm_device *dev,
  82. struct intel_framebuffer *ifb,
  83. struct drm_mode_fb_cmd2 *mode_cmd,
  84. struct drm_i915_gem_object *obj);
  85. static void intel_dp_set_m_n(struct intel_crtc *crtc);
  86. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
  87. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
  88. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  89. struct intel_link_m_n *m_n);
  90. static void ironlake_set_pipeconf(struct drm_crtc *crtc);
  91. static void haswell_set_pipeconf(struct drm_crtc *crtc);
  92. static void intel_set_pipe_csc(struct drm_crtc *crtc);
  93. static void vlv_prepare_pll(struct intel_crtc *crtc);
  94. typedef struct {
  95. int min, max;
  96. } intel_range_t;
  97. typedef struct {
  98. int dot_limit;
  99. int p2_slow, p2_fast;
  100. } intel_p2_t;
  101. typedef struct intel_limit intel_limit_t;
  102. struct intel_limit {
  103. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  104. intel_p2_t p2;
  105. };
  106. int
  107. intel_pch_rawclk(struct drm_device *dev)
  108. {
  109. struct drm_i915_private *dev_priv = dev->dev_private;
  110. WARN_ON(!HAS_PCH_SPLIT(dev));
  111. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  112. }
  113. static inline u32 /* units of 100MHz */
  114. intel_fdi_link_freq(struct drm_device *dev)
  115. {
  116. if (IS_GEN5(dev)) {
  117. struct drm_i915_private *dev_priv = dev->dev_private;
  118. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  119. } else
  120. return 27;
  121. }
  122. static const intel_limit_t intel_limits_i8xx_dac = {
  123. .dot = { .min = 25000, .max = 350000 },
  124. .vco = { .min = 908000, .max = 1512000 },
  125. .n = { .min = 2, .max = 16 },
  126. .m = { .min = 96, .max = 140 },
  127. .m1 = { .min = 18, .max = 26 },
  128. .m2 = { .min = 6, .max = 16 },
  129. .p = { .min = 4, .max = 128 },
  130. .p1 = { .min = 2, .max = 33 },
  131. .p2 = { .dot_limit = 165000,
  132. .p2_slow = 4, .p2_fast = 2 },
  133. };
  134. static const intel_limit_t intel_limits_i8xx_dvo = {
  135. .dot = { .min = 25000, .max = 350000 },
  136. .vco = { .min = 908000, .max = 1512000 },
  137. .n = { .min = 2, .max = 16 },
  138. .m = { .min = 96, .max = 140 },
  139. .m1 = { .min = 18, .max = 26 },
  140. .m2 = { .min = 6, .max = 16 },
  141. .p = { .min = 4, .max = 128 },
  142. .p1 = { .min = 2, .max = 33 },
  143. .p2 = { .dot_limit = 165000,
  144. .p2_slow = 4, .p2_fast = 4 },
  145. };
  146. static const intel_limit_t intel_limits_i8xx_lvds = {
  147. .dot = { .min = 25000, .max = 350000 },
  148. .vco = { .min = 908000, .max = 1512000 },
  149. .n = { .min = 2, .max = 16 },
  150. .m = { .min = 96, .max = 140 },
  151. .m1 = { .min = 18, .max = 26 },
  152. .m2 = { .min = 6, .max = 16 },
  153. .p = { .min = 4, .max = 128 },
  154. .p1 = { .min = 1, .max = 6 },
  155. .p2 = { .dot_limit = 165000,
  156. .p2_slow = 14, .p2_fast = 7 },
  157. };
  158. static const intel_limit_t intel_limits_i9xx_sdvo = {
  159. .dot = { .min = 20000, .max = 400000 },
  160. .vco = { .min = 1400000, .max = 2800000 },
  161. .n = { .min = 1, .max = 6 },
  162. .m = { .min = 70, .max = 120 },
  163. .m1 = { .min = 8, .max = 18 },
  164. .m2 = { .min = 3, .max = 7 },
  165. .p = { .min = 5, .max = 80 },
  166. .p1 = { .min = 1, .max = 8 },
  167. .p2 = { .dot_limit = 200000,
  168. .p2_slow = 10, .p2_fast = 5 },
  169. };
  170. static const intel_limit_t intel_limits_i9xx_lvds = {
  171. .dot = { .min = 20000, .max = 400000 },
  172. .vco = { .min = 1400000, .max = 2800000 },
  173. .n = { .min = 1, .max = 6 },
  174. .m = { .min = 70, .max = 120 },
  175. .m1 = { .min = 8, .max = 18 },
  176. .m2 = { .min = 3, .max = 7 },
  177. .p = { .min = 7, .max = 98 },
  178. .p1 = { .min = 1, .max = 8 },
  179. .p2 = { .dot_limit = 112000,
  180. .p2_slow = 14, .p2_fast = 7 },
  181. };
  182. static const intel_limit_t intel_limits_g4x_sdvo = {
  183. .dot = { .min = 25000, .max = 270000 },
  184. .vco = { .min = 1750000, .max = 3500000},
  185. .n = { .min = 1, .max = 4 },
  186. .m = { .min = 104, .max = 138 },
  187. .m1 = { .min = 17, .max = 23 },
  188. .m2 = { .min = 5, .max = 11 },
  189. .p = { .min = 10, .max = 30 },
  190. .p1 = { .min = 1, .max = 3},
  191. .p2 = { .dot_limit = 270000,
  192. .p2_slow = 10,
  193. .p2_fast = 10
  194. },
  195. };
  196. static const intel_limit_t intel_limits_g4x_hdmi = {
  197. .dot = { .min = 22000, .max = 400000 },
  198. .vco = { .min = 1750000, .max = 3500000},
  199. .n = { .min = 1, .max = 4 },
  200. .m = { .min = 104, .max = 138 },
  201. .m1 = { .min = 16, .max = 23 },
  202. .m2 = { .min = 5, .max = 11 },
  203. .p = { .min = 5, .max = 80 },
  204. .p1 = { .min = 1, .max = 8},
  205. .p2 = { .dot_limit = 165000,
  206. .p2_slow = 10, .p2_fast = 5 },
  207. };
  208. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  209. .dot = { .min = 20000, .max = 115000 },
  210. .vco = { .min = 1750000, .max = 3500000 },
  211. .n = { .min = 1, .max = 3 },
  212. .m = { .min = 104, .max = 138 },
  213. .m1 = { .min = 17, .max = 23 },
  214. .m2 = { .min = 5, .max = 11 },
  215. .p = { .min = 28, .max = 112 },
  216. .p1 = { .min = 2, .max = 8 },
  217. .p2 = { .dot_limit = 0,
  218. .p2_slow = 14, .p2_fast = 14
  219. },
  220. };
  221. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  222. .dot = { .min = 80000, .max = 224000 },
  223. .vco = { .min = 1750000, .max = 3500000 },
  224. .n = { .min = 1, .max = 3 },
  225. .m = { .min = 104, .max = 138 },
  226. .m1 = { .min = 17, .max = 23 },
  227. .m2 = { .min = 5, .max = 11 },
  228. .p = { .min = 14, .max = 42 },
  229. .p1 = { .min = 2, .max = 6 },
  230. .p2 = { .dot_limit = 0,
  231. .p2_slow = 7, .p2_fast = 7
  232. },
  233. };
  234. static const intel_limit_t intel_limits_pineview_sdvo = {
  235. .dot = { .min = 20000, .max = 400000},
  236. .vco = { .min = 1700000, .max = 3500000 },
  237. /* Pineview's Ncounter is a ring counter */
  238. .n = { .min = 3, .max = 6 },
  239. .m = { .min = 2, .max = 256 },
  240. /* Pineview only has one combined m divider, which we treat as m2. */
  241. .m1 = { .min = 0, .max = 0 },
  242. .m2 = { .min = 0, .max = 254 },
  243. .p = { .min = 5, .max = 80 },
  244. .p1 = { .min = 1, .max = 8 },
  245. .p2 = { .dot_limit = 200000,
  246. .p2_slow = 10, .p2_fast = 5 },
  247. };
  248. static const intel_limit_t intel_limits_pineview_lvds = {
  249. .dot = { .min = 20000, .max = 400000 },
  250. .vco = { .min = 1700000, .max = 3500000 },
  251. .n = { .min = 3, .max = 6 },
  252. .m = { .min = 2, .max = 256 },
  253. .m1 = { .min = 0, .max = 0 },
  254. .m2 = { .min = 0, .max = 254 },
  255. .p = { .min = 7, .max = 112 },
  256. .p1 = { .min = 1, .max = 8 },
  257. .p2 = { .dot_limit = 112000,
  258. .p2_slow = 14, .p2_fast = 14 },
  259. };
  260. /* Ironlake / Sandybridge
  261. *
  262. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  263. * the range value for them is (actual_value - 2).
  264. */
  265. static const intel_limit_t intel_limits_ironlake_dac = {
  266. .dot = { .min = 25000, .max = 350000 },
  267. .vco = { .min = 1760000, .max = 3510000 },
  268. .n = { .min = 1, .max = 5 },
  269. .m = { .min = 79, .max = 127 },
  270. .m1 = { .min = 12, .max = 22 },
  271. .m2 = { .min = 5, .max = 9 },
  272. .p = { .min = 5, .max = 80 },
  273. .p1 = { .min = 1, .max = 8 },
  274. .p2 = { .dot_limit = 225000,
  275. .p2_slow = 10, .p2_fast = 5 },
  276. };
  277. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  278. .dot = { .min = 25000, .max = 350000 },
  279. .vco = { .min = 1760000, .max = 3510000 },
  280. .n = { .min = 1, .max = 3 },
  281. .m = { .min = 79, .max = 118 },
  282. .m1 = { .min = 12, .max = 22 },
  283. .m2 = { .min = 5, .max = 9 },
  284. .p = { .min = 28, .max = 112 },
  285. .p1 = { .min = 2, .max = 8 },
  286. .p2 = { .dot_limit = 225000,
  287. .p2_slow = 14, .p2_fast = 14 },
  288. };
  289. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  290. .dot = { .min = 25000, .max = 350000 },
  291. .vco = { .min = 1760000, .max = 3510000 },
  292. .n = { .min = 1, .max = 3 },
  293. .m = { .min = 79, .max = 127 },
  294. .m1 = { .min = 12, .max = 22 },
  295. .m2 = { .min = 5, .max = 9 },
  296. .p = { .min = 14, .max = 56 },
  297. .p1 = { .min = 2, .max = 8 },
  298. .p2 = { .dot_limit = 225000,
  299. .p2_slow = 7, .p2_fast = 7 },
  300. };
  301. /* LVDS 100mhz refclk limits. */
  302. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  303. .dot = { .min = 25000, .max = 350000 },
  304. .vco = { .min = 1760000, .max = 3510000 },
  305. .n = { .min = 1, .max = 2 },
  306. .m = { .min = 79, .max = 126 },
  307. .m1 = { .min = 12, .max = 22 },
  308. .m2 = { .min = 5, .max = 9 },
  309. .p = { .min = 28, .max = 112 },
  310. .p1 = { .min = 2, .max = 8 },
  311. .p2 = { .dot_limit = 225000,
  312. .p2_slow = 14, .p2_fast = 14 },
  313. };
  314. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  315. .dot = { .min = 25000, .max = 350000 },
  316. .vco = { .min = 1760000, .max = 3510000 },
  317. .n = { .min = 1, .max = 3 },
  318. .m = { .min = 79, .max = 126 },
  319. .m1 = { .min = 12, .max = 22 },
  320. .m2 = { .min = 5, .max = 9 },
  321. .p = { .min = 14, .max = 42 },
  322. .p1 = { .min = 2, .max = 6 },
  323. .p2 = { .dot_limit = 225000,
  324. .p2_slow = 7, .p2_fast = 7 },
  325. };
  326. static const intel_limit_t intel_limits_vlv = {
  327. /*
  328. * These are the data rate limits (measured in fast clocks)
  329. * since those are the strictest limits we have. The fast
  330. * clock and actual rate limits are more relaxed, so checking
  331. * them would make no difference.
  332. */
  333. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  334. .vco = { .min = 4000000, .max = 6000000 },
  335. .n = { .min = 1, .max = 7 },
  336. .m1 = { .min = 2, .max = 3 },
  337. .m2 = { .min = 11, .max = 156 },
  338. .p1 = { .min = 2, .max = 3 },
  339. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  340. };
  341. static const intel_limit_t intel_limits_chv = {
  342. /*
  343. * These are the data rate limits (measured in fast clocks)
  344. * since those are the strictest limits we have. The fast
  345. * clock and actual rate limits are more relaxed, so checking
  346. * them would make no difference.
  347. */
  348. .dot = { .min = 25000 * 5, .max = 540000 * 5},
  349. .vco = { .min = 4860000, .max = 6700000 },
  350. .n = { .min = 1, .max = 1 },
  351. .m1 = { .min = 2, .max = 2 },
  352. .m2 = { .min = 24 << 22, .max = 175 << 22 },
  353. .p1 = { .min = 2, .max = 4 },
  354. .p2 = { .p2_slow = 1, .p2_fast = 14 },
  355. };
  356. static void vlv_clock(int refclk, intel_clock_t *clock)
  357. {
  358. clock->m = clock->m1 * clock->m2;
  359. clock->p = clock->p1 * clock->p2;
  360. if (WARN_ON(clock->n == 0 || clock->p == 0))
  361. return;
  362. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  363. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  364. }
  365. /**
  366. * Returns whether any output on the specified pipe is of the specified type
  367. */
  368. static bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  369. {
  370. struct drm_device *dev = crtc->dev;
  371. struct intel_encoder *encoder;
  372. for_each_encoder_on_crtc(dev, crtc, encoder)
  373. if (encoder->type == type)
  374. return true;
  375. return false;
  376. }
  377. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  378. int refclk)
  379. {
  380. struct drm_device *dev = crtc->dev;
  381. const intel_limit_t *limit;
  382. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  383. if (intel_is_dual_link_lvds(dev)) {
  384. if (refclk == 100000)
  385. limit = &intel_limits_ironlake_dual_lvds_100m;
  386. else
  387. limit = &intel_limits_ironlake_dual_lvds;
  388. } else {
  389. if (refclk == 100000)
  390. limit = &intel_limits_ironlake_single_lvds_100m;
  391. else
  392. limit = &intel_limits_ironlake_single_lvds;
  393. }
  394. } else
  395. limit = &intel_limits_ironlake_dac;
  396. return limit;
  397. }
  398. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  399. {
  400. struct drm_device *dev = crtc->dev;
  401. const intel_limit_t *limit;
  402. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  403. if (intel_is_dual_link_lvds(dev))
  404. limit = &intel_limits_g4x_dual_channel_lvds;
  405. else
  406. limit = &intel_limits_g4x_single_channel_lvds;
  407. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  408. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  409. limit = &intel_limits_g4x_hdmi;
  410. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  411. limit = &intel_limits_g4x_sdvo;
  412. } else /* The option is for other outputs */
  413. limit = &intel_limits_i9xx_sdvo;
  414. return limit;
  415. }
  416. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  417. {
  418. struct drm_device *dev = crtc->dev;
  419. const intel_limit_t *limit;
  420. if (HAS_PCH_SPLIT(dev))
  421. limit = intel_ironlake_limit(crtc, refclk);
  422. else if (IS_G4X(dev)) {
  423. limit = intel_g4x_limit(crtc);
  424. } else if (IS_PINEVIEW(dev)) {
  425. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  426. limit = &intel_limits_pineview_lvds;
  427. else
  428. limit = &intel_limits_pineview_sdvo;
  429. } else if (IS_CHERRYVIEW(dev)) {
  430. limit = &intel_limits_chv;
  431. } else if (IS_VALLEYVIEW(dev)) {
  432. limit = &intel_limits_vlv;
  433. } else if (!IS_GEN2(dev)) {
  434. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  435. limit = &intel_limits_i9xx_lvds;
  436. else
  437. limit = &intel_limits_i9xx_sdvo;
  438. } else {
  439. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  440. limit = &intel_limits_i8xx_lvds;
  441. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  442. limit = &intel_limits_i8xx_dvo;
  443. else
  444. limit = &intel_limits_i8xx_dac;
  445. }
  446. return limit;
  447. }
  448. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  449. static void pineview_clock(int refclk, intel_clock_t *clock)
  450. {
  451. clock->m = clock->m2 + 2;
  452. clock->p = clock->p1 * clock->p2;
  453. if (WARN_ON(clock->n == 0 || clock->p == 0))
  454. return;
  455. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  456. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  457. }
  458. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  459. {
  460. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  461. }
  462. static void i9xx_clock(int refclk, intel_clock_t *clock)
  463. {
  464. clock->m = i9xx_dpll_compute_m(clock);
  465. clock->p = clock->p1 * clock->p2;
  466. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  467. return;
  468. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  469. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  470. }
  471. static void chv_clock(int refclk, intel_clock_t *clock)
  472. {
  473. clock->m = clock->m1 * clock->m2;
  474. clock->p = clock->p1 * clock->p2;
  475. if (WARN_ON(clock->n == 0 || clock->p == 0))
  476. return;
  477. clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
  478. clock->n << 22);
  479. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  480. }
  481. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  482. /**
  483. * Returns whether the given set of divisors are valid for a given refclk with
  484. * the given connectors.
  485. */
  486. static bool intel_PLL_is_valid(struct drm_device *dev,
  487. const intel_limit_t *limit,
  488. const intel_clock_t *clock)
  489. {
  490. if (clock->n < limit->n.min || limit->n.max < clock->n)
  491. INTELPllInvalid("n out of range\n");
  492. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  493. INTELPllInvalid("p1 out of range\n");
  494. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  495. INTELPllInvalid("m2 out of range\n");
  496. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  497. INTELPllInvalid("m1 out of range\n");
  498. if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev))
  499. if (clock->m1 <= clock->m2)
  500. INTELPllInvalid("m1 <= m2\n");
  501. if (!IS_VALLEYVIEW(dev)) {
  502. if (clock->p < limit->p.min || limit->p.max < clock->p)
  503. INTELPllInvalid("p out of range\n");
  504. if (clock->m < limit->m.min || limit->m.max < clock->m)
  505. INTELPllInvalid("m out of range\n");
  506. }
  507. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  508. INTELPllInvalid("vco out of range\n");
  509. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  510. * connector, etc., rather than just a single range.
  511. */
  512. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  513. INTELPllInvalid("dot out of range\n");
  514. return true;
  515. }
  516. static bool
  517. i9xx_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  518. int target, int refclk, intel_clock_t *match_clock,
  519. intel_clock_t *best_clock)
  520. {
  521. struct drm_device *dev = crtc->dev;
  522. intel_clock_t clock;
  523. int err = target;
  524. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  525. /*
  526. * For LVDS just rely on its current settings for dual-channel.
  527. * We haven't figured out how to reliably set up different
  528. * single/dual channel state, if we even can.
  529. */
  530. if (intel_is_dual_link_lvds(dev))
  531. clock.p2 = limit->p2.p2_fast;
  532. else
  533. clock.p2 = limit->p2.p2_slow;
  534. } else {
  535. if (target < limit->p2.dot_limit)
  536. clock.p2 = limit->p2.p2_slow;
  537. else
  538. clock.p2 = limit->p2.p2_fast;
  539. }
  540. memset(best_clock, 0, sizeof(*best_clock));
  541. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  542. clock.m1++) {
  543. for (clock.m2 = limit->m2.min;
  544. clock.m2 <= limit->m2.max; clock.m2++) {
  545. if (clock.m2 >= clock.m1)
  546. break;
  547. for (clock.n = limit->n.min;
  548. clock.n <= limit->n.max; clock.n++) {
  549. for (clock.p1 = limit->p1.min;
  550. clock.p1 <= limit->p1.max; clock.p1++) {
  551. int this_err;
  552. i9xx_clock(refclk, &clock);
  553. if (!intel_PLL_is_valid(dev, limit,
  554. &clock))
  555. continue;
  556. if (match_clock &&
  557. clock.p != match_clock->p)
  558. continue;
  559. this_err = abs(clock.dot - target);
  560. if (this_err < err) {
  561. *best_clock = clock;
  562. err = this_err;
  563. }
  564. }
  565. }
  566. }
  567. }
  568. return (err != target);
  569. }
  570. static bool
  571. pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  572. int target, int refclk, intel_clock_t *match_clock,
  573. intel_clock_t *best_clock)
  574. {
  575. struct drm_device *dev = crtc->dev;
  576. intel_clock_t clock;
  577. int err = target;
  578. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  579. /*
  580. * For LVDS just rely on its current settings for dual-channel.
  581. * We haven't figured out how to reliably set up different
  582. * single/dual channel state, if we even can.
  583. */
  584. if (intel_is_dual_link_lvds(dev))
  585. clock.p2 = limit->p2.p2_fast;
  586. else
  587. clock.p2 = limit->p2.p2_slow;
  588. } else {
  589. if (target < limit->p2.dot_limit)
  590. clock.p2 = limit->p2.p2_slow;
  591. else
  592. clock.p2 = limit->p2.p2_fast;
  593. }
  594. memset(best_clock, 0, sizeof(*best_clock));
  595. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  596. clock.m1++) {
  597. for (clock.m2 = limit->m2.min;
  598. clock.m2 <= limit->m2.max; clock.m2++) {
  599. for (clock.n = limit->n.min;
  600. clock.n <= limit->n.max; clock.n++) {
  601. for (clock.p1 = limit->p1.min;
  602. clock.p1 <= limit->p1.max; clock.p1++) {
  603. int this_err;
  604. pineview_clock(refclk, &clock);
  605. if (!intel_PLL_is_valid(dev, limit,
  606. &clock))
  607. continue;
  608. if (match_clock &&
  609. clock.p != match_clock->p)
  610. continue;
  611. this_err = abs(clock.dot - target);
  612. if (this_err < err) {
  613. *best_clock = clock;
  614. err = this_err;
  615. }
  616. }
  617. }
  618. }
  619. }
  620. return (err != target);
  621. }
  622. static bool
  623. g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  624. int target, int refclk, intel_clock_t *match_clock,
  625. intel_clock_t *best_clock)
  626. {
  627. struct drm_device *dev = crtc->dev;
  628. intel_clock_t clock;
  629. int max_n;
  630. bool found;
  631. /* approximately equals target * 0.00585 */
  632. int err_most = (target >> 8) + (target >> 9);
  633. found = false;
  634. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  635. if (intel_is_dual_link_lvds(dev))
  636. clock.p2 = limit->p2.p2_fast;
  637. else
  638. clock.p2 = limit->p2.p2_slow;
  639. } else {
  640. if (target < limit->p2.dot_limit)
  641. clock.p2 = limit->p2.p2_slow;
  642. else
  643. clock.p2 = limit->p2.p2_fast;
  644. }
  645. memset(best_clock, 0, sizeof(*best_clock));
  646. max_n = limit->n.max;
  647. /* based on hardware requirement, prefer smaller n to precision */
  648. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  649. /* based on hardware requirement, prefere larger m1,m2 */
  650. for (clock.m1 = limit->m1.max;
  651. clock.m1 >= limit->m1.min; clock.m1--) {
  652. for (clock.m2 = limit->m2.max;
  653. clock.m2 >= limit->m2.min; clock.m2--) {
  654. for (clock.p1 = limit->p1.max;
  655. clock.p1 >= limit->p1.min; clock.p1--) {
  656. int this_err;
  657. i9xx_clock(refclk, &clock);
  658. if (!intel_PLL_is_valid(dev, limit,
  659. &clock))
  660. continue;
  661. this_err = abs(clock.dot - target);
  662. if (this_err < err_most) {
  663. *best_clock = clock;
  664. err_most = this_err;
  665. max_n = clock.n;
  666. found = true;
  667. }
  668. }
  669. }
  670. }
  671. }
  672. return found;
  673. }
  674. static bool
  675. vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  676. int target, int refclk, intel_clock_t *match_clock,
  677. intel_clock_t *best_clock)
  678. {
  679. struct drm_device *dev = crtc->dev;
  680. intel_clock_t clock;
  681. unsigned int bestppm = 1000000;
  682. /* min update 19.2 MHz */
  683. int max_n = min(limit->n.max, refclk / 19200);
  684. bool found = false;
  685. target *= 5; /* fast clock */
  686. memset(best_clock, 0, sizeof(*best_clock));
  687. /* based on hardware requirement, prefer smaller n to precision */
  688. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  689. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  690. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  691. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  692. clock.p = clock.p1 * clock.p2;
  693. /* based on hardware requirement, prefer bigger m1,m2 values */
  694. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  695. unsigned int ppm, diff;
  696. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  697. refclk * clock.m1);
  698. vlv_clock(refclk, &clock);
  699. if (!intel_PLL_is_valid(dev, limit,
  700. &clock))
  701. continue;
  702. diff = abs(clock.dot - target);
  703. ppm = div_u64(1000000ULL * diff, target);
  704. if (ppm < 100 && clock.p > best_clock->p) {
  705. bestppm = 0;
  706. *best_clock = clock;
  707. found = true;
  708. }
  709. if (bestppm >= 10 && ppm < bestppm - 10) {
  710. bestppm = ppm;
  711. *best_clock = clock;
  712. found = true;
  713. }
  714. }
  715. }
  716. }
  717. }
  718. return found;
  719. }
  720. static bool
  721. chv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  722. int target, int refclk, intel_clock_t *match_clock,
  723. intel_clock_t *best_clock)
  724. {
  725. struct drm_device *dev = crtc->dev;
  726. intel_clock_t clock;
  727. uint64_t m2;
  728. int found = false;
  729. memset(best_clock, 0, sizeof(*best_clock));
  730. /*
  731. * Based on hardware doc, the n always set to 1, and m1 always
  732. * set to 2. If requires to support 200Mhz refclk, we need to
  733. * revisit this because n may not 1 anymore.
  734. */
  735. clock.n = 1, clock.m1 = 2;
  736. target *= 5; /* fast clock */
  737. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  738. for (clock.p2 = limit->p2.p2_fast;
  739. clock.p2 >= limit->p2.p2_slow;
  740. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  741. clock.p = clock.p1 * clock.p2;
  742. m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
  743. clock.n) << 22, refclk * clock.m1);
  744. if (m2 > INT_MAX/clock.m1)
  745. continue;
  746. clock.m2 = m2;
  747. chv_clock(refclk, &clock);
  748. if (!intel_PLL_is_valid(dev, limit, &clock))
  749. continue;
  750. /* based on hardware requirement, prefer bigger p
  751. */
  752. if (clock.p > best_clock->p) {
  753. *best_clock = clock;
  754. found = true;
  755. }
  756. }
  757. }
  758. return found;
  759. }
  760. bool intel_crtc_active(struct drm_crtc *crtc)
  761. {
  762. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  763. /* Be paranoid as we can arrive here with only partial
  764. * state retrieved from the hardware during setup.
  765. *
  766. * We can ditch the adjusted_mode.crtc_clock check as soon
  767. * as Haswell has gained clock readout/fastboot support.
  768. *
  769. * We can ditch the crtc->primary->fb check as soon as we can
  770. * properly reconstruct framebuffers.
  771. */
  772. return intel_crtc->active && crtc->primary->fb &&
  773. intel_crtc->config.adjusted_mode.crtc_clock;
  774. }
  775. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  776. enum pipe pipe)
  777. {
  778. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  779. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  780. return intel_crtc->config.cpu_transcoder;
  781. }
  782. static void g4x_wait_for_vblank(struct drm_device *dev, int pipe)
  783. {
  784. struct drm_i915_private *dev_priv = dev->dev_private;
  785. u32 frame, frame_reg = PIPE_FRMCOUNT_GM45(pipe);
  786. frame = I915_READ(frame_reg);
  787. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  788. WARN(1, "vblank wait timed out\n");
  789. }
  790. /**
  791. * intel_wait_for_vblank - wait for vblank on a given pipe
  792. * @dev: drm device
  793. * @pipe: pipe to wait for
  794. *
  795. * Wait for vblank to occur on a given pipe. Needed for various bits of
  796. * mode setting code.
  797. */
  798. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  799. {
  800. struct drm_i915_private *dev_priv = dev->dev_private;
  801. int pipestat_reg = PIPESTAT(pipe);
  802. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  803. g4x_wait_for_vblank(dev, pipe);
  804. return;
  805. }
  806. /* Clear existing vblank status. Note this will clear any other
  807. * sticky status fields as well.
  808. *
  809. * This races with i915_driver_irq_handler() with the result
  810. * that either function could miss a vblank event. Here it is not
  811. * fatal, as we will either wait upon the next vblank interrupt or
  812. * timeout. Generally speaking intel_wait_for_vblank() is only
  813. * called during modeset at which time the GPU should be idle and
  814. * should *not* be performing page flips and thus not waiting on
  815. * vblanks...
  816. * Currently, the result of us stealing a vblank from the irq
  817. * handler is that a single frame will be skipped during swapbuffers.
  818. */
  819. I915_WRITE(pipestat_reg,
  820. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  821. /* Wait for vblank interrupt bit to set */
  822. if (wait_for(I915_READ(pipestat_reg) &
  823. PIPE_VBLANK_INTERRUPT_STATUS,
  824. 50))
  825. DRM_DEBUG_KMS("vblank wait timed out\n");
  826. }
  827. static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
  828. {
  829. struct drm_i915_private *dev_priv = dev->dev_private;
  830. u32 reg = PIPEDSL(pipe);
  831. u32 line1, line2;
  832. u32 line_mask;
  833. if (IS_GEN2(dev))
  834. line_mask = DSL_LINEMASK_GEN2;
  835. else
  836. line_mask = DSL_LINEMASK_GEN3;
  837. line1 = I915_READ(reg) & line_mask;
  838. mdelay(5);
  839. line2 = I915_READ(reg) & line_mask;
  840. return line1 == line2;
  841. }
  842. /*
  843. * intel_wait_for_pipe_off - wait for pipe to turn off
  844. * @dev: drm device
  845. * @pipe: pipe to wait for
  846. *
  847. * After disabling a pipe, we can't wait for vblank in the usual way,
  848. * spinning on the vblank interrupt status bit, since we won't actually
  849. * see an interrupt when the pipe is disabled.
  850. *
  851. * On Gen4 and above:
  852. * wait for the pipe register state bit to turn off
  853. *
  854. * Otherwise:
  855. * wait for the display line value to settle (it usually
  856. * ends up stopping at the start of the next frame).
  857. *
  858. */
  859. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  860. {
  861. struct drm_i915_private *dev_priv = dev->dev_private;
  862. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  863. pipe);
  864. if (INTEL_INFO(dev)->gen >= 4) {
  865. int reg = PIPECONF(cpu_transcoder);
  866. /* Wait for the Pipe State to go off */
  867. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  868. 100))
  869. WARN(1, "pipe_off wait timed out\n");
  870. } else {
  871. /* Wait for the display line to settle */
  872. if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
  873. WARN(1, "pipe_off wait timed out\n");
  874. }
  875. }
  876. /*
  877. * ibx_digital_port_connected - is the specified port connected?
  878. * @dev_priv: i915 private structure
  879. * @port: the port to test
  880. *
  881. * Returns true if @port is connected, false otherwise.
  882. */
  883. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  884. struct intel_digital_port *port)
  885. {
  886. u32 bit;
  887. if (HAS_PCH_IBX(dev_priv->dev)) {
  888. switch (port->port) {
  889. case PORT_B:
  890. bit = SDE_PORTB_HOTPLUG;
  891. break;
  892. case PORT_C:
  893. bit = SDE_PORTC_HOTPLUG;
  894. break;
  895. case PORT_D:
  896. bit = SDE_PORTD_HOTPLUG;
  897. break;
  898. default:
  899. return true;
  900. }
  901. } else {
  902. switch (port->port) {
  903. case PORT_B:
  904. bit = SDE_PORTB_HOTPLUG_CPT;
  905. break;
  906. case PORT_C:
  907. bit = SDE_PORTC_HOTPLUG_CPT;
  908. break;
  909. case PORT_D:
  910. bit = SDE_PORTD_HOTPLUG_CPT;
  911. break;
  912. default:
  913. return true;
  914. }
  915. }
  916. return I915_READ(SDEISR) & bit;
  917. }
  918. static const char *state_string(bool enabled)
  919. {
  920. return enabled ? "on" : "off";
  921. }
  922. /* Only for pre-ILK configs */
  923. void assert_pll(struct drm_i915_private *dev_priv,
  924. enum pipe pipe, bool state)
  925. {
  926. int reg;
  927. u32 val;
  928. bool cur_state;
  929. reg = DPLL(pipe);
  930. val = I915_READ(reg);
  931. cur_state = !!(val & DPLL_VCO_ENABLE);
  932. WARN(cur_state != state,
  933. "PLL state assertion failure (expected %s, current %s)\n",
  934. state_string(state), state_string(cur_state));
  935. }
  936. /* XXX: the dsi pll is shared between MIPI DSI ports */
  937. static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  938. {
  939. u32 val;
  940. bool cur_state;
  941. mutex_lock(&dev_priv->dpio_lock);
  942. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  943. mutex_unlock(&dev_priv->dpio_lock);
  944. cur_state = val & DSI_PLL_VCO_EN;
  945. WARN(cur_state != state,
  946. "DSI PLL state assertion failure (expected %s, current %s)\n",
  947. state_string(state), state_string(cur_state));
  948. }
  949. #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
  950. #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
  951. struct intel_shared_dpll *
  952. intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
  953. {
  954. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  955. if (crtc->config.shared_dpll < 0)
  956. return NULL;
  957. return &dev_priv->shared_dplls[crtc->config.shared_dpll];
  958. }
  959. /* For ILK+ */
  960. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  961. struct intel_shared_dpll *pll,
  962. bool state)
  963. {
  964. bool cur_state;
  965. struct intel_dpll_hw_state hw_state;
  966. if (HAS_PCH_LPT(dev_priv->dev)) {
  967. DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
  968. return;
  969. }
  970. if (WARN (!pll,
  971. "asserting DPLL %s with no DPLL\n", state_string(state)))
  972. return;
  973. cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
  974. WARN(cur_state != state,
  975. "%s assertion failure (expected %s, current %s)\n",
  976. pll->name, state_string(state), state_string(cur_state));
  977. }
  978. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  979. enum pipe pipe, bool state)
  980. {
  981. int reg;
  982. u32 val;
  983. bool cur_state;
  984. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  985. pipe);
  986. if (HAS_DDI(dev_priv->dev)) {
  987. /* DDI does not have a specific FDI_TX register */
  988. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  989. val = I915_READ(reg);
  990. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  991. } else {
  992. reg = FDI_TX_CTL(pipe);
  993. val = I915_READ(reg);
  994. cur_state = !!(val & FDI_TX_ENABLE);
  995. }
  996. WARN(cur_state != state,
  997. "FDI TX state assertion failure (expected %s, current %s)\n",
  998. state_string(state), state_string(cur_state));
  999. }
  1000. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1001. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1002. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1003. enum pipe pipe, bool state)
  1004. {
  1005. int reg;
  1006. u32 val;
  1007. bool cur_state;
  1008. reg = FDI_RX_CTL(pipe);
  1009. val = I915_READ(reg);
  1010. cur_state = !!(val & FDI_RX_ENABLE);
  1011. WARN(cur_state != state,
  1012. "FDI RX state assertion failure (expected %s, current %s)\n",
  1013. state_string(state), state_string(cur_state));
  1014. }
  1015. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1016. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1017. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1018. enum pipe pipe)
  1019. {
  1020. int reg;
  1021. u32 val;
  1022. /* ILK FDI PLL is always enabled */
  1023. if (INTEL_INFO(dev_priv->dev)->gen == 5)
  1024. return;
  1025. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1026. if (HAS_DDI(dev_priv->dev))
  1027. return;
  1028. reg = FDI_TX_CTL(pipe);
  1029. val = I915_READ(reg);
  1030. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1031. }
  1032. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  1033. enum pipe pipe, bool state)
  1034. {
  1035. int reg;
  1036. u32 val;
  1037. bool cur_state;
  1038. reg = FDI_RX_CTL(pipe);
  1039. val = I915_READ(reg);
  1040. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  1041. WARN(cur_state != state,
  1042. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  1043. state_string(state), state_string(cur_state));
  1044. }
  1045. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1046. enum pipe pipe)
  1047. {
  1048. int pp_reg, lvds_reg;
  1049. u32 val;
  1050. enum pipe panel_pipe = PIPE_A;
  1051. bool locked = true;
  1052. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1053. pp_reg = PCH_PP_CONTROL;
  1054. lvds_reg = PCH_LVDS;
  1055. } else {
  1056. pp_reg = PP_CONTROL;
  1057. lvds_reg = LVDS;
  1058. }
  1059. val = I915_READ(pp_reg);
  1060. if (!(val & PANEL_POWER_ON) ||
  1061. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  1062. locked = false;
  1063. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  1064. panel_pipe = PIPE_B;
  1065. WARN(panel_pipe == pipe && locked,
  1066. "panel assertion failure, pipe %c regs locked\n",
  1067. pipe_name(pipe));
  1068. }
  1069. static void assert_cursor(struct drm_i915_private *dev_priv,
  1070. enum pipe pipe, bool state)
  1071. {
  1072. struct drm_device *dev = dev_priv->dev;
  1073. bool cur_state;
  1074. if (IS_845G(dev) || IS_I865G(dev))
  1075. cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
  1076. else
  1077. cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  1078. WARN(cur_state != state,
  1079. "cursor on pipe %c assertion failure (expected %s, current %s)\n",
  1080. pipe_name(pipe), state_string(state), state_string(cur_state));
  1081. }
  1082. #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
  1083. #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
  1084. void assert_pipe(struct drm_i915_private *dev_priv,
  1085. enum pipe pipe, bool state)
  1086. {
  1087. int reg;
  1088. u32 val;
  1089. bool cur_state;
  1090. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1091. pipe);
  1092. /* if we need the pipe A quirk it must be always on */
  1093. if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  1094. state = true;
  1095. if (!intel_display_power_enabled(dev_priv,
  1096. POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
  1097. cur_state = false;
  1098. } else {
  1099. reg = PIPECONF(cpu_transcoder);
  1100. val = I915_READ(reg);
  1101. cur_state = !!(val & PIPECONF_ENABLE);
  1102. }
  1103. WARN(cur_state != state,
  1104. "pipe %c assertion failure (expected %s, current %s)\n",
  1105. pipe_name(pipe), state_string(state), state_string(cur_state));
  1106. }
  1107. static void assert_plane(struct drm_i915_private *dev_priv,
  1108. enum plane plane, bool state)
  1109. {
  1110. int reg;
  1111. u32 val;
  1112. bool cur_state;
  1113. reg = DSPCNTR(plane);
  1114. val = I915_READ(reg);
  1115. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1116. WARN(cur_state != state,
  1117. "plane %c assertion failure (expected %s, current %s)\n",
  1118. plane_name(plane), state_string(state), state_string(cur_state));
  1119. }
  1120. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1121. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1122. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1123. enum pipe pipe)
  1124. {
  1125. struct drm_device *dev = dev_priv->dev;
  1126. int reg, i;
  1127. u32 val;
  1128. int cur_pipe;
  1129. /* Primary planes are fixed to pipes on gen4+ */
  1130. if (INTEL_INFO(dev)->gen >= 4) {
  1131. reg = DSPCNTR(pipe);
  1132. val = I915_READ(reg);
  1133. WARN(val & DISPLAY_PLANE_ENABLE,
  1134. "plane %c assertion failure, should be disabled but not\n",
  1135. plane_name(pipe));
  1136. return;
  1137. }
  1138. /* Need to check both planes against the pipe */
  1139. for_each_pipe(i) {
  1140. reg = DSPCNTR(i);
  1141. val = I915_READ(reg);
  1142. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1143. DISPPLANE_SEL_PIPE_SHIFT;
  1144. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1145. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1146. plane_name(i), pipe_name(pipe));
  1147. }
  1148. }
  1149. static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
  1150. enum pipe pipe)
  1151. {
  1152. struct drm_device *dev = dev_priv->dev;
  1153. int reg, sprite;
  1154. u32 val;
  1155. if (IS_VALLEYVIEW(dev)) {
  1156. for_each_sprite(pipe, sprite) {
  1157. reg = SPCNTR(pipe, sprite);
  1158. val = I915_READ(reg);
  1159. WARN(val & SP_ENABLE,
  1160. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1161. sprite_name(pipe, sprite), pipe_name(pipe));
  1162. }
  1163. } else if (INTEL_INFO(dev)->gen >= 7) {
  1164. reg = SPRCTL(pipe);
  1165. val = I915_READ(reg);
  1166. WARN(val & SPRITE_ENABLE,
  1167. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1168. plane_name(pipe), pipe_name(pipe));
  1169. } else if (INTEL_INFO(dev)->gen >= 5) {
  1170. reg = DVSCNTR(pipe);
  1171. val = I915_READ(reg);
  1172. WARN(val & DVS_ENABLE,
  1173. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1174. plane_name(pipe), pipe_name(pipe));
  1175. }
  1176. }
  1177. static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1178. {
  1179. u32 val;
  1180. bool enabled;
  1181. WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
  1182. val = I915_READ(PCH_DREF_CONTROL);
  1183. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1184. DREF_SUPERSPREAD_SOURCE_MASK));
  1185. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1186. }
  1187. static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1188. enum pipe pipe)
  1189. {
  1190. int reg;
  1191. u32 val;
  1192. bool enabled;
  1193. reg = PCH_TRANSCONF(pipe);
  1194. val = I915_READ(reg);
  1195. enabled = !!(val & TRANS_ENABLE);
  1196. WARN(enabled,
  1197. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1198. pipe_name(pipe));
  1199. }
  1200. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1201. enum pipe pipe, u32 port_sel, u32 val)
  1202. {
  1203. if ((val & DP_PORT_EN) == 0)
  1204. return false;
  1205. if (HAS_PCH_CPT(dev_priv->dev)) {
  1206. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1207. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1208. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1209. return false;
  1210. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1211. if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
  1212. return false;
  1213. } else {
  1214. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1215. return false;
  1216. }
  1217. return true;
  1218. }
  1219. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1220. enum pipe pipe, u32 val)
  1221. {
  1222. if ((val & SDVO_ENABLE) == 0)
  1223. return false;
  1224. if (HAS_PCH_CPT(dev_priv->dev)) {
  1225. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1226. return false;
  1227. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1228. if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
  1229. return false;
  1230. } else {
  1231. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1232. return false;
  1233. }
  1234. return true;
  1235. }
  1236. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1237. enum pipe pipe, u32 val)
  1238. {
  1239. if ((val & LVDS_PORT_EN) == 0)
  1240. return false;
  1241. if (HAS_PCH_CPT(dev_priv->dev)) {
  1242. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1243. return false;
  1244. } else {
  1245. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1246. return false;
  1247. }
  1248. return true;
  1249. }
  1250. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1251. enum pipe pipe, u32 val)
  1252. {
  1253. if ((val & ADPA_DAC_ENABLE) == 0)
  1254. return false;
  1255. if (HAS_PCH_CPT(dev_priv->dev)) {
  1256. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1257. return false;
  1258. } else {
  1259. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1260. return false;
  1261. }
  1262. return true;
  1263. }
  1264. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1265. enum pipe pipe, int reg, u32 port_sel)
  1266. {
  1267. u32 val = I915_READ(reg);
  1268. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1269. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1270. reg, pipe_name(pipe));
  1271. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1272. && (val & DP_PIPEB_SELECT),
  1273. "IBX PCH dp port still using transcoder B\n");
  1274. }
  1275. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1276. enum pipe pipe, int reg)
  1277. {
  1278. u32 val = I915_READ(reg);
  1279. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1280. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1281. reg, pipe_name(pipe));
  1282. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
  1283. && (val & SDVO_PIPE_B_SELECT),
  1284. "IBX PCH hdmi port still using transcoder B\n");
  1285. }
  1286. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1287. enum pipe pipe)
  1288. {
  1289. int reg;
  1290. u32 val;
  1291. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1292. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1293. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1294. reg = PCH_ADPA;
  1295. val = I915_READ(reg);
  1296. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1297. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1298. pipe_name(pipe));
  1299. reg = PCH_LVDS;
  1300. val = I915_READ(reg);
  1301. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1302. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1303. pipe_name(pipe));
  1304. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1305. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1306. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1307. }
  1308. static void intel_init_dpio(struct drm_device *dev)
  1309. {
  1310. struct drm_i915_private *dev_priv = dev->dev_private;
  1311. if (!IS_VALLEYVIEW(dev))
  1312. return;
  1313. /*
  1314. * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
  1315. * CHV x1 PHY (DP/HDMI D)
  1316. * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
  1317. */
  1318. if (IS_CHERRYVIEW(dev)) {
  1319. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
  1320. DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
  1321. } else {
  1322. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  1323. }
  1324. }
  1325. static void intel_reset_dpio(struct drm_device *dev)
  1326. {
  1327. struct drm_i915_private *dev_priv = dev->dev_private;
  1328. if (!IS_VALLEYVIEW(dev))
  1329. return;
  1330. if (IS_CHERRYVIEW(dev)) {
  1331. enum dpio_phy phy;
  1332. u32 val;
  1333. for (phy = DPIO_PHY0; phy < I915_NUM_PHYS_VLV; phy++) {
  1334. /* Poll for phypwrgood signal */
  1335. if (wait_for(I915_READ(DISPLAY_PHY_STATUS) &
  1336. PHY_POWERGOOD(phy), 1))
  1337. DRM_ERROR("Display PHY %d is not power up\n", phy);
  1338. /*
  1339. * Deassert common lane reset for PHY.
  1340. *
  1341. * This should only be done on init and resume from S3
  1342. * with both PLLs disabled, or we risk losing DPIO and
  1343. * PLL synchronization.
  1344. */
  1345. val = I915_READ(DISPLAY_PHY_CONTROL);
  1346. I915_WRITE(DISPLAY_PHY_CONTROL,
  1347. PHY_COM_LANE_RESET_DEASSERT(phy, val));
  1348. }
  1349. } else {
  1350. /*
  1351. * If DPIO has already been reset, e.g. by BIOS, just skip all
  1352. * this.
  1353. */
  1354. if (I915_READ(DPIO_CTL) & DPIO_CMNRST)
  1355. return;
  1356. /*
  1357. * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
  1358. * Need to assert and de-assert PHY SB reset by gating the
  1359. * common lane power, then un-gating it.
  1360. * Simply ungating isn't enough to reset the PHY enough to get
  1361. * ports and lanes running.
  1362. */
  1363. __vlv_set_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC,
  1364. false);
  1365. __vlv_set_power_well(dev_priv, PUNIT_POWER_WELL_DPIO_CMN_BC,
  1366. true);
  1367. }
  1368. }
  1369. static void vlv_enable_pll(struct intel_crtc *crtc)
  1370. {
  1371. struct drm_device *dev = crtc->base.dev;
  1372. struct drm_i915_private *dev_priv = dev->dev_private;
  1373. int reg = DPLL(crtc->pipe);
  1374. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1375. assert_pipe_disabled(dev_priv, crtc->pipe);
  1376. /* No really, not for ILK+ */
  1377. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1378. /* PLL is protected by panel, make sure we can write it */
  1379. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1380. assert_panel_unlocked(dev_priv, crtc->pipe);
  1381. I915_WRITE(reg, dpll);
  1382. POSTING_READ(reg);
  1383. udelay(150);
  1384. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1385. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1386. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1387. POSTING_READ(DPLL_MD(crtc->pipe));
  1388. /* We do this three times for luck */
  1389. I915_WRITE(reg, dpll);
  1390. POSTING_READ(reg);
  1391. udelay(150); /* wait for warmup */
  1392. I915_WRITE(reg, dpll);
  1393. POSTING_READ(reg);
  1394. udelay(150); /* wait for warmup */
  1395. I915_WRITE(reg, dpll);
  1396. POSTING_READ(reg);
  1397. udelay(150); /* wait for warmup */
  1398. }
  1399. static void chv_enable_pll(struct intel_crtc *crtc)
  1400. {
  1401. struct drm_device *dev = crtc->base.dev;
  1402. struct drm_i915_private *dev_priv = dev->dev_private;
  1403. int pipe = crtc->pipe;
  1404. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1405. u32 tmp;
  1406. assert_pipe_disabled(dev_priv, crtc->pipe);
  1407. BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
  1408. mutex_lock(&dev_priv->dpio_lock);
  1409. /* Enable back the 10bit clock to display controller */
  1410. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1411. tmp |= DPIO_DCLKP_EN;
  1412. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1413. /*
  1414. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1415. */
  1416. udelay(1);
  1417. /* Enable PLL */
  1418. I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll);
  1419. /* Check PLL is locked */
  1420. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1421. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1422. /* not sure when this should be written */
  1423. I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md);
  1424. POSTING_READ(DPLL_MD(pipe));
  1425. mutex_unlock(&dev_priv->dpio_lock);
  1426. }
  1427. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1428. {
  1429. struct drm_device *dev = crtc->base.dev;
  1430. struct drm_i915_private *dev_priv = dev->dev_private;
  1431. int reg = DPLL(crtc->pipe);
  1432. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1433. assert_pipe_disabled(dev_priv, crtc->pipe);
  1434. /* No really, not for ILK+ */
  1435. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1436. /* PLL is protected by panel, make sure we can write it */
  1437. if (IS_MOBILE(dev) && !IS_I830(dev))
  1438. assert_panel_unlocked(dev_priv, crtc->pipe);
  1439. I915_WRITE(reg, dpll);
  1440. /* Wait for the clocks to stabilize. */
  1441. POSTING_READ(reg);
  1442. udelay(150);
  1443. if (INTEL_INFO(dev)->gen >= 4) {
  1444. I915_WRITE(DPLL_MD(crtc->pipe),
  1445. crtc->config.dpll_hw_state.dpll_md);
  1446. } else {
  1447. /* The pixel multiplier can only be updated once the
  1448. * DPLL is enabled and the clocks are stable.
  1449. *
  1450. * So write it again.
  1451. */
  1452. I915_WRITE(reg, dpll);
  1453. }
  1454. /* We do this three times for luck */
  1455. I915_WRITE(reg, dpll);
  1456. POSTING_READ(reg);
  1457. udelay(150); /* wait for warmup */
  1458. I915_WRITE(reg, dpll);
  1459. POSTING_READ(reg);
  1460. udelay(150); /* wait for warmup */
  1461. I915_WRITE(reg, dpll);
  1462. POSTING_READ(reg);
  1463. udelay(150); /* wait for warmup */
  1464. }
  1465. /**
  1466. * i9xx_disable_pll - disable a PLL
  1467. * @dev_priv: i915 private structure
  1468. * @pipe: pipe PLL to disable
  1469. *
  1470. * Disable the PLL for @pipe, making sure the pipe is off first.
  1471. *
  1472. * Note! This is for pre-ILK only.
  1473. */
  1474. static void i9xx_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1475. {
  1476. /* Don't disable pipe A or pipe A PLLs if needed */
  1477. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1478. return;
  1479. /* Make sure the pipe isn't still relying on us */
  1480. assert_pipe_disabled(dev_priv, pipe);
  1481. I915_WRITE(DPLL(pipe), 0);
  1482. POSTING_READ(DPLL(pipe));
  1483. }
  1484. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1485. {
  1486. u32 val = 0;
  1487. /* Make sure the pipe isn't still relying on us */
  1488. assert_pipe_disabled(dev_priv, pipe);
  1489. /*
  1490. * Leave integrated clock source and reference clock enabled for pipe B.
  1491. * The latter is needed for VGA hotplug / manual detection.
  1492. */
  1493. if (pipe == PIPE_B)
  1494. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1495. I915_WRITE(DPLL(pipe), val);
  1496. POSTING_READ(DPLL(pipe));
  1497. }
  1498. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1499. {
  1500. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1501. u32 val;
  1502. /* Make sure the pipe isn't still relying on us */
  1503. assert_pipe_disabled(dev_priv, pipe);
  1504. /* Set PLL en = 0 */
  1505. val = DPLL_SSC_REF_CLOCK_CHV;
  1506. if (pipe != PIPE_A)
  1507. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1508. I915_WRITE(DPLL(pipe), val);
  1509. POSTING_READ(DPLL(pipe));
  1510. mutex_lock(&dev_priv->dpio_lock);
  1511. /* Disable 10bit clock to display controller */
  1512. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1513. val &= ~DPIO_DCLKP_EN;
  1514. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1515. /* disable left/right clock distribution */
  1516. if (pipe != PIPE_B) {
  1517. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1518. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1519. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1520. } else {
  1521. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1522. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1523. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1524. }
  1525. mutex_unlock(&dev_priv->dpio_lock);
  1526. }
  1527. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1528. struct intel_digital_port *dport)
  1529. {
  1530. u32 port_mask;
  1531. int dpll_reg;
  1532. switch (dport->port) {
  1533. case PORT_B:
  1534. port_mask = DPLL_PORTB_READY_MASK;
  1535. dpll_reg = DPLL(0);
  1536. break;
  1537. case PORT_C:
  1538. port_mask = DPLL_PORTC_READY_MASK;
  1539. dpll_reg = DPLL(0);
  1540. break;
  1541. case PORT_D:
  1542. port_mask = DPLL_PORTD_READY_MASK;
  1543. dpll_reg = DPIO_PHY_STATUS;
  1544. break;
  1545. default:
  1546. BUG();
  1547. }
  1548. if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000))
  1549. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1550. port_name(dport->port), I915_READ(dpll_reg));
  1551. }
  1552. static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
  1553. {
  1554. struct drm_device *dev = crtc->base.dev;
  1555. struct drm_i915_private *dev_priv = dev->dev_private;
  1556. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1557. if (WARN_ON(pll == NULL))
  1558. return;
  1559. WARN_ON(!pll->refcount);
  1560. if (pll->active == 0) {
  1561. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  1562. WARN_ON(pll->on);
  1563. assert_shared_dpll_disabled(dev_priv, pll);
  1564. pll->mode_set(dev_priv, pll);
  1565. }
  1566. }
  1567. /**
  1568. * intel_enable_shared_dpll - enable PCH PLL
  1569. * @dev_priv: i915 private structure
  1570. * @pipe: pipe PLL to enable
  1571. *
  1572. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1573. * drives the transcoder clock.
  1574. */
  1575. static void intel_enable_shared_dpll(struct intel_crtc *crtc)
  1576. {
  1577. struct drm_device *dev = crtc->base.dev;
  1578. struct drm_i915_private *dev_priv = dev->dev_private;
  1579. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1580. if (WARN_ON(pll == NULL))
  1581. return;
  1582. if (WARN_ON(pll->refcount == 0))
  1583. return;
  1584. DRM_DEBUG_KMS("enable %s (active %d, on? %d)for crtc %d\n",
  1585. pll->name, pll->active, pll->on,
  1586. crtc->base.base.id);
  1587. if (pll->active++) {
  1588. WARN_ON(!pll->on);
  1589. assert_shared_dpll_enabled(dev_priv, pll);
  1590. return;
  1591. }
  1592. WARN_ON(pll->on);
  1593. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1594. pll->enable(dev_priv, pll);
  1595. pll->on = true;
  1596. }
  1597. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1598. {
  1599. struct drm_device *dev = crtc->base.dev;
  1600. struct drm_i915_private *dev_priv = dev->dev_private;
  1601. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1602. /* PCH only available on ILK+ */
  1603. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1604. if (WARN_ON(pll == NULL))
  1605. return;
  1606. if (WARN_ON(pll->refcount == 0))
  1607. return;
  1608. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1609. pll->name, pll->active, pll->on,
  1610. crtc->base.base.id);
  1611. if (WARN_ON(pll->active == 0)) {
  1612. assert_shared_dpll_disabled(dev_priv, pll);
  1613. return;
  1614. }
  1615. assert_shared_dpll_enabled(dev_priv, pll);
  1616. WARN_ON(!pll->on);
  1617. if (--pll->active)
  1618. return;
  1619. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1620. pll->disable(dev_priv, pll);
  1621. pll->on = false;
  1622. }
  1623. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1624. enum pipe pipe)
  1625. {
  1626. struct drm_device *dev = dev_priv->dev;
  1627. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1628. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1629. uint32_t reg, val, pipeconf_val;
  1630. /* PCH only available on ILK+ */
  1631. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1632. /* Make sure PCH DPLL is enabled */
  1633. assert_shared_dpll_enabled(dev_priv,
  1634. intel_crtc_to_shared_dpll(intel_crtc));
  1635. /* FDI must be feeding us bits for PCH ports */
  1636. assert_fdi_tx_enabled(dev_priv, pipe);
  1637. assert_fdi_rx_enabled(dev_priv, pipe);
  1638. if (HAS_PCH_CPT(dev)) {
  1639. /* Workaround: Set the timing override bit before enabling the
  1640. * pch transcoder. */
  1641. reg = TRANS_CHICKEN2(pipe);
  1642. val = I915_READ(reg);
  1643. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1644. I915_WRITE(reg, val);
  1645. }
  1646. reg = PCH_TRANSCONF(pipe);
  1647. val = I915_READ(reg);
  1648. pipeconf_val = I915_READ(PIPECONF(pipe));
  1649. if (HAS_PCH_IBX(dev_priv->dev)) {
  1650. /*
  1651. * make the BPC in transcoder be consistent with
  1652. * that in pipeconf reg.
  1653. */
  1654. val &= ~PIPECONF_BPC_MASK;
  1655. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1656. }
  1657. val &= ~TRANS_INTERLACE_MASK;
  1658. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1659. if (HAS_PCH_IBX(dev_priv->dev) &&
  1660. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1661. val |= TRANS_LEGACY_INTERLACED_ILK;
  1662. else
  1663. val |= TRANS_INTERLACED;
  1664. else
  1665. val |= TRANS_PROGRESSIVE;
  1666. I915_WRITE(reg, val | TRANS_ENABLE);
  1667. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1668. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1669. }
  1670. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1671. enum transcoder cpu_transcoder)
  1672. {
  1673. u32 val, pipeconf_val;
  1674. /* PCH only available on ILK+ */
  1675. BUG_ON(INTEL_INFO(dev_priv->dev)->gen < 5);
  1676. /* FDI must be feeding us bits for PCH ports */
  1677. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1678. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1679. /* Workaround: set timing override bit. */
  1680. val = I915_READ(_TRANSA_CHICKEN2);
  1681. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1682. I915_WRITE(_TRANSA_CHICKEN2, val);
  1683. val = TRANS_ENABLE;
  1684. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1685. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1686. PIPECONF_INTERLACED_ILK)
  1687. val |= TRANS_INTERLACED;
  1688. else
  1689. val |= TRANS_PROGRESSIVE;
  1690. I915_WRITE(LPT_TRANSCONF, val);
  1691. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1692. DRM_ERROR("Failed to enable PCH transcoder\n");
  1693. }
  1694. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1695. enum pipe pipe)
  1696. {
  1697. struct drm_device *dev = dev_priv->dev;
  1698. uint32_t reg, val;
  1699. /* FDI relies on the transcoder */
  1700. assert_fdi_tx_disabled(dev_priv, pipe);
  1701. assert_fdi_rx_disabled(dev_priv, pipe);
  1702. /* Ports must be off as well */
  1703. assert_pch_ports_disabled(dev_priv, pipe);
  1704. reg = PCH_TRANSCONF(pipe);
  1705. val = I915_READ(reg);
  1706. val &= ~TRANS_ENABLE;
  1707. I915_WRITE(reg, val);
  1708. /* wait for PCH transcoder off, transcoder state */
  1709. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1710. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1711. if (!HAS_PCH_IBX(dev)) {
  1712. /* Workaround: Clear the timing override chicken bit again. */
  1713. reg = TRANS_CHICKEN2(pipe);
  1714. val = I915_READ(reg);
  1715. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1716. I915_WRITE(reg, val);
  1717. }
  1718. }
  1719. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1720. {
  1721. u32 val;
  1722. val = I915_READ(LPT_TRANSCONF);
  1723. val &= ~TRANS_ENABLE;
  1724. I915_WRITE(LPT_TRANSCONF, val);
  1725. /* wait for PCH transcoder off, transcoder state */
  1726. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1727. DRM_ERROR("Failed to disable PCH transcoder\n");
  1728. /* Workaround: clear timing override bit. */
  1729. val = I915_READ(_TRANSA_CHICKEN2);
  1730. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1731. I915_WRITE(_TRANSA_CHICKEN2, val);
  1732. }
  1733. /**
  1734. * intel_enable_pipe - enable a pipe, asserting requirements
  1735. * @crtc: crtc responsible for the pipe
  1736. *
  1737. * Enable @crtc's pipe, making sure that various hardware specific requirements
  1738. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1739. */
  1740. static void intel_enable_pipe(struct intel_crtc *crtc)
  1741. {
  1742. struct drm_device *dev = crtc->base.dev;
  1743. struct drm_i915_private *dev_priv = dev->dev_private;
  1744. enum pipe pipe = crtc->pipe;
  1745. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1746. pipe);
  1747. enum pipe pch_transcoder;
  1748. int reg;
  1749. u32 val;
  1750. assert_planes_disabled(dev_priv, pipe);
  1751. assert_cursor_disabled(dev_priv, pipe);
  1752. assert_sprites_disabled(dev_priv, pipe);
  1753. if (HAS_PCH_LPT(dev_priv->dev))
  1754. pch_transcoder = TRANSCODER_A;
  1755. else
  1756. pch_transcoder = pipe;
  1757. /*
  1758. * A pipe without a PLL won't actually be able to drive bits from
  1759. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1760. * need the check.
  1761. */
  1762. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1763. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI))
  1764. assert_dsi_pll_enabled(dev_priv);
  1765. else
  1766. assert_pll_enabled(dev_priv, pipe);
  1767. else {
  1768. if (crtc->config.has_pch_encoder) {
  1769. /* if driving the PCH, we need FDI enabled */
  1770. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1771. assert_fdi_tx_pll_enabled(dev_priv,
  1772. (enum pipe) cpu_transcoder);
  1773. }
  1774. /* FIXME: assert CPU port conditions for SNB+ */
  1775. }
  1776. reg = PIPECONF(cpu_transcoder);
  1777. val = I915_READ(reg);
  1778. if (val & PIPECONF_ENABLE) {
  1779. WARN_ON(!(pipe == PIPE_A &&
  1780. dev_priv->quirks & QUIRK_PIPEA_FORCE));
  1781. return;
  1782. }
  1783. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1784. POSTING_READ(reg);
  1785. }
  1786. /**
  1787. * intel_disable_pipe - disable a pipe, asserting requirements
  1788. * @dev_priv: i915 private structure
  1789. * @pipe: pipe to disable
  1790. *
  1791. * Disable @pipe, making sure that various hardware specific requirements
  1792. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1793. *
  1794. * @pipe should be %PIPE_A or %PIPE_B.
  1795. *
  1796. * Will wait until the pipe has shut down before returning.
  1797. */
  1798. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1799. enum pipe pipe)
  1800. {
  1801. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1802. pipe);
  1803. int reg;
  1804. u32 val;
  1805. /*
  1806. * Make sure planes won't keep trying to pump pixels to us,
  1807. * or we might hang the display.
  1808. */
  1809. assert_planes_disabled(dev_priv, pipe);
  1810. assert_cursor_disabled(dev_priv, pipe);
  1811. assert_sprites_disabled(dev_priv, pipe);
  1812. /* Don't disable pipe A or pipe A PLLs if needed */
  1813. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1814. return;
  1815. reg = PIPECONF(cpu_transcoder);
  1816. val = I915_READ(reg);
  1817. if ((val & PIPECONF_ENABLE) == 0)
  1818. return;
  1819. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1820. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1821. }
  1822. /*
  1823. * Plane regs are double buffered, going from enabled->disabled needs a
  1824. * trigger in order to latch. The display address reg provides this.
  1825. */
  1826. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1827. enum plane plane)
  1828. {
  1829. struct drm_device *dev = dev_priv->dev;
  1830. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1831. I915_WRITE(reg, I915_READ(reg));
  1832. POSTING_READ(reg);
  1833. }
  1834. /**
  1835. * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
  1836. * @dev_priv: i915 private structure
  1837. * @plane: plane to enable
  1838. * @pipe: pipe being fed
  1839. *
  1840. * Enable @plane on @pipe, making sure that @pipe is running first.
  1841. */
  1842. static void intel_enable_primary_hw_plane(struct drm_i915_private *dev_priv,
  1843. enum plane plane, enum pipe pipe)
  1844. {
  1845. struct drm_device *dev = dev_priv->dev;
  1846. struct intel_crtc *intel_crtc =
  1847. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1848. int reg;
  1849. u32 val;
  1850. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1851. assert_pipe_enabled(dev_priv, pipe);
  1852. if (intel_crtc->primary_enabled)
  1853. return;
  1854. intel_crtc->primary_enabled = true;
  1855. reg = DSPCNTR(plane);
  1856. val = I915_READ(reg);
  1857. WARN_ON(val & DISPLAY_PLANE_ENABLE);
  1858. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1859. intel_flush_primary_plane(dev_priv, plane);
  1860. /*
  1861. * BDW signals flip done immediately if the plane
  1862. * is disabled, even if the plane enable is already
  1863. * armed to occur at the next vblank :(
  1864. */
  1865. if (IS_BROADWELL(dev))
  1866. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1867. }
  1868. /**
  1869. * intel_disable_primary_hw_plane - disable the primary hardware plane
  1870. * @dev_priv: i915 private structure
  1871. * @plane: plane to disable
  1872. * @pipe: pipe consuming the data
  1873. *
  1874. * Disable @plane; should be an independent operation.
  1875. */
  1876. static void intel_disable_primary_hw_plane(struct drm_i915_private *dev_priv,
  1877. enum plane plane, enum pipe pipe)
  1878. {
  1879. struct intel_crtc *intel_crtc =
  1880. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1881. int reg;
  1882. u32 val;
  1883. if (!intel_crtc->primary_enabled)
  1884. return;
  1885. intel_crtc->primary_enabled = false;
  1886. reg = DSPCNTR(plane);
  1887. val = I915_READ(reg);
  1888. WARN_ON((val & DISPLAY_PLANE_ENABLE) == 0);
  1889. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1890. intel_flush_primary_plane(dev_priv, plane);
  1891. }
  1892. static bool need_vtd_wa(struct drm_device *dev)
  1893. {
  1894. #ifdef CONFIG_INTEL_IOMMU
  1895. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1896. return true;
  1897. #endif
  1898. return false;
  1899. }
  1900. static int intel_align_height(struct drm_device *dev, int height, bool tiled)
  1901. {
  1902. int tile_height;
  1903. tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1;
  1904. return ALIGN(height, tile_height);
  1905. }
  1906. int
  1907. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1908. struct drm_i915_gem_object *obj,
  1909. struct intel_engine_cs *pipelined)
  1910. {
  1911. struct drm_i915_private *dev_priv = dev->dev_private;
  1912. u32 alignment;
  1913. int ret;
  1914. switch (obj->tiling_mode) {
  1915. case I915_TILING_NONE:
  1916. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1917. alignment = 128 * 1024;
  1918. else if (INTEL_INFO(dev)->gen >= 4)
  1919. alignment = 4 * 1024;
  1920. else
  1921. alignment = 64 * 1024;
  1922. break;
  1923. case I915_TILING_X:
  1924. /* pin() will align the object as required by fence */
  1925. alignment = 0;
  1926. break;
  1927. case I915_TILING_Y:
  1928. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1929. return -EINVAL;
  1930. default:
  1931. BUG();
  1932. }
  1933. /* Note that the w/a also requires 64 PTE of padding following the
  1934. * bo. We currently fill all unused PTE with the shadow page and so
  1935. * we should always have valid PTE following the scanout preventing
  1936. * the VT-d warning.
  1937. */
  1938. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1939. alignment = 256 * 1024;
  1940. dev_priv->mm.interruptible = false;
  1941. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1942. if (ret)
  1943. goto err_interruptible;
  1944. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1945. * fence, whereas 965+ only requires a fence if using
  1946. * framebuffer compression. For simplicity, we always install
  1947. * a fence as the cost is not that onerous.
  1948. */
  1949. ret = i915_gem_object_get_fence(obj);
  1950. if (ret)
  1951. goto err_unpin;
  1952. i915_gem_object_pin_fence(obj);
  1953. dev_priv->mm.interruptible = true;
  1954. return 0;
  1955. err_unpin:
  1956. i915_gem_object_unpin_from_display_plane(obj);
  1957. err_interruptible:
  1958. dev_priv->mm.interruptible = true;
  1959. return ret;
  1960. }
  1961. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1962. {
  1963. i915_gem_object_unpin_fence(obj);
  1964. i915_gem_object_unpin_from_display_plane(obj);
  1965. }
  1966. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1967. * is assumed to be a power-of-two. */
  1968. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1969. unsigned int tiling_mode,
  1970. unsigned int cpp,
  1971. unsigned int pitch)
  1972. {
  1973. if (tiling_mode != I915_TILING_NONE) {
  1974. unsigned int tile_rows, tiles;
  1975. tile_rows = *y / 8;
  1976. *y %= 8;
  1977. tiles = *x / (512/cpp);
  1978. *x %= 512/cpp;
  1979. return tile_rows * pitch * 8 + tiles * 4096;
  1980. } else {
  1981. unsigned int offset;
  1982. offset = *y * pitch + *x * cpp;
  1983. *y = 0;
  1984. *x = (offset & 4095) / cpp;
  1985. return offset & -4096;
  1986. }
  1987. }
  1988. int intel_format_to_fourcc(int format)
  1989. {
  1990. switch (format) {
  1991. case DISPPLANE_8BPP:
  1992. return DRM_FORMAT_C8;
  1993. case DISPPLANE_BGRX555:
  1994. return DRM_FORMAT_XRGB1555;
  1995. case DISPPLANE_BGRX565:
  1996. return DRM_FORMAT_RGB565;
  1997. default:
  1998. case DISPPLANE_BGRX888:
  1999. return DRM_FORMAT_XRGB8888;
  2000. case DISPPLANE_RGBX888:
  2001. return DRM_FORMAT_XBGR8888;
  2002. case DISPPLANE_BGRX101010:
  2003. return DRM_FORMAT_XRGB2101010;
  2004. case DISPPLANE_RGBX101010:
  2005. return DRM_FORMAT_XBGR2101010;
  2006. }
  2007. }
  2008. static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
  2009. struct intel_plane_config *plane_config)
  2010. {
  2011. struct drm_device *dev = crtc->base.dev;
  2012. struct drm_i915_gem_object *obj = NULL;
  2013. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  2014. u32 base = plane_config->base;
  2015. if (plane_config->size == 0)
  2016. return false;
  2017. obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base,
  2018. plane_config->size);
  2019. if (!obj)
  2020. return false;
  2021. if (plane_config->tiled) {
  2022. obj->tiling_mode = I915_TILING_X;
  2023. obj->stride = crtc->base.primary->fb->pitches[0];
  2024. }
  2025. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2026. mode_cmd.width = crtc->base.primary->fb->width;
  2027. mode_cmd.height = crtc->base.primary->fb->height;
  2028. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2029. mutex_lock(&dev->struct_mutex);
  2030. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2031. &mode_cmd, obj)) {
  2032. DRM_DEBUG_KMS("intel fb init failed\n");
  2033. goto out_unref_obj;
  2034. }
  2035. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2036. mutex_unlock(&dev->struct_mutex);
  2037. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2038. return true;
  2039. out_unref_obj:
  2040. drm_gem_object_unreference(&obj->base);
  2041. mutex_unlock(&dev->struct_mutex);
  2042. return false;
  2043. }
  2044. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2045. struct intel_plane_config *plane_config)
  2046. {
  2047. struct drm_device *dev = intel_crtc->base.dev;
  2048. struct drm_crtc *c;
  2049. struct intel_crtc *i;
  2050. struct intel_framebuffer *fb;
  2051. if (!intel_crtc->base.primary->fb)
  2052. return;
  2053. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2054. return;
  2055. kfree(intel_crtc->base.primary->fb);
  2056. intel_crtc->base.primary->fb = NULL;
  2057. /*
  2058. * Failed to alloc the obj, check to see if we should share
  2059. * an fb with another CRTC instead
  2060. */
  2061. for_each_crtc(dev, c) {
  2062. i = to_intel_crtc(c);
  2063. if (c == &intel_crtc->base)
  2064. continue;
  2065. if (!i->active || !c->primary->fb)
  2066. continue;
  2067. fb = to_intel_framebuffer(c->primary->fb);
  2068. if (i915_gem_obj_ggtt_offset(fb->obj) == plane_config->base) {
  2069. drm_framebuffer_reference(c->primary->fb);
  2070. intel_crtc->base.primary->fb = c->primary->fb;
  2071. fb->obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2072. break;
  2073. }
  2074. }
  2075. }
  2076. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2077. struct drm_framebuffer *fb,
  2078. int x, int y)
  2079. {
  2080. struct drm_device *dev = crtc->dev;
  2081. struct drm_i915_private *dev_priv = dev->dev_private;
  2082. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2083. struct intel_framebuffer *intel_fb;
  2084. struct drm_i915_gem_object *obj;
  2085. int plane = intel_crtc->plane;
  2086. unsigned long linear_offset;
  2087. u32 dspcntr;
  2088. u32 reg;
  2089. intel_fb = to_intel_framebuffer(fb);
  2090. obj = intel_fb->obj;
  2091. reg = DSPCNTR(plane);
  2092. dspcntr = I915_READ(reg);
  2093. /* Mask out pixel format bits in case we change it */
  2094. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  2095. switch (fb->pixel_format) {
  2096. case DRM_FORMAT_C8:
  2097. dspcntr |= DISPPLANE_8BPP;
  2098. break;
  2099. case DRM_FORMAT_XRGB1555:
  2100. case DRM_FORMAT_ARGB1555:
  2101. dspcntr |= DISPPLANE_BGRX555;
  2102. break;
  2103. case DRM_FORMAT_RGB565:
  2104. dspcntr |= DISPPLANE_BGRX565;
  2105. break;
  2106. case DRM_FORMAT_XRGB8888:
  2107. case DRM_FORMAT_ARGB8888:
  2108. dspcntr |= DISPPLANE_BGRX888;
  2109. break;
  2110. case DRM_FORMAT_XBGR8888:
  2111. case DRM_FORMAT_ABGR8888:
  2112. dspcntr |= DISPPLANE_RGBX888;
  2113. break;
  2114. case DRM_FORMAT_XRGB2101010:
  2115. case DRM_FORMAT_ARGB2101010:
  2116. dspcntr |= DISPPLANE_BGRX101010;
  2117. break;
  2118. case DRM_FORMAT_XBGR2101010:
  2119. case DRM_FORMAT_ABGR2101010:
  2120. dspcntr |= DISPPLANE_RGBX101010;
  2121. break;
  2122. default:
  2123. BUG();
  2124. }
  2125. if (INTEL_INFO(dev)->gen >= 4) {
  2126. if (obj->tiling_mode != I915_TILING_NONE)
  2127. dspcntr |= DISPPLANE_TILED;
  2128. else
  2129. dspcntr &= ~DISPPLANE_TILED;
  2130. }
  2131. if (IS_G4X(dev))
  2132. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2133. I915_WRITE(reg, dspcntr);
  2134. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  2135. if (INTEL_INFO(dev)->gen >= 4) {
  2136. intel_crtc->dspaddr_offset =
  2137. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2138. fb->bits_per_pixel / 8,
  2139. fb->pitches[0]);
  2140. linear_offset -= intel_crtc->dspaddr_offset;
  2141. } else {
  2142. intel_crtc->dspaddr_offset = linear_offset;
  2143. }
  2144. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2145. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2146. fb->pitches[0]);
  2147. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2148. if (INTEL_INFO(dev)->gen >= 4) {
  2149. I915_WRITE(DSPSURF(plane),
  2150. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2151. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2152. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2153. } else
  2154. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2155. POSTING_READ(reg);
  2156. }
  2157. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2158. struct drm_framebuffer *fb,
  2159. int x, int y)
  2160. {
  2161. struct drm_device *dev = crtc->dev;
  2162. struct drm_i915_private *dev_priv = dev->dev_private;
  2163. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2164. struct intel_framebuffer *intel_fb;
  2165. struct drm_i915_gem_object *obj;
  2166. int plane = intel_crtc->plane;
  2167. unsigned long linear_offset;
  2168. u32 dspcntr;
  2169. u32 reg;
  2170. intel_fb = to_intel_framebuffer(fb);
  2171. obj = intel_fb->obj;
  2172. reg = DSPCNTR(plane);
  2173. dspcntr = I915_READ(reg);
  2174. /* Mask out pixel format bits in case we change it */
  2175. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  2176. switch (fb->pixel_format) {
  2177. case DRM_FORMAT_C8:
  2178. dspcntr |= DISPPLANE_8BPP;
  2179. break;
  2180. case DRM_FORMAT_RGB565:
  2181. dspcntr |= DISPPLANE_BGRX565;
  2182. break;
  2183. case DRM_FORMAT_XRGB8888:
  2184. case DRM_FORMAT_ARGB8888:
  2185. dspcntr |= DISPPLANE_BGRX888;
  2186. break;
  2187. case DRM_FORMAT_XBGR8888:
  2188. case DRM_FORMAT_ABGR8888:
  2189. dspcntr |= DISPPLANE_RGBX888;
  2190. break;
  2191. case DRM_FORMAT_XRGB2101010:
  2192. case DRM_FORMAT_ARGB2101010:
  2193. dspcntr |= DISPPLANE_BGRX101010;
  2194. break;
  2195. case DRM_FORMAT_XBGR2101010:
  2196. case DRM_FORMAT_ABGR2101010:
  2197. dspcntr |= DISPPLANE_RGBX101010;
  2198. break;
  2199. default:
  2200. BUG();
  2201. }
  2202. if (obj->tiling_mode != I915_TILING_NONE)
  2203. dspcntr |= DISPPLANE_TILED;
  2204. else
  2205. dspcntr &= ~DISPPLANE_TILED;
  2206. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2207. dspcntr &= ~DISPPLANE_TRICKLE_FEED_DISABLE;
  2208. else
  2209. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2210. I915_WRITE(reg, dspcntr);
  2211. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  2212. intel_crtc->dspaddr_offset =
  2213. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2214. fb->bits_per_pixel / 8,
  2215. fb->pitches[0]);
  2216. linear_offset -= intel_crtc->dspaddr_offset;
  2217. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2218. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2219. fb->pitches[0]);
  2220. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2221. I915_WRITE(DSPSURF(plane),
  2222. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2223. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2224. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2225. } else {
  2226. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2227. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2228. }
  2229. POSTING_READ(reg);
  2230. }
  2231. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2232. static int
  2233. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2234. int x, int y, enum mode_set_atomic state)
  2235. {
  2236. struct drm_device *dev = crtc->dev;
  2237. struct drm_i915_private *dev_priv = dev->dev_private;
  2238. if (dev_priv->display.disable_fbc)
  2239. dev_priv->display.disable_fbc(dev);
  2240. intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe);
  2241. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2242. return 0;
  2243. }
  2244. void intel_display_handle_reset(struct drm_device *dev)
  2245. {
  2246. struct drm_i915_private *dev_priv = dev->dev_private;
  2247. struct drm_crtc *crtc;
  2248. /*
  2249. * Flips in the rings have been nuked by the reset,
  2250. * so complete all pending flips so that user space
  2251. * will get its events and not get stuck.
  2252. *
  2253. * Also update the base address of all primary
  2254. * planes to the the last fb to make sure we're
  2255. * showing the correct fb after a reset.
  2256. *
  2257. * Need to make two loops over the crtcs so that we
  2258. * don't try to grab a crtc mutex before the
  2259. * pending_flip_queue really got woken up.
  2260. */
  2261. for_each_crtc(dev, crtc) {
  2262. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2263. enum plane plane = intel_crtc->plane;
  2264. intel_prepare_page_flip(dev, plane);
  2265. intel_finish_page_flip_plane(dev, plane);
  2266. }
  2267. for_each_crtc(dev, crtc) {
  2268. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2269. drm_modeset_lock(&crtc->mutex, NULL);
  2270. /*
  2271. * FIXME: Once we have proper support for primary planes (and
  2272. * disabling them without disabling the entire crtc) allow again
  2273. * a NULL crtc->primary->fb.
  2274. */
  2275. if (intel_crtc->active && crtc->primary->fb)
  2276. dev_priv->display.update_primary_plane(crtc,
  2277. crtc->primary->fb,
  2278. crtc->x,
  2279. crtc->y);
  2280. drm_modeset_unlock(&crtc->mutex);
  2281. }
  2282. }
  2283. static int
  2284. intel_finish_fb(struct drm_framebuffer *old_fb)
  2285. {
  2286. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  2287. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2288. bool was_interruptible = dev_priv->mm.interruptible;
  2289. int ret;
  2290. /* Big Hammer, we also need to ensure that any pending
  2291. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2292. * current scanout is retired before unpinning the old
  2293. * framebuffer.
  2294. *
  2295. * This should only fail upon a hung GPU, in which case we
  2296. * can safely continue.
  2297. */
  2298. dev_priv->mm.interruptible = false;
  2299. ret = i915_gem_object_finish_gpu(obj);
  2300. dev_priv->mm.interruptible = was_interruptible;
  2301. return ret;
  2302. }
  2303. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2304. {
  2305. struct drm_device *dev = crtc->dev;
  2306. struct drm_i915_private *dev_priv = dev->dev_private;
  2307. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2308. unsigned long flags;
  2309. bool pending;
  2310. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2311. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2312. return false;
  2313. spin_lock_irqsave(&dev->event_lock, flags);
  2314. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2315. spin_unlock_irqrestore(&dev->event_lock, flags);
  2316. return pending;
  2317. }
  2318. static int
  2319. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2320. struct drm_framebuffer *fb)
  2321. {
  2322. struct drm_device *dev = crtc->dev;
  2323. struct drm_i915_private *dev_priv = dev->dev_private;
  2324. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2325. enum pipe pipe = intel_crtc->pipe;
  2326. struct drm_framebuffer *old_fb;
  2327. struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
  2328. struct drm_i915_gem_object *old_obj;
  2329. int ret;
  2330. if (intel_crtc_has_pending_flip(crtc)) {
  2331. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2332. return -EBUSY;
  2333. }
  2334. /* no fb bound */
  2335. if (!fb) {
  2336. DRM_ERROR("No FB bound\n");
  2337. return 0;
  2338. }
  2339. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2340. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2341. plane_name(intel_crtc->plane),
  2342. INTEL_INFO(dev)->num_pipes);
  2343. return -EINVAL;
  2344. }
  2345. old_fb = crtc->primary->fb;
  2346. old_obj = old_fb ? to_intel_framebuffer(old_fb)->obj : NULL;
  2347. mutex_lock(&dev->struct_mutex);
  2348. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2349. if (ret == 0)
  2350. i915_gem_track_fb(old_obj, obj,
  2351. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2352. mutex_unlock(&dev->struct_mutex);
  2353. if (ret != 0) {
  2354. DRM_ERROR("pin & fence failed\n");
  2355. return ret;
  2356. }
  2357. /*
  2358. * Update pipe size and adjust fitter if needed: the reason for this is
  2359. * that in compute_mode_changes we check the native mode (not the pfit
  2360. * mode) to see if we can flip rather than do a full mode set. In the
  2361. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2362. * pfit state, we'll end up with a big fb scanned out into the wrong
  2363. * sized surface.
  2364. *
  2365. * To fix this properly, we need to hoist the checks up into
  2366. * compute_mode_changes (or above), check the actual pfit state and
  2367. * whether the platform allows pfit disable with pipe active, and only
  2368. * then update the pipesrc and pfit state, even on the flip path.
  2369. */
  2370. if (i915.fastboot) {
  2371. const struct drm_display_mode *adjusted_mode =
  2372. &intel_crtc->config.adjusted_mode;
  2373. I915_WRITE(PIPESRC(intel_crtc->pipe),
  2374. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2375. (adjusted_mode->crtc_vdisplay - 1));
  2376. if (!intel_crtc->config.pch_pfit.enabled &&
  2377. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2378. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2379. I915_WRITE(PF_CTL(intel_crtc->pipe), 0);
  2380. I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0);
  2381. I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0);
  2382. }
  2383. intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2384. intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2385. }
  2386. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2387. if (intel_crtc->active)
  2388. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2389. crtc->primary->fb = fb;
  2390. crtc->x = x;
  2391. crtc->y = y;
  2392. if (old_fb) {
  2393. if (intel_crtc->active && old_fb != fb)
  2394. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2395. mutex_lock(&dev->struct_mutex);
  2396. intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
  2397. mutex_unlock(&dev->struct_mutex);
  2398. }
  2399. mutex_lock(&dev->struct_mutex);
  2400. intel_update_fbc(dev);
  2401. mutex_unlock(&dev->struct_mutex);
  2402. return 0;
  2403. }
  2404. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2405. {
  2406. struct drm_device *dev = crtc->dev;
  2407. struct drm_i915_private *dev_priv = dev->dev_private;
  2408. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2409. int pipe = intel_crtc->pipe;
  2410. u32 reg, temp;
  2411. /* enable normal train */
  2412. reg = FDI_TX_CTL(pipe);
  2413. temp = I915_READ(reg);
  2414. if (IS_IVYBRIDGE(dev)) {
  2415. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2416. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2417. } else {
  2418. temp &= ~FDI_LINK_TRAIN_NONE;
  2419. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2420. }
  2421. I915_WRITE(reg, temp);
  2422. reg = FDI_RX_CTL(pipe);
  2423. temp = I915_READ(reg);
  2424. if (HAS_PCH_CPT(dev)) {
  2425. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2426. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2427. } else {
  2428. temp &= ~FDI_LINK_TRAIN_NONE;
  2429. temp |= FDI_LINK_TRAIN_NONE;
  2430. }
  2431. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2432. /* wait one idle pattern time */
  2433. POSTING_READ(reg);
  2434. udelay(1000);
  2435. /* IVB wants error correction enabled */
  2436. if (IS_IVYBRIDGE(dev))
  2437. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2438. FDI_FE_ERRC_ENABLE);
  2439. }
  2440. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2441. {
  2442. return crtc->base.enabled && crtc->active &&
  2443. crtc->config.has_pch_encoder;
  2444. }
  2445. static void ivb_modeset_global_resources(struct drm_device *dev)
  2446. {
  2447. struct drm_i915_private *dev_priv = dev->dev_private;
  2448. struct intel_crtc *pipe_B_crtc =
  2449. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2450. struct intel_crtc *pipe_C_crtc =
  2451. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2452. uint32_t temp;
  2453. /*
  2454. * When everything is off disable fdi C so that we could enable fdi B
  2455. * with all lanes. Note that we don't care about enabled pipes without
  2456. * an enabled pch encoder.
  2457. */
  2458. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2459. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2460. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2461. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2462. temp = I915_READ(SOUTH_CHICKEN1);
  2463. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2464. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2465. I915_WRITE(SOUTH_CHICKEN1, temp);
  2466. }
  2467. }
  2468. /* The FDI link training functions for ILK/Ibexpeak. */
  2469. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2470. {
  2471. struct drm_device *dev = crtc->dev;
  2472. struct drm_i915_private *dev_priv = dev->dev_private;
  2473. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2474. int pipe = intel_crtc->pipe;
  2475. u32 reg, temp, tries;
  2476. /* FDI needs bits from pipe first */
  2477. assert_pipe_enabled(dev_priv, pipe);
  2478. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2479. for train result */
  2480. reg = FDI_RX_IMR(pipe);
  2481. temp = I915_READ(reg);
  2482. temp &= ~FDI_RX_SYMBOL_LOCK;
  2483. temp &= ~FDI_RX_BIT_LOCK;
  2484. I915_WRITE(reg, temp);
  2485. I915_READ(reg);
  2486. udelay(150);
  2487. /* enable CPU FDI TX and PCH FDI RX */
  2488. reg = FDI_TX_CTL(pipe);
  2489. temp = I915_READ(reg);
  2490. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2491. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2492. temp &= ~FDI_LINK_TRAIN_NONE;
  2493. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2494. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2495. reg = FDI_RX_CTL(pipe);
  2496. temp = I915_READ(reg);
  2497. temp &= ~FDI_LINK_TRAIN_NONE;
  2498. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2499. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2500. POSTING_READ(reg);
  2501. udelay(150);
  2502. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2503. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2504. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2505. FDI_RX_PHASE_SYNC_POINTER_EN);
  2506. reg = FDI_RX_IIR(pipe);
  2507. for (tries = 0; tries < 5; tries++) {
  2508. temp = I915_READ(reg);
  2509. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2510. if ((temp & FDI_RX_BIT_LOCK)) {
  2511. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2512. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2513. break;
  2514. }
  2515. }
  2516. if (tries == 5)
  2517. DRM_ERROR("FDI train 1 fail!\n");
  2518. /* Train 2 */
  2519. reg = FDI_TX_CTL(pipe);
  2520. temp = I915_READ(reg);
  2521. temp &= ~FDI_LINK_TRAIN_NONE;
  2522. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2523. I915_WRITE(reg, temp);
  2524. reg = FDI_RX_CTL(pipe);
  2525. temp = I915_READ(reg);
  2526. temp &= ~FDI_LINK_TRAIN_NONE;
  2527. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2528. I915_WRITE(reg, temp);
  2529. POSTING_READ(reg);
  2530. udelay(150);
  2531. reg = FDI_RX_IIR(pipe);
  2532. for (tries = 0; tries < 5; tries++) {
  2533. temp = I915_READ(reg);
  2534. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2535. if (temp & FDI_RX_SYMBOL_LOCK) {
  2536. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2537. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2538. break;
  2539. }
  2540. }
  2541. if (tries == 5)
  2542. DRM_ERROR("FDI train 2 fail!\n");
  2543. DRM_DEBUG_KMS("FDI train done\n");
  2544. }
  2545. static const int snb_b_fdi_train_param[] = {
  2546. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2547. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2548. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2549. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2550. };
  2551. /* The FDI link training functions for SNB/Cougarpoint. */
  2552. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2553. {
  2554. struct drm_device *dev = crtc->dev;
  2555. struct drm_i915_private *dev_priv = dev->dev_private;
  2556. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2557. int pipe = intel_crtc->pipe;
  2558. u32 reg, temp, i, retry;
  2559. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2560. for train result */
  2561. reg = FDI_RX_IMR(pipe);
  2562. temp = I915_READ(reg);
  2563. temp &= ~FDI_RX_SYMBOL_LOCK;
  2564. temp &= ~FDI_RX_BIT_LOCK;
  2565. I915_WRITE(reg, temp);
  2566. POSTING_READ(reg);
  2567. udelay(150);
  2568. /* enable CPU FDI TX and PCH FDI RX */
  2569. reg = FDI_TX_CTL(pipe);
  2570. temp = I915_READ(reg);
  2571. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2572. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2573. temp &= ~FDI_LINK_TRAIN_NONE;
  2574. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2575. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2576. /* SNB-B */
  2577. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2578. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2579. I915_WRITE(FDI_RX_MISC(pipe),
  2580. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2581. reg = FDI_RX_CTL(pipe);
  2582. temp = I915_READ(reg);
  2583. if (HAS_PCH_CPT(dev)) {
  2584. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2585. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2586. } else {
  2587. temp &= ~FDI_LINK_TRAIN_NONE;
  2588. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2589. }
  2590. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2591. POSTING_READ(reg);
  2592. udelay(150);
  2593. for (i = 0; i < 4; i++) {
  2594. reg = FDI_TX_CTL(pipe);
  2595. temp = I915_READ(reg);
  2596. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2597. temp |= snb_b_fdi_train_param[i];
  2598. I915_WRITE(reg, temp);
  2599. POSTING_READ(reg);
  2600. udelay(500);
  2601. for (retry = 0; retry < 5; retry++) {
  2602. reg = FDI_RX_IIR(pipe);
  2603. temp = I915_READ(reg);
  2604. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2605. if (temp & FDI_RX_BIT_LOCK) {
  2606. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2607. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2608. break;
  2609. }
  2610. udelay(50);
  2611. }
  2612. if (retry < 5)
  2613. break;
  2614. }
  2615. if (i == 4)
  2616. DRM_ERROR("FDI train 1 fail!\n");
  2617. /* Train 2 */
  2618. reg = FDI_TX_CTL(pipe);
  2619. temp = I915_READ(reg);
  2620. temp &= ~FDI_LINK_TRAIN_NONE;
  2621. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2622. if (IS_GEN6(dev)) {
  2623. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2624. /* SNB-B */
  2625. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2626. }
  2627. I915_WRITE(reg, temp);
  2628. reg = FDI_RX_CTL(pipe);
  2629. temp = I915_READ(reg);
  2630. if (HAS_PCH_CPT(dev)) {
  2631. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2632. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2633. } else {
  2634. temp &= ~FDI_LINK_TRAIN_NONE;
  2635. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2636. }
  2637. I915_WRITE(reg, temp);
  2638. POSTING_READ(reg);
  2639. udelay(150);
  2640. for (i = 0; i < 4; i++) {
  2641. reg = FDI_TX_CTL(pipe);
  2642. temp = I915_READ(reg);
  2643. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2644. temp |= snb_b_fdi_train_param[i];
  2645. I915_WRITE(reg, temp);
  2646. POSTING_READ(reg);
  2647. udelay(500);
  2648. for (retry = 0; retry < 5; retry++) {
  2649. reg = FDI_RX_IIR(pipe);
  2650. temp = I915_READ(reg);
  2651. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2652. if (temp & FDI_RX_SYMBOL_LOCK) {
  2653. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2654. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2655. break;
  2656. }
  2657. udelay(50);
  2658. }
  2659. if (retry < 5)
  2660. break;
  2661. }
  2662. if (i == 4)
  2663. DRM_ERROR("FDI train 2 fail!\n");
  2664. DRM_DEBUG_KMS("FDI train done.\n");
  2665. }
  2666. /* Manual link training for Ivy Bridge A0 parts */
  2667. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2668. {
  2669. struct drm_device *dev = crtc->dev;
  2670. struct drm_i915_private *dev_priv = dev->dev_private;
  2671. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2672. int pipe = intel_crtc->pipe;
  2673. u32 reg, temp, i, j;
  2674. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2675. for train result */
  2676. reg = FDI_RX_IMR(pipe);
  2677. temp = I915_READ(reg);
  2678. temp &= ~FDI_RX_SYMBOL_LOCK;
  2679. temp &= ~FDI_RX_BIT_LOCK;
  2680. I915_WRITE(reg, temp);
  2681. POSTING_READ(reg);
  2682. udelay(150);
  2683. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2684. I915_READ(FDI_RX_IIR(pipe)));
  2685. /* Try each vswing and preemphasis setting twice before moving on */
  2686. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2687. /* disable first in case we need to retry */
  2688. reg = FDI_TX_CTL(pipe);
  2689. temp = I915_READ(reg);
  2690. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2691. temp &= ~FDI_TX_ENABLE;
  2692. I915_WRITE(reg, temp);
  2693. reg = FDI_RX_CTL(pipe);
  2694. temp = I915_READ(reg);
  2695. temp &= ~FDI_LINK_TRAIN_AUTO;
  2696. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2697. temp &= ~FDI_RX_ENABLE;
  2698. I915_WRITE(reg, temp);
  2699. /* enable CPU FDI TX and PCH FDI RX */
  2700. reg = FDI_TX_CTL(pipe);
  2701. temp = I915_READ(reg);
  2702. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2703. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2704. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2705. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2706. temp |= snb_b_fdi_train_param[j/2];
  2707. temp |= FDI_COMPOSITE_SYNC;
  2708. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2709. I915_WRITE(FDI_RX_MISC(pipe),
  2710. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2711. reg = FDI_RX_CTL(pipe);
  2712. temp = I915_READ(reg);
  2713. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2714. temp |= FDI_COMPOSITE_SYNC;
  2715. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2716. POSTING_READ(reg);
  2717. udelay(1); /* should be 0.5us */
  2718. for (i = 0; i < 4; i++) {
  2719. reg = FDI_RX_IIR(pipe);
  2720. temp = I915_READ(reg);
  2721. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2722. if (temp & FDI_RX_BIT_LOCK ||
  2723. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2724. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2725. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2726. i);
  2727. break;
  2728. }
  2729. udelay(1); /* should be 0.5us */
  2730. }
  2731. if (i == 4) {
  2732. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2733. continue;
  2734. }
  2735. /* Train 2 */
  2736. reg = FDI_TX_CTL(pipe);
  2737. temp = I915_READ(reg);
  2738. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2739. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2740. I915_WRITE(reg, temp);
  2741. reg = FDI_RX_CTL(pipe);
  2742. temp = I915_READ(reg);
  2743. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2744. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2745. I915_WRITE(reg, temp);
  2746. POSTING_READ(reg);
  2747. udelay(2); /* should be 1.5us */
  2748. for (i = 0; i < 4; i++) {
  2749. reg = FDI_RX_IIR(pipe);
  2750. temp = I915_READ(reg);
  2751. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2752. if (temp & FDI_RX_SYMBOL_LOCK ||
  2753. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2754. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2755. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2756. i);
  2757. goto train_done;
  2758. }
  2759. udelay(2); /* should be 1.5us */
  2760. }
  2761. if (i == 4)
  2762. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2763. }
  2764. train_done:
  2765. DRM_DEBUG_KMS("FDI train done.\n");
  2766. }
  2767. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2768. {
  2769. struct drm_device *dev = intel_crtc->base.dev;
  2770. struct drm_i915_private *dev_priv = dev->dev_private;
  2771. int pipe = intel_crtc->pipe;
  2772. u32 reg, temp;
  2773. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2774. reg = FDI_RX_CTL(pipe);
  2775. temp = I915_READ(reg);
  2776. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2777. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2778. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2779. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2780. POSTING_READ(reg);
  2781. udelay(200);
  2782. /* Switch from Rawclk to PCDclk */
  2783. temp = I915_READ(reg);
  2784. I915_WRITE(reg, temp | FDI_PCDCLK);
  2785. POSTING_READ(reg);
  2786. udelay(200);
  2787. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2788. reg = FDI_TX_CTL(pipe);
  2789. temp = I915_READ(reg);
  2790. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2791. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2792. POSTING_READ(reg);
  2793. udelay(100);
  2794. }
  2795. }
  2796. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2797. {
  2798. struct drm_device *dev = intel_crtc->base.dev;
  2799. struct drm_i915_private *dev_priv = dev->dev_private;
  2800. int pipe = intel_crtc->pipe;
  2801. u32 reg, temp;
  2802. /* Switch from PCDclk to Rawclk */
  2803. reg = FDI_RX_CTL(pipe);
  2804. temp = I915_READ(reg);
  2805. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2806. /* Disable CPU FDI TX PLL */
  2807. reg = FDI_TX_CTL(pipe);
  2808. temp = I915_READ(reg);
  2809. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2810. POSTING_READ(reg);
  2811. udelay(100);
  2812. reg = FDI_RX_CTL(pipe);
  2813. temp = I915_READ(reg);
  2814. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2815. /* Wait for the clocks to turn off. */
  2816. POSTING_READ(reg);
  2817. udelay(100);
  2818. }
  2819. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2820. {
  2821. struct drm_device *dev = crtc->dev;
  2822. struct drm_i915_private *dev_priv = dev->dev_private;
  2823. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2824. int pipe = intel_crtc->pipe;
  2825. u32 reg, temp;
  2826. /* disable CPU FDI tx and PCH FDI rx */
  2827. reg = FDI_TX_CTL(pipe);
  2828. temp = I915_READ(reg);
  2829. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2830. POSTING_READ(reg);
  2831. reg = FDI_RX_CTL(pipe);
  2832. temp = I915_READ(reg);
  2833. temp &= ~(0x7 << 16);
  2834. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2835. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2836. POSTING_READ(reg);
  2837. udelay(100);
  2838. /* Ironlake workaround, disable clock pointer after downing FDI */
  2839. if (HAS_PCH_IBX(dev))
  2840. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2841. /* still set train pattern 1 */
  2842. reg = FDI_TX_CTL(pipe);
  2843. temp = I915_READ(reg);
  2844. temp &= ~FDI_LINK_TRAIN_NONE;
  2845. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2846. I915_WRITE(reg, temp);
  2847. reg = FDI_RX_CTL(pipe);
  2848. temp = I915_READ(reg);
  2849. if (HAS_PCH_CPT(dev)) {
  2850. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2851. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2852. } else {
  2853. temp &= ~FDI_LINK_TRAIN_NONE;
  2854. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2855. }
  2856. /* BPC in FDI rx is consistent with that in PIPECONF */
  2857. temp &= ~(0x07 << 16);
  2858. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2859. I915_WRITE(reg, temp);
  2860. POSTING_READ(reg);
  2861. udelay(100);
  2862. }
  2863. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2864. {
  2865. struct intel_crtc *crtc;
  2866. /* Note that we don't need to be called with mode_config.lock here
  2867. * as our list of CRTC objects is static for the lifetime of the
  2868. * device and so cannot disappear as we iterate. Similarly, we can
  2869. * happily treat the predicates as racy, atomic checks as userspace
  2870. * cannot claim and pin a new fb without at least acquring the
  2871. * struct_mutex and so serialising with us.
  2872. */
  2873. for_each_intel_crtc(dev, crtc) {
  2874. if (atomic_read(&crtc->unpin_work_count) == 0)
  2875. continue;
  2876. if (crtc->unpin_work)
  2877. intel_wait_for_vblank(dev, crtc->pipe);
  2878. return true;
  2879. }
  2880. return false;
  2881. }
  2882. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2883. {
  2884. struct drm_device *dev = crtc->dev;
  2885. struct drm_i915_private *dev_priv = dev->dev_private;
  2886. if (crtc->primary->fb == NULL)
  2887. return;
  2888. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2889. WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  2890. !intel_crtc_has_pending_flip(crtc),
  2891. 60*HZ) == 0);
  2892. mutex_lock(&dev->struct_mutex);
  2893. intel_finish_fb(crtc->primary->fb);
  2894. mutex_unlock(&dev->struct_mutex);
  2895. }
  2896. /* Program iCLKIP clock to the desired frequency */
  2897. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2898. {
  2899. struct drm_device *dev = crtc->dev;
  2900. struct drm_i915_private *dev_priv = dev->dev_private;
  2901. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2902. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2903. u32 temp;
  2904. mutex_lock(&dev_priv->dpio_lock);
  2905. /* It is necessary to ungate the pixclk gate prior to programming
  2906. * the divisors, and gate it back when it is done.
  2907. */
  2908. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2909. /* Disable SSCCTL */
  2910. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2911. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2912. SBI_SSCCTL_DISABLE,
  2913. SBI_ICLK);
  2914. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2915. if (clock == 20000) {
  2916. auxdiv = 1;
  2917. divsel = 0x41;
  2918. phaseinc = 0x20;
  2919. } else {
  2920. /* The iCLK virtual clock root frequency is in MHz,
  2921. * but the adjusted_mode->crtc_clock in in KHz. To get the
  2922. * divisors, it is necessary to divide one by another, so we
  2923. * convert the virtual clock precision to KHz here for higher
  2924. * precision.
  2925. */
  2926. u32 iclk_virtual_root_freq = 172800 * 1000;
  2927. u32 iclk_pi_range = 64;
  2928. u32 desired_divisor, msb_divisor_value, pi_value;
  2929. desired_divisor = (iclk_virtual_root_freq / clock);
  2930. msb_divisor_value = desired_divisor / iclk_pi_range;
  2931. pi_value = desired_divisor % iclk_pi_range;
  2932. auxdiv = 0;
  2933. divsel = msb_divisor_value - 2;
  2934. phaseinc = pi_value;
  2935. }
  2936. /* This should not happen with any sane values */
  2937. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  2938. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  2939. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  2940. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  2941. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  2942. clock,
  2943. auxdiv,
  2944. divsel,
  2945. phasedir,
  2946. phaseinc);
  2947. /* Program SSCDIVINTPHASE6 */
  2948. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  2949. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  2950. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  2951. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  2952. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  2953. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  2954. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  2955. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  2956. /* Program SSCAUXDIV */
  2957. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  2958. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  2959. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  2960. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  2961. /* Enable modulator and associated divider */
  2962. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  2963. temp &= ~SBI_SSCCTL_DISABLE;
  2964. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  2965. /* Wait for initialization time */
  2966. udelay(24);
  2967. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  2968. mutex_unlock(&dev_priv->dpio_lock);
  2969. }
  2970. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  2971. enum pipe pch_transcoder)
  2972. {
  2973. struct drm_device *dev = crtc->base.dev;
  2974. struct drm_i915_private *dev_priv = dev->dev_private;
  2975. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  2976. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  2977. I915_READ(HTOTAL(cpu_transcoder)));
  2978. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  2979. I915_READ(HBLANK(cpu_transcoder)));
  2980. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  2981. I915_READ(HSYNC(cpu_transcoder)));
  2982. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  2983. I915_READ(VTOTAL(cpu_transcoder)));
  2984. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  2985. I915_READ(VBLANK(cpu_transcoder)));
  2986. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  2987. I915_READ(VSYNC(cpu_transcoder)));
  2988. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  2989. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  2990. }
  2991. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  2992. {
  2993. struct drm_i915_private *dev_priv = dev->dev_private;
  2994. uint32_t temp;
  2995. temp = I915_READ(SOUTH_CHICKEN1);
  2996. if (temp & FDI_BC_BIFURCATION_SELECT)
  2997. return;
  2998. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2999. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  3000. temp |= FDI_BC_BIFURCATION_SELECT;
  3001. DRM_DEBUG_KMS("enabling fdi C rx\n");
  3002. I915_WRITE(SOUTH_CHICKEN1, temp);
  3003. POSTING_READ(SOUTH_CHICKEN1);
  3004. }
  3005. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  3006. {
  3007. struct drm_device *dev = intel_crtc->base.dev;
  3008. struct drm_i915_private *dev_priv = dev->dev_private;
  3009. switch (intel_crtc->pipe) {
  3010. case PIPE_A:
  3011. break;
  3012. case PIPE_B:
  3013. if (intel_crtc->config.fdi_lanes > 2)
  3014. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  3015. else
  3016. cpt_enable_fdi_bc_bifurcation(dev);
  3017. break;
  3018. case PIPE_C:
  3019. cpt_enable_fdi_bc_bifurcation(dev);
  3020. break;
  3021. default:
  3022. BUG();
  3023. }
  3024. }
  3025. /*
  3026. * Enable PCH resources required for PCH ports:
  3027. * - PCH PLLs
  3028. * - FDI training & RX/TX
  3029. * - update transcoder timings
  3030. * - DP transcoding bits
  3031. * - transcoder
  3032. */
  3033. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3034. {
  3035. struct drm_device *dev = crtc->dev;
  3036. struct drm_i915_private *dev_priv = dev->dev_private;
  3037. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3038. int pipe = intel_crtc->pipe;
  3039. u32 reg, temp;
  3040. assert_pch_transcoder_disabled(dev_priv, pipe);
  3041. if (IS_IVYBRIDGE(dev))
  3042. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3043. /* Write the TU size bits before fdi link training, so that error
  3044. * detection works. */
  3045. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3046. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3047. /* For PCH output, training FDI link */
  3048. dev_priv->display.fdi_link_train(crtc);
  3049. /* We need to program the right clock selection before writing the pixel
  3050. * mutliplier into the DPLL. */
  3051. if (HAS_PCH_CPT(dev)) {
  3052. u32 sel;
  3053. temp = I915_READ(PCH_DPLL_SEL);
  3054. temp |= TRANS_DPLL_ENABLE(pipe);
  3055. sel = TRANS_DPLLB_SEL(pipe);
  3056. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3057. temp |= sel;
  3058. else
  3059. temp &= ~sel;
  3060. I915_WRITE(PCH_DPLL_SEL, temp);
  3061. }
  3062. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3063. * transcoder, and we actually should do this to not upset any PCH
  3064. * transcoder that already use the clock when we share it.
  3065. *
  3066. * Note that enable_shared_dpll tries to do the right thing, but
  3067. * get_shared_dpll unconditionally resets the pll - we need that to have
  3068. * the right LVDS enable sequence. */
  3069. intel_enable_shared_dpll(intel_crtc);
  3070. /* set transcoder timing, panel must allow it */
  3071. assert_panel_unlocked(dev_priv, pipe);
  3072. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3073. intel_fdi_normal_train(crtc);
  3074. /* For PCH DP, enable TRANS_DP_CTL */
  3075. if (HAS_PCH_CPT(dev) &&
  3076. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3077. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  3078. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3079. reg = TRANS_DP_CTL(pipe);
  3080. temp = I915_READ(reg);
  3081. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3082. TRANS_DP_SYNC_MASK |
  3083. TRANS_DP_BPC_MASK);
  3084. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3085. TRANS_DP_ENH_FRAMING);
  3086. temp |= bpc << 9; /* same format but at 11:9 */
  3087. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3088. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3089. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3090. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3091. switch (intel_trans_dp_port_sel(crtc)) {
  3092. case PCH_DP_B:
  3093. temp |= TRANS_DP_PORT_SEL_B;
  3094. break;
  3095. case PCH_DP_C:
  3096. temp |= TRANS_DP_PORT_SEL_C;
  3097. break;
  3098. case PCH_DP_D:
  3099. temp |= TRANS_DP_PORT_SEL_D;
  3100. break;
  3101. default:
  3102. BUG();
  3103. }
  3104. I915_WRITE(reg, temp);
  3105. }
  3106. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3107. }
  3108. static void lpt_pch_enable(struct drm_crtc *crtc)
  3109. {
  3110. struct drm_device *dev = crtc->dev;
  3111. struct drm_i915_private *dev_priv = dev->dev_private;
  3112. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3113. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3114. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3115. lpt_program_iclkip(crtc);
  3116. /* Set transcoder timing. */
  3117. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3118. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3119. }
  3120. static void intel_put_shared_dpll(struct intel_crtc *crtc)
  3121. {
  3122. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3123. if (pll == NULL)
  3124. return;
  3125. if (pll->refcount == 0) {
  3126. WARN(1, "bad %s refcount\n", pll->name);
  3127. return;
  3128. }
  3129. if (--pll->refcount == 0) {
  3130. WARN_ON(pll->on);
  3131. WARN_ON(pll->active);
  3132. }
  3133. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3134. }
  3135. static struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3136. {
  3137. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3138. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3139. enum intel_dpll_id i;
  3140. if (pll) {
  3141. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3142. crtc->base.base.id, pll->name);
  3143. intel_put_shared_dpll(crtc);
  3144. }
  3145. if (HAS_PCH_IBX(dev_priv->dev)) {
  3146. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3147. i = (enum intel_dpll_id) crtc->pipe;
  3148. pll = &dev_priv->shared_dplls[i];
  3149. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3150. crtc->base.base.id, pll->name);
  3151. WARN_ON(pll->refcount);
  3152. goto found;
  3153. }
  3154. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3155. pll = &dev_priv->shared_dplls[i];
  3156. /* Only want to check enabled timings first */
  3157. if (pll->refcount == 0)
  3158. continue;
  3159. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3160. sizeof(pll->hw_state)) == 0) {
  3161. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3162. crtc->base.base.id,
  3163. pll->name, pll->refcount, pll->active);
  3164. goto found;
  3165. }
  3166. }
  3167. /* Ok no matching timings, maybe there's a free one? */
  3168. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3169. pll = &dev_priv->shared_dplls[i];
  3170. if (pll->refcount == 0) {
  3171. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3172. crtc->base.base.id, pll->name);
  3173. goto found;
  3174. }
  3175. }
  3176. return NULL;
  3177. found:
  3178. if (pll->refcount == 0)
  3179. pll->hw_state = crtc->config.dpll_hw_state;
  3180. crtc->config.shared_dpll = i;
  3181. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3182. pipe_name(crtc->pipe));
  3183. pll->refcount++;
  3184. return pll;
  3185. }
  3186. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3187. {
  3188. struct drm_i915_private *dev_priv = dev->dev_private;
  3189. int dslreg = PIPEDSL(pipe);
  3190. u32 temp;
  3191. temp = I915_READ(dslreg);
  3192. udelay(500);
  3193. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3194. if (wait_for(I915_READ(dslreg) != temp, 5))
  3195. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3196. }
  3197. }
  3198. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3199. {
  3200. struct drm_device *dev = crtc->base.dev;
  3201. struct drm_i915_private *dev_priv = dev->dev_private;
  3202. int pipe = crtc->pipe;
  3203. if (crtc->config.pch_pfit.enabled) {
  3204. /* Force use of hard-coded filter coefficients
  3205. * as some pre-programmed values are broken,
  3206. * e.g. x201.
  3207. */
  3208. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3209. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3210. PF_PIPE_SEL_IVB(pipe));
  3211. else
  3212. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3213. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3214. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3215. }
  3216. }
  3217. static void intel_enable_planes(struct drm_crtc *crtc)
  3218. {
  3219. struct drm_device *dev = crtc->dev;
  3220. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3221. struct drm_plane *plane;
  3222. struct intel_plane *intel_plane;
  3223. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3224. intel_plane = to_intel_plane(plane);
  3225. if (intel_plane->pipe == pipe)
  3226. intel_plane_restore(&intel_plane->base);
  3227. }
  3228. }
  3229. static void intel_disable_planes(struct drm_crtc *crtc)
  3230. {
  3231. struct drm_device *dev = crtc->dev;
  3232. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3233. struct drm_plane *plane;
  3234. struct intel_plane *intel_plane;
  3235. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3236. intel_plane = to_intel_plane(plane);
  3237. if (intel_plane->pipe == pipe)
  3238. intel_plane_disable(&intel_plane->base);
  3239. }
  3240. }
  3241. void hsw_enable_ips(struct intel_crtc *crtc)
  3242. {
  3243. struct drm_device *dev = crtc->base.dev;
  3244. struct drm_i915_private *dev_priv = dev->dev_private;
  3245. if (!crtc->config.ips_enabled)
  3246. return;
  3247. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3248. intel_wait_for_vblank(dev, crtc->pipe);
  3249. assert_plane_enabled(dev_priv, crtc->plane);
  3250. if (IS_BROADWELL(dev)) {
  3251. mutex_lock(&dev_priv->rps.hw_lock);
  3252. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3253. mutex_unlock(&dev_priv->rps.hw_lock);
  3254. /* Quoting Art Runyan: "its not safe to expect any particular
  3255. * value in IPS_CTL bit 31 after enabling IPS through the
  3256. * mailbox." Moreover, the mailbox may return a bogus state,
  3257. * so we need to just enable it and continue on.
  3258. */
  3259. } else {
  3260. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3261. /* The bit only becomes 1 in the next vblank, so this wait here
  3262. * is essentially intel_wait_for_vblank. If we don't have this
  3263. * and don't wait for vblanks until the end of crtc_enable, then
  3264. * the HW state readout code will complain that the expected
  3265. * IPS_CTL value is not the one we read. */
  3266. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3267. DRM_ERROR("Timed out waiting for IPS enable\n");
  3268. }
  3269. }
  3270. void hsw_disable_ips(struct intel_crtc *crtc)
  3271. {
  3272. struct drm_device *dev = crtc->base.dev;
  3273. struct drm_i915_private *dev_priv = dev->dev_private;
  3274. if (!crtc->config.ips_enabled)
  3275. return;
  3276. assert_plane_enabled(dev_priv, crtc->plane);
  3277. if (IS_BROADWELL(dev)) {
  3278. mutex_lock(&dev_priv->rps.hw_lock);
  3279. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  3280. mutex_unlock(&dev_priv->rps.hw_lock);
  3281. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3282. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3283. DRM_ERROR("Timed out waiting for IPS disable\n");
  3284. } else {
  3285. I915_WRITE(IPS_CTL, 0);
  3286. POSTING_READ(IPS_CTL);
  3287. }
  3288. /* We need to wait for a vblank before we can disable the plane. */
  3289. intel_wait_for_vblank(dev, crtc->pipe);
  3290. }
  3291. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3292. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3293. {
  3294. struct drm_device *dev = crtc->dev;
  3295. struct drm_i915_private *dev_priv = dev->dev_private;
  3296. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3297. enum pipe pipe = intel_crtc->pipe;
  3298. int palreg = PALETTE(pipe);
  3299. int i;
  3300. bool reenable_ips = false;
  3301. /* The clocks have to be on to load the palette. */
  3302. if (!crtc->enabled || !intel_crtc->active)
  3303. return;
  3304. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3305. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3306. assert_dsi_pll_enabled(dev_priv);
  3307. else
  3308. assert_pll_enabled(dev_priv, pipe);
  3309. }
  3310. /* use legacy palette for Ironlake */
  3311. if (HAS_PCH_SPLIT(dev))
  3312. palreg = LGC_PALETTE(pipe);
  3313. /* Workaround : Do not read or write the pipe palette/gamma data while
  3314. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3315. */
  3316. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3317. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3318. GAMMA_MODE_MODE_SPLIT)) {
  3319. hsw_disable_ips(intel_crtc);
  3320. reenable_ips = true;
  3321. }
  3322. for (i = 0; i < 256; i++) {
  3323. I915_WRITE(palreg + 4 * i,
  3324. (intel_crtc->lut_r[i] << 16) |
  3325. (intel_crtc->lut_g[i] << 8) |
  3326. intel_crtc->lut_b[i]);
  3327. }
  3328. if (reenable_ips)
  3329. hsw_enable_ips(intel_crtc);
  3330. }
  3331. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3332. {
  3333. if (!enable && intel_crtc->overlay) {
  3334. struct drm_device *dev = intel_crtc->base.dev;
  3335. struct drm_i915_private *dev_priv = dev->dev_private;
  3336. mutex_lock(&dev->struct_mutex);
  3337. dev_priv->mm.interruptible = false;
  3338. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3339. dev_priv->mm.interruptible = true;
  3340. mutex_unlock(&dev->struct_mutex);
  3341. }
  3342. /* Let userspace switch the overlay on again. In most cases userspace
  3343. * has to recompute where to put it anyway.
  3344. */
  3345. }
  3346. /**
  3347. * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware
  3348. * cursor plane briefly if not already running after enabling the display
  3349. * plane.
  3350. * This workaround avoids occasional blank screens when self refresh is
  3351. * enabled.
  3352. */
  3353. static void
  3354. g4x_fixup_plane(struct drm_i915_private *dev_priv, enum pipe pipe)
  3355. {
  3356. u32 cntl = I915_READ(CURCNTR(pipe));
  3357. if ((cntl & CURSOR_MODE) == 0) {
  3358. u32 fw_bcl_self = I915_READ(FW_BLC_SELF);
  3359. I915_WRITE(FW_BLC_SELF, fw_bcl_self & ~FW_BLC_SELF_EN);
  3360. I915_WRITE(CURCNTR(pipe), CURSOR_MODE_64_ARGB_AX);
  3361. intel_wait_for_vblank(dev_priv->dev, pipe);
  3362. I915_WRITE(CURCNTR(pipe), cntl);
  3363. I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe)));
  3364. I915_WRITE(FW_BLC_SELF, fw_bcl_self);
  3365. }
  3366. }
  3367. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3368. {
  3369. struct drm_device *dev = crtc->dev;
  3370. struct drm_i915_private *dev_priv = dev->dev_private;
  3371. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3372. int pipe = intel_crtc->pipe;
  3373. int plane = intel_crtc->plane;
  3374. drm_vblank_on(dev, pipe);
  3375. intel_enable_primary_hw_plane(dev_priv, plane, pipe);
  3376. intel_enable_planes(crtc);
  3377. /* The fixup needs to happen before cursor is enabled */
  3378. if (IS_G4X(dev))
  3379. g4x_fixup_plane(dev_priv, pipe);
  3380. intel_crtc_update_cursor(crtc, true);
  3381. intel_crtc_dpms_overlay(intel_crtc, true);
  3382. hsw_enable_ips(intel_crtc);
  3383. mutex_lock(&dev->struct_mutex);
  3384. intel_update_fbc(dev);
  3385. mutex_unlock(&dev->struct_mutex);
  3386. /*
  3387. * FIXME: Once we grow proper nuclear flip support out of this we need
  3388. * to compute the mask of flip planes precisely. For the time being
  3389. * consider this a flip from a NULL plane.
  3390. */
  3391. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3392. }
  3393. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3394. {
  3395. struct drm_device *dev = crtc->dev;
  3396. struct drm_i915_private *dev_priv = dev->dev_private;
  3397. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3398. int pipe = intel_crtc->pipe;
  3399. int plane = intel_crtc->plane;
  3400. intel_crtc_wait_for_pending_flips(crtc);
  3401. if (dev_priv->fbc.plane == plane)
  3402. intel_disable_fbc(dev);
  3403. hsw_disable_ips(intel_crtc);
  3404. intel_crtc_dpms_overlay(intel_crtc, false);
  3405. intel_crtc_update_cursor(crtc, false);
  3406. intel_disable_planes(crtc);
  3407. intel_disable_primary_hw_plane(dev_priv, plane, pipe);
  3408. /*
  3409. * FIXME: Once we grow proper nuclear flip support out of this we need
  3410. * to compute the mask of flip planes precisely. For the time being
  3411. * consider this a flip to a NULL plane.
  3412. */
  3413. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3414. drm_vblank_off(dev, pipe);
  3415. }
  3416. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3417. {
  3418. struct drm_device *dev = crtc->dev;
  3419. struct drm_i915_private *dev_priv = dev->dev_private;
  3420. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3421. struct intel_encoder *encoder;
  3422. int pipe = intel_crtc->pipe;
  3423. enum plane plane = intel_crtc->plane;
  3424. WARN_ON(!crtc->enabled);
  3425. if (intel_crtc->active)
  3426. return;
  3427. if (intel_crtc->config.has_pch_encoder)
  3428. intel_prepare_shared_dpll(intel_crtc);
  3429. if (intel_crtc->config.has_dp_encoder)
  3430. intel_dp_set_m_n(intel_crtc);
  3431. intel_set_pipe_timings(intel_crtc);
  3432. if (intel_crtc->config.has_pch_encoder) {
  3433. intel_cpu_transcoder_set_m_n(intel_crtc,
  3434. &intel_crtc->config.fdi_m_n);
  3435. }
  3436. ironlake_set_pipeconf(crtc);
  3437. /* Set up the display plane register */
  3438. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  3439. POSTING_READ(DSPCNTR(plane));
  3440. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3441. crtc->x, crtc->y);
  3442. intel_crtc->active = true;
  3443. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3444. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3445. for_each_encoder_on_crtc(dev, crtc, encoder)
  3446. if (encoder->pre_enable)
  3447. encoder->pre_enable(encoder);
  3448. if (intel_crtc->config.has_pch_encoder) {
  3449. /* Note: FDI PLL enabling _must_ be done before we enable the
  3450. * cpu pipes, hence this is separate from all the other fdi/pch
  3451. * enabling. */
  3452. ironlake_fdi_pll_enable(intel_crtc);
  3453. } else {
  3454. assert_fdi_tx_disabled(dev_priv, pipe);
  3455. assert_fdi_rx_disabled(dev_priv, pipe);
  3456. }
  3457. ironlake_pfit_enable(intel_crtc);
  3458. /*
  3459. * On ILK+ LUT must be loaded before the pipe is running but with
  3460. * clocks enabled
  3461. */
  3462. intel_crtc_load_lut(crtc);
  3463. intel_update_watermarks(crtc);
  3464. intel_enable_pipe(intel_crtc);
  3465. if (intel_crtc->config.has_pch_encoder)
  3466. ironlake_pch_enable(crtc);
  3467. for_each_encoder_on_crtc(dev, crtc, encoder)
  3468. encoder->enable(encoder);
  3469. if (HAS_PCH_CPT(dev))
  3470. cpt_verify_modeset(dev, intel_crtc->pipe);
  3471. intel_crtc_enable_planes(crtc);
  3472. }
  3473. /* IPS only exists on ULT machines and is tied to pipe A. */
  3474. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3475. {
  3476. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3477. }
  3478. /*
  3479. * This implements the workaround described in the "notes" section of the mode
  3480. * set sequence documentation. When going from no pipes or single pipe to
  3481. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3482. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3483. */
  3484. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3485. {
  3486. struct drm_device *dev = crtc->base.dev;
  3487. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3488. /* We want to get the other_active_crtc only if there's only 1 other
  3489. * active crtc. */
  3490. for_each_intel_crtc(dev, crtc_it) {
  3491. if (!crtc_it->active || crtc_it == crtc)
  3492. continue;
  3493. if (other_active_crtc)
  3494. return;
  3495. other_active_crtc = crtc_it;
  3496. }
  3497. if (!other_active_crtc)
  3498. return;
  3499. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3500. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3501. }
  3502. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3503. {
  3504. struct drm_device *dev = crtc->dev;
  3505. struct drm_i915_private *dev_priv = dev->dev_private;
  3506. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3507. struct intel_encoder *encoder;
  3508. int pipe = intel_crtc->pipe;
  3509. enum plane plane = intel_crtc->plane;
  3510. WARN_ON(!crtc->enabled);
  3511. if (intel_crtc->active)
  3512. return;
  3513. if (intel_crtc->config.has_dp_encoder)
  3514. intel_dp_set_m_n(intel_crtc);
  3515. intel_set_pipe_timings(intel_crtc);
  3516. if (intel_crtc->config.has_pch_encoder) {
  3517. intel_cpu_transcoder_set_m_n(intel_crtc,
  3518. &intel_crtc->config.fdi_m_n);
  3519. }
  3520. haswell_set_pipeconf(crtc);
  3521. intel_set_pipe_csc(crtc);
  3522. /* Set up the display plane register */
  3523. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
  3524. POSTING_READ(DSPCNTR(plane));
  3525. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3526. crtc->x, crtc->y);
  3527. intel_crtc->active = true;
  3528. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3529. if (intel_crtc->config.has_pch_encoder)
  3530. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3531. if (intel_crtc->config.has_pch_encoder)
  3532. dev_priv->display.fdi_link_train(crtc);
  3533. for_each_encoder_on_crtc(dev, crtc, encoder)
  3534. if (encoder->pre_enable)
  3535. encoder->pre_enable(encoder);
  3536. intel_ddi_enable_pipe_clock(intel_crtc);
  3537. ironlake_pfit_enable(intel_crtc);
  3538. /*
  3539. * On ILK+ LUT must be loaded before the pipe is running but with
  3540. * clocks enabled
  3541. */
  3542. intel_crtc_load_lut(crtc);
  3543. intel_ddi_set_pipe_settings(crtc);
  3544. intel_ddi_enable_transcoder_func(crtc);
  3545. intel_update_watermarks(crtc);
  3546. intel_enable_pipe(intel_crtc);
  3547. if (intel_crtc->config.has_pch_encoder)
  3548. lpt_pch_enable(crtc);
  3549. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3550. encoder->enable(encoder);
  3551. intel_opregion_notify_encoder(encoder, true);
  3552. }
  3553. /* If we change the relative order between pipe/planes enabling, we need
  3554. * to change the workaround. */
  3555. haswell_mode_set_planes_workaround(intel_crtc);
  3556. intel_crtc_enable_planes(crtc);
  3557. }
  3558. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3559. {
  3560. struct drm_device *dev = crtc->base.dev;
  3561. struct drm_i915_private *dev_priv = dev->dev_private;
  3562. int pipe = crtc->pipe;
  3563. /* To avoid upsetting the power well on haswell only disable the pfit if
  3564. * it's in use. The hw state code will make sure we get this right. */
  3565. if (crtc->config.pch_pfit.enabled) {
  3566. I915_WRITE(PF_CTL(pipe), 0);
  3567. I915_WRITE(PF_WIN_POS(pipe), 0);
  3568. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3569. }
  3570. }
  3571. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3572. {
  3573. struct drm_device *dev = crtc->dev;
  3574. struct drm_i915_private *dev_priv = dev->dev_private;
  3575. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3576. struct intel_encoder *encoder;
  3577. int pipe = intel_crtc->pipe;
  3578. u32 reg, temp;
  3579. if (!intel_crtc->active)
  3580. return;
  3581. intel_crtc_disable_planes(crtc);
  3582. for_each_encoder_on_crtc(dev, crtc, encoder)
  3583. encoder->disable(encoder);
  3584. if (intel_crtc->config.has_pch_encoder)
  3585. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3586. intel_disable_pipe(dev_priv, pipe);
  3587. ironlake_pfit_disable(intel_crtc);
  3588. for_each_encoder_on_crtc(dev, crtc, encoder)
  3589. if (encoder->post_disable)
  3590. encoder->post_disable(encoder);
  3591. if (intel_crtc->config.has_pch_encoder) {
  3592. ironlake_fdi_disable(crtc);
  3593. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3594. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3595. if (HAS_PCH_CPT(dev)) {
  3596. /* disable TRANS_DP_CTL */
  3597. reg = TRANS_DP_CTL(pipe);
  3598. temp = I915_READ(reg);
  3599. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3600. TRANS_DP_PORT_SEL_MASK);
  3601. temp |= TRANS_DP_PORT_SEL_NONE;
  3602. I915_WRITE(reg, temp);
  3603. /* disable DPLL_SEL */
  3604. temp = I915_READ(PCH_DPLL_SEL);
  3605. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3606. I915_WRITE(PCH_DPLL_SEL, temp);
  3607. }
  3608. /* disable PCH DPLL */
  3609. intel_disable_shared_dpll(intel_crtc);
  3610. ironlake_fdi_pll_disable(intel_crtc);
  3611. }
  3612. intel_crtc->active = false;
  3613. intel_update_watermarks(crtc);
  3614. mutex_lock(&dev->struct_mutex);
  3615. intel_update_fbc(dev);
  3616. mutex_unlock(&dev->struct_mutex);
  3617. }
  3618. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3619. {
  3620. struct drm_device *dev = crtc->dev;
  3621. struct drm_i915_private *dev_priv = dev->dev_private;
  3622. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3623. struct intel_encoder *encoder;
  3624. int pipe = intel_crtc->pipe;
  3625. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3626. if (!intel_crtc->active)
  3627. return;
  3628. intel_crtc_disable_planes(crtc);
  3629. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3630. intel_opregion_notify_encoder(encoder, false);
  3631. encoder->disable(encoder);
  3632. }
  3633. if (intel_crtc->config.has_pch_encoder)
  3634. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3635. intel_disable_pipe(dev_priv, pipe);
  3636. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3637. ironlake_pfit_disable(intel_crtc);
  3638. intel_ddi_disable_pipe_clock(intel_crtc);
  3639. for_each_encoder_on_crtc(dev, crtc, encoder)
  3640. if (encoder->post_disable)
  3641. encoder->post_disable(encoder);
  3642. if (intel_crtc->config.has_pch_encoder) {
  3643. lpt_disable_pch_transcoder(dev_priv);
  3644. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3645. intel_ddi_fdi_disable(crtc);
  3646. }
  3647. intel_crtc->active = false;
  3648. intel_update_watermarks(crtc);
  3649. mutex_lock(&dev->struct_mutex);
  3650. intel_update_fbc(dev);
  3651. mutex_unlock(&dev->struct_mutex);
  3652. }
  3653. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3654. {
  3655. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3656. intel_put_shared_dpll(intel_crtc);
  3657. }
  3658. static void haswell_crtc_off(struct drm_crtc *crtc)
  3659. {
  3660. intel_ddi_put_crtc_pll(crtc);
  3661. }
  3662. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3663. {
  3664. struct drm_device *dev = crtc->base.dev;
  3665. struct drm_i915_private *dev_priv = dev->dev_private;
  3666. struct intel_crtc_config *pipe_config = &crtc->config;
  3667. if (!crtc->config.gmch_pfit.control)
  3668. return;
  3669. /*
  3670. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3671. * according to register description and PRM.
  3672. */
  3673. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3674. assert_pipe_disabled(dev_priv, crtc->pipe);
  3675. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3676. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3677. /* Border color in case we don't scale up to the full screen. Black by
  3678. * default, change to something else for debugging. */
  3679. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3680. }
  3681. #define for_each_power_domain(domain, mask) \
  3682. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3683. if ((1 << (domain)) & (mask))
  3684. enum intel_display_power_domain
  3685. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3686. {
  3687. struct drm_device *dev = intel_encoder->base.dev;
  3688. struct intel_digital_port *intel_dig_port;
  3689. switch (intel_encoder->type) {
  3690. case INTEL_OUTPUT_UNKNOWN:
  3691. /* Only DDI platforms should ever use this output type */
  3692. WARN_ON_ONCE(!HAS_DDI(dev));
  3693. case INTEL_OUTPUT_DISPLAYPORT:
  3694. case INTEL_OUTPUT_HDMI:
  3695. case INTEL_OUTPUT_EDP:
  3696. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3697. switch (intel_dig_port->port) {
  3698. case PORT_A:
  3699. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3700. case PORT_B:
  3701. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3702. case PORT_C:
  3703. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3704. case PORT_D:
  3705. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3706. default:
  3707. WARN_ON_ONCE(1);
  3708. return POWER_DOMAIN_PORT_OTHER;
  3709. }
  3710. case INTEL_OUTPUT_ANALOG:
  3711. return POWER_DOMAIN_PORT_CRT;
  3712. case INTEL_OUTPUT_DSI:
  3713. return POWER_DOMAIN_PORT_DSI;
  3714. default:
  3715. return POWER_DOMAIN_PORT_OTHER;
  3716. }
  3717. }
  3718. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3719. {
  3720. struct drm_device *dev = crtc->dev;
  3721. struct intel_encoder *intel_encoder;
  3722. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3723. enum pipe pipe = intel_crtc->pipe;
  3724. bool pfit_enabled = intel_crtc->config.pch_pfit.enabled;
  3725. unsigned long mask;
  3726. enum transcoder transcoder;
  3727. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3728. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3729. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3730. if (pfit_enabled)
  3731. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3732. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3733. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3734. return mask;
  3735. }
  3736. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  3737. bool enable)
  3738. {
  3739. if (dev_priv->power_domains.init_power_on == enable)
  3740. return;
  3741. if (enable)
  3742. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3743. else
  3744. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3745. dev_priv->power_domains.init_power_on = enable;
  3746. }
  3747. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3748. {
  3749. struct drm_i915_private *dev_priv = dev->dev_private;
  3750. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3751. struct intel_crtc *crtc;
  3752. /*
  3753. * First get all needed power domains, then put all unneeded, to avoid
  3754. * any unnecessary toggling of the power wells.
  3755. */
  3756. for_each_intel_crtc(dev, crtc) {
  3757. enum intel_display_power_domain domain;
  3758. if (!crtc->base.enabled)
  3759. continue;
  3760. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3761. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3762. intel_display_power_get(dev_priv, domain);
  3763. }
  3764. for_each_intel_crtc(dev, crtc) {
  3765. enum intel_display_power_domain domain;
  3766. for_each_power_domain(domain, crtc->enabled_power_domains)
  3767. intel_display_power_put(dev_priv, domain);
  3768. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3769. }
  3770. intel_display_set_init_power(dev_priv, false);
  3771. }
  3772. /* returns HPLL frequency in kHz */
  3773. int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3774. {
  3775. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3776. /* Obtain SKU information */
  3777. mutex_lock(&dev_priv->dpio_lock);
  3778. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3779. CCK_FUSE_HPLL_FREQ_MASK;
  3780. mutex_unlock(&dev_priv->dpio_lock);
  3781. return vco_freq[hpll_freq] * 1000;
  3782. }
  3783. /* Adjust CDclk dividers to allow high res or save power if possible */
  3784. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3785. {
  3786. struct drm_i915_private *dev_priv = dev->dev_private;
  3787. u32 val, cmd;
  3788. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3789. dev_priv->vlv_cdclk_freq = cdclk;
  3790. if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
  3791. cmd = 2;
  3792. else if (cdclk == 266667)
  3793. cmd = 1;
  3794. else
  3795. cmd = 0;
  3796. mutex_lock(&dev_priv->rps.hw_lock);
  3797. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3798. val &= ~DSPFREQGUAR_MASK;
  3799. val |= (cmd << DSPFREQGUAR_SHIFT);
  3800. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3801. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3802. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3803. 50)) {
  3804. DRM_ERROR("timed out waiting for CDclk change\n");
  3805. }
  3806. mutex_unlock(&dev_priv->rps.hw_lock);
  3807. if (cdclk == 400000) {
  3808. u32 divider, vco;
  3809. vco = valleyview_get_vco(dev_priv);
  3810. divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1;
  3811. mutex_lock(&dev_priv->dpio_lock);
  3812. /* adjust cdclk divider */
  3813. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3814. val &= ~DISPLAY_FREQUENCY_VALUES;
  3815. val |= divider;
  3816. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3817. mutex_unlock(&dev_priv->dpio_lock);
  3818. }
  3819. mutex_lock(&dev_priv->dpio_lock);
  3820. /* adjust self-refresh exit latency value */
  3821. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3822. val &= ~0x7f;
  3823. /*
  3824. * For high bandwidth configs, we set a higher latency in the bunit
  3825. * so that the core display fetch happens in time to avoid underruns.
  3826. */
  3827. if (cdclk == 400000)
  3828. val |= 4500 / 250; /* 4.5 usec */
  3829. else
  3830. val |= 3000 / 250; /* 3.0 usec */
  3831. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3832. mutex_unlock(&dev_priv->dpio_lock);
  3833. /* Since we changed the CDclk, we need to update the GMBUSFREQ too */
  3834. intel_i2c_reset(dev);
  3835. }
  3836. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3837. int max_pixclk)
  3838. {
  3839. int vco = valleyview_get_vco(dev_priv);
  3840. int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000;
  3841. /*
  3842. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3843. * 200MHz
  3844. * 267MHz
  3845. * 320/333MHz (depends on HPLL freq)
  3846. * 400MHz
  3847. * So we check to see whether we're above 90% of the lower bin and
  3848. * adjust if needed.
  3849. */
  3850. if (max_pixclk > freq_320*9/10)
  3851. return 400000;
  3852. else if (max_pixclk > 266667*9/10)
  3853. return freq_320;
  3854. else
  3855. return 266667;
  3856. /* Looks like the 200MHz CDclk freq doesn't work on some configs */
  3857. }
  3858. /* compute the max pixel clock for new configuration */
  3859. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3860. {
  3861. struct drm_device *dev = dev_priv->dev;
  3862. struct intel_crtc *intel_crtc;
  3863. int max_pixclk = 0;
  3864. for_each_intel_crtc(dev, intel_crtc) {
  3865. if (intel_crtc->new_enabled)
  3866. max_pixclk = max(max_pixclk,
  3867. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3868. }
  3869. return max_pixclk;
  3870. }
  3871. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  3872. unsigned *prepare_pipes)
  3873. {
  3874. struct drm_i915_private *dev_priv = dev->dev_private;
  3875. struct intel_crtc *intel_crtc;
  3876. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3877. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  3878. dev_priv->vlv_cdclk_freq)
  3879. return;
  3880. /* disable/enable all currently active pipes while we change cdclk */
  3881. for_each_intel_crtc(dev, intel_crtc)
  3882. if (intel_crtc->base.enabled)
  3883. *prepare_pipes |= (1 << intel_crtc->pipe);
  3884. }
  3885. static void valleyview_modeset_global_resources(struct drm_device *dev)
  3886. {
  3887. struct drm_i915_private *dev_priv = dev->dev_private;
  3888. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  3889. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  3890. if (req_cdclk != dev_priv->vlv_cdclk_freq)
  3891. valleyview_set_cdclk(dev, req_cdclk);
  3892. modeset_update_crtc_power_domains(dev);
  3893. }
  3894. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  3895. {
  3896. struct drm_device *dev = crtc->dev;
  3897. struct drm_i915_private *dev_priv = dev->dev_private;
  3898. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3899. struct intel_encoder *encoder;
  3900. int pipe = intel_crtc->pipe;
  3901. int plane = intel_crtc->plane;
  3902. bool is_dsi;
  3903. u32 dspcntr;
  3904. WARN_ON(!crtc->enabled);
  3905. if (intel_crtc->active)
  3906. return;
  3907. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  3908. if (!is_dsi && !IS_CHERRYVIEW(dev))
  3909. vlv_prepare_pll(intel_crtc);
  3910. /* Set up the display plane register */
  3911. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3912. if (intel_crtc->config.has_dp_encoder)
  3913. intel_dp_set_m_n(intel_crtc);
  3914. intel_set_pipe_timings(intel_crtc);
  3915. /* pipesrc and dspsize control the size that is scaled from,
  3916. * which should always be the user's requested size.
  3917. */
  3918. I915_WRITE(DSPSIZE(plane),
  3919. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  3920. (intel_crtc->config.pipe_src_w - 1));
  3921. I915_WRITE(DSPPOS(plane), 0);
  3922. i9xx_set_pipeconf(intel_crtc);
  3923. I915_WRITE(DSPCNTR(plane), dspcntr);
  3924. POSTING_READ(DSPCNTR(plane));
  3925. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3926. crtc->x, crtc->y);
  3927. intel_crtc->active = true;
  3928. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3929. for_each_encoder_on_crtc(dev, crtc, encoder)
  3930. if (encoder->pre_pll_enable)
  3931. encoder->pre_pll_enable(encoder);
  3932. if (!is_dsi) {
  3933. if (IS_CHERRYVIEW(dev))
  3934. chv_enable_pll(intel_crtc);
  3935. else
  3936. vlv_enable_pll(intel_crtc);
  3937. }
  3938. for_each_encoder_on_crtc(dev, crtc, encoder)
  3939. if (encoder->pre_enable)
  3940. encoder->pre_enable(encoder);
  3941. i9xx_pfit_enable(intel_crtc);
  3942. intel_crtc_load_lut(crtc);
  3943. intel_update_watermarks(crtc);
  3944. intel_enable_pipe(intel_crtc);
  3945. for_each_encoder_on_crtc(dev, crtc, encoder)
  3946. encoder->enable(encoder);
  3947. intel_crtc_enable_planes(crtc);
  3948. /* Underruns don't raise interrupts, so check manually. */
  3949. i9xx_check_fifo_underruns(dev);
  3950. }
  3951. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  3952. {
  3953. struct drm_device *dev = crtc->base.dev;
  3954. struct drm_i915_private *dev_priv = dev->dev_private;
  3955. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  3956. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  3957. }
  3958. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  3959. {
  3960. struct drm_device *dev = crtc->dev;
  3961. struct drm_i915_private *dev_priv = dev->dev_private;
  3962. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3963. struct intel_encoder *encoder;
  3964. int pipe = intel_crtc->pipe;
  3965. int plane = intel_crtc->plane;
  3966. u32 dspcntr;
  3967. WARN_ON(!crtc->enabled);
  3968. if (intel_crtc->active)
  3969. return;
  3970. i9xx_set_pll_dividers(intel_crtc);
  3971. /* Set up the display plane register */
  3972. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3973. if (pipe == 0)
  3974. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3975. else
  3976. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3977. if (intel_crtc->config.has_dp_encoder)
  3978. intel_dp_set_m_n(intel_crtc);
  3979. intel_set_pipe_timings(intel_crtc);
  3980. /* pipesrc and dspsize control the size that is scaled from,
  3981. * which should always be the user's requested size.
  3982. */
  3983. I915_WRITE(DSPSIZE(plane),
  3984. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  3985. (intel_crtc->config.pipe_src_w - 1));
  3986. I915_WRITE(DSPPOS(plane), 0);
  3987. i9xx_set_pipeconf(intel_crtc);
  3988. I915_WRITE(DSPCNTR(plane), dspcntr);
  3989. POSTING_READ(DSPCNTR(plane));
  3990. dev_priv->display.update_primary_plane(crtc, crtc->primary->fb,
  3991. crtc->x, crtc->y);
  3992. intel_crtc->active = true;
  3993. if (!IS_GEN2(dev))
  3994. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3995. for_each_encoder_on_crtc(dev, crtc, encoder)
  3996. if (encoder->pre_enable)
  3997. encoder->pre_enable(encoder);
  3998. i9xx_enable_pll(intel_crtc);
  3999. i9xx_pfit_enable(intel_crtc);
  4000. intel_crtc_load_lut(crtc);
  4001. intel_update_watermarks(crtc);
  4002. intel_enable_pipe(intel_crtc);
  4003. for_each_encoder_on_crtc(dev, crtc, encoder)
  4004. encoder->enable(encoder);
  4005. intel_crtc_enable_planes(crtc);
  4006. /*
  4007. * Gen2 reports pipe underruns whenever all planes are disabled.
  4008. * So don't enable underrun reporting before at least some planes
  4009. * are enabled.
  4010. * FIXME: Need to fix the logic to work when we turn off all planes
  4011. * but leave the pipe running.
  4012. */
  4013. if (IS_GEN2(dev))
  4014. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4015. /* Underruns don't raise interrupts, so check manually. */
  4016. i9xx_check_fifo_underruns(dev);
  4017. }
  4018. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  4019. {
  4020. struct drm_device *dev = crtc->base.dev;
  4021. struct drm_i915_private *dev_priv = dev->dev_private;
  4022. if (!crtc->config.gmch_pfit.control)
  4023. return;
  4024. assert_pipe_disabled(dev_priv, crtc->pipe);
  4025. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  4026. I915_READ(PFIT_CONTROL));
  4027. I915_WRITE(PFIT_CONTROL, 0);
  4028. }
  4029. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4030. {
  4031. struct drm_device *dev = crtc->dev;
  4032. struct drm_i915_private *dev_priv = dev->dev_private;
  4033. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4034. struct intel_encoder *encoder;
  4035. int pipe = intel_crtc->pipe;
  4036. if (!intel_crtc->active)
  4037. return;
  4038. /*
  4039. * Gen2 reports pipe underruns whenever all planes are disabled.
  4040. * So diasble underrun reporting before all the planes get disabled.
  4041. * FIXME: Need to fix the logic to work when we turn off all planes
  4042. * but leave the pipe running.
  4043. */
  4044. if (IS_GEN2(dev))
  4045. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4046. intel_crtc_disable_planes(crtc);
  4047. for_each_encoder_on_crtc(dev, crtc, encoder)
  4048. encoder->disable(encoder);
  4049. /*
  4050. * On gen2 planes are double buffered but the pipe isn't, so we must
  4051. * wait for planes to fully turn off before disabling the pipe.
  4052. */
  4053. if (IS_GEN2(dev))
  4054. intel_wait_for_vblank(dev, pipe);
  4055. intel_disable_pipe(dev_priv, pipe);
  4056. i9xx_pfit_disable(intel_crtc);
  4057. for_each_encoder_on_crtc(dev, crtc, encoder)
  4058. if (encoder->post_disable)
  4059. encoder->post_disable(encoder);
  4060. if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) {
  4061. if (IS_CHERRYVIEW(dev))
  4062. chv_disable_pll(dev_priv, pipe);
  4063. else if (IS_VALLEYVIEW(dev))
  4064. vlv_disable_pll(dev_priv, pipe);
  4065. else
  4066. i9xx_disable_pll(dev_priv, pipe);
  4067. }
  4068. if (!IS_GEN2(dev))
  4069. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4070. intel_crtc->active = false;
  4071. intel_update_watermarks(crtc);
  4072. mutex_lock(&dev->struct_mutex);
  4073. intel_update_fbc(dev);
  4074. mutex_unlock(&dev->struct_mutex);
  4075. }
  4076. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4077. {
  4078. }
  4079. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4080. bool enabled)
  4081. {
  4082. struct drm_device *dev = crtc->dev;
  4083. struct drm_i915_master_private *master_priv;
  4084. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4085. int pipe = intel_crtc->pipe;
  4086. if (!dev->primary->master)
  4087. return;
  4088. master_priv = dev->primary->master->driver_priv;
  4089. if (!master_priv->sarea_priv)
  4090. return;
  4091. switch (pipe) {
  4092. case 0:
  4093. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4094. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4095. break;
  4096. case 1:
  4097. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4098. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4099. break;
  4100. default:
  4101. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4102. break;
  4103. }
  4104. }
  4105. /**
  4106. * Sets the power management mode of the pipe and plane.
  4107. */
  4108. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4109. {
  4110. struct drm_device *dev = crtc->dev;
  4111. struct drm_i915_private *dev_priv = dev->dev_private;
  4112. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4113. struct intel_encoder *intel_encoder;
  4114. enum intel_display_power_domain domain;
  4115. unsigned long domains;
  4116. bool enable = false;
  4117. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4118. enable |= intel_encoder->connectors_active;
  4119. if (enable) {
  4120. if (!intel_crtc->active) {
  4121. /*
  4122. * FIXME: DDI plls and relevant code isn't converted
  4123. * yet, so do runtime PM for DPMS only for all other
  4124. * platforms for now.
  4125. */
  4126. if (!HAS_DDI(dev)) {
  4127. domains = get_crtc_power_domains(crtc);
  4128. for_each_power_domain(domain, domains)
  4129. intel_display_power_get(dev_priv, domain);
  4130. intel_crtc->enabled_power_domains = domains;
  4131. }
  4132. dev_priv->display.crtc_enable(crtc);
  4133. }
  4134. } else {
  4135. if (intel_crtc->active) {
  4136. dev_priv->display.crtc_disable(crtc);
  4137. if (!HAS_DDI(dev)) {
  4138. domains = intel_crtc->enabled_power_domains;
  4139. for_each_power_domain(domain, domains)
  4140. intel_display_power_put(dev_priv, domain);
  4141. intel_crtc->enabled_power_domains = 0;
  4142. }
  4143. }
  4144. }
  4145. intel_crtc_update_sarea(crtc, enable);
  4146. }
  4147. static void intel_crtc_disable(struct drm_crtc *crtc)
  4148. {
  4149. struct drm_device *dev = crtc->dev;
  4150. struct drm_connector *connector;
  4151. struct drm_i915_private *dev_priv = dev->dev_private;
  4152. struct drm_i915_gem_object *old_obj;
  4153. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4154. /* crtc should still be enabled when we disable it. */
  4155. WARN_ON(!crtc->enabled);
  4156. dev_priv->display.crtc_disable(crtc);
  4157. intel_crtc_update_sarea(crtc, false);
  4158. dev_priv->display.off(crtc);
  4159. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  4160. assert_cursor_disabled(dev_priv, pipe);
  4161. assert_pipe_disabled(dev->dev_private, pipe);
  4162. if (crtc->primary->fb) {
  4163. old_obj = to_intel_framebuffer(crtc->primary->fb)->obj;
  4164. mutex_lock(&dev->struct_mutex);
  4165. intel_unpin_fb_obj(old_obj);
  4166. i915_gem_track_fb(old_obj, NULL,
  4167. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4168. mutex_unlock(&dev->struct_mutex);
  4169. crtc->primary->fb = NULL;
  4170. }
  4171. /* Update computed state. */
  4172. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4173. if (!connector->encoder || !connector->encoder->crtc)
  4174. continue;
  4175. if (connector->encoder->crtc != crtc)
  4176. continue;
  4177. connector->dpms = DRM_MODE_DPMS_OFF;
  4178. to_intel_encoder(connector->encoder)->connectors_active = false;
  4179. }
  4180. }
  4181. void intel_encoder_destroy(struct drm_encoder *encoder)
  4182. {
  4183. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4184. drm_encoder_cleanup(encoder);
  4185. kfree(intel_encoder);
  4186. }
  4187. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4188. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4189. * state of the entire output pipe. */
  4190. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4191. {
  4192. if (mode == DRM_MODE_DPMS_ON) {
  4193. encoder->connectors_active = true;
  4194. intel_crtc_update_dpms(encoder->base.crtc);
  4195. } else {
  4196. encoder->connectors_active = false;
  4197. intel_crtc_update_dpms(encoder->base.crtc);
  4198. }
  4199. }
  4200. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4201. * internal consistency). */
  4202. static void intel_connector_check_state(struct intel_connector *connector)
  4203. {
  4204. if (connector->get_hw_state(connector)) {
  4205. struct intel_encoder *encoder = connector->encoder;
  4206. struct drm_crtc *crtc;
  4207. bool encoder_enabled;
  4208. enum pipe pipe;
  4209. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4210. connector->base.base.id,
  4211. connector->base.name);
  4212. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4213. "wrong connector dpms state\n");
  4214. WARN(connector->base.encoder != &encoder->base,
  4215. "active connector not linked to encoder\n");
  4216. WARN(!encoder->connectors_active,
  4217. "encoder->connectors_active not set\n");
  4218. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4219. WARN(!encoder_enabled, "encoder not enabled\n");
  4220. if (WARN_ON(!encoder->base.crtc))
  4221. return;
  4222. crtc = encoder->base.crtc;
  4223. WARN(!crtc->enabled, "crtc not enabled\n");
  4224. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4225. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4226. "encoder active on the wrong pipe\n");
  4227. }
  4228. }
  4229. /* Even simpler default implementation, if there's really no special case to
  4230. * consider. */
  4231. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4232. {
  4233. /* All the simple cases only support two dpms states. */
  4234. if (mode != DRM_MODE_DPMS_ON)
  4235. mode = DRM_MODE_DPMS_OFF;
  4236. if (mode == connector->dpms)
  4237. return;
  4238. connector->dpms = mode;
  4239. /* Only need to change hw state when actually enabled */
  4240. if (connector->encoder)
  4241. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4242. intel_modeset_check_state(connector->dev);
  4243. }
  4244. /* Simple connector->get_hw_state implementation for encoders that support only
  4245. * one connector and no cloning and hence the encoder state determines the state
  4246. * of the connector. */
  4247. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4248. {
  4249. enum pipe pipe = 0;
  4250. struct intel_encoder *encoder = connector->encoder;
  4251. return encoder->get_hw_state(encoder, &pipe);
  4252. }
  4253. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4254. struct intel_crtc_config *pipe_config)
  4255. {
  4256. struct drm_i915_private *dev_priv = dev->dev_private;
  4257. struct intel_crtc *pipe_B_crtc =
  4258. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4259. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4260. pipe_name(pipe), pipe_config->fdi_lanes);
  4261. if (pipe_config->fdi_lanes > 4) {
  4262. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4263. pipe_name(pipe), pipe_config->fdi_lanes);
  4264. return false;
  4265. }
  4266. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4267. if (pipe_config->fdi_lanes > 2) {
  4268. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4269. pipe_config->fdi_lanes);
  4270. return false;
  4271. } else {
  4272. return true;
  4273. }
  4274. }
  4275. if (INTEL_INFO(dev)->num_pipes == 2)
  4276. return true;
  4277. /* Ivybridge 3 pipe is really complicated */
  4278. switch (pipe) {
  4279. case PIPE_A:
  4280. return true;
  4281. case PIPE_B:
  4282. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4283. pipe_config->fdi_lanes > 2) {
  4284. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4285. pipe_name(pipe), pipe_config->fdi_lanes);
  4286. return false;
  4287. }
  4288. return true;
  4289. case PIPE_C:
  4290. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4291. pipe_B_crtc->config.fdi_lanes <= 2) {
  4292. if (pipe_config->fdi_lanes > 2) {
  4293. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4294. pipe_name(pipe), pipe_config->fdi_lanes);
  4295. return false;
  4296. }
  4297. } else {
  4298. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4299. return false;
  4300. }
  4301. return true;
  4302. default:
  4303. BUG();
  4304. }
  4305. }
  4306. #define RETRY 1
  4307. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4308. struct intel_crtc_config *pipe_config)
  4309. {
  4310. struct drm_device *dev = intel_crtc->base.dev;
  4311. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4312. int lane, link_bw, fdi_dotclock;
  4313. bool setup_ok, needs_recompute = false;
  4314. retry:
  4315. /* FDI is a binary signal running at ~2.7GHz, encoding
  4316. * each output octet as 10 bits. The actual frequency
  4317. * is stored as a divider into a 100MHz clock, and the
  4318. * mode pixel clock is stored in units of 1KHz.
  4319. * Hence the bw of each lane in terms of the mode signal
  4320. * is:
  4321. */
  4322. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4323. fdi_dotclock = adjusted_mode->crtc_clock;
  4324. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4325. pipe_config->pipe_bpp);
  4326. pipe_config->fdi_lanes = lane;
  4327. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4328. link_bw, &pipe_config->fdi_m_n);
  4329. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4330. intel_crtc->pipe, pipe_config);
  4331. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4332. pipe_config->pipe_bpp -= 2*3;
  4333. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4334. pipe_config->pipe_bpp);
  4335. needs_recompute = true;
  4336. pipe_config->bw_constrained = true;
  4337. goto retry;
  4338. }
  4339. if (needs_recompute)
  4340. return RETRY;
  4341. return setup_ok ? 0 : -EINVAL;
  4342. }
  4343. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4344. struct intel_crtc_config *pipe_config)
  4345. {
  4346. pipe_config->ips_enabled = i915.enable_ips &&
  4347. hsw_crtc_supports_ips(crtc) &&
  4348. pipe_config->pipe_bpp <= 24;
  4349. }
  4350. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4351. struct intel_crtc_config *pipe_config)
  4352. {
  4353. struct drm_device *dev = crtc->base.dev;
  4354. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4355. /* FIXME should check pixel clock limits on all platforms */
  4356. if (INTEL_INFO(dev)->gen < 4) {
  4357. struct drm_i915_private *dev_priv = dev->dev_private;
  4358. int clock_limit =
  4359. dev_priv->display.get_display_clock_speed(dev);
  4360. /*
  4361. * Enable pixel doubling when the dot clock
  4362. * is > 90% of the (display) core speed.
  4363. *
  4364. * GDG double wide on either pipe,
  4365. * otherwise pipe A only.
  4366. */
  4367. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4368. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4369. clock_limit *= 2;
  4370. pipe_config->double_wide = true;
  4371. }
  4372. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4373. return -EINVAL;
  4374. }
  4375. /*
  4376. * Pipe horizontal size must be even in:
  4377. * - DVO ganged mode
  4378. * - LVDS dual channel mode
  4379. * - Double wide pipe
  4380. */
  4381. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4382. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4383. pipe_config->pipe_src_w &= ~1;
  4384. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4385. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4386. */
  4387. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4388. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4389. return -EINVAL;
  4390. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4391. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4392. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4393. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4394. * for lvds. */
  4395. pipe_config->pipe_bpp = 8*3;
  4396. }
  4397. if (HAS_IPS(dev))
  4398. hsw_compute_ips_config(crtc, pipe_config);
  4399. /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old
  4400. * clock survives for now. */
  4401. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  4402. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4403. if (pipe_config->has_pch_encoder)
  4404. return ironlake_fdi_compute_config(crtc, pipe_config);
  4405. return 0;
  4406. }
  4407. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4408. {
  4409. struct drm_i915_private *dev_priv = dev->dev_private;
  4410. int vco = valleyview_get_vco(dev_priv);
  4411. u32 val;
  4412. int divider;
  4413. mutex_lock(&dev_priv->dpio_lock);
  4414. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  4415. mutex_unlock(&dev_priv->dpio_lock);
  4416. divider = val & DISPLAY_FREQUENCY_VALUES;
  4417. return DIV_ROUND_CLOSEST(vco << 1, divider + 1);
  4418. }
  4419. static int i945_get_display_clock_speed(struct drm_device *dev)
  4420. {
  4421. return 400000;
  4422. }
  4423. static int i915_get_display_clock_speed(struct drm_device *dev)
  4424. {
  4425. return 333000;
  4426. }
  4427. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4428. {
  4429. return 200000;
  4430. }
  4431. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4432. {
  4433. u16 gcfgc = 0;
  4434. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4435. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4436. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4437. return 267000;
  4438. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4439. return 333000;
  4440. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4441. return 444000;
  4442. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4443. return 200000;
  4444. default:
  4445. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4446. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4447. return 133000;
  4448. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4449. return 167000;
  4450. }
  4451. }
  4452. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4453. {
  4454. u16 gcfgc = 0;
  4455. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4456. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4457. return 133000;
  4458. else {
  4459. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4460. case GC_DISPLAY_CLOCK_333_MHZ:
  4461. return 333000;
  4462. default:
  4463. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4464. return 190000;
  4465. }
  4466. }
  4467. }
  4468. static int i865_get_display_clock_speed(struct drm_device *dev)
  4469. {
  4470. return 266000;
  4471. }
  4472. static int i855_get_display_clock_speed(struct drm_device *dev)
  4473. {
  4474. u16 hpllcc = 0;
  4475. /* Assume that the hardware is in the high speed state. This
  4476. * should be the default.
  4477. */
  4478. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4479. case GC_CLOCK_133_200:
  4480. case GC_CLOCK_100_200:
  4481. return 200000;
  4482. case GC_CLOCK_166_250:
  4483. return 250000;
  4484. case GC_CLOCK_100_133:
  4485. return 133000;
  4486. }
  4487. /* Shouldn't happen */
  4488. return 0;
  4489. }
  4490. static int i830_get_display_clock_speed(struct drm_device *dev)
  4491. {
  4492. return 133000;
  4493. }
  4494. static void
  4495. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4496. {
  4497. while (*num > DATA_LINK_M_N_MASK ||
  4498. *den > DATA_LINK_M_N_MASK) {
  4499. *num >>= 1;
  4500. *den >>= 1;
  4501. }
  4502. }
  4503. static void compute_m_n(unsigned int m, unsigned int n,
  4504. uint32_t *ret_m, uint32_t *ret_n)
  4505. {
  4506. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4507. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4508. intel_reduce_m_n_ratio(ret_m, ret_n);
  4509. }
  4510. void
  4511. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4512. int pixel_clock, int link_clock,
  4513. struct intel_link_m_n *m_n)
  4514. {
  4515. m_n->tu = 64;
  4516. compute_m_n(bits_per_pixel * pixel_clock,
  4517. link_clock * nlanes * 8,
  4518. &m_n->gmch_m, &m_n->gmch_n);
  4519. compute_m_n(pixel_clock, link_clock,
  4520. &m_n->link_m, &m_n->link_n);
  4521. }
  4522. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4523. {
  4524. if (i915.panel_use_ssc >= 0)
  4525. return i915.panel_use_ssc != 0;
  4526. return dev_priv->vbt.lvds_use_ssc
  4527. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4528. }
  4529. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4530. {
  4531. struct drm_device *dev = crtc->dev;
  4532. struct drm_i915_private *dev_priv = dev->dev_private;
  4533. int refclk;
  4534. if (IS_VALLEYVIEW(dev)) {
  4535. refclk = 100000;
  4536. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4537. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4538. refclk = dev_priv->vbt.lvds_ssc_freq;
  4539. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4540. } else if (!IS_GEN2(dev)) {
  4541. refclk = 96000;
  4542. } else {
  4543. refclk = 48000;
  4544. }
  4545. return refclk;
  4546. }
  4547. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4548. {
  4549. return (1 << dpll->n) << 16 | dpll->m2;
  4550. }
  4551. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4552. {
  4553. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4554. }
  4555. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4556. intel_clock_t *reduced_clock)
  4557. {
  4558. struct drm_device *dev = crtc->base.dev;
  4559. u32 fp, fp2 = 0;
  4560. if (IS_PINEVIEW(dev)) {
  4561. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4562. if (reduced_clock)
  4563. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4564. } else {
  4565. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4566. if (reduced_clock)
  4567. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4568. }
  4569. crtc->config.dpll_hw_state.fp0 = fp;
  4570. crtc->lowfreq_avail = false;
  4571. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4572. reduced_clock && i915.powersave) {
  4573. crtc->config.dpll_hw_state.fp1 = fp2;
  4574. crtc->lowfreq_avail = true;
  4575. } else {
  4576. crtc->config.dpll_hw_state.fp1 = fp;
  4577. }
  4578. }
  4579. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4580. pipe)
  4581. {
  4582. u32 reg_val;
  4583. /*
  4584. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4585. * and set it to a reasonable value instead.
  4586. */
  4587. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4588. reg_val &= 0xffffff00;
  4589. reg_val |= 0x00000030;
  4590. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4591. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4592. reg_val &= 0x8cffffff;
  4593. reg_val = 0x8c000000;
  4594. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4595. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4596. reg_val &= 0xffffff00;
  4597. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4598. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4599. reg_val &= 0x00ffffff;
  4600. reg_val |= 0xb0000000;
  4601. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4602. }
  4603. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4604. struct intel_link_m_n *m_n)
  4605. {
  4606. struct drm_device *dev = crtc->base.dev;
  4607. struct drm_i915_private *dev_priv = dev->dev_private;
  4608. int pipe = crtc->pipe;
  4609. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4610. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4611. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4612. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4613. }
  4614. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4615. struct intel_link_m_n *m_n)
  4616. {
  4617. struct drm_device *dev = crtc->base.dev;
  4618. struct drm_i915_private *dev_priv = dev->dev_private;
  4619. int pipe = crtc->pipe;
  4620. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4621. if (INTEL_INFO(dev)->gen >= 5) {
  4622. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4623. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4624. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4625. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4626. } else {
  4627. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4628. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4629. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4630. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4631. }
  4632. }
  4633. static void intel_dp_set_m_n(struct intel_crtc *crtc)
  4634. {
  4635. if (crtc->config.has_pch_encoder)
  4636. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4637. else
  4638. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4639. }
  4640. static void vlv_update_pll(struct intel_crtc *crtc)
  4641. {
  4642. u32 dpll, dpll_md;
  4643. /*
  4644. * Enable DPIO clock input. We should never disable the reference
  4645. * clock for pipe B, since VGA hotplug / manual detection depends
  4646. * on it.
  4647. */
  4648. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4649. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4650. /* We should never disable this, set it here for state tracking */
  4651. if (crtc->pipe == PIPE_B)
  4652. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4653. dpll |= DPLL_VCO_ENABLE;
  4654. crtc->config.dpll_hw_state.dpll = dpll;
  4655. dpll_md = (crtc->config.pixel_multiplier - 1)
  4656. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4657. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4658. }
  4659. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4660. {
  4661. struct drm_device *dev = crtc->base.dev;
  4662. struct drm_i915_private *dev_priv = dev->dev_private;
  4663. int pipe = crtc->pipe;
  4664. u32 mdiv;
  4665. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4666. u32 coreclk, reg_val;
  4667. mutex_lock(&dev_priv->dpio_lock);
  4668. bestn = crtc->config.dpll.n;
  4669. bestm1 = crtc->config.dpll.m1;
  4670. bestm2 = crtc->config.dpll.m2;
  4671. bestp1 = crtc->config.dpll.p1;
  4672. bestp2 = crtc->config.dpll.p2;
  4673. /* See eDP HDMI DPIO driver vbios notes doc */
  4674. /* PLL B needs special handling */
  4675. if (pipe == PIPE_B)
  4676. vlv_pllb_recal_opamp(dev_priv, pipe);
  4677. /* Set up Tx target for periodic Rcomp update */
  4678. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4679. /* Disable target IRef on PLL */
  4680. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4681. reg_val &= 0x00ffffff;
  4682. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4683. /* Disable fast lock */
  4684. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4685. /* Set idtafcrecal before PLL is enabled */
  4686. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4687. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4688. mdiv |= ((bestn << DPIO_N_SHIFT));
  4689. mdiv |= (1 << DPIO_K_SHIFT);
  4690. /*
  4691. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4692. * but we don't support that).
  4693. * Note: don't use the DAC post divider as it seems unstable.
  4694. */
  4695. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4696. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4697. mdiv |= DPIO_ENABLE_CALIBRATION;
  4698. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4699. /* Set HBR and RBR LPF coefficients */
  4700. if (crtc->config.port_clock == 162000 ||
  4701. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4702. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4703. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4704. 0x009f0003);
  4705. else
  4706. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4707. 0x00d0000f);
  4708. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4709. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4710. /* Use SSC source */
  4711. if (pipe == PIPE_A)
  4712. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4713. 0x0df40000);
  4714. else
  4715. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4716. 0x0df70000);
  4717. } else { /* HDMI or VGA */
  4718. /* Use bend source */
  4719. if (pipe == PIPE_A)
  4720. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4721. 0x0df70000);
  4722. else
  4723. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4724. 0x0df40000);
  4725. }
  4726. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4727. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4728. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4729. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4730. coreclk |= 0x01000000;
  4731. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4732. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4733. mutex_unlock(&dev_priv->dpio_lock);
  4734. }
  4735. static void chv_update_pll(struct intel_crtc *crtc)
  4736. {
  4737. struct drm_device *dev = crtc->base.dev;
  4738. struct drm_i915_private *dev_priv = dev->dev_private;
  4739. int pipe = crtc->pipe;
  4740. int dpll_reg = DPLL(crtc->pipe);
  4741. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4742. u32 loopfilter, intcoeff;
  4743. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4744. int refclk;
  4745. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4746. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4747. DPLL_VCO_ENABLE;
  4748. if (pipe != PIPE_A)
  4749. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4750. crtc->config.dpll_hw_state.dpll_md =
  4751. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4752. bestn = crtc->config.dpll.n;
  4753. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4754. bestm1 = crtc->config.dpll.m1;
  4755. bestm2 = crtc->config.dpll.m2 >> 22;
  4756. bestp1 = crtc->config.dpll.p1;
  4757. bestp2 = crtc->config.dpll.p2;
  4758. /*
  4759. * Enable Refclk and SSC
  4760. */
  4761. I915_WRITE(dpll_reg,
  4762. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4763. mutex_lock(&dev_priv->dpio_lock);
  4764. /* p1 and p2 divider */
  4765. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4766. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4767. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4768. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4769. 1 << DPIO_CHV_K_DIV_SHIFT);
  4770. /* Feedback post-divider - m2 */
  4771. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4772. /* Feedback refclk divider - n and m1 */
  4773. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4774. DPIO_CHV_M1_DIV_BY_2 |
  4775. 1 << DPIO_CHV_N_DIV_SHIFT);
  4776. /* M2 fraction division */
  4777. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4778. /* M2 fraction division enable */
  4779. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4780. DPIO_CHV_FRAC_DIV_EN |
  4781. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4782. /* Loop filter */
  4783. refclk = i9xx_get_refclk(&crtc->base, 0);
  4784. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4785. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4786. if (refclk == 100000)
  4787. intcoeff = 11;
  4788. else if (refclk == 38400)
  4789. intcoeff = 10;
  4790. else
  4791. intcoeff = 9;
  4792. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4793. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4794. /* AFC Recal */
  4795. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4796. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4797. DPIO_AFC_RECAL);
  4798. mutex_unlock(&dev_priv->dpio_lock);
  4799. }
  4800. static void i9xx_update_pll(struct intel_crtc *crtc,
  4801. intel_clock_t *reduced_clock,
  4802. int num_connectors)
  4803. {
  4804. struct drm_device *dev = crtc->base.dev;
  4805. struct drm_i915_private *dev_priv = dev->dev_private;
  4806. u32 dpll;
  4807. bool is_sdvo;
  4808. struct dpll *clock = &crtc->config.dpll;
  4809. i9xx_update_pll_dividers(crtc, reduced_clock);
  4810. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4811. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4812. dpll = DPLL_VGA_MODE_DIS;
  4813. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4814. dpll |= DPLLB_MODE_LVDS;
  4815. else
  4816. dpll |= DPLLB_MODE_DAC_SERIAL;
  4817. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4818. dpll |= (crtc->config.pixel_multiplier - 1)
  4819. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4820. }
  4821. if (is_sdvo)
  4822. dpll |= DPLL_SDVO_HIGH_SPEED;
  4823. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4824. dpll |= DPLL_SDVO_HIGH_SPEED;
  4825. /* compute bitmask from p1 value */
  4826. if (IS_PINEVIEW(dev))
  4827. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4828. else {
  4829. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4830. if (IS_G4X(dev) && reduced_clock)
  4831. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4832. }
  4833. switch (clock->p2) {
  4834. case 5:
  4835. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4836. break;
  4837. case 7:
  4838. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4839. break;
  4840. case 10:
  4841. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4842. break;
  4843. case 14:
  4844. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4845. break;
  4846. }
  4847. if (INTEL_INFO(dev)->gen >= 4)
  4848. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4849. if (crtc->config.sdvo_tv_clock)
  4850. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4851. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4852. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4853. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4854. else
  4855. dpll |= PLL_REF_INPUT_DREFCLK;
  4856. dpll |= DPLL_VCO_ENABLE;
  4857. crtc->config.dpll_hw_state.dpll = dpll;
  4858. if (INTEL_INFO(dev)->gen >= 4) {
  4859. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4860. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4861. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4862. }
  4863. }
  4864. static void i8xx_update_pll(struct intel_crtc *crtc,
  4865. intel_clock_t *reduced_clock,
  4866. int num_connectors)
  4867. {
  4868. struct drm_device *dev = crtc->base.dev;
  4869. struct drm_i915_private *dev_priv = dev->dev_private;
  4870. u32 dpll;
  4871. struct dpll *clock = &crtc->config.dpll;
  4872. i9xx_update_pll_dividers(crtc, reduced_clock);
  4873. dpll = DPLL_VGA_MODE_DIS;
  4874. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  4875. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4876. } else {
  4877. if (clock->p1 == 2)
  4878. dpll |= PLL_P1_DIVIDE_BY_TWO;
  4879. else
  4880. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4881. if (clock->p2 == 4)
  4882. dpll |= PLL_P2_DIVIDE_BY_4;
  4883. }
  4884. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  4885. dpll |= DPLL_DVO_2X_MODE;
  4886. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4887. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4888. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4889. else
  4890. dpll |= PLL_REF_INPUT_DREFCLK;
  4891. dpll |= DPLL_VCO_ENABLE;
  4892. crtc->config.dpll_hw_state.dpll = dpll;
  4893. }
  4894. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  4895. {
  4896. struct drm_device *dev = intel_crtc->base.dev;
  4897. struct drm_i915_private *dev_priv = dev->dev_private;
  4898. enum pipe pipe = intel_crtc->pipe;
  4899. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  4900. struct drm_display_mode *adjusted_mode =
  4901. &intel_crtc->config.adjusted_mode;
  4902. uint32_t crtc_vtotal, crtc_vblank_end;
  4903. int vsyncshift = 0;
  4904. /* We need to be careful not to changed the adjusted mode, for otherwise
  4905. * the hw state checker will get angry at the mismatch. */
  4906. crtc_vtotal = adjusted_mode->crtc_vtotal;
  4907. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  4908. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  4909. /* the chip adds 2 halflines automatically */
  4910. crtc_vtotal -= 1;
  4911. crtc_vblank_end -= 1;
  4912. if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  4913. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  4914. else
  4915. vsyncshift = adjusted_mode->crtc_hsync_start -
  4916. adjusted_mode->crtc_htotal / 2;
  4917. if (vsyncshift < 0)
  4918. vsyncshift += adjusted_mode->crtc_htotal;
  4919. }
  4920. if (INTEL_INFO(dev)->gen > 3)
  4921. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  4922. I915_WRITE(HTOTAL(cpu_transcoder),
  4923. (adjusted_mode->crtc_hdisplay - 1) |
  4924. ((adjusted_mode->crtc_htotal - 1) << 16));
  4925. I915_WRITE(HBLANK(cpu_transcoder),
  4926. (adjusted_mode->crtc_hblank_start - 1) |
  4927. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  4928. I915_WRITE(HSYNC(cpu_transcoder),
  4929. (adjusted_mode->crtc_hsync_start - 1) |
  4930. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  4931. I915_WRITE(VTOTAL(cpu_transcoder),
  4932. (adjusted_mode->crtc_vdisplay - 1) |
  4933. ((crtc_vtotal - 1) << 16));
  4934. I915_WRITE(VBLANK(cpu_transcoder),
  4935. (adjusted_mode->crtc_vblank_start - 1) |
  4936. ((crtc_vblank_end - 1) << 16));
  4937. I915_WRITE(VSYNC(cpu_transcoder),
  4938. (adjusted_mode->crtc_vsync_start - 1) |
  4939. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  4940. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  4941. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  4942. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  4943. * bits. */
  4944. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  4945. (pipe == PIPE_B || pipe == PIPE_C))
  4946. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  4947. /* pipesrc controls the size that is scaled from, which should
  4948. * always be the user's requested size.
  4949. */
  4950. I915_WRITE(PIPESRC(pipe),
  4951. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  4952. (intel_crtc->config.pipe_src_h - 1));
  4953. }
  4954. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  4955. struct intel_crtc_config *pipe_config)
  4956. {
  4957. struct drm_device *dev = crtc->base.dev;
  4958. struct drm_i915_private *dev_priv = dev->dev_private;
  4959. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  4960. uint32_t tmp;
  4961. tmp = I915_READ(HTOTAL(cpu_transcoder));
  4962. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  4963. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  4964. tmp = I915_READ(HBLANK(cpu_transcoder));
  4965. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  4966. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  4967. tmp = I915_READ(HSYNC(cpu_transcoder));
  4968. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  4969. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  4970. tmp = I915_READ(VTOTAL(cpu_transcoder));
  4971. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  4972. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  4973. tmp = I915_READ(VBLANK(cpu_transcoder));
  4974. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  4975. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  4976. tmp = I915_READ(VSYNC(cpu_transcoder));
  4977. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  4978. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  4979. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  4980. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  4981. pipe_config->adjusted_mode.crtc_vtotal += 1;
  4982. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  4983. }
  4984. tmp = I915_READ(PIPESRC(crtc->pipe));
  4985. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  4986. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  4987. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  4988. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  4989. }
  4990. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  4991. struct intel_crtc_config *pipe_config)
  4992. {
  4993. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  4994. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  4995. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  4996. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  4997. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  4998. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  4999. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  5000. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  5001. mode->flags = pipe_config->adjusted_mode.flags;
  5002. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  5003. mode->flags |= pipe_config->adjusted_mode.flags;
  5004. }
  5005. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  5006. {
  5007. struct drm_device *dev = intel_crtc->base.dev;
  5008. struct drm_i915_private *dev_priv = dev->dev_private;
  5009. uint32_t pipeconf;
  5010. pipeconf = 0;
  5011. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  5012. I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE)
  5013. pipeconf |= PIPECONF_ENABLE;
  5014. if (intel_crtc->config.double_wide)
  5015. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5016. /* only g4x and later have fancy bpc/dither controls */
  5017. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5018. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5019. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5020. pipeconf |= PIPECONF_DITHER_EN |
  5021. PIPECONF_DITHER_TYPE_SP;
  5022. switch (intel_crtc->config.pipe_bpp) {
  5023. case 18:
  5024. pipeconf |= PIPECONF_6BPC;
  5025. break;
  5026. case 24:
  5027. pipeconf |= PIPECONF_8BPC;
  5028. break;
  5029. case 30:
  5030. pipeconf |= PIPECONF_10BPC;
  5031. break;
  5032. default:
  5033. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5034. BUG();
  5035. }
  5036. }
  5037. if (HAS_PIPE_CXSR(dev)) {
  5038. if (intel_crtc->lowfreq_avail) {
  5039. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5040. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5041. } else {
  5042. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5043. }
  5044. }
  5045. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5046. if (INTEL_INFO(dev)->gen < 4 ||
  5047. intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5048. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5049. else
  5050. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5051. } else
  5052. pipeconf |= PIPECONF_PROGRESSIVE;
  5053. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5054. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5055. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5056. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5057. }
  5058. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  5059. int x, int y,
  5060. struct drm_framebuffer *fb)
  5061. {
  5062. struct drm_device *dev = crtc->dev;
  5063. struct drm_i915_private *dev_priv = dev->dev_private;
  5064. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5065. int refclk, num_connectors = 0;
  5066. intel_clock_t clock, reduced_clock;
  5067. bool ok, has_reduced_clock = false;
  5068. bool is_lvds = false, is_dsi = false;
  5069. struct intel_encoder *encoder;
  5070. const intel_limit_t *limit;
  5071. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5072. switch (encoder->type) {
  5073. case INTEL_OUTPUT_LVDS:
  5074. is_lvds = true;
  5075. break;
  5076. case INTEL_OUTPUT_DSI:
  5077. is_dsi = true;
  5078. break;
  5079. }
  5080. num_connectors++;
  5081. }
  5082. if (is_dsi)
  5083. return 0;
  5084. if (!intel_crtc->config.clock_set) {
  5085. refclk = i9xx_get_refclk(crtc, num_connectors);
  5086. /*
  5087. * Returns a set of divisors for the desired target clock with
  5088. * the given refclk, or FALSE. The returned values represent
  5089. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5090. * 2) / p1 / p2.
  5091. */
  5092. limit = intel_limit(crtc, refclk);
  5093. ok = dev_priv->display.find_dpll(limit, crtc,
  5094. intel_crtc->config.port_clock,
  5095. refclk, NULL, &clock);
  5096. if (!ok) {
  5097. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5098. return -EINVAL;
  5099. }
  5100. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5101. /*
  5102. * Ensure we match the reduced clock's P to the target
  5103. * clock. If the clocks don't match, we can't switch
  5104. * the display clock by using the FP0/FP1. In such case
  5105. * we will disable the LVDS downclock feature.
  5106. */
  5107. has_reduced_clock =
  5108. dev_priv->display.find_dpll(limit, crtc,
  5109. dev_priv->lvds_downclock,
  5110. refclk, &clock,
  5111. &reduced_clock);
  5112. }
  5113. /* Compat-code for transition, will disappear. */
  5114. intel_crtc->config.dpll.n = clock.n;
  5115. intel_crtc->config.dpll.m1 = clock.m1;
  5116. intel_crtc->config.dpll.m2 = clock.m2;
  5117. intel_crtc->config.dpll.p1 = clock.p1;
  5118. intel_crtc->config.dpll.p2 = clock.p2;
  5119. }
  5120. if (IS_GEN2(dev)) {
  5121. i8xx_update_pll(intel_crtc,
  5122. has_reduced_clock ? &reduced_clock : NULL,
  5123. num_connectors);
  5124. } else if (IS_CHERRYVIEW(dev)) {
  5125. chv_update_pll(intel_crtc);
  5126. } else if (IS_VALLEYVIEW(dev)) {
  5127. vlv_update_pll(intel_crtc);
  5128. } else {
  5129. i9xx_update_pll(intel_crtc,
  5130. has_reduced_clock ? &reduced_clock : NULL,
  5131. num_connectors);
  5132. }
  5133. return 0;
  5134. }
  5135. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5136. struct intel_crtc_config *pipe_config)
  5137. {
  5138. struct drm_device *dev = crtc->base.dev;
  5139. struct drm_i915_private *dev_priv = dev->dev_private;
  5140. uint32_t tmp;
  5141. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5142. return;
  5143. tmp = I915_READ(PFIT_CONTROL);
  5144. if (!(tmp & PFIT_ENABLE))
  5145. return;
  5146. /* Check whether the pfit is attached to our pipe. */
  5147. if (INTEL_INFO(dev)->gen < 4) {
  5148. if (crtc->pipe != PIPE_B)
  5149. return;
  5150. } else {
  5151. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5152. return;
  5153. }
  5154. pipe_config->gmch_pfit.control = tmp;
  5155. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5156. if (INTEL_INFO(dev)->gen < 5)
  5157. pipe_config->gmch_pfit.lvds_border_bits =
  5158. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5159. }
  5160. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5161. struct intel_crtc_config *pipe_config)
  5162. {
  5163. struct drm_device *dev = crtc->base.dev;
  5164. struct drm_i915_private *dev_priv = dev->dev_private;
  5165. int pipe = pipe_config->cpu_transcoder;
  5166. intel_clock_t clock;
  5167. u32 mdiv;
  5168. int refclk = 100000;
  5169. mutex_lock(&dev_priv->dpio_lock);
  5170. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5171. mutex_unlock(&dev_priv->dpio_lock);
  5172. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5173. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5174. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5175. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5176. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5177. vlv_clock(refclk, &clock);
  5178. /* clock.dot is the fast clock */
  5179. pipe_config->port_clock = clock.dot / 5;
  5180. }
  5181. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5182. struct intel_plane_config *plane_config)
  5183. {
  5184. struct drm_device *dev = crtc->base.dev;
  5185. struct drm_i915_private *dev_priv = dev->dev_private;
  5186. u32 val, base, offset;
  5187. int pipe = crtc->pipe, plane = crtc->plane;
  5188. int fourcc, pixel_format;
  5189. int aligned_height;
  5190. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5191. if (!crtc->base.primary->fb) {
  5192. DRM_DEBUG_KMS("failed to alloc fb\n");
  5193. return;
  5194. }
  5195. val = I915_READ(DSPCNTR(plane));
  5196. if (INTEL_INFO(dev)->gen >= 4)
  5197. if (val & DISPPLANE_TILED)
  5198. plane_config->tiled = true;
  5199. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5200. fourcc = intel_format_to_fourcc(pixel_format);
  5201. crtc->base.primary->fb->pixel_format = fourcc;
  5202. crtc->base.primary->fb->bits_per_pixel =
  5203. drm_format_plane_cpp(fourcc, 0) * 8;
  5204. if (INTEL_INFO(dev)->gen >= 4) {
  5205. if (plane_config->tiled)
  5206. offset = I915_READ(DSPTILEOFF(plane));
  5207. else
  5208. offset = I915_READ(DSPLINOFF(plane));
  5209. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5210. } else {
  5211. base = I915_READ(DSPADDR(plane));
  5212. }
  5213. plane_config->base = base;
  5214. val = I915_READ(PIPESRC(pipe));
  5215. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5216. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5217. val = I915_READ(DSPSTRIDE(pipe));
  5218. crtc->base.primary->fb->pitches[0] = val & 0xffffff80;
  5219. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5220. plane_config->tiled);
  5221. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  5222. aligned_height);
  5223. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5224. pipe, plane, crtc->base.primary->fb->width,
  5225. crtc->base.primary->fb->height,
  5226. crtc->base.primary->fb->bits_per_pixel, base,
  5227. crtc->base.primary->fb->pitches[0],
  5228. plane_config->size);
  5229. }
  5230. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5231. struct intel_crtc_config *pipe_config)
  5232. {
  5233. struct drm_device *dev = crtc->base.dev;
  5234. struct drm_i915_private *dev_priv = dev->dev_private;
  5235. int pipe = pipe_config->cpu_transcoder;
  5236. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5237. intel_clock_t clock;
  5238. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5239. int refclk = 100000;
  5240. mutex_lock(&dev_priv->dpio_lock);
  5241. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5242. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5243. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5244. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5245. mutex_unlock(&dev_priv->dpio_lock);
  5246. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5247. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5248. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5249. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5250. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5251. chv_clock(refclk, &clock);
  5252. /* clock.dot is the fast clock */
  5253. pipe_config->port_clock = clock.dot / 5;
  5254. }
  5255. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5256. struct intel_crtc_config *pipe_config)
  5257. {
  5258. struct drm_device *dev = crtc->base.dev;
  5259. struct drm_i915_private *dev_priv = dev->dev_private;
  5260. uint32_t tmp;
  5261. if (!intel_display_power_enabled(dev_priv,
  5262. POWER_DOMAIN_PIPE(crtc->pipe)))
  5263. return false;
  5264. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5265. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5266. tmp = I915_READ(PIPECONF(crtc->pipe));
  5267. if (!(tmp & PIPECONF_ENABLE))
  5268. return false;
  5269. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5270. switch (tmp & PIPECONF_BPC_MASK) {
  5271. case PIPECONF_6BPC:
  5272. pipe_config->pipe_bpp = 18;
  5273. break;
  5274. case PIPECONF_8BPC:
  5275. pipe_config->pipe_bpp = 24;
  5276. break;
  5277. case PIPECONF_10BPC:
  5278. pipe_config->pipe_bpp = 30;
  5279. break;
  5280. default:
  5281. break;
  5282. }
  5283. }
  5284. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5285. pipe_config->limited_color_range = true;
  5286. if (INTEL_INFO(dev)->gen < 4)
  5287. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5288. intel_get_pipe_timings(crtc, pipe_config);
  5289. i9xx_get_pfit_config(crtc, pipe_config);
  5290. if (INTEL_INFO(dev)->gen >= 4) {
  5291. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5292. pipe_config->pixel_multiplier =
  5293. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5294. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5295. pipe_config->dpll_hw_state.dpll_md = tmp;
  5296. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5297. tmp = I915_READ(DPLL(crtc->pipe));
  5298. pipe_config->pixel_multiplier =
  5299. ((tmp & SDVO_MULTIPLIER_MASK)
  5300. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5301. } else {
  5302. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5303. * port and will be fixed up in the encoder->get_config
  5304. * function. */
  5305. pipe_config->pixel_multiplier = 1;
  5306. }
  5307. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5308. if (!IS_VALLEYVIEW(dev)) {
  5309. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5310. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5311. } else {
  5312. /* Mask out read-only status bits. */
  5313. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5314. DPLL_PORTC_READY_MASK |
  5315. DPLL_PORTB_READY_MASK);
  5316. }
  5317. if (IS_CHERRYVIEW(dev))
  5318. chv_crtc_clock_get(crtc, pipe_config);
  5319. else if (IS_VALLEYVIEW(dev))
  5320. vlv_crtc_clock_get(crtc, pipe_config);
  5321. else
  5322. i9xx_crtc_clock_get(crtc, pipe_config);
  5323. return true;
  5324. }
  5325. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5326. {
  5327. struct drm_i915_private *dev_priv = dev->dev_private;
  5328. struct drm_mode_config *mode_config = &dev->mode_config;
  5329. struct intel_encoder *encoder;
  5330. u32 val, final;
  5331. bool has_lvds = false;
  5332. bool has_cpu_edp = false;
  5333. bool has_panel = false;
  5334. bool has_ck505 = false;
  5335. bool can_ssc = false;
  5336. /* We need to take the global config into account */
  5337. list_for_each_entry(encoder, &mode_config->encoder_list,
  5338. base.head) {
  5339. switch (encoder->type) {
  5340. case INTEL_OUTPUT_LVDS:
  5341. has_panel = true;
  5342. has_lvds = true;
  5343. break;
  5344. case INTEL_OUTPUT_EDP:
  5345. has_panel = true;
  5346. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5347. has_cpu_edp = true;
  5348. break;
  5349. }
  5350. }
  5351. if (HAS_PCH_IBX(dev)) {
  5352. has_ck505 = dev_priv->vbt.display_clock_mode;
  5353. can_ssc = has_ck505;
  5354. } else {
  5355. has_ck505 = false;
  5356. can_ssc = true;
  5357. }
  5358. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5359. has_panel, has_lvds, has_ck505);
  5360. /* Ironlake: try to setup display ref clock before DPLL
  5361. * enabling. This is only under driver's control after
  5362. * PCH B stepping, previous chipset stepping should be
  5363. * ignoring this setting.
  5364. */
  5365. val = I915_READ(PCH_DREF_CONTROL);
  5366. /* As we must carefully and slowly disable/enable each source in turn,
  5367. * compute the final state we want first and check if we need to
  5368. * make any changes at all.
  5369. */
  5370. final = val;
  5371. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5372. if (has_ck505)
  5373. final |= DREF_NONSPREAD_CK505_ENABLE;
  5374. else
  5375. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5376. final &= ~DREF_SSC_SOURCE_MASK;
  5377. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5378. final &= ~DREF_SSC1_ENABLE;
  5379. if (has_panel) {
  5380. final |= DREF_SSC_SOURCE_ENABLE;
  5381. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5382. final |= DREF_SSC1_ENABLE;
  5383. if (has_cpu_edp) {
  5384. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5385. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5386. else
  5387. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5388. } else
  5389. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5390. } else {
  5391. final |= DREF_SSC_SOURCE_DISABLE;
  5392. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5393. }
  5394. if (final == val)
  5395. return;
  5396. /* Always enable nonspread source */
  5397. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5398. if (has_ck505)
  5399. val |= DREF_NONSPREAD_CK505_ENABLE;
  5400. else
  5401. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5402. if (has_panel) {
  5403. val &= ~DREF_SSC_SOURCE_MASK;
  5404. val |= DREF_SSC_SOURCE_ENABLE;
  5405. /* SSC must be turned on before enabling the CPU output */
  5406. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5407. DRM_DEBUG_KMS("Using SSC on panel\n");
  5408. val |= DREF_SSC1_ENABLE;
  5409. } else
  5410. val &= ~DREF_SSC1_ENABLE;
  5411. /* Get SSC going before enabling the outputs */
  5412. I915_WRITE(PCH_DREF_CONTROL, val);
  5413. POSTING_READ(PCH_DREF_CONTROL);
  5414. udelay(200);
  5415. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5416. /* Enable CPU source on CPU attached eDP */
  5417. if (has_cpu_edp) {
  5418. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5419. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5420. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5421. } else
  5422. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5423. } else
  5424. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5425. I915_WRITE(PCH_DREF_CONTROL, val);
  5426. POSTING_READ(PCH_DREF_CONTROL);
  5427. udelay(200);
  5428. } else {
  5429. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5430. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5431. /* Turn off CPU output */
  5432. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5433. I915_WRITE(PCH_DREF_CONTROL, val);
  5434. POSTING_READ(PCH_DREF_CONTROL);
  5435. udelay(200);
  5436. /* Turn off the SSC source */
  5437. val &= ~DREF_SSC_SOURCE_MASK;
  5438. val |= DREF_SSC_SOURCE_DISABLE;
  5439. /* Turn off SSC1 */
  5440. val &= ~DREF_SSC1_ENABLE;
  5441. I915_WRITE(PCH_DREF_CONTROL, val);
  5442. POSTING_READ(PCH_DREF_CONTROL);
  5443. udelay(200);
  5444. }
  5445. BUG_ON(val != final);
  5446. }
  5447. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5448. {
  5449. uint32_t tmp;
  5450. tmp = I915_READ(SOUTH_CHICKEN2);
  5451. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5452. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5453. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5454. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5455. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5456. tmp = I915_READ(SOUTH_CHICKEN2);
  5457. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5458. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5459. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5460. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5461. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5462. }
  5463. /* WaMPhyProgramming:hsw */
  5464. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5465. {
  5466. uint32_t tmp;
  5467. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5468. tmp &= ~(0xFF << 24);
  5469. tmp |= (0x12 << 24);
  5470. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5471. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5472. tmp |= (1 << 11);
  5473. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5474. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5475. tmp |= (1 << 11);
  5476. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5477. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5478. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5479. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5480. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5481. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5482. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5483. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5484. tmp &= ~(7 << 13);
  5485. tmp |= (5 << 13);
  5486. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5487. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5488. tmp &= ~(7 << 13);
  5489. tmp |= (5 << 13);
  5490. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5491. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5492. tmp &= ~0xFF;
  5493. tmp |= 0x1C;
  5494. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5495. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5496. tmp &= ~0xFF;
  5497. tmp |= 0x1C;
  5498. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5499. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5500. tmp &= ~(0xFF << 16);
  5501. tmp |= (0x1C << 16);
  5502. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5503. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5504. tmp &= ~(0xFF << 16);
  5505. tmp |= (0x1C << 16);
  5506. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5507. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5508. tmp |= (1 << 27);
  5509. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5510. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5511. tmp |= (1 << 27);
  5512. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5513. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5514. tmp &= ~(0xF << 28);
  5515. tmp |= (4 << 28);
  5516. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5517. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5518. tmp &= ~(0xF << 28);
  5519. tmp |= (4 << 28);
  5520. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5521. }
  5522. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5523. * Programming" based on the parameters passed:
  5524. * - Sequence to enable CLKOUT_DP
  5525. * - Sequence to enable CLKOUT_DP without spread
  5526. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5527. */
  5528. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5529. bool with_fdi)
  5530. {
  5531. struct drm_i915_private *dev_priv = dev->dev_private;
  5532. uint32_t reg, tmp;
  5533. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5534. with_spread = true;
  5535. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5536. with_fdi, "LP PCH doesn't have FDI\n"))
  5537. with_fdi = false;
  5538. mutex_lock(&dev_priv->dpio_lock);
  5539. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5540. tmp &= ~SBI_SSCCTL_DISABLE;
  5541. tmp |= SBI_SSCCTL_PATHALT;
  5542. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5543. udelay(24);
  5544. if (with_spread) {
  5545. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5546. tmp &= ~SBI_SSCCTL_PATHALT;
  5547. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5548. if (with_fdi) {
  5549. lpt_reset_fdi_mphy(dev_priv);
  5550. lpt_program_fdi_mphy(dev_priv);
  5551. }
  5552. }
  5553. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5554. SBI_GEN0 : SBI_DBUFF0;
  5555. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5556. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5557. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5558. mutex_unlock(&dev_priv->dpio_lock);
  5559. }
  5560. /* Sequence to disable CLKOUT_DP */
  5561. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5562. {
  5563. struct drm_i915_private *dev_priv = dev->dev_private;
  5564. uint32_t reg, tmp;
  5565. mutex_lock(&dev_priv->dpio_lock);
  5566. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5567. SBI_GEN0 : SBI_DBUFF0;
  5568. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5569. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5570. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5571. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5572. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5573. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5574. tmp |= SBI_SSCCTL_PATHALT;
  5575. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5576. udelay(32);
  5577. }
  5578. tmp |= SBI_SSCCTL_DISABLE;
  5579. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5580. }
  5581. mutex_unlock(&dev_priv->dpio_lock);
  5582. }
  5583. static void lpt_init_pch_refclk(struct drm_device *dev)
  5584. {
  5585. struct drm_mode_config *mode_config = &dev->mode_config;
  5586. struct intel_encoder *encoder;
  5587. bool has_vga = false;
  5588. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  5589. switch (encoder->type) {
  5590. case INTEL_OUTPUT_ANALOG:
  5591. has_vga = true;
  5592. break;
  5593. }
  5594. }
  5595. if (has_vga)
  5596. lpt_enable_clkout_dp(dev, true, true);
  5597. else
  5598. lpt_disable_clkout_dp(dev);
  5599. }
  5600. /*
  5601. * Initialize reference clocks when the driver loads
  5602. */
  5603. void intel_init_pch_refclk(struct drm_device *dev)
  5604. {
  5605. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5606. ironlake_init_pch_refclk(dev);
  5607. else if (HAS_PCH_LPT(dev))
  5608. lpt_init_pch_refclk(dev);
  5609. }
  5610. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5611. {
  5612. struct drm_device *dev = crtc->dev;
  5613. struct drm_i915_private *dev_priv = dev->dev_private;
  5614. struct intel_encoder *encoder;
  5615. int num_connectors = 0;
  5616. bool is_lvds = false;
  5617. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5618. switch (encoder->type) {
  5619. case INTEL_OUTPUT_LVDS:
  5620. is_lvds = true;
  5621. break;
  5622. }
  5623. num_connectors++;
  5624. }
  5625. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5626. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5627. dev_priv->vbt.lvds_ssc_freq);
  5628. return dev_priv->vbt.lvds_ssc_freq;
  5629. }
  5630. return 120000;
  5631. }
  5632. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5633. {
  5634. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5635. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5636. int pipe = intel_crtc->pipe;
  5637. uint32_t val;
  5638. val = 0;
  5639. switch (intel_crtc->config.pipe_bpp) {
  5640. case 18:
  5641. val |= PIPECONF_6BPC;
  5642. break;
  5643. case 24:
  5644. val |= PIPECONF_8BPC;
  5645. break;
  5646. case 30:
  5647. val |= PIPECONF_10BPC;
  5648. break;
  5649. case 36:
  5650. val |= PIPECONF_12BPC;
  5651. break;
  5652. default:
  5653. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5654. BUG();
  5655. }
  5656. if (intel_crtc->config.dither)
  5657. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5658. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5659. val |= PIPECONF_INTERLACED_ILK;
  5660. else
  5661. val |= PIPECONF_PROGRESSIVE;
  5662. if (intel_crtc->config.limited_color_range)
  5663. val |= PIPECONF_COLOR_RANGE_SELECT;
  5664. I915_WRITE(PIPECONF(pipe), val);
  5665. POSTING_READ(PIPECONF(pipe));
  5666. }
  5667. /*
  5668. * Set up the pipe CSC unit.
  5669. *
  5670. * Currently only full range RGB to limited range RGB conversion
  5671. * is supported, but eventually this should handle various
  5672. * RGB<->YCbCr scenarios as well.
  5673. */
  5674. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5675. {
  5676. struct drm_device *dev = crtc->dev;
  5677. struct drm_i915_private *dev_priv = dev->dev_private;
  5678. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5679. int pipe = intel_crtc->pipe;
  5680. uint16_t coeff = 0x7800; /* 1.0 */
  5681. /*
  5682. * TODO: Check what kind of values actually come out of the pipe
  5683. * with these coeff/postoff values and adjust to get the best
  5684. * accuracy. Perhaps we even need to take the bpc value into
  5685. * consideration.
  5686. */
  5687. if (intel_crtc->config.limited_color_range)
  5688. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5689. /*
  5690. * GY/GU and RY/RU should be the other way around according
  5691. * to BSpec, but reality doesn't agree. Just set them up in
  5692. * a way that results in the correct picture.
  5693. */
  5694. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5695. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5696. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5697. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5698. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5699. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5700. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5701. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5702. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5703. if (INTEL_INFO(dev)->gen > 6) {
  5704. uint16_t postoff = 0;
  5705. if (intel_crtc->config.limited_color_range)
  5706. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5707. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5708. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5709. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5710. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5711. } else {
  5712. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5713. if (intel_crtc->config.limited_color_range)
  5714. mode |= CSC_BLACK_SCREEN_OFFSET;
  5715. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5716. }
  5717. }
  5718. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5719. {
  5720. struct drm_device *dev = crtc->dev;
  5721. struct drm_i915_private *dev_priv = dev->dev_private;
  5722. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5723. enum pipe pipe = intel_crtc->pipe;
  5724. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5725. uint32_t val;
  5726. val = 0;
  5727. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5728. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5729. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5730. val |= PIPECONF_INTERLACED_ILK;
  5731. else
  5732. val |= PIPECONF_PROGRESSIVE;
  5733. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5734. POSTING_READ(PIPECONF(cpu_transcoder));
  5735. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5736. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5737. if (IS_BROADWELL(dev)) {
  5738. val = 0;
  5739. switch (intel_crtc->config.pipe_bpp) {
  5740. case 18:
  5741. val |= PIPEMISC_DITHER_6_BPC;
  5742. break;
  5743. case 24:
  5744. val |= PIPEMISC_DITHER_8_BPC;
  5745. break;
  5746. case 30:
  5747. val |= PIPEMISC_DITHER_10_BPC;
  5748. break;
  5749. case 36:
  5750. val |= PIPEMISC_DITHER_12_BPC;
  5751. break;
  5752. default:
  5753. /* Case prevented by pipe_config_set_bpp. */
  5754. BUG();
  5755. }
  5756. if (intel_crtc->config.dither)
  5757. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5758. I915_WRITE(PIPEMISC(pipe), val);
  5759. }
  5760. }
  5761. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5762. intel_clock_t *clock,
  5763. bool *has_reduced_clock,
  5764. intel_clock_t *reduced_clock)
  5765. {
  5766. struct drm_device *dev = crtc->dev;
  5767. struct drm_i915_private *dev_priv = dev->dev_private;
  5768. struct intel_encoder *intel_encoder;
  5769. int refclk;
  5770. const intel_limit_t *limit;
  5771. bool ret, is_lvds = false;
  5772. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5773. switch (intel_encoder->type) {
  5774. case INTEL_OUTPUT_LVDS:
  5775. is_lvds = true;
  5776. break;
  5777. }
  5778. }
  5779. refclk = ironlake_get_refclk(crtc);
  5780. /*
  5781. * Returns a set of divisors for the desired target clock with the given
  5782. * refclk, or FALSE. The returned values represent the clock equation:
  5783. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5784. */
  5785. limit = intel_limit(crtc, refclk);
  5786. ret = dev_priv->display.find_dpll(limit, crtc,
  5787. to_intel_crtc(crtc)->config.port_clock,
  5788. refclk, NULL, clock);
  5789. if (!ret)
  5790. return false;
  5791. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5792. /*
  5793. * Ensure we match the reduced clock's P to the target clock.
  5794. * If the clocks don't match, we can't switch the display clock
  5795. * by using the FP0/FP1. In such case we will disable the LVDS
  5796. * downclock feature.
  5797. */
  5798. *has_reduced_clock =
  5799. dev_priv->display.find_dpll(limit, crtc,
  5800. dev_priv->lvds_downclock,
  5801. refclk, clock,
  5802. reduced_clock);
  5803. }
  5804. return true;
  5805. }
  5806. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5807. {
  5808. /*
  5809. * Account for spread spectrum to avoid
  5810. * oversubscribing the link. Max center spread
  5811. * is 2.5%; use 5% for safety's sake.
  5812. */
  5813. u32 bps = target_clock * bpp * 21 / 20;
  5814. return DIV_ROUND_UP(bps, link_bw * 8);
  5815. }
  5816. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5817. {
  5818. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5819. }
  5820. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5821. u32 *fp,
  5822. intel_clock_t *reduced_clock, u32 *fp2)
  5823. {
  5824. struct drm_crtc *crtc = &intel_crtc->base;
  5825. struct drm_device *dev = crtc->dev;
  5826. struct drm_i915_private *dev_priv = dev->dev_private;
  5827. struct intel_encoder *intel_encoder;
  5828. uint32_t dpll;
  5829. int factor, num_connectors = 0;
  5830. bool is_lvds = false, is_sdvo = false;
  5831. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5832. switch (intel_encoder->type) {
  5833. case INTEL_OUTPUT_LVDS:
  5834. is_lvds = true;
  5835. break;
  5836. case INTEL_OUTPUT_SDVO:
  5837. case INTEL_OUTPUT_HDMI:
  5838. is_sdvo = true;
  5839. break;
  5840. }
  5841. num_connectors++;
  5842. }
  5843. /* Enable autotuning of the PLL clock (if permissible) */
  5844. factor = 21;
  5845. if (is_lvds) {
  5846. if ((intel_panel_use_ssc(dev_priv) &&
  5847. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5848. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5849. factor = 25;
  5850. } else if (intel_crtc->config.sdvo_tv_clock)
  5851. factor = 20;
  5852. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5853. *fp |= FP_CB_TUNE;
  5854. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5855. *fp2 |= FP_CB_TUNE;
  5856. dpll = 0;
  5857. if (is_lvds)
  5858. dpll |= DPLLB_MODE_LVDS;
  5859. else
  5860. dpll |= DPLLB_MODE_DAC_SERIAL;
  5861. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  5862. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  5863. if (is_sdvo)
  5864. dpll |= DPLL_SDVO_HIGH_SPEED;
  5865. if (intel_crtc->config.has_dp_encoder)
  5866. dpll |= DPLL_SDVO_HIGH_SPEED;
  5867. /* compute bitmask from p1 value */
  5868. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5869. /* also FPA1 */
  5870. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  5871. switch (intel_crtc->config.dpll.p2) {
  5872. case 5:
  5873. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  5874. break;
  5875. case 7:
  5876. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  5877. break;
  5878. case 10:
  5879. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  5880. break;
  5881. case 14:
  5882. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  5883. break;
  5884. }
  5885. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5886. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5887. else
  5888. dpll |= PLL_REF_INPUT_DREFCLK;
  5889. return dpll | DPLL_VCO_ENABLE;
  5890. }
  5891. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  5892. int x, int y,
  5893. struct drm_framebuffer *fb)
  5894. {
  5895. struct drm_device *dev = crtc->dev;
  5896. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5897. int num_connectors = 0;
  5898. intel_clock_t clock, reduced_clock;
  5899. u32 dpll = 0, fp = 0, fp2 = 0;
  5900. bool ok, has_reduced_clock = false;
  5901. bool is_lvds = false;
  5902. struct intel_encoder *encoder;
  5903. struct intel_shared_dpll *pll;
  5904. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5905. switch (encoder->type) {
  5906. case INTEL_OUTPUT_LVDS:
  5907. is_lvds = true;
  5908. break;
  5909. }
  5910. num_connectors++;
  5911. }
  5912. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  5913. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  5914. ok = ironlake_compute_clocks(crtc, &clock,
  5915. &has_reduced_clock, &reduced_clock);
  5916. if (!ok && !intel_crtc->config.clock_set) {
  5917. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5918. return -EINVAL;
  5919. }
  5920. /* Compat-code for transition, will disappear. */
  5921. if (!intel_crtc->config.clock_set) {
  5922. intel_crtc->config.dpll.n = clock.n;
  5923. intel_crtc->config.dpll.m1 = clock.m1;
  5924. intel_crtc->config.dpll.m2 = clock.m2;
  5925. intel_crtc->config.dpll.p1 = clock.p1;
  5926. intel_crtc->config.dpll.p2 = clock.p2;
  5927. }
  5928. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  5929. if (intel_crtc->config.has_pch_encoder) {
  5930. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  5931. if (has_reduced_clock)
  5932. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  5933. dpll = ironlake_compute_dpll(intel_crtc,
  5934. &fp, &reduced_clock,
  5935. has_reduced_clock ? &fp2 : NULL);
  5936. intel_crtc->config.dpll_hw_state.dpll = dpll;
  5937. intel_crtc->config.dpll_hw_state.fp0 = fp;
  5938. if (has_reduced_clock)
  5939. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  5940. else
  5941. intel_crtc->config.dpll_hw_state.fp1 = fp;
  5942. pll = intel_get_shared_dpll(intel_crtc);
  5943. if (pll == NULL) {
  5944. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  5945. pipe_name(intel_crtc->pipe));
  5946. return -EINVAL;
  5947. }
  5948. } else
  5949. intel_put_shared_dpll(intel_crtc);
  5950. if (is_lvds && has_reduced_clock && i915.powersave)
  5951. intel_crtc->lowfreq_avail = true;
  5952. else
  5953. intel_crtc->lowfreq_avail = false;
  5954. return 0;
  5955. }
  5956. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  5957. struct intel_link_m_n *m_n)
  5958. {
  5959. struct drm_device *dev = crtc->base.dev;
  5960. struct drm_i915_private *dev_priv = dev->dev_private;
  5961. enum pipe pipe = crtc->pipe;
  5962. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  5963. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  5964. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  5965. & ~TU_SIZE_MASK;
  5966. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  5967. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  5968. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5969. }
  5970. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  5971. enum transcoder transcoder,
  5972. struct intel_link_m_n *m_n)
  5973. {
  5974. struct drm_device *dev = crtc->base.dev;
  5975. struct drm_i915_private *dev_priv = dev->dev_private;
  5976. enum pipe pipe = crtc->pipe;
  5977. if (INTEL_INFO(dev)->gen >= 5) {
  5978. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  5979. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  5980. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  5981. & ~TU_SIZE_MASK;
  5982. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  5983. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  5984. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5985. } else {
  5986. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  5987. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  5988. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  5989. & ~TU_SIZE_MASK;
  5990. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  5991. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  5992. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  5993. }
  5994. }
  5995. void intel_dp_get_m_n(struct intel_crtc *crtc,
  5996. struct intel_crtc_config *pipe_config)
  5997. {
  5998. if (crtc->config.has_pch_encoder)
  5999. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  6000. else
  6001. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6002. &pipe_config->dp_m_n);
  6003. }
  6004. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  6005. struct intel_crtc_config *pipe_config)
  6006. {
  6007. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6008. &pipe_config->fdi_m_n);
  6009. }
  6010. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  6011. struct intel_crtc_config *pipe_config)
  6012. {
  6013. struct drm_device *dev = crtc->base.dev;
  6014. struct drm_i915_private *dev_priv = dev->dev_private;
  6015. uint32_t tmp;
  6016. tmp = I915_READ(PF_CTL(crtc->pipe));
  6017. if (tmp & PF_ENABLE) {
  6018. pipe_config->pch_pfit.enabled = true;
  6019. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6020. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6021. /* We currently do not free assignements of panel fitters on
  6022. * ivb/hsw (since we don't use the higher upscaling modes which
  6023. * differentiates them) so just WARN about this case for now. */
  6024. if (IS_GEN7(dev)) {
  6025. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6026. PF_PIPE_SEL_IVB(crtc->pipe));
  6027. }
  6028. }
  6029. }
  6030. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6031. struct intel_plane_config *plane_config)
  6032. {
  6033. struct drm_device *dev = crtc->base.dev;
  6034. struct drm_i915_private *dev_priv = dev->dev_private;
  6035. u32 val, base, offset;
  6036. int pipe = crtc->pipe, plane = crtc->plane;
  6037. int fourcc, pixel_format;
  6038. int aligned_height;
  6039. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6040. if (!crtc->base.primary->fb) {
  6041. DRM_DEBUG_KMS("failed to alloc fb\n");
  6042. return;
  6043. }
  6044. val = I915_READ(DSPCNTR(plane));
  6045. if (INTEL_INFO(dev)->gen >= 4)
  6046. if (val & DISPPLANE_TILED)
  6047. plane_config->tiled = true;
  6048. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6049. fourcc = intel_format_to_fourcc(pixel_format);
  6050. crtc->base.primary->fb->pixel_format = fourcc;
  6051. crtc->base.primary->fb->bits_per_pixel =
  6052. drm_format_plane_cpp(fourcc, 0) * 8;
  6053. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6054. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6055. offset = I915_READ(DSPOFFSET(plane));
  6056. } else {
  6057. if (plane_config->tiled)
  6058. offset = I915_READ(DSPTILEOFF(plane));
  6059. else
  6060. offset = I915_READ(DSPLINOFF(plane));
  6061. }
  6062. plane_config->base = base;
  6063. val = I915_READ(PIPESRC(pipe));
  6064. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6065. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6066. val = I915_READ(DSPSTRIDE(pipe));
  6067. crtc->base.primary->fb->pitches[0] = val & 0xffffff80;
  6068. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6069. plane_config->tiled);
  6070. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  6071. aligned_height);
  6072. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6073. pipe, plane, crtc->base.primary->fb->width,
  6074. crtc->base.primary->fb->height,
  6075. crtc->base.primary->fb->bits_per_pixel, base,
  6076. crtc->base.primary->fb->pitches[0],
  6077. plane_config->size);
  6078. }
  6079. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6080. struct intel_crtc_config *pipe_config)
  6081. {
  6082. struct drm_device *dev = crtc->base.dev;
  6083. struct drm_i915_private *dev_priv = dev->dev_private;
  6084. uint32_t tmp;
  6085. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6086. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6087. tmp = I915_READ(PIPECONF(crtc->pipe));
  6088. if (!(tmp & PIPECONF_ENABLE))
  6089. return false;
  6090. switch (tmp & PIPECONF_BPC_MASK) {
  6091. case PIPECONF_6BPC:
  6092. pipe_config->pipe_bpp = 18;
  6093. break;
  6094. case PIPECONF_8BPC:
  6095. pipe_config->pipe_bpp = 24;
  6096. break;
  6097. case PIPECONF_10BPC:
  6098. pipe_config->pipe_bpp = 30;
  6099. break;
  6100. case PIPECONF_12BPC:
  6101. pipe_config->pipe_bpp = 36;
  6102. break;
  6103. default:
  6104. break;
  6105. }
  6106. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6107. pipe_config->limited_color_range = true;
  6108. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6109. struct intel_shared_dpll *pll;
  6110. pipe_config->has_pch_encoder = true;
  6111. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6112. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6113. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6114. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6115. if (HAS_PCH_IBX(dev_priv->dev)) {
  6116. pipe_config->shared_dpll =
  6117. (enum intel_dpll_id) crtc->pipe;
  6118. } else {
  6119. tmp = I915_READ(PCH_DPLL_SEL);
  6120. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6121. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6122. else
  6123. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6124. }
  6125. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6126. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6127. &pipe_config->dpll_hw_state));
  6128. tmp = pipe_config->dpll_hw_state.dpll;
  6129. pipe_config->pixel_multiplier =
  6130. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6131. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6132. ironlake_pch_clock_get(crtc, pipe_config);
  6133. } else {
  6134. pipe_config->pixel_multiplier = 1;
  6135. }
  6136. intel_get_pipe_timings(crtc, pipe_config);
  6137. ironlake_get_pfit_config(crtc, pipe_config);
  6138. return true;
  6139. }
  6140. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6141. {
  6142. struct drm_device *dev = dev_priv->dev;
  6143. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  6144. struct intel_crtc *crtc;
  6145. for_each_intel_crtc(dev, crtc)
  6146. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6147. pipe_name(crtc->pipe));
  6148. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6149. WARN(plls->spll_refcount, "SPLL enabled\n");
  6150. WARN(plls->wrpll1_refcount, "WRPLL1 enabled\n");
  6151. WARN(plls->wrpll2_refcount, "WRPLL2 enabled\n");
  6152. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6153. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6154. "CPU PWM1 enabled\n");
  6155. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6156. "CPU PWM2 enabled\n");
  6157. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6158. "PCH PWM1 enabled\n");
  6159. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6160. "Utility pin enabled\n");
  6161. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6162. /*
  6163. * In theory we can still leave IRQs enabled, as long as only the HPD
  6164. * interrupts remain enabled. We used to check for that, but since it's
  6165. * gen-specific and since we only disable LCPLL after we fully disable
  6166. * the interrupts, the check below should be enough.
  6167. */
  6168. WARN(!dev_priv->pm.irqs_disabled, "IRQs enabled\n");
  6169. }
  6170. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6171. {
  6172. struct drm_device *dev = dev_priv->dev;
  6173. if (IS_HASWELL(dev)) {
  6174. mutex_lock(&dev_priv->rps.hw_lock);
  6175. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6176. val))
  6177. DRM_ERROR("Failed to disable D_COMP\n");
  6178. mutex_unlock(&dev_priv->rps.hw_lock);
  6179. } else {
  6180. I915_WRITE(D_COMP, val);
  6181. }
  6182. POSTING_READ(D_COMP);
  6183. }
  6184. /*
  6185. * This function implements pieces of two sequences from BSpec:
  6186. * - Sequence for display software to disable LCPLL
  6187. * - Sequence for display software to allow package C8+
  6188. * The steps implemented here are just the steps that actually touch the LCPLL
  6189. * register. Callers should take care of disabling all the display engine
  6190. * functions, doing the mode unset, fixing interrupts, etc.
  6191. */
  6192. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6193. bool switch_to_fclk, bool allow_power_down)
  6194. {
  6195. uint32_t val;
  6196. assert_can_disable_lcpll(dev_priv);
  6197. val = I915_READ(LCPLL_CTL);
  6198. if (switch_to_fclk) {
  6199. val |= LCPLL_CD_SOURCE_FCLK;
  6200. I915_WRITE(LCPLL_CTL, val);
  6201. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6202. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6203. DRM_ERROR("Switching to FCLK failed\n");
  6204. val = I915_READ(LCPLL_CTL);
  6205. }
  6206. val |= LCPLL_PLL_DISABLE;
  6207. I915_WRITE(LCPLL_CTL, val);
  6208. POSTING_READ(LCPLL_CTL);
  6209. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6210. DRM_ERROR("LCPLL still locked\n");
  6211. val = I915_READ(D_COMP);
  6212. val |= D_COMP_COMP_DISABLE;
  6213. hsw_write_dcomp(dev_priv, val);
  6214. ndelay(100);
  6215. if (wait_for((I915_READ(D_COMP) & D_COMP_RCOMP_IN_PROGRESS) == 0, 1))
  6216. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6217. if (allow_power_down) {
  6218. val = I915_READ(LCPLL_CTL);
  6219. val |= LCPLL_POWER_DOWN_ALLOW;
  6220. I915_WRITE(LCPLL_CTL, val);
  6221. POSTING_READ(LCPLL_CTL);
  6222. }
  6223. }
  6224. /*
  6225. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6226. * source.
  6227. */
  6228. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6229. {
  6230. uint32_t val;
  6231. unsigned long irqflags;
  6232. val = I915_READ(LCPLL_CTL);
  6233. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6234. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6235. return;
  6236. /*
  6237. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6238. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6239. *
  6240. * The other problem is that hsw_restore_lcpll() is called as part of
  6241. * the runtime PM resume sequence, so we can't just call
  6242. * gen6_gt_force_wake_get() because that function calls
  6243. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6244. * while we are on the resume sequence. So to solve this problem we have
  6245. * to call special forcewake code that doesn't touch runtime PM and
  6246. * doesn't enable the forcewake delayed work.
  6247. */
  6248. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6249. if (dev_priv->uncore.forcewake_count++ == 0)
  6250. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6251. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6252. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6253. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6254. I915_WRITE(LCPLL_CTL, val);
  6255. POSTING_READ(LCPLL_CTL);
  6256. }
  6257. val = I915_READ(D_COMP);
  6258. val |= D_COMP_COMP_FORCE;
  6259. val &= ~D_COMP_COMP_DISABLE;
  6260. hsw_write_dcomp(dev_priv, val);
  6261. val = I915_READ(LCPLL_CTL);
  6262. val &= ~LCPLL_PLL_DISABLE;
  6263. I915_WRITE(LCPLL_CTL, val);
  6264. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6265. DRM_ERROR("LCPLL not locked yet\n");
  6266. if (val & LCPLL_CD_SOURCE_FCLK) {
  6267. val = I915_READ(LCPLL_CTL);
  6268. val &= ~LCPLL_CD_SOURCE_FCLK;
  6269. I915_WRITE(LCPLL_CTL, val);
  6270. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6271. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6272. DRM_ERROR("Switching back to LCPLL failed\n");
  6273. }
  6274. /* See the big comment above. */
  6275. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6276. if (--dev_priv->uncore.forcewake_count == 0)
  6277. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6278. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6279. }
  6280. /*
  6281. * Package states C8 and deeper are really deep PC states that can only be
  6282. * reached when all the devices on the system allow it, so even if the graphics
  6283. * device allows PC8+, it doesn't mean the system will actually get to these
  6284. * states. Our driver only allows PC8+ when going into runtime PM.
  6285. *
  6286. * The requirements for PC8+ are that all the outputs are disabled, the power
  6287. * well is disabled and most interrupts are disabled, and these are also
  6288. * requirements for runtime PM. When these conditions are met, we manually do
  6289. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6290. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6291. * hang the machine.
  6292. *
  6293. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6294. * the state of some registers, so when we come back from PC8+ we need to
  6295. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6296. * need to take care of the registers kept by RC6. Notice that this happens even
  6297. * if we don't put the device in PCI D3 state (which is what currently happens
  6298. * because of the runtime PM support).
  6299. *
  6300. * For more, read "Display Sequences for Package C8" on the hardware
  6301. * documentation.
  6302. */
  6303. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6304. {
  6305. struct drm_device *dev = dev_priv->dev;
  6306. uint32_t val;
  6307. DRM_DEBUG_KMS("Enabling package C8+\n");
  6308. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6309. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6310. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6311. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6312. }
  6313. lpt_disable_clkout_dp(dev);
  6314. hsw_disable_lcpll(dev_priv, true, true);
  6315. }
  6316. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6317. {
  6318. struct drm_device *dev = dev_priv->dev;
  6319. uint32_t val;
  6320. DRM_DEBUG_KMS("Disabling package C8+\n");
  6321. hsw_restore_lcpll(dev_priv);
  6322. lpt_init_pch_refclk(dev);
  6323. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6324. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6325. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6326. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6327. }
  6328. intel_prepare_ddi(dev);
  6329. }
  6330. static void snb_modeset_global_resources(struct drm_device *dev)
  6331. {
  6332. modeset_update_crtc_power_domains(dev);
  6333. }
  6334. static void haswell_modeset_global_resources(struct drm_device *dev)
  6335. {
  6336. modeset_update_crtc_power_domains(dev);
  6337. }
  6338. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  6339. int x, int y,
  6340. struct drm_framebuffer *fb)
  6341. {
  6342. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6343. if (!intel_ddi_pll_select(intel_crtc))
  6344. return -EINVAL;
  6345. intel_ddi_pll_enable(intel_crtc);
  6346. intel_crtc->lowfreq_avail = false;
  6347. return 0;
  6348. }
  6349. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6350. struct intel_crtc_config *pipe_config)
  6351. {
  6352. struct drm_device *dev = crtc->base.dev;
  6353. struct drm_i915_private *dev_priv = dev->dev_private;
  6354. enum intel_display_power_domain pfit_domain;
  6355. uint32_t tmp;
  6356. if (!intel_display_power_enabled(dev_priv,
  6357. POWER_DOMAIN_PIPE(crtc->pipe)))
  6358. return false;
  6359. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6360. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6361. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6362. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6363. enum pipe trans_edp_pipe;
  6364. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6365. default:
  6366. WARN(1, "unknown pipe linked to edp transcoder\n");
  6367. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6368. case TRANS_DDI_EDP_INPUT_A_ON:
  6369. trans_edp_pipe = PIPE_A;
  6370. break;
  6371. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6372. trans_edp_pipe = PIPE_B;
  6373. break;
  6374. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6375. trans_edp_pipe = PIPE_C;
  6376. break;
  6377. }
  6378. if (trans_edp_pipe == crtc->pipe)
  6379. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6380. }
  6381. if (!intel_display_power_enabled(dev_priv,
  6382. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6383. return false;
  6384. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6385. if (!(tmp & PIPECONF_ENABLE))
  6386. return false;
  6387. /*
  6388. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6389. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6390. * the PCH transcoder is on.
  6391. */
  6392. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6393. if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(PORT_E) &&
  6394. I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6395. pipe_config->has_pch_encoder = true;
  6396. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6397. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6398. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6399. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6400. }
  6401. intel_get_pipe_timings(crtc, pipe_config);
  6402. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6403. if (intel_display_power_enabled(dev_priv, pfit_domain))
  6404. ironlake_get_pfit_config(crtc, pipe_config);
  6405. if (IS_HASWELL(dev))
  6406. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6407. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6408. pipe_config->pixel_multiplier = 1;
  6409. return true;
  6410. }
  6411. static struct {
  6412. int clock;
  6413. u32 config;
  6414. } hdmi_audio_clock[] = {
  6415. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6416. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6417. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6418. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6419. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6420. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6421. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6422. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6423. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6424. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6425. };
  6426. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6427. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6428. {
  6429. int i;
  6430. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6431. if (mode->clock == hdmi_audio_clock[i].clock)
  6432. break;
  6433. }
  6434. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6435. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6436. i = 1;
  6437. }
  6438. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6439. hdmi_audio_clock[i].clock,
  6440. hdmi_audio_clock[i].config);
  6441. return hdmi_audio_clock[i].config;
  6442. }
  6443. static bool intel_eld_uptodate(struct drm_connector *connector,
  6444. int reg_eldv, uint32_t bits_eldv,
  6445. int reg_elda, uint32_t bits_elda,
  6446. int reg_edid)
  6447. {
  6448. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6449. uint8_t *eld = connector->eld;
  6450. uint32_t i;
  6451. i = I915_READ(reg_eldv);
  6452. i &= bits_eldv;
  6453. if (!eld[0])
  6454. return !i;
  6455. if (!i)
  6456. return false;
  6457. i = I915_READ(reg_elda);
  6458. i &= ~bits_elda;
  6459. I915_WRITE(reg_elda, i);
  6460. for (i = 0; i < eld[2]; i++)
  6461. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6462. return false;
  6463. return true;
  6464. }
  6465. static void g4x_write_eld(struct drm_connector *connector,
  6466. struct drm_crtc *crtc,
  6467. struct drm_display_mode *mode)
  6468. {
  6469. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6470. uint8_t *eld = connector->eld;
  6471. uint32_t eldv;
  6472. uint32_t len;
  6473. uint32_t i;
  6474. i = I915_READ(G4X_AUD_VID_DID);
  6475. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6476. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6477. else
  6478. eldv = G4X_ELDV_DEVCTG;
  6479. if (intel_eld_uptodate(connector,
  6480. G4X_AUD_CNTL_ST, eldv,
  6481. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6482. G4X_HDMIW_HDMIEDID))
  6483. return;
  6484. i = I915_READ(G4X_AUD_CNTL_ST);
  6485. i &= ~(eldv | G4X_ELD_ADDR);
  6486. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6487. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6488. if (!eld[0])
  6489. return;
  6490. len = min_t(uint8_t, eld[2], len);
  6491. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6492. for (i = 0; i < len; i++)
  6493. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6494. i = I915_READ(G4X_AUD_CNTL_ST);
  6495. i |= eldv;
  6496. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6497. }
  6498. static void haswell_write_eld(struct drm_connector *connector,
  6499. struct drm_crtc *crtc,
  6500. struct drm_display_mode *mode)
  6501. {
  6502. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6503. uint8_t *eld = connector->eld;
  6504. uint32_t eldv;
  6505. uint32_t i;
  6506. int len;
  6507. int pipe = to_intel_crtc(crtc)->pipe;
  6508. int tmp;
  6509. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6510. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6511. int aud_config = HSW_AUD_CFG(pipe);
  6512. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6513. /* Audio output enable */
  6514. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6515. tmp = I915_READ(aud_cntrl_st2);
  6516. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6517. I915_WRITE(aud_cntrl_st2, tmp);
  6518. POSTING_READ(aud_cntrl_st2);
  6519. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6520. /* Set ELD valid state */
  6521. tmp = I915_READ(aud_cntrl_st2);
  6522. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6523. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6524. I915_WRITE(aud_cntrl_st2, tmp);
  6525. tmp = I915_READ(aud_cntrl_st2);
  6526. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6527. /* Enable HDMI mode */
  6528. tmp = I915_READ(aud_config);
  6529. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6530. /* clear N_programing_enable and N_value_index */
  6531. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6532. I915_WRITE(aud_config, tmp);
  6533. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6534. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6535. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6536. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6537. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6538. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6539. } else {
  6540. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6541. }
  6542. if (intel_eld_uptodate(connector,
  6543. aud_cntrl_st2, eldv,
  6544. aud_cntl_st, IBX_ELD_ADDRESS,
  6545. hdmiw_hdmiedid))
  6546. return;
  6547. i = I915_READ(aud_cntrl_st2);
  6548. i &= ~eldv;
  6549. I915_WRITE(aud_cntrl_st2, i);
  6550. if (!eld[0])
  6551. return;
  6552. i = I915_READ(aud_cntl_st);
  6553. i &= ~IBX_ELD_ADDRESS;
  6554. I915_WRITE(aud_cntl_st, i);
  6555. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6556. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6557. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6558. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6559. for (i = 0; i < len; i++)
  6560. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6561. i = I915_READ(aud_cntrl_st2);
  6562. i |= eldv;
  6563. I915_WRITE(aud_cntrl_st2, i);
  6564. }
  6565. static void ironlake_write_eld(struct drm_connector *connector,
  6566. struct drm_crtc *crtc,
  6567. struct drm_display_mode *mode)
  6568. {
  6569. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6570. uint8_t *eld = connector->eld;
  6571. uint32_t eldv;
  6572. uint32_t i;
  6573. int len;
  6574. int hdmiw_hdmiedid;
  6575. int aud_config;
  6576. int aud_cntl_st;
  6577. int aud_cntrl_st2;
  6578. int pipe = to_intel_crtc(crtc)->pipe;
  6579. if (HAS_PCH_IBX(connector->dev)) {
  6580. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6581. aud_config = IBX_AUD_CFG(pipe);
  6582. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6583. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6584. } else if (IS_VALLEYVIEW(connector->dev)) {
  6585. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6586. aud_config = VLV_AUD_CFG(pipe);
  6587. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6588. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6589. } else {
  6590. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6591. aud_config = CPT_AUD_CFG(pipe);
  6592. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6593. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6594. }
  6595. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6596. if (IS_VALLEYVIEW(connector->dev)) {
  6597. struct intel_encoder *intel_encoder;
  6598. struct intel_digital_port *intel_dig_port;
  6599. intel_encoder = intel_attached_encoder(connector);
  6600. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6601. i = intel_dig_port->port;
  6602. } else {
  6603. i = I915_READ(aud_cntl_st);
  6604. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6605. /* DIP_Port_Select, 0x1 = PortB */
  6606. }
  6607. if (!i) {
  6608. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6609. /* operate blindly on all ports */
  6610. eldv = IBX_ELD_VALIDB;
  6611. eldv |= IBX_ELD_VALIDB << 4;
  6612. eldv |= IBX_ELD_VALIDB << 8;
  6613. } else {
  6614. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6615. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6616. }
  6617. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6618. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6619. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6620. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6621. } else {
  6622. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6623. }
  6624. if (intel_eld_uptodate(connector,
  6625. aud_cntrl_st2, eldv,
  6626. aud_cntl_st, IBX_ELD_ADDRESS,
  6627. hdmiw_hdmiedid))
  6628. return;
  6629. i = I915_READ(aud_cntrl_st2);
  6630. i &= ~eldv;
  6631. I915_WRITE(aud_cntrl_st2, i);
  6632. if (!eld[0])
  6633. return;
  6634. i = I915_READ(aud_cntl_st);
  6635. i &= ~IBX_ELD_ADDRESS;
  6636. I915_WRITE(aud_cntl_st, i);
  6637. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6638. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6639. for (i = 0; i < len; i++)
  6640. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6641. i = I915_READ(aud_cntrl_st2);
  6642. i |= eldv;
  6643. I915_WRITE(aud_cntrl_st2, i);
  6644. }
  6645. void intel_write_eld(struct drm_encoder *encoder,
  6646. struct drm_display_mode *mode)
  6647. {
  6648. struct drm_crtc *crtc = encoder->crtc;
  6649. struct drm_connector *connector;
  6650. struct drm_device *dev = encoder->dev;
  6651. struct drm_i915_private *dev_priv = dev->dev_private;
  6652. connector = drm_select_eld(encoder, mode);
  6653. if (!connector)
  6654. return;
  6655. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6656. connector->base.id,
  6657. connector->name,
  6658. connector->encoder->base.id,
  6659. connector->encoder->name);
  6660. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6661. if (dev_priv->display.write_eld)
  6662. dev_priv->display.write_eld(connector, crtc, mode);
  6663. }
  6664. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6665. {
  6666. struct drm_device *dev = crtc->dev;
  6667. struct drm_i915_private *dev_priv = dev->dev_private;
  6668. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6669. uint32_t cntl;
  6670. if (base != intel_crtc->cursor_base) {
  6671. /* On these chipsets we can only modify the base whilst
  6672. * the cursor is disabled.
  6673. */
  6674. if (intel_crtc->cursor_cntl) {
  6675. I915_WRITE(_CURACNTR, 0);
  6676. POSTING_READ(_CURACNTR);
  6677. intel_crtc->cursor_cntl = 0;
  6678. }
  6679. I915_WRITE(_CURABASE, base);
  6680. POSTING_READ(_CURABASE);
  6681. }
  6682. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  6683. cntl = 0;
  6684. if (base)
  6685. cntl = (CURSOR_ENABLE |
  6686. CURSOR_GAMMA_ENABLE |
  6687. CURSOR_FORMAT_ARGB);
  6688. if (intel_crtc->cursor_cntl != cntl) {
  6689. I915_WRITE(_CURACNTR, cntl);
  6690. POSTING_READ(_CURACNTR);
  6691. intel_crtc->cursor_cntl = cntl;
  6692. }
  6693. }
  6694. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6695. {
  6696. struct drm_device *dev = crtc->dev;
  6697. struct drm_i915_private *dev_priv = dev->dev_private;
  6698. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6699. int pipe = intel_crtc->pipe;
  6700. uint32_t cntl;
  6701. cntl = 0;
  6702. if (base) {
  6703. cntl = MCURSOR_GAMMA_ENABLE;
  6704. switch (intel_crtc->cursor_width) {
  6705. case 64:
  6706. cntl |= CURSOR_MODE_64_ARGB_AX;
  6707. break;
  6708. case 128:
  6709. cntl |= CURSOR_MODE_128_ARGB_AX;
  6710. break;
  6711. case 256:
  6712. cntl |= CURSOR_MODE_256_ARGB_AX;
  6713. break;
  6714. default:
  6715. WARN_ON(1);
  6716. return;
  6717. }
  6718. cntl |= pipe << 28; /* Connect to correct pipe */
  6719. }
  6720. if (intel_crtc->cursor_cntl != cntl) {
  6721. I915_WRITE(CURCNTR(pipe), cntl);
  6722. POSTING_READ(CURCNTR(pipe));
  6723. intel_crtc->cursor_cntl = cntl;
  6724. }
  6725. /* and commit changes on next vblank */
  6726. I915_WRITE(CURBASE(pipe), base);
  6727. POSTING_READ(CURBASE(pipe));
  6728. }
  6729. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  6730. {
  6731. struct drm_device *dev = crtc->dev;
  6732. struct drm_i915_private *dev_priv = dev->dev_private;
  6733. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6734. int pipe = intel_crtc->pipe;
  6735. uint32_t cntl;
  6736. cntl = 0;
  6737. if (base) {
  6738. cntl = MCURSOR_GAMMA_ENABLE;
  6739. switch (intel_crtc->cursor_width) {
  6740. case 64:
  6741. cntl |= CURSOR_MODE_64_ARGB_AX;
  6742. break;
  6743. case 128:
  6744. cntl |= CURSOR_MODE_128_ARGB_AX;
  6745. break;
  6746. case 256:
  6747. cntl |= CURSOR_MODE_256_ARGB_AX;
  6748. break;
  6749. default:
  6750. WARN_ON(1);
  6751. return;
  6752. }
  6753. }
  6754. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6755. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6756. if (intel_crtc->cursor_cntl != cntl) {
  6757. I915_WRITE(CURCNTR(pipe), cntl);
  6758. POSTING_READ(CURCNTR(pipe));
  6759. intel_crtc->cursor_cntl = cntl;
  6760. }
  6761. /* and commit changes on next vblank */
  6762. I915_WRITE(CURBASE(pipe), base);
  6763. POSTING_READ(CURBASE(pipe));
  6764. }
  6765. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6766. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6767. bool on)
  6768. {
  6769. struct drm_device *dev = crtc->dev;
  6770. struct drm_i915_private *dev_priv = dev->dev_private;
  6771. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6772. int pipe = intel_crtc->pipe;
  6773. int x = crtc->cursor_x;
  6774. int y = crtc->cursor_y;
  6775. u32 base = 0, pos = 0;
  6776. if (on)
  6777. base = intel_crtc->cursor_addr;
  6778. if (x >= intel_crtc->config.pipe_src_w)
  6779. base = 0;
  6780. if (y >= intel_crtc->config.pipe_src_h)
  6781. base = 0;
  6782. if (x < 0) {
  6783. if (x + intel_crtc->cursor_width <= 0)
  6784. base = 0;
  6785. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6786. x = -x;
  6787. }
  6788. pos |= x << CURSOR_X_SHIFT;
  6789. if (y < 0) {
  6790. if (y + intel_crtc->cursor_height <= 0)
  6791. base = 0;
  6792. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6793. y = -y;
  6794. }
  6795. pos |= y << CURSOR_Y_SHIFT;
  6796. if (base == 0 && intel_crtc->cursor_base == 0)
  6797. return;
  6798. I915_WRITE(CURPOS(pipe), pos);
  6799. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev) || IS_BROADWELL(dev))
  6800. ivb_update_cursor(crtc, base);
  6801. else if (IS_845G(dev) || IS_I865G(dev))
  6802. i845_update_cursor(crtc, base);
  6803. else
  6804. i9xx_update_cursor(crtc, base);
  6805. intel_crtc->cursor_base = base;
  6806. }
  6807. /*
  6808. * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
  6809. *
  6810. * Note that the object's reference will be consumed if the update fails. If
  6811. * the update succeeds, the reference of the old object (if any) will be
  6812. * consumed.
  6813. */
  6814. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  6815. struct drm_i915_gem_object *obj,
  6816. uint32_t width, uint32_t height)
  6817. {
  6818. struct drm_device *dev = crtc->dev;
  6819. struct drm_i915_private *dev_priv = dev->dev_private;
  6820. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6821. enum pipe pipe = intel_crtc->pipe;
  6822. unsigned old_width;
  6823. uint32_t addr;
  6824. int ret;
  6825. /* if we want to turn off the cursor ignore width and height */
  6826. if (!obj) {
  6827. DRM_DEBUG_KMS("cursor off\n");
  6828. addr = 0;
  6829. obj = NULL;
  6830. mutex_lock(&dev->struct_mutex);
  6831. goto finish;
  6832. }
  6833. /* Check for which cursor types we support */
  6834. if (!((width == 64 && height == 64) ||
  6835. (width == 128 && height == 128 && !IS_GEN2(dev)) ||
  6836. (width == 256 && height == 256 && !IS_GEN2(dev)))) {
  6837. DRM_DEBUG("Cursor dimension not supported\n");
  6838. return -EINVAL;
  6839. }
  6840. if (obj->base.size < width * height * 4) {
  6841. DRM_DEBUG_KMS("buffer is too small\n");
  6842. ret = -ENOMEM;
  6843. goto fail;
  6844. }
  6845. /* we only need to pin inside GTT if cursor is non-phy */
  6846. mutex_lock(&dev->struct_mutex);
  6847. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  6848. unsigned alignment;
  6849. if (obj->tiling_mode) {
  6850. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  6851. ret = -EINVAL;
  6852. goto fail_locked;
  6853. }
  6854. /* Note that the w/a also requires 2 PTE of padding following
  6855. * the bo. We currently fill all unused PTE with the shadow
  6856. * page and so we should always have valid PTE following the
  6857. * cursor preventing the VT-d warning.
  6858. */
  6859. alignment = 0;
  6860. if (need_vtd_wa(dev))
  6861. alignment = 64*1024;
  6862. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  6863. if (ret) {
  6864. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  6865. goto fail_locked;
  6866. }
  6867. ret = i915_gem_object_put_fence(obj);
  6868. if (ret) {
  6869. DRM_DEBUG_KMS("failed to release fence for cursor");
  6870. goto fail_unpin;
  6871. }
  6872. addr = i915_gem_obj_ggtt_offset(obj);
  6873. } else {
  6874. int align = IS_I830(dev) ? 16 * 1024 : 256;
  6875. ret = i915_gem_object_attach_phys(obj, align);
  6876. if (ret) {
  6877. DRM_DEBUG_KMS("failed to attach phys object\n");
  6878. goto fail_locked;
  6879. }
  6880. addr = obj->phys_handle->busaddr;
  6881. }
  6882. if (IS_GEN2(dev))
  6883. I915_WRITE(CURSIZE, (height << 12) | width);
  6884. finish:
  6885. if (intel_crtc->cursor_bo) {
  6886. if (!INTEL_INFO(dev)->cursor_needs_physical)
  6887. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  6888. }
  6889. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  6890. INTEL_FRONTBUFFER_CURSOR(pipe));
  6891. mutex_unlock(&dev->struct_mutex);
  6892. old_width = intel_crtc->cursor_width;
  6893. intel_crtc->cursor_addr = addr;
  6894. intel_crtc->cursor_bo = obj;
  6895. intel_crtc->cursor_width = width;
  6896. intel_crtc->cursor_height = height;
  6897. if (intel_crtc->active) {
  6898. if (old_width != width)
  6899. intel_update_watermarks(crtc);
  6900. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  6901. }
  6902. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  6903. return 0;
  6904. fail_unpin:
  6905. i915_gem_object_unpin_from_display_plane(obj);
  6906. fail_locked:
  6907. mutex_unlock(&dev->struct_mutex);
  6908. fail:
  6909. drm_gem_object_unreference_unlocked(&obj->base);
  6910. return ret;
  6911. }
  6912. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  6913. u16 *blue, uint32_t start, uint32_t size)
  6914. {
  6915. int end = (start + size > 256) ? 256 : start + size, i;
  6916. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6917. for (i = start; i < end; i++) {
  6918. intel_crtc->lut_r[i] = red[i] >> 8;
  6919. intel_crtc->lut_g[i] = green[i] >> 8;
  6920. intel_crtc->lut_b[i] = blue[i] >> 8;
  6921. }
  6922. intel_crtc_load_lut(crtc);
  6923. }
  6924. /* VESA 640x480x72Hz mode to set on the pipe */
  6925. static struct drm_display_mode load_detect_mode = {
  6926. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  6927. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  6928. };
  6929. struct drm_framebuffer *
  6930. __intel_framebuffer_create(struct drm_device *dev,
  6931. struct drm_mode_fb_cmd2 *mode_cmd,
  6932. struct drm_i915_gem_object *obj)
  6933. {
  6934. struct intel_framebuffer *intel_fb;
  6935. int ret;
  6936. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  6937. if (!intel_fb) {
  6938. drm_gem_object_unreference_unlocked(&obj->base);
  6939. return ERR_PTR(-ENOMEM);
  6940. }
  6941. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  6942. if (ret)
  6943. goto err;
  6944. return &intel_fb->base;
  6945. err:
  6946. drm_gem_object_unreference_unlocked(&obj->base);
  6947. kfree(intel_fb);
  6948. return ERR_PTR(ret);
  6949. }
  6950. static struct drm_framebuffer *
  6951. intel_framebuffer_create(struct drm_device *dev,
  6952. struct drm_mode_fb_cmd2 *mode_cmd,
  6953. struct drm_i915_gem_object *obj)
  6954. {
  6955. struct drm_framebuffer *fb;
  6956. int ret;
  6957. ret = i915_mutex_lock_interruptible(dev);
  6958. if (ret)
  6959. return ERR_PTR(ret);
  6960. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  6961. mutex_unlock(&dev->struct_mutex);
  6962. return fb;
  6963. }
  6964. static u32
  6965. intel_framebuffer_pitch_for_width(int width, int bpp)
  6966. {
  6967. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  6968. return ALIGN(pitch, 64);
  6969. }
  6970. static u32
  6971. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  6972. {
  6973. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  6974. return PAGE_ALIGN(pitch * mode->vdisplay);
  6975. }
  6976. static struct drm_framebuffer *
  6977. intel_framebuffer_create_for_mode(struct drm_device *dev,
  6978. struct drm_display_mode *mode,
  6979. int depth, int bpp)
  6980. {
  6981. struct drm_i915_gem_object *obj;
  6982. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  6983. obj = i915_gem_alloc_object(dev,
  6984. intel_framebuffer_size_for_mode(mode, bpp));
  6985. if (obj == NULL)
  6986. return ERR_PTR(-ENOMEM);
  6987. mode_cmd.width = mode->hdisplay;
  6988. mode_cmd.height = mode->vdisplay;
  6989. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  6990. bpp);
  6991. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  6992. return intel_framebuffer_create(dev, &mode_cmd, obj);
  6993. }
  6994. static struct drm_framebuffer *
  6995. mode_fits_in_fbdev(struct drm_device *dev,
  6996. struct drm_display_mode *mode)
  6997. {
  6998. #ifdef CONFIG_DRM_I915_FBDEV
  6999. struct drm_i915_private *dev_priv = dev->dev_private;
  7000. struct drm_i915_gem_object *obj;
  7001. struct drm_framebuffer *fb;
  7002. if (!dev_priv->fbdev)
  7003. return NULL;
  7004. if (!dev_priv->fbdev->fb)
  7005. return NULL;
  7006. obj = dev_priv->fbdev->fb->obj;
  7007. BUG_ON(!obj);
  7008. fb = &dev_priv->fbdev->fb->base;
  7009. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7010. fb->bits_per_pixel))
  7011. return NULL;
  7012. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7013. return NULL;
  7014. return fb;
  7015. #else
  7016. return NULL;
  7017. #endif
  7018. }
  7019. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7020. struct drm_display_mode *mode,
  7021. struct intel_load_detect_pipe *old,
  7022. struct drm_modeset_acquire_ctx *ctx)
  7023. {
  7024. struct intel_crtc *intel_crtc;
  7025. struct intel_encoder *intel_encoder =
  7026. intel_attached_encoder(connector);
  7027. struct drm_crtc *possible_crtc;
  7028. struct drm_encoder *encoder = &intel_encoder->base;
  7029. struct drm_crtc *crtc = NULL;
  7030. struct drm_device *dev = encoder->dev;
  7031. struct drm_framebuffer *fb;
  7032. struct drm_mode_config *config = &dev->mode_config;
  7033. int ret, i = -1;
  7034. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7035. connector->base.id, connector->name,
  7036. encoder->base.id, encoder->name);
  7037. drm_modeset_acquire_init(ctx, 0);
  7038. retry:
  7039. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7040. if (ret)
  7041. goto fail_unlock;
  7042. /*
  7043. * Algorithm gets a little messy:
  7044. *
  7045. * - if the connector already has an assigned crtc, use it (but make
  7046. * sure it's on first)
  7047. *
  7048. * - try to find the first unused crtc that can drive this connector,
  7049. * and use that if we find one
  7050. */
  7051. /* See if we already have a CRTC for this connector */
  7052. if (encoder->crtc) {
  7053. crtc = encoder->crtc;
  7054. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7055. if (ret)
  7056. goto fail_unlock;
  7057. old->dpms_mode = connector->dpms;
  7058. old->load_detect_temp = false;
  7059. /* Make sure the crtc and connector are running */
  7060. if (connector->dpms != DRM_MODE_DPMS_ON)
  7061. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7062. return true;
  7063. }
  7064. /* Find an unused one (if possible) */
  7065. for_each_crtc(dev, possible_crtc) {
  7066. i++;
  7067. if (!(encoder->possible_crtcs & (1 << i)))
  7068. continue;
  7069. if (!possible_crtc->enabled) {
  7070. crtc = possible_crtc;
  7071. break;
  7072. }
  7073. }
  7074. /*
  7075. * If we didn't find an unused CRTC, don't use any.
  7076. */
  7077. if (!crtc) {
  7078. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7079. goto fail_unlock;
  7080. }
  7081. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7082. if (ret)
  7083. goto fail_unlock;
  7084. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7085. to_intel_connector(connector)->new_encoder = intel_encoder;
  7086. intel_crtc = to_intel_crtc(crtc);
  7087. intel_crtc->new_enabled = true;
  7088. intel_crtc->new_config = &intel_crtc->config;
  7089. old->dpms_mode = connector->dpms;
  7090. old->load_detect_temp = true;
  7091. old->release_fb = NULL;
  7092. if (!mode)
  7093. mode = &load_detect_mode;
  7094. /* We need a framebuffer large enough to accommodate all accesses
  7095. * that the plane may generate whilst we perform load detection.
  7096. * We can not rely on the fbcon either being present (we get called
  7097. * during its initialisation to detect all boot displays, or it may
  7098. * not even exist) or that it is large enough to satisfy the
  7099. * requested mode.
  7100. */
  7101. fb = mode_fits_in_fbdev(dev, mode);
  7102. if (fb == NULL) {
  7103. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7104. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7105. old->release_fb = fb;
  7106. } else
  7107. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7108. if (IS_ERR(fb)) {
  7109. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7110. goto fail;
  7111. }
  7112. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7113. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7114. if (old->release_fb)
  7115. old->release_fb->funcs->destroy(old->release_fb);
  7116. goto fail;
  7117. }
  7118. /* let the connector get through one full cycle before testing */
  7119. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7120. return true;
  7121. fail:
  7122. intel_crtc->new_enabled = crtc->enabled;
  7123. if (intel_crtc->new_enabled)
  7124. intel_crtc->new_config = &intel_crtc->config;
  7125. else
  7126. intel_crtc->new_config = NULL;
  7127. fail_unlock:
  7128. if (ret == -EDEADLK) {
  7129. drm_modeset_backoff(ctx);
  7130. goto retry;
  7131. }
  7132. drm_modeset_drop_locks(ctx);
  7133. drm_modeset_acquire_fini(ctx);
  7134. return false;
  7135. }
  7136. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7137. struct intel_load_detect_pipe *old,
  7138. struct drm_modeset_acquire_ctx *ctx)
  7139. {
  7140. struct intel_encoder *intel_encoder =
  7141. intel_attached_encoder(connector);
  7142. struct drm_encoder *encoder = &intel_encoder->base;
  7143. struct drm_crtc *crtc = encoder->crtc;
  7144. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7145. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7146. connector->base.id, connector->name,
  7147. encoder->base.id, encoder->name);
  7148. if (old->load_detect_temp) {
  7149. to_intel_connector(connector)->new_encoder = NULL;
  7150. intel_encoder->new_crtc = NULL;
  7151. intel_crtc->new_enabled = false;
  7152. intel_crtc->new_config = NULL;
  7153. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7154. if (old->release_fb) {
  7155. drm_framebuffer_unregister_private(old->release_fb);
  7156. drm_framebuffer_unreference(old->release_fb);
  7157. }
  7158. goto unlock;
  7159. return;
  7160. }
  7161. /* Switch crtc and encoder back off if necessary */
  7162. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7163. connector->funcs->dpms(connector, old->dpms_mode);
  7164. unlock:
  7165. drm_modeset_drop_locks(ctx);
  7166. drm_modeset_acquire_fini(ctx);
  7167. }
  7168. static int i9xx_pll_refclk(struct drm_device *dev,
  7169. const struct intel_crtc_config *pipe_config)
  7170. {
  7171. struct drm_i915_private *dev_priv = dev->dev_private;
  7172. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7173. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7174. return dev_priv->vbt.lvds_ssc_freq;
  7175. else if (HAS_PCH_SPLIT(dev))
  7176. return 120000;
  7177. else if (!IS_GEN2(dev))
  7178. return 96000;
  7179. else
  7180. return 48000;
  7181. }
  7182. /* Returns the clock of the currently programmed mode of the given pipe. */
  7183. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7184. struct intel_crtc_config *pipe_config)
  7185. {
  7186. struct drm_device *dev = crtc->base.dev;
  7187. struct drm_i915_private *dev_priv = dev->dev_private;
  7188. int pipe = pipe_config->cpu_transcoder;
  7189. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7190. u32 fp;
  7191. intel_clock_t clock;
  7192. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7193. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7194. fp = pipe_config->dpll_hw_state.fp0;
  7195. else
  7196. fp = pipe_config->dpll_hw_state.fp1;
  7197. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7198. if (IS_PINEVIEW(dev)) {
  7199. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7200. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7201. } else {
  7202. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7203. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7204. }
  7205. if (!IS_GEN2(dev)) {
  7206. if (IS_PINEVIEW(dev))
  7207. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7208. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7209. else
  7210. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7211. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7212. switch (dpll & DPLL_MODE_MASK) {
  7213. case DPLLB_MODE_DAC_SERIAL:
  7214. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7215. 5 : 10;
  7216. break;
  7217. case DPLLB_MODE_LVDS:
  7218. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7219. 7 : 14;
  7220. break;
  7221. default:
  7222. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7223. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7224. return;
  7225. }
  7226. if (IS_PINEVIEW(dev))
  7227. pineview_clock(refclk, &clock);
  7228. else
  7229. i9xx_clock(refclk, &clock);
  7230. } else {
  7231. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7232. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7233. if (is_lvds) {
  7234. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7235. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7236. if (lvds & LVDS_CLKB_POWER_UP)
  7237. clock.p2 = 7;
  7238. else
  7239. clock.p2 = 14;
  7240. } else {
  7241. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7242. clock.p1 = 2;
  7243. else {
  7244. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7245. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7246. }
  7247. if (dpll & PLL_P2_DIVIDE_BY_4)
  7248. clock.p2 = 4;
  7249. else
  7250. clock.p2 = 2;
  7251. }
  7252. i9xx_clock(refclk, &clock);
  7253. }
  7254. /*
  7255. * This value includes pixel_multiplier. We will use
  7256. * port_clock to compute adjusted_mode.crtc_clock in the
  7257. * encoder's get_config() function.
  7258. */
  7259. pipe_config->port_clock = clock.dot;
  7260. }
  7261. int intel_dotclock_calculate(int link_freq,
  7262. const struct intel_link_m_n *m_n)
  7263. {
  7264. /*
  7265. * The calculation for the data clock is:
  7266. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7267. * But we want to avoid losing precison if possible, so:
  7268. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7269. *
  7270. * and the link clock is simpler:
  7271. * link_clock = (m * link_clock) / n
  7272. */
  7273. if (!m_n->link_n)
  7274. return 0;
  7275. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7276. }
  7277. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7278. struct intel_crtc_config *pipe_config)
  7279. {
  7280. struct drm_device *dev = crtc->base.dev;
  7281. /* read out port_clock from the DPLL */
  7282. i9xx_crtc_clock_get(crtc, pipe_config);
  7283. /*
  7284. * This value does not include pixel_multiplier.
  7285. * We will check that port_clock and adjusted_mode.crtc_clock
  7286. * agree once we know their relationship in the encoder's
  7287. * get_config() function.
  7288. */
  7289. pipe_config->adjusted_mode.crtc_clock =
  7290. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7291. &pipe_config->fdi_m_n);
  7292. }
  7293. /** Returns the currently programmed mode of the given pipe. */
  7294. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7295. struct drm_crtc *crtc)
  7296. {
  7297. struct drm_i915_private *dev_priv = dev->dev_private;
  7298. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7299. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7300. struct drm_display_mode *mode;
  7301. struct intel_crtc_config pipe_config;
  7302. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7303. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7304. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7305. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7306. enum pipe pipe = intel_crtc->pipe;
  7307. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7308. if (!mode)
  7309. return NULL;
  7310. /*
  7311. * Construct a pipe_config sufficient for getting the clock info
  7312. * back out of crtc_clock_get.
  7313. *
  7314. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7315. * to use a real value here instead.
  7316. */
  7317. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7318. pipe_config.pixel_multiplier = 1;
  7319. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7320. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7321. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7322. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7323. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7324. mode->hdisplay = (htot & 0xffff) + 1;
  7325. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7326. mode->hsync_start = (hsync & 0xffff) + 1;
  7327. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7328. mode->vdisplay = (vtot & 0xffff) + 1;
  7329. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7330. mode->vsync_start = (vsync & 0xffff) + 1;
  7331. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7332. drm_mode_set_name(mode);
  7333. return mode;
  7334. }
  7335. static void intel_increase_pllclock(struct drm_device *dev,
  7336. enum pipe pipe)
  7337. {
  7338. struct drm_i915_private *dev_priv = dev->dev_private;
  7339. int dpll_reg = DPLL(pipe);
  7340. int dpll;
  7341. if (HAS_PCH_SPLIT(dev))
  7342. return;
  7343. if (!dev_priv->lvds_downclock_avail)
  7344. return;
  7345. dpll = I915_READ(dpll_reg);
  7346. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  7347. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  7348. assert_panel_unlocked(dev_priv, pipe);
  7349. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  7350. I915_WRITE(dpll_reg, dpll);
  7351. intel_wait_for_vblank(dev, pipe);
  7352. dpll = I915_READ(dpll_reg);
  7353. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  7354. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  7355. }
  7356. }
  7357. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7358. {
  7359. struct drm_device *dev = crtc->dev;
  7360. struct drm_i915_private *dev_priv = dev->dev_private;
  7361. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7362. if (HAS_PCH_SPLIT(dev))
  7363. return;
  7364. if (!dev_priv->lvds_downclock_avail)
  7365. return;
  7366. /*
  7367. * Since this is called by a timer, we should never get here in
  7368. * the manual case.
  7369. */
  7370. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7371. int pipe = intel_crtc->pipe;
  7372. int dpll_reg = DPLL(pipe);
  7373. int dpll;
  7374. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7375. assert_panel_unlocked(dev_priv, pipe);
  7376. dpll = I915_READ(dpll_reg);
  7377. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7378. I915_WRITE(dpll_reg, dpll);
  7379. intel_wait_for_vblank(dev, pipe);
  7380. dpll = I915_READ(dpll_reg);
  7381. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7382. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7383. }
  7384. }
  7385. void intel_mark_busy(struct drm_device *dev)
  7386. {
  7387. struct drm_i915_private *dev_priv = dev->dev_private;
  7388. if (dev_priv->mm.busy)
  7389. return;
  7390. intel_runtime_pm_get(dev_priv);
  7391. i915_update_gfx_val(dev_priv);
  7392. dev_priv->mm.busy = true;
  7393. }
  7394. void intel_mark_idle(struct drm_device *dev)
  7395. {
  7396. struct drm_i915_private *dev_priv = dev->dev_private;
  7397. struct drm_crtc *crtc;
  7398. if (!dev_priv->mm.busy)
  7399. return;
  7400. dev_priv->mm.busy = false;
  7401. if (!i915.powersave)
  7402. goto out;
  7403. for_each_crtc(dev, crtc) {
  7404. if (!crtc->primary->fb)
  7405. continue;
  7406. intel_decrease_pllclock(crtc);
  7407. }
  7408. if (INTEL_INFO(dev)->gen >= 6)
  7409. gen6_rps_idle(dev->dev_private);
  7410. out:
  7411. intel_runtime_pm_put(dev_priv);
  7412. }
  7413. /**
  7414. * intel_mark_fb_busy - mark given planes as busy
  7415. * @dev: DRM device
  7416. * @frontbuffer_bits: bits for the affected planes
  7417. * @ring: optional ring for asynchronous commands
  7418. *
  7419. * This function gets called every time the screen contents change. It can be
  7420. * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
  7421. */
  7422. static void intel_mark_fb_busy(struct drm_device *dev,
  7423. unsigned frontbuffer_bits,
  7424. struct intel_engine_cs *ring)
  7425. {
  7426. enum pipe pipe;
  7427. if (!i915.powersave)
  7428. return;
  7429. for_each_pipe(pipe) {
  7430. if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)))
  7431. continue;
  7432. intel_increase_pllclock(dev, pipe);
  7433. if (ring && intel_fbc_enabled(dev))
  7434. ring->fbc_dirty = true;
  7435. }
  7436. }
  7437. /**
  7438. * intel_fb_obj_invalidate - invalidate frontbuffer object
  7439. * @obj: GEM object to invalidate
  7440. * @ring: set for asynchronous rendering
  7441. *
  7442. * This function gets called every time rendering on the given object starts and
  7443. * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
  7444. * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
  7445. * until the rendering completes or a flip on this frontbuffer plane is
  7446. * scheduled.
  7447. */
  7448. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  7449. struct intel_engine_cs *ring)
  7450. {
  7451. struct drm_device *dev = obj->base.dev;
  7452. struct drm_i915_private *dev_priv = dev->dev_private;
  7453. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7454. if (!obj->frontbuffer_bits)
  7455. return;
  7456. if (ring) {
  7457. mutex_lock(&dev_priv->fb_tracking.lock);
  7458. dev_priv->fb_tracking.busy_bits
  7459. |= obj->frontbuffer_bits;
  7460. dev_priv->fb_tracking.flip_bits
  7461. &= ~obj->frontbuffer_bits;
  7462. mutex_unlock(&dev_priv->fb_tracking.lock);
  7463. }
  7464. intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring);
  7465. intel_edp_psr_exit(dev);
  7466. }
  7467. /**
  7468. * intel_frontbuffer_flush - flush frontbuffer
  7469. * @dev: DRM device
  7470. * @frontbuffer_bits: frontbuffer plane tracking bits
  7471. *
  7472. * This function gets called every time rendering on the given planes has
  7473. * completed and frontbuffer caching can be started again. Flushes will get
  7474. * delayed if they're blocked by some oustanding asynchronous rendering.
  7475. *
  7476. * Can be called without any locks held.
  7477. */
  7478. void intel_frontbuffer_flush(struct drm_device *dev,
  7479. unsigned frontbuffer_bits)
  7480. {
  7481. struct drm_i915_private *dev_priv = dev->dev_private;
  7482. /* Delay flushing when rings are still busy.*/
  7483. mutex_lock(&dev_priv->fb_tracking.lock);
  7484. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  7485. mutex_unlock(&dev_priv->fb_tracking.lock);
  7486. intel_mark_fb_busy(dev, frontbuffer_bits, NULL);
  7487. intel_edp_psr_exit(dev);
  7488. }
  7489. /**
  7490. * intel_fb_obj_flush - flush frontbuffer object
  7491. * @obj: GEM object to flush
  7492. * @retire: set when retiring asynchronous rendering
  7493. *
  7494. * This function gets called every time rendering on the given object has
  7495. * completed and frontbuffer caching can be started again. If @retire is true
  7496. * then any delayed flushes will be unblocked.
  7497. */
  7498. void intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  7499. bool retire)
  7500. {
  7501. struct drm_device *dev = obj->base.dev;
  7502. struct drm_i915_private *dev_priv = dev->dev_private;
  7503. unsigned frontbuffer_bits;
  7504. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7505. if (!obj->frontbuffer_bits)
  7506. return;
  7507. frontbuffer_bits = obj->frontbuffer_bits;
  7508. if (retire) {
  7509. mutex_lock(&dev_priv->fb_tracking.lock);
  7510. /* Filter out new bits since rendering started. */
  7511. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  7512. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  7513. mutex_unlock(&dev_priv->fb_tracking.lock);
  7514. }
  7515. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7516. }
  7517. /**
  7518. * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
  7519. * @dev: DRM device
  7520. * @frontbuffer_bits: frontbuffer plane tracking bits
  7521. *
  7522. * This function gets called after scheduling a flip on @obj. The actual
  7523. * frontbuffer flushing will be delayed until completion is signalled with
  7524. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  7525. * flush will be cancelled.
  7526. *
  7527. * Can be called without any locks held.
  7528. */
  7529. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  7530. unsigned frontbuffer_bits)
  7531. {
  7532. struct drm_i915_private *dev_priv = dev->dev_private;
  7533. mutex_lock(&dev_priv->fb_tracking.lock);
  7534. dev_priv->fb_tracking.flip_bits
  7535. |= frontbuffer_bits;
  7536. mutex_unlock(&dev_priv->fb_tracking.lock);
  7537. }
  7538. /**
  7539. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
  7540. * @dev: DRM device
  7541. * @frontbuffer_bits: frontbuffer plane tracking bits
  7542. *
  7543. * This function gets called after the flip has been latched and will complete
  7544. * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
  7545. *
  7546. * Can be called without any locks held.
  7547. */
  7548. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  7549. unsigned frontbuffer_bits)
  7550. {
  7551. struct drm_i915_private *dev_priv = dev->dev_private;
  7552. mutex_lock(&dev_priv->fb_tracking.lock);
  7553. /* Mask any cancelled flips. */
  7554. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  7555. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  7556. mutex_unlock(&dev_priv->fb_tracking.lock);
  7557. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7558. }
  7559. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7560. {
  7561. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7562. struct drm_device *dev = crtc->dev;
  7563. struct intel_unpin_work *work;
  7564. unsigned long flags;
  7565. spin_lock_irqsave(&dev->event_lock, flags);
  7566. work = intel_crtc->unpin_work;
  7567. intel_crtc->unpin_work = NULL;
  7568. spin_unlock_irqrestore(&dev->event_lock, flags);
  7569. if (work) {
  7570. cancel_work_sync(&work->work);
  7571. kfree(work);
  7572. }
  7573. drm_crtc_cleanup(crtc);
  7574. kfree(intel_crtc);
  7575. }
  7576. static void intel_unpin_work_fn(struct work_struct *__work)
  7577. {
  7578. struct intel_unpin_work *work =
  7579. container_of(__work, struct intel_unpin_work, work);
  7580. struct drm_device *dev = work->crtc->dev;
  7581. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7582. mutex_lock(&dev->struct_mutex);
  7583. intel_unpin_fb_obj(work->old_fb_obj);
  7584. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7585. drm_gem_object_unreference(&work->old_fb_obj->base);
  7586. intel_update_fbc(dev);
  7587. mutex_unlock(&dev->struct_mutex);
  7588. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7589. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7590. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7591. kfree(work);
  7592. }
  7593. static void do_intel_finish_page_flip(struct drm_device *dev,
  7594. struct drm_crtc *crtc)
  7595. {
  7596. struct drm_i915_private *dev_priv = dev->dev_private;
  7597. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7598. struct intel_unpin_work *work;
  7599. unsigned long flags;
  7600. /* Ignore early vblank irqs */
  7601. if (intel_crtc == NULL)
  7602. return;
  7603. spin_lock_irqsave(&dev->event_lock, flags);
  7604. work = intel_crtc->unpin_work;
  7605. /* Ensure we don't miss a work->pending update ... */
  7606. smp_rmb();
  7607. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7608. spin_unlock_irqrestore(&dev->event_lock, flags);
  7609. return;
  7610. }
  7611. /* and that the unpin work is consistent wrt ->pending. */
  7612. smp_rmb();
  7613. intel_crtc->unpin_work = NULL;
  7614. if (work->event)
  7615. drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
  7616. drm_crtc_vblank_put(crtc);
  7617. spin_unlock_irqrestore(&dev->event_lock, flags);
  7618. wake_up_all(&dev_priv->pending_flip_queue);
  7619. queue_work(dev_priv->wq, &work->work);
  7620. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  7621. }
  7622. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7623. {
  7624. struct drm_i915_private *dev_priv = dev->dev_private;
  7625. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7626. do_intel_finish_page_flip(dev, crtc);
  7627. }
  7628. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7629. {
  7630. struct drm_i915_private *dev_priv = dev->dev_private;
  7631. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7632. do_intel_finish_page_flip(dev, crtc);
  7633. }
  7634. /* Is 'a' after or equal to 'b'? */
  7635. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7636. {
  7637. return !((a - b) & 0x80000000);
  7638. }
  7639. static bool page_flip_finished(struct intel_crtc *crtc)
  7640. {
  7641. struct drm_device *dev = crtc->base.dev;
  7642. struct drm_i915_private *dev_priv = dev->dev_private;
  7643. /*
  7644. * The relevant registers doen't exist on pre-ctg.
  7645. * As the flip done interrupt doesn't trigger for mmio
  7646. * flips on gmch platforms, a flip count check isn't
  7647. * really needed there. But since ctg has the registers,
  7648. * include it in the check anyway.
  7649. */
  7650. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7651. return true;
  7652. /*
  7653. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7654. * used the same base address. In that case the mmio flip might
  7655. * have completed, but the CS hasn't even executed the flip yet.
  7656. *
  7657. * A flip count check isn't enough as the CS might have updated
  7658. * the base address just after start of vblank, but before we
  7659. * managed to process the interrupt. This means we'd complete the
  7660. * CS flip too soon.
  7661. *
  7662. * Combining both checks should get us a good enough result. It may
  7663. * still happen that the CS flip has been executed, but has not
  7664. * yet actually completed. But in case the base address is the same
  7665. * anyway, we don't really care.
  7666. */
  7667. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7668. crtc->unpin_work->gtt_offset &&
  7669. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7670. crtc->unpin_work->flip_count);
  7671. }
  7672. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7673. {
  7674. struct drm_i915_private *dev_priv = dev->dev_private;
  7675. struct intel_crtc *intel_crtc =
  7676. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7677. unsigned long flags;
  7678. /* NB: An MMIO update of the plane base pointer will also
  7679. * generate a page-flip completion irq, i.e. every modeset
  7680. * is also accompanied by a spurious intel_prepare_page_flip().
  7681. */
  7682. spin_lock_irqsave(&dev->event_lock, flags);
  7683. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7684. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7685. spin_unlock_irqrestore(&dev->event_lock, flags);
  7686. }
  7687. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7688. {
  7689. /* Ensure that the work item is consistent when activating it ... */
  7690. smp_wmb();
  7691. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7692. /* and that it is marked active as soon as the irq could fire. */
  7693. smp_wmb();
  7694. }
  7695. static int intel_gen2_queue_flip(struct drm_device *dev,
  7696. struct drm_crtc *crtc,
  7697. struct drm_framebuffer *fb,
  7698. struct drm_i915_gem_object *obj,
  7699. struct intel_engine_cs *ring,
  7700. uint32_t flags)
  7701. {
  7702. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7703. u32 flip_mask;
  7704. int ret;
  7705. ret = intel_ring_begin(ring, 6);
  7706. if (ret)
  7707. return ret;
  7708. /* Can't queue multiple flips, so wait for the previous
  7709. * one to finish before executing the next.
  7710. */
  7711. if (intel_crtc->plane)
  7712. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7713. else
  7714. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7715. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7716. intel_ring_emit(ring, MI_NOOP);
  7717. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7718. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7719. intel_ring_emit(ring, fb->pitches[0]);
  7720. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7721. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7722. intel_mark_page_flip_active(intel_crtc);
  7723. __intel_ring_advance(ring);
  7724. return 0;
  7725. }
  7726. static int intel_gen3_queue_flip(struct drm_device *dev,
  7727. struct drm_crtc *crtc,
  7728. struct drm_framebuffer *fb,
  7729. struct drm_i915_gem_object *obj,
  7730. struct intel_engine_cs *ring,
  7731. uint32_t flags)
  7732. {
  7733. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7734. u32 flip_mask;
  7735. int ret;
  7736. ret = intel_ring_begin(ring, 6);
  7737. if (ret)
  7738. return ret;
  7739. if (intel_crtc->plane)
  7740. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7741. else
  7742. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7743. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7744. intel_ring_emit(ring, MI_NOOP);
  7745. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7746. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7747. intel_ring_emit(ring, fb->pitches[0]);
  7748. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7749. intel_ring_emit(ring, MI_NOOP);
  7750. intel_mark_page_flip_active(intel_crtc);
  7751. __intel_ring_advance(ring);
  7752. return 0;
  7753. }
  7754. static int intel_gen4_queue_flip(struct drm_device *dev,
  7755. struct drm_crtc *crtc,
  7756. struct drm_framebuffer *fb,
  7757. struct drm_i915_gem_object *obj,
  7758. struct intel_engine_cs *ring,
  7759. uint32_t flags)
  7760. {
  7761. struct drm_i915_private *dev_priv = dev->dev_private;
  7762. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7763. uint32_t pf, pipesrc;
  7764. int ret;
  7765. ret = intel_ring_begin(ring, 4);
  7766. if (ret)
  7767. return ret;
  7768. /* i965+ uses the linear or tiled offsets from the
  7769. * Display Registers (which do not change across a page-flip)
  7770. * so we need only reprogram the base address.
  7771. */
  7772. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7773. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7774. intel_ring_emit(ring, fb->pitches[0]);
  7775. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7776. obj->tiling_mode);
  7777. /* XXX Enabling the panel-fitter across page-flip is so far
  7778. * untested on non-native modes, so ignore it for now.
  7779. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  7780. */
  7781. pf = 0;
  7782. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7783. intel_ring_emit(ring, pf | pipesrc);
  7784. intel_mark_page_flip_active(intel_crtc);
  7785. __intel_ring_advance(ring);
  7786. return 0;
  7787. }
  7788. static int intel_gen6_queue_flip(struct drm_device *dev,
  7789. struct drm_crtc *crtc,
  7790. struct drm_framebuffer *fb,
  7791. struct drm_i915_gem_object *obj,
  7792. struct intel_engine_cs *ring,
  7793. uint32_t flags)
  7794. {
  7795. struct drm_i915_private *dev_priv = dev->dev_private;
  7796. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7797. uint32_t pf, pipesrc;
  7798. int ret;
  7799. ret = intel_ring_begin(ring, 4);
  7800. if (ret)
  7801. return ret;
  7802. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7803. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7804. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  7805. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7806. /* Contrary to the suggestions in the documentation,
  7807. * "Enable Panel Fitter" does not seem to be required when page
  7808. * flipping with a non-native mode, and worse causes a normal
  7809. * modeset to fail.
  7810. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  7811. */
  7812. pf = 0;
  7813. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  7814. intel_ring_emit(ring, pf | pipesrc);
  7815. intel_mark_page_flip_active(intel_crtc);
  7816. __intel_ring_advance(ring);
  7817. return 0;
  7818. }
  7819. static int intel_gen7_queue_flip(struct drm_device *dev,
  7820. struct drm_crtc *crtc,
  7821. struct drm_framebuffer *fb,
  7822. struct drm_i915_gem_object *obj,
  7823. struct intel_engine_cs *ring,
  7824. uint32_t flags)
  7825. {
  7826. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7827. uint32_t plane_bit = 0;
  7828. int len, ret;
  7829. switch (intel_crtc->plane) {
  7830. case PLANE_A:
  7831. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  7832. break;
  7833. case PLANE_B:
  7834. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  7835. break;
  7836. case PLANE_C:
  7837. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  7838. break;
  7839. default:
  7840. WARN_ONCE(1, "unknown plane in flip command\n");
  7841. return -ENODEV;
  7842. }
  7843. len = 4;
  7844. if (ring->id == RCS) {
  7845. len += 6;
  7846. /*
  7847. * On Gen 8, SRM is now taking an extra dword to accommodate
  7848. * 48bits addresses, and we need a NOOP for the batch size to
  7849. * stay even.
  7850. */
  7851. if (IS_GEN8(dev))
  7852. len += 2;
  7853. }
  7854. /*
  7855. * BSpec MI_DISPLAY_FLIP for IVB:
  7856. * "The full packet must be contained within the same cache line."
  7857. *
  7858. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  7859. * cacheline, if we ever start emitting more commands before
  7860. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  7861. * then do the cacheline alignment, and finally emit the
  7862. * MI_DISPLAY_FLIP.
  7863. */
  7864. ret = intel_ring_cacheline_align(ring);
  7865. if (ret)
  7866. return ret;
  7867. ret = intel_ring_begin(ring, len);
  7868. if (ret)
  7869. return ret;
  7870. /* Unmask the flip-done completion message. Note that the bspec says that
  7871. * we should do this for both the BCS and RCS, and that we must not unmask
  7872. * more than one flip event at any time (or ensure that one flip message
  7873. * can be sent by waiting for flip-done prior to queueing new flips).
  7874. * Experimentation says that BCS works despite DERRMR masking all
  7875. * flip-done completion events and that unmasking all planes at once
  7876. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  7877. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  7878. */
  7879. if (ring->id == RCS) {
  7880. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  7881. intel_ring_emit(ring, DERRMR);
  7882. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  7883. DERRMR_PIPEB_PRI_FLIP_DONE |
  7884. DERRMR_PIPEC_PRI_FLIP_DONE));
  7885. if (IS_GEN8(dev))
  7886. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  7887. MI_SRM_LRM_GLOBAL_GTT);
  7888. else
  7889. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  7890. MI_SRM_LRM_GLOBAL_GTT);
  7891. intel_ring_emit(ring, DERRMR);
  7892. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  7893. if (IS_GEN8(dev)) {
  7894. intel_ring_emit(ring, 0);
  7895. intel_ring_emit(ring, MI_NOOP);
  7896. }
  7897. }
  7898. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  7899. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  7900. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7901. intel_ring_emit(ring, (MI_NOOP));
  7902. intel_mark_page_flip_active(intel_crtc);
  7903. __intel_ring_advance(ring);
  7904. return 0;
  7905. }
  7906. static bool use_mmio_flip(struct intel_engine_cs *ring,
  7907. struct drm_i915_gem_object *obj)
  7908. {
  7909. /*
  7910. * This is not being used for older platforms, because
  7911. * non-availability of flip done interrupt forces us to use
  7912. * CS flips. Older platforms derive flip done using some clever
  7913. * tricks involving the flip_pending status bits and vblank irqs.
  7914. * So using MMIO flips there would disrupt this mechanism.
  7915. */
  7916. if (INTEL_INFO(ring->dev)->gen < 5)
  7917. return false;
  7918. if (i915.use_mmio_flip < 0)
  7919. return false;
  7920. else if (i915.use_mmio_flip > 0)
  7921. return true;
  7922. else
  7923. return ring != obj->ring;
  7924. }
  7925. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  7926. {
  7927. struct drm_device *dev = intel_crtc->base.dev;
  7928. struct drm_i915_private *dev_priv = dev->dev_private;
  7929. struct intel_framebuffer *intel_fb =
  7930. to_intel_framebuffer(intel_crtc->base.primary->fb);
  7931. struct drm_i915_gem_object *obj = intel_fb->obj;
  7932. u32 dspcntr;
  7933. u32 reg;
  7934. intel_mark_page_flip_active(intel_crtc);
  7935. reg = DSPCNTR(intel_crtc->plane);
  7936. dspcntr = I915_READ(reg);
  7937. if (INTEL_INFO(dev)->gen >= 4) {
  7938. if (obj->tiling_mode != I915_TILING_NONE)
  7939. dspcntr |= DISPPLANE_TILED;
  7940. else
  7941. dspcntr &= ~DISPPLANE_TILED;
  7942. }
  7943. I915_WRITE(reg, dspcntr);
  7944. I915_WRITE(DSPSURF(intel_crtc->plane),
  7945. intel_crtc->unpin_work->gtt_offset);
  7946. POSTING_READ(DSPSURF(intel_crtc->plane));
  7947. }
  7948. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  7949. {
  7950. struct intel_engine_cs *ring;
  7951. int ret;
  7952. lockdep_assert_held(&obj->base.dev->struct_mutex);
  7953. if (!obj->last_write_seqno)
  7954. return 0;
  7955. ring = obj->ring;
  7956. if (i915_seqno_passed(ring->get_seqno(ring, true),
  7957. obj->last_write_seqno))
  7958. return 0;
  7959. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  7960. if (ret)
  7961. return ret;
  7962. if (WARN_ON(!ring->irq_get(ring)))
  7963. return 0;
  7964. return 1;
  7965. }
  7966. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  7967. {
  7968. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  7969. struct intel_crtc *intel_crtc;
  7970. unsigned long irq_flags;
  7971. u32 seqno;
  7972. seqno = ring->get_seqno(ring, false);
  7973. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  7974. for_each_intel_crtc(ring->dev, intel_crtc) {
  7975. struct intel_mmio_flip *mmio_flip;
  7976. mmio_flip = &intel_crtc->mmio_flip;
  7977. if (mmio_flip->seqno == 0)
  7978. continue;
  7979. if (ring->id != mmio_flip->ring_id)
  7980. continue;
  7981. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  7982. intel_do_mmio_flip(intel_crtc);
  7983. mmio_flip->seqno = 0;
  7984. ring->irq_put(ring);
  7985. }
  7986. }
  7987. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  7988. }
  7989. static int intel_queue_mmio_flip(struct drm_device *dev,
  7990. struct drm_crtc *crtc,
  7991. struct drm_framebuffer *fb,
  7992. struct drm_i915_gem_object *obj,
  7993. struct intel_engine_cs *ring,
  7994. uint32_t flags)
  7995. {
  7996. struct drm_i915_private *dev_priv = dev->dev_private;
  7997. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7998. unsigned long irq_flags;
  7999. int ret;
  8000. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  8001. return -EBUSY;
  8002. ret = intel_postpone_flip(obj);
  8003. if (ret < 0)
  8004. return ret;
  8005. if (ret == 0) {
  8006. intel_do_mmio_flip(intel_crtc);
  8007. return 0;
  8008. }
  8009. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8010. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8011. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8012. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8013. /*
  8014. * Double check to catch cases where irq fired before
  8015. * mmio flip data was ready
  8016. */
  8017. intel_notify_mmio_flip(obj->ring);
  8018. return 0;
  8019. }
  8020. static int intel_default_queue_flip(struct drm_device *dev,
  8021. struct drm_crtc *crtc,
  8022. struct drm_framebuffer *fb,
  8023. struct drm_i915_gem_object *obj,
  8024. struct intel_engine_cs *ring,
  8025. uint32_t flags)
  8026. {
  8027. return -ENODEV;
  8028. }
  8029. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8030. struct drm_framebuffer *fb,
  8031. struct drm_pending_vblank_event *event,
  8032. uint32_t page_flip_flags)
  8033. {
  8034. struct drm_device *dev = crtc->dev;
  8035. struct drm_i915_private *dev_priv = dev->dev_private;
  8036. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8037. struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
  8038. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8039. enum pipe pipe = intel_crtc->pipe;
  8040. struct intel_unpin_work *work;
  8041. struct intel_engine_cs *ring;
  8042. unsigned long flags;
  8043. int ret;
  8044. /* Can't change pixel format via MI display flips. */
  8045. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8046. return -EINVAL;
  8047. /*
  8048. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8049. * Note that pitch changes could also affect these register.
  8050. */
  8051. if (INTEL_INFO(dev)->gen > 3 &&
  8052. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8053. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8054. return -EINVAL;
  8055. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8056. goto out_hang;
  8057. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8058. if (work == NULL)
  8059. return -ENOMEM;
  8060. work->event = event;
  8061. work->crtc = crtc;
  8062. work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
  8063. INIT_WORK(&work->work, intel_unpin_work_fn);
  8064. ret = drm_crtc_vblank_get(crtc);
  8065. if (ret)
  8066. goto free_work;
  8067. /* We borrow the event spin lock for protecting unpin_work */
  8068. spin_lock_irqsave(&dev->event_lock, flags);
  8069. if (intel_crtc->unpin_work) {
  8070. spin_unlock_irqrestore(&dev->event_lock, flags);
  8071. kfree(work);
  8072. drm_crtc_vblank_put(crtc);
  8073. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8074. return -EBUSY;
  8075. }
  8076. intel_crtc->unpin_work = work;
  8077. spin_unlock_irqrestore(&dev->event_lock, flags);
  8078. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8079. flush_workqueue(dev_priv->wq);
  8080. ret = i915_mutex_lock_interruptible(dev);
  8081. if (ret)
  8082. goto cleanup;
  8083. /* Reference the objects for the scheduled work. */
  8084. drm_gem_object_reference(&work->old_fb_obj->base);
  8085. drm_gem_object_reference(&obj->base);
  8086. crtc->primary->fb = fb;
  8087. work->pending_flip_obj = obj;
  8088. work->enable_stall_check = true;
  8089. atomic_inc(&intel_crtc->unpin_work_count);
  8090. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8091. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8092. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8093. if (IS_VALLEYVIEW(dev)) {
  8094. ring = &dev_priv->ring[BCS];
  8095. } else if (INTEL_INFO(dev)->gen >= 7) {
  8096. ring = obj->ring;
  8097. if (ring == NULL || ring->id != RCS)
  8098. ring = &dev_priv->ring[BCS];
  8099. } else {
  8100. ring = &dev_priv->ring[RCS];
  8101. }
  8102. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8103. if (ret)
  8104. goto cleanup_pending;
  8105. work->gtt_offset =
  8106. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8107. if (use_mmio_flip(ring, obj))
  8108. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8109. page_flip_flags);
  8110. else
  8111. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8112. page_flip_flags);
  8113. if (ret)
  8114. goto cleanup_unpin;
  8115. i915_gem_track_fb(work->old_fb_obj, obj,
  8116. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8117. intel_disable_fbc(dev);
  8118. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8119. mutex_unlock(&dev->struct_mutex);
  8120. trace_i915_flip_request(intel_crtc->plane, obj);
  8121. return 0;
  8122. cleanup_unpin:
  8123. intel_unpin_fb_obj(obj);
  8124. cleanup_pending:
  8125. atomic_dec(&intel_crtc->unpin_work_count);
  8126. crtc->primary->fb = old_fb;
  8127. drm_gem_object_unreference(&work->old_fb_obj->base);
  8128. drm_gem_object_unreference(&obj->base);
  8129. mutex_unlock(&dev->struct_mutex);
  8130. cleanup:
  8131. spin_lock_irqsave(&dev->event_lock, flags);
  8132. intel_crtc->unpin_work = NULL;
  8133. spin_unlock_irqrestore(&dev->event_lock, flags);
  8134. drm_crtc_vblank_put(crtc);
  8135. free_work:
  8136. kfree(work);
  8137. if (ret == -EIO) {
  8138. out_hang:
  8139. intel_crtc_wait_for_pending_flips(crtc);
  8140. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8141. if (ret == 0 && event)
  8142. drm_send_vblank_event(dev, pipe, event);
  8143. }
  8144. return ret;
  8145. }
  8146. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8147. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8148. .load_lut = intel_crtc_load_lut,
  8149. };
  8150. /**
  8151. * intel_modeset_update_staged_output_state
  8152. *
  8153. * Updates the staged output configuration state, e.g. after we've read out the
  8154. * current hw state.
  8155. */
  8156. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8157. {
  8158. struct intel_crtc *crtc;
  8159. struct intel_encoder *encoder;
  8160. struct intel_connector *connector;
  8161. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8162. base.head) {
  8163. connector->new_encoder =
  8164. to_intel_encoder(connector->base.encoder);
  8165. }
  8166. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8167. base.head) {
  8168. encoder->new_crtc =
  8169. to_intel_crtc(encoder->base.crtc);
  8170. }
  8171. for_each_intel_crtc(dev, crtc) {
  8172. crtc->new_enabled = crtc->base.enabled;
  8173. if (crtc->new_enabled)
  8174. crtc->new_config = &crtc->config;
  8175. else
  8176. crtc->new_config = NULL;
  8177. }
  8178. }
  8179. /**
  8180. * intel_modeset_commit_output_state
  8181. *
  8182. * This function copies the stage display pipe configuration to the real one.
  8183. */
  8184. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8185. {
  8186. struct intel_crtc *crtc;
  8187. struct intel_encoder *encoder;
  8188. struct intel_connector *connector;
  8189. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8190. base.head) {
  8191. connector->base.encoder = &connector->new_encoder->base;
  8192. }
  8193. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8194. base.head) {
  8195. encoder->base.crtc = &encoder->new_crtc->base;
  8196. }
  8197. for_each_intel_crtc(dev, crtc) {
  8198. crtc->base.enabled = crtc->new_enabled;
  8199. }
  8200. }
  8201. static void
  8202. connected_sink_compute_bpp(struct intel_connector *connector,
  8203. struct intel_crtc_config *pipe_config)
  8204. {
  8205. int bpp = pipe_config->pipe_bpp;
  8206. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8207. connector->base.base.id,
  8208. connector->base.name);
  8209. /* Don't use an invalid EDID bpc value */
  8210. if (connector->base.display_info.bpc &&
  8211. connector->base.display_info.bpc * 3 < bpp) {
  8212. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8213. bpp, connector->base.display_info.bpc*3);
  8214. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8215. }
  8216. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8217. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8218. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8219. bpp);
  8220. pipe_config->pipe_bpp = 24;
  8221. }
  8222. }
  8223. static int
  8224. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8225. struct drm_framebuffer *fb,
  8226. struct intel_crtc_config *pipe_config)
  8227. {
  8228. struct drm_device *dev = crtc->base.dev;
  8229. struct intel_connector *connector;
  8230. int bpp;
  8231. switch (fb->pixel_format) {
  8232. case DRM_FORMAT_C8:
  8233. bpp = 8*3; /* since we go through a colormap */
  8234. break;
  8235. case DRM_FORMAT_XRGB1555:
  8236. case DRM_FORMAT_ARGB1555:
  8237. /* checked in intel_framebuffer_init already */
  8238. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8239. return -EINVAL;
  8240. case DRM_FORMAT_RGB565:
  8241. bpp = 6*3; /* min is 18bpp */
  8242. break;
  8243. case DRM_FORMAT_XBGR8888:
  8244. case DRM_FORMAT_ABGR8888:
  8245. /* checked in intel_framebuffer_init already */
  8246. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8247. return -EINVAL;
  8248. case DRM_FORMAT_XRGB8888:
  8249. case DRM_FORMAT_ARGB8888:
  8250. bpp = 8*3;
  8251. break;
  8252. case DRM_FORMAT_XRGB2101010:
  8253. case DRM_FORMAT_ARGB2101010:
  8254. case DRM_FORMAT_XBGR2101010:
  8255. case DRM_FORMAT_ABGR2101010:
  8256. /* checked in intel_framebuffer_init already */
  8257. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8258. return -EINVAL;
  8259. bpp = 10*3;
  8260. break;
  8261. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8262. default:
  8263. DRM_DEBUG_KMS("unsupported depth\n");
  8264. return -EINVAL;
  8265. }
  8266. pipe_config->pipe_bpp = bpp;
  8267. /* Clamp display bpp to EDID value */
  8268. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8269. base.head) {
  8270. if (!connector->new_encoder ||
  8271. connector->new_encoder->new_crtc != crtc)
  8272. continue;
  8273. connected_sink_compute_bpp(connector, pipe_config);
  8274. }
  8275. return bpp;
  8276. }
  8277. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8278. {
  8279. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8280. "type: 0x%x flags: 0x%x\n",
  8281. mode->crtc_clock,
  8282. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8283. mode->crtc_hsync_end, mode->crtc_htotal,
  8284. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8285. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8286. }
  8287. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8288. struct intel_crtc_config *pipe_config,
  8289. const char *context)
  8290. {
  8291. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8292. context, pipe_name(crtc->pipe));
  8293. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8294. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8295. pipe_config->pipe_bpp, pipe_config->dither);
  8296. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8297. pipe_config->has_pch_encoder,
  8298. pipe_config->fdi_lanes,
  8299. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8300. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8301. pipe_config->fdi_m_n.tu);
  8302. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8303. pipe_config->has_dp_encoder,
  8304. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8305. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8306. pipe_config->dp_m_n.tu);
  8307. DRM_DEBUG_KMS("requested mode:\n");
  8308. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8309. DRM_DEBUG_KMS("adjusted mode:\n");
  8310. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8311. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8312. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8313. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8314. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8315. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8316. pipe_config->gmch_pfit.control,
  8317. pipe_config->gmch_pfit.pgm_ratios,
  8318. pipe_config->gmch_pfit.lvds_border_bits);
  8319. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8320. pipe_config->pch_pfit.pos,
  8321. pipe_config->pch_pfit.size,
  8322. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8323. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8324. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8325. }
  8326. static bool encoders_cloneable(const struct intel_encoder *a,
  8327. const struct intel_encoder *b)
  8328. {
  8329. /* masks could be asymmetric, so check both ways */
  8330. return a == b || (a->cloneable & (1 << b->type) &&
  8331. b->cloneable & (1 << a->type));
  8332. }
  8333. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8334. struct intel_encoder *encoder)
  8335. {
  8336. struct drm_device *dev = crtc->base.dev;
  8337. struct intel_encoder *source_encoder;
  8338. list_for_each_entry(source_encoder,
  8339. &dev->mode_config.encoder_list, base.head) {
  8340. if (source_encoder->new_crtc != crtc)
  8341. continue;
  8342. if (!encoders_cloneable(encoder, source_encoder))
  8343. return false;
  8344. }
  8345. return true;
  8346. }
  8347. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8348. {
  8349. struct drm_device *dev = crtc->base.dev;
  8350. struct intel_encoder *encoder;
  8351. list_for_each_entry(encoder,
  8352. &dev->mode_config.encoder_list, base.head) {
  8353. if (encoder->new_crtc != crtc)
  8354. continue;
  8355. if (!check_single_encoder_cloning(crtc, encoder))
  8356. return false;
  8357. }
  8358. return true;
  8359. }
  8360. static struct intel_crtc_config *
  8361. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8362. struct drm_framebuffer *fb,
  8363. struct drm_display_mode *mode)
  8364. {
  8365. struct drm_device *dev = crtc->dev;
  8366. struct intel_encoder *encoder;
  8367. struct intel_crtc_config *pipe_config;
  8368. int plane_bpp, ret = -EINVAL;
  8369. bool retry = true;
  8370. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8371. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8372. return ERR_PTR(-EINVAL);
  8373. }
  8374. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8375. if (!pipe_config)
  8376. return ERR_PTR(-ENOMEM);
  8377. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8378. drm_mode_copy(&pipe_config->requested_mode, mode);
  8379. pipe_config->cpu_transcoder =
  8380. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8381. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8382. /*
  8383. * Sanitize sync polarity flags based on requested ones. If neither
  8384. * positive or negative polarity is requested, treat this as meaning
  8385. * negative polarity.
  8386. */
  8387. if (!(pipe_config->adjusted_mode.flags &
  8388. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8389. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8390. if (!(pipe_config->adjusted_mode.flags &
  8391. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8392. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8393. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8394. * plane pixel format and any sink constraints into account. Returns the
  8395. * source plane bpp so that dithering can be selected on mismatches
  8396. * after encoders and crtc also have had their say. */
  8397. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8398. fb, pipe_config);
  8399. if (plane_bpp < 0)
  8400. goto fail;
  8401. /*
  8402. * Determine the real pipe dimensions. Note that stereo modes can
  8403. * increase the actual pipe size due to the frame doubling and
  8404. * insertion of additional space for blanks between the frame. This
  8405. * is stored in the crtc timings. We use the requested mode to do this
  8406. * computation to clearly distinguish it from the adjusted mode, which
  8407. * can be changed by the connectors in the below retry loop.
  8408. */
  8409. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8410. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8411. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8412. encoder_retry:
  8413. /* Ensure the port clock defaults are reset when retrying. */
  8414. pipe_config->port_clock = 0;
  8415. pipe_config->pixel_multiplier = 1;
  8416. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8417. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8418. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8419. * adjust it according to limitations or connector properties, and also
  8420. * a chance to reject the mode entirely.
  8421. */
  8422. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8423. base.head) {
  8424. if (&encoder->new_crtc->base != crtc)
  8425. continue;
  8426. if (!(encoder->compute_config(encoder, pipe_config))) {
  8427. DRM_DEBUG_KMS("Encoder config failure\n");
  8428. goto fail;
  8429. }
  8430. }
  8431. /* Set default port clock if not overwritten by the encoder. Needs to be
  8432. * done afterwards in case the encoder adjusts the mode. */
  8433. if (!pipe_config->port_clock)
  8434. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8435. * pipe_config->pixel_multiplier;
  8436. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8437. if (ret < 0) {
  8438. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8439. goto fail;
  8440. }
  8441. if (ret == RETRY) {
  8442. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8443. ret = -EINVAL;
  8444. goto fail;
  8445. }
  8446. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8447. retry = false;
  8448. goto encoder_retry;
  8449. }
  8450. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8451. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8452. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8453. return pipe_config;
  8454. fail:
  8455. kfree(pipe_config);
  8456. return ERR_PTR(ret);
  8457. }
  8458. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8459. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8460. static void
  8461. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8462. unsigned *prepare_pipes, unsigned *disable_pipes)
  8463. {
  8464. struct intel_crtc *intel_crtc;
  8465. struct drm_device *dev = crtc->dev;
  8466. struct intel_encoder *encoder;
  8467. struct intel_connector *connector;
  8468. struct drm_crtc *tmp_crtc;
  8469. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8470. /* Check which crtcs have changed outputs connected to them, these need
  8471. * to be part of the prepare_pipes mask. We don't (yet) support global
  8472. * modeset across multiple crtcs, so modeset_pipes will only have one
  8473. * bit set at most. */
  8474. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8475. base.head) {
  8476. if (connector->base.encoder == &connector->new_encoder->base)
  8477. continue;
  8478. if (connector->base.encoder) {
  8479. tmp_crtc = connector->base.encoder->crtc;
  8480. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8481. }
  8482. if (connector->new_encoder)
  8483. *prepare_pipes |=
  8484. 1 << connector->new_encoder->new_crtc->pipe;
  8485. }
  8486. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8487. base.head) {
  8488. if (encoder->base.crtc == &encoder->new_crtc->base)
  8489. continue;
  8490. if (encoder->base.crtc) {
  8491. tmp_crtc = encoder->base.crtc;
  8492. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8493. }
  8494. if (encoder->new_crtc)
  8495. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8496. }
  8497. /* Check for pipes that will be enabled/disabled ... */
  8498. for_each_intel_crtc(dev, intel_crtc) {
  8499. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8500. continue;
  8501. if (!intel_crtc->new_enabled)
  8502. *disable_pipes |= 1 << intel_crtc->pipe;
  8503. else
  8504. *prepare_pipes |= 1 << intel_crtc->pipe;
  8505. }
  8506. /* set_mode is also used to update properties on life display pipes. */
  8507. intel_crtc = to_intel_crtc(crtc);
  8508. if (intel_crtc->new_enabled)
  8509. *prepare_pipes |= 1 << intel_crtc->pipe;
  8510. /*
  8511. * For simplicity do a full modeset on any pipe where the output routing
  8512. * changed. We could be more clever, but that would require us to be
  8513. * more careful with calling the relevant encoder->mode_set functions.
  8514. */
  8515. if (*prepare_pipes)
  8516. *modeset_pipes = *prepare_pipes;
  8517. /* ... and mask these out. */
  8518. *modeset_pipes &= ~(*disable_pipes);
  8519. *prepare_pipes &= ~(*disable_pipes);
  8520. /*
  8521. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8522. * obies this rule, but the modeset restore mode of
  8523. * intel_modeset_setup_hw_state does not.
  8524. */
  8525. *modeset_pipes &= 1 << intel_crtc->pipe;
  8526. *prepare_pipes &= 1 << intel_crtc->pipe;
  8527. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8528. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8529. }
  8530. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8531. {
  8532. struct drm_encoder *encoder;
  8533. struct drm_device *dev = crtc->dev;
  8534. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8535. if (encoder->crtc == crtc)
  8536. return true;
  8537. return false;
  8538. }
  8539. static void
  8540. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8541. {
  8542. struct intel_encoder *intel_encoder;
  8543. struct intel_crtc *intel_crtc;
  8544. struct drm_connector *connector;
  8545. list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
  8546. base.head) {
  8547. if (!intel_encoder->base.crtc)
  8548. continue;
  8549. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8550. if (prepare_pipes & (1 << intel_crtc->pipe))
  8551. intel_encoder->connectors_active = false;
  8552. }
  8553. intel_modeset_commit_output_state(dev);
  8554. /* Double check state. */
  8555. for_each_intel_crtc(dev, intel_crtc) {
  8556. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8557. WARN_ON(intel_crtc->new_config &&
  8558. intel_crtc->new_config != &intel_crtc->config);
  8559. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8560. }
  8561. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8562. if (!connector->encoder || !connector->encoder->crtc)
  8563. continue;
  8564. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8565. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8566. struct drm_property *dpms_property =
  8567. dev->mode_config.dpms_property;
  8568. connector->dpms = DRM_MODE_DPMS_ON;
  8569. drm_object_property_set_value(&connector->base,
  8570. dpms_property,
  8571. DRM_MODE_DPMS_ON);
  8572. intel_encoder = to_intel_encoder(connector->encoder);
  8573. intel_encoder->connectors_active = true;
  8574. }
  8575. }
  8576. }
  8577. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8578. {
  8579. int diff;
  8580. if (clock1 == clock2)
  8581. return true;
  8582. if (!clock1 || !clock2)
  8583. return false;
  8584. diff = abs(clock1 - clock2);
  8585. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8586. return true;
  8587. return false;
  8588. }
  8589. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8590. list_for_each_entry((intel_crtc), \
  8591. &(dev)->mode_config.crtc_list, \
  8592. base.head) \
  8593. if (mask & (1 <<(intel_crtc)->pipe))
  8594. static bool
  8595. intel_pipe_config_compare(struct drm_device *dev,
  8596. struct intel_crtc_config *current_config,
  8597. struct intel_crtc_config *pipe_config)
  8598. {
  8599. #define PIPE_CONF_CHECK_X(name) \
  8600. if (current_config->name != pipe_config->name) { \
  8601. DRM_ERROR("mismatch in " #name " " \
  8602. "(expected 0x%08x, found 0x%08x)\n", \
  8603. current_config->name, \
  8604. pipe_config->name); \
  8605. return false; \
  8606. }
  8607. #define PIPE_CONF_CHECK_I(name) \
  8608. if (current_config->name != pipe_config->name) { \
  8609. DRM_ERROR("mismatch in " #name " " \
  8610. "(expected %i, found %i)\n", \
  8611. current_config->name, \
  8612. pipe_config->name); \
  8613. return false; \
  8614. }
  8615. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8616. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8617. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8618. "(expected %i, found %i)\n", \
  8619. current_config->name & (mask), \
  8620. pipe_config->name & (mask)); \
  8621. return false; \
  8622. }
  8623. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8624. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8625. DRM_ERROR("mismatch in " #name " " \
  8626. "(expected %i, found %i)\n", \
  8627. current_config->name, \
  8628. pipe_config->name); \
  8629. return false; \
  8630. }
  8631. #define PIPE_CONF_QUIRK(quirk) \
  8632. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8633. PIPE_CONF_CHECK_I(cpu_transcoder);
  8634. PIPE_CONF_CHECK_I(has_pch_encoder);
  8635. PIPE_CONF_CHECK_I(fdi_lanes);
  8636. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8637. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8638. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8639. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8640. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8641. PIPE_CONF_CHECK_I(has_dp_encoder);
  8642. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8643. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8644. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8645. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8646. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8647. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8648. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8649. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8650. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8651. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8652. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8653. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8654. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8655. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8656. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8657. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8658. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8659. PIPE_CONF_CHECK_I(pixel_multiplier);
  8660. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8661. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8662. IS_VALLEYVIEW(dev))
  8663. PIPE_CONF_CHECK_I(limited_color_range);
  8664. PIPE_CONF_CHECK_I(has_audio);
  8665. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8666. DRM_MODE_FLAG_INTERLACE);
  8667. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  8668. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8669. DRM_MODE_FLAG_PHSYNC);
  8670. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8671. DRM_MODE_FLAG_NHSYNC);
  8672. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8673. DRM_MODE_FLAG_PVSYNC);
  8674. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8675. DRM_MODE_FLAG_NVSYNC);
  8676. }
  8677. PIPE_CONF_CHECK_I(pipe_src_w);
  8678. PIPE_CONF_CHECK_I(pipe_src_h);
  8679. /*
  8680. * FIXME: BIOS likes to set up a cloned config with lvds+external
  8681. * screen. Since we don't yet re-compute the pipe config when moving
  8682. * just the lvds port away to another pipe the sw tracking won't match.
  8683. *
  8684. * Proper atomic modesets with recomputed global state will fix this.
  8685. * Until then just don't check gmch state for inherited modes.
  8686. */
  8687. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  8688. PIPE_CONF_CHECK_I(gmch_pfit.control);
  8689. /* pfit ratios are autocomputed by the hw on gen4+ */
  8690. if (INTEL_INFO(dev)->gen < 4)
  8691. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  8692. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  8693. }
  8694. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  8695. if (current_config->pch_pfit.enabled) {
  8696. PIPE_CONF_CHECK_I(pch_pfit.pos);
  8697. PIPE_CONF_CHECK_I(pch_pfit.size);
  8698. }
  8699. /* BDW+ don't expose a synchronous way to read the state */
  8700. if (IS_HASWELL(dev))
  8701. PIPE_CONF_CHECK_I(ips_enabled);
  8702. PIPE_CONF_CHECK_I(double_wide);
  8703. PIPE_CONF_CHECK_I(shared_dpll);
  8704. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  8705. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  8706. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  8707. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  8708. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  8709. PIPE_CONF_CHECK_I(pipe_bpp);
  8710. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  8711. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  8712. #undef PIPE_CONF_CHECK_X
  8713. #undef PIPE_CONF_CHECK_I
  8714. #undef PIPE_CONF_CHECK_FLAGS
  8715. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  8716. #undef PIPE_CONF_QUIRK
  8717. return true;
  8718. }
  8719. static void
  8720. check_connector_state(struct drm_device *dev)
  8721. {
  8722. struct intel_connector *connector;
  8723. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8724. base.head) {
  8725. /* This also checks the encoder/connector hw state with the
  8726. * ->get_hw_state callbacks. */
  8727. intel_connector_check_state(connector);
  8728. WARN(&connector->new_encoder->base != connector->base.encoder,
  8729. "connector's staged encoder doesn't match current encoder\n");
  8730. }
  8731. }
  8732. static void
  8733. check_encoder_state(struct drm_device *dev)
  8734. {
  8735. struct intel_encoder *encoder;
  8736. struct intel_connector *connector;
  8737. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8738. base.head) {
  8739. bool enabled = false;
  8740. bool active = false;
  8741. enum pipe pipe, tracked_pipe;
  8742. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  8743. encoder->base.base.id,
  8744. encoder->base.name);
  8745. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  8746. "encoder's stage crtc doesn't match current crtc\n");
  8747. WARN(encoder->connectors_active && !encoder->base.crtc,
  8748. "encoder's active_connectors set, but no crtc\n");
  8749. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8750. base.head) {
  8751. if (connector->base.encoder != &encoder->base)
  8752. continue;
  8753. enabled = true;
  8754. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  8755. active = true;
  8756. }
  8757. WARN(!!encoder->base.crtc != enabled,
  8758. "encoder's enabled state mismatch "
  8759. "(expected %i, found %i)\n",
  8760. !!encoder->base.crtc, enabled);
  8761. WARN(active && !encoder->base.crtc,
  8762. "active encoder with no crtc\n");
  8763. WARN(encoder->connectors_active != active,
  8764. "encoder's computed active state doesn't match tracked active state "
  8765. "(expected %i, found %i)\n", active, encoder->connectors_active);
  8766. active = encoder->get_hw_state(encoder, &pipe);
  8767. WARN(active != encoder->connectors_active,
  8768. "encoder's hw state doesn't match sw tracking "
  8769. "(expected %i, found %i)\n",
  8770. encoder->connectors_active, active);
  8771. if (!encoder->base.crtc)
  8772. continue;
  8773. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  8774. WARN(active && pipe != tracked_pipe,
  8775. "active encoder's pipe doesn't match"
  8776. "(expected %i, found %i)\n",
  8777. tracked_pipe, pipe);
  8778. }
  8779. }
  8780. static void
  8781. check_crtc_state(struct drm_device *dev)
  8782. {
  8783. struct drm_i915_private *dev_priv = dev->dev_private;
  8784. struct intel_crtc *crtc;
  8785. struct intel_encoder *encoder;
  8786. struct intel_crtc_config pipe_config;
  8787. for_each_intel_crtc(dev, crtc) {
  8788. bool enabled = false;
  8789. bool active = false;
  8790. memset(&pipe_config, 0, sizeof(pipe_config));
  8791. DRM_DEBUG_KMS("[CRTC:%d]\n",
  8792. crtc->base.base.id);
  8793. WARN(crtc->active && !crtc->base.enabled,
  8794. "active crtc, but not enabled in sw tracking\n");
  8795. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8796. base.head) {
  8797. if (encoder->base.crtc != &crtc->base)
  8798. continue;
  8799. enabled = true;
  8800. if (encoder->connectors_active)
  8801. active = true;
  8802. }
  8803. WARN(active != crtc->active,
  8804. "crtc's computed active state doesn't match tracked active state "
  8805. "(expected %i, found %i)\n", active, crtc->active);
  8806. WARN(enabled != crtc->base.enabled,
  8807. "crtc's computed enabled state doesn't match tracked enabled state "
  8808. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  8809. active = dev_priv->display.get_pipe_config(crtc,
  8810. &pipe_config);
  8811. /* hw state is inconsistent with the pipe A quirk */
  8812. if (crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  8813. active = crtc->active;
  8814. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  8815. base.head) {
  8816. enum pipe pipe;
  8817. if (encoder->base.crtc != &crtc->base)
  8818. continue;
  8819. if (encoder->get_hw_state(encoder, &pipe))
  8820. encoder->get_config(encoder, &pipe_config);
  8821. }
  8822. WARN(crtc->active != active,
  8823. "crtc active state doesn't match with hw state "
  8824. "(expected %i, found %i)\n", crtc->active, active);
  8825. if (active &&
  8826. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  8827. WARN(1, "pipe state doesn't match!\n");
  8828. intel_dump_pipe_config(crtc, &pipe_config,
  8829. "[hw state]");
  8830. intel_dump_pipe_config(crtc, &crtc->config,
  8831. "[sw state]");
  8832. }
  8833. }
  8834. }
  8835. static void
  8836. check_shared_dpll_state(struct drm_device *dev)
  8837. {
  8838. struct drm_i915_private *dev_priv = dev->dev_private;
  8839. struct intel_crtc *crtc;
  8840. struct intel_dpll_hw_state dpll_hw_state;
  8841. int i;
  8842. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  8843. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  8844. int enabled_crtcs = 0, active_crtcs = 0;
  8845. bool active;
  8846. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  8847. DRM_DEBUG_KMS("%s\n", pll->name);
  8848. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  8849. WARN(pll->active > pll->refcount,
  8850. "more active pll users than references: %i vs %i\n",
  8851. pll->active, pll->refcount);
  8852. WARN(pll->active && !pll->on,
  8853. "pll in active use but not on in sw tracking\n");
  8854. WARN(pll->on && !pll->active,
  8855. "pll in on but not on in use in sw tracking\n");
  8856. WARN(pll->on != active,
  8857. "pll on state mismatch (expected %i, found %i)\n",
  8858. pll->on, active);
  8859. for_each_intel_crtc(dev, crtc) {
  8860. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  8861. enabled_crtcs++;
  8862. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  8863. active_crtcs++;
  8864. }
  8865. WARN(pll->active != active_crtcs,
  8866. "pll active crtcs mismatch (expected %i, found %i)\n",
  8867. pll->active, active_crtcs);
  8868. WARN(pll->refcount != enabled_crtcs,
  8869. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  8870. pll->refcount, enabled_crtcs);
  8871. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  8872. sizeof(dpll_hw_state)),
  8873. "pll hw state mismatch\n");
  8874. }
  8875. }
  8876. void
  8877. intel_modeset_check_state(struct drm_device *dev)
  8878. {
  8879. check_connector_state(dev);
  8880. check_encoder_state(dev);
  8881. check_crtc_state(dev);
  8882. check_shared_dpll_state(dev);
  8883. }
  8884. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  8885. int dotclock)
  8886. {
  8887. /*
  8888. * FDI already provided one idea for the dotclock.
  8889. * Yell if the encoder disagrees.
  8890. */
  8891. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  8892. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  8893. pipe_config->adjusted_mode.crtc_clock, dotclock);
  8894. }
  8895. static void update_scanline_offset(struct intel_crtc *crtc)
  8896. {
  8897. struct drm_device *dev = crtc->base.dev;
  8898. /*
  8899. * The scanline counter increments at the leading edge of hsync.
  8900. *
  8901. * On most platforms it starts counting from vtotal-1 on the
  8902. * first active line. That means the scanline counter value is
  8903. * always one less than what we would expect. Ie. just after
  8904. * start of vblank, which also occurs at start of hsync (on the
  8905. * last active line), the scanline counter will read vblank_start-1.
  8906. *
  8907. * On gen2 the scanline counter starts counting from 1 instead
  8908. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  8909. * to keep the value positive), instead of adding one.
  8910. *
  8911. * On HSW+ the behaviour of the scanline counter depends on the output
  8912. * type. For DP ports it behaves like most other platforms, but on HDMI
  8913. * there's an extra 1 line difference. So we need to add two instead of
  8914. * one to the value.
  8915. */
  8916. if (IS_GEN2(dev)) {
  8917. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  8918. int vtotal;
  8919. vtotal = mode->crtc_vtotal;
  8920. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  8921. vtotal /= 2;
  8922. crtc->scanline_offset = vtotal - 1;
  8923. } else if (HAS_DDI(dev) &&
  8924. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
  8925. crtc->scanline_offset = 2;
  8926. } else
  8927. crtc->scanline_offset = 1;
  8928. }
  8929. static int __intel_set_mode(struct drm_crtc *crtc,
  8930. struct drm_display_mode *mode,
  8931. int x, int y, struct drm_framebuffer *fb)
  8932. {
  8933. struct drm_device *dev = crtc->dev;
  8934. struct drm_i915_private *dev_priv = dev->dev_private;
  8935. struct drm_display_mode *saved_mode;
  8936. struct intel_crtc_config *pipe_config = NULL;
  8937. struct intel_crtc *intel_crtc;
  8938. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  8939. int ret = 0;
  8940. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  8941. if (!saved_mode)
  8942. return -ENOMEM;
  8943. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  8944. &prepare_pipes, &disable_pipes);
  8945. *saved_mode = crtc->mode;
  8946. /* Hack: Because we don't (yet) support global modeset on multiple
  8947. * crtcs, we don't keep track of the new mode for more than one crtc.
  8948. * Hence simply check whether any bit is set in modeset_pipes in all the
  8949. * pieces of code that are not yet converted to deal with mutliple crtcs
  8950. * changing their mode at the same time. */
  8951. if (modeset_pipes) {
  8952. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  8953. if (IS_ERR(pipe_config)) {
  8954. ret = PTR_ERR(pipe_config);
  8955. pipe_config = NULL;
  8956. goto out;
  8957. }
  8958. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  8959. "[modeset]");
  8960. to_intel_crtc(crtc)->new_config = pipe_config;
  8961. }
  8962. /*
  8963. * See if the config requires any additional preparation, e.g.
  8964. * to adjust global state with pipes off. We need to do this
  8965. * here so we can get the modeset_pipe updated config for the new
  8966. * mode set on this crtc. For other crtcs we need to use the
  8967. * adjusted_mode bits in the crtc directly.
  8968. */
  8969. if (IS_VALLEYVIEW(dev)) {
  8970. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  8971. /* may have added more to prepare_pipes than we should */
  8972. prepare_pipes &= ~disable_pipes;
  8973. }
  8974. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  8975. intel_crtc_disable(&intel_crtc->base);
  8976. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  8977. if (intel_crtc->base.enabled)
  8978. dev_priv->display.crtc_disable(&intel_crtc->base);
  8979. }
  8980. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  8981. * to set it here already despite that we pass it down the callchain.
  8982. */
  8983. if (modeset_pipes) {
  8984. crtc->mode = *mode;
  8985. /* mode_set/enable/disable functions rely on a correct pipe
  8986. * config. */
  8987. to_intel_crtc(crtc)->config = *pipe_config;
  8988. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  8989. /*
  8990. * Calculate and store various constants which
  8991. * are later needed by vblank and swap-completion
  8992. * timestamping. They are derived from true hwmode.
  8993. */
  8994. drm_calc_timestamping_constants(crtc,
  8995. &pipe_config->adjusted_mode);
  8996. }
  8997. /* Only after disabling all output pipelines that will be changed can we
  8998. * update the the output configuration. */
  8999. intel_modeset_update_state(dev, prepare_pipes);
  9000. if (dev_priv->display.modeset_global_resources)
  9001. dev_priv->display.modeset_global_resources(dev);
  9002. /* Set up the DPLL and any encoders state that needs to adjust or depend
  9003. * on the DPLL.
  9004. */
  9005. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  9006. struct drm_framebuffer *old_fb;
  9007. struct drm_i915_gem_object *old_obj = NULL;
  9008. struct drm_i915_gem_object *obj =
  9009. to_intel_framebuffer(fb)->obj;
  9010. mutex_lock(&dev->struct_mutex);
  9011. ret = intel_pin_and_fence_fb_obj(dev,
  9012. obj,
  9013. NULL);
  9014. if (ret != 0) {
  9015. DRM_ERROR("pin & fence failed\n");
  9016. mutex_unlock(&dev->struct_mutex);
  9017. goto done;
  9018. }
  9019. old_fb = crtc->primary->fb;
  9020. if (old_fb) {
  9021. old_obj = to_intel_framebuffer(old_fb)->obj;
  9022. intel_unpin_fb_obj(old_obj);
  9023. }
  9024. i915_gem_track_fb(old_obj, obj,
  9025. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9026. mutex_unlock(&dev->struct_mutex);
  9027. crtc->primary->fb = fb;
  9028. crtc->x = x;
  9029. crtc->y = y;
  9030. ret = dev_priv->display.crtc_mode_set(&intel_crtc->base,
  9031. x, y, fb);
  9032. if (ret)
  9033. goto done;
  9034. }
  9035. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9036. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9037. update_scanline_offset(intel_crtc);
  9038. dev_priv->display.crtc_enable(&intel_crtc->base);
  9039. }
  9040. /* FIXME: add subpixel order */
  9041. done:
  9042. if (ret && crtc->enabled)
  9043. crtc->mode = *saved_mode;
  9044. out:
  9045. kfree(pipe_config);
  9046. kfree(saved_mode);
  9047. return ret;
  9048. }
  9049. static int intel_set_mode(struct drm_crtc *crtc,
  9050. struct drm_display_mode *mode,
  9051. int x, int y, struct drm_framebuffer *fb)
  9052. {
  9053. int ret;
  9054. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9055. if (ret == 0)
  9056. intel_modeset_check_state(crtc->dev);
  9057. return ret;
  9058. }
  9059. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9060. {
  9061. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9062. }
  9063. #undef for_each_intel_crtc_masked
  9064. static void intel_set_config_free(struct intel_set_config *config)
  9065. {
  9066. if (!config)
  9067. return;
  9068. kfree(config->save_connector_encoders);
  9069. kfree(config->save_encoder_crtcs);
  9070. kfree(config->save_crtc_enabled);
  9071. kfree(config);
  9072. }
  9073. static int intel_set_config_save_state(struct drm_device *dev,
  9074. struct intel_set_config *config)
  9075. {
  9076. struct drm_crtc *crtc;
  9077. struct drm_encoder *encoder;
  9078. struct drm_connector *connector;
  9079. int count;
  9080. config->save_crtc_enabled =
  9081. kcalloc(dev->mode_config.num_crtc,
  9082. sizeof(bool), GFP_KERNEL);
  9083. if (!config->save_crtc_enabled)
  9084. return -ENOMEM;
  9085. config->save_encoder_crtcs =
  9086. kcalloc(dev->mode_config.num_encoder,
  9087. sizeof(struct drm_crtc *), GFP_KERNEL);
  9088. if (!config->save_encoder_crtcs)
  9089. return -ENOMEM;
  9090. config->save_connector_encoders =
  9091. kcalloc(dev->mode_config.num_connector,
  9092. sizeof(struct drm_encoder *), GFP_KERNEL);
  9093. if (!config->save_connector_encoders)
  9094. return -ENOMEM;
  9095. /* Copy data. Note that driver private data is not affected.
  9096. * Should anything bad happen only the expected state is
  9097. * restored, not the drivers personal bookkeeping.
  9098. */
  9099. count = 0;
  9100. for_each_crtc(dev, crtc) {
  9101. config->save_crtc_enabled[count++] = crtc->enabled;
  9102. }
  9103. count = 0;
  9104. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9105. config->save_encoder_crtcs[count++] = encoder->crtc;
  9106. }
  9107. count = 0;
  9108. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9109. config->save_connector_encoders[count++] = connector->encoder;
  9110. }
  9111. return 0;
  9112. }
  9113. static void intel_set_config_restore_state(struct drm_device *dev,
  9114. struct intel_set_config *config)
  9115. {
  9116. struct intel_crtc *crtc;
  9117. struct intel_encoder *encoder;
  9118. struct intel_connector *connector;
  9119. int count;
  9120. count = 0;
  9121. for_each_intel_crtc(dev, crtc) {
  9122. crtc->new_enabled = config->save_crtc_enabled[count++];
  9123. if (crtc->new_enabled)
  9124. crtc->new_config = &crtc->config;
  9125. else
  9126. crtc->new_config = NULL;
  9127. }
  9128. count = 0;
  9129. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9130. encoder->new_crtc =
  9131. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9132. }
  9133. count = 0;
  9134. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9135. connector->new_encoder =
  9136. to_intel_encoder(config->save_connector_encoders[count++]);
  9137. }
  9138. }
  9139. static bool
  9140. is_crtc_connector_off(struct drm_mode_set *set)
  9141. {
  9142. int i;
  9143. if (set->num_connectors == 0)
  9144. return false;
  9145. if (WARN_ON(set->connectors == NULL))
  9146. return false;
  9147. for (i = 0; i < set->num_connectors; i++)
  9148. if (set->connectors[i]->encoder &&
  9149. set->connectors[i]->encoder->crtc == set->crtc &&
  9150. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9151. return true;
  9152. return false;
  9153. }
  9154. static void
  9155. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9156. struct intel_set_config *config)
  9157. {
  9158. /* We should be able to check here if the fb has the same properties
  9159. * and then just flip_or_move it */
  9160. if (is_crtc_connector_off(set)) {
  9161. config->mode_changed = true;
  9162. } else if (set->crtc->primary->fb != set->fb) {
  9163. /*
  9164. * If we have no fb, we can only flip as long as the crtc is
  9165. * active, otherwise we need a full mode set. The crtc may
  9166. * be active if we've only disabled the primary plane, or
  9167. * in fastboot situations.
  9168. */
  9169. if (set->crtc->primary->fb == NULL) {
  9170. struct intel_crtc *intel_crtc =
  9171. to_intel_crtc(set->crtc);
  9172. if (intel_crtc->active) {
  9173. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9174. config->fb_changed = true;
  9175. } else {
  9176. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9177. config->mode_changed = true;
  9178. }
  9179. } else if (set->fb == NULL) {
  9180. config->mode_changed = true;
  9181. } else if (set->fb->pixel_format !=
  9182. set->crtc->primary->fb->pixel_format) {
  9183. config->mode_changed = true;
  9184. } else {
  9185. config->fb_changed = true;
  9186. }
  9187. }
  9188. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9189. config->fb_changed = true;
  9190. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9191. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9192. drm_mode_debug_printmodeline(&set->crtc->mode);
  9193. drm_mode_debug_printmodeline(set->mode);
  9194. config->mode_changed = true;
  9195. }
  9196. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9197. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9198. }
  9199. static int
  9200. intel_modeset_stage_output_state(struct drm_device *dev,
  9201. struct drm_mode_set *set,
  9202. struct intel_set_config *config)
  9203. {
  9204. struct intel_connector *connector;
  9205. struct intel_encoder *encoder;
  9206. struct intel_crtc *crtc;
  9207. int ro;
  9208. /* The upper layers ensure that we either disable a crtc or have a list
  9209. * of connectors. For paranoia, double-check this. */
  9210. WARN_ON(!set->fb && (set->num_connectors != 0));
  9211. WARN_ON(set->fb && (set->num_connectors == 0));
  9212. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9213. base.head) {
  9214. /* Otherwise traverse passed in connector list and get encoders
  9215. * for them. */
  9216. for (ro = 0; ro < set->num_connectors; ro++) {
  9217. if (set->connectors[ro] == &connector->base) {
  9218. connector->new_encoder = connector->encoder;
  9219. break;
  9220. }
  9221. }
  9222. /* If we disable the crtc, disable all its connectors. Also, if
  9223. * the connector is on the changing crtc but not on the new
  9224. * connector list, disable it. */
  9225. if ((!set->fb || ro == set->num_connectors) &&
  9226. connector->base.encoder &&
  9227. connector->base.encoder->crtc == set->crtc) {
  9228. connector->new_encoder = NULL;
  9229. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9230. connector->base.base.id,
  9231. connector->base.name);
  9232. }
  9233. if (&connector->new_encoder->base != connector->base.encoder) {
  9234. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9235. config->mode_changed = true;
  9236. }
  9237. }
  9238. /* connector->new_encoder is now updated for all connectors. */
  9239. /* Update crtc of enabled connectors. */
  9240. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9241. base.head) {
  9242. struct drm_crtc *new_crtc;
  9243. if (!connector->new_encoder)
  9244. continue;
  9245. new_crtc = connector->new_encoder->base.crtc;
  9246. for (ro = 0; ro < set->num_connectors; ro++) {
  9247. if (set->connectors[ro] == &connector->base)
  9248. new_crtc = set->crtc;
  9249. }
  9250. /* Make sure the new CRTC will work with the encoder */
  9251. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9252. new_crtc)) {
  9253. return -EINVAL;
  9254. }
  9255. connector->encoder->new_crtc = to_intel_crtc(new_crtc);
  9256. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9257. connector->base.base.id,
  9258. connector->base.name,
  9259. new_crtc->base.id);
  9260. }
  9261. /* Check for any encoders that needs to be disabled. */
  9262. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  9263. base.head) {
  9264. int num_connectors = 0;
  9265. list_for_each_entry(connector,
  9266. &dev->mode_config.connector_list,
  9267. base.head) {
  9268. if (connector->new_encoder == encoder) {
  9269. WARN_ON(!connector->new_encoder->new_crtc);
  9270. num_connectors++;
  9271. }
  9272. }
  9273. if (num_connectors == 0)
  9274. encoder->new_crtc = NULL;
  9275. else if (num_connectors > 1)
  9276. return -EINVAL;
  9277. /* Only now check for crtc changes so we don't miss encoders
  9278. * that will be disabled. */
  9279. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9280. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9281. config->mode_changed = true;
  9282. }
  9283. }
  9284. /* Now we've also updated encoder->new_crtc for all encoders. */
  9285. for_each_intel_crtc(dev, crtc) {
  9286. crtc->new_enabled = false;
  9287. list_for_each_entry(encoder,
  9288. &dev->mode_config.encoder_list,
  9289. base.head) {
  9290. if (encoder->new_crtc == crtc) {
  9291. crtc->new_enabled = true;
  9292. break;
  9293. }
  9294. }
  9295. if (crtc->new_enabled != crtc->base.enabled) {
  9296. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9297. crtc->new_enabled ? "en" : "dis");
  9298. config->mode_changed = true;
  9299. }
  9300. if (crtc->new_enabled)
  9301. crtc->new_config = &crtc->config;
  9302. else
  9303. crtc->new_config = NULL;
  9304. }
  9305. return 0;
  9306. }
  9307. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9308. {
  9309. struct drm_device *dev = crtc->base.dev;
  9310. struct intel_encoder *encoder;
  9311. struct intel_connector *connector;
  9312. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9313. pipe_name(crtc->pipe));
  9314. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9315. if (connector->new_encoder &&
  9316. connector->new_encoder->new_crtc == crtc)
  9317. connector->new_encoder = NULL;
  9318. }
  9319. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9320. if (encoder->new_crtc == crtc)
  9321. encoder->new_crtc = NULL;
  9322. }
  9323. crtc->new_enabled = false;
  9324. crtc->new_config = NULL;
  9325. }
  9326. static int intel_crtc_set_config(struct drm_mode_set *set)
  9327. {
  9328. struct drm_device *dev;
  9329. struct drm_mode_set save_set;
  9330. struct intel_set_config *config;
  9331. int ret;
  9332. BUG_ON(!set);
  9333. BUG_ON(!set->crtc);
  9334. BUG_ON(!set->crtc->helper_private);
  9335. /* Enforce sane interface api - has been abused by the fb helper. */
  9336. BUG_ON(!set->mode && set->fb);
  9337. BUG_ON(set->fb && set->num_connectors == 0);
  9338. if (set->fb) {
  9339. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9340. set->crtc->base.id, set->fb->base.id,
  9341. (int)set->num_connectors, set->x, set->y);
  9342. } else {
  9343. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9344. }
  9345. dev = set->crtc->dev;
  9346. ret = -ENOMEM;
  9347. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9348. if (!config)
  9349. goto out_config;
  9350. ret = intel_set_config_save_state(dev, config);
  9351. if (ret)
  9352. goto out_config;
  9353. save_set.crtc = set->crtc;
  9354. save_set.mode = &set->crtc->mode;
  9355. save_set.x = set->crtc->x;
  9356. save_set.y = set->crtc->y;
  9357. save_set.fb = set->crtc->primary->fb;
  9358. /* Compute whether we need a full modeset, only an fb base update or no
  9359. * change at all. In the future we might also check whether only the
  9360. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9361. * such cases. */
  9362. intel_set_config_compute_mode_changes(set, config);
  9363. ret = intel_modeset_stage_output_state(dev, set, config);
  9364. if (ret)
  9365. goto fail;
  9366. if (config->mode_changed) {
  9367. ret = intel_set_mode(set->crtc, set->mode,
  9368. set->x, set->y, set->fb);
  9369. } else if (config->fb_changed) {
  9370. struct drm_i915_private *dev_priv = dev->dev_private;
  9371. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9372. intel_crtc_wait_for_pending_flips(set->crtc);
  9373. ret = intel_pipe_set_base(set->crtc,
  9374. set->x, set->y, set->fb);
  9375. /*
  9376. * We need to make sure the primary plane is re-enabled if it
  9377. * has previously been turned off.
  9378. */
  9379. if (!intel_crtc->primary_enabled && ret == 0) {
  9380. WARN_ON(!intel_crtc->active);
  9381. intel_enable_primary_hw_plane(dev_priv, intel_crtc->plane,
  9382. intel_crtc->pipe);
  9383. }
  9384. /*
  9385. * In the fastboot case this may be our only check of the
  9386. * state after boot. It would be better to only do it on
  9387. * the first update, but we don't have a nice way of doing that
  9388. * (and really, set_config isn't used much for high freq page
  9389. * flipping, so increasing its cost here shouldn't be a big
  9390. * deal).
  9391. */
  9392. if (i915.fastboot && ret == 0)
  9393. intel_modeset_check_state(set->crtc->dev);
  9394. }
  9395. if (ret) {
  9396. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9397. set->crtc->base.id, ret);
  9398. fail:
  9399. intel_set_config_restore_state(dev, config);
  9400. /*
  9401. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9402. * force the pipe off to avoid oopsing in the modeset code
  9403. * due to fb==NULL. This should only happen during boot since
  9404. * we don't yet reconstruct the FB from the hardware state.
  9405. */
  9406. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9407. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9408. /* Try to restore the config */
  9409. if (config->mode_changed &&
  9410. intel_set_mode(save_set.crtc, save_set.mode,
  9411. save_set.x, save_set.y, save_set.fb))
  9412. DRM_ERROR("failed to restore config after modeset failure\n");
  9413. }
  9414. out_config:
  9415. intel_set_config_free(config);
  9416. return ret;
  9417. }
  9418. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9419. .gamma_set = intel_crtc_gamma_set,
  9420. .set_config = intel_crtc_set_config,
  9421. .destroy = intel_crtc_destroy,
  9422. .page_flip = intel_crtc_page_flip,
  9423. };
  9424. static void intel_cpu_pll_init(struct drm_device *dev)
  9425. {
  9426. if (HAS_DDI(dev))
  9427. intel_ddi_pll_init(dev);
  9428. }
  9429. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9430. struct intel_shared_dpll *pll,
  9431. struct intel_dpll_hw_state *hw_state)
  9432. {
  9433. uint32_t val;
  9434. val = I915_READ(PCH_DPLL(pll->id));
  9435. hw_state->dpll = val;
  9436. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9437. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9438. return val & DPLL_VCO_ENABLE;
  9439. }
  9440. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9441. struct intel_shared_dpll *pll)
  9442. {
  9443. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9444. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9445. }
  9446. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9447. struct intel_shared_dpll *pll)
  9448. {
  9449. /* PCH refclock must be enabled first */
  9450. ibx_assert_pch_refclk_enabled(dev_priv);
  9451. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9452. /* Wait for the clocks to stabilize. */
  9453. POSTING_READ(PCH_DPLL(pll->id));
  9454. udelay(150);
  9455. /* The pixel multiplier can only be updated once the
  9456. * DPLL is enabled and the clocks are stable.
  9457. *
  9458. * So write it again.
  9459. */
  9460. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9461. POSTING_READ(PCH_DPLL(pll->id));
  9462. udelay(200);
  9463. }
  9464. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9465. struct intel_shared_dpll *pll)
  9466. {
  9467. struct drm_device *dev = dev_priv->dev;
  9468. struct intel_crtc *crtc;
  9469. /* Make sure no transcoder isn't still depending on us. */
  9470. for_each_intel_crtc(dev, crtc) {
  9471. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9472. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9473. }
  9474. I915_WRITE(PCH_DPLL(pll->id), 0);
  9475. POSTING_READ(PCH_DPLL(pll->id));
  9476. udelay(200);
  9477. }
  9478. static char *ibx_pch_dpll_names[] = {
  9479. "PCH DPLL A",
  9480. "PCH DPLL B",
  9481. };
  9482. static void ibx_pch_dpll_init(struct drm_device *dev)
  9483. {
  9484. struct drm_i915_private *dev_priv = dev->dev_private;
  9485. int i;
  9486. dev_priv->num_shared_dpll = 2;
  9487. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9488. dev_priv->shared_dplls[i].id = i;
  9489. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9490. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9491. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9492. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9493. dev_priv->shared_dplls[i].get_hw_state =
  9494. ibx_pch_dpll_get_hw_state;
  9495. }
  9496. }
  9497. static void intel_shared_dpll_init(struct drm_device *dev)
  9498. {
  9499. struct drm_i915_private *dev_priv = dev->dev_private;
  9500. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9501. ibx_pch_dpll_init(dev);
  9502. else
  9503. dev_priv->num_shared_dpll = 0;
  9504. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9505. }
  9506. static int
  9507. intel_primary_plane_disable(struct drm_plane *plane)
  9508. {
  9509. struct drm_device *dev = plane->dev;
  9510. struct drm_i915_private *dev_priv = dev->dev_private;
  9511. struct intel_plane *intel_plane = to_intel_plane(plane);
  9512. struct intel_crtc *intel_crtc;
  9513. if (!plane->fb)
  9514. return 0;
  9515. BUG_ON(!plane->crtc);
  9516. intel_crtc = to_intel_crtc(plane->crtc);
  9517. /*
  9518. * Even though we checked plane->fb above, it's still possible that
  9519. * the primary plane has been implicitly disabled because the crtc
  9520. * coordinates given weren't visible, or because we detected
  9521. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9522. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9523. * In either case, we need to unpin the FB and let the fb pointer get
  9524. * updated, but otherwise we don't need to touch the hardware.
  9525. */
  9526. if (!intel_crtc->primary_enabled)
  9527. goto disable_unpin;
  9528. intel_crtc_wait_for_pending_flips(plane->crtc);
  9529. intel_disable_primary_hw_plane(dev_priv, intel_plane->plane,
  9530. intel_plane->pipe);
  9531. disable_unpin:
  9532. i915_gem_track_fb(to_intel_framebuffer(plane->fb)->obj, NULL,
  9533. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9534. intel_unpin_fb_obj(to_intel_framebuffer(plane->fb)->obj);
  9535. plane->fb = NULL;
  9536. return 0;
  9537. }
  9538. static int
  9539. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9540. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9541. unsigned int crtc_w, unsigned int crtc_h,
  9542. uint32_t src_x, uint32_t src_y,
  9543. uint32_t src_w, uint32_t src_h)
  9544. {
  9545. struct drm_device *dev = crtc->dev;
  9546. struct drm_i915_private *dev_priv = dev->dev_private;
  9547. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9548. struct intel_plane *intel_plane = to_intel_plane(plane);
  9549. struct drm_i915_gem_object *obj, *old_obj = NULL;
  9550. struct drm_rect dest = {
  9551. /* integer pixels */
  9552. .x1 = crtc_x,
  9553. .y1 = crtc_y,
  9554. .x2 = crtc_x + crtc_w,
  9555. .y2 = crtc_y + crtc_h,
  9556. };
  9557. struct drm_rect src = {
  9558. /* 16.16 fixed point */
  9559. .x1 = src_x,
  9560. .y1 = src_y,
  9561. .x2 = src_x + src_w,
  9562. .y2 = src_y + src_h,
  9563. };
  9564. const struct drm_rect clip = {
  9565. /* integer pixels */
  9566. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  9567. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  9568. };
  9569. bool visible;
  9570. int ret;
  9571. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9572. &src, &dest, &clip,
  9573. DRM_PLANE_HELPER_NO_SCALING,
  9574. DRM_PLANE_HELPER_NO_SCALING,
  9575. false, true, &visible);
  9576. if (ret)
  9577. return ret;
  9578. if (plane->fb)
  9579. old_obj = to_intel_framebuffer(plane->fb)->obj;
  9580. obj = to_intel_framebuffer(fb)->obj;
  9581. /*
  9582. * If the CRTC isn't enabled, we're just pinning the framebuffer,
  9583. * updating the fb pointer, and returning without touching the
  9584. * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
  9585. * turn on the display with all planes setup as desired.
  9586. */
  9587. if (!crtc->enabled) {
  9588. /*
  9589. * If we already called setplane while the crtc was disabled,
  9590. * we may have an fb pinned; unpin it.
  9591. */
  9592. if (plane->fb)
  9593. intel_unpin_fb_obj(old_obj);
  9594. i915_gem_track_fb(old_obj, obj,
  9595. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9596. /* Pin and return without programming hardware */
  9597. return intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9598. }
  9599. intel_crtc_wait_for_pending_flips(crtc);
  9600. /*
  9601. * If clipping results in a non-visible primary plane, we'll disable
  9602. * the primary plane. Note that this is a bit different than what
  9603. * happens if userspace explicitly disables the plane by passing fb=0
  9604. * because plane->fb still gets set and pinned.
  9605. */
  9606. if (!visible) {
  9607. /*
  9608. * Try to pin the new fb first so that we can bail out if we
  9609. * fail.
  9610. */
  9611. if (plane->fb != fb) {
  9612. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9613. if (ret)
  9614. return ret;
  9615. }
  9616. i915_gem_track_fb(old_obj, obj,
  9617. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9618. if (intel_crtc->primary_enabled)
  9619. intel_disable_primary_hw_plane(dev_priv,
  9620. intel_plane->plane,
  9621. intel_plane->pipe);
  9622. if (plane->fb != fb)
  9623. if (plane->fb)
  9624. intel_unpin_fb_obj(old_obj);
  9625. return 0;
  9626. }
  9627. ret = intel_pipe_set_base(crtc, src.x1, src.y1, fb);
  9628. if (ret)
  9629. return ret;
  9630. if (!intel_crtc->primary_enabled)
  9631. intel_enable_primary_hw_plane(dev_priv, intel_crtc->plane,
  9632. intel_crtc->pipe);
  9633. return 0;
  9634. }
  9635. /* Common destruction function for both primary and cursor planes */
  9636. static void intel_plane_destroy(struct drm_plane *plane)
  9637. {
  9638. struct intel_plane *intel_plane = to_intel_plane(plane);
  9639. drm_plane_cleanup(plane);
  9640. kfree(intel_plane);
  9641. }
  9642. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  9643. .update_plane = intel_primary_plane_setplane,
  9644. .disable_plane = intel_primary_plane_disable,
  9645. .destroy = intel_plane_destroy,
  9646. };
  9647. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  9648. int pipe)
  9649. {
  9650. struct intel_plane *primary;
  9651. const uint32_t *intel_primary_formats;
  9652. int num_formats;
  9653. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  9654. if (primary == NULL)
  9655. return NULL;
  9656. primary->can_scale = false;
  9657. primary->max_downscale = 1;
  9658. primary->pipe = pipe;
  9659. primary->plane = pipe;
  9660. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  9661. primary->plane = !pipe;
  9662. if (INTEL_INFO(dev)->gen <= 3) {
  9663. intel_primary_formats = intel_primary_formats_gen2;
  9664. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  9665. } else {
  9666. intel_primary_formats = intel_primary_formats_gen4;
  9667. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  9668. }
  9669. drm_universal_plane_init(dev, &primary->base, 0,
  9670. &intel_primary_plane_funcs,
  9671. intel_primary_formats, num_formats,
  9672. DRM_PLANE_TYPE_PRIMARY);
  9673. return &primary->base;
  9674. }
  9675. static int
  9676. intel_cursor_plane_disable(struct drm_plane *plane)
  9677. {
  9678. if (!plane->fb)
  9679. return 0;
  9680. BUG_ON(!plane->crtc);
  9681. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  9682. }
  9683. static int
  9684. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  9685. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9686. unsigned int crtc_w, unsigned int crtc_h,
  9687. uint32_t src_x, uint32_t src_y,
  9688. uint32_t src_w, uint32_t src_h)
  9689. {
  9690. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9691. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  9692. struct drm_i915_gem_object *obj = intel_fb->obj;
  9693. struct drm_rect dest = {
  9694. /* integer pixels */
  9695. .x1 = crtc_x,
  9696. .y1 = crtc_y,
  9697. .x2 = crtc_x + crtc_w,
  9698. .y2 = crtc_y + crtc_h,
  9699. };
  9700. struct drm_rect src = {
  9701. /* 16.16 fixed point */
  9702. .x1 = src_x,
  9703. .y1 = src_y,
  9704. .x2 = src_x + src_w,
  9705. .y2 = src_y + src_h,
  9706. };
  9707. const struct drm_rect clip = {
  9708. /* integer pixels */
  9709. .x2 = intel_crtc->config.pipe_src_w,
  9710. .y2 = intel_crtc->config.pipe_src_h,
  9711. };
  9712. bool visible;
  9713. int ret;
  9714. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9715. &src, &dest, &clip,
  9716. DRM_PLANE_HELPER_NO_SCALING,
  9717. DRM_PLANE_HELPER_NO_SCALING,
  9718. true, true, &visible);
  9719. if (ret)
  9720. return ret;
  9721. crtc->cursor_x = crtc_x;
  9722. crtc->cursor_y = crtc_y;
  9723. if (fb != crtc->cursor->fb) {
  9724. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  9725. } else {
  9726. intel_crtc_update_cursor(crtc, visible);
  9727. return 0;
  9728. }
  9729. }
  9730. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  9731. .update_plane = intel_cursor_plane_update,
  9732. .disable_plane = intel_cursor_plane_disable,
  9733. .destroy = intel_plane_destroy,
  9734. };
  9735. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  9736. int pipe)
  9737. {
  9738. struct intel_plane *cursor;
  9739. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  9740. if (cursor == NULL)
  9741. return NULL;
  9742. cursor->can_scale = false;
  9743. cursor->max_downscale = 1;
  9744. cursor->pipe = pipe;
  9745. cursor->plane = pipe;
  9746. drm_universal_plane_init(dev, &cursor->base, 0,
  9747. &intel_cursor_plane_funcs,
  9748. intel_cursor_formats,
  9749. ARRAY_SIZE(intel_cursor_formats),
  9750. DRM_PLANE_TYPE_CURSOR);
  9751. return &cursor->base;
  9752. }
  9753. static void intel_crtc_init(struct drm_device *dev, int pipe)
  9754. {
  9755. struct drm_i915_private *dev_priv = dev->dev_private;
  9756. struct intel_crtc *intel_crtc;
  9757. struct drm_plane *primary = NULL;
  9758. struct drm_plane *cursor = NULL;
  9759. int i, ret;
  9760. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  9761. if (intel_crtc == NULL)
  9762. return;
  9763. primary = intel_primary_plane_create(dev, pipe);
  9764. if (!primary)
  9765. goto fail;
  9766. cursor = intel_cursor_plane_create(dev, pipe);
  9767. if (!cursor)
  9768. goto fail;
  9769. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  9770. cursor, &intel_crtc_funcs);
  9771. if (ret)
  9772. goto fail;
  9773. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  9774. for (i = 0; i < 256; i++) {
  9775. intel_crtc->lut_r[i] = i;
  9776. intel_crtc->lut_g[i] = i;
  9777. intel_crtc->lut_b[i] = i;
  9778. }
  9779. /*
  9780. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  9781. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  9782. */
  9783. intel_crtc->pipe = pipe;
  9784. intel_crtc->plane = pipe;
  9785. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  9786. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  9787. intel_crtc->plane = !pipe;
  9788. }
  9789. intel_crtc->cursor_base = ~0;
  9790. intel_crtc->cursor_cntl = ~0;
  9791. init_waitqueue_head(&intel_crtc->vbl_wait);
  9792. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  9793. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  9794. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  9795. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  9796. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  9797. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  9798. return;
  9799. fail:
  9800. if (primary)
  9801. drm_plane_cleanup(primary);
  9802. if (cursor)
  9803. drm_plane_cleanup(cursor);
  9804. kfree(intel_crtc);
  9805. }
  9806. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  9807. {
  9808. struct drm_encoder *encoder = connector->base.encoder;
  9809. struct drm_device *dev = connector->base.dev;
  9810. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  9811. if (!encoder)
  9812. return INVALID_PIPE;
  9813. return to_intel_crtc(encoder->crtc)->pipe;
  9814. }
  9815. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  9816. struct drm_file *file)
  9817. {
  9818. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  9819. struct drm_mode_object *drmmode_obj;
  9820. struct intel_crtc *crtc;
  9821. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  9822. return -ENODEV;
  9823. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  9824. DRM_MODE_OBJECT_CRTC);
  9825. if (!drmmode_obj) {
  9826. DRM_ERROR("no such CRTC id\n");
  9827. return -ENOENT;
  9828. }
  9829. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  9830. pipe_from_crtc_id->pipe = crtc->pipe;
  9831. return 0;
  9832. }
  9833. static int intel_encoder_clones(struct intel_encoder *encoder)
  9834. {
  9835. struct drm_device *dev = encoder->base.dev;
  9836. struct intel_encoder *source_encoder;
  9837. int index_mask = 0;
  9838. int entry = 0;
  9839. list_for_each_entry(source_encoder,
  9840. &dev->mode_config.encoder_list, base.head) {
  9841. if (encoders_cloneable(encoder, source_encoder))
  9842. index_mask |= (1 << entry);
  9843. entry++;
  9844. }
  9845. return index_mask;
  9846. }
  9847. static bool has_edp_a(struct drm_device *dev)
  9848. {
  9849. struct drm_i915_private *dev_priv = dev->dev_private;
  9850. if (!IS_MOBILE(dev))
  9851. return false;
  9852. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  9853. return false;
  9854. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  9855. return false;
  9856. return true;
  9857. }
  9858. const char *intel_output_name(int output)
  9859. {
  9860. static const char *names[] = {
  9861. [INTEL_OUTPUT_UNUSED] = "Unused",
  9862. [INTEL_OUTPUT_ANALOG] = "Analog",
  9863. [INTEL_OUTPUT_DVO] = "DVO",
  9864. [INTEL_OUTPUT_SDVO] = "SDVO",
  9865. [INTEL_OUTPUT_LVDS] = "LVDS",
  9866. [INTEL_OUTPUT_TVOUT] = "TV",
  9867. [INTEL_OUTPUT_HDMI] = "HDMI",
  9868. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  9869. [INTEL_OUTPUT_EDP] = "eDP",
  9870. [INTEL_OUTPUT_DSI] = "DSI",
  9871. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  9872. };
  9873. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  9874. return "Invalid";
  9875. return names[output];
  9876. }
  9877. static bool intel_crt_present(struct drm_device *dev)
  9878. {
  9879. struct drm_i915_private *dev_priv = dev->dev_private;
  9880. if (IS_ULT(dev))
  9881. return false;
  9882. if (IS_CHERRYVIEW(dev))
  9883. return false;
  9884. if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
  9885. return false;
  9886. return true;
  9887. }
  9888. static void intel_setup_outputs(struct drm_device *dev)
  9889. {
  9890. struct drm_i915_private *dev_priv = dev->dev_private;
  9891. struct intel_encoder *encoder;
  9892. bool dpd_is_edp = false;
  9893. intel_lvds_init(dev);
  9894. if (intel_crt_present(dev))
  9895. intel_crt_init(dev);
  9896. if (HAS_DDI(dev)) {
  9897. int found;
  9898. /* Haswell uses DDI functions to detect digital outputs */
  9899. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  9900. /* DDI A only supports eDP */
  9901. if (found)
  9902. intel_ddi_init(dev, PORT_A);
  9903. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  9904. * register */
  9905. found = I915_READ(SFUSE_STRAP);
  9906. if (found & SFUSE_STRAP_DDIB_DETECTED)
  9907. intel_ddi_init(dev, PORT_B);
  9908. if (found & SFUSE_STRAP_DDIC_DETECTED)
  9909. intel_ddi_init(dev, PORT_C);
  9910. if (found & SFUSE_STRAP_DDID_DETECTED)
  9911. intel_ddi_init(dev, PORT_D);
  9912. } else if (HAS_PCH_SPLIT(dev)) {
  9913. int found;
  9914. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  9915. if (has_edp_a(dev))
  9916. intel_dp_init(dev, DP_A, PORT_A);
  9917. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  9918. /* PCH SDVOB multiplex with HDMIB */
  9919. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  9920. if (!found)
  9921. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  9922. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  9923. intel_dp_init(dev, PCH_DP_B, PORT_B);
  9924. }
  9925. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  9926. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  9927. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  9928. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  9929. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  9930. intel_dp_init(dev, PCH_DP_C, PORT_C);
  9931. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  9932. intel_dp_init(dev, PCH_DP_D, PORT_D);
  9933. } else if (IS_VALLEYVIEW(dev)) {
  9934. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) {
  9935. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  9936. PORT_B);
  9937. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  9938. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  9939. }
  9940. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) {
  9941. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  9942. PORT_C);
  9943. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  9944. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  9945. }
  9946. if (IS_CHERRYVIEW(dev)) {
  9947. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) {
  9948. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  9949. PORT_D);
  9950. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  9951. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  9952. }
  9953. }
  9954. intel_dsi_init(dev);
  9955. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  9956. bool found = false;
  9957. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  9958. DRM_DEBUG_KMS("probing SDVOB\n");
  9959. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  9960. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  9961. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  9962. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  9963. }
  9964. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  9965. intel_dp_init(dev, DP_B, PORT_B);
  9966. }
  9967. /* Before G4X SDVOC doesn't have its own detect register */
  9968. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  9969. DRM_DEBUG_KMS("probing SDVOC\n");
  9970. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  9971. }
  9972. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  9973. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  9974. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  9975. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  9976. }
  9977. if (SUPPORTS_INTEGRATED_DP(dev))
  9978. intel_dp_init(dev, DP_C, PORT_C);
  9979. }
  9980. if (SUPPORTS_INTEGRATED_DP(dev) &&
  9981. (I915_READ(DP_D) & DP_DETECTED))
  9982. intel_dp_init(dev, DP_D, PORT_D);
  9983. } else if (IS_GEN2(dev))
  9984. intel_dvo_init(dev);
  9985. if (SUPPORTS_TV(dev))
  9986. intel_tv_init(dev);
  9987. intel_edp_psr_init(dev);
  9988. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  9989. encoder->base.possible_crtcs = encoder->crtc_mask;
  9990. encoder->base.possible_clones =
  9991. intel_encoder_clones(encoder);
  9992. }
  9993. intel_init_pch_refclk(dev);
  9994. drm_helper_move_panel_connectors_to_head(dev);
  9995. }
  9996. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  9997. {
  9998. struct drm_device *dev = fb->dev;
  9999. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10000. drm_framebuffer_cleanup(fb);
  10001. mutex_lock(&dev->struct_mutex);
  10002. WARN_ON(!intel_fb->obj->framebuffer_references--);
  10003. drm_gem_object_unreference(&intel_fb->obj->base);
  10004. mutex_unlock(&dev->struct_mutex);
  10005. kfree(intel_fb);
  10006. }
  10007. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  10008. struct drm_file *file,
  10009. unsigned int *handle)
  10010. {
  10011. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10012. struct drm_i915_gem_object *obj = intel_fb->obj;
  10013. return drm_gem_handle_create(file, &obj->base, handle);
  10014. }
  10015. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  10016. .destroy = intel_user_framebuffer_destroy,
  10017. .create_handle = intel_user_framebuffer_create_handle,
  10018. };
  10019. static int intel_framebuffer_init(struct drm_device *dev,
  10020. struct intel_framebuffer *intel_fb,
  10021. struct drm_mode_fb_cmd2 *mode_cmd,
  10022. struct drm_i915_gem_object *obj)
  10023. {
  10024. int aligned_height;
  10025. int pitch_limit;
  10026. int ret;
  10027. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10028. if (obj->tiling_mode == I915_TILING_Y) {
  10029. DRM_DEBUG("hardware does not support tiling Y\n");
  10030. return -EINVAL;
  10031. }
  10032. if (mode_cmd->pitches[0] & 63) {
  10033. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10034. mode_cmd->pitches[0]);
  10035. return -EINVAL;
  10036. }
  10037. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10038. pitch_limit = 32*1024;
  10039. } else if (INTEL_INFO(dev)->gen >= 4) {
  10040. if (obj->tiling_mode)
  10041. pitch_limit = 16*1024;
  10042. else
  10043. pitch_limit = 32*1024;
  10044. } else if (INTEL_INFO(dev)->gen >= 3) {
  10045. if (obj->tiling_mode)
  10046. pitch_limit = 8*1024;
  10047. else
  10048. pitch_limit = 16*1024;
  10049. } else
  10050. /* XXX DSPC is limited to 4k tiled */
  10051. pitch_limit = 8*1024;
  10052. if (mode_cmd->pitches[0] > pitch_limit) {
  10053. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10054. obj->tiling_mode ? "tiled" : "linear",
  10055. mode_cmd->pitches[0], pitch_limit);
  10056. return -EINVAL;
  10057. }
  10058. if (obj->tiling_mode != I915_TILING_NONE &&
  10059. mode_cmd->pitches[0] != obj->stride) {
  10060. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10061. mode_cmd->pitches[0], obj->stride);
  10062. return -EINVAL;
  10063. }
  10064. /* Reject formats not supported by any plane early. */
  10065. switch (mode_cmd->pixel_format) {
  10066. case DRM_FORMAT_C8:
  10067. case DRM_FORMAT_RGB565:
  10068. case DRM_FORMAT_XRGB8888:
  10069. case DRM_FORMAT_ARGB8888:
  10070. break;
  10071. case DRM_FORMAT_XRGB1555:
  10072. case DRM_FORMAT_ARGB1555:
  10073. if (INTEL_INFO(dev)->gen > 3) {
  10074. DRM_DEBUG("unsupported pixel format: %s\n",
  10075. drm_get_format_name(mode_cmd->pixel_format));
  10076. return -EINVAL;
  10077. }
  10078. break;
  10079. case DRM_FORMAT_XBGR8888:
  10080. case DRM_FORMAT_ABGR8888:
  10081. case DRM_FORMAT_XRGB2101010:
  10082. case DRM_FORMAT_ARGB2101010:
  10083. case DRM_FORMAT_XBGR2101010:
  10084. case DRM_FORMAT_ABGR2101010:
  10085. if (INTEL_INFO(dev)->gen < 4) {
  10086. DRM_DEBUG("unsupported pixel format: %s\n",
  10087. drm_get_format_name(mode_cmd->pixel_format));
  10088. return -EINVAL;
  10089. }
  10090. break;
  10091. case DRM_FORMAT_YUYV:
  10092. case DRM_FORMAT_UYVY:
  10093. case DRM_FORMAT_YVYU:
  10094. case DRM_FORMAT_VYUY:
  10095. if (INTEL_INFO(dev)->gen < 5) {
  10096. DRM_DEBUG("unsupported pixel format: %s\n",
  10097. drm_get_format_name(mode_cmd->pixel_format));
  10098. return -EINVAL;
  10099. }
  10100. break;
  10101. default:
  10102. DRM_DEBUG("unsupported pixel format: %s\n",
  10103. drm_get_format_name(mode_cmd->pixel_format));
  10104. return -EINVAL;
  10105. }
  10106. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10107. if (mode_cmd->offsets[0] != 0)
  10108. return -EINVAL;
  10109. aligned_height = intel_align_height(dev, mode_cmd->height,
  10110. obj->tiling_mode);
  10111. /* FIXME drm helper for size checks (especially planar formats)? */
  10112. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10113. return -EINVAL;
  10114. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10115. intel_fb->obj = obj;
  10116. intel_fb->obj->framebuffer_references++;
  10117. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10118. if (ret) {
  10119. DRM_ERROR("framebuffer init failed %d\n", ret);
  10120. return ret;
  10121. }
  10122. return 0;
  10123. }
  10124. static struct drm_framebuffer *
  10125. intel_user_framebuffer_create(struct drm_device *dev,
  10126. struct drm_file *filp,
  10127. struct drm_mode_fb_cmd2 *mode_cmd)
  10128. {
  10129. struct drm_i915_gem_object *obj;
  10130. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10131. mode_cmd->handles[0]));
  10132. if (&obj->base == NULL)
  10133. return ERR_PTR(-ENOENT);
  10134. return intel_framebuffer_create(dev, mode_cmd, obj);
  10135. }
  10136. #ifndef CONFIG_DRM_I915_FBDEV
  10137. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10138. {
  10139. }
  10140. #endif
  10141. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10142. .fb_create = intel_user_framebuffer_create,
  10143. .output_poll_changed = intel_fbdev_output_poll_changed,
  10144. };
  10145. /* Set up chip specific display functions */
  10146. static void intel_init_display(struct drm_device *dev)
  10147. {
  10148. struct drm_i915_private *dev_priv = dev->dev_private;
  10149. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10150. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10151. else if (IS_CHERRYVIEW(dev))
  10152. dev_priv->display.find_dpll = chv_find_best_dpll;
  10153. else if (IS_VALLEYVIEW(dev))
  10154. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10155. else if (IS_PINEVIEW(dev))
  10156. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10157. else
  10158. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10159. if (HAS_DDI(dev)) {
  10160. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10161. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10162. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10163. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10164. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10165. dev_priv->display.off = haswell_crtc_off;
  10166. dev_priv->display.update_primary_plane =
  10167. ironlake_update_primary_plane;
  10168. } else if (HAS_PCH_SPLIT(dev)) {
  10169. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10170. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10171. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10172. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10173. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10174. dev_priv->display.off = ironlake_crtc_off;
  10175. dev_priv->display.update_primary_plane =
  10176. ironlake_update_primary_plane;
  10177. } else if (IS_VALLEYVIEW(dev)) {
  10178. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10179. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10180. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10181. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10182. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10183. dev_priv->display.off = i9xx_crtc_off;
  10184. dev_priv->display.update_primary_plane =
  10185. i9xx_update_primary_plane;
  10186. } else {
  10187. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10188. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10189. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10190. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10191. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10192. dev_priv->display.off = i9xx_crtc_off;
  10193. dev_priv->display.update_primary_plane =
  10194. i9xx_update_primary_plane;
  10195. }
  10196. /* Returns the core display clock speed */
  10197. if (IS_VALLEYVIEW(dev))
  10198. dev_priv->display.get_display_clock_speed =
  10199. valleyview_get_display_clock_speed;
  10200. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10201. dev_priv->display.get_display_clock_speed =
  10202. i945_get_display_clock_speed;
  10203. else if (IS_I915G(dev))
  10204. dev_priv->display.get_display_clock_speed =
  10205. i915_get_display_clock_speed;
  10206. else if (IS_I945GM(dev) || IS_845G(dev))
  10207. dev_priv->display.get_display_clock_speed =
  10208. i9xx_misc_get_display_clock_speed;
  10209. else if (IS_PINEVIEW(dev))
  10210. dev_priv->display.get_display_clock_speed =
  10211. pnv_get_display_clock_speed;
  10212. else if (IS_I915GM(dev))
  10213. dev_priv->display.get_display_clock_speed =
  10214. i915gm_get_display_clock_speed;
  10215. else if (IS_I865G(dev))
  10216. dev_priv->display.get_display_clock_speed =
  10217. i865_get_display_clock_speed;
  10218. else if (IS_I85X(dev))
  10219. dev_priv->display.get_display_clock_speed =
  10220. i855_get_display_clock_speed;
  10221. else /* 852, 830 */
  10222. dev_priv->display.get_display_clock_speed =
  10223. i830_get_display_clock_speed;
  10224. if (HAS_PCH_SPLIT(dev)) {
  10225. if (IS_GEN5(dev)) {
  10226. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10227. dev_priv->display.write_eld = ironlake_write_eld;
  10228. } else if (IS_GEN6(dev)) {
  10229. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10230. dev_priv->display.write_eld = ironlake_write_eld;
  10231. dev_priv->display.modeset_global_resources =
  10232. snb_modeset_global_resources;
  10233. } else if (IS_IVYBRIDGE(dev)) {
  10234. /* FIXME: detect B0+ stepping and use auto training */
  10235. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10236. dev_priv->display.write_eld = ironlake_write_eld;
  10237. dev_priv->display.modeset_global_resources =
  10238. ivb_modeset_global_resources;
  10239. } else if (IS_HASWELL(dev) || IS_GEN8(dev)) {
  10240. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10241. dev_priv->display.write_eld = haswell_write_eld;
  10242. dev_priv->display.modeset_global_resources =
  10243. haswell_modeset_global_resources;
  10244. }
  10245. } else if (IS_G4X(dev)) {
  10246. dev_priv->display.write_eld = g4x_write_eld;
  10247. } else if (IS_VALLEYVIEW(dev)) {
  10248. dev_priv->display.modeset_global_resources =
  10249. valleyview_modeset_global_resources;
  10250. dev_priv->display.write_eld = ironlake_write_eld;
  10251. }
  10252. /* Default just returns -ENODEV to indicate unsupported */
  10253. dev_priv->display.queue_flip = intel_default_queue_flip;
  10254. switch (INTEL_INFO(dev)->gen) {
  10255. case 2:
  10256. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10257. break;
  10258. case 3:
  10259. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10260. break;
  10261. case 4:
  10262. case 5:
  10263. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10264. break;
  10265. case 6:
  10266. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10267. break;
  10268. case 7:
  10269. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10270. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10271. break;
  10272. }
  10273. intel_panel_init_backlight_funcs(dev);
  10274. }
  10275. /*
  10276. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10277. * resume, or other times. This quirk makes sure that's the case for
  10278. * affected systems.
  10279. */
  10280. static void quirk_pipea_force(struct drm_device *dev)
  10281. {
  10282. struct drm_i915_private *dev_priv = dev->dev_private;
  10283. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10284. DRM_INFO("applying pipe a force quirk\n");
  10285. }
  10286. /*
  10287. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10288. */
  10289. static void quirk_ssc_force_disable(struct drm_device *dev)
  10290. {
  10291. struct drm_i915_private *dev_priv = dev->dev_private;
  10292. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10293. DRM_INFO("applying lvds SSC disable quirk\n");
  10294. }
  10295. /*
  10296. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10297. * brightness value
  10298. */
  10299. static void quirk_invert_brightness(struct drm_device *dev)
  10300. {
  10301. struct drm_i915_private *dev_priv = dev->dev_private;
  10302. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10303. DRM_INFO("applying inverted panel brightness quirk\n");
  10304. }
  10305. struct intel_quirk {
  10306. int device;
  10307. int subsystem_vendor;
  10308. int subsystem_device;
  10309. void (*hook)(struct drm_device *dev);
  10310. };
  10311. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10312. struct intel_dmi_quirk {
  10313. void (*hook)(struct drm_device *dev);
  10314. const struct dmi_system_id (*dmi_id_list)[];
  10315. };
  10316. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10317. {
  10318. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10319. return 1;
  10320. }
  10321. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10322. {
  10323. .dmi_id_list = &(const struct dmi_system_id[]) {
  10324. {
  10325. .callback = intel_dmi_reverse_brightness,
  10326. .ident = "NCR Corporation",
  10327. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10328. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10329. },
  10330. },
  10331. { } /* terminating entry */
  10332. },
  10333. .hook = quirk_invert_brightness,
  10334. },
  10335. };
  10336. static struct intel_quirk intel_quirks[] = {
  10337. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10338. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10339. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10340. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10341. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10342. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10343. /* Lenovo U160 cannot use SSC on LVDS */
  10344. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10345. /* Sony Vaio Y cannot use SSC on LVDS */
  10346. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10347. /* Acer Aspire 5734Z must invert backlight brightness */
  10348. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10349. /* Acer/eMachines G725 */
  10350. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10351. /* Acer/eMachines e725 */
  10352. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10353. /* Acer/Packard Bell NCL20 */
  10354. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10355. /* Acer Aspire 4736Z */
  10356. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10357. /* Acer Aspire 5336 */
  10358. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10359. };
  10360. static void intel_init_quirks(struct drm_device *dev)
  10361. {
  10362. struct pci_dev *d = dev->pdev;
  10363. int i;
  10364. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10365. struct intel_quirk *q = &intel_quirks[i];
  10366. if (d->device == q->device &&
  10367. (d->subsystem_vendor == q->subsystem_vendor ||
  10368. q->subsystem_vendor == PCI_ANY_ID) &&
  10369. (d->subsystem_device == q->subsystem_device ||
  10370. q->subsystem_device == PCI_ANY_ID))
  10371. q->hook(dev);
  10372. }
  10373. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10374. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10375. intel_dmi_quirks[i].hook(dev);
  10376. }
  10377. }
  10378. /* Disable the VGA plane that we never use */
  10379. static void i915_disable_vga(struct drm_device *dev)
  10380. {
  10381. struct drm_i915_private *dev_priv = dev->dev_private;
  10382. u8 sr1;
  10383. u32 vga_reg = i915_vgacntrl_reg(dev);
  10384. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10385. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10386. outb(SR01, VGA_SR_INDEX);
  10387. sr1 = inb(VGA_SR_DATA);
  10388. outb(sr1 | 1<<5, VGA_SR_DATA);
  10389. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10390. udelay(300);
  10391. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  10392. POSTING_READ(vga_reg);
  10393. }
  10394. void intel_modeset_init_hw(struct drm_device *dev)
  10395. {
  10396. intel_prepare_ddi(dev);
  10397. intel_init_clock_gating(dev);
  10398. intel_reset_dpio(dev);
  10399. intel_enable_gt_powersave(dev);
  10400. }
  10401. void intel_modeset_suspend_hw(struct drm_device *dev)
  10402. {
  10403. intel_suspend_hw(dev);
  10404. }
  10405. void intel_modeset_init(struct drm_device *dev)
  10406. {
  10407. struct drm_i915_private *dev_priv = dev->dev_private;
  10408. int sprite, ret;
  10409. enum pipe pipe;
  10410. struct intel_crtc *crtc;
  10411. drm_mode_config_init(dev);
  10412. dev->mode_config.min_width = 0;
  10413. dev->mode_config.min_height = 0;
  10414. dev->mode_config.preferred_depth = 24;
  10415. dev->mode_config.prefer_shadow = 1;
  10416. dev->mode_config.funcs = &intel_mode_funcs;
  10417. intel_init_quirks(dev);
  10418. intel_init_pm(dev);
  10419. if (INTEL_INFO(dev)->num_pipes == 0)
  10420. return;
  10421. intel_init_display(dev);
  10422. if (IS_GEN2(dev)) {
  10423. dev->mode_config.max_width = 2048;
  10424. dev->mode_config.max_height = 2048;
  10425. } else if (IS_GEN3(dev)) {
  10426. dev->mode_config.max_width = 4096;
  10427. dev->mode_config.max_height = 4096;
  10428. } else {
  10429. dev->mode_config.max_width = 8192;
  10430. dev->mode_config.max_height = 8192;
  10431. }
  10432. if (IS_GEN2(dev)) {
  10433. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10434. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10435. } else {
  10436. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10437. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10438. }
  10439. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10440. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10441. INTEL_INFO(dev)->num_pipes,
  10442. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10443. for_each_pipe(pipe) {
  10444. intel_crtc_init(dev, pipe);
  10445. for_each_sprite(pipe, sprite) {
  10446. ret = intel_plane_init(dev, pipe, sprite);
  10447. if (ret)
  10448. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10449. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10450. }
  10451. }
  10452. intel_init_dpio(dev);
  10453. intel_reset_dpio(dev);
  10454. intel_cpu_pll_init(dev);
  10455. intel_shared_dpll_init(dev);
  10456. /* Just disable it once at startup */
  10457. i915_disable_vga(dev);
  10458. intel_setup_outputs(dev);
  10459. /* Just in case the BIOS is doing something questionable. */
  10460. intel_disable_fbc(dev);
  10461. drm_modeset_lock_all(dev);
  10462. intel_modeset_setup_hw_state(dev, false);
  10463. drm_modeset_unlock_all(dev);
  10464. for_each_intel_crtc(dev, crtc) {
  10465. if (!crtc->active)
  10466. continue;
  10467. /*
  10468. * Note that reserving the BIOS fb up front prevents us
  10469. * from stuffing other stolen allocations like the ring
  10470. * on top. This prevents some ugliness at boot time, and
  10471. * can even allow for smooth boot transitions if the BIOS
  10472. * fb is large enough for the active pipe configuration.
  10473. */
  10474. if (dev_priv->display.get_plane_config) {
  10475. dev_priv->display.get_plane_config(crtc,
  10476. &crtc->plane_config);
  10477. /*
  10478. * If the fb is shared between multiple heads, we'll
  10479. * just get the first one.
  10480. */
  10481. intel_find_plane_obj(crtc, &crtc->plane_config);
  10482. }
  10483. }
  10484. }
  10485. static void intel_enable_pipe_a(struct drm_device *dev)
  10486. {
  10487. struct intel_connector *connector;
  10488. struct drm_connector *crt = NULL;
  10489. struct intel_load_detect_pipe load_detect_temp;
  10490. struct drm_modeset_acquire_ctx ctx;
  10491. /* We can't just switch on the pipe A, we need to set things up with a
  10492. * proper mode and output configuration. As a gross hack, enable pipe A
  10493. * by enabling the load detect pipe once. */
  10494. list_for_each_entry(connector,
  10495. &dev->mode_config.connector_list,
  10496. base.head) {
  10497. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  10498. crt = &connector->base;
  10499. break;
  10500. }
  10501. }
  10502. if (!crt)
  10503. return;
  10504. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, &ctx))
  10505. intel_release_load_detect_pipe(crt, &load_detect_temp, &ctx);
  10506. }
  10507. static bool
  10508. intel_check_plane_mapping(struct intel_crtc *crtc)
  10509. {
  10510. struct drm_device *dev = crtc->base.dev;
  10511. struct drm_i915_private *dev_priv = dev->dev_private;
  10512. u32 reg, val;
  10513. if (INTEL_INFO(dev)->num_pipes == 1)
  10514. return true;
  10515. reg = DSPCNTR(!crtc->plane);
  10516. val = I915_READ(reg);
  10517. if ((val & DISPLAY_PLANE_ENABLE) &&
  10518. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  10519. return false;
  10520. return true;
  10521. }
  10522. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  10523. {
  10524. struct drm_device *dev = crtc->base.dev;
  10525. struct drm_i915_private *dev_priv = dev->dev_private;
  10526. u32 reg;
  10527. /* Clear any frame start delays used for debugging left by the BIOS */
  10528. reg = PIPECONF(crtc->config.cpu_transcoder);
  10529. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  10530. /* restore vblank interrupts to correct state */
  10531. if (crtc->active)
  10532. drm_vblank_on(dev, crtc->pipe);
  10533. else
  10534. drm_vblank_off(dev, crtc->pipe);
  10535. /* We need to sanitize the plane -> pipe mapping first because this will
  10536. * disable the crtc (and hence change the state) if it is wrong. Note
  10537. * that gen4+ has a fixed plane -> pipe mapping. */
  10538. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  10539. struct intel_connector *connector;
  10540. bool plane;
  10541. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  10542. crtc->base.base.id);
  10543. /* Pipe has the wrong plane attached and the plane is active.
  10544. * Temporarily change the plane mapping and disable everything
  10545. * ... */
  10546. plane = crtc->plane;
  10547. crtc->plane = !plane;
  10548. dev_priv->display.crtc_disable(&crtc->base);
  10549. crtc->plane = plane;
  10550. /* ... and break all links. */
  10551. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10552. base.head) {
  10553. if (connector->encoder->base.crtc != &crtc->base)
  10554. continue;
  10555. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10556. connector->base.encoder = NULL;
  10557. }
  10558. /* multiple connectors may have the same encoder:
  10559. * handle them and break crtc link separately */
  10560. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10561. base.head)
  10562. if (connector->encoder->base.crtc == &crtc->base) {
  10563. connector->encoder->base.crtc = NULL;
  10564. connector->encoder->connectors_active = false;
  10565. }
  10566. WARN_ON(crtc->active);
  10567. crtc->base.enabled = false;
  10568. }
  10569. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  10570. crtc->pipe == PIPE_A && !crtc->active) {
  10571. /* BIOS forgot to enable pipe A, this mostly happens after
  10572. * resume. Force-enable the pipe to fix this, the update_dpms
  10573. * call below we restore the pipe to the right state, but leave
  10574. * the required bits on. */
  10575. intel_enable_pipe_a(dev);
  10576. }
  10577. /* Adjust the state of the output pipe according to whether we
  10578. * have active connectors/encoders. */
  10579. intel_crtc_update_dpms(&crtc->base);
  10580. if (crtc->active != crtc->base.enabled) {
  10581. struct intel_encoder *encoder;
  10582. /* This can happen either due to bugs in the get_hw_state
  10583. * functions or because the pipe is force-enabled due to the
  10584. * pipe A quirk. */
  10585. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  10586. crtc->base.base.id,
  10587. crtc->base.enabled ? "enabled" : "disabled",
  10588. crtc->active ? "enabled" : "disabled");
  10589. crtc->base.enabled = crtc->active;
  10590. /* Because we only establish the connector -> encoder ->
  10591. * crtc links if something is active, this means the
  10592. * crtc is now deactivated. Break the links. connector
  10593. * -> encoder links are only establish when things are
  10594. * actually up, hence no need to break them. */
  10595. WARN_ON(crtc->active);
  10596. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  10597. WARN_ON(encoder->connectors_active);
  10598. encoder->base.crtc = NULL;
  10599. }
  10600. }
  10601. if (crtc->active || IS_VALLEYVIEW(dev) || INTEL_INFO(dev)->gen < 5) {
  10602. /*
  10603. * We start out with underrun reporting disabled to avoid races.
  10604. * For correct bookkeeping mark this on active crtcs.
  10605. *
  10606. * Also on gmch platforms we dont have any hardware bits to
  10607. * disable the underrun reporting. Which means we need to start
  10608. * out with underrun reporting disabled also on inactive pipes,
  10609. * since otherwise we'll complain about the garbage we read when
  10610. * e.g. coming up after runtime pm.
  10611. *
  10612. * No protection against concurrent access is required - at
  10613. * worst a fifo underrun happens which also sets this to false.
  10614. */
  10615. crtc->cpu_fifo_underrun_disabled = true;
  10616. crtc->pch_fifo_underrun_disabled = true;
  10617. update_scanline_offset(crtc);
  10618. }
  10619. }
  10620. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  10621. {
  10622. struct intel_connector *connector;
  10623. struct drm_device *dev = encoder->base.dev;
  10624. /* We need to check both for a crtc link (meaning that the
  10625. * encoder is active and trying to read from a pipe) and the
  10626. * pipe itself being active. */
  10627. bool has_active_crtc = encoder->base.crtc &&
  10628. to_intel_crtc(encoder->base.crtc)->active;
  10629. if (encoder->connectors_active && !has_active_crtc) {
  10630. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  10631. encoder->base.base.id,
  10632. encoder->base.name);
  10633. /* Connector is active, but has no active pipe. This is
  10634. * fallout from our resume register restoring. Disable
  10635. * the encoder manually again. */
  10636. if (encoder->base.crtc) {
  10637. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  10638. encoder->base.base.id,
  10639. encoder->base.name);
  10640. encoder->disable(encoder);
  10641. }
  10642. encoder->base.crtc = NULL;
  10643. encoder->connectors_active = false;
  10644. /* Inconsistent output/port/pipe state happens presumably due to
  10645. * a bug in one of the get_hw_state functions. Or someplace else
  10646. * in our code, like the register restore mess on resume. Clamp
  10647. * things to off as a safer default. */
  10648. list_for_each_entry(connector,
  10649. &dev->mode_config.connector_list,
  10650. base.head) {
  10651. if (connector->encoder != encoder)
  10652. continue;
  10653. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10654. connector->base.encoder = NULL;
  10655. }
  10656. }
  10657. /* Enabled encoders without active connectors will be fixed in
  10658. * the crtc fixup. */
  10659. }
  10660. void i915_redisable_vga_power_on(struct drm_device *dev)
  10661. {
  10662. struct drm_i915_private *dev_priv = dev->dev_private;
  10663. u32 vga_reg = i915_vgacntrl_reg(dev);
  10664. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  10665. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  10666. i915_disable_vga(dev);
  10667. }
  10668. }
  10669. void i915_redisable_vga(struct drm_device *dev)
  10670. {
  10671. struct drm_i915_private *dev_priv = dev->dev_private;
  10672. /* This function can be called both from intel_modeset_setup_hw_state or
  10673. * at a very early point in our resume sequence, where the power well
  10674. * structures are not yet restored. Since this function is at a very
  10675. * paranoid "someone might have enabled VGA while we were not looking"
  10676. * level, just check if the power well is enabled instead of trying to
  10677. * follow the "don't touch the power well if we don't need it" policy
  10678. * the rest of the driver uses. */
  10679. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA))
  10680. return;
  10681. i915_redisable_vga_power_on(dev);
  10682. }
  10683. static bool primary_get_hw_state(struct intel_crtc *crtc)
  10684. {
  10685. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  10686. if (!crtc->active)
  10687. return false;
  10688. return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE;
  10689. }
  10690. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  10691. {
  10692. struct drm_i915_private *dev_priv = dev->dev_private;
  10693. enum pipe pipe;
  10694. struct intel_crtc *crtc;
  10695. struct intel_encoder *encoder;
  10696. struct intel_connector *connector;
  10697. int i;
  10698. for_each_intel_crtc(dev, crtc) {
  10699. memset(&crtc->config, 0, sizeof(crtc->config));
  10700. crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
  10701. crtc->active = dev_priv->display.get_pipe_config(crtc,
  10702. &crtc->config);
  10703. crtc->base.enabled = crtc->active;
  10704. crtc->primary_enabled = primary_get_hw_state(crtc);
  10705. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  10706. crtc->base.base.id,
  10707. crtc->active ? "enabled" : "disabled");
  10708. }
  10709. /* FIXME: Smash this into the new shared dpll infrastructure. */
  10710. if (HAS_DDI(dev))
  10711. intel_ddi_setup_hw_pll_state(dev);
  10712. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  10713. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  10714. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  10715. pll->active = 0;
  10716. for_each_intel_crtc(dev, crtc) {
  10717. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  10718. pll->active++;
  10719. }
  10720. pll->refcount = pll->active;
  10721. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  10722. pll->name, pll->refcount, pll->on);
  10723. }
  10724. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  10725. base.head) {
  10726. pipe = 0;
  10727. if (encoder->get_hw_state(encoder, &pipe)) {
  10728. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  10729. encoder->base.crtc = &crtc->base;
  10730. encoder->get_config(encoder, &crtc->config);
  10731. } else {
  10732. encoder->base.crtc = NULL;
  10733. }
  10734. encoder->connectors_active = false;
  10735. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  10736. encoder->base.base.id,
  10737. encoder->base.name,
  10738. encoder->base.crtc ? "enabled" : "disabled",
  10739. pipe_name(pipe));
  10740. }
  10741. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10742. base.head) {
  10743. if (connector->get_hw_state(connector)) {
  10744. connector->base.dpms = DRM_MODE_DPMS_ON;
  10745. connector->encoder->connectors_active = true;
  10746. connector->base.encoder = &connector->encoder->base;
  10747. } else {
  10748. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10749. connector->base.encoder = NULL;
  10750. }
  10751. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  10752. connector->base.base.id,
  10753. connector->base.name,
  10754. connector->base.encoder ? "enabled" : "disabled");
  10755. }
  10756. }
  10757. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  10758. * and i915 state tracking structures. */
  10759. void intel_modeset_setup_hw_state(struct drm_device *dev,
  10760. bool force_restore)
  10761. {
  10762. struct drm_i915_private *dev_priv = dev->dev_private;
  10763. enum pipe pipe;
  10764. struct intel_crtc *crtc;
  10765. struct intel_encoder *encoder;
  10766. int i;
  10767. intel_modeset_readout_hw_state(dev);
  10768. /*
  10769. * Now that we have the config, copy it to each CRTC struct
  10770. * Note that this could go away if we move to using crtc_config
  10771. * checking everywhere.
  10772. */
  10773. for_each_intel_crtc(dev, crtc) {
  10774. if (crtc->active && i915.fastboot) {
  10775. intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config);
  10776. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  10777. crtc->base.base.id);
  10778. drm_mode_debug_printmodeline(&crtc->base.mode);
  10779. }
  10780. }
  10781. /* HW state is read out, now we need to sanitize this mess. */
  10782. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  10783. base.head) {
  10784. intel_sanitize_encoder(encoder);
  10785. }
  10786. for_each_pipe(pipe) {
  10787. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  10788. intel_sanitize_crtc(crtc);
  10789. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  10790. }
  10791. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  10792. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  10793. if (!pll->on || pll->active)
  10794. continue;
  10795. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  10796. pll->disable(dev_priv, pll);
  10797. pll->on = false;
  10798. }
  10799. if (HAS_PCH_SPLIT(dev))
  10800. ilk_wm_get_hw_state(dev);
  10801. if (force_restore) {
  10802. i915_redisable_vga(dev);
  10803. /*
  10804. * We need to use raw interfaces for restoring state to avoid
  10805. * checking (bogus) intermediate states.
  10806. */
  10807. for_each_pipe(pipe) {
  10808. struct drm_crtc *crtc =
  10809. dev_priv->pipe_to_crtc_mapping[pipe];
  10810. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  10811. crtc->primary->fb);
  10812. }
  10813. } else {
  10814. intel_modeset_update_staged_output_state(dev);
  10815. }
  10816. intel_modeset_check_state(dev);
  10817. }
  10818. void intel_modeset_gem_init(struct drm_device *dev)
  10819. {
  10820. struct drm_crtc *c;
  10821. struct intel_framebuffer *fb;
  10822. mutex_lock(&dev->struct_mutex);
  10823. intel_init_gt_powersave(dev);
  10824. mutex_unlock(&dev->struct_mutex);
  10825. intel_modeset_init_hw(dev);
  10826. intel_setup_overlay(dev);
  10827. /*
  10828. * Make sure any fbs we allocated at startup are properly
  10829. * pinned & fenced. When we do the allocation it's too early
  10830. * for this.
  10831. */
  10832. mutex_lock(&dev->struct_mutex);
  10833. for_each_crtc(dev, c) {
  10834. if (!c->primary->fb)
  10835. continue;
  10836. fb = to_intel_framebuffer(c->primary->fb);
  10837. if (intel_pin_and_fence_fb_obj(dev, fb->obj, NULL)) {
  10838. DRM_ERROR("failed to pin boot fb on pipe %d\n",
  10839. to_intel_crtc(c)->pipe);
  10840. drm_framebuffer_unreference(c->primary->fb);
  10841. c->primary->fb = NULL;
  10842. }
  10843. }
  10844. mutex_unlock(&dev->struct_mutex);
  10845. }
  10846. void intel_connector_unregister(struct intel_connector *intel_connector)
  10847. {
  10848. struct drm_connector *connector = &intel_connector->base;
  10849. intel_panel_destroy_backlight(connector);
  10850. drm_sysfs_connector_remove(connector);
  10851. }
  10852. void intel_modeset_cleanup(struct drm_device *dev)
  10853. {
  10854. struct drm_i915_private *dev_priv = dev->dev_private;
  10855. struct drm_connector *connector;
  10856. /*
  10857. * Interrupts and polling as the first thing to avoid creating havoc.
  10858. * Too much stuff here (turning of rps, connectors, ...) would
  10859. * experience fancy races otherwise.
  10860. */
  10861. drm_irq_uninstall(dev);
  10862. cancel_work_sync(&dev_priv->hotplug_work);
  10863. /*
  10864. * Due to the hpd irq storm handling the hotplug work can re-arm the
  10865. * poll handlers. Hence disable polling after hpd handling is shut down.
  10866. */
  10867. drm_kms_helper_poll_fini(dev);
  10868. mutex_lock(&dev->struct_mutex);
  10869. intel_unregister_dsm_handler();
  10870. intel_disable_fbc(dev);
  10871. intel_disable_gt_powersave(dev);
  10872. ironlake_teardown_rc6(dev);
  10873. mutex_unlock(&dev->struct_mutex);
  10874. /* flush any delayed tasks or pending work */
  10875. flush_scheduled_work();
  10876. /* destroy the backlight and sysfs files before encoders/connectors */
  10877. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  10878. struct intel_connector *intel_connector;
  10879. intel_connector = to_intel_connector(connector);
  10880. intel_connector->unregister(intel_connector);
  10881. }
  10882. drm_mode_config_cleanup(dev);
  10883. intel_cleanup_overlay(dev);
  10884. mutex_lock(&dev->struct_mutex);
  10885. intel_cleanup_gt_powersave(dev);
  10886. mutex_unlock(&dev->struct_mutex);
  10887. }
  10888. /*
  10889. * Return which encoder is currently attached for connector.
  10890. */
  10891. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  10892. {
  10893. return &intel_attached_encoder(connector)->base;
  10894. }
  10895. void intel_connector_attach_encoder(struct intel_connector *connector,
  10896. struct intel_encoder *encoder)
  10897. {
  10898. connector->encoder = encoder;
  10899. drm_mode_connector_attach_encoder(&connector->base,
  10900. &encoder->base);
  10901. }
  10902. /*
  10903. * set vga decode state - true == enable VGA decode
  10904. */
  10905. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  10906. {
  10907. struct drm_i915_private *dev_priv = dev->dev_private;
  10908. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  10909. u16 gmch_ctrl;
  10910. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  10911. DRM_ERROR("failed to read control word\n");
  10912. return -EIO;
  10913. }
  10914. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  10915. return 0;
  10916. if (state)
  10917. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  10918. else
  10919. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  10920. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  10921. DRM_ERROR("failed to write control word\n");
  10922. return -EIO;
  10923. }
  10924. return 0;
  10925. }
  10926. struct intel_display_error_state {
  10927. u32 power_well_driver;
  10928. int num_transcoders;
  10929. struct intel_cursor_error_state {
  10930. u32 control;
  10931. u32 position;
  10932. u32 base;
  10933. u32 size;
  10934. } cursor[I915_MAX_PIPES];
  10935. struct intel_pipe_error_state {
  10936. bool power_domain_on;
  10937. u32 source;
  10938. u32 stat;
  10939. } pipe[I915_MAX_PIPES];
  10940. struct intel_plane_error_state {
  10941. u32 control;
  10942. u32 stride;
  10943. u32 size;
  10944. u32 pos;
  10945. u32 addr;
  10946. u32 surface;
  10947. u32 tile_offset;
  10948. } plane[I915_MAX_PIPES];
  10949. struct intel_transcoder_error_state {
  10950. bool power_domain_on;
  10951. enum transcoder cpu_transcoder;
  10952. u32 conf;
  10953. u32 htotal;
  10954. u32 hblank;
  10955. u32 hsync;
  10956. u32 vtotal;
  10957. u32 vblank;
  10958. u32 vsync;
  10959. } transcoder[4];
  10960. };
  10961. struct intel_display_error_state *
  10962. intel_display_capture_error_state(struct drm_device *dev)
  10963. {
  10964. struct drm_i915_private *dev_priv = dev->dev_private;
  10965. struct intel_display_error_state *error;
  10966. int transcoders[] = {
  10967. TRANSCODER_A,
  10968. TRANSCODER_B,
  10969. TRANSCODER_C,
  10970. TRANSCODER_EDP,
  10971. };
  10972. int i;
  10973. if (INTEL_INFO(dev)->num_pipes == 0)
  10974. return NULL;
  10975. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  10976. if (error == NULL)
  10977. return NULL;
  10978. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  10979. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  10980. for_each_pipe(i) {
  10981. error->pipe[i].power_domain_on =
  10982. intel_display_power_enabled_unlocked(dev_priv,
  10983. POWER_DOMAIN_PIPE(i));
  10984. if (!error->pipe[i].power_domain_on)
  10985. continue;
  10986. error->cursor[i].control = I915_READ(CURCNTR(i));
  10987. error->cursor[i].position = I915_READ(CURPOS(i));
  10988. error->cursor[i].base = I915_READ(CURBASE(i));
  10989. error->plane[i].control = I915_READ(DSPCNTR(i));
  10990. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  10991. if (INTEL_INFO(dev)->gen <= 3) {
  10992. error->plane[i].size = I915_READ(DSPSIZE(i));
  10993. error->plane[i].pos = I915_READ(DSPPOS(i));
  10994. }
  10995. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  10996. error->plane[i].addr = I915_READ(DSPADDR(i));
  10997. if (INTEL_INFO(dev)->gen >= 4) {
  10998. error->plane[i].surface = I915_READ(DSPSURF(i));
  10999. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  11000. }
  11001. error->pipe[i].source = I915_READ(PIPESRC(i));
  11002. if (!HAS_PCH_SPLIT(dev))
  11003. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  11004. }
  11005. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  11006. if (HAS_DDI(dev_priv->dev))
  11007. error->num_transcoders++; /* Account for eDP. */
  11008. for (i = 0; i < error->num_transcoders; i++) {
  11009. enum transcoder cpu_transcoder = transcoders[i];
  11010. error->transcoder[i].power_domain_on =
  11011. intel_display_power_enabled_unlocked(dev_priv,
  11012. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  11013. if (!error->transcoder[i].power_domain_on)
  11014. continue;
  11015. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  11016. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  11017. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  11018. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  11019. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  11020. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  11021. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  11022. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  11023. }
  11024. return error;
  11025. }
  11026. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  11027. void
  11028. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  11029. struct drm_device *dev,
  11030. struct intel_display_error_state *error)
  11031. {
  11032. int i;
  11033. if (!error)
  11034. return;
  11035. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  11036. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11037. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  11038. error->power_well_driver);
  11039. for_each_pipe(i) {
  11040. err_printf(m, "Pipe [%d]:\n", i);
  11041. err_printf(m, " Power: %s\n",
  11042. error->pipe[i].power_domain_on ? "on" : "off");
  11043. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  11044. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  11045. err_printf(m, "Plane [%d]:\n", i);
  11046. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  11047. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  11048. if (INTEL_INFO(dev)->gen <= 3) {
  11049. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  11050. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  11051. }
  11052. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11053. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  11054. if (INTEL_INFO(dev)->gen >= 4) {
  11055. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  11056. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  11057. }
  11058. err_printf(m, "Cursor [%d]:\n", i);
  11059. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  11060. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  11061. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  11062. }
  11063. for (i = 0; i < error->num_transcoders; i++) {
  11064. err_printf(m, "CPU transcoder: %c\n",
  11065. transcoder_name(error->transcoder[i].cpu_transcoder));
  11066. err_printf(m, " Power: %s\n",
  11067. error->transcoder[i].power_domain_on ? "on" : "off");
  11068. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  11069. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  11070. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  11071. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  11072. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  11073. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  11074. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  11075. }
  11076. }