intel_display.c 381 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809
  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. static void intel_increase_pllclock(struct drm_device *dev,
  71. enum pipe pipe);
  72. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  73. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  74. struct intel_crtc_config *pipe_config);
  75. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  76. struct intel_crtc_config *pipe_config);
  77. static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
  78. int x, int y, struct drm_framebuffer *old_fb);
  79. static int intel_framebuffer_init(struct drm_device *dev,
  80. struct intel_framebuffer *ifb,
  81. struct drm_mode_fb_cmd2 *mode_cmd,
  82. struct drm_i915_gem_object *obj);
  83. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc);
  84. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc);
  85. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  86. struct intel_link_m_n *m_n,
  87. struct intel_link_m_n *m2_n2);
  88. static void ironlake_set_pipeconf(struct drm_crtc *crtc);
  89. static void haswell_set_pipeconf(struct drm_crtc *crtc);
  90. static void intel_set_pipe_csc(struct drm_crtc *crtc);
  91. static void vlv_prepare_pll(struct intel_crtc *crtc);
  92. static void chv_prepare_pll(struct intel_crtc *crtc);
  93. static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe)
  94. {
  95. if (!connector->mst_port)
  96. return connector->encoder;
  97. else
  98. return &connector->mst_port->mst_encoders[pipe]->base;
  99. }
  100. typedef struct {
  101. int min, max;
  102. } intel_range_t;
  103. typedef struct {
  104. int dot_limit;
  105. int p2_slow, p2_fast;
  106. } intel_p2_t;
  107. typedef struct intel_limit intel_limit_t;
  108. struct intel_limit {
  109. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  110. intel_p2_t p2;
  111. };
  112. int
  113. intel_pch_rawclk(struct drm_device *dev)
  114. {
  115. struct drm_i915_private *dev_priv = dev->dev_private;
  116. WARN_ON(!HAS_PCH_SPLIT(dev));
  117. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  118. }
  119. static inline u32 /* units of 100MHz */
  120. intel_fdi_link_freq(struct drm_device *dev)
  121. {
  122. if (IS_GEN5(dev)) {
  123. struct drm_i915_private *dev_priv = dev->dev_private;
  124. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  125. } else
  126. return 27;
  127. }
  128. static const intel_limit_t intel_limits_i8xx_dac = {
  129. .dot = { .min = 25000, .max = 350000 },
  130. .vco = { .min = 908000, .max = 1512000 },
  131. .n = { .min = 2, .max = 16 },
  132. .m = { .min = 96, .max = 140 },
  133. .m1 = { .min = 18, .max = 26 },
  134. .m2 = { .min = 6, .max = 16 },
  135. .p = { .min = 4, .max = 128 },
  136. .p1 = { .min = 2, .max = 33 },
  137. .p2 = { .dot_limit = 165000,
  138. .p2_slow = 4, .p2_fast = 2 },
  139. };
  140. static const intel_limit_t intel_limits_i8xx_dvo = {
  141. .dot = { .min = 25000, .max = 350000 },
  142. .vco = { .min = 908000, .max = 1512000 },
  143. .n = { .min = 2, .max = 16 },
  144. .m = { .min = 96, .max = 140 },
  145. .m1 = { .min = 18, .max = 26 },
  146. .m2 = { .min = 6, .max = 16 },
  147. .p = { .min = 4, .max = 128 },
  148. .p1 = { .min = 2, .max = 33 },
  149. .p2 = { .dot_limit = 165000,
  150. .p2_slow = 4, .p2_fast = 4 },
  151. };
  152. static const intel_limit_t intel_limits_i8xx_lvds = {
  153. .dot = { .min = 25000, .max = 350000 },
  154. .vco = { .min = 908000, .max = 1512000 },
  155. .n = { .min = 2, .max = 16 },
  156. .m = { .min = 96, .max = 140 },
  157. .m1 = { .min = 18, .max = 26 },
  158. .m2 = { .min = 6, .max = 16 },
  159. .p = { .min = 4, .max = 128 },
  160. .p1 = { .min = 1, .max = 6 },
  161. .p2 = { .dot_limit = 165000,
  162. .p2_slow = 14, .p2_fast = 7 },
  163. };
  164. static const intel_limit_t intel_limits_i9xx_sdvo = {
  165. .dot = { .min = 20000, .max = 400000 },
  166. .vco = { .min = 1400000, .max = 2800000 },
  167. .n = { .min = 1, .max = 6 },
  168. .m = { .min = 70, .max = 120 },
  169. .m1 = { .min = 8, .max = 18 },
  170. .m2 = { .min = 3, .max = 7 },
  171. .p = { .min = 5, .max = 80 },
  172. .p1 = { .min = 1, .max = 8 },
  173. .p2 = { .dot_limit = 200000,
  174. .p2_slow = 10, .p2_fast = 5 },
  175. };
  176. static const intel_limit_t intel_limits_i9xx_lvds = {
  177. .dot = { .min = 20000, .max = 400000 },
  178. .vco = { .min = 1400000, .max = 2800000 },
  179. .n = { .min = 1, .max = 6 },
  180. .m = { .min = 70, .max = 120 },
  181. .m1 = { .min = 8, .max = 18 },
  182. .m2 = { .min = 3, .max = 7 },
  183. .p = { .min = 7, .max = 98 },
  184. .p1 = { .min = 1, .max = 8 },
  185. .p2 = { .dot_limit = 112000,
  186. .p2_slow = 14, .p2_fast = 7 },
  187. };
  188. static const intel_limit_t intel_limits_g4x_sdvo = {
  189. .dot = { .min = 25000, .max = 270000 },
  190. .vco = { .min = 1750000, .max = 3500000},
  191. .n = { .min = 1, .max = 4 },
  192. .m = { .min = 104, .max = 138 },
  193. .m1 = { .min = 17, .max = 23 },
  194. .m2 = { .min = 5, .max = 11 },
  195. .p = { .min = 10, .max = 30 },
  196. .p1 = { .min = 1, .max = 3},
  197. .p2 = { .dot_limit = 270000,
  198. .p2_slow = 10,
  199. .p2_fast = 10
  200. },
  201. };
  202. static const intel_limit_t intel_limits_g4x_hdmi = {
  203. .dot = { .min = 22000, .max = 400000 },
  204. .vco = { .min = 1750000, .max = 3500000},
  205. .n = { .min = 1, .max = 4 },
  206. .m = { .min = 104, .max = 138 },
  207. .m1 = { .min = 16, .max = 23 },
  208. .m2 = { .min = 5, .max = 11 },
  209. .p = { .min = 5, .max = 80 },
  210. .p1 = { .min = 1, .max = 8},
  211. .p2 = { .dot_limit = 165000,
  212. .p2_slow = 10, .p2_fast = 5 },
  213. };
  214. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  215. .dot = { .min = 20000, .max = 115000 },
  216. .vco = { .min = 1750000, .max = 3500000 },
  217. .n = { .min = 1, .max = 3 },
  218. .m = { .min = 104, .max = 138 },
  219. .m1 = { .min = 17, .max = 23 },
  220. .m2 = { .min = 5, .max = 11 },
  221. .p = { .min = 28, .max = 112 },
  222. .p1 = { .min = 2, .max = 8 },
  223. .p2 = { .dot_limit = 0,
  224. .p2_slow = 14, .p2_fast = 14
  225. },
  226. };
  227. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  228. .dot = { .min = 80000, .max = 224000 },
  229. .vco = { .min = 1750000, .max = 3500000 },
  230. .n = { .min = 1, .max = 3 },
  231. .m = { .min = 104, .max = 138 },
  232. .m1 = { .min = 17, .max = 23 },
  233. .m2 = { .min = 5, .max = 11 },
  234. .p = { .min = 14, .max = 42 },
  235. .p1 = { .min = 2, .max = 6 },
  236. .p2 = { .dot_limit = 0,
  237. .p2_slow = 7, .p2_fast = 7
  238. },
  239. };
  240. static const intel_limit_t intel_limits_pineview_sdvo = {
  241. .dot = { .min = 20000, .max = 400000},
  242. .vco = { .min = 1700000, .max = 3500000 },
  243. /* Pineview's Ncounter is a ring counter */
  244. .n = { .min = 3, .max = 6 },
  245. .m = { .min = 2, .max = 256 },
  246. /* Pineview only has one combined m divider, which we treat as m2. */
  247. .m1 = { .min = 0, .max = 0 },
  248. .m2 = { .min = 0, .max = 254 },
  249. .p = { .min = 5, .max = 80 },
  250. .p1 = { .min = 1, .max = 8 },
  251. .p2 = { .dot_limit = 200000,
  252. .p2_slow = 10, .p2_fast = 5 },
  253. };
  254. static const intel_limit_t intel_limits_pineview_lvds = {
  255. .dot = { .min = 20000, .max = 400000 },
  256. .vco = { .min = 1700000, .max = 3500000 },
  257. .n = { .min = 3, .max = 6 },
  258. .m = { .min = 2, .max = 256 },
  259. .m1 = { .min = 0, .max = 0 },
  260. .m2 = { .min = 0, .max = 254 },
  261. .p = { .min = 7, .max = 112 },
  262. .p1 = { .min = 1, .max = 8 },
  263. .p2 = { .dot_limit = 112000,
  264. .p2_slow = 14, .p2_fast = 14 },
  265. };
  266. /* Ironlake / Sandybridge
  267. *
  268. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  269. * the range value for them is (actual_value - 2).
  270. */
  271. static const intel_limit_t intel_limits_ironlake_dac = {
  272. .dot = { .min = 25000, .max = 350000 },
  273. .vco = { .min = 1760000, .max = 3510000 },
  274. .n = { .min = 1, .max = 5 },
  275. .m = { .min = 79, .max = 127 },
  276. .m1 = { .min = 12, .max = 22 },
  277. .m2 = { .min = 5, .max = 9 },
  278. .p = { .min = 5, .max = 80 },
  279. .p1 = { .min = 1, .max = 8 },
  280. .p2 = { .dot_limit = 225000,
  281. .p2_slow = 10, .p2_fast = 5 },
  282. };
  283. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  284. .dot = { .min = 25000, .max = 350000 },
  285. .vco = { .min = 1760000, .max = 3510000 },
  286. .n = { .min = 1, .max = 3 },
  287. .m = { .min = 79, .max = 118 },
  288. .m1 = { .min = 12, .max = 22 },
  289. .m2 = { .min = 5, .max = 9 },
  290. .p = { .min = 28, .max = 112 },
  291. .p1 = { .min = 2, .max = 8 },
  292. .p2 = { .dot_limit = 225000,
  293. .p2_slow = 14, .p2_fast = 14 },
  294. };
  295. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  296. .dot = { .min = 25000, .max = 350000 },
  297. .vco = { .min = 1760000, .max = 3510000 },
  298. .n = { .min = 1, .max = 3 },
  299. .m = { .min = 79, .max = 127 },
  300. .m1 = { .min = 12, .max = 22 },
  301. .m2 = { .min = 5, .max = 9 },
  302. .p = { .min = 14, .max = 56 },
  303. .p1 = { .min = 2, .max = 8 },
  304. .p2 = { .dot_limit = 225000,
  305. .p2_slow = 7, .p2_fast = 7 },
  306. };
  307. /* LVDS 100mhz refclk limits. */
  308. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  309. .dot = { .min = 25000, .max = 350000 },
  310. .vco = { .min = 1760000, .max = 3510000 },
  311. .n = { .min = 1, .max = 2 },
  312. .m = { .min = 79, .max = 126 },
  313. .m1 = { .min = 12, .max = 22 },
  314. .m2 = { .min = 5, .max = 9 },
  315. .p = { .min = 28, .max = 112 },
  316. .p1 = { .min = 2, .max = 8 },
  317. .p2 = { .dot_limit = 225000,
  318. .p2_slow = 14, .p2_fast = 14 },
  319. };
  320. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  321. .dot = { .min = 25000, .max = 350000 },
  322. .vco = { .min = 1760000, .max = 3510000 },
  323. .n = { .min = 1, .max = 3 },
  324. .m = { .min = 79, .max = 126 },
  325. .m1 = { .min = 12, .max = 22 },
  326. .m2 = { .min = 5, .max = 9 },
  327. .p = { .min = 14, .max = 42 },
  328. .p1 = { .min = 2, .max = 6 },
  329. .p2 = { .dot_limit = 225000,
  330. .p2_slow = 7, .p2_fast = 7 },
  331. };
  332. static const intel_limit_t intel_limits_vlv = {
  333. /*
  334. * These are the data rate limits (measured in fast clocks)
  335. * since those are the strictest limits we have. The fast
  336. * clock and actual rate limits are more relaxed, so checking
  337. * them would make no difference.
  338. */
  339. .dot = { .min = 25000 * 5, .max = 270000 * 5 },
  340. .vco = { .min = 4000000, .max = 6000000 },
  341. .n = { .min = 1, .max = 7 },
  342. .m1 = { .min = 2, .max = 3 },
  343. .m2 = { .min = 11, .max = 156 },
  344. .p1 = { .min = 2, .max = 3 },
  345. .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
  346. };
  347. static const intel_limit_t intel_limits_chv = {
  348. /*
  349. * These are the data rate limits (measured in fast clocks)
  350. * since those are the strictest limits we have. The fast
  351. * clock and actual rate limits are more relaxed, so checking
  352. * them would make no difference.
  353. */
  354. .dot = { .min = 25000 * 5, .max = 540000 * 5},
  355. .vco = { .min = 4860000, .max = 6700000 },
  356. .n = { .min = 1, .max = 1 },
  357. .m1 = { .min = 2, .max = 2 },
  358. .m2 = { .min = 24 << 22, .max = 175 << 22 },
  359. .p1 = { .min = 2, .max = 4 },
  360. .p2 = { .p2_slow = 1, .p2_fast = 14 },
  361. };
  362. static void vlv_clock(int refclk, intel_clock_t *clock)
  363. {
  364. clock->m = clock->m1 * clock->m2;
  365. clock->p = clock->p1 * clock->p2;
  366. if (WARN_ON(clock->n == 0 || clock->p == 0))
  367. return;
  368. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  369. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  370. }
  371. /**
  372. * Returns whether any output on the specified pipe is of the specified type
  373. */
  374. static bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  375. {
  376. struct drm_device *dev = crtc->dev;
  377. struct intel_encoder *encoder;
  378. for_each_encoder_on_crtc(dev, crtc, encoder)
  379. if (encoder->type == type)
  380. return true;
  381. return false;
  382. }
  383. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  384. int refclk)
  385. {
  386. struct drm_device *dev = crtc->dev;
  387. const intel_limit_t *limit;
  388. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  389. if (intel_is_dual_link_lvds(dev)) {
  390. if (refclk == 100000)
  391. limit = &intel_limits_ironlake_dual_lvds_100m;
  392. else
  393. limit = &intel_limits_ironlake_dual_lvds;
  394. } else {
  395. if (refclk == 100000)
  396. limit = &intel_limits_ironlake_single_lvds_100m;
  397. else
  398. limit = &intel_limits_ironlake_single_lvds;
  399. }
  400. } else
  401. limit = &intel_limits_ironlake_dac;
  402. return limit;
  403. }
  404. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  405. {
  406. struct drm_device *dev = crtc->dev;
  407. const intel_limit_t *limit;
  408. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  409. if (intel_is_dual_link_lvds(dev))
  410. limit = &intel_limits_g4x_dual_channel_lvds;
  411. else
  412. limit = &intel_limits_g4x_single_channel_lvds;
  413. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  414. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  415. limit = &intel_limits_g4x_hdmi;
  416. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  417. limit = &intel_limits_g4x_sdvo;
  418. } else /* The option is for other outputs */
  419. limit = &intel_limits_i9xx_sdvo;
  420. return limit;
  421. }
  422. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  423. {
  424. struct drm_device *dev = crtc->dev;
  425. const intel_limit_t *limit;
  426. if (HAS_PCH_SPLIT(dev))
  427. limit = intel_ironlake_limit(crtc, refclk);
  428. else if (IS_G4X(dev)) {
  429. limit = intel_g4x_limit(crtc);
  430. } else if (IS_PINEVIEW(dev)) {
  431. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  432. limit = &intel_limits_pineview_lvds;
  433. else
  434. limit = &intel_limits_pineview_sdvo;
  435. } else if (IS_CHERRYVIEW(dev)) {
  436. limit = &intel_limits_chv;
  437. } else if (IS_VALLEYVIEW(dev)) {
  438. limit = &intel_limits_vlv;
  439. } else if (!IS_GEN2(dev)) {
  440. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  441. limit = &intel_limits_i9xx_lvds;
  442. else
  443. limit = &intel_limits_i9xx_sdvo;
  444. } else {
  445. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  446. limit = &intel_limits_i8xx_lvds;
  447. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO))
  448. limit = &intel_limits_i8xx_dvo;
  449. else
  450. limit = &intel_limits_i8xx_dac;
  451. }
  452. return limit;
  453. }
  454. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  455. static void pineview_clock(int refclk, intel_clock_t *clock)
  456. {
  457. clock->m = clock->m2 + 2;
  458. clock->p = clock->p1 * clock->p2;
  459. if (WARN_ON(clock->n == 0 || clock->p == 0))
  460. return;
  461. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
  462. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  463. }
  464. static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
  465. {
  466. return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
  467. }
  468. static void i9xx_clock(int refclk, intel_clock_t *clock)
  469. {
  470. clock->m = i9xx_dpll_compute_m(clock);
  471. clock->p = clock->p1 * clock->p2;
  472. if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
  473. return;
  474. clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
  475. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  476. }
  477. static void chv_clock(int refclk, intel_clock_t *clock)
  478. {
  479. clock->m = clock->m1 * clock->m2;
  480. clock->p = clock->p1 * clock->p2;
  481. if (WARN_ON(clock->n == 0 || clock->p == 0))
  482. return;
  483. clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
  484. clock->n << 22);
  485. clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
  486. }
  487. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  488. /**
  489. * Returns whether the given set of divisors are valid for a given refclk with
  490. * the given connectors.
  491. */
  492. static bool intel_PLL_is_valid(struct drm_device *dev,
  493. const intel_limit_t *limit,
  494. const intel_clock_t *clock)
  495. {
  496. if (clock->n < limit->n.min || limit->n.max < clock->n)
  497. INTELPllInvalid("n out of range\n");
  498. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  499. INTELPllInvalid("p1 out of range\n");
  500. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  501. INTELPllInvalid("m2 out of range\n");
  502. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  503. INTELPllInvalid("m1 out of range\n");
  504. if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev))
  505. if (clock->m1 <= clock->m2)
  506. INTELPllInvalid("m1 <= m2\n");
  507. if (!IS_VALLEYVIEW(dev)) {
  508. if (clock->p < limit->p.min || limit->p.max < clock->p)
  509. INTELPllInvalid("p out of range\n");
  510. if (clock->m < limit->m.min || limit->m.max < clock->m)
  511. INTELPllInvalid("m out of range\n");
  512. }
  513. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  514. INTELPllInvalid("vco out of range\n");
  515. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  516. * connector, etc., rather than just a single range.
  517. */
  518. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  519. INTELPllInvalid("dot out of range\n");
  520. return true;
  521. }
  522. static bool
  523. i9xx_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  524. int target, int refclk, intel_clock_t *match_clock,
  525. intel_clock_t *best_clock)
  526. {
  527. struct drm_device *dev = crtc->dev;
  528. intel_clock_t clock;
  529. int err = target;
  530. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  531. /*
  532. * For LVDS just rely on its current settings for dual-channel.
  533. * We haven't figured out how to reliably set up different
  534. * single/dual channel state, if we even can.
  535. */
  536. if (intel_is_dual_link_lvds(dev))
  537. clock.p2 = limit->p2.p2_fast;
  538. else
  539. clock.p2 = limit->p2.p2_slow;
  540. } else {
  541. if (target < limit->p2.dot_limit)
  542. clock.p2 = limit->p2.p2_slow;
  543. else
  544. clock.p2 = limit->p2.p2_fast;
  545. }
  546. memset(best_clock, 0, sizeof(*best_clock));
  547. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  548. clock.m1++) {
  549. for (clock.m2 = limit->m2.min;
  550. clock.m2 <= limit->m2.max; clock.m2++) {
  551. if (clock.m2 >= clock.m1)
  552. break;
  553. for (clock.n = limit->n.min;
  554. clock.n <= limit->n.max; clock.n++) {
  555. for (clock.p1 = limit->p1.min;
  556. clock.p1 <= limit->p1.max; clock.p1++) {
  557. int this_err;
  558. i9xx_clock(refclk, &clock);
  559. if (!intel_PLL_is_valid(dev, limit,
  560. &clock))
  561. continue;
  562. if (match_clock &&
  563. clock.p != match_clock->p)
  564. continue;
  565. this_err = abs(clock.dot - target);
  566. if (this_err < err) {
  567. *best_clock = clock;
  568. err = this_err;
  569. }
  570. }
  571. }
  572. }
  573. }
  574. return (err != target);
  575. }
  576. static bool
  577. pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  578. int target, int refclk, intel_clock_t *match_clock,
  579. intel_clock_t *best_clock)
  580. {
  581. struct drm_device *dev = crtc->dev;
  582. intel_clock_t clock;
  583. int err = target;
  584. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  585. /*
  586. * For LVDS just rely on its current settings for dual-channel.
  587. * We haven't figured out how to reliably set up different
  588. * single/dual channel state, if we even can.
  589. */
  590. if (intel_is_dual_link_lvds(dev))
  591. clock.p2 = limit->p2.p2_fast;
  592. else
  593. clock.p2 = limit->p2.p2_slow;
  594. } else {
  595. if (target < limit->p2.dot_limit)
  596. clock.p2 = limit->p2.p2_slow;
  597. else
  598. clock.p2 = limit->p2.p2_fast;
  599. }
  600. memset(best_clock, 0, sizeof(*best_clock));
  601. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  602. clock.m1++) {
  603. for (clock.m2 = limit->m2.min;
  604. clock.m2 <= limit->m2.max; clock.m2++) {
  605. for (clock.n = limit->n.min;
  606. clock.n <= limit->n.max; clock.n++) {
  607. for (clock.p1 = limit->p1.min;
  608. clock.p1 <= limit->p1.max; clock.p1++) {
  609. int this_err;
  610. pineview_clock(refclk, &clock);
  611. if (!intel_PLL_is_valid(dev, limit,
  612. &clock))
  613. continue;
  614. if (match_clock &&
  615. clock.p != match_clock->p)
  616. continue;
  617. this_err = abs(clock.dot - target);
  618. if (this_err < err) {
  619. *best_clock = clock;
  620. err = this_err;
  621. }
  622. }
  623. }
  624. }
  625. }
  626. return (err != target);
  627. }
  628. static bool
  629. g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  630. int target, int refclk, intel_clock_t *match_clock,
  631. intel_clock_t *best_clock)
  632. {
  633. struct drm_device *dev = crtc->dev;
  634. intel_clock_t clock;
  635. int max_n;
  636. bool found;
  637. /* approximately equals target * 0.00585 */
  638. int err_most = (target >> 8) + (target >> 9);
  639. found = false;
  640. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  641. if (intel_is_dual_link_lvds(dev))
  642. clock.p2 = limit->p2.p2_fast;
  643. else
  644. clock.p2 = limit->p2.p2_slow;
  645. } else {
  646. if (target < limit->p2.dot_limit)
  647. clock.p2 = limit->p2.p2_slow;
  648. else
  649. clock.p2 = limit->p2.p2_fast;
  650. }
  651. memset(best_clock, 0, sizeof(*best_clock));
  652. max_n = limit->n.max;
  653. /* based on hardware requirement, prefer smaller n to precision */
  654. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  655. /* based on hardware requirement, prefere larger m1,m2 */
  656. for (clock.m1 = limit->m1.max;
  657. clock.m1 >= limit->m1.min; clock.m1--) {
  658. for (clock.m2 = limit->m2.max;
  659. clock.m2 >= limit->m2.min; clock.m2--) {
  660. for (clock.p1 = limit->p1.max;
  661. clock.p1 >= limit->p1.min; clock.p1--) {
  662. int this_err;
  663. i9xx_clock(refclk, &clock);
  664. if (!intel_PLL_is_valid(dev, limit,
  665. &clock))
  666. continue;
  667. this_err = abs(clock.dot - target);
  668. if (this_err < err_most) {
  669. *best_clock = clock;
  670. err_most = this_err;
  671. max_n = clock.n;
  672. found = true;
  673. }
  674. }
  675. }
  676. }
  677. }
  678. return found;
  679. }
  680. static bool
  681. vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  682. int target, int refclk, intel_clock_t *match_clock,
  683. intel_clock_t *best_clock)
  684. {
  685. struct drm_device *dev = crtc->dev;
  686. intel_clock_t clock;
  687. unsigned int bestppm = 1000000;
  688. /* min update 19.2 MHz */
  689. int max_n = min(limit->n.max, refclk / 19200);
  690. bool found = false;
  691. target *= 5; /* fast clock */
  692. memset(best_clock, 0, sizeof(*best_clock));
  693. /* based on hardware requirement, prefer smaller n to precision */
  694. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  695. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  696. for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
  697. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  698. clock.p = clock.p1 * clock.p2;
  699. /* based on hardware requirement, prefer bigger m1,m2 values */
  700. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  701. unsigned int ppm, diff;
  702. clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
  703. refclk * clock.m1);
  704. vlv_clock(refclk, &clock);
  705. if (!intel_PLL_is_valid(dev, limit,
  706. &clock))
  707. continue;
  708. diff = abs(clock.dot - target);
  709. ppm = div_u64(1000000ULL * diff, target);
  710. if (ppm < 100 && clock.p > best_clock->p) {
  711. bestppm = 0;
  712. *best_clock = clock;
  713. found = true;
  714. }
  715. if (bestppm >= 10 && ppm < bestppm - 10) {
  716. bestppm = ppm;
  717. *best_clock = clock;
  718. found = true;
  719. }
  720. }
  721. }
  722. }
  723. }
  724. return found;
  725. }
  726. static bool
  727. chv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc,
  728. int target, int refclk, intel_clock_t *match_clock,
  729. intel_clock_t *best_clock)
  730. {
  731. struct drm_device *dev = crtc->dev;
  732. intel_clock_t clock;
  733. uint64_t m2;
  734. int found = false;
  735. memset(best_clock, 0, sizeof(*best_clock));
  736. /*
  737. * Based on hardware doc, the n always set to 1, and m1 always
  738. * set to 2. If requires to support 200Mhz refclk, we need to
  739. * revisit this because n may not 1 anymore.
  740. */
  741. clock.n = 1, clock.m1 = 2;
  742. target *= 5; /* fast clock */
  743. for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
  744. for (clock.p2 = limit->p2.p2_fast;
  745. clock.p2 >= limit->p2.p2_slow;
  746. clock.p2 -= clock.p2 > 10 ? 2 : 1) {
  747. clock.p = clock.p1 * clock.p2;
  748. m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
  749. clock.n) << 22, refclk * clock.m1);
  750. if (m2 > INT_MAX/clock.m1)
  751. continue;
  752. clock.m2 = m2;
  753. chv_clock(refclk, &clock);
  754. if (!intel_PLL_is_valid(dev, limit, &clock))
  755. continue;
  756. /* based on hardware requirement, prefer bigger p
  757. */
  758. if (clock.p > best_clock->p) {
  759. *best_clock = clock;
  760. found = true;
  761. }
  762. }
  763. }
  764. return found;
  765. }
  766. bool intel_crtc_active(struct drm_crtc *crtc)
  767. {
  768. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  769. /* Be paranoid as we can arrive here with only partial
  770. * state retrieved from the hardware during setup.
  771. *
  772. * We can ditch the adjusted_mode.crtc_clock check as soon
  773. * as Haswell has gained clock readout/fastboot support.
  774. *
  775. * We can ditch the crtc->primary->fb check as soon as we can
  776. * properly reconstruct framebuffers.
  777. */
  778. return intel_crtc->active && crtc->primary->fb &&
  779. intel_crtc->config.adjusted_mode.crtc_clock;
  780. }
  781. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  782. enum pipe pipe)
  783. {
  784. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  785. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  786. return intel_crtc->config.cpu_transcoder;
  787. }
  788. static void g4x_wait_for_vblank(struct drm_device *dev, int pipe)
  789. {
  790. struct drm_i915_private *dev_priv = dev->dev_private;
  791. u32 frame, frame_reg = PIPE_FRMCOUNT_GM45(pipe);
  792. frame = I915_READ(frame_reg);
  793. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  794. WARN(1, "vblank wait on pipe %c timed out\n",
  795. pipe_name(pipe));
  796. }
  797. /**
  798. * intel_wait_for_vblank - wait for vblank on a given pipe
  799. * @dev: drm device
  800. * @pipe: pipe to wait for
  801. *
  802. * Wait for vblank to occur on a given pipe. Needed for various bits of
  803. * mode setting code.
  804. */
  805. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  806. {
  807. struct drm_i915_private *dev_priv = dev->dev_private;
  808. int pipestat_reg = PIPESTAT(pipe);
  809. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
  810. g4x_wait_for_vblank(dev, pipe);
  811. return;
  812. }
  813. /* Clear existing vblank status. Note this will clear any other
  814. * sticky status fields as well.
  815. *
  816. * This races with i915_driver_irq_handler() with the result
  817. * that either function could miss a vblank event. Here it is not
  818. * fatal, as we will either wait upon the next vblank interrupt or
  819. * timeout. Generally speaking intel_wait_for_vblank() is only
  820. * called during modeset at which time the GPU should be idle and
  821. * should *not* be performing page flips and thus not waiting on
  822. * vblanks...
  823. * Currently, the result of us stealing a vblank from the irq
  824. * handler is that a single frame will be skipped during swapbuffers.
  825. */
  826. I915_WRITE(pipestat_reg,
  827. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  828. /* Wait for vblank interrupt bit to set */
  829. if (wait_for(I915_READ(pipestat_reg) &
  830. PIPE_VBLANK_INTERRUPT_STATUS,
  831. 50))
  832. DRM_DEBUG_KMS("vblank wait on pipe %c timed out\n",
  833. pipe_name(pipe));
  834. }
  835. static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe)
  836. {
  837. struct drm_i915_private *dev_priv = dev->dev_private;
  838. u32 reg = PIPEDSL(pipe);
  839. u32 line1, line2;
  840. u32 line_mask;
  841. if (IS_GEN2(dev))
  842. line_mask = DSL_LINEMASK_GEN2;
  843. else
  844. line_mask = DSL_LINEMASK_GEN3;
  845. line1 = I915_READ(reg) & line_mask;
  846. mdelay(5);
  847. line2 = I915_READ(reg) & line_mask;
  848. return line1 == line2;
  849. }
  850. /*
  851. * intel_wait_for_pipe_off - wait for pipe to turn off
  852. * @crtc: crtc whose pipe to wait for
  853. *
  854. * After disabling a pipe, we can't wait for vblank in the usual way,
  855. * spinning on the vblank interrupt status bit, since we won't actually
  856. * see an interrupt when the pipe is disabled.
  857. *
  858. * On Gen4 and above:
  859. * wait for the pipe register state bit to turn off
  860. *
  861. * Otherwise:
  862. * wait for the display line value to settle (it usually
  863. * ends up stopping at the start of the next frame).
  864. *
  865. */
  866. static void intel_wait_for_pipe_off(struct intel_crtc *crtc)
  867. {
  868. struct drm_device *dev = crtc->base.dev;
  869. struct drm_i915_private *dev_priv = dev->dev_private;
  870. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  871. enum pipe pipe = crtc->pipe;
  872. if (INTEL_INFO(dev)->gen >= 4) {
  873. int reg = PIPECONF(cpu_transcoder);
  874. /* Wait for the Pipe State to go off */
  875. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  876. 100))
  877. WARN(1, "pipe_off wait timed out\n");
  878. } else {
  879. /* Wait for the display line to settle */
  880. if (wait_for(pipe_dsl_stopped(dev, pipe), 100))
  881. WARN(1, "pipe_off wait timed out\n");
  882. }
  883. }
  884. /*
  885. * ibx_digital_port_connected - is the specified port connected?
  886. * @dev_priv: i915 private structure
  887. * @port: the port to test
  888. *
  889. * Returns true if @port is connected, false otherwise.
  890. */
  891. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  892. struct intel_digital_port *port)
  893. {
  894. u32 bit;
  895. if (HAS_PCH_IBX(dev_priv->dev)) {
  896. switch (port->port) {
  897. case PORT_B:
  898. bit = SDE_PORTB_HOTPLUG;
  899. break;
  900. case PORT_C:
  901. bit = SDE_PORTC_HOTPLUG;
  902. break;
  903. case PORT_D:
  904. bit = SDE_PORTD_HOTPLUG;
  905. break;
  906. default:
  907. return true;
  908. }
  909. } else {
  910. switch (port->port) {
  911. case PORT_B:
  912. bit = SDE_PORTB_HOTPLUG_CPT;
  913. break;
  914. case PORT_C:
  915. bit = SDE_PORTC_HOTPLUG_CPT;
  916. break;
  917. case PORT_D:
  918. bit = SDE_PORTD_HOTPLUG_CPT;
  919. break;
  920. default:
  921. return true;
  922. }
  923. }
  924. return I915_READ(SDEISR) & bit;
  925. }
  926. static const char *state_string(bool enabled)
  927. {
  928. return enabled ? "on" : "off";
  929. }
  930. /* Only for pre-ILK configs */
  931. void assert_pll(struct drm_i915_private *dev_priv,
  932. enum pipe pipe, bool state)
  933. {
  934. int reg;
  935. u32 val;
  936. bool cur_state;
  937. reg = DPLL(pipe);
  938. val = I915_READ(reg);
  939. cur_state = !!(val & DPLL_VCO_ENABLE);
  940. WARN(cur_state != state,
  941. "PLL state assertion failure (expected %s, current %s)\n",
  942. state_string(state), state_string(cur_state));
  943. }
  944. /* XXX: the dsi pll is shared between MIPI DSI ports */
  945. static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
  946. {
  947. u32 val;
  948. bool cur_state;
  949. mutex_lock(&dev_priv->dpio_lock);
  950. val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
  951. mutex_unlock(&dev_priv->dpio_lock);
  952. cur_state = val & DSI_PLL_VCO_EN;
  953. WARN(cur_state != state,
  954. "DSI PLL state assertion failure (expected %s, current %s)\n",
  955. state_string(state), state_string(cur_state));
  956. }
  957. #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true)
  958. #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false)
  959. struct intel_shared_dpll *
  960. intel_crtc_to_shared_dpll(struct intel_crtc *crtc)
  961. {
  962. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  963. if (crtc->config.shared_dpll < 0)
  964. return NULL;
  965. return &dev_priv->shared_dplls[crtc->config.shared_dpll];
  966. }
  967. /* For ILK+ */
  968. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  969. struct intel_shared_dpll *pll,
  970. bool state)
  971. {
  972. bool cur_state;
  973. struct intel_dpll_hw_state hw_state;
  974. if (WARN (!pll,
  975. "asserting DPLL %s with no DPLL\n", state_string(state)))
  976. return;
  977. cur_state = pll->get_hw_state(dev_priv, pll, &hw_state);
  978. WARN(cur_state != state,
  979. "%s assertion failure (expected %s, current %s)\n",
  980. pll->name, state_string(state), state_string(cur_state));
  981. }
  982. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  983. enum pipe pipe, bool state)
  984. {
  985. int reg;
  986. u32 val;
  987. bool cur_state;
  988. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  989. pipe);
  990. if (HAS_DDI(dev_priv->dev)) {
  991. /* DDI does not have a specific FDI_TX register */
  992. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  993. val = I915_READ(reg);
  994. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  995. } else {
  996. reg = FDI_TX_CTL(pipe);
  997. val = I915_READ(reg);
  998. cur_state = !!(val & FDI_TX_ENABLE);
  999. }
  1000. WARN(cur_state != state,
  1001. "FDI TX state assertion failure (expected %s, current %s)\n",
  1002. state_string(state), state_string(cur_state));
  1003. }
  1004. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1005. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1006. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1007. enum pipe pipe, bool state)
  1008. {
  1009. int reg;
  1010. u32 val;
  1011. bool cur_state;
  1012. reg = FDI_RX_CTL(pipe);
  1013. val = I915_READ(reg);
  1014. cur_state = !!(val & FDI_RX_ENABLE);
  1015. WARN(cur_state != state,
  1016. "FDI RX state assertion failure (expected %s, current %s)\n",
  1017. state_string(state), state_string(cur_state));
  1018. }
  1019. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1020. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1021. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1022. enum pipe pipe)
  1023. {
  1024. int reg;
  1025. u32 val;
  1026. /* ILK FDI PLL is always enabled */
  1027. if (INTEL_INFO(dev_priv->dev)->gen == 5)
  1028. return;
  1029. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1030. if (HAS_DDI(dev_priv->dev))
  1031. return;
  1032. reg = FDI_TX_CTL(pipe);
  1033. val = I915_READ(reg);
  1034. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1035. }
  1036. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  1037. enum pipe pipe, bool state)
  1038. {
  1039. int reg;
  1040. u32 val;
  1041. bool cur_state;
  1042. reg = FDI_RX_CTL(pipe);
  1043. val = I915_READ(reg);
  1044. cur_state = !!(val & FDI_RX_PLL_ENABLE);
  1045. WARN(cur_state != state,
  1046. "FDI RX PLL assertion failure (expected %s, current %s)\n",
  1047. state_string(state), state_string(cur_state));
  1048. }
  1049. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1050. enum pipe pipe)
  1051. {
  1052. struct drm_device *dev = dev_priv->dev;
  1053. int pp_reg;
  1054. u32 val;
  1055. enum pipe panel_pipe = PIPE_A;
  1056. bool locked = true;
  1057. if (WARN_ON(HAS_DDI(dev)))
  1058. return;
  1059. if (HAS_PCH_SPLIT(dev)) {
  1060. u32 port_sel;
  1061. pp_reg = PCH_PP_CONTROL;
  1062. port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK;
  1063. if (port_sel == PANEL_PORT_SELECT_LVDS &&
  1064. I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT)
  1065. panel_pipe = PIPE_B;
  1066. /* XXX: else fix for eDP */
  1067. } else if (IS_VALLEYVIEW(dev)) {
  1068. /* presumably write lock depends on pipe, not port select */
  1069. pp_reg = VLV_PIPE_PP_CONTROL(pipe);
  1070. panel_pipe = pipe;
  1071. } else {
  1072. pp_reg = PP_CONTROL;
  1073. if (I915_READ(LVDS) & LVDS_PIPEB_SELECT)
  1074. panel_pipe = PIPE_B;
  1075. }
  1076. val = I915_READ(pp_reg);
  1077. if (!(val & PANEL_POWER_ON) ||
  1078. ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
  1079. locked = false;
  1080. WARN(panel_pipe == pipe && locked,
  1081. "panel assertion failure, pipe %c regs locked\n",
  1082. pipe_name(pipe));
  1083. }
  1084. static void assert_cursor(struct drm_i915_private *dev_priv,
  1085. enum pipe pipe, bool state)
  1086. {
  1087. struct drm_device *dev = dev_priv->dev;
  1088. bool cur_state;
  1089. if (IS_845G(dev) || IS_I865G(dev))
  1090. cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
  1091. else
  1092. cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
  1093. WARN(cur_state != state,
  1094. "cursor on pipe %c assertion failure (expected %s, current %s)\n",
  1095. pipe_name(pipe), state_string(state), state_string(cur_state));
  1096. }
  1097. #define assert_cursor_enabled(d, p) assert_cursor(d, p, true)
  1098. #define assert_cursor_disabled(d, p) assert_cursor(d, p, false)
  1099. void assert_pipe(struct drm_i915_private *dev_priv,
  1100. enum pipe pipe, bool state)
  1101. {
  1102. int reg;
  1103. u32 val;
  1104. bool cur_state;
  1105. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1106. pipe);
  1107. /* if we need the pipe quirk it must be always on */
  1108. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1109. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1110. state = true;
  1111. if (!intel_display_power_enabled(dev_priv,
  1112. POWER_DOMAIN_TRANSCODER(cpu_transcoder))) {
  1113. cur_state = false;
  1114. } else {
  1115. reg = PIPECONF(cpu_transcoder);
  1116. val = I915_READ(reg);
  1117. cur_state = !!(val & PIPECONF_ENABLE);
  1118. }
  1119. WARN(cur_state != state,
  1120. "pipe %c assertion failure (expected %s, current %s)\n",
  1121. pipe_name(pipe), state_string(state), state_string(cur_state));
  1122. }
  1123. static void assert_plane(struct drm_i915_private *dev_priv,
  1124. enum plane plane, bool state)
  1125. {
  1126. int reg;
  1127. u32 val;
  1128. bool cur_state;
  1129. reg = DSPCNTR(plane);
  1130. val = I915_READ(reg);
  1131. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1132. WARN(cur_state != state,
  1133. "plane %c assertion failure (expected %s, current %s)\n",
  1134. plane_name(plane), state_string(state), state_string(cur_state));
  1135. }
  1136. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1137. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1138. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1139. enum pipe pipe)
  1140. {
  1141. struct drm_device *dev = dev_priv->dev;
  1142. int reg, i;
  1143. u32 val;
  1144. int cur_pipe;
  1145. /* Primary planes are fixed to pipes on gen4+ */
  1146. if (INTEL_INFO(dev)->gen >= 4) {
  1147. reg = DSPCNTR(pipe);
  1148. val = I915_READ(reg);
  1149. WARN(val & DISPLAY_PLANE_ENABLE,
  1150. "plane %c assertion failure, should be disabled but not\n",
  1151. plane_name(pipe));
  1152. return;
  1153. }
  1154. /* Need to check both planes against the pipe */
  1155. for_each_pipe(dev_priv, i) {
  1156. reg = DSPCNTR(i);
  1157. val = I915_READ(reg);
  1158. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1159. DISPPLANE_SEL_PIPE_SHIFT;
  1160. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1161. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1162. plane_name(i), pipe_name(pipe));
  1163. }
  1164. }
  1165. static void assert_sprites_disabled(struct drm_i915_private *dev_priv,
  1166. enum pipe pipe)
  1167. {
  1168. struct drm_device *dev = dev_priv->dev;
  1169. int reg, sprite;
  1170. u32 val;
  1171. if (IS_VALLEYVIEW(dev)) {
  1172. for_each_sprite(pipe, sprite) {
  1173. reg = SPCNTR(pipe, sprite);
  1174. val = I915_READ(reg);
  1175. WARN(val & SP_ENABLE,
  1176. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1177. sprite_name(pipe, sprite), pipe_name(pipe));
  1178. }
  1179. } else if (INTEL_INFO(dev)->gen >= 7) {
  1180. reg = SPRCTL(pipe);
  1181. val = I915_READ(reg);
  1182. WARN(val & SPRITE_ENABLE,
  1183. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1184. plane_name(pipe), pipe_name(pipe));
  1185. } else if (INTEL_INFO(dev)->gen >= 5) {
  1186. reg = DVSCNTR(pipe);
  1187. val = I915_READ(reg);
  1188. WARN(val & DVS_ENABLE,
  1189. "sprite %c assertion failure, should be off on pipe %c but is still active\n",
  1190. plane_name(pipe), pipe_name(pipe));
  1191. }
  1192. }
  1193. static void assert_vblank_disabled(struct drm_crtc *crtc)
  1194. {
  1195. if (WARN_ON(drm_crtc_vblank_get(crtc) == 0))
  1196. drm_crtc_vblank_put(crtc);
  1197. }
  1198. static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1199. {
  1200. u32 val;
  1201. bool enabled;
  1202. WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev)));
  1203. val = I915_READ(PCH_DREF_CONTROL);
  1204. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1205. DREF_SUPERSPREAD_SOURCE_MASK));
  1206. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1207. }
  1208. static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
  1209. enum pipe pipe)
  1210. {
  1211. int reg;
  1212. u32 val;
  1213. bool enabled;
  1214. reg = PCH_TRANSCONF(pipe);
  1215. val = I915_READ(reg);
  1216. enabled = !!(val & TRANS_ENABLE);
  1217. WARN(enabled,
  1218. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1219. pipe_name(pipe));
  1220. }
  1221. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1222. enum pipe pipe, u32 port_sel, u32 val)
  1223. {
  1224. if ((val & DP_PORT_EN) == 0)
  1225. return false;
  1226. if (HAS_PCH_CPT(dev_priv->dev)) {
  1227. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1228. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1229. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1230. return false;
  1231. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1232. if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe))
  1233. return false;
  1234. } else {
  1235. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1236. return false;
  1237. }
  1238. return true;
  1239. }
  1240. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1241. enum pipe pipe, u32 val)
  1242. {
  1243. if ((val & SDVO_ENABLE) == 0)
  1244. return false;
  1245. if (HAS_PCH_CPT(dev_priv->dev)) {
  1246. if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe))
  1247. return false;
  1248. } else if (IS_CHERRYVIEW(dev_priv->dev)) {
  1249. if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe))
  1250. return false;
  1251. } else {
  1252. if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe))
  1253. return false;
  1254. }
  1255. return true;
  1256. }
  1257. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1258. enum pipe pipe, u32 val)
  1259. {
  1260. if ((val & LVDS_PORT_EN) == 0)
  1261. return false;
  1262. if (HAS_PCH_CPT(dev_priv->dev)) {
  1263. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1264. return false;
  1265. } else {
  1266. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1267. return false;
  1268. }
  1269. return true;
  1270. }
  1271. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1272. enum pipe pipe, u32 val)
  1273. {
  1274. if ((val & ADPA_DAC_ENABLE) == 0)
  1275. return false;
  1276. if (HAS_PCH_CPT(dev_priv->dev)) {
  1277. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1278. return false;
  1279. } else {
  1280. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1281. return false;
  1282. }
  1283. return true;
  1284. }
  1285. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1286. enum pipe pipe, int reg, u32 port_sel)
  1287. {
  1288. u32 val = I915_READ(reg);
  1289. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1290. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1291. reg, pipe_name(pipe));
  1292. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1293. && (val & DP_PIPEB_SELECT),
  1294. "IBX PCH dp port still using transcoder B\n");
  1295. }
  1296. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1297. enum pipe pipe, int reg)
  1298. {
  1299. u32 val = I915_READ(reg);
  1300. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1301. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1302. reg, pipe_name(pipe));
  1303. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0
  1304. && (val & SDVO_PIPE_B_SELECT),
  1305. "IBX PCH hdmi port still using transcoder B\n");
  1306. }
  1307. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1308. enum pipe pipe)
  1309. {
  1310. int reg;
  1311. u32 val;
  1312. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1313. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1314. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1315. reg = PCH_ADPA;
  1316. val = I915_READ(reg);
  1317. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1318. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1319. pipe_name(pipe));
  1320. reg = PCH_LVDS;
  1321. val = I915_READ(reg);
  1322. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1323. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1324. pipe_name(pipe));
  1325. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB);
  1326. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC);
  1327. assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID);
  1328. }
  1329. static void intel_init_dpio(struct drm_device *dev)
  1330. {
  1331. struct drm_i915_private *dev_priv = dev->dev_private;
  1332. if (!IS_VALLEYVIEW(dev))
  1333. return;
  1334. /*
  1335. * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C),
  1336. * CHV x1 PHY (DP/HDMI D)
  1337. * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C)
  1338. */
  1339. if (IS_CHERRYVIEW(dev)) {
  1340. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2;
  1341. DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO;
  1342. } else {
  1343. DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO;
  1344. }
  1345. }
  1346. static void vlv_enable_pll(struct intel_crtc *crtc)
  1347. {
  1348. struct drm_device *dev = crtc->base.dev;
  1349. struct drm_i915_private *dev_priv = dev->dev_private;
  1350. int reg = DPLL(crtc->pipe);
  1351. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1352. assert_pipe_disabled(dev_priv, crtc->pipe);
  1353. /* No really, not for ILK+ */
  1354. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev));
  1355. /* PLL is protected by panel, make sure we can write it */
  1356. if (IS_MOBILE(dev_priv->dev))
  1357. assert_panel_unlocked(dev_priv, crtc->pipe);
  1358. I915_WRITE(reg, dpll);
  1359. POSTING_READ(reg);
  1360. udelay(150);
  1361. if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1362. DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe);
  1363. I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md);
  1364. POSTING_READ(DPLL_MD(crtc->pipe));
  1365. /* We do this three times for luck */
  1366. I915_WRITE(reg, dpll);
  1367. POSTING_READ(reg);
  1368. udelay(150); /* wait for warmup */
  1369. I915_WRITE(reg, dpll);
  1370. POSTING_READ(reg);
  1371. udelay(150); /* wait for warmup */
  1372. I915_WRITE(reg, dpll);
  1373. POSTING_READ(reg);
  1374. udelay(150); /* wait for warmup */
  1375. }
  1376. static void chv_enable_pll(struct intel_crtc *crtc)
  1377. {
  1378. struct drm_device *dev = crtc->base.dev;
  1379. struct drm_i915_private *dev_priv = dev->dev_private;
  1380. int pipe = crtc->pipe;
  1381. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1382. u32 tmp;
  1383. assert_pipe_disabled(dev_priv, crtc->pipe);
  1384. BUG_ON(!IS_CHERRYVIEW(dev_priv->dev));
  1385. mutex_lock(&dev_priv->dpio_lock);
  1386. /* Enable back the 10bit clock to display controller */
  1387. tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1388. tmp |= DPIO_DCLKP_EN;
  1389. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
  1390. /*
  1391. * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
  1392. */
  1393. udelay(1);
  1394. /* Enable PLL */
  1395. I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll);
  1396. /* Check PLL is locked */
  1397. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  1398. DRM_ERROR("PLL %d failed to lock\n", pipe);
  1399. /* not sure when this should be written */
  1400. I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md);
  1401. POSTING_READ(DPLL_MD(pipe));
  1402. mutex_unlock(&dev_priv->dpio_lock);
  1403. }
  1404. static int intel_num_dvo_pipes(struct drm_device *dev)
  1405. {
  1406. struct intel_crtc *crtc;
  1407. int count = 0;
  1408. for_each_intel_crtc(dev, crtc)
  1409. count += crtc->active &&
  1410. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO);
  1411. return count;
  1412. }
  1413. static void i9xx_enable_pll(struct intel_crtc *crtc)
  1414. {
  1415. struct drm_device *dev = crtc->base.dev;
  1416. struct drm_i915_private *dev_priv = dev->dev_private;
  1417. int reg = DPLL(crtc->pipe);
  1418. u32 dpll = crtc->config.dpll_hw_state.dpll;
  1419. assert_pipe_disabled(dev_priv, crtc->pipe);
  1420. /* No really, not for ILK+ */
  1421. BUG_ON(INTEL_INFO(dev)->gen >= 5);
  1422. /* PLL is protected by panel, make sure we can write it */
  1423. if (IS_MOBILE(dev) && !IS_I830(dev))
  1424. assert_panel_unlocked(dev_priv, crtc->pipe);
  1425. /* Enable DVO 2x clock on both PLLs if necessary */
  1426. if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) {
  1427. /*
  1428. * It appears to be important that we don't enable this
  1429. * for the current pipe before otherwise configuring the
  1430. * PLL. No idea how this should be handled if multiple
  1431. * DVO outputs are enabled simultaneosly.
  1432. */
  1433. dpll |= DPLL_DVO_2X_MODE;
  1434. I915_WRITE(DPLL(!crtc->pipe),
  1435. I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
  1436. }
  1437. /* Wait for the clocks to stabilize. */
  1438. POSTING_READ(reg);
  1439. udelay(150);
  1440. if (INTEL_INFO(dev)->gen >= 4) {
  1441. I915_WRITE(DPLL_MD(crtc->pipe),
  1442. crtc->config.dpll_hw_state.dpll_md);
  1443. } else {
  1444. /* The pixel multiplier can only be updated once the
  1445. * DPLL is enabled and the clocks are stable.
  1446. *
  1447. * So write it again.
  1448. */
  1449. I915_WRITE(reg, dpll);
  1450. }
  1451. /* We do this three times for luck */
  1452. I915_WRITE(reg, dpll);
  1453. POSTING_READ(reg);
  1454. udelay(150); /* wait for warmup */
  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. }
  1462. /**
  1463. * i9xx_disable_pll - disable a PLL
  1464. * @dev_priv: i915 private structure
  1465. * @pipe: pipe PLL to disable
  1466. *
  1467. * Disable the PLL for @pipe, making sure the pipe is off first.
  1468. *
  1469. * Note! This is for pre-ILK only.
  1470. */
  1471. static void i9xx_disable_pll(struct intel_crtc *crtc)
  1472. {
  1473. struct drm_device *dev = crtc->base.dev;
  1474. struct drm_i915_private *dev_priv = dev->dev_private;
  1475. enum pipe pipe = crtc->pipe;
  1476. /* Disable DVO 2x clock on both PLLs if necessary */
  1477. if (IS_I830(dev) &&
  1478. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO) &&
  1479. intel_num_dvo_pipes(dev) == 1) {
  1480. I915_WRITE(DPLL(PIPE_B),
  1481. I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
  1482. I915_WRITE(DPLL(PIPE_A),
  1483. I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
  1484. }
  1485. /* Don't disable pipe or pipe PLLs if needed */
  1486. if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1487. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1488. return;
  1489. /* Make sure the pipe isn't still relying on us */
  1490. assert_pipe_disabled(dev_priv, pipe);
  1491. I915_WRITE(DPLL(pipe), 0);
  1492. POSTING_READ(DPLL(pipe));
  1493. }
  1494. static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1495. {
  1496. u32 val = 0;
  1497. /* Make sure the pipe isn't still relying on us */
  1498. assert_pipe_disabled(dev_priv, pipe);
  1499. /*
  1500. * Leave integrated clock source and reference clock enabled for pipe B.
  1501. * The latter is needed for VGA hotplug / manual detection.
  1502. */
  1503. if (pipe == PIPE_B)
  1504. val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV;
  1505. I915_WRITE(DPLL(pipe), val);
  1506. POSTING_READ(DPLL(pipe));
  1507. }
  1508. static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1509. {
  1510. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  1511. u32 val;
  1512. /* Make sure the pipe isn't still relying on us */
  1513. assert_pipe_disabled(dev_priv, pipe);
  1514. /* Set PLL en = 0 */
  1515. val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV;
  1516. if (pipe != PIPE_A)
  1517. val |= DPLL_INTEGRATED_CRI_CLK_VLV;
  1518. I915_WRITE(DPLL(pipe), val);
  1519. POSTING_READ(DPLL(pipe));
  1520. mutex_lock(&dev_priv->dpio_lock);
  1521. /* Disable 10bit clock to display controller */
  1522. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
  1523. val &= ~DPIO_DCLKP_EN;
  1524. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
  1525. /* disable left/right clock distribution */
  1526. if (pipe != PIPE_B) {
  1527. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1528. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1529. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1530. } else {
  1531. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1532. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1533. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1534. }
  1535. mutex_unlock(&dev_priv->dpio_lock);
  1536. }
  1537. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  1538. struct intel_digital_port *dport)
  1539. {
  1540. u32 port_mask;
  1541. int dpll_reg;
  1542. switch (dport->port) {
  1543. case PORT_B:
  1544. port_mask = DPLL_PORTB_READY_MASK;
  1545. dpll_reg = DPLL(0);
  1546. break;
  1547. case PORT_C:
  1548. port_mask = DPLL_PORTC_READY_MASK;
  1549. dpll_reg = DPLL(0);
  1550. break;
  1551. case PORT_D:
  1552. port_mask = DPLL_PORTD_READY_MASK;
  1553. dpll_reg = DPIO_PHY_STATUS;
  1554. break;
  1555. default:
  1556. BUG();
  1557. }
  1558. if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000))
  1559. WARN(1, "timed out waiting for port %c ready: 0x%08x\n",
  1560. port_name(dport->port), I915_READ(dpll_reg));
  1561. }
  1562. static void intel_prepare_shared_dpll(struct intel_crtc *crtc)
  1563. {
  1564. struct drm_device *dev = crtc->base.dev;
  1565. struct drm_i915_private *dev_priv = dev->dev_private;
  1566. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1567. if (WARN_ON(pll == NULL))
  1568. return;
  1569. WARN_ON(!pll->refcount);
  1570. if (pll->active == 0) {
  1571. DRM_DEBUG_DRIVER("setting up %s\n", pll->name);
  1572. WARN_ON(pll->on);
  1573. assert_shared_dpll_disabled(dev_priv, pll);
  1574. pll->mode_set(dev_priv, pll);
  1575. }
  1576. }
  1577. /**
  1578. * intel_enable_shared_dpll - enable PCH PLL
  1579. * @dev_priv: i915 private structure
  1580. * @pipe: pipe PLL to enable
  1581. *
  1582. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1583. * drives the transcoder clock.
  1584. */
  1585. static void intel_enable_shared_dpll(struct intel_crtc *crtc)
  1586. {
  1587. struct drm_device *dev = crtc->base.dev;
  1588. struct drm_i915_private *dev_priv = dev->dev_private;
  1589. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1590. if (WARN_ON(pll == NULL))
  1591. return;
  1592. if (WARN_ON(pll->refcount == 0))
  1593. return;
  1594. DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n",
  1595. pll->name, pll->active, pll->on,
  1596. crtc->base.base.id);
  1597. if (pll->active++) {
  1598. WARN_ON(!pll->on);
  1599. assert_shared_dpll_enabled(dev_priv, pll);
  1600. return;
  1601. }
  1602. WARN_ON(pll->on);
  1603. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  1604. DRM_DEBUG_KMS("enabling %s\n", pll->name);
  1605. pll->enable(dev_priv, pll);
  1606. pll->on = true;
  1607. }
  1608. static void intel_disable_shared_dpll(struct intel_crtc *crtc)
  1609. {
  1610. struct drm_device *dev = crtc->base.dev;
  1611. struct drm_i915_private *dev_priv = dev->dev_private;
  1612. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  1613. /* PCH only available on ILK+ */
  1614. BUG_ON(INTEL_INFO(dev)->gen < 5);
  1615. if (WARN_ON(pll == NULL))
  1616. return;
  1617. if (WARN_ON(pll->refcount == 0))
  1618. return;
  1619. DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n",
  1620. pll->name, pll->active, pll->on,
  1621. crtc->base.base.id);
  1622. if (WARN_ON(pll->active == 0)) {
  1623. assert_shared_dpll_disabled(dev_priv, pll);
  1624. return;
  1625. }
  1626. assert_shared_dpll_enabled(dev_priv, pll);
  1627. WARN_ON(!pll->on);
  1628. if (--pll->active)
  1629. return;
  1630. DRM_DEBUG_KMS("disabling %s\n", pll->name);
  1631. pll->disable(dev_priv, pll);
  1632. pll->on = false;
  1633. intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS);
  1634. }
  1635. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1636. enum pipe pipe)
  1637. {
  1638. struct drm_device *dev = dev_priv->dev;
  1639. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1640. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1641. uint32_t reg, val, pipeconf_val;
  1642. /* PCH only available on ILK+ */
  1643. BUG_ON(!HAS_PCH_SPLIT(dev));
  1644. /* Make sure PCH DPLL is enabled */
  1645. assert_shared_dpll_enabled(dev_priv,
  1646. intel_crtc_to_shared_dpll(intel_crtc));
  1647. /* FDI must be feeding us bits for PCH ports */
  1648. assert_fdi_tx_enabled(dev_priv, pipe);
  1649. assert_fdi_rx_enabled(dev_priv, pipe);
  1650. if (HAS_PCH_CPT(dev)) {
  1651. /* Workaround: Set the timing override bit before enabling the
  1652. * pch transcoder. */
  1653. reg = TRANS_CHICKEN2(pipe);
  1654. val = I915_READ(reg);
  1655. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1656. I915_WRITE(reg, val);
  1657. }
  1658. reg = PCH_TRANSCONF(pipe);
  1659. val = I915_READ(reg);
  1660. pipeconf_val = I915_READ(PIPECONF(pipe));
  1661. if (HAS_PCH_IBX(dev_priv->dev)) {
  1662. /*
  1663. * make the BPC in transcoder be consistent with
  1664. * that in pipeconf reg.
  1665. */
  1666. val &= ~PIPECONF_BPC_MASK;
  1667. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1668. }
  1669. val &= ~TRANS_INTERLACE_MASK;
  1670. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1671. if (HAS_PCH_IBX(dev_priv->dev) &&
  1672. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1673. val |= TRANS_LEGACY_INTERLACED_ILK;
  1674. else
  1675. val |= TRANS_INTERLACED;
  1676. else
  1677. val |= TRANS_PROGRESSIVE;
  1678. I915_WRITE(reg, val | TRANS_ENABLE);
  1679. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1680. DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
  1681. }
  1682. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1683. enum transcoder cpu_transcoder)
  1684. {
  1685. u32 val, pipeconf_val;
  1686. /* PCH only available on ILK+ */
  1687. BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev));
  1688. /* FDI must be feeding us bits for PCH ports */
  1689. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1690. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1691. /* Workaround: set timing override bit. */
  1692. val = I915_READ(_TRANSA_CHICKEN2);
  1693. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1694. I915_WRITE(_TRANSA_CHICKEN2, val);
  1695. val = TRANS_ENABLE;
  1696. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1697. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1698. PIPECONF_INTERLACED_ILK)
  1699. val |= TRANS_INTERLACED;
  1700. else
  1701. val |= TRANS_PROGRESSIVE;
  1702. I915_WRITE(LPT_TRANSCONF, val);
  1703. if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100))
  1704. DRM_ERROR("Failed to enable PCH transcoder\n");
  1705. }
  1706. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1707. enum pipe pipe)
  1708. {
  1709. struct drm_device *dev = dev_priv->dev;
  1710. uint32_t reg, val;
  1711. /* FDI relies on the transcoder */
  1712. assert_fdi_tx_disabled(dev_priv, pipe);
  1713. assert_fdi_rx_disabled(dev_priv, pipe);
  1714. /* Ports must be off as well */
  1715. assert_pch_ports_disabled(dev_priv, pipe);
  1716. reg = PCH_TRANSCONF(pipe);
  1717. val = I915_READ(reg);
  1718. val &= ~TRANS_ENABLE;
  1719. I915_WRITE(reg, val);
  1720. /* wait for PCH transcoder off, transcoder state */
  1721. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1722. DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
  1723. if (!HAS_PCH_IBX(dev)) {
  1724. /* Workaround: Clear the timing override chicken bit again. */
  1725. reg = TRANS_CHICKEN2(pipe);
  1726. val = I915_READ(reg);
  1727. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1728. I915_WRITE(reg, val);
  1729. }
  1730. }
  1731. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1732. {
  1733. u32 val;
  1734. val = I915_READ(LPT_TRANSCONF);
  1735. val &= ~TRANS_ENABLE;
  1736. I915_WRITE(LPT_TRANSCONF, val);
  1737. /* wait for PCH transcoder off, transcoder state */
  1738. if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50))
  1739. DRM_ERROR("Failed to disable PCH transcoder\n");
  1740. /* Workaround: clear timing override bit. */
  1741. val = I915_READ(_TRANSA_CHICKEN2);
  1742. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1743. I915_WRITE(_TRANSA_CHICKEN2, val);
  1744. }
  1745. /**
  1746. * intel_enable_pipe - enable a pipe, asserting requirements
  1747. * @crtc: crtc responsible for the pipe
  1748. *
  1749. * Enable @crtc's pipe, making sure that various hardware specific requirements
  1750. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1751. */
  1752. static void intel_enable_pipe(struct intel_crtc *crtc)
  1753. {
  1754. struct drm_device *dev = crtc->base.dev;
  1755. struct drm_i915_private *dev_priv = dev->dev_private;
  1756. enum pipe pipe = crtc->pipe;
  1757. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1758. pipe);
  1759. enum pipe pch_transcoder;
  1760. int reg;
  1761. u32 val;
  1762. assert_planes_disabled(dev_priv, pipe);
  1763. assert_cursor_disabled(dev_priv, pipe);
  1764. assert_sprites_disabled(dev_priv, pipe);
  1765. if (HAS_PCH_LPT(dev_priv->dev))
  1766. pch_transcoder = TRANSCODER_A;
  1767. else
  1768. pch_transcoder = pipe;
  1769. /*
  1770. * A pipe without a PLL won't actually be able to drive bits from
  1771. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1772. * need the check.
  1773. */
  1774. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1775. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI))
  1776. assert_dsi_pll_enabled(dev_priv);
  1777. else
  1778. assert_pll_enabled(dev_priv, pipe);
  1779. else {
  1780. if (crtc->config.has_pch_encoder) {
  1781. /* if driving the PCH, we need FDI enabled */
  1782. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1783. assert_fdi_tx_pll_enabled(dev_priv,
  1784. (enum pipe) cpu_transcoder);
  1785. }
  1786. /* FIXME: assert CPU port conditions for SNB+ */
  1787. }
  1788. reg = PIPECONF(cpu_transcoder);
  1789. val = I915_READ(reg);
  1790. if (val & PIPECONF_ENABLE) {
  1791. WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  1792. (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)));
  1793. return;
  1794. }
  1795. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1796. POSTING_READ(reg);
  1797. }
  1798. /**
  1799. * intel_disable_pipe - disable a pipe, asserting requirements
  1800. * @crtc: crtc whose pipes is to be disabled
  1801. *
  1802. * Disable the pipe of @crtc, making sure that various hardware
  1803. * specific requirements are met, if applicable, e.g. plane
  1804. * disabled, panel fitter off, etc.
  1805. *
  1806. * Will wait until the pipe has shut down before returning.
  1807. */
  1808. static void intel_disable_pipe(struct intel_crtc *crtc)
  1809. {
  1810. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  1811. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  1812. enum pipe pipe = crtc->pipe;
  1813. int reg;
  1814. u32 val;
  1815. /*
  1816. * Make sure planes won't keep trying to pump pixels to us,
  1817. * or we might hang the display.
  1818. */
  1819. assert_planes_disabled(dev_priv, pipe);
  1820. assert_cursor_disabled(dev_priv, pipe);
  1821. assert_sprites_disabled(dev_priv, pipe);
  1822. reg = PIPECONF(cpu_transcoder);
  1823. val = I915_READ(reg);
  1824. if ((val & PIPECONF_ENABLE) == 0)
  1825. return;
  1826. /*
  1827. * Double wide has implications for planes
  1828. * so best keep it disabled when not needed.
  1829. */
  1830. if (crtc->config.double_wide)
  1831. val &= ~PIPECONF_DOUBLE_WIDE;
  1832. /* Don't disable pipe or pipe PLLs if needed */
  1833. if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) &&
  1834. !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  1835. val &= ~PIPECONF_ENABLE;
  1836. I915_WRITE(reg, val);
  1837. if ((val & PIPECONF_ENABLE) == 0)
  1838. intel_wait_for_pipe_off(crtc);
  1839. }
  1840. /*
  1841. * Plane regs are double buffered, going from enabled->disabled needs a
  1842. * trigger in order to latch. The display address reg provides this.
  1843. */
  1844. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  1845. enum plane plane)
  1846. {
  1847. struct drm_device *dev = dev_priv->dev;
  1848. u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane);
  1849. I915_WRITE(reg, I915_READ(reg));
  1850. POSTING_READ(reg);
  1851. }
  1852. /**
  1853. * intel_enable_primary_hw_plane - enable the primary plane on a given pipe
  1854. * @plane: plane to be enabled
  1855. * @crtc: crtc for the plane
  1856. *
  1857. * Enable @plane on @crtc, making sure that the pipe is running first.
  1858. */
  1859. static void intel_enable_primary_hw_plane(struct drm_plane *plane,
  1860. struct drm_crtc *crtc)
  1861. {
  1862. struct drm_device *dev = plane->dev;
  1863. struct drm_i915_private *dev_priv = dev->dev_private;
  1864. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1865. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1866. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1867. if (intel_crtc->primary_enabled)
  1868. return;
  1869. intel_crtc->primary_enabled = true;
  1870. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1871. crtc->x, crtc->y);
  1872. /*
  1873. * BDW signals flip done immediately if the plane
  1874. * is disabled, even if the plane enable is already
  1875. * armed to occur at the next vblank :(
  1876. */
  1877. if (IS_BROADWELL(dev))
  1878. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1879. }
  1880. /**
  1881. * intel_disable_primary_hw_plane - disable the primary hardware plane
  1882. * @plane: plane to be disabled
  1883. * @crtc: crtc for the plane
  1884. *
  1885. * Disable @plane on @crtc, making sure that the pipe is running first.
  1886. */
  1887. static void intel_disable_primary_hw_plane(struct drm_plane *plane,
  1888. struct drm_crtc *crtc)
  1889. {
  1890. struct drm_device *dev = plane->dev;
  1891. struct drm_i915_private *dev_priv = dev->dev_private;
  1892. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1893. assert_pipe_enabled(dev_priv, intel_crtc->pipe);
  1894. if (!intel_crtc->primary_enabled)
  1895. return;
  1896. intel_crtc->primary_enabled = false;
  1897. dev_priv->display.update_primary_plane(crtc, plane->fb,
  1898. crtc->x, crtc->y);
  1899. }
  1900. static bool need_vtd_wa(struct drm_device *dev)
  1901. {
  1902. #ifdef CONFIG_INTEL_IOMMU
  1903. if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped)
  1904. return true;
  1905. #endif
  1906. return false;
  1907. }
  1908. static int intel_align_height(struct drm_device *dev, int height, bool tiled)
  1909. {
  1910. int tile_height;
  1911. tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1;
  1912. return ALIGN(height, tile_height);
  1913. }
  1914. int
  1915. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1916. struct drm_i915_gem_object *obj,
  1917. struct intel_engine_cs *pipelined)
  1918. {
  1919. struct drm_i915_private *dev_priv = dev->dev_private;
  1920. u32 alignment;
  1921. int ret;
  1922. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  1923. switch (obj->tiling_mode) {
  1924. case I915_TILING_NONE:
  1925. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1926. alignment = 128 * 1024;
  1927. else if (INTEL_INFO(dev)->gen >= 4)
  1928. alignment = 4 * 1024;
  1929. else
  1930. alignment = 64 * 1024;
  1931. break;
  1932. case I915_TILING_X:
  1933. /* pin() will align the object as required by fence */
  1934. alignment = 0;
  1935. break;
  1936. case I915_TILING_Y:
  1937. WARN(1, "Y tiled bo slipped through, driver bug!\n");
  1938. return -EINVAL;
  1939. default:
  1940. BUG();
  1941. }
  1942. /* Note that the w/a also requires 64 PTE of padding following the
  1943. * bo. We currently fill all unused PTE with the shadow page and so
  1944. * we should always have valid PTE following the scanout preventing
  1945. * the VT-d warning.
  1946. */
  1947. if (need_vtd_wa(dev) && alignment < 256 * 1024)
  1948. alignment = 256 * 1024;
  1949. /*
  1950. * Global gtt pte registers are special registers which actually forward
  1951. * writes to a chunk of system memory. Which means that there is no risk
  1952. * that the register values disappear as soon as we call
  1953. * intel_runtime_pm_put(), so it is correct to wrap only the
  1954. * pin/unpin/fence and not more.
  1955. */
  1956. intel_runtime_pm_get(dev_priv);
  1957. dev_priv->mm.interruptible = false;
  1958. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1959. if (ret)
  1960. goto err_interruptible;
  1961. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1962. * fence, whereas 965+ only requires a fence if using
  1963. * framebuffer compression. For simplicity, we always install
  1964. * a fence as the cost is not that onerous.
  1965. */
  1966. ret = i915_gem_object_get_fence(obj);
  1967. if (ret)
  1968. goto err_unpin;
  1969. i915_gem_object_pin_fence(obj);
  1970. dev_priv->mm.interruptible = true;
  1971. intel_runtime_pm_put(dev_priv);
  1972. return 0;
  1973. err_unpin:
  1974. i915_gem_object_unpin_from_display_plane(obj);
  1975. err_interruptible:
  1976. dev_priv->mm.interruptible = true;
  1977. intel_runtime_pm_put(dev_priv);
  1978. return ret;
  1979. }
  1980. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1981. {
  1982. WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex));
  1983. i915_gem_object_unpin_fence(obj);
  1984. i915_gem_object_unpin_from_display_plane(obj);
  1985. }
  1986. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1987. * is assumed to be a power-of-two. */
  1988. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  1989. unsigned int tiling_mode,
  1990. unsigned int cpp,
  1991. unsigned int pitch)
  1992. {
  1993. if (tiling_mode != I915_TILING_NONE) {
  1994. unsigned int tile_rows, tiles;
  1995. tile_rows = *y / 8;
  1996. *y %= 8;
  1997. tiles = *x / (512/cpp);
  1998. *x %= 512/cpp;
  1999. return tile_rows * pitch * 8 + tiles * 4096;
  2000. } else {
  2001. unsigned int offset;
  2002. offset = *y * pitch + *x * cpp;
  2003. *y = 0;
  2004. *x = (offset & 4095) / cpp;
  2005. return offset & -4096;
  2006. }
  2007. }
  2008. int intel_format_to_fourcc(int format)
  2009. {
  2010. switch (format) {
  2011. case DISPPLANE_8BPP:
  2012. return DRM_FORMAT_C8;
  2013. case DISPPLANE_BGRX555:
  2014. return DRM_FORMAT_XRGB1555;
  2015. case DISPPLANE_BGRX565:
  2016. return DRM_FORMAT_RGB565;
  2017. default:
  2018. case DISPPLANE_BGRX888:
  2019. return DRM_FORMAT_XRGB8888;
  2020. case DISPPLANE_RGBX888:
  2021. return DRM_FORMAT_XBGR8888;
  2022. case DISPPLANE_BGRX101010:
  2023. return DRM_FORMAT_XRGB2101010;
  2024. case DISPPLANE_RGBX101010:
  2025. return DRM_FORMAT_XBGR2101010;
  2026. }
  2027. }
  2028. static bool intel_alloc_plane_obj(struct intel_crtc *crtc,
  2029. struct intel_plane_config *plane_config)
  2030. {
  2031. struct drm_device *dev = crtc->base.dev;
  2032. struct drm_i915_gem_object *obj = NULL;
  2033. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  2034. u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
  2035. u32 size_aligned = round_up(plane_config->base + plane_config->size,
  2036. PAGE_SIZE);
  2037. size_aligned -= base_aligned;
  2038. if (plane_config->size == 0)
  2039. return false;
  2040. obj = i915_gem_object_create_stolen_for_preallocated(dev,
  2041. base_aligned,
  2042. base_aligned,
  2043. size_aligned);
  2044. if (!obj)
  2045. return false;
  2046. if (plane_config->tiled) {
  2047. obj->tiling_mode = I915_TILING_X;
  2048. obj->stride = crtc->base.primary->fb->pitches[0];
  2049. }
  2050. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2051. mode_cmd.width = crtc->base.primary->fb->width;
  2052. mode_cmd.height = crtc->base.primary->fb->height;
  2053. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2054. mutex_lock(&dev->struct_mutex);
  2055. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2056. &mode_cmd, obj)) {
  2057. DRM_DEBUG_KMS("intel fb init failed\n");
  2058. goto out_unref_obj;
  2059. }
  2060. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2061. mutex_unlock(&dev->struct_mutex);
  2062. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2063. return true;
  2064. out_unref_obj:
  2065. drm_gem_object_unreference(&obj->base);
  2066. mutex_unlock(&dev->struct_mutex);
  2067. return false;
  2068. }
  2069. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2070. struct intel_plane_config *plane_config)
  2071. {
  2072. struct drm_device *dev = intel_crtc->base.dev;
  2073. struct drm_crtc *c;
  2074. struct intel_crtc *i;
  2075. struct drm_i915_gem_object *obj;
  2076. if (!intel_crtc->base.primary->fb)
  2077. return;
  2078. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2079. return;
  2080. kfree(intel_crtc->base.primary->fb);
  2081. intel_crtc->base.primary->fb = NULL;
  2082. /*
  2083. * Failed to alloc the obj, check to see if we should share
  2084. * an fb with another CRTC instead
  2085. */
  2086. for_each_crtc(dev, c) {
  2087. i = to_intel_crtc(c);
  2088. if (c == &intel_crtc->base)
  2089. continue;
  2090. if (!i->active)
  2091. continue;
  2092. obj = intel_fb_obj(c->primary->fb);
  2093. if (obj == NULL)
  2094. continue;
  2095. if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
  2096. drm_framebuffer_reference(c->primary->fb);
  2097. intel_crtc->base.primary->fb = c->primary->fb;
  2098. obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2099. break;
  2100. }
  2101. }
  2102. }
  2103. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2104. struct drm_framebuffer *fb,
  2105. int x, int y)
  2106. {
  2107. struct drm_device *dev = crtc->dev;
  2108. struct drm_i915_private *dev_priv = dev->dev_private;
  2109. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2110. struct drm_i915_gem_object *obj;
  2111. int plane = intel_crtc->plane;
  2112. unsigned long linear_offset;
  2113. u32 dspcntr;
  2114. u32 reg = DSPCNTR(plane);
  2115. int pixel_size;
  2116. if (!intel_crtc->primary_enabled) {
  2117. I915_WRITE(reg, 0);
  2118. if (INTEL_INFO(dev)->gen >= 4)
  2119. I915_WRITE(DSPSURF(plane), 0);
  2120. else
  2121. I915_WRITE(DSPADDR(plane), 0);
  2122. POSTING_READ(reg);
  2123. return;
  2124. }
  2125. obj = intel_fb_obj(fb);
  2126. if (WARN_ON(obj == NULL))
  2127. return;
  2128. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2129. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2130. dspcntr |= DISPLAY_PLANE_ENABLE;
  2131. if (INTEL_INFO(dev)->gen < 4) {
  2132. if (intel_crtc->pipe == PIPE_B)
  2133. dspcntr |= DISPPLANE_SEL_PIPE_B;
  2134. /* pipesrc and dspsize control the size that is scaled from,
  2135. * which should always be the user's requested size.
  2136. */
  2137. I915_WRITE(DSPSIZE(plane),
  2138. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  2139. (intel_crtc->config.pipe_src_w - 1));
  2140. I915_WRITE(DSPPOS(plane), 0);
  2141. }
  2142. switch (fb->pixel_format) {
  2143. case DRM_FORMAT_C8:
  2144. dspcntr |= DISPPLANE_8BPP;
  2145. break;
  2146. case DRM_FORMAT_XRGB1555:
  2147. case DRM_FORMAT_ARGB1555:
  2148. dspcntr |= DISPPLANE_BGRX555;
  2149. break;
  2150. case DRM_FORMAT_RGB565:
  2151. dspcntr |= DISPPLANE_BGRX565;
  2152. break;
  2153. case DRM_FORMAT_XRGB8888:
  2154. case DRM_FORMAT_ARGB8888:
  2155. dspcntr |= DISPPLANE_BGRX888;
  2156. break;
  2157. case DRM_FORMAT_XBGR8888:
  2158. case DRM_FORMAT_ABGR8888:
  2159. dspcntr |= DISPPLANE_RGBX888;
  2160. break;
  2161. case DRM_FORMAT_XRGB2101010:
  2162. case DRM_FORMAT_ARGB2101010:
  2163. dspcntr |= DISPPLANE_BGRX101010;
  2164. break;
  2165. case DRM_FORMAT_XBGR2101010:
  2166. case DRM_FORMAT_ABGR2101010:
  2167. dspcntr |= DISPPLANE_RGBX101010;
  2168. break;
  2169. default:
  2170. BUG();
  2171. }
  2172. if (INTEL_INFO(dev)->gen >= 4 &&
  2173. obj->tiling_mode != I915_TILING_NONE)
  2174. dspcntr |= DISPPLANE_TILED;
  2175. if (IS_G4X(dev))
  2176. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2177. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2178. if (INTEL_INFO(dev)->gen >= 4) {
  2179. intel_crtc->dspaddr_offset =
  2180. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2181. pixel_size,
  2182. fb->pitches[0]);
  2183. linear_offset -= intel_crtc->dspaddr_offset;
  2184. } else {
  2185. intel_crtc->dspaddr_offset = linear_offset;
  2186. }
  2187. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2188. dspcntr |= DISPPLANE_ROTATE_180;
  2189. x += (intel_crtc->config.pipe_src_w - 1);
  2190. y += (intel_crtc->config.pipe_src_h - 1);
  2191. /* Finding the last pixel of the last line of the display
  2192. data and adding to linear_offset*/
  2193. linear_offset +=
  2194. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2195. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2196. }
  2197. I915_WRITE(reg, dspcntr);
  2198. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2199. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2200. fb->pitches[0]);
  2201. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2202. if (INTEL_INFO(dev)->gen >= 4) {
  2203. I915_WRITE(DSPSURF(plane),
  2204. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2205. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2206. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2207. } else
  2208. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2209. POSTING_READ(reg);
  2210. }
  2211. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2212. struct drm_framebuffer *fb,
  2213. int x, int y)
  2214. {
  2215. struct drm_device *dev = crtc->dev;
  2216. struct drm_i915_private *dev_priv = dev->dev_private;
  2217. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2218. struct drm_i915_gem_object *obj;
  2219. int plane = intel_crtc->plane;
  2220. unsigned long linear_offset;
  2221. u32 dspcntr;
  2222. u32 reg = DSPCNTR(plane);
  2223. int pixel_size;
  2224. if (!intel_crtc->primary_enabled) {
  2225. I915_WRITE(reg, 0);
  2226. I915_WRITE(DSPSURF(plane), 0);
  2227. POSTING_READ(reg);
  2228. return;
  2229. }
  2230. obj = intel_fb_obj(fb);
  2231. if (WARN_ON(obj == NULL))
  2232. return;
  2233. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2234. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2235. dspcntr |= DISPLAY_PLANE_ENABLE;
  2236. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2237. dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
  2238. switch (fb->pixel_format) {
  2239. case DRM_FORMAT_C8:
  2240. dspcntr |= DISPPLANE_8BPP;
  2241. break;
  2242. case DRM_FORMAT_RGB565:
  2243. dspcntr |= DISPPLANE_BGRX565;
  2244. break;
  2245. case DRM_FORMAT_XRGB8888:
  2246. case DRM_FORMAT_ARGB8888:
  2247. dspcntr |= DISPPLANE_BGRX888;
  2248. break;
  2249. case DRM_FORMAT_XBGR8888:
  2250. case DRM_FORMAT_ABGR8888:
  2251. dspcntr |= DISPPLANE_RGBX888;
  2252. break;
  2253. case DRM_FORMAT_XRGB2101010:
  2254. case DRM_FORMAT_ARGB2101010:
  2255. dspcntr |= DISPPLANE_BGRX101010;
  2256. break;
  2257. case DRM_FORMAT_XBGR2101010:
  2258. case DRM_FORMAT_ABGR2101010:
  2259. dspcntr |= DISPPLANE_RGBX101010;
  2260. break;
  2261. default:
  2262. BUG();
  2263. }
  2264. if (obj->tiling_mode != I915_TILING_NONE)
  2265. dspcntr |= DISPPLANE_TILED;
  2266. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
  2267. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2268. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2269. intel_crtc->dspaddr_offset =
  2270. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2271. pixel_size,
  2272. fb->pitches[0]);
  2273. linear_offset -= intel_crtc->dspaddr_offset;
  2274. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2275. dspcntr |= DISPPLANE_ROTATE_180;
  2276. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
  2277. x += (intel_crtc->config.pipe_src_w - 1);
  2278. y += (intel_crtc->config.pipe_src_h - 1);
  2279. /* Finding the last pixel of the last line of the display
  2280. data and adding to linear_offset*/
  2281. linear_offset +=
  2282. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2283. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2284. }
  2285. }
  2286. I915_WRITE(reg, dspcntr);
  2287. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2288. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2289. fb->pitches[0]);
  2290. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2291. I915_WRITE(DSPSURF(plane),
  2292. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2293. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2294. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2295. } else {
  2296. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2297. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2298. }
  2299. POSTING_READ(reg);
  2300. }
  2301. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2302. static int
  2303. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2304. int x, int y, enum mode_set_atomic state)
  2305. {
  2306. struct drm_device *dev = crtc->dev;
  2307. struct drm_i915_private *dev_priv = dev->dev_private;
  2308. if (dev_priv->display.disable_fbc)
  2309. dev_priv->display.disable_fbc(dev);
  2310. intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe);
  2311. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2312. return 0;
  2313. }
  2314. void intel_display_handle_reset(struct drm_device *dev)
  2315. {
  2316. struct drm_i915_private *dev_priv = dev->dev_private;
  2317. struct drm_crtc *crtc;
  2318. /*
  2319. * Flips in the rings have been nuked by the reset,
  2320. * so complete all pending flips so that user space
  2321. * will get its events and not get stuck.
  2322. *
  2323. * Also update the base address of all primary
  2324. * planes to the the last fb to make sure we're
  2325. * showing the correct fb after a reset.
  2326. *
  2327. * Need to make two loops over the crtcs so that we
  2328. * don't try to grab a crtc mutex before the
  2329. * pending_flip_queue really got woken up.
  2330. */
  2331. for_each_crtc(dev, crtc) {
  2332. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2333. enum plane plane = intel_crtc->plane;
  2334. intel_prepare_page_flip(dev, plane);
  2335. intel_finish_page_flip_plane(dev, plane);
  2336. }
  2337. for_each_crtc(dev, crtc) {
  2338. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2339. drm_modeset_lock(&crtc->mutex, NULL);
  2340. /*
  2341. * FIXME: Once we have proper support for primary planes (and
  2342. * disabling them without disabling the entire crtc) allow again
  2343. * a NULL crtc->primary->fb.
  2344. */
  2345. if (intel_crtc->active && crtc->primary->fb)
  2346. dev_priv->display.update_primary_plane(crtc,
  2347. crtc->primary->fb,
  2348. crtc->x,
  2349. crtc->y);
  2350. drm_modeset_unlock(&crtc->mutex);
  2351. }
  2352. }
  2353. static int
  2354. intel_finish_fb(struct drm_framebuffer *old_fb)
  2355. {
  2356. struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
  2357. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2358. bool was_interruptible = dev_priv->mm.interruptible;
  2359. int ret;
  2360. /* Big Hammer, we also need to ensure that any pending
  2361. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2362. * current scanout is retired before unpinning the old
  2363. * framebuffer.
  2364. *
  2365. * This should only fail upon a hung GPU, in which case we
  2366. * can safely continue.
  2367. */
  2368. dev_priv->mm.interruptible = false;
  2369. ret = i915_gem_object_finish_gpu(obj);
  2370. dev_priv->mm.interruptible = was_interruptible;
  2371. return ret;
  2372. }
  2373. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2374. {
  2375. struct drm_device *dev = crtc->dev;
  2376. struct drm_i915_private *dev_priv = dev->dev_private;
  2377. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2378. unsigned long flags;
  2379. bool pending;
  2380. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2381. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2382. return false;
  2383. spin_lock_irqsave(&dev->event_lock, flags);
  2384. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2385. spin_unlock_irqrestore(&dev->event_lock, flags);
  2386. return pending;
  2387. }
  2388. static int
  2389. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2390. struct drm_framebuffer *fb)
  2391. {
  2392. struct drm_device *dev = crtc->dev;
  2393. struct drm_i915_private *dev_priv = dev->dev_private;
  2394. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2395. enum pipe pipe = intel_crtc->pipe;
  2396. struct drm_framebuffer *old_fb = crtc->primary->fb;
  2397. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  2398. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  2399. int ret;
  2400. if (intel_crtc_has_pending_flip(crtc)) {
  2401. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2402. return -EBUSY;
  2403. }
  2404. /* no fb bound */
  2405. if (!fb) {
  2406. DRM_ERROR("No FB bound\n");
  2407. return 0;
  2408. }
  2409. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2410. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2411. plane_name(intel_crtc->plane),
  2412. INTEL_INFO(dev)->num_pipes);
  2413. return -EINVAL;
  2414. }
  2415. mutex_lock(&dev->struct_mutex);
  2416. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2417. if (ret == 0)
  2418. i915_gem_track_fb(old_obj, obj,
  2419. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2420. mutex_unlock(&dev->struct_mutex);
  2421. if (ret != 0) {
  2422. DRM_ERROR("pin & fence failed\n");
  2423. return ret;
  2424. }
  2425. /*
  2426. * Update pipe size and adjust fitter if needed: the reason for this is
  2427. * that in compute_mode_changes we check the native mode (not the pfit
  2428. * mode) to see if we can flip rather than do a full mode set. In the
  2429. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2430. * pfit state, we'll end up with a big fb scanned out into the wrong
  2431. * sized surface.
  2432. *
  2433. * To fix this properly, we need to hoist the checks up into
  2434. * compute_mode_changes (or above), check the actual pfit state and
  2435. * whether the platform allows pfit disable with pipe active, and only
  2436. * then update the pipesrc and pfit state, even on the flip path.
  2437. */
  2438. if (i915.fastboot) {
  2439. const struct drm_display_mode *adjusted_mode =
  2440. &intel_crtc->config.adjusted_mode;
  2441. I915_WRITE(PIPESRC(intel_crtc->pipe),
  2442. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2443. (adjusted_mode->crtc_vdisplay - 1));
  2444. if (!intel_crtc->config.pch_pfit.enabled &&
  2445. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2446. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2447. I915_WRITE(PF_CTL(intel_crtc->pipe), 0);
  2448. I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0);
  2449. I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0);
  2450. }
  2451. intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2452. intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2453. }
  2454. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2455. if (intel_crtc->active)
  2456. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2457. crtc->primary->fb = fb;
  2458. crtc->x = x;
  2459. crtc->y = y;
  2460. if (old_fb) {
  2461. if (intel_crtc->active && old_fb != fb)
  2462. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2463. mutex_lock(&dev->struct_mutex);
  2464. intel_unpin_fb_obj(old_obj);
  2465. mutex_unlock(&dev->struct_mutex);
  2466. }
  2467. mutex_lock(&dev->struct_mutex);
  2468. intel_update_fbc(dev);
  2469. mutex_unlock(&dev->struct_mutex);
  2470. return 0;
  2471. }
  2472. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2473. {
  2474. struct drm_device *dev = crtc->dev;
  2475. struct drm_i915_private *dev_priv = dev->dev_private;
  2476. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2477. int pipe = intel_crtc->pipe;
  2478. u32 reg, temp;
  2479. /* enable normal train */
  2480. reg = FDI_TX_CTL(pipe);
  2481. temp = I915_READ(reg);
  2482. if (IS_IVYBRIDGE(dev)) {
  2483. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2484. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2485. } else {
  2486. temp &= ~FDI_LINK_TRAIN_NONE;
  2487. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2488. }
  2489. I915_WRITE(reg, temp);
  2490. reg = FDI_RX_CTL(pipe);
  2491. temp = I915_READ(reg);
  2492. if (HAS_PCH_CPT(dev)) {
  2493. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2494. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2495. } else {
  2496. temp &= ~FDI_LINK_TRAIN_NONE;
  2497. temp |= FDI_LINK_TRAIN_NONE;
  2498. }
  2499. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2500. /* wait one idle pattern time */
  2501. POSTING_READ(reg);
  2502. udelay(1000);
  2503. /* IVB wants error correction enabled */
  2504. if (IS_IVYBRIDGE(dev))
  2505. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2506. FDI_FE_ERRC_ENABLE);
  2507. }
  2508. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2509. {
  2510. return crtc->base.enabled && crtc->active &&
  2511. crtc->config.has_pch_encoder;
  2512. }
  2513. static void ivb_modeset_global_resources(struct drm_device *dev)
  2514. {
  2515. struct drm_i915_private *dev_priv = dev->dev_private;
  2516. struct intel_crtc *pipe_B_crtc =
  2517. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2518. struct intel_crtc *pipe_C_crtc =
  2519. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2520. uint32_t temp;
  2521. /*
  2522. * When everything is off disable fdi C so that we could enable fdi B
  2523. * with all lanes. Note that we don't care about enabled pipes without
  2524. * an enabled pch encoder.
  2525. */
  2526. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2527. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2528. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2529. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2530. temp = I915_READ(SOUTH_CHICKEN1);
  2531. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2532. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2533. I915_WRITE(SOUTH_CHICKEN1, temp);
  2534. }
  2535. }
  2536. /* The FDI link training functions for ILK/Ibexpeak. */
  2537. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2538. {
  2539. struct drm_device *dev = crtc->dev;
  2540. struct drm_i915_private *dev_priv = dev->dev_private;
  2541. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2542. int pipe = intel_crtc->pipe;
  2543. u32 reg, temp, tries;
  2544. /* FDI needs bits from pipe first */
  2545. assert_pipe_enabled(dev_priv, pipe);
  2546. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2547. for train result */
  2548. reg = FDI_RX_IMR(pipe);
  2549. temp = I915_READ(reg);
  2550. temp &= ~FDI_RX_SYMBOL_LOCK;
  2551. temp &= ~FDI_RX_BIT_LOCK;
  2552. I915_WRITE(reg, temp);
  2553. I915_READ(reg);
  2554. udelay(150);
  2555. /* enable CPU FDI TX and PCH FDI RX */
  2556. reg = FDI_TX_CTL(pipe);
  2557. temp = I915_READ(reg);
  2558. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2559. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2560. temp &= ~FDI_LINK_TRAIN_NONE;
  2561. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2562. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2563. reg = FDI_RX_CTL(pipe);
  2564. temp = I915_READ(reg);
  2565. temp &= ~FDI_LINK_TRAIN_NONE;
  2566. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2567. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2568. POSTING_READ(reg);
  2569. udelay(150);
  2570. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2571. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2572. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2573. FDI_RX_PHASE_SYNC_POINTER_EN);
  2574. reg = FDI_RX_IIR(pipe);
  2575. for (tries = 0; tries < 5; tries++) {
  2576. temp = I915_READ(reg);
  2577. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2578. if ((temp & FDI_RX_BIT_LOCK)) {
  2579. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2580. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2581. break;
  2582. }
  2583. }
  2584. if (tries == 5)
  2585. DRM_ERROR("FDI train 1 fail!\n");
  2586. /* Train 2 */
  2587. reg = FDI_TX_CTL(pipe);
  2588. temp = I915_READ(reg);
  2589. temp &= ~FDI_LINK_TRAIN_NONE;
  2590. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2591. I915_WRITE(reg, temp);
  2592. reg = FDI_RX_CTL(pipe);
  2593. temp = I915_READ(reg);
  2594. temp &= ~FDI_LINK_TRAIN_NONE;
  2595. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2596. I915_WRITE(reg, temp);
  2597. POSTING_READ(reg);
  2598. udelay(150);
  2599. reg = FDI_RX_IIR(pipe);
  2600. for (tries = 0; tries < 5; tries++) {
  2601. temp = I915_READ(reg);
  2602. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2603. if (temp & FDI_RX_SYMBOL_LOCK) {
  2604. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2605. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2606. break;
  2607. }
  2608. }
  2609. if (tries == 5)
  2610. DRM_ERROR("FDI train 2 fail!\n");
  2611. DRM_DEBUG_KMS("FDI train done\n");
  2612. }
  2613. static const int snb_b_fdi_train_param[] = {
  2614. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2615. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2616. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2617. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2618. };
  2619. /* The FDI link training functions for SNB/Cougarpoint. */
  2620. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2621. {
  2622. struct drm_device *dev = crtc->dev;
  2623. struct drm_i915_private *dev_priv = dev->dev_private;
  2624. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2625. int pipe = intel_crtc->pipe;
  2626. u32 reg, temp, i, retry;
  2627. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2628. for train result */
  2629. reg = FDI_RX_IMR(pipe);
  2630. temp = I915_READ(reg);
  2631. temp &= ~FDI_RX_SYMBOL_LOCK;
  2632. temp &= ~FDI_RX_BIT_LOCK;
  2633. I915_WRITE(reg, temp);
  2634. POSTING_READ(reg);
  2635. udelay(150);
  2636. /* enable CPU FDI TX and PCH FDI RX */
  2637. reg = FDI_TX_CTL(pipe);
  2638. temp = I915_READ(reg);
  2639. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2640. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2641. temp &= ~FDI_LINK_TRAIN_NONE;
  2642. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2643. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2644. /* SNB-B */
  2645. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2646. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2647. I915_WRITE(FDI_RX_MISC(pipe),
  2648. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2649. reg = FDI_RX_CTL(pipe);
  2650. temp = I915_READ(reg);
  2651. if (HAS_PCH_CPT(dev)) {
  2652. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2653. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2654. } else {
  2655. temp &= ~FDI_LINK_TRAIN_NONE;
  2656. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2657. }
  2658. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2659. POSTING_READ(reg);
  2660. udelay(150);
  2661. for (i = 0; i < 4; i++) {
  2662. reg = FDI_TX_CTL(pipe);
  2663. temp = I915_READ(reg);
  2664. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2665. temp |= snb_b_fdi_train_param[i];
  2666. I915_WRITE(reg, temp);
  2667. POSTING_READ(reg);
  2668. udelay(500);
  2669. for (retry = 0; retry < 5; retry++) {
  2670. reg = FDI_RX_IIR(pipe);
  2671. temp = I915_READ(reg);
  2672. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2673. if (temp & FDI_RX_BIT_LOCK) {
  2674. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2675. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2676. break;
  2677. }
  2678. udelay(50);
  2679. }
  2680. if (retry < 5)
  2681. break;
  2682. }
  2683. if (i == 4)
  2684. DRM_ERROR("FDI train 1 fail!\n");
  2685. /* Train 2 */
  2686. reg = FDI_TX_CTL(pipe);
  2687. temp = I915_READ(reg);
  2688. temp &= ~FDI_LINK_TRAIN_NONE;
  2689. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2690. if (IS_GEN6(dev)) {
  2691. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2692. /* SNB-B */
  2693. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2694. }
  2695. I915_WRITE(reg, temp);
  2696. reg = FDI_RX_CTL(pipe);
  2697. temp = I915_READ(reg);
  2698. if (HAS_PCH_CPT(dev)) {
  2699. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2700. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2701. } else {
  2702. temp &= ~FDI_LINK_TRAIN_NONE;
  2703. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2704. }
  2705. I915_WRITE(reg, temp);
  2706. POSTING_READ(reg);
  2707. udelay(150);
  2708. for (i = 0; i < 4; i++) {
  2709. reg = FDI_TX_CTL(pipe);
  2710. temp = I915_READ(reg);
  2711. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2712. temp |= snb_b_fdi_train_param[i];
  2713. I915_WRITE(reg, temp);
  2714. POSTING_READ(reg);
  2715. udelay(500);
  2716. for (retry = 0; retry < 5; retry++) {
  2717. reg = FDI_RX_IIR(pipe);
  2718. temp = I915_READ(reg);
  2719. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2720. if (temp & FDI_RX_SYMBOL_LOCK) {
  2721. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2722. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2723. break;
  2724. }
  2725. udelay(50);
  2726. }
  2727. if (retry < 5)
  2728. break;
  2729. }
  2730. if (i == 4)
  2731. DRM_ERROR("FDI train 2 fail!\n");
  2732. DRM_DEBUG_KMS("FDI train done.\n");
  2733. }
  2734. /* Manual link training for Ivy Bridge A0 parts */
  2735. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2736. {
  2737. struct drm_device *dev = crtc->dev;
  2738. struct drm_i915_private *dev_priv = dev->dev_private;
  2739. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2740. int pipe = intel_crtc->pipe;
  2741. u32 reg, temp, i, j;
  2742. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2743. for train result */
  2744. reg = FDI_RX_IMR(pipe);
  2745. temp = I915_READ(reg);
  2746. temp &= ~FDI_RX_SYMBOL_LOCK;
  2747. temp &= ~FDI_RX_BIT_LOCK;
  2748. I915_WRITE(reg, temp);
  2749. POSTING_READ(reg);
  2750. udelay(150);
  2751. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2752. I915_READ(FDI_RX_IIR(pipe)));
  2753. /* Try each vswing and preemphasis setting twice before moving on */
  2754. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2755. /* disable first in case we need to retry */
  2756. reg = FDI_TX_CTL(pipe);
  2757. temp = I915_READ(reg);
  2758. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2759. temp &= ~FDI_TX_ENABLE;
  2760. I915_WRITE(reg, temp);
  2761. reg = FDI_RX_CTL(pipe);
  2762. temp = I915_READ(reg);
  2763. temp &= ~FDI_LINK_TRAIN_AUTO;
  2764. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2765. temp &= ~FDI_RX_ENABLE;
  2766. I915_WRITE(reg, temp);
  2767. /* enable CPU FDI TX and PCH FDI RX */
  2768. reg = FDI_TX_CTL(pipe);
  2769. temp = I915_READ(reg);
  2770. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2771. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2772. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2773. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2774. temp |= snb_b_fdi_train_param[j/2];
  2775. temp |= FDI_COMPOSITE_SYNC;
  2776. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2777. I915_WRITE(FDI_RX_MISC(pipe),
  2778. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2779. reg = FDI_RX_CTL(pipe);
  2780. temp = I915_READ(reg);
  2781. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2782. temp |= FDI_COMPOSITE_SYNC;
  2783. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2784. POSTING_READ(reg);
  2785. udelay(1); /* should be 0.5us */
  2786. for (i = 0; i < 4; i++) {
  2787. reg = FDI_RX_IIR(pipe);
  2788. temp = I915_READ(reg);
  2789. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2790. if (temp & FDI_RX_BIT_LOCK ||
  2791. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2792. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2793. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2794. i);
  2795. break;
  2796. }
  2797. udelay(1); /* should be 0.5us */
  2798. }
  2799. if (i == 4) {
  2800. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2801. continue;
  2802. }
  2803. /* Train 2 */
  2804. reg = FDI_TX_CTL(pipe);
  2805. temp = I915_READ(reg);
  2806. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2807. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2808. I915_WRITE(reg, temp);
  2809. reg = FDI_RX_CTL(pipe);
  2810. temp = I915_READ(reg);
  2811. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2812. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2813. I915_WRITE(reg, temp);
  2814. POSTING_READ(reg);
  2815. udelay(2); /* should be 1.5us */
  2816. for (i = 0; i < 4; i++) {
  2817. reg = FDI_RX_IIR(pipe);
  2818. temp = I915_READ(reg);
  2819. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2820. if (temp & FDI_RX_SYMBOL_LOCK ||
  2821. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2822. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2823. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2824. i);
  2825. goto train_done;
  2826. }
  2827. udelay(2); /* should be 1.5us */
  2828. }
  2829. if (i == 4)
  2830. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2831. }
  2832. train_done:
  2833. DRM_DEBUG_KMS("FDI train done.\n");
  2834. }
  2835. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2836. {
  2837. struct drm_device *dev = intel_crtc->base.dev;
  2838. struct drm_i915_private *dev_priv = dev->dev_private;
  2839. int pipe = intel_crtc->pipe;
  2840. u32 reg, temp;
  2841. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2842. reg = FDI_RX_CTL(pipe);
  2843. temp = I915_READ(reg);
  2844. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2845. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2846. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2847. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2848. POSTING_READ(reg);
  2849. udelay(200);
  2850. /* Switch from Rawclk to PCDclk */
  2851. temp = I915_READ(reg);
  2852. I915_WRITE(reg, temp | FDI_PCDCLK);
  2853. POSTING_READ(reg);
  2854. udelay(200);
  2855. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2856. reg = FDI_TX_CTL(pipe);
  2857. temp = I915_READ(reg);
  2858. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2859. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2860. POSTING_READ(reg);
  2861. udelay(100);
  2862. }
  2863. }
  2864. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2865. {
  2866. struct drm_device *dev = intel_crtc->base.dev;
  2867. struct drm_i915_private *dev_priv = dev->dev_private;
  2868. int pipe = intel_crtc->pipe;
  2869. u32 reg, temp;
  2870. /* Switch from PCDclk to Rawclk */
  2871. reg = FDI_RX_CTL(pipe);
  2872. temp = I915_READ(reg);
  2873. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2874. /* Disable CPU FDI TX PLL */
  2875. reg = FDI_TX_CTL(pipe);
  2876. temp = I915_READ(reg);
  2877. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2878. POSTING_READ(reg);
  2879. udelay(100);
  2880. reg = FDI_RX_CTL(pipe);
  2881. temp = I915_READ(reg);
  2882. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2883. /* Wait for the clocks to turn off. */
  2884. POSTING_READ(reg);
  2885. udelay(100);
  2886. }
  2887. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2888. {
  2889. struct drm_device *dev = crtc->dev;
  2890. struct drm_i915_private *dev_priv = dev->dev_private;
  2891. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2892. int pipe = intel_crtc->pipe;
  2893. u32 reg, temp;
  2894. /* disable CPU FDI tx and PCH FDI rx */
  2895. reg = FDI_TX_CTL(pipe);
  2896. temp = I915_READ(reg);
  2897. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2898. POSTING_READ(reg);
  2899. reg = FDI_RX_CTL(pipe);
  2900. temp = I915_READ(reg);
  2901. temp &= ~(0x7 << 16);
  2902. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2903. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2904. POSTING_READ(reg);
  2905. udelay(100);
  2906. /* Ironlake workaround, disable clock pointer after downing FDI */
  2907. if (HAS_PCH_IBX(dev))
  2908. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2909. /* still set train pattern 1 */
  2910. reg = FDI_TX_CTL(pipe);
  2911. temp = I915_READ(reg);
  2912. temp &= ~FDI_LINK_TRAIN_NONE;
  2913. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2914. I915_WRITE(reg, temp);
  2915. reg = FDI_RX_CTL(pipe);
  2916. temp = I915_READ(reg);
  2917. if (HAS_PCH_CPT(dev)) {
  2918. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2919. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2920. } else {
  2921. temp &= ~FDI_LINK_TRAIN_NONE;
  2922. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2923. }
  2924. /* BPC in FDI rx is consistent with that in PIPECONF */
  2925. temp &= ~(0x07 << 16);
  2926. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2927. I915_WRITE(reg, temp);
  2928. POSTING_READ(reg);
  2929. udelay(100);
  2930. }
  2931. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2932. {
  2933. struct intel_crtc *crtc;
  2934. /* Note that we don't need to be called with mode_config.lock here
  2935. * as our list of CRTC objects is static for the lifetime of the
  2936. * device and so cannot disappear as we iterate. Similarly, we can
  2937. * happily treat the predicates as racy, atomic checks as userspace
  2938. * cannot claim and pin a new fb without at least acquring the
  2939. * struct_mutex and so serialising with us.
  2940. */
  2941. for_each_intel_crtc(dev, crtc) {
  2942. if (atomic_read(&crtc->unpin_work_count) == 0)
  2943. continue;
  2944. if (crtc->unpin_work)
  2945. intel_wait_for_vblank(dev, crtc->pipe);
  2946. return true;
  2947. }
  2948. return false;
  2949. }
  2950. static void page_flip_completed(struct intel_crtc *intel_crtc)
  2951. {
  2952. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  2953. struct intel_unpin_work *work = intel_crtc->unpin_work;
  2954. /* ensure that the unpin work is consistent wrt ->pending. */
  2955. smp_rmb();
  2956. intel_crtc->unpin_work = NULL;
  2957. if (work->event)
  2958. drm_send_vblank_event(intel_crtc->base.dev,
  2959. intel_crtc->pipe,
  2960. work->event);
  2961. drm_crtc_vblank_put(&intel_crtc->base);
  2962. wake_up_all(&dev_priv->pending_flip_queue);
  2963. queue_work(dev_priv->wq, &work->work);
  2964. trace_i915_flip_complete(intel_crtc->plane,
  2965. work->pending_flip_obj);
  2966. }
  2967. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2968. {
  2969. struct drm_device *dev = crtc->dev;
  2970. struct drm_i915_private *dev_priv = dev->dev_private;
  2971. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2972. if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  2973. !intel_crtc_has_pending_flip(crtc),
  2974. 60*HZ) == 0)) {
  2975. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2976. unsigned long flags;
  2977. spin_lock_irqsave(&dev->event_lock, flags);
  2978. if (intel_crtc->unpin_work) {
  2979. WARN_ONCE(1, "Removing stuck page flip\n");
  2980. page_flip_completed(intel_crtc);
  2981. }
  2982. spin_unlock_irqrestore(&dev->event_lock, flags);
  2983. }
  2984. if (crtc->primary->fb) {
  2985. mutex_lock(&dev->struct_mutex);
  2986. intel_finish_fb(crtc->primary->fb);
  2987. mutex_unlock(&dev->struct_mutex);
  2988. }
  2989. }
  2990. /* Program iCLKIP clock to the desired frequency */
  2991. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2992. {
  2993. struct drm_device *dev = crtc->dev;
  2994. struct drm_i915_private *dev_priv = dev->dev_private;
  2995. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2996. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2997. u32 temp;
  2998. mutex_lock(&dev_priv->dpio_lock);
  2999. /* It is necessary to ungate the pixclk gate prior to programming
  3000. * the divisors, and gate it back when it is done.
  3001. */
  3002. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  3003. /* Disable SSCCTL */
  3004. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  3005. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  3006. SBI_SSCCTL_DISABLE,
  3007. SBI_ICLK);
  3008. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  3009. if (clock == 20000) {
  3010. auxdiv = 1;
  3011. divsel = 0x41;
  3012. phaseinc = 0x20;
  3013. } else {
  3014. /* The iCLK virtual clock root frequency is in MHz,
  3015. * but the adjusted_mode->crtc_clock in in KHz. To get the
  3016. * divisors, it is necessary to divide one by another, so we
  3017. * convert the virtual clock precision to KHz here for higher
  3018. * precision.
  3019. */
  3020. u32 iclk_virtual_root_freq = 172800 * 1000;
  3021. u32 iclk_pi_range = 64;
  3022. u32 desired_divisor, msb_divisor_value, pi_value;
  3023. desired_divisor = (iclk_virtual_root_freq / clock);
  3024. msb_divisor_value = desired_divisor / iclk_pi_range;
  3025. pi_value = desired_divisor % iclk_pi_range;
  3026. auxdiv = 0;
  3027. divsel = msb_divisor_value - 2;
  3028. phaseinc = pi_value;
  3029. }
  3030. /* This should not happen with any sane values */
  3031. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  3032. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  3033. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  3034. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  3035. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  3036. clock,
  3037. auxdiv,
  3038. divsel,
  3039. phasedir,
  3040. phaseinc);
  3041. /* Program SSCDIVINTPHASE6 */
  3042. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  3043. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  3044. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  3045. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  3046. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  3047. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  3048. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  3049. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  3050. /* Program SSCAUXDIV */
  3051. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  3052. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  3053. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  3054. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  3055. /* Enable modulator and associated divider */
  3056. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  3057. temp &= ~SBI_SSCCTL_DISABLE;
  3058. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  3059. /* Wait for initialization time */
  3060. udelay(24);
  3061. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  3062. mutex_unlock(&dev_priv->dpio_lock);
  3063. }
  3064. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  3065. enum pipe pch_transcoder)
  3066. {
  3067. struct drm_device *dev = crtc->base.dev;
  3068. struct drm_i915_private *dev_priv = dev->dev_private;
  3069. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  3070. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  3071. I915_READ(HTOTAL(cpu_transcoder)));
  3072. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  3073. I915_READ(HBLANK(cpu_transcoder)));
  3074. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  3075. I915_READ(HSYNC(cpu_transcoder)));
  3076. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  3077. I915_READ(VTOTAL(cpu_transcoder)));
  3078. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  3079. I915_READ(VBLANK(cpu_transcoder)));
  3080. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  3081. I915_READ(VSYNC(cpu_transcoder)));
  3082. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  3083. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  3084. }
  3085. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  3086. {
  3087. struct drm_i915_private *dev_priv = dev->dev_private;
  3088. uint32_t temp;
  3089. temp = I915_READ(SOUTH_CHICKEN1);
  3090. if (temp & FDI_BC_BIFURCATION_SELECT)
  3091. return;
  3092. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  3093. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  3094. temp |= FDI_BC_BIFURCATION_SELECT;
  3095. DRM_DEBUG_KMS("enabling fdi C rx\n");
  3096. I915_WRITE(SOUTH_CHICKEN1, temp);
  3097. POSTING_READ(SOUTH_CHICKEN1);
  3098. }
  3099. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  3100. {
  3101. struct drm_device *dev = intel_crtc->base.dev;
  3102. struct drm_i915_private *dev_priv = dev->dev_private;
  3103. switch (intel_crtc->pipe) {
  3104. case PIPE_A:
  3105. break;
  3106. case PIPE_B:
  3107. if (intel_crtc->config.fdi_lanes > 2)
  3108. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  3109. else
  3110. cpt_enable_fdi_bc_bifurcation(dev);
  3111. break;
  3112. case PIPE_C:
  3113. cpt_enable_fdi_bc_bifurcation(dev);
  3114. break;
  3115. default:
  3116. BUG();
  3117. }
  3118. }
  3119. /*
  3120. * Enable PCH resources required for PCH ports:
  3121. * - PCH PLLs
  3122. * - FDI training & RX/TX
  3123. * - update transcoder timings
  3124. * - DP transcoding bits
  3125. * - transcoder
  3126. */
  3127. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3128. {
  3129. struct drm_device *dev = crtc->dev;
  3130. struct drm_i915_private *dev_priv = dev->dev_private;
  3131. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3132. int pipe = intel_crtc->pipe;
  3133. u32 reg, temp;
  3134. assert_pch_transcoder_disabled(dev_priv, pipe);
  3135. if (IS_IVYBRIDGE(dev))
  3136. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3137. /* Write the TU size bits before fdi link training, so that error
  3138. * detection works. */
  3139. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3140. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3141. /* For PCH output, training FDI link */
  3142. dev_priv->display.fdi_link_train(crtc);
  3143. /* We need to program the right clock selection before writing the pixel
  3144. * mutliplier into the DPLL. */
  3145. if (HAS_PCH_CPT(dev)) {
  3146. u32 sel;
  3147. temp = I915_READ(PCH_DPLL_SEL);
  3148. temp |= TRANS_DPLL_ENABLE(pipe);
  3149. sel = TRANS_DPLLB_SEL(pipe);
  3150. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3151. temp |= sel;
  3152. else
  3153. temp &= ~sel;
  3154. I915_WRITE(PCH_DPLL_SEL, temp);
  3155. }
  3156. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3157. * transcoder, and we actually should do this to not upset any PCH
  3158. * transcoder that already use the clock when we share it.
  3159. *
  3160. * Note that enable_shared_dpll tries to do the right thing, but
  3161. * get_shared_dpll unconditionally resets the pll - we need that to have
  3162. * the right LVDS enable sequence. */
  3163. intel_enable_shared_dpll(intel_crtc);
  3164. /* set transcoder timing, panel must allow it */
  3165. assert_panel_unlocked(dev_priv, pipe);
  3166. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3167. intel_fdi_normal_train(crtc);
  3168. /* For PCH DP, enable TRANS_DP_CTL */
  3169. if (HAS_PCH_CPT(dev) &&
  3170. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3171. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  3172. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3173. reg = TRANS_DP_CTL(pipe);
  3174. temp = I915_READ(reg);
  3175. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3176. TRANS_DP_SYNC_MASK |
  3177. TRANS_DP_BPC_MASK);
  3178. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3179. TRANS_DP_ENH_FRAMING);
  3180. temp |= bpc << 9; /* same format but at 11:9 */
  3181. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3182. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3183. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3184. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3185. switch (intel_trans_dp_port_sel(crtc)) {
  3186. case PCH_DP_B:
  3187. temp |= TRANS_DP_PORT_SEL_B;
  3188. break;
  3189. case PCH_DP_C:
  3190. temp |= TRANS_DP_PORT_SEL_C;
  3191. break;
  3192. case PCH_DP_D:
  3193. temp |= TRANS_DP_PORT_SEL_D;
  3194. break;
  3195. default:
  3196. BUG();
  3197. }
  3198. I915_WRITE(reg, temp);
  3199. }
  3200. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3201. }
  3202. static void lpt_pch_enable(struct drm_crtc *crtc)
  3203. {
  3204. struct drm_device *dev = crtc->dev;
  3205. struct drm_i915_private *dev_priv = dev->dev_private;
  3206. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3207. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3208. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3209. lpt_program_iclkip(crtc);
  3210. /* Set transcoder timing. */
  3211. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3212. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3213. }
  3214. void intel_put_shared_dpll(struct intel_crtc *crtc)
  3215. {
  3216. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3217. if (pll == NULL)
  3218. return;
  3219. if (pll->refcount == 0) {
  3220. WARN(1, "bad %s refcount\n", pll->name);
  3221. return;
  3222. }
  3223. if (--pll->refcount == 0) {
  3224. WARN_ON(pll->on);
  3225. WARN_ON(pll->active);
  3226. }
  3227. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3228. }
  3229. struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3230. {
  3231. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3232. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3233. enum intel_dpll_id i;
  3234. if (pll) {
  3235. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3236. crtc->base.base.id, pll->name);
  3237. intel_put_shared_dpll(crtc);
  3238. }
  3239. if (HAS_PCH_IBX(dev_priv->dev)) {
  3240. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3241. i = (enum intel_dpll_id) crtc->pipe;
  3242. pll = &dev_priv->shared_dplls[i];
  3243. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3244. crtc->base.base.id, pll->name);
  3245. WARN_ON(pll->refcount);
  3246. goto found;
  3247. }
  3248. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3249. pll = &dev_priv->shared_dplls[i];
  3250. /* Only want to check enabled timings first */
  3251. if (pll->refcount == 0)
  3252. continue;
  3253. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3254. sizeof(pll->hw_state)) == 0) {
  3255. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3256. crtc->base.base.id,
  3257. pll->name, pll->refcount, pll->active);
  3258. goto found;
  3259. }
  3260. }
  3261. /* Ok no matching timings, maybe there's a free one? */
  3262. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3263. pll = &dev_priv->shared_dplls[i];
  3264. if (pll->refcount == 0) {
  3265. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3266. crtc->base.base.id, pll->name);
  3267. goto found;
  3268. }
  3269. }
  3270. return NULL;
  3271. found:
  3272. if (pll->refcount == 0)
  3273. pll->hw_state = crtc->config.dpll_hw_state;
  3274. crtc->config.shared_dpll = i;
  3275. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3276. pipe_name(crtc->pipe));
  3277. pll->refcount++;
  3278. return pll;
  3279. }
  3280. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3281. {
  3282. struct drm_i915_private *dev_priv = dev->dev_private;
  3283. int dslreg = PIPEDSL(pipe);
  3284. u32 temp;
  3285. temp = I915_READ(dslreg);
  3286. udelay(500);
  3287. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3288. if (wait_for(I915_READ(dslreg) != temp, 5))
  3289. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3290. }
  3291. }
  3292. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3293. {
  3294. struct drm_device *dev = crtc->base.dev;
  3295. struct drm_i915_private *dev_priv = dev->dev_private;
  3296. int pipe = crtc->pipe;
  3297. if (crtc->config.pch_pfit.enabled) {
  3298. /* Force use of hard-coded filter coefficients
  3299. * as some pre-programmed values are broken,
  3300. * e.g. x201.
  3301. */
  3302. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3303. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3304. PF_PIPE_SEL_IVB(pipe));
  3305. else
  3306. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3307. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3308. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3309. }
  3310. }
  3311. static void intel_enable_planes(struct drm_crtc *crtc)
  3312. {
  3313. struct drm_device *dev = crtc->dev;
  3314. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3315. struct drm_plane *plane;
  3316. struct intel_plane *intel_plane;
  3317. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3318. intel_plane = to_intel_plane(plane);
  3319. if (intel_plane->pipe == pipe)
  3320. intel_plane_restore(&intel_plane->base);
  3321. }
  3322. }
  3323. static void intel_disable_planes(struct drm_crtc *crtc)
  3324. {
  3325. struct drm_device *dev = crtc->dev;
  3326. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3327. struct drm_plane *plane;
  3328. struct intel_plane *intel_plane;
  3329. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3330. intel_plane = to_intel_plane(plane);
  3331. if (intel_plane->pipe == pipe)
  3332. intel_plane_disable(&intel_plane->base);
  3333. }
  3334. }
  3335. void hsw_enable_ips(struct intel_crtc *crtc)
  3336. {
  3337. struct drm_device *dev = crtc->base.dev;
  3338. struct drm_i915_private *dev_priv = dev->dev_private;
  3339. if (!crtc->config.ips_enabled)
  3340. return;
  3341. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3342. intel_wait_for_vblank(dev, crtc->pipe);
  3343. assert_plane_enabled(dev_priv, crtc->plane);
  3344. if (IS_BROADWELL(dev)) {
  3345. mutex_lock(&dev_priv->rps.hw_lock);
  3346. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3347. mutex_unlock(&dev_priv->rps.hw_lock);
  3348. /* Quoting Art Runyan: "its not safe to expect any particular
  3349. * value in IPS_CTL bit 31 after enabling IPS through the
  3350. * mailbox." Moreover, the mailbox may return a bogus state,
  3351. * so we need to just enable it and continue on.
  3352. */
  3353. } else {
  3354. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3355. /* The bit only becomes 1 in the next vblank, so this wait here
  3356. * is essentially intel_wait_for_vblank. If we don't have this
  3357. * and don't wait for vblanks until the end of crtc_enable, then
  3358. * the HW state readout code will complain that the expected
  3359. * IPS_CTL value is not the one we read. */
  3360. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3361. DRM_ERROR("Timed out waiting for IPS enable\n");
  3362. }
  3363. }
  3364. void hsw_disable_ips(struct intel_crtc *crtc)
  3365. {
  3366. struct drm_device *dev = crtc->base.dev;
  3367. struct drm_i915_private *dev_priv = dev->dev_private;
  3368. if (!crtc->config.ips_enabled)
  3369. return;
  3370. assert_plane_enabled(dev_priv, crtc->plane);
  3371. if (IS_BROADWELL(dev)) {
  3372. mutex_lock(&dev_priv->rps.hw_lock);
  3373. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  3374. mutex_unlock(&dev_priv->rps.hw_lock);
  3375. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3376. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3377. DRM_ERROR("Timed out waiting for IPS disable\n");
  3378. } else {
  3379. I915_WRITE(IPS_CTL, 0);
  3380. POSTING_READ(IPS_CTL);
  3381. }
  3382. /* We need to wait for a vblank before we can disable the plane. */
  3383. intel_wait_for_vblank(dev, crtc->pipe);
  3384. }
  3385. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3386. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3387. {
  3388. struct drm_device *dev = crtc->dev;
  3389. struct drm_i915_private *dev_priv = dev->dev_private;
  3390. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3391. enum pipe pipe = intel_crtc->pipe;
  3392. int palreg = PALETTE(pipe);
  3393. int i;
  3394. bool reenable_ips = false;
  3395. /* The clocks have to be on to load the palette. */
  3396. if (!crtc->enabled || !intel_crtc->active)
  3397. return;
  3398. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3399. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3400. assert_dsi_pll_enabled(dev_priv);
  3401. else
  3402. assert_pll_enabled(dev_priv, pipe);
  3403. }
  3404. /* use legacy palette for Ironlake */
  3405. if (!HAS_GMCH_DISPLAY(dev))
  3406. palreg = LGC_PALETTE(pipe);
  3407. /* Workaround : Do not read or write the pipe palette/gamma data while
  3408. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3409. */
  3410. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3411. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3412. GAMMA_MODE_MODE_SPLIT)) {
  3413. hsw_disable_ips(intel_crtc);
  3414. reenable_ips = true;
  3415. }
  3416. for (i = 0; i < 256; i++) {
  3417. I915_WRITE(palreg + 4 * i,
  3418. (intel_crtc->lut_r[i] << 16) |
  3419. (intel_crtc->lut_g[i] << 8) |
  3420. intel_crtc->lut_b[i]);
  3421. }
  3422. if (reenable_ips)
  3423. hsw_enable_ips(intel_crtc);
  3424. }
  3425. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3426. {
  3427. if (!enable && intel_crtc->overlay) {
  3428. struct drm_device *dev = intel_crtc->base.dev;
  3429. struct drm_i915_private *dev_priv = dev->dev_private;
  3430. mutex_lock(&dev->struct_mutex);
  3431. dev_priv->mm.interruptible = false;
  3432. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3433. dev_priv->mm.interruptible = true;
  3434. mutex_unlock(&dev->struct_mutex);
  3435. }
  3436. /* Let userspace switch the overlay on again. In most cases userspace
  3437. * has to recompute where to put it anyway.
  3438. */
  3439. }
  3440. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3441. {
  3442. struct drm_device *dev = crtc->dev;
  3443. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3444. int pipe = intel_crtc->pipe;
  3445. assert_vblank_disabled(crtc);
  3446. drm_vblank_on(dev, pipe);
  3447. intel_enable_primary_hw_plane(crtc->primary, crtc);
  3448. intel_enable_planes(crtc);
  3449. intel_crtc_update_cursor(crtc, true);
  3450. intel_crtc_dpms_overlay(intel_crtc, true);
  3451. hsw_enable_ips(intel_crtc);
  3452. mutex_lock(&dev->struct_mutex);
  3453. intel_update_fbc(dev);
  3454. mutex_unlock(&dev->struct_mutex);
  3455. /*
  3456. * FIXME: Once we grow proper nuclear flip support out of this we need
  3457. * to compute the mask of flip planes precisely. For the time being
  3458. * consider this a flip from a NULL plane.
  3459. */
  3460. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3461. }
  3462. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3463. {
  3464. struct drm_device *dev = crtc->dev;
  3465. struct drm_i915_private *dev_priv = dev->dev_private;
  3466. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3467. int pipe = intel_crtc->pipe;
  3468. int plane = intel_crtc->plane;
  3469. intel_crtc_wait_for_pending_flips(crtc);
  3470. if (dev_priv->fbc.plane == plane)
  3471. intel_disable_fbc(dev);
  3472. hsw_disable_ips(intel_crtc);
  3473. intel_crtc_dpms_overlay(intel_crtc, false);
  3474. intel_crtc_update_cursor(crtc, false);
  3475. intel_disable_planes(crtc);
  3476. intel_disable_primary_hw_plane(crtc->primary, crtc);
  3477. /*
  3478. * FIXME: Once we grow proper nuclear flip support out of this we need
  3479. * to compute the mask of flip planes precisely. For the time being
  3480. * consider this a flip to a NULL plane.
  3481. */
  3482. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3483. drm_vblank_off(dev, pipe);
  3484. assert_vblank_disabled(crtc);
  3485. }
  3486. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3487. {
  3488. struct drm_device *dev = crtc->dev;
  3489. struct drm_i915_private *dev_priv = dev->dev_private;
  3490. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3491. struct intel_encoder *encoder;
  3492. int pipe = intel_crtc->pipe;
  3493. WARN_ON(!crtc->enabled);
  3494. if (intel_crtc->active)
  3495. return;
  3496. if (intel_crtc->config.has_pch_encoder)
  3497. intel_prepare_shared_dpll(intel_crtc);
  3498. if (intel_crtc->config.has_dp_encoder)
  3499. intel_dp_set_m_n(intel_crtc);
  3500. intel_set_pipe_timings(intel_crtc);
  3501. if (intel_crtc->config.has_pch_encoder) {
  3502. intel_cpu_transcoder_set_m_n(intel_crtc,
  3503. &intel_crtc->config.fdi_m_n, NULL);
  3504. }
  3505. ironlake_set_pipeconf(crtc);
  3506. intel_crtc->active = true;
  3507. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3508. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3509. for_each_encoder_on_crtc(dev, crtc, encoder)
  3510. if (encoder->pre_enable)
  3511. encoder->pre_enable(encoder);
  3512. if (intel_crtc->config.has_pch_encoder) {
  3513. /* Note: FDI PLL enabling _must_ be done before we enable the
  3514. * cpu pipes, hence this is separate from all the other fdi/pch
  3515. * enabling. */
  3516. ironlake_fdi_pll_enable(intel_crtc);
  3517. } else {
  3518. assert_fdi_tx_disabled(dev_priv, pipe);
  3519. assert_fdi_rx_disabled(dev_priv, pipe);
  3520. }
  3521. ironlake_pfit_enable(intel_crtc);
  3522. /*
  3523. * On ILK+ LUT must be loaded before the pipe is running but with
  3524. * clocks enabled
  3525. */
  3526. intel_crtc_load_lut(crtc);
  3527. intel_update_watermarks(crtc);
  3528. intel_enable_pipe(intel_crtc);
  3529. if (intel_crtc->config.has_pch_encoder)
  3530. ironlake_pch_enable(crtc);
  3531. for_each_encoder_on_crtc(dev, crtc, encoder)
  3532. encoder->enable(encoder);
  3533. if (HAS_PCH_CPT(dev))
  3534. cpt_verify_modeset(dev, intel_crtc->pipe);
  3535. intel_crtc_enable_planes(crtc);
  3536. }
  3537. /* IPS only exists on ULT machines and is tied to pipe A. */
  3538. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3539. {
  3540. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3541. }
  3542. /*
  3543. * This implements the workaround described in the "notes" section of the mode
  3544. * set sequence documentation. When going from no pipes or single pipe to
  3545. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3546. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3547. */
  3548. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3549. {
  3550. struct drm_device *dev = crtc->base.dev;
  3551. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3552. /* We want to get the other_active_crtc only if there's only 1 other
  3553. * active crtc. */
  3554. for_each_intel_crtc(dev, crtc_it) {
  3555. if (!crtc_it->active || crtc_it == crtc)
  3556. continue;
  3557. if (other_active_crtc)
  3558. return;
  3559. other_active_crtc = crtc_it;
  3560. }
  3561. if (!other_active_crtc)
  3562. return;
  3563. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3564. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3565. }
  3566. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3567. {
  3568. struct drm_device *dev = crtc->dev;
  3569. struct drm_i915_private *dev_priv = dev->dev_private;
  3570. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3571. struct intel_encoder *encoder;
  3572. int pipe = intel_crtc->pipe;
  3573. WARN_ON(!crtc->enabled);
  3574. if (intel_crtc->active)
  3575. return;
  3576. if (intel_crtc_to_shared_dpll(intel_crtc))
  3577. intel_enable_shared_dpll(intel_crtc);
  3578. if (intel_crtc->config.has_dp_encoder)
  3579. intel_dp_set_m_n(intel_crtc);
  3580. intel_set_pipe_timings(intel_crtc);
  3581. if (intel_crtc->config.cpu_transcoder != TRANSCODER_EDP) {
  3582. I915_WRITE(PIPE_MULT(intel_crtc->config.cpu_transcoder),
  3583. intel_crtc->config.pixel_multiplier - 1);
  3584. }
  3585. if (intel_crtc->config.has_pch_encoder) {
  3586. intel_cpu_transcoder_set_m_n(intel_crtc,
  3587. &intel_crtc->config.fdi_m_n, NULL);
  3588. }
  3589. haswell_set_pipeconf(crtc);
  3590. intel_set_pipe_csc(crtc);
  3591. intel_crtc->active = true;
  3592. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3593. for_each_encoder_on_crtc(dev, crtc, encoder)
  3594. if (encoder->pre_enable)
  3595. encoder->pre_enable(encoder);
  3596. if (intel_crtc->config.has_pch_encoder) {
  3597. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3598. dev_priv->display.fdi_link_train(crtc);
  3599. }
  3600. intel_ddi_enable_pipe_clock(intel_crtc);
  3601. ironlake_pfit_enable(intel_crtc);
  3602. /*
  3603. * On ILK+ LUT must be loaded before the pipe is running but with
  3604. * clocks enabled
  3605. */
  3606. intel_crtc_load_lut(crtc);
  3607. intel_ddi_set_pipe_settings(crtc);
  3608. intel_ddi_enable_transcoder_func(crtc);
  3609. intel_update_watermarks(crtc);
  3610. intel_enable_pipe(intel_crtc);
  3611. if (intel_crtc->config.has_pch_encoder)
  3612. lpt_pch_enable(crtc);
  3613. if (intel_crtc->config.dp_encoder_is_mst)
  3614. intel_ddi_set_vc_payload_alloc(crtc, true);
  3615. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3616. encoder->enable(encoder);
  3617. intel_opregion_notify_encoder(encoder, true);
  3618. }
  3619. /* If we change the relative order between pipe/planes enabling, we need
  3620. * to change the workaround. */
  3621. haswell_mode_set_planes_workaround(intel_crtc);
  3622. intel_crtc_enable_planes(crtc);
  3623. }
  3624. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3625. {
  3626. struct drm_device *dev = crtc->base.dev;
  3627. struct drm_i915_private *dev_priv = dev->dev_private;
  3628. int pipe = crtc->pipe;
  3629. /* To avoid upsetting the power well on haswell only disable the pfit if
  3630. * it's in use. The hw state code will make sure we get this right. */
  3631. if (crtc->config.pch_pfit.enabled) {
  3632. I915_WRITE(PF_CTL(pipe), 0);
  3633. I915_WRITE(PF_WIN_POS(pipe), 0);
  3634. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3635. }
  3636. }
  3637. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3638. {
  3639. struct drm_device *dev = crtc->dev;
  3640. struct drm_i915_private *dev_priv = dev->dev_private;
  3641. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3642. struct intel_encoder *encoder;
  3643. int pipe = intel_crtc->pipe;
  3644. u32 reg, temp;
  3645. if (!intel_crtc->active)
  3646. return;
  3647. intel_crtc_disable_planes(crtc);
  3648. for_each_encoder_on_crtc(dev, crtc, encoder)
  3649. encoder->disable(encoder);
  3650. if (intel_crtc->config.has_pch_encoder)
  3651. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3652. intel_disable_pipe(intel_crtc);
  3653. ironlake_pfit_disable(intel_crtc);
  3654. for_each_encoder_on_crtc(dev, crtc, encoder)
  3655. if (encoder->post_disable)
  3656. encoder->post_disable(encoder);
  3657. if (intel_crtc->config.has_pch_encoder) {
  3658. ironlake_fdi_disable(crtc);
  3659. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3660. if (HAS_PCH_CPT(dev)) {
  3661. /* disable TRANS_DP_CTL */
  3662. reg = TRANS_DP_CTL(pipe);
  3663. temp = I915_READ(reg);
  3664. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3665. TRANS_DP_PORT_SEL_MASK);
  3666. temp |= TRANS_DP_PORT_SEL_NONE;
  3667. I915_WRITE(reg, temp);
  3668. /* disable DPLL_SEL */
  3669. temp = I915_READ(PCH_DPLL_SEL);
  3670. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3671. I915_WRITE(PCH_DPLL_SEL, temp);
  3672. }
  3673. /* disable PCH DPLL */
  3674. intel_disable_shared_dpll(intel_crtc);
  3675. ironlake_fdi_pll_disable(intel_crtc);
  3676. }
  3677. intel_crtc->active = false;
  3678. intel_update_watermarks(crtc);
  3679. mutex_lock(&dev->struct_mutex);
  3680. intel_update_fbc(dev);
  3681. mutex_unlock(&dev->struct_mutex);
  3682. }
  3683. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3684. {
  3685. struct drm_device *dev = crtc->dev;
  3686. struct drm_i915_private *dev_priv = dev->dev_private;
  3687. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3688. struct intel_encoder *encoder;
  3689. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3690. if (!intel_crtc->active)
  3691. return;
  3692. intel_crtc_disable_planes(crtc);
  3693. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3694. intel_opregion_notify_encoder(encoder, false);
  3695. encoder->disable(encoder);
  3696. }
  3697. if (intel_crtc->config.has_pch_encoder)
  3698. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3699. intel_disable_pipe(intel_crtc);
  3700. if (intel_crtc->config.dp_encoder_is_mst)
  3701. intel_ddi_set_vc_payload_alloc(crtc, false);
  3702. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3703. ironlake_pfit_disable(intel_crtc);
  3704. intel_ddi_disable_pipe_clock(intel_crtc);
  3705. if (intel_crtc->config.has_pch_encoder) {
  3706. lpt_disable_pch_transcoder(dev_priv);
  3707. intel_ddi_fdi_disable(crtc);
  3708. }
  3709. for_each_encoder_on_crtc(dev, crtc, encoder)
  3710. if (encoder->post_disable)
  3711. encoder->post_disable(encoder);
  3712. intel_crtc->active = false;
  3713. intel_update_watermarks(crtc);
  3714. mutex_lock(&dev->struct_mutex);
  3715. intel_update_fbc(dev);
  3716. mutex_unlock(&dev->struct_mutex);
  3717. if (intel_crtc_to_shared_dpll(intel_crtc))
  3718. intel_disable_shared_dpll(intel_crtc);
  3719. }
  3720. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3721. {
  3722. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3723. intel_put_shared_dpll(intel_crtc);
  3724. }
  3725. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3726. {
  3727. struct drm_device *dev = crtc->base.dev;
  3728. struct drm_i915_private *dev_priv = dev->dev_private;
  3729. struct intel_crtc_config *pipe_config = &crtc->config;
  3730. if (!crtc->config.gmch_pfit.control)
  3731. return;
  3732. /*
  3733. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3734. * according to register description and PRM.
  3735. */
  3736. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3737. assert_pipe_disabled(dev_priv, crtc->pipe);
  3738. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3739. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3740. /* Border color in case we don't scale up to the full screen. Black by
  3741. * default, change to something else for debugging. */
  3742. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3743. }
  3744. static enum intel_display_power_domain port_to_power_domain(enum port port)
  3745. {
  3746. switch (port) {
  3747. case PORT_A:
  3748. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3749. case PORT_B:
  3750. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3751. case PORT_C:
  3752. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3753. case PORT_D:
  3754. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3755. default:
  3756. WARN_ON_ONCE(1);
  3757. return POWER_DOMAIN_PORT_OTHER;
  3758. }
  3759. }
  3760. #define for_each_power_domain(domain, mask) \
  3761. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3762. if ((1 << (domain)) & (mask))
  3763. enum intel_display_power_domain
  3764. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3765. {
  3766. struct drm_device *dev = intel_encoder->base.dev;
  3767. struct intel_digital_port *intel_dig_port;
  3768. switch (intel_encoder->type) {
  3769. case INTEL_OUTPUT_UNKNOWN:
  3770. /* Only DDI platforms should ever use this output type */
  3771. WARN_ON_ONCE(!HAS_DDI(dev));
  3772. case INTEL_OUTPUT_DISPLAYPORT:
  3773. case INTEL_OUTPUT_HDMI:
  3774. case INTEL_OUTPUT_EDP:
  3775. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3776. return port_to_power_domain(intel_dig_port->port);
  3777. case INTEL_OUTPUT_DP_MST:
  3778. intel_dig_port = enc_to_mst(&intel_encoder->base)->primary;
  3779. return port_to_power_domain(intel_dig_port->port);
  3780. case INTEL_OUTPUT_ANALOG:
  3781. return POWER_DOMAIN_PORT_CRT;
  3782. case INTEL_OUTPUT_DSI:
  3783. return POWER_DOMAIN_PORT_DSI;
  3784. default:
  3785. return POWER_DOMAIN_PORT_OTHER;
  3786. }
  3787. }
  3788. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3789. {
  3790. struct drm_device *dev = crtc->dev;
  3791. struct intel_encoder *intel_encoder;
  3792. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3793. enum pipe pipe = intel_crtc->pipe;
  3794. unsigned long mask;
  3795. enum transcoder transcoder;
  3796. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3797. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3798. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3799. if (intel_crtc->config.pch_pfit.enabled ||
  3800. intel_crtc->config.pch_pfit.force_thru)
  3801. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3802. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3803. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3804. return mask;
  3805. }
  3806. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  3807. bool enable)
  3808. {
  3809. if (dev_priv->power_domains.init_power_on == enable)
  3810. return;
  3811. if (enable)
  3812. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3813. else
  3814. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3815. dev_priv->power_domains.init_power_on = enable;
  3816. }
  3817. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3818. {
  3819. struct drm_i915_private *dev_priv = dev->dev_private;
  3820. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3821. struct intel_crtc *crtc;
  3822. /*
  3823. * First get all needed power domains, then put all unneeded, to avoid
  3824. * any unnecessary toggling of the power wells.
  3825. */
  3826. for_each_intel_crtc(dev, crtc) {
  3827. enum intel_display_power_domain domain;
  3828. if (!crtc->base.enabled)
  3829. continue;
  3830. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3831. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3832. intel_display_power_get(dev_priv, domain);
  3833. }
  3834. for_each_intel_crtc(dev, crtc) {
  3835. enum intel_display_power_domain domain;
  3836. for_each_power_domain(domain, crtc->enabled_power_domains)
  3837. intel_display_power_put(dev_priv, domain);
  3838. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3839. }
  3840. intel_display_set_init_power(dev_priv, false);
  3841. }
  3842. /* returns HPLL frequency in kHz */
  3843. static int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3844. {
  3845. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3846. /* Obtain SKU information */
  3847. mutex_lock(&dev_priv->dpio_lock);
  3848. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3849. CCK_FUSE_HPLL_FREQ_MASK;
  3850. mutex_unlock(&dev_priv->dpio_lock);
  3851. return vco_freq[hpll_freq] * 1000;
  3852. }
  3853. static void vlv_update_cdclk(struct drm_device *dev)
  3854. {
  3855. struct drm_i915_private *dev_priv = dev->dev_private;
  3856. dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
  3857. DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz",
  3858. dev_priv->vlv_cdclk_freq);
  3859. /*
  3860. * Program the gmbus_freq based on the cdclk frequency.
  3861. * BSpec erroneously claims we should aim for 4MHz, but
  3862. * in fact 1MHz is the correct frequency.
  3863. */
  3864. I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->vlv_cdclk_freq, 1000));
  3865. }
  3866. /* Adjust CDclk dividers to allow high res or save power if possible */
  3867. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3868. {
  3869. struct drm_i915_private *dev_priv = dev->dev_private;
  3870. u32 val, cmd;
  3871. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3872. if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
  3873. cmd = 2;
  3874. else if (cdclk == 266667)
  3875. cmd = 1;
  3876. else
  3877. cmd = 0;
  3878. mutex_lock(&dev_priv->rps.hw_lock);
  3879. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3880. val &= ~DSPFREQGUAR_MASK;
  3881. val |= (cmd << DSPFREQGUAR_SHIFT);
  3882. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3883. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3884. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3885. 50)) {
  3886. DRM_ERROR("timed out waiting for CDclk change\n");
  3887. }
  3888. mutex_unlock(&dev_priv->rps.hw_lock);
  3889. if (cdclk == 400000) {
  3890. u32 divider, vco;
  3891. vco = valleyview_get_vco(dev_priv);
  3892. divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1;
  3893. mutex_lock(&dev_priv->dpio_lock);
  3894. /* adjust cdclk divider */
  3895. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3896. val &= ~DISPLAY_FREQUENCY_VALUES;
  3897. val |= divider;
  3898. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3899. if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
  3900. DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  3901. 50))
  3902. DRM_ERROR("timed out waiting for CDclk change\n");
  3903. mutex_unlock(&dev_priv->dpio_lock);
  3904. }
  3905. mutex_lock(&dev_priv->dpio_lock);
  3906. /* adjust self-refresh exit latency value */
  3907. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3908. val &= ~0x7f;
  3909. /*
  3910. * For high bandwidth configs, we set a higher latency in the bunit
  3911. * so that the core display fetch happens in time to avoid underruns.
  3912. */
  3913. if (cdclk == 400000)
  3914. val |= 4500 / 250; /* 4.5 usec */
  3915. else
  3916. val |= 3000 / 250; /* 3.0 usec */
  3917. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3918. mutex_unlock(&dev_priv->dpio_lock);
  3919. vlv_update_cdclk(dev);
  3920. }
  3921. static void cherryview_set_cdclk(struct drm_device *dev, int cdclk)
  3922. {
  3923. struct drm_i915_private *dev_priv = dev->dev_private;
  3924. u32 val, cmd;
  3925. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3926. switch (cdclk) {
  3927. case 400000:
  3928. cmd = 3;
  3929. break;
  3930. case 333333:
  3931. case 320000:
  3932. cmd = 2;
  3933. break;
  3934. case 266667:
  3935. cmd = 1;
  3936. break;
  3937. case 200000:
  3938. cmd = 0;
  3939. break;
  3940. default:
  3941. WARN_ON(1);
  3942. return;
  3943. }
  3944. mutex_lock(&dev_priv->rps.hw_lock);
  3945. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3946. val &= ~DSPFREQGUAR_MASK_CHV;
  3947. val |= (cmd << DSPFREQGUAR_SHIFT_CHV);
  3948. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3949. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3950. DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV),
  3951. 50)) {
  3952. DRM_ERROR("timed out waiting for CDclk change\n");
  3953. }
  3954. mutex_unlock(&dev_priv->rps.hw_lock);
  3955. vlv_update_cdclk(dev);
  3956. }
  3957. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3958. int max_pixclk)
  3959. {
  3960. int vco = valleyview_get_vco(dev_priv);
  3961. int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000;
  3962. /* FIXME: Punit isn't quite ready yet */
  3963. if (IS_CHERRYVIEW(dev_priv->dev))
  3964. return 400000;
  3965. /*
  3966. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3967. * 200MHz
  3968. * 267MHz
  3969. * 320/333MHz (depends on HPLL freq)
  3970. * 400MHz
  3971. * So we check to see whether we're above 90% of the lower bin and
  3972. * adjust if needed.
  3973. *
  3974. * We seem to get an unstable or solid color picture at 200MHz.
  3975. * Not sure what's wrong. For now use 200MHz only when all pipes
  3976. * are off.
  3977. */
  3978. if (max_pixclk > freq_320*9/10)
  3979. return 400000;
  3980. else if (max_pixclk > 266667*9/10)
  3981. return freq_320;
  3982. else if (max_pixclk > 0)
  3983. return 266667;
  3984. else
  3985. return 200000;
  3986. }
  3987. /* compute the max pixel clock for new configuration */
  3988. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3989. {
  3990. struct drm_device *dev = dev_priv->dev;
  3991. struct intel_crtc *intel_crtc;
  3992. int max_pixclk = 0;
  3993. for_each_intel_crtc(dev, intel_crtc) {
  3994. if (intel_crtc->new_enabled)
  3995. max_pixclk = max(max_pixclk,
  3996. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3997. }
  3998. return max_pixclk;
  3999. }
  4000. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  4001. unsigned *prepare_pipes)
  4002. {
  4003. struct drm_i915_private *dev_priv = dev->dev_private;
  4004. struct intel_crtc *intel_crtc;
  4005. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4006. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  4007. dev_priv->vlv_cdclk_freq)
  4008. return;
  4009. /* disable/enable all currently active pipes while we change cdclk */
  4010. for_each_intel_crtc(dev, intel_crtc)
  4011. if (intel_crtc->base.enabled)
  4012. *prepare_pipes |= (1 << intel_crtc->pipe);
  4013. }
  4014. static void valleyview_modeset_global_resources(struct drm_device *dev)
  4015. {
  4016. struct drm_i915_private *dev_priv = dev->dev_private;
  4017. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4018. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  4019. if (req_cdclk != dev_priv->vlv_cdclk_freq) {
  4020. if (IS_CHERRYVIEW(dev))
  4021. cherryview_set_cdclk(dev, req_cdclk);
  4022. else
  4023. valleyview_set_cdclk(dev, req_cdclk);
  4024. }
  4025. modeset_update_crtc_power_domains(dev);
  4026. }
  4027. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  4028. {
  4029. struct drm_device *dev = crtc->dev;
  4030. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4031. struct intel_encoder *encoder;
  4032. int pipe = intel_crtc->pipe;
  4033. bool is_dsi;
  4034. WARN_ON(!crtc->enabled);
  4035. if (intel_crtc->active)
  4036. return;
  4037. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  4038. if (!is_dsi) {
  4039. if (IS_CHERRYVIEW(dev))
  4040. chv_prepare_pll(intel_crtc);
  4041. else
  4042. vlv_prepare_pll(intel_crtc);
  4043. }
  4044. if (intel_crtc->config.has_dp_encoder)
  4045. intel_dp_set_m_n(intel_crtc);
  4046. intel_set_pipe_timings(intel_crtc);
  4047. i9xx_set_pipeconf(intel_crtc);
  4048. intel_crtc->active = true;
  4049. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4050. for_each_encoder_on_crtc(dev, crtc, encoder)
  4051. if (encoder->pre_pll_enable)
  4052. encoder->pre_pll_enable(encoder);
  4053. if (!is_dsi) {
  4054. if (IS_CHERRYVIEW(dev))
  4055. chv_enable_pll(intel_crtc);
  4056. else
  4057. vlv_enable_pll(intel_crtc);
  4058. }
  4059. for_each_encoder_on_crtc(dev, crtc, encoder)
  4060. if (encoder->pre_enable)
  4061. encoder->pre_enable(encoder);
  4062. i9xx_pfit_enable(intel_crtc);
  4063. intel_crtc_load_lut(crtc);
  4064. intel_update_watermarks(crtc);
  4065. intel_enable_pipe(intel_crtc);
  4066. for_each_encoder_on_crtc(dev, crtc, encoder)
  4067. encoder->enable(encoder);
  4068. intel_crtc_enable_planes(crtc);
  4069. /* Underruns don't raise interrupts, so check manually. */
  4070. i9xx_check_fifo_underruns(dev);
  4071. }
  4072. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  4073. {
  4074. struct drm_device *dev = crtc->base.dev;
  4075. struct drm_i915_private *dev_priv = dev->dev_private;
  4076. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  4077. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  4078. }
  4079. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  4080. {
  4081. struct drm_device *dev = crtc->dev;
  4082. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4083. struct intel_encoder *encoder;
  4084. int pipe = intel_crtc->pipe;
  4085. WARN_ON(!crtc->enabled);
  4086. if (intel_crtc->active)
  4087. return;
  4088. i9xx_set_pll_dividers(intel_crtc);
  4089. if (intel_crtc->config.has_dp_encoder)
  4090. intel_dp_set_m_n(intel_crtc);
  4091. intel_set_pipe_timings(intel_crtc);
  4092. i9xx_set_pipeconf(intel_crtc);
  4093. intel_crtc->active = true;
  4094. if (!IS_GEN2(dev))
  4095. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4096. for_each_encoder_on_crtc(dev, crtc, encoder)
  4097. if (encoder->pre_enable)
  4098. encoder->pre_enable(encoder);
  4099. i9xx_enable_pll(intel_crtc);
  4100. i9xx_pfit_enable(intel_crtc);
  4101. intel_crtc_load_lut(crtc);
  4102. intel_update_watermarks(crtc);
  4103. intel_enable_pipe(intel_crtc);
  4104. for_each_encoder_on_crtc(dev, crtc, encoder)
  4105. encoder->enable(encoder);
  4106. intel_crtc_enable_planes(crtc);
  4107. /*
  4108. * Gen2 reports pipe underruns whenever all planes are disabled.
  4109. * So don't enable underrun reporting before at least some planes
  4110. * are enabled.
  4111. * FIXME: Need to fix the logic to work when we turn off all planes
  4112. * but leave the pipe running.
  4113. */
  4114. if (IS_GEN2(dev))
  4115. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4116. /* Underruns don't raise interrupts, so check manually. */
  4117. i9xx_check_fifo_underruns(dev);
  4118. }
  4119. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  4120. {
  4121. struct drm_device *dev = crtc->base.dev;
  4122. struct drm_i915_private *dev_priv = dev->dev_private;
  4123. if (!crtc->config.gmch_pfit.control)
  4124. return;
  4125. assert_pipe_disabled(dev_priv, crtc->pipe);
  4126. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  4127. I915_READ(PFIT_CONTROL));
  4128. I915_WRITE(PFIT_CONTROL, 0);
  4129. }
  4130. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4131. {
  4132. struct drm_device *dev = crtc->dev;
  4133. struct drm_i915_private *dev_priv = dev->dev_private;
  4134. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4135. struct intel_encoder *encoder;
  4136. int pipe = intel_crtc->pipe;
  4137. if (!intel_crtc->active)
  4138. return;
  4139. /*
  4140. * Gen2 reports pipe underruns whenever all planes are disabled.
  4141. * So diasble underrun reporting before all the planes get disabled.
  4142. * FIXME: Need to fix the logic to work when we turn off all planes
  4143. * but leave the pipe running.
  4144. */
  4145. if (IS_GEN2(dev))
  4146. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4147. /*
  4148. * Vblank time updates from the shadow to live plane control register
  4149. * are blocked if the memory self-refresh mode is active at that
  4150. * moment. So to make sure the plane gets truly disabled, disable
  4151. * first the self-refresh mode. The self-refresh enable bit in turn
  4152. * will be checked/applied by the HW only at the next frame start
  4153. * event which is after the vblank start event, so we need to have a
  4154. * wait-for-vblank between disabling the plane and the pipe.
  4155. */
  4156. intel_set_memory_cxsr(dev_priv, false);
  4157. intel_crtc_disable_planes(crtc);
  4158. for_each_encoder_on_crtc(dev, crtc, encoder)
  4159. encoder->disable(encoder);
  4160. /*
  4161. * On gen2 planes are double buffered but the pipe isn't, so we must
  4162. * wait for planes to fully turn off before disabling the pipe.
  4163. * We also need to wait on all gmch platforms because of the
  4164. * self-refresh mode constraint explained above.
  4165. */
  4166. intel_wait_for_vblank(dev, pipe);
  4167. intel_disable_pipe(intel_crtc);
  4168. i9xx_pfit_disable(intel_crtc);
  4169. for_each_encoder_on_crtc(dev, crtc, encoder)
  4170. if (encoder->post_disable)
  4171. encoder->post_disable(encoder);
  4172. if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) {
  4173. if (IS_CHERRYVIEW(dev))
  4174. chv_disable_pll(dev_priv, pipe);
  4175. else if (IS_VALLEYVIEW(dev))
  4176. vlv_disable_pll(dev_priv, pipe);
  4177. else
  4178. i9xx_disable_pll(intel_crtc);
  4179. }
  4180. if (!IS_GEN2(dev))
  4181. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4182. intel_crtc->active = false;
  4183. intel_update_watermarks(crtc);
  4184. mutex_lock(&dev->struct_mutex);
  4185. intel_update_fbc(dev);
  4186. mutex_unlock(&dev->struct_mutex);
  4187. }
  4188. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4189. {
  4190. }
  4191. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4192. bool enabled)
  4193. {
  4194. struct drm_device *dev = crtc->dev;
  4195. struct drm_i915_master_private *master_priv;
  4196. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4197. int pipe = intel_crtc->pipe;
  4198. if (!dev->primary->master)
  4199. return;
  4200. master_priv = dev->primary->master->driver_priv;
  4201. if (!master_priv->sarea_priv)
  4202. return;
  4203. switch (pipe) {
  4204. case 0:
  4205. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4206. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4207. break;
  4208. case 1:
  4209. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4210. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4211. break;
  4212. default:
  4213. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4214. break;
  4215. }
  4216. }
  4217. /* Master function to enable/disable CRTC and corresponding power wells */
  4218. void intel_crtc_control(struct drm_crtc *crtc, bool enable)
  4219. {
  4220. struct drm_device *dev = crtc->dev;
  4221. struct drm_i915_private *dev_priv = dev->dev_private;
  4222. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4223. enum intel_display_power_domain domain;
  4224. unsigned long domains;
  4225. if (enable) {
  4226. if (!intel_crtc->active) {
  4227. domains = get_crtc_power_domains(crtc);
  4228. for_each_power_domain(domain, domains)
  4229. intel_display_power_get(dev_priv, domain);
  4230. intel_crtc->enabled_power_domains = domains;
  4231. dev_priv->display.crtc_enable(crtc);
  4232. }
  4233. } else {
  4234. if (intel_crtc->active) {
  4235. dev_priv->display.crtc_disable(crtc);
  4236. domains = intel_crtc->enabled_power_domains;
  4237. for_each_power_domain(domain, domains)
  4238. intel_display_power_put(dev_priv, domain);
  4239. intel_crtc->enabled_power_domains = 0;
  4240. }
  4241. }
  4242. }
  4243. /**
  4244. * Sets the power management mode of the pipe and plane.
  4245. */
  4246. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4247. {
  4248. struct drm_device *dev = crtc->dev;
  4249. struct intel_encoder *intel_encoder;
  4250. bool enable = false;
  4251. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4252. enable |= intel_encoder->connectors_active;
  4253. intel_crtc_control(crtc, enable);
  4254. intel_crtc_update_sarea(crtc, enable);
  4255. }
  4256. static void intel_crtc_disable(struct drm_crtc *crtc)
  4257. {
  4258. struct drm_device *dev = crtc->dev;
  4259. struct drm_connector *connector;
  4260. struct drm_i915_private *dev_priv = dev->dev_private;
  4261. struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb);
  4262. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4263. /* crtc should still be enabled when we disable it. */
  4264. WARN_ON(!crtc->enabled);
  4265. dev_priv->display.crtc_disable(crtc);
  4266. intel_crtc_update_sarea(crtc, false);
  4267. dev_priv->display.off(crtc);
  4268. if (crtc->primary->fb) {
  4269. mutex_lock(&dev->struct_mutex);
  4270. intel_unpin_fb_obj(old_obj);
  4271. i915_gem_track_fb(old_obj, NULL,
  4272. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4273. mutex_unlock(&dev->struct_mutex);
  4274. crtc->primary->fb = NULL;
  4275. }
  4276. /* Update computed state. */
  4277. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4278. if (!connector->encoder || !connector->encoder->crtc)
  4279. continue;
  4280. if (connector->encoder->crtc != crtc)
  4281. continue;
  4282. connector->dpms = DRM_MODE_DPMS_OFF;
  4283. to_intel_encoder(connector->encoder)->connectors_active = false;
  4284. }
  4285. }
  4286. void intel_encoder_destroy(struct drm_encoder *encoder)
  4287. {
  4288. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4289. drm_encoder_cleanup(encoder);
  4290. kfree(intel_encoder);
  4291. }
  4292. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4293. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4294. * state of the entire output pipe. */
  4295. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4296. {
  4297. if (mode == DRM_MODE_DPMS_ON) {
  4298. encoder->connectors_active = true;
  4299. intel_crtc_update_dpms(encoder->base.crtc);
  4300. } else {
  4301. encoder->connectors_active = false;
  4302. intel_crtc_update_dpms(encoder->base.crtc);
  4303. }
  4304. }
  4305. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4306. * internal consistency). */
  4307. static void intel_connector_check_state(struct intel_connector *connector)
  4308. {
  4309. if (connector->get_hw_state(connector)) {
  4310. struct intel_encoder *encoder = connector->encoder;
  4311. struct drm_crtc *crtc;
  4312. bool encoder_enabled;
  4313. enum pipe pipe;
  4314. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4315. connector->base.base.id,
  4316. connector->base.name);
  4317. /* there is no real hw state for MST connectors */
  4318. if (connector->mst_port)
  4319. return;
  4320. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4321. "wrong connector dpms state\n");
  4322. WARN(connector->base.encoder != &encoder->base,
  4323. "active connector not linked to encoder\n");
  4324. if (encoder) {
  4325. WARN(!encoder->connectors_active,
  4326. "encoder->connectors_active not set\n");
  4327. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4328. WARN(!encoder_enabled, "encoder not enabled\n");
  4329. if (WARN_ON(!encoder->base.crtc))
  4330. return;
  4331. crtc = encoder->base.crtc;
  4332. WARN(!crtc->enabled, "crtc not enabled\n");
  4333. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4334. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4335. "encoder active on the wrong pipe\n");
  4336. }
  4337. }
  4338. }
  4339. /* Even simpler default implementation, if there's really no special case to
  4340. * consider. */
  4341. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4342. {
  4343. /* All the simple cases only support two dpms states. */
  4344. if (mode != DRM_MODE_DPMS_ON)
  4345. mode = DRM_MODE_DPMS_OFF;
  4346. if (mode == connector->dpms)
  4347. return;
  4348. connector->dpms = mode;
  4349. /* Only need to change hw state when actually enabled */
  4350. if (connector->encoder)
  4351. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4352. intel_modeset_check_state(connector->dev);
  4353. }
  4354. /* Simple connector->get_hw_state implementation for encoders that support only
  4355. * one connector and no cloning and hence the encoder state determines the state
  4356. * of the connector. */
  4357. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4358. {
  4359. enum pipe pipe = 0;
  4360. struct intel_encoder *encoder = connector->encoder;
  4361. return encoder->get_hw_state(encoder, &pipe);
  4362. }
  4363. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4364. struct intel_crtc_config *pipe_config)
  4365. {
  4366. struct drm_i915_private *dev_priv = dev->dev_private;
  4367. struct intel_crtc *pipe_B_crtc =
  4368. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4369. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4370. pipe_name(pipe), pipe_config->fdi_lanes);
  4371. if (pipe_config->fdi_lanes > 4) {
  4372. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4373. pipe_name(pipe), pipe_config->fdi_lanes);
  4374. return false;
  4375. }
  4376. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4377. if (pipe_config->fdi_lanes > 2) {
  4378. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4379. pipe_config->fdi_lanes);
  4380. return false;
  4381. } else {
  4382. return true;
  4383. }
  4384. }
  4385. if (INTEL_INFO(dev)->num_pipes == 2)
  4386. return true;
  4387. /* Ivybridge 3 pipe is really complicated */
  4388. switch (pipe) {
  4389. case PIPE_A:
  4390. return true;
  4391. case PIPE_B:
  4392. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4393. pipe_config->fdi_lanes > 2) {
  4394. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4395. pipe_name(pipe), pipe_config->fdi_lanes);
  4396. return false;
  4397. }
  4398. return true;
  4399. case PIPE_C:
  4400. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4401. pipe_B_crtc->config.fdi_lanes <= 2) {
  4402. if (pipe_config->fdi_lanes > 2) {
  4403. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4404. pipe_name(pipe), pipe_config->fdi_lanes);
  4405. return false;
  4406. }
  4407. } else {
  4408. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4409. return false;
  4410. }
  4411. return true;
  4412. default:
  4413. BUG();
  4414. }
  4415. }
  4416. #define RETRY 1
  4417. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4418. struct intel_crtc_config *pipe_config)
  4419. {
  4420. struct drm_device *dev = intel_crtc->base.dev;
  4421. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4422. int lane, link_bw, fdi_dotclock;
  4423. bool setup_ok, needs_recompute = false;
  4424. retry:
  4425. /* FDI is a binary signal running at ~2.7GHz, encoding
  4426. * each output octet as 10 bits. The actual frequency
  4427. * is stored as a divider into a 100MHz clock, and the
  4428. * mode pixel clock is stored in units of 1KHz.
  4429. * Hence the bw of each lane in terms of the mode signal
  4430. * is:
  4431. */
  4432. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4433. fdi_dotclock = adjusted_mode->crtc_clock;
  4434. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4435. pipe_config->pipe_bpp);
  4436. pipe_config->fdi_lanes = lane;
  4437. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4438. link_bw, &pipe_config->fdi_m_n);
  4439. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4440. intel_crtc->pipe, pipe_config);
  4441. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4442. pipe_config->pipe_bpp -= 2*3;
  4443. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4444. pipe_config->pipe_bpp);
  4445. needs_recompute = true;
  4446. pipe_config->bw_constrained = true;
  4447. goto retry;
  4448. }
  4449. if (needs_recompute)
  4450. return RETRY;
  4451. return setup_ok ? 0 : -EINVAL;
  4452. }
  4453. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4454. struct intel_crtc_config *pipe_config)
  4455. {
  4456. pipe_config->ips_enabled = i915.enable_ips &&
  4457. hsw_crtc_supports_ips(crtc) &&
  4458. pipe_config->pipe_bpp <= 24;
  4459. }
  4460. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4461. struct intel_crtc_config *pipe_config)
  4462. {
  4463. struct drm_device *dev = crtc->base.dev;
  4464. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4465. /* FIXME should check pixel clock limits on all platforms */
  4466. if (INTEL_INFO(dev)->gen < 4) {
  4467. struct drm_i915_private *dev_priv = dev->dev_private;
  4468. int clock_limit =
  4469. dev_priv->display.get_display_clock_speed(dev);
  4470. /*
  4471. * Enable pixel doubling when the dot clock
  4472. * is > 90% of the (display) core speed.
  4473. *
  4474. * GDG double wide on either pipe,
  4475. * otherwise pipe A only.
  4476. */
  4477. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4478. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4479. clock_limit *= 2;
  4480. pipe_config->double_wide = true;
  4481. }
  4482. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4483. return -EINVAL;
  4484. }
  4485. /*
  4486. * Pipe horizontal size must be even in:
  4487. * - DVO ganged mode
  4488. * - LVDS dual channel mode
  4489. * - Double wide pipe
  4490. */
  4491. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4492. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4493. pipe_config->pipe_src_w &= ~1;
  4494. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4495. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4496. */
  4497. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4498. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4499. return -EINVAL;
  4500. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4501. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4502. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4503. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4504. * for lvds. */
  4505. pipe_config->pipe_bpp = 8*3;
  4506. }
  4507. if (HAS_IPS(dev))
  4508. hsw_compute_ips_config(crtc, pipe_config);
  4509. /*
  4510. * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the
  4511. * old clock survives for now.
  4512. */
  4513. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev) || HAS_DDI(dev))
  4514. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4515. if (pipe_config->has_pch_encoder)
  4516. return ironlake_fdi_compute_config(crtc, pipe_config);
  4517. return 0;
  4518. }
  4519. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4520. {
  4521. struct drm_i915_private *dev_priv = dev->dev_private;
  4522. int vco = valleyview_get_vco(dev_priv);
  4523. u32 val;
  4524. int divider;
  4525. /* FIXME: Punit isn't quite ready yet */
  4526. if (IS_CHERRYVIEW(dev))
  4527. return 400000;
  4528. mutex_lock(&dev_priv->dpio_lock);
  4529. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  4530. mutex_unlock(&dev_priv->dpio_lock);
  4531. divider = val & DISPLAY_FREQUENCY_VALUES;
  4532. WARN((val & DISPLAY_FREQUENCY_STATUS) !=
  4533. (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  4534. "cdclk change in progress\n");
  4535. return DIV_ROUND_CLOSEST(vco << 1, divider + 1);
  4536. }
  4537. static int i945_get_display_clock_speed(struct drm_device *dev)
  4538. {
  4539. return 400000;
  4540. }
  4541. static int i915_get_display_clock_speed(struct drm_device *dev)
  4542. {
  4543. return 333000;
  4544. }
  4545. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4546. {
  4547. return 200000;
  4548. }
  4549. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4550. {
  4551. u16 gcfgc = 0;
  4552. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4553. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4554. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4555. return 267000;
  4556. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4557. return 333000;
  4558. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4559. return 444000;
  4560. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4561. return 200000;
  4562. default:
  4563. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4564. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4565. return 133000;
  4566. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4567. return 167000;
  4568. }
  4569. }
  4570. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4571. {
  4572. u16 gcfgc = 0;
  4573. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4574. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4575. return 133000;
  4576. else {
  4577. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4578. case GC_DISPLAY_CLOCK_333_MHZ:
  4579. return 333000;
  4580. default:
  4581. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4582. return 190000;
  4583. }
  4584. }
  4585. }
  4586. static int i865_get_display_clock_speed(struct drm_device *dev)
  4587. {
  4588. return 266000;
  4589. }
  4590. static int i855_get_display_clock_speed(struct drm_device *dev)
  4591. {
  4592. u16 hpllcc = 0;
  4593. /* Assume that the hardware is in the high speed state. This
  4594. * should be the default.
  4595. */
  4596. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4597. case GC_CLOCK_133_200:
  4598. case GC_CLOCK_100_200:
  4599. return 200000;
  4600. case GC_CLOCK_166_250:
  4601. return 250000;
  4602. case GC_CLOCK_100_133:
  4603. return 133000;
  4604. }
  4605. /* Shouldn't happen */
  4606. return 0;
  4607. }
  4608. static int i830_get_display_clock_speed(struct drm_device *dev)
  4609. {
  4610. return 133000;
  4611. }
  4612. static void
  4613. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4614. {
  4615. while (*num > DATA_LINK_M_N_MASK ||
  4616. *den > DATA_LINK_M_N_MASK) {
  4617. *num >>= 1;
  4618. *den >>= 1;
  4619. }
  4620. }
  4621. static void compute_m_n(unsigned int m, unsigned int n,
  4622. uint32_t *ret_m, uint32_t *ret_n)
  4623. {
  4624. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4625. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4626. intel_reduce_m_n_ratio(ret_m, ret_n);
  4627. }
  4628. void
  4629. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4630. int pixel_clock, int link_clock,
  4631. struct intel_link_m_n *m_n)
  4632. {
  4633. m_n->tu = 64;
  4634. compute_m_n(bits_per_pixel * pixel_clock,
  4635. link_clock * nlanes * 8,
  4636. &m_n->gmch_m, &m_n->gmch_n);
  4637. compute_m_n(pixel_clock, link_clock,
  4638. &m_n->link_m, &m_n->link_n);
  4639. }
  4640. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4641. {
  4642. if (i915.panel_use_ssc >= 0)
  4643. return i915.panel_use_ssc != 0;
  4644. return dev_priv->vbt.lvds_use_ssc
  4645. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4646. }
  4647. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4648. {
  4649. struct drm_device *dev = crtc->dev;
  4650. struct drm_i915_private *dev_priv = dev->dev_private;
  4651. int refclk;
  4652. if (IS_VALLEYVIEW(dev)) {
  4653. refclk = 100000;
  4654. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4655. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4656. refclk = dev_priv->vbt.lvds_ssc_freq;
  4657. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4658. } else if (!IS_GEN2(dev)) {
  4659. refclk = 96000;
  4660. } else {
  4661. refclk = 48000;
  4662. }
  4663. return refclk;
  4664. }
  4665. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4666. {
  4667. return (1 << dpll->n) << 16 | dpll->m2;
  4668. }
  4669. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4670. {
  4671. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4672. }
  4673. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4674. intel_clock_t *reduced_clock)
  4675. {
  4676. struct drm_device *dev = crtc->base.dev;
  4677. u32 fp, fp2 = 0;
  4678. if (IS_PINEVIEW(dev)) {
  4679. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4680. if (reduced_clock)
  4681. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4682. } else {
  4683. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4684. if (reduced_clock)
  4685. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4686. }
  4687. crtc->config.dpll_hw_state.fp0 = fp;
  4688. crtc->lowfreq_avail = false;
  4689. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4690. reduced_clock && i915.powersave) {
  4691. crtc->config.dpll_hw_state.fp1 = fp2;
  4692. crtc->lowfreq_avail = true;
  4693. } else {
  4694. crtc->config.dpll_hw_state.fp1 = fp;
  4695. }
  4696. }
  4697. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4698. pipe)
  4699. {
  4700. u32 reg_val;
  4701. /*
  4702. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4703. * and set it to a reasonable value instead.
  4704. */
  4705. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4706. reg_val &= 0xffffff00;
  4707. reg_val |= 0x00000030;
  4708. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4709. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4710. reg_val &= 0x8cffffff;
  4711. reg_val = 0x8c000000;
  4712. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4713. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4714. reg_val &= 0xffffff00;
  4715. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4716. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4717. reg_val &= 0x00ffffff;
  4718. reg_val |= 0xb0000000;
  4719. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4720. }
  4721. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4722. struct intel_link_m_n *m_n)
  4723. {
  4724. struct drm_device *dev = crtc->base.dev;
  4725. struct drm_i915_private *dev_priv = dev->dev_private;
  4726. int pipe = crtc->pipe;
  4727. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4728. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4729. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4730. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4731. }
  4732. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4733. struct intel_link_m_n *m_n,
  4734. struct intel_link_m_n *m2_n2)
  4735. {
  4736. struct drm_device *dev = crtc->base.dev;
  4737. struct drm_i915_private *dev_priv = dev->dev_private;
  4738. int pipe = crtc->pipe;
  4739. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4740. if (INTEL_INFO(dev)->gen >= 5) {
  4741. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4742. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4743. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4744. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4745. /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
  4746. * for gen < 8) and if DRRS is supported (to make sure the
  4747. * registers are not unnecessarily accessed).
  4748. */
  4749. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  4750. crtc->config.has_drrs) {
  4751. I915_WRITE(PIPE_DATA_M2(transcoder),
  4752. TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
  4753. I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
  4754. I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
  4755. I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
  4756. }
  4757. } else {
  4758. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4759. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4760. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4761. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4762. }
  4763. }
  4764. void intel_dp_set_m_n(struct intel_crtc *crtc)
  4765. {
  4766. if (crtc->config.has_pch_encoder)
  4767. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4768. else
  4769. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n,
  4770. &crtc->config.dp_m2_n2);
  4771. }
  4772. static void vlv_update_pll(struct intel_crtc *crtc)
  4773. {
  4774. u32 dpll, dpll_md;
  4775. /*
  4776. * Enable DPIO clock input. We should never disable the reference
  4777. * clock for pipe B, since VGA hotplug / manual detection depends
  4778. * on it.
  4779. */
  4780. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4781. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4782. /* We should never disable this, set it here for state tracking */
  4783. if (crtc->pipe == PIPE_B)
  4784. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4785. dpll |= DPLL_VCO_ENABLE;
  4786. crtc->config.dpll_hw_state.dpll = dpll;
  4787. dpll_md = (crtc->config.pixel_multiplier - 1)
  4788. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4789. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4790. }
  4791. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4792. {
  4793. struct drm_device *dev = crtc->base.dev;
  4794. struct drm_i915_private *dev_priv = dev->dev_private;
  4795. int pipe = crtc->pipe;
  4796. u32 mdiv;
  4797. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4798. u32 coreclk, reg_val;
  4799. mutex_lock(&dev_priv->dpio_lock);
  4800. bestn = crtc->config.dpll.n;
  4801. bestm1 = crtc->config.dpll.m1;
  4802. bestm2 = crtc->config.dpll.m2;
  4803. bestp1 = crtc->config.dpll.p1;
  4804. bestp2 = crtc->config.dpll.p2;
  4805. /* See eDP HDMI DPIO driver vbios notes doc */
  4806. /* PLL B needs special handling */
  4807. if (pipe == PIPE_B)
  4808. vlv_pllb_recal_opamp(dev_priv, pipe);
  4809. /* Set up Tx target for periodic Rcomp update */
  4810. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4811. /* Disable target IRef on PLL */
  4812. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4813. reg_val &= 0x00ffffff;
  4814. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4815. /* Disable fast lock */
  4816. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4817. /* Set idtafcrecal before PLL is enabled */
  4818. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4819. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4820. mdiv |= ((bestn << DPIO_N_SHIFT));
  4821. mdiv |= (1 << DPIO_K_SHIFT);
  4822. /*
  4823. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4824. * but we don't support that).
  4825. * Note: don't use the DAC post divider as it seems unstable.
  4826. */
  4827. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4828. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4829. mdiv |= DPIO_ENABLE_CALIBRATION;
  4830. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4831. /* Set HBR and RBR LPF coefficients */
  4832. if (crtc->config.port_clock == 162000 ||
  4833. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4834. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4835. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4836. 0x009f0003);
  4837. else
  4838. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4839. 0x00d0000f);
  4840. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4841. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4842. /* Use SSC source */
  4843. if (pipe == PIPE_A)
  4844. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4845. 0x0df40000);
  4846. else
  4847. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4848. 0x0df70000);
  4849. } else { /* HDMI or VGA */
  4850. /* Use bend source */
  4851. if (pipe == PIPE_A)
  4852. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4853. 0x0df70000);
  4854. else
  4855. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4856. 0x0df40000);
  4857. }
  4858. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4859. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4860. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4861. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4862. coreclk |= 0x01000000;
  4863. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4864. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4865. mutex_unlock(&dev_priv->dpio_lock);
  4866. }
  4867. static void chv_update_pll(struct intel_crtc *crtc)
  4868. {
  4869. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4870. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4871. DPLL_VCO_ENABLE;
  4872. if (crtc->pipe != PIPE_A)
  4873. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4874. crtc->config.dpll_hw_state.dpll_md =
  4875. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4876. }
  4877. static void chv_prepare_pll(struct intel_crtc *crtc)
  4878. {
  4879. struct drm_device *dev = crtc->base.dev;
  4880. struct drm_i915_private *dev_priv = dev->dev_private;
  4881. int pipe = crtc->pipe;
  4882. int dpll_reg = DPLL(crtc->pipe);
  4883. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4884. u32 loopfilter, intcoeff;
  4885. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4886. int refclk;
  4887. bestn = crtc->config.dpll.n;
  4888. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4889. bestm1 = crtc->config.dpll.m1;
  4890. bestm2 = crtc->config.dpll.m2 >> 22;
  4891. bestp1 = crtc->config.dpll.p1;
  4892. bestp2 = crtc->config.dpll.p2;
  4893. /*
  4894. * Enable Refclk and SSC
  4895. */
  4896. I915_WRITE(dpll_reg,
  4897. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4898. mutex_lock(&dev_priv->dpio_lock);
  4899. /* p1 and p2 divider */
  4900. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4901. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4902. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4903. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4904. 1 << DPIO_CHV_K_DIV_SHIFT);
  4905. /* Feedback post-divider - m2 */
  4906. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4907. /* Feedback refclk divider - n and m1 */
  4908. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4909. DPIO_CHV_M1_DIV_BY_2 |
  4910. 1 << DPIO_CHV_N_DIV_SHIFT);
  4911. /* M2 fraction division */
  4912. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4913. /* M2 fraction division enable */
  4914. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4915. DPIO_CHV_FRAC_DIV_EN |
  4916. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4917. /* Loop filter */
  4918. refclk = i9xx_get_refclk(&crtc->base, 0);
  4919. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4920. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4921. if (refclk == 100000)
  4922. intcoeff = 11;
  4923. else if (refclk == 38400)
  4924. intcoeff = 10;
  4925. else
  4926. intcoeff = 9;
  4927. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4928. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4929. /* AFC Recal */
  4930. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4931. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4932. DPIO_AFC_RECAL);
  4933. mutex_unlock(&dev_priv->dpio_lock);
  4934. }
  4935. static void i9xx_update_pll(struct intel_crtc *crtc,
  4936. intel_clock_t *reduced_clock,
  4937. int num_connectors)
  4938. {
  4939. struct drm_device *dev = crtc->base.dev;
  4940. struct drm_i915_private *dev_priv = dev->dev_private;
  4941. u32 dpll;
  4942. bool is_sdvo;
  4943. struct dpll *clock = &crtc->config.dpll;
  4944. i9xx_update_pll_dividers(crtc, reduced_clock);
  4945. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4946. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4947. dpll = DPLL_VGA_MODE_DIS;
  4948. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4949. dpll |= DPLLB_MODE_LVDS;
  4950. else
  4951. dpll |= DPLLB_MODE_DAC_SERIAL;
  4952. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4953. dpll |= (crtc->config.pixel_multiplier - 1)
  4954. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4955. }
  4956. if (is_sdvo)
  4957. dpll |= DPLL_SDVO_HIGH_SPEED;
  4958. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4959. dpll |= DPLL_SDVO_HIGH_SPEED;
  4960. /* compute bitmask from p1 value */
  4961. if (IS_PINEVIEW(dev))
  4962. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4963. else {
  4964. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4965. if (IS_G4X(dev) && reduced_clock)
  4966. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4967. }
  4968. switch (clock->p2) {
  4969. case 5:
  4970. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4971. break;
  4972. case 7:
  4973. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4974. break;
  4975. case 10:
  4976. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4977. break;
  4978. case 14:
  4979. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4980. break;
  4981. }
  4982. if (INTEL_INFO(dev)->gen >= 4)
  4983. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4984. if (crtc->config.sdvo_tv_clock)
  4985. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4986. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4987. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4988. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4989. else
  4990. dpll |= PLL_REF_INPUT_DREFCLK;
  4991. dpll |= DPLL_VCO_ENABLE;
  4992. crtc->config.dpll_hw_state.dpll = dpll;
  4993. if (INTEL_INFO(dev)->gen >= 4) {
  4994. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4995. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4996. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4997. }
  4998. }
  4999. static void i8xx_update_pll(struct intel_crtc *crtc,
  5000. intel_clock_t *reduced_clock,
  5001. int num_connectors)
  5002. {
  5003. struct drm_device *dev = crtc->base.dev;
  5004. struct drm_i915_private *dev_priv = dev->dev_private;
  5005. u32 dpll;
  5006. struct dpll *clock = &crtc->config.dpll;
  5007. i9xx_update_pll_dividers(crtc, reduced_clock);
  5008. dpll = DPLL_VGA_MODE_DIS;
  5009. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  5010. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5011. } else {
  5012. if (clock->p1 == 2)
  5013. dpll |= PLL_P1_DIVIDE_BY_TWO;
  5014. else
  5015. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5016. if (clock->p2 == 4)
  5017. dpll |= PLL_P2_DIVIDE_BY_4;
  5018. }
  5019. if (!IS_I830(dev) && intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  5020. dpll |= DPLL_DVO_2X_MODE;
  5021. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  5022. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5023. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5024. else
  5025. dpll |= PLL_REF_INPUT_DREFCLK;
  5026. dpll |= DPLL_VCO_ENABLE;
  5027. crtc->config.dpll_hw_state.dpll = dpll;
  5028. }
  5029. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  5030. {
  5031. struct drm_device *dev = intel_crtc->base.dev;
  5032. struct drm_i915_private *dev_priv = dev->dev_private;
  5033. enum pipe pipe = intel_crtc->pipe;
  5034. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5035. struct drm_display_mode *adjusted_mode =
  5036. &intel_crtc->config.adjusted_mode;
  5037. uint32_t crtc_vtotal, crtc_vblank_end;
  5038. int vsyncshift = 0;
  5039. /* We need to be careful not to changed the adjusted mode, for otherwise
  5040. * the hw state checker will get angry at the mismatch. */
  5041. crtc_vtotal = adjusted_mode->crtc_vtotal;
  5042. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  5043. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  5044. /* the chip adds 2 halflines automatically */
  5045. crtc_vtotal -= 1;
  5046. crtc_vblank_end -= 1;
  5047. if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5048. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  5049. else
  5050. vsyncshift = adjusted_mode->crtc_hsync_start -
  5051. adjusted_mode->crtc_htotal / 2;
  5052. if (vsyncshift < 0)
  5053. vsyncshift += adjusted_mode->crtc_htotal;
  5054. }
  5055. if (INTEL_INFO(dev)->gen > 3)
  5056. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  5057. I915_WRITE(HTOTAL(cpu_transcoder),
  5058. (adjusted_mode->crtc_hdisplay - 1) |
  5059. ((adjusted_mode->crtc_htotal - 1) << 16));
  5060. I915_WRITE(HBLANK(cpu_transcoder),
  5061. (adjusted_mode->crtc_hblank_start - 1) |
  5062. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  5063. I915_WRITE(HSYNC(cpu_transcoder),
  5064. (adjusted_mode->crtc_hsync_start - 1) |
  5065. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  5066. I915_WRITE(VTOTAL(cpu_transcoder),
  5067. (adjusted_mode->crtc_vdisplay - 1) |
  5068. ((crtc_vtotal - 1) << 16));
  5069. I915_WRITE(VBLANK(cpu_transcoder),
  5070. (adjusted_mode->crtc_vblank_start - 1) |
  5071. ((crtc_vblank_end - 1) << 16));
  5072. I915_WRITE(VSYNC(cpu_transcoder),
  5073. (adjusted_mode->crtc_vsync_start - 1) |
  5074. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  5075. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  5076. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  5077. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  5078. * bits. */
  5079. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  5080. (pipe == PIPE_B || pipe == PIPE_C))
  5081. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  5082. /* pipesrc controls the size that is scaled from, which should
  5083. * always be the user's requested size.
  5084. */
  5085. I915_WRITE(PIPESRC(pipe),
  5086. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  5087. (intel_crtc->config.pipe_src_h - 1));
  5088. }
  5089. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  5090. struct intel_crtc_config *pipe_config)
  5091. {
  5092. struct drm_device *dev = crtc->base.dev;
  5093. struct drm_i915_private *dev_priv = dev->dev_private;
  5094. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  5095. uint32_t tmp;
  5096. tmp = I915_READ(HTOTAL(cpu_transcoder));
  5097. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  5098. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  5099. tmp = I915_READ(HBLANK(cpu_transcoder));
  5100. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  5101. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  5102. tmp = I915_READ(HSYNC(cpu_transcoder));
  5103. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  5104. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  5105. tmp = I915_READ(VTOTAL(cpu_transcoder));
  5106. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  5107. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  5108. tmp = I915_READ(VBLANK(cpu_transcoder));
  5109. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  5110. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  5111. tmp = I915_READ(VSYNC(cpu_transcoder));
  5112. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  5113. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  5114. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  5115. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  5116. pipe_config->adjusted_mode.crtc_vtotal += 1;
  5117. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  5118. }
  5119. tmp = I915_READ(PIPESRC(crtc->pipe));
  5120. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  5121. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  5122. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  5123. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  5124. }
  5125. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  5126. struct intel_crtc_config *pipe_config)
  5127. {
  5128. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  5129. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  5130. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  5131. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  5132. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  5133. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  5134. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  5135. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  5136. mode->flags = pipe_config->adjusted_mode.flags;
  5137. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  5138. mode->flags |= pipe_config->adjusted_mode.flags;
  5139. }
  5140. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  5141. {
  5142. struct drm_device *dev = intel_crtc->base.dev;
  5143. struct drm_i915_private *dev_priv = dev->dev_private;
  5144. uint32_t pipeconf;
  5145. pipeconf = 0;
  5146. if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  5147. (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  5148. pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
  5149. if (intel_crtc->config.double_wide)
  5150. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5151. /* only g4x and later have fancy bpc/dither controls */
  5152. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5153. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5154. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5155. pipeconf |= PIPECONF_DITHER_EN |
  5156. PIPECONF_DITHER_TYPE_SP;
  5157. switch (intel_crtc->config.pipe_bpp) {
  5158. case 18:
  5159. pipeconf |= PIPECONF_6BPC;
  5160. break;
  5161. case 24:
  5162. pipeconf |= PIPECONF_8BPC;
  5163. break;
  5164. case 30:
  5165. pipeconf |= PIPECONF_10BPC;
  5166. break;
  5167. default:
  5168. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5169. BUG();
  5170. }
  5171. }
  5172. if (HAS_PIPE_CXSR(dev)) {
  5173. if (intel_crtc->lowfreq_avail) {
  5174. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5175. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5176. } else {
  5177. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5178. }
  5179. }
  5180. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5181. if (INTEL_INFO(dev)->gen < 4 ||
  5182. intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5183. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5184. else
  5185. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5186. } else
  5187. pipeconf |= PIPECONF_PROGRESSIVE;
  5188. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5189. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5190. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5191. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5192. }
  5193. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  5194. int x, int y,
  5195. struct drm_framebuffer *fb)
  5196. {
  5197. struct drm_device *dev = crtc->dev;
  5198. struct drm_i915_private *dev_priv = dev->dev_private;
  5199. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5200. int refclk, num_connectors = 0;
  5201. intel_clock_t clock, reduced_clock;
  5202. bool ok, has_reduced_clock = false;
  5203. bool is_lvds = false, is_dsi = false;
  5204. struct intel_encoder *encoder;
  5205. const intel_limit_t *limit;
  5206. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5207. switch (encoder->type) {
  5208. case INTEL_OUTPUT_LVDS:
  5209. is_lvds = true;
  5210. break;
  5211. case INTEL_OUTPUT_DSI:
  5212. is_dsi = true;
  5213. break;
  5214. }
  5215. num_connectors++;
  5216. }
  5217. if (is_dsi)
  5218. return 0;
  5219. if (!intel_crtc->config.clock_set) {
  5220. refclk = i9xx_get_refclk(crtc, num_connectors);
  5221. /*
  5222. * Returns a set of divisors for the desired target clock with
  5223. * the given refclk, or FALSE. The returned values represent
  5224. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5225. * 2) / p1 / p2.
  5226. */
  5227. limit = intel_limit(crtc, refclk);
  5228. ok = dev_priv->display.find_dpll(limit, crtc,
  5229. intel_crtc->config.port_clock,
  5230. refclk, NULL, &clock);
  5231. if (!ok) {
  5232. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5233. return -EINVAL;
  5234. }
  5235. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5236. /*
  5237. * Ensure we match the reduced clock's P to the target
  5238. * clock. If the clocks don't match, we can't switch
  5239. * the display clock by using the FP0/FP1. In such case
  5240. * we will disable the LVDS downclock feature.
  5241. */
  5242. has_reduced_clock =
  5243. dev_priv->display.find_dpll(limit, crtc,
  5244. dev_priv->lvds_downclock,
  5245. refclk, &clock,
  5246. &reduced_clock);
  5247. }
  5248. /* Compat-code for transition, will disappear. */
  5249. intel_crtc->config.dpll.n = clock.n;
  5250. intel_crtc->config.dpll.m1 = clock.m1;
  5251. intel_crtc->config.dpll.m2 = clock.m2;
  5252. intel_crtc->config.dpll.p1 = clock.p1;
  5253. intel_crtc->config.dpll.p2 = clock.p2;
  5254. }
  5255. if (IS_GEN2(dev)) {
  5256. i8xx_update_pll(intel_crtc,
  5257. has_reduced_clock ? &reduced_clock : NULL,
  5258. num_connectors);
  5259. } else if (IS_CHERRYVIEW(dev)) {
  5260. chv_update_pll(intel_crtc);
  5261. } else if (IS_VALLEYVIEW(dev)) {
  5262. vlv_update_pll(intel_crtc);
  5263. } else {
  5264. i9xx_update_pll(intel_crtc,
  5265. has_reduced_clock ? &reduced_clock : NULL,
  5266. num_connectors);
  5267. }
  5268. return 0;
  5269. }
  5270. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5271. struct intel_crtc_config *pipe_config)
  5272. {
  5273. struct drm_device *dev = crtc->base.dev;
  5274. struct drm_i915_private *dev_priv = dev->dev_private;
  5275. uint32_t tmp;
  5276. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5277. return;
  5278. tmp = I915_READ(PFIT_CONTROL);
  5279. if (!(tmp & PFIT_ENABLE))
  5280. return;
  5281. /* Check whether the pfit is attached to our pipe. */
  5282. if (INTEL_INFO(dev)->gen < 4) {
  5283. if (crtc->pipe != PIPE_B)
  5284. return;
  5285. } else {
  5286. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5287. return;
  5288. }
  5289. pipe_config->gmch_pfit.control = tmp;
  5290. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5291. if (INTEL_INFO(dev)->gen < 5)
  5292. pipe_config->gmch_pfit.lvds_border_bits =
  5293. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5294. }
  5295. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5296. struct intel_crtc_config *pipe_config)
  5297. {
  5298. struct drm_device *dev = crtc->base.dev;
  5299. struct drm_i915_private *dev_priv = dev->dev_private;
  5300. int pipe = pipe_config->cpu_transcoder;
  5301. intel_clock_t clock;
  5302. u32 mdiv;
  5303. int refclk = 100000;
  5304. /* In case of MIPI DPLL will not even be used */
  5305. if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE))
  5306. return;
  5307. mutex_lock(&dev_priv->dpio_lock);
  5308. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5309. mutex_unlock(&dev_priv->dpio_lock);
  5310. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5311. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5312. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5313. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5314. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5315. vlv_clock(refclk, &clock);
  5316. /* clock.dot is the fast clock */
  5317. pipe_config->port_clock = clock.dot / 5;
  5318. }
  5319. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5320. struct intel_plane_config *plane_config)
  5321. {
  5322. struct drm_device *dev = crtc->base.dev;
  5323. struct drm_i915_private *dev_priv = dev->dev_private;
  5324. u32 val, base, offset;
  5325. int pipe = crtc->pipe, plane = crtc->plane;
  5326. int fourcc, pixel_format;
  5327. int aligned_height;
  5328. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5329. if (!crtc->base.primary->fb) {
  5330. DRM_DEBUG_KMS("failed to alloc fb\n");
  5331. return;
  5332. }
  5333. val = I915_READ(DSPCNTR(plane));
  5334. if (INTEL_INFO(dev)->gen >= 4)
  5335. if (val & DISPPLANE_TILED)
  5336. plane_config->tiled = true;
  5337. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5338. fourcc = intel_format_to_fourcc(pixel_format);
  5339. crtc->base.primary->fb->pixel_format = fourcc;
  5340. crtc->base.primary->fb->bits_per_pixel =
  5341. drm_format_plane_cpp(fourcc, 0) * 8;
  5342. if (INTEL_INFO(dev)->gen >= 4) {
  5343. if (plane_config->tiled)
  5344. offset = I915_READ(DSPTILEOFF(plane));
  5345. else
  5346. offset = I915_READ(DSPLINOFF(plane));
  5347. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5348. } else {
  5349. base = I915_READ(DSPADDR(plane));
  5350. }
  5351. plane_config->base = base;
  5352. val = I915_READ(PIPESRC(pipe));
  5353. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5354. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5355. val = I915_READ(DSPSTRIDE(pipe));
  5356. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  5357. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5358. plane_config->tiled);
  5359. plane_config->size = crtc->base.primary->fb->pitches[0] * aligned_height;
  5360. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5361. pipe, plane, crtc->base.primary->fb->width,
  5362. crtc->base.primary->fb->height,
  5363. crtc->base.primary->fb->bits_per_pixel, base,
  5364. crtc->base.primary->fb->pitches[0],
  5365. plane_config->size);
  5366. }
  5367. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5368. struct intel_crtc_config *pipe_config)
  5369. {
  5370. struct drm_device *dev = crtc->base.dev;
  5371. struct drm_i915_private *dev_priv = dev->dev_private;
  5372. int pipe = pipe_config->cpu_transcoder;
  5373. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5374. intel_clock_t clock;
  5375. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5376. int refclk = 100000;
  5377. mutex_lock(&dev_priv->dpio_lock);
  5378. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5379. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5380. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5381. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5382. mutex_unlock(&dev_priv->dpio_lock);
  5383. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5384. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5385. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5386. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5387. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5388. chv_clock(refclk, &clock);
  5389. /* clock.dot is the fast clock */
  5390. pipe_config->port_clock = clock.dot / 5;
  5391. }
  5392. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5393. struct intel_crtc_config *pipe_config)
  5394. {
  5395. struct drm_device *dev = crtc->base.dev;
  5396. struct drm_i915_private *dev_priv = dev->dev_private;
  5397. uint32_t tmp;
  5398. if (!intel_display_power_enabled(dev_priv,
  5399. POWER_DOMAIN_PIPE(crtc->pipe)))
  5400. return false;
  5401. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5402. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5403. tmp = I915_READ(PIPECONF(crtc->pipe));
  5404. if (!(tmp & PIPECONF_ENABLE))
  5405. return false;
  5406. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5407. switch (tmp & PIPECONF_BPC_MASK) {
  5408. case PIPECONF_6BPC:
  5409. pipe_config->pipe_bpp = 18;
  5410. break;
  5411. case PIPECONF_8BPC:
  5412. pipe_config->pipe_bpp = 24;
  5413. break;
  5414. case PIPECONF_10BPC:
  5415. pipe_config->pipe_bpp = 30;
  5416. break;
  5417. default:
  5418. break;
  5419. }
  5420. }
  5421. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5422. pipe_config->limited_color_range = true;
  5423. if (INTEL_INFO(dev)->gen < 4)
  5424. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5425. intel_get_pipe_timings(crtc, pipe_config);
  5426. i9xx_get_pfit_config(crtc, pipe_config);
  5427. if (INTEL_INFO(dev)->gen >= 4) {
  5428. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5429. pipe_config->pixel_multiplier =
  5430. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5431. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5432. pipe_config->dpll_hw_state.dpll_md = tmp;
  5433. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5434. tmp = I915_READ(DPLL(crtc->pipe));
  5435. pipe_config->pixel_multiplier =
  5436. ((tmp & SDVO_MULTIPLIER_MASK)
  5437. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5438. } else {
  5439. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5440. * port and will be fixed up in the encoder->get_config
  5441. * function. */
  5442. pipe_config->pixel_multiplier = 1;
  5443. }
  5444. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5445. if (!IS_VALLEYVIEW(dev)) {
  5446. /*
  5447. * DPLL_DVO_2X_MODE must be enabled for both DPLLs
  5448. * on 830. Filter it out here so that we don't
  5449. * report errors due to that.
  5450. */
  5451. if (IS_I830(dev))
  5452. pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
  5453. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5454. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5455. } else {
  5456. /* Mask out read-only status bits. */
  5457. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5458. DPLL_PORTC_READY_MASK |
  5459. DPLL_PORTB_READY_MASK);
  5460. }
  5461. if (IS_CHERRYVIEW(dev))
  5462. chv_crtc_clock_get(crtc, pipe_config);
  5463. else if (IS_VALLEYVIEW(dev))
  5464. vlv_crtc_clock_get(crtc, pipe_config);
  5465. else
  5466. i9xx_crtc_clock_get(crtc, pipe_config);
  5467. return true;
  5468. }
  5469. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5470. {
  5471. struct drm_i915_private *dev_priv = dev->dev_private;
  5472. struct intel_encoder *encoder;
  5473. u32 val, final;
  5474. bool has_lvds = false;
  5475. bool has_cpu_edp = false;
  5476. bool has_panel = false;
  5477. bool has_ck505 = false;
  5478. bool can_ssc = false;
  5479. /* We need to take the global config into account */
  5480. for_each_intel_encoder(dev, encoder) {
  5481. switch (encoder->type) {
  5482. case INTEL_OUTPUT_LVDS:
  5483. has_panel = true;
  5484. has_lvds = true;
  5485. break;
  5486. case INTEL_OUTPUT_EDP:
  5487. has_panel = true;
  5488. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5489. has_cpu_edp = true;
  5490. break;
  5491. }
  5492. }
  5493. if (HAS_PCH_IBX(dev)) {
  5494. has_ck505 = dev_priv->vbt.display_clock_mode;
  5495. can_ssc = has_ck505;
  5496. } else {
  5497. has_ck505 = false;
  5498. can_ssc = true;
  5499. }
  5500. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5501. has_panel, has_lvds, has_ck505);
  5502. /* Ironlake: try to setup display ref clock before DPLL
  5503. * enabling. This is only under driver's control after
  5504. * PCH B stepping, previous chipset stepping should be
  5505. * ignoring this setting.
  5506. */
  5507. val = I915_READ(PCH_DREF_CONTROL);
  5508. /* As we must carefully and slowly disable/enable each source in turn,
  5509. * compute the final state we want first and check if we need to
  5510. * make any changes at all.
  5511. */
  5512. final = val;
  5513. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5514. if (has_ck505)
  5515. final |= DREF_NONSPREAD_CK505_ENABLE;
  5516. else
  5517. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5518. final &= ~DREF_SSC_SOURCE_MASK;
  5519. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5520. final &= ~DREF_SSC1_ENABLE;
  5521. if (has_panel) {
  5522. final |= DREF_SSC_SOURCE_ENABLE;
  5523. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5524. final |= DREF_SSC1_ENABLE;
  5525. if (has_cpu_edp) {
  5526. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5527. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5528. else
  5529. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5530. } else
  5531. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5532. } else {
  5533. final |= DREF_SSC_SOURCE_DISABLE;
  5534. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5535. }
  5536. if (final == val)
  5537. return;
  5538. /* Always enable nonspread source */
  5539. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5540. if (has_ck505)
  5541. val |= DREF_NONSPREAD_CK505_ENABLE;
  5542. else
  5543. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5544. if (has_panel) {
  5545. val &= ~DREF_SSC_SOURCE_MASK;
  5546. val |= DREF_SSC_SOURCE_ENABLE;
  5547. /* SSC must be turned on before enabling the CPU output */
  5548. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5549. DRM_DEBUG_KMS("Using SSC on panel\n");
  5550. val |= DREF_SSC1_ENABLE;
  5551. } else
  5552. val &= ~DREF_SSC1_ENABLE;
  5553. /* Get SSC going before enabling the outputs */
  5554. I915_WRITE(PCH_DREF_CONTROL, val);
  5555. POSTING_READ(PCH_DREF_CONTROL);
  5556. udelay(200);
  5557. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5558. /* Enable CPU source on CPU attached eDP */
  5559. if (has_cpu_edp) {
  5560. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5561. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5562. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5563. } else
  5564. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5565. } else
  5566. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5567. I915_WRITE(PCH_DREF_CONTROL, val);
  5568. POSTING_READ(PCH_DREF_CONTROL);
  5569. udelay(200);
  5570. } else {
  5571. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5572. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5573. /* Turn off CPU output */
  5574. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5575. I915_WRITE(PCH_DREF_CONTROL, val);
  5576. POSTING_READ(PCH_DREF_CONTROL);
  5577. udelay(200);
  5578. /* Turn off the SSC source */
  5579. val &= ~DREF_SSC_SOURCE_MASK;
  5580. val |= DREF_SSC_SOURCE_DISABLE;
  5581. /* Turn off SSC1 */
  5582. val &= ~DREF_SSC1_ENABLE;
  5583. I915_WRITE(PCH_DREF_CONTROL, val);
  5584. POSTING_READ(PCH_DREF_CONTROL);
  5585. udelay(200);
  5586. }
  5587. BUG_ON(val != final);
  5588. }
  5589. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5590. {
  5591. uint32_t tmp;
  5592. tmp = I915_READ(SOUTH_CHICKEN2);
  5593. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5594. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5595. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5596. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5597. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5598. tmp = I915_READ(SOUTH_CHICKEN2);
  5599. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5600. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5601. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5602. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5603. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5604. }
  5605. /* WaMPhyProgramming:hsw */
  5606. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5607. {
  5608. uint32_t tmp;
  5609. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5610. tmp &= ~(0xFF << 24);
  5611. tmp |= (0x12 << 24);
  5612. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5613. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5614. tmp |= (1 << 11);
  5615. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5616. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5617. tmp |= (1 << 11);
  5618. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5619. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5620. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5621. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5622. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5623. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5624. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5625. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5626. tmp &= ~(7 << 13);
  5627. tmp |= (5 << 13);
  5628. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5629. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5630. tmp &= ~(7 << 13);
  5631. tmp |= (5 << 13);
  5632. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5633. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5634. tmp &= ~0xFF;
  5635. tmp |= 0x1C;
  5636. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5637. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5638. tmp &= ~0xFF;
  5639. tmp |= 0x1C;
  5640. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5641. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5642. tmp &= ~(0xFF << 16);
  5643. tmp |= (0x1C << 16);
  5644. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5645. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5646. tmp &= ~(0xFF << 16);
  5647. tmp |= (0x1C << 16);
  5648. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5649. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5650. tmp |= (1 << 27);
  5651. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5652. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5653. tmp |= (1 << 27);
  5654. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5655. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5656. tmp &= ~(0xF << 28);
  5657. tmp |= (4 << 28);
  5658. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5659. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5660. tmp &= ~(0xF << 28);
  5661. tmp |= (4 << 28);
  5662. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5663. }
  5664. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5665. * Programming" based on the parameters passed:
  5666. * - Sequence to enable CLKOUT_DP
  5667. * - Sequence to enable CLKOUT_DP without spread
  5668. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5669. */
  5670. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5671. bool with_fdi)
  5672. {
  5673. struct drm_i915_private *dev_priv = dev->dev_private;
  5674. uint32_t reg, tmp;
  5675. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5676. with_spread = true;
  5677. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5678. with_fdi, "LP PCH doesn't have FDI\n"))
  5679. with_fdi = false;
  5680. mutex_lock(&dev_priv->dpio_lock);
  5681. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5682. tmp &= ~SBI_SSCCTL_DISABLE;
  5683. tmp |= SBI_SSCCTL_PATHALT;
  5684. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5685. udelay(24);
  5686. if (with_spread) {
  5687. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5688. tmp &= ~SBI_SSCCTL_PATHALT;
  5689. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5690. if (with_fdi) {
  5691. lpt_reset_fdi_mphy(dev_priv);
  5692. lpt_program_fdi_mphy(dev_priv);
  5693. }
  5694. }
  5695. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5696. SBI_GEN0 : SBI_DBUFF0;
  5697. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5698. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5699. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5700. mutex_unlock(&dev_priv->dpio_lock);
  5701. }
  5702. /* Sequence to disable CLKOUT_DP */
  5703. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5704. {
  5705. struct drm_i915_private *dev_priv = dev->dev_private;
  5706. uint32_t reg, tmp;
  5707. mutex_lock(&dev_priv->dpio_lock);
  5708. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5709. SBI_GEN0 : SBI_DBUFF0;
  5710. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5711. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5712. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5713. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5714. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5715. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5716. tmp |= SBI_SSCCTL_PATHALT;
  5717. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5718. udelay(32);
  5719. }
  5720. tmp |= SBI_SSCCTL_DISABLE;
  5721. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5722. }
  5723. mutex_unlock(&dev_priv->dpio_lock);
  5724. }
  5725. static void lpt_init_pch_refclk(struct drm_device *dev)
  5726. {
  5727. struct intel_encoder *encoder;
  5728. bool has_vga = false;
  5729. for_each_intel_encoder(dev, encoder) {
  5730. switch (encoder->type) {
  5731. case INTEL_OUTPUT_ANALOG:
  5732. has_vga = true;
  5733. break;
  5734. }
  5735. }
  5736. if (has_vga)
  5737. lpt_enable_clkout_dp(dev, true, true);
  5738. else
  5739. lpt_disable_clkout_dp(dev);
  5740. }
  5741. /*
  5742. * Initialize reference clocks when the driver loads
  5743. */
  5744. void intel_init_pch_refclk(struct drm_device *dev)
  5745. {
  5746. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5747. ironlake_init_pch_refclk(dev);
  5748. else if (HAS_PCH_LPT(dev))
  5749. lpt_init_pch_refclk(dev);
  5750. }
  5751. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5752. {
  5753. struct drm_device *dev = crtc->dev;
  5754. struct drm_i915_private *dev_priv = dev->dev_private;
  5755. struct intel_encoder *encoder;
  5756. int num_connectors = 0;
  5757. bool is_lvds = false;
  5758. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5759. switch (encoder->type) {
  5760. case INTEL_OUTPUT_LVDS:
  5761. is_lvds = true;
  5762. break;
  5763. }
  5764. num_connectors++;
  5765. }
  5766. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5767. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5768. dev_priv->vbt.lvds_ssc_freq);
  5769. return dev_priv->vbt.lvds_ssc_freq;
  5770. }
  5771. return 120000;
  5772. }
  5773. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5774. {
  5775. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5776. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5777. int pipe = intel_crtc->pipe;
  5778. uint32_t val;
  5779. val = 0;
  5780. switch (intel_crtc->config.pipe_bpp) {
  5781. case 18:
  5782. val |= PIPECONF_6BPC;
  5783. break;
  5784. case 24:
  5785. val |= PIPECONF_8BPC;
  5786. break;
  5787. case 30:
  5788. val |= PIPECONF_10BPC;
  5789. break;
  5790. case 36:
  5791. val |= PIPECONF_12BPC;
  5792. break;
  5793. default:
  5794. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5795. BUG();
  5796. }
  5797. if (intel_crtc->config.dither)
  5798. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5799. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5800. val |= PIPECONF_INTERLACED_ILK;
  5801. else
  5802. val |= PIPECONF_PROGRESSIVE;
  5803. if (intel_crtc->config.limited_color_range)
  5804. val |= PIPECONF_COLOR_RANGE_SELECT;
  5805. I915_WRITE(PIPECONF(pipe), val);
  5806. POSTING_READ(PIPECONF(pipe));
  5807. }
  5808. /*
  5809. * Set up the pipe CSC unit.
  5810. *
  5811. * Currently only full range RGB to limited range RGB conversion
  5812. * is supported, but eventually this should handle various
  5813. * RGB<->YCbCr scenarios as well.
  5814. */
  5815. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5816. {
  5817. struct drm_device *dev = crtc->dev;
  5818. struct drm_i915_private *dev_priv = dev->dev_private;
  5819. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5820. int pipe = intel_crtc->pipe;
  5821. uint16_t coeff = 0x7800; /* 1.0 */
  5822. /*
  5823. * TODO: Check what kind of values actually come out of the pipe
  5824. * with these coeff/postoff values and adjust to get the best
  5825. * accuracy. Perhaps we even need to take the bpc value into
  5826. * consideration.
  5827. */
  5828. if (intel_crtc->config.limited_color_range)
  5829. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5830. /*
  5831. * GY/GU and RY/RU should be the other way around according
  5832. * to BSpec, but reality doesn't agree. Just set them up in
  5833. * a way that results in the correct picture.
  5834. */
  5835. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5836. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5837. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5838. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5839. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5840. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5841. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5842. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5843. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5844. if (INTEL_INFO(dev)->gen > 6) {
  5845. uint16_t postoff = 0;
  5846. if (intel_crtc->config.limited_color_range)
  5847. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5848. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5849. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5850. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5851. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5852. } else {
  5853. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5854. if (intel_crtc->config.limited_color_range)
  5855. mode |= CSC_BLACK_SCREEN_OFFSET;
  5856. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5857. }
  5858. }
  5859. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5860. {
  5861. struct drm_device *dev = crtc->dev;
  5862. struct drm_i915_private *dev_priv = dev->dev_private;
  5863. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5864. enum pipe pipe = intel_crtc->pipe;
  5865. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5866. uint32_t val;
  5867. val = 0;
  5868. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5869. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5870. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5871. val |= PIPECONF_INTERLACED_ILK;
  5872. else
  5873. val |= PIPECONF_PROGRESSIVE;
  5874. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5875. POSTING_READ(PIPECONF(cpu_transcoder));
  5876. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5877. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5878. if (IS_BROADWELL(dev)) {
  5879. val = 0;
  5880. switch (intel_crtc->config.pipe_bpp) {
  5881. case 18:
  5882. val |= PIPEMISC_DITHER_6_BPC;
  5883. break;
  5884. case 24:
  5885. val |= PIPEMISC_DITHER_8_BPC;
  5886. break;
  5887. case 30:
  5888. val |= PIPEMISC_DITHER_10_BPC;
  5889. break;
  5890. case 36:
  5891. val |= PIPEMISC_DITHER_12_BPC;
  5892. break;
  5893. default:
  5894. /* Case prevented by pipe_config_set_bpp. */
  5895. BUG();
  5896. }
  5897. if (intel_crtc->config.dither)
  5898. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5899. I915_WRITE(PIPEMISC(pipe), val);
  5900. }
  5901. }
  5902. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5903. intel_clock_t *clock,
  5904. bool *has_reduced_clock,
  5905. intel_clock_t *reduced_clock)
  5906. {
  5907. struct drm_device *dev = crtc->dev;
  5908. struct drm_i915_private *dev_priv = dev->dev_private;
  5909. struct intel_encoder *intel_encoder;
  5910. int refclk;
  5911. const intel_limit_t *limit;
  5912. bool ret, is_lvds = false;
  5913. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5914. switch (intel_encoder->type) {
  5915. case INTEL_OUTPUT_LVDS:
  5916. is_lvds = true;
  5917. break;
  5918. }
  5919. }
  5920. refclk = ironlake_get_refclk(crtc);
  5921. /*
  5922. * Returns a set of divisors for the desired target clock with the given
  5923. * refclk, or FALSE. The returned values represent the clock equation:
  5924. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5925. */
  5926. limit = intel_limit(crtc, refclk);
  5927. ret = dev_priv->display.find_dpll(limit, crtc,
  5928. to_intel_crtc(crtc)->config.port_clock,
  5929. refclk, NULL, clock);
  5930. if (!ret)
  5931. return false;
  5932. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5933. /*
  5934. * Ensure we match the reduced clock's P to the target clock.
  5935. * If the clocks don't match, we can't switch the display clock
  5936. * by using the FP0/FP1. In such case we will disable the LVDS
  5937. * downclock feature.
  5938. */
  5939. *has_reduced_clock =
  5940. dev_priv->display.find_dpll(limit, crtc,
  5941. dev_priv->lvds_downclock,
  5942. refclk, clock,
  5943. reduced_clock);
  5944. }
  5945. return true;
  5946. }
  5947. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5948. {
  5949. /*
  5950. * Account for spread spectrum to avoid
  5951. * oversubscribing the link. Max center spread
  5952. * is 2.5%; use 5% for safety's sake.
  5953. */
  5954. u32 bps = target_clock * bpp * 21 / 20;
  5955. return DIV_ROUND_UP(bps, link_bw * 8);
  5956. }
  5957. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5958. {
  5959. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5960. }
  5961. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5962. u32 *fp,
  5963. intel_clock_t *reduced_clock, u32 *fp2)
  5964. {
  5965. struct drm_crtc *crtc = &intel_crtc->base;
  5966. struct drm_device *dev = crtc->dev;
  5967. struct drm_i915_private *dev_priv = dev->dev_private;
  5968. struct intel_encoder *intel_encoder;
  5969. uint32_t dpll;
  5970. int factor, num_connectors = 0;
  5971. bool is_lvds = false, is_sdvo = false;
  5972. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5973. switch (intel_encoder->type) {
  5974. case INTEL_OUTPUT_LVDS:
  5975. is_lvds = true;
  5976. break;
  5977. case INTEL_OUTPUT_SDVO:
  5978. case INTEL_OUTPUT_HDMI:
  5979. is_sdvo = true;
  5980. break;
  5981. }
  5982. num_connectors++;
  5983. }
  5984. /* Enable autotuning of the PLL clock (if permissible) */
  5985. factor = 21;
  5986. if (is_lvds) {
  5987. if ((intel_panel_use_ssc(dev_priv) &&
  5988. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5989. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5990. factor = 25;
  5991. } else if (intel_crtc->config.sdvo_tv_clock)
  5992. factor = 20;
  5993. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5994. *fp |= FP_CB_TUNE;
  5995. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5996. *fp2 |= FP_CB_TUNE;
  5997. dpll = 0;
  5998. if (is_lvds)
  5999. dpll |= DPLLB_MODE_LVDS;
  6000. else
  6001. dpll |= DPLLB_MODE_DAC_SERIAL;
  6002. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  6003. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  6004. if (is_sdvo)
  6005. dpll |= DPLL_SDVO_HIGH_SPEED;
  6006. if (intel_crtc->config.has_dp_encoder)
  6007. dpll |= DPLL_SDVO_HIGH_SPEED;
  6008. /* compute bitmask from p1 value */
  6009. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  6010. /* also FPA1 */
  6011. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  6012. switch (intel_crtc->config.dpll.p2) {
  6013. case 5:
  6014. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  6015. break;
  6016. case 7:
  6017. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  6018. break;
  6019. case 10:
  6020. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  6021. break;
  6022. case 14:
  6023. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  6024. break;
  6025. }
  6026. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  6027. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  6028. else
  6029. dpll |= PLL_REF_INPUT_DREFCLK;
  6030. return dpll | DPLL_VCO_ENABLE;
  6031. }
  6032. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  6033. int x, int y,
  6034. struct drm_framebuffer *fb)
  6035. {
  6036. struct drm_device *dev = crtc->dev;
  6037. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6038. int num_connectors = 0;
  6039. intel_clock_t clock, reduced_clock;
  6040. u32 dpll = 0, fp = 0, fp2 = 0;
  6041. bool ok, has_reduced_clock = false;
  6042. bool is_lvds = false;
  6043. struct intel_encoder *encoder;
  6044. struct intel_shared_dpll *pll;
  6045. for_each_encoder_on_crtc(dev, crtc, encoder) {
  6046. switch (encoder->type) {
  6047. case INTEL_OUTPUT_LVDS:
  6048. is_lvds = true;
  6049. break;
  6050. }
  6051. num_connectors++;
  6052. }
  6053. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  6054. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  6055. ok = ironlake_compute_clocks(crtc, &clock,
  6056. &has_reduced_clock, &reduced_clock);
  6057. if (!ok && !intel_crtc->config.clock_set) {
  6058. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6059. return -EINVAL;
  6060. }
  6061. /* Compat-code for transition, will disappear. */
  6062. if (!intel_crtc->config.clock_set) {
  6063. intel_crtc->config.dpll.n = clock.n;
  6064. intel_crtc->config.dpll.m1 = clock.m1;
  6065. intel_crtc->config.dpll.m2 = clock.m2;
  6066. intel_crtc->config.dpll.p1 = clock.p1;
  6067. intel_crtc->config.dpll.p2 = clock.p2;
  6068. }
  6069. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  6070. if (intel_crtc->config.has_pch_encoder) {
  6071. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  6072. if (has_reduced_clock)
  6073. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  6074. dpll = ironlake_compute_dpll(intel_crtc,
  6075. &fp, &reduced_clock,
  6076. has_reduced_clock ? &fp2 : NULL);
  6077. intel_crtc->config.dpll_hw_state.dpll = dpll;
  6078. intel_crtc->config.dpll_hw_state.fp0 = fp;
  6079. if (has_reduced_clock)
  6080. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  6081. else
  6082. intel_crtc->config.dpll_hw_state.fp1 = fp;
  6083. pll = intel_get_shared_dpll(intel_crtc);
  6084. if (pll == NULL) {
  6085. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  6086. pipe_name(intel_crtc->pipe));
  6087. return -EINVAL;
  6088. }
  6089. } else
  6090. intel_put_shared_dpll(intel_crtc);
  6091. if (is_lvds && has_reduced_clock && i915.powersave)
  6092. intel_crtc->lowfreq_avail = true;
  6093. else
  6094. intel_crtc->lowfreq_avail = false;
  6095. return 0;
  6096. }
  6097. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  6098. struct intel_link_m_n *m_n)
  6099. {
  6100. struct drm_device *dev = crtc->base.dev;
  6101. struct drm_i915_private *dev_priv = dev->dev_private;
  6102. enum pipe pipe = crtc->pipe;
  6103. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  6104. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  6105. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  6106. & ~TU_SIZE_MASK;
  6107. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  6108. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  6109. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6110. }
  6111. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  6112. enum transcoder transcoder,
  6113. struct intel_link_m_n *m_n,
  6114. struct intel_link_m_n *m2_n2)
  6115. {
  6116. struct drm_device *dev = crtc->base.dev;
  6117. struct drm_i915_private *dev_priv = dev->dev_private;
  6118. enum pipe pipe = crtc->pipe;
  6119. if (INTEL_INFO(dev)->gen >= 5) {
  6120. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  6121. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  6122. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  6123. & ~TU_SIZE_MASK;
  6124. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  6125. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  6126. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6127. /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
  6128. * gen < 8) and if DRRS is supported (to make sure the
  6129. * registers are not unnecessarily read).
  6130. */
  6131. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  6132. crtc->config.has_drrs) {
  6133. m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
  6134. m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
  6135. m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
  6136. & ~TU_SIZE_MASK;
  6137. m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
  6138. m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
  6139. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6140. }
  6141. } else {
  6142. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  6143. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  6144. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  6145. & ~TU_SIZE_MASK;
  6146. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  6147. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  6148. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6149. }
  6150. }
  6151. void intel_dp_get_m_n(struct intel_crtc *crtc,
  6152. struct intel_crtc_config *pipe_config)
  6153. {
  6154. if (crtc->config.has_pch_encoder)
  6155. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  6156. else
  6157. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6158. &pipe_config->dp_m_n,
  6159. &pipe_config->dp_m2_n2);
  6160. }
  6161. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  6162. struct intel_crtc_config *pipe_config)
  6163. {
  6164. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6165. &pipe_config->fdi_m_n, NULL);
  6166. }
  6167. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  6168. struct intel_crtc_config *pipe_config)
  6169. {
  6170. struct drm_device *dev = crtc->base.dev;
  6171. struct drm_i915_private *dev_priv = dev->dev_private;
  6172. uint32_t tmp;
  6173. tmp = I915_READ(PF_CTL(crtc->pipe));
  6174. if (tmp & PF_ENABLE) {
  6175. pipe_config->pch_pfit.enabled = true;
  6176. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6177. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6178. /* We currently do not free assignements of panel fitters on
  6179. * ivb/hsw (since we don't use the higher upscaling modes which
  6180. * differentiates them) so just WARN about this case for now. */
  6181. if (IS_GEN7(dev)) {
  6182. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6183. PF_PIPE_SEL_IVB(crtc->pipe));
  6184. }
  6185. }
  6186. }
  6187. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6188. struct intel_plane_config *plane_config)
  6189. {
  6190. struct drm_device *dev = crtc->base.dev;
  6191. struct drm_i915_private *dev_priv = dev->dev_private;
  6192. u32 val, base, offset;
  6193. int pipe = crtc->pipe, plane = crtc->plane;
  6194. int fourcc, pixel_format;
  6195. int aligned_height;
  6196. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6197. if (!crtc->base.primary->fb) {
  6198. DRM_DEBUG_KMS("failed to alloc fb\n");
  6199. return;
  6200. }
  6201. val = I915_READ(DSPCNTR(plane));
  6202. if (INTEL_INFO(dev)->gen >= 4)
  6203. if (val & DISPPLANE_TILED)
  6204. plane_config->tiled = true;
  6205. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6206. fourcc = intel_format_to_fourcc(pixel_format);
  6207. crtc->base.primary->fb->pixel_format = fourcc;
  6208. crtc->base.primary->fb->bits_per_pixel =
  6209. drm_format_plane_cpp(fourcc, 0) * 8;
  6210. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6211. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6212. offset = I915_READ(DSPOFFSET(plane));
  6213. } else {
  6214. if (plane_config->tiled)
  6215. offset = I915_READ(DSPTILEOFF(plane));
  6216. else
  6217. offset = I915_READ(DSPLINOFF(plane));
  6218. }
  6219. plane_config->base = base;
  6220. val = I915_READ(PIPESRC(pipe));
  6221. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6222. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6223. val = I915_READ(DSPSTRIDE(pipe));
  6224. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  6225. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6226. plane_config->tiled);
  6227. plane_config->size = crtc->base.primary->fb->pitches[0] * aligned_height;
  6228. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6229. pipe, plane, crtc->base.primary->fb->width,
  6230. crtc->base.primary->fb->height,
  6231. crtc->base.primary->fb->bits_per_pixel, base,
  6232. crtc->base.primary->fb->pitches[0],
  6233. plane_config->size);
  6234. }
  6235. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6236. struct intel_crtc_config *pipe_config)
  6237. {
  6238. struct drm_device *dev = crtc->base.dev;
  6239. struct drm_i915_private *dev_priv = dev->dev_private;
  6240. uint32_t tmp;
  6241. if (!intel_display_power_enabled(dev_priv,
  6242. POWER_DOMAIN_PIPE(crtc->pipe)))
  6243. return false;
  6244. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6245. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6246. tmp = I915_READ(PIPECONF(crtc->pipe));
  6247. if (!(tmp & PIPECONF_ENABLE))
  6248. return false;
  6249. switch (tmp & PIPECONF_BPC_MASK) {
  6250. case PIPECONF_6BPC:
  6251. pipe_config->pipe_bpp = 18;
  6252. break;
  6253. case PIPECONF_8BPC:
  6254. pipe_config->pipe_bpp = 24;
  6255. break;
  6256. case PIPECONF_10BPC:
  6257. pipe_config->pipe_bpp = 30;
  6258. break;
  6259. case PIPECONF_12BPC:
  6260. pipe_config->pipe_bpp = 36;
  6261. break;
  6262. default:
  6263. break;
  6264. }
  6265. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6266. pipe_config->limited_color_range = true;
  6267. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6268. struct intel_shared_dpll *pll;
  6269. pipe_config->has_pch_encoder = true;
  6270. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6271. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6272. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6273. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6274. if (HAS_PCH_IBX(dev_priv->dev)) {
  6275. pipe_config->shared_dpll =
  6276. (enum intel_dpll_id) crtc->pipe;
  6277. } else {
  6278. tmp = I915_READ(PCH_DPLL_SEL);
  6279. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6280. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6281. else
  6282. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6283. }
  6284. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6285. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6286. &pipe_config->dpll_hw_state));
  6287. tmp = pipe_config->dpll_hw_state.dpll;
  6288. pipe_config->pixel_multiplier =
  6289. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6290. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6291. ironlake_pch_clock_get(crtc, pipe_config);
  6292. } else {
  6293. pipe_config->pixel_multiplier = 1;
  6294. }
  6295. intel_get_pipe_timings(crtc, pipe_config);
  6296. ironlake_get_pfit_config(crtc, pipe_config);
  6297. return true;
  6298. }
  6299. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6300. {
  6301. struct drm_device *dev = dev_priv->dev;
  6302. struct intel_crtc *crtc;
  6303. for_each_intel_crtc(dev, crtc)
  6304. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6305. pipe_name(crtc->pipe));
  6306. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6307. WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
  6308. WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
  6309. WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
  6310. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6311. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6312. "CPU PWM1 enabled\n");
  6313. if (IS_HASWELL(dev))
  6314. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6315. "CPU PWM2 enabled\n");
  6316. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6317. "PCH PWM1 enabled\n");
  6318. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6319. "Utility pin enabled\n");
  6320. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6321. /*
  6322. * In theory we can still leave IRQs enabled, as long as only the HPD
  6323. * interrupts remain enabled. We used to check for that, but since it's
  6324. * gen-specific and since we only disable LCPLL after we fully disable
  6325. * the interrupts, the check below should be enough.
  6326. */
  6327. WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
  6328. }
  6329. static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
  6330. {
  6331. struct drm_device *dev = dev_priv->dev;
  6332. if (IS_HASWELL(dev))
  6333. return I915_READ(D_COMP_HSW);
  6334. else
  6335. return I915_READ(D_COMP_BDW);
  6336. }
  6337. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6338. {
  6339. struct drm_device *dev = dev_priv->dev;
  6340. if (IS_HASWELL(dev)) {
  6341. mutex_lock(&dev_priv->rps.hw_lock);
  6342. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6343. val))
  6344. DRM_ERROR("Failed to write to D_COMP\n");
  6345. mutex_unlock(&dev_priv->rps.hw_lock);
  6346. } else {
  6347. I915_WRITE(D_COMP_BDW, val);
  6348. POSTING_READ(D_COMP_BDW);
  6349. }
  6350. }
  6351. /*
  6352. * This function implements pieces of two sequences from BSpec:
  6353. * - Sequence for display software to disable LCPLL
  6354. * - Sequence for display software to allow package C8+
  6355. * The steps implemented here are just the steps that actually touch the LCPLL
  6356. * register. Callers should take care of disabling all the display engine
  6357. * functions, doing the mode unset, fixing interrupts, etc.
  6358. */
  6359. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6360. bool switch_to_fclk, bool allow_power_down)
  6361. {
  6362. uint32_t val;
  6363. assert_can_disable_lcpll(dev_priv);
  6364. val = I915_READ(LCPLL_CTL);
  6365. if (switch_to_fclk) {
  6366. val |= LCPLL_CD_SOURCE_FCLK;
  6367. I915_WRITE(LCPLL_CTL, val);
  6368. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6369. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6370. DRM_ERROR("Switching to FCLK failed\n");
  6371. val = I915_READ(LCPLL_CTL);
  6372. }
  6373. val |= LCPLL_PLL_DISABLE;
  6374. I915_WRITE(LCPLL_CTL, val);
  6375. POSTING_READ(LCPLL_CTL);
  6376. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6377. DRM_ERROR("LCPLL still locked\n");
  6378. val = hsw_read_dcomp(dev_priv);
  6379. val |= D_COMP_COMP_DISABLE;
  6380. hsw_write_dcomp(dev_priv, val);
  6381. ndelay(100);
  6382. if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
  6383. 1))
  6384. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6385. if (allow_power_down) {
  6386. val = I915_READ(LCPLL_CTL);
  6387. val |= LCPLL_POWER_DOWN_ALLOW;
  6388. I915_WRITE(LCPLL_CTL, val);
  6389. POSTING_READ(LCPLL_CTL);
  6390. }
  6391. }
  6392. /*
  6393. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6394. * source.
  6395. */
  6396. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6397. {
  6398. uint32_t val;
  6399. unsigned long irqflags;
  6400. val = I915_READ(LCPLL_CTL);
  6401. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6402. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6403. return;
  6404. /*
  6405. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6406. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6407. *
  6408. * The other problem is that hsw_restore_lcpll() is called as part of
  6409. * the runtime PM resume sequence, so we can't just call
  6410. * gen6_gt_force_wake_get() because that function calls
  6411. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6412. * while we are on the resume sequence. So to solve this problem we have
  6413. * to call special forcewake code that doesn't touch runtime PM and
  6414. * doesn't enable the forcewake delayed work.
  6415. */
  6416. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6417. if (dev_priv->uncore.forcewake_count++ == 0)
  6418. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6419. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6420. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6421. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6422. I915_WRITE(LCPLL_CTL, val);
  6423. POSTING_READ(LCPLL_CTL);
  6424. }
  6425. val = hsw_read_dcomp(dev_priv);
  6426. val |= D_COMP_COMP_FORCE;
  6427. val &= ~D_COMP_COMP_DISABLE;
  6428. hsw_write_dcomp(dev_priv, val);
  6429. val = I915_READ(LCPLL_CTL);
  6430. val &= ~LCPLL_PLL_DISABLE;
  6431. I915_WRITE(LCPLL_CTL, val);
  6432. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6433. DRM_ERROR("LCPLL not locked yet\n");
  6434. if (val & LCPLL_CD_SOURCE_FCLK) {
  6435. val = I915_READ(LCPLL_CTL);
  6436. val &= ~LCPLL_CD_SOURCE_FCLK;
  6437. I915_WRITE(LCPLL_CTL, val);
  6438. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6439. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6440. DRM_ERROR("Switching back to LCPLL failed\n");
  6441. }
  6442. /* See the big comment above. */
  6443. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6444. if (--dev_priv->uncore.forcewake_count == 0)
  6445. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6446. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6447. }
  6448. /*
  6449. * Package states C8 and deeper are really deep PC states that can only be
  6450. * reached when all the devices on the system allow it, so even if the graphics
  6451. * device allows PC8+, it doesn't mean the system will actually get to these
  6452. * states. Our driver only allows PC8+ when going into runtime PM.
  6453. *
  6454. * The requirements for PC8+ are that all the outputs are disabled, the power
  6455. * well is disabled and most interrupts are disabled, and these are also
  6456. * requirements for runtime PM. When these conditions are met, we manually do
  6457. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6458. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6459. * hang the machine.
  6460. *
  6461. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6462. * the state of some registers, so when we come back from PC8+ we need to
  6463. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6464. * need to take care of the registers kept by RC6. Notice that this happens even
  6465. * if we don't put the device in PCI D3 state (which is what currently happens
  6466. * because of the runtime PM support).
  6467. *
  6468. * For more, read "Display Sequences for Package C8" on the hardware
  6469. * documentation.
  6470. */
  6471. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6472. {
  6473. struct drm_device *dev = dev_priv->dev;
  6474. uint32_t val;
  6475. DRM_DEBUG_KMS("Enabling package C8+\n");
  6476. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6477. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6478. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6479. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6480. }
  6481. lpt_disable_clkout_dp(dev);
  6482. hsw_disable_lcpll(dev_priv, true, true);
  6483. }
  6484. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6485. {
  6486. struct drm_device *dev = dev_priv->dev;
  6487. uint32_t val;
  6488. DRM_DEBUG_KMS("Disabling package C8+\n");
  6489. hsw_restore_lcpll(dev_priv);
  6490. lpt_init_pch_refclk(dev);
  6491. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6492. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6493. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6494. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6495. }
  6496. intel_prepare_ddi(dev);
  6497. }
  6498. static void snb_modeset_global_resources(struct drm_device *dev)
  6499. {
  6500. modeset_update_crtc_power_domains(dev);
  6501. }
  6502. static void haswell_modeset_global_resources(struct drm_device *dev)
  6503. {
  6504. modeset_update_crtc_power_domains(dev);
  6505. }
  6506. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  6507. int x, int y,
  6508. struct drm_framebuffer *fb)
  6509. {
  6510. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6511. if (!intel_ddi_pll_select(intel_crtc))
  6512. return -EINVAL;
  6513. intel_crtc->lowfreq_avail = false;
  6514. return 0;
  6515. }
  6516. static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
  6517. enum port port,
  6518. struct intel_crtc_config *pipe_config)
  6519. {
  6520. pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
  6521. switch (pipe_config->ddi_pll_sel) {
  6522. case PORT_CLK_SEL_WRPLL1:
  6523. pipe_config->shared_dpll = DPLL_ID_WRPLL1;
  6524. break;
  6525. case PORT_CLK_SEL_WRPLL2:
  6526. pipe_config->shared_dpll = DPLL_ID_WRPLL2;
  6527. break;
  6528. }
  6529. }
  6530. static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
  6531. struct intel_crtc_config *pipe_config)
  6532. {
  6533. struct drm_device *dev = crtc->base.dev;
  6534. struct drm_i915_private *dev_priv = dev->dev_private;
  6535. struct intel_shared_dpll *pll;
  6536. enum port port;
  6537. uint32_t tmp;
  6538. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6539. port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
  6540. haswell_get_ddi_pll(dev_priv, port, pipe_config);
  6541. if (pipe_config->shared_dpll >= 0) {
  6542. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6543. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6544. &pipe_config->dpll_hw_state));
  6545. }
  6546. /*
  6547. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6548. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6549. * the PCH transcoder is on.
  6550. */
  6551. if ((port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6552. pipe_config->has_pch_encoder = true;
  6553. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6554. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6555. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6556. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6557. }
  6558. }
  6559. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6560. struct intel_crtc_config *pipe_config)
  6561. {
  6562. struct drm_device *dev = crtc->base.dev;
  6563. struct drm_i915_private *dev_priv = dev->dev_private;
  6564. enum intel_display_power_domain pfit_domain;
  6565. uint32_t tmp;
  6566. if (!intel_display_power_enabled(dev_priv,
  6567. POWER_DOMAIN_PIPE(crtc->pipe)))
  6568. return false;
  6569. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6570. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6571. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6572. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6573. enum pipe trans_edp_pipe;
  6574. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6575. default:
  6576. WARN(1, "unknown pipe linked to edp transcoder\n");
  6577. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6578. case TRANS_DDI_EDP_INPUT_A_ON:
  6579. trans_edp_pipe = PIPE_A;
  6580. break;
  6581. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6582. trans_edp_pipe = PIPE_B;
  6583. break;
  6584. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6585. trans_edp_pipe = PIPE_C;
  6586. break;
  6587. }
  6588. if (trans_edp_pipe == crtc->pipe)
  6589. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6590. }
  6591. if (!intel_display_power_enabled(dev_priv,
  6592. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6593. return false;
  6594. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6595. if (!(tmp & PIPECONF_ENABLE))
  6596. return false;
  6597. haswell_get_ddi_port_state(crtc, pipe_config);
  6598. intel_get_pipe_timings(crtc, pipe_config);
  6599. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6600. if (intel_display_power_enabled(dev_priv, pfit_domain))
  6601. ironlake_get_pfit_config(crtc, pipe_config);
  6602. if (IS_HASWELL(dev))
  6603. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6604. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6605. if (pipe_config->cpu_transcoder != TRANSCODER_EDP) {
  6606. pipe_config->pixel_multiplier =
  6607. I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
  6608. } else {
  6609. pipe_config->pixel_multiplier = 1;
  6610. }
  6611. return true;
  6612. }
  6613. static struct {
  6614. int clock;
  6615. u32 config;
  6616. } hdmi_audio_clock[] = {
  6617. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6618. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6619. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6620. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6621. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6622. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6623. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6624. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6625. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6626. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6627. };
  6628. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6629. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6630. {
  6631. int i;
  6632. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6633. if (mode->clock == hdmi_audio_clock[i].clock)
  6634. break;
  6635. }
  6636. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6637. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6638. i = 1;
  6639. }
  6640. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6641. hdmi_audio_clock[i].clock,
  6642. hdmi_audio_clock[i].config);
  6643. return hdmi_audio_clock[i].config;
  6644. }
  6645. static bool intel_eld_uptodate(struct drm_connector *connector,
  6646. int reg_eldv, uint32_t bits_eldv,
  6647. int reg_elda, uint32_t bits_elda,
  6648. int reg_edid)
  6649. {
  6650. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6651. uint8_t *eld = connector->eld;
  6652. uint32_t i;
  6653. i = I915_READ(reg_eldv);
  6654. i &= bits_eldv;
  6655. if (!eld[0])
  6656. return !i;
  6657. if (!i)
  6658. return false;
  6659. i = I915_READ(reg_elda);
  6660. i &= ~bits_elda;
  6661. I915_WRITE(reg_elda, i);
  6662. for (i = 0; i < eld[2]; i++)
  6663. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6664. return false;
  6665. return true;
  6666. }
  6667. static void g4x_write_eld(struct drm_connector *connector,
  6668. struct drm_crtc *crtc,
  6669. struct drm_display_mode *mode)
  6670. {
  6671. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6672. uint8_t *eld = connector->eld;
  6673. uint32_t eldv;
  6674. uint32_t len;
  6675. uint32_t i;
  6676. i = I915_READ(G4X_AUD_VID_DID);
  6677. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6678. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6679. else
  6680. eldv = G4X_ELDV_DEVCTG;
  6681. if (intel_eld_uptodate(connector,
  6682. G4X_AUD_CNTL_ST, eldv,
  6683. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6684. G4X_HDMIW_HDMIEDID))
  6685. return;
  6686. i = I915_READ(G4X_AUD_CNTL_ST);
  6687. i &= ~(eldv | G4X_ELD_ADDR);
  6688. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6689. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6690. if (!eld[0])
  6691. return;
  6692. len = min_t(uint8_t, eld[2], len);
  6693. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6694. for (i = 0; i < len; i++)
  6695. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6696. i = I915_READ(G4X_AUD_CNTL_ST);
  6697. i |= eldv;
  6698. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6699. }
  6700. static void haswell_write_eld(struct drm_connector *connector,
  6701. struct drm_crtc *crtc,
  6702. struct drm_display_mode *mode)
  6703. {
  6704. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6705. uint8_t *eld = connector->eld;
  6706. uint32_t eldv;
  6707. uint32_t i;
  6708. int len;
  6709. int pipe = to_intel_crtc(crtc)->pipe;
  6710. int tmp;
  6711. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6712. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6713. int aud_config = HSW_AUD_CFG(pipe);
  6714. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6715. /* Audio output enable */
  6716. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6717. tmp = I915_READ(aud_cntrl_st2);
  6718. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6719. I915_WRITE(aud_cntrl_st2, tmp);
  6720. POSTING_READ(aud_cntrl_st2);
  6721. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6722. /* Set ELD valid state */
  6723. tmp = I915_READ(aud_cntrl_st2);
  6724. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6725. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6726. I915_WRITE(aud_cntrl_st2, tmp);
  6727. tmp = I915_READ(aud_cntrl_st2);
  6728. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6729. /* Enable HDMI mode */
  6730. tmp = I915_READ(aud_config);
  6731. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6732. /* clear N_programing_enable and N_value_index */
  6733. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6734. I915_WRITE(aud_config, tmp);
  6735. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6736. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6737. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6738. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6739. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6740. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6741. } else {
  6742. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6743. }
  6744. if (intel_eld_uptodate(connector,
  6745. aud_cntrl_st2, eldv,
  6746. aud_cntl_st, IBX_ELD_ADDRESS,
  6747. hdmiw_hdmiedid))
  6748. return;
  6749. i = I915_READ(aud_cntrl_st2);
  6750. i &= ~eldv;
  6751. I915_WRITE(aud_cntrl_st2, i);
  6752. if (!eld[0])
  6753. return;
  6754. i = I915_READ(aud_cntl_st);
  6755. i &= ~IBX_ELD_ADDRESS;
  6756. I915_WRITE(aud_cntl_st, i);
  6757. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6758. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6759. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6760. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6761. for (i = 0; i < len; i++)
  6762. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6763. i = I915_READ(aud_cntrl_st2);
  6764. i |= eldv;
  6765. I915_WRITE(aud_cntrl_st2, i);
  6766. }
  6767. static void ironlake_write_eld(struct drm_connector *connector,
  6768. struct drm_crtc *crtc,
  6769. struct drm_display_mode *mode)
  6770. {
  6771. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6772. uint8_t *eld = connector->eld;
  6773. uint32_t eldv;
  6774. uint32_t i;
  6775. int len;
  6776. int hdmiw_hdmiedid;
  6777. int aud_config;
  6778. int aud_cntl_st;
  6779. int aud_cntrl_st2;
  6780. int pipe = to_intel_crtc(crtc)->pipe;
  6781. if (HAS_PCH_IBX(connector->dev)) {
  6782. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6783. aud_config = IBX_AUD_CFG(pipe);
  6784. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6785. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6786. } else if (IS_VALLEYVIEW(connector->dev)) {
  6787. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6788. aud_config = VLV_AUD_CFG(pipe);
  6789. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6790. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6791. } else {
  6792. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6793. aud_config = CPT_AUD_CFG(pipe);
  6794. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6795. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6796. }
  6797. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6798. if (IS_VALLEYVIEW(connector->dev)) {
  6799. struct intel_encoder *intel_encoder;
  6800. struct intel_digital_port *intel_dig_port;
  6801. intel_encoder = intel_attached_encoder(connector);
  6802. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6803. i = intel_dig_port->port;
  6804. } else {
  6805. i = I915_READ(aud_cntl_st);
  6806. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6807. /* DIP_Port_Select, 0x1 = PortB */
  6808. }
  6809. if (!i) {
  6810. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6811. /* operate blindly on all ports */
  6812. eldv = IBX_ELD_VALIDB;
  6813. eldv |= IBX_ELD_VALIDB << 4;
  6814. eldv |= IBX_ELD_VALIDB << 8;
  6815. } else {
  6816. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6817. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6818. }
  6819. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6820. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6821. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6822. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6823. } else {
  6824. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6825. }
  6826. if (intel_eld_uptodate(connector,
  6827. aud_cntrl_st2, eldv,
  6828. aud_cntl_st, IBX_ELD_ADDRESS,
  6829. hdmiw_hdmiedid))
  6830. return;
  6831. i = I915_READ(aud_cntrl_st2);
  6832. i &= ~eldv;
  6833. I915_WRITE(aud_cntrl_st2, i);
  6834. if (!eld[0])
  6835. return;
  6836. i = I915_READ(aud_cntl_st);
  6837. i &= ~IBX_ELD_ADDRESS;
  6838. I915_WRITE(aud_cntl_st, i);
  6839. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6840. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6841. for (i = 0; i < len; i++)
  6842. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6843. i = I915_READ(aud_cntrl_st2);
  6844. i |= eldv;
  6845. I915_WRITE(aud_cntrl_st2, i);
  6846. }
  6847. void intel_write_eld(struct drm_encoder *encoder,
  6848. struct drm_display_mode *mode)
  6849. {
  6850. struct drm_crtc *crtc = encoder->crtc;
  6851. struct drm_connector *connector;
  6852. struct drm_device *dev = encoder->dev;
  6853. struct drm_i915_private *dev_priv = dev->dev_private;
  6854. connector = drm_select_eld(encoder, mode);
  6855. if (!connector)
  6856. return;
  6857. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6858. connector->base.id,
  6859. connector->name,
  6860. connector->encoder->base.id,
  6861. connector->encoder->name);
  6862. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6863. if (dev_priv->display.write_eld)
  6864. dev_priv->display.write_eld(connector, crtc, mode);
  6865. }
  6866. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6867. {
  6868. struct drm_device *dev = crtc->dev;
  6869. struct drm_i915_private *dev_priv = dev->dev_private;
  6870. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6871. uint32_t cntl = 0, size = 0;
  6872. if (base) {
  6873. unsigned int width = intel_crtc->cursor_width;
  6874. unsigned int height = intel_crtc->cursor_height;
  6875. unsigned int stride = roundup_pow_of_two(width) * 4;
  6876. switch (stride) {
  6877. default:
  6878. WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
  6879. width, stride);
  6880. stride = 256;
  6881. /* fallthrough */
  6882. case 256:
  6883. case 512:
  6884. case 1024:
  6885. case 2048:
  6886. break;
  6887. }
  6888. cntl |= CURSOR_ENABLE |
  6889. CURSOR_GAMMA_ENABLE |
  6890. CURSOR_FORMAT_ARGB |
  6891. CURSOR_STRIDE(stride);
  6892. size = (height << 12) | width;
  6893. }
  6894. if (intel_crtc->cursor_cntl != 0 &&
  6895. (intel_crtc->cursor_base != base ||
  6896. intel_crtc->cursor_size != size ||
  6897. intel_crtc->cursor_cntl != cntl)) {
  6898. /* On these chipsets we can only modify the base/size/stride
  6899. * whilst the cursor is disabled.
  6900. */
  6901. I915_WRITE(_CURACNTR, 0);
  6902. POSTING_READ(_CURACNTR);
  6903. intel_crtc->cursor_cntl = 0;
  6904. }
  6905. if (intel_crtc->cursor_base != base)
  6906. I915_WRITE(_CURABASE, base);
  6907. if (intel_crtc->cursor_size != size) {
  6908. I915_WRITE(CURSIZE, size);
  6909. intel_crtc->cursor_size = size;
  6910. }
  6911. if (intel_crtc->cursor_cntl != cntl) {
  6912. I915_WRITE(_CURACNTR, cntl);
  6913. POSTING_READ(_CURACNTR);
  6914. intel_crtc->cursor_cntl = cntl;
  6915. }
  6916. }
  6917. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6918. {
  6919. struct drm_device *dev = crtc->dev;
  6920. struct drm_i915_private *dev_priv = dev->dev_private;
  6921. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6922. int pipe = intel_crtc->pipe;
  6923. uint32_t cntl;
  6924. cntl = 0;
  6925. if (base) {
  6926. cntl = MCURSOR_GAMMA_ENABLE;
  6927. switch (intel_crtc->cursor_width) {
  6928. case 64:
  6929. cntl |= CURSOR_MODE_64_ARGB_AX;
  6930. break;
  6931. case 128:
  6932. cntl |= CURSOR_MODE_128_ARGB_AX;
  6933. break;
  6934. case 256:
  6935. cntl |= CURSOR_MODE_256_ARGB_AX;
  6936. break;
  6937. default:
  6938. WARN_ON(1);
  6939. return;
  6940. }
  6941. cntl |= pipe << 28; /* Connect to correct pipe */
  6942. }
  6943. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6944. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6945. if (intel_crtc->cursor_cntl != cntl) {
  6946. I915_WRITE(CURCNTR(pipe), cntl);
  6947. POSTING_READ(CURCNTR(pipe));
  6948. intel_crtc->cursor_cntl = cntl;
  6949. }
  6950. /* and commit changes on next vblank */
  6951. I915_WRITE(CURBASE(pipe), base);
  6952. POSTING_READ(CURBASE(pipe));
  6953. }
  6954. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6955. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6956. bool on)
  6957. {
  6958. struct drm_device *dev = crtc->dev;
  6959. struct drm_i915_private *dev_priv = dev->dev_private;
  6960. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6961. int pipe = intel_crtc->pipe;
  6962. int x = crtc->cursor_x;
  6963. int y = crtc->cursor_y;
  6964. u32 base = 0, pos = 0;
  6965. if (on)
  6966. base = intel_crtc->cursor_addr;
  6967. if (x >= intel_crtc->config.pipe_src_w)
  6968. base = 0;
  6969. if (y >= intel_crtc->config.pipe_src_h)
  6970. base = 0;
  6971. if (x < 0) {
  6972. if (x + intel_crtc->cursor_width <= 0)
  6973. base = 0;
  6974. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6975. x = -x;
  6976. }
  6977. pos |= x << CURSOR_X_SHIFT;
  6978. if (y < 0) {
  6979. if (y + intel_crtc->cursor_height <= 0)
  6980. base = 0;
  6981. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6982. y = -y;
  6983. }
  6984. pos |= y << CURSOR_Y_SHIFT;
  6985. if (base == 0 && intel_crtc->cursor_base == 0)
  6986. return;
  6987. I915_WRITE(CURPOS(pipe), pos);
  6988. if (IS_845G(dev) || IS_I865G(dev))
  6989. i845_update_cursor(crtc, base);
  6990. else
  6991. i9xx_update_cursor(crtc, base);
  6992. intel_crtc->cursor_base = base;
  6993. }
  6994. static bool cursor_size_ok(struct drm_device *dev,
  6995. uint32_t width, uint32_t height)
  6996. {
  6997. if (width == 0 || height == 0)
  6998. return false;
  6999. /*
  7000. * 845g/865g are special in that they are only limited by
  7001. * the width of their cursors, the height is arbitrary up to
  7002. * the precision of the register. Everything else requires
  7003. * square cursors, limited to a few power-of-two sizes.
  7004. */
  7005. if (IS_845G(dev) || IS_I865G(dev)) {
  7006. if ((width & 63) != 0)
  7007. return false;
  7008. if (width > (IS_845G(dev) ? 64 : 512))
  7009. return false;
  7010. if (height > 1023)
  7011. return false;
  7012. } else {
  7013. switch (width | height) {
  7014. case 256:
  7015. case 128:
  7016. if (IS_GEN2(dev))
  7017. return false;
  7018. case 64:
  7019. break;
  7020. default:
  7021. return false;
  7022. }
  7023. }
  7024. return true;
  7025. }
  7026. /*
  7027. * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
  7028. *
  7029. * Note that the object's reference will be consumed if the update fails. If
  7030. * the update succeeds, the reference of the old object (if any) will be
  7031. * consumed.
  7032. */
  7033. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  7034. struct drm_i915_gem_object *obj,
  7035. uint32_t width, uint32_t height)
  7036. {
  7037. struct drm_device *dev = crtc->dev;
  7038. struct drm_i915_private *dev_priv = dev->dev_private;
  7039. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7040. enum pipe pipe = intel_crtc->pipe;
  7041. unsigned old_width, stride;
  7042. uint32_t addr;
  7043. int ret;
  7044. /* if we want to turn off the cursor ignore width and height */
  7045. if (!obj) {
  7046. DRM_DEBUG_KMS("cursor off\n");
  7047. addr = 0;
  7048. mutex_lock(&dev->struct_mutex);
  7049. goto finish;
  7050. }
  7051. /* Check for which cursor types we support */
  7052. if (!cursor_size_ok(dev, width, height)) {
  7053. DRM_DEBUG("Cursor dimension not supported\n");
  7054. return -EINVAL;
  7055. }
  7056. stride = roundup_pow_of_two(width) * 4;
  7057. if (obj->base.size < stride * height) {
  7058. DRM_DEBUG_KMS("buffer is too small\n");
  7059. ret = -ENOMEM;
  7060. goto fail;
  7061. }
  7062. /* we only need to pin inside GTT if cursor is non-phy */
  7063. mutex_lock(&dev->struct_mutex);
  7064. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  7065. unsigned alignment;
  7066. if (obj->tiling_mode) {
  7067. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  7068. ret = -EINVAL;
  7069. goto fail_locked;
  7070. }
  7071. /*
  7072. * Global gtt pte registers are special registers which actually
  7073. * forward writes to a chunk of system memory. Which means that
  7074. * there is no risk that the register values disappear as soon
  7075. * as we call intel_runtime_pm_put(), so it is correct to wrap
  7076. * only the pin/unpin/fence and not more.
  7077. */
  7078. intel_runtime_pm_get(dev_priv);
  7079. /* Note that the w/a also requires 2 PTE of padding following
  7080. * the bo. We currently fill all unused PTE with the shadow
  7081. * page and so we should always have valid PTE following the
  7082. * cursor preventing the VT-d warning.
  7083. */
  7084. alignment = 0;
  7085. if (need_vtd_wa(dev))
  7086. alignment = 64*1024;
  7087. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  7088. if (ret) {
  7089. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  7090. intel_runtime_pm_put(dev_priv);
  7091. goto fail_locked;
  7092. }
  7093. ret = i915_gem_object_put_fence(obj);
  7094. if (ret) {
  7095. DRM_DEBUG_KMS("failed to release fence for cursor");
  7096. intel_runtime_pm_put(dev_priv);
  7097. goto fail_unpin;
  7098. }
  7099. addr = i915_gem_obj_ggtt_offset(obj);
  7100. intel_runtime_pm_put(dev_priv);
  7101. } else {
  7102. int align = IS_I830(dev) ? 16 * 1024 : 256;
  7103. ret = i915_gem_object_attach_phys(obj, align);
  7104. if (ret) {
  7105. DRM_DEBUG_KMS("failed to attach phys object\n");
  7106. goto fail_locked;
  7107. }
  7108. addr = obj->phys_handle->busaddr;
  7109. }
  7110. finish:
  7111. if (intel_crtc->cursor_bo) {
  7112. if (!INTEL_INFO(dev)->cursor_needs_physical)
  7113. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  7114. }
  7115. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  7116. INTEL_FRONTBUFFER_CURSOR(pipe));
  7117. mutex_unlock(&dev->struct_mutex);
  7118. old_width = intel_crtc->cursor_width;
  7119. intel_crtc->cursor_addr = addr;
  7120. intel_crtc->cursor_bo = obj;
  7121. intel_crtc->cursor_width = width;
  7122. intel_crtc->cursor_height = height;
  7123. if (intel_crtc->active) {
  7124. if (old_width != width)
  7125. intel_update_watermarks(crtc);
  7126. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  7127. }
  7128. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  7129. return 0;
  7130. fail_unpin:
  7131. i915_gem_object_unpin_from_display_plane(obj);
  7132. fail_locked:
  7133. mutex_unlock(&dev->struct_mutex);
  7134. fail:
  7135. drm_gem_object_unreference_unlocked(&obj->base);
  7136. return ret;
  7137. }
  7138. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  7139. u16 *blue, uint32_t start, uint32_t size)
  7140. {
  7141. int end = (start + size > 256) ? 256 : start + size, i;
  7142. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7143. for (i = start; i < end; i++) {
  7144. intel_crtc->lut_r[i] = red[i] >> 8;
  7145. intel_crtc->lut_g[i] = green[i] >> 8;
  7146. intel_crtc->lut_b[i] = blue[i] >> 8;
  7147. }
  7148. intel_crtc_load_lut(crtc);
  7149. }
  7150. /* VESA 640x480x72Hz mode to set on the pipe */
  7151. static struct drm_display_mode load_detect_mode = {
  7152. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  7153. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  7154. };
  7155. struct drm_framebuffer *
  7156. __intel_framebuffer_create(struct drm_device *dev,
  7157. struct drm_mode_fb_cmd2 *mode_cmd,
  7158. struct drm_i915_gem_object *obj)
  7159. {
  7160. struct intel_framebuffer *intel_fb;
  7161. int ret;
  7162. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  7163. if (!intel_fb) {
  7164. drm_gem_object_unreference_unlocked(&obj->base);
  7165. return ERR_PTR(-ENOMEM);
  7166. }
  7167. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  7168. if (ret)
  7169. goto err;
  7170. return &intel_fb->base;
  7171. err:
  7172. drm_gem_object_unreference_unlocked(&obj->base);
  7173. kfree(intel_fb);
  7174. return ERR_PTR(ret);
  7175. }
  7176. static struct drm_framebuffer *
  7177. intel_framebuffer_create(struct drm_device *dev,
  7178. struct drm_mode_fb_cmd2 *mode_cmd,
  7179. struct drm_i915_gem_object *obj)
  7180. {
  7181. struct drm_framebuffer *fb;
  7182. int ret;
  7183. ret = i915_mutex_lock_interruptible(dev);
  7184. if (ret)
  7185. return ERR_PTR(ret);
  7186. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  7187. mutex_unlock(&dev->struct_mutex);
  7188. return fb;
  7189. }
  7190. static u32
  7191. intel_framebuffer_pitch_for_width(int width, int bpp)
  7192. {
  7193. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  7194. return ALIGN(pitch, 64);
  7195. }
  7196. static u32
  7197. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  7198. {
  7199. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  7200. return PAGE_ALIGN(pitch * mode->vdisplay);
  7201. }
  7202. static struct drm_framebuffer *
  7203. intel_framebuffer_create_for_mode(struct drm_device *dev,
  7204. struct drm_display_mode *mode,
  7205. int depth, int bpp)
  7206. {
  7207. struct drm_i915_gem_object *obj;
  7208. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  7209. obj = i915_gem_alloc_object(dev,
  7210. intel_framebuffer_size_for_mode(mode, bpp));
  7211. if (obj == NULL)
  7212. return ERR_PTR(-ENOMEM);
  7213. mode_cmd.width = mode->hdisplay;
  7214. mode_cmd.height = mode->vdisplay;
  7215. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  7216. bpp);
  7217. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  7218. return intel_framebuffer_create(dev, &mode_cmd, obj);
  7219. }
  7220. static struct drm_framebuffer *
  7221. mode_fits_in_fbdev(struct drm_device *dev,
  7222. struct drm_display_mode *mode)
  7223. {
  7224. #ifdef CONFIG_DRM_I915_FBDEV
  7225. struct drm_i915_private *dev_priv = dev->dev_private;
  7226. struct drm_i915_gem_object *obj;
  7227. struct drm_framebuffer *fb;
  7228. if (!dev_priv->fbdev)
  7229. return NULL;
  7230. if (!dev_priv->fbdev->fb)
  7231. return NULL;
  7232. obj = dev_priv->fbdev->fb->obj;
  7233. BUG_ON(!obj);
  7234. fb = &dev_priv->fbdev->fb->base;
  7235. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7236. fb->bits_per_pixel))
  7237. return NULL;
  7238. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7239. return NULL;
  7240. return fb;
  7241. #else
  7242. return NULL;
  7243. #endif
  7244. }
  7245. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7246. struct drm_display_mode *mode,
  7247. struct intel_load_detect_pipe *old,
  7248. struct drm_modeset_acquire_ctx *ctx)
  7249. {
  7250. struct intel_crtc *intel_crtc;
  7251. struct intel_encoder *intel_encoder =
  7252. intel_attached_encoder(connector);
  7253. struct drm_crtc *possible_crtc;
  7254. struct drm_encoder *encoder = &intel_encoder->base;
  7255. struct drm_crtc *crtc = NULL;
  7256. struct drm_device *dev = encoder->dev;
  7257. struct drm_framebuffer *fb;
  7258. struct drm_mode_config *config = &dev->mode_config;
  7259. int ret, i = -1;
  7260. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7261. connector->base.id, connector->name,
  7262. encoder->base.id, encoder->name);
  7263. retry:
  7264. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7265. if (ret)
  7266. goto fail_unlock;
  7267. /*
  7268. * Algorithm gets a little messy:
  7269. *
  7270. * - if the connector already has an assigned crtc, use it (but make
  7271. * sure it's on first)
  7272. *
  7273. * - try to find the first unused crtc that can drive this connector,
  7274. * and use that if we find one
  7275. */
  7276. /* See if we already have a CRTC for this connector */
  7277. if (encoder->crtc) {
  7278. crtc = encoder->crtc;
  7279. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7280. if (ret)
  7281. goto fail_unlock;
  7282. old->dpms_mode = connector->dpms;
  7283. old->load_detect_temp = false;
  7284. /* Make sure the crtc and connector are running */
  7285. if (connector->dpms != DRM_MODE_DPMS_ON)
  7286. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7287. return true;
  7288. }
  7289. /* Find an unused one (if possible) */
  7290. for_each_crtc(dev, possible_crtc) {
  7291. i++;
  7292. if (!(encoder->possible_crtcs & (1 << i)))
  7293. continue;
  7294. if (possible_crtc->enabled)
  7295. continue;
  7296. /* This can occur when applying the pipe A quirk on resume. */
  7297. if (to_intel_crtc(possible_crtc)->new_enabled)
  7298. continue;
  7299. crtc = possible_crtc;
  7300. break;
  7301. }
  7302. /*
  7303. * If we didn't find an unused CRTC, don't use any.
  7304. */
  7305. if (!crtc) {
  7306. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7307. goto fail_unlock;
  7308. }
  7309. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7310. if (ret)
  7311. goto fail_unlock;
  7312. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7313. to_intel_connector(connector)->new_encoder = intel_encoder;
  7314. intel_crtc = to_intel_crtc(crtc);
  7315. intel_crtc->new_enabled = true;
  7316. intel_crtc->new_config = &intel_crtc->config;
  7317. old->dpms_mode = connector->dpms;
  7318. old->load_detect_temp = true;
  7319. old->release_fb = NULL;
  7320. if (!mode)
  7321. mode = &load_detect_mode;
  7322. /* We need a framebuffer large enough to accommodate all accesses
  7323. * that the plane may generate whilst we perform load detection.
  7324. * We can not rely on the fbcon either being present (we get called
  7325. * during its initialisation to detect all boot displays, or it may
  7326. * not even exist) or that it is large enough to satisfy the
  7327. * requested mode.
  7328. */
  7329. fb = mode_fits_in_fbdev(dev, mode);
  7330. if (fb == NULL) {
  7331. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7332. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7333. old->release_fb = fb;
  7334. } else
  7335. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7336. if (IS_ERR(fb)) {
  7337. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7338. goto fail;
  7339. }
  7340. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7341. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7342. if (old->release_fb)
  7343. old->release_fb->funcs->destroy(old->release_fb);
  7344. goto fail;
  7345. }
  7346. /* let the connector get through one full cycle before testing */
  7347. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7348. return true;
  7349. fail:
  7350. intel_crtc->new_enabled = crtc->enabled;
  7351. if (intel_crtc->new_enabled)
  7352. intel_crtc->new_config = &intel_crtc->config;
  7353. else
  7354. intel_crtc->new_config = NULL;
  7355. fail_unlock:
  7356. if (ret == -EDEADLK) {
  7357. drm_modeset_backoff(ctx);
  7358. goto retry;
  7359. }
  7360. return false;
  7361. }
  7362. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7363. struct intel_load_detect_pipe *old)
  7364. {
  7365. struct intel_encoder *intel_encoder =
  7366. intel_attached_encoder(connector);
  7367. struct drm_encoder *encoder = &intel_encoder->base;
  7368. struct drm_crtc *crtc = encoder->crtc;
  7369. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7370. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7371. connector->base.id, connector->name,
  7372. encoder->base.id, encoder->name);
  7373. if (old->load_detect_temp) {
  7374. to_intel_connector(connector)->new_encoder = NULL;
  7375. intel_encoder->new_crtc = NULL;
  7376. intel_crtc->new_enabled = false;
  7377. intel_crtc->new_config = NULL;
  7378. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7379. if (old->release_fb) {
  7380. drm_framebuffer_unregister_private(old->release_fb);
  7381. drm_framebuffer_unreference(old->release_fb);
  7382. }
  7383. return;
  7384. }
  7385. /* Switch crtc and encoder back off if necessary */
  7386. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7387. connector->funcs->dpms(connector, old->dpms_mode);
  7388. }
  7389. static int i9xx_pll_refclk(struct drm_device *dev,
  7390. const struct intel_crtc_config *pipe_config)
  7391. {
  7392. struct drm_i915_private *dev_priv = dev->dev_private;
  7393. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7394. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7395. return dev_priv->vbt.lvds_ssc_freq;
  7396. else if (HAS_PCH_SPLIT(dev))
  7397. return 120000;
  7398. else if (!IS_GEN2(dev))
  7399. return 96000;
  7400. else
  7401. return 48000;
  7402. }
  7403. /* Returns the clock of the currently programmed mode of the given pipe. */
  7404. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7405. struct intel_crtc_config *pipe_config)
  7406. {
  7407. struct drm_device *dev = crtc->base.dev;
  7408. struct drm_i915_private *dev_priv = dev->dev_private;
  7409. int pipe = pipe_config->cpu_transcoder;
  7410. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7411. u32 fp;
  7412. intel_clock_t clock;
  7413. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7414. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7415. fp = pipe_config->dpll_hw_state.fp0;
  7416. else
  7417. fp = pipe_config->dpll_hw_state.fp1;
  7418. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7419. if (IS_PINEVIEW(dev)) {
  7420. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7421. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7422. } else {
  7423. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7424. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7425. }
  7426. if (!IS_GEN2(dev)) {
  7427. if (IS_PINEVIEW(dev))
  7428. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7429. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7430. else
  7431. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7432. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7433. switch (dpll & DPLL_MODE_MASK) {
  7434. case DPLLB_MODE_DAC_SERIAL:
  7435. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7436. 5 : 10;
  7437. break;
  7438. case DPLLB_MODE_LVDS:
  7439. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7440. 7 : 14;
  7441. break;
  7442. default:
  7443. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7444. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7445. return;
  7446. }
  7447. if (IS_PINEVIEW(dev))
  7448. pineview_clock(refclk, &clock);
  7449. else
  7450. i9xx_clock(refclk, &clock);
  7451. } else {
  7452. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7453. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7454. if (is_lvds) {
  7455. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7456. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7457. if (lvds & LVDS_CLKB_POWER_UP)
  7458. clock.p2 = 7;
  7459. else
  7460. clock.p2 = 14;
  7461. } else {
  7462. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7463. clock.p1 = 2;
  7464. else {
  7465. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7466. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7467. }
  7468. if (dpll & PLL_P2_DIVIDE_BY_4)
  7469. clock.p2 = 4;
  7470. else
  7471. clock.p2 = 2;
  7472. }
  7473. i9xx_clock(refclk, &clock);
  7474. }
  7475. /*
  7476. * This value includes pixel_multiplier. We will use
  7477. * port_clock to compute adjusted_mode.crtc_clock in the
  7478. * encoder's get_config() function.
  7479. */
  7480. pipe_config->port_clock = clock.dot;
  7481. }
  7482. int intel_dotclock_calculate(int link_freq,
  7483. const struct intel_link_m_n *m_n)
  7484. {
  7485. /*
  7486. * The calculation for the data clock is:
  7487. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7488. * But we want to avoid losing precison if possible, so:
  7489. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7490. *
  7491. * and the link clock is simpler:
  7492. * link_clock = (m * link_clock) / n
  7493. */
  7494. if (!m_n->link_n)
  7495. return 0;
  7496. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7497. }
  7498. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7499. struct intel_crtc_config *pipe_config)
  7500. {
  7501. struct drm_device *dev = crtc->base.dev;
  7502. /* read out port_clock from the DPLL */
  7503. i9xx_crtc_clock_get(crtc, pipe_config);
  7504. /*
  7505. * This value does not include pixel_multiplier.
  7506. * We will check that port_clock and adjusted_mode.crtc_clock
  7507. * agree once we know their relationship in the encoder's
  7508. * get_config() function.
  7509. */
  7510. pipe_config->adjusted_mode.crtc_clock =
  7511. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7512. &pipe_config->fdi_m_n);
  7513. }
  7514. /** Returns the currently programmed mode of the given pipe. */
  7515. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7516. struct drm_crtc *crtc)
  7517. {
  7518. struct drm_i915_private *dev_priv = dev->dev_private;
  7519. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7520. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7521. struct drm_display_mode *mode;
  7522. struct intel_crtc_config pipe_config;
  7523. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7524. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7525. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7526. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7527. enum pipe pipe = intel_crtc->pipe;
  7528. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7529. if (!mode)
  7530. return NULL;
  7531. /*
  7532. * Construct a pipe_config sufficient for getting the clock info
  7533. * back out of crtc_clock_get.
  7534. *
  7535. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7536. * to use a real value here instead.
  7537. */
  7538. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7539. pipe_config.pixel_multiplier = 1;
  7540. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7541. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7542. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7543. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7544. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7545. mode->hdisplay = (htot & 0xffff) + 1;
  7546. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7547. mode->hsync_start = (hsync & 0xffff) + 1;
  7548. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7549. mode->vdisplay = (vtot & 0xffff) + 1;
  7550. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7551. mode->vsync_start = (vsync & 0xffff) + 1;
  7552. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7553. drm_mode_set_name(mode);
  7554. return mode;
  7555. }
  7556. static void intel_increase_pllclock(struct drm_device *dev,
  7557. enum pipe pipe)
  7558. {
  7559. struct drm_i915_private *dev_priv = dev->dev_private;
  7560. int dpll_reg = DPLL(pipe);
  7561. int dpll;
  7562. if (!HAS_GMCH_DISPLAY(dev))
  7563. return;
  7564. if (!dev_priv->lvds_downclock_avail)
  7565. return;
  7566. dpll = I915_READ(dpll_reg);
  7567. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  7568. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  7569. assert_panel_unlocked(dev_priv, pipe);
  7570. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  7571. I915_WRITE(dpll_reg, dpll);
  7572. intel_wait_for_vblank(dev, pipe);
  7573. dpll = I915_READ(dpll_reg);
  7574. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  7575. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  7576. }
  7577. }
  7578. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7579. {
  7580. struct drm_device *dev = crtc->dev;
  7581. struct drm_i915_private *dev_priv = dev->dev_private;
  7582. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7583. if (!HAS_GMCH_DISPLAY(dev))
  7584. return;
  7585. if (!dev_priv->lvds_downclock_avail)
  7586. return;
  7587. /*
  7588. * Since this is called by a timer, we should never get here in
  7589. * the manual case.
  7590. */
  7591. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7592. int pipe = intel_crtc->pipe;
  7593. int dpll_reg = DPLL(pipe);
  7594. int dpll;
  7595. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7596. assert_panel_unlocked(dev_priv, pipe);
  7597. dpll = I915_READ(dpll_reg);
  7598. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7599. I915_WRITE(dpll_reg, dpll);
  7600. intel_wait_for_vblank(dev, pipe);
  7601. dpll = I915_READ(dpll_reg);
  7602. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7603. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7604. }
  7605. }
  7606. void intel_mark_busy(struct drm_device *dev)
  7607. {
  7608. struct drm_i915_private *dev_priv = dev->dev_private;
  7609. if (dev_priv->mm.busy)
  7610. return;
  7611. intel_runtime_pm_get(dev_priv);
  7612. i915_update_gfx_val(dev_priv);
  7613. dev_priv->mm.busy = true;
  7614. }
  7615. void intel_mark_idle(struct drm_device *dev)
  7616. {
  7617. struct drm_i915_private *dev_priv = dev->dev_private;
  7618. struct drm_crtc *crtc;
  7619. if (!dev_priv->mm.busy)
  7620. return;
  7621. dev_priv->mm.busy = false;
  7622. if (!i915.powersave)
  7623. goto out;
  7624. for_each_crtc(dev, crtc) {
  7625. if (!crtc->primary->fb)
  7626. continue;
  7627. intel_decrease_pllclock(crtc);
  7628. }
  7629. if (INTEL_INFO(dev)->gen >= 6)
  7630. gen6_rps_idle(dev->dev_private);
  7631. out:
  7632. intel_runtime_pm_put(dev_priv);
  7633. }
  7634. /**
  7635. * intel_mark_fb_busy - mark given planes as busy
  7636. * @dev: DRM device
  7637. * @frontbuffer_bits: bits for the affected planes
  7638. * @ring: optional ring for asynchronous commands
  7639. *
  7640. * This function gets called every time the screen contents change. It can be
  7641. * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
  7642. */
  7643. static void intel_mark_fb_busy(struct drm_device *dev,
  7644. unsigned frontbuffer_bits,
  7645. struct intel_engine_cs *ring)
  7646. {
  7647. struct drm_i915_private *dev_priv = dev->dev_private;
  7648. enum pipe pipe;
  7649. if (!i915.powersave)
  7650. return;
  7651. for_each_pipe(dev_priv, pipe) {
  7652. if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)))
  7653. continue;
  7654. intel_increase_pllclock(dev, pipe);
  7655. if (ring && intel_fbc_enabled(dev))
  7656. ring->fbc_dirty = true;
  7657. }
  7658. }
  7659. /**
  7660. * intel_fb_obj_invalidate - invalidate frontbuffer object
  7661. * @obj: GEM object to invalidate
  7662. * @ring: set for asynchronous rendering
  7663. *
  7664. * This function gets called every time rendering on the given object starts and
  7665. * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
  7666. * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
  7667. * until the rendering completes or a flip on this frontbuffer plane is
  7668. * scheduled.
  7669. */
  7670. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  7671. struct intel_engine_cs *ring)
  7672. {
  7673. struct drm_device *dev = obj->base.dev;
  7674. struct drm_i915_private *dev_priv = dev->dev_private;
  7675. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7676. if (!obj->frontbuffer_bits)
  7677. return;
  7678. if (ring) {
  7679. mutex_lock(&dev_priv->fb_tracking.lock);
  7680. dev_priv->fb_tracking.busy_bits
  7681. |= obj->frontbuffer_bits;
  7682. dev_priv->fb_tracking.flip_bits
  7683. &= ~obj->frontbuffer_bits;
  7684. mutex_unlock(&dev_priv->fb_tracking.lock);
  7685. }
  7686. intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring);
  7687. intel_edp_psr_invalidate(dev, obj->frontbuffer_bits);
  7688. }
  7689. /**
  7690. * intel_frontbuffer_flush - flush frontbuffer
  7691. * @dev: DRM device
  7692. * @frontbuffer_bits: frontbuffer plane tracking bits
  7693. *
  7694. * This function gets called every time rendering on the given planes has
  7695. * completed and frontbuffer caching can be started again. Flushes will get
  7696. * delayed if they're blocked by some oustanding asynchronous rendering.
  7697. *
  7698. * Can be called without any locks held.
  7699. */
  7700. void intel_frontbuffer_flush(struct drm_device *dev,
  7701. unsigned frontbuffer_bits)
  7702. {
  7703. struct drm_i915_private *dev_priv = dev->dev_private;
  7704. /* Delay flushing when rings are still busy.*/
  7705. mutex_lock(&dev_priv->fb_tracking.lock);
  7706. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  7707. mutex_unlock(&dev_priv->fb_tracking.lock);
  7708. intel_mark_fb_busy(dev, frontbuffer_bits, NULL);
  7709. intel_edp_psr_flush(dev, frontbuffer_bits);
  7710. /*
  7711. * FIXME: Unconditional fbc flushing here is a rather gross hack and
  7712. * needs to be reworked into a proper frontbuffer tracking scheme like
  7713. * psr employs.
  7714. */
  7715. if (IS_BROADWELL(dev))
  7716. gen8_fbc_sw_flush(dev, FBC_REND_CACHE_CLEAN);
  7717. }
  7718. /**
  7719. * intel_fb_obj_flush - flush frontbuffer object
  7720. * @obj: GEM object to flush
  7721. * @retire: set when retiring asynchronous rendering
  7722. *
  7723. * This function gets called every time rendering on the given object has
  7724. * completed and frontbuffer caching can be started again. If @retire is true
  7725. * then any delayed flushes will be unblocked.
  7726. */
  7727. void intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  7728. bool retire)
  7729. {
  7730. struct drm_device *dev = obj->base.dev;
  7731. struct drm_i915_private *dev_priv = dev->dev_private;
  7732. unsigned frontbuffer_bits;
  7733. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7734. if (!obj->frontbuffer_bits)
  7735. return;
  7736. frontbuffer_bits = obj->frontbuffer_bits;
  7737. if (retire) {
  7738. mutex_lock(&dev_priv->fb_tracking.lock);
  7739. /* Filter out new bits since rendering started. */
  7740. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  7741. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  7742. mutex_unlock(&dev_priv->fb_tracking.lock);
  7743. }
  7744. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7745. }
  7746. /**
  7747. * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
  7748. * @dev: DRM device
  7749. * @frontbuffer_bits: frontbuffer plane tracking bits
  7750. *
  7751. * This function gets called after scheduling a flip on @obj. The actual
  7752. * frontbuffer flushing will be delayed until completion is signalled with
  7753. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  7754. * flush will be cancelled.
  7755. *
  7756. * Can be called without any locks held.
  7757. */
  7758. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  7759. unsigned frontbuffer_bits)
  7760. {
  7761. struct drm_i915_private *dev_priv = dev->dev_private;
  7762. mutex_lock(&dev_priv->fb_tracking.lock);
  7763. dev_priv->fb_tracking.flip_bits
  7764. |= frontbuffer_bits;
  7765. mutex_unlock(&dev_priv->fb_tracking.lock);
  7766. }
  7767. /**
  7768. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
  7769. * @dev: DRM device
  7770. * @frontbuffer_bits: frontbuffer plane tracking bits
  7771. *
  7772. * This function gets called after the flip has been latched and will complete
  7773. * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
  7774. *
  7775. * Can be called without any locks held.
  7776. */
  7777. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  7778. unsigned frontbuffer_bits)
  7779. {
  7780. struct drm_i915_private *dev_priv = dev->dev_private;
  7781. mutex_lock(&dev_priv->fb_tracking.lock);
  7782. /* Mask any cancelled flips. */
  7783. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  7784. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  7785. mutex_unlock(&dev_priv->fb_tracking.lock);
  7786. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7787. }
  7788. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7789. {
  7790. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7791. struct drm_device *dev = crtc->dev;
  7792. struct intel_unpin_work *work;
  7793. unsigned long flags;
  7794. spin_lock_irqsave(&dev->event_lock, flags);
  7795. work = intel_crtc->unpin_work;
  7796. intel_crtc->unpin_work = NULL;
  7797. spin_unlock_irqrestore(&dev->event_lock, flags);
  7798. if (work) {
  7799. cancel_work_sync(&work->work);
  7800. kfree(work);
  7801. }
  7802. drm_crtc_cleanup(crtc);
  7803. kfree(intel_crtc);
  7804. }
  7805. static void intel_unpin_work_fn(struct work_struct *__work)
  7806. {
  7807. struct intel_unpin_work *work =
  7808. container_of(__work, struct intel_unpin_work, work);
  7809. struct drm_device *dev = work->crtc->dev;
  7810. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7811. mutex_lock(&dev->struct_mutex);
  7812. intel_unpin_fb_obj(work->old_fb_obj);
  7813. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7814. drm_gem_object_unreference(&work->old_fb_obj->base);
  7815. intel_update_fbc(dev);
  7816. mutex_unlock(&dev->struct_mutex);
  7817. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7818. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7819. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7820. kfree(work);
  7821. }
  7822. static void do_intel_finish_page_flip(struct drm_device *dev,
  7823. struct drm_crtc *crtc)
  7824. {
  7825. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7826. struct intel_unpin_work *work;
  7827. unsigned long flags;
  7828. /* Ignore early vblank irqs */
  7829. if (intel_crtc == NULL)
  7830. return;
  7831. spin_lock_irqsave(&dev->event_lock, flags);
  7832. work = intel_crtc->unpin_work;
  7833. /* Ensure we don't miss a work->pending update ... */
  7834. smp_rmb();
  7835. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7836. spin_unlock_irqrestore(&dev->event_lock, flags);
  7837. return;
  7838. }
  7839. page_flip_completed(intel_crtc);
  7840. spin_unlock_irqrestore(&dev->event_lock, flags);
  7841. }
  7842. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7843. {
  7844. struct drm_i915_private *dev_priv = dev->dev_private;
  7845. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7846. do_intel_finish_page_flip(dev, crtc);
  7847. }
  7848. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7849. {
  7850. struct drm_i915_private *dev_priv = dev->dev_private;
  7851. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7852. do_intel_finish_page_flip(dev, crtc);
  7853. }
  7854. /* Is 'a' after or equal to 'b'? */
  7855. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7856. {
  7857. return !((a - b) & 0x80000000);
  7858. }
  7859. static bool page_flip_finished(struct intel_crtc *crtc)
  7860. {
  7861. struct drm_device *dev = crtc->base.dev;
  7862. struct drm_i915_private *dev_priv = dev->dev_private;
  7863. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  7864. crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  7865. return true;
  7866. /*
  7867. * The relevant registers doen't exist on pre-ctg.
  7868. * As the flip done interrupt doesn't trigger for mmio
  7869. * flips on gmch platforms, a flip count check isn't
  7870. * really needed there. But since ctg has the registers,
  7871. * include it in the check anyway.
  7872. */
  7873. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7874. return true;
  7875. /*
  7876. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7877. * used the same base address. In that case the mmio flip might
  7878. * have completed, but the CS hasn't even executed the flip yet.
  7879. *
  7880. * A flip count check isn't enough as the CS might have updated
  7881. * the base address just after start of vblank, but before we
  7882. * managed to process the interrupt. This means we'd complete the
  7883. * CS flip too soon.
  7884. *
  7885. * Combining both checks should get us a good enough result. It may
  7886. * still happen that the CS flip has been executed, but has not
  7887. * yet actually completed. But in case the base address is the same
  7888. * anyway, we don't really care.
  7889. */
  7890. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7891. crtc->unpin_work->gtt_offset &&
  7892. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7893. crtc->unpin_work->flip_count);
  7894. }
  7895. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7896. {
  7897. struct drm_i915_private *dev_priv = dev->dev_private;
  7898. struct intel_crtc *intel_crtc =
  7899. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7900. unsigned long flags;
  7901. /* NB: An MMIO update of the plane base pointer will also
  7902. * generate a page-flip completion irq, i.e. every modeset
  7903. * is also accompanied by a spurious intel_prepare_page_flip().
  7904. */
  7905. spin_lock_irqsave(&dev->event_lock, flags);
  7906. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7907. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7908. spin_unlock_irqrestore(&dev->event_lock, flags);
  7909. }
  7910. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7911. {
  7912. /* Ensure that the work item is consistent when activating it ... */
  7913. smp_wmb();
  7914. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7915. /* and that it is marked active as soon as the irq could fire. */
  7916. smp_wmb();
  7917. }
  7918. static int intel_gen2_queue_flip(struct drm_device *dev,
  7919. struct drm_crtc *crtc,
  7920. struct drm_framebuffer *fb,
  7921. struct drm_i915_gem_object *obj,
  7922. struct intel_engine_cs *ring,
  7923. uint32_t flags)
  7924. {
  7925. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7926. u32 flip_mask;
  7927. int ret;
  7928. ret = intel_ring_begin(ring, 6);
  7929. if (ret)
  7930. return ret;
  7931. /* Can't queue multiple flips, so wait for the previous
  7932. * one to finish before executing the next.
  7933. */
  7934. if (intel_crtc->plane)
  7935. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7936. else
  7937. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7938. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7939. intel_ring_emit(ring, MI_NOOP);
  7940. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7941. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7942. intel_ring_emit(ring, fb->pitches[0]);
  7943. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7944. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7945. intel_mark_page_flip_active(intel_crtc);
  7946. __intel_ring_advance(ring);
  7947. return 0;
  7948. }
  7949. static int intel_gen3_queue_flip(struct drm_device *dev,
  7950. struct drm_crtc *crtc,
  7951. struct drm_framebuffer *fb,
  7952. struct drm_i915_gem_object *obj,
  7953. struct intel_engine_cs *ring,
  7954. uint32_t flags)
  7955. {
  7956. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7957. u32 flip_mask;
  7958. int ret;
  7959. ret = intel_ring_begin(ring, 6);
  7960. if (ret)
  7961. return ret;
  7962. if (intel_crtc->plane)
  7963. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7964. else
  7965. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7966. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7967. intel_ring_emit(ring, MI_NOOP);
  7968. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7969. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7970. intel_ring_emit(ring, fb->pitches[0]);
  7971. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7972. intel_ring_emit(ring, MI_NOOP);
  7973. intel_mark_page_flip_active(intel_crtc);
  7974. __intel_ring_advance(ring);
  7975. return 0;
  7976. }
  7977. static int intel_gen4_queue_flip(struct drm_device *dev,
  7978. struct drm_crtc *crtc,
  7979. struct drm_framebuffer *fb,
  7980. struct drm_i915_gem_object *obj,
  7981. struct intel_engine_cs *ring,
  7982. uint32_t flags)
  7983. {
  7984. struct drm_i915_private *dev_priv = dev->dev_private;
  7985. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7986. uint32_t pf, pipesrc;
  7987. int ret;
  7988. ret = intel_ring_begin(ring, 4);
  7989. if (ret)
  7990. return ret;
  7991. /* i965+ uses the linear or tiled offsets from the
  7992. * Display Registers (which do not change across a page-flip)
  7993. * so we need only reprogram the base address.
  7994. */
  7995. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7996. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7997. intel_ring_emit(ring, fb->pitches[0]);
  7998. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7999. obj->tiling_mode);
  8000. /* XXX Enabling the panel-fitter across page-flip is so far
  8001. * untested on non-native modes, so ignore it for now.
  8002. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  8003. */
  8004. pf = 0;
  8005. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  8006. intel_ring_emit(ring, pf | pipesrc);
  8007. intel_mark_page_flip_active(intel_crtc);
  8008. __intel_ring_advance(ring);
  8009. return 0;
  8010. }
  8011. static int intel_gen6_queue_flip(struct drm_device *dev,
  8012. struct drm_crtc *crtc,
  8013. struct drm_framebuffer *fb,
  8014. struct drm_i915_gem_object *obj,
  8015. struct intel_engine_cs *ring,
  8016. uint32_t flags)
  8017. {
  8018. struct drm_i915_private *dev_priv = dev->dev_private;
  8019. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8020. uint32_t pf, pipesrc;
  8021. int ret;
  8022. ret = intel_ring_begin(ring, 4);
  8023. if (ret)
  8024. return ret;
  8025. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  8026. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  8027. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  8028. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  8029. /* Contrary to the suggestions in the documentation,
  8030. * "Enable Panel Fitter" does not seem to be required when page
  8031. * flipping with a non-native mode, and worse causes a normal
  8032. * modeset to fail.
  8033. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  8034. */
  8035. pf = 0;
  8036. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  8037. intel_ring_emit(ring, pf | pipesrc);
  8038. intel_mark_page_flip_active(intel_crtc);
  8039. __intel_ring_advance(ring);
  8040. return 0;
  8041. }
  8042. static int intel_gen7_queue_flip(struct drm_device *dev,
  8043. struct drm_crtc *crtc,
  8044. struct drm_framebuffer *fb,
  8045. struct drm_i915_gem_object *obj,
  8046. struct intel_engine_cs *ring,
  8047. uint32_t flags)
  8048. {
  8049. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8050. uint32_t plane_bit = 0;
  8051. int len, ret;
  8052. switch (intel_crtc->plane) {
  8053. case PLANE_A:
  8054. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  8055. break;
  8056. case PLANE_B:
  8057. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  8058. break;
  8059. case PLANE_C:
  8060. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  8061. break;
  8062. default:
  8063. WARN_ONCE(1, "unknown plane in flip command\n");
  8064. return -ENODEV;
  8065. }
  8066. len = 4;
  8067. if (ring->id == RCS) {
  8068. len += 6;
  8069. /*
  8070. * On Gen 8, SRM is now taking an extra dword to accommodate
  8071. * 48bits addresses, and we need a NOOP for the batch size to
  8072. * stay even.
  8073. */
  8074. if (IS_GEN8(dev))
  8075. len += 2;
  8076. }
  8077. /*
  8078. * BSpec MI_DISPLAY_FLIP for IVB:
  8079. * "The full packet must be contained within the same cache line."
  8080. *
  8081. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  8082. * cacheline, if we ever start emitting more commands before
  8083. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  8084. * then do the cacheline alignment, and finally emit the
  8085. * MI_DISPLAY_FLIP.
  8086. */
  8087. ret = intel_ring_cacheline_align(ring);
  8088. if (ret)
  8089. return ret;
  8090. ret = intel_ring_begin(ring, len);
  8091. if (ret)
  8092. return ret;
  8093. /* Unmask the flip-done completion message. Note that the bspec says that
  8094. * we should do this for both the BCS and RCS, and that we must not unmask
  8095. * more than one flip event at any time (or ensure that one flip message
  8096. * can be sent by waiting for flip-done prior to queueing new flips).
  8097. * Experimentation says that BCS works despite DERRMR masking all
  8098. * flip-done completion events and that unmasking all planes at once
  8099. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  8100. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  8101. */
  8102. if (ring->id == RCS) {
  8103. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  8104. intel_ring_emit(ring, DERRMR);
  8105. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  8106. DERRMR_PIPEB_PRI_FLIP_DONE |
  8107. DERRMR_PIPEC_PRI_FLIP_DONE));
  8108. if (IS_GEN8(dev))
  8109. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  8110. MI_SRM_LRM_GLOBAL_GTT);
  8111. else
  8112. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  8113. MI_SRM_LRM_GLOBAL_GTT);
  8114. intel_ring_emit(ring, DERRMR);
  8115. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  8116. if (IS_GEN8(dev)) {
  8117. intel_ring_emit(ring, 0);
  8118. intel_ring_emit(ring, MI_NOOP);
  8119. }
  8120. }
  8121. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  8122. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  8123. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  8124. intel_ring_emit(ring, (MI_NOOP));
  8125. intel_mark_page_flip_active(intel_crtc);
  8126. __intel_ring_advance(ring);
  8127. return 0;
  8128. }
  8129. static bool use_mmio_flip(struct intel_engine_cs *ring,
  8130. struct drm_i915_gem_object *obj)
  8131. {
  8132. /*
  8133. * This is not being used for older platforms, because
  8134. * non-availability of flip done interrupt forces us to use
  8135. * CS flips. Older platforms derive flip done using some clever
  8136. * tricks involving the flip_pending status bits and vblank irqs.
  8137. * So using MMIO flips there would disrupt this mechanism.
  8138. */
  8139. if (ring == NULL)
  8140. return true;
  8141. if (INTEL_INFO(ring->dev)->gen < 5)
  8142. return false;
  8143. if (i915.use_mmio_flip < 0)
  8144. return false;
  8145. else if (i915.use_mmio_flip > 0)
  8146. return true;
  8147. else if (i915.enable_execlists)
  8148. return true;
  8149. else
  8150. return ring != obj->ring;
  8151. }
  8152. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  8153. {
  8154. struct drm_device *dev = intel_crtc->base.dev;
  8155. struct drm_i915_private *dev_priv = dev->dev_private;
  8156. struct intel_framebuffer *intel_fb =
  8157. to_intel_framebuffer(intel_crtc->base.primary->fb);
  8158. struct drm_i915_gem_object *obj = intel_fb->obj;
  8159. u32 dspcntr;
  8160. u32 reg;
  8161. intel_mark_page_flip_active(intel_crtc);
  8162. reg = DSPCNTR(intel_crtc->plane);
  8163. dspcntr = I915_READ(reg);
  8164. if (INTEL_INFO(dev)->gen >= 4) {
  8165. if (obj->tiling_mode != I915_TILING_NONE)
  8166. dspcntr |= DISPPLANE_TILED;
  8167. else
  8168. dspcntr &= ~DISPPLANE_TILED;
  8169. }
  8170. I915_WRITE(reg, dspcntr);
  8171. I915_WRITE(DSPSURF(intel_crtc->plane),
  8172. intel_crtc->unpin_work->gtt_offset);
  8173. POSTING_READ(DSPSURF(intel_crtc->plane));
  8174. }
  8175. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  8176. {
  8177. struct intel_engine_cs *ring;
  8178. int ret;
  8179. lockdep_assert_held(&obj->base.dev->struct_mutex);
  8180. if (!obj->last_write_seqno)
  8181. return 0;
  8182. ring = obj->ring;
  8183. if (i915_seqno_passed(ring->get_seqno(ring, true),
  8184. obj->last_write_seqno))
  8185. return 0;
  8186. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  8187. if (ret)
  8188. return ret;
  8189. if (WARN_ON(!ring->irq_get(ring)))
  8190. return 0;
  8191. return 1;
  8192. }
  8193. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  8194. {
  8195. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  8196. struct intel_crtc *intel_crtc;
  8197. unsigned long irq_flags;
  8198. u32 seqno;
  8199. seqno = ring->get_seqno(ring, false);
  8200. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8201. for_each_intel_crtc(ring->dev, intel_crtc) {
  8202. struct intel_mmio_flip *mmio_flip;
  8203. mmio_flip = &intel_crtc->mmio_flip;
  8204. if (mmio_flip->seqno == 0)
  8205. continue;
  8206. if (ring->id != mmio_flip->ring_id)
  8207. continue;
  8208. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  8209. intel_do_mmio_flip(intel_crtc);
  8210. mmio_flip->seqno = 0;
  8211. ring->irq_put(ring);
  8212. }
  8213. }
  8214. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8215. }
  8216. static int intel_queue_mmio_flip(struct drm_device *dev,
  8217. struct drm_crtc *crtc,
  8218. struct drm_framebuffer *fb,
  8219. struct drm_i915_gem_object *obj,
  8220. struct intel_engine_cs *ring,
  8221. uint32_t flags)
  8222. {
  8223. struct drm_i915_private *dev_priv = dev->dev_private;
  8224. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8225. unsigned long irq_flags;
  8226. int ret;
  8227. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  8228. return -EBUSY;
  8229. ret = intel_postpone_flip(obj);
  8230. if (ret < 0)
  8231. return ret;
  8232. if (ret == 0) {
  8233. intel_do_mmio_flip(intel_crtc);
  8234. return 0;
  8235. }
  8236. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8237. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8238. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8239. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8240. /*
  8241. * Double check to catch cases where irq fired before
  8242. * mmio flip data was ready
  8243. */
  8244. intel_notify_mmio_flip(obj->ring);
  8245. return 0;
  8246. }
  8247. static int intel_default_queue_flip(struct drm_device *dev,
  8248. struct drm_crtc *crtc,
  8249. struct drm_framebuffer *fb,
  8250. struct drm_i915_gem_object *obj,
  8251. struct intel_engine_cs *ring,
  8252. uint32_t flags)
  8253. {
  8254. return -ENODEV;
  8255. }
  8256. static bool __intel_pageflip_stall_check(struct drm_device *dev,
  8257. struct drm_crtc *crtc)
  8258. {
  8259. struct drm_i915_private *dev_priv = dev->dev_private;
  8260. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8261. struct intel_unpin_work *work = intel_crtc->unpin_work;
  8262. u32 addr;
  8263. if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE)
  8264. return true;
  8265. if (!work->enable_stall_check)
  8266. return false;
  8267. if (work->flip_ready_vblank == 0) {
  8268. if (work->flip_queued_ring &&
  8269. !i915_seqno_passed(work->flip_queued_ring->get_seqno(work->flip_queued_ring, true),
  8270. work->flip_queued_seqno))
  8271. return false;
  8272. work->flip_ready_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8273. }
  8274. if (drm_vblank_count(dev, intel_crtc->pipe) - work->flip_ready_vblank < 3)
  8275. return false;
  8276. /* Potential stall - if we see that the flip has happened,
  8277. * assume a missed interrupt. */
  8278. if (INTEL_INFO(dev)->gen >= 4)
  8279. addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane)));
  8280. else
  8281. addr = I915_READ(DSPADDR(intel_crtc->plane));
  8282. /* There is a potential issue here with a false positive after a flip
  8283. * to the same address. We could address this by checking for a
  8284. * non-incrementing frame counter.
  8285. */
  8286. return addr == work->gtt_offset;
  8287. }
  8288. void intel_check_page_flip(struct drm_device *dev, int pipe)
  8289. {
  8290. struct drm_i915_private *dev_priv = dev->dev_private;
  8291. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  8292. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8293. unsigned long flags;
  8294. if (crtc == NULL)
  8295. return;
  8296. spin_lock_irqsave(&dev->event_lock, flags);
  8297. if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) {
  8298. WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
  8299. intel_crtc->unpin_work->flip_queued_vblank, drm_vblank_count(dev, pipe));
  8300. page_flip_completed(intel_crtc);
  8301. }
  8302. spin_unlock_irqrestore(&dev->event_lock, flags);
  8303. }
  8304. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8305. struct drm_framebuffer *fb,
  8306. struct drm_pending_vblank_event *event,
  8307. uint32_t page_flip_flags)
  8308. {
  8309. struct drm_device *dev = crtc->dev;
  8310. struct drm_i915_private *dev_priv = dev->dev_private;
  8311. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8312. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  8313. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8314. enum pipe pipe = intel_crtc->pipe;
  8315. struct intel_unpin_work *work;
  8316. struct intel_engine_cs *ring;
  8317. unsigned long flags;
  8318. int ret;
  8319. /*
  8320. * drm_mode_page_flip_ioctl() should already catch this, but double
  8321. * check to be safe. In the future we may enable pageflipping from
  8322. * a disabled primary plane.
  8323. */
  8324. if (WARN_ON(intel_fb_obj(old_fb) == NULL))
  8325. return -EBUSY;
  8326. /* Can't change pixel format via MI display flips. */
  8327. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8328. return -EINVAL;
  8329. /*
  8330. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8331. * Note that pitch changes could also affect these register.
  8332. */
  8333. if (INTEL_INFO(dev)->gen > 3 &&
  8334. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8335. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8336. return -EINVAL;
  8337. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8338. goto out_hang;
  8339. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8340. if (work == NULL)
  8341. return -ENOMEM;
  8342. work->event = event;
  8343. work->crtc = crtc;
  8344. work->old_fb_obj = intel_fb_obj(old_fb);
  8345. INIT_WORK(&work->work, intel_unpin_work_fn);
  8346. ret = drm_crtc_vblank_get(crtc);
  8347. if (ret)
  8348. goto free_work;
  8349. /* We borrow the event spin lock for protecting unpin_work */
  8350. spin_lock_irqsave(&dev->event_lock, flags);
  8351. if (intel_crtc->unpin_work) {
  8352. /* Before declaring the flip queue wedged, check if
  8353. * the hardware completed the operation behind our backs.
  8354. */
  8355. if (__intel_pageflip_stall_check(dev, crtc)) {
  8356. DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
  8357. page_flip_completed(intel_crtc);
  8358. } else {
  8359. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8360. spin_unlock_irqrestore(&dev->event_lock, flags);
  8361. drm_crtc_vblank_put(crtc);
  8362. kfree(work);
  8363. return -EBUSY;
  8364. }
  8365. }
  8366. intel_crtc->unpin_work = work;
  8367. spin_unlock_irqrestore(&dev->event_lock, flags);
  8368. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8369. flush_workqueue(dev_priv->wq);
  8370. ret = i915_mutex_lock_interruptible(dev);
  8371. if (ret)
  8372. goto cleanup;
  8373. /* Reference the objects for the scheduled work. */
  8374. drm_gem_object_reference(&work->old_fb_obj->base);
  8375. drm_gem_object_reference(&obj->base);
  8376. crtc->primary->fb = fb;
  8377. work->pending_flip_obj = obj;
  8378. atomic_inc(&intel_crtc->unpin_work_count);
  8379. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8380. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8381. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8382. if (IS_VALLEYVIEW(dev)) {
  8383. ring = &dev_priv->ring[BCS];
  8384. if (obj->tiling_mode != work->old_fb_obj->tiling_mode)
  8385. /* vlv: DISPLAY_FLIP fails to change tiling */
  8386. ring = NULL;
  8387. } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
  8388. ring = &dev_priv->ring[BCS];
  8389. } else if (INTEL_INFO(dev)->gen >= 7) {
  8390. ring = obj->ring;
  8391. if (ring == NULL || ring->id != RCS)
  8392. ring = &dev_priv->ring[BCS];
  8393. } else {
  8394. ring = &dev_priv->ring[RCS];
  8395. }
  8396. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8397. if (ret)
  8398. goto cleanup_pending;
  8399. work->gtt_offset =
  8400. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8401. if (use_mmio_flip(ring, obj)) {
  8402. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8403. page_flip_flags);
  8404. if (ret)
  8405. goto cleanup_unpin;
  8406. work->flip_queued_seqno = obj->last_write_seqno;
  8407. work->flip_queued_ring = obj->ring;
  8408. } else {
  8409. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8410. page_flip_flags);
  8411. if (ret)
  8412. goto cleanup_unpin;
  8413. work->flip_queued_seqno = intel_ring_get_seqno(ring);
  8414. work->flip_queued_ring = ring;
  8415. }
  8416. work->flip_queued_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8417. work->enable_stall_check = true;
  8418. i915_gem_track_fb(work->old_fb_obj, obj,
  8419. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8420. intel_disable_fbc(dev);
  8421. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8422. mutex_unlock(&dev->struct_mutex);
  8423. trace_i915_flip_request(intel_crtc->plane, obj);
  8424. return 0;
  8425. cleanup_unpin:
  8426. intel_unpin_fb_obj(obj);
  8427. cleanup_pending:
  8428. atomic_dec(&intel_crtc->unpin_work_count);
  8429. crtc->primary->fb = old_fb;
  8430. drm_gem_object_unreference(&work->old_fb_obj->base);
  8431. drm_gem_object_unreference(&obj->base);
  8432. mutex_unlock(&dev->struct_mutex);
  8433. cleanup:
  8434. spin_lock_irqsave(&dev->event_lock, flags);
  8435. intel_crtc->unpin_work = NULL;
  8436. spin_unlock_irqrestore(&dev->event_lock, flags);
  8437. drm_crtc_vblank_put(crtc);
  8438. free_work:
  8439. kfree(work);
  8440. if (ret == -EIO) {
  8441. out_hang:
  8442. intel_crtc_wait_for_pending_flips(crtc);
  8443. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8444. if (ret == 0 && event) {
  8445. spin_lock_irqsave(&dev->event_lock, flags);
  8446. drm_send_vblank_event(dev, pipe, event);
  8447. spin_unlock_irqrestore(&dev->event_lock, flags);
  8448. }
  8449. }
  8450. return ret;
  8451. }
  8452. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8453. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8454. .load_lut = intel_crtc_load_lut,
  8455. };
  8456. /**
  8457. * intel_modeset_update_staged_output_state
  8458. *
  8459. * Updates the staged output configuration state, e.g. after we've read out the
  8460. * current hw state.
  8461. */
  8462. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8463. {
  8464. struct intel_crtc *crtc;
  8465. struct intel_encoder *encoder;
  8466. struct intel_connector *connector;
  8467. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8468. base.head) {
  8469. connector->new_encoder =
  8470. to_intel_encoder(connector->base.encoder);
  8471. }
  8472. for_each_intel_encoder(dev, encoder) {
  8473. encoder->new_crtc =
  8474. to_intel_crtc(encoder->base.crtc);
  8475. }
  8476. for_each_intel_crtc(dev, crtc) {
  8477. crtc->new_enabled = crtc->base.enabled;
  8478. if (crtc->new_enabled)
  8479. crtc->new_config = &crtc->config;
  8480. else
  8481. crtc->new_config = NULL;
  8482. }
  8483. }
  8484. /**
  8485. * intel_modeset_commit_output_state
  8486. *
  8487. * This function copies the stage display pipe configuration to the real one.
  8488. */
  8489. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8490. {
  8491. struct intel_crtc *crtc;
  8492. struct intel_encoder *encoder;
  8493. struct intel_connector *connector;
  8494. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8495. base.head) {
  8496. connector->base.encoder = &connector->new_encoder->base;
  8497. }
  8498. for_each_intel_encoder(dev, encoder) {
  8499. encoder->base.crtc = &encoder->new_crtc->base;
  8500. }
  8501. for_each_intel_crtc(dev, crtc) {
  8502. crtc->base.enabled = crtc->new_enabled;
  8503. }
  8504. }
  8505. static void
  8506. connected_sink_compute_bpp(struct intel_connector *connector,
  8507. struct intel_crtc_config *pipe_config)
  8508. {
  8509. int bpp = pipe_config->pipe_bpp;
  8510. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8511. connector->base.base.id,
  8512. connector->base.name);
  8513. /* Don't use an invalid EDID bpc value */
  8514. if (connector->base.display_info.bpc &&
  8515. connector->base.display_info.bpc * 3 < bpp) {
  8516. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8517. bpp, connector->base.display_info.bpc*3);
  8518. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8519. }
  8520. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8521. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8522. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8523. bpp);
  8524. pipe_config->pipe_bpp = 24;
  8525. }
  8526. }
  8527. static int
  8528. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8529. struct drm_framebuffer *fb,
  8530. struct intel_crtc_config *pipe_config)
  8531. {
  8532. struct drm_device *dev = crtc->base.dev;
  8533. struct intel_connector *connector;
  8534. int bpp;
  8535. switch (fb->pixel_format) {
  8536. case DRM_FORMAT_C8:
  8537. bpp = 8*3; /* since we go through a colormap */
  8538. break;
  8539. case DRM_FORMAT_XRGB1555:
  8540. case DRM_FORMAT_ARGB1555:
  8541. /* checked in intel_framebuffer_init already */
  8542. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8543. return -EINVAL;
  8544. case DRM_FORMAT_RGB565:
  8545. bpp = 6*3; /* min is 18bpp */
  8546. break;
  8547. case DRM_FORMAT_XBGR8888:
  8548. case DRM_FORMAT_ABGR8888:
  8549. /* checked in intel_framebuffer_init already */
  8550. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8551. return -EINVAL;
  8552. case DRM_FORMAT_XRGB8888:
  8553. case DRM_FORMAT_ARGB8888:
  8554. bpp = 8*3;
  8555. break;
  8556. case DRM_FORMAT_XRGB2101010:
  8557. case DRM_FORMAT_ARGB2101010:
  8558. case DRM_FORMAT_XBGR2101010:
  8559. case DRM_FORMAT_ABGR2101010:
  8560. /* checked in intel_framebuffer_init already */
  8561. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8562. return -EINVAL;
  8563. bpp = 10*3;
  8564. break;
  8565. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8566. default:
  8567. DRM_DEBUG_KMS("unsupported depth\n");
  8568. return -EINVAL;
  8569. }
  8570. pipe_config->pipe_bpp = bpp;
  8571. /* Clamp display bpp to EDID value */
  8572. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8573. base.head) {
  8574. if (!connector->new_encoder ||
  8575. connector->new_encoder->new_crtc != crtc)
  8576. continue;
  8577. connected_sink_compute_bpp(connector, pipe_config);
  8578. }
  8579. return bpp;
  8580. }
  8581. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8582. {
  8583. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8584. "type: 0x%x flags: 0x%x\n",
  8585. mode->crtc_clock,
  8586. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8587. mode->crtc_hsync_end, mode->crtc_htotal,
  8588. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8589. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8590. }
  8591. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8592. struct intel_crtc_config *pipe_config,
  8593. const char *context)
  8594. {
  8595. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8596. context, pipe_name(crtc->pipe));
  8597. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8598. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8599. pipe_config->pipe_bpp, pipe_config->dither);
  8600. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8601. pipe_config->has_pch_encoder,
  8602. pipe_config->fdi_lanes,
  8603. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8604. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8605. pipe_config->fdi_m_n.tu);
  8606. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8607. pipe_config->has_dp_encoder,
  8608. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8609. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8610. pipe_config->dp_m_n.tu);
  8611. DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
  8612. pipe_config->has_dp_encoder,
  8613. pipe_config->dp_m2_n2.gmch_m,
  8614. pipe_config->dp_m2_n2.gmch_n,
  8615. pipe_config->dp_m2_n2.link_m,
  8616. pipe_config->dp_m2_n2.link_n,
  8617. pipe_config->dp_m2_n2.tu);
  8618. DRM_DEBUG_KMS("requested mode:\n");
  8619. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8620. DRM_DEBUG_KMS("adjusted mode:\n");
  8621. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8622. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8623. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8624. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8625. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8626. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8627. pipe_config->gmch_pfit.control,
  8628. pipe_config->gmch_pfit.pgm_ratios,
  8629. pipe_config->gmch_pfit.lvds_border_bits);
  8630. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8631. pipe_config->pch_pfit.pos,
  8632. pipe_config->pch_pfit.size,
  8633. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8634. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8635. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8636. }
  8637. static bool encoders_cloneable(const struct intel_encoder *a,
  8638. const struct intel_encoder *b)
  8639. {
  8640. /* masks could be asymmetric, so check both ways */
  8641. return a == b || (a->cloneable & (1 << b->type) &&
  8642. b->cloneable & (1 << a->type));
  8643. }
  8644. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8645. struct intel_encoder *encoder)
  8646. {
  8647. struct drm_device *dev = crtc->base.dev;
  8648. struct intel_encoder *source_encoder;
  8649. for_each_intel_encoder(dev, source_encoder) {
  8650. if (source_encoder->new_crtc != crtc)
  8651. continue;
  8652. if (!encoders_cloneable(encoder, source_encoder))
  8653. return false;
  8654. }
  8655. return true;
  8656. }
  8657. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8658. {
  8659. struct drm_device *dev = crtc->base.dev;
  8660. struct intel_encoder *encoder;
  8661. for_each_intel_encoder(dev, encoder) {
  8662. if (encoder->new_crtc != crtc)
  8663. continue;
  8664. if (!check_single_encoder_cloning(crtc, encoder))
  8665. return false;
  8666. }
  8667. return true;
  8668. }
  8669. static struct intel_crtc_config *
  8670. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8671. struct drm_framebuffer *fb,
  8672. struct drm_display_mode *mode)
  8673. {
  8674. struct drm_device *dev = crtc->dev;
  8675. struct intel_encoder *encoder;
  8676. struct intel_crtc_config *pipe_config;
  8677. int plane_bpp, ret = -EINVAL;
  8678. bool retry = true;
  8679. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8680. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8681. return ERR_PTR(-EINVAL);
  8682. }
  8683. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8684. if (!pipe_config)
  8685. return ERR_PTR(-ENOMEM);
  8686. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8687. drm_mode_copy(&pipe_config->requested_mode, mode);
  8688. pipe_config->cpu_transcoder =
  8689. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8690. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8691. /*
  8692. * Sanitize sync polarity flags based on requested ones. If neither
  8693. * positive or negative polarity is requested, treat this as meaning
  8694. * negative polarity.
  8695. */
  8696. if (!(pipe_config->adjusted_mode.flags &
  8697. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8698. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8699. if (!(pipe_config->adjusted_mode.flags &
  8700. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8701. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8702. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8703. * plane pixel format and any sink constraints into account. Returns the
  8704. * source plane bpp so that dithering can be selected on mismatches
  8705. * after encoders and crtc also have had their say. */
  8706. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8707. fb, pipe_config);
  8708. if (plane_bpp < 0)
  8709. goto fail;
  8710. /*
  8711. * Determine the real pipe dimensions. Note that stereo modes can
  8712. * increase the actual pipe size due to the frame doubling and
  8713. * insertion of additional space for blanks between the frame. This
  8714. * is stored in the crtc timings. We use the requested mode to do this
  8715. * computation to clearly distinguish it from the adjusted mode, which
  8716. * can be changed by the connectors in the below retry loop.
  8717. */
  8718. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8719. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8720. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8721. encoder_retry:
  8722. /* Ensure the port clock defaults are reset when retrying. */
  8723. pipe_config->port_clock = 0;
  8724. pipe_config->pixel_multiplier = 1;
  8725. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8726. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8727. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8728. * adjust it according to limitations or connector properties, and also
  8729. * a chance to reject the mode entirely.
  8730. */
  8731. for_each_intel_encoder(dev, encoder) {
  8732. if (&encoder->new_crtc->base != crtc)
  8733. continue;
  8734. if (!(encoder->compute_config(encoder, pipe_config))) {
  8735. DRM_DEBUG_KMS("Encoder config failure\n");
  8736. goto fail;
  8737. }
  8738. }
  8739. /* Set default port clock if not overwritten by the encoder. Needs to be
  8740. * done afterwards in case the encoder adjusts the mode. */
  8741. if (!pipe_config->port_clock)
  8742. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8743. * pipe_config->pixel_multiplier;
  8744. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8745. if (ret < 0) {
  8746. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8747. goto fail;
  8748. }
  8749. if (ret == RETRY) {
  8750. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8751. ret = -EINVAL;
  8752. goto fail;
  8753. }
  8754. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8755. retry = false;
  8756. goto encoder_retry;
  8757. }
  8758. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8759. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8760. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8761. return pipe_config;
  8762. fail:
  8763. kfree(pipe_config);
  8764. return ERR_PTR(ret);
  8765. }
  8766. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8767. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8768. static void
  8769. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8770. unsigned *prepare_pipes, unsigned *disable_pipes)
  8771. {
  8772. struct intel_crtc *intel_crtc;
  8773. struct drm_device *dev = crtc->dev;
  8774. struct intel_encoder *encoder;
  8775. struct intel_connector *connector;
  8776. struct drm_crtc *tmp_crtc;
  8777. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8778. /* Check which crtcs have changed outputs connected to them, these need
  8779. * to be part of the prepare_pipes mask. We don't (yet) support global
  8780. * modeset across multiple crtcs, so modeset_pipes will only have one
  8781. * bit set at most. */
  8782. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8783. base.head) {
  8784. if (connector->base.encoder == &connector->new_encoder->base)
  8785. continue;
  8786. if (connector->base.encoder) {
  8787. tmp_crtc = connector->base.encoder->crtc;
  8788. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8789. }
  8790. if (connector->new_encoder)
  8791. *prepare_pipes |=
  8792. 1 << connector->new_encoder->new_crtc->pipe;
  8793. }
  8794. for_each_intel_encoder(dev, encoder) {
  8795. if (encoder->base.crtc == &encoder->new_crtc->base)
  8796. continue;
  8797. if (encoder->base.crtc) {
  8798. tmp_crtc = encoder->base.crtc;
  8799. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8800. }
  8801. if (encoder->new_crtc)
  8802. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8803. }
  8804. /* Check for pipes that will be enabled/disabled ... */
  8805. for_each_intel_crtc(dev, intel_crtc) {
  8806. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8807. continue;
  8808. if (!intel_crtc->new_enabled)
  8809. *disable_pipes |= 1 << intel_crtc->pipe;
  8810. else
  8811. *prepare_pipes |= 1 << intel_crtc->pipe;
  8812. }
  8813. /* set_mode is also used to update properties on life display pipes. */
  8814. intel_crtc = to_intel_crtc(crtc);
  8815. if (intel_crtc->new_enabled)
  8816. *prepare_pipes |= 1 << intel_crtc->pipe;
  8817. /*
  8818. * For simplicity do a full modeset on any pipe where the output routing
  8819. * changed. We could be more clever, but that would require us to be
  8820. * more careful with calling the relevant encoder->mode_set functions.
  8821. */
  8822. if (*prepare_pipes)
  8823. *modeset_pipes = *prepare_pipes;
  8824. /* ... and mask these out. */
  8825. *modeset_pipes &= ~(*disable_pipes);
  8826. *prepare_pipes &= ~(*disable_pipes);
  8827. /*
  8828. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8829. * obies this rule, but the modeset restore mode of
  8830. * intel_modeset_setup_hw_state does not.
  8831. */
  8832. *modeset_pipes &= 1 << intel_crtc->pipe;
  8833. *prepare_pipes &= 1 << intel_crtc->pipe;
  8834. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8835. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8836. }
  8837. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8838. {
  8839. struct drm_encoder *encoder;
  8840. struct drm_device *dev = crtc->dev;
  8841. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8842. if (encoder->crtc == crtc)
  8843. return true;
  8844. return false;
  8845. }
  8846. static void
  8847. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8848. {
  8849. struct intel_encoder *intel_encoder;
  8850. struct intel_crtc *intel_crtc;
  8851. struct drm_connector *connector;
  8852. for_each_intel_encoder(dev, intel_encoder) {
  8853. if (!intel_encoder->base.crtc)
  8854. continue;
  8855. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8856. if (prepare_pipes & (1 << intel_crtc->pipe))
  8857. intel_encoder->connectors_active = false;
  8858. }
  8859. intel_modeset_commit_output_state(dev);
  8860. /* Double check state. */
  8861. for_each_intel_crtc(dev, intel_crtc) {
  8862. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8863. WARN_ON(intel_crtc->new_config &&
  8864. intel_crtc->new_config != &intel_crtc->config);
  8865. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8866. }
  8867. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8868. if (!connector->encoder || !connector->encoder->crtc)
  8869. continue;
  8870. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8871. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8872. struct drm_property *dpms_property =
  8873. dev->mode_config.dpms_property;
  8874. connector->dpms = DRM_MODE_DPMS_ON;
  8875. drm_object_property_set_value(&connector->base,
  8876. dpms_property,
  8877. DRM_MODE_DPMS_ON);
  8878. intel_encoder = to_intel_encoder(connector->encoder);
  8879. intel_encoder->connectors_active = true;
  8880. }
  8881. }
  8882. }
  8883. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8884. {
  8885. int diff;
  8886. if (clock1 == clock2)
  8887. return true;
  8888. if (!clock1 || !clock2)
  8889. return false;
  8890. diff = abs(clock1 - clock2);
  8891. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8892. return true;
  8893. return false;
  8894. }
  8895. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8896. list_for_each_entry((intel_crtc), \
  8897. &(dev)->mode_config.crtc_list, \
  8898. base.head) \
  8899. if (mask & (1 <<(intel_crtc)->pipe))
  8900. static bool
  8901. intel_pipe_config_compare(struct drm_device *dev,
  8902. struct intel_crtc_config *current_config,
  8903. struct intel_crtc_config *pipe_config)
  8904. {
  8905. #define PIPE_CONF_CHECK_X(name) \
  8906. if (current_config->name != pipe_config->name) { \
  8907. DRM_ERROR("mismatch in " #name " " \
  8908. "(expected 0x%08x, found 0x%08x)\n", \
  8909. current_config->name, \
  8910. pipe_config->name); \
  8911. return false; \
  8912. }
  8913. #define PIPE_CONF_CHECK_I(name) \
  8914. if (current_config->name != pipe_config->name) { \
  8915. DRM_ERROR("mismatch in " #name " " \
  8916. "(expected %i, found %i)\n", \
  8917. current_config->name, \
  8918. pipe_config->name); \
  8919. return false; \
  8920. }
  8921. /* This is required for BDW+ where there is only one set of registers for
  8922. * switching between high and low RR.
  8923. * This macro can be used whenever a comparison has to be made between one
  8924. * hw state and multiple sw state variables.
  8925. */
  8926. #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
  8927. if ((current_config->name != pipe_config->name) && \
  8928. (current_config->alt_name != pipe_config->name)) { \
  8929. DRM_ERROR("mismatch in " #name " " \
  8930. "(expected %i or %i, found %i)\n", \
  8931. current_config->name, \
  8932. current_config->alt_name, \
  8933. pipe_config->name); \
  8934. return false; \
  8935. }
  8936. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8937. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8938. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8939. "(expected %i, found %i)\n", \
  8940. current_config->name & (mask), \
  8941. pipe_config->name & (mask)); \
  8942. return false; \
  8943. }
  8944. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8945. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8946. DRM_ERROR("mismatch in " #name " " \
  8947. "(expected %i, found %i)\n", \
  8948. current_config->name, \
  8949. pipe_config->name); \
  8950. return false; \
  8951. }
  8952. #define PIPE_CONF_QUIRK(quirk) \
  8953. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8954. PIPE_CONF_CHECK_I(cpu_transcoder);
  8955. PIPE_CONF_CHECK_I(has_pch_encoder);
  8956. PIPE_CONF_CHECK_I(fdi_lanes);
  8957. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8958. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8959. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8960. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8961. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8962. PIPE_CONF_CHECK_I(has_dp_encoder);
  8963. if (INTEL_INFO(dev)->gen < 8) {
  8964. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8965. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8966. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8967. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8968. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8969. if (current_config->has_drrs) {
  8970. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m);
  8971. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n);
  8972. PIPE_CONF_CHECK_I(dp_m2_n2.link_m);
  8973. PIPE_CONF_CHECK_I(dp_m2_n2.link_n);
  8974. PIPE_CONF_CHECK_I(dp_m2_n2.tu);
  8975. }
  8976. } else {
  8977. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m);
  8978. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n);
  8979. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m);
  8980. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n);
  8981. PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu);
  8982. }
  8983. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8984. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8985. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8986. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8987. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8988. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8989. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8990. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8991. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8992. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8993. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8994. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8995. PIPE_CONF_CHECK_I(pixel_multiplier);
  8996. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8997. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8998. IS_VALLEYVIEW(dev))
  8999. PIPE_CONF_CHECK_I(limited_color_range);
  9000. PIPE_CONF_CHECK_I(has_audio);
  9001. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9002. DRM_MODE_FLAG_INTERLACE);
  9003. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  9004. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9005. DRM_MODE_FLAG_PHSYNC);
  9006. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9007. DRM_MODE_FLAG_NHSYNC);
  9008. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9009. DRM_MODE_FLAG_PVSYNC);
  9010. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9011. DRM_MODE_FLAG_NVSYNC);
  9012. }
  9013. PIPE_CONF_CHECK_I(pipe_src_w);
  9014. PIPE_CONF_CHECK_I(pipe_src_h);
  9015. /*
  9016. * FIXME: BIOS likes to set up a cloned config with lvds+external
  9017. * screen. Since we don't yet re-compute the pipe config when moving
  9018. * just the lvds port away to another pipe the sw tracking won't match.
  9019. *
  9020. * Proper atomic modesets with recomputed global state will fix this.
  9021. * Until then just don't check gmch state for inherited modes.
  9022. */
  9023. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  9024. PIPE_CONF_CHECK_I(gmch_pfit.control);
  9025. /* pfit ratios are autocomputed by the hw on gen4+ */
  9026. if (INTEL_INFO(dev)->gen < 4)
  9027. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  9028. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  9029. }
  9030. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  9031. if (current_config->pch_pfit.enabled) {
  9032. PIPE_CONF_CHECK_I(pch_pfit.pos);
  9033. PIPE_CONF_CHECK_I(pch_pfit.size);
  9034. }
  9035. /* BDW+ don't expose a synchronous way to read the state */
  9036. if (IS_HASWELL(dev))
  9037. PIPE_CONF_CHECK_I(ips_enabled);
  9038. PIPE_CONF_CHECK_I(double_wide);
  9039. PIPE_CONF_CHECK_X(ddi_pll_sel);
  9040. PIPE_CONF_CHECK_I(shared_dpll);
  9041. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  9042. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  9043. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  9044. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  9045. PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
  9046. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  9047. PIPE_CONF_CHECK_I(pipe_bpp);
  9048. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  9049. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  9050. #undef PIPE_CONF_CHECK_X
  9051. #undef PIPE_CONF_CHECK_I
  9052. #undef PIPE_CONF_CHECK_I_ALT
  9053. #undef PIPE_CONF_CHECK_FLAGS
  9054. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  9055. #undef PIPE_CONF_QUIRK
  9056. return true;
  9057. }
  9058. static void
  9059. check_connector_state(struct drm_device *dev)
  9060. {
  9061. struct intel_connector *connector;
  9062. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9063. base.head) {
  9064. /* This also checks the encoder/connector hw state with the
  9065. * ->get_hw_state callbacks. */
  9066. intel_connector_check_state(connector);
  9067. WARN(&connector->new_encoder->base != connector->base.encoder,
  9068. "connector's staged encoder doesn't match current encoder\n");
  9069. }
  9070. }
  9071. static void
  9072. check_encoder_state(struct drm_device *dev)
  9073. {
  9074. struct intel_encoder *encoder;
  9075. struct intel_connector *connector;
  9076. for_each_intel_encoder(dev, encoder) {
  9077. bool enabled = false;
  9078. bool active = false;
  9079. enum pipe pipe, tracked_pipe;
  9080. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  9081. encoder->base.base.id,
  9082. encoder->base.name);
  9083. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  9084. "encoder's stage crtc doesn't match current crtc\n");
  9085. WARN(encoder->connectors_active && !encoder->base.crtc,
  9086. "encoder's active_connectors set, but no crtc\n");
  9087. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9088. base.head) {
  9089. if (connector->base.encoder != &encoder->base)
  9090. continue;
  9091. enabled = true;
  9092. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  9093. active = true;
  9094. }
  9095. /*
  9096. * for MST connectors if we unplug the connector is gone
  9097. * away but the encoder is still connected to a crtc
  9098. * until a modeset happens in response to the hotplug.
  9099. */
  9100. if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
  9101. continue;
  9102. WARN(!!encoder->base.crtc != enabled,
  9103. "encoder's enabled state mismatch "
  9104. "(expected %i, found %i)\n",
  9105. !!encoder->base.crtc, enabled);
  9106. WARN(active && !encoder->base.crtc,
  9107. "active encoder with no crtc\n");
  9108. WARN(encoder->connectors_active != active,
  9109. "encoder's computed active state doesn't match tracked active state "
  9110. "(expected %i, found %i)\n", active, encoder->connectors_active);
  9111. active = encoder->get_hw_state(encoder, &pipe);
  9112. WARN(active != encoder->connectors_active,
  9113. "encoder's hw state doesn't match sw tracking "
  9114. "(expected %i, found %i)\n",
  9115. encoder->connectors_active, active);
  9116. if (!encoder->base.crtc)
  9117. continue;
  9118. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  9119. WARN(active && pipe != tracked_pipe,
  9120. "active encoder's pipe doesn't match"
  9121. "(expected %i, found %i)\n",
  9122. tracked_pipe, pipe);
  9123. }
  9124. }
  9125. static void
  9126. check_crtc_state(struct drm_device *dev)
  9127. {
  9128. struct drm_i915_private *dev_priv = dev->dev_private;
  9129. struct intel_crtc *crtc;
  9130. struct intel_encoder *encoder;
  9131. struct intel_crtc_config pipe_config;
  9132. for_each_intel_crtc(dev, crtc) {
  9133. bool enabled = false;
  9134. bool active = false;
  9135. memset(&pipe_config, 0, sizeof(pipe_config));
  9136. DRM_DEBUG_KMS("[CRTC:%d]\n",
  9137. crtc->base.base.id);
  9138. WARN(crtc->active && !crtc->base.enabled,
  9139. "active crtc, but not enabled in sw tracking\n");
  9140. for_each_intel_encoder(dev, encoder) {
  9141. if (encoder->base.crtc != &crtc->base)
  9142. continue;
  9143. enabled = true;
  9144. if (encoder->connectors_active)
  9145. active = true;
  9146. }
  9147. WARN(active != crtc->active,
  9148. "crtc's computed active state doesn't match tracked active state "
  9149. "(expected %i, found %i)\n", active, crtc->active);
  9150. WARN(enabled != crtc->base.enabled,
  9151. "crtc's computed enabled state doesn't match tracked enabled state "
  9152. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  9153. active = dev_priv->display.get_pipe_config(crtc,
  9154. &pipe_config);
  9155. /* hw state is inconsistent with the pipe quirk */
  9156. if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  9157. (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  9158. active = crtc->active;
  9159. for_each_intel_encoder(dev, encoder) {
  9160. enum pipe pipe;
  9161. if (encoder->base.crtc != &crtc->base)
  9162. continue;
  9163. if (encoder->get_hw_state(encoder, &pipe))
  9164. encoder->get_config(encoder, &pipe_config);
  9165. }
  9166. WARN(crtc->active != active,
  9167. "crtc active state doesn't match with hw state "
  9168. "(expected %i, found %i)\n", crtc->active, active);
  9169. if (active &&
  9170. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  9171. WARN(1, "pipe state doesn't match!\n");
  9172. intel_dump_pipe_config(crtc, &pipe_config,
  9173. "[hw state]");
  9174. intel_dump_pipe_config(crtc, &crtc->config,
  9175. "[sw state]");
  9176. }
  9177. }
  9178. }
  9179. static void
  9180. check_shared_dpll_state(struct drm_device *dev)
  9181. {
  9182. struct drm_i915_private *dev_priv = dev->dev_private;
  9183. struct intel_crtc *crtc;
  9184. struct intel_dpll_hw_state dpll_hw_state;
  9185. int i;
  9186. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9187. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  9188. int enabled_crtcs = 0, active_crtcs = 0;
  9189. bool active;
  9190. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  9191. DRM_DEBUG_KMS("%s\n", pll->name);
  9192. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  9193. WARN(pll->active > pll->refcount,
  9194. "more active pll users than references: %i vs %i\n",
  9195. pll->active, pll->refcount);
  9196. WARN(pll->active && !pll->on,
  9197. "pll in active use but not on in sw tracking\n");
  9198. WARN(pll->on && !pll->active,
  9199. "pll in on but not on in use in sw tracking\n");
  9200. WARN(pll->on != active,
  9201. "pll on state mismatch (expected %i, found %i)\n",
  9202. pll->on, active);
  9203. for_each_intel_crtc(dev, crtc) {
  9204. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  9205. enabled_crtcs++;
  9206. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  9207. active_crtcs++;
  9208. }
  9209. WARN(pll->active != active_crtcs,
  9210. "pll active crtcs mismatch (expected %i, found %i)\n",
  9211. pll->active, active_crtcs);
  9212. WARN(pll->refcount != enabled_crtcs,
  9213. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  9214. pll->refcount, enabled_crtcs);
  9215. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  9216. sizeof(dpll_hw_state)),
  9217. "pll hw state mismatch\n");
  9218. }
  9219. }
  9220. void
  9221. intel_modeset_check_state(struct drm_device *dev)
  9222. {
  9223. check_connector_state(dev);
  9224. check_encoder_state(dev);
  9225. check_crtc_state(dev);
  9226. check_shared_dpll_state(dev);
  9227. }
  9228. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  9229. int dotclock)
  9230. {
  9231. /*
  9232. * FDI already provided one idea for the dotclock.
  9233. * Yell if the encoder disagrees.
  9234. */
  9235. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  9236. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  9237. pipe_config->adjusted_mode.crtc_clock, dotclock);
  9238. }
  9239. static void update_scanline_offset(struct intel_crtc *crtc)
  9240. {
  9241. struct drm_device *dev = crtc->base.dev;
  9242. /*
  9243. * The scanline counter increments at the leading edge of hsync.
  9244. *
  9245. * On most platforms it starts counting from vtotal-1 on the
  9246. * first active line. That means the scanline counter value is
  9247. * always one less than what we would expect. Ie. just after
  9248. * start of vblank, which also occurs at start of hsync (on the
  9249. * last active line), the scanline counter will read vblank_start-1.
  9250. *
  9251. * On gen2 the scanline counter starts counting from 1 instead
  9252. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  9253. * to keep the value positive), instead of adding one.
  9254. *
  9255. * On HSW+ the behaviour of the scanline counter depends on the output
  9256. * type. For DP ports it behaves like most other platforms, but on HDMI
  9257. * there's an extra 1 line difference. So we need to add two instead of
  9258. * one to the value.
  9259. */
  9260. if (IS_GEN2(dev)) {
  9261. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  9262. int vtotal;
  9263. vtotal = mode->crtc_vtotal;
  9264. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  9265. vtotal /= 2;
  9266. crtc->scanline_offset = vtotal - 1;
  9267. } else if (HAS_DDI(dev) &&
  9268. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
  9269. crtc->scanline_offset = 2;
  9270. } else
  9271. crtc->scanline_offset = 1;
  9272. }
  9273. static int __intel_set_mode(struct drm_crtc *crtc,
  9274. struct drm_display_mode *mode,
  9275. int x, int y, struct drm_framebuffer *fb)
  9276. {
  9277. struct drm_device *dev = crtc->dev;
  9278. struct drm_i915_private *dev_priv = dev->dev_private;
  9279. struct drm_display_mode *saved_mode;
  9280. struct intel_crtc_config *pipe_config = NULL;
  9281. struct intel_crtc *intel_crtc;
  9282. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  9283. int ret = 0;
  9284. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  9285. if (!saved_mode)
  9286. return -ENOMEM;
  9287. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  9288. &prepare_pipes, &disable_pipes);
  9289. *saved_mode = crtc->mode;
  9290. /* Hack: Because we don't (yet) support global modeset on multiple
  9291. * crtcs, we don't keep track of the new mode for more than one crtc.
  9292. * Hence simply check whether any bit is set in modeset_pipes in all the
  9293. * pieces of code that are not yet converted to deal with mutliple crtcs
  9294. * changing their mode at the same time. */
  9295. if (modeset_pipes) {
  9296. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  9297. if (IS_ERR(pipe_config)) {
  9298. ret = PTR_ERR(pipe_config);
  9299. pipe_config = NULL;
  9300. goto out;
  9301. }
  9302. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  9303. "[modeset]");
  9304. to_intel_crtc(crtc)->new_config = pipe_config;
  9305. }
  9306. /*
  9307. * See if the config requires any additional preparation, e.g.
  9308. * to adjust global state with pipes off. We need to do this
  9309. * here so we can get the modeset_pipe updated config for the new
  9310. * mode set on this crtc. For other crtcs we need to use the
  9311. * adjusted_mode bits in the crtc directly.
  9312. */
  9313. if (IS_VALLEYVIEW(dev)) {
  9314. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  9315. /* may have added more to prepare_pipes than we should */
  9316. prepare_pipes &= ~disable_pipes;
  9317. }
  9318. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  9319. intel_crtc_disable(&intel_crtc->base);
  9320. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9321. if (intel_crtc->base.enabled)
  9322. dev_priv->display.crtc_disable(&intel_crtc->base);
  9323. }
  9324. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  9325. * to set it here already despite that we pass it down the callchain.
  9326. */
  9327. if (modeset_pipes) {
  9328. crtc->mode = *mode;
  9329. /* mode_set/enable/disable functions rely on a correct pipe
  9330. * config. */
  9331. to_intel_crtc(crtc)->config = *pipe_config;
  9332. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  9333. /*
  9334. * Calculate and store various constants which
  9335. * are later needed by vblank and swap-completion
  9336. * timestamping. They are derived from true hwmode.
  9337. */
  9338. drm_calc_timestamping_constants(crtc,
  9339. &pipe_config->adjusted_mode);
  9340. }
  9341. /* Only after disabling all output pipelines that will be changed can we
  9342. * update the the output configuration. */
  9343. intel_modeset_update_state(dev, prepare_pipes);
  9344. if (dev_priv->display.modeset_global_resources)
  9345. dev_priv->display.modeset_global_resources(dev);
  9346. /* Set up the DPLL and any encoders state that needs to adjust or depend
  9347. * on the DPLL.
  9348. */
  9349. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  9350. struct drm_framebuffer *old_fb = crtc->primary->fb;
  9351. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  9352. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9353. mutex_lock(&dev->struct_mutex);
  9354. ret = intel_pin_and_fence_fb_obj(dev,
  9355. obj,
  9356. NULL);
  9357. if (ret != 0) {
  9358. DRM_ERROR("pin & fence failed\n");
  9359. mutex_unlock(&dev->struct_mutex);
  9360. goto done;
  9361. }
  9362. if (old_fb)
  9363. intel_unpin_fb_obj(old_obj);
  9364. i915_gem_track_fb(old_obj, obj,
  9365. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9366. mutex_unlock(&dev->struct_mutex);
  9367. crtc->primary->fb = fb;
  9368. crtc->x = x;
  9369. crtc->y = y;
  9370. ret = dev_priv->display.crtc_mode_set(&intel_crtc->base,
  9371. x, y, fb);
  9372. if (ret)
  9373. goto done;
  9374. }
  9375. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9376. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9377. update_scanline_offset(intel_crtc);
  9378. dev_priv->display.crtc_enable(&intel_crtc->base);
  9379. }
  9380. /* FIXME: add subpixel order */
  9381. done:
  9382. if (ret && crtc->enabled)
  9383. crtc->mode = *saved_mode;
  9384. out:
  9385. kfree(pipe_config);
  9386. kfree(saved_mode);
  9387. return ret;
  9388. }
  9389. static int intel_set_mode(struct drm_crtc *crtc,
  9390. struct drm_display_mode *mode,
  9391. int x, int y, struct drm_framebuffer *fb)
  9392. {
  9393. int ret;
  9394. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9395. if (ret == 0)
  9396. intel_modeset_check_state(crtc->dev);
  9397. return ret;
  9398. }
  9399. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9400. {
  9401. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9402. }
  9403. #undef for_each_intel_crtc_masked
  9404. static void intel_set_config_free(struct intel_set_config *config)
  9405. {
  9406. if (!config)
  9407. return;
  9408. kfree(config->save_connector_encoders);
  9409. kfree(config->save_encoder_crtcs);
  9410. kfree(config->save_crtc_enabled);
  9411. kfree(config);
  9412. }
  9413. static int intel_set_config_save_state(struct drm_device *dev,
  9414. struct intel_set_config *config)
  9415. {
  9416. struct drm_crtc *crtc;
  9417. struct drm_encoder *encoder;
  9418. struct drm_connector *connector;
  9419. int count;
  9420. config->save_crtc_enabled =
  9421. kcalloc(dev->mode_config.num_crtc,
  9422. sizeof(bool), GFP_KERNEL);
  9423. if (!config->save_crtc_enabled)
  9424. return -ENOMEM;
  9425. config->save_encoder_crtcs =
  9426. kcalloc(dev->mode_config.num_encoder,
  9427. sizeof(struct drm_crtc *), GFP_KERNEL);
  9428. if (!config->save_encoder_crtcs)
  9429. return -ENOMEM;
  9430. config->save_connector_encoders =
  9431. kcalloc(dev->mode_config.num_connector,
  9432. sizeof(struct drm_encoder *), GFP_KERNEL);
  9433. if (!config->save_connector_encoders)
  9434. return -ENOMEM;
  9435. /* Copy data. Note that driver private data is not affected.
  9436. * Should anything bad happen only the expected state is
  9437. * restored, not the drivers personal bookkeeping.
  9438. */
  9439. count = 0;
  9440. for_each_crtc(dev, crtc) {
  9441. config->save_crtc_enabled[count++] = crtc->enabled;
  9442. }
  9443. count = 0;
  9444. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9445. config->save_encoder_crtcs[count++] = encoder->crtc;
  9446. }
  9447. count = 0;
  9448. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9449. config->save_connector_encoders[count++] = connector->encoder;
  9450. }
  9451. return 0;
  9452. }
  9453. static void intel_set_config_restore_state(struct drm_device *dev,
  9454. struct intel_set_config *config)
  9455. {
  9456. struct intel_crtc *crtc;
  9457. struct intel_encoder *encoder;
  9458. struct intel_connector *connector;
  9459. int count;
  9460. count = 0;
  9461. for_each_intel_crtc(dev, crtc) {
  9462. crtc->new_enabled = config->save_crtc_enabled[count++];
  9463. if (crtc->new_enabled)
  9464. crtc->new_config = &crtc->config;
  9465. else
  9466. crtc->new_config = NULL;
  9467. }
  9468. count = 0;
  9469. for_each_intel_encoder(dev, encoder) {
  9470. encoder->new_crtc =
  9471. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9472. }
  9473. count = 0;
  9474. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9475. connector->new_encoder =
  9476. to_intel_encoder(config->save_connector_encoders[count++]);
  9477. }
  9478. }
  9479. static bool
  9480. is_crtc_connector_off(struct drm_mode_set *set)
  9481. {
  9482. int i;
  9483. if (set->num_connectors == 0)
  9484. return false;
  9485. if (WARN_ON(set->connectors == NULL))
  9486. return false;
  9487. for (i = 0; i < set->num_connectors; i++)
  9488. if (set->connectors[i]->encoder &&
  9489. set->connectors[i]->encoder->crtc == set->crtc &&
  9490. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9491. return true;
  9492. return false;
  9493. }
  9494. static void
  9495. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9496. struct intel_set_config *config)
  9497. {
  9498. /* We should be able to check here if the fb has the same properties
  9499. * and then just flip_or_move it */
  9500. if (is_crtc_connector_off(set)) {
  9501. config->mode_changed = true;
  9502. } else if (set->crtc->primary->fb != set->fb) {
  9503. /*
  9504. * If we have no fb, we can only flip as long as the crtc is
  9505. * active, otherwise we need a full mode set. The crtc may
  9506. * be active if we've only disabled the primary plane, or
  9507. * in fastboot situations.
  9508. */
  9509. if (set->crtc->primary->fb == NULL) {
  9510. struct intel_crtc *intel_crtc =
  9511. to_intel_crtc(set->crtc);
  9512. if (intel_crtc->active) {
  9513. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9514. config->fb_changed = true;
  9515. } else {
  9516. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9517. config->mode_changed = true;
  9518. }
  9519. } else if (set->fb == NULL) {
  9520. config->mode_changed = true;
  9521. } else if (set->fb->pixel_format !=
  9522. set->crtc->primary->fb->pixel_format) {
  9523. config->mode_changed = true;
  9524. } else {
  9525. config->fb_changed = true;
  9526. }
  9527. }
  9528. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9529. config->fb_changed = true;
  9530. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9531. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9532. drm_mode_debug_printmodeline(&set->crtc->mode);
  9533. drm_mode_debug_printmodeline(set->mode);
  9534. config->mode_changed = true;
  9535. }
  9536. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9537. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9538. }
  9539. static int
  9540. intel_modeset_stage_output_state(struct drm_device *dev,
  9541. struct drm_mode_set *set,
  9542. struct intel_set_config *config)
  9543. {
  9544. struct intel_connector *connector;
  9545. struct intel_encoder *encoder;
  9546. struct intel_crtc *crtc;
  9547. int ro;
  9548. /* The upper layers ensure that we either disable a crtc or have a list
  9549. * of connectors. For paranoia, double-check this. */
  9550. WARN_ON(!set->fb && (set->num_connectors != 0));
  9551. WARN_ON(set->fb && (set->num_connectors == 0));
  9552. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9553. base.head) {
  9554. /* Otherwise traverse passed in connector list and get encoders
  9555. * for them. */
  9556. for (ro = 0; ro < set->num_connectors; ro++) {
  9557. if (set->connectors[ro] == &connector->base) {
  9558. connector->new_encoder = intel_find_encoder(connector, to_intel_crtc(set->crtc)->pipe);
  9559. break;
  9560. }
  9561. }
  9562. /* If we disable the crtc, disable all its connectors. Also, if
  9563. * the connector is on the changing crtc but not on the new
  9564. * connector list, disable it. */
  9565. if ((!set->fb || ro == set->num_connectors) &&
  9566. connector->base.encoder &&
  9567. connector->base.encoder->crtc == set->crtc) {
  9568. connector->new_encoder = NULL;
  9569. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9570. connector->base.base.id,
  9571. connector->base.name);
  9572. }
  9573. if (&connector->new_encoder->base != connector->base.encoder) {
  9574. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9575. config->mode_changed = true;
  9576. }
  9577. }
  9578. /* connector->new_encoder is now updated for all connectors. */
  9579. /* Update crtc of enabled connectors. */
  9580. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9581. base.head) {
  9582. struct drm_crtc *new_crtc;
  9583. if (!connector->new_encoder)
  9584. continue;
  9585. new_crtc = connector->new_encoder->base.crtc;
  9586. for (ro = 0; ro < set->num_connectors; ro++) {
  9587. if (set->connectors[ro] == &connector->base)
  9588. new_crtc = set->crtc;
  9589. }
  9590. /* Make sure the new CRTC will work with the encoder */
  9591. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9592. new_crtc)) {
  9593. return -EINVAL;
  9594. }
  9595. connector->new_encoder->new_crtc = to_intel_crtc(new_crtc);
  9596. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9597. connector->base.base.id,
  9598. connector->base.name,
  9599. new_crtc->base.id);
  9600. }
  9601. /* Check for any encoders that needs to be disabled. */
  9602. for_each_intel_encoder(dev, encoder) {
  9603. int num_connectors = 0;
  9604. list_for_each_entry(connector,
  9605. &dev->mode_config.connector_list,
  9606. base.head) {
  9607. if (connector->new_encoder == encoder) {
  9608. WARN_ON(!connector->new_encoder->new_crtc);
  9609. num_connectors++;
  9610. }
  9611. }
  9612. if (num_connectors == 0)
  9613. encoder->new_crtc = NULL;
  9614. else if (num_connectors > 1)
  9615. return -EINVAL;
  9616. /* Only now check for crtc changes so we don't miss encoders
  9617. * that will be disabled. */
  9618. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9619. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9620. config->mode_changed = true;
  9621. }
  9622. }
  9623. /* Now we've also updated encoder->new_crtc for all encoders. */
  9624. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9625. base.head) {
  9626. if (connector->new_encoder)
  9627. if (connector->new_encoder != connector->encoder)
  9628. connector->encoder = connector->new_encoder;
  9629. }
  9630. for_each_intel_crtc(dev, crtc) {
  9631. crtc->new_enabled = false;
  9632. for_each_intel_encoder(dev, encoder) {
  9633. if (encoder->new_crtc == crtc) {
  9634. crtc->new_enabled = true;
  9635. break;
  9636. }
  9637. }
  9638. if (crtc->new_enabled != crtc->base.enabled) {
  9639. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9640. crtc->new_enabled ? "en" : "dis");
  9641. config->mode_changed = true;
  9642. }
  9643. if (crtc->new_enabled)
  9644. crtc->new_config = &crtc->config;
  9645. else
  9646. crtc->new_config = NULL;
  9647. }
  9648. return 0;
  9649. }
  9650. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9651. {
  9652. struct drm_device *dev = crtc->base.dev;
  9653. struct intel_encoder *encoder;
  9654. struct intel_connector *connector;
  9655. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9656. pipe_name(crtc->pipe));
  9657. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9658. if (connector->new_encoder &&
  9659. connector->new_encoder->new_crtc == crtc)
  9660. connector->new_encoder = NULL;
  9661. }
  9662. for_each_intel_encoder(dev, encoder) {
  9663. if (encoder->new_crtc == crtc)
  9664. encoder->new_crtc = NULL;
  9665. }
  9666. crtc->new_enabled = false;
  9667. crtc->new_config = NULL;
  9668. }
  9669. static int intel_crtc_set_config(struct drm_mode_set *set)
  9670. {
  9671. struct drm_device *dev;
  9672. struct drm_mode_set save_set;
  9673. struct intel_set_config *config;
  9674. int ret;
  9675. BUG_ON(!set);
  9676. BUG_ON(!set->crtc);
  9677. BUG_ON(!set->crtc->helper_private);
  9678. /* Enforce sane interface api - has been abused by the fb helper. */
  9679. BUG_ON(!set->mode && set->fb);
  9680. BUG_ON(set->fb && set->num_connectors == 0);
  9681. if (set->fb) {
  9682. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9683. set->crtc->base.id, set->fb->base.id,
  9684. (int)set->num_connectors, set->x, set->y);
  9685. } else {
  9686. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9687. }
  9688. dev = set->crtc->dev;
  9689. ret = -ENOMEM;
  9690. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9691. if (!config)
  9692. goto out_config;
  9693. ret = intel_set_config_save_state(dev, config);
  9694. if (ret)
  9695. goto out_config;
  9696. save_set.crtc = set->crtc;
  9697. save_set.mode = &set->crtc->mode;
  9698. save_set.x = set->crtc->x;
  9699. save_set.y = set->crtc->y;
  9700. save_set.fb = set->crtc->primary->fb;
  9701. /* Compute whether we need a full modeset, only an fb base update or no
  9702. * change at all. In the future we might also check whether only the
  9703. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9704. * such cases. */
  9705. intel_set_config_compute_mode_changes(set, config);
  9706. ret = intel_modeset_stage_output_state(dev, set, config);
  9707. if (ret)
  9708. goto fail;
  9709. if (config->mode_changed) {
  9710. ret = intel_set_mode(set->crtc, set->mode,
  9711. set->x, set->y, set->fb);
  9712. } else if (config->fb_changed) {
  9713. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9714. intel_crtc_wait_for_pending_flips(set->crtc);
  9715. ret = intel_pipe_set_base(set->crtc,
  9716. set->x, set->y, set->fb);
  9717. /*
  9718. * We need to make sure the primary plane is re-enabled if it
  9719. * has previously been turned off.
  9720. */
  9721. if (!intel_crtc->primary_enabled && ret == 0) {
  9722. WARN_ON(!intel_crtc->active);
  9723. intel_enable_primary_hw_plane(set->crtc->primary, set->crtc);
  9724. }
  9725. /*
  9726. * In the fastboot case this may be our only check of the
  9727. * state after boot. It would be better to only do it on
  9728. * the first update, but we don't have a nice way of doing that
  9729. * (and really, set_config isn't used much for high freq page
  9730. * flipping, so increasing its cost here shouldn't be a big
  9731. * deal).
  9732. */
  9733. if (i915.fastboot && ret == 0)
  9734. intel_modeset_check_state(set->crtc->dev);
  9735. }
  9736. if (ret) {
  9737. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9738. set->crtc->base.id, ret);
  9739. fail:
  9740. intel_set_config_restore_state(dev, config);
  9741. /*
  9742. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9743. * force the pipe off to avoid oopsing in the modeset code
  9744. * due to fb==NULL. This should only happen during boot since
  9745. * we don't yet reconstruct the FB from the hardware state.
  9746. */
  9747. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9748. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9749. /* Try to restore the config */
  9750. if (config->mode_changed &&
  9751. intel_set_mode(save_set.crtc, save_set.mode,
  9752. save_set.x, save_set.y, save_set.fb))
  9753. DRM_ERROR("failed to restore config after modeset failure\n");
  9754. }
  9755. out_config:
  9756. intel_set_config_free(config);
  9757. return ret;
  9758. }
  9759. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9760. .gamma_set = intel_crtc_gamma_set,
  9761. .set_config = intel_crtc_set_config,
  9762. .destroy = intel_crtc_destroy,
  9763. .page_flip = intel_crtc_page_flip,
  9764. };
  9765. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9766. struct intel_shared_dpll *pll,
  9767. struct intel_dpll_hw_state *hw_state)
  9768. {
  9769. uint32_t val;
  9770. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
  9771. return false;
  9772. val = I915_READ(PCH_DPLL(pll->id));
  9773. hw_state->dpll = val;
  9774. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9775. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9776. return val & DPLL_VCO_ENABLE;
  9777. }
  9778. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9779. struct intel_shared_dpll *pll)
  9780. {
  9781. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9782. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9783. }
  9784. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9785. struct intel_shared_dpll *pll)
  9786. {
  9787. /* PCH refclock must be enabled first */
  9788. ibx_assert_pch_refclk_enabled(dev_priv);
  9789. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9790. /* Wait for the clocks to stabilize. */
  9791. POSTING_READ(PCH_DPLL(pll->id));
  9792. udelay(150);
  9793. /* The pixel multiplier can only be updated once the
  9794. * DPLL is enabled and the clocks are stable.
  9795. *
  9796. * So write it again.
  9797. */
  9798. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9799. POSTING_READ(PCH_DPLL(pll->id));
  9800. udelay(200);
  9801. }
  9802. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9803. struct intel_shared_dpll *pll)
  9804. {
  9805. struct drm_device *dev = dev_priv->dev;
  9806. struct intel_crtc *crtc;
  9807. /* Make sure no transcoder isn't still depending on us. */
  9808. for_each_intel_crtc(dev, crtc) {
  9809. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9810. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9811. }
  9812. I915_WRITE(PCH_DPLL(pll->id), 0);
  9813. POSTING_READ(PCH_DPLL(pll->id));
  9814. udelay(200);
  9815. }
  9816. static char *ibx_pch_dpll_names[] = {
  9817. "PCH DPLL A",
  9818. "PCH DPLL B",
  9819. };
  9820. static void ibx_pch_dpll_init(struct drm_device *dev)
  9821. {
  9822. struct drm_i915_private *dev_priv = dev->dev_private;
  9823. int i;
  9824. dev_priv->num_shared_dpll = 2;
  9825. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9826. dev_priv->shared_dplls[i].id = i;
  9827. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9828. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9829. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9830. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9831. dev_priv->shared_dplls[i].get_hw_state =
  9832. ibx_pch_dpll_get_hw_state;
  9833. }
  9834. }
  9835. static void intel_shared_dpll_init(struct drm_device *dev)
  9836. {
  9837. struct drm_i915_private *dev_priv = dev->dev_private;
  9838. if (HAS_DDI(dev))
  9839. intel_ddi_pll_init(dev);
  9840. else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9841. ibx_pch_dpll_init(dev);
  9842. else
  9843. dev_priv->num_shared_dpll = 0;
  9844. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9845. }
  9846. static int
  9847. intel_primary_plane_disable(struct drm_plane *plane)
  9848. {
  9849. struct drm_device *dev = plane->dev;
  9850. struct intel_crtc *intel_crtc;
  9851. if (!plane->fb)
  9852. return 0;
  9853. BUG_ON(!plane->crtc);
  9854. intel_crtc = to_intel_crtc(plane->crtc);
  9855. /*
  9856. * Even though we checked plane->fb above, it's still possible that
  9857. * the primary plane has been implicitly disabled because the crtc
  9858. * coordinates given weren't visible, or because we detected
  9859. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9860. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9861. * In either case, we need to unpin the FB and let the fb pointer get
  9862. * updated, but otherwise we don't need to touch the hardware.
  9863. */
  9864. if (!intel_crtc->primary_enabled)
  9865. goto disable_unpin;
  9866. intel_crtc_wait_for_pending_flips(plane->crtc);
  9867. intel_disable_primary_hw_plane(plane, plane->crtc);
  9868. disable_unpin:
  9869. mutex_lock(&dev->struct_mutex);
  9870. i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
  9871. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9872. intel_unpin_fb_obj(intel_fb_obj(plane->fb));
  9873. mutex_unlock(&dev->struct_mutex);
  9874. plane->fb = NULL;
  9875. return 0;
  9876. }
  9877. static int
  9878. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9879. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9880. unsigned int crtc_w, unsigned int crtc_h,
  9881. uint32_t src_x, uint32_t src_y,
  9882. uint32_t src_w, uint32_t src_h)
  9883. {
  9884. struct drm_device *dev = crtc->dev;
  9885. struct drm_i915_private *dev_priv = dev->dev_private;
  9886. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9887. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9888. struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
  9889. struct drm_rect dest = {
  9890. /* integer pixels */
  9891. .x1 = crtc_x,
  9892. .y1 = crtc_y,
  9893. .x2 = crtc_x + crtc_w,
  9894. .y2 = crtc_y + crtc_h,
  9895. };
  9896. struct drm_rect src = {
  9897. /* 16.16 fixed point */
  9898. .x1 = src_x,
  9899. .y1 = src_y,
  9900. .x2 = src_x + src_w,
  9901. .y2 = src_y + src_h,
  9902. };
  9903. const struct drm_rect clip = {
  9904. /* integer pixels */
  9905. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  9906. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  9907. };
  9908. const struct {
  9909. int crtc_x, crtc_y;
  9910. unsigned int crtc_w, crtc_h;
  9911. uint32_t src_x, src_y, src_w, src_h;
  9912. } orig = {
  9913. .crtc_x = crtc_x,
  9914. .crtc_y = crtc_y,
  9915. .crtc_w = crtc_w,
  9916. .crtc_h = crtc_h,
  9917. .src_x = src_x,
  9918. .src_y = src_y,
  9919. .src_w = src_w,
  9920. .src_h = src_h,
  9921. };
  9922. struct intel_plane *intel_plane = to_intel_plane(plane);
  9923. bool visible;
  9924. int ret;
  9925. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9926. &src, &dest, &clip,
  9927. DRM_PLANE_HELPER_NO_SCALING,
  9928. DRM_PLANE_HELPER_NO_SCALING,
  9929. false, true, &visible);
  9930. if (ret)
  9931. return ret;
  9932. /*
  9933. * If the CRTC isn't enabled, we're just pinning the framebuffer,
  9934. * updating the fb pointer, and returning without touching the
  9935. * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
  9936. * turn on the display with all planes setup as desired.
  9937. */
  9938. if (!crtc->enabled) {
  9939. mutex_lock(&dev->struct_mutex);
  9940. /*
  9941. * If we already called setplane while the crtc was disabled,
  9942. * we may have an fb pinned; unpin it.
  9943. */
  9944. if (plane->fb)
  9945. intel_unpin_fb_obj(old_obj);
  9946. i915_gem_track_fb(old_obj, obj,
  9947. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9948. /* Pin and return without programming hardware */
  9949. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9950. mutex_unlock(&dev->struct_mutex);
  9951. return ret;
  9952. }
  9953. intel_crtc_wait_for_pending_flips(crtc);
  9954. /*
  9955. * If clipping results in a non-visible primary plane, we'll disable
  9956. * the primary plane. Note that this is a bit different than what
  9957. * happens if userspace explicitly disables the plane by passing fb=0
  9958. * because plane->fb still gets set and pinned.
  9959. */
  9960. if (!visible) {
  9961. mutex_lock(&dev->struct_mutex);
  9962. /*
  9963. * Try to pin the new fb first so that we can bail out if we
  9964. * fail.
  9965. */
  9966. if (plane->fb != fb) {
  9967. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9968. if (ret) {
  9969. mutex_unlock(&dev->struct_mutex);
  9970. return ret;
  9971. }
  9972. }
  9973. i915_gem_track_fb(old_obj, obj,
  9974. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9975. if (intel_crtc->primary_enabled)
  9976. intel_disable_primary_hw_plane(plane, crtc);
  9977. if (plane->fb != fb)
  9978. if (plane->fb)
  9979. intel_unpin_fb_obj(old_obj);
  9980. mutex_unlock(&dev->struct_mutex);
  9981. } else {
  9982. if (intel_crtc && intel_crtc->active &&
  9983. intel_crtc->primary_enabled) {
  9984. /*
  9985. * FBC does not work on some platforms for rotated
  9986. * planes, so disable it when rotation is not 0 and
  9987. * update it when rotation is set back to 0.
  9988. *
  9989. * FIXME: This is redundant with the fbc update done in
  9990. * the primary plane enable function except that that
  9991. * one is done too late. We eventually need to unify
  9992. * this.
  9993. */
  9994. if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
  9995. dev_priv->fbc.plane == intel_crtc->plane &&
  9996. intel_plane->rotation != BIT(DRM_ROTATE_0)) {
  9997. intel_disable_fbc(dev);
  9998. }
  9999. }
  10000. ret = intel_pipe_set_base(crtc, src.x1, src.y1, fb);
  10001. if (ret)
  10002. return ret;
  10003. if (!intel_crtc->primary_enabled)
  10004. intel_enable_primary_hw_plane(plane, crtc);
  10005. }
  10006. intel_plane->crtc_x = orig.crtc_x;
  10007. intel_plane->crtc_y = orig.crtc_y;
  10008. intel_plane->crtc_w = orig.crtc_w;
  10009. intel_plane->crtc_h = orig.crtc_h;
  10010. intel_plane->src_x = orig.src_x;
  10011. intel_plane->src_y = orig.src_y;
  10012. intel_plane->src_w = orig.src_w;
  10013. intel_plane->src_h = orig.src_h;
  10014. intel_plane->obj = obj;
  10015. return 0;
  10016. }
  10017. /* Common destruction function for both primary and cursor planes */
  10018. static void intel_plane_destroy(struct drm_plane *plane)
  10019. {
  10020. struct intel_plane *intel_plane = to_intel_plane(plane);
  10021. drm_plane_cleanup(plane);
  10022. kfree(intel_plane);
  10023. }
  10024. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  10025. .update_plane = intel_primary_plane_setplane,
  10026. .disable_plane = intel_primary_plane_disable,
  10027. .destroy = intel_plane_destroy,
  10028. .set_property = intel_plane_set_property
  10029. };
  10030. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  10031. int pipe)
  10032. {
  10033. struct intel_plane *primary;
  10034. const uint32_t *intel_primary_formats;
  10035. int num_formats;
  10036. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  10037. if (primary == NULL)
  10038. return NULL;
  10039. primary->can_scale = false;
  10040. primary->max_downscale = 1;
  10041. primary->pipe = pipe;
  10042. primary->plane = pipe;
  10043. primary->rotation = BIT(DRM_ROTATE_0);
  10044. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  10045. primary->plane = !pipe;
  10046. if (INTEL_INFO(dev)->gen <= 3) {
  10047. intel_primary_formats = intel_primary_formats_gen2;
  10048. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  10049. } else {
  10050. intel_primary_formats = intel_primary_formats_gen4;
  10051. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  10052. }
  10053. drm_universal_plane_init(dev, &primary->base, 0,
  10054. &intel_primary_plane_funcs,
  10055. intel_primary_formats, num_formats,
  10056. DRM_PLANE_TYPE_PRIMARY);
  10057. if (INTEL_INFO(dev)->gen >= 4) {
  10058. if (!dev->mode_config.rotation_property)
  10059. dev->mode_config.rotation_property =
  10060. drm_mode_create_rotation_property(dev,
  10061. BIT(DRM_ROTATE_0) |
  10062. BIT(DRM_ROTATE_180));
  10063. if (dev->mode_config.rotation_property)
  10064. drm_object_attach_property(&primary->base.base,
  10065. dev->mode_config.rotation_property,
  10066. primary->rotation);
  10067. }
  10068. return &primary->base;
  10069. }
  10070. static int
  10071. intel_cursor_plane_disable(struct drm_plane *plane)
  10072. {
  10073. if (!plane->fb)
  10074. return 0;
  10075. BUG_ON(!plane->crtc);
  10076. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  10077. }
  10078. static int
  10079. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  10080. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  10081. unsigned int crtc_w, unsigned int crtc_h,
  10082. uint32_t src_x, uint32_t src_y,
  10083. uint32_t src_w, uint32_t src_h)
  10084. {
  10085. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10086. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10087. struct drm_i915_gem_object *obj = intel_fb->obj;
  10088. struct drm_rect dest = {
  10089. /* integer pixels */
  10090. .x1 = crtc_x,
  10091. .y1 = crtc_y,
  10092. .x2 = crtc_x + crtc_w,
  10093. .y2 = crtc_y + crtc_h,
  10094. };
  10095. struct drm_rect src = {
  10096. /* 16.16 fixed point */
  10097. .x1 = src_x,
  10098. .y1 = src_y,
  10099. .x2 = src_x + src_w,
  10100. .y2 = src_y + src_h,
  10101. };
  10102. const struct drm_rect clip = {
  10103. /* integer pixels */
  10104. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  10105. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  10106. };
  10107. bool visible;
  10108. int ret;
  10109. ret = drm_plane_helper_check_update(plane, crtc, fb,
  10110. &src, &dest, &clip,
  10111. DRM_PLANE_HELPER_NO_SCALING,
  10112. DRM_PLANE_HELPER_NO_SCALING,
  10113. true, true, &visible);
  10114. if (ret)
  10115. return ret;
  10116. crtc->cursor_x = crtc_x;
  10117. crtc->cursor_y = crtc_y;
  10118. if (fb != crtc->cursor->fb) {
  10119. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  10120. } else {
  10121. intel_crtc_update_cursor(crtc, visible);
  10122. intel_frontbuffer_flip(crtc->dev,
  10123. INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe));
  10124. return 0;
  10125. }
  10126. }
  10127. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  10128. .update_plane = intel_cursor_plane_update,
  10129. .disable_plane = intel_cursor_plane_disable,
  10130. .destroy = intel_plane_destroy,
  10131. };
  10132. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  10133. int pipe)
  10134. {
  10135. struct intel_plane *cursor;
  10136. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  10137. if (cursor == NULL)
  10138. return NULL;
  10139. cursor->can_scale = false;
  10140. cursor->max_downscale = 1;
  10141. cursor->pipe = pipe;
  10142. cursor->plane = pipe;
  10143. drm_universal_plane_init(dev, &cursor->base, 0,
  10144. &intel_cursor_plane_funcs,
  10145. intel_cursor_formats,
  10146. ARRAY_SIZE(intel_cursor_formats),
  10147. DRM_PLANE_TYPE_CURSOR);
  10148. return &cursor->base;
  10149. }
  10150. static void intel_crtc_init(struct drm_device *dev, int pipe)
  10151. {
  10152. struct drm_i915_private *dev_priv = dev->dev_private;
  10153. struct intel_crtc *intel_crtc;
  10154. struct drm_plane *primary = NULL;
  10155. struct drm_plane *cursor = NULL;
  10156. int i, ret;
  10157. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  10158. if (intel_crtc == NULL)
  10159. return;
  10160. primary = intel_primary_plane_create(dev, pipe);
  10161. if (!primary)
  10162. goto fail;
  10163. cursor = intel_cursor_plane_create(dev, pipe);
  10164. if (!cursor)
  10165. goto fail;
  10166. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  10167. cursor, &intel_crtc_funcs);
  10168. if (ret)
  10169. goto fail;
  10170. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  10171. for (i = 0; i < 256; i++) {
  10172. intel_crtc->lut_r[i] = i;
  10173. intel_crtc->lut_g[i] = i;
  10174. intel_crtc->lut_b[i] = i;
  10175. }
  10176. /*
  10177. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  10178. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  10179. */
  10180. intel_crtc->pipe = pipe;
  10181. intel_crtc->plane = pipe;
  10182. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  10183. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  10184. intel_crtc->plane = !pipe;
  10185. }
  10186. intel_crtc->cursor_base = ~0;
  10187. intel_crtc->cursor_cntl = ~0;
  10188. intel_crtc->cursor_size = ~0;
  10189. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  10190. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  10191. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  10192. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  10193. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  10194. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  10195. return;
  10196. fail:
  10197. if (primary)
  10198. drm_plane_cleanup(primary);
  10199. if (cursor)
  10200. drm_plane_cleanup(cursor);
  10201. kfree(intel_crtc);
  10202. }
  10203. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  10204. {
  10205. struct drm_encoder *encoder = connector->base.encoder;
  10206. struct drm_device *dev = connector->base.dev;
  10207. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  10208. if (!encoder)
  10209. return INVALID_PIPE;
  10210. return to_intel_crtc(encoder->crtc)->pipe;
  10211. }
  10212. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  10213. struct drm_file *file)
  10214. {
  10215. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  10216. struct drm_crtc *drmmode_crtc;
  10217. struct intel_crtc *crtc;
  10218. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  10219. return -ENODEV;
  10220. drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id);
  10221. if (!drmmode_crtc) {
  10222. DRM_ERROR("no such CRTC id\n");
  10223. return -ENOENT;
  10224. }
  10225. crtc = to_intel_crtc(drmmode_crtc);
  10226. pipe_from_crtc_id->pipe = crtc->pipe;
  10227. return 0;
  10228. }
  10229. static int intel_encoder_clones(struct intel_encoder *encoder)
  10230. {
  10231. struct drm_device *dev = encoder->base.dev;
  10232. struct intel_encoder *source_encoder;
  10233. int index_mask = 0;
  10234. int entry = 0;
  10235. for_each_intel_encoder(dev, source_encoder) {
  10236. if (encoders_cloneable(encoder, source_encoder))
  10237. index_mask |= (1 << entry);
  10238. entry++;
  10239. }
  10240. return index_mask;
  10241. }
  10242. static bool has_edp_a(struct drm_device *dev)
  10243. {
  10244. struct drm_i915_private *dev_priv = dev->dev_private;
  10245. if (!IS_MOBILE(dev))
  10246. return false;
  10247. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  10248. return false;
  10249. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  10250. return false;
  10251. return true;
  10252. }
  10253. const char *intel_output_name(int output)
  10254. {
  10255. static const char *names[] = {
  10256. [INTEL_OUTPUT_UNUSED] = "Unused",
  10257. [INTEL_OUTPUT_ANALOG] = "Analog",
  10258. [INTEL_OUTPUT_DVO] = "DVO",
  10259. [INTEL_OUTPUT_SDVO] = "SDVO",
  10260. [INTEL_OUTPUT_LVDS] = "LVDS",
  10261. [INTEL_OUTPUT_TVOUT] = "TV",
  10262. [INTEL_OUTPUT_HDMI] = "HDMI",
  10263. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  10264. [INTEL_OUTPUT_EDP] = "eDP",
  10265. [INTEL_OUTPUT_DSI] = "DSI",
  10266. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  10267. };
  10268. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  10269. return "Invalid";
  10270. return names[output];
  10271. }
  10272. static bool intel_crt_present(struct drm_device *dev)
  10273. {
  10274. struct drm_i915_private *dev_priv = dev->dev_private;
  10275. if (IS_ULT(dev))
  10276. return false;
  10277. if (IS_CHERRYVIEW(dev))
  10278. return false;
  10279. if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
  10280. return false;
  10281. return true;
  10282. }
  10283. static void intel_setup_outputs(struct drm_device *dev)
  10284. {
  10285. struct drm_i915_private *dev_priv = dev->dev_private;
  10286. struct intel_encoder *encoder;
  10287. bool dpd_is_edp = false;
  10288. intel_lvds_init(dev);
  10289. if (intel_crt_present(dev))
  10290. intel_crt_init(dev);
  10291. if (HAS_DDI(dev)) {
  10292. int found;
  10293. /* Haswell uses DDI functions to detect digital outputs */
  10294. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  10295. /* DDI A only supports eDP */
  10296. if (found)
  10297. intel_ddi_init(dev, PORT_A);
  10298. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  10299. * register */
  10300. found = I915_READ(SFUSE_STRAP);
  10301. if (found & SFUSE_STRAP_DDIB_DETECTED)
  10302. intel_ddi_init(dev, PORT_B);
  10303. if (found & SFUSE_STRAP_DDIC_DETECTED)
  10304. intel_ddi_init(dev, PORT_C);
  10305. if (found & SFUSE_STRAP_DDID_DETECTED)
  10306. intel_ddi_init(dev, PORT_D);
  10307. } else if (HAS_PCH_SPLIT(dev)) {
  10308. int found;
  10309. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  10310. if (has_edp_a(dev))
  10311. intel_dp_init(dev, DP_A, PORT_A);
  10312. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  10313. /* PCH SDVOB multiplex with HDMIB */
  10314. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  10315. if (!found)
  10316. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  10317. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  10318. intel_dp_init(dev, PCH_DP_B, PORT_B);
  10319. }
  10320. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  10321. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  10322. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  10323. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  10324. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  10325. intel_dp_init(dev, PCH_DP_C, PORT_C);
  10326. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  10327. intel_dp_init(dev, PCH_DP_D, PORT_D);
  10328. } else if (IS_VALLEYVIEW(dev)) {
  10329. /*
  10330. * The DP_DETECTED bit is the latched state of the DDC
  10331. * SDA pin at boot. However since eDP doesn't require DDC
  10332. * (no way to plug in a DP->HDMI dongle) the DDC pins for
  10333. * eDP ports may have been muxed to an alternate function.
  10334. * Thus we can't rely on the DP_DETECTED bit alone to detect
  10335. * eDP ports. Consult the VBT as well as DP_DETECTED to
  10336. * detect eDP ports.
  10337. */
  10338. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED)
  10339. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  10340. PORT_B);
  10341. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED ||
  10342. intel_dp_is_edp(dev, PORT_B))
  10343. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  10344. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED)
  10345. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  10346. PORT_C);
  10347. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED ||
  10348. intel_dp_is_edp(dev, PORT_C))
  10349. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  10350. if (IS_CHERRYVIEW(dev)) {
  10351. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED)
  10352. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  10353. PORT_D);
  10354. /* eDP not supported on port D, so don't check VBT */
  10355. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  10356. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  10357. }
  10358. intel_dsi_init(dev);
  10359. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  10360. bool found = false;
  10361. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10362. DRM_DEBUG_KMS("probing SDVOB\n");
  10363. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  10364. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  10365. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  10366. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  10367. }
  10368. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  10369. intel_dp_init(dev, DP_B, PORT_B);
  10370. }
  10371. /* Before G4X SDVOC doesn't have its own detect register */
  10372. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10373. DRM_DEBUG_KMS("probing SDVOC\n");
  10374. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  10375. }
  10376. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  10377. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  10378. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  10379. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  10380. }
  10381. if (SUPPORTS_INTEGRATED_DP(dev))
  10382. intel_dp_init(dev, DP_C, PORT_C);
  10383. }
  10384. if (SUPPORTS_INTEGRATED_DP(dev) &&
  10385. (I915_READ(DP_D) & DP_DETECTED))
  10386. intel_dp_init(dev, DP_D, PORT_D);
  10387. } else if (IS_GEN2(dev))
  10388. intel_dvo_init(dev);
  10389. if (SUPPORTS_TV(dev))
  10390. intel_tv_init(dev);
  10391. intel_edp_psr_init(dev);
  10392. for_each_intel_encoder(dev, encoder) {
  10393. encoder->base.possible_crtcs = encoder->crtc_mask;
  10394. encoder->base.possible_clones =
  10395. intel_encoder_clones(encoder);
  10396. }
  10397. intel_init_pch_refclk(dev);
  10398. drm_helper_move_panel_connectors_to_head(dev);
  10399. }
  10400. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  10401. {
  10402. struct drm_device *dev = fb->dev;
  10403. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10404. drm_framebuffer_cleanup(fb);
  10405. mutex_lock(&dev->struct_mutex);
  10406. WARN_ON(!intel_fb->obj->framebuffer_references--);
  10407. drm_gem_object_unreference(&intel_fb->obj->base);
  10408. mutex_unlock(&dev->struct_mutex);
  10409. kfree(intel_fb);
  10410. }
  10411. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  10412. struct drm_file *file,
  10413. unsigned int *handle)
  10414. {
  10415. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10416. struct drm_i915_gem_object *obj = intel_fb->obj;
  10417. return drm_gem_handle_create(file, &obj->base, handle);
  10418. }
  10419. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  10420. .destroy = intel_user_framebuffer_destroy,
  10421. .create_handle = intel_user_framebuffer_create_handle,
  10422. };
  10423. static int intel_framebuffer_init(struct drm_device *dev,
  10424. struct intel_framebuffer *intel_fb,
  10425. struct drm_mode_fb_cmd2 *mode_cmd,
  10426. struct drm_i915_gem_object *obj)
  10427. {
  10428. int aligned_height;
  10429. int pitch_limit;
  10430. int ret;
  10431. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10432. if (obj->tiling_mode == I915_TILING_Y) {
  10433. DRM_DEBUG("hardware does not support tiling Y\n");
  10434. return -EINVAL;
  10435. }
  10436. if (mode_cmd->pitches[0] & 63) {
  10437. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10438. mode_cmd->pitches[0]);
  10439. return -EINVAL;
  10440. }
  10441. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10442. pitch_limit = 32*1024;
  10443. } else if (INTEL_INFO(dev)->gen >= 4) {
  10444. if (obj->tiling_mode)
  10445. pitch_limit = 16*1024;
  10446. else
  10447. pitch_limit = 32*1024;
  10448. } else if (INTEL_INFO(dev)->gen >= 3) {
  10449. if (obj->tiling_mode)
  10450. pitch_limit = 8*1024;
  10451. else
  10452. pitch_limit = 16*1024;
  10453. } else
  10454. /* XXX DSPC is limited to 4k tiled */
  10455. pitch_limit = 8*1024;
  10456. if (mode_cmd->pitches[0] > pitch_limit) {
  10457. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10458. obj->tiling_mode ? "tiled" : "linear",
  10459. mode_cmd->pitches[0], pitch_limit);
  10460. return -EINVAL;
  10461. }
  10462. if (obj->tiling_mode != I915_TILING_NONE &&
  10463. mode_cmd->pitches[0] != obj->stride) {
  10464. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10465. mode_cmd->pitches[0], obj->stride);
  10466. return -EINVAL;
  10467. }
  10468. /* Reject formats not supported by any plane early. */
  10469. switch (mode_cmd->pixel_format) {
  10470. case DRM_FORMAT_C8:
  10471. case DRM_FORMAT_RGB565:
  10472. case DRM_FORMAT_XRGB8888:
  10473. case DRM_FORMAT_ARGB8888:
  10474. break;
  10475. case DRM_FORMAT_XRGB1555:
  10476. case DRM_FORMAT_ARGB1555:
  10477. if (INTEL_INFO(dev)->gen > 3) {
  10478. DRM_DEBUG("unsupported pixel format: %s\n",
  10479. drm_get_format_name(mode_cmd->pixel_format));
  10480. return -EINVAL;
  10481. }
  10482. break;
  10483. case DRM_FORMAT_XBGR8888:
  10484. case DRM_FORMAT_ABGR8888:
  10485. case DRM_FORMAT_XRGB2101010:
  10486. case DRM_FORMAT_ARGB2101010:
  10487. case DRM_FORMAT_XBGR2101010:
  10488. case DRM_FORMAT_ABGR2101010:
  10489. if (INTEL_INFO(dev)->gen < 4) {
  10490. DRM_DEBUG("unsupported pixel format: %s\n",
  10491. drm_get_format_name(mode_cmd->pixel_format));
  10492. return -EINVAL;
  10493. }
  10494. break;
  10495. case DRM_FORMAT_YUYV:
  10496. case DRM_FORMAT_UYVY:
  10497. case DRM_FORMAT_YVYU:
  10498. case DRM_FORMAT_VYUY:
  10499. if (INTEL_INFO(dev)->gen < 5) {
  10500. DRM_DEBUG("unsupported pixel format: %s\n",
  10501. drm_get_format_name(mode_cmd->pixel_format));
  10502. return -EINVAL;
  10503. }
  10504. break;
  10505. default:
  10506. DRM_DEBUG("unsupported pixel format: %s\n",
  10507. drm_get_format_name(mode_cmd->pixel_format));
  10508. return -EINVAL;
  10509. }
  10510. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10511. if (mode_cmd->offsets[0] != 0)
  10512. return -EINVAL;
  10513. aligned_height = intel_align_height(dev, mode_cmd->height,
  10514. obj->tiling_mode);
  10515. /* FIXME drm helper for size checks (especially planar formats)? */
  10516. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10517. return -EINVAL;
  10518. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10519. intel_fb->obj = obj;
  10520. intel_fb->obj->framebuffer_references++;
  10521. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10522. if (ret) {
  10523. DRM_ERROR("framebuffer init failed %d\n", ret);
  10524. return ret;
  10525. }
  10526. return 0;
  10527. }
  10528. static struct drm_framebuffer *
  10529. intel_user_framebuffer_create(struct drm_device *dev,
  10530. struct drm_file *filp,
  10531. struct drm_mode_fb_cmd2 *mode_cmd)
  10532. {
  10533. struct drm_i915_gem_object *obj;
  10534. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10535. mode_cmd->handles[0]));
  10536. if (&obj->base == NULL)
  10537. return ERR_PTR(-ENOENT);
  10538. return intel_framebuffer_create(dev, mode_cmd, obj);
  10539. }
  10540. #ifndef CONFIG_DRM_I915_FBDEV
  10541. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10542. {
  10543. }
  10544. #endif
  10545. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10546. .fb_create = intel_user_framebuffer_create,
  10547. .output_poll_changed = intel_fbdev_output_poll_changed,
  10548. };
  10549. /* Set up chip specific display functions */
  10550. static void intel_init_display(struct drm_device *dev)
  10551. {
  10552. struct drm_i915_private *dev_priv = dev->dev_private;
  10553. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10554. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10555. else if (IS_CHERRYVIEW(dev))
  10556. dev_priv->display.find_dpll = chv_find_best_dpll;
  10557. else if (IS_VALLEYVIEW(dev))
  10558. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10559. else if (IS_PINEVIEW(dev))
  10560. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10561. else
  10562. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10563. if (HAS_DDI(dev)) {
  10564. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10565. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10566. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10567. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10568. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10569. dev_priv->display.off = ironlake_crtc_off;
  10570. dev_priv->display.update_primary_plane =
  10571. ironlake_update_primary_plane;
  10572. } else if (HAS_PCH_SPLIT(dev)) {
  10573. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10574. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10575. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10576. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10577. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10578. dev_priv->display.off = ironlake_crtc_off;
  10579. dev_priv->display.update_primary_plane =
  10580. ironlake_update_primary_plane;
  10581. } else if (IS_VALLEYVIEW(dev)) {
  10582. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10583. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10584. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10585. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10586. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10587. dev_priv->display.off = i9xx_crtc_off;
  10588. dev_priv->display.update_primary_plane =
  10589. i9xx_update_primary_plane;
  10590. } else {
  10591. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10592. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10593. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10594. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10595. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10596. dev_priv->display.off = i9xx_crtc_off;
  10597. dev_priv->display.update_primary_plane =
  10598. i9xx_update_primary_plane;
  10599. }
  10600. /* Returns the core display clock speed */
  10601. if (IS_VALLEYVIEW(dev))
  10602. dev_priv->display.get_display_clock_speed =
  10603. valleyview_get_display_clock_speed;
  10604. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10605. dev_priv->display.get_display_clock_speed =
  10606. i945_get_display_clock_speed;
  10607. else if (IS_I915G(dev))
  10608. dev_priv->display.get_display_clock_speed =
  10609. i915_get_display_clock_speed;
  10610. else if (IS_I945GM(dev) || IS_845G(dev))
  10611. dev_priv->display.get_display_clock_speed =
  10612. i9xx_misc_get_display_clock_speed;
  10613. else if (IS_PINEVIEW(dev))
  10614. dev_priv->display.get_display_clock_speed =
  10615. pnv_get_display_clock_speed;
  10616. else if (IS_I915GM(dev))
  10617. dev_priv->display.get_display_clock_speed =
  10618. i915gm_get_display_clock_speed;
  10619. else if (IS_I865G(dev))
  10620. dev_priv->display.get_display_clock_speed =
  10621. i865_get_display_clock_speed;
  10622. else if (IS_I85X(dev))
  10623. dev_priv->display.get_display_clock_speed =
  10624. i855_get_display_clock_speed;
  10625. else /* 852, 830 */
  10626. dev_priv->display.get_display_clock_speed =
  10627. i830_get_display_clock_speed;
  10628. if (IS_G4X(dev)) {
  10629. dev_priv->display.write_eld = g4x_write_eld;
  10630. } else if (IS_GEN5(dev)) {
  10631. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10632. dev_priv->display.write_eld = ironlake_write_eld;
  10633. } else if (IS_GEN6(dev)) {
  10634. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10635. dev_priv->display.write_eld = ironlake_write_eld;
  10636. dev_priv->display.modeset_global_resources =
  10637. snb_modeset_global_resources;
  10638. } else if (IS_IVYBRIDGE(dev)) {
  10639. /* FIXME: detect B0+ stepping and use auto training */
  10640. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10641. dev_priv->display.write_eld = ironlake_write_eld;
  10642. dev_priv->display.modeset_global_resources =
  10643. ivb_modeset_global_resources;
  10644. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  10645. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10646. dev_priv->display.write_eld = haswell_write_eld;
  10647. dev_priv->display.modeset_global_resources =
  10648. haswell_modeset_global_resources;
  10649. } else if (IS_VALLEYVIEW(dev)) {
  10650. dev_priv->display.modeset_global_resources =
  10651. valleyview_modeset_global_resources;
  10652. dev_priv->display.write_eld = ironlake_write_eld;
  10653. }
  10654. /* Default just returns -ENODEV to indicate unsupported */
  10655. dev_priv->display.queue_flip = intel_default_queue_flip;
  10656. switch (INTEL_INFO(dev)->gen) {
  10657. case 2:
  10658. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10659. break;
  10660. case 3:
  10661. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10662. break;
  10663. case 4:
  10664. case 5:
  10665. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10666. break;
  10667. case 6:
  10668. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10669. break;
  10670. case 7:
  10671. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10672. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10673. break;
  10674. }
  10675. intel_panel_init_backlight_funcs(dev);
  10676. mutex_init(&dev_priv->pps_mutex);
  10677. }
  10678. /*
  10679. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10680. * resume, or other times. This quirk makes sure that's the case for
  10681. * affected systems.
  10682. */
  10683. static void quirk_pipea_force(struct drm_device *dev)
  10684. {
  10685. struct drm_i915_private *dev_priv = dev->dev_private;
  10686. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10687. DRM_INFO("applying pipe a force quirk\n");
  10688. }
  10689. static void quirk_pipeb_force(struct drm_device *dev)
  10690. {
  10691. struct drm_i915_private *dev_priv = dev->dev_private;
  10692. dev_priv->quirks |= QUIRK_PIPEB_FORCE;
  10693. DRM_INFO("applying pipe b force quirk\n");
  10694. }
  10695. /*
  10696. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10697. */
  10698. static void quirk_ssc_force_disable(struct drm_device *dev)
  10699. {
  10700. struct drm_i915_private *dev_priv = dev->dev_private;
  10701. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10702. DRM_INFO("applying lvds SSC disable quirk\n");
  10703. }
  10704. /*
  10705. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10706. * brightness value
  10707. */
  10708. static void quirk_invert_brightness(struct drm_device *dev)
  10709. {
  10710. struct drm_i915_private *dev_priv = dev->dev_private;
  10711. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10712. DRM_INFO("applying inverted panel brightness quirk\n");
  10713. }
  10714. /* Some VBT's incorrectly indicate no backlight is present */
  10715. static void quirk_backlight_present(struct drm_device *dev)
  10716. {
  10717. struct drm_i915_private *dev_priv = dev->dev_private;
  10718. dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
  10719. DRM_INFO("applying backlight present quirk\n");
  10720. }
  10721. struct intel_quirk {
  10722. int device;
  10723. int subsystem_vendor;
  10724. int subsystem_device;
  10725. void (*hook)(struct drm_device *dev);
  10726. };
  10727. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10728. struct intel_dmi_quirk {
  10729. void (*hook)(struct drm_device *dev);
  10730. const struct dmi_system_id (*dmi_id_list)[];
  10731. };
  10732. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10733. {
  10734. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10735. return 1;
  10736. }
  10737. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10738. {
  10739. .dmi_id_list = &(const struct dmi_system_id[]) {
  10740. {
  10741. .callback = intel_dmi_reverse_brightness,
  10742. .ident = "NCR Corporation",
  10743. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10744. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10745. },
  10746. },
  10747. { } /* terminating entry */
  10748. },
  10749. .hook = quirk_invert_brightness,
  10750. },
  10751. };
  10752. static struct intel_quirk intel_quirks[] = {
  10753. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10754. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10755. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10756. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10757. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10758. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10759. /* 830 needs to leave pipe A & dpll A up */
  10760. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10761. /* 830 needs to leave pipe B & dpll B up */
  10762. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force },
  10763. /* Lenovo U160 cannot use SSC on LVDS */
  10764. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10765. /* Sony Vaio Y cannot use SSC on LVDS */
  10766. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10767. /* Acer Aspire 5734Z must invert backlight brightness */
  10768. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10769. /* Acer/eMachines G725 */
  10770. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10771. /* Acer/eMachines e725 */
  10772. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10773. /* Acer/Packard Bell NCL20 */
  10774. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10775. /* Acer Aspire 4736Z */
  10776. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10777. /* Acer Aspire 5336 */
  10778. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10779. /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
  10780. { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
  10781. /* Acer C720 Chromebook (Core i3 4005U) */
  10782. { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
  10783. /* Apple Macbook 2,1 (Core 2 T7400) */
  10784. { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
  10785. /* Toshiba CB35 Chromebook (Celeron 2955U) */
  10786. { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
  10787. /* HP Chromebook 14 (Celeron 2955U) */
  10788. { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
  10789. /* Dell Chromebook 11 */
  10790. { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
  10791. };
  10792. static void intel_init_quirks(struct drm_device *dev)
  10793. {
  10794. struct pci_dev *d = dev->pdev;
  10795. int i;
  10796. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10797. struct intel_quirk *q = &intel_quirks[i];
  10798. if (d->device == q->device &&
  10799. (d->subsystem_vendor == q->subsystem_vendor ||
  10800. q->subsystem_vendor == PCI_ANY_ID) &&
  10801. (d->subsystem_device == q->subsystem_device ||
  10802. q->subsystem_device == PCI_ANY_ID))
  10803. q->hook(dev);
  10804. }
  10805. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10806. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10807. intel_dmi_quirks[i].hook(dev);
  10808. }
  10809. }
  10810. /* Disable the VGA plane that we never use */
  10811. static void i915_disable_vga(struct drm_device *dev)
  10812. {
  10813. struct drm_i915_private *dev_priv = dev->dev_private;
  10814. u8 sr1;
  10815. u32 vga_reg = i915_vgacntrl_reg(dev);
  10816. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10817. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10818. outb(SR01, VGA_SR_INDEX);
  10819. sr1 = inb(VGA_SR_DATA);
  10820. outb(sr1 | 1<<5, VGA_SR_DATA);
  10821. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10822. udelay(300);
  10823. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  10824. POSTING_READ(vga_reg);
  10825. }
  10826. void intel_modeset_init_hw(struct drm_device *dev)
  10827. {
  10828. intel_prepare_ddi(dev);
  10829. if (IS_VALLEYVIEW(dev))
  10830. vlv_update_cdclk(dev);
  10831. intel_init_clock_gating(dev);
  10832. intel_enable_gt_powersave(dev);
  10833. }
  10834. void intel_modeset_suspend_hw(struct drm_device *dev)
  10835. {
  10836. intel_suspend_hw(dev);
  10837. }
  10838. void intel_modeset_init(struct drm_device *dev)
  10839. {
  10840. struct drm_i915_private *dev_priv = dev->dev_private;
  10841. int sprite, ret;
  10842. enum pipe pipe;
  10843. struct intel_crtc *crtc;
  10844. drm_mode_config_init(dev);
  10845. dev->mode_config.min_width = 0;
  10846. dev->mode_config.min_height = 0;
  10847. dev->mode_config.preferred_depth = 24;
  10848. dev->mode_config.prefer_shadow = 1;
  10849. dev->mode_config.funcs = &intel_mode_funcs;
  10850. intel_init_quirks(dev);
  10851. intel_init_pm(dev);
  10852. if (INTEL_INFO(dev)->num_pipes == 0)
  10853. return;
  10854. intel_init_display(dev);
  10855. if (IS_GEN2(dev)) {
  10856. dev->mode_config.max_width = 2048;
  10857. dev->mode_config.max_height = 2048;
  10858. } else if (IS_GEN3(dev)) {
  10859. dev->mode_config.max_width = 4096;
  10860. dev->mode_config.max_height = 4096;
  10861. } else {
  10862. dev->mode_config.max_width = 8192;
  10863. dev->mode_config.max_height = 8192;
  10864. }
  10865. if (IS_845G(dev) || IS_I865G(dev)) {
  10866. dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512;
  10867. dev->mode_config.cursor_height = 1023;
  10868. } else if (IS_GEN2(dev)) {
  10869. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10870. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10871. } else {
  10872. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10873. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10874. }
  10875. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10876. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10877. INTEL_INFO(dev)->num_pipes,
  10878. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10879. for_each_pipe(dev_priv, pipe) {
  10880. intel_crtc_init(dev, pipe);
  10881. for_each_sprite(pipe, sprite) {
  10882. ret = intel_plane_init(dev, pipe, sprite);
  10883. if (ret)
  10884. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10885. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10886. }
  10887. }
  10888. intel_init_dpio(dev);
  10889. intel_shared_dpll_init(dev);
  10890. /* Just disable it once at startup */
  10891. i915_disable_vga(dev);
  10892. intel_setup_outputs(dev);
  10893. /* Just in case the BIOS is doing something questionable. */
  10894. intel_disable_fbc(dev);
  10895. drm_modeset_lock_all(dev);
  10896. intel_modeset_setup_hw_state(dev, false);
  10897. drm_modeset_unlock_all(dev);
  10898. for_each_intel_crtc(dev, crtc) {
  10899. if (!crtc->active)
  10900. continue;
  10901. /*
  10902. * Note that reserving the BIOS fb up front prevents us
  10903. * from stuffing other stolen allocations like the ring
  10904. * on top. This prevents some ugliness at boot time, and
  10905. * can even allow for smooth boot transitions if the BIOS
  10906. * fb is large enough for the active pipe configuration.
  10907. */
  10908. if (dev_priv->display.get_plane_config) {
  10909. dev_priv->display.get_plane_config(crtc,
  10910. &crtc->plane_config);
  10911. /*
  10912. * If the fb is shared between multiple heads, we'll
  10913. * just get the first one.
  10914. */
  10915. intel_find_plane_obj(crtc, &crtc->plane_config);
  10916. }
  10917. }
  10918. }
  10919. static void intel_enable_pipe_a(struct drm_device *dev)
  10920. {
  10921. struct intel_connector *connector;
  10922. struct drm_connector *crt = NULL;
  10923. struct intel_load_detect_pipe load_detect_temp;
  10924. struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx;
  10925. /* We can't just switch on the pipe A, we need to set things up with a
  10926. * proper mode and output configuration. As a gross hack, enable pipe A
  10927. * by enabling the load detect pipe once. */
  10928. list_for_each_entry(connector,
  10929. &dev->mode_config.connector_list,
  10930. base.head) {
  10931. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  10932. crt = &connector->base;
  10933. break;
  10934. }
  10935. }
  10936. if (!crt)
  10937. return;
  10938. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx))
  10939. intel_release_load_detect_pipe(crt, &load_detect_temp);
  10940. }
  10941. static bool
  10942. intel_check_plane_mapping(struct intel_crtc *crtc)
  10943. {
  10944. struct drm_device *dev = crtc->base.dev;
  10945. struct drm_i915_private *dev_priv = dev->dev_private;
  10946. u32 reg, val;
  10947. if (INTEL_INFO(dev)->num_pipes == 1)
  10948. return true;
  10949. reg = DSPCNTR(!crtc->plane);
  10950. val = I915_READ(reg);
  10951. if ((val & DISPLAY_PLANE_ENABLE) &&
  10952. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  10953. return false;
  10954. return true;
  10955. }
  10956. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  10957. {
  10958. struct drm_device *dev = crtc->base.dev;
  10959. struct drm_i915_private *dev_priv = dev->dev_private;
  10960. u32 reg;
  10961. /* Clear any frame start delays used for debugging left by the BIOS */
  10962. reg = PIPECONF(crtc->config.cpu_transcoder);
  10963. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  10964. /* restore vblank interrupts to correct state */
  10965. if (crtc->active) {
  10966. update_scanline_offset(crtc);
  10967. drm_vblank_on(dev, crtc->pipe);
  10968. } else
  10969. drm_vblank_off(dev, crtc->pipe);
  10970. /* We need to sanitize the plane -> pipe mapping first because this will
  10971. * disable the crtc (and hence change the state) if it is wrong. Note
  10972. * that gen4+ has a fixed plane -> pipe mapping. */
  10973. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  10974. struct intel_connector *connector;
  10975. bool plane;
  10976. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  10977. crtc->base.base.id);
  10978. /* Pipe has the wrong plane attached and the plane is active.
  10979. * Temporarily change the plane mapping and disable everything
  10980. * ... */
  10981. plane = crtc->plane;
  10982. crtc->plane = !plane;
  10983. crtc->primary_enabled = true;
  10984. dev_priv->display.crtc_disable(&crtc->base);
  10985. crtc->plane = plane;
  10986. /* ... and break all links. */
  10987. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10988. base.head) {
  10989. if (connector->encoder->base.crtc != &crtc->base)
  10990. continue;
  10991. connector->base.dpms = DRM_MODE_DPMS_OFF;
  10992. connector->base.encoder = NULL;
  10993. }
  10994. /* multiple connectors may have the same encoder:
  10995. * handle them and break crtc link separately */
  10996. list_for_each_entry(connector, &dev->mode_config.connector_list,
  10997. base.head)
  10998. if (connector->encoder->base.crtc == &crtc->base) {
  10999. connector->encoder->base.crtc = NULL;
  11000. connector->encoder->connectors_active = false;
  11001. }
  11002. WARN_ON(crtc->active);
  11003. crtc->base.enabled = false;
  11004. }
  11005. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  11006. crtc->pipe == PIPE_A && !crtc->active) {
  11007. /* BIOS forgot to enable pipe A, this mostly happens after
  11008. * resume. Force-enable the pipe to fix this, the update_dpms
  11009. * call below we restore the pipe to the right state, but leave
  11010. * the required bits on. */
  11011. intel_enable_pipe_a(dev);
  11012. }
  11013. /* Adjust the state of the output pipe according to whether we
  11014. * have active connectors/encoders. */
  11015. intel_crtc_update_dpms(&crtc->base);
  11016. if (crtc->active != crtc->base.enabled) {
  11017. struct intel_encoder *encoder;
  11018. /* This can happen either due to bugs in the get_hw_state
  11019. * functions or because the pipe is force-enabled due to the
  11020. * pipe A quirk. */
  11021. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  11022. crtc->base.base.id,
  11023. crtc->base.enabled ? "enabled" : "disabled",
  11024. crtc->active ? "enabled" : "disabled");
  11025. crtc->base.enabled = crtc->active;
  11026. /* Because we only establish the connector -> encoder ->
  11027. * crtc links if something is active, this means the
  11028. * crtc is now deactivated. Break the links. connector
  11029. * -> encoder links are only establish when things are
  11030. * actually up, hence no need to break them. */
  11031. WARN_ON(crtc->active);
  11032. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  11033. WARN_ON(encoder->connectors_active);
  11034. encoder->base.crtc = NULL;
  11035. }
  11036. }
  11037. if (crtc->active || HAS_GMCH_DISPLAY(dev)) {
  11038. /*
  11039. * We start out with underrun reporting disabled to avoid races.
  11040. * For correct bookkeeping mark this on active crtcs.
  11041. *
  11042. * Also on gmch platforms we dont have any hardware bits to
  11043. * disable the underrun reporting. Which means we need to start
  11044. * out with underrun reporting disabled also on inactive pipes,
  11045. * since otherwise we'll complain about the garbage we read when
  11046. * e.g. coming up after runtime pm.
  11047. *
  11048. * No protection against concurrent access is required - at
  11049. * worst a fifo underrun happens which also sets this to false.
  11050. */
  11051. crtc->cpu_fifo_underrun_disabled = true;
  11052. crtc->pch_fifo_underrun_disabled = true;
  11053. }
  11054. }
  11055. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  11056. {
  11057. struct intel_connector *connector;
  11058. struct drm_device *dev = encoder->base.dev;
  11059. /* We need to check both for a crtc link (meaning that the
  11060. * encoder is active and trying to read from a pipe) and the
  11061. * pipe itself being active. */
  11062. bool has_active_crtc = encoder->base.crtc &&
  11063. to_intel_crtc(encoder->base.crtc)->active;
  11064. if (encoder->connectors_active && !has_active_crtc) {
  11065. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  11066. encoder->base.base.id,
  11067. encoder->base.name);
  11068. /* Connector is active, but has no active pipe. This is
  11069. * fallout from our resume register restoring. Disable
  11070. * the encoder manually again. */
  11071. if (encoder->base.crtc) {
  11072. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  11073. encoder->base.base.id,
  11074. encoder->base.name);
  11075. encoder->disable(encoder);
  11076. if (encoder->post_disable)
  11077. encoder->post_disable(encoder);
  11078. }
  11079. encoder->base.crtc = NULL;
  11080. encoder->connectors_active = false;
  11081. /* Inconsistent output/port/pipe state happens presumably due to
  11082. * a bug in one of the get_hw_state functions. Or someplace else
  11083. * in our code, like the register restore mess on resume. Clamp
  11084. * things to off as a safer default. */
  11085. list_for_each_entry(connector,
  11086. &dev->mode_config.connector_list,
  11087. base.head) {
  11088. if (connector->encoder != encoder)
  11089. continue;
  11090. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11091. connector->base.encoder = NULL;
  11092. }
  11093. }
  11094. /* Enabled encoders without active connectors will be fixed in
  11095. * the crtc fixup. */
  11096. }
  11097. void i915_redisable_vga_power_on(struct drm_device *dev)
  11098. {
  11099. struct drm_i915_private *dev_priv = dev->dev_private;
  11100. u32 vga_reg = i915_vgacntrl_reg(dev);
  11101. if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
  11102. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  11103. i915_disable_vga(dev);
  11104. }
  11105. }
  11106. void i915_redisable_vga(struct drm_device *dev)
  11107. {
  11108. struct drm_i915_private *dev_priv = dev->dev_private;
  11109. /* This function can be called both from intel_modeset_setup_hw_state or
  11110. * at a very early point in our resume sequence, where the power well
  11111. * structures are not yet restored. Since this function is at a very
  11112. * paranoid "someone might have enabled VGA while we were not looking"
  11113. * level, just check if the power well is enabled instead of trying to
  11114. * follow the "don't touch the power well if we don't need it" policy
  11115. * the rest of the driver uses. */
  11116. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA))
  11117. return;
  11118. i915_redisable_vga_power_on(dev);
  11119. }
  11120. static bool primary_get_hw_state(struct intel_crtc *crtc)
  11121. {
  11122. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  11123. if (!crtc->active)
  11124. return false;
  11125. return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE;
  11126. }
  11127. static void intel_modeset_readout_hw_state(struct drm_device *dev)
  11128. {
  11129. struct drm_i915_private *dev_priv = dev->dev_private;
  11130. enum pipe pipe;
  11131. struct intel_crtc *crtc;
  11132. struct intel_encoder *encoder;
  11133. struct intel_connector *connector;
  11134. int i;
  11135. for_each_intel_crtc(dev, crtc) {
  11136. memset(&crtc->config, 0, sizeof(crtc->config));
  11137. crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE;
  11138. crtc->active = dev_priv->display.get_pipe_config(crtc,
  11139. &crtc->config);
  11140. crtc->base.enabled = crtc->active;
  11141. crtc->primary_enabled = primary_get_hw_state(crtc);
  11142. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  11143. crtc->base.base.id,
  11144. crtc->active ? "enabled" : "disabled");
  11145. }
  11146. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11147. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11148. pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state);
  11149. pll->active = 0;
  11150. for_each_intel_crtc(dev, crtc) {
  11151. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  11152. pll->active++;
  11153. }
  11154. pll->refcount = pll->active;
  11155. DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n",
  11156. pll->name, pll->refcount, pll->on);
  11157. if (pll->refcount)
  11158. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  11159. }
  11160. for_each_intel_encoder(dev, encoder) {
  11161. pipe = 0;
  11162. if (encoder->get_hw_state(encoder, &pipe)) {
  11163. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11164. encoder->base.crtc = &crtc->base;
  11165. encoder->get_config(encoder, &crtc->config);
  11166. } else {
  11167. encoder->base.crtc = NULL;
  11168. }
  11169. encoder->connectors_active = false;
  11170. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
  11171. encoder->base.base.id,
  11172. encoder->base.name,
  11173. encoder->base.crtc ? "enabled" : "disabled",
  11174. pipe_name(pipe));
  11175. }
  11176. list_for_each_entry(connector, &dev->mode_config.connector_list,
  11177. base.head) {
  11178. if (connector->get_hw_state(connector)) {
  11179. connector->base.dpms = DRM_MODE_DPMS_ON;
  11180. connector->encoder->connectors_active = true;
  11181. connector->base.encoder = &connector->encoder->base;
  11182. } else {
  11183. connector->base.dpms = DRM_MODE_DPMS_OFF;
  11184. connector->base.encoder = NULL;
  11185. }
  11186. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  11187. connector->base.base.id,
  11188. connector->base.name,
  11189. connector->base.encoder ? "enabled" : "disabled");
  11190. }
  11191. }
  11192. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  11193. * and i915 state tracking structures. */
  11194. void intel_modeset_setup_hw_state(struct drm_device *dev,
  11195. bool force_restore)
  11196. {
  11197. struct drm_i915_private *dev_priv = dev->dev_private;
  11198. enum pipe pipe;
  11199. struct intel_crtc *crtc;
  11200. struct intel_encoder *encoder;
  11201. int i;
  11202. intel_modeset_readout_hw_state(dev);
  11203. /*
  11204. * Now that we have the config, copy it to each CRTC struct
  11205. * Note that this could go away if we move to using crtc_config
  11206. * checking everywhere.
  11207. */
  11208. for_each_intel_crtc(dev, crtc) {
  11209. if (crtc->active && i915.fastboot) {
  11210. intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config);
  11211. DRM_DEBUG_KMS("[CRTC:%d] found active mode: ",
  11212. crtc->base.base.id);
  11213. drm_mode_debug_printmodeline(&crtc->base.mode);
  11214. }
  11215. }
  11216. /* HW state is read out, now we need to sanitize this mess. */
  11217. for_each_intel_encoder(dev, encoder) {
  11218. intel_sanitize_encoder(encoder);
  11219. }
  11220. for_each_pipe(dev_priv, pipe) {
  11221. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  11222. intel_sanitize_crtc(crtc);
  11223. intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]");
  11224. }
  11225. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  11226. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  11227. if (!pll->on || pll->active)
  11228. continue;
  11229. DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name);
  11230. pll->disable(dev_priv, pll);
  11231. pll->on = false;
  11232. }
  11233. if (HAS_PCH_SPLIT(dev))
  11234. ilk_wm_get_hw_state(dev);
  11235. if (force_restore) {
  11236. i915_redisable_vga(dev);
  11237. /*
  11238. * We need to use raw interfaces for restoring state to avoid
  11239. * checking (bogus) intermediate states.
  11240. */
  11241. for_each_pipe(dev_priv, pipe) {
  11242. struct drm_crtc *crtc =
  11243. dev_priv->pipe_to_crtc_mapping[pipe];
  11244. __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y,
  11245. crtc->primary->fb);
  11246. }
  11247. } else {
  11248. intel_modeset_update_staged_output_state(dev);
  11249. }
  11250. intel_modeset_check_state(dev);
  11251. }
  11252. void intel_modeset_gem_init(struct drm_device *dev)
  11253. {
  11254. struct drm_crtc *c;
  11255. struct drm_i915_gem_object *obj;
  11256. mutex_lock(&dev->struct_mutex);
  11257. intel_init_gt_powersave(dev);
  11258. mutex_unlock(&dev->struct_mutex);
  11259. intel_modeset_init_hw(dev);
  11260. intel_setup_overlay(dev);
  11261. /*
  11262. * Make sure any fbs we allocated at startup are properly
  11263. * pinned & fenced. When we do the allocation it's too early
  11264. * for this.
  11265. */
  11266. mutex_lock(&dev->struct_mutex);
  11267. for_each_crtc(dev, c) {
  11268. obj = intel_fb_obj(c->primary->fb);
  11269. if (obj == NULL)
  11270. continue;
  11271. if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
  11272. DRM_ERROR("failed to pin boot fb on pipe %d\n",
  11273. to_intel_crtc(c)->pipe);
  11274. drm_framebuffer_unreference(c->primary->fb);
  11275. c->primary->fb = NULL;
  11276. }
  11277. }
  11278. mutex_unlock(&dev->struct_mutex);
  11279. }
  11280. void intel_connector_unregister(struct intel_connector *intel_connector)
  11281. {
  11282. struct drm_connector *connector = &intel_connector->base;
  11283. intel_panel_destroy_backlight(connector);
  11284. drm_connector_unregister(connector);
  11285. }
  11286. void intel_modeset_cleanup(struct drm_device *dev)
  11287. {
  11288. struct drm_i915_private *dev_priv = dev->dev_private;
  11289. struct drm_connector *connector;
  11290. /*
  11291. * Interrupts and polling as the first thing to avoid creating havoc.
  11292. * Too much stuff here (turning of rps, connectors, ...) would
  11293. * experience fancy races otherwise.
  11294. */
  11295. drm_irq_uninstall(dev);
  11296. intel_hpd_cancel_work(dev_priv);
  11297. dev_priv->pm._irqs_disabled = true;
  11298. /*
  11299. * Due to the hpd irq storm handling the hotplug work can re-arm the
  11300. * poll handlers. Hence disable polling after hpd handling is shut down.
  11301. */
  11302. drm_kms_helper_poll_fini(dev);
  11303. mutex_lock(&dev->struct_mutex);
  11304. intel_unregister_dsm_handler();
  11305. intel_disable_fbc(dev);
  11306. intel_disable_gt_powersave(dev);
  11307. ironlake_teardown_rc6(dev);
  11308. mutex_unlock(&dev->struct_mutex);
  11309. /* flush any delayed tasks or pending work */
  11310. flush_scheduled_work();
  11311. /* destroy the backlight and sysfs files before encoders/connectors */
  11312. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  11313. struct intel_connector *intel_connector;
  11314. intel_connector = to_intel_connector(connector);
  11315. intel_connector->unregister(intel_connector);
  11316. }
  11317. drm_mode_config_cleanup(dev);
  11318. intel_cleanup_overlay(dev);
  11319. mutex_lock(&dev->struct_mutex);
  11320. intel_cleanup_gt_powersave(dev);
  11321. mutex_unlock(&dev->struct_mutex);
  11322. }
  11323. /*
  11324. * Return which encoder is currently attached for connector.
  11325. */
  11326. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  11327. {
  11328. return &intel_attached_encoder(connector)->base;
  11329. }
  11330. void intel_connector_attach_encoder(struct intel_connector *connector,
  11331. struct intel_encoder *encoder)
  11332. {
  11333. connector->encoder = encoder;
  11334. drm_mode_connector_attach_encoder(&connector->base,
  11335. &encoder->base);
  11336. }
  11337. /*
  11338. * set vga decode state - true == enable VGA decode
  11339. */
  11340. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  11341. {
  11342. struct drm_i915_private *dev_priv = dev->dev_private;
  11343. unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
  11344. u16 gmch_ctrl;
  11345. if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
  11346. DRM_ERROR("failed to read control word\n");
  11347. return -EIO;
  11348. }
  11349. if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
  11350. return 0;
  11351. if (state)
  11352. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  11353. else
  11354. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  11355. if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
  11356. DRM_ERROR("failed to write control word\n");
  11357. return -EIO;
  11358. }
  11359. return 0;
  11360. }
  11361. struct intel_display_error_state {
  11362. u32 power_well_driver;
  11363. int num_transcoders;
  11364. struct intel_cursor_error_state {
  11365. u32 control;
  11366. u32 position;
  11367. u32 base;
  11368. u32 size;
  11369. } cursor[I915_MAX_PIPES];
  11370. struct intel_pipe_error_state {
  11371. bool power_domain_on;
  11372. u32 source;
  11373. u32 stat;
  11374. } pipe[I915_MAX_PIPES];
  11375. struct intel_plane_error_state {
  11376. u32 control;
  11377. u32 stride;
  11378. u32 size;
  11379. u32 pos;
  11380. u32 addr;
  11381. u32 surface;
  11382. u32 tile_offset;
  11383. } plane[I915_MAX_PIPES];
  11384. struct intel_transcoder_error_state {
  11385. bool power_domain_on;
  11386. enum transcoder cpu_transcoder;
  11387. u32 conf;
  11388. u32 htotal;
  11389. u32 hblank;
  11390. u32 hsync;
  11391. u32 vtotal;
  11392. u32 vblank;
  11393. u32 vsync;
  11394. } transcoder[4];
  11395. };
  11396. struct intel_display_error_state *
  11397. intel_display_capture_error_state(struct drm_device *dev)
  11398. {
  11399. struct drm_i915_private *dev_priv = dev->dev_private;
  11400. struct intel_display_error_state *error;
  11401. int transcoders[] = {
  11402. TRANSCODER_A,
  11403. TRANSCODER_B,
  11404. TRANSCODER_C,
  11405. TRANSCODER_EDP,
  11406. };
  11407. int i;
  11408. if (INTEL_INFO(dev)->num_pipes == 0)
  11409. return NULL;
  11410. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  11411. if (error == NULL)
  11412. return NULL;
  11413. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11414. error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER);
  11415. for_each_pipe(dev_priv, i) {
  11416. error->pipe[i].power_domain_on =
  11417. intel_display_power_enabled_unlocked(dev_priv,
  11418. POWER_DOMAIN_PIPE(i));
  11419. if (!error->pipe[i].power_domain_on)
  11420. continue;
  11421. error->cursor[i].control = I915_READ(CURCNTR(i));
  11422. error->cursor[i].position = I915_READ(CURPOS(i));
  11423. error->cursor[i].base = I915_READ(CURBASE(i));
  11424. error->plane[i].control = I915_READ(DSPCNTR(i));
  11425. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  11426. if (INTEL_INFO(dev)->gen <= 3) {
  11427. error->plane[i].size = I915_READ(DSPSIZE(i));
  11428. error->plane[i].pos = I915_READ(DSPPOS(i));
  11429. }
  11430. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11431. error->plane[i].addr = I915_READ(DSPADDR(i));
  11432. if (INTEL_INFO(dev)->gen >= 4) {
  11433. error->plane[i].surface = I915_READ(DSPSURF(i));
  11434. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  11435. }
  11436. error->pipe[i].source = I915_READ(PIPESRC(i));
  11437. if (HAS_GMCH_DISPLAY(dev))
  11438. error->pipe[i].stat = I915_READ(PIPESTAT(i));
  11439. }
  11440. error->num_transcoders = INTEL_INFO(dev)->num_pipes;
  11441. if (HAS_DDI(dev_priv->dev))
  11442. error->num_transcoders++; /* Account for eDP. */
  11443. for (i = 0; i < error->num_transcoders; i++) {
  11444. enum transcoder cpu_transcoder = transcoders[i];
  11445. error->transcoder[i].power_domain_on =
  11446. intel_display_power_enabled_unlocked(dev_priv,
  11447. POWER_DOMAIN_TRANSCODER(cpu_transcoder));
  11448. if (!error->transcoder[i].power_domain_on)
  11449. continue;
  11450. error->transcoder[i].cpu_transcoder = cpu_transcoder;
  11451. error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  11452. error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  11453. error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  11454. error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  11455. error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  11456. error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  11457. error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  11458. }
  11459. return error;
  11460. }
  11461. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  11462. void
  11463. intel_display_print_error_state(struct drm_i915_error_state_buf *m,
  11464. struct drm_device *dev,
  11465. struct intel_display_error_state *error)
  11466. {
  11467. struct drm_i915_private *dev_priv = dev->dev_private;
  11468. int i;
  11469. if (!error)
  11470. return;
  11471. err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes);
  11472. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  11473. err_printf(m, "PWR_WELL_CTL2: %08x\n",
  11474. error->power_well_driver);
  11475. for_each_pipe(dev_priv, i) {
  11476. err_printf(m, "Pipe [%d]:\n", i);
  11477. err_printf(m, " Power: %s\n",
  11478. error->pipe[i].power_domain_on ? "on" : "off");
  11479. err_printf(m, " SRC: %08x\n", error->pipe[i].source);
  11480. err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
  11481. err_printf(m, "Plane [%d]:\n", i);
  11482. err_printf(m, " CNTR: %08x\n", error->plane[i].control);
  11483. err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  11484. if (INTEL_INFO(dev)->gen <= 3) {
  11485. err_printf(m, " SIZE: %08x\n", error->plane[i].size);
  11486. err_printf(m, " POS: %08x\n", error->plane[i].pos);
  11487. }
  11488. if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev))
  11489. err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  11490. if (INTEL_INFO(dev)->gen >= 4) {
  11491. err_printf(m, " SURF: %08x\n", error->plane[i].surface);
  11492. err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  11493. }
  11494. err_printf(m, "Cursor [%d]:\n", i);
  11495. err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  11496. err_printf(m, " POS: %08x\n", error->cursor[i].position);
  11497. err_printf(m, " BASE: %08x\n", error->cursor[i].base);
  11498. }
  11499. for (i = 0; i < error->num_transcoders; i++) {
  11500. err_printf(m, "CPU transcoder: %c\n",
  11501. transcoder_name(error->transcoder[i].cpu_transcoder));
  11502. err_printf(m, " Power: %s\n",
  11503. error->transcoder[i].power_domain_on ? "on" : "off");
  11504. err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
  11505. err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
  11506. err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
  11507. err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
  11508. err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
  11509. err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
  11510. err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
  11511. }
  11512. }
  11513. void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file)
  11514. {
  11515. struct intel_crtc *crtc;
  11516. for_each_intel_crtc(dev, crtc) {
  11517. struct intel_unpin_work *work;
  11518. unsigned long irqflags;
  11519. spin_lock_irqsave(&dev->event_lock, irqflags);
  11520. work = crtc->unpin_work;
  11521. if (work && work->event &&
  11522. work->event->base.file_priv == file) {
  11523. kfree(work->event);
  11524. work->event = NULL;
  11525. }
  11526. spin_unlock_irqrestore(&dev->event_lock, irqflags);
  11527. }
  11528. }