intel_display.c 381 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806
  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 = plane_config->base;
  2035. if (plane_config->size == 0)
  2036. return false;
  2037. obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base,
  2038. plane_config->size);
  2039. if (!obj)
  2040. return false;
  2041. if (plane_config->tiled) {
  2042. obj->tiling_mode = I915_TILING_X;
  2043. obj->stride = crtc->base.primary->fb->pitches[0];
  2044. }
  2045. mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format;
  2046. mode_cmd.width = crtc->base.primary->fb->width;
  2047. mode_cmd.height = crtc->base.primary->fb->height;
  2048. mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0];
  2049. mutex_lock(&dev->struct_mutex);
  2050. if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb),
  2051. &mode_cmd, obj)) {
  2052. DRM_DEBUG_KMS("intel fb init failed\n");
  2053. goto out_unref_obj;
  2054. }
  2055. obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe);
  2056. mutex_unlock(&dev->struct_mutex);
  2057. DRM_DEBUG_KMS("plane fb obj %p\n", obj);
  2058. return true;
  2059. out_unref_obj:
  2060. drm_gem_object_unreference(&obj->base);
  2061. mutex_unlock(&dev->struct_mutex);
  2062. return false;
  2063. }
  2064. static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
  2065. struct intel_plane_config *plane_config)
  2066. {
  2067. struct drm_device *dev = intel_crtc->base.dev;
  2068. struct drm_crtc *c;
  2069. struct intel_crtc *i;
  2070. struct drm_i915_gem_object *obj;
  2071. if (!intel_crtc->base.primary->fb)
  2072. return;
  2073. if (intel_alloc_plane_obj(intel_crtc, plane_config))
  2074. return;
  2075. kfree(intel_crtc->base.primary->fb);
  2076. intel_crtc->base.primary->fb = NULL;
  2077. /*
  2078. * Failed to alloc the obj, check to see if we should share
  2079. * an fb with another CRTC instead
  2080. */
  2081. for_each_crtc(dev, c) {
  2082. i = to_intel_crtc(c);
  2083. if (c == &intel_crtc->base)
  2084. continue;
  2085. if (!i->active)
  2086. continue;
  2087. obj = intel_fb_obj(c->primary->fb);
  2088. if (obj == NULL)
  2089. continue;
  2090. if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
  2091. drm_framebuffer_reference(c->primary->fb);
  2092. intel_crtc->base.primary->fb = c->primary->fb;
  2093. obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
  2094. break;
  2095. }
  2096. }
  2097. }
  2098. static void i9xx_update_primary_plane(struct drm_crtc *crtc,
  2099. struct drm_framebuffer *fb,
  2100. int x, int y)
  2101. {
  2102. struct drm_device *dev = crtc->dev;
  2103. struct drm_i915_private *dev_priv = dev->dev_private;
  2104. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2105. struct drm_i915_gem_object *obj;
  2106. int plane = intel_crtc->plane;
  2107. unsigned long linear_offset;
  2108. u32 dspcntr;
  2109. u32 reg = DSPCNTR(plane);
  2110. int pixel_size;
  2111. if (!intel_crtc->primary_enabled) {
  2112. I915_WRITE(reg, 0);
  2113. if (INTEL_INFO(dev)->gen >= 4)
  2114. I915_WRITE(DSPSURF(plane), 0);
  2115. else
  2116. I915_WRITE(DSPADDR(plane), 0);
  2117. POSTING_READ(reg);
  2118. return;
  2119. }
  2120. obj = intel_fb_obj(fb);
  2121. if (WARN_ON(obj == NULL))
  2122. return;
  2123. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2124. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2125. dspcntr |= DISPLAY_PLANE_ENABLE;
  2126. if (INTEL_INFO(dev)->gen < 4) {
  2127. if (intel_crtc->pipe == PIPE_B)
  2128. dspcntr |= DISPPLANE_SEL_PIPE_B;
  2129. /* pipesrc and dspsize control the size that is scaled from,
  2130. * which should always be the user's requested size.
  2131. */
  2132. I915_WRITE(DSPSIZE(plane),
  2133. ((intel_crtc->config.pipe_src_h - 1) << 16) |
  2134. (intel_crtc->config.pipe_src_w - 1));
  2135. I915_WRITE(DSPPOS(plane), 0);
  2136. }
  2137. switch (fb->pixel_format) {
  2138. case DRM_FORMAT_C8:
  2139. dspcntr |= DISPPLANE_8BPP;
  2140. break;
  2141. case DRM_FORMAT_XRGB1555:
  2142. case DRM_FORMAT_ARGB1555:
  2143. dspcntr |= DISPPLANE_BGRX555;
  2144. break;
  2145. case DRM_FORMAT_RGB565:
  2146. dspcntr |= DISPPLANE_BGRX565;
  2147. break;
  2148. case DRM_FORMAT_XRGB8888:
  2149. case DRM_FORMAT_ARGB8888:
  2150. dspcntr |= DISPPLANE_BGRX888;
  2151. break;
  2152. case DRM_FORMAT_XBGR8888:
  2153. case DRM_FORMAT_ABGR8888:
  2154. dspcntr |= DISPPLANE_RGBX888;
  2155. break;
  2156. case DRM_FORMAT_XRGB2101010:
  2157. case DRM_FORMAT_ARGB2101010:
  2158. dspcntr |= DISPPLANE_BGRX101010;
  2159. break;
  2160. case DRM_FORMAT_XBGR2101010:
  2161. case DRM_FORMAT_ABGR2101010:
  2162. dspcntr |= DISPPLANE_RGBX101010;
  2163. break;
  2164. default:
  2165. BUG();
  2166. }
  2167. if (INTEL_INFO(dev)->gen >= 4 &&
  2168. obj->tiling_mode != I915_TILING_NONE)
  2169. dspcntr |= DISPPLANE_TILED;
  2170. if (IS_G4X(dev))
  2171. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2172. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2173. if (INTEL_INFO(dev)->gen >= 4) {
  2174. intel_crtc->dspaddr_offset =
  2175. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2176. pixel_size,
  2177. fb->pitches[0]);
  2178. linear_offset -= intel_crtc->dspaddr_offset;
  2179. } else {
  2180. intel_crtc->dspaddr_offset = linear_offset;
  2181. }
  2182. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2183. dspcntr |= DISPPLANE_ROTATE_180;
  2184. x += (intel_crtc->config.pipe_src_w - 1);
  2185. y += (intel_crtc->config.pipe_src_h - 1);
  2186. /* Finding the last pixel of the last line of the display
  2187. data and adding to linear_offset*/
  2188. linear_offset +=
  2189. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2190. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2191. }
  2192. I915_WRITE(reg, dspcntr);
  2193. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2194. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2195. fb->pitches[0]);
  2196. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2197. if (INTEL_INFO(dev)->gen >= 4) {
  2198. I915_WRITE(DSPSURF(plane),
  2199. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2200. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2201. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2202. } else
  2203. I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset);
  2204. POSTING_READ(reg);
  2205. }
  2206. static void ironlake_update_primary_plane(struct drm_crtc *crtc,
  2207. struct drm_framebuffer *fb,
  2208. int x, int y)
  2209. {
  2210. struct drm_device *dev = crtc->dev;
  2211. struct drm_i915_private *dev_priv = dev->dev_private;
  2212. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2213. struct drm_i915_gem_object *obj;
  2214. int plane = intel_crtc->plane;
  2215. unsigned long linear_offset;
  2216. u32 dspcntr;
  2217. u32 reg = DSPCNTR(plane);
  2218. int pixel_size;
  2219. if (!intel_crtc->primary_enabled) {
  2220. I915_WRITE(reg, 0);
  2221. I915_WRITE(DSPSURF(plane), 0);
  2222. POSTING_READ(reg);
  2223. return;
  2224. }
  2225. obj = intel_fb_obj(fb);
  2226. if (WARN_ON(obj == NULL))
  2227. return;
  2228. pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
  2229. dspcntr = DISPPLANE_GAMMA_ENABLE;
  2230. dspcntr |= DISPLAY_PLANE_ENABLE;
  2231. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  2232. dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
  2233. switch (fb->pixel_format) {
  2234. case DRM_FORMAT_C8:
  2235. dspcntr |= DISPPLANE_8BPP;
  2236. break;
  2237. case DRM_FORMAT_RGB565:
  2238. dspcntr |= DISPPLANE_BGRX565;
  2239. break;
  2240. case DRM_FORMAT_XRGB8888:
  2241. case DRM_FORMAT_ARGB8888:
  2242. dspcntr |= DISPPLANE_BGRX888;
  2243. break;
  2244. case DRM_FORMAT_XBGR8888:
  2245. case DRM_FORMAT_ABGR8888:
  2246. dspcntr |= DISPPLANE_RGBX888;
  2247. break;
  2248. case DRM_FORMAT_XRGB2101010:
  2249. case DRM_FORMAT_ARGB2101010:
  2250. dspcntr |= DISPPLANE_BGRX101010;
  2251. break;
  2252. case DRM_FORMAT_XBGR2101010:
  2253. case DRM_FORMAT_ABGR2101010:
  2254. dspcntr |= DISPPLANE_RGBX101010;
  2255. break;
  2256. default:
  2257. BUG();
  2258. }
  2259. if (obj->tiling_mode != I915_TILING_NONE)
  2260. dspcntr |= DISPPLANE_TILED;
  2261. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev))
  2262. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  2263. linear_offset = y * fb->pitches[0] + x * pixel_size;
  2264. intel_crtc->dspaddr_offset =
  2265. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  2266. pixel_size,
  2267. fb->pitches[0]);
  2268. linear_offset -= intel_crtc->dspaddr_offset;
  2269. if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) {
  2270. dspcntr |= DISPPLANE_ROTATE_180;
  2271. if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
  2272. x += (intel_crtc->config.pipe_src_w - 1);
  2273. y += (intel_crtc->config.pipe_src_h - 1);
  2274. /* Finding the last pixel of the last line of the display
  2275. data and adding to linear_offset*/
  2276. linear_offset +=
  2277. (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] +
  2278. (intel_crtc->config.pipe_src_w - 1) * pixel_size;
  2279. }
  2280. }
  2281. I915_WRITE(reg, dspcntr);
  2282. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  2283. i915_gem_obj_ggtt_offset(obj), linear_offset, x, y,
  2284. fb->pitches[0]);
  2285. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  2286. I915_WRITE(DSPSURF(plane),
  2287. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset);
  2288. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2289. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  2290. } else {
  2291. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  2292. I915_WRITE(DSPLINOFF(plane), linear_offset);
  2293. }
  2294. POSTING_READ(reg);
  2295. }
  2296. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  2297. static int
  2298. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  2299. int x, int y, enum mode_set_atomic state)
  2300. {
  2301. struct drm_device *dev = crtc->dev;
  2302. struct drm_i915_private *dev_priv = dev->dev_private;
  2303. if (dev_priv->display.disable_fbc)
  2304. dev_priv->display.disable_fbc(dev);
  2305. intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe);
  2306. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2307. return 0;
  2308. }
  2309. void intel_display_handle_reset(struct drm_device *dev)
  2310. {
  2311. struct drm_i915_private *dev_priv = dev->dev_private;
  2312. struct drm_crtc *crtc;
  2313. /*
  2314. * Flips in the rings have been nuked by the reset,
  2315. * so complete all pending flips so that user space
  2316. * will get its events and not get stuck.
  2317. *
  2318. * Also update the base address of all primary
  2319. * planes to the the last fb to make sure we're
  2320. * showing the correct fb after a reset.
  2321. *
  2322. * Need to make two loops over the crtcs so that we
  2323. * don't try to grab a crtc mutex before the
  2324. * pending_flip_queue really got woken up.
  2325. */
  2326. for_each_crtc(dev, crtc) {
  2327. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2328. enum plane plane = intel_crtc->plane;
  2329. intel_prepare_page_flip(dev, plane);
  2330. intel_finish_page_flip_plane(dev, plane);
  2331. }
  2332. for_each_crtc(dev, crtc) {
  2333. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2334. drm_modeset_lock(&crtc->mutex, NULL);
  2335. /*
  2336. * FIXME: Once we have proper support for primary planes (and
  2337. * disabling them without disabling the entire crtc) allow again
  2338. * a NULL crtc->primary->fb.
  2339. */
  2340. if (intel_crtc->active && crtc->primary->fb)
  2341. dev_priv->display.update_primary_plane(crtc,
  2342. crtc->primary->fb,
  2343. crtc->x,
  2344. crtc->y);
  2345. drm_modeset_unlock(&crtc->mutex);
  2346. }
  2347. }
  2348. static int
  2349. intel_finish_fb(struct drm_framebuffer *old_fb)
  2350. {
  2351. struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
  2352. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  2353. bool was_interruptible = dev_priv->mm.interruptible;
  2354. int ret;
  2355. /* Big Hammer, we also need to ensure that any pending
  2356. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  2357. * current scanout is retired before unpinning the old
  2358. * framebuffer.
  2359. *
  2360. * This should only fail upon a hung GPU, in which case we
  2361. * can safely continue.
  2362. */
  2363. dev_priv->mm.interruptible = false;
  2364. ret = i915_gem_object_finish_gpu(obj);
  2365. dev_priv->mm.interruptible = was_interruptible;
  2366. return ret;
  2367. }
  2368. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2369. {
  2370. struct drm_device *dev = crtc->dev;
  2371. struct drm_i915_private *dev_priv = dev->dev_private;
  2372. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2373. unsigned long flags;
  2374. bool pending;
  2375. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2376. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2377. return false;
  2378. spin_lock_irqsave(&dev->event_lock, flags);
  2379. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2380. spin_unlock_irqrestore(&dev->event_lock, flags);
  2381. return pending;
  2382. }
  2383. static int
  2384. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2385. struct drm_framebuffer *fb)
  2386. {
  2387. struct drm_device *dev = crtc->dev;
  2388. struct drm_i915_private *dev_priv = dev->dev_private;
  2389. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2390. enum pipe pipe = intel_crtc->pipe;
  2391. struct drm_framebuffer *old_fb = crtc->primary->fb;
  2392. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  2393. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  2394. int ret;
  2395. if (intel_crtc_has_pending_flip(crtc)) {
  2396. DRM_ERROR("pipe is still busy with an old pageflip\n");
  2397. return -EBUSY;
  2398. }
  2399. /* no fb bound */
  2400. if (!fb) {
  2401. DRM_ERROR("No FB bound\n");
  2402. return 0;
  2403. }
  2404. if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) {
  2405. DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n",
  2406. plane_name(intel_crtc->plane),
  2407. INTEL_INFO(dev)->num_pipes);
  2408. return -EINVAL;
  2409. }
  2410. mutex_lock(&dev->struct_mutex);
  2411. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  2412. if (ret == 0)
  2413. i915_gem_track_fb(old_obj, obj,
  2414. INTEL_FRONTBUFFER_PRIMARY(pipe));
  2415. mutex_unlock(&dev->struct_mutex);
  2416. if (ret != 0) {
  2417. DRM_ERROR("pin & fence failed\n");
  2418. return ret;
  2419. }
  2420. /*
  2421. * Update pipe size and adjust fitter if needed: the reason for this is
  2422. * that in compute_mode_changes we check the native mode (not the pfit
  2423. * mode) to see if we can flip rather than do a full mode set. In the
  2424. * fastboot case, we'll flip, but if we don't update the pipesrc and
  2425. * pfit state, we'll end up with a big fb scanned out into the wrong
  2426. * sized surface.
  2427. *
  2428. * To fix this properly, we need to hoist the checks up into
  2429. * compute_mode_changes (or above), check the actual pfit state and
  2430. * whether the platform allows pfit disable with pipe active, and only
  2431. * then update the pipesrc and pfit state, even on the flip path.
  2432. */
  2433. if (i915.fastboot) {
  2434. const struct drm_display_mode *adjusted_mode =
  2435. &intel_crtc->config.adjusted_mode;
  2436. I915_WRITE(PIPESRC(intel_crtc->pipe),
  2437. ((adjusted_mode->crtc_hdisplay - 1) << 16) |
  2438. (adjusted_mode->crtc_vdisplay - 1));
  2439. if (!intel_crtc->config.pch_pfit.enabled &&
  2440. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2441. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2442. I915_WRITE(PF_CTL(intel_crtc->pipe), 0);
  2443. I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0);
  2444. I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0);
  2445. }
  2446. intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay;
  2447. intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay;
  2448. }
  2449. dev_priv->display.update_primary_plane(crtc, fb, x, y);
  2450. if (intel_crtc->active)
  2451. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  2452. crtc->primary->fb = fb;
  2453. crtc->x = x;
  2454. crtc->y = y;
  2455. if (old_fb) {
  2456. if (intel_crtc->active && old_fb != fb)
  2457. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2458. mutex_lock(&dev->struct_mutex);
  2459. intel_unpin_fb_obj(old_obj);
  2460. mutex_unlock(&dev->struct_mutex);
  2461. }
  2462. mutex_lock(&dev->struct_mutex);
  2463. intel_update_fbc(dev);
  2464. mutex_unlock(&dev->struct_mutex);
  2465. return 0;
  2466. }
  2467. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2468. {
  2469. struct drm_device *dev = crtc->dev;
  2470. struct drm_i915_private *dev_priv = dev->dev_private;
  2471. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2472. int pipe = intel_crtc->pipe;
  2473. u32 reg, temp;
  2474. /* enable normal train */
  2475. reg = FDI_TX_CTL(pipe);
  2476. temp = I915_READ(reg);
  2477. if (IS_IVYBRIDGE(dev)) {
  2478. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2479. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2480. } else {
  2481. temp &= ~FDI_LINK_TRAIN_NONE;
  2482. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2483. }
  2484. I915_WRITE(reg, temp);
  2485. reg = FDI_RX_CTL(pipe);
  2486. temp = I915_READ(reg);
  2487. if (HAS_PCH_CPT(dev)) {
  2488. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2489. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2490. } else {
  2491. temp &= ~FDI_LINK_TRAIN_NONE;
  2492. temp |= FDI_LINK_TRAIN_NONE;
  2493. }
  2494. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2495. /* wait one idle pattern time */
  2496. POSTING_READ(reg);
  2497. udelay(1000);
  2498. /* IVB wants error correction enabled */
  2499. if (IS_IVYBRIDGE(dev))
  2500. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2501. FDI_FE_ERRC_ENABLE);
  2502. }
  2503. static bool pipe_has_enabled_pch(struct intel_crtc *crtc)
  2504. {
  2505. return crtc->base.enabled && crtc->active &&
  2506. crtc->config.has_pch_encoder;
  2507. }
  2508. static void ivb_modeset_global_resources(struct drm_device *dev)
  2509. {
  2510. struct drm_i915_private *dev_priv = dev->dev_private;
  2511. struct intel_crtc *pipe_B_crtc =
  2512. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2513. struct intel_crtc *pipe_C_crtc =
  2514. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2515. uint32_t temp;
  2516. /*
  2517. * When everything is off disable fdi C so that we could enable fdi B
  2518. * with all lanes. Note that we don't care about enabled pipes without
  2519. * an enabled pch encoder.
  2520. */
  2521. if (!pipe_has_enabled_pch(pipe_B_crtc) &&
  2522. !pipe_has_enabled_pch(pipe_C_crtc)) {
  2523. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2524. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2525. temp = I915_READ(SOUTH_CHICKEN1);
  2526. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2527. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2528. I915_WRITE(SOUTH_CHICKEN1, temp);
  2529. }
  2530. }
  2531. /* The FDI link training functions for ILK/Ibexpeak. */
  2532. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2533. {
  2534. struct drm_device *dev = crtc->dev;
  2535. struct drm_i915_private *dev_priv = dev->dev_private;
  2536. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2537. int pipe = intel_crtc->pipe;
  2538. u32 reg, temp, tries;
  2539. /* FDI needs bits from pipe first */
  2540. assert_pipe_enabled(dev_priv, pipe);
  2541. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2542. for train result */
  2543. reg = FDI_RX_IMR(pipe);
  2544. temp = I915_READ(reg);
  2545. temp &= ~FDI_RX_SYMBOL_LOCK;
  2546. temp &= ~FDI_RX_BIT_LOCK;
  2547. I915_WRITE(reg, temp);
  2548. I915_READ(reg);
  2549. udelay(150);
  2550. /* enable CPU FDI TX and PCH FDI RX */
  2551. reg = FDI_TX_CTL(pipe);
  2552. temp = I915_READ(reg);
  2553. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2554. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2555. temp &= ~FDI_LINK_TRAIN_NONE;
  2556. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2557. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2558. reg = FDI_RX_CTL(pipe);
  2559. temp = I915_READ(reg);
  2560. temp &= ~FDI_LINK_TRAIN_NONE;
  2561. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2562. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2563. POSTING_READ(reg);
  2564. udelay(150);
  2565. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2566. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2567. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2568. FDI_RX_PHASE_SYNC_POINTER_EN);
  2569. reg = FDI_RX_IIR(pipe);
  2570. for (tries = 0; tries < 5; tries++) {
  2571. temp = I915_READ(reg);
  2572. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2573. if ((temp & FDI_RX_BIT_LOCK)) {
  2574. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2575. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2576. break;
  2577. }
  2578. }
  2579. if (tries == 5)
  2580. DRM_ERROR("FDI train 1 fail!\n");
  2581. /* Train 2 */
  2582. reg = FDI_TX_CTL(pipe);
  2583. temp = I915_READ(reg);
  2584. temp &= ~FDI_LINK_TRAIN_NONE;
  2585. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2586. I915_WRITE(reg, temp);
  2587. reg = FDI_RX_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. POSTING_READ(reg);
  2593. udelay(150);
  2594. reg = FDI_RX_IIR(pipe);
  2595. for (tries = 0; tries < 5; tries++) {
  2596. temp = I915_READ(reg);
  2597. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2598. if (temp & FDI_RX_SYMBOL_LOCK) {
  2599. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2600. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2601. break;
  2602. }
  2603. }
  2604. if (tries == 5)
  2605. DRM_ERROR("FDI train 2 fail!\n");
  2606. DRM_DEBUG_KMS("FDI train done\n");
  2607. }
  2608. static const int snb_b_fdi_train_param[] = {
  2609. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2610. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2611. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2612. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2613. };
  2614. /* The FDI link training functions for SNB/Cougarpoint. */
  2615. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2616. {
  2617. struct drm_device *dev = crtc->dev;
  2618. struct drm_i915_private *dev_priv = dev->dev_private;
  2619. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2620. int pipe = intel_crtc->pipe;
  2621. u32 reg, temp, i, retry;
  2622. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2623. for train result */
  2624. reg = FDI_RX_IMR(pipe);
  2625. temp = I915_READ(reg);
  2626. temp &= ~FDI_RX_SYMBOL_LOCK;
  2627. temp &= ~FDI_RX_BIT_LOCK;
  2628. I915_WRITE(reg, temp);
  2629. POSTING_READ(reg);
  2630. udelay(150);
  2631. /* enable CPU FDI TX and PCH FDI RX */
  2632. reg = FDI_TX_CTL(pipe);
  2633. temp = I915_READ(reg);
  2634. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2635. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2636. temp &= ~FDI_LINK_TRAIN_NONE;
  2637. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2638. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2639. /* SNB-B */
  2640. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2641. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2642. I915_WRITE(FDI_RX_MISC(pipe),
  2643. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2644. reg = FDI_RX_CTL(pipe);
  2645. temp = I915_READ(reg);
  2646. if (HAS_PCH_CPT(dev)) {
  2647. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2648. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2649. } else {
  2650. temp &= ~FDI_LINK_TRAIN_NONE;
  2651. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2652. }
  2653. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2654. POSTING_READ(reg);
  2655. udelay(150);
  2656. for (i = 0; i < 4; i++) {
  2657. reg = FDI_TX_CTL(pipe);
  2658. temp = I915_READ(reg);
  2659. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2660. temp |= snb_b_fdi_train_param[i];
  2661. I915_WRITE(reg, temp);
  2662. POSTING_READ(reg);
  2663. udelay(500);
  2664. for (retry = 0; retry < 5; retry++) {
  2665. reg = FDI_RX_IIR(pipe);
  2666. temp = I915_READ(reg);
  2667. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2668. if (temp & FDI_RX_BIT_LOCK) {
  2669. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2670. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2671. break;
  2672. }
  2673. udelay(50);
  2674. }
  2675. if (retry < 5)
  2676. break;
  2677. }
  2678. if (i == 4)
  2679. DRM_ERROR("FDI train 1 fail!\n");
  2680. /* Train 2 */
  2681. reg = FDI_TX_CTL(pipe);
  2682. temp = I915_READ(reg);
  2683. temp &= ~FDI_LINK_TRAIN_NONE;
  2684. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2685. if (IS_GEN6(dev)) {
  2686. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2687. /* SNB-B */
  2688. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2689. }
  2690. I915_WRITE(reg, temp);
  2691. reg = FDI_RX_CTL(pipe);
  2692. temp = I915_READ(reg);
  2693. if (HAS_PCH_CPT(dev)) {
  2694. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2695. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2696. } else {
  2697. temp &= ~FDI_LINK_TRAIN_NONE;
  2698. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2699. }
  2700. I915_WRITE(reg, temp);
  2701. POSTING_READ(reg);
  2702. udelay(150);
  2703. for (i = 0; i < 4; i++) {
  2704. reg = FDI_TX_CTL(pipe);
  2705. temp = I915_READ(reg);
  2706. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2707. temp |= snb_b_fdi_train_param[i];
  2708. I915_WRITE(reg, temp);
  2709. POSTING_READ(reg);
  2710. udelay(500);
  2711. for (retry = 0; retry < 5; retry++) {
  2712. reg = FDI_RX_IIR(pipe);
  2713. temp = I915_READ(reg);
  2714. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2715. if (temp & FDI_RX_SYMBOL_LOCK) {
  2716. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2717. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2718. break;
  2719. }
  2720. udelay(50);
  2721. }
  2722. if (retry < 5)
  2723. break;
  2724. }
  2725. if (i == 4)
  2726. DRM_ERROR("FDI train 2 fail!\n");
  2727. DRM_DEBUG_KMS("FDI train done.\n");
  2728. }
  2729. /* Manual link training for Ivy Bridge A0 parts */
  2730. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2731. {
  2732. struct drm_device *dev = crtc->dev;
  2733. struct drm_i915_private *dev_priv = dev->dev_private;
  2734. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2735. int pipe = intel_crtc->pipe;
  2736. u32 reg, temp, i, j;
  2737. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2738. for train result */
  2739. reg = FDI_RX_IMR(pipe);
  2740. temp = I915_READ(reg);
  2741. temp &= ~FDI_RX_SYMBOL_LOCK;
  2742. temp &= ~FDI_RX_BIT_LOCK;
  2743. I915_WRITE(reg, temp);
  2744. POSTING_READ(reg);
  2745. udelay(150);
  2746. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2747. I915_READ(FDI_RX_IIR(pipe)));
  2748. /* Try each vswing and preemphasis setting twice before moving on */
  2749. for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
  2750. /* disable first in case we need to retry */
  2751. reg = FDI_TX_CTL(pipe);
  2752. temp = I915_READ(reg);
  2753. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2754. temp &= ~FDI_TX_ENABLE;
  2755. I915_WRITE(reg, temp);
  2756. reg = FDI_RX_CTL(pipe);
  2757. temp = I915_READ(reg);
  2758. temp &= ~FDI_LINK_TRAIN_AUTO;
  2759. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2760. temp &= ~FDI_RX_ENABLE;
  2761. I915_WRITE(reg, temp);
  2762. /* enable CPU FDI TX and PCH FDI RX */
  2763. reg = FDI_TX_CTL(pipe);
  2764. temp = I915_READ(reg);
  2765. temp &= ~FDI_DP_PORT_WIDTH_MASK;
  2766. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2767. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2768. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2769. temp |= snb_b_fdi_train_param[j/2];
  2770. temp |= FDI_COMPOSITE_SYNC;
  2771. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2772. I915_WRITE(FDI_RX_MISC(pipe),
  2773. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2774. reg = FDI_RX_CTL(pipe);
  2775. temp = I915_READ(reg);
  2776. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2777. temp |= FDI_COMPOSITE_SYNC;
  2778. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2779. POSTING_READ(reg);
  2780. udelay(1); /* should be 0.5us */
  2781. for (i = 0; i < 4; i++) {
  2782. reg = FDI_RX_IIR(pipe);
  2783. temp = I915_READ(reg);
  2784. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2785. if (temp & FDI_RX_BIT_LOCK ||
  2786. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2787. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2788. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
  2789. i);
  2790. break;
  2791. }
  2792. udelay(1); /* should be 0.5us */
  2793. }
  2794. if (i == 4) {
  2795. DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
  2796. continue;
  2797. }
  2798. /* Train 2 */
  2799. reg = FDI_TX_CTL(pipe);
  2800. temp = I915_READ(reg);
  2801. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2802. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2803. I915_WRITE(reg, temp);
  2804. reg = FDI_RX_CTL(pipe);
  2805. temp = I915_READ(reg);
  2806. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2807. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2808. I915_WRITE(reg, temp);
  2809. POSTING_READ(reg);
  2810. udelay(2); /* should be 1.5us */
  2811. for (i = 0; i < 4; i++) {
  2812. reg = FDI_RX_IIR(pipe);
  2813. temp = I915_READ(reg);
  2814. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2815. if (temp & FDI_RX_SYMBOL_LOCK ||
  2816. (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
  2817. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2818. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
  2819. i);
  2820. goto train_done;
  2821. }
  2822. udelay(2); /* should be 1.5us */
  2823. }
  2824. if (i == 4)
  2825. DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
  2826. }
  2827. train_done:
  2828. DRM_DEBUG_KMS("FDI train done.\n");
  2829. }
  2830. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2831. {
  2832. struct drm_device *dev = intel_crtc->base.dev;
  2833. struct drm_i915_private *dev_priv = dev->dev_private;
  2834. int pipe = intel_crtc->pipe;
  2835. u32 reg, temp;
  2836. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2837. reg = FDI_RX_CTL(pipe);
  2838. temp = I915_READ(reg);
  2839. temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
  2840. temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  2841. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2842. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2843. POSTING_READ(reg);
  2844. udelay(200);
  2845. /* Switch from Rawclk to PCDclk */
  2846. temp = I915_READ(reg);
  2847. I915_WRITE(reg, temp | FDI_PCDCLK);
  2848. POSTING_READ(reg);
  2849. udelay(200);
  2850. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2851. reg = FDI_TX_CTL(pipe);
  2852. temp = I915_READ(reg);
  2853. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2854. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2855. POSTING_READ(reg);
  2856. udelay(100);
  2857. }
  2858. }
  2859. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2860. {
  2861. struct drm_device *dev = intel_crtc->base.dev;
  2862. struct drm_i915_private *dev_priv = dev->dev_private;
  2863. int pipe = intel_crtc->pipe;
  2864. u32 reg, temp;
  2865. /* Switch from PCDclk to Rawclk */
  2866. reg = FDI_RX_CTL(pipe);
  2867. temp = I915_READ(reg);
  2868. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2869. /* Disable CPU FDI TX PLL */
  2870. reg = FDI_TX_CTL(pipe);
  2871. temp = I915_READ(reg);
  2872. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2873. POSTING_READ(reg);
  2874. udelay(100);
  2875. reg = FDI_RX_CTL(pipe);
  2876. temp = I915_READ(reg);
  2877. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2878. /* Wait for the clocks to turn off. */
  2879. POSTING_READ(reg);
  2880. udelay(100);
  2881. }
  2882. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2883. {
  2884. struct drm_device *dev = crtc->dev;
  2885. struct drm_i915_private *dev_priv = dev->dev_private;
  2886. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2887. int pipe = intel_crtc->pipe;
  2888. u32 reg, temp;
  2889. /* disable CPU FDI tx and PCH FDI rx */
  2890. reg = FDI_TX_CTL(pipe);
  2891. temp = I915_READ(reg);
  2892. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2893. POSTING_READ(reg);
  2894. reg = FDI_RX_CTL(pipe);
  2895. temp = I915_READ(reg);
  2896. temp &= ~(0x7 << 16);
  2897. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2898. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2899. POSTING_READ(reg);
  2900. udelay(100);
  2901. /* Ironlake workaround, disable clock pointer after downing FDI */
  2902. if (HAS_PCH_IBX(dev))
  2903. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2904. /* still set train pattern 1 */
  2905. reg = FDI_TX_CTL(pipe);
  2906. temp = I915_READ(reg);
  2907. temp &= ~FDI_LINK_TRAIN_NONE;
  2908. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2909. I915_WRITE(reg, temp);
  2910. reg = FDI_RX_CTL(pipe);
  2911. temp = I915_READ(reg);
  2912. if (HAS_PCH_CPT(dev)) {
  2913. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2914. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2915. } else {
  2916. temp &= ~FDI_LINK_TRAIN_NONE;
  2917. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2918. }
  2919. /* BPC in FDI rx is consistent with that in PIPECONF */
  2920. temp &= ~(0x07 << 16);
  2921. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2922. I915_WRITE(reg, temp);
  2923. POSTING_READ(reg);
  2924. udelay(100);
  2925. }
  2926. bool intel_has_pending_fb_unpin(struct drm_device *dev)
  2927. {
  2928. struct intel_crtc *crtc;
  2929. /* Note that we don't need to be called with mode_config.lock here
  2930. * as our list of CRTC objects is static for the lifetime of the
  2931. * device and so cannot disappear as we iterate. Similarly, we can
  2932. * happily treat the predicates as racy, atomic checks as userspace
  2933. * cannot claim and pin a new fb without at least acquring the
  2934. * struct_mutex and so serialising with us.
  2935. */
  2936. for_each_intel_crtc(dev, crtc) {
  2937. if (atomic_read(&crtc->unpin_work_count) == 0)
  2938. continue;
  2939. if (crtc->unpin_work)
  2940. intel_wait_for_vblank(dev, crtc->pipe);
  2941. return true;
  2942. }
  2943. return false;
  2944. }
  2945. static void page_flip_completed(struct intel_crtc *intel_crtc)
  2946. {
  2947. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  2948. struct intel_unpin_work *work = intel_crtc->unpin_work;
  2949. /* ensure that the unpin work is consistent wrt ->pending. */
  2950. smp_rmb();
  2951. intel_crtc->unpin_work = NULL;
  2952. if (work->event)
  2953. drm_send_vblank_event(intel_crtc->base.dev,
  2954. intel_crtc->pipe,
  2955. work->event);
  2956. drm_crtc_vblank_put(&intel_crtc->base);
  2957. wake_up_all(&dev_priv->pending_flip_queue);
  2958. queue_work(dev_priv->wq, &work->work);
  2959. trace_i915_flip_complete(intel_crtc->plane,
  2960. work->pending_flip_obj);
  2961. }
  2962. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2963. {
  2964. struct drm_device *dev = crtc->dev;
  2965. struct drm_i915_private *dev_priv = dev->dev_private;
  2966. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2967. if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue,
  2968. !intel_crtc_has_pending_flip(crtc),
  2969. 60*HZ) == 0)) {
  2970. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2971. unsigned long flags;
  2972. spin_lock_irqsave(&dev->event_lock, flags);
  2973. if (intel_crtc->unpin_work) {
  2974. WARN_ONCE(1, "Removing stuck page flip\n");
  2975. page_flip_completed(intel_crtc);
  2976. }
  2977. spin_unlock_irqrestore(&dev->event_lock, flags);
  2978. }
  2979. if (crtc->primary->fb) {
  2980. mutex_lock(&dev->struct_mutex);
  2981. intel_finish_fb(crtc->primary->fb);
  2982. mutex_unlock(&dev->struct_mutex);
  2983. }
  2984. }
  2985. /* Program iCLKIP clock to the desired frequency */
  2986. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2987. {
  2988. struct drm_device *dev = crtc->dev;
  2989. struct drm_i915_private *dev_priv = dev->dev_private;
  2990. int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock;
  2991. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2992. u32 temp;
  2993. mutex_lock(&dev_priv->dpio_lock);
  2994. /* It is necessary to ungate the pixclk gate prior to programming
  2995. * the divisors, and gate it back when it is done.
  2996. */
  2997. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2998. /* Disable SSCCTL */
  2999. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  3000. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  3001. SBI_SSCCTL_DISABLE,
  3002. SBI_ICLK);
  3003. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  3004. if (clock == 20000) {
  3005. auxdiv = 1;
  3006. divsel = 0x41;
  3007. phaseinc = 0x20;
  3008. } else {
  3009. /* The iCLK virtual clock root frequency is in MHz,
  3010. * but the adjusted_mode->crtc_clock in in KHz. To get the
  3011. * divisors, it is necessary to divide one by another, so we
  3012. * convert the virtual clock precision to KHz here for higher
  3013. * precision.
  3014. */
  3015. u32 iclk_virtual_root_freq = 172800 * 1000;
  3016. u32 iclk_pi_range = 64;
  3017. u32 desired_divisor, msb_divisor_value, pi_value;
  3018. desired_divisor = (iclk_virtual_root_freq / clock);
  3019. msb_divisor_value = desired_divisor / iclk_pi_range;
  3020. pi_value = desired_divisor % iclk_pi_range;
  3021. auxdiv = 0;
  3022. divsel = msb_divisor_value - 2;
  3023. phaseinc = pi_value;
  3024. }
  3025. /* This should not happen with any sane values */
  3026. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  3027. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  3028. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  3029. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  3030. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  3031. clock,
  3032. auxdiv,
  3033. divsel,
  3034. phasedir,
  3035. phaseinc);
  3036. /* Program SSCDIVINTPHASE6 */
  3037. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  3038. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  3039. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  3040. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  3041. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  3042. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  3043. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  3044. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  3045. /* Program SSCAUXDIV */
  3046. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  3047. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  3048. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  3049. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  3050. /* Enable modulator and associated divider */
  3051. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  3052. temp &= ~SBI_SSCCTL_DISABLE;
  3053. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  3054. /* Wait for initialization time */
  3055. udelay(24);
  3056. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  3057. mutex_unlock(&dev_priv->dpio_lock);
  3058. }
  3059. static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc,
  3060. enum pipe pch_transcoder)
  3061. {
  3062. struct drm_device *dev = crtc->base.dev;
  3063. struct drm_i915_private *dev_priv = dev->dev_private;
  3064. enum transcoder cpu_transcoder = crtc->config.cpu_transcoder;
  3065. I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
  3066. I915_READ(HTOTAL(cpu_transcoder)));
  3067. I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
  3068. I915_READ(HBLANK(cpu_transcoder)));
  3069. I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
  3070. I915_READ(HSYNC(cpu_transcoder)));
  3071. I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
  3072. I915_READ(VTOTAL(cpu_transcoder)));
  3073. I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
  3074. I915_READ(VBLANK(cpu_transcoder)));
  3075. I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
  3076. I915_READ(VSYNC(cpu_transcoder)));
  3077. I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
  3078. I915_READ(VSYNCSHIFT(cpu_transcoder)));
  3079. }
  3080. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  3081. {
  3082. struct drm_i915_private *dev_priv = dev->dev_private;
  3083. uint32_t temp;
  3084. temp = I915_READ(SOUTH_CHICKEN1);
  3085. if (temp & FDI_BC_BIFURCATION_SELECT)
  3086. return;
  3087. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  3088. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  3089. temp |= FDI_BC_BIFURCATION_SELECT;
  3090. DRM_DEBUG_KMS("enabling fdi C rx\n");
  3091. I915_WRITE(SOUTH_CHICKEN1, temp);
  3092. POSTING_READ(SOUTH_CHICKEN1);
  3093. }
  3094. static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc)
  3095. {
  3096. struct drm_device *dev = intel_crtc->base.dev;
  3097. struct drm_i915_private *dev_priv = dev->dev_private;
  3098. switch (intel_crtc->pipe) {
  3099. case PIPE_A:
  3100. break;
  3101. case PIPE_B:
  3102. if (intel_crtc->config.fdi_lanes > 2)
  3103. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  3104. else
  3105. cpt_enable_fdi_bc_bifurcation(dev);
  3106. break;
  3107. case PIPE_C:
  3108. cpt_enable_fdi_bc_bifurcation(dev);
  3109. break;
  3110. default:
  3111. BUG();
  3112. }
  3113. }
  3114. /*
  3115. * Enable PCH resources required for PCH ports:
  3116. * - PCH PLLs
  3117. * - FDI training & RX/TX
  3118. * - update transcoder timings
  3119. * - DP transcoding bits
  3120. * - transcoder
  3121. */
  3122. static void ironlake_pch_enable(struct drm_crtc *crtc)
  3123. {
  3124. struct drm_device *dev = crtc->dev;
  3125. struct drm_i915_private *dev_priv = dev->dev_private;
  3126. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3127. int pipe = intel_crtc->pipe;
  3128. u32 reg, temp;
  3129. assert_pch_transcoder_disabled(dev_priv, pipe);
  3130. if (IS_IVYBRIDGE(dev))
  3131. ivybridge_update_fdi_bc_bifurcation(intel_crtc);
  3132. /* Write the TU size bits before fdi link training, so that error
  3133. * detection works. */
  3134. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  3135. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  3136. /* For PCH output, training FDI link */
  3137. dev_priv->display.fdi_link_train(crtc);
  3138. /* We need to program the right clock selection before writing the pixel
  3139. * mutliplier into the DPLL. */
  3140. if (HAS_PCH_CPT(dev)) {
  3141. u32 sel;
  3142. temp = I915_READ(PCH_DPLL_SEL);
  3143. temp |= TRANS_DPLL_ENABLE(pipe);
  3144. sel = TRANS_DPLLB_SEL(pipe);
  3145. if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B)
  3146. temp |= sel;
  3147. else
  3148. temp &= ~sel;
  3149. I915_WRITE(PCH_DPLL_SEL, temp);
  3150. }
  3151. /* XXX: pch pll's can be enabled any time before we enable the PCH
  3152. * transcoder, and we actually should do this to not upset any PCH
  3153. * transcoder that already use the clock when we share it.
  3154. *
  3155. * Note that enable_shared_dpll tries to do the right thing, but
  3156. * get_shared_dpll unconditionally resets the pll - we need that to have
  3157. * the right LVDS enable sequence. */
  3158. intel_enable_shared_dpll(intel_crtc);
  3159. /* set transcoder timing, panel must allow it */
  3160. assert_panel_unlocked(dev_priv, pipe);
  3161. ironlake_pch_transcoder_set_timings(intel_crtc, pipe);
  3162. intel_fdi_normal_train(crtc);
  3163. /* For PCH DP, enable TRANS_DP_CTL */
  3164. if (HAS_PCH_CPT(dev) &&
  3165. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  3166. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  3167. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  3168. reg = TRANS_DP_CTL(pipe);
  3169. temp = I915_READ(reg);
  3170. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  3171. TRANS_DP_SYNC_MASK |
  3172. TRANS_DP_BPC_MASK);
  3173. temp |= (TRANS_DP_OUTPUT_ENABLE |
  3174. TRANS_DP_ENH_FRAMING);
  3175. temp |= bpc << 9; /* same format but at 11:9 */
  3176. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  3177. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  3178. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  3179. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  3180. switch (intel_trans_dp_port_sel(crtc)) {
  3181. case PCH_DP_B:
  3182. temp |= TRANS_DP_PORT_SEL_B;
  3183. break;
  3184. case PCH_DP_C:
  3185. temp |= TRANS_DP_PORT_SEL_C;
  3186. break;
  3187. case PCH_DP_D:
  3188. temp |= TRANS_DP_PORT_SEL_D;
  3189. break;
  3190. default:
  3191. BUG();
  3192. }
  3193. I915_WRITE(reg, temp);
  3194. }
  3195. ironlake_enable_pch_transcoder(dev_priv, pipe);
  3196. }
  3197. static void lpt_pch_enable(struct drm_crtc *crtc)
  3198. {
  3199. struct drm_device *dev = crtc->dev;
  3200. struct drm_i915_private *dev_priv = dev->dev_private;
  3201. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3202. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3203. assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A);
  3204. lpt_program_iclkip(crtc);
  3205. /* Set transcoder timing. */
  3206. ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A);
  3207. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  3208. }
  3209. void intel_put_shared_dpll(struct intel_crtc *crtc)
  3210. {
  3211. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3212. if (pll == NULL)
  3213. return;
  3214. if (pll->refcount == 0) {
  3215. WARN(1, "bad %s refcount\n", pll->name);
  3216. return;
  3217. }
  3218. if (--pll->refcount == 0) {
  3219. WARN_ON(pll->on);
  3220. WARN_ON(pll->active);
  3221. }
  3222. crtc->config.shared_dpll = DPLL_ID_PRIVATE;
  3223. }
  3224. struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc)
  3225. {
  3226. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  3227. struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc);
  3228. enum intel_dpll_id i;
  3229. if (pll) {
  3230. DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n",
  3231. crtc->base.base.id, pll->name);
  3232. intel_put_shared_dpll(crtc);
  3233. }
  3234. if (HAS_PCH_IBX(dev_priv->dev)) {
  3235. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  3236. i = (enum intel_dpll_id) crtc->pipe;
  3237. pll = &dev_priv->shared_dplls[i];
  3238. DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n",
  3239. crtc->base.base.id, pll->name);
  3240. WARN_ON(pll->refcount);
  3241. goto found;
  3242. }
  3243. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3244. pll = &dev_priv->shared_dplls[i];
  3245. /* Only want to check enabled timings first */
  3246. if (pll->refcount == 0)
  3247. continue;
  3248. if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state,
  3249. sizeof(pll->hw_state)) == 0) {
  3250. DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n",
  3251. crtc->base.base.id,
  3252. pll->name, pll->refcount, pll->active);
  3253. goto found;
  3254. }
  3255. }
  3256. /* Ok no matching timings, maybe there's a free one? */
  3257. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  3258. pll = &dev_priv->shared_dplls[i];
  3259. if (pll->refcount == 0) {
  3260. DRM_DEBUG_KMS("CRTC:%d allocated %s\n",
  3261. crtc->base.base.id, pll->name);
  3262. goto found;
  3263. }
  3264. }
  3265. return NULL;
  3266. found:
  3267. if (pll->refcount == 0)
  3268. pll->hw_state = crtc->config.dpll_hw_state;
  3269. crtc->config.shared_dpll = i;
  3270. DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name,
  3271. pipe_name(crtc->pipe));
  3272. pll->refcount++;
  3273. return pll;
  3274. }
  3275. static void cpt_verify_modeset(struct drm_device *dev, int pipe)
  3276. {
  3277. struct drm_i915_private *dev_priv = dev->dev_private;
  3278. int dslreg = PIPEDSL(pipe);
  3279. u32 temp;
  3280. temp = I915_READ(dslreg);
  3281. udelay(500);
  3282. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  3283. if (wait_for(I915_READ(dslreg) != temp, 5))
  3284. DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
  3285. }
  3286. }
  3287. static void ironlake_pfit_enable(struct intel_crtc *crtc)
  3288. {
  3289. struct drm_device *dev = crtc->base.dev;
  3290. struct drm_i915_private *dev_priv = dev->dev_private;
  3291. int pipe = crtc->pipe;
  3292. if (crtc->config.pch_pfit.enabled) {
  3293. /* Force use of hard-coded filter coefficients
  3294. * as some pre-programmed values are broken,
  3295. * e.g. x201.
  3296. */
  3297. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev))
  3298. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  3299. PF_PIPE_SEL_IVB(pipe));
  3300. else
  3301. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  3302. I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos);
  3303. I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size);
  3304. }
  3305. }
  3306. static void intel_enable_planes(struct drm_crtc *crtc)
  3307. {
  3308. struct drm_device *dev = crtc->dev;
  3309. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3310. struct drm_plane *plane;
  3311. struct intel_plane *intel_plane;
  3312. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3313. intel_plane = to_intel_plane(plane);
  3314. if (intel_plane->pipe == pipe)
  3315. intel_plane_restore(&intel_plane->base);
  3316. }
  3317. }
  3318. static void intel_disable_planes(struct drm_crtc *crtc)
  3319. {
  3320. struct drm_device *dev = crtc->dev;
  3321. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  3322. struct drm_plane *plane;
  3323. struct intel_plane *intel_plane;
  3324. drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) {
  3325. intel_plane = to_intel_plane(plane);
  3326. if (intel_plane->pipe == pipe)
  3327. intel_plane_disable(&intel_plane->base);
  3328. }
  3329. }
  3330. void hsw_enable_ips(struct intel_crtc *crtc)
  3331. {
  3332. struct drm_device *dev = crtc->base.dev;
  3333. struct drm_i915_private *dev_priv = dev->dev_private;
  3334. if (!crtc->config.ips_enabled)
  3335. return;
  3336. /* We can only enable IPS after we enable a plane and wait for a vblank */
  3337. intel_wait_for_vblank(dev, crtc->pipe);
  3338. assert_plane_enabled(dev_priv, crtc->plane);
  3339. if (IS_BROADWELL(dev)) {
  3340. mutex_lock(&dev_priv->rps.hw_lock);
  3341. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000));
  3342. mutex_unlock(&dev_priv->rps.hw_lock);
  3343. /* Quoting Art Runyan: "its not safe to expect any particular
  3344. * value in IPS_CTL bit 31 after enabling IPS through the
  3345. * mailbox." Moreover, the mailbox may return a bogus state,
  3346. * so we need to just enable it and continue on.
  3347. */
  3348. } else {
  3349. I915_WRITE(IPS_CTL, IPS_ENABLE);
  3350. /* The bit only becomes 1 in the next vblank, so this wait here
  3351. * is essentially intel_wait_for_vblank. If we don't have this
  3352. * and don't wait for vblanks until the end of crtc_enable, then
  3353. * the HW state readout code will complain that the expected
  3354. * IPS_CTL value is not the one we read. */
  3355. if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50))
  3356. DRM_ERROR("Timed out waiting for IPS enable\n");
  3357. }
  3358. }
  3359. void hsw_disable_ips(struct intel_crtc *crtc)
  3360. {
  3361. struct drm_device *dev = crtc->base.dev;
  3362. struct drm_i915_private *dev_priv = dev->dev_private;
  3363. if (!crtc->config.ips_enabled)
  3364. return;
  3365. assert_plane_enabled(dev_priv, crtc->plane);
  3366. if (IS_BROADWELL(dev)) {
  3367. mutex_lock(&dev_priv->rps.hw_lock);
  3368. WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
  3369. mutex_unlock(&dev_priv->rps.hw_lock);
  3370. /* wait for pcode to finish disabling IPS, which may take up to 42ms */
  3371. if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42))
  3372. DRM_ERROR("Timed out waiting for IPS disable\n");
  3373. } else {
  3374. I915_WRITE(IPS_CTL, 0);
  3375. POSTING_READ(IPS_CTL);
  3376. }
  3377. /* We need to wait for a vblank before we can disable the plane. */
  3378. intel_wait_for_vblank(dev, crtc->pipe);
  3379. }
  3380. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  3381. static void intel_crtc_load_lut(struct drm_crtc *crtc)
  3382. {
  3383. struct drm_device *dev = crtc->dev;
  3384. struct drm_i915_private *dev_priv = dev->dev_private;
  3385. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3386. enum pipe pipe = intel_crtc->pipe;
  3387. int palreg = PALETTE(pipe);
  3388. int i;
  3389. bool reenable_ips = false;
  3390. /* The clocks have to be on to load the palette. */
  3391. if (!crtc->enabled || !intel_crtc->active)
  3392. return;
  3393. if (!HAS_PCH_SPLIT(dev_priv->dev)) {
  3394. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI))
  3395. assert_dsi_pll_enabled(dev_priv);
  3396. else
  3397. assert_pll_enabled(dev_priv, pipe);
  3398. }
  3399. /* use legacy palette for Ironlake */
  3400. if (!HAS_GMCH_DISPLAY(dev))
  3401. palreg = LGC_PALETTE(pipe);
  3402. /* Workaround : Do not read or write the pipe palette/gamma data while
  3403. * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
  3404. */
  3405. if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled &&
  3406. ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) ==
  3407. GAMMA_MODE_MODE_SPLIT)) {
  3408. hsw_disable_ips(intel_crtc);
  3409. reenable_ips = true;
  3410. }
  3411. for (i = 0; i < 256; i++) {
  3412. I915_WRITE(palreg + 4 * i,
  3413. (intel_crtc->lut_r[i] << 16) |
  3414. (intel_crtc->lut_g[i] << 8) |
  3415. intel_crtc->lut_b[i]);
  3416. }
  3417. if (reenable_ips)
  3418. hsw_enable_ips(intel_crtc);
  3419. }
  3420. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3421. {
  3422. if (!enable && intel_crtc->overlay) {
  3423. struct drm_device *dev = intel_crtc->base.dev;
  3424. struct drm_i915_private *dev_priv = dev->dev_private;
  3425. mutex_lock(&dev->struct_mutex);
  3426. dev_priv->mm.interruptible = false;
  3427. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3428. dev_priv->mm.interruptible = true;
  3429. mutex_unlock(&dev->struct_mutex);
  3430. }
  3431. /* Let userspace switch the overlay on again. In most cases userspace
  3432. * has to recompute where to put it anyway.
  3433. */
  3434. }
  3435. static void intel_crtc_enable_planes(struct drm_crtc *crtc)
  3436. {
  3437. struct drm_device *dev = crtc->dev;
  3438. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3439. int pipe = intel_crtc->pipe;
  3440. assert_vblank_disabled(crtc);
  3441. drm_vblank_on(dev, pipe);
  3442. intel_enable_primary_hw_plane(crtc->primary, crtc);
  3443. intel_enable_planes(crtc);
  3444. intel_crtc_update_cursor(crtc, true);
  3445. intel_crtc_dpms_overlay(intel_crtc, true);
  3446. hsw_enable_ips(intel_crtc);
  3447. mutex_lock(&dev->struct_mutex);
  3448. intel_update_fbc(dev);
  3449. mutex_unlock(&dev->struct_mutex);
  3450. /*
  3451. * FIXME: Once we grow proper nuclear flip support out of this we need
  3452. * to compute the mask of flip planes precisely. For the time being
  3453. * consider this a flip from a NULL plane.
  3454. */
  3455. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3456. }
  3457. static void intel_crtc_disable_planes(struct drm_crtc *crtc)
  3458. {
  3459. struct drm_device *dev = crtc->dev;
  3460. struct drm_i915_private *dev_priv = dev->dev_private;
  3461. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3462. int pipe = intel_crtc->pipe;
  3463. int plane = intel_crtc->plane;
  3464. intel_crtc_wait_for_pending_flips(crtc);
  3465. if (dev_priv->fbc.plane == plane)
  3466. intel_disable_fbc(dev);
  3467. hsw_disable_ips(intel_crtc);
  3468. intel_crtc_dpms_overlay(intel_crtc, false);
  3469. intel_crtc_update_cursor(crtc, false);
  3470. intel_disable_planes(crtc);
  3471. intel_disable_primary_hw_plane(crtc->primary, crtc);
  3472. /*
  3473. * FIXME: Once we grow proper nuclear flip support out of this we need
  3474. * to compute the mask of flip planes precisely. For the time being
  3475. * consider this a flip to a NULL plane.
  3476. */
  3477. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe));
  3478. drm_vblank_off(dev, pipe);
  3479. assert_vblank_disabled(crtc);
  3480. }
  3481. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  3482. {
  3483. struct drm_device *dev = crtc->dev;
  3484. struct drm_i915_private *dev_priv = dev->dev_private;
  3485. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3486. struct intel_encoder *encoder;
  3487. int pipe = intel_crtc->pipe;
  3488. WARN_ON(!crtc->enabled);
  3489. if (intel_crtc->active)
  3490. return;
  3491. if (intel_crtc->config.has_pch_encoder)
  3492. intel_prepare_shared_dpll(intel_crtc);
  3493. if (intel_crtc->config.has_dp_encoder)
  3494. intel_dp_set_m_n(intel_crtc);
  3495. intel_set_pipe_timings(intel_crtc);
  3496. if (intel_crtc->config.has_pch_encoder) {
  3497. intel_cpu_transcoder_set_m_n(intel_crtc,
  3498. &intel_crtc->config.fdi_m_n, NULL);
  3499. }
  3500. ironlake_set_pipeconf(crtc);
  3501. intel_crtc->active = true;
  3502. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3503. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3504. for_each_encoder_on_crtc(dev, crtc, encoder)
  3505. if (encoder->pre_enable)
  3506. encoder->pre_enable(encoder);
  3507. if (intel_crtc->config.has_pch_encoder) {
  3508. /* Note: FDI PLL enabling _must_ be done before we enable the
  3509. * cpu pipes, hence this is separate from all the other fdi/pch
  3510. * enabling. */
  3511. ironlake_fdi_pll_enable(intel_crtc);
  3512. } else {
  3513. assert_fdi_tx_disabled(dev_priv, pipe);
  3514. assert_fdi_rx_disabled(dev_priv, pipe);
  3515. }
  3516. ironlake_pfit_enable(intel_crtc);
  3517. /*
  3518. * On ILK+ LUT must be loaded before the pipe is running but with
  3519. * clocks enabled
  3520. */
  3521. intel_crtc_load_lut(crtc);
  3522. intel_update_watermarks(crtc);
  3523. intel_enable_pipe(intel_crtc);
  3524. if (intel_crtc->config.has_pch_encoder)
  3525. ironlake_pch_enable(crtc);
  3526. for_each_encoder_on_crtc(dev, crtc, encoder)
  3527. encoder->enable(encoder);
  3528. if (HAS_PCH_CPT(dev))
  3529. cpt_verify_modeset(dev, intel_crtc->pipe);
  3530. intel_crtc_enable_planes(crtc);
  3531. }
  3532. /* IPS only exists on ULT machines and is tied to pipe A. */
  3533. static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
  3534. {
  3535. return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A;
  3536. }
  3537. /*
  3538. * This implements the workaround described in the "notes" section of the mode
  3539. * set sequence documentation. When going from no pipes or single pipe to
  3540. * multiple pipes, and planes are enabled after the pipe, we need to wait at
  3541. * least 2 vblanks on the first pipe before enabling planes on the second pipe.
  3542. */
  3543. static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc)
  3544. {
  3545. struct drm_device *dev = crtc->base.dev;
  3546. struct intel_crtc *crtc_it, *other_active_crtc = NULL;
  3547. /* We want to get the other_active_crtc only if there's only 1 other
  3548. * active crtc. */
  3549. for_each_intel_crtc(dev, crtc_it) {
  3550. if (!crtc_it->active || crtc_it == crtc)
  3551. continue;
  3552. if (other_active_crtc)
  3553. return;
  3554. other_active_crtc = crtc_it;
  3555. }
  3556. if (!other_active_crtc)
  3557. return;
  3558. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3559. intel_wait_for_vblank(dev, other_active_crtc->pipe);
  3560. }
  3561. static void haswell_crtc_enable(struct drm_crtc *crtc)
  3562. {
  3563. struct drm_device *dev = crtc->dev;
  3564. struct drm_i915_private *dev_priv = dev->dev_private;
  3565. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3566. struct intel_encoder *encoder;
  3567. int pipe = intel_crtc->pipe;
  3568. WARN_ON(!crtc->enabled);
  3569. if (intel_crtc->active)
  3570. return;
  3571. if (intel_crtc_to_shared_dpll(intel_crtc))
  3572. intel_enable_shared_dpll(intel_crtc);
  3573. if (intel_crtc->config.has_dp_encoder)
  3574. intel_dp_set_m_n(intel_crtc);
  3575. intel_set_pipe_timings(intel_crtc);
  3576. if (intel_crtc->config.cpu_transcoder != TRANSCODER_EDP) {
  3577. I915_WRITE(PIPE_MULT(intel_crtc->config.cpu_transcoder),
  3578. intel_crtc->config.pixel_multiplier - 1);
  3579. }
  3580. if (intel_crtc->config.has_pch_encoder) {
  3581. intel_cpu_transcoder_set_m_n(intel_crtc,
  3582. &intel_crtc->config.fdi_m_n, NULL);
  3583. }
  3584. haswell_set_pipeconf(crtc);
  3585. intel_set_pipe_csc(crtc);
  3586. intel_crtc->active = true;
  3587. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  3588. for_each_encoder_on_crtc(dev, crtc, encoder)
  3589. if (encoder->pre_enable)
  3590. encoder->pre_enable(encoder);
  3591. if (intel_crtc->config.has_pch_encoder) {
  3592. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3593. dev_priv->display.fdi_link_train(crtc);
  3594. }
  3595. intel_ddi_enable_pipe_clock(intel_crtc);
  3596. ironlake_pfit_enable(intel_crtc);
  3597. /*
  3598. * On ILK+ LUT must be loaded before the pipe is running but with
  3599. * clocks enabled
  3600. */
  3601. intel_crtc_load_lut(crtc);
  3602. intel_ddi_set_pipe_settings(crtc);
  3603. intel_ddi_enable_transcoder_func(crtc);
  3604. intel_update_watermarks(crtc);
  3605. intel_enable_pipe(intel_crtc);
  3606. if (intel_crtc->config.has_pch_encoder)
  3607. lpt_pch_enable(crtc);
  3608. if (intel_crtc->config.dp_encoder_is_mst)
  3609. intel_ddi_set_vc_payload_alloc(crtc, true);
  3610. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3611. encoder->enable(encoder);
  3612. intel_opregion_notify_encoder(encoder, true);
  3613. }
  3614. /* If we change the relative order between pipe/planes enabling, we need
  3615. * to change the workaround. */
  3616. haswell_mode_set_planes_workaround(intel_crtc);
  3617. intel_crtc_enable_planes(crtc);
  3618. }
  3619. static void ironlake_pfit_disable(struct intel_crtc *crtc)
  3620. {
  3621. struct drm_device *dev = crtc->base.dev;
  3622. struct drm_i915_private *dev_priv = dev->dev_private;
  3623. int pipe = crtc->pipe;
  3624. /* To avoid upsetting the power well on haswell only disable the pfit if
  3625. * it's in use. The hw state code will make sure we get this right. */
  3626. if (crtc->config.pch_pfit.enabled) {
  3627. I915_WRITE(PF_CTL(pipe), 0);
  3628. I915_WRITE(PF_WIN_POS(pipe), 0);
  3629. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3630. }
  3631. }
  3632. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  3633. {
  3634. struct drm_device *dev = crtc->dev;
  3635. struct drm_i915_private *dev_priv = dev->dev_private;
  3636. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3637. struct intel_encoder *encoder;
  3638. int pipe = intel_crtc->pipe;
  3639. u32 reg, temp;
  3640. if (!intel_crtc->active)
  3641. return;
  3642. intel_crtc_disable_planes(crtc);
  3643. for_each_encoder_on_crtc(dev, crtc, encoder)
  3644. encoder->disable(encoder);
  3645. if (intel_crtc->config.has_pch_encoder)
  3646. intel_set_pch_fifo_underrun_reporting(dev, pipe, false);
  3647. intel_disable_pipe(intel_crtc);
  3648. ironlake_pfit_disable(intel_crtc);
  3649. for_each_encoder_on_crtc(dev, crtc, encoder)
  3650. if (encoder->post_disable)
  3651. encoder->post_disable(encoder);
  3652. if (intel_crtc->config.has_pch_encoder) {
  3653. ironlake_fdi_disable(crtc);
  3654. ironlake_disable_pch_transcoder(dev_priv, pipe);
  3655. intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
  3656. if (HAS_PCH_CPT(dev)) {
  3657. /* disable TRANS_DP_CTL */
  3658. reg = TRANS_DP_CTL(pipe);
  3659. temp = I915_READ(reg);
  3660. temp &= ~(TRANS_DP_OUTPUT_ENABLE |
  3661. TRANS_DP_PORT_SEL_MASK);
  3662. temp |= TRANS_DP_PORT_SEL_NONE;
  3663. I915_WRITE(reg, temp);
  3664. /* disable DPLL_SEL */
  3665. temp = I915_READ(PCH_DPLL_SEL);
  3666. temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
  3667. I915_WRITE(PCH_DPLL_SEL, temp);
  3668. }
  3669. /* disable PCH DPLL */
  3670. intel_disable_shared_dpll(intel_crtc);
  3671. ironlake_fdi_pll_disable(intel_crtc);
  3672. }
  3673. intel_crtc->active = false;
  3674. intel_update_watermarks(crtc);
  3675. mutex_lock(&dev->struct_mutex);
  3676. intel_update_fbc(dev);
  3677. mutex_unlock(&dev->struct_mutex);
  3678. }
  3679. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3680. {
  3681. struct drm_device *dev = crtc->dev;
  3682. struct drm_i915_private *dev_priv = dev->dev_private;
  3683. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3684. struct intel_encoder *encoder;
  3685. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  3686. if (!intel_crtc->active)
  3687. return;
  3688. intel_crtc_disable_planes(crtc);
  3689. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3690. intel_opregion_notify_encoder(encoder, false);
  3691. encoder->disable(encoder);
  3692. }
  3693. if (intel_crtc->config.has_pch_encoder)
  3694. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false);
  3695. intel_disable_pipe(intel_crtc);
  3696. if (intel_crtc->config.dp_encoder_is_mst)
  3697. intel_ddi_set_vc_payload_alloc(crtc, false);
  3698. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3699. ironlake_pfit_disable(intel_crtc);
  3700. intel_ddi_disable_pipe_clock(intel_crtc);
  3701. if (intel_crtc->config.has_pch_encoder) {
  3702. lpt_disable_pch_transcoder(dev_priv);
  3703. intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
  3704. intel_ddi_fdi_disable(crtc);
  3705. }
  3706. for_each_encoder_on_crtc(dev, crtc, encoder)
  3707. if (encoder->post_disable)
  3708. encoder->post_disable(encoder);
  3709. intel_crtc->active = false;
  3710. intel_update_watermarks(crtc);
  3711. mutex_lock(&dev->struct_mutex);
  3712. intel_update_fbc(dev);
  3713. mutex_unlock(&dev->struct_mutex);
  3714. if (intel_crtc_to_shared_dpll(intel_crtc))
  3715. intel_disable_shared_dpll(intel_crtc);
  3716. }
  3717. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3718. {
  3719. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3720. intel_put_shared_dpll(intel_crtc);
  3721. }
  3722. static void i9xx_pfit_enable(struct intel_crtc *crtc)
  3723. {
  3724. struct drm_device *dev = crtc->base.dev;
  3725. struct drm_i915_private *dev_priv = dev->dev_private;
  3726. struct intel_crtc_config *pipe_config = &crtc->config;
  3727. if (!crtc->config.gmch_pfit.control)
  3728. return;
  3729. /*
  3730. * The panel fitter should only be adjusted whilst the pipe is disabled,
  3731. * according to register description and PRM.
  3732. */
  3733. WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
  3734. assert_pipe_disabled(dev_priv, crtc->pipe);
  3735. I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios);
  3736. I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control);
  3737. /* Border color in case we don't scale up to the full screen. Black by
  3738. * default, change to something else for debugging. */
  3739. I915_WRITE(BCLRPAT(crtc->pipe), 0);
  3740. }
  3741. static enum intel_display_power_domain port_to_power_domain(enum port port)
  3742. {
  3743. switch (port) {
  3744. case PORT_A:
  3745. return POWER_DOMAIN_PORT_DDI_A_4_LANES;
  3746. case PORT_B:
  3747. return POWER_DOMAIN_PORT_DDI_B_4_LANES;
  3748. case PORT_C:
  3749. return POWER_DOMAIN_PORT_DDI_C_4_LANES;
  3750. case PORT_D:
  3751. return POWER_DOMAIN_PORT_DDI_D_4_LANES;
  3752. default:
  3753. WARN_ON_ONCE(1);
  3754. return POWER_DOMAIN_PORT_OTHER;
  3755. }
  3756. }
  3757. #define for_each_power_domain(domain, mask) \
  3758. for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
  3759. if ((1 << (domain)) & (mask))
  3760. enum intel_display_power_domain
  3761. intel_display_port_power_domain(struct intel_encoder *intel_encoder)
  3762. {
  3763. struct drm_device *dev = intel_encoder->base.dev;
  3764. struct intel_digital_port *intel_dig_port;
  3765. switch (intel_encoder->type) {
  3766. case INTEL_OUTPUT_UNKNOWN:
  3767. /* Only DDI platforms should ever use this output type */
  3768. WARN_ON_ONCE(!HAS_DDI(dev));
  3769. case INTEL_OUTPUT_DISPLAYPORT:
  3770. case INTEL_OUTPUT_HDMI:
  3771. case INTEL_OUTPUT_EDP:
  3772. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  3773. return port_to_power_domain(intel_dig_port->port);
  3774. case INTEL_OUTPUT_DP_MST:
  3775. intel_dig_port = enc_to_mst(&intel_encoder->base)->primary;
  3776. return port_to_power_domain(intel_dig_port->port);
  3777. case INTEL_OUTPUT_ANALOG:
  3778. return POWER_DOMAIN_PORT_CRT;
  3779. case INTEL_OUTPUT_DSI:
  3780. return POWER_DOMAIN_PORT_DSI;
  3781. default:
  3782. return POWER_DOMAIN_PORT_OTHER;
  3783. }
  3784. }
  3785. static unsigned long get_crtc_power_domains(struct drm_crtc *crtc)
  3786. {
  3787. struct drm_device *dev = crtc->dev;
  3788. struct intel_encoder *intel_encoder;
  3789. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3790. enum pipe pipe = intel_crtc->pipe;
  3791. unsigned long mask;
  3792. enum transcoder transcoder;
  3793. transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe);
  3794. mask = BIT(POWER_DOMAIN_PIPE(pipe));
  3795. mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder));
  3796. if (intel_crtc->config.pch_pfit.enabled ||
  3797. intel_crtc->config.pch_pfit.force_thru)
  3798. mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
  3799. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3800. mask |= BIT(intel_display_port_power_domain(intel_encoder));
  3801. return mask;
  3802. }
  3803. void intel_display_set_init_power(struct drm_i915_private *dev_priv,
  3804. bool enable)
  3805. {
  3806. if (dev_priv->power_domains.init_power_on == enable)
  3807. return;
  3808. if (enable)
  3809. intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
  3810. else
  3811. intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
  3812. dev_priv->power_domains.init_power_on = enable;
  3813. }
  3814. static void modeset_update_crtc_power_domains(struct drm_device *dev)
  3815. {
  3816. struct drm_i915_private *dev_priv = dev->dev_private;
  3817. unsigned long pipe_domains[I915_MAX_PIPES] = { 0, };
  3818. struct intel_crtc *crtc;
  3819. /*
  3820. * First get all needed power domains, then put all unneeded, to avoid
  3821. * any unnecessary toggling of the power wells.
  3822. */
  3823. for_each_intel_crtc(dev, crtc) {
  3824. enum intel_display_power_domain domain;
  3825. if (!crtc->base.enabled)
  3826. continue;
  3827. pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base);
  3828. for_each_power_domain(domain, pipe_domains[crtc->pipe])
  3829. intel_display_power_get(dev_priv, domain);
  3830. }
  3831. for_each_intel_crtc(dev, crtc) {
  3832. enum intel_display_power_domain domain;
  3833. for_each_power_domain(domain, crtc->enabled_power_domains)
  3834. intel_display_power_put(dev_priv, domain);
  3835. crtc->enabled_power_domains = pipe_domains[crtc->pipe];
  3836. }
  3837. intel_display_set_init_power(dev_priv, false);
  3838. }
  3839. /* returns HPLL frequency in kHz */
  3840. static int valleyview_get_vco(struct drm_i915_private *dev_priv)
  3841. {
  3842. int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
  3843. /* Obtain SKU information */
  3844. mutex_lock(&dev_priv->dpio_lock);
  3845. hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
  3846. CCK_FUSE_HPLL_FREQ_MASK;
  3847. mutex_unlock(&dev_priv->dpio_lock);
  3848. return vco_freq[hpll_freq] * 1000;
  3849. }
  3850. static void vlv_update_cdclk(struct drm_device *dev)
  3851. {
  3852. struct drm_i915_private *dev_priv = dev->dev_private;
  3853. dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
  3854. DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz",
  3855. dev_priv->vlv_cdclk_freq);
  3856. /*
  3857. * Program the gmbus_freq based on the cdclk frequency.
  3858. * BSpec erroneously claims we should aim for 4MHz, but
  3859. * in fact 1MHz is the correct frequency.
  3860. */
  3861. I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->vlv_cdclk_freq, 1000));
  3862. }
  3863. /* Adjust CDclk dividers to allow high res or save power if possible */
  3864. static void valleyview_set_cdclk(struct drm_device *dev, int cdclk)
  3865. {
  3866. struct drm_i915_private *dev_priv = dev->dev_private;
  3867. u32 val, cmd;
  3868. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3869. if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */
  3870. cmd = 2;
  3871. else if (cdclk == 266667)
  3872. cmd = 1;
  3873. else
  3874. cmd = 0;
  3875. mutex_lock(&dev_priv->rps.hw_lock);
  3876. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3877. val &= ~DSPFREQGUAR_MASK;
  3878. val |= (cmd << DSPFREQGUAR_SHIFT);
  3879. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3880. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3881. DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT),
  3882. 50)) {
  3883. DRM_ERROR("timed out waiting for CDclk change\n");
  3884. }
  3885. mutex_unlock(&dev_priv->rps.hw_lock);
  3886. if (cdclk == 400000) {
  3887. u32 divider, vco;
  3888. vco = valleyview_get_vco(dev_priv);
  3889. divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1;
  3890. mutex_lock(&dev_priv->dpio_lock);
  3891. /* adjust cdclk divider */
  3892. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  3893. val &= ~DISPLAY_FREQUENCY_VALUES;
  3894. val |= divider;
  3895. vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val);
  3896. if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) &
  3897. DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  3898. 50))
  3899. DRM_ERROR("timed out waiting for CDclk change\n");
  3900. mutex_unlock(&dev_priv->dpio_lock);
  3901. }
  3902. mutex_lock(&dev_priv->dpio_lock);
  3903. /* adjust self-refresh exit latency value */
  3904. val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC);
  3905. val &= ~0x7f;
  3906. /*
  3907. * For high bandwidth configs, we set a higher latency in the bunit
  3908. * so that the core display fetch happens in time to avoid underruns.
  3909. */
  3910. if (cdclk == 400000)
  3911. val |= 4500 / 250; /* 4.5 usec */
  3912. else
  3913. val |= 3000 / 250; /* 3.0 usec */
  3914. vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val);
  3915. mutex_unlock(&dev_priv->dpio_lock);
  3916. vlv_update_cdclk(dev);
  3917. }
  3918. static void cherryview_set_cdclk(struct drm_device *dev, int cdclk)
  3919. {
  3920. struct drm_i915_private *dev_priv = dev->dev_private;
  3921. u32 val, cmd;
  3922. WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq);
  3923. switch (cdclk) {
  3924. case 400000:
  3925. cmd = 3;
  3926. break;
  3927. case 333333:
  3928. case 320000:
  3929. cmd = 2;
  3930. break;
  3931. case 266667:
  3932. cmd = 1;
  3933. break;
  3934. case 200000:
  3935. cmd = 0;
  3936. break;
  3937. default:
  3938. WARN_ON(1);
  3939. return;
  3940. }
  3941. mutex_lock(&dev_priv->rps.hw_lock);
  3942. val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ);
  3943. val &= ~DSPFREQGUAR_MASK_CHV;
  3944. val |= (cmd << DSPFREQGUAR_SHIFT_CHV);
  3945. vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val);
  3946. if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) &
  3947. DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV),
  3948. 50)) {
  3949. DRM_ERROR("timed out waiting for CDclk change\n");
  3950. }
  3951. mutex_unlock(&dev_priv->rps.hw_lock);
  3952. vlv_update_cdclk(dev);
  3953. }
  3954. static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv,
  3955. int max_pixclk)
  3956. {
  3957. int vco = valleyview_get_vco(dev_priv);
  3958. int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000;
  3959. /* FIXME: Punit isn't quite ready yet */
  3960. if (IS_CHERRYVIEW(dev_priv->dev))
  3961. return 400000;
  3962. /*
  3963. * Really only a few cases to deal with, as only 4 CDclks are supported:
  3964. * 200MHz
  3965. * 267MHz
  3966. * 320/333MHz (depends on HPLL freq)
  3967. * 400MHz
  3968. * So we check to see whether we're above 90% of the lower bin and
  3969. * adjust if needed.
  3970. *
  3971. * We seem to get an unstable or solid color picture at 200MHz.
  3972. * Not sure what's wrong. For now use 200MHz only when all pipes
  3973. * are off.
  3974. */
  3975. if (max_pixclk > freq_320*9/10)
  3976. return 400000;
  3977. else if (max_pixclk > 266667*9/10)
  3978. return freq_320;
  3979. else if (max_pixclk > 0)
  3980. return 266667;
  3981. else
  3982. return 200000;
  3983. }
  3984. /* compute the max pixel clock for new configuration */
  3985. static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv)
  3986. {
  3987. struct drm_device *dev = dev_priv->dev;
  3988. struct intel_crtc *intel_crtc;
  3989. int max_pixclk = 0;
  3990. for_each_intel_crtc(dev, intel_crtc) {
  3991. if (intel_crtc->new_enabled)
  3992. max_pixclk = max(max_pixclk,
  3993. intel_crtc->new_config->adjusted_mode.crtc_clock);
  3994. }
  3995. return max_pixclk;
  3996. }
  3997. static void valleyview_modeset_global_pipes(struct drm_device *dev,
  3998. unsigned *prepare_pipes)
  3999. {
  4000. struct drm_i915_private *dev_priv = dev->dev_private;
  4001. struct intel_crtc *intel_crtc;
  4002. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4003. if (valleyview_calc_cdclk(dev_priv, max_pixclk) ==
  4004. dev_priv->vlv_cdclk_freq)
  4005. return;
  4006. /* disable/enable all currently active pipes while we change cdclk */
  4007. for_each_intel_crtc(dev, intel_crtc)
  4008. if (intel_crtc->base.enabled)
  4009. *prepare_pipes |= (1 << intel_crtc->pipe);
  4010. }
  4011. static void valleyview_modeset_global_resources(struct drm_device *dev)
  4012. {
  4013. struct drm_i915_private *dev_priv = dev->dev_private;
  4014. int max_pixclk = intel_mode_max_pixclk(dev_priv);
  4015. int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk);
  4016. if (req_cdclk != dev_priv->vlv_cdclk_freq) {
  4017. if (IS_CHERRYVIEW(dev))
  4018. cherryview_set_cdclk(dev, req_cdclk);
  4019. else
  4020. valleyview_set_cdclk(dev, req_cdclk);
  4021. }
  4022. modeset_update_crtc_power_domains(dev);
  4023. }
  4024. static void valleyview_crtc_enable(struct drm_crtc *crtc)
  4025. {
  4026. struct drm_device *dev = crtc->dev;
  4027. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4028. struct intel_encoder *encoder;
  4029. int pipe = intel_crtc->pipe;
  4030. bool is_dsi;
  4031. WARN_ON(!crtc->enabled);
  4032. if (intel_crtc->active)
  4033. return;
  4034. is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI);
  4035. if (!is_dsi) {
  4036. if (IS_CHERRYVIEW(dev))
  4037. chv_prepare_pll(intel_crtc);
  4038. else
  4039. vlv_prepare_pll(intel_crtc);
  4040. }
  4041. if (intel_crtc->config.has_dp_encoder)
  4042. intel_dp_set_m_n(intel_crtc);
  4043. intel_set_pipe_timings(intel_crtc);
  4044. i9xx_set_pipeconf(intel_crtc);
  4045. intel_crtc->active = true;
  4046. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4047. for_each_encoder_on_crtc(dev, crtc, encoder)
  4048. if (encoder->pre_pll_enable)
  4049. encoder->pre_pll_enable(encoder);
  4050. if (!is_dsi) {
  4051. if (IS_CHERRYVIEW(dev))
  4052. chv_enable_pll(intel_crtc);
  4053. else
  4054. vlv_enable_pll(intel_crtc);
  4055. }
  4056. for_each_encoder_on_crtc(dev, crtc, encoder)
  4057. if (encoder->pre_enable)
  4058. encoder->pre_enable(encoder);
  4059. i9xx_pfit_enable(intel_crtc);
  4060. intel_crtc_load_lut(crtc);
  4061. intel_update_watermarks(crtc);
  4062. intel_enable_pipe(intel_crtc);
  4063. for_each_encoder_on_crtc(dev, crtc, encoder)
  4064. encoder->enable(encoder);
  4065. intel_crtc_enable_planes(crtc);
  4066. /* Underruns don't raise interrupts, so check manually. */
  4067. i9xx_check_fifo_underruns(dev);
  4068. }
  4069. static void i9xx_set_pll_dividers(struct intel_crtc *crtc)
  4070. {
  4071. struct drm_device *dev = crtc->base.dev;
  4072. struct drm_i915_private *dev_priv = dev->dev_private;
  4073. I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0);
  4074. I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1);
  4075. }
  4076. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  4077. {
  4078. struct drm_device *dev = crtc->dev;
  4079. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4080. struct intel_encoder *encoder;
  4081. int pipe = intel_crtc->pipe;
  4082. WARN_ON(!crtc->enabled);
  4083. if (intel_crtc->active)
  4084. return;
  4085. i9xx_set_pll_dividers(intel_crtc);
  4086. if (intel_crtc->config.has_dp_encoder)
  4087. intel_dp_set_m_n(intel_crtc);
  4088. intel_set_pipe_timings(intel_crtc);
  4089. i9xx_set_pipeconf(intel_crtc);
  4090. intel_crtc->active = true;
  4091. if (!IS_GEN2(dev))
  4092. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4093. for_each_encoder_on_crtc(dev, crtc, encoder)
  4094. if (encoder->pre_enable)
  4095. encoder->pre_enable(encoder);
  4096. i9xx_enable_pll(intel_crtc);
  4097. i9xx_pfit_enable(intel_crtc);
  4098. intel_crtc_load_lut(crtc);
  4099. intel_update_watermarks(crtc);
  4100. intel_enable_pipe(intel_crtc);
  4101. for_each_encoder_on_crtc(dev, crtc, encoder)
  4102. encoder->enable(encoder);
  4103. intel_crtc_enable_planes(crtc);
  4104. /*
  4105. * Gen2 reports pipe underruns whenever all planes are disabled.
  4106. * So don't enable underrun reporting before at least some planes
  4107. * are enabled.
  4108. * FIXME: Need to fix the logic to work when we turn off all planes
  4109. * but leave the pipe running.
  4110. */
  4111. if (IS_GEN2(dev))
  4112. intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
  4113. /* Underruns don't raise interrupts, so check manually. */
  4114. i9xx_check_fifo_underruns(dev);
  4115. }
  4116. static void i9xx_pfit_disable(struct intel_crtc *crtc)
  4117. {
  4118. struct drm_device *dev = crtc->base.dev;
  4119. struct drm_i915_private *dev_priv = dev->dev_private;
  4120. if (!crtc->config.gmch_pfit.control)
  4121. return;
  4122. assert_pipe_disabled(dev_priv, crtc->pipe);
  4123. DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n",
  4124. I915_READ(PFIT_CONTROL));
  4125. I915_WRITE(PFIT_CONTROL, 0);
  4126. }
  4127. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  4128. {
  4129. struct drm_device *dev = crtc->dev;
  4130. struct drm_i915_private *dev_priv = dev->dev_private;
  4131. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4132. struct intel_encoder *encoder;
  4133. int pipe = intel_crtc->pipe;
  4134. if (!intel_crtc->active)
  4135. return;
  4136. /*
  4137. * Gen2 reports pipe underruns whenever all planes are disabled.
  4138. * So diasble underrun reporting before all the planes get disabled.
  4139. * FIXME: Need to fix the logic to work when we turn off all planes
  4140. * but leave the pipe running.
  4141. */
  4142. if (IS_GEN2(dev))
  4143. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4144. /*
  4145. * Vblank time updates from the shadow to live plane control register
  4146. * are blocked if the memory self-refresh mode is active at that
  4147. * moment. So to make sure the plane gets truly disabled, disable
  4148. * first the self-refresh mode. The self-refresh enable bit in turn
  4149. * will be checked/applied by the HW only at the next frame start
  4150. * event which is after the vblank start event, so we need to have a
  4151. * wait-for-vblank between disabling the plane and the pipe.
  4152. */
  4153. intel_set_memory_cxsr(dev_priv, false);
  4154. intel_crtc_disable_planes(crtc);
  4155. for_each_encoder_on_crtc(dev, crtc, encoder)
  4156. encoder->disable(encoder);
  4157. /*
  4158. * On gen2 planes are double buffered but the pipe isn't, so we must
  4159. * wait for planes to fully turn off before disabling the pipe.
  4160. * We also need to wait on all gmch platforms because of the
  4161. * self-refresh mode constraint explained above.
  4162. */
  4163. intel_wait_for_vblank(dev, pipe);
  4164. intel_disable_pipe(intel_crtc);
  4165. i9xx_pfit_disable(intel_crtc);
  4166. for_each_encoder_on_crtc(dev, crtc, encoder)
  4167. if (encoder->post_disable)
  4168. encoder->post_disable(encoder);
  4169. if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) {
  4170. if (IS_CHERRYVIEW(dev))
  4171. chv_disable_pll(dev_priv, pipe);
  4172. else if (IS_VALLEYVIEW(dev))
  4173. vlv_disable_pll(dev_priv, pipe);
  4174. else
  4175. i9xx_disable_pll(intel_crtc);
  4176. }
  4177. if (!IS_GEN2(dev))
  4178. intel_set_cpu_fifo_underrun_reporting(dev, pipe, false);
  4179. intel_crtc->active = false;
  4180. intel_update_watermarks(crtc);
  4181. mutex_lock(&dev->struct_mutex);
  4182. intel_update_fbc(dev);
  4183. mutex_unlock(&dev->struct_mutex);
  4184. }
  4185. static void i9xx_crtc_off(struct drm_crtc *crtc)
  4186. {
  4187. }
  4188. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  4189. bool enabled)
  4190. {
  4191. struct drm_device *dev = crtc->dev;
  4192. struct drm_i915_master_private *master_priv;
  4193. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4194. int pipe = intel_crtc->pipe;
  4195. if (!dev->primary->master)
  4196. return;
  4197. master_priv = dev->primary->master->driver_priv;
  4198. if (!master_priv->sarea_priv)
  4199. return;
  4200. switch (pipe) {
  4201. case 0:
  4202. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  4203. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  4204. break;
  4205. case 1:
  4206. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  4207. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  4208. break;
  4209. default:
  4210. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  4211. break;
  4212. }
  4213. }
  4214. /* Master function to enable/disable CRTC and corresponding power wells */
  4215. void intel_crtc_control(struct drm_crtc *crtc, bool enable)
  4216. {
  4217. struct drm_device *dev = crtc->dev;
  4218. struct drm_i915_private *dev_priv = dev->dev_private;
  4219. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4220. enum intel_display_power_domain domain;
  4221. unsigned long domains;
  4222. if (enable) {
  4223. if (!intel_crtc->active) {
  4224. domains = get_crtc_power_domains(crtc);
  4225. for_each_power_domain(domain, domains)
  4226. intel_display_power_get(dev_priv, domain);
  4227. intel_crtc->enabled_power_domains = domains;
  4228. dev_priv->display.crtc_enable(crtc);
  4229. }
  4230. } else {
  4231. if (intel_crtc->active) {
  4232. dev_priv->display.crtc_disable(crtc);
  4233. domains = intel_crtc->enabled_power_domains;
  4234. for_each_power_domain(domain, domains)
  4235. intel_display_power_put(dev_priv, domain);
  4236. intel_crtc->enabled_power_domains = 0;
  4237. }
  4238. }
  4239. }
  4240. /**
  4241. * Sets the power management mode of the pipe and plane.
  4242. */
  4243. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  4244. {
  4245. struct drm_device *dev = crtc->dev;
  4246. struct intel_encoder *intel_encoder;
  4247. bool enable = false;
  4248. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  4249. enable |= intel_encoder->connectors_active;
  4250. intel_crtc_control(crtc, enable);
  4251. intel_crtc_update_sarea(crtc, enable);
  4252. }
  4253. static void intel_crtc_disable(struct drm_crtc *crtc)
  4254. {
  4255. struct drm_device *dev = crtc->dev;
  4256. struct drm_connector *connector;
  4257. struct drm_i915_private *dev_priv = dev->dev_private;
  4258. struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb);
  4259. enum pipe pipe = to_intel_crtc(crtc)->pipe;
  4260. /* crtc should still be enabled when we disable it. */
  4261. WARN_ON(!crtc->enabled);
  4262. dev_priv->display.crtc_disable(crtc);
  4263. intel_crtc_update_sarea(crtc, false);
  4264. dev_priv->display.off(crtc);
  4265. if (crtc->primary->fb) {
  4266. mutex_lock(&dev->struct_mutex);
  4267. intel_unpin_fb_obj(old_obj);
  4268. i915_gem_track_fb(old_obj, NULL,
  4269. INTEL_FRONTBUFFER_PRIMARY(pipe));
  4270. mutex_unlock(&dev->struct_mutex);
  4271. crtc->primary->fb = NULL;
  4272. }
  4273. /* Update computed state. */
  4274. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  4275. if (!connector->encoder || !connector->encoder->crtc)
  4276. continue;
  4277. if (connector->encoder->crtc != crtc)
  4278. continue;
  4279. connector->dpms = DRM_MODE_DPMS_OFF;
  4280. to_intel_encoder(connector->encoder)->connectors_active = false;
  4281. }
  4282. }
  4283. void intel_encoder_destroy(struct drm_encoder *encoder)
  4284. {
  4285. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  4286. drm_encoder_cleanup(encoder);
  4287. kfree(intel_encoder);
  4288. }
  4289. /* Simple dpms helper for encoders with just one connector, no cloning and only
  4290. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  4291. * state of the entire output pipe. */
  4292. static void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  4293. {
  4294. if (mode == DRM_MODE_DPMS_ON) {
  4295. encoder->connectors_active = true;
  4296. intel_crtc_update_dpms(encoder->base.crtc);
  4297. } else {
  4298. encoder->connectors_active = false;
  4299. intel_crtc_update_dpms(encoder->base.crtc);
  4300. }
  4301. }
  4302. /* Cross check the actual hw state with our own modeset state tracking (and it's
  4303. * internal consistency). */
  4304. static void intel_connector_check_state(struct intel_connector *connector)
  4305. {
  4306. if (connector->get_hw_state(connector)) {
  4307. struct intel_encoder *encoder = connector->encoder;
  4308. struct drm_crtc *crtc;
  4309. bool encoder_enabled;
  4310. enum pipe pipe;
  4311. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4312. connector->base.base.id,
  4313. connector->base.name);
  4314. /* there is no real hw state for MST connectors */
  4315. if (connector->mst_port)
  4316. return;
  4317. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  4318. "wrong connector dpms state\n");
  4319. WARN(connector->base.encoder != &encoder->base,
  4320. "active connector not linked to encoder\n");
  4321. if (encoder) {
  4322. WARN(!encoder->connectors_active,
  4323. "encoder->connectors_active not set\n");
  4324. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  4325. WARN(!encoder_enabled, "encoder not enabled\n");
  4326. if (WARN_ON(!encoder->base.crtc))
  4327. return;
  4328. crtc = encoder->base.crtc;
  4329. WARN(!crtc->enabled, "crtc not enabled\n");
  4330. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  4331. WARN(pipe != to_intel_crtc(crtc)->pipe,
  4332. "encoder active on the wrong pipe\n");
  4333. }
  4334. }
  4335. }
  4336. /* Even simpler default implementation, if there's really no special case to
  4337. * consider. */
  4338. void intel_connector_dpms(struct drm_connector *connector, int mode)
  4339. {
  4340. /* All the simple cases only support two dpms states. */
  4341. if (mode != DRM_MODE_DPMS_ON)
  4342. mode = DRM_MODE_DPMS_OFF;
  4343. if (mode == connector->dpms)
  4344. return;
  4345. connector->dpms = mode;
  4346. /* Only need to change hw state when actually enabled */
  4347. if (connector->encoder)
  4348. intel_encoder_dpms(to_intel_encoder(connector->encoder), mode);
  4349. intel_modeset_check_state(connector->dev);
  4350. }
  4351. /* Simple connector->get_hw_state implementation for encoders that support only
  4352. * one connector and no cloning and hence the encoder state determines the state
  4353. * of the connector. */
  4354. bool intel_connector_get_hw_state(struct intel_connector *connector)
  4355. {
  4356. enum pipe pipe = 0;
  4357. struct intel_encoder *encoder = connector->encoder;
  4358. return encoder->get_hw_state(encoder, &pipe);
  4359. }
  4360. static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
  4361. struct intel_crtc_config *pipe_config)
  4362. {
  4363. struct drm_i915_private *dev_priv = dev->dev_private;
  4364. struct intel_crtc *pipe_B_crtc =
  4365. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4366. DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
  4367. pipe_name(pipe), pipe_config->fdi_lanes);
  4368. if (pipe_config->fdi_lanes > 4) {
  4369. DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
  4370. pipe_name(pipe), pipe_config->fdi_lanes);
  4371. return false;
  4372. }
  4373. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  4374. if (pipe_config->fdi_lanes > 2) {
  4375. DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
  4376. pipe_config->fdi_lanes);
  4377. return false;
  4378. } else {
  4379. return true;
  4380. }
  4381. }
  4382. if (INTEL_INFO(dev)->num_pipes == 2)
  4383. return true;
  4384. /* Ivybridge 3 pipe is really complicated */
  4385. switch (pipe) {
  4386. case PIPE_A:
  4387. return true;
  4388. case PIPE_B:
  4389. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4390. pipe_config->fdi_lanes > 2) {
  4391. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4392. pipe_name(pipe), pipe_config->fdi_lanes);
  4393. return false;
  4394. }
  4395. return true;
  4396. case PIPE_C:
  4397. if (!pipe_has_enabled_pch(pipe_B_crtc) ||
  4398. pipe_B_crtc->config.fdi_lanes <= 2) {
  4399. if (pipe_config->fdi_lanes > 2) {
  4400. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
  4401. pipe_name(pipe), pipe_config->fdi_lanes);
  4402. return false;
  4403. }
  4404. } else {
  4405. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4406. return false;
  4407. }
  4408. return true;
  4409. default:
  4410. BUG();
  4411. }
  4412. }
  4413. #define RETRY 1
  4414. static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
  4415. struct intel_crtc_config *pipe_config)
  4416. {
  4417. struct drm_device *dev = intel_crtc->base.dev;
  4418. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4419. int lane, link_bw, fdi_dotclock;
  4420. bool setup_ok, needs_recompute = false;
  4421. retry:
  4422. /* FDI is a binary signal running at ~2.7GHz, encoding
  4423. * each output octet as 10 bits. The actual frequency
  4424. * is stored as a divider into a 100MHz clock, and the
  4425. * mode pixel clock is stored in units of 1KHz.
  4426. * Hence the bw of each lane in terms of the mode signal
  4427. * is:
  4428. */
  4429. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4430. fdi_dotclock = adjusted_mode->crtc_clock;
  4431. lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
  4432. pipe_config->pipe_bpp);
  4433. pipe_config->fdi_lanes = lane;
  4434. intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
  4435. link_bw, &pipe_config->fdi_m_n);
  4436. setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev,
  4437. intel_crtc->pipe, pipe_config);
  4438. if (!setup_ok && pipe_config->pipe_bpp > 6*3) {
  4439. pipe_config->pipe_bpp -= 2*3;
  4440. DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
  4441. pipe_config->pipe_bpp);
  4442. needs_recompute = true;
  4443. pipe_config->bw_constrained = true;
  4444. goto retry;
  4445. }
  4446. if (needs_recompute)
  4447. return RETRY;
  4448. return setup_ok ? 0 : -EINVAL;
  4449. }
  4450. static void hsw_compute_ips_config(struct intel_crtc *crtc,
  4451. struct intel_crtc_config *pipe_config)
  4452. {
  4453. pipe_config->ips_enabled = i915.enable_ips &&
  4454. hsw_crtc_supports_ips(crtc) &&
  4455. pipe_config->pipe_bpp <= 24;
  4456. }
  4457. static int intel_crtc_compute_config(struct intel_crtc *crtc,
  4458. struct intel_crtc_config *pipe_config)
  4459. {
  4460. struct drm_device *dev = crtc->base.dev;
  4461. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  4462. /* FIXME should check pixel clock limits on all platforms */
  4463. if (INTEL_INFO(dev)->gen < 4) {
  4464. struct drm_i915_private *dev_priv = dev->dev_private;
  4465. int clock_limit =
  4466. dev_priv->display.get_display_clock_speed(dev);
  4467. /*
  4468. * Enable pixel doubling when the dot clock
  4469. * is > 90% of the (display) core speed.
  4470. *
  4471. * GDG double wide on either pipe,
  4472. * otherwise pipe A only.
  4473. */
  4474. if ((crtc->pipe == PIPE_A || IS_I915G(dev)) &&
  4475. adjusted_mode->crtc_clock > clock_limit * 9 / 10) {
  4476. clock_limit *= 2;
  4477. pipe_config->double_wide = true;
  4478. }
  4479. if (adjusted_mode->crtc_clock > clock_limit * 9 / 10)
  4480. return -EINVAL;
  4481. }
  4482. /*
  4483. * Pipe horizontal size must be even in:
  4484. * - DVO ganged mode
  4485. * - LVDS dual channel mode
  4486. * - Double wide pipe
  4487. */
  4488. if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4489. intel_is_dual_link_lvds(dev)) || pipe_config->double_wide)
  4490. pipe_config->pipe_src_w &= ~1;
  4491. /* Cantiga+ cannot handle modes with a hsync front porch of 0.
  4492. * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
  4493. */
  4494. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  4495. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  4496. return -EINVAL;
  4497. if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) {
  4498. pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */
  4499. } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) {
  4500. /* only a 8bpc pipe, with 6bpc dither through the panel fitter
  4501. * for lvds. */
  4502. pipe_config->pipe_bpp = 8*3;
  4503. }
  4504. if (HAS_IPS(dev))
  4505. hsw_compute_ips_config(crtc, pipe_config);
  4506. /*
  4507. * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the
  4508. * old clock survives for now.
  4509. */
  4510. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev) || HAS_DDI(dev))
  4511. pipe_config->shared_dpll = crtc->config.shared_dpll;
  4512. if (pipe_config->has_pch_encoder)
  4513. return ironlake_fdi_compute_config(crtc, pipe_config);
  4514. return 0;
  4515. }
  4516. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  4517. {
  4518. struct drm_i915_private *dev_priv = dev->dev_private;
  4519. int vco = valleyview_get_vco(dev_priv);
  4520. u32 val;
  4521. int divider;
  4522. /* FIXME: Punit isn't quite ready yet */
  4523. if (IS_CHERRYVIEW(dev))
  4524. return 400000;
  4525. mutex_lock(&dev_priv->dpio_lock);
  4526. val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL);
  4527. mutex_unlock(&dev_priv->dpio_lock);
  4528. divider = val & DISPLAY_FREQUENCY_VALUES;
  4529. WARN((val & DISPLAY_FREQUENCY_STATUS) !=
  4530. (divider << DISPLAY_FREQUENCY_STATUS_SHIFT),
  4531. "cdclk change in progress\n");
  4532. return DIV_ROUND_CLOSEST(vco << 1, divider + 1);
  4533. }
  4534. static int i945_get_display_clock_speed(struct drm_device *dev)
  4535. {
  4536. return 400000;
  4537. }
  4538. static int i915_get_display_clock_speed(struct drm_device *dev)
  4539. {
  4540. return 333000;
  4541. }
  4542. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  4543. {
  4544. return 200000;
  4545. }
  4546. static int pnv_get_display_clock_speed(struct drm_device *dev)
  4547. {
  4548. u16 gcfgc = 0;
  4549. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4550. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4551. case GC_DISPLAY_CLOCK_267_MHZ_PNV:
  4552. return 267000;
  4553. case GC_DISPLAY_CLOCK_333_MHZ_PNV:
  4554. return 333000;
  4555. case GC_DISPLAY_CLOCK_444_MHZ_PNV:
  4556. return 444000;
  4557. case GC_DISPLAY_CLOCK_200_MHZ_PNV:
  4558. return 200000;
  4559. default:
  4560. DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc);
  4561. case GC_DISPLAY_CLOCK_133_MHZ_PNV:
  4562. return 133000;
  4563. case GC_DISPLAY_CLOCK_167_MHZ_PNV:
  4564. return 167000;
  4565. }
  4566. }
  4567. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  4568. {
  4569. u16 gcfgc = 0;
  4570. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  4571. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  4572. return 133000;
  4573. else {
  4574. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  4575. case GC_DISPLAY_CLOCK_333_MHZ:
  4576. return 333000;
  4577. default:
  4578. case GC_DISPLAY_CLOCK_190_200_MHZ:
  4579. return 190000;
  4580. }
  4581. }
  4582. }
  4583. static int i865_get_display_clock_speed(struct drm_device *dev)
  4584. {
  4585. return 266000;
  4586. }
  4587. static int i855_get_display_clock_speed(struct drm_device *dev)
  4588. {
  4589. u16 hpllcc = 0;
  4590. /* Assume that the hardware is in the high speed state. This
  4591. * should be the default.
  4592. */
  4593. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  4594. case GC_CLOCK_133_200:
  4595. case GC_CLOCK_100_200:
  4596. return 200000;
  4597. case GC_CLOCK_166_250:
  4598. return 250000;
  4599. case GC_CLOCK_100_133:
  4600. return 133000;
  4601. }
  4602. /* Shouldn't happen */
  4603. return 0;
  4604. }
  4605. static int i830_get_display_clock_speed(struct drm_device *dev)
  4606. {
  4607. return 133000;
  4608. }
  4609. static void
  4610. intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
  4611. {
  4612. while (*num > DATA_LINK_M_N_MASK ||
  4613. *den > DATA_LINK_M_N_MASK) {
  4614. *num >>= 1;
  4615. *den >>= 1;
  4616. }
  4617. }
  4618. static void compute_m_n(unsigned int m, unsigned int n,
  4619. uint32_t *ret_m, uint32_t *ret_n)
  4620. {
  4621. *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
  4622. *ret_m = div_u64((uint64_t) m * *ret_n, n);
  4623. intel_reduce_m_n_ratio(ret_m, ret_n);
  4624. }
  4625. void
  4626. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  4627. int pixel_clock, int link_clock,
  4628. struct intel_link_m_n *m_n)
  4629. {
  4630. m_n->tu = 64;
  4631. compute_m_n(bits_per_pixel * pixel_clock,
  4632. link_clock * nlanes * 8,
  4633. &m_n->gmch_m, &m_n->gmch_n);
  4634. compute_m_n(pixel_clock, link_clock,
  4635. &m_n->link_m, &m_n->link_n);
  4636. }
  4637. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  4638. {
  4639. if (i915.panel_use_ssc >= 0)
  4640. return i915.panel_use_ssc != 0;
  4641. return dev_priv->vbt.lvds_use_ssc
  4642. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  4643. }
  4644. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  4645. {
  4646. struct drm_device *dev = crtc->dev;
  4647. struct drm_i915_private *dev_priv = dev->dev_private;
  4648. int refclk;
  4649. if (IS_VALLEYVIEW(dev)) {
  4650. refclk = 100000;
  4651. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  4652. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4653. refclk = dev_priv->vbt.lvds_ssc_freq;
  4654. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
  4655. } else if (!IS_GEN2(dev)) {
  4656. refclk = 96000;
  4657. } else {
  4658. refclk = 48000;
  4659. }
  4660. return refclk;
  4661. }
  4662. static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
  4663. {
  4664. return (1 << dpll->n) << 16 | dpll->m2;
  4665. }
  4666. static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
  4667. {
  4668. return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
  4669. }
  4670. static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
  4671. intel_clock_t *reduced_clock)
  4672. {
  4673. struct drm_device *dev = crtc->base.dev;
  4674. u32 fp, fp2 = 0;
  4675. if (IS_PINEVIEW(dev)) {
  4676. fp = pnv_dpll_compute_fp(&crtc->config.dpll);
  4677. if (reduced_clock)
  4678. fp2 = pnv_dpll_compute_fp(reduced_clock);
  4679. } else {
  4680. fp = i9xx_dpll_compute_fp(&crtc->config.dpll);
  4681. if (reduced_clock)
  4682. fp2 = i9xx_dpll_compute_fp(reduced_clock);
  4683. }
  4684. crtc->config.dpll_hw_state.fp0 = fp;
  4685. crtc->lowfreq_avail = false;
  4686. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4687. reduced_clock && i915.powersave) {
  4688. crtc->config.dpll_hw_state.fp1 = fp2;
  4689. crtc->lowfreq_avail = true;
  4690. } else {
  4691. crtc->config.dpll_hw_state.fp1 = fp;
  4692. }
  4693. }
  4694. static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
  4695. pipe)
  4696. {
  4697. u32 reg_val;
  4698. /*
  4699. * PLLB opamp always calibrates to max value of 0x3f, force enable it
  4700. * and set it to a reasonable value instead.
  4701. */
  4702. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4703. reg_val &= 0xffffff00;
  4704. reg_val |= 0x00000030;
  4705. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4706. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4707. reg_val &= 0x8cffffff;
  4708. reg_val = 0x8c000000;
  4709. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4710. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
  4711. reg_val &= 0xffffff00;
  4712. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
  4713. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
  4714. reg_val &= 0x00ffffff;
  4715. reg_val |= 0xb0000000;
  4716. vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
  4717. }
  4718. static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc,
  4719. struct intel_link_m_n *m_n)
  4720. {
  4721. struct drm_device *dev = crtc->base.dev;
  4722. struct drm_i915_private *dev_priv = dev->dev_private;
  4723. int pipe = crtc->pipe;
  4724. I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4725. I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
  4726. I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
  4727. I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
  4728. }
  4729. static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc,
  4730. struct intel_link_m_n *m_n,
  4731. struct intel_link_m_n *m2_n2)
  4732. {
  4733. struct drm_device *dev = crtc->base.dev;
  4734. struct drm_i915_private *dev_priv = dev->dev_private;
  4735. int pipe = crtc->pipe;
  4736. enum transcoder transcoder = crtc->config.cpu_transcoder;
  4737. if (INTEL_INFO(dev)->gen >= 5) {
  4738. I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4739. I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
  4740. I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
  4741. I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
  4742. /* M2_N2 registers to be set only for gen < 8 (M2_N2 available
  4743. * for gen < 8) and if DRRS is supported (to make sure the
  4744. * registers are not unnecessarily accessed).
  4745. */
  4746. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  4747. crtc->config.has_drrs) {
  4748. I915_WRITE(PIPE_DATA_M2(transcoder),
  4749. TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
  4750. I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
  4751. I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
  4752. I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
  4753. }
  4754. } else {
  4755. I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
  4756. I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
  4757. I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
  4758. I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
  4759. }
  4760. }
  4761. void intel_dp_set_m_n(struct intel_crtc *crtc)
  4762. {
  4763. if (crtc->config.has_pch_encoder)
  4764. intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n);
  4765. else
  4766. intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n,
  4767. &crtc->config.dp_m2_n2);
  4768. }
  4769. static void vlv_update_pll(struct intel_crtc *crtc)
  4770. {
  4771. u32 dpll, dpll_md;
  4772. /*
  4773. * Enable DPIO clock input. We should never disable the reference
  4774. * clock for pipe B, since VGA hotplug / manual detection depends
  4775. * on it.
  4776. */
  4777. dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV |
  4778. DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV;
  4779. /* We should never disable this, set it here for state tracking */
  4780. if (crtc->pipe == PIPE_B)
  4781. dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4782. dpll |= DPLL_VCO_ENABLE;
  4783. crtc->config.dpll_hw_state.dpll = dpll;
  4784. dpll_md = (crtc->config.pixel_multiplier - 1)
  4785. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4786. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4787. }
  4788. static void vlv_prepare_pll(struct intel_crtc *crtc)
  4789. {
  4790. struct drm_device *dev = crtc->base.dev;
  4791. struct drm_i915_private *dev_priv = dev->dev_private;
  4792. int pipe = crtc->pipe;
  4793. u32 mdiv;
  4794. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  4795. u32 coreclk, reg_val;
  4796. mutex_lock(&dev_priv->dpio_lock);
  4797. bestn = crtc->config.dpll.n;
  4798. bestm1 = crtc->config.dpll.m1;
  4799. bestm2 = crtc->config.dpll.m2;
  4800. bestp1 = crtc->config.dpll.p1;
  4801. bestp2 = crtc->config.dpll.p2;
  4802. /* See eDP HDMI DPIO driver vbios notes doc */
  4803. /* PLL B needs special handling */
  4804. if (pipe == PIPE_B)
  4805. vlv_pllb_recal_opamp(dev_priv, pipe);
  4806. /* Set up Tx target for periodic Rcomp update */
  4807. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
  4808. /* Disable target IRef on PLL */
  4809. reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
  4810. reg_val &= 0x00ffffff;
  4811. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
  4812. /* Disable fast lock */
  4813. vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
  4814. /* Set idtafcrecal before PLL is enabled */
  4815. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  4816. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  4817. mdiv |= ((bestn << DPIO_N_SHIFT));
  4818. mdiv |= (1 << DPIO_K_SHIFT);
  4819. /*
  4820. * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
  4821. * but we don't support that).
  4822. * Note: don't use the DAC post divider as it seems unstable.
  4823. */
  4824. mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
  4825. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4826. mdiv |= DPIO_ENABLE_CALIBRATION;
  4827. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
  4828. /* Set HBR and RBR LPF coefficients */
  4829. if (crtc->config.port_clock == 162000 ||
  4830. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) ||
  4831. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI))
  4832. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4833. 0x009f0003);
  4834. else
  4835. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
  4836. 0x00d0000f);
  4837. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) ||
  4838. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) {
  4839. /* Use SSC source */
  4840. if (pipe == PIPE_A)
  4841. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4842. 0x0df40000);
  4843. else
  4844. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4845. 0x0df70000);
  4846. } else { /* HDMI or VGA */
  4847. /* Use bend source */
  4848. if (pipe == PIPE_A)
  4849. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4850. 0x0df70000);
  4851. else
  4852. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
  4853. 0x0df40000);
  4854. }
  4855. coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
  4856. coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
  4857. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) ||
  4858. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))
  4859. coreclk |= 0x01000000;
  4860. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
  4861. vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
  4862. mutex_unlock(&dev_priv->dpio_lock);
  4863. }
  4864. static void chv_update_pll(struct intel_crtc *crtc)
  4865. {
  4866. crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV |
  4867. DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS |
  4868. DPLL_VCO_ENABLE;
  4869. if (crtc->pipe != PIPE_A)
  4870. crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
  4871. crtc->config.dpll_hw_state.dpll_md =
  4872. (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4873. }
  4874. static void chv_prepare_pll(struct intel_crtc *crtc)
  4875. {
  4876. struct drm_device *dev = crtc->base.dev;
  4877. struct drm_i915_private *dev_priv = dev->dev_private;
  4878. int pipe = crtc->pipe;
  4879. int dpll_reg = DPLL(crtc->pipe);
  4880. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  4881. u32 loopfilter, intcoeff;
  4882. u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
  4883. int refclk;
  4884. bestn = crtc->config.dpll.n;
  4885. bestm2_frac = crtc->config.dpll.m2 & 0x3fffff;
  4886. bestm1 = crtc->config.dpll.m1;
  4887. bestm2 = crtc->config.dpll.m2 >> 22;
  4888. bestp1 = crtc->config.dpll.p1;
  4889. bestp2 = crtc->config.dpll.p2;
  4890. /*
  4891. * Enable Refclk and SSC
  4892. */
  4893. I915_WRITE(dpll_reg,
  4894. crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
  4895. mutex_lock(&dev_priv->dpio_lock);
  4896. /* p1 and p2 divider */
  4897. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
  4898. 5 << DPIO_CHV_S1_DIV_SHIFT |
  4899. bestp1 << DPIO_CHV_P1_DIV_SHIFT |
  4900. bestp2 << DPIO_CHV_P2_DIV_SHIFT |
  4901. 1 << DPIO_CHV_K_DIV_SHIFT);
  4902. /* Feedback post-divider - m2 */
  4903. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
  4904. /* Feedback refclk divider - n and m1 */
  4905. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
  4906. DPIO_CHV_M1_DIV_BY_2 |
  4907. 1 << DPIO_CHV_N_DIV_SHIFT);
  4908. /* M2 fraction division */
  4909. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
  4910. /* M2 fraction division enable */
  4911. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port),
  4912. DPIO_CHV_FRAC_DIV_EN |
  4913. (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT));
  4914. /* Loop filter */
  4915. refclk = i9xx_get_refclk(&crtc->base, 0);
  4916. loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT |
  4917. 2 << DPIO_CHV_GAIN_CTRL_SHIFT;
  4918. if (refclk == 100000)
  4919. intcoeff = 11;
  4920. else if (refclk == 38400)
  4921. intcoeff = 10;
  4922. else
  4923. intcoeff = 9;
  4924. loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT;
  4925. vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
  4926. /* AFC Recal */
  4927. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
  4928. vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
  4929. DPIO_AFC_RECAL);
  4930. mutex_unlock(&dev_priv->dpio_lock);
  4931. }
  4932. static void i9xx_update_pll(struct intel_crtc *crtc,
  4933. intel_clock_t *reduced_clock,
  4934. int num_connectors)
  4935. {
  4936. struct drm_device *dev = crtc->base.dev;
  4937. struct drm_i915_private *dev_priv = dev->dev_private;
  4938. u32 dpll;
  4939. bool is_sdvo;
  4940. struct dpll *clock = &crtc->config.dpll;
  4941. i9xx_update_pll_dividers(crtc, reduced_clock);
  4942. is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) ||
  4943. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI);
  4944. dpll = DPLL_VGA_MODE_DIS;
  4945. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS))
  4946. dpll |= DPLLB_MODE_LVDS;
  4947. else
  4948. dpll |= DPLLB_MODE_DAC_SERIAL;
  4949. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  4950. dpll |= (crtc->config.pixel_multiplier - 1)
  4951. << SDVO_MULTIPLIER_SHIFT_HIRES;
  4952. }
  4953. if (is_sdvo)
  4954. dpll |= DPLL_SDVO_HIGH_SPEED;
  4955. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT))
  4956. dpll |= DPLL_SDVO_HIGH_SPEED;
  4957. /* compute bitmask from p1 value */
  4958. if (IS_PINEVIEW(dev))
  4959. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  4960. else {
  4961. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4962. if (IS_G4X(dev) && reduced_clock)
  4963. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4964. }
  4965. switch (clock->p2) {
  4966. case 5:
  4967. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4968. break;
  4969. case 7:
  4970. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4971. break;
  4972. case 10:
  4973. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4974. break;
  4975. case 14:
  4976. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4977. break;
  4978. }
  4979. if (INTEL_INFO(dev)->gen >= 4)
  4980. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  4981. if (crtc->config.sdvo_tv_clock)
  4982. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4983. else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  4984. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4985. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4986. else
  4987. dpll |= PLL_REF_INPUT_DREFCLK;
  4988. dpll |= DPLL_VCO_ENABLE;
  4989. crtc->config.dpll_hw_state.dpll = dpll;
  4990. if (INTEL_INFO(dev)->gen >= 4) {
  4991. u32 dpll_md = (crtc->config.pixel_multiplier - 1)
  4992. << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  4993. crtc->config.dpll_hw_state.dpll_md = dpll_md;
  4994. }
  4995. }
  4996. static void i8xx_update_pll(struct intel_crtc *crtc,
  4997. intel_clock_t *reduced_clock,
  4998. int num_connectors)
  4999. {
  5000. struct drm_device *dev = crtc->base.dev;
  5001. struct drm_i915_private *dev_priv = dev->dev_private;
  5002. u32 dpll;
  5003. struct dpll *clock = &crtc->config.dpll;
  5004. i9xx_update_pll_dividers(crtc, reduced_clock);
  5005. dpll = DPLL_VGA_MODE_DIS;
  5006. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) {
  5007. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5008. } else {
  5009. if (clock->p1 == 2)
  5010. dpll |= PLL_P1_DIVIDE_BY_TWO;
  5011. else
  5012. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  5013. if (clock->p2 == 4)
  5014. dpll |= PLL_P2_DIVIDE_BY_4;
  5015. }
  5016. if (!IS_I830(dev) && intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO))
  5017. dpll |= DPLL_DVO_2X_MODE;
  5018. if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) &&
  5019. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  5020. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  5021. else
  5022. dpll |= PLL_REF_INPUT_DREFCLK;
  5023. dpll |= DPLL_VCO_ENABLE;
  5024. crtc->config.dpll_hw_state.dpll = dpll;
  5025. }
  5026. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc)
  5027. {
  5028. struct drm_device *dev = intel_crtc->base.dev;
  5029. struct drm_i915_private *dev_priv = dev->dev_private;
  5030. enum pipe pipe = intel_crtc->pipe;
  5031. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5032. struct drm_display_mode *adjusted_mode =
  5033. &intel_crtc->config.adjusted_mode;
  5034. uint32_t crtc_vtotal, crtc_vblank_end;
  5035. int vsyncshift = 0;
  5036. /* We need to be careful not to changed the adjusted mode, for otherwise
  5037. * the hw state checker will get angry at the mismatch. */
  5038. crtc_vtotal = adjusted_mode->crtc_vtotal;
  5039. crtc_vblank_end = adjusted_mode->crtc_vblank_end;
  5040. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  5041. /* the chip adds 2 halflines automatically */
  5042. crtc_vtotal -= 1;
  5043. crtc_vblank_end -= 1;
  5044. if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5045. vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
  5046. else
  5047. vsyncshift = adjusted_mode->crtc_hsync_start -
  5048. adjusted_mode->crtc_htotal / 2;
  5049. if (vsyncshift < 0)
  5050. vsyncshift += adjusted_mode->crtc_htotal;
  5051. }
  5052. if (INTEL_INFO(dev)->gen > 3)
  5053. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  5054. I915_WRITE(HTOTAL(cpu_transcoder),
  5055. (adjusted_mode->crtc_hdisplay - 1) |
  5056. ((adjusted_mode->crtc_htotal - 1) << 16));
  5057. I915_WRITE(HBLANK(cpu_transcoder),
  5058. (adjusted_mode->crtc_hblank_start - 1) |
  5059. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  5060. I915_WRITE(HSYNC(cpu_transcoder),
  5061. (adjusted_mode->crtc_hsync_start - 1) |
  5062. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  5063. I915_WRITE(VTOTAL(cpu_transcoder),
  5064. (adjusted_mode->crtc_vdisplay - 1) |
  5065. ((crtc_vtotal - 1) << 16));
  5066. I915_WRITE(VBLANK(cpu_transcoder),
  5067. (adjusted_mode->crtc_vblank_start - 1) |
  5068. ((crtc_vblank_end - 1) << 16));
  5069. I915_WRITE(VSYNC(cpu_transcoder),
  5070. (adjusted_mode->crtc_vsync_start - 1) |
  5071. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  5072. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  5073. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  5074. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  5075. * bits. */
  5076. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  5077. (pipe == PIPE_B || pipe == PIPE_C))
  5078. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  5079. /* pipesrc controls the size that is scaled from, which should
  5080. * always be the user's requested size.
  5081. */
  5082. I915_WRITE(PIPESRC(pipe),
  5083. ((intel_crtc->config.pipe_src_w - 1) << 16) |
  5084. (intel_crtc->config.pipe_src_h - 1));
  5085. }
  5086. static void intel_get_pipe_timings(struct intel_crtc *crtc,
  5087. struct intel_crtc_config *pipe_config)
  5088. {
  5089. struct drm_device *dev = crtc->base.dev;
  5090. struct drm_i915_private *dev_priv = dev->dev_private;
  5091. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  5092. uint32_t tmp;
  5093. tmp = I915_READ(HTOTAL(cpu_transcoder));
  5094. pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
  5095. pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
  5096. tmp = I915_READ(HBLANK(cpu_transcoder));
  5097. pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
  5098. pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
  5099. tmp = I915_READ(HSYNC(cpu_transcoder));
  5100. pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
  5101. pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
  5102. tmp = I915_READ(VTOTAL(cpu_transcoder));
  5103. pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
  5104. pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
  5105. tmp = I915_READ(VBLANK(cpu_transcoder));
  5106. pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
  5107. pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
  5108. tmp = I915_READ(VSYNC(cpu_transcoder));
  5109. pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
  5110. pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
  5111. if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
  5112. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  5113. pipe_config->adjusted_mode.crtc_vtotal += 1;
  5114. pipe_config->adjusted_mode.crtc_vblank_end += 1;
  5115. }
  5116. tmp = I915_READ(PIPESRC(crtc->pipe));
  5117. pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
  5118. pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
  5119. pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h;
  5120. pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w;
  5121. }
  5122. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  5123. struct intel_crtc_config *pipe_config)
  5124. {
  5125. mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay;
  5126. mode->htotal = pipe_config->adjusted_mode.crtc_htotal;
  5127. mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start;
  5128. mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end;
  5129. mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay;
  5130. mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal;
  5131. mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start;
  5132. mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end;
  5133. mode->flags = pipe_config->adjusted_mode.flags;
  5134. mode->clock = pipe_config->adjusted_mode.crtc_clock;
  5135. mode->flags |= pipe_config->adjusted_mode.flags;
  5136. }
  5137. static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc)
  5138. {
  5139. struct drm_device *dev = intel_crtc->base.dev;
  5140. struct drm_i915_private *dev_priv = dev->dev_private;
  5141. uint32_t pipeconf;
  5142. pipeconf = 0;
  5143. if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  5144. (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  5145. pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE;
  5146. if (intel_crtc->config.double_wide)
  5147. pipeconf |= PIPECONF_DOUBLE_WIDE;
  5148. /* only g4x and later have fancy bpc/dither controls */
  5149. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5150. /* Bspec claims that we can't use dithering for 30bpp pipes. */
  5151. if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30)
  5152. pipeconf |= PIPECONF_DITHER_EN |
  5153. PIPECONF_DITHER_TYPE_SP;
  5154. switch (intel_crtc->config.pipe_bpp) {
  5155. case 18:
  5156. pipeconf |= PIPECONF_6BPC;
  5157. break;
  5158. case 24:
  5159. pipeconf |= PIPECONF_8BPC;
  5160. break;
  5161. case 30:
  5162. pipeconf |= PIPECONF_10BPC;
  5163. break;
  5164. default:
  5165. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5166. BUG();
  5167. }
  5168. }
  5169. if (HAS_PIPE_CXSR(dev)) {
  5170. if (intel_crtc->lowfreq_avail) {
  5171. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  5172. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  5173. } else {
  5174. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  5175. }
  5176. }
  5177. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  5178. if (INTEL_INFO(dev)->gen < 4 ||
  5179. intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO))
  5180. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  5181. else
  5182. pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
  5183. } else
  5184. pipeconf |= PIPECONF_PROGRESSIVE;
  5185. if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range)
  5186. pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
  5187. I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf);
  5188. POSTING_READ(PIPECONF(intel_crtc->pipe));
  5189. }
  5190. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  5191. int x, int y,
  5192. struct drm_framebuffer *fb)
  5193. {
  5194. struct drm_device *dev = crtc->dev;
  5195. struct drm_i915_private *dev_priv = dev->dev_private;
  5196. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5197. int refclk, num_connectors = 0;
  5198. intel_clock_t clock, reduced_clock;
  5199. bool ok, has_reduced_clock = false;
  5200. bool is_lvds = false, is_dsi = false;
  5201. struct intel_encoder *encoder;
  5202. const intel_limit_t *limit;
  5203. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5204. switch (encoder->type) {
  5205. case INTEL_OUTPUT_LVDS:
  5206. is_lvds = true;
  5207. break;
  5208. case INTEL_OUTPUT_DSI:
  5209. is_dsi = true;
  5210. break;
  5211. }
  5212. num_connectors++;
  5213. }
  5214. if (is_dsi)
  5215. return 0;
  5216. if (!intel_crtc->config.clock_set) {
  5217. refclk = i9xx_get_refclk(crtc, num_connectors);
  5218. /*
  5219. * Returns a set of divisors for the desired target clock with
  5220. * the given refclk, or FALSE. The returned values represent
  5221. * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n +
  5222. * 2) / p1 / p2.
  5223. */
  5224. limit = intel_limit(crtc, refclk);
  5225. ok = dev_priv->display.find_dpll(limit, crtc,
  5226. intel_crtc->config.port_clock,
  5227. refclk, NULL, &clock);
  5228. if (!ok) {
  5229. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  5230. return -EINVAL;
  5231. }
  5232. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5233. /*
  5234. * Ensure we match the reduced clock's P to the target
  5235. * clock. If the clocks don't match, we can't switch
  5236. * the display clock by using the FP0/FP1. In such case
  5237. * we will disable the LVDS downclock feature.
  5238. */
  5239. has_reduced_clock =
  5240. dev_priv->display.find_dpll(limit, crtc,
  5241. dev_priv->lvds_downclock,
  5242. refclk, &clock,
  5243. &reduced_clock);
  5244. }
  5245. /* Compat-code for transition, will disappear. */
  5246. intel_crtc->config.dpll.n = clock.n;
  5247. intel_crtc->config.dpll.m1 = clock.m1;
  5248. intel_crtc->config.dpll.m2 = clock.m2;
  5249. intel_crtc->config.dpll.p1 = clock.p1;
  5250. intel_crtc->config.dpll.p2 = clock.p2;
  5251. }
  5252. if (IS_GEN2(dev)) {
  5253. i8xx_update_pll(intel_crtc,
  5254. has_reduced_clock ? &reduced_clock : NULL,
  5255. num_connectors);
  5256. } else if (IS_CHERRYVIEW(dev)) {
  5257. chv_update_pll(intel_crtc);
  5258. } else if (IS_VALLEYVIEW(dev)) {
  5259. vlv_update_pll(intel_crtc);
  5260. } else {
  5261. i9xx_update_pll(intel_crtc,
  5262. has_reduced_clock ? &reduced_clock : NULL,
  5263. num_connectors);
  5264. }
  5265. return 0;
  5266. }
  5267. static void i9xx_get_pfit_config(struct intel_crtc *crtc,
  5268. struct intel_crtc_config *pipe_config)
  5269. {
  5270. struct drm_device *dev = crtc->base.dev;
  5271. struct drm_i915_private *dev_priv = dev->dev_private;
  5272. uint32_t tmp;
  5273. if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev)))
  5274. return;
  5275. tmp = I915_READ(PFIT_CONTROL);
  5276. if (!(tmp & PFIT_ENABLE))
  5277. return;
  5278. /* Check whether the pfit is attached to our pipe. */
  5279. if (INTEL_INFO(dev)->gen < 4) {
  5280. if (crtc->pipe != PIPE_B)
  5281. return;
  5282. } else {
  5283. if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
  5284. return;
  5285. }
  5286. pipe_config->gmch_pfit.control = tmp;
  5287. pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
  5288. if (INTEL_INFO(dev)->gen < 5)
  5289. pipe_config->gmch_pfit.lvds_border_bits =
  5290. I915_READ(LVDS) & LVDS_BORDER_ENABLE;
  5291. }
  5292. static void vlv_crtc_clock_get(struct intel_crtc *crtc,
  5293. struct intel_crtc_config *pipe_config)
  5294. {
  5295. struct drm_device *dev = crtc->base.dev;
  5296. struct drm_i915_private *dev_priv = dev->dev_private;
  5297. int pipe = pipe_config->cpu_transcoder;
  5298. intel_clock_t clock;
  5299. u32 mdiv;
  5300. int refclk = 100000;
  5301. /* In case of MIPI DPLL will not even be used */
  5302. if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE))
  5303. return;
  5304. mutex_lock(&dev_priv->dpio_lock);
  5305. mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
  5306. mutex_unlock(&dev_priv->dpio_lock);
  5307. clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
  5308. clock.m2 = mdiv & DPIO_M2DIV_MASK;
  5309. clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
  5310. clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
  5311. clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
  5312. vlv_clock(refclk, &clock);
  5313. /* clock.dot is the fast clock */
  5314. pipe_config->port_clock = clock.dot / 5;
  5315. }
  5316. static void i9xx_get_plane_config(struct intel_crtc *crtc,
  5317. struct intel_plane_config *plane_config)
  5318. {
  5319. struct drm_device *dev = crtc->base.dev;
  5320. struct drm_i915_private *dev_priv = dev->dev_private;
  5321. u32 val, base, offset;
  5322. int pipe = crtc->pipe, plane = crtc->plane;
  5323. int fourcc, pixel_format;
  5324. int aligned_height;
  5325. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  5326. if (!crtc->base.primary->fb) {
  5327. DRM_DEBUG_KMS("failed to alloc fb\n");
  5328. return;
  5329. }
  5330. val = I915_READ(DSPCNTR(plane));
  5331. if (INTEL_INFO(dev)->gen >= 4)
  5332. if (val & DISPPLANE_TILED)
  5333. plane_config->tiled = true;
  5334. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  5335. fourcc = intel_format_to_fourcc(pixel_format);
  5336. crtc->base.primary->fb->pixel_format = fourcc;
  5337. crtc->base.primary->fb->bits_per_pixel =
  5338. drm_format_plane_cpp(fourcc, 0) * 8;
  5339. if (INTEL_INFO(dev)->gen >= 4) {
  5340. if (plane_config->tiled)
  5341. offset = I915_READ(DSPTILEOFF(plane));
  5342. else
  5343. offset = I915_READ(DSPLINOFF(plane));
  5344. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  5345. } else {
  5346. base = I915_READ(DSPADDR(plane));
  5347. }
  5348. plane_config->base = base;
  5349. val = I915_READ(PIPESRC(pipe));
  5350. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  5351. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  5352. val = I915_READ(DSPSTRIDE(pipe));
  5353. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  5354. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  5355. plane_config->tiled);
  5356. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  5357. aligned_height);
  5358. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  5359. pipe, plane, crtc->base.primary->fb->width,
  5360. crtc->base.primary->fb->height,
  5361. crtc->base.primary->fb->bits_per_pixel, base,
  5362. crtc->base.primary->fb->pitches[0],
  5363. plane_config->size);
  5364. }
  5365. static void chv_crtc_clock_get(struct intel_crtc *crtc,
  5366. struct intel_crtc_config *pipe_config)
  5367. {
  5368. struct drm_device *dev = crtc->base.dev;
  5369. struct drm_i915_private *dev_priv = dev->dev_private;
  5370. int pipe = pipe_config->cpu_transcoder;
  5371. enum dpio_channel port = vlv_pipe_to_channel(pipe);
  5372. intel_clock_t clock;
  5373. u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2;
  5374. int refclk = 100000;
  5375. mutex_lock(&dev_priv->dpio_lock);
  5376. cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
  5377. pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
  5378. pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
  5379. pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
  5380. mutex_unlock(&dev_priv->dpio_lock);
  5381. clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
  5382. clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff);
  5383. clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
  5384. clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
  5385. clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
  5386. chv_clock(refclk, &clock);
  5387. /* clock.dot is the fast clock */
  5388. pipe_config->port_clock = clock.dot / 5;
  5389. }
  5390. static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
  5391. struct intel_crtc_config *pipe_config)
  5392. {
  5393. struct drm_device *dev = crtc->base.dev;
  5394. struct drm_i915_private *dev_priv = dev->dev_private;
  5395. uint32_t tmp;
  5396. if (!intel_display_power_enabled(dev_priv,
  5397. POWER_DOMAIN_PIPE(crtc->pipe)))
  5398. return false;
  5399. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  5400. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  5401. tmp = I915_READ(PIPECONF(crtc->pipe));
  5402. if (!(tmp & PIPECONF_ENABLE))
  5403. return false;
  5404. if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
  5405. switch (tmp & PIPECONF_BPC_MASK) {
  5406. case PIPECONF_6BPC:
  5407. pipe_config->pipe_bpp = 18;
  5408. break;
  5409. case PIPECONF_8BPC:
  5410. pipe_config->pipe_bpp = 24;
  5411. break;
  5412. case PIPECONF_10BPC:
  5413. pipe_config->pipe_bpp = 30;
  5414. break;
  5415. default:
  5416. break;
  5417. }
  5418. }
  5419. if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT))
  5420. pipe_config->limited_color_range = true;
  5421. if (INTEL_INFO(dev)->gen < 4)
  5422. pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
  5423. intel_get_pipe_timings(crtc, pipe_config);
  5424. i9xx_get_pfit_config(crtc, pipe_config);
  5425. if (INTEL_INFO(dev)->gen >= 4) {
  5426. tmp = I915_READ(DPLL_MD(crtc->pipe));
  5427. pipe_config->pixel_multiplier =
  5428. ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
  5429. >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
  5430. pipe_config->dpll_hw_state.dpll_md = tmp;
  5431. } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) {
  5432. tmp = I915_READ(DPLL(crtc->pipe));
  5433. pipe_config->pixel_multiplier =
  5434. ((tmp & SDVO_MULTIPLIER_MASK)
  5435. >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
  5436. } else {
  5437. /* Note that on i915G/GM the pixel multiplier is in the sdvo
  5438. * port and will be fixed up in the encoder->get_config
  5439. * function. */
  5440. pipe_config->pixel_multiplier = 1;
  5441. }
  5442. pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
  5443. if (!IS_VALLEYVIEW(dev)) {
  5444. /*
  5445. * DPLL_DVO_2X_MODE must be enabled for both DPLLs
  5446. * on 830. Filter it out here so that we don't
  5447. * report errors due to that.
  5448. */
  5449. if (IS_I830(dev))
  5450. pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
  5451. pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
  5452. pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
  5453. } else {
  5454. /* Mask out read-only status bits. */
  5455. pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
  5456. DPLL_PORTC_READY_MASK |
  5457. DPLL_PORTB_READY_MASK);
  5458. }
  5459. if (IS_CHERRYVIEW(dev))
  5460. chv_crtc_clock_get(crtc, pipe_config);
  5461. else if (IS_VALLEYVIEW(dev))
  5462. vlv_crtc_clock_get(crtc, pipe_config);
  5463. else
  5464. i9xx_crtc_clock_get(crtc, pipe_config);
  5465. return true;
  5466. }
  5467. static void ironlake_init_pch_refclk(struct drm_device *dev)
  5468. {
  5469. struct drm_i915_private *dev_priv = dev->dev_private;
  5470. struct intel_encoder *encoder;
  5471. u32 val, final;
  5472. bool has_lvds = false;
  5473. bool has_cpu_edp = false;
  5474. bool has_panel = false;
  5475. bool has_ck505 = false;
  5476. bool can_ssc = false;
  5477. /* We need to take the global config into account */
  5478. for_each_intel_encoder(dev, encoder) {
  5479. switch (encoder->type) {
  5480. case INTEL_OUTPUT_LVDS:
  5481. has_panel = true;
  5482. has_lvds = true;
  5483. break;
  5484. case INTEL_OUTPUT_EDP:
  5485. has_panel = true;
  5486. if (enc_to_dig_port(&encoder->base)->port == PORT_A)
  5487. has_cpu_edp = true;
  5488. break;
  5489. }
  5490. }
  5491. if (HAS_PCH_IBX(dev)) {
  5492. has_ck505 = dev_priv->vbt.display_clock_mode;
  5493. can_ssc = has_ck505;
  5494. } else {
  5495. has_ck505 = false;
  5496. can_ssc = true;
  5497. }
  5498. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n",
  5499. has_panel, has_lvds, has_ck505);
  5500. /* Ironlake: try to setup display ref clock before DPLL
  5501. * enabling. This is only under driver's control after
  5502. * PCH B stepping, previous chipset stepping should be
  5503. * ignoring this setting.
  5504. */
  5505. val = I915_READ(PCH_DREF_CONTROL);
  5506. /* As we must carefully and slowly disable/enable each source in turn,
  5507. * compute the final state we want first and check if we need to
  5508. * make any changes at all.
  5509. */
  5510. final = val;
  5511. final &= ~DREF_NONSPREAD_SOURCE_MASK;
  5512. if (has_ck505)
  5513. final |= DREF_NONSPREAD_CK505_ENABLE;
  5514. else
  5515. final |= DREF_NONSPREAD_SOURCE_ENABLE;
  5516. final &= ~DREF_SSC_SOURCE_MASK;
  5517. final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5518. final &= ~DREF_SSC1_ENABLE;
  5519. if (has_panel) {
  5520. final |= DREF_SSC_SOURCE_ENABLE;
  5521. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5522. final |= DREF_SSC1_ENABLE;
  5523. if (has_cpu_edp) {
  5524. if (intel_panel_use_ssc(dev_priv) && can_ssc)
  5525. final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5526. else
  5527. final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5528. } else
  5529. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5530. } else {
  5531. final |= DREF_SSC_SOURCE_DISABLE;
  5532. final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5533. }
  5534. if (final == val)
  5535. return;
  5536. /* Always enable nonspread source */
  5537. val &= ~DREF_NONSPREAD_SOURCE_MASK;
  5538. if (has_ck505)
  5539. val |= DREF_NONSPREAD_CK505_ENABLE;
  5540. else
  5541. val |= DREF_NONSPREAD_SOURCE_ENABLE;
  5542. if (has_panel) {
  5543. val &= ~DREF_SSC_SOURCE_MASK;
  5544. val |= DREF_SSC_SOURCE_ENABLE;
  5545. /* SSC must be turned on before enabling the CPU output */
  5546. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5547. DRM_DEBUG_KMS("Using SSC on panel\n");
  5548. val |= DREF_SSC1_ENABLE;
  5549. } else
  5550. val &= ~DREF_SSC1_ENABLE;
  5551. /* Get SSC going before enabling the outputs */
  5552. I915_WRITE(PCH_DREF_CONTROL, val);
  5553. POSTING_READ(PCH_DREF_CONTROL);
  5554. udelay(200);
  5555. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5556. /* Enable CPU source on CPU attached eDP */
  5557. if (has_cpu_edp) {
  5558. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  5559. DRM_DEBUG_KMS("Using SSC on eDP\n");
  5560. val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  5561. } else
  5562. val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  5563. } else
  5564. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5565. I915_WRITE(PCH_DREF_CONTROL, val);
  5566. POSTING_READ(PCH_DREF_CONTROL);
  5567. udelay(200);
  5568. } else {
  5569. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  5570. val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  5571. /* Turn off CPU output */
  5572. val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  5573. I915_WRITE(PCH_DREF_CONTROL, val);
  5574. POSTING_READ(PCH_DREF_CONTROL);
  5575. udelay(200);
  5576. /* Turn off the SSC source */
  5577. val &= ~DREF_SSC_SOURCE_MASK;
  5578. val |= DREF_SSC_SOURCE_DISABLE;
  5579. /* Turn off SSC1 */
  5580. val &= ~DREF_SSC1_ENABLE;
  5581. I915_WRITE(PCH_DREF_CONTROL, val);
  5582. POSTING_READ(PCH_DREF_CONTROL);
  5583. udelay(200);
  5584. }
  5585. BUG_ON(val != final);
  5586. }
  5587. static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
  5588. {
  5589. uint32_t tmp;
  5590. tmp = I915_READ(SOUTH_CHICKEN2);
  5591. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  5592. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5593. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  5594. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  5595. DRM_ERROR("FDI mPHY reset assert timeout\n");
  5596. tmp = I915_READ(SOUTH_CHICKEN2);
  5597. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  5598. I915_WRITE(SOUTH_CHICKEN2, tmp);
  5599. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  5600. FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
  5601. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  5602. }
  5603. /* WaMPhyProgramming:hsw */
  5604. static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
  5605. {
  5606. uint32_t tmp;
  5607. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  5608. tmp &= ~(0xFF << 24);
  5609. tmp |= (0x12 << 24);
  5610. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  5611. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  5612. tmp |= (1 << 11);
  5613. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  5614. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  5615. tmp |= (1 << 11);
  5616. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  5617. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  5618. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5619. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  5620. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  5621. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  5622. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  5623. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  5624. tmp &= ~(7 << 13);
  5625. tmp |= (5 << 13);
  5626. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  5627. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  5628. tmp &= ~(7 << 13);
  5629. tmp |= (5 << 13);
  5630. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  5631. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  5632. tmp &= ~0xFF;
  5633. tmp |= 0x1C;
  5634. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  5635. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  5636. tmp &= ~0xFF;
  5637. tmp |= 0x1C;
  5638. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  5639. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  5640. tmp &= ~(0xFF << 16);
  5641. tmp |= (0x1C << 16);
  5642. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  5643. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  5644. tmp &= ~(0xFF << 16);
  5645. tmp |= (0x1C << 16);
  5646. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  5647. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  5648. tmp |= (1 << 27);
  5649. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  5650. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  5651. tmp |= (1 << 27);
  5652. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  5653. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  5654. tmp &= ~(0xF << 28);
  5655. tmp |= (4 << 28);
  5656. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  5657. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  5658. tmp &= ~(0xF << 28);
  5659. tmp |= (4 << 28);
  5660. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  5661. }
  5662. /* Implements 3 different sequences from BSpec chapter "Display iCLK
  5663. * Programming" based on the parameters passed:
  5664. * - Sequence to enable CLKOUT_DP
  5665. * - Sequence to enable CLKOUT_DP without spread
  5666. * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
  5667. */
  5668. static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread,
  5669. bool with_fdi)
  5670. {
  5671. struct drm_i915_private *dev_priv = dev->dev_private;
  5672. uint32_t reg, tmp;
  5673. if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
  5674. with_spread = true;
  5675. if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE &&
  5676. with_fdi, "LP PCH doesn't have FDI\n"))
  5677. with_fdi = false;
  5678. mutex_lock(&dev_priv->dpio_lock);
  5679. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5680. tmp &= ~SBI_SSCCTL_DISABLE;
  5681. tmp |= SBI_SSCCTL_PATHALT;
  5682. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5683. udelay(24);
  5684. if (with_spread) {
  5685. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5686. tmp &= ~SBI_SSCCTL_PATHALT;
  5687. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5688. if (with_fdi) {
  5689. lpt_reset_fdi_mphy(dev_priv);
  5690. lpt_program_fdi_mphy(dev_priv);
  5691. }
  5692. }
  5693. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5694. SBI_GEN0 : SBI_DBUFF0;
  5695. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5696. tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5697. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5698. mutex_unlock(&dev_priv->dpio_lock);
  5699. }
  5700. /* Sequence to disable CLKOUT_DP */
  5701. static void lpt_disable_clkout_dp(struct drm_device *dev)
  5702. {
  5703. struct drm_i915_private *dev_priv = dev->dev_private;
  5704. uint32_t reg, tmp;
  5705. mutex_lock(&dev_priv->dpio_lock);
  5706. reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ?
  5707. SBI_GEN0 : SBI_DBUFF0;
  5708. tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
  5709. tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
  5710. intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
  5711. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  5712. if (!(tmp & SBI_SSCCTL_DISABLE)) {
  5713. if (!(tmp & SBI_SSCCTL_PATHALT)) {
  5714. tmp |= SBI_SSCCTL_PATHALT;
  5715. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5716. udelay(32);
  5717. }
  5718. tmp |= SBI_SSCCTL_DISABLE;
  5719. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  5720. }
  5721. mutex_unlock(&dev_priv->dpio_lock);
  5722. }
  5723. static void lpt_init_pch_refclk(struct drm_device *dev)
  5724. {
  5725. struct intel_encoder *encoder;
  5726. bool has_vga = false;
  5727. for_each_intel_encoder(dev, encoder) {
  5728. switch (encoder->type) {
  5729. case INTEL_OUTPUT_ANALOG:
  5730. has_vga = true;
  5731. break;
  5732. }
  5733. }
  5734. if (has_vga)
  5735. lpt_enable_clkout_dp(dev, true, true);
  5736. else
  5737. lpt_disable_clkout_dp(dev);
  5738. }
  5739. /*
  5740. * Initialize reference clocks when the driver loads
  5741. */
  5742. void intel_init_pch_refclk(struct drm_device *dev)
  5743. {
  5744. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  5745. ironlake_init_pch_refclk(dev);
  5746. else if (HAS_PCH_LPT(dev))
  5747. lpt_init_pch_refclk(dev);
  5748. }
  5749. static int ironlake_get_refclk(struct drm_crtc *crtc)
  5750. {
  5751. struct drm_device *dev = crtc->dev;
  5752. struct drm_i915_private *dev_priv = dev->dev_private;
  5753. struct intel_encoder *encoder;
  5754. int num_connectors = 0;
  5755. bool is_lvds = false;
  5756. for_each_encoder_on_crtc(dev, crtc, encoder) {
  5757. switch (encoder->type) {
  5758. case INTEL_OUTPUT_LVDS:
  5759. is_lvds = true;
  5760. break;
  5761. }
  5762. num_connectors++;
  5763. }
  5764. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  5765. DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
  5766. dev_priv->vbt.lvds_ssc_freq);
  5767. return dev_priv->vbt.lvds_ssc_freq;
  5768. }
  5769. return 120000;
  5770. }
  5771. static void ironlake_set_pipeconf(struct drm_crtc *crtc)
  5772. {
  5773. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  5774. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5775. int pipe = intel_crtc->pipe;
  5776. uint32_t val;
  5777. val = 0;
  5778. switch (intel_crtc->config.pipe_bpp) {
  5779. case 18:
  5780. val |= PIPECONF_6BPC;
  5781. break;
  5782. case 24:
  5783. val |= PIPECONF_8BPC;
  5784. break;
  5785. case 30:
  5786. val |= PIPECONF_10BPC;
  5787. break;
  5788. case 36:
  5789. val |= PIPECONF_12BPC;
  5790. break;
  5791. default:
  5792. /* Case prevented by intel_choose_pipe_bpp_dither. */
  5793. BUG();
  5794. }
  5795. if (intel_crtc->config.dither)
  5796. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5797. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5798. val |= PIPECONF_INTERLACED_ILK;
  5799. else
  5800. val |= PIPECONF_PROGRESSIVE;
  5801. if (intel_crtc->config.limited_color_range)
  5802. val |= PIPECONF_COLOR_RANGE_SELECT;
  5803. I915_WRITE(PIPECONF(pipe), val);
  5804. POSTING_READ(PIPECONF(pipe));
  5805. }
  5806. /*
  5807. * Set up the pipe CSC unit.
  5808. *
  5809. * Currently only full range RGB to limited range RGB conversion
  5810. * is supported, but eventually this should handle various
  5811. * RGB<->YCbCr scenarios as well.
  5812. */
  5813. static void intel_set_pipe_csc(struct drm_crtc *crtc)
  5814. {
  5815. struct drm_device *dev = crtc->dev;
  5816. struct drm_i915_private *dev_priv = dev->dev_private;
  5817. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5818. int pipe = intel_crtc->pipe;
  5819. uint16_t coeff = 0x7800; /* 1.0 */
  5820. /*
  5821. * TODO: Check what kind of values actually come out of the pipe
  5822. * with these coeff/postoff values and adjust to get the best
  5823. * accuracy. Perhaps we even need to take the bpc value into
  5824. * consideration.
  5825. */
  5826. if (intel_crtc->config.limited_color_range)
  5827. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  5828. /*
  5829. * GY/GU and RY/RU should be the other way around according
  5830. * to BSpec, but reality doesn't agree. Just set them up in
  5831. * a way that results in the correct picture.
  5832. */
  5833. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  5834. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  5835. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  5836. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  5837. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  5838. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  5839. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  5840. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  5841. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  5842. if (INTEL_INFO(dev)->gen > 6) {
  5843. uint16_t postoff = 0;
  5844. if (intel_crtc->config.limited_color_range)
  5845. postoff = (16 * (1 << 12) / 255) & 0x1fff;
  5846. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  5847. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  5848. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  5849. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  5850. } else {
  5851. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  5852. if (intel_crtc->config.limited_color_range)
  5853. mode |= CSC_BLACK_SCREEN_OFFSET;
  5854. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  5855. }
  5856. }
  5857. static void haswell_set_pipeconf(struct drm_crtc *crtc)
  5858. {
  5859. struct drm_device *dev = crtc->dev;
  5860. struct drm_i915_private *dev_priv = dev->dev_private;
  5861. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5862. enum pipe pipe = intel_crtc->pipe;
  5863. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  5864. uint32_t val;
  5865. val = 0;
  5866. if (IS_HASWELL(dev) && intel_crtc->config.dither)
  5867. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  5868. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
  5869. val |= PIPECONF_INTERLACED_ILK;
  5870. else
  5871. val |= PIPECONF_PROGRESSIVE;
  5872. I915_WRITE(PIPECONF(cpu_transcoder), val);
  5873. POSTING_READ(PIPECONF(cpu_transcoder));
  5874. I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT);
  5875. POSTING_READ(GAMMA_MODE(intel_crtc->pipe));
  5876. if (IS_BROADWELL(dev)) {
  5877. val = 0;
  5878. switch (intel_crtc->config.pipe_bpp) {
  5879. case 18:
  5880. val |= PIPEMISC_DITHER_6_BPC;
  5881. break;
  5882. case 24:
  5883. val |= PIPEMISC_DITHER_8_BPC;
  5884. break;
  5885. case 30:
  5886. val |= PIPEMISC_DITHER_10_BPC;
  5887. break;
  5888. case 36:
  5889. val |= PIPEMISC_DITHER_12_BPC;
  5890. break;
  5891. default:
  5892. /* Case prevented by pipe_config_set_bpp. */
  5893. BUG();
  5894. }
  5895. if (intel_crtc->config.dither)
  5896. val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
  5897. I915_WRITE(PIPEMISC(pipe), val);
  5898. }
  5899. }
  5900. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  5901. intel_clock_t *clock,
  5902. bool *has_reduced_clock,
  5903. intel_clock_t *reduced_clock)
  5904. {
  5905. struct drm_device *dev = crtc->dev;
  5906. struct drm_i915_private *dev_priv = dev->dev_private;
  5907. struct intel_encoder *intel_encoder;
  5908. int refclk;
  5909. const intel_limit_t *limit;
  5910. bool ret, is_lvds = false;
  5911. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5912. switch (intel_encoder->type) {
  5913. case INTEL_OUTPUT_LVDS:
  5914. is_lvds = true;
  5915. break;
  5916. }
  5917. }
  5918. refclk = ironlake_get_refclk(crtc);
  5919. /*
  5920. * Returns a set of divisors for the desired target clock with the given
  5921. * refclk, or FALSE. The returned values represent the clock equation:
  5922. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  5923. */
  5924. limit = intel_limit(crtc, refclk);
  5925. ret = dev_priv->display.find_dpll(limit, crtc,
  5926. to_intel_crtc(crtc)->config.port_clock,
  5927. refclk, NULL, clock);
  5928. if (!ret)
  5929. return false;
  5930. if (is_lvds && dev_priv->lvds_downclock_avail) {
  5931. /*
  5932. * Ensure we match the reduced clock's P to the target clock.
  5933. * If the clocks don't match, we can't switch the display clock
  5934. * by using the FP0/FP1. In such case we will disable the LVDS
  5935. * downclock feature.
  5936. */
  5937. *has_reduced_clock =
  5938. dev_priv->display.find_dpll(limit, crtc,
  5939. dev_priv->lvds_downclock,
  5940. refclk, clock,
  5941. reduced_clock);
  5942. }
  5943. return true;
  5944. }
  5945. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  5946. {
  5947. /*
  5948. * Account for spread spectrum to avoid
  5949. * oversubscribing the link. Max center spread
  5950. * is 2.5%; use 5% for safety's sake.
  5951. */
  5952. u32 bps = target_clock * bpp * 21 / 20;
  5953. return DIV_ROUND_UP(bps, link_bw * 8);
  5954. }
  5955. static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
  5956. {
  5957. return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
  5958. }
  5959. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  5960. u32 *fp,
  5961. intel_clock_t *reduced_clock, u32 *fp2)
  5962. {
  5963. struct drm_crtc *crtc = &intel_crtc->base;
  5964. struct drm_device *dev = crtc->dev;
  5965. struct drm_i915_private *dev_priv = dev->dev_private;
  5966. struct intel_encoder *intel_encoder;
  5967. uint32_t dpll;
  5968. int factor, num_connectors = 0;
  5969. bool is_lvds = false, is_sdvo = false;
  5970. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  5971. switch (intel_encoder->type) {
  5972. case INTEL_OUTPUT_LVDS:
  5973. is_lvds = true;
  5974. break;
  5975. case INTEL_OUTPUT_SDVO:
  5976. case INTEL_OUTPUT_HDMI:
  5977. is_sdvo = true;
  5978. break;
  5979. }
  5980. num_connectors++;
  5981. }
  5982. /* Enable autotuning of the PLL clock (if permissible) */
  5983. factor = 21;
  5984. if (is_lvds) {
  5985. if ((intel_panel_use_ssc(dev_priv) &&
  5986. dev_priv->vbt.lvds_ssc_freq == 100000) ||
  5987. (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev)))
  5988. factor = 25;
  5989. } else if (intel_crtc->config.sdvo_tv_clock)
  5990. factor = 20;
  5991. if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor))
  5992. *fp |= FP_CB_TUNE;
  5993. if (fp2 && (reduced_clock->m < factor * reduced_clock->n))
  5994. *fp2 |= FP_CB_TUNE;
  5995. dpll = 0;
  5996. if (is_lvds)
  5997. dpll |= DPLLB_MODE_LVDS;
  5998. else
  5999. dpll |= DPLLB_MODE_DAC_SERIAL;
  6000. dpll |= (intel_crtc->config.pixel_multiplier - 1)
  6001. << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  6002. if (is_sdvo)
  6003. dpll |= DPLL_SDVO_HIGH_SPEED;
  6004. if (intel_crtc->config.has_dp_encoder)
  6005. dpll |= DPLL_SDVO_HIGH_SPEED;
  6006. /* compute bitmask from p1 value */
  6007. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  6008. /* also FPA1 */
  6009. dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  6010. switch (intel_crtc->config.dpll.p2) {
  6011. case 5:
  6012. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  6013. break;
  6014. case 7:
  6015. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  6016. break;
  6017. case 10:
  6018. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  6019. break;
  6020. case 14:
  6021. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  6022. break;
  6023. }
  6024. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  6025. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  6026. else
  6027. dpll |= PLL_REF_INPUT_DREFCLK;
  6028. return dpll | DPLL_VCO_ENABLE;
  6029. }
  6030. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  6031. int x, int y,
  6032. struct drm_framebuffer *fb)
  6033. {
  6034. struct drm_device *dev = crtc->dev;
  6035. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6036. int num_connectors = 0;
  6037. intel_clock_t clock, reduced_clock;
  6038. u32 dpll = 0, fp = 0, fp2 = 0;
  6039. bool ok, has_reduced_clock = false;
  6040. bool is_lvds = false;
  6041. struct intel_encoder *encoder;
  6042. struct intel_shared_dpll *pll;
  6043. for_each_encoder_on_crtc(dev, crtc, encoder) {
  6044. switch (encoder->type) {
  6045. case INTEL_OUTPUT_LVDS:
  6046. is_lvds = true;
  6047. break;
  6048. }
  6049. num_connectors++;
  6050. }
  6051. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  6052. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  6053. ok = ironlake_compute_clocks(crtc, &clock,
  6054. &has_reduced_clock, &reduced_clock);
  6055. if (!ok && !intel_crtc->config.clock_set) {
  6056. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  6057. return -EINVAL;
  6058. }
  6059. /* Compat-code for transition, will disappear. */
  6060. if (!intel_crtc->config.clock_set) {
  6061. intel_crtc->config.dpll.n = clock.n;
  6062. intel_crtc->config.dpll.m1 = clock.m1;
  6063. intel_crtc->config.dpll.m2 = clock.m2;
  6064. intel_crtc->config.dpll.p1 = clock.p1;
  6065. intel_crtc->config.dpll.p2 = clock.p2;
  6066. }
  6067. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  6068. if (intel_crtc->config.has_pch_encoder) {
  6069. fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll);
  6070. if (has_reduced_clock)
  6071. fp2 = i9xx_dpll_compute_fp(&reduced_clock);
  6072. dpll = ironlake_compute_dpll(intel_crtc,
  6073. &fp, &reduced_clock,
  6074. has_reduced_clock ? &fp2 : NULL);
  6075. intel_crtc->config.dpll_hw_state.dpll = dpll;
  6076. intel_crtc->config.dpll_hw_state.fp0 = fp;
  6077. if (has_reduced_clock)
  6078. intel_crtc->config.dpll_hw_state.fp1 = fp2;
  6079. else
  6080. intel_crtc->config.dpll_hw_state.fp1 = fp;
  6081. pll = intel_get_shared_dpll(intel_crtc);
  6082. if (pll == NULL) {
  6083. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  6084. pipe_name(intel_crtc->pipe));
  6085. return -EINVAL;
  6086. }
  6087. } else
  6088. intel_put_shared_dpll(intel_crtc);
  6089. if (is_lvds && has_reduced_clock && i915.powersave)
  6090. intel_crtc->lowfreq_avail = true;
  6091. else
  6092. intel_crtc->lowfreq_avail = false;
  6093. return 0;
  6094. }
  6095. static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
  6096. struct intel_link_m_n *m_n)
  6097. {
  6098. struct drm_device *dev = crtc->base.dev;
  6099. struct drm_i915_private *dev_priv = dev->dev_private;
  6100. enum pipe pipe = crtc->pipe;
  6101. m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
  6102. m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
  6103. m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
  6104. & ~TU_SIZE_MASK;
  6105. m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
  6106. m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
  6107. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6108. }
  6109. static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
  6110. enum transcoder transcoder,
  6111. struct intel_link_m_n *m_n,
  6112. struct intel_link_m_n *m2_n2)
  6113. {
  6114. struct drm_device *dev = crtc->base.dev;
  6115. struct drm_i915_private *dev_priv = dev->dev_private;
  6116. enum pipe pipe = crtc->pipe;
  6117. if (INTEL_INFO(dev)->gen >= 5) {
  6118. m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
  6119. m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
  6120. m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
  6121. & ~TU_SIZE_MASK;
  6122. m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
  6123. m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
  6124. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6125. /* Read M2_N2 registers only for gen < 8 (M2_N2 available for
  6126. * gen < 8) and if DRRS is supported (to make sure the
  6127. * registers are not unnecessarily read).
  6128. */
  6129. if (m2_n2 && INTEL_INFO(dev)->gen < 8 &&
  6130. crtc->config.has_drrs) {
  6131. m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
  6132. m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
  6133. m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
  6134. & ~TU_SIZE_MASK;
  6135. m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
  6136. m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
  6137. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6138. }
  6139. } else {
  6140. m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
  6141. m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
  6142. m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
  6143. & ~TU_SIZE_MASK;
  6144. m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
  6145. m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
  6146. & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
  6147. }
  6148. }
  6149. void intel_dp_get_m_n(struct intel_crtc *crtc,
  6150. struct intel_crtc_config *pipe_config)
  6151. {
  6152. if (crtc->config.has_pch_encoder)
  6153. intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
  6154. else
  6155. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6156. &pipe_config->dp_m_n,
  6157. &pipe_config->dp_m2_n2);
  6158. }
  6159. static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
  6160. struct intel_crtc_config *pipe_config)
  6161. {
  6162. intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
  6163. &pipe_config->fdi_m_n, NULL);
  6164. }
  6165. static void ironlake_get_pfit_config(struct intel_crtc *crtc,
  6166. struct intel_crtc_config *pipe_config)
  6167. {
  6168. struct drm_device *dev = crtc->base.dev;
  6169. struct drm_i915_private *dev_priv = dev->dev_private;
  6170. uint32_t tmp;
  6171. tmp = I915_READ(PF_CTL(crtc->pipe));
  6172. if (tmp & PF_ENABLE) {
  6173. pipe_config->pch_pfit.enabled = true;
  6174. pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
  6175. pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
  6176. /* We currently do not free assignements of panel fitters on
  6177. * ivb/hsw (since we don't use the higher upscaling modes which
  6178. * differentiates them) so just WARN about this case for now. */
  6179. if (IS_GEN7(dev)) {
  6180. WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
  6181. PF_PIPE_SEL_IVB(crtc->pipe));
  6182. }
  6183. }
  6184. }
  6185. static void ironlake_get_plane_config(struct intel_crtc *crtc,
  6186. struct intel_plane_config *plane_config)
  6187. {
  6188. struct drm_device *dev = crtc->base.dev;
  6189. struct drm_i915_private *dev_priv = dev->dev_private;
  6190. u32 val, base, offset;
  6191. int pipe = crtc->pipe, plane = crtc->plane;
  6192. int fourcc, pixel_format;
  6193. int aligned_height;
  6194. crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL);
  6195. if (!crtc->base.primary->fb) {
  6196. DRM_DEBUG_KMS("failed to alloc fb\n");
  6197. return;
  6198. }
  6199. val = I915_READ(DSPCNTR(plane));
  6200. if (INTEL_INFO(dev)->gen >= 4)
  6201. if (val & DISPPLANE_TILED)
  6202. plane_config->tiled = true;
  6203. pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
  6204. fourcc = intel_format_to_fourcc(pixel_format);
  6205. crtc->base.primary->fb->pixel_format = fourcc;
  6206. crtc->base.primary->fb->bits_per_pixel =
  6207. drm_format_plane_cpp(fourcc, 0) * 8;
  6208. base = I915_READ(DSPSURF(plane)) & 0xfffff000;
  6209. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  6210. offset = I915_READ(DSPOFFSET(plane));
  6211. } else {
  6212. if (plane_config->tiled)
  6213. offset = I915_READ(DSPTILEOFF(plane));
  6214. else
  6215. offset = I915_READ(DSPLINOFF(plane));
  6216. }
  6217. plane_config->base = base;
  6218. val = I915_READ(PIPESRC(pipe));
  6219. crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1;
  6220. crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1;
  6221. val = I915_READ(DSPSTRIDE(pipe));
  6222. crtc->base.primary->fb->pitches[0] = val & 0xffffffc0;
  6223. aligned_height = intel_align_height(dev, crtc->base.primary->fb->height,
  6224. plane_config->tiled);
  6225. plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] *
  6226. aligned_height);
  6227. DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
  6228. pipe, plane, crtc->base.primary->fb->width,
  6229. crtc->base.primary->fb->height,
  6230. crtc->base.primary->fb->bits_per_pixel, base,
  6231. crtc->base.primary->fb->pitches[0],
  6232. plane_config->size);
  6233. }
  6234. static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
  6235. struct intel_crtc_config *pipe_config)
  6236. {
  6237. struct drm_device *dev = crtc->base.dev;
  6238. struct drm_i915_private *dev_priv = dev->dev_private;
  6239. uint32_t tmp;
  6240. if (!intel_display_power_enabled(dev_priv,
  6241. POWER_DOMAIN_PIPE(crtc->pipe)))
  6242. return false;
  6243. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6244. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6245. tmp = I915_READ(PIPECONF(crtc->pipe));
  6246. if (!(tmp & PIPECONF_ENABLE))
  6247. return false;
  6248. switch (tmp & PIPECONF_BPC_MASK) {
  6249. case PIPECONF_6BPC:
  6250. pipe_config->pipe_bpp = 18;
  6251. break;
  6252. case PIPECONF_8BPC:
  6253. pipe_config->pipe_bpp = 24;
  6254. break;
  6255. case PIPECONF_10BPC:
  6256. pipe_config->pipe_bpp = 30;
  6257. break;
  6258. case PIPECONF_12BPC:
  6259. pipe_config->pipe_bpp = 36;
  6260. break;
  6261. default:
  6262. break;
  6263. }
  6264. if (tmp & PIPECONF_COLOR_RANGE_SELECT)
  6265. pipe_config->limited_color_range = true;
  6266. if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
  6267. struct intel_shared_dpll *pll;
  6268. pipe_config->has_pch_encoder = true;
  6269. tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
  6270. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6271. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6272. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6273. if (HAS_PCH_IBX(dev_priv->dev)) {
  6274. pipe_config->shared_dpll =
  6275. (enum intel_dpll_id) crtc->pipe;
  6276. } else {
  6277. tmp = I915_READ(PCH_DPLL_SEL);
  6278. if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
  6279. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B;
  6280. else
  6281. pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A;
  6282. }
  6283. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6284. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6285. &pipe_config->dpll_hw_state));
  6286. tmp = pipe_config->dpll_hw_state.dpll;
  6287. pipe_config->pixel_multiplier =
  6288. ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
  6289. >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
  6290. ironlake_pch_clock_get(crtc, pipe_config);
  6291. } else {
  6292. pipe_config->pixel_multiplier = 1;
  6293. }
  6294. intel_get_pipe_timings(crtc, pipe_config);
  6295. ironlake_get_pfit_config(crtc, pipe_config);
  6296. return true;
  6297. }
  6298. static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
  6299. {
  6300. struct drm_device *dev = dev_priv->dev;
  6301. struct intel_crtc *crtc;
  6302. for_each_intel_crtc(dev, crtc)
  6303. WARN(crtc->active, "CRTC for pipe %c enabled\n",
  6304. pipe_name(crtc->pipe));
  6305. WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n");
  6306. WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
  6307. WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
  6308. WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
  6309. WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n");
  6310. WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
  6311. "CPU PWM1 enabled\n");
  6312. if (IS_HASWELL(dev))
  6313. WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
  6314. "CPU PWM2 enabled\n");
  6315. WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
  6316. "PCH PWM1 enabled\n");
  6317. WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
  6318. "Utility pin enabled\n");
  6319. WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
  6320. /*
  6321. * In theory we can still leave IRQs enabled, as long as only the HPD
  6322. * interrupts remain enabled. We used to check for that, but since it's
  6323. * gen-specific and since we only disable LCPLL after we fully disable
  6324. * the interrupts, the check below should be enough.
  6325. */
  6326. WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
  6327. }
  6328. static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
  6329. {
  6330. struct drm_device *dev = dev_priv->dev;
  6331. if (IS_HASWELL(dev))
  6332. return I915_READ(D_COMP_HSW);
  6333. else
  6334. return I915_READ(D_COMP_BDW);
  6335. }
  6336. static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
  6337. {
  6338. struct drm_device *dev = dev_priv->dev;
  6339. if (IS_HASWELL(dev)) {
  6340. mutex_lock(&dev_priv->rps.hw_lock);
  6341. if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
  6342. val))
  6343. DRM_ERROR("Failed to write to D_COMP\n");
  6344. mutex_unlock(&dev_priv->rps.hw_lock);
  6345. } else {
  6346. I915_WRITE(D_COMP_BDW, val);
  6347. POSTING_READ(D_COMP_BDW);
  6348. }
  6349. }
  6350. /*
  6351. * This function implements pieces of two sequences from BSpec:
  6352. * - Sequence for display software to disable LCPLL
  6353. * - Sequence for display software to allow package C8+
  6354. * The steps implemented here are just the steps that actually touch the LCPLL
  6355. * register. Callers should take care of disabling all the display engine
  6356. * functions, doing the mode unset, fixing interrupts, etc.
  6357. */
  6358. static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
  6359. bool switch_to_fclk, bool allow_power_down)
  6360. {
  6361. uint32_t val;
  6362. assert_can_disable_lcpll(dev_priv);
  6363. val = I915_READ(LCPLL_CTL);
  6364. if (switch_to_fclk) {
  6365. val |= LCPLL_CD_SOURCE_FCLK;
  6366. I915_WRITE(LCPLL_CTL, val);
  6367. if (wait_for_atomic_us(I915_READ(LCPLL_CTL) &
  6368. LCPLL_CD_SOURCE_FCLK_DONE, 1))
  6369. DRM_ERROR("Switching to FCLK failed\n");
  6370. val = I915_READ(LCPLL_CTL);
  6371. }
  6372. val |= LCPLL_PLL_DISABLE;
  6373. I915_WRITE(LCPLL_CTL, val);
  6374. POSTING_READ(LCPLL_CTL);
  6375. if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1))
  6376. DRM_ERROR("LCPLL still locked\n");
  6377. val = hsw_read_dcomp(dev_priv);
  6378. val |= D_COMP_COMP_DISABLE;
  6379. hsw_write_dcomp(dev_priv, val);
  6380. ndelay(100);
  6381. if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
  6382. 1))
  6383. DRM_ERROR("D_COMP RCOMP still in progress\n");
  6384. if (allow_power_down) {
  6385. val = I915_READ(LCPLL_CTL);
  6386. val |= LCPLL_POWER_DOWN_ALLOW;
  6387. I915_WRITE(LCPLL_CTL, val);
  6388. POSTING_READ(LCPLL_CTL);
  6389. }
  6390. }
  6391. /*
  6392. * Fully restores LCPLL, disallowing power down and switching back to LCPLL
  6393. * source.
  6394. */
  6395. static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
  6396. {
  6397. uint32_t val;
  6398. unsigned long irqflags;
  6399. val = I915_READ(LCPLL_CTL);
  6400. if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
  6401. LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
  6402. return;
  6403. /*
  6404. * Make sure we're not on PC8 state before disabling PC8, otherwise
  6405. * we'll hang the machine. To prevent PC8 state, just enable force_wake.
  6406. *
  6407. * The other problem is that hsw_restore_lcpll() is called as part of
  6408. * the runtime PM resume sequence, so we can't just call
  6409. * gen6_gt_force_wake_get() because that function calls
  6410. * intel_runtime_pm_get(), and we can't change the runtime PM refcount
  6411. * while we are on the resume sequence. So to solve this problem we have
  6412. * to call special forcewake code that doesn't touch runtime PM and
  6413. * doesn't enable the forcewake delayed work.
  6414. */
  6415. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6416. if (dev_priv->uncore.forcewake_count++ == 0)
  6417. dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL);
  6418. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6419. if (val & LCPLL_POWER_DOWN_ALLOW) {
  6420. val &= ~LCPLL_POWER_DOWN_ALLOW;
  6421. I915_WRITE(LCPLL_CTL, val);
  6422. POSTING_READ(LCPLL_CTL);
  6423. }
  6424. val = hsw_read_dcomp(dev_priv);
  6425. val |= D_COMP_COMP_FORCE;
  6426. val &= ~D_COMP_COMP_DISABLE;
  6427. hsw_write_dcomp(dev_priv, val);
  6428. val = I915_READ(LCPLL_CTL);
  6429. val &= ~LCPLL_PLL_DISABLE;
  6430. I915_WRITE(LCPLL_CTL, val);
  6431. if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5))
  6432. DRM_ERROR("LCPLL not locked yet\n");
  6433. if (val & LCPLL_CD_SOURCE_FCLK) {
  6434. val = I915_READ(LCPLL_CTL);
  6435. val &= ~LCPLL_CD_SOURCE_FCLK;
  6436. I915_WRITE(LCPLL_CTL, val);
  6437. if (wait_for_atomic_us((I915_READ(LCPLL_CTL) &
  6438. LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
  6439. DRM_ERROR("Switching back to LCPLL failed\n");
  6440. }
  6441. /* See the big comment above. */
  6442. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  6443. if (--dev_priv->uncore.forcewake_count == 0)
  6444. dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL);
  6445. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  6446. }
  6447. /*
  6448. * Package states C8 and deeper are really deep PC states that can only be
  6449. * reached when all the devices on the system allow it, so even if the graphics
  6450. * device allows PC8+, it doesn't mean the system will actually get to these
  6451. * states. Our driver only allows PC8+ when going into runtime PM.
  6452. *
  6453. * The requirements for PC8+ are that all the outputs are disabled, the power
  6454. * well is disabled and most interrupts are disabled, and these are also
  6455. * requirements for runtime PM. When these conditions are met, we manually do
  6456. * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
  6457. * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
  6458. * hang the machine.
  6459. *
  6460. * When we really reach PC8 or deeper states (not just when we allow it) we lose
  6461. * the state of some registers, so when we come back from PC8+ we need to
  6462. * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
  6463. * need to take care of the registers kept by RC6. Notice that this happens even
  6464. * if we don't put the device in PCI D3 state (which is what currently happens
  6465. * because of the runtime PM support).
  6466. *
  6467. * For more, read "Display Sequences for Package C8" on the hardware
  6468. * documentation.
  6469. */
  6470. void hsw_enable_pc8(struct drm_i915_private *dev_priv)
  6471. {
  6472. struct drm_device *dev = dev_priv->dev;
  6473. uint32_t val;
  6474. DRM_DEBUG_KMS("Enabling package C8+\n");
  6475. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6476. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6477. val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
  6478. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6479. }
  6480. lpt_disable_clkout_dp(dev);
  6481. hsw_disable_lcpll(dev_priv, true, true);
  6482. }
  6483. void hsw_disable_pc8(struct drm_i915_private *dev_priv)
  6484. {
  6485. struct drm_device *dev = dev_priv->dev;
  6486. uint32_t val;
  6487. DRM_DEBUG_KMS("Disabling package C8+\n");
  6488. hsw_restore_lcpll(dev_priv);
  6489. lpt_init_pch_refclk(dev);
  6490. if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) {
  6491. val = I915_READ(SOUTH_DSPCLK_GATE_D);
  6492. val |= PCH_LP_PARTITION_LEVEL_DISABLE;
  6493. I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
  6494. }
  6495. intel_prepare_ddi(dev);
  6496. }
  6497. static void snb_modeset_global_resources(struct drm_device *dev)
  6498. {
  6499. modeset_update_crtc_power_domains(dev);
  6500. }
  6501. static void haswell_modeset_global_resources(struct drm_device *dev)
  6502. {
  6503. modeset_update_crtc_power_domains(dev);
  6504. }
  6505. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  6506. int x, int y,
  6507. struct drm_framebuffer *fb)
  6508. {
  6509. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6510. if (!intel_ddi_pll_select(intel_crtc))
  6511. return -EINVAL;
  6512. intel_crtc->lowfreq_avail = false;
  6513. return 0;
  6514. }
  6515. static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
  6516. enum port port,
  6517. struct intel_crtc_config *pipe_config)
  6518. {
  6519. pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
  6520. switch (pipe_config->ddi_pll_sel) {
  6521. case PORT_CLK_SEL_WRPLL1:
  6522. pipe_config->shared_dpll = DPLL_ID_WRPLL1;
  6523. break;
  6524. case PORT_CLK_SEL_WRPLL2:
  6525. pipe_config->shared_dpll = DPLL_ID_WRPLL2;
  6526. break;
  6527. }
  6528. }
  6529. static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
  6530. struct intel_crtc_config *pipe_config)
  6531. {
  6532. struct drm_device *dev = crtc->base.dev;
  6533. struct drm_i915_private *dev_priv = dev->dev_private;
  6534. struct intel_shared_dpll *pll;
  6535. enum port port;
  6536. uint32_t tmp;
  6537. tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
  6538. port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
  6539. haswell_get_ddi_pll(dev_priv, port, pipe_config);
  6540. if (pipe_config->shared_dpll >= 0) {
  6541. pll = &dev_priv->shared_dplls[pipe_config->shared_dpll];
  6542. WARN_ON(!pll->get_hw_state(dev_priv, pll,
  6543. &pipe_config->dpll_hw_state));
  6544. }
  6545. /*
  6546. * Haswell has only FDI/PCH transcoder A. It is which is connected to
  6547. * DDI E. So just check whether this pipe is wired to DDI E and whether
  6548. * the PCH transcoder is on.
  6549. */
  6550. if ((port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
  6551. pipe_config->has_pch_encoder = true;
  6552. tmp = I915_READ(FDI_RX_CTL(PIPE_A));
  6553. pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
  6554. FDI_DP_PORT_WIDTH_SHIFT) + 1;
  6555. ironlake_get_fdi_m_n_config(crtc, pipe_config);
  6556. }
  6557. }
  6558. static bool haswell_get_pipe_config(struct intel_crtc *crtc,
  6559. struct intel_crtc_config *pipe_config)
  6560. {
  6561. struct drm_device *dev = crtc->base.dev;
  6562. struct drm_i915_private *dev_priv = dev->dev_private;
  6563. enum intel_display_power_domain pfit_domain;
  6564. uint32_t tmp;
  6565. if (!intel_display_power_enabled(dev_priv,
  6566. POWER_DOMAIN_PIPE(crtc->pipe)))
  6567. return false;
  6568. pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
  6569. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  6570. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  6571. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  6572. enum pipe trans_edp_pipe;
  6573. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  6574. default:
  6575. WARN(1, "unknown pipe linked to edp transcoder\n");
  6576. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  6577. case TRANS_DDI_EDP_INPUT_A_ON:
  6578. trans_edp_pipe = PIPE_A;
  6579. break;
  6580. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  6581. trans_edp_pipe = PIPE_B;
  6582. break;
  6583. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  6584. trans_edp_pipe = PIPE_C;
  6585. break;
  6586. }
  6587. if (trans_edp_pipe == crtc->pipe)
  6588. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  6589. }
  6590. if (!intel_display_power_enabled(dev_priv,
  6591. POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
  6592. return false;
  6593. tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
  6594. if (!(tmp & PIPECONF_ENABLE))
  6595. return false;
  6596. haswell_get_ddi_port_state(crtc, pipe_config);
  6597. intel_get_pipe_timings(crtc, pipe_config);
  6598. pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
  6599. if (intel_display_power_enabled(dev_priv, pfit_domain))
  6600. ironlake_get_pfit_config(crtc, pipe_config);
  6601. if (IS_HASWELL(dev))
  6602. pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) &&
  6603. (I915_READ(IPS_CTL) & IPS_ENABLE);
  6604. if (pipe_config->cpu_transcoder != TRANSCODER_EDP) {
  6605. pipe_config->pixel_multiplier =
  6606. I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
  6607. } else {
  6608. pipe_config->pixel_multiplier = 1;
  6609. }
  6610. return true;
  6611. }
  6612. static struct {
  6613. int clock;
  6614. u32 config;
  6615. } hdmi_audio_clock[] = {
  6616. { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
  6617. { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
  6618. { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
  6619. { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
  6620. { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
  6621. { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
  6622. { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
  6623. { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
  6624. { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
  6625. { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
  6626. };
  6627. /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */
  6628. static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode)
  6629. {
  6630. int i;
  6631. for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) {
  6632. if (mode->clock == hdmi_audio_clock[i].clock)
  6633. break;
  6634. }
  6635. if (i == ARRAY_SIZE(hdmi_audio_clock)) {
  6636. DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock);
  6637. i = 1;
  6638. }
  6639. DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n",
  6640. hdmi_audio_clock[i].clock,
  6641. hdmi_audio_clock[i].config);
  6642. return hdmi_audio_clock[i].config;
  6643. }
  6644. static bool intel_eld_uptodate(struct drm_connector *connector,
  6645. int reg_eldv, uint32_t bits_eldv,
  6646. int reg_elda, uint32_t bits_elda,
  6647. int reg_edid)
  6648. {
  6649. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6650. uint8_t *eld = connector->eld;
  6651. uint32_t i;
  6652. i = I915_READ(reg_eldv);
  6653. i &= bits_eldv;
  6654. if (!eld[0])
  6655. return !i;
  6656. if (!i)
  6657. return false;
  6658. i = I915_READ(reg_elda);
  6659. i &= ~bits_elda;
  6660. I915_WRITE(reg_elda, i);
  6661. for (i = 0; i < eld[2]; i++)
  6662. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  6663. return false;
  6664. return true;
  6665. }
  6666. static void g4x_write_eld(struct drm_connector *connector,
  6667. struct drm_crtc *crtc,
  6668. struct drm_display_mode *mode)
  6669. {
  6670. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6671. uint8_t *eld = connector->eld;
  6672. uint32_t eldv;
  6673. uint32_t len;
  6674. uint32_t i;
  6675. i = I915_READ(G4X_AUD_VID_DID);
  6676. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  6677. eldv = G4X_ELDV_DEVCL_DEVBLC;
  6678. else
  6679. eldv = G4X_ELDV_DEVCTG;
  6680. if (intel_eld_uptodate(connector,
  6681. G4X_AUD_CNTL_ST, eldv,
  6682. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  6683. G4X_HDMIW_HDMIEDID))
  6684. return;
  6685. i = I915_READ(G4X_AUD_CNTL_ST);
  6686. i &= ~(eldv | G4X_ELD_ADDR);
  6687. len = (i >> 9) & 0x1f; /* ELD buffer size */
  6688. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6689. if (!eld[0])
  6690. return;
  6691. len = min_t(uint8_t, eld[2], len);
  6692. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6693. for (i = 0; i < len; i++)
  6694. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  6695. i = I915_READ(G4X_AUD_CNTL_ST);
  6696. i |= eldv;
  6697. I915_WRITE(G4X_AUD_CNTL_ST, i);
  6698. }
  6699. static void haswell_write_eld(struct drm_connector *connector,
  6700. struct drm_crtc *crtc,
  6701. struct drm_display_mode *mode)
  6702. {
  6703. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6704. uint8_t *eld = connector->eld;
  6705. uint32_t eldv;
  6706. uint32_t i;
  6707. int len;
  6708. int pipe = to_intel_crtc(crtc)->pipe;
  6709. int tmp;
  6710. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  6711. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  6712. int aud_config = HSW_AUD_CFG(pipe);
  6713. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  6714. /* Audio output enable */
  6715. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  6716. tmp = I915_READ(aud_cntrl_st2);
  6717. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  6718. I915_WRITE(aud_cntrl_st2, tmp);
  6719. POSTING_READ(aud_cntrl_st2);
  6720. assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe);
  6721. /* Set ELD valid state */
  6722. tmp = I915_READ(aud_cntrl_st2);
  6723. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp);
  6724. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  6725. I915_WRITE(aud_cntrl_st2, tmp);
  6726. tmp = I915_READ(aud_cntrl_st2);
  6727. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp);
  6728. /* Enable HDMI mode */
  6729. tmp = I915_READ(aud_config);
  6730. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp);
  6731. /* clear N_programing_enable and N_value_index */
  6732. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  6733. I915_WRITE(aud_config, tmp);
  6734. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6735. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  6736. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6737. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6738. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6739. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6740. } else {
  6741. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6742. }
  6743. if (intel_eld_uptodate(connector,
  6744. aud_cntrl_st2, eldv,
  6745. aud_cntl_st, IBX_ELD_ADDRESS,
  6746. hdmiw_hdmiedid))
  6747. return;
  6748. i = I915_READ(aud_cntrl_st2);
  6749. i &= ~eldv;
  6750. I915_WRITE(aud_cntrl_st2, i);
  6751. if (!eld[0])
  6752. return;
  6753. i = I915_READ(aud_cntl_st);
  6754. i &= ~IBX_ELD_ADDRESS;
  6755. I915_WRITE(aud_cntl_st, i);
  6756. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  6757. DRM_DEBUG_DRIVER("port num:%d\n", i);
  6758. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6759. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6760. for (i = 0; i < len; i++)
  6761. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6762. i = I915_READ(aud_cntrl_st2);
  6763. i |= eldv;
  6764. I915_WRITE(aud_cntrl_st2, i);
  6765. }
  6766. static void ironlake_write_eld(struct drm_connector *connector,
  6767. struct drm_crtc *crtc,
  6768. struct drm_display_mode *mode)
  6769. {
  6770. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  6771. uint8_t *eld = connector->eld;
  6772. uint32_t eldv;
  6773. uint32_t i;
  6774. int len;
  6775. int hdmiw_hdmiedid;
  6776. int aud_config;
  6777. int aud_cntl_st;
  6778. int aud_cntrl_st2;
  6779. int pipe = to_intel_crtc(crtc)->pipe;
  6780. if (HAS_PCH_IBX(connector->dev)) {
  6781. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  6782. aud_config = IBX_AUD_CFG(pipe);
  6783. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  6784. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  6785. } else if (IS_VALLEYVIEW(connector->dev)) {
  6786. hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe);
  6787. aud_config = VLV_AUD_CFG(pipe);
  6788. aud_cntl_st = VLV_AUD_CNTL_ST(pipe);
  6789. aud_cntrl_st2 = VLV_AUD_CNTL_ST2;
  6790. } else {
  6791. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  6792. aud_config = CPT_AUD_CFG(pipe);
  6793. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  6794. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  6795. }
  6796. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  6797. if (IS_VALLEYVIEW(connector->dev)) {
  6798. struct intel_encoder *intel_encoder;
  6799. struct intel_digital_port *intel_dig_port;
  6800. intel_encoder = intel_attached_encoder(connector);
  6801. intel_dig_port = enc_to_dig_port(&intel_encoder->base);
  6802. i = intel_dig_port->port;
  6803. } else {
  6804. i = I915_READ(aud_cntl_st);
  6805. i = (i >> 29) & DIP_PORT_SEL_MASK;
  6806. /* DIP_Port_Select, 0x1 = PortB */
  6807. }
  6808. if (!i) {
  6809. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  6810. /* operate blindly on all ports */
  6811. eldv = IBX_ELD_VALIDB;
  6812. eldv |= IBX_ELD_VALIDB << 4;
  6813. eldv |= IBX_ELD_VALIDB << 8;
  6814. } else {
  6815. DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i));
  6816. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  6817. }
  6818. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  6819. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  6820. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  6821. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  6822. } else {
  6823. I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode));
  6824. }
  6825. if (intel_eld_uptodate(connector,
  6826. aud_cntrl_st2, eldv,
  6827. aud_cntl_st, IBX_ELD_ADDRESS,
  6828. hdmiw_hdmiedid))
  6829. return;
  6830. i = I915_READ(aud_cntrl_st2);
  6831. i &= ~eldv;
  6832. I915_WRITE(aud_cntrl_st2, i);
  6833. if (!eld[0])
  6834. return;
  6835. i = I915_READ(aud_cntl_st);
  6836. i &= ~IBX_ELD_ADDRESS;
  6837. I915_WRITE(aud_cntl_st, i);
  6838. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  6839. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  6840. for (i = 0; i < len; i++)
  6841. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  6842. i = I915_READ(aud_cntrl_st2);
  6843. i |= eldv;
  6844. I915_WRITE(aud_cntrl_st2, i);
  6845. }
  6846. void intel_write_eld(struct drm_encoder *encoder,
  6847. struct drm_display_mode *mode)
  6848. {
  6849. struct drm_crtc *crtc = encoder->crtc;
  6850. struct drm_connector *connector;
  6851. struct drm_device *dev = encoder->dev;
  6852. struct drm_i915_private *dev_priv = dev->dev_private;
  6853. connector = drm_select_eld(encoder, mode);
  6854. if (!connector)
  6855. return;
  6856. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  6857. connector->base.id,
  6858. connector->name,
  6859. connector->encoder->base.id,
  6860. connector->encoder->name);
  6861. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  6862. if (dev_priv->display.write_eld)
  6863. dev_priv->display.write_eld(connector, crtc, mode);
  6864. }
  6865. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  6866. {
  6867. struct drm_device *dev = crtc->dev;
  6868. struct drm_i915_private *dev_priv = dev->dev_private;
  6869. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6870. uint32_t cntl = 0, size = 0;
  6871. if (base) {
  6872. unsigned int width = intel_crtc->cursor_width;
  6873. unsigned int height = intel_crtc->cursor_height;
  6874. unsigned int stride = roundup_pow_of_two(width) * 4;
  6875. switch (stride) {
  6876. default:
  6877. WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
  6878. width, stride);
  6879. stride = 256;
  6880. /* fallthrough */
  6881. case 256:
  6882. case 512:
  6883. case 1024:
  6884. case 2048:
  6885. break;
  6886. }
  6887. cntl |= CURSOR_ENABLE |
  6888. CURSOR_GAMMA_ENABLE |
  6889. CURSOR_FORMAT_ARGB |
  6890. CURSOR_STRIDE(stride);
  6891. size = (height << 12) | width;
  6892. }
  6893. if (intel_crtc->cursor_cntl != 0 &&
  6894. (intel_crtc->cursor_base != base ||
  6895. intel_crtc->cursor_size != size ||
  6896. intel_crtc->cursor_cntl != cntl)) {
  6897. /* On these chipsets we can only modify the base/size/stride
  6898. * whilst the cursor is disabled.
  6899. */
  6900. I915_WRITE(_CURACNTR, 0);
  6901. POSTING_READ(_CURACNTR);
  6902. intel_crtc->cursor_cntl = 0;
  6903. }
  6904. if (intel_crtc->cursor_base != base)
  6905. I915_WRITE(_CURABASE, base);
  6906. if (intel_crtc->cursor_size != size) {
  6907. I915_WRITE(CURSIZE, size);
  6908. intel_crtc->cursor_size = size;
  6909. }
  6910. if (intel_crtc->cursor_cntl != cntl) {
  6911. I915_WRITE(_CURACNTR, cntl);
  6912. POSTING_READ(_CURACNTR);
  6913. intel_crtc->cursor_cntl = cntl;
  6914. }
  6915. }
  6916. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  6917. {
  6918. struct drm_device *dev = crtc->dev;
  6919. struct drm_i915_private *dev_priv = dev->dev_private;
  6920. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6921. int pipe = intel_crtc->pipe;
  6922. uint32_t cntl;
  6923. cntl = 0;
  6924. if (base) {
  6925. cntl = MCURSOR_GAMMA_ENABLE;
  6926. switch (intel_crtc->cursor_width) {
  6927. case 64:
  6928. cntl |= CURSOR_MODE_64_ARGB_AX;
  6929. break;
  6930. case 128:
  6931. cntl |= CURSOR_MODE_128_ARGB_AX;
  6932. break;
  6933. case 256:
  6934. cntl |= CURSOR_MODE_256_ARGB_AX;
  6935. break;
  6936. default:
  6937. WARN_ON(1);
  6938. return;
  6939. }
  6940. cntl |= pipe << 28; /* Connect to correct pipe */
  6941. }
  6942. if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  6943. cntl |= CURSOR_PIPE_CSC_ENABLE;
  6944. if (intel_crtc->cursor_cntl != cntl) {
  6945. I915_WRITE(CURCNTR(pipe), cntl);
  6946. POSTING_READ(CURCNTR(pipe));
  6947. intel_crtc->cursor_cntl = cntl;
  6948. }
  6949. /* and commit changes on next vblank */
  6950. I915_WRITE(CURBASE(pipe), base);
  6951. POSTING_READ(CURBASE(pipe));
  6952. }
  6953. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  6954. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  6955. bool on)
  6956. {
  6957. struct drm_device *dev = crtc->dev;
  6958. struct drm_i915_private *dev_priv = dev->dev_private;
  6959. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6960. int pipe = intel_crtc->pipe;
  6961. int x = crtc->cursor_x;
  6962. int y = crtc->cursor_y;
  6963. u32 base = 0, pos = 0;
  6964. if (on)
  6965. base = intel_crtc->cursor_addr;
  6966. if (x >= intel_crtc->config.pipe_src_w)
  6967. base = 0;
  6968. if (y >= intel_crtc->config.pipe_src_h)
  6969. base = 0;
  6970. if (x < 0) {
  6971. if (x + intel_crtc->cursor_width <= 0)
  6972. base = 0;
  6973. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  6974. x = -x;
  6975. }
  6976. pos |= x << CURSOR_X_SHIFT;
  6977. if (y < 0) {
  6978. if (y + intel_crtc->cursor_height <= 0)
  6979. base = 0;
  6980. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  6981. y = -y;
  6982. }
  6983. pos |= y << CURSOR_Y_SHIFT;
  6984. if (base == 0 && intel_crtc->cursor_base == 0)
  6985. return;
  6986. I915_WRITE(CURPOS(pipe), pos);
  6987. if (IS_845G(dev) || IS_I865G(dev))
  6988. i845_update_cursor(crtc, base);
  6989. else
  6990. i9xx_update_cursor(crtc, base);
  6991. intel_crtc->cursor_base = base;
  6992. }
  6993. static bool cursor_size_ok(struct drm_device *dev,
  6994. uint32_t width, uint32_t height)
  6995. {
  6996. if (width == 0 || height == 0)
  6997. return false;
  6998. /*
  6999. * 845g/865g are special in that they are only limited by
  7000. * the width of their cursors, the height is arbitrary up to
  7001. * the precision of the register. Everything else requires
  7002. * square cursors, limited to a few power-of-two sizes.
  7003. */
  7004. if (IS_845G(dev) || IS_I865G(dev)) {
  7005. if ((width & 63) != 0)
  7006. return false;
  7007. if (width > (IS_845G(dev) ? 64 : 512))
  7008. return false;
  7009. if (height > 1023)
  7010. return false;
  7011. } else {
  7012. switch (width | height) {
  7013. case 256:
  7014. case 128:
  7015. if (IS_GEN2(dev))
  7016. return false;
  7017. case 64:
  7018. break;
  7019. default:
  7020. return false;
  7021. }
  7022. }
  7023. return true;
  7024. }
  7025. /*
  7026. * intel_crtc_cursor_set_obj - Set cursor to specified GEM object
  7027. *
  7028. * Note that the object's reference will be consumed if the update fails. If
  7029. * the update succeeds, the reference of the old object (if any) will be
  7030. * consumed.
  7031. */
  7032. static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc,
  7033. struct drm_i915_gem_object *obj,
  7034. uint32_t width, uint32_t height)
  7035. {
  7036. struct drm_device *dev = crtc->dev;
  7037. struct drm_i915_private *dev_priv = dev->dev_private;
  7038. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7039. enum pipe pipe = intel_crtc->pipe;
  7040. unsigned old_width, stride;
  7041. uint32_t addr;
  7042. int ret;
  7043. /* if we want to turn off the cursor ignore width and height */
  7044. if (!obj) {
  7045. DRM_DEBUG_KMS("cursor off\n");
  7046. addr = 0;
  7047. mutex_lock(&dev->struct_mutex);
  7048. goto finish;
  7049. }
  7050. /* Check for which cursor types we support */
  7051. if (!cursor_size_ok(dev, width, height)) {
  7052. DRM_DEBUG("Cursor dimension not supported\n");
  7053. return -EINVAL;
  7054. }
  7055. stride = roundup_pow_of_two(width) * 4;
  7056. if (obj->base.size < stride * height) {
  7057. DRM_DEBUG_KMS("buffer is too small\n");
  7058. ret = -ENOMEM;
  7059. goto fail;
  7060. }
  7061. /* we only need to pin inside GTT if cursor is non-phy */
  7062. mutex_lock(&dev->struct_mutex);
  7063. if (!INTEL_INFO(dev)->cursor_needs_physical) {
  7064. unsigned alignment;
  7065. if (obj->tiling_mode) {
  7066. DRM_DEBUG_KMS("cursor cannot be tiled\n");
  7067. ret = -EINVAL;
  7068. goto fail_locked;
  7069. }
  7070. /*
  7071. * Global gtt pte registers are special registers which actually
  7072. * forward writes to a chunk of system memory. Which means that
  7073. * there is no risk that the register values disappear as soon
  7074. * as we call intel_runtime_pm_put(), so it is correct to wrap
  7075. * only the pin/unpin/fence and not more.
  7076. */
  7077. intel_runtime_pm_get(dev_priv);
  7078. /* Note that the w/a also requires 2 PTE of padding following
  7079. * the bo. We currently fill all unused PTE with the shadow
  7080. * page and so we should always have valid PTE following the
  7081. * cursor preventing the VT-d warning.
  7082. */
  7083. alignment = 0;
  7084. if (need_vtd_wa(dev))
  7085. alignment = 64*1024;
  7086. ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL);
  7087. if (ret) {
  7088. DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n");
  7089. intel_runtime_pm_put(dev_priv);
  7090. goto fail_locked;
  7091. }
  7092. ret = i915_gem_object_put_fence(obj);
  7093. if (ret) {
  7094. DRM_DEBUG_KMS("failed to release fence for cursor");
  7095. intel_runtime_pm_put(dev_priv);
  7096. goto fail_unpin;
  7097. }
  7098. addr = i915_gem_obj_ggtt_offset(obj);
  7099. intel_runtime_pm_put(dev_priv);
  7100. } else {
  7101. int align = IS_I830(dev) ? 16 * 1024 : 256;
  7102. ret = i915_gem_object_attach_phys(obj, align);
  7103. if (ret) {
  7104. DRM_DEBUG_KMS("failed to attach phys object\n");
  7105. goto fail_locked;
  7106. }
  7107. addr = obj->phys_handle->busaddr;
  7108. }
  7109. finish:
  7110. if (intel_crtc->cursor_bo) {
  7111. if (!INTEL_INFO(dev)->cursor_needs_physical)
  7112. i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
  7113. }
  7114. i915_gem_track_fb(intel_crtc->cursor_bo, obj,
  7115. INTEL_FRONTBUFFER_CURSOR(pipe));
  7116. mutex_unlock(&dev->struct_mutex);
  7117. old_width = intel_crtc->cursor_width;
  7118. intel_crtc->cursor_addr = addr;
  7119. intel_crtc->cursor_bo = obj;
  7120. intel_crtc->cursor_width = width;
  7121. intel_crtc->cursor_height = height;
  7122. if (intel_crtc->active) {
  7123. if (old_width != width)
  7124. intel_update_watermarks(crtc);
  7125. intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
  7126. }
  7127. intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe));
  7128. return 0;
  7129. fail_unpin:
  7130. i915_gem_object_unpin_from_display_plane(obj);
  7131. fail_locked:
  7132. mutex_unlock(&dev->struct_mutex);
  7133. fail:
  7134. drm_gem_object_unreference_unlocked(&obj->base);
  7135. return ret;
  7136. }
  7137. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  7138. u16 *blue, uint32_t start, uint32_t size)
  7139. {
  7140. int end = (start + size > 256) ? 256 : start + size, i;
  7141. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7142. for (i = start; i < end; i++) {
  7143. intel_crtc->lut_r[i] = red[i] >> 8;
  7144. intel_crtc->lut_g[i] = green[i] >> 8;
  7145. intel_crtc->lut_b[i] = blue[i] >> 8;
  7146. }
  7147. intel_crtc_load_lut(crtc);
  7148. }
  7149. /* VESA 640x480x72Hz mode to set on the pipe */
  7150. static struct drm_display_mode load_detect_mode = {
  7151. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  7152. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  7153. };
  7154. struct drm_framebuffer *
  7155. __intel_framebuffer_create(struct drm_device *dev,
  7156. struct drm_mode_fb_cmd2 *mode_cmd,
  7157. struct drm_i915_gem_object *obj)
  7158. {
  7159. struct intel_framebuffer *intel_fb;
  7160. int ret;
  7161. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  7162. if (!intel_fb) {
  7163. drm_gem_object_unreference_unlocked(&obj->base);
  7164. return ERR_PTR(-ENOMEM);
  7165. }
  7166. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  7167. if (ret)
  7168. goto err;
  7169. return &intel_fb->base;
  7170. err:
  7171. drm_gem_object_unreference_unlocked(&obj->base);
  7172. kfree(intel_fb);
  7173. return ERR_PTR(ret);
  7174. }
  7175. static struct drm_framebuffer *
  7176. intel_framebuffer_create(struct drm_device *dev,
  7177. struct drm_mode_fb_cmd2 *mode_cmd,
  7178. struct drm_i915_gem_object *obj)
  7179. {
  7180. struct drm_framebuffer *fb;
  7181. int ret;
  7182. ret = i915_mutex_lock_interruptible(dev);
  7183. if (ret)
  7184. return ERR_PTR(ret);
  7185. fb = __intel_framebuffer_create(dev, mode_cmd, obj);
  7186. mutex_unlock(&dev->struct_mutex);
  7187. return fb;
  7188. }
  7189. static u32
  7190. intel_framebuffer_pitch_for_width(int width, int bpp)
  7191. {
  7192. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  7193. return ALIGN(pitch, 64);
  7194. }
  7195. static u32
  7196. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  7197. {
  7198. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  7199. return PAGE_ALIGN(pitch * mode->vdisplay);
  7200. }
  7201. static struct drm_framebuffer *
  7202. intel_framebuffer_create_for_mode(struct drm_device *dev,
  7203. struct drm_display_mode *mode,
  7204. int depth, int bpp)
  7205. {
  7206. struct drm_i915_gem_object *obj;
  7207. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  7208. obj = i915_gem_alloc_object(dev,
  7209. intel_framebuffer_size_for_mode(mode, bpp));
  7210. if (obj == NULL)
  7211. return ERR_PTR(-ENOMEM);
  7212. mode_cmd.width = mode->hdisplay;
  7213. mode_cmd.height = mode->vdisplay;
  7214. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  7215. bpp);
  7216. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  7217. return intel_framebuffer_create(dev, &mode_cmd, obj);
  7218. }
  7219. static struct drm_framebuffer *
  7220. mode_fits_in_fbdev(struct drm_device *dev,
  7221. struct drm_display_mode *mode)
  7222. {
  7223. #ifdef CONFIG_DRM_I915_FBDEV
  7224. struct drm_i915_private *dev_priv = dev->dev_private;
  7225. struct drm_i915_gem_object *obj;
  7226. struct drm_framebuffer *fb;
  7227. if (!dev_priv->fbdev)
  7228. return NULL;
  7229. if (!dev_priv->fbdev->fb)
  7230. return NULL;
  7231. obj = dev_priv->fbdev->fb->obj;
  7232. BUG_ON(!obj);
  7233. fb = &dev_priv->fbdev->fb->base;
  7234. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  7235. fb->bits_per_pixel))
  7236. return NULL;
  7237. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  7238. return NULL;
  7239. return fb;
  7240. #else
  7241. return NULL;
  7242. #endif
  7243. }
  7244. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  7245. struct drm_display_mode *mode,
  7246. struct intel_load_detect_pipe *old,
  7247. struct drm_modeset_acquire_ctx *ctx)
  7248. {
  7249. struct intel_crtc *intel_crtc;
  7250. struct intel_encoder *intel_encoder =
  7251. intel_attached_encoder(connector);
  7252. struct drm_crtc *possible_crtc;
  7253. struct drm_encoder *encoder = &intel_encoder->base;
  7254. struct drm_crtc *crtc = NULL;
  7255. struct drm_device *dev = encoder->dev;
  7256. struct drm_framebuffer *fb;
  7257. struct drm_mode_config *config = &dev->mode_config;
  7258. int ret, i = -1;
  7259. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7260. connector->base.id, connector->name,
  7261. encoder->base.id, encoder->name);
  7262. retry:
  7263. ret = drm_modeset_lock(&config->connection_mutex, ctx);
  7264. if (ret)
  7265. goto fail_unlock;
  7266. /*
  7267. * Algorithm gets a little messy:
  7268. *
  7269. * - if the connector already has an assigned crtc, use it (but make
  7270. * sure it's on first)
  7271. *
  7272. * - try to find the first unused crtc that can drive this connector,
  7273. * and use that if we find one
  7274. */
  7275. /* See if we already have a CRTC for this connector */
  7276. if (encoder->crtc) {
  7277. crtc = encoder->crtc;
  7278. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7279. if (ret)
  7280. goto fail_unlock;
  7281. old->dpms_mode = connector->dpms;
  7282. old->load_detect_temp = false;
  7283. /* Make sure the crtc and connector are running */
  7284. if (connector->dpms != DRM_MODE_DPMS_ON)
  7285. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  7286. return true;
  7287. }
  7288. /* Find an unused one (if possible) */
  7289. for_each_crtc(dev, possible_crtc) {
  7290. i++;
  7291. if (!(encoder->possible_crtcs & (1 << i)))
  7292. continue;
  7293. if (possible_crtc->enabled)
  7294. continue;
  7295. /* This can occur when applying the pipe A quirk on resume. */
  7296. if (to_intel_crtc(possible_crtc)->new_enabled)
  7297. continue;
  7298. crtc = possible_crtc;
  7299. break;
  7300. }
  7301. /*
  7302. * If we didn't find an unused CRTC, don't use any.
  7303. */
  7304. if (!crtc) {
  7305. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  7306. goto fail_unlock;
  7307. }
  7308. ret = drm_modeset_lock(&crtc->mutex, ctx);
  7309. if (ret)
  7310. goto fail_unlock;
  7311. intel_encoder->new_crtc = to_intel_crtc(crtc);
  7312. to_intel_connector(connector)->new_encoder = intel_encoder;
  7313. intel_crtc = to_intel_crtc(crtc);
  7314. intel_crtc->new_enabled = true;
  7315. intel_crtc->new_config = &intel_crtc->config;
  7316. old->dpms_mode = connector->dpms;
  7317. old->load_detect_temp = true;
  7318. old->release_fb = NULL;
  7319. if (!mode)
  7320. mode = &load_detect_mode;
  7321. /* We need a framebuffer large enough to accommodate all accesses
  7322. * that the plane may generate whilst we perform load detection.
  7323. * We can not rely on the fbcon either being present (we get called
  7324. * during its initialisation to detect all boot displays, or it may
  7325. * not even exist) or that it is large enough to satisfy the
  7326. * requested mode.
  7327. */
  7328. fb = mode_fits_in_fbdev(dev, mode);
  7329. if (fb == NULL) {
  7330. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  7331. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  7332. old->release_fb = fb;
  7333. } else
  7334. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  7335. if (IS_ERR(fb)) {
  7336. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  7337. goto fail;
  7338. }
  7339. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  7340. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  7341. if (old->release_fb)
  7342. old->release_fb->funcs->destroy(old->release_fb);
  7343. goto fail;
  7344. }
  7345. /* let the connector get through one full cycle before testing */
  7346. intel_wait_for_vblank(dev, intel_crtc->pipe);
  7347. return true;
  7348. fail:
  7349. intel_crtc->new_enabled = crtc->enabled;
  7350. if (intel_crtc->new_enabled)
  7351. intel_crtc->new_config = &intel_crtc->config;
  7352. else
  7353. intel_crtc->new_config = NULL;
  7354. fail_unlock:
  7355. if (ret == -EDEADLK) {
  7356. drm_modeset_backoff(ctx);
  7357. goto retry;
  7358. }
  7359. return false;
  7360. }
  7361. void intel_release_load_detect_pipe(struct drm_connector *connector,
  7362. struct intel_load_detect_pipe *old)
  7363. {
  7364. struct intel_encoder *intel_encoder =
  7365. intel_attached_encoder(connector);
  7366. struct drm_encoder *encoder = &intel_encoder->base;
  7367. struct drm_crtc *crtc = encoder->crtc;
  7368. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7369. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  7370. connector->base.id, connector->name,
  7371. encoder->base.id, encoder->name);
  7372. if (old->load_detect_temp) {
  7373. to_intel_connector(connector)->new_encoder = NULL;
  7374. intel_encoder->new_crtc = NULL;
  7375. intel_crtc->new_enabled = false;
  7376. intel_crtc->new_config = NULL;
  7377. intel_set_mode(crtc, NULL, 0, 0, NULL);
  7378. if (old->release_fb) {
  7379. drm_framebuffer_unregister_private(old->release_fb);
  7380. drm_framebuffer_unreference(old->release_fb);
  7381. }
  7382. return;
  7383. }
  7384. /* Switch crtc and encoder back off if necessary */
  7385. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  7386. connector->funcs->dpms(connector, old->dpms_mode);
  7387. }
  7388. static int i9xx_pll_refclk(struct drm_device *dev,
  7389. const struct intel_crtc_config *pipe_config)
  7390. {
  7391. struct drm_i915_private *dev_priv = dev->dev_private;
  7392. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7393. if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
  7394. return dev_priv->vbt.lvds_ssc_freq;
  7395. else if (HAS_PCH_SPLIT(dev))
  7396. return 120000;
  7397. else if (!IS_GEN2(dev))
  7398. return 96000;
  7399. else
  7400. return 48000;
  7401. }
  7402. /* Returns the clock of the currently programmed mode of the given pipe. */
  7403. static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
  7404. struct intel_crtc_config *pipe_config)
  7405. {
  7406. struct drm_device *dev = crtc->base.dev;
  7407. struct drm_i915_private *dev_priv = dev->dev_private;
  7408. int pipe = pipe_config->cpu_transcoder;
  7409. u32 dpll = pipe_config->dpll_hw_state.dpll;
  7410. u32 fp;
  7411. intel_clock_t clock;
  7412. int refclk = i9xx_pll_refclk(dev, pipe_config);
  7413. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  7414. fp = pipe_config->dpll_hw_state.fp0;
  7415. else
  7416. fp = pipe_config->dpll_hw_state.fp1;
  7417. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  7418. if (IS_PINEVIEW(dev)) {
  7419. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  7420. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7421. } else {
  7422. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  7423. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  7424. }
  7425. if (!IS_GEN2(dev)) {
  7426. if (IS_PINEVIEW(dev))
  7427. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  7428. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  7429. else
  7430. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  7431. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7432. switch (dpll & DPLL_MODE_MASK) {
  7433. case DPLLB_MODE_DAC_SERIAL:
  7434. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  7435. 5 : 10;
  7436. break;
  7437. case DPLLB_MODE_LVDS:
  7438. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  7439. 7 : 14;
  7440. break;
  7441. default:
  7442. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  7443. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  7444. return;
  7445. }
  7446. if (IS_PINEVIEW(dev))
  7447. pineview_clock(refclk, &clock);
  7448. else
  7449. i9xx_clock(refclk, &clock);
  7450. } else {
  7451. u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS);
  7452. bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
  7453. if (is_lvds) {
  7454. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  7455. DPLL_FPA01_P1_POST_DIV_SHIFT);
  7456. if (lvds & LVDS_CLKB_POWER_UP)
  7457. clock.p2 = 7;
  7458. else
  7459. clock.p2 = 14;
  7460. } else {
  7461. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  7462. clock.p1 = 2;
  7463. else {
  7464. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  7465. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  7466. }
  7467. if (dpll & PLL_P2_DIVIDE_BY_4)
  7468. clock.p2 = 4;
  7469. else
  7470. clock.p2 = 2;
  7471. }
  7472. i9xx_clock(refclk, &clock);
  7473. }
  7474. /*
  7475. * This value includes pixel_multiplier. We will use
  7476. * port_clock to compute adjusted_mode.crtc_clock in the
  7477. * encoder's get_config() function.
  7478. */
  7479. pipe_config->port_clock = clock.dot;
  7480. }
  7481. int intel_dotclock_calculate(int link_freq,
  7482. const struct intel_link_m_n *m_n)
  7483. {
  7484. /*
  7485. * The calculation for the data clock is:
  7486. * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
  7487. * But we want to avoid losing precison if possible, so:
  7488. * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
  7489. *
  7490. * and the link clock is simpler:
  7491. * link_clock = (m * link_clock) / n
  7492. */
  7493. if (!m_n->link_n)
  7494. return 0;
  7495. return div_u64((u64)m_n->link_m * link_freq, m_n->link_n);
  7496. }
  7497. static void ironlake_pch_clock_get(struct intel_crtc *crtc,
  7498. struct intel_crtc_config *pipe_config)
  7499. {
  7500. struct drm_device *dev = crtc->base.dev;
  7501. /* read out port_clock from the DPLL */
  7502. i9xx_crtc_clock_get(crtc, pipe_config);
  7503. /*
  7504. * This value does not include pixel_multiplier.
  7505. * We will check that port_clock and adjusted_mode.crtc_clock
  7506. * agree once we know their relationship in the encoder's
  7507. * get_config() function.
  7508. */
  7509. pipe_config->adjusted_mode.crtc_clock =
  7510. intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000,
  7511. &pipe_config->fdi_m_n);
  7512. }
  7513. /** Returns the currently programmed mode of the given pipe. */
  7514. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  7515. struct drm_crtc *crtc)
  7516. {
  7517. struct drm_i915_private *dev_priv = dev->dev_private;
  7518. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7519. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  7520. struct drm_display_mode *mode;
  7521. struct intel_crtc_config pipe_config;
  7522. int htot = I915_READ(HTOTAL(cpu_transcoder));
  7523. int hsync = I915_READ(HSYNC(cpu_transcoder));
  7524. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  7525. int vsync = I915_READ(VSYNC(cpu_transcoder));
  7526. enum pipe pipe = intel_crtc->pipe;
  7527. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  7528. if (!mode)
  7529. return NULL;
  7530. /*
  7531. * Construct a pipe_config sufficient for getting the clock info
  7532. * back out of crtc_clock_get.
  7533. *
  7534. * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need
  7535. * to use a real value here instead.
  7536. */
  7537. pipe_config.cpu_transcoder = (enum transcoder) pipe;
  7538. pipe_config.pixel_multiplier = 1;
  7539. pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe));
  7540. pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe));
  7541. pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe));
  7542. i9xx_crtc_clock_get(intel_crtc, &pipe_config);
  7543. mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier;
  7544. mode->hdisplay = (htot & 0xffff) + 1;
  7545. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  7546. mode->hsync_start = (hsync & 0xffff) + 1;
  7547. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  7548. mode->vdisplay = (vtot & 0xffff) + 1;
  7549. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  7550. mode->vsync_start = (vsync & 0xffff) + 1;
  7551. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  7552. drm_mode_set_name(mode);
  7553. return mode;
  7554. }
  7555. static void intel_increase_pllclock(struct drm_device *dev,
  7556. enum pipe pipe)
  7557. {
  7558. struct drm_i915_private *dev_priv = dev->dev_private;
  7559. int dpll_reg = DPLL(pipe);
  7560. int dpll;
  7561. if (!HAS_GMCH_DISPLAY(dev))
  7562. return;
  7563. if (!dev_priv->lvds_downclock_avail)
  7564. return;
  7565. dpll = I915_READ(dpll_reg);
  7566. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  7567. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  7568. assert_panel_unlocked(dev_priv, pipe);
  7569. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  7570. I915_WRITE(dpll_reg, dpll);
  7571. intel_wait_for_vblank(dev, pipe);
  7572. dpll = I915_READ(dpll_reg);
  7573. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  7574. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  7575. }
  7576. }
  7577. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  7578. {
  7579. struct drm_device *dev = crtc->dev;
  7580. struct drm_i915_private *dev_priv = dev->dev_private;
  7581. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7582. if (!HAS_GMCH_DISPLAY(dev))
  7583. return;
  7584. if (!dev_priv->lvds_downclock_avail)
  7585. return;
  7586. /*
  7587. * Since this is called by a timer, we should never get here in
  7588. * the manual case.
  7589. */
  7590. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  7591. int pipe = intel_crtc->pipe;
  7592. int dpll_reg = DPLL(pipe);
  7593. int dpll;
  7594. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  7595. assert_panel_unlocked(dev_priv, pipe);
  7596. dpll = I915_READ(dpll_reg);
  7597. dpll |= DISPLAY_RATE_SELECT_FPA1;
  7598. I915_WRITE(dpll_reg, dpll);
  7599. intel_wait_for_vblank(dev, pipe);
  7600. dpll = I915_READ(dpll_reg);
  7601. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  7602. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  7603. }
  7604. }
  7605. void intel_mark_busy(struct drm_device *dev)
  7606. {
  7607. struct drm_i915_private *dev_priv = dev->dev_private;
  7608. if (dev_priv->mm.busy)
  7609. return;
  7610. intel_runtime_pm_get(dev_priv);
  7611. i915_update_gfx_val(dev_priv);
  7612. dev_priv->mm.busy = true;
  7613. }
  7614. void intel_mark_idle(struct drm_device *dev)
  7615. {
  7616. struct drm_i915_private *dev_priv = dev->dev_private;
  7617. struct drm_crtc *crtc;
  7618. if (!dev_priv->mm.busy)
  7619. return;
  7620. dev_priv->mm.busy = false;
  7621. if (!i915.powersave)
  7622. goto out;
  7623. for_each_crtc(dev, crtc) {
  7624. if (!crtc->primary->fb)
  7625. continue;
  7626. intel_decrease_pllclock(crtc);
  7627. }
  7628. if (INTEL_INFO(dev)->gen >= 6)
  7629. gen6_rps_idle(dev->dev_private);
  7630. out:
  7631. intel_runtime_pm_put(dev_priv);
  7632. }
  7633. /**
  7634. * intel_mark_fb_busy - mark given planes as busy
  7635. * @dev: DRM device
  7636. * @frontbuffer_bits: bits for the affected planes
  7637. * @ring: optional ring for asynchronous commands
  7638. *
  7639. * This function gets called every time the screen contents change. It can be
  7640. * used to keep e.g. the update rate at the nominal refresh rate with DRRS.
  7641. */
  7642. static void intel_mark_fb_busy(struct drm_device *dev,
  7643. unsigned frontbuffer_bits,
  7644. struct intel_engine_cs *ring)
  7645. {
  7646. struct drm_i915_private *dev_priv = dev->dev_private;
  7647. enum pipe pipe;
  7648. if (!i915.powersave)
  7649. return;
  7650. for_each_pipe(dev_priv, pipe) {
  7651. if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe)))
  7652. continue;
  7653. intel_increase_pllclock(dev, pipe);
  7654. if (ring && intel_fbc_enabled(dev))
  7655. ring->fbc_dirty = true;
  7656. }
  7657. }
  7658. /**
  7659. * intel_fb_obj_invalidate - invalidate frontbuffer object
  7660. * @obj: GEM object to invalidate
  7661. * @ring: set for asynchronous rendering
  7662. *
  7663. * This function gets called every time rendering on the given object starts and
  7664. * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
  7665. * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed
  7666. * until the rendering completes or a flip on this frontbuffer plane is
  7667. * scheduled.
  7668. */
  7669. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  7670. struct intel_engine_cs *ring)
  7671. {
  7672. struct drm_device *dev = obj->base.dev;
  7673. struct drm_i915_private *dev_priv = dev->dev_private;
  7674. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7675. if (!obj->frontbuffer_bits)
  7676. return;
  7677. if (ring) {
  7678. mutex_lock(&dev_priv->fb_tracking.lock);
  7679. dev_priv->fb_tracking.busy_bits
  7680. |= obj->frontbuffer_bits;
  7681. dev_priv->fb_tracking.flip_bits
  7682. &= ~obj->frontbuffer_bits;
  7683. mutex_unlock(&dev_priv->fb_tracking.lock);
  7684. }
  7685. intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring);
  7686. intel_edp_psr_invalidate(dev, obj->frontbuffer_bits);
  7687. }
  7688. /**
  7689. * intel_frontbuffer_flush - flush frontbuffer
  7690. * @dev: DRM device
  7691. * @frontbuffer_bits: frontbuffer plane tracking bits
  7692. *
  7693. * This function gets called every time rendering on the given planes has
  7694. * completed and frontbuffer caching can be started again. Flushes will get
  7695. * delayed if they're blocked by some oustanding asynchronous rendering.
  7696. *
  7697. * Can be called without any locks held.
  7698. */
  7699. void intel_frontbuffer_flush(struct drm_device *dev,
  7700. unsigned frontbuffer_bits)
  7701. {
  7702. struct drm_i915_private *dev_priv = dev->dev_private;
  7703. /* Delay flushing when rings are still busy.*/
  7704. mutex_lock(&dev_priv->fb_tracking.lock);
  7705. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  7706. mutex_unlock(&dev_priv->fb_tracking.lock);
  7707. intel_mark_fb_busy(dev, frontbuffer_bits, NULL);
  7708. intel_edp_psr_flush(dev, frontbuffer_bits);
  7709. /*
  7710. * FIXME: Unconditional fbc flushing here is a rather gross hack and
  7711. * needs to be reworked into a proper frontbuffer tracking scheme like
  7712. * psr employs.
  7713. */
  7714. if (IS_BROADWELL(dev))
  7715. gen8_fbc_sw_flush(dev, FBC_REND_CACHE_CLEAN);
  7716. }
  7717. /**
  7718. * intel_fb_obj_flush - flush frontbuffer object
  7719. * @obj: GEM object to flush
  7720. * @retire: set when retiring asynchronous rendering
  7721. *
  7722. * This function gets called every time rendering on the given object has
  7723. * completed and frontbuffer caching can be started again. If @retire is true
  7724. * then any delayed flushes will be unblocked.
  7725. */
  7726. void intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  7727. bool retire)
  7728. {
  7729. struct drm_device *dev = obj->base.dev;
  7730. struct drm_i915_private *dev_priv = dev->dev_private;
  7731. unsigned frontbuffer_bits;
  7732. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  7733. if (!obj->frontbuffer_bits)
  7734. return;
  7735. frontbuffer_bits = obj->frontbuffer_bits;
  7736. if (retire) {
  7737. mutex_lock(&dev_priv->fb_tracking.lock);
  7738. /* Filter out new bits since rendering started. */
  7739. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  7740. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  7741. mutex_unlock(&dev_priv->fb_tracking.lock);
  7742. }
  7743. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7744. }
  7745. /**
  7746. * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip
  7747. * @dev: DRM device
  7748. * @frontbuffer_bits: frontbuffer plane tracking bits
  7749. *
  7750. * This function gets called after scheduling a flip on @obj. The actual
  7751. * frontbuffer flushing will be delayed until completion is signalled with
  7752. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  7753. * flush will be cancelled.
  7754. *
  7755. * Can be called without any locks held.
  7756. */
  7757. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  7758. unsigned frontbuffer_bits)
  7759. {
  7760. struct drm_i915_private *dev_priv = dev->dev_private;
  7761. mutex_lock(&dev_priv->fb_tracking.lock);
  7762. dev_priv->fb_tracking.flip_bits
  7763. |= frontbuffer_bits;
  7764. mutex_unlock(&dev_priv->fb_tracking.lock);
  7765. }
  7766. /**
  7767. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush
  7768. * @dev: DRM device
  7769. * @frontbuffer_bits: frontbuffer plane tracking bits
  7770. *
  7771. * This function gets called after the flip has been latched and will complete
  7772. * on the next vblank. It will execute the fush if it hasn't been cancalled yet.
  7773. *
  7774. * Can be called without any locks held.
  7775. */
  7776. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  7777. unsigned frontbuffer_bits)
  7778. {
  7779. struct drm_i915_private *dev_priv = dev->dev_private;
  7780. mutex_lock(&dev_priv->fb_tracking.lock);
  7781. /* Mask any cancelled flips. */
  7782. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  7783. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  7784. mutex_unlock(&dev_priv->fb_tracking.lock);
  7785. intel_frontbuffer_flush(dev, frontbuffer_bits);
  7786. }
  7787. static void intel_crtc_destroy(struct drm_crtc *crtc)
  7788. {
  7789. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7790. struct drm_device *dev = crtc->dev;
  7791. struct intel_unpin_work *work;
  7792. unsigned long flags;
  7793. spin_lock_irqsave(&dev->event_lock, flags);
  7794. work = intel_crtc->unpin_work;
  7795. intel_crtc->unpin_work = NULL;
  7796. spin_unlock_irqrestore(&dev->event_lock, flags);
  7797. if (work) {
  7798. cancel_work_sync(&work->work);
  7799. kfree(work);
  7800. }
  7801. drm_crtc_cleanup(crtc);
  7802. kfree(intel_crtc);
  7803. }
  7804. static void intel_unpin_work_fn(struct work_struct *__work)
  7805. {
  7806. struct intel_unpin_work *work =
  7807. container_of(__work, struct intel_unpin_work, work);
  7808. struct drm_device *dev = work->crtc->dev;
  7809. enum pipe pipe = to_intel_crtc(work->crtc)->pipe;
  7810. mutex_lock(&dev->struct_mutex);
  7811. intel_unpin_fb_obj(work->old_fb_obj);
  7812. drm_gem_object_unreference(&work->pending_flip_obj->base);
  7813. drm_gem_object_unreference(&work->old_fb_obj->base);
  7814. intel_update_fbc(dev);
  7815. mutex_unlock(&dev->struct_mutex);
  7816. intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  7817. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  7818. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  7819. kfree(work);
  7820. }
  7821. static void do_intel_finish_page_flip(struct drm_device *dev,
  7822. struct drm_crtc *crtc)
  7823. {
  7824. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7825. struct intel_unpin_work *work;
  7826. unsigned long flags;
  7827. /* Ignore early vblank irqs */
  7828. if (intel_crtc == NULL)
  7829. return;
  7830. spin_lock_irqsave(&dev->event_lock, flags);
  7831. work = intel_crtc->unpin_work;
  7832. /* Ensure we don't miss a work->pending update ... */
  7833. smp_rmb();
  7834. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  7835. spin_unlock_irqrestore(&dev->event_lock, flags);
  7836. return;
  7837. }
  7838. page_flip_completed(intel_crtc);
  7839. spin_unlock_irqrestore(&dev->event_lock, flags);
  7840. }
  7841. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  7842. {
  7843. struct drm_i915_private *dev_priv = dev->dev_private;
  7844. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  7845. do_intel_finish_page_flip(dev, crtc);
  7846. }
  7847. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  7848. {
  7849. struct drm_i915_private *dev_priv = dev->dev_private;
  7850. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  7851. do_intel_finish_page_flip(dev, crtc);
  7852. }
  7853. /* Is 'a' after or equal to 'b'? */
  7854. static bool g4x_flip_count_after_eq(u32 a, u32 b)
  7855. {
  7856. return !((a - b) & 0x80000000);
  7857. }
  7858. static bool page_flip_finished(struct intel_crtc *crtc)
  7859. {
  7860. struct drm_device *dev = crtc->base.dev;
  7861. struct drm_i915_private *dev_priv = dev->dev_private;
  7862. /*
  7863. * The relevant registers doen't exist on pre-ctg.
  7864. * As the flip done interrupt doesn't trigger for mmio
  7865. * flips on gmch platforms, a flip count check isn't
  7866. * really needed there. But since ctg has the registers,
  7867. * include it in the check anyway.
  7868. */
  7869. if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev))
  7870. return true;
  7871. /*
  7872. * A DSPSURFLIVE check isn't enough in case the mmio and CS flips
  7873. * used the same base address. In that case the mmio flip might
  7874. * have completed, but the CS hasn't even executed the flip yet.
  7875. *
  7876. * A flip count check isn't enough as the CS might have updated
  7877. * the base address just after start of vblank, but before we
  7878. * managed to process the interrupt. This means we'd complete the
  7879. * CS flip too soon.
  7880. *
  7881. * Combining both checks should get us a good enough result. It may
  7882. * still happen that the CS flip has been executed, but has not
  7883. * yet actually completed. But in case the base address is the same
  7884. * anyway, we don't really care.
  7885. */
  7886. return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) ==
  7887. crtc->unpin_work->gtt_offset &&
  7888. g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)),
  7889. crtc->unpin_work->flip_count);
  7890. }
  7891. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  7892. {
  7893. struct drm_i915_private *dev_priv = dev->dev_private;
  7894. struct intel_crtc *intel_crtc =
  7895. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  7896. unsigned long flags;
  7897. /* NB: An MMIO update of the plane base pointer will also
  7898. * generate a page-flip completion irq, i.e. every modeset
  7899. * is also accompanied by a spurious intel_prepare_page_flip().
  7900. */
  7901. spin_lock_irqsave(&dev->event_lock, flags);
  7902. if (intel_crtc->unpin_work && page_flip_finished(intel_crtc))
  7903. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  7904. spin_unlock_irqrestore(&dev->event_lock, flags);
  7905. }
  7906. static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  7907. {
  7908. /* Ensure that the work item is consistent when activating it ... */
  7909. smp_wmb();
  7910. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  7911. /* and that it is marked active as soon as the irq could fire. */
  7912. smp_wmb();
  7913. }
  7914. static int intel_gen2_queue_flip(struct drm_device *dev,
  7915. struct drm_crtc *crtc,
  7916. struct drm_framebuffer *fb,
  7917. struct drm_i915_gem_object *obj,
  7918. struct intel_engine_cs *ring,
  7919. uint32_t flags)
  7920. {
  7921. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7922. u32 flip_mask;
  7923. int ret;
  7924. ret = intel_ring_begin(ring, 6);
  7925. if (ret)
  7926. return ret;
  7927. /* Can't queue multiple flips, so wait for the previous
  7928. * one to finish before executing the next.
  7929. */
  7930. if (intel_crtc->plane)
  7931. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7932. else
  7933. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7934. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7935. intel_ring_emit(ring, MI_NOOP);
  7936. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7937. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7938. intel_ring_emit(ring, fb->pitches[0]);
  7939. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7940. intel_ring_emit(ring, 0); /* aux display base address, unused */
  7941. intel_mark_page_flip_active(intel_crtc);
  7942. __intel_ring_advance(ring);
  7943. return 0;
  7944. }
  7945. static int intel_gen3_queue_flip(struct drm_device *dev,
  7946. struct drm_crtc *crtc,
  7947. struct drm_framebuffer *fb,
  7948. struct drm_i915_gem_object *obj,
  7949. struct intel_engine_cs *ring,
  7950. uint32_t flags)
  7951. {
  7952. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7953. u32 flip_mask;
  7954. int ret;
  7955. ret = intel_ring_begin(ring, 6);
  7956. if (ret)
  7957. return ret;
  7958. if (intel_crtc->plane)
  7959. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  7960. else
  7961. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  7962. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  7963. intel_ring_emit(ring, MI_NOOP);
  7964. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  7965. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7966. intel_ring_emit(ring, fb->pitches[0]);
  7967. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  7968. intel_ring_emit(ring, MI_NOOP);
  7969. intel_mark_page_flip_active(intel_crtc);
  7970. __intel_ring_advance(ring);
  7971. return 0;
  7972. }
  7973. static int intel_gen4_queue_flip(struct drm_device *dev,
  7974. struct drm_crtc *crtc,
  7975. struct drm_framebuffer *fb,
  7976. struct drm_i915_gem_object *obj,
  7977. struct intel_engine_cs *ring,
  7978. uint32_t flags)
  7979. {
  7980. struct drm_i915_private *dev_priv = dev->dev_private;
  7981. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7982. uint32_t pf, pipesrc;
  7983. int ret;
  7984. ret = intel_ring_begin(ring, 4);
  7985. if (ret)
  7986. return ret;
  7987. /* i965+ uses the linear or tiled offsets from the
  7988. * Display Registers (which do not change across a page-flip)
  7989. * so we need only reprogram the base address.
  7990. */
  7991. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  7992. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  7993. intel_ring_emit(ring, fb->pitches[0]);
  7994. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset |
  7995. obj->tiling_mode);
  7996. /* XXX Enabling the panel-fitter across page-flip is so far
  7997. * untested on non-native modes, so ignore it for now.
  7998. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  7999. */
  8000. pf = 0;
  8001. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  8002. intel_ring_emit(ring, pf | pipesrc);
  8003. intel_mark_page_flip_active(intel_crtc);
  8004. __intel_ring_advance(ring);
  8005. return 0;
  8006. }
  8007. static int intel_gen6_queue_flip(struct drm_device *dev,
  8008. struct drm_crtc *crtc,
  8009. struct drm_framebuffer *fb,
  8010. struct drm_i915_gem_object *obj,
  8011. struct intel_engine_cs *ring,
  8012. uint32_t flags)
  8013. {
  8014. struct drm_i915_private *dev_priv = dev->dev_private;
  8015. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8016. uint32_t pf, pipesrc;
  8017. int ret;
  8018. ret = intel_ring_begin(ring, 4);
  8019. if (ret)
  8020. return ret;
  8021. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  8022. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  8023. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  8024. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  8025. /* Contrary to the suggestions in the documentation,
  8026. * "Enable Panel Fitter" does not seem to be required when page
  8027. * flipping with a non-native mode, and worse causes a normal
  8028. * modeset to fail.
  8029. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  8030. */
  8031. pf = 0;
  8032. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  8033. intel_ring_emit(ring, pf | pipesrc);
  8034. intel_mark_page_flip_active(intel_crtc);
  8035. __intel_ring_advance(ring);
  8036. return 0;
  8037. }
  8038. static int intel_gen7_queue_flip(struct drm_device *dev,
  8039. struct drm_crtc *crtc,
  8040. struct drm_framebuffer *fb,
  8041. struct drm_i915_gem_object *obj,
  8042. struct intel_engine_cs *ring,
  8043. uint32_t flags)
  8044. {
  8045. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8046. uint32_t plane_bit = 0;
  8047. int len, ret;
  8048. switch (intel_crtc->plane) {
  8049. case PLANE_A:
  8050. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  8051. break;
  8052. case PLANE_B:
  8053. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  8054. break;
  8055. case PLANE_C:
  8056. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  8057. break;
  8058. default:
  8059. WARN_ONCE(1, "unknown plane in flip command\n");
  8060. return -ENODEV;
  8061. }
  8062. len = 4;
  8063. if (ring->id == RCS) {
  8064. len += 6;
  8065. /*
  8066. * On Gen 8, SRM is now taking an extra dword to accommodate
  8067. * 48bits addresses, and we need a NOOP for the batch size to
  8068. * stay even.
  8069. */
  8070. if (IS_GEN8(dev))
  8071. len += 2;
  8072. }
  8073. /*
  8074. * BSpec MI_DISPLAY_FLIP for IVB:
  8075. * "The full packet must be contained within the same cache line."
  8076. *
  8077. * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same
  8078. * cacheline, if we ever start emitting more commands before
  8079. * the MI_DISPLAY_FLIP we may need to first emit everything else,
  8080. * then do the cacheline alignment, and finally emit the
  8081. * MI_DISPLAY_FLIP.
  8082. */
  8083. ret = intel_ring_cacheline_align(ring);
  8084. if (ret)
  8085. return ret;
  8086. ret = intel_ring_begin(ring, len);
  8087. if (ret)
  8088. return ret;
  8089. /* Unmask the flip-done completion message. Note that the bspec says that
  8090. * we should do this for both the BCS and RCS, and that we must not unmask
  8091. * more than one flip event at any time (or ensure that one flip message
  8092. * can be sent by waiting for flip-done prior to queueing new flips).
  8093. * Experimentation says that BCS works despite DERRMR masking all
  8094. * flip-done completion events and that unmasking all planes at once
  8095. * for the RCS also doesn't appear to drop events. Setting the DERRMR
  8096. * to zero does lead to lockups within MI_DISPLAY_FLIP.
  8097. */
  8098. if (ring->id == RCS) {
  8099. intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1));
  8100. intel_ring_emit(ring, DERRMR);
  8101. intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE |
  8102. DERRMR_PIPEB_PRI_FLIP_DONE |
  8103. DERRMR_PIPEC_PRI_FLIP_DONE));
  8104. if (IS_GEN8(dev))
  8105. intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) |
  8106. MI_SRM_LRM_GLOBAL_GTT);
  8107. else
  8108. intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) |
  8109. MI_SRM_LRM_GLOBAL_GTT);
  8110. intel_ring_emit(ring, DERRMR);
  8111. intel_ring_emit(ring, ring->scratch.gtt_offset + 256);
  8112. if (IS_GEN8(dev)) {
  8113. intel_ring_emit(ring, 0);
  8114. intel_ring_emit(ring, MI_NOOP);
  8115. }
  8116. }
  8117. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  8118. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  8119. intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset);
  8120. intel_ring_emit(ring, (MI_NOOP));
  8121. intel_mark_page_flip_active(intel_crtc);
  8122. __intel_ring_advance(ring);
  8123. return 0;
  8124. }
  8125. static bool use_mmio_flip(struct intel_engine_cs *ring,
  8126. struct drm_i915_gem_object *obj)
  8127. {
  8128. /*
  8129. * This is not being used for older platforms, because
  8130. * non-availability of flip done interrupt forces us to use
  8131. * CS flips. Older platforms derive flip done using some clever
  8132. * tricks involving the flip_pending status bits and vblank irqs.
  8133. * So using MMIO flips there would disrupt this mechanism.
  8134. */
  8135. if (ring == NULL)
  8136. return true;
  8137. if (INTEL_INFO(ring->dev)->gen < 5)
  8138. return false;
  8139. if (i915.use_mmio_flip < 0)
  8140. return false;
  8141. else if (i915.use_mmio_flip > 0)
  8142. return true;
  8143. else if (i915.enable_execlists)
  8144. return true;
  8145. else
  8146. return ring != obj->ring;
  8147. }
  8148. static void intel_do_mmio_flip(struct intel_crtc *intel_crtc)
  8149. {
  8150. struct drm_device *dev = intel_crtc->base.dev;
  8151. struct drm_i915_private *dev_priv = dev->dev_private;
  8152. struct intel_framebuffer *intel_fb =
  8153. to_intel_framebuffer(intel_crtc->base.primary->fb);
  8154. struct drm_i915_gem_object *obj = intel_fb->obj;
  8155. u32 dspcntr;
  8156. u32 reg;
  8157. intel_mark_page_flip_active(intel_crtc);
  8158. reg = DSPCNTR(intel_crtc->plane);
  8159. dspcntr = I915_READ(reg);
  8160. if (INTEL_INFO(dev)->gen >= 4) {
  8161. if (obj->tiling_mode != I915_TILING_NONE)
  8162. dspcntr |= DISPPLANE_TILED;
  8163. else
  8164. dspcntr &= ~DISPPLANE_TILED;
  8165. }
  8166. I915_WRITE(reg, dspcntr);
  8167. I915_WRITE(DSPSURF(intel_crtc->plane),
  8168. intel_crtc->unpin_work->gtt_offset);
  8169. POSTING_READ(DSPSURF(intel_crtc->plane));
  8170. }
  8171. static int intel_postpone_flip(struct drm_i915_gem_object *obj)
  8172. {
  8173. struct intel_engine_cs *ring;
  8174. int ret;
  8175. lockdep_assert_held(&obj->base.dev->struct_mutex);
  8176. if (!obj->last_write_seqno)
  8177. return 0;
  8178. ring = obj->ring;
  8179. if (i915_seqno_passed(ring->get_seqno(ring, true),
  8180. obj->last_write_seqno))
  8181. return 0;
  8182. ret = i915_gem_check_olr(ring, obj->last_write_seqno);
  8183. if (ret)
  8184. return ret;
  8185. if (WARN_ON(!ring->irq_get(ring)))
  8186. return 0;
  8187. return 1;
  8188. }
  8189. void intel_notify_mmio_flip(struct intel_engine_cs *ring)
  8190. {
  8191. struct drm_i915_private *dev_priv = to_i915(ring->dev);
  8192. struct intel_crtc *intel_crtc;
  8193. unsigned long irq_flags;
  8194. u32 seqno;
  8195. seqno = ring->get_seqno(ring, false);
  8196. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8197. for_each_intel_crtc(ring->dev, intel_crtc) {
  8198. struct intel_mmio_flip *mmio_flip;
  8199. mmio_flip = &intel_crtc->mmio_flip;
  8200. if (mmio_flip->seqno == 0)
  8201. continue;
  8202. if (ring->id != mmio_flip->ring_id)
  8203. continue;
  8204. if (i915_seqno_passed(seqno, mmio_flip->seqno)) {
  8205. intel_do_mmio_flip(intel_crtc);
  8206. mmio_flip->seqno = 0;
  8207. ring->irq_put(ring);
  8208. }
  8209. }
  8210. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8211. }
  8212. static int intel_queue_mmio_flip(struct drm_device *dev,
  8213. struct drm_crtc *crtc,
  8214. struct drm_framebuffer *fb,
  8215. struct drm_i915_gem_object *obj,
  8216. struct intel_engine_cs *ring,
  8217. uint32_t flags)
  8218. {
  8219. struct drm_i915_private *dev_priv = dev->dev_private;
  8220. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8221. unsigned long irq_flags;
  8222. int ret;
  8223. if (WARN_ON(intel_crtc->mmio_flip.seqno))
  8224. return -EBUSY;
  8225. ret = intel_postpone_flip(obj);
  8226. if (ret < 0)
  8227. return ret;
  8228. if (ret == 0) {
  8229. intel_do_mmio_flip(intel_crtc);
  8230. return 0;
  8231. }
  8232. spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags);
  8233. intel_crtc->mmio_flip.seqno = obj->last_write_seqno;
  8234. intel_crtc->mmio_flip.ring_id = obj->ring->id;
  8235. spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags);
  8236. /*
  8237. * Double check to catch cases where irq fired before
  8238. * mmio flip data was ready
  8239. */
  8240. intel_notify_mmio_flip(obj->ring);
  8241. return 0;
  8242. }
  8243. static int intel_default_queue_flip(struct drm_device *dev,
  8244. struct drm_crtc *crtc,
  8245. struct drm_framebuffer *fb,
  8246. struct drm_i915_gem_object *obj,
  8247. struct intel_engine_cs *ring,
  8248. uint32_t flags)
  8249. {
  8250. return -ENODEV;
  8251. }
  8252. static bool __intel_pageflip_stall_check(struct drm_device *dev,
  8253. struct drm_crtc *crtc)
  8254. {
  8255. struct drm_i915_private *dev_priv = dev->dev_private;
  8256. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8257. struct intel_unpin_work *work = intel_crtc->unpin_work;
  8258. u32 addr;
  8259. if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE)
  8260. return true;
  8261. if (!work->enable_stall_check)
  8262. return false;
  8263. if (work->flip_ready_vblank == 0) {
  8264. if (work->flip_queued_ring &&
  8265. !i915_seqno_passed(work->flip_queued_ring->get_seqno(work->flip_queued_ring, true),
  8266. work->flip_queued_seqno))
  8267. return false;
  8268. work->flip_ready_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8269. }
  8270. if (drm_vblank_count(dev, intel_crtc->pipe) - work->flip_ready_vblank < 3)
  8271. return false;
  8272. /* Potential stall - if we see that the flip has happened,
  8273. * assume a missed interrupt. */
  8274. if (INTEL_INFO(dev)->gen >= 4)
  8275. addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane)));
  8276. else
  8277. addr = I915_READ(DSPADDR(intel_crtc->plane));
  8278. /* There is a potential issue here with a false positive after a flip
  8279. * to the same address. We could address this by checking for a
  8280. * non-incrementing frame counter.
  8281. */
  8282. return addr == work->gtt_offset;
  8283. }
  8284. void intel_check_page_flip(struct drm_device *dev, int pipe)
  8285. {
  8286. struct drm_i915_private *dev_priv = dev->dev_private;
  8287. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  8288. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8289. unsigned long flags;
  8290. if (crtc == NULL)
  8291. return;
  8292. spin_lock_irqsave(&dev->event_lock, flags);
  8293. if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) {
  8294. WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n",
  8295. intel_crtc->unpin_work->flip_queued_vblank, drm_vblank_count(dev, pipe));
  8296. page_flip_completed(intel_crtc);
  8297. }
  8298. spin_unlock_irqrestore(&dev->event_lock, flags);
  8299. }
  8300. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  8301. struct drm_framebuffer *fb,
  8302. struct drm_pending_vblank_event *event,
  8303. uint32_t page_flip_flags)
  8304. {
  8305. struct drm_device *dev = crtc->dev;
  8306. struct drm_i915_private *dev_priv = dev->dev_private;
  8307. struct drm_framebuffer *old_fb = crtc->primary->fb;
  8308. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  8309. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  8310. enum pipe pipe = intel_crtc->pipe;
  8311. struct intel_unpin_work *work;
  8312. struct intel_engine_cs *ring;
  8313. unsigned long flags;
  8314. int ret;
  8315. /*
  8316. * drm_mode_page_flip_ioctl() should already catch this, but double
  8317. * check to be safe. In the future we may enable pageflipping from
  8318. * a disabled primary plane.
  8319. */
  8320. if (WARN_ON(intel_fb_obj(old_fb) == NULL))
  8321. return -EBUSY;
  8322. /* Can't change pixel format via MI display flips. */
  8323. if (fb->pixel_format != crtc->primary->fb->pixel_format)
  8324. return -EINVAL;
  8325. /*
  8326. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  8327. * Note that pitch changes could also affect these register.
  8328. */
  8329. if (INTEL_INFO(dev)->gen > 3 &&
  8330. (fb->offsets[0] != crtc->primary->fb->offsets[0] ||
  8331. fb->pitches[0] != crtc->primary->fb->pitches[0]))
  8332. return -EINVAL;
  8333. if (i915_terminally_wedged(&dev_priv->gpu_error))
  8334. goto out_hang;
  8335. work = kzalloc(sizeof(*work), GFP_KERNEL);
  8336. if (work == NULL)
  8337. return -ENOMEM;
  8338. work->event = event;
  8339. work->crtc = crtc;
  8340. work->old_fb_obj = intel_fb_obj(old_fb);
  8341. INIT_WORK(&work->work, intel_unpin_work_fn);
  8342. ret = drm_crtc_vblank_get(crtc);
  8343. if (ret)
  8344. goto free_work;
  8345. /* We borrow the event spin lock for protecting unpin_work */
  8346. spin_lock_irqsave(&dev->event_lock, flags);
  8347. if (intel_crtc->unpin_work) {
  8348. /* Before declaring the flip queue wedged, check if
  8349. * the hardware completed the operation behind our backs.
  8350. */
  8351. if (__intel_pageflip_stall_check(dev, crtc)) {
  8352. DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n");
  8353. page_flip_completed(intel_crtc);
  8354. } else {
  8355. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  8356. spin_unlock_irqrestore(&dev->event_lock, flags);
  8357. drm_crtc_vblank_put(crtc);
  8358. kfree(work);
  8359. return -EBUSY;
  8360. }
  8361. }
  8362. intel_crtc->unpin_work = work;
  8363. spin_unlock_irqrestore(&dev->event_lock, flags);
  8364. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  8365. flush_workqueue(dev_priv->wq);
  8366. ret = i915_mutex_lock_interruptible(dev);
  8367. if (ret)
  8368. goto cleanup;
  8369. /* Reference the objects for the scheduled work. */
  8370. drm_gem_object_reference(&work->old_fb_obj->base);
  8371. drm_gem_object_reference(&obj->base);
  8372. crtc->primary->fb = fb;
  8373. work->pending_flip_obj = obj;
  8374. atomic_inc(&intel_crtc->unpin_work_count);
  8375. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  8376. if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
  8377. work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1;
  8378. if (IS_VALLEYVIEW(dev)) {
  8379. ring = &dev_priv->ring[BCS];
  8380. if (obj->tiling_mode != work->old_fb_obj->tiling_mode)
  8381. /* vlv: DISPLAY_FLIP fails to change tiling */
  8382. ring = NULL;
  8383. } else if (IS_IVYBRIDGE(dev)) {
  8384. ring = &dev_priv->ring[BCS];
  8385. } else if (INTEL_INFO(dev)->gen >= 7) {
  8386. ring = obj->ring;
  8387. if (ring == NULL || ring->id != RCS)
  8388. ring = &dev_priv->ring[BCS];
  8389. } else {
  8390. ring = &dev_priv->ring[RCS];
  8391. }
  8392. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  8393. if (ret)
  8394. goto cleanup_pending;
  8395. work->gtt_offset =
  8396. i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset;
  8397. if (use_mmio_flip(ring, obj)) {
  8398. ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring,
  8399. page_flip_flags);
  8400. if (ret)
  8401. goto cleanup_unpin;
  8402. work->flip_queued_seqno = obj->last_write_seqno;
  8403. work->flip_queued_ring = obj->ring;
  8404. } else {
  8405. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring,
  8406. page_flip_flags);
  8407. if (ret)
  8408. goto cleanup_unpin;
  8409. work->flip_queued_seqno = intel_ring_get_seqno(ring);
  8410. work->flip_queued_ring = ring;
  8411. }
  8412. work->flip_queued_vblank = drm_vblank_count(dev, intel_crtc->pipe);
  8413. work->enable_stall_check = true;
  8414. i915_gem_track_fb(work->old_fb_obj, obj,
  8415. INTEL_FRONTBUFFER_PRIMARY(pipe));
  8416. intel_disable_fbc(dev);
  8417. intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe));
  8418. mutex_unlock(&dev->struct_mutex);
  8419. trace_i915_flip_request(intel_crtc->plane, obj);
  8420. return 0;
  8421. cleanup_unpin:
  8422. intel_unpin_fb_obj(obj);
  8423. cleanup_pending:
  8424. atomic_dec(&intel_crtc->unpin_work_count);
  8425. crtc->primary->fb = old_fb;
  8426. drm_gem_object_unreference(&work->old_fb_obj->base);
  8427. drm_gem_object_unreference(&obj->base);
  8428. mutex_unlock(&dev->struct_mutex);
  8429. cleanup:
  8430. spin_lock_irqsave(&dev->event_lock, flags);
  8431. intel_crtc->unpin_work = NULL;
  8432. spin_unlock_irqrestore(&dev->event_lock, flags);
  8433. drm_crtc_vblank_put(crtc);
  8434. free_work:
  8435. kfree(work);
  8436. if (ret == -EIO) {
  8437. out_hang:
  8438. intel_crtc_wait_for_pending_flips(crtc);
  8439. ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb);
  8440. if (ret == 0 && event) {
  8441. spin_lock_irqsave(&dev->event_lock, flags);
  8442. drm_send_vblank_event(dev, pipe, event);
  8443. spin_unlock_irqrestore(&dev->event_lock, flags);
  8444. }
  8445. }
  8446. return ret;
  8447. }
  8448. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  8449. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  8450. .load_lut = intel_crtc_load_lut,
  8451. };
  8452. /**
  8453. * intel_modeset_update_staged_output_state
  8454. *
  8455. * Updates the staged output configuration state, e.g. after we've read out the
  8456. * current hw state.
  8457. */
  8458. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  8459. {
  8460. struct intel_crtc *crtc;
  8461. struct intel_encoder *encoder;
  8462. struct intel_connector *connector;
  8463. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8464. base.head) {
  8465. connector->new_encoder =
  8466. to_intel_encoder(connector->base.encoder);
  8467. }
  8468. for_each_intel_encoder(dev, encoder) {
  8469. encoder->new_crtc =
  8470. to_intel_crtc(encoder->base.crtc);
  8471. }
  8472. for_each_intel_crtc(dev, crtc) {
  8473. crtc->new_enabled = crtc->base.enabled;
  8474. if (crtc->new_enabled)
  8475. crtc->new_config = &crtc->config;
  8476. else
  8477. crtc->new_config = NULL;
  8478. }
  8479. }
  8480. /**
  8481. * intel_modeset_commit_output_state
  8482. *
  8483. * This function copies the stage display pipe configuration to the real one.
  8484. */
  8485. static void intel_modeset_commit_output_state(struct drm_device *dev)
  8486. {
  8487. struct intel_crtc *crtc;
  8488. struct intel_encoder *encoder;
  8489. struct intel_connector *connector;
  8490. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8491. base.head) {
  8492. connector->base.encoder = &connector->new_encoder->base;
  8493. }
  8494. for_each_intel_encoder(dev, encoder) {
  8495. encoder->base.crtc = &encoder->new_crtc->base;
  8496. }
  8497. for_each_intel_crtc(dev, crtc) {
  8498. crtc->base.enabled = crtc->new_enabled;
  8499. }
  8500. }
  8501. static void
  8502. connected_sink_compute_bpp(struct intel_connector *connector,
  8503. struct intel_crtc_config *pipe_config)
  8504. {
  8505. int bpp = pipe_config->pipe_bpp;
  8506. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n",
  8507. connector->base.base.id,
  8508. connector->base.name);
  8509. /* Don't use an invalid EDID bpc value */
  8510. if (connector->base.display_info.bpc &&
  8511. connector->base.display_info.bpc * 3 < bpp) {
  8512. DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n",
  8513. bpp, connector->base.display_info.bpc*3);
  8514. pipe_config->pipe_bpp = connector->base.display_info.bpc*3;
  8515. }
  8516. /* Clamp bpp to 8 on screens without EDID 1.4 */
  8517. if (connector->base.display_info.bpc == 0 && bpp > 24) {
  8518. DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n",
  8519. bpp);
  8520. pipe_config->pipe_bpp = 24;
  8521. }
  8522. }
  8523. static int
  8524. compute_baseline_pipe_bpp(struct intel_crtc *crtc,
  8525. struct drm_framebuffer *fb,
  8526. struct intel_crtc_config *pipe_config)
  8527. {
  8528. struct drm_device *dev = crtc->base.dev;
  8529. struct intel_connector *connector;
  8530. int bpp;
  8531. switch (fb->pixel_format) {
  8532. case DRM_FORMAT_C8:
  8533. bpp = 8*3; /* since we go through a colormap */
  8534. break;
  8535. case DRM_FORMAT_XRGB1555:
  8536. case DRM_FORMAT_ARGB1555:
  8537. /* checked in intel_framebuffer_init already */
  8538. if (WARN_ON(INTEL_INFO(dev)->gen > 3))
  8539. return -EINVAL;
  8540. case DRM_FORMAT_RGB565:
  8541. bpp = 6*3; /* min is 18bpp */
  8542. break;
  8543. case DRM_FORMAT_XBGR8888:
  8544. case DRM_FORMAT_ABGR8888:
  8545. /* checked in intel_framebuffer_init already */
  8546. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8547. return -EINVAL;
  8548. case DRM_FORMAT_XRGB8888:
  8549. case DRM_FORMAT_ARGB8888:
  8550. bpp = 8*3;
  8551. break;
  8552. case DRM_FORMAT_XRGB2101010:
  8553. case DRM_FORMAT_ARGB2101010:
  8554. case DRM_FORMAT_XBGR2101010:
  8555. case DRM_FORMAT_ABGR2101010:
  8556. /* checked in intel_framebuffer_init already */
  8557. if (WARN_ON(INTEL_INFO(dev)->gen < 4))
  8558. return -EINVAL;
  8559. bpp = 10*3;
  8560. break;
  8561. /* TODO: gen4+ supports 16 bpc floating point, too. */
  8562. default:
  8563. DRM_DEBUG_KMS("unsupported depth\n");
  8564. return -EINVAL;
  8565. }
  8566. pipe_config->pipe_bpp = bpp;
  8567. /* Clamp display bpp to EDID value */
  8568. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8569. base.head) {
  8570. if (!connector->new_encoder ||
  8571. connector->new_encoder->new_crtc != crtc)
  8572. continue;
  8573. connected_sink_compute_bpp(connector, pipe_config);
  8574. }
  8575. return bpp;
  8576. }
  8577. static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
  8578. {
  8579. DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
  8580. "type: 0x%x flags: 0x%x\n",
  8581. mode->crtc_clock,
  8582. mode->crtc_hdisplay, mode->crtc_hsync_start,
  8583. mode->crtc_hsync_end, mode->crtc_htotal,
  8584. mode->crtc_vdisplay, mode->crtc_vsync_start,
  8585. mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
  8586. }
  8587. static void intel_dump_pipe_config(struct intel_crtc *crtc,
  8588. struct intel_crtc_config *pipe_config,
  8589. const char *context)
  8590. {
  8591. DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id,
  8592. context, pipe_name(crtc->pipe));
  8593. DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder));
  8594. DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n",
  8595. pipe_config->pipe_bpp, pipe_config->dither);
  8596. DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8597. pipe_config->has_pch_encoder,
  8598. pipe_config->fdi_lanes,
  8599. pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n,
  8600. pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n,
  8601. pipe_config->fdi_m_n.tu);
  8602. DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
  8603. pipe_config->has_dp_encoder,
  8604. pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n,
  8605. pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n,
  8606. pipe_config->dp_m_n.tu);
  8607. DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n",
  8608. pipe_config->has_dp_encoder,
  8609. pipe_config->dp_m2_n2.gmch_m,
  8610. pipe_config->dp_m2_n2.gmch_n,
  8611. pipe_config->dp_m2_n2.link_m,
  8612. pipe_config->dp_m2_n2.link_n,
  8613. pipe_config->dp_m2_n2.tu);
  8614. DRM_DEBUG_KMS("requested mode:\n");
  8615. drm_mode_debug_printmodeline(&pipe_config->requested_mode);
  8616. DRM_DEBUG_KMS("adjusted mode:\n");
  8617. drm_mode_debug_printmodeline(&pipe_config->adjusted_mode);
  8618. intel_dump_crtc_timings(&pipe_config->adjusted_mode);
  8619. DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock);
  8620. DRM_DEBUG_KMS("pipe src size: %dx%d\n",
  8621. pipe_config->pipe_src_w, pipe_config->pipe_src_h);
  8622. DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
  8623. pipe_config->gmch_pfit.control,
  8624. pipe_config->gmch_pfit.pgm_ratios,
  8625. pipe_config->gmch_pfit.lvds_border_bits);
  8626. DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
  8627. pipe_config->pch_pfit.pos,
  8628. pipe_config->pch_pfit.size,
  8629. pipe_config->pch_pfit.enabled ? "enabled" : "disabled");
  8630. DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled);
  8631. DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide);
  8632. }
  8633. static bool encoders_cloneable(const struct intel_encoder *a,
  8634. const struct intel_encoder *b)
  8635. {
  8636. /* masks could be asymmetric, so check both ways */
  8637. return a == b || (a->cloneable & (1 << b->type) &&
  8638. b->cloneable & (1 << a->type));
  8639. }
  8640. static bool check_single_encoder_cloning(struct intel_crtc *crtc,
  8641. struct intel_encoder *encoder)
  8642. {
  8643. struct drm_device *dev = crtc->base.dev;
  8644. struct intel_encoder *source_encoder;
  8645. for_each_intel_encoder(dev, source_encoder) {
  8646. if (source_encoder->new_crtc != crtc)
  8647. continue;
  8648. if (!encoders_cloneable(encoder, source_encoder))
  8649. return false;
  8650. }
  8651. return true;
  8652. }
  8653. static bool check_encoder_cloning(struct intel_crtc *crtc)
  8654. {
  8655. struct drm_device *dev = crtc->base.dev;
  8656. struct intel_encoder *encoder;
  8657. for_each_intel_encoder(dev, encoder) {
  8658. if (encoder->new_crtc != crtc)
  8659. continue;
  8660. if (!check_single_encoder_cloning(crtc, encoder))
  8661. return false;
  8662. }
  8663. return true;
  8664. }
  8665. static struct intel_crtc_config *
  8666. intel_modeset_pipe_config(struct drm_crtc *crtc,
  8667. struct drm_framebuffer *fb,
  8668. struct drm_display_mode *mode)
  8669. {
  8670. struct drm_device *dev = crtc->dev;
  8671. struct intel_encoder *encoder;
  8672. struct intel_crtc_config *pipe_config;
  8673. int plane_bpp, ret = -EINVAL;
  8674. bool retry = true;
  8675. if (!check_encoder_cloning(to_intel_crtc(crtc))) {
  8676. DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
  8677. return ERR_PTR(-EINVAL);
  8678. }
  8679. pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
  8680. if (!pipe_config)
  8681. return ERR_PTR(-ENOMEM);
  8682. drm_mode_copy(&pipe_config->adjusted_mode, mode);
  8683. drm_mode_copy(&pipe_config->requested_mode, mode);
  8684. pipe_config->cpu_transcoder =
  8685. (enum transcoder) to_intel_crtc(crtc)->pipe;
  8686. pipe_config->shared_dpll = DPLL_ID_PRIVATE;
  8687. /*
  8688. * Sanitize sync polarity flags based on requested ones. If neither
  8689. * positive or negative polarity is requested, treat this as meaning
  8690. * negative polarity.
  8691. */
  8692. if (!(pipe_config->adjusted_mode.flags &
  8693. (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
  8694. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  8695. if (!(pipe_config->adjusted_mode.flags &
  8696. (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
  8697. pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  8698. /* Compute a starting value for pipe_config->pipe_bpp taking the source
  8699. * plane pixel format and any sink constraints into account. Returns the
  8700. * source plane bpp so that dithering can be selected on mismatches
  8701. * after encoders and crtc also have had their say. */
  8702. plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
  8703. fb, pipe_config);
  8704. if (plane_bpp < 0)
  8705. goto fail;
  8706. /*
  8707. * Determine the real pipe dimensions. Note that stereo modes can
  8708. * increase the actual pipe size due to the frame doubling and
  8709. * insertion of additional space for blanks between the frame. This
  8710. * is stored in the crtc timings. We use the requested mode to do this
  8711. * computation to clearly distinguish it from the adjusted mode, which
  8712. * can be changed by the connectors in the below retry loop.
  8713. */
  8714. drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE);
  8715. pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay;
  8716. pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay;
  8717. encoder_retry:
  8718. /* Ensure the port clock defaults are reset when retrying. */
  8719. pipe_config->port_clock = 0;
  8720. pipe_config->pixel_multiplier = 1;
  8721. /* Fill in default crtc timings, allow encoders to overwrite them. */
  8722. drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE);
  8723. /* Pass our mode to the connectors and the CRTC to give them a chance to
  8724. * adjust it according to limitations or connector properties, and also
  8725. * a chance to reject the mode entirely.
  8726. */
  8727. for_each_intel_encoder(dev, encoder) {
  8728. if (&encoder->new_crtc->base != crtc)
  8729. continue;
  8730. if (!(encoder->compute_config(encoder, pipe_config))) {
  8731. DRM_DEBUG_KMS("Encoder config failure\n");
  8732. goto fail;
  8733. }
  8734. }
  8735. /* Set default port clock if not overwritten by the encoder. Needs to be
  8736. * done afterwards in case the encoder adjusts the mode. */
  8737. if (!pipe_config->port_clock)
  8738. pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock
  8739. * pipe_config->pixel_multiplier;
  8740. ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
  8741. if (ret < 0) {
  8742. DRM_DEBUG_KMS("CRTC fixup failed\n");
  8743. goto fail;
  8744. }
  8745. if (ret == RETRY) {
  8746. if (WARN(!retry, "loop in pipe configuration computation\n")) {
  8747. ret = -EINVAL;
  8748. goto fail;
  8749. }
  8750. DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
  8751. retry = false;
  8752. goto encoder_retry;
  8753. }
  8754. pipe_config->dither = pipe_config->pipe_bpp != plane_bpp;
  8755. DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n",
  8756. plane_bpp, pipe_config->pipe_bpp, pipe_config->dither);
  8757. return pipe_config;
  8758. fail:
  8759. kfree(pipe_config);
  8760. return ERR_PTR(ret);
  8761. }
  8762. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  8763. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  8764. static void
  8765. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  8766. unsigned *prepare_pipes, unsigned *disable_pipes)
  8767. {
  8768. struct intel_crtc *intel_crtc;
  8769. struct drm_device *dev = crtc->dev;
  8770. struct intel_encoder *encoder;
  8771. struct intel_connector *connector;
  8772. struct drm_crtc *tmp_crtc;
  8773. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  8774. /* Check which crtcs have changed outputs connected to them, these need
  8775. * to be part of the prepare_pipes mask. We don't (yet) support global
  8776. * modeset across multiple crtcs, so modeset_pipes will only have one
  8777. * bit set at most. */
  8778. list_for_each_entry(connector, &dev->mode_config.connector_list,
  8779. base.head) {
  8780. if (connector->base.encoder == &connector->new_encoder->base)
  8781. continue;
  8782. if (connector->base.encoder) {
  8783. tmp_crtc = connector->base.encoder->crtc;
  8784. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8785. }
  8786. if (connector->new_encoder)
  8787. *prepare_pipes |=
  8788. 1 << connector->new_encoder->new_crtc->pipe;
  8789. }
  8790. for_each_intel_encoder(dev, encoder) {
  8791. if (encoder->base.crtc == &encoder->new_crtc->base)
  8792. continue;
  8793. if (encoder->base.crtc) {
  8794. tmp_crtc = encoder->base.crtc;
  8795. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  8796. }
  8797. if (encoder->new_crtc)
  8798. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  8799. }
  8800. /* Check for pipes that will be enabled/disabled ... */
  8801. for_each_intel_crtc(dev, intel_crtc) {
  8802. if (intel_crtc->base.enabled == intel_crtc->new_enabled)
  8803. continue;
  8804. if (!intel_crtc->new_enabled)
  8805. *disable_pipes |= 1 << intel_crtc->pipe;
  8806. else
  8807. *prepare_pipes |= 1 << intel_crtc->pipe;
  8808. }
  8809. /* set_mode is also used to update properties on life display pipes. */
  8810. intel_crtc = to_intel_crtc(crtc);
  8811. if (intel_crtc->new_enabled)
  8812. *prepare_pipes |= 1 << intel_crtc->pipe;
  8813. /*
  8814. * For simplicity do a full modeset on any pipe where the output routing
  8815. * changed. We could be more clever, but that would require us to be
  8816. * more careful with calling the relevant encoder->mode_set functions.
  8817. */
  8818. if (*prepare_pipes)
  8819. *modeset_pipes = *prepare_pipes;
  8820. /* ... and mask these out. */
  8821. *modeset_pipes &= ~(*disable_pipes);
  8822. *prepare_pipes &= ~(*disable_pipes);
  8823. /*
  8824. * HACK: We don't (yet) fully support global modesets. intel_set_config
  8825. * obies this rule, but the modeset restore mode of
  8826. * intel_modeset_setup_hw_state does not.
  8827. */
  8828. *modeset_pipes &= 1 << intel_crtc->pipe;
  8829. *prepare_pipes &= 1 << intel_crtc->pipe;
  8830. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  8831. *modeset_pipes, *prepare_pipes, *disable_pipes);
  8832. }
  8833. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  8834. {
  8835. struct drm_encoder *encoder;
  8836. struct drm_device *dev = crtc->dev;
  8837. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  8838. if (encoder->crtc == crtc)
  8839. return true;
  8840. return false;
  8841. }
  8842. static void
  8843. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  8844. {
  8845. struct intel_encoder *intel_encoder;
  8846. struct intel_crtc *intel_crtc;
  8847. struct drm_connector *connector;
  8848. for_each_intel_encoder(dev, intel_encoder) {
  8849. if (!intel_encoder->base.crtc)
  8850. continue;
  8851. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  8852. if (prepare_pipes & (1 << intel_crtc->pipe))
  8853. intel_encoder->connectors_active = false;
  8854. }
  8855. intel_modeset_commit_output_state(dev);
  8856. /* Double check state. */
  8857. for_each_intel_crtc(dev, intel_crtc) {
  8858. WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base));
  8859. WARN_ON(intel_crtc->new_config &&
  8860. intel_crtc->new_config != &intel_crtc->config);
  8861. WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config);
  8862. }
  8863. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  8864. if (!connector->encoder || !connector->encoder->crtc)
  8865. continue;
  8866. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  8867. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  8868. struct drm_property *dpms_property =
  8869. dev->mode_config.dpms_property;
  8870. connector->dpms = DRM_MODE_DPMS_ON;
  8871. drm_object_property_set_value(&connector->base,
  8872. dpms_property,
  8873. DRM_MODE_DPMS_ON);
  8874. intel_encoder = to_intel_encoder(connector->encoder);
  8875. intel_encoder->connectors_active = true;
  8876. }
  8877. }
  8878. }
  8879. static bool intel_fuzzy_clock_check(int clock1, int clock2)
  8880. {
  8881. int diff;
  8882. if (clock1 == clock2)
  8883. return true;
  8884. if (!clock1 || !clock2)
  8885. return false;
  8886. diff = abs(clock1 - clock2);
  8887. if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
  8888. return true;
  8889. return false;
  8890. }
  8891. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  8892. list_for_each_entry((intel_crtc), \
  8893. &(dev)->mode_config.crtc_list, \
  8894. base.head) \
  8895. if (mask & (1 <<(intel_crtc)->pipe))
  8896. static bool
  8897. intel_pipe_config_compare(struct drm_device *dev,
  8898. struct intel_crtc_config *current_config,
  8899. struct intel_crtc_config *pipe_config)
  8900. {
  8901. #define PIPE_CONF_CHECK_X(name) \
  8902. if (current_config->name != pipe_config->name) { \
  8903. DRM_ERROR("mismatch in " #name " " \
  8904. "(expected 0x%08x, found 0x%08x)\n", \
  8905. current_config->name, \
  8906. pipe_config->name); \
  8907. return false; \
  8908. }
  8909. #define PIPE_CONF_CHECK_I(name) \
  8910. if (current_config->name != pipe_config->name) { \
  8911. DRM_ERROR("mismatch in " #name " " \
  8912. "(expected %i, found %i)\n", \
  8913. current_config->name, \
  8914. pipe_config->name); \
  8915. return false; \
  8916. }
  8917. /* This is required for BDW+ where there is only one set of registers for
  8918. * switching between high and low RR.
  8919. * This macro can be used whenever a comparison has to be made between one
  8920. * hw state and multiple sw state variables.
  8921. */
  8922. #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \
  8923. if ((current_config->name != pipe_config->name) && \
  8924. (current_config->alt_name != pipe_config->name)) { \
  8925. DRM_ERROR("mismatch in " #name " " \
  8926. "(expected %i or %i, found %i)\n", \
  8927. current_config->name, \
  8928. current_config->alt_name, \
  8929. pipe_config->name); \
  8930. return false; \
  8931. }
  8932. #define PIPE_CONF_CHECK_FLAGS(name, mask) \
  8933. if ((current_config->name ^ pipe_config->name) & (mask)) { \
  8934. DRM_ERROR("mismatch in " #name "(" #mask ") " \
  8935. "(expected %i, found %i)\n", \
  8936. current_config->name & (mask), \
  8937. pipe_config->name & (mask)); \
  8938. return false; \
  8939. }
  8940. #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \
  8941. if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
  8942. DRM_ERROR("mismatch in " #name " " \
  8943. "(expected %i, found %i)\n", \
  8944. current_config->name, \
  8945. pipe_config->name); \
  8946. return false; \
  8947. }
  8948. #define PIPE_CONF_QUIRK(quirk) \
  8949. ((current_config->quirks | pipe_config->quirks) & (quirk))
  8950. PIPE_CONF_CHECK_I(cpu_transcoder);
  8951. PIPE_CONF_CHECK_I(has_pch_encoder);
  8952. PIPE_CONF_CHECK_I(fdi_lanes);
  8953. PIPE_CONF_CHECK_I(fdi_m_n.gmch_m);
  8954. PIPE_CONF_CHECK_I(fdi_m_n.gmch_n);
  8955. PIPE_CONF_CHECK_I(fdi_m_n.link_m);
  8956. PIPE_CONF_CHECK_I(fdi_m_n.link_n);
  8957. PIPE_CONF_CHECK_I(fdi_m_n.tu);
  8958. PIPE_CONF_CHECK_I(has_dp_encoder);
  8959. if (INTEL_INFO(dev)->gen < 8) {
  8960. PIPE_CONF_CHECK_I(dp_m_n.gmch_m);
  8961. PIPE_CONF_CHECK_I(dp_m_n.gmch_n);
  8962. PIPE_CONF_CHECK_I(dp_m_n.link_m);
  8963. PIPE_CONF_CHECK_I(dp_m_n.link_n);
  8964. PIPE_CONF_CHECK_I(dp_m_n.tu);
  8965. if (current_config->has_drrs) {
  8966. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m);
  8967. PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n);
  8968. PIPE_CONF_CHECK_I(dp_m2_n2.link_m);
  8969. PIPE_CONF_CHECK_I(dp_m2_n2.link_n);
  8970. PIPE_CONF_CHECK_I(dp_m2_n2.tu);
  8971. }
  8972. } else {
  8973. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m);
  8974. PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n);
  8975. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m);
  8976. PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n);
  8977. PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu);
  8978. }
  8979. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay);
  8980. PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal);
  8981. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start);
  8982. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end);
  8983. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start);
  8984. PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end);
  8985. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay);
  8986. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal);
  8987. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start);
  8988. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end);
  8989. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start);
  8990. PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end);
  8991. PIPE_CONF_CHECK_I(pixel_multiplier);
  8992. PIPE_CONF_CHECK_I(has_hdmi_sink);
  8993. if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) ||
  8994. IS_VALLEYVIEW(dev))
  8995. PIPE_CONF_CHECK_I(limited_color_range);
  8996. PIPE_CONF_CHECK_I(has_audio);
  8997. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  8998. DRM_MODE_FLAG_INTERLACE);
  8999. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
  9000. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9001. DRM_MODE_FLAG_PHSYNC);
  9002. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9003. DRM_MODE_FLAG_NHSYNC);
  9004. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9005. DRM_MODE_FLAG_PVSYNC);
  9006. PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags,
  9007. DRM_MODE_FLAG_NVSYNC);
  9008. }
  9009. PIPE_CONF_CHECK_I(pipe_src_w);
  9010. PIPE_CONF_CHECK_I(pipe_src_h);
  9011. /*
  9012. * FIXME: BIOS likes to set up a cloned config with lvds+external
  9013. * screen. Since we don't yet re-compute the pipe config when moving
  9014. * just the lvds port away to another pipe the sw tracking won't match.
  9015. *
  9016. * Proper atomic modesets with recomputed global state will fix this.
  9017. * Until then just don't check gmch state for inherited modes.
  9018. */
  9019. if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) {
  9020. PIPE_CONF_CHECK_I(gmch_pfit.control);
  9021. /* pfit ratios are autocomputed by the hw on gen4+ */
  9022. if (INTEL_INFO(dev)->gen < 4)
  9023. PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios);
  9024. PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits);
  9025. }
  9026. PIPE_CONF_CHECK_I(pch_pfit.enabled);
  9027. if (current_config->pch_pfit.enabled) {
  9028. PIPE_CONF_CHECK_I(pch_pfit.pos);
  9029. PIPE_CONF_CHECK_I(pch_pfit.size);
  9030. }
  9031. /* BDW+ don't expose a synchronous way to read the state */
  9032. if (IS_HASWELL(dev))
  9033. PIPE_CONF_CHECK_I(ips_enabled);
  9034. PIPE_CONF_CHECK_I(double_wide);
  9035. PIPE_CONF_CHECK_X(ddi_pll_sel);
  9036. PIPE_CONF_CHECK_I(shared_dpll);
  9037. PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
  9038. PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
  9039. PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
  9040. PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
  9041. PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
  9042. if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5)
  9043. PIPE_CONF_CHECK_I(pipe_bpp);
  9044. PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock);
  9045. PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
  9046. #undef PIPE_CONF_CHECK_X
  9047. #undef PIPE_CONF_CHECK_I
  9048. #undef PIPE_CONF_CHECK_I_ALT
  9049. #undef PIPE_CONF_CHECK_FLAGS
  9050. #undef PIPE_CONF_CHECK_CLOCK_FUZZY
  9051. #undef PIPE_CONF_QUIRK
  9052. return true;
  9053. }
  9054. static void
  9055. check_connector_state(struct drm_device *dev)
  9056. {
  9057. struct intel_connector *connector;
  9058. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9059. base.head) {
  9060. /* This also checks the encoder/connector hw state with the
  9061. * ->get_hw_state callbacks. */
  9062. intel_connector_check_state(connector);
  9063. WARN(&connector->new_encoder->base != connector->base.encoder,
  9064. "connector's staged encoder doesn't match current encoder\n");
  9065. }
  9066. }
  9067. static void
  9068. check_encoder_state(struct drm_device *dev)
  9069. {
  9070. struct intel_encoder *encoder;
  9071. struct intel_connector *connector;
  9072. for_each_intel_encoder(dev, encoder) {
  9073. bool enabled = false;
  9074. bool active = false;
  9075. enum pipe pipe, tracked_pipe;
  9076. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  9077. encoder->base.base.id,
  9078. encoder->base.name);
  9079. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  9080. "encoder's stage crtc doesn't match current crtc\n");
  9081. WARN(encoder->connectors_active && !encoder->base.crtc,
  9082. "encoder's active_connectors set, but no crtc\n");
  9083. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9084. base.head) {
  9085. if (connector->base.encoder != &encoder->base)
  9086. continue;
  9087. enabled = true;
  9088. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  9089. active = true;
  9090. }
  9091. /*
  9092. * for MST connectors if we unplug the connector is gone
  9093. * away but the encoder is still connected to a crtc
  9094. * until a modeset happens in response to the hotplug.
  9095. */
  9096. if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
  9097. continue;
  9098. WARN(!!encoder->base.crtc != enabled,
  9099. "encoder's enabled state mismatch "
  9100. "(expected %i, found %i)\n",
  9101. !!encoder->base.crtc, enabled);
  9102. WARN(active && !encoder->base.crtc,
  9103. "active encoder with no crtc\n");
  9104. WARN(encoder->connectors_active != active,
  9105. "encoder's computed active state doesn't match tracked active state "
  9106. "(expected %i, found %i)\n", active, encoder->connectors_active);
  9107. active = encoder->get_hw_state(encoder, &pipe);
  9108. WARN(active != encoder->connectors_active,
  9109. "encoder's hw state doesn't match sw tracking "
  9110. "(expected %i, found %i)\n",
  9111. encoder->connectors_active, active);
  9112. if (!encoder->base.crtc)
  9113. continue;
  9114. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  9115. WARN(active && pipe != tracked_pipe,
  9116. "active encoder's pipe doesn't match"
  9117. "(expected %i, found %i)\n",
  9118. tracked_pipe, pipe);
  9119. }
  9120. }
  9121. static void
  9122. check_crtc_state(struct drm_device *dev)
  9123. {
  9124. struct drm_i915_private *dev_priv = dev->dev_private;
  9125. struct intel_crtc *crtc;
  9126. struct intel_encoder *encoder;
  9127. struct intel_crtc_config pipe_config;
  9128. for_each_intel_crtc(dev, crtc) {
  9129. bool enabled = false;
  9130. bool active = false;
  9131. memset(&pipe_config, 0, sizeof(pipe_config));
  9132. DRM_DEBUG_KMS("[CRTC:%d]\n",
  9133. crtc->base.base.id);
  9134. WARN(crtc->active && !crtc->base.enabled,
  9135. "active crtc, but not enabled in sw tracking\n");
  9136. for_each_intel_encoder(dev, encoder) {
  9137. if (encoder->base.crtc != &crtc->base)
  9138. continue;
  9139. enabled = true;
  9140. if (encoder->connectors_active)
  9141. active = true;
  9142. }
  9143. WARN(active != crtc->active,
  9144. "crtc's computed active state doesn't match tracked active state "
  9145. "(expected %i, found %i)\n", active, crtc->active);
  9146. WARN(enabled != crtc->base.enabled,
  9147. "crtc's computed enabled state doesn't match tracked enabled state "
  9148. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  9149. active = dev_priv->display.get_pipe_config(crtc,
  9150. &pipe_config);
  9151. /* hw state is inconsistent with the pipe quirk */
  9152. if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) ||
  9153. (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))
  9154. active = crtc->active;
  9155. for_each_intel_encoder(dev, encoder) {
  9156. enum pipe pipe;
  9157. if (encoder->base.crtc != &crtc->base)
  9158. continue;
  9159. if (encoder->get_hw_state(encoder, &pipe))
  9160. encoder->get_config(encoder, &pipe_config);
  9161. }
  9162. WARN(crtc->active != active,
  9163. "crtc active state doesn't match with hw state "
  9164. "(expected %i, found %i)\n", crtc->active, active);
  9165. if (active &&
  9166. !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) {
  9167. WARN(1, "pipe state doesn't match!\n");
  9168. intel_dump_pipe_config(crtc, &pipe_config,
  9169. "[hw state]");
  9170. intel_dump_pipe_config(crtc, &crtc->config,
  9171. "[sw state]");
  9172. }
  9173. }
  9174. }
  9175. static void
  9176. check_shared_dpll_state(struct drm_device *dev)
  9177. {
  9178. struct drm_i915_private *dev_priv = dev->dev_private;
  9179. struct intel_crtc *crtc;
  9180. struct intel_dpll_hw_state dpll_hw_state;
  9181. int i;
  9182. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9183. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  9184. int enabled_crtcs = 0, active_crtcs = 0;
  9185. bool active;
  9186. memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
  9187. DRM_DEBUG_KMS("%s\n", pll->name);
  9188. active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state);
  9189. WARN(pll->active > pll->refcount,
  9190. "more active pll users than references: %i vs %i\n",
  9191. pll->active, pll->refcount);
  9192. WARN(pll->active && !pll->on,
  9193. "pll in active use but not on in sw tracking\n");
  9194. WARN(pll->on && !pll->active,
  9195. "pll in on but not on in use in sw tracking\n");
  9196. WARN(pll->on != active,
  9197. "pll on state mismatch (expected %i, found %i)\n",
  9198. pll->on, active);
  9199. for_each_intel_crtc(dev, crtc) {
  9200. if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll)
  9201. enabled_crtcs++;
  9202. if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll)
  9203. active_crtcs++;
  9204. }
  9205. WARN(pll->active != active_crtcs,
  9206. "pll active crtcs mismatch (expected %i, found %i)\n",
  9207. pll->active, active_crtcs);
  9208. WARN(pll->refcount != enabled_crtcs,
  9209. "pll enabled crtcs mismatch (expected %i, found %i)\n",
  9210. pll->refcount, enabled_crtcs);
  9211. WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state,
  9212. sizeof(dpll_hw_state)),
  9213. "pll hw state mismatch\n");
  9214. }
  9215. }
  9216. void
  9217. intel_modeset_check_state(struct drm_device *dev)
  9218. {
  9219. check_connector_state(dev);
  9220. check_encoder_state(dev);
  9221. check_crtc_state(dev);
  9222. check_shared_dpll_state(dev);
  9223. }
  9224. void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  9225. int dotclock)
  9226. {
  9227. /*
  9228. * FDI already provided one idea for the dotclock.
  9229. * Yell if the encoder disagrees.
  9230. */
  9231. WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock),
  9232. "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
  9233. pipe_config->adjusted_mode.crtc_clock, dotclock);
  9234. }
  9235. static void update_scanline_offset(struct intel_crtc *crtc)
  9236. {
  9237. struct drm_device *dev = crtc->base.dev;
  9238. /*
  9239. * The scanline counter increments at the leading edge of hsync.
  9240. *
  9241. * On most platforms it starts counting from vtotal-1 on the
  9242. * first active line. That means the scanline counter value is
  9243. * always one less than what we would expect. Ie. just after
  9244. * start of vblank, which also occurs at start of hsync (on the
  9245. * last active line), the scanline counter will read vblank_start-1.
  9246. *
  9247. * On gen2 the scanline counter starts counting from 1 instead
  9248. * of vtotal-1, so we have to subtract one (or rather add vtotal-1
  9249. * to keep the value positive), instead of adding one.
  9250. *
  9251. * On HSW+ the behaviour of the scanline counter depends on the output
  9252. * type. For DP ports it behaves like most other platforms, but on HDMI
  9253. * there's an extra 1 line difference. So we need to add two instead of
  9254. * one to the value.
  9255. */
  9256. if (IS_GEN2(dev)) {
  9257. const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
  9258. int vtotal;
  9259. vtotal = mode->crtc_vtotal;
  9260. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  9261. vtotal /= 2;
  9262. crtc->scanline_offset = vtotal - 1;
  9263. } else if (HAS_DDI(dev) &&
  9264. intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) {
  9265. crtc->scanline_offset = 2;
  9266. } else
  9267. crtc->scanline_offset = 1;
  9268. }
  9269. static int __intel_set_mode(struct drm_crtc *crtc,
  9270. struct drm_display_mode *mode,
  9271. int x, int y, struct drm_framebuffer *fb)
  9272. {
  9273. struct drm_device *dev = crtc->dev;
  9274. struct drm_i915_private *dev_priv = dev->dev_private;
  9275. struct drm_display_mode *saved_mode;
  9276. struct intel_crtc_config *pipe_config = NULL;
  9277. struct intel_crtc *intel_crtc;
  9278. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  9279. int ret = 0;
  9280. saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL);
  9281. if (!saved_mode)
  9282. return -ENOMEM;
  9283. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  9284. &prepare_pipes, &disable_pipes);
  9285. *saved_mode = crtc->mode;
  9286. /* Hack: Because we don't (yet) support global modeset on multiple
  9287. * crtcs, we don't keep track of the new mode for more than one crtc.
  9288. * Hence simply check whether any bit is set in modeset_pipes in all the
  9289. * pieces of code that are not yet converted to deal with mutliple crtcs
  9290. * changing their mode at the same time. */
  9291. if (modeset_pipes) {
  9292. pipe_config = intel_modeset_pipe_config(crtc, fb, mode);
  9293. if (IS_ERR(pipe_config)) {
  9294. ret = PTR_ERR(pipe_config);
  9295. pipe_config = NULL;
  9296. goto out;
  9297. }
  9298. intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
  9299. "[modeset]");
  9300. to_intel_crtc(crtc)->new_config = pipe_config;
  9301. }
  9302. /*
  9303. * See if the config requires any additional preparation, e.g.
  9304. * to adjust global state with pipes off. We need to do this
  9305. * here so we can get the modeset_pipe updated config for the new
  9306. * mode set on this crtc. For other crtcs we need to use the
  9307. * adjusted_mode bits in the crtc directly.
  9308. */
  9309. if (IS_VALLEYVIEW(dev)) {
  9310. valleyview_modeset_global_pipes(dev, &prepare_pipes);
  9311. /* may have added more to prepare_pipes than we should */
  9312. prepare_pipes &= ~disable_pipes;
  9313. }
  9314. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  9315. intel_crtc_disable(&intel_crtc->base);
  9316. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9317. if (intel_crtc->base.enabled)
  9318. dev_priv->display.crtc_disable(&intel_crtc->base);
  9319. }
  9320. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  9321. * to set it here already despite that we pass it down the callchain.
  9322. */
  9323. if (modeset_pipes) {
  9324. crtc->mode = *mode;
  9325. /* mode_set/enable/disable functions rely on a correct pipe
  9326. * config. */
  9327. to_intel_crtc(crtc)->config = *pipe_config;
  9328. to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config;
  9329. /*
  9330. * Calculate and store various constants which
  9331. * are later needed by vblank and swap-completion
  9332. * timestamping. They are derived from true hwmode.
  9333. */
  9334. drm_calc_timestamping_constants(crtc,
  9335. &pipe_config->adjusted_mode);
  9336. }
  9337. /* Only after disabling all output pipelines that will be changed can we
  9338. * update the the output configuration. */
  9339. intel_modeset_update_state(dev, prepare_pipes);
  9340. if (dev_priv->display.modeset_global_resources)
  9341. dev_priv->display.modeset_global_resources(dev);
  9342. /* Set up the DPLL and any encoders state that needs to adjust or depend
  9343. * on the DPLL.
  9344. */
  9345. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  9346. struct drm_framebuffer *old_fb = crtc->primary->fb;
  9347. struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
  9348. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9349. mutex_lock(&dev->struct_mutex);
  9350. ret = intel_pin_and_fence_fb_obj(dev,
  9351. obj,
  9352. NULL);
  9353. if (ret != 0) {
  9354. DRM_ERROR("pin & fence failed\n");
  9355. mutex_unlock(&dev->struct_mutex);
  9356. goto done;
  9357. }
  9358. if (old_fb)
  9359. intel_unpin_fb_obj(old_obj);
  9360. i915_gem_track_fb(old_obj, obj,
  9361. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9362. mutex_unlock(&dev->struct_mutex);
  9363. crtc->primary->fb = fb;
  9364. crtc->x = x;
  9365. crtc->y = y;
  9366. ret = dev_priv->display.crtc_mode_set(&intel_crtc->base,
  9367. x, y, fb);
  9368. if (ret)
  9369. goto done;
  9370. }
  9371. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  9372. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  9373. update_scanline_offset(intel_crtc);
  9374. dev_priv->display.crtc_enable(&intel_crtc->base);
  9375. }
  9376. /* FIXME: add subpixel order */
  9377. done:
  9378. if (ret && crtc->enabled)
  9379. crtc->mode = *saved_mode;
  9380. out:
  9381. kfree(pipe_config);
  9382. kfree(saved_mode);
  9383. return ret;
  9384. }
  9385. static int intel_set_mode(struct drm_crtc *crtc,
  9386. struct drm_display_mode *mode,
  9387. int x, int y, struct drm_framebuffer *fb)
  9388. {
  9389. int ret;
  9390. ret = __intel_set_mode(crtc, mode, x, y, fb);
  9391. if (ret == 0)
  9392. intel_modeset_check_state(crtc->dev);
  9393. return ret;
  9394. }
  9395. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  9396. {
  9397. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb);
  9398. }
  9399. #undef for_each_intel_crtc_masked
  9400. static void intel_set_config_free(struct intel_set_config *config)
  9401. {
  9402. if (!config)
  9403. return;
  9404. kfree(config->save_connector_encoders);
  9405. kfree(config->save_encoder_crtcs);
  9406. kfree(config->save_crtc_enabled);
  9407. kfree(config);
  9408. }
  9409. static int intel_set_config_save_state(struct drm_device *dev,
  9410. struct intel_set_config *config)
  9411. {
  9412. struct drm_crtc *crtc;
  9413. struct drm_encoder *encoder;
  9414. struct drm_connector *connector;
  9415. int count;
  9416. config->save_crtc_enabled =
  9417. kcalloc(dev->mode_config.num_crtc,
  9418. sizeof(bool), GFP_KERNEL);
  9419. if (!config->save_crtc_enabled)
  9420. return -ENOMEM;
  9421. config->save_encoder_crtcs =
  9422. kcalloc(dev->mode_config.num_encoder,
  9423. sizeof(struct drm_crtc *), GFP_KERNEL);
  9424. if (!config->save_encoder_crtcs)
  9425. return -ENOMEM;
  9426. config->save_connector_encoders =
  9427. kcalloc(dev->mode_config.num_connector,
  9428. sizeof(struct drm_encoder *), GFP_KERNEL);
  9429. if (!config->save_connector_encoders)
  9430. return -ENOMEM;
  9431. /* Copy data. Note that driver private data is not affected.
  9432. * Should anything bad happen only the expected state is
  9433. * restored, not the drivers personal bookkeeping.
  9434. */
  9435. count = 0;
  9436. for_each_crtc(dev, crtc) {
  9437. config->save_crtc_enabled[count++] = crtc->enabled;
  9438. }
  9439. count = 0;
  9440. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  9441. config->save_encoder_crtcs[count++] = encoder->crtc;
  9442. }
  9443. count = 0;
  9444. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  9445. config->save_connector_encoders[count++] = connector->encoder;
  9446. }
  9447. return 0;
  9448. }
  9449. static void intel_set_config_restore_state(struct drm_device *dev,
  9450. struct intel_set_config *config)
  9451. {
  9452. struct intel_crtc *crtc;
  9453. struct intel_encoder *encoder;
  9454. struct intel_connector *connector;
  9455. int count;
  9456. count = 0;
  9457. for_each_intel_crtc(dev, crtc) {
  9458. crtc->new_enabled = config->save_crtc_enabled[count++];
  9459. if (crtc->new_enabled)
  9460. crtc->new_config = &crtc->config;
  9461. else
  9462. crtc->new_config = NULL;
  9463. }
  9464. count = 0;
  9465. for_each_intel_encoder(dev, encoder) {
  9466. encoder->new_crtc =
  9467. to_intel_crtc(config->save_encoder_crtcs[count++]);
  9468. }
  9469. count = 0;
  9470. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9471. connector->new_encoder =
  9472. to_intel_encoder(config->save_connector_encoders[count++]);
  9473. }
  9474. }
  9475. static bool
  9476. is_crtc_connector_off(struct drm_mode_set *set)
  9477. {
  9478. int i;
  9479. if (set->num_connectors == 0)
  9480. return false;
  9481. if (WARN_ON(set->connectors == NULL))
  9482. return false;
  9483. for (i = 0; i < set->num_connectors; i++)
  9484. if (set->connectors[i]->encoder &&
  9485. set->connectors[i]->encoder->crtc == set->crtc &&
  9486. set->connectors[i]->dpms != DRM_MODE_DPMS_ON)
  9487. return true;
  9488. return false;
  9489. }
  9490. static void
  9491. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  9492. struct intel_set_config *config)
  9493. {
  9494. /* We should be able to check here if the fb has the same properties
  9495. * and then just flip_or_move it */
  9496. if (is_crtc_connector_off(set)) {
  9497. config->mode_changed = true;
  9498. } else if (set->crtc->primary->fb != set->fb) {
  9499. /*
  9500. * If we have no fb, we can only flip as long as the crtc is
  9501. * active, otherwise we need a full mode set. The crtc may
  9502. * be active if we've only disabled the primary plane, or
  9503. * in fastboot situations.
  9504. */
  9505. if (set->crtc->primary->fb == NULL) {
  9506. struct intel_crtc *intel_crtc =
  9507. to_intel_crtc(set->crtc);
  9508. if (intel_crtc->active) {
  9509. DRM_DEBUG_KMS("crtc has no fb, will flip\n");
  9510. config->fb_changed = true;
  9511. } else {
  9512. DRM_DEBUG_KMS("inactive crtc, full mode set\n");
  9513. config->mode_changed = true;
  9514. }
  9515. } else if (set->fb == NULL) {
  9516. config->mode_changed = true;
  9517. } else if (set->fb->pixel_format !=
  9518. set->crtc->primary->fb->pixel_format) {
  9519. config->mode_changed = true;
  9520. } else {
  9521. config->fb_changed = true;
  9522. }
  9523. }
  9524. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  9525. config->fb_changed = true;
  9526. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  9527. DRM_DEBUG_KMS("modes are different, full mode set\n");
  9528. drm_mode_debug_printmodeline(&set->crtc->mode);
  9529. drm_mode_debug_printmodeline(set->mode);
  9530. config->mode_changed = true;
  9531. }
  9532. DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n",
  9533. set->crtc->base.id, config->mode_changed, config->fb_changed);
  9534. }
  9535. static int
  9536. intel_modeset_stage_output_state(struct drm_device *dev,
  9537. struct drm_mode_set *set,
  9538. struct intel_set_config *config)
  9539. {
  9540. struct intel_connector *connector;
  9541. struct intel_encoder *encoder;
  9542. struct intel_crtc *crtc;
  9543. int ro;
  9544. /* The upper layers ensure that we either disable a crtc or have a list
  9545. * of connectors. For paranoia, double-check this. */
  9546. WARN_ON(!set->fb && (set->num_connectors != 0));
  9547. WARN_ON(set->fb && (set->num_connectors == 0));
  9548. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9549. base.head) {
  9550. /* Otherwise traverse passed in connector list and get encoders
  9551. * for them. */
  9552. for (ro = 0; ro < set->num_connectors; ro++) {
  9553. if (set->connectors[ro] == &connector->base) {
  9554. connector->new_encoder = intel_find_encoder(connector, to_intel_crtc(set->crtc)->pipe);
  9555. break;
  9556. }
  9557. }
  9558. /* If we disable the crtc, disable all its connectors. Also, if
  9559. * the connector is on the changing crtc but not on the new
  9560. * connector list, disable it. */
  9561. if ((!set->fb || ro == set->num_connectors) &&
  9562. connector->base.encoder &&
  9563. connector->base.encoder->crtc == set->crtc) {
  9564. connector->new_encoder = NULL;
  9565. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  9566. connector->base.base.id,
  9567. connector->base.name);
  9568. }
  9569. if (&connector->new_encoder->base != connector->base.encoder) {
  9570. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  9571. config->mode_changed = true;
  9572. }
  9573. }
  9574. /* connector->new_encoder is now updated for all connectors. */
  9575. /* Update crtc of enabled connectors. */
  9576. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9577. base.head) {
  9578. struct drm_crtc *new_crtc;
  9579. if (!connector->new_encoder)
  9580. continue;
  9581. new_crtc = connector->new_encoder->base.crtc;
  9582. for (ro = 0; ro < set->num_connectors; ro++) {
  9583. if (set->connectors[ro] == &connector->base)
  9584. new_crtc = set->crtc;
  9585. }
  9586. /* Make sure the new CRTC will work with the encoder */
  9587. if (!drm_encoder_crtc_ok(&connector->new_encoder->base,
  9588. new_crtc)) {
  9589. return -EINVAL;
  9590. }
  9591. connector->new_encoder->new_crtc = to_intel_crtc(new_crtc);
  9592. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  9593. connector->base.base.id,
  9594. connector->base.name,
  9595. new_crtc->base.id);
  9596. }
  9597. /* Check for any encoders that needs to be disabled. */
  9598. for_each_intel_encoder(dev, encoder) {
  9599. int num_connectors = 0;
  9600. list_for_each_entry(connector,
  9601. &dev->mode_config.connector_list,
  9602. base.head) {
  9603. if (connector->new_encoder == encoder) {
  9604. WARN_ON(!connector->new_encoder->new_crtc);
  9605. num_connectors++;
  9606. }
  9607. }
  9608. if (num_connectors == 0)
  9609. encoder->new_crtc = NULL;
  9610. else if (num_connectors > 1)
  9611. return -EINVAL;
  9612. /* Only now check for crtc changes so we don't miss encoders
  9613. * that will be disabled. */
  9614. if (&encoder->new_crtc->base != encoder->base.crtc) {
  9615. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  9616. config->mode_changed = true;
  9617. }
  9618. }
  9619. /* Now we've also updated encoder->new_crtc for all encoders. */
  9620. list_for_each_entry(connector, &dev->mode_config.connector_list,
  9621. base.head) {
  9622. if (connector->new_encoder)
  9623. if (connector->new_encoder != connector->encoder)
  9624. connector->encoder = connector->new_encoder;
  9625. }
  9626. for_each_intel_crtc(dev, crtc) {
  9627. crtc->new_enabled = false;
  9628. for_each_intel_encoder(dev, encoder) {
  9629. if (encoder->new_crtc == crtc) {
  9630. crtc->new_enabled = true;
  9631. break;
  9632. }
  9633. }
  9634. if (crtc->new_enabled != crtc->base.enabled) {
  9635. DRM_DEBUG_KMS("crtc %sabled, full mode switch\n",
  9636. crtc->new_enabled ? "en" : "dis");
  9637. config->mode_changed = true;
  9638. }
  9639. if (crtc->new_enabled)
  9640. crtc->new_config = &crtc->config;
  9641. else
  9642. crtc->new_config = NULL;
  9643. }
  9644. return 0;
  9645. }
  9646. static void disable_crtc_nofb(struct intel_crtc *crtc)
  9647. {
  9648. struct drm_device *dev = crtc->base.dev;
  9649. struct intel_encoder *encoder;
  9650. struct intel_connector *connector;
  9651. DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n",
  9652. pipe_name(crtc->pipe));
  9653. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  9654. if (connector->new_encoder &&
  9655. connector->new_encoder->new_crtc == crtc)
  9656. connector->new_encoder = NULL;
  9657. }
  9658. for_each_intel_encoder(dev, encoder) {
  9659. if (encoder->new_crtc == crtc)
  9660. encoder->new_crtc = NULL;
  9661. }
  9662. crtc->new_enabled = false;
  9663. crtc->new_config = NULL;
  9664. }
  9665. static int intel_crtc_set_config(struct drm_mode_set *set)
  9666. {
  9667. struct drm_device *dev;
  9668. struct drm_mode_set save_set;
  9669. struct intel_set_config *config;
  9670. int ret;
  9671. BUG_ON(!set);
  9672. BUG_ON(!set->crtc);
  9673. BUG_ON(!set->crtc->helper_private);
  9674. /* Enforce sane interface api - has been abused by the fb helper. */
  9675. BUG_ON(!set->mode && set->fb);
  9676. BUG_ON(set->fb && set->num_connectors == 0);
  9677. if (set->fb) {
  9678. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  9679. set->crtc->base.id, set->fb->base.id,
  9680. (int)set->num_connectors, set->x, set->y);
  9681. } else {
  9682. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  9683. }
  9684. dev = set->crtc->dev;
  9685. ret = -ENOMEM;
  9686. config = kzalloc(sizeof(*config), GFP_KERNEL);
  9687. if (!config)
  9688. goto out_config;
  9689. ret = intel_set_config_save_state(dev, config);
  9690. if (ret)
  9691. goto out_config;
  9692. save_set.crtc = set->crtc;
  9693. save_set.mode = &set->crtc->mode;
  9694. save_set.x = set->crtc->x;
  9695. save_set.y = set->crtc->y;
  9696. save_set.fb = set->crtc->primary->fb;
  9697. /* Compute whether we need a full modeset, only an fb base update or no
  9698. * change at all. In the future we might also check whether only the
  9699. * mode changed, e.g. for LVDS where we only change the panel fitter in
  9700. * such cases. */
  9701. intel_set_config_compute_mode_changes(set, config);
  9702. ret = intel_modeset_stage_output_state(dev, set, config);
  9703. if (ret)
  9704. goto fail;
  9705. if (config->mode_changed) {
  9706. ret = intel_set_mode(set->crtc, set->mode,
  9707. set->x, set->y, set->fb);
  9708. } else if (config->fb_changed) {
  9709. struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc);
  9710. intel_crtc_wait_for_pending_flips(set->crtc);
  9711. ret = intel_pipe_set_base(set->crtc,
  9712. set->x, set->y, set->fb);
  9713. /*
  9714. * We need to make sure the primary plane is re-enabled if it
  9715. * has previously been turned off.
  9716. */
  9717. if (!intel_crtc->primary_enabled && ret == 0) {
  9718. WARN_ON(!intel_crtc->active);
  9719. intel_enable_primary_hw_plane(set->crtc->primary, set->crtc);
  9720. }
  9721. /*
  9722. * In the fastboot case this may be our only check of the
  9723. * state after boot. It would be better to only do it on
  9724. * the first update, but we don't have a nice way of doing that
  9725. * (and really, set_config isn't used much for high freq page
  9726. * flipping, so increasing its cost here shouldn't be a big
  9727. * deal).
  9728. */
  9729. if (i915.fastboot && ret == 0)
  9730. intel_modeset_check_state(set->crtc->dev);
  9731. }
  9732. if (ret) {
  9733. DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n",
  9734. set->crtc->base.id, ret);
  9735. fail:
  9736. intel_set_config_restore_state(dev, config);
  9737. /*
  9738. * HACK: if the pipe was on, but we didn't have a framebuffer,
  9739. * force the pipe off to avoid oopsing in the modeset code
  9740. * due to fb==NULL. This should only happen during boot since
  9741. * we don't yet reconstruct the FB from the hardware state.
  9742. */
  9743. if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb)
  9744. disable_crtc_nofb(to_intel_crtc(save_set.crtc));
  9745. /* Try to restore the config */
  9746. if (config->mode_changed &&
  9747. intel_set_mode(save_set.crtc, save_set.mode,
  9748. save_set.x, save_set.y, save_set.fb))
  9749. DRM_ERROR("failed to restore config after modeset failure\n");
  9750. }
  9751. out_config:
  9752. intel_set_config_free(config);
  9753. return ret;
  9754. }
  9755. static const struct drm_crtc_funcs intel_crtc_funcs = {
  9756. .gamma_set = intel_crtc_gamma_set,
  9757. .set_config = intel_crtc_set_config,
  9758. .destroy = intel_crtc_destroy,
  9759. .page_flip = intel_crtc_page_flip,
  9760. };
  9761. static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
  9762. struct intel_shared_dpll *pll,
  9763. struct intel_dpll_hw_state *hw_state)
  9764. {
  9765. uint32_t val;
  9766. if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS))
  9767. return false;
  9768. val = I915_READ(PCH_DPLL(pll->id));
  9769. hw_state->dpll = val;
  9770. hw_state->fp0 = I915_READ(PCH_FP0(pll->id));
  9771. hw_state->fp1 = I915_READ(PCH_FP1(pll->id));
  9772. return val & DPLL_VCO_ENABLE;
  9773. }
  9774. static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv,
  9775. struct intel_shared_dpll *pll)
  9776. {
  9777. I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0);
  9778. I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1);
  9779. }
  9780. static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv,
  9781. struct intel_shared_dpll *pll)
  9782. {
  9783. /* PCH refclock must be enabled first */
  9784. ibx_assert_pch_refclk_enabled(dev_priv);
  9785. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9786. /* Wait for the clocks to stabilize. */
  9787. POSTING_READ(PCH_DPLL(pll->id));
  9788. udelay(150);
  9789. /* The pixel multiplier can only be updated once the
  9790. * DPLL is enabled and the clocks are stable.
  9791. *
  9792. * So write it again.
  9793. */
  9794. I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll);
  9795. POSTING_READ(PCH_DPLL(pll->id));
  9796. udelay(200);
  9797. }
  9798. static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv,
  9799. struct intel_shared_dpll *pll)
  9800. {
  9801. struct drm_device *dev = dev_priv->dev;
  9802. struct intel_crtc *crtc;
  9803. /* Make sure no transcoder isn't still depending on us. */
  9804. for_each_intel_crtc(dev, crtc) {
  9805. if (intel_crtc_to_shared_dpll(crtc) == pll)
  9806. assert_pch_transcoder_disabled(dev_priv, crtc->pipe);
  9807. }
  9808. I915_WRITE(PCH_DPLL(pll->id), 0);
  9809. POSTING_READ(PCH_DPLL(pll->id));
  9810. udelay(200);
  9811. }
  9812. static char *ibx_pch_dpll_names[] = {
  9813. "PCH DPLL A",
  9814. "PCH DPLL B",
  9815. };
  9816. static void ibx_pch_dpll_init(struct drm_device *dev)
  9817. {
  9818. struct drm_i915_private *dev_priv = dev->dev_private;
  9819. int i;
  9820. dev_priv->num_shared_dpll = 2;
  9821. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  9822. dev_priv->shared_dplls[i].id = i;
  9823. dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i];
  9824. dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set;
  9825. dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable;
  9826. dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable;
  9827. dev_priv->shared_dplls[i].get_hw_state =
  9828. ibx_pch_dpll_get_hw_state;
  9829. }
  9830. }
  9831. static void intel_shared_dpll_init(struct drm_device *dev)
  9832. {
  9833. struct drm_i915_private *dev_priv = dev->dev_private;
  9834. if (HAS_DDI(dev))
  9835. intel_ddi_pll_init(dev);
  9836. else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  9837. ibx_pch_dpll_init(dev);
  9838. else
  9839. dev_priv->num_shared_dpll = 0;
  9840. BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
  9841. }
  9842. static int
  9843. intel_primary_plane_disable(struct drm_plane *plane)
  9844. {
  9845. struct drm_device *dev = plane->dev;
  9846. struct intel_crtc *intel_crtc;
  9847. if (!plane->fb)
  9848. return 0;
  9849. BUG_ON(!plane->crtc);
  9850. intel_crtc = to_intel_crtc(plane->crtc);
  9851. /*
  9852. * Even though we checked plane->fb above, it's still possible that
  9853. * the primary plane has been implicitly disabled because the crtc
  9854. * coordinates given weren't visible, or because we detected
  9855. * that it was 100% covered by a sprite plane. Or, the CRTC may be
  9856. * off and we've set a fb, but haven't actually turned on the CRTC yet.
  9857. * In either case, we need to unpin the FB and let the fb pointer get
  9858. * updated, but otherwise we don't need to touch the hardware.
  9859. */
  9860. if (!intel_crtc->primary_enabled)
  9861. goto disable_unpin;
  9862. intel_crtc_wait_for_pending_flips(plane->crtc);
  9863. intel_disable_primary_hw_plane(plane, plane->crtc);
  9864. disable_unpin:
  9865. mutex_lock(&dev->struct_mutex);
  9866. i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
  9867. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9868. intel_unpin_fb_obj(intel_fb_obj(plane->fb));
  9869. mutex_unlock(&dev->struct_mutex);
  9870. plane->fb = NULL;
  9871. return 0;
  9872. }
  9873. static int
  9874. intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
  9875. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  9876. unsigned int crtc_w, unsigned int crtc_h,
  9877. uint32_t src_x, uint32_t src_y,
  9878. uint32_t src_w, uint32_t src_h)
  9879. {
  9880. struct drm_device *dev = crtc->dev;
  9881. struct drm_i915_private *dev_priv = dev->dev_private;
  9882. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  9883. struct drm_i915_gem_object *obj = intel_fb_obj(fb);
  9884. struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
  9885. struct drm_rect dest = {
  9886. /* integer pixels */
  9887. .x1 = crtc_x,
  9888. .y1 = crtc_y,
  9889. .x2 = crtc_x + crtc_w,
  9890. .y2 = crtc_y + crtc_h,
  9891. };
  9892. struct drm_rect src = {
  9893. /* 16.16 fixed point */
  9894. .x1 = src_x,
  9895. .y1 = src_y,
  9896. .x2 = src_x + src_w,
  9897. .y2 = src_y + src_h,
  9898. };
  9899. const struct drm_rect clip = {
  9900. /* integer pixels */
  9901. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  9902. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  9903. };
  9904. const struct {
  9905. int crtc_x, crtc_y;
  9906. unsigned int crtc_w, crtc_h;
  9907. uint32_t src_x, src_y, src_w, src_h;
  9908. } orig = {
  9909. .crtc_x = crtc_x,
  9910. .crtc_y = crtc_y,
  9911. .crtc_w = crtc_w,
  9912. .crtc_h = crtc_h,
  9913. .src_x = src_x,
  9914. .src_y = src_y,
  9915. .src_w = src_w,
  9916. .src_h = src_h,
  9917. };
  9918. struct intel_plane *intel_plane = to_intel_plane(plane);
  9919. bool visible;
  9920. int ret;
  9921. ret = drm_plane_helper_check_update(plane, crtc, fb,
  9922. &src, &dest, &clip,
  9923. DRM_PLANE_HELPER_NO_SCALING,
  9924. DRM_PLANE_HELPER_NO_SCALING,
  9925. false, true, &visible);
  9926. if (ret)
  9927. return ret;
  9928. /*
  9929. * If the CRTC isn't enabled, we're just pinning the framebuffer,
  9930. * updating the fb pointer, and returning without touching the
  9931. * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to
  9932. * turn on the display with all planes setup as desired.
  9933. */
  9934. if (!crtc->enabled) {
  9935. mutex_lock(&dev->struct_mutex);
  9936. /*
  9937. * If we already called setplane while the crtc was disabled,
  9938. * we may have an fb pinned; unpin it.
  9939. */
  9940. if (plane->fb)
  9941. intel_unpin_fb_obj(old_obj);
  9942. i915_gem_track_fb(old_obj, obj,
  9943. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9944. /* Pin and return without programming hardware */
  9945. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9946. mutex_unlock(&dev->struct_mutex);
  9947. return ret;
  9948. }
  9949. intel_crtc_wait_for_pending_flips(crtc);
  9950. /*
  9951. * If clipping results in a non-visible primary plane, we'll disable
  9952. * the primary plane. Note that this is a bit different than what
  9953. * happens if userspace explicitly disables the plane by passing fb=0
  9954. * because plane->fb still gets set and pinned.
  9955. */
  9956. if (!visible) {
  9957. mutex_lock(&dev->struct_mutex);
  9958. /*
  9959. * Try to pin the new fb first so that we can bail out if we
  9960. * fail.
  9961. */
  9962. if (plane->fb != fb) {
  9963. ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
  9964. if (ret) {
  9965. mutex_unlock(&dev->struct_mutex);
  9966. return ret;
  9967. }
  9968. }
  9969. i915_gem_track_fb(old_obj, obj,
  9970. INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
  9971. if (intel_crtc->primary_enabled)
  9972. intel_disable_primary_hw_plane(plane, crtc);
  9973. if (plane->fb != fb)
  9974. if (plane->fb)
  9975. intel_unpin_fb_obj(old_obj);
  9976. mutex_unlock(&dev->struct_mutex);
  9977. } else {
  9978. if (intel_crtc && intel_crtc->active &&
  9979. intel_crtc->primary_enabled) {
  9980. /*
  9981. * FBC does not work on some platforms for rotated
  9982. * planes, so disable it when rotation is not 0 and
  9983. * update it when rotation is set back to 0.
  9984. *
  9985. * FIXME: This is redundant with the fbc update done in
  9986. * the primary plane enable function except that that
  9987. * one is done too late. We eventually need to unify
  9988. * this.
  9989. */
  9990. if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
  9991. dev_priv->fbc.plane == intel_crtc->plane &&
  9992. intel_plane->rotation != BIT(DRM_ROTATE_0)) {
  9993. intel_disable_fbc(dev);
  9994. }
  9995. }
  9996. ret = intel_pipe_set_base(crtc, src.x1, src.y1, fb);
  9997. if (ret)
  9998. return ret;
  9999. if (!intel_crtc->primary_enabled)
  10000. intel_enable_primary_hw_plane(plane, crtc);
  10001. }
  10002. intel_plane->crtc_x = orig.crtc_x;
  10003. intel_plane->crtc_y = orig.crtc_y;
  10004. intel_plane->crtc_w = orig.crtc_w;
  10005. intel_plane->crtc_h = orig.crtc_h;
  10006. intel_plane->src_x = orig.src_x;
  10007. intel_plane->src_y = orig.src_y;
  10008. intel_plane->src_w = orig.src_w;
  10009. intel_plane->src_h = orig.src_h;
  10010. intel_plane->obj = obj;
  10011. return 0;
  10012. }
  10013. /* Common destruction function for both primary and cursor planes */
  10014. static void intel_plane_destroy(struct drm_plane *plane)
  10015. {
  10016. struct intel_plane *intel_plane = to_intel_plane(plane);
  10017. drm_plane_cleanup(plane);
  10018. kfree(intel_plane);
  10019. }
  10020. static const struct drm_plane_funcs intel_primary_plane_funcs = {
  10021. .update_plane = intel_primary_plane_setplane,
  10022. .disable_plane = intel_primary_plane_disable,
  10023. .destroy = intel_plane_destroy,
  10024. .set_property = intel_plane_set_property
  10025. };
  10026. static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
  10027. int pipe)
  10028. {
  10029. struct intel_plane *primary;
  10030. const uint32_t *intel_primary_formats;
  10031. int num_formats;
  10032. primary = kzalloc(sizeof(*primary), GFP_KERNEL);
  10033. if (primary == NULL)
  10034. return NULL;
  10035. primary->can_scale = false;
  10036. primary->max_downscale = 1;
  10037. primary->pipe = pipe;
  10038. primary->plane = pipe;
  10039. primary->rotation = BIT(DRM_ROTATE_0);
  10040. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
  10041. primary->plane = !pipe;
  10042. if (INTEL_INFO(dev)->gen <= 3) {
  10043. intel_primary_formats = intel_primary_formats_gen2;
  10044. num_formats = ARRAY_SIZE(intel_primary_formats_gen2);
  10045. } else {
  10046. intel_primary_formats = intel_primary_formats_gen4;
  10047. num_formats = ARRAY_SIZE(intel_primary_formats_gen4);
  10048. }
  10049. drm_universal_plane_init(dev, &primary->base, 0,
  10050. &intel_primary_plane_funcs,
  10051. intel_primary_formats, num_formats,
  10052. DRM_PLANE_TYPE_PRIMARY);
  10053. if (INTEL_INFO(dev)->gen >= 4) {
  10054. if (!dev->mode_config.rotation_property)
  10055. dev->mode_config.rotation_property =
  10056. drm_mode_create_rotation_property(dev,
  10057. BIT(DRM_ROTATE_0) |
  10058. BIT(DRM_ROTATE_180));
  10059. if (dev->mode_config.rotation_property)
  10060. drm_object_attach_property(&primary->base.base,
  10061. dev->mode_config.rotation_property,
  10062. primary->rotation);
  10063. }
  10064. return &primary->base;
  10065. }
  10066. static int
  10067. intel_cursor_plane_disable(struct drm_plane *plane)
  10068. {
  10069. if (!plane->fb)
  10070. return 0;
  10071. BUG_ON(!plane->crtc);
  10072. return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0);
  10073. }
  10074. static int
  10075. intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
  10076. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  10077. unsigned int crtc_w, unsigned int crtc_h,
  10078. uint32_t src_x, uint32_t src_y,
  10079. uint32_t src_w, uint32_t src_h)
  10080. {
  10081. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  10082. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10083. struct drm_i915_gem_object *obj = intel_fb->obj;
  10084. struct drm_rect dest = {
  10085. /* integer pixels */
  10086. .x1 = crtc_x,
  10087. .y1 = crtc_y,
  10088. .x2 = crtc_x + crtc_w,
  10089. .y2 = crtc_y + crtc_h,
  10090. };
  10091. struct drm_rect src = {
  10092. /* 16.16 fixed point */
  10093. .x1 = src_x,
  10094. .y1 = src_y,
  10095. .x2 = src_x + src_w,
  10096. .y2 = src_y + src_h,
  10097. };
  10098. const struct drm_rect clip = {
  10099. /* integer pixels */
  10100. .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
  10101. .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
  10102. };
  10103. bool visible;
  10104. int ret;
  10105. ret = drm_plane_helper_check_update(plane, crtc, fb,
  10106. &src, &dest, &clip,
  10107. DRM_PLANE_HELPER_NO_SCALING,
  10108. DRM_PLANE_HELPER_NO_SCALING,
  10109. true, true, &visible);
  10110. if (ret)
  10111. return ret;
  10112. crtc->cursor_x = crtc_x;
  10113. crtc->cursor_y = crtc_y;
  10114. if (fb != crtc->cursor->fb) {
  10115. return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h);
  10116. } else {
  10117. intel_crtc_update_cursor(crtc, visible);
  10118. intel_frontbuffer_flip(crtc->dev,
  10119. INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe));
  10120. return 0;
  10121. }
  10122. }
  10123. static const struct drm_plane_funcs intel_cursor_plane_funcs = {
  10124. .update_plane = intel_cursor_plane_update,
  10125. .disable_plane = intel_cursor_plane_disable,
  10126. .destroy = intel_plane_destroy,
  10127. };
  10128. static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
  10129. int pipe)
  10130. {
  10131. struct intel_plane *cursor;
  10132. cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
  10133. if (cursor == NULL)
  10134. return NULL;
  10135. cursor->can_scale = false;
  10136. cursor->max_downscale = 1;
  10137. cursor->pipe = pipe;
  10138. cursor->plane = pipe;
  10139. drm_universal_plane_init(dev, &cursor->base, 0,
  10140. &intel_cursor_plane_funcs,
  10141. intel_cursor_formats,
  10142. ARRAY_SIZE(intel_cursor_formats),
  10143. DRM_PLANE_TYPE_CURSOR);
  10144. return &cursor->base;
  10145. }
  10146. static void intel_crtc_init(struct drm_device *dev, int pipe)
  10147. {
  10148. struct drm_i915_private *dev_priv = dev->dev_private;
  10149. struct intel_crtc *intel_crtc;
  10150. struct drm_plane *primary = NULL;
  10151. struct drm_plane *cursor = NULL;
  10152. int i, ret;
  10153. intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
  10154. if (intel_crtc == NULL)
  10155. return;
  10156. primary = intel_primary_plane_create(dev, pipe);
  10157. if (!primary)
  10158. goto fail;
  10159. cursor = intel_cursor_plane_create(dev, pipe);
  10160. if (!cursor)
  10161. goto fail;
  10162. ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary,
  10163. cursor, &intel_crtc_funcs);
  10164. if (ret)
  10165. goto fail;
  10166. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  10167. for (i = 0; i < 256; i++) {
  10168. intel_crtc->lut_r[i] = i;
  10169. intel_crtc->lut_g[i] = i;
  10170. intel_crtc->lut_b[i] = i;
  10171. }
  10172. /*
  10173. * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port
  10174. * is hooked to pipe B. Hence we want plane A feeding pipe B.
  10175. */
  10176. intel_crtc->pipe = pipe;
  10177. intel_crtc->plane = pipe;
  10178. if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) {
  10179. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  10180. intel_crtc->plane = !pipe;
  10181. }
  10182. intel_crtc->cursor_base = ~0;
  10183. intel_crtc->cursor_cntl = ~0;
  10184. intel_crtc->cursor_size = ~0;
  10185. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  10186. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  10187. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  10188. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  10189. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  10190. WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
  10191. return;
  10192. fail:
  10193. if (primary)
  10194. drm_plane_cleanup(primary);
  10195. if (cursor)
  10196. drm_plane_cleanup(cursor);
  10197. kfree(intel_crtc);
  10198. }
  10199. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector)
  10200. {
  10201. struct drm_encoder *encoder = connector->base.encoder;
  10202. struct drm_device *dev = connector->base.dev;
  10203. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  10204. if (!encoder)
  10205. return INVALID_PIPE;
  10206. return to_intel_crtc(encoder->crtc)->pipe;
  10207. }
  10208. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  10209. struct drm_file *file)
  10210. {
  10211. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  10212. struct drm_crtc *drmmode_crtc;
  10213. struct intel_crtc *crtc;
  10214. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  10215. return -ENODEV;
  10216. drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id);
  10217. if (!drmmode_crtc) {
  10218. DRM_ERROR("no such CRTC id\n");
  10219. return -ENOENT;
  10220. }
  10221. crtc = to_intel_crtc(drmmode_crtc);
  10222. pipe_from_crtc_id->pipe = crtc->pipe;
  10223. return 0;
  10224. }
  10225. static int intel_encoder_clones(struct intel_encoder *encoder)
  10226. {
  10227. struct drm_device *dev = encoder->base.dev;
  10228. struct intel_encoder *source_encoder;
  10229. int index_mask = 0;
  10230. int entry = 0;
  10231. for_each_intel_encoder(dev, source_encoder) {
  10232. if (encoders_cloneable(encoder, source_encoder))
  10233. index_mask |= (1 << entry);
  10234. entry++;
  10235. }
  10236. return index_mask;
  10237. }
  10238. static bool has_edp_a(struct drm_device *dev)
  10239. {
  10240. struct drm_i915_private *dev_priv = dev->dev_private;
  10241. if (!IS_MOBILE(dev))
  10242. return false;
  10243. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  10244. return false;
  10245. if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
  10246. return false;
  10247. return true;
  10248. }
  10249. const char *intel_output_name(int output)
  10250. {
  10251. static const char *names[] = {
  10252. [INTEL_OUTPUT_UNUSED] = "Unused",
  10253. [INTEL_OUTPUT_ANALOG] = "Analog",
  10254. [INTEL_OUTPUT_DVO] = "DVO",
  10255. [INTEL_OUTPUT_SDVO] = "SDVO",
  10256. [INTEL_OUTPUT_LVDS] = "LVDS",
  10257. [INTEL_OUTPUT_TVOUT] = "TV",
  10258. [INTEL_OUTPUT_HDMI] = "HDMI",
  10259. [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort",
  10260. [INTEL_OUTPUT_EDP] = "eDP",
  10261. [INTEL_OUTPUT_DSI] = "DSI",
  10262. [INTEL_OUTPUT_UNKNOWN] = "Unknown",
  10263. };
  10264. if (output < 0 || output >= ARRAY_SIZE(names) || !names[output])
  10265. return "Invalid";
  10266. return names[output];
  10267. }
  10268. static bool intel_crt_present(struct drm_device *dev)
  10269. {
  10270. struct drm_i915_private *dev_priv = dev->dev_private;
  10271. if (IS_ULT(dev))
  10272. return false;
  10273. if (IS_CHERRYVIEW(dev))
  10274. return false;
  10275. if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support)
  10276. return false;
  10277. return true;
  10278. }
  10279. static void intel_setup_outputs(struct drm_device *dev)
  10280. {
  10281. struct drm_i915_private *dev_priv = dev->dev_private;
  10282. struct intel_encoder *encoder;
  10283. bool dpd_is_edp = false;
  10284. intel_lvds_init(dev);
  10285. if (intel_crt_present(dev))
  10286. intel_crt_init(dev);
  10287. if (HAS_DDI(dev)) {
  10288. int found;
  10289. /* Haswell uses DDI functions to detect digital outputs */
  10290. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  10291. /* DDI A only supports eDP */
  10292. if (found)
  10293. intel_ddi_init(dev, PORT_A);
  10294. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  10295. * register */
  10296. found = I915_READ(SFUSE_STRAP);
  10297. if (found & SFUSE_STRAP_DDIB_DETECTED)
  10298. intel_ddi_init(dev, PORT_B);
  10299. if (found & SFUSE_STRAP_DDIC_DETECTED)
  10300. intel_ddi_init(dev, PORT_C);
  10301. if (found & SFUSE_STRAP_DDID_DETECTED)
  10302. intel_ddi_init(dev, PORT_D);
  10303. } else if (HAS_PCH_SPLIT(dev)) {
  10304. int found;
  10305. dpd_is_edp = intel_dp_is_edp(dev, PORT_D);
  10306. if (has_edp_a(dev))
  10307. intel_dp_init(dev, DP_A, PORT_A);
  10308. if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
  10309. /* PCH SDVOB multiplex with HDMIB */
  10310. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  10311. if (!found)
  10312. intel_hdmi_init(dev, PCH_HDMIB, PORT_B);
  10313. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  10314. intel_dp_init(dev, PCH_DP_B, PORT_B);
  10315. }
  10316. if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
  10317. intel_hdmi_init(dev, PCH_HDMIC, PORT_C);
  10318. if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
  10319. intel_hdmi_init(dev, PCH_HDMID, PORT_D);
  10320. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  10321. intel_dp_init(dev, PCH_DP_C, PORT_C);
  10322. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  10323. intel_dp_init(dev, PCH_DP_D, PORT_D);
  10324. } else if (IS_VALLEYVIEW(dev)) {
  10325. /*
  10326. * The DP_DETECTED bit is the latched state of the DDC
  10327. * SDA pin at boot. However since eDP doesn't require DDC
  10328. * (no way to plug in a DP->HDMI dongle) the DDC pins for
  10329. * eDP ports may have been muxed to an alternate function.
  10330. * Thus we can't rely on the DP_DETECTED bit alone to detect
  10331. * eDP ports. Consult the VBT as well as DP_DETECTED to
  10332. * detect eDP ports.
  10333. */
  10334. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED)
  10335. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB,
  10336. PORT_B);
  10337. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED ||
  10338. intel_dp_is_edp(dev, PORT_B))
  10339. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  10340. if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED)
  10341. intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC,
  10342. PORT_C);
  10343. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED ||
  10344. intel_dp_is_edp(dev, PORT_C))
  10345. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  10346. if (IS_CHERRYVIEW(dev)) {
  10347. if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED)
  10348. intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID,
  10349. PORT_D);
  10350. /* eDP not supported on port D, so don't check VBT */
  10351. if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED)
  10352. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D);
  10353. }
  10354. intel_dsi_init(dev);
  10355. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  10356. bool found = false;
  10357. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10358. DRM_DEBUG_KMS("probing SDVOB\n");
  10359. found = intel_sdvo_init(dev, GEN3_SDVOB, true);
  10360. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  10361. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  10362. intel_hdmi_init(dev, GEN4_HDMIB, PORT_B);
  10363. }
  10364. if (!found && SUPPORTS_INTEGRATED_DP(dev))
  10365. intel_dp_init(dev, DP_B, PORT_B);
  10366. }
  10367. /* Before G4X SDVOC doesn't have its own detect register */
  10368. if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
  10369. DRM_DEBUG_KMS("probing SDVOC\n");
  10370. found = intel_sdvo_init(dev, GEN3_SDVOC, false);
  10371. }
  10372. if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
  10373. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  10374. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  10375. intel_hdmi_init(dev, GEN4_HDMIC, PORT_C);
  10376. }
  10377. if (SUPPORTS_INTEGRATED_DP(dev))
  10378. intel_dp_init(dev, DP_C, PORT_C);
  10379. }
  10380. if (SUPPORTS_INTEGRATED_DP(dev) &&
  10381. (I915_READ(DP_D) & DP_DETECTED))
  10382. intel_dp_init(dev, DP_D, PORT_D);
  10383. } else if (IS_GEN2(dev))
  10384. intel_dvo_init(dev);
  10385. if (SUPPORTS_TV(dev))
  10386. intel_tv_init(dev);
  10387. intel_edp_psr_init(dev);
  10388. for_each_intel_encoder(dev, encoder) {
  10389. encoder->base.possible_crtcs = encoder->crtc_mask;
  10390. encoder->base.possible_clones =
  10391. intel_encoder_clones(encoder);
  10392. }
  10393. intel_init_pch_refclk(dev);
  10394. drm_helper_move_panel_connectors_to_head(dev);
  10395. }
  10396. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  10397. {
  10398. struct drm_device *dev = fb->dev;
  10399. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10400. drm_framebuffer_cleanup(fb);
  10401. mutex_lock(&dev->struct_mutex);
  10402. WARN_ON(!intel_fb->obj->framebuffer_references--);
  10403. drm_gem_object_unreference(&intel_fb->obj->base);
  10404. mutex_unlock(&dev->struct_mutex);
  10405. kfree(intel_fb);
  10406. }
  10407. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  10408. struct drm_file *file,
  10409. unsigned int *handle)
  10410. {
  10411. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  10412. struct drm_i915_gem_object *obj = intel_fb->obj;
  10413. return drm_gem_handle_create(file, &obj->base, handle);
  10414. }
  10415. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  10416. .destroy = intel_user_framebuffer_destroy,
  10417. .create_handle = intel_user_framebuffer_create_handle,
  10418. };
  10419. static int intel_framebuffer_init(struct drm_device *dev,
  10420. struct intel_framebuffer *intel_fb,
  10421. struct drm_mode_fb_cmd2 *mode_cmd,
  10422. struct drm_i915_gem_object *obj)
  10423. {
  10424. int aligned_height;
  10425. int pitch_limit;
  10426. int ret;
  10427. WARN_ON(!mutex_is_locked(&dev->struct_mutex));
  10428. if (obj->tiling_mode == I915_TILING_Y) {
  10429. DRM_DEBUG("hardware does not support tiling Y\n");
  10430. return -EINVAL;
  10431. }
  10432. if (mode_cmd->pitches[0] & 63) {
  10433. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  10434. mode_cmd->pitches[0]);
  10435. return -EINVAL;
  10436. }
  10437. if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) {
  10438. pitch_limit = 32*1024;
  10439. } else if (INTEL_INFO(dev)->gen >= 4) {
  10440. if (obj->tiling_mode)
  10441. pitch_limit = 16*1024;
  10442. else
  10443. pitch_limit = 32*1024;
  10444. } else if (INTEL_INFO(dev)->gen >= 3) {
  10445. if (obj->tiling_mode)
  10446. pitch_limit = 8*1024;
  10447. else
  10448. pitch_limit = 16*1024;
  10449. } else
  10450. /* XXX DSPC is limited to 4k tiled */
  10451. pitch_limit = 8*1024;
  10452. if (mode_cmd->pitches[0] > pitch_limit) {
  10453. DRM_DEBUG("%s pitch (%d) must be at less than %d\n",
  10454. obj->tiling_mode ? "tiled" : "linear",
  10455. mode_cmd->pitches[0], pitch_limit);
  10456. return -EINVAL;
  10457. }
  10458. if (obj->tiling_mode != I915_TILING_NONE &&
  10459. mode_cmd->pitches[0] != obj->stride) {
  10460. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  10461. mode_cmd->pitches[0], obj->stride);
  10462. return -EINVAL;
  10463. }
  10464. /* Reject formats not supported by any plane early. */
  10465. switch (mode_cmd->pixel_format) {
  10466. case DRM_FORMAT_C8:
  10467. case DRM_FORMAT_RGB565:
  10468. case DRM_FORMAT_XRGB8888:
  10469. case DRM_FORMAT_ARGB8888:
  10470. break;
  10471. case DRM_FORMAT_XRGB1555:
  10472. case DRM_FORMAT_ARGB1555:
  10473. if (INTEL_INFO(dev)->gen > 3) {
  10474. DRM_DEBUG("unsupported pixel format: %s\n",
  10475. drm_get_format_name(mode_cmd->pixel_format));
  10476. return -EINVAL;
  10477. }
  10478. break;
  10479. case DRM_FORMAT_XBGR8888:
  10480. case DRM_FORMAT_ABGR8888:
  10481. case DRM_FORMAT_XRGB2101010:
  10482. case DRM_FORMAT_ARGB2101010:
  10483. case DRM_FORMAT_XBGR2101010:
  10484. case DRM_FORMAT_ABGR2101010:
  10485. if (INTEL_INFO(dev)->gen < 4) {
  10486. DRM_DEBUG("unsupported pixel format: %s\n",
  10487. drm_get_format_name(mode_cmd->pixel_format));
  10488. return -EINVAL;
  10489. }
  10490. break;
  10491. case DRM_FORMAT_YUYV:
  10492. case DRM_FORMAT_UYVY:
  10493. case DRM_FORMAT_YVYU:
  10494. case DRM_FORMAT_VYUY:
  10495. if (INTEL_INFO(dev)->gen < 5) {
  10496. DRM_DEBUG("unsupported pixel format: %s\n",
  10497. drm_get_format_name(mode_cmd->pixel_format));
  10498. return -EINVAL;
  10499. }
  10500. break;
  10501. default:
  10502. DRM_DEBUG("unsupported pixel format: %s\n",
  10503. drm_get_format_name(mode_cmd->pixel_format));
  10504. return -EINVAL;
  10505. }
  10506. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  10507. if (mode_cmd->offsets[0] != 0)
  10508. return -EINVAL;
  10509. aligned_height = intel_align_height(dev, mode_cmd->height,
  10510. obj->tiling_mode);
  10511. /* FIXME drm helper for size checks (especially planar formats)? */
  10512. if (obj->base.size < aligned_height * mode_cmd->pitches[0])
  10513. return -EINVAL;
  10514. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  10515. intel_fb->obj = obj;
  10516. intel_fb->obj->framebuffer_references++;
  10517. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  10518. if (ret) {
  10519. DRM_ERROR("framebuffer init failed %d\n", ret);
  10520. return ret;
  10521. }
  10522. return 0;
  10523. }
  10524. static struct drm_framebuffer *
  10525. intel_user_framebuffer_create(struct drm_device *dev,
  10526. struct drm_file *filp,
  10527. struct drm_mode_fb_cmd2 *mode_cmd)
  10528. {
  10529. struct drm_i915_gem_object *obj;
  10530. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  10531. mode_cmd->handles[0]));
  10532. if (&obj->base == NULL)
  10533. return ERR_PTR(-ENOENT);
  10534. return intel_framebuffer_create(dev, mode_cmd, obj);
  10535. }
  10536. #ifndef CONFIG_DRM_I915_FBDEV
  10537. static inline void intel_fbdev_output_poll_changed(struct drm_device *dev)
  10538. {
  10539. }
  10540. #endif
  10541. static const struct drm_mode_config_funcs intel_mode_funcs = {
  10542. .fb_create = intel_user_framebuffer_create,
  10543. .output_poll_changed = intel_fbdev_output_poll_changed,
  10544. };
  10545. /* Set up chip specific display functions */
  10546. static void intel_init_display(struct drm_device *dev)
  10547. {
  10548. struct drm_i915_private *dev_priv = dev->dev_private;
  10549. if (HAS_PCH_SPLIT(dev) || IS_G4X(dev))
  10550. dev_priv->display.find_dpll = g4x_find_best_dpll;
  10551. else if (IS_CHERRYVIEW(dev))
  10552. dev_priv->display.find_dpll = chv_find_best_dpll;
  10553. else if (IS_VALLEYVIEW(dev))
  10554. dev_priv->display.find_dpll = vlv_find_best_dpll;
  10555. else if (IS_PINEVIEW(dev))
  10556. dev_priv->display.find_dpll = pnv_find_best_dpll;
  10557. else
  10558. dev_priv->display.find_dpll = i9xx_find_best_dpll;
  10559. if (HAS_DDI(dev)) {
  10560. dev_priv->display.get_pipe_config = haswell_get_pipe_config;
  10561. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10562. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  10563. dev_priv->display.crtc_enable = haswell_crtc_enable;
  10564. dev_priv->display.crtc_disable = haswell_crtc_disable;
  10565. dev_priv->display.off = ironlake_crtc_off;
  10566. dev_priv->display.update_primary_plane =
  10567. ironlake_update_primary_plane;
  10568. } else if (HAS_PCH_SPLIT(dev)) {
  10569. dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
  10570. dev_priv->display.get_plane_config = ironlake_get_plane_config;
  10571. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  10572. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  10573. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  10574. dev_priv->display.off = ironlake_crtc_off;
  10575. dev_priv->display.update_primary_plane =
  10576. ironlake_update_primary_plane;
  10577. } else if (IS_VALLEYVIEW(dev)) {
  10578. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10579. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10580. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10581. dev_priv->display.crtc_enable = valleyview_crtc_enable;
  10582. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10583. dev_priv->display.off = i9xx_crtc_off;
  10584. dev_priv->display.update_primary_plane =
  10585. i9xx_update_primary_plane;
  10586. } else {
  10587. dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
  10588. dev_priv->display.get_plane_config = i9xx_get_plane_config;
  10589. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  10590. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  10591. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  10592. dev_priv->display.off = i9xx_crtc_off;
  10593. dev_priv->display.update_primary_plane =
  10594. i9xx_update_primary_plane;
  10595. }
  10596. /* Returns the core display clock speed */
  10597. if (IS_VALLEYVIEW(dev))
  10598. dev_priv->display.get_display_clock_speed =
  10599. valleyview_get_display_clock_speed;
  10600. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  10601. dev_priv->display.get_display_clock_speed =
  10602. i945_get_display_clock_speed;
  10603. else if (IS_I915G(dev))
  10604. dev_priv->display.get_display_clock_speed =
  10605. i915_get_display_clock_speed;
  10606. else if (IS_I945GM(dev) || IS_845G(dev))
  10607. dev_priv->display.get_display_clock_speed =
  10608. i9xx_misc_get_display_clock_speed;
  10609. else if (IS_PINEVIEW(dev))
  10610. dev_priv->display.get_display_clock_speed =
  10611. pnv_get_display_clock_speed;
  10612. else if (IS_I915GM(dev))
  10613. dev_priv->display.get_display_clock_speed =
  10614. i915gm_get_display_clock_speed;
  10615. else if (IS_I865G(dev))
  10616. dev_priv->display.get_display_clock_speed =
  10617. i865_get_display_clock_speed;
  10618. else if (IS_I85X(dev))
  10619. dev_priv->display.get_display_clock_speed =
  10620. i855_get_display_clock_speed;
  10621. else /* 852, 830 */
  10622. dev_priv->display.get_display_clock_speed =
  10623. i830_get_display_clock_speed;
  10624. if (IS_G4X(dev)) {
  10625. dev_priv->display.write_eld = g4x_write_eld;
  10626. } else if (IS_GEN5(dev)) {
  10627. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  10628. dev_priv->display.write_eld = ironlake_write_eld;
  10629. } else if (IS_GEN6(dev)) {
  10630. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  10631. dev_priv->display.write_eld = ironlake_write_eld;
  10632. dev_priv->display.modeset_global_resources =
  10633. snb_modeset_global_resources;
  10634. } else if (IS_IVYBRIDGE(dev)) {
  10635. /* FIXME: detect B0+ stepping and use auto training */
  10636. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  10637. dev_priv->display.write_eld = ironlake_write_eld;
  10638. dev_priv->display.modeset_global_resources =
  10639. ivb_modeset_global_resources;
  10640. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  10641. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  10642. dev_priv->display.write_eld = haswell_write_eld;
  10643. dev_priv->display.modeset_global_resources =
  10644. haswell_modeset_global_resources;
  10645. } else if (IS_VALLEYVIEW(dev)) {
  10646. dev_priv->display.modeset_global_resources =
  10647. valleyview_modeset_global_resources;
  10648. dev_priv->display.write_eld = ironlake_write_eld;
  10649. }
  10650. /* Default just returns -ENODEV to indicate unsupported */
  10651. dev_priv->display.queue_flip = intel_default_queue_flip;
  10652. switch (INTEL_INFO(dev)->gen) {
  10653. case 2:
  10654. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  10655. break;
  10656. case 3:
  10657. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  10658. break;
  10659. case 4:
  10660. case 5:
  10661. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  10662. break;
  10663. case 6:
  10664. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  10665. break;
  10666. case 7:
  10667. case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */
  10668. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  10669. break;
  10670. }
  10671. intel_panel_init_backlight_funcs(dev);
  10672. mutex_init(&dev_priv->pps_mutex);
  10673. }
  10674. /*
  10675. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  10676. * resume, or other times. This quirk makes sure that's the case for
  10677. * affected systems.
  10678. */
  10679. static void quirk_pipea_force(struct drm_device *dev)
  10680. {
  10681. struct drm_i915_private *dev_priv = dev->dev_private;
  10682. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  10683. DRM_INFO("applying pipe a force quirk\n");
  10684. }
  10685. static void quirk_pipeb_force(struct drm_device *dev)
  10686. {
  10687. struct drm_i915_private *dev_priv = dev->dev_private;
  10688. dev_priv->quirks |= QUIRK_PIPEB_FORCE;
  10689. DRM_INFO("applying pipe b force quirk\n");
  10690. }
  10691. /*
  10692. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  10693. */
  10694. static void quirk_ssc_force_disable(struct drm_device *dev)
  10695. {
  10696. struct drm_i915_private *dev_priv = dev->dev_private;
  10697. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  10698. DRM_INFO("applying lvds SSC disable quirk\n");
  10699. }
  10700. /*
  10701. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  10702. * brightness value
  10703. */
  10704. static void quirk_invert_brightness(struct drm_device *dev)
  10705. {
  10706. struct drm_i915_private *dev_priv = dev->dev_private;
  10707. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  10708. DRM_INFO("applying inverted panel brightness quirk\n");
  10709. }
  10710. /* Some VBT's incorrectly indicate no backlight is present */
  10711. static void quirk_backlight_present(struct drm_device *dev)
  10712. {
  10713. struct drm_i915_private *dev_priv = dev->dev_private;
  10714. dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT;
  10715. DRM_INFO("applying backlight present quirk\n");
  10716. }
  10717. struct intel_quirk {
  10718. int device;
  10719. int subsystem_vendor;
  10720. int subsystem_device;
  10721. void (*hook)(struct drm_device *dev);
  10722. };
  10723. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  10724. struct intel_dmi_quirk {
  10725. void (*hook)(struct drm_device *dev);
  10726. const struct dmi_system_id (*dmi_id_list)[];
  10727. };
  10728. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  10729. {
  10730. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  10731. return 1;
  10732. }
  10733. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  10734. {
  10735. .dmi_id_list = &(const struct dmi_system_id[]) {
  10736. {
  10737. .callback = intel_dmi_reverse_brightness,
  10738. .ident = "NCR Corporation",
  10739. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  10740. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  10741. },
  10742. },
  10743. { } /* terminating entry */
  10744. },
  10745. .hook = quirk_invert_brightness,
  10746. },
  10747. };
  10748. static struct intel_quirk intel_quirks[] = {
  10749. /* HP Mini needs pipe A force quirk (LP: #322104) */
  10750. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  10751. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  10752. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  10753. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  10754. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  10755. /* 830 needs to leave pipe A & dpll A up */
  10756. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  10757. /* 830 needs to leave pipe B & dpll B up */
  10758. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force },
  10759. /* Lenovo U160 cannot use SSC on LVDS */
  10760. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  10761. /* Sony Vaio Y cannot use SSC on LVDS */
  10762. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  10763. /* Acer Aspire 5734Z must invert backlight brightness */
  10764. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  10765. /* Acer/eMachines G725 */
  10766. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  10767. /* Acer/eMachines e725 */
  10768. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  10769. /* Acer/Packard Bell NCL20 */
  10770. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  10771. /* Acer Aspire 4736Z */
  10772. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  10773. /* Acer Aspire 5336 */
  10774. { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
  10775. /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
  10776. { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
  10777. /* Acer C720 Chromebook (Core i3 4005U) */
  10778. { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
  10779. /* Apple Macbook 2,1 (Core 2 T7400) */
  10780. { 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
  10781. /* Toshiba CB35 Chromebook (Celeron 2955U) */
  10782. { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
  10783. /* HP Chromebook 14 (Celeron 2955U) */
  10784. { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
  10785. };
  10786. static void intel_init_quirks(struct drm_device *dev)
  10787. {
  10788. struct pci_dev *d = dev->pdev;
  10789. int i;
  10790. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  10791. struct intel_quirk *q = &intel_quirks[i];
  10792. if (d->device == q->device &&
  10793. (d->subsystem_vendor == q->subsystem_vendor ||
  10794. q->subsystem_vendor == PCI_ANY_ID) &&
  10795. (d->subsystem_device == q->subsystem_device ||
  10796. q->subsystem_device == PCI_ANY_ID))
  10797. q->hook(dev);
  10798. }
  10799. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  10800. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  10801. intel_dmi_quirks[i].hook(dev);
  10802. }
  10803. }
  10804. /* Disable the VGA plane that we never use */
  10805. static void i915_disable_vga(struct drm_device *dev)
  10806. {
  10807. struct drm_i915_private *dev_priv = dev->dev_private;
  10808. u8 sr1;
  10809. u32 vga_reg = i915_vgacntrl_reg(dev);
  10810. /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
  10811. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  10812. outb(SR01, VGA_SR_INDEX);
  10813. sr1 = inb(VGA_SR_DATA);
  10814. outb(sr1 | 1<<5, VGA_SR_DATA);
  10815. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  10816. udelay(300);
  10817. /*
  10818. * Fujitsu-Siemens Lifebook S6010 (830) has problems resuming
  10819. * from S3 without preserving (some of?) the other bits.
  10820. */
  10821. I915_WRITE(vga_reg, dev_priv->bios_vgacntr | VGA_DISP_DISABLE);
  10822. POSTING_READ(vga_reg);
  10823. }
  10824. void intel_modeset_init_hw(struct drm_device *dev)
  10825. {
  10826. intel_prepare_ddi(dev);
  10827. if (IS_VALLEYVIEW(dev))
  10828. vlv_update_cdclk(dev);
  10829. intel_init_clock_gating(dev);
  10830. intel_enable_gt_powersave(dev);
  10831. }
  10832. void intel_modeset_suspend_hw(struct drm_device *dev)
  10833. {
  10834. intel_suspend_hw(dev);
  10835. }
  10836. void intel_modeset_init(struct drm_device *dev)
  10837. {
  10838. struct drm_i915_private *dev_priv = dev->dev_private;
  10839. int sprite, ret;
  10840. enum pipe pipe;
  10841. struct intel_crtc *crtc;
  10842. drm_mode_config_init(dev);
  10843. dev->mode_config.min_width = 0;
  10844. dev->mode_config.min_height = 0;
  10845. dev->mode_config.preferred_depth = 24;
  10846. dev->mode_config.prefer_shadow = 1;
  10847. dev->mode_config.funcs = &intel_mode_funcs;
  10848. intel_init_quirks(dev);
  10849. intel_init_pm(dev);
  10850. if (INTEL_INFO(dev)->num_pipes == 0)
  10851. return;
  10852. intel_init_display(dev);
  10853. if (IS_GEN2(dev)) {
  10854. dev->mode_config.max_width = 2048;
  10855. dev->mode_config.max_height = 2048;
  10856. } else if (IS_GEN3(dev)) {
  10857. dev->mode_config.max_width = 4096;
  10858. dev->mode_config.max_height = 4096;
  10859. } else {
  10860. dev->mode_config.max_width = 8192;
  10861. dev->mode_config.max_height = 8192;
  10862. }
  10863. if (IS_845G(dev) || IS_I865G(dev)) {
  10864. dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512;
  10865. dev->mode_config.cursor_height = 1023;
  10866. } else if (IS_GEN2(dev)) {
  10867. dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH;
  10868. dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT;
  10869. } else {
  10870. dev->mode_config.cursor_width = MAX_CURSOR_WIDTH;
  10871. dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT;
  10872. }
  10873. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  10874. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  10875. INTEL_INFO(dev)->num_pipes,
  10876. INTEL_INFO(dev)->num_pipes > 1 ? "s" : "");
  10877. for_each_pipe(dev_priv, pipe) {
  10878. intel_crtc_init(dev, pipe);
  10879. for_each_sprite(pipe, sprite) {
  10880. ret = intel_plane_init(dev, pipe, sprite);
  10881. if (ret)
  10882. DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n",
  10883. pipe_name(pipe), sprite_name(pipe, sprite), ret);
  10884. }
  10885. }
  10886. intel_init_dpio(dev);
  10887. intel_shared_dpll_init(dev);
  10888. /* save the BIOS value before clobbering it */
  10889. dev_priv->bios_vgacntr = I915_READ(i915_vgacntrl_reg(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. }